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:
parent
5b4fced510
commit
8137b68fbd
@ -82,8 +82,8 @@ static inline ExtensionSystem::PluginManager *pluginManager()
|
||||
|
||||
UAVGadgetManagerPlaceHolder::UAVGadgetManagerPlaceHolder(Core::Internal::UAVGadgetMode *mode, QWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_current(0),
|
||||
m_uavGadgetMode(mode)
|
||||
m_uavGadgetMode(mode),
|
||||
m_current(0)
|
||||
{
|
||||
m_mode = dynamic_cast<Core::IMode*>(mode);
|
||||
setLayout(new QVBoxLayout);
|
||||
@ -104,7 +104,6 @@ UAVGadgetManagerPlaceHolder::~UAVGadgetManagerPlaceHolder()
|
||||
|
||||
void UAVGadgetManagerPlaceHolder::currentModeChanged(Core::IMode *mode)
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << mode;
|
||||
UAVGadgetManager *gm = m_uavGadgetMode->uavGadgetManager();
|
||||
if (m_current == this) {
|
||||
m_current = 0;
|
||||
@ -119,11 +118,6 @@ void UAVGadgetManagerPlaceHolder::currentModeChanged(Core::IMode *mode)
|
||||
}
|
||||
}
|
||||
|
||||
//UAVGadgetManagerPlaceHolder* UAVGadgetManagerPlaceHolder::current()
|
||||
//{
|
||||
// return m_current;
|
||||
//}
|
||||
|
||||
// ---------------- UAVGadgetManager
|
||||
|
||||
namespace Core {
|
||||
@ -135,7 +129,6 @@ struct UAVGadgetManagerPrivate {
|
||||
Internal::UAVGadgetView *m_view;
|
||||
Internal::SplitterOrView *m_splitterOrView;
|
||||
QPointer<IUAVGadget> m_currentUAVGadget;
|
||||
QPointer<SplitterOrView> m_currentView;
|
||||
|
||||
ICore *m_core;
|
||||
|
||||
@ -175,13 +168,9 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
|
||||
m_hidden(false),
|
||||
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 *)),
|
||||
this, SLOT(handleContextChange(Core::IContext *)));
|
||||
// const QList<int> gc = QList<int>() << Constants::C_GLOBAL_ID;
|
||||
const QList<int> uavGadgetManagerContext =
|
||||
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->setCheckable(true);
|
||||
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);
|
||||
|
||||
//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)));
|
||||
|
||||
#ifdef Q_WS_MAC
|
||||
QString prefix = tr("Meta+E");
|
||||
QString prefix = tr("Meta+Shift");
|
||||
#else
|
||||
QString prefix = tr("Ctrl+E");
|
||||
QString prefix = tr("Ctrl+Shift");
|
||||
#endif
|
||||
|
||||
if (m_d->m_splitAction == 0)
|
||||
{
|
||||
m_d->m_splitAction = new QAction(tr("Split"), this);
|
||||
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);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
connect(m_d->m_splitSideBySideAction, SIGNAL(triggered()), this, SLOT(splitSideBySide()));
|
||||
|
||||
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->setDefaultKeySequence(QKeySequence(tr("%1,0").arg(prefix)));
|
||||
cmd->setDefaultKeySequence(QKeySequence(tr("%1+C").arg(prefix)));
|
||||
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
|
||||
}
|
||||
connect(m_d->m_removeCurrentSplitAction, SIGNAL(triggered()), this, SLOT(removeCurrentSplit()));
|
||||
|
||||
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->setDefaultKeySequence(QKeySequence(tr("%1,1").arg(prefix)));
|
||||
cmd->setDefaultKeySequence(QKeySequence(tr("%1+A").arg(prefix)));
|
||||
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
|
||||
}
|
||||
connect(m_d->m_removeAllSplitsAction, SIGNAL(triggered()), this, SLOT(removeAllSplits()));
|
||||
|
||||
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->setDefaultKeySequence(QKeySequence(tr("%1,o").arg(prefix)));
|
||||
cmd->setDefaultKeySequence(QKeySequence(tr("%1+N").arg(prefix)));
|
||||
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
|
||||
}
|
||||
connect(m_d->m_gotoOtherSplitAction, SIGNAL(triggered()), this, SLOT(gotoOtherSplit()));
|
||||
@ -273,6 +262,7 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
|
||||
// other setup
|
||||
m_d->m_splitterOrView = new SplitterOrView(this, 0, true);
|
||||
m_d->m_view = m_d->m_splitterOrView->view();
|
||||
setCurrentUAVGadget(m_d->m_view->uavGadget());
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
layout->setMargin(0);
|
||||
@ -296,7 +286,6 @@ UAVGadgetManager::~UAVGadgetManager()
|
||||
|
||||
void UAVGadgetManager::init()
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
QList<int> context;
|
||||
context << m_d->m_core->uniqueIDManager()->uniqueIdentifier("OpenPilot.UAVGadgetManager");
|
||||
|
||||
@ -305,20 +294,10 @@ void UAVGadgetManager::init()
|
||||
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)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (debugUAVGadgetManager)
|
||||
qDebug() << Q_FUNC_INFO << context;
|
||||
// if (debugUAVGadgetManager)
|
||||
// qDebug() << Q_FUNC_INFO << context;
|
||||
IUAVGadget *uavGadget = context ? qobject_cast<IUAVGadget*>(context) : 0;
|
||||
if (uavGadget) {
|
||||
setCurrentUAVGadget(uavGadget);
|
||||
@ -329,294 +308,83 @@ void UAVGadgetManager::handleContextChange(Core::IContext *context)
|
||||
|
||||
void UAVGadgetManager::setCurrentUAVGadget(IUAVGadget *uavGadget)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (uavGadget)
|
||||
setCurrentView(0);
|
||||
|
||||
if (m_d->m_currentUAVGadget == uavGadget)
|
||||
return;
|
||||
|
||||
SplitterOrView *oldView = currentSplitterOrView();
|
||||
m_d->m_currentUAVGadget = uavGadget;
|
||||
if (uavGadget) {
|
||||
if (SplitterOrView *splitterOrView = m_d->m_splitterOrView->findView(uavGadget))
|
||||
splitterOrView->view()->setCurrentUAVGadget(uavGadget);
|
||||
SplitterOrView *view = currentSplitterOrView();
|
||||
if (oldView != view) {
|
||||
if (oldView)
|
||||
oldView->update();
|
||||
if (view)
|
||||
view->update();
|
||||
}
|
||||
uavGadget->widget()->setFocus();
|
||||
updateActions();
|
||||
// emit currentUAVGadgetChanged(uavGadget);
|
||||
}
|
||||
|
||||
|
||||
void UAVGadgetManager::setCurrentView(Core::Internal::SplitterOrView *view)
|
||||
{
|
||||
//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();
|
||||
}
|
||||
|
||||
/* Contract: return current SplitterOrView.
|
||||
* Implications: must not return SplitterOrView that is splitter.
|
||||
*/
|
||||
Core::Internal::SplitterOrView *UAVGadgetManager::currentSplitterOrView() const
|
||||
{
|
||||
SplitterOrView *view = m_d->m_currentView;
|
||||
if (!view)
|
||||
view = m_d->m_currentUAVGadget?
|
||||
if (!m_d->m_splitterOrView) // this is only for startup
|
||||
return 0;
|
||||
SplitterOrView *view = m_d->m_currentUAVGadget ?
|
||||
m_d->m_splitterOrView->findView(m_d->m_currentUAVGadget) :
|
||||
m_d->m_splitterOrView->findFirstView();
|
||||
if (!view)
|
||||
return m_d->m_splitterOrView;
|
||||
0;
|
||||
return view;
|
||||
}
|
||||
|
||||
Core::Internal::UAVGadgetView *UAVGadgetManager::currentUAVGadgetView() const
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
return currentSplitterOrView()->view();
|
||||
}
|
||||
|
||||
IUAVGadget *UAVGadgetManager::currentUAVGadget() const
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
return m_d->m_currentUAVGadget;
|
||||
}
|
||||
|
||||
void UAVGadgetManager::emptyView(Core::Internal::UAVGadgetView *view)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO << view;
|
||||
if (!view)
|
||||
return;
|
||||
|
||||
IUAVGadget *uavGadget = view->currentUAVGadget();
|
||||
//qDebug() << Q_FUNC_INFO << view << uavGadget;
|
||||
IUAVGadget *uavGadget = view->uavGadget();
|
||||
// emit uavGadgetAboutToClose(uavGadget);
|
||||
removeUAVGadget(uavGadget);
|
||||
//qDebug() << Q_FUNC_INFO << view << uavGadget;
|
||||
view->removeUAVGadget();
|
||||
//qDebug() << Q_FUNC_INFO << view << uavGadget;
|
||||
|
||||
// emit uavGadgetsClosed(uavGadgets);
|
||||
if (uavGadget)
|
||||
delete uavGadget; // FIXME correct?
|
||||
}
|
||||
|
||||
|
||||
void UAVGadgetManager::closeView(Core::Internal::UAVGadgetView *view)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (!view)
|
||||
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);
|
||||
Q_ASSERT(splitterOrView);
|
||||
Q_ASSERT(splitterOrView->view() == view);
|
||||
if (splitterOrView == m_d->m_splitterOrView)
|
||||
return;
|
||||
|
||||
emptyView(view);
|
||||
|
||||
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();
|
||||
delete splitterOrView;
|
||||
|
||||
splitter->unsplit();
|
||||
|
||||
SplitterOrView *newCurrent = splitter->findFirstView();
|
||||
if (newCurrent) {
|
||||
if (newCurrent->uavGadget())
|
||||
activateUAVGadget(newCurrent->view(), newCurrent->uavGadget());
|
||||
else
|
||||
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;
|
||||
Q_ASSERT(newCurrent);
|
||||
if (newCurrent)
|
||||
setCurrentUAVGadget(newCurrent->uavGadget());
|
||||
updateActions();
|
||||
}
|
||||
|
||||
void UAVGadgetManager::addUAVGadget(IUAVGadget *uavGadget)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (!uavGadget)
|
||||
return;
|
||||
m_d->m_core->addContextObject(uavGadget);
|
||||
@ -624,16 +392,23 @@ void UAVGadgetManager::addUAVGadget(IUAVGadget *uavGadget)
|
||||
// emit uavGadgetOpened(uavGadget);
|
||||
}
|
||||
|
||||
void UAVGadgetManager::removeUAVGadget(IUAVGadget *uavGadget)
|
||||
{
|
||||
if (!uavGadget)
|
||||
return;
|
||||
m_d->m_core->removeContextObject(qobject_cast<IContext*>(uavGadget));
|
||||
}
|
||||
|
||||
void UAVGadgetManager::ensureUAVGadgetManagerVisible()
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (!isVisible())
|
||||
m_d->m_core->modeManager()->activateMode(m_uavGadgetMode->uniqueModeName());
|
||||
}
|
||||
|
||||
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
|
||||
bool hidden = m_d->m_hideToolbarsAction->isChecked();
|
||||
bool hasSplitter = m_d->m_splitterOrView->isSplitter();
|
||||
@ -642,6 +417,14 @@ void UAVGadgetManager::updateActions()
|
||||
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 bytes;
|
||||
@ -768,28 +551,26 @@ void UAVGadgetManager::split(Qt::Orientation orientation)
|
||||
{
|
||||
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
||||
return;
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
SplitterOrView *view = m_d->m_currentView;
|
||||
// //qDebug() << Q_FUNC_INFO << view << m_d->m_currentUAVGadget;
|
||||
if (!view)
|
||||
view = m_d->m_currentUAVGadget ? m_d->m_splitterOrView->findView(m_d->m_currentUAVGadget)
|
||||
: m_d->m_splitterOrView->findFirstView();
|
||||
//qDebug() << Q_FUNC_INFO << view << m_d->m_currentUAVGadget << view->splitter();
|
||||
if (view && !view->splitter()) {
|
||||
|
||||
IUAVGadget *uavGadget = m_d->m_currentUAVGadget;
|
||||
Q_ASSERT(uavGadget);
|
||||
SplitterOrView *view = currentSplitterOrView();
|
||||
Q_ASSERT(view);
|
||||
view->split(orientation);
|
||||
}
|
||||
|
||||
SplitterOrView *sor = m_d->m_splitterOrView->findView(uavGadget);
|
||||
SplitterOrView *next = m_d->m_splitterOrView->findNextView(sor);
|
||||
setCurrentUAVGadget(next->uavGadget());
|
||||
updateActions();
|
||||
}
|
||||
|
||||
void UAVGadgetManager::split()
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
split(Qt::Vertical);
|
||||
}
|
||||
|
||||
void UAVGadgetManager::splitSideBySide()
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
split(Qt::Horizontal);
|
||||
}
|
||||
|
||||
@ -797,14 +578,10 @@ void UAVGadgetManager::removeCurrentSplit()
|
||||
{
|
||||
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
||||
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;
|
||||
|
||||
closeView(viewToClose->view());
|
||||
updateActions();
|
||||
}
|
||||
@ -813,36 +590,28 @@ void UAVGadgetManager::removeAllSplits()
|
||||
{
|
||||
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
||||
return;
|
||||
|
||||
if (!m_d->m_splitterOrView->isSplitter())
|
||||
return;
|
||||
IUAVGadget *uavGadget = m_d->m_currentUAVGadget;
|
||||
m_d->m_currentUAVGadget = 0; // trigger update below
|
||||
m_d->m_splitterOrView->unsplitAll();
|
||||
if (!uavGadget)
|
||||
uavGadget = pickUnusedUAVGadget();
|
||||
activateUAVGadget(uavGadget);
|
||||
m_d->m_splitterOrView->view()->setUAVGadget(uavGadget);
|
||||
setCurrentUAVGadget(uavGadget);
|
||||
}
|
||||
|
||||
void UAVGadgetManager::gotoOtherSplit()
|
||||
{
|
||||
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
||||
return;
|
||||
|
||||
if (m_d->m_splitterOrView->isSplitter()) {
|
||||
SplitterOrView *currentView = m_d->m_currentView;
|
||||
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 *currentView = currentSplitterOrView();
|
||||
SplitterOrView *view = m_d->m_splitterOrView->findNextView(currentView);
|
||||
if (!view)
|
||||
view = m_d->m_splitterOrView->findFirstView();
|
||||
if (view) {
|
||||
if (IUAVGadget *uavGadget = view->uavGadget()) {
|
||||
setCurrentUAVGadget(uavGadget);
|
||||
uavGadget->widget()->setFocus();
|
||||
} else {
|
||||
setCurrentView(view);
|
||||
}
|
||||
setCurrentUAVGadget(view->uavGadget());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -851,32 +620,20 @@ void UAVGadgetManager::hideToolbars(bool hide)
|
||||
{
|
||||
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
||||
return;
|
||||
|
||||
m_d->m_hideToolbarsAction->setChecked(hide);
|
||||
m_hidden = hide;
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
QList<SplitterOrView*> views;
|
||||
SplitterOrView *next = m_d->m_splitterOrView->findFirstView();
|
||||
//qDebug() << Q_FUNC_INFO << next->m_isRoot;
|
||||
do {
|
||||
views.append(next);
|
||||
next->view()->hideToolbar(hide);
|
||||
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_splitSideBySideAction->setEnabled(!hide);
|
||||
m_d->m_removeCurrentSplitAction->setEnabled(!hide);
|
||||
m_d->m_removeAllSplitsAction->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======================
|
||||
|
||||
@ -889,5 +646,5 @@ bool UAVGadgetClosingCoreListener::coreAboutToClose()
|
||||
{
|
||||
// Do not ask for files to save.
|
||||
// MainWindow::closeEvent has already done that.
|
||||
return m_em->closeAllUAVGadgets();
|
||||
return true;
|
||||
}
|
||||
|
@ -78,12 +78,14 @@ private:
|
||||
UAVGadgetManagerPlaceHolder* m_current;
|
||||
};
|
||||
|
||||
typedef QList<IUAVGadgetFactory*> UAVGadgetFactoryList;
|
||||
|
||||
|
||||
class CORE_EXPORT UAVGadgetManager : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
typedef QList<IUAVGadgetFactory*> UAVGadgetFactoryList;
|
||||
|
||||
explicit UAVGadgetManager(ICore *core, QWidget *parent);
|
||||
virtual ~UAVGadgetManager();
|
||||
@ -95,9 +97,6 @@ public:
|
||||
void ensureUAVGadgetManagerVisible();
|
||||
|
||||
IUAVGadget *currentUAVGadget() const;
|
||||
IUAVGadget *activateUAVGadget(IUAVGadget *gadget);
|
||||
|
||||
bool closeUAVGadgets(const QList<IUAVGadget *> uavGadgetsToClose);
|
||||
|
||||
QByteArray saveState() const;
|
||||
bool restoreState(const QByteArray &state);
|
||||
@ -110,11 +109,6 @@ public:
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
bool closeAllUAVGadgets();
|
||||
|
||||
void closeUAVGadget();
|
||||
|
||||
private slots:
|
||||
void handleContextChange(Core::IContext *context);
|
||||
void updateActions();
|
||||
@ -130,25 +124,15 @@ public slots:
|
||||
|
||||
private:
|
||||
void addUAVGadget(IUAVGadget *gadget);
|
||||
IUAVGadget *createUAVGadget(const QString &uavGadgetKind = QString());
|
||||
void removeUAVGadget(IUAVGadget *gadget);
|
||||
|
||||
IUAVGadget *placeUAVGadget(Core::Internal::UAVGadgetView *view, Core::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 emptyView(Core::Internal::UAVGadgetView *view);
|
||||
Core::Internal::UAVGadgetView *currentUAVGadgetView() const;
|
||||
IUAVGadget *pickUnusedUAVGadget() const;
|
||||
Core::Internal::SplitterOrView *currentSplitterOrView() const;
|
||||
|
||||
bool m_hidden;
|
||||
UAVGadgetManagerPrivate *m_d;
|
||||
Core::Internal::UAVGadgetMode *m_uavGadgetMode;
|
||||
bool m_hidden;
|
||||
|
||||
friend class Core::Internal::SplitterOrView;
|
||||
friend class Core::Internal::UAVGadgetView;
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include "uavgadgetview.h"
|
||||
#include "uavgadgetmanager.h"
|
||||
#include "iuavgadgetfactory.h"
|
||||
#include "iuavgadget.h"
|
||||
#include "coreimpl.h"
|
||||
#include "minisplitter.h"
|
||||
@ -60,7 +61,6 @@ Q_DECLARE_METATYPE(Core::IUAVGadget *)
|
||||
using namespace Core;
|
||||
using namespace Core::Internal;
|
||||
|
||||
|
||||
// ================UAVGadgetView====================
|
||||
|
||||
UAVGadgetView::UAVGadgetView(UAVGadgetManager *uavGadgetManager, IUAVGadget *uavGadget, QWidget *parent) :
|
||||
@ -70,20 +70,27 @@ UAVGadgetView::UAVGadgetView(UAVGadgetManager *uavGadgetManager, IUAVGadget *uav
|
||||
m_toolBar(new QWidget),
|
||||
m_defaultToolBar(new QWidget(this)),
|
||||
m_uavGadgetList(new QComboBox),
|
||||
m_closeButton(new QToolButton)
|
||||
m_closeButton(new QToolButton),
|
||||
m_defaultIndex(0)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
|
||||
tl = new QVBoxLayout(this);
|
||||
tl->setSpacing(0);
|
||||
tl->setMargin(0);
|
||||
{
|
||||
|
||||
m_uavGadgetList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
m_uavGadgetList->setMinimumContentsLength(20);
|
||||
// m_uavGadgetList->setModel(m_model);
|
||||
m_uavGadgetList->setMaxVisibleItems(40);
|
||||
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_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_closeButton, SIGNAL(clicked()), this, SLOT(closeView()), Qt::QueuedConnection);
|
||||
}
|
||||
setCurrentUAVGadget(m_uavGadget);
|
||||
|
||||
// //qDebug() << Q_FUNC_INFO << uavGadget;
|
||||
ActionManager *am = ICore::instance()->actionManager();
|
||||
// //qDebug() << Q_FUNC_INFO << uavGadget << am;
|
||||
// connect(am->command(Constants::CLOSE), SIGNAL(keySequenceChanged()),
|
||||
// this, SLOT(updateActionShortcuts()));
|
||||
|
||||
updateActionShortcuts();
|
||||
// updateActions();
|
||||
if (m_uavGadget) {
|
||||
setUAVGadget(m_uavGadget);
|
||||
} else {
|
||||
listSelectionActivated(m_defaultIndex);
|
||||
}
|
||||
}
|
||||
|
||||
UAVGadgetView::~UAVGadgetView()
|
||||
@ -140,24 +142,16 @@ void UAVGadgetView::hideToolbar(bool hide)
|
||||
|
||||
void UAVGadgetView::closeView()
|
||||
{
|
||||
// m_top->hide();
|
||||
m_uavGadgetManager->closeView(this);
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
/* removeUAVGadget();
|
||||
if (m_uavGadget)
|
||||
delete m_uavGadget;
|
||||
m_uavGadget = 0;*/
|
||||
}
|
||||
|
||||
void UAVGadgetView::removeUAVGadget()
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (!m_uavGadget)
|
||||
return;
|
||||
tl->removeWidget(m_uavGadget->widget());
|
||||
|
||||
m_uavGadget->widget()->setParent(0);
|
||||
// disconnect(m_uavGadget, SIGNAL(changed()), this, SLOT(checkUAVGadgetStatus()));
|
||||
QWidget *toolBar = m_uavGadget->toolBar();
|
||||
if (toolBar != 0) {
|
||||
if (m_activeToolBar == toolBar) {
|
||||
@ -168,39 +162,31 @@ void UAVGadgetView::removeUAVGadget()
|
||||
toolBar->setVisible(false);
|
||||
toolBar->setParent(0);
|
||||
}
|
||||
setCurrentUAVGadget(0);
|
||||
m_uavGadget = 0;
|
||||
}
|
||||
|
||||
IUAVGadget *UAVGadgetView::currentUAVGadget() const
|
||||
IUAVGadget *UAVGadgetView::uavGadget() const
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
return m_uavGadget;
|
||||
}
|
||||
|
||||
void UAVGadgetView::setCurrentUAVGadget(IUAVGadget *uavGadget)
|
||||
void UAVGadgetView::setUAVGadget(IUAVGadget *uavGadget)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
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;
|
||||
}
|
||||
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()
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (!m_uavGadget)
|
||||
return;
|
||||
QWidget *toolBar = m_uavGadget->toolBar();
|
||||
@ -215,30 +201,21 @@ void UAVGadgetView::updateToolBar()
|
||||
|
||||
void UAVGadgetView::listSelectionActivated(int index)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
// UAVGadgetManager *em = CoreImpl::instance()->uavGadgetManager();
|
||||
/* QAbstractItemModel *model = m_uavGadgetList->model();
|
||||
if (IUAVGadget *uavGadget = model->data(model->index(index, 0), Qt::UserRole).value<IUAVGadget*>()) {
|
||||
em->activateUAVGadget(this, uavGadget);
|
||||
} else {
|
||||
em->activateUAVGadget(model->index(index, 0), this);
|
||||
}*/
|
||||
if (m_uavGadget && m_uavGadget->index() == index)
|
||||
return;
|
||||
if (m_uavGadgetManager->uavGadgetFactories().count() == 0)
|
||||
return;
|
||||
IUAVGadgetFactory *factory = m_uavGadgetManager->uavGadgetFactories().at(index);
|
||||
IUAVGadget *gadget = factory->createUAVGadget(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) :
|
||||
m_uavGadgetManager(uavGadgetManager),
|
||||
m_isRoot(isRoot)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO << uavGadget << isRoot;
|
||||
// //qDebug() << Q_FUNC_INFO << uavGadget << isRoot;
|
||||
m_view = new UAVGadgetView(m_uavGadgetManager, uavGadget);
|
||||
m_layout = new QStackedLayout(this);
|
||||
m_splitter = 0;
|
||||
@ -255,20 +232,26 @@ SplitterOrView::~SplitterOrView()
|
||||
|
||||
void SplitterOrView::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
if (uavGadget()) {
|
||||
setFocus(Qt::MouseFocusReason);
|
||||
m_uavGadgetManager->setCurrentView(this);
|
||||
m_uavGadgetManager->setCurrentUAVGadget(this->uavGadget());
|
||||
}
|
||||
}
|
||||
|
||||
void SplitterOrView::paintEvent(QPaintEvent *)
|
||||
void SplitterOrView::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
// //qDebug() << Q_FUNC_INFO;
|
||||
if (m_uavGadgetManager->currentSplitterOrView() != this)
|
||||
return;
|
||||
|
||||
if (!m_view || hasUAVGadgets())
|
||||
if (!m_view)
|
||||
return;
|
||||
|
||||
// if (hasUAVGadget())
|
||||
// return;
|
||||
|
||||
if (m_uavGadgetManager->toolbarsHidden())
|
||||
return;
|
||||
|
||||
// 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.setPen(Qt::NoPen);
|
||||
QColor shadeBrush(Qt::black);
|
||||
shadeBrush.setAlpha(10);
|
||||
shadeBrush.setAlpha(25);
|
||||
painter.setBrush(shadeBrush);
|
||||
const int r = 3;
|
||||
painter.drawRoundedRect(rect().adjusted(r, r, -r, -r), r * 2, r * 2);
|
||||
@ -308,9 +291,11 @@ void SplitterOrView::paintEvent(QPaintEvent *)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Contract: return SplitterOrView that is not splitter, or 0 if not found.
|
||||
* Implications: must not return SplitterOrView that is splitter.
|
||||
*/
|
||||
SplitterOrView *SplitterOrView::findFirstView()
|
||||
{
|
||||
//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)))
|
||||
@ -322,25 +307,11 @@ SplitterOrView *SplitterOrView::findFirstView()
|
||||
return this;
|
||||
}
|
||||
|
||||
SplitterOrView *SplitterOrView::findEmptyView()
|
||||
{
|
||||
//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;
|
||||
}
|
||||
|
||||
/* Contract: return SplitterOrView that has 'uavGadget', or 0 if not found.
|
||||
* Implications: must not return SplitterOrView that is splitter.
|
||||
*/
|
||||
SplitterOrView *SplitterOrView::findView(Core::IUAVGadget *uavGadget)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (!uavGadget || hasUAVGadget(uavGadget))
|
||||
return this;
|
||||
if (m_splitter) {
|
||||
@ -353,9 +324,11 @@ SplitterOrView *SplitterOrView::findView(Core::IUAVGadget *uavGadget)
|
||||
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)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (view == m_view)
|
||||
return this;
|
||||
if (m_splitter) {
|
||||
@ -368,9 +341,12 @@ SplitterOrView *SplitterOrView::findView(UAVGadgetView *view)
|
||||
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)
|
||||
{
|
||||
//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))) {
|
||||
@ -384,9 +360,12 @@ SplitterOrView *SplitterOrView::findSplitter(Core::IUAVGadget *uavGadget)
|
||||
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)
|
||||
{
|
||||
//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))) {
|
||||
@ -400,16 +379,18 @@ SplitterOrView *SplitterOrView::findSplitter(SplitterOrView *child)
|
||||
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)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
bool found = false;
|
||||
return findNextView_helper(view, &found);
|
||||
}
|
||||
|
||||
SplitterOrView *SplitterOrView::findNextView_helper(SplitterOrView *view, bool *found)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (*found && m_view) {
|
||||
return this;
|
||||
}
|
||||
@ -432,7 +413,6 @@ SplitterOrView *SplitterOrView::findNextView_helper(SplitterOrView *view, bool *
|
||||
|
||||
QSize SplitterOrView::minimumSizeHint() const
|
||||
{
|
||||
// //qDebug() << Q_FUNC_INFO;
|
||||
if (m_splitter)
|
||||
return m_splitter->minimumSizeHint();
|
||||
return QSize(64, 64);
|
||||
@ -440,7 +420,6 @@ QSize SplitterOrView::minimumSizeHint() const
|
||||
|
||||
QSplitter *SplitterOrView::takeSplitter()
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
QSplitter *oldSplitter = m_splitter;
|
||||
if (m_splitter)
|
||||
m_layout->removeWidget(m_splitter);
|
||||
@ -450,7 +429,6 @@ QSplitter *SplitterOrView::takeSplitter()
|
||||
|
||||
UAVGadgetView *SplitterOrView::takeView()
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
UAVGadgetView *oldView = m_view;
|
||||
if (m_view)
|
||||
m_layout->removeWidget(m_view);
|
||||
@ -460,12 +438,11 @@ UAVGadgetView *SplitterOrView::takeView()
|
||||
|
||||
void SplitterOrView::split(Qt::Orientation orientation)
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
Q_ASSERT(m_view && (m_splitter == 0));
|
||||
m_splitter = new MiniSplitter(this);
|
||||
m_splitter->setOrientation(orientation);
|
||||
m_layout->addWidget(m_splitter);
|
||||
Core::IUAVGadget *e = m_view->currentUAVGadget();
|
||||
Core::IUAVGadget *e = m_view->uavGadget();
|
||||
|
||||
SplitterOrView *view = 0;
|
||||
SplitterOrView *otherView = 0;
|
||||
@ -478,22 +455,17 @@ void SplitterOrView::split(Qt::Orientation orientation)
|
||||
m_splitter->addWidget((view = new SplitterOrView(m_uavGadgetManager)));
|
||||
}
|
||||
|
||||
// QWidget *w = m_layout->currentWidget();
|
||||
m_layout->setCurrentWidget(m_splitter);
|
||||
// m_layout->removeWidget(w);
|
||||
|
||||
if (m_view && !m_isRoot) {
|
||||
m_uavGadgetManager->emptyView(m_view);
|
||||
delete m_view;
|
||||
m_view = 0;
|
||||
}
|
||||
|
||||
m_uavGadgetManager->setCurrentView(view);
|
||||
}
|
||||
|
||||
void SplitterOrView::unsplitAll()
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
m_splitter->hide();
|
||||
m_layout->removeWidget(m_splitter); // workaround Qt bug
|
||||
unsplitAll_helper();
|
||||
@ -503,7 +475,6 @@ void SplitterOrView::unsplitAll()
|
||||
|
||||
void SplitterOrView::unsplitAll_helper()
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (!m_isRoot && m_view)
|
||||
m_uavGadgetManager->emptyView(m_view);
|
||||
if (m_splitter) {
|
||||
@ -517,10 +488,8 @@ void SplitterOrView::unsplitAll_helper()
|
||||
|
||||
void SplitterOrView::unsplit()
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
if (!m_splitter)
|
||||
return;
|
||||
|
||||
Q_ASSERT(m_splitter->count() == 1);
|
||||
SplitterOrView *childSplitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(0));
|
||||
QSplitter *oldSplitter = m_splitter;
|
||||
@ -535,9 +504,9 @@ void SplitterOrView::unsplit()
|
||||
UAVGadgetView *childView = childSplitterOrView->view();
|
||||
Q_ASSERT(childView);
|
||||
if (m_view) {
|
||||
if (IUAVGadget *e = childView->currentUAVGadget()) {
|
||||
if (IUAVGadget *e = childView->uavGadget()) {
|
||||
childView->removeUAVGadget();
|
||||
m_view->setCurrentUAVGadget(e);
|
||||
m_view->setUAVGadget(e);
|
||||
}
|
||||
m_uavGadgetManager->emptyView(childView);
|
||||
} else {
|
||||
@ -547,7 +516,7 @@ void SplitterOrView::unsplit()
|
||||
m_layout->setCurrentWidget(m_view);
|
||||
}
|
||||
delete oldSplitter;
|
||||
m_uavGadgetManager->setCurrentView(findFirstView());
|
||||
m_uavGadgetManager->setCurrentUAVGadget(findFirstView()->uavGadget());
|
||||
}
|
||||
|
||||
|
||||
@ -566,7 +535,7 @@ QByteArray SplitterOrView::saveState() const
|
||||
// IUAVGadget* e = uavGadget();
|
||||
// UAVGadgetManager *em = CoreImpl::instance()->uavGadgetManager();
|
||||
//
|
||||
// if (e && e == em->currentUAVGadget()) {
|
||||
// if (e && e == em->uavGadget()) {
|
||||
// stream << QByteArray("currentuavGadget")
|
||||
// << e->file()->fileName() << e->kind() << e->saveState();
|
||||
// } else if (e) {
|
||||
@ -611,7 +580,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
|
||||
// if (e) {
|
||||
// e->restoreState(uavGadgetState);
|
||||
// if (mode == "currentuavGadget")
|
||||
// em->setCurrentUAVGadget(e);
|
||||
// em->setUAVGadget(e);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -67,13 +67,12 @@ public:
|
||||
virtual ~UAVGadgetView();
|
||||
|
||||
void removeUAVGadget();
|
||||
IUAVGadget *currentUAVGadget() const;
|
||||
void setCurrentUAVGadget(IUAVGadget *uavGadget);
|
||||
IUAVGadget *uavGadget() const;
|
||||
void setUAVGadget(IUAVGadget *uavGadget);
|
||||
bool hasUAVGadget(IUAVGadget *uavGadget) const;
|
||||
void hideToolbar(bool hide);
|
||||
|
||||
public slots:
|
||||
void updateActionShortcuts();
|
||||
void closeView();
|
||||
|
||||
private slots:
|
||||
@ -92,6 +91,7 @@ private:
|
||||
QToolButton *m_closeButton;
|
||||
Utils::StyledBar *m_top;
|
||||
QVBoxLayout *tl; // top layout
|
||||
int m_defaultIndex;
|
||||
};
|
||||
|
||||
class SplitterOrView : public QWidget
|
||||
@ -108,9 +108,9 @@ public:
|
||||
inline bool isRoot() const { return m_isRoot; }
|
||||
|
||||
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 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 QSplitter *splitter() const { return m_splitter; }
|
||||
QSplitter *takeSplitter();
|
||||
@ -122,7 +122,6 @@ public:
|
||||
SplitterOrView *findView(Core::IUAVGadget *uavGadget);
|
||||
SplitterOrView *findView(UAVGadgetView *view);
|
||||
SplitterOrView *findFirstView();
|
||||
SplitterOrView *findEmptyView();
|
||||
SplitterOrView *findSplitter(Core::IUAVGadget *uavGadget);
|
||||
SplitterOrView *findSplitter(SplitterOrView *child);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user