1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

GCS/coreplugin: Changes to allow uavgadgets to be shown in views

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@337 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-03-19 15:28:11 +00:00 committed by ephy
parent 5b4fced510
commit 8137b68fbd
4 changed files with 176 additions and 467 deletions

View File

@ -82,8 +82,8 @@ static inline ExtensionSystem::PluginManager *pluginManager()
UAVGadgetManagerPlaceHolder::UAVGadgetManagerPlaceHolder(Core::Internal::UAVGadgetMode *mode, QWidget *parent) UAVGadgetManagerPlaceHolder::UAVGadgetManagerPlaceHolder(Core::Internal::UAVGadgetMode *mode, QWidget *parent)
: QWidget(parent), : QWidget(parent),
m_current(0), m_uavGadgetMode(mode),
m_uavGadgetMode(mode) m_current(0)
{ {
m_mode = dynamic_cast<Core::IMode*>(mode); m_mode = dynamic_cast<Core::IMode*>(mode);
setLayout(new QVBoxLayout); setLayout(new QVBoxLayout);
@ -104,7 +104,6 @@ UAVGadgetManagerPlaceHolder::~UAVGadgetManagerPlaceHolder()
void UAVGadgetManagerPlaceHolder::currentModeChanged(Core::IMode *mode) void UAVGadgetManagerPlaceHolder::currentModeChanged(Core::IMode *mode)
{ {
// qDebug() << Q_FUNC_INFO << mode;
UAVGadgetManager *gm = m_uavGadgetMode->uavGadgetManager(); UAVGadgetManager *gm = m_uavGadgetMode->uavGadgetManager();
if (m_current == this) { if (m_current == this) {
m_current = 0; m_current = 0;
@ -119,11 +118,6 @@ void UAVGadgetManagerPlaceHolder::currentModeChanged(Core::IMode *mode)
} }
} }
//UAVGadgetManagerPlaceHolder* UAVGadgetManagerPlaceHolder::current()
//{
// return m_current;
//}
// ---------------- UAVGadgetManager // ---------------- UAVGadgetManager
namespace Core { namespace Core {
@ -135,7 +129,6 @@ struct UAVGadgetManagerPrivate {
Internal::UAVGadgetView *m_view; Internal::UAVGadgetView *m_view;
Internal::SplitterOrView *m_splitterOrView; Internal::SplitterOrView *m_splitterOrView;
QPointer<IUAVGadget> m_currentUAVGadget; QPointer<IUAVGadget> m_currentUAVGadget;
QPointer<SplitterOrView> m_currentView;
ICore *m_core; ICore *m_core;
@ -175,13 +168,9 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
m_hidden(false), m_hidden(false),
m_d(new UAVGadgetManagerPrivate(core, parent)) m_d(new UAVGadgetManagerPrivate(core, parent))
{ {
//qDebug() << Q_FUNC_INFO;
// m_instance = this;
// //qDebug() << Q_FUNC_INFO << m_d->m_core->resourcePath();
connect(m_d->m_core, SIGNAL(contextAboutToChange(Core::IContext *)), connect(m_d->m_core, SIGNAL(contextAboutToChange(Core::IContext *)),
this, SLOT(handleContextChange(Core::IContext *))); this, SLOT(handleContextChange(Core::IContext *)));
// const QList<int> gc = QList<int>() << Constants::C_GLOBAL_ID;
const QList<int> uavGadgetManagerContext = const QList<int> uavGadgetManagerContext =
QList<int>() << m_d->m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_UAVGADGETMANAGER); QList<int>() << m_d->m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_UAVGADGETMANAGER);
@ -208,7 +197,7 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
m_d->m_hideToolbarsAction = new QAction(tr("Hide toolbars"), this); m_d->m_hideToolbarsAction = new QAction(tr("Hide toolbars"), this);
m_d->m_hideToolbarsAction->setCheckable(true); m_d->m_hideToolbarsAction->setCheckable(true);
cmd = am->registerAction(m_d->m_hideToolbarsAction, Constants::HIDE_TOOLBARS, uavGadgetManagerContext); cmd = am->registerAction(m_d->m_hideToolbarsAction, Constants::HIDE_TOOLBARS, uavGadgetManagerContext);
cmd->setDefaultKeySequence(QKeySequence("Ctrl+Shift+F10")); cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F10")));
mwindow->addAction(cmd, Constants::G_WINDOW_HIDE_TOOLBAR); mwindow->addAction(cmd, Constants::G_WINDOW_HIDE_TOOLBAR);
//Window menu separators //Window menu separators
@ -220,16 +209,16 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
connect(m_d->m_hideToolbarsAction, SIGNAL(triggered(bool)), this, SLOT(hideToolbars(bool))); connect(m_d->m_hideToolbarsAction, SIGNAL(triggered(bool)), this, SLOT(hideToolbars(bool)));
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
QString prefix = tr("Meta+E"); QString prefix = tr("Meta+Shift");
#else #else
QString prefix = tr("Ctrl+E"); QString prefix = tr("Ctrl+Shift");
#endif #endif
if (m_d->m_splitAction == 0) if (m_d->m_splitAction == 0)
{ {
m_d->m_splitAction = new QAction(tr("Split"), this); m_d->m_splitAction = new QAction(tr("Split"), this);
cmd = am->registerAction(m_d->m_splitAction, Constants::SPLIT, uavGadgetManagerContext); cmd = am->registerAction(m_d->m_splitAction, Constants::SPLIT, uavGadgetManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("%1,2").arg(prefix))); cmd->setDefaultKeySequence(QKeySequence(tr("%1+Down").arg(prefix)));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT); mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
} }
connect(m_d->m_splitAction, SIGNAL(triggered()), this, SLOT(split())); connect(m_d->m_splitAction, SIGNAL(triggered()), this, SLOT(split()));
@ -238,34 +227,34 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
{ {
m_d->m_splitSideBySideAction = new QAction(tr("Split Side by Side"), this); m_d->m_splitSideBySideAction = new QAction(tr("Split Side by Side"), this);
cmd = am->registerAction(m_d->m_splitSideBySideAction, Constants::SPLIT_SIDE_BY_SIDE, uavGadgetManagerContext); cmd = am->registerAction(m_d->m_splitSideBySideAction, Constants::SPLIT_SIDE_BY_SIDE, uavGadgetManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("%1,3").arg(prefix))); cmd->setDefaultKeySequence(QKeySequence(tr("%1+Right").arg(prefix)));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT); mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
} }
connect(m_d->m_splitSideBySideAction, SIGNAL(triggered()), this, SLOT(splitSideBySide())); connect(m_d->m_splitSideBySideAction, SIGNAL(triggered()), this, SLOT(splitSideBySide()));
if (m_d->m_removeCurrentSplitAction == 0) if (m_d->m_removeCurrentSplitAction == 0)
{ {
m_d->m_removeCurrentSplitAction = new QAction(tr("Remove Current Split"), this); m_d->m_removeCurrentSplitAction = new QAction(tr("Close Current View"), this);
cmd = am->registerAction(m_d->m_removeCurrentSplitAction, Constants::REMOVE_CURRENT_SPLIT, uavGadgetManagerContext); cmd = am->registerAction(m_d->m_removeCurrentSplitAction, Constants::REMOVE_CURRENT_SPLIT, uavGadgetManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("%1,0").arg(prefix))); cmd->setDefaultKeySequence(QKeySequence(tr("%1+C").arg(prefix)));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT); mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
} }
connect(m_d->m_removeCurrentSplitAction, SIGNAL(triggered()), this, SLOT(removeCurrentSplit())); connect(m_d->m_removeCurrentSplitAction, SIGNAL(triggered()), this, SLOT(removeCurrentSplit()));
if (m_d->m_removeAllSplitsAction == 0) if (m_d->m_removeAllSplitsAction == 0)
{ {
m_d->m_removeAllSplitsAction = new QAction(tr("Remove All Splits"), this); m_d->m_removeAllSplitsAction = new QAction(tr("Close All Other Views"), this);
cmd = am->registerAction(m_d->m_removeAllSplitsAction, Constants::REMOVE_ALL_SPLITS, uavGadgetManagerContext); cmd = am->registerAction(m_d->m_removeAllSplitsAction, Constants::REMOVE_ALL_SPLITS, uavGadgetManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("%1,1").arg(prefix))); cmd->setDefaultKeySequence(QKeySequence(tr("%1+A").arg(prefix)));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT); mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
} }
connect(m_d->m_removeAllSplitsAction, SIGNAL(triggered()), this, SLOT(removeAllSplits())); connect(m_d->m_removeAllSplitsAction, SIGNAL(triggered()), this, SLOT(removeAllSplits()));
if (m_d->m_gotoOtherSplitAction == 0) if (m_d->m_gotoOtherSplitAction == 0)
{ {
m_d->m_gotoOtherSplitAction = new QAction(tr("Goto Other Split"), this); m_d->m_gotoOtherSplitAction = new QAction(tr("Goto Next View"), this);
cmd = am->registerAction(m_d->m_gotoOtherSplitAction, Constants::GOTO_OTHER_SPLIT, uavGadgetManagerContext); cmd = am->registerAction(m_d->m_gotoOtherSplitAction, Constants::GOTO_OTHER_SPLIT, uavGadgetManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("%1,o").arg(prefix))); cmd->setDefaultKeySequence(QKeySequence(tr("%1+N").arg(prefix)));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT); mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
} }
connect(m_d->m_gotoOtherSplitAction, SIGNAL(triggered()), this, SLOT(gotoOtherSplit())); connect(m_d->m_gotoOtherSplitAction, SIGNAL(triggered()), this, SLOT(gotoOtherSplit()));
@ -273,6 +262,7 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
// other setup // other setup
m_d->m_splitterOrView = new SplitterOrView(this, 0, true); m_d->m_splitterOrView = new SplitterOrView(this, 0, true);
m_d->m_view = m_d->m_splitterOrView->view(); m_d->m_view = m_d->m_splitterOrView->view();
setCurrentUAVGadget(m_d->m_view->uavGadget());
QHBoxLayout *layout = new QHBoxLayout(this); QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(0); layout->setMargin(0);
@ -296,7 +286,6 @@ UAVGadgetManager::~UAVGadgetManager()
void UAVGadgetManager::init() void UAVGadgetManager::init()
{ {
//qDebug() << Q_FUNC_INFO;
QList<int> context; QList<int> context;
context << m_d->m_core->uniqueIDManager()->uniqueIdentifier("OpenPilot.UAVGadgetManager"); context << m_d->m_core->uniqueIDManager()->uniqueIdentifier("OpenPilot.UAVGadgetManager");
@ -305,20 +294,10 @@ void UAVGadgetManager::init()
pluginManager()->addObject(m_d->m_coreListener); pluginManager()->addObject(m_d->m_coreListener);
} }
void UAVGadgetManager::removeUAVGadget(IUAVGadget *uavGadget)
{
//qDebug() << Q_FUNC_INFO << uavGadget;
if (!uavGadget)
return;
//qDebug() << Q_FUNC_INFO << uavGadget;
m_d->m_core->removeContextObject(qobject_cast<IContext*>(uavGadget));
}
void UAVGadgetManager::handleContextChange(Core::IContext *context) void UAVGadgetManager::handleContextChange(Core::IContext *context)
{ {
//qDebug() << Q_FUNC_INFO; // if (debugUAVGadgetManager)
if (debugUAVGadgetManager) // qDebug() << Q_FUNC_INFO << context;
qDebug() << Q_FUNC_INFO << context;
IUAVGadget *uavGadget = context ? qobject_cast<IUAVGadget*>(context) : 0; IUAVGadget *uavGadget = context ? qobject_cast<IUAVGadget*>(context) : 0;
if (uavGadget) { if (uavGadget) {
setCurrentUAVGadget(uavGadget); setCurrentUAVGadget(uavGadget);
@ -329,294 +308,83 @@ void UAVGadgetManager::handleContextChange(Core::IContext *context)
void UAVGadgetManager::setCurrentUAVGadget(IUAVGadget *uavGadget) void UAVGadgetManager::setCurrentUAVGadget(IUAVGadget *uavGadget)
{ {
//qDebug() << Q_FUNC_INFO;
if (uavGadget)
setCurrentView(0);
if (m_d->m_currentUAVGadget == uavGadget) if (m_d->m_currentUAVGadget == uavGadget)
return; return;
SplitterOrView *oldView = currentSplitterOrView();
m_d->m_currentUAVGadget = uavGadget; m_d->m_currentUAVGadget = uavGadget;
if (uavGadget) { SplitterOrView *view = currentSplitterOrView();
if (SplitterOrView *splitterOrView = m_d->m_splitterOrView->findView(uavGadget)) if (oldView != view) {
splitterOrView->view()->setCurrentUAVGadget(uavGadget); if (oldView)
oldView->update();
if (view)
view->update();
} }
uavGadget->widget()->setFocus();
updateActions(); updateActions();
// emit currentUAVGadgetChanged(uavGadget); // emit currentUAVGadgetChanged(uavGadget);
} }
/* Contract: return current SplitterOrView.
void UAVGadgetManager::setCurrentView(Core::Internal::SplitterOrView *view) * Implications: must not return SplitterOrView that is splitter.
{ */
//qDebug() << Q_FUNC_INFO;
if (view == m_d->m_currentView)
return;
SplitterOrView *old = m_d->m_currentView;
m_d->m_currentView = view;
if (old)
old->update();
if (view)
view->update();
if (view && !view->uavGadget())
view->setFocus();
}
Core::Internal::SplitterOrView *UAVGadgetManager::currentSplitterOrView() const Core::Internal::SplitterOrView *UAVGadgetManager::currentSplitterOrView() const
{ {
SplitterOrView *view = m_d->m_currentView; if (!m_d->m_splitterOrView) // this is only for startup
if (!view) return 0;
view = m_d->m_currentUAVGadget? SplitterOrView *view = m_d->m_currentUAVGadget ?
m_d->m_splitterOrView->findView(m_d->m_currentUAVGadget): m_d->m_splitterOrView->findView(m_d->m_currentUAVGadget) :
m_d->m_splitterOrView->findFirstView(); 0;
if (!view)
return m_d->m_splitterOrView;
return view; return view;
} }
Core::Internal::UAVGadgetView *UAVGadgetManager::currentUAVGadgetView() const
{
//qDebug() << Q_FUNC_INFO;
return currentSplitterOrView()->view();
}
IUAVGadget *UAVGadgetManager::currentUAVGadget() const IUAVGadget *UAVGadgetManager::currentUAVGadget() const
{ {
//qDebug() << Q_FUNC_INFO;
return m_d->m_currentUAVGadget; return m_d->m_currentUAVGadget;
} }
void UAVGadgetManager::emptyView(Core::Internal::UAVGadgetView *view) void UAVGadgetManager::emptyView(Core::Internal::UAVGadgetView *view)
{ {
//qDebug() << Q_FUNC_INFO << view;
if (!view) if (!view)
return; return;
IUAVGadget *uavGadget = view->currentUAVGadget(); IUAVGadget *uavGadget = view->uavGadget();
//qDebug() << Q_FUNC_INFO << view << uavGadget;
// emit uavGadgetAboutToClose(uavGadget); // emit uavGadgetAboutToClose(uavGadget);
removeUAVGadget(uavGadget); removeUAVGadget(uavGadget);
//qDebug() << Q_FUNC_INFO << view << uavGadget;
view->removeUAVGadget(); view->removeUAVGadget();
//qDebug() << Q_FUNC_INFO << view << uavGadget;
// emit uavGadgetsClosed(uavGadgets); // emit uavGadgetsClosed(uavGadgets);
if (uavGadget)
delete uavGadget; // FIXME correct?
} }
void UAVGadgetManager::closeView(Core::Internal::UAVGadgetView *view) void UAVGadgetManager::closeView(Core::Internal::UAVGadgetView *view)
{ {
//qDebug() << Q_FUNC_INFO;
if (!view) if (!view)
return; return;
if (view == m_d->m_view) {
if (IUAVGadget *e = view->currentUAVGadget())
closeUAVGadgets(QList<IUAVGadget *>() << e);
return;
}
emptyView(view);
SplitterOrView *splitterOrView = m_d->m_splitterOrView->findView(view); SplitterOrView *splitterOrView = m_d->m_splitterOrView->findView(view);
Q_ASSERT(splitterOrView); Q_ASSERT(splitterOrView);
Q_ASSERT(splitterOrView->view() == view); Q_ASSERT(splitterOrView->view() == view);
if (splitterOrView == m_d->m_splitterOrView)
return;
emptyView(view);
SplitterOrView *splitter = m_d->m_splitterOrView->findSplitter(splitterOrView); SplitterOrView *splitter = m_d->m_splitterOrView->findSplitter(splitterOrView);
Q_ASSERT(splitterOrView->hasUAVGadgets() == false); Q_ASSERT(splitterOrView->hasUAVGadget() == false);
Q_ASSERT(splitter->isSplitter() == true);
splitterOrView->hide(); splitterOrView->hide();
delete splitterOrView; delete splitterOrView;
splitter->unsplit(); splitter->unsplit();
SplitterOrView *newCurrent = splitter->findFirstView(); SplitterOrView *newCurrent = splitter->findFirstView();
if (newCurrent) { Q_ASSERT(newCurrent);
if (newCurrent->uavGadget()) if (newCurrent)
activateUAVGadget(newCurrent->view(), newCurrent->uavGadget()); setCurrentUAVGadget(newCurrent->uavGadget());
else updateActions();
setCurrentView(newCurrent);
}
}
bool UAVGadgetManager::closeAllUAVGadgets()
{
// if (closeUAVGadgets(openedUAVGadgets())) {
// m_d->clearNavigationHistory();
// return true;
// }
return true;
}
// SLOT connected to action
// since this is potentially called in the event handler of the uavGadget
// we simply postpone it with a single shot timer
void UAVGadgetManager::closeUAVGadget()
{
//qDebug() << Q_FUNC_INFO;
closeUAVGadget(m_d->m_currentUAVGadget);
}
void UAVGadgetManager::closeUAVGadget(Core::IUAVGadget *uavGadget)
{
//qDebug() << Q_FUNC_INFO;
if (!uavGadget)
return;
closeUAVGadgets(QList<IUAVGadget *>() << uavGadget);
}
bool UAVGadgetManager::closeUAVGadgets(const QList<IUAVGadget*> uavGadgetsToClose)
{
//qDebug() << Q_FUNC_INFO;
if (uavGadgetsToClose.isEmpty())
return true;
SplitterOrView *currentSplitterOrView = this->currentSplitterOrView();
QList<UAVGadgetView*> closedViews;
// remove the uavGadgets
foreach (IUAVGadget *uavGadget, uavGadgetsToClose) {
// emit uavGadgetAboutToClose(uavGadget);
removeUAVGadget(uavGadget);
if (SplitterOrView *view = m_d->m_splitterOrView->findView(uavGadget)) {
if (uavGadget == view->view()->currentUAVGadget())
closedViews += view->view();
view->view()->removeUAVGadget();
}
}
// emit uavGadgetsClosed(acceptedUAVGadgets);
foreach (IUAVGadget *uavGadget, uavGadgetsToClose) {
delete uavGadget;
}
if (currentSplitterOrView) {
if (IUAVGadget *uavGadget = currentSplitterOrView->uavGadget())
activateUAVGadget(currentSplitterOrView->view(), uavGadget);
}
if (!currentUAVGadget()) {}
// emit currentUAVGadgetChanged(0);
return true;
}
Core::IUAVGadget *UAVGadgetManager::pickUnusedUAVGadget() const
{
//qDebug() << Q_FUNC_INFO;
//TODO
// foreach (IUAVGadget *uavGadget, openedUAVGadgets()) {
// SplitterOrView *view = m_d->m_splitterOrView->findView(uavGadget);
// if (!view || view->uavGadget() != uavGadget)
// return uavGadget;
// }
return 0;
}
Core::IUAVGadget *UAVGadgetManager::placeUAVGadget(Core::Internal::UAVGadgetView *view, Core::IUAVGadget *uavGadget)
{
//qDebug() << Q_FUNC_INFO;
Q_ASSERT(view && uavGadget);
if (view->currentUAVGadget())
uavGadget = view->currentUAVGadget();
if (!view->hasUAVGadget(uavGadget)) {
if (SplitterOrView *sourceView = m_d->m_splitterOrView->findView(uavGadget)) {
sourceView->view()->removeUAVGadget();
view->setCurrentUAVGadget(uavGadget);
if (!sourceView->uavGadget()) {
if (IUAVGadget *replacement = pickUnusedUAVGadget()) {
sourceView->view()->setCurrentUAVGadget(replacement);
}
}
return uavGadget;
}
view->setCurrentUAVGadget(uavGadget);
}
return uavGadget;
}
Core::IUAVGadget *UAVGadgetManager::activateUAVGadget(Core::IUAVGadget *uavGadget)
{
//qDebug() << Q_FUNC_INFO;
return activateUAVGadget(0, uavGadget);
}
Core::IUAVGadget *UAVGadgetManager::activateUAVGadget(Core::Internal::UAVGadgetView *view, Core::IUAVGadget *uavGadget)
{
//qDebug() << Q_FUNC_INFO;
if (!view)
view = currentUAVGadgetView();
Q_ASSERT(view);
if (!uavGadget) {
if (!m_d->m_currentUAVGadget)
setCurrentUAVGadget(0);
return 0;
}
uavGadget = placeUAVGadget(view, uavGadget);
/* if (!(flags & NoActivate)) {
setCurrentUAVGadget(uavGadget);
if (!(flags & NoModeSwitch))
ensureUAVGadgetManagerVisible();
if (isVisible())
uavGadget->widget()->setFocus();
}*/
return uavGadget;
}
UAVGadgetManager::UAVGadgetFactoryList
UAVGadgetManager::uavGadgetFactories() const
{
//qDebug() << Q_FUNC_INFO;
UAVGadgetFactoryList rc = pluginManager()->getObjects<IUAVGadgetFactory>();
//if (debugUAVGadgetManager)
//qDebug() << Q_FUNC_INFO << rc;
return rc;
}
IUAVGadget *UAVGadgetManager::createUAVGadget(const QString &uavGadgetKind)
{
//qDebug() << Q_FUNC_INFO;
if (debugUAVGadgetManager)
qDebug() << Q_FUNC_INFO << uavGadgetKind;
UAVGadgetFactoryList factories = uavGadgetFactories();
IUAVGadgetFactory *factory = 0;
foreach(IUAVGadgetFactory *f, factories) {
if (f->name() == uavGadgetKind) {
factory = f;
break;
}
}
if (!factory) {
qWarning("%s: unable to find an uavGadget factory for the uavGadget kind '%s'.",
Q_FUNC_INFO, uavGadgetKind.toUtf8().constData());
return 0;
}
IUAVGadget *uavGadget = factory->createUAVGadget(this);
// if (uavGadget)
// connect(uavGadget, SIGNAL(changed()), this, SLOT(updateActions()));
// if (uavGadget)
// emit uavGadgetCreated(uavGadget, fileName);
return uavGadget;
} }
void UAVGadgetManager::addUAVGadget(IUAVGadget *uavGadget) void UAVGadgetManager::addUAVGadget(IUAVGadget *uavGadget)
{ {
//qDebug() << Q_FUNC_INFO;
if (!uavGadget) if (!uavGadget)
return; return;
m_d->m_core->addContextObject(uavGadget); m_d->m_core->addContextObject(uavGadget);
@ -624,16 +392,23 @@ void UAVGadgetManager::addUAVGadget(IUAVGadget *uavGadget)
// emit uavGadgetOpened(uavGadget); // emit uavGadgetOpened(uavGadget);
} }
void UAVGadgetManager::removeUAVGadget(IUAVGadget *uavGadget)
{
if (!uavGadget)
return;
m_d->m_core->removeContextObject(qobject_cast<IContext*>(uavGadget));
}
void UAVGadgetManager::ensureUAVGadgetManagerVisible() void UAVGadgetManager::ensureUAVGadgetManagerVisible()
{ {
//qDebug() << Q_FUNC_INFO;
if (!isVisible()) if (!isVisible())
m_d->m_core->modeManager()->activateMode(m_uavGadgetMode->uniqueModeName()); m_d->m_core->modeManager()->activateMode(m_uavGadgetMode->uniqueModeName());
} }
void UAVGadgetManager::updateActions() void UAVGadgetManager::updateActions()
{ {
//qDebug() << Q_FUNC_INFO; if (!m_d->m_splitterOrView) // this is only for startup
return;
// Splitting is only possible when the toolbars are shown // Splitting is only possible when the toolbars are shown
bool hidden = m_d->m_hideToolbarsAction->isChecked(); bool hidden = m_d->m_hideToolbarsAction->isChecked();
bool hasSplitter = m_d->m_splitterOrView->isSplitter(); bool hasSplitter = m_d->m_splitterOrView->isSplitter();
@ -642,6 +417,14 @@ void UAVGadgetManager::updateActions()
m_d->m_gotoOtherSplitAction->setEnabled(!hidden && hasSplitter); m_d->m_gotoOtherSplitAction->setEnabled(!hidden && hasSplitter);
} }
UAVGadgetFactoryList UAVGadgetManager::uavGadgetFactories() const
{
UAVGadgetFactoryList rc = pluginManager()->getObjects<Core::IUAVGadgetFactory>();
//if (debugUAVGadgetManager)
//qDebug() << Q_FUNC_INFO << rc;
return rc;
}
QByteArray UAVGadgetManager::saveState() const QByteArray UAVGadgetManager::saveState() const
{ {
QByteArray bytes; QByteArray bytes;
@ -768,28 +551,26 @@ void UAVGadgetManager::split(Qt::Orientation orientation)
{ {
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode) if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
return; return;
//qDebug() << Q_FUNC_INFO;
SplitterOrView *view = m_d->m_currentView; IUAVGadget *uavGadget = m_d->m_currentUAVGadget;
// //qDebug() << Q_FUNC_INFO << view << m_d->m_currentUAVGadget; Q_ASSERT(uavGadget);
if (!view) SplitterOrView *view = currentSplitterOrView();
view = m_d->m_currentUAVGadget ? m_d->m_splitterOrView->findView(m_d->m_currentUAVGadget) Q_ASSERT(view);
: m_d->m_splitterOrView->findFirstView(); view->split(orientation);
//qDebug() << Q_FUNC_INFO << view << m_d->m_currentUAVGadget << view->splitter();
if (view && !view->splitter()) { SplitterOrView *sor = m_d->m_splitterOrView->findView(uavGadget);
view->split(orientation); SplitterOrView *next = m_d->m_splitterOrView->findNextView(sor);
} setCurrentUAVGadget(next->uavGadget());
updateActions(); updateActions();
} }
void UAVGadgetManager::split() void UAVGadgetManager::split()
{ {
//qDebug() << Q_FUNC_INFO;
split(Qt::Vertical); split(Qt::Vertical);
} }
void UAVGadgetManager::splitSideBySide() void UAVGadgetManager::splitSideBySide()
{ {
//qDebug() << Q_FUNC_INFO;
split(Qt::Horizontal); split(Qt::Horizontal);
} }
@ -797,14 +578,10 @@ void UAVGadgetManager::removeCurrentSplit()
{ {
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode) if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
return; return;
//qDebug() << Q_FUNC_INFO;
SplitterOrView *viewToClose = m_d->m_currentView;
if (!viewToClose && m_d->m_currentUAVGadget)
viewToClose = m_d->m_splitterOrView->findView(m_d->m_currentUAVGadget);
if (!viewToClose || viewToClose->isSplitter() || viewToClose == m_d->m_splitterOrView) SplitterOrView *viewToClose = currentSplitterOrView();
if (viewToClose == m_d->m_splitterOrView)
return; return;
closeView(viewToClose->view()); closeView(viewToClose->view());
updateActions(); updateActions();
} }
@ -813,36 +590,28 @@ void UAVGadgetManager::removeAllSplits()
{ {
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode) if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
return; return;
if (!m_d->m_splitterOrView->isSplitter()) if (!m_d->m_splitterOrView->isSplitter())
return; return;
IUAVGadget *uavGadget = m_d->m_currentUAVGadget; IUAVGadget *uavGadget = m_d->m_currentUAVGadget;
m_d->m_currentUAVGadget = 0; // trigger update below m_d->m_currentUAVGadget = 0; // trigger update below
m_d->m_splitterOrView->unsplitAll(); m_d->m_splitterOrView->unsplitAll();
if (!uavGadget) m_d->m_splitterOrView->view()->setUAVGadget(uavGadget);
uavGadget = pickUnusedUAVGadget(); setCurrentUAVGadget(uavGadget);
activateUAVGadget(uavGadget);
} }
void UAVGadgetManager::gotoOtherSplit() void UAVGadgetManager::gotoOtherSplit()
{ {
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode) if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
return; return;
if (m_d->m_splitterOrView->isSplitter()) { if (m_d->m_splitterOrView->isSplitter()) {
SplitterOrView *currentView = m_d->m_currentView; SplitterOrView *currentView = currentSplitterOrView();
if (!currentView && m_d->m_currentUAVGadget)
currentView = m_d->m_splitterOrView->findView(m_d->m_currentUAVGadget);
if (!currentView)
currentView = m_d->m_splitterOrView->findFirstView();
SplitterOrView *view = m_d->m_splitterOrView->findNextView(currentView); SplitterOrView *view = m_d->m_splitterOrView->findNextView(currentView);
if (!view) if (!view)
view = m_d->m_splitterOrView->findFirstView(); view = m_d->m_splitterOrView->findFirstView();
if (view) { if (view) {
if (IUAVGadget *uavGadget = view->uavGadget()) { setCurrentUAVGadget(view->uavGadget());
setCurrentUAVGadget(uavGadget);
uavGadget->widget()->setFocus();
} else {
setCurrentView(view);
}
} }
} }
} }
@ -850,33 +619,21 @@ void UAVGadgetManager::gotoOtherSplit()
void UAVGadgetManager::hideToolbars(bool hide) void UAVGadgetManager::hideToolbars(bool hide)
{ {
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode) if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
return; return;
m_d->m_hideToolbarsAction->setChecked(hide); m_d->m_hideToolbarsAction->setChecked(hide);
m_hidden = hide; m_hidden = hide;
//qDebug() << Q_FUNC_INFO; SplitterOrView *next = m_d->m_splitterOrView->findFirstView();
QList<SplitterOrView*> views; do {
SplitterOrView *next = m_d->m_splitterOrView->findFirstView(); next->view()->hideToolbar(hide);
//qDebug() << Q_FUNC_INFO << next->m_isRoot; next = m_d->m_splitterOrView->findNextView(next);
do { } while (next);
views.append(next);
next = m_d->m_splitterOrView->findNextView(next);
} while(next);
foreach(SplitterOrView *s, views)
{
// //qDebug() << Q_FUNC_INFO << s;
s->view()->hideToolbar(hide);
}
m_d->m_splitAction->setEnabled(!hide); m_d->m_splitAction->setEnabled(!hide);
m_d->m_splitSideBySideAction->setEnabled(!hide); m_d->m_splitSideBySideAction->setEnabled(!hide);
m_d->m_removeCurrentSplitAction->setEnabled(!hide); m_d->m_removeCurrentSplitAction->setEnabled(!hide);
m_d->m_removeAllSplitsAction->setEnabled(!hide); m_d->m_removeAllSplitsAction->setEnabled(!hide);
m_d->m_gotoOtherSplitAction->setEnabled(!hide); m_d->m_gotoOtherSplitAction->setEnabled(!hide);
// m_d->m_splitAction->setVisible(!hide);
// m_d->m_splitSideBySideAction->setVisible(!hide);
// m_d->m_removeCurrentSplitAction->setVisible(!hide);
// m_d->m_removeAllSplitsAction->setVisible(!hide);
// m_d->m_gotoOtherSplitAction->setVisible(!hide);
} }
//===================UAVGadgetClosingCoreListener====================== //===================UAVGadgetClosingCoreListener======================
@ -889,5 +646,5 @@ bool UAVGadgetClosingCoreListener::coreAboutToClose()
{ {
// Do not ask for files to save. // Do not ask for files to save.
// MainWindow::closeEvent has already done that. // MainWindow::closeEvent has already done that.
return m_em->closeAllUAVGadgets(); return true;
} }

View File

@ -78,12 +78,14 @@ private:
UAVGadgetManagerPlaceHolder* m_current; UAVGadgetManagerPlaceHolder* m_current;
}; };
typedef QList<IUAVGadgetFactory*> UAVGadgetFactoryList;
class CORE_EXPORT UAVGadgetManager : public QWidget class CORE_EXPORT UAVGadgetManager : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
typedef QList<IUAVGadgetFactory*> UAVGadgetFactoryList;
explicit UAVGadgetManager(ICore *core, QWidget *parent); explicit UAVGadgetManager(ICore *core, QWidget *parent);
virtual ~UAVGadgetManager(); virtual ~UAVGadgetManager();
@ -95,9 +97,6 @@ public:
void ensureUAVGadgetManagerVisible(); void ensureUAVGadgetManagerVisible();
IUAVGadget *currentUAVGadget() const; IUAVGadget *currentUAVGadget() const;
IUAVGadget *activateUAVGadget(IUAVGadget *gadget);
bool closeUAVGadgets(const QList<IUAVGadget *> uavGadgetsToClose);
QByteArray saveState() const; QByteArray saveState() const;
bool restoreState(const QByteArray &state); bool restoreState(const QByteArray &state);
@ -110,11 +109,6 @@ public:
signals: signals:
public slots:
bool closeAllUAVGadgets();
void closeUAVGadget();
private slots: private slots:
void handleContextChange(Core::IContext *context); void handleContextChange(Core::IContext *context);
void updateActions(); void updateActions();
@ -130,25 +124,15 @@ public slots:
private: private:
void addUAVGadget(IUAVGadget *gadget); void addUAVGadget(IUAVGadget *gadget);
IUAVGadget *createUAVGadget(const QString &uavGadgetKind = QString());
void removeUAVGadget(IUAVGadget *gadget); void removeUAVGadget(IUAVGadget *gadget);
IUAVGadget *placeUAVGadget(Core::Internal::UAVGadgetView *view, Core::IUAVGadget *gadget);
void setCurrentUAVGadget(IUAVGadget *gadget); void setCurrentUAVGadget(IUAVGadget *gadget);
void setCurrentView(Core::Internal::SplitterOrView *view);
IUAVGadget *activateUAVGadget(Core::Internal::UAVGadgetView *view, Core::IUAVGadget *gadget);
Core::Internal::SplitterOrView *currentSplitterOrView() const;
void closeUAVGadget(Core::IUAVGadget *gadget);
void closeView(Core::Internal::UAVGadgetView *view); void closeView(Core::Internal::UAVGadgetView *view);
void emptyView(Core::Internal::UAVGadgetView *view); void emptyView(Core::Internal::UAVGadgetView *view);
Core::Internal::UAVGadgetView *currentUAVGadgetView() const; Core::Internal::SplitterOrView *currentSplitterOrView() const;
IUAVGadget *pickUnusedUAVGadget() const;
bool m_hidden;
UAVGadgetManagerPrivate *m_d; UAVGadgetManagerPrivate *m_d;
Core::Internal::UAVGadgetMode *m_uavGadgetMode; Core::Internal::UAVGadgetMode *m_uavGadgetMode;
bool m_hidden;
friend class Core::Internal::SplitterOrView; friend class Core::Internal::SplitterOrView;
friend class Core::Internal::UAVGadgetView; friend class Core::Internal::UAVGadgetView;

View File

@ -28,6 +28,7 @@
#include "uavgadgetview.h" #include "uavgadgetview.h"
#include "uavgadgetmanager.h" #include "uavgadgetmanager.h"
#include "iuavgadgetfactory.h"
#include "iuavgadget.h" #include "iuavgadget.h"
#include "coreimpl.h" #include "coreimpl.h"
#include "minisplitter.h" #include "minisplitter.h"
@ -60,7 +61,6 @@ Q_DECLARE_METATYPE(Core::IUAVGadget *)
using namespace Core; using namespace Core;
using namespace Core::Internal; using namespace Core::Internal;
// ================UAVGadgetView==================== // ================UAVGadgetView====================
UAVGadgetView::UAVGadgetView(UAVGadgetManager *uavGadgetManager, IUAVGadget *uavGadget, QWidget *parent) : UAVGadgetView::UAVGadgetView(UAVGadgetManager *uavGadgetManager, IUAVGadget *uavGadget, QWidget *parent) :
@ -70,20 +70,27 @@ UAVGadgetView::UAVGadgetView(UAVGadgetManager *uavGadgetManager, IUAVGadget *uav
m_toolBar(new QWidget), m_toolBar(new QWidget),
m_defaultToolBar(new QWidget(this)), m_defaultToolBar(new QWidget(this)),
m_uavGadgetList(new QComboBox), m_uavGadgetList(new QComboBox),
m_closeButton(new QToolButton) m_closeButton(new QToolButton),
m_defaultIndex(0)
{ {
//qDebug() << Q_FUNC_INFO;
tl = new QVBoxLayout(this); tl = new QVBoxLayout(this);
tl->setSpacing(0); tl->setSpacing(0);
tl->setMargin(0); tl->setMargin(0);
{ {
m_uavGadgetList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); m_uavGadgetList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_uavGadgetList->setMinimumContentsLength(20); m_uavGadgetList->setMinimumContentsLength(20);
// m_uavGadgetList->setModel(m_model);
m_uavGadgetList->setMaxVisibleItems(40); m_uavGadgetList->setMaxVisibleItems(40);
m_uavGadgetList->setContextMenuPolicy(Qt::CustomContextMenu); m_uavGadgetList->setContextMenuPolicy(Qt::CustomContextMenu);
UAVGadgetFactoryList fl = m_uavGadgetManager->uavGadgetFactories();
int index = 0;
foreach(Core::IUAVGadgetFactory *factory, fl)
{
m_uavGadgetList->addItem(factory->name());
if (factory->name() == QString("EmptyGadget"))
m_defaultIndex = index;
++index;
}
m_defaultToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); m_defaultToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_activeToolBar = m_defaultToolBar; m_activeToolBar = m_defaultToolBar;
@ -112,16 +119,11 @@ UAVGadgetView::UAVGadgetView(UAVGadgetManager *uavGadgetManager, IUAVGadget *uav
connect(m_uavGadgetList, SIGNAL(activated(int)), this, SLOT(listSelectionActivated(int))); connect(m_uavGadgetList, SIGNAL(activated(int)), this, SLOT(listSelectionActivated(int)));
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeView()), Qt::QueuedConnection); connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeView()), Qt::QueuedConnection);
} }
setCurrentUAVGadget(m_uavGadget); if (m_uavGadget) {
setUAVGadget(m_uavGadget);
// //qDebug() << Q_FUNC_INFO << uavGadget; } else {
ActionManager *am = ICore::instance()->actionManager(); listSelectionActivated(m_defaultIndex);
// //qDebug() << Q_FUNC_INFO << uavGadget << am; }
// connect(am->command(Constants::CLOSE), SIGNAL(keySequenceChanged()),
// this, SLOT(updateActionShortcuts()));
updateActionShortcuts();
// updateActions();
} }
UAVGadgetView::~UAVGadgetView() UAVGadgetView::~UAVGadgetView()
@ -140,24 +142,16 @@ void UAVGadgetView::hideToolbar(bool hide)
void UAVGadgetView::closeView() void UAVGadgetView::closeView()
{ {
// m_top->hide();
m_uavGadgetManager->closeView(this); m_uavGadgetManager->closeView(this);
//qDebug() << Q_FUNC_INFO;
/* removeUAVGadget();
if (m_uavGadget)
delete m_uavGadget;
m_uavGadget = 0;*/
} }
void UAVGadgetView::removeUAVGadget() void UAVGadgetView::removeUAVGadget()
{ {
//qDebug() << Q_FUNC_INFO;
if (!m_uavGadget) if (!m_uavGadget)
return; return;
tl->removeWidget(m_uavGadget->widget()); tl->removeWidget(m_uavGadget->widget());
m_uavGadget->widget()->setParent(0); m_uavGadget->widget()->setParent(0);
// disconnect(m_uavGadget, SIGNAL(changed()), this, SLOT(checkUAVGadgetStatus()));
QWidget *toolBar = m_uavGadget->toolBar(); QWidget *toolBar = m_uavGadget->toolBar();
if (toolBar != 0) { if (toolBar != 0) {
if (m_activeToolBar == toolBar) { if (m_activeToolBar == toolBar) {
@ -168,39 +162,31 @@ void UAVGadgetView::removeUAVGadget()
toolBar->setVisible(false); toolBar->setVisible(false);
toolBar->setParent(0); toolBar->setParent(0);
} }
setCurrentUAVGadget(0); m_uavGadget = 0;
} }
IUAVGadget *UAVGadgetView::currentUAVGadget() const IUAVGadget *UAVGadgetView::uavGadget() const
{ {
//qDebug() << Q_FUNC_INFO;
return m_uavGadget; return m_uavGadget;
} }
void UAVGadgetView::setCurrentUAVGadget(IUAVGadget *uavGadget) void UAVGadgetView::setUAVGadget(IUAVGadget *uavGadget)
{ {
//qDebug() << Q_FUNC_INFO;
if (!uavGadget) { if (!uavGadget) {
QString s = "This view is empty. ";
QLabel *label = new QLabel(s);
label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
// label->setFrameStyle(QFrame::Plain | QFrame::Box);
// label->setLineWidth(3);
m_uavGadgetList->addItem(QString("UAVGadget1"));
m_uavGadgetList->addItem(QString("UAVGadget2"));
m_uavGadgetList->addItem(QString("UAVGadget3"));
tl->addWidget(label);
// ### TODO the combo box m_uavGadgetList should show an empty item
return; return;
} }
removeUAVGadget();
m_uavGadget = uavGadget;
tl->addWidget(m_uavGadget->widget());
m_uavGadget->widget()->setParent(this);
m_uavGadget->widget()->show();
m_uavGadgetList->setCurrentIndex(m_uavGadget->index());
// m_uavGadgetList->setCurrentIndex(m_model->indexOf(uavGadget).row()); // updateToolBar();
updateToolBar();
} }
void UAVGadgetView::updateToolBar() void UAVGadgetView::updateToolBar()
{ {
//qDebug() << Q_FUNC_INFO;
if (!m_uavGadget) if (!m_uavGadget)
return; return;
QWidget *toolBar = m_uavGadget->toolBar(); QWidget *toolBar = m_uavGadget->toolBar();
@ -215,30 +201,21 @@ void UAVGadgetView::updateToolBar()
void UAVGadgetView::listSelectionActivated(int index) void UAVGadgetView::listSelectionActivated(int index)
{ {
//qDebug() << Q_FUNC_INFO; if (m_uavGadget && m_uavGadget->index() == index)
// UAVGadgetManager *em = CoreImpl::instance()->uavGadgetManager(); return;
/* QAbstractItemModel *model = m_uavGadgetList->model(); if (m_uavGadgetManager->uavGadgetFactories().count() == 0)
if (IUAVGadget *uavGadget = model->data(model->index(index, 0), Qt::UserRole).value<IUAVGadget*>()) { return;
em->activateUAVGadget(this, uavGadget); IUAVGadgetFactory *factory = m_uavGadgetManager->uavGadgetFactories().at(index);
} else { IUAVGadget *gadget = factory->createUAVGadget(this);
em->activateUAVGadget(model->index(index, 0), this); gadget->setIndex(index);
}*/ setUAVGadget(gadget);
m_uavGadgetManager->setCurrentUAVGadget(gadget);
} }
void UAVGadgetView::updateActionShortcuts()
{
//qDebug() << Q_FUNC_INFO;
// ActionManager *am = ICore::instance()->actionManager();
// m_closeButton->setToolTip(am->command(Constants::CLOSE)->stringWithAppendedShortcut(UAVGadgetManager::tr("Close")));
}
SplitterOrView::SplitterOrView(UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget, bool isRoot) : SplitterOrView::SplitterOrView(UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget, bool isRoot) :
m_uavGadgetManager(uavGadgetManager), m_uavGadgetManager(uavGadgetManager),
m_isRoot(isRoot) m_isRoot(isRoot)
{ {
//qDebug() << Q_FUNC_INFO << uavGadget << isRoot;
// //qDebug() << Q_FUNC_INFO << uavGadget << isRoot;
m_view = new UAVGadgetView(m_uavGadgetManager, uavGadget); m_view = new UAVGadgetView(m_uavGadgetManager, uavGadget);
m_layout = new QStackedLayout(this); m_layout = new QStackedLayout(this);
m_splitter = 0; m_splitter = 0;
@ -255,20 +232,26 @@ SplitterOrView::~SplitterOrView()
void SplitterOrView::mousePressEvent(QMouseEvent *e) void SplitterOrView::mousePressEvent(QMouseEvent *e)
{ {
//qDebug() << Q_FUNC_INFO;
if (e->button() != Qt::LeftButton) if (e->button() != Qt::LeftButton)
return; return;
setFocus(Qt::MouseFocusReason); if (uavGadget()) {
m_uavGadgetManager->setCurrentView(this); setFocus(Qt::MouseFocusReason);
m_uavGadgetManager->setCurrentUAVGadget(this->uavGadget());
}
} }
void SplitterOrView::paintEvent(QPaintEvent *) void SplitterOrView::paintEvent(QPaintEvent *event)
{ {
// //qDebug() << Q_FUNC_INFO;
if (m_uavGadgetManager->currentSplitterOrView() != this) if (m_uavGadgetManager->currentSplitterOrView() != this)
return; return;
if (!m_view || hasUAVGadgets()) if (!m_view)
return;
// if (hasUAVGadget())
// return;
if (m_uavGadgetManager->toolbarsHidden())
return; return;
// Discreet indication where an uavGadget would be if there is none // Discreet indication where an uavGadget would be if there is none
@ -276,7 +259,7 @@ void SplitterOrView::paintEvent(QPaintEvent *)
painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(Qt::NoPen); painter.setPen(Qt::NoPen);
QColor shadeBrush(Qt::black); QColor shadeBrush(Qt::black);
shadeBrush.setAlpha(10); shadeBrush.setAlpha(25);
painter.setBrush(shadeBrush); painter.setBrush(shadeBrush);
const int r = 3; const int r = 3;
painter.drawRoundedRect(rect().adjusted(r, r, -r, -r), r * 2, r * 2); painter.drawRoundedRect(rect().adjusted(r, r, -r, -r), r * 2, r * 2);
@ -308,9 +291,11 @@ void SplitterOrView::paintEvent(QPaintEvent *)
#endif #endif
} }
/* Contract: return SplitterOrView that is not splitter, or 0 if not found.
* Implications: must not return SplitterOrView that is splitter.
*/
SplitterOrView *SplitterOrView::findFirstView() SplitterOrView *SplitterOrView::findFirstView()
{ {
//qDebug() << Q_FUNC_INFO;
if (m_splitter) { if (m_splitter) {
for (int i = 0; i < m_splitter->count(); ++i) { for (int i = 0; i < m_splitter->count(); ++i) {
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i)))
@ -322,25 +307,11 @@ SplitterOrView *SplitterOrView::findFirstView()
return this; return this;
} }
SplitterOrView *SplitterOrView::findEmptyView() /* Contract: return SplitterOrView that has 'uavGadget', or 0 if not found.
{ * Implications: must not return SplitterOrView that is splitter.
//qDebug() << Q_FUNC_INFO; */
if (m_splitter) {
for (int i = 0; i < m_splitter->count(); ++i) {
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i)))
if (SplitterOrView *result = splitterOrView->findEmptyView())
return result;
}
return 0;
}
if (!hasUAVGadgets())
return this;
return 0;
}
SplitterOrView *SplitterOrView::findView(Core::IUAVGadget *uavGadget) SplitterOrView *SplitterOrView::findView(Core::IUAVGadget *uavGadget)
{ {
//qDebug() << Q_FUNC_INFO;
if (!uavGadget || hasUAVGadget(uavGadget)) if (!uavGadget || hasUAVGadget(uavGadget))
return this; return this;
if (m_splitter) { if (m_splitter) {
@ -353,9 +324,11 @@ SplitterOrView *SplitterOrView::findView(Core::IUAVGadget *uavGadget)
return 0; return 0;
} }
/* Contract: return SplitterOrView that has 'view', or 0 if not found.
* Implications: must not return SplitterOrView that is splitter.
*/
SplitterOrView *SplitterOrView::findView(UAVGadgetView *view) SplitterOrView *SplitterOrView::findView(UAVGadgetView *view)
{ {
//qDebug() << Q_FUNC_INFO;
if (view == m_view) if (view == m_view)
return this; return this;
if (m_splitter) { if (m_splitter) {
@ -368,9 +341,12 @@ SplitterOrView *SplitterOrView::findView(UAVGadgetView *view)
return 0; return 0;
} }
/* Contract: return SplitterOrView that is splitter that has as child SplitterOrView containing 'uavGadget',
* or 0 if not found.
* Implications: must return SplitterOrView that is splitter.
*/
SplitterOrView *SplitterOrView::findSplitter(Core::IUAVGadget *uavGadget) SplitterOrView *SplitterOrView::findSplitter(Core::IUAVGadget *uavGadget)
{ {
//qDebug() << Q_FUNC_INFO;
if (m_splitter) { if (m_splitter) {
for (int i = 0; i < m_splitter->count(); ++i) { for (int i = 0; i < m_splitter->count(); ++i) {
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) { if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) {
@ -384,9 +360,12 @@ SplitterOrView *SplitterOrView::findSplitter(Core::IUAVGadget *uavGadget)
return 0; return 0;
} }
/* Contract: return SplitterOrView that is splitter that has as child SplitterOrView 'child',
* or 0 if not found.
* Implications: must return SplitterOrView that is splitter.
*/
SplitterOrView *SplitterOrView::findSplitter(SplitterOrView *child) SplitterOrView *SplitterOrView::findSplitter(SplitterOrView *child)
{ {
//qDebug() << Q_FUNC_INFO;
if (m_splitter) { if (m_splitter) {
for (int i = 0; i < m_splitter->count(); ++i) { for (int i = 0; i < m_splitter->count(); ++i) {
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) { if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) {
@ -400,16 +379,18 @@ SplitterOrView *SplitterOrView::findSplitter(SplitterOrView *child)
return 0; return 0;
} }
/* Contract: return SplitterOrView that follows SplitterOrView 'view' in tree structure,
* or 0 if not found.
* Implications: must not return SplitterOrView that is splitter.
*/
SplitterOrView *SplitterOrView::findNextView(SplitterOrView *view) SplitterOrView *SplitterOrView::findNextView(SplitterOrView *view)
{ {
//qDebug() << Q_FUNC_INFO;
bool found = false; bool found = false;
return findNextView_helper(view, &found); return findNextView_helper(view, &found);
} }
SplitterOrView *SplitterOrView::findNextView_helper(SplitterOrView *view, bool *found) SplitterOrView *SplitterOrView::findNextView_helper(SplitterOrView *view, bool *found)
{ {
//qDebug() << Q_FUNC_INFO;
if (*found && m_view) { if (*found && m_view) {
return this; return this;
} }
@ -432,7 +413,6 @@ SplitterOrView *SplitterOrView::findNextView_helper(SplitterOrView *view, bool *
QSize SplitterOrView::minimumSizeHint() const QSize SplitterOrView::minimumSizeHint() const
{ {
// //qDebug() << Q_FUNC_INFO;
if (m_splitter) if (m_splitter)
return m_splitter->minimumSizeHint(); return m_splitter->minimumSizeHint();
return QSize(64, 64); return QSize(64, 64);
@ -440,7 +420,6 @@ QSize SplitterOrView::minimumSizeHint() const
QSplitter *SplitterOrView::takeSplitter() QSplitter *SplitterOrView::takeSplitter()
{ {
//qDebug() << Q_FUNC_INFO;
QSplitter *oldSplitter = m_splitter; QSplitter *oldSplitter = m_splitter;
if (m_splitter) if (m_splitter)
m_layout->removeWidget(m_splitter); m_layout->removeWidget(m_splitter);
@ -450,7 +429,6 @@ QSplitter *SplitterOrView::takeSplitter()
UAVGadgetView *SplitterOrView::takeView() UAVGadgetView *SplitterOrView::takeView()
{ {
//qDebug() << Q_FUNC_INFO;
UAVGadgetView *oldView = m_view; UAVGadgetView *oldView = m_view;
if (m_view) if (m_view)
m_layout->removeWidget(m_view); m_layout->removeWidget(m_view);
@ -460,12 +438,11 @@ UAVGadgetView *SplitterOrView::takeView()
void SplitterOrView::split(Qt::Orientation orientation) void SplitterOrView::split(Qt::Orientation orientation)
{ {
//qDebug() << Q_FUNC_INFO;
Q_ASSERT(m_view && (m_splitter == 0)); Q_ASSERT(m_view && (m_splitter == 0));
m_splitter = new MiniSplitter(this); m_splitter = new MiniSplitter(this);
m_splitter->setOrientation(orientation); m_splitter->setOrientation(orientation);
m_layout->addWidget(m_splitter); m_layout->addWidget(m_splitter);
Core::IUAVGadget *e = m_view->currentUAVGadget(); Core::IUAVGadget *e = m_view->uavGadget();
SplitterOrView *view = 0; SplitterOrView *view = 0;
SplitterOrView *otherView = 0; SplitterOrView *otherView = 0;
@ -478,22 +455,17 @@ void SplitterOrView::split(Qt::Orientation orientation)
m_splitter->addWidget((view = new SplitterOrView(m_uavGadgetManager))); m_splitter->addWidget((view = new SplitterOrView(m_uavGadgetManager)));
} }
// QWidget *w = m_layout->currentWidget();
m_layout->setCurrentWidget(m_splitter); m_layout->setCurrentWidget(m_splitter);
// m_layout->removeWidget(w);
if (m_view && !m_isRoot) { if (m_view && !m_isRoot) {
m_uavGadgetManager->emptyView(m_view); m_uavGadgetManager->emptyView(m_view);
delete m_view; delete m_view;
m_view = 0; m_view = 0;
} }
m_uavGadgetManager->setCurrentView(view);
} }
void SplitterOrView::unsplitAll() void SplitterOrView::unsplitAll()
{ {
//qDebug() << Q_FUNC_INFO;
m_splitter->hide(); m_splitter->hide();
m_layout->removeWidget(m_splitter); // workaround Qt bug m_layout->removeWidget(m_splitter); // workaround Qt bug
unsplitAll_helper(); unsplitAll_helper();
@ -503,7 +475,6 @@ void SplitterOrView::unsplitAll()
void SplitterOrView::unsplitAll_helper() void SplitterOrView::unsplitAll_helper()
{ {
//qDebug() << Q_FUNC_INFO;
if (!m_isRoot && m_view) if (!m_isRoot && m_view)
m_uavGadgetManager->emptyView(m_view); m_uavGadgetManager->emptyView(m_view);
if (m_splitter) { if (m_splitter) {
@ -517,10 +488,8 @@ void SplitterOrView::unsplitAll_helper()
void SplitterOrView::unsplit() void SplitterOrView::unsplit()
{ {
//qDebug() << Q_FUNC_INFO;
if (!m_splitter) if (!m_splitter)
return; return;
Q_ASSERT(m_splitter->count() == 1); Q_ASSERT(m_splitter->count() == 1);
SplitterOrView *childSplitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(0)); SplitterOrView *childSplitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(0));
QSplitter *oldSplitter = m_splitter; QSplitter *oldSplitter = m_splitter;
@ -535,9 +504,9 @@ void SplitterOrView::unsplit()
UAVGadgetView *childView = childSplitterOrView->view(); UAVGadgetView *childView = childSplitterOrView->view();
Q_ASSERT(childView); Q_ASSERT(childView);
if (m_view) { if (m_view) {
if (IUAVGadget *e = childView->currentUAVGadget()) { if (IUAVGadget *e = childView->uavGadget()) {
childView->removeUAVGadget(); childView->removeUAVGadget();
m_view->setCurrentUAVGadget(e); m_view->setUAVGadget(e);
} }
m_uavGadgetManager->emptyView(childView); m_uavGadgetManager->emptyView(childView);
} else { } else {
@ -547,7 +516,7 @@ void SplitterOrView::unsplit()
m_layout->setCurrentWidget(m_view); m_layout->setCurrentWidget(m_view);
} }
delete oldSplitter; delete oldSplitter;
m_uavGadgetManager->setCurrentView(findFirstView()); m_uavGadgetManager->setCurrentUAVGadget(findFirstView()->uavGadget());
} }
@ -566,7 +535,7 @@ QByteArray SplitterOrView::saveState() const
// IUAVGadget* e = uavGadget(); // IUAVGadget* e = uavGadget();
// UAVGadgetManager *em = CoreImpl::instance()->uavGadgetManager(); // UAVGadgetManager *em = CoreImpl::instance()->uavGadgetManager();
// //
// if (e && e == em->currentUAVGadget()) { // if (e && e == em->uavGadget()) {
// stream << QByteArray("currentuavGadget") // stream << QByteArray("currentuavGadget")
// << e->file()->fileName() << e->kind() << e->saveState(); // << e->file()->fileName() << e->kind() << e->saveState();
// } else if (e) { // } else if (e) {
@ -611,7 +580,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
// if (e) { // if (e) {
// e->restoreState(uavGadgetState); // e->restoreState(uavGadgetState);
// if (mode == "currentuavGadget") // if (mode == "currentuavGadget")
// em->setCurrentUAVGadget(e); // em->setUAVGadget(e);
// } // }
// } // }
} }

View File

@ -67,13 +67,12 @@ public:
virtual ~UAVGadgetView(); virtual ~UAVGadgetView();
void removeUAVGadget(); void removeUAVGadget();
IUAVGadget *currentUAVGadget() const; IUAVGadget *uavGadget() const;
void setCurrentUAVGadget(IUAVGadget *uavGadget); void setUAVGadget(IUAVGadget *uavGadget);
bool hasUAVGadget(IUAVGadget *uavGadget) const; bool hasUAVGadget(IUAVGadget *uavGadget) const;
void hideToolbar(bool hide); void hideToolbar(bool hide);
public slots: public slots:
void updateActionShortcuts();
void closeView(); void closeView();
private slots: private slots:
@ -92,6 +91,7 @@ private:
QToolButton *m_closeButton; QToolButton *m_closeButton;
Utils::StyledBar *m_top; Utils::StyledBar *m_top;
QVBoxLayout *tl; // top layout QVBoxLayout *tl; // top layout
int m_defaultIndex;
}; };
class SplitterOrView : public QWidget class SplitterOrView : public QWidget
@ -108,9 +108,9 @@ public:
inline bool isRoot() const { return m_isRoot; } inline bool isRoot() const { return m_isRoot; }
inline bool isSplitter() const { return m_splitter != 0; } inline bool isSplitter() const { return m_splitter != 0; }
inline Core::IUAVGadget *uavGadget() const { return m_view ? m_view->currentUAVGadget() : 0; } inline Core::IUAVGadget *uavGadget() const { return m_view ? m_view->uavGadget() : 0; }
inline bool hasUAVGadget(Core::IUAVGadget *uavGadget) const { return m_view && m_view->hasUAVGadget(uavGadget); } inline bool hasUAVGadget(Core::IUAVGadget *uavGadget) const { return m_view && m_view->hasUAVGadget(uavGadget); }
inline bool hasUAVGadgets() const { return m_view && (m_view->currentUAVGadget() != 0); } inline bool hasUAVGadget() const { return m_view && (m_view->uavGadget() != 0); }
inline UAVGadgetView *view() const { return m_view; } inline UAVGadgetView *view() const { return m_view; }
inline QSplitter *splitter() const { return m_splitter; } inline QSplitter *splitter() const { return m_splitter; }
QSplitter *takeSplitter(); QSplitter *takeSplitter();
@ -122,7 +122,6 @@ public:
SplitterOrView *findView(Core::IUAVGadget *uavGadget); SplitterOrView *findView(Core::IUAVGadget *uavGadget);
SplitterOrView *findView(UAVGadgetView *view); SplitterOrView *findView(UAVGadgetView *view);
SplitterOrView *findFirstView(); SplitterOrView *findFirstView();
SplitterOrView *findEmptyView();
SplitterOrView *findSplitter(Core::IUAVGadget *uavGadget); SplitterOrView *findSplitter(Core::IUAVGadget *uavGadget);
SplitterOrView *findSplitter(SplitterOrView *child); SplitterOrView *findSplitter(SplitterOrView *child);