2010-03-16 07:48:35 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file uavgadgetmanager.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
|
|
|
* @brief
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
* @defgroup coreplugin
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "uavgadgetmanager.h"
|
|
|
|
#include "uavgadgetview.h"
|
2010-03-17 08:06:18 +00:00
|
|
|
#include "uavgadgetmode.h"
|
2010-03-27 19:24:21 +00:00
|
|
|
#include "uavgadgetinstancemanager.h"
|
2010-03-16 07:48:35 +00:00
|
|
|
#include "iuavgadgetfactory.h"
|
|
|
|
#include "iuavgadget.h"
|
|
|
|
#include "icore.h"
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
#include <coreplugin/baseview.h>
|
|
|
|
#include <coreplugin/imode.h>
|
|
|
|
#include <coreplugin/settingsdatabase.h>
|
|
|
|
#include <coreplugin/variablemanager.h>
|
|
|
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
|
|
#include <utils/consoleprocess.h>
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
#include <QtCore/QMap>
|
|
|
|
#include <QtCore/QProcess>
|
|
|
|
#include <QtCore/QSet>
|
|
|
|
#include <QtCore/QSettings>
|
|
|
|
|
|
|
|
#include <QtGui/QAction>
|
|
|
|
#include <QtGui/QApplication>
|
|
|
|
#include <QtGui/QLayout>
|
|
|
|
#include <QtGui/QMainWindow>
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
#include <QtGui/QMessageBox>
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
#include <QtGui/QSplitter>
|
|
|
|
#include <QtGui/QStackedLayout>
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Core::IUAVGadget*)
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
using namespace Core::Internal;
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
enum { debugUAVGadgetManager=0 };
|
|
|
|
|
|
|
|
static inline ExtensionSystem::PluginManager *pluginManager()
|
|
|
|
{
|
|
|
|
return ExtensionSystem::PluginManager::instance();
|
|
|
|
}
|
|
|
|
|
|
|
|
//===================UAVGadgetManager=====================
|
|
|
|
|
2010-03-17 08:06:18 +00:00
|
|
|
//UAVGadgetManagerPlaceHolder *UAVGadgetManagerPlaceHolder::m_current = 0;
|
2010-03-16 07:48:35 +00:00
|
|
|
|
2010-03-17 08:06:18 +00:00
|
|
|
UAVGadgetManagerPlaceHolder::UAVGadgetManagerPlaceHolder(Core::Internal::UAVGadgetMode *mode, QWidget *parent)
|
|
|
|
: QWidget(parent),
|
2010-03-19 15:28:11 +00:00
|
|
|
m_uavGadgetMode(mode),
|
|
|
|
m_current(0)
|
2010-03-16 07:48:35 +00:00
|
|
|
{
|
2010-03-17 08:06:18 +00:00
|
|
|
m_mode = dynamic_cast<Core::IMode*>(mode);
|
2010-03-16 07:48:35 +00:00
|
|
|
setLayout(new QVBoxLayout);
|
|
|
|
layout()->setMargin(0);
|
|
|
|
connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode *)),
|
|
|
|
this, SLOT(currentModeChanged(Core::IMode *)));
|
|
|
|
|
2010-03-17 08:06:18 +00:00
|
|
|
currentModeChanged(Core::ModeManager::instance()->currentMode());
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UAVGadgetManagerPlaceHolder::~UAVGadgetManagerPlaceHolder()
|
|
|
|
{
|
|
|
|
if (m_current == this) {
|
2010-03-17 08:06:18 +00:00
|
|
|
m_uavGadgetMode->uavGadgetManager()->setParent(0);
|
|
|
|
m_uavGadgetMode->uavGadgetManager()->hide();
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManagerPlaceHolder::currentModeChanged(Core::IMode *mode)
|
|
|
|
{
|
2010-03-17 08:06:18 +00:00
|
|
|
UAVGadgetManager *gm = m_uavGadgetMode->uavGadgetManager();
|
2010-03-16 07:48:35 +00:00
|
|
|
if (m_current == this) {
|
|
|
|
m_current = 0;
|
2010-03-17 08:06:18 +00:00
|
|
|
gm->setParent(0);
|
|
|
|
gm->hide();
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
if (m_mode == mode) {
|
|
|
|
m_current = this;
|
2010-03-17 08:06:18 +00:00
|
|
|
layout()->addWidget(gm);
|
2010-03-21 16:50:00 +00:00
|
|
|
gm->showToolbars(gm->toolbarsShown());
|
2010-03-17 08:06:18 +00:00
|
|
|
gm->show();
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------- UAVGadgetManager
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
|
|
|
|
struct UAVGadgetManagerPrivate {
|
|
|
|
explicit UAVGadgetManagerPrivate(ICore *core, QWidget *parent);
|
|
|
|
~UAVGadgetManagerPrivate();
|
|
|
|
Internal::UAVGadgetView *m_view;
|
|
|
|
Internal::SplitterOrView *m_splitterOrView;
|
2010-03-25 18:33:58 +00:00
|
|
|
QPointer<IUAVGadget> m_currentGadget;
|
2010-03-16 07:48:35 +00:00
|
|
|
|
|
|
|
ICore *m_core;
|
|
|
|
|
|
|
|
// actions
|
2010-03-21 16:50:00 +00:00
|
|
|
static QAction *m_showToolbarsAction;
|
2010-03-17 08:06:18 +00:00
|
|
|
static QAction *m_splitAction;
|
|
|
|
static QAction *m_splitSideBySideAction;
|
|
|
|
static QAction *m_removeCurrentSplitAction;
|
|
|
|
static QAction *m_removeAllSplitsAction;
|
|
|
|
static QAction *m_gotoOtherSplitAction;
|
2010-03-16 07:48:35 +00:00
|
|
|
|
|
|
|
Internal::UAVGadgetClosingCoreListener *m_coreListener;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-03-21 16:50:00 +00:00
|
|
|
QAction *UAVGadgetManagerPrivate::m_showToolbarsAction = 0;
|
2010-03-17 08:06:18 +00:00
|
|
|
QAction *UAVGadgetManagerPrivate::m_splitAction = 0;
|
|
|
|
QAction *UAVGadgetManagerPrivate::m_splitSideBySideAction = 0;
|
|
|
|
QAction *UAVGadgetManagerPrivate::m_removeCurrentSplitAction = 0;
|
|
|
|
QAction *UAVGadgetManagerPrivate::m_removeAllSplitsAction = 0;
|
|
|
|
QAction *UAVGadgetManagerPrivate::m_gotoOtherSplitAction = 0;
|
|
|
|
|
2010-03-16 07:48:35 +00:00
|
|
|
UAVGadgetManagerPrivate::UAVGadgetManagerPrivate(ICore *core, QWidget *parent) :
|
|
|
|
m_view(0),
|
|
|
|
m_splitterOrView(0),
|
|
|
|
m_core(core),
|
|
|
|
m_coreListener(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UAVGadgetManagerPrivate::~UAVGadgetManagerPrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
|
|
|
|
QWidget(parent),
|
2010-03-21 16:50:00 +00:00
|
|
|
m_showToolbars(false),
|
2010-04-06 09:26:20 +00:00
|
|
|
m_d(new UAVGadgetManagerPrivate(core, parent)),
|
|
|
|
m_uavGadgetMode(0)
|
2010-03-16 07:48:35 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
connect(m_d->m_core, SIGNAL(contextAboutToChange(Core::IContext *)),
|
|
|
|
this, SLOT(handleContextChange(Core::IContext *)));
|
|
|
|
const QList<int> uavGadgetManagerContext =
|
|
|
|
QList<int>() << m_d->m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_UAVGADGETMANAGER);
|
|
|
|
|
|
|
|
ActionManager *am = m_d->m_core->actionManager();
|
|
|
|
|
|
|
|
//Window Menu
|
|
|
|
ActionContainer *mwindow = am->actionContainer(Constants::M_WINDOW);
|
2010-03-17 08:06:18 +00:00
|
|
|
Command *cmd;
|
|
|
|
|
2010-03-21 16:50:00 +00:00
|
|
|
// The actions m_d->m_showToolbarsAction etc are common to all instances of UAVGadgetManager
|
2010-03-17 08:06:18 +00:00
|
|
|
// which means that they share the menu items/signals in the Window menu.
|
|
|
|
// That is, they all connect their slots to the same signal and have to check in the slot
|
|
|
|
// if the current mode is their mode, otherwise they just ignore the signal.
|
|
|
|
// The first UAVGadgetManager creates the actions, and the following just use them
|
|
|
|
// (This also implies that they share the same context.)
|
2010-03-21 16:50:00 +00:00
|
|
|
if (m_d->m_showToolbarsAction == 0)
|
2010-03-17 08:06:18 +00:00
|
|
|
{
|
|
|
|
//Window menu separators
|
|
|
|
QAction *tmpaction = new QAction(this);
|
|
|
|
tmpaction->setSeparator(true);
|
|
|
|
cmd = am->registerAction(tmpaction, QLatin1String("OpenPilot.Window.Sep.Split"), uavGadgetManagerContext);
|
|
|
|
mwindow->addAction(cmd, Constants::G_WINDOW_HIDE_TOOLBAR);
|
|
|
|
|
2010-04-06 10:19:25 +00:00
|
|
|
m_d->m_showToolbarsAction = new QAction(tr("Edit Gadgets Mode"), this);
|
2010-03-21 16:50:00 +00:00
|
|
|
m_d->m_showToolbarsAction->setCheckable(true);
|
|
|
|
cmd = am->registerAction(m_d->m_showToolbarsAction, Constants::HIDE_TOOLBARS, uavGadgetManagerContext);
|
2010-03-19 15:28:11 +00:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F10")));
|
2010-03-17 08:06:18 +00:00
|
|
|
mwindow->addAction(cmd, Constants::G_WINDOW_HIDE_TOOLBAR);
|
|
|
|
|
|
|
|
//Window menu separators
|
|
|
|
QAction *tmpaction2 = new QAction(this);
|
|
|
|
tmpaction2->setSeparator(true);
|
|
|
|
cmd = am->registerAction(tmpaction2, QLatin1String("OpenPilot.Window.Sep.Split2"), uavGadgetManagerContext);
|
|
|
|
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
|
|
|
|
}
|
2010-03-21 16:50:00 +00:00
|
|
|
connect(m_d->m_showToolbarsAction, SIGNAL(triggered(bool)), this, SLOT(showToolbars(bool)));
|
2010-03-16 07:48:35 +00:00
|
|
|
|
|
|
|
#ifdef Q_WS_MAC
|
2010-03-19 15:28:11 +00:00
|
|
|
QString prefix = tr("Meta+Shift");
|
2010-03-16 07:48:35 +00:00
|
|
|
#else
|
2010-03-19 15:28:11 +00:00
|
|
|
QString prefix = tr("Ctrl+Shift");
|
2010-03-16 07:48:35 +00:00
|
|
|
#endif
|
|
|
|
|
2010-03-17 08:06:18 +00:00
|
|
|
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);
|
2010-03-19 15:28:11 +00:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("%1+Down").arg(prefix)));
|
2010-03-17 08:06:18 +00:00
|
|
|
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
|
|
|
|
}
|
2010-03-16 07:48:35 +00:00
|
|
|
connect(m_d->m_splitAction, SIGNAL(triggered()), this, SLOT(split()));
|
|
|
|
|
2010-03-17 08:06:18 +00:00
|
|
|
if (m_d->m_splitSideBySideAction == 0)
|
|
|
|
{
|
|
|
|
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);
|
2010-03-19 15:28:11 +00:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("%1+Right").arg(prefix)));
|
2010-03-17 08:06:18 +00:00
|
|
|
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
|
|
|
|
}
|
2010-03-16 07:48:35 +00:00
|
|
|
connect(m_d->m_splitSideBySideAction, SIGNAL(triggered()), this, SLOT(splitSideBySide()));
|
|
|
|
|
2010-03-17 08:06:18 +00:00
|
|
|
if (m_d->m_removeCurrentSplitAction == 0)
|
|
|
|
{
|
2010-03-19 15:28:11 +00:00
|
|
|
m_d->m_removeCurrentSplitAction = new QAction(tr("Close Current View"), this);
|
2010-03-17 08:06:18 +00:00
|
|
|
cmd = am->registerAction(m_d->m_removeCurrentSplitAction, Constants::REMOVE_CURRENT_SPLIT, uavGadgetManagerContext);
|
2010-03-19 15:28:11 +00:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("%1+C").arg(prefix)));
|
2010-03-17 08:06:18 +00:00
|
|
|
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
|
|
|
|
}
|
2010-03-16 07:48:35 +00:00
|
|
|
connect(m_d->m_removeCurrentSplitAction, SIGNAL(triggered()), this, SLOT(removeCurrentSplit()));
|
|
|
|
|
2010-03-17 08:06:18 +00:00
|
|
|
if (m_d->m_removeAllSplitsAction == 0)
|
|
|
|
{
|
2010-03-19 15:28:11 +00:00
|
|
|
m_d->m_removeAllSplitsAction = new QAction(tr("Close All Other Views"), this);
|
2010-03-17 08:06:18 +00:00
|
|
|
cmd = am->registerAction(m_d->m_removeAllSplitsAction, Constants::REMOVE_ALL_SPLITS, uavGadgetManagerContext);
|
2010-03-19 15:28:11 +00:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("%1+A").arg(prefix)));
|
2010-03-17 08:06:18 +00:00
|
|
|
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
|
|
|
|
}
|
2010-03-16 07:48:35 +00:00
|
|
|
connect(m_d->m_removeAllSplitsAction, SIGNAL(triggered()), this, SLOT(removeAllSplits()));
|
|
|
|
|
2010-03-17 08:06:18 +00:00
|
|
|
if (m_d->m_gotoOtherSplitAction == 0)
|
|
|
|
{
|
2010-03-19 15:28:11 +00:00
|
|
|
m_d->m_gotoOtherSplitAction = new QAction(tr("Goto Next View"), this);
|
2010-03-17 08:06:18 +00:00
|
|
|
cmd = am->registerAction(m_d->m_gotoOtherSplitAction, Constants::GOTO_OTHER_SPLIT, uavGadgetManagerContext);
|
2010-03-19 15:28:11 +00:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("%1+N").arg(prefix)));
|
2010-03-17 08:06:18 +00:00
|
|
|
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
|
|
|
|
}
|
2010-03-16 07:48:35 +00:00
|
|
|
connect(m_d->m_gotoOtherSplitAction, SIGNAL(triggered()), this, SLOT(gotoOtherSplit()));
|
|
|
|
|
|
|
|
// other setup
|
2010-03-17 08:06:18 +00:00
|
|
|
m_d->m_splitterOrView = new SplitterOrView(this, 0, true);
|
2010-03-16 07:48:35 +00:00
|
|
|
m_d->m_view = m_d->m_splitterOrView->view();
|
2010-03-25 18:33:58 +00:00
|
|
|
setCurrentGadget(m_d->m_view->gadget());
|
2010-03-16 07:48:35 +00:00
|
|
|
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
|
|
|
layout->setMargin(0);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
layout->addWidget(m_d->m_splitterOrView);
|
|
|
|
|
2010-03-21 16:50:00 +00:00
|
|
|
showToolbars(m_showToolbars);
|
2010-03-16 07:48:35 +00:00
|
|
|
updateActions();
|
|
|
|
}
|
|
|
|
|
|
|
|
UAVGadgetManager::~UAVGadgetManager()
|
|
|
|
{
|
|
|
|
if (m_d->m_core) {
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
if (m_d->m_coreListener) {
|
|
|
|
pm->removeObject(m_d->m_coreListener);
|
|
|
|
delete m_d->m_coreListener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete m_d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::init()
|
|
|
|
{
|
|
|
|
QList<int> context;
|
|
|
|
context << m_d->m_core->uniqueIDManager()->uniqueIdentifier("OpenPilot.UAVGadgetManager");
|
|
|
|
|
|
|
|
m_d->m_coreListener = new UAVGadgetClosingCoreListener(this);
|
|
|
|
|
|
|
|
pluginManager()->addObject(m_d->m_coreListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::handleContextChange(Core::IContext *context)
|
|
|
|
{
|
2010-03-19 15:28:11 +00:00
|
|
|
// if (debugUAVGadgetManager)
|
|
|
|
// qDebug() << Q_FUNC_INFO << context;
|
2010-03-16 07:48:35 +00:00
|
|
|
IUAVGadget *uavGadget = context ? qobject_cast<IUAVGadget*>(context) : 0;
|
2010-03-27 19:24:21 +00:00
|
|
|
if (uavGadget)
|
2010-03-25 18:33:58 +00:00
|
|
|
setCurrentGadget(uavGadget);
|
2010-03-27 19:24:21 +00:00
|
|
|
updateActions();
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
2010-03-25 18:33:58 +00:00
|
|
|
void UAVGadgetManager::setCurrentGadget(IUAVGadget *uavGadget)
|
2010-03-16 07:48:35 +00:00
|
|
|
{
|
2010-03-25 18:33:58 +00:00
|
|
|
if (m_d->m_currentGadget == uavGadget)
|
2010-03-16 07:48:35 +00:00
|
|
|
return;
|
|
|
|
|
2010-03-19 15:28:11 +00:00
|
|
|
SplitterOrView *oldView = currentSplitterOrView();
|
2010-03-25 18:33:58 +00:00
|
|
|
m_d->m_currentGadget = uavGadget;
|
2010-03-19 15:28:11 +00:00
|
|
|
SplitterOrView *view = currentSplitterOrView();
|
|
|
|
if (oldView != view) {
|
|
|
|
if (oldView)
|
|
|
|
oldView->update();
|
|
|
|
if (view)
|
|
|
|
view->update();
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
2010-03-19 15:28:11 +00:00
|
|
|
uavGadget->widget()->setFocus();
|
2010-03-25 18:33:58 +00:00
|
|
|
emit currentGadgetChanged(uavGadget);
|
2010-03-16 07:48:35 +00:00
|
|
|
updateActions();
|
2010-03-25 18:33:58 +00:00
|
|
|
// emit currentGadgetChanged(uavGadget);
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:28:11 +00:00
|
|
|
/* Contract: return current SplitterOrView.
|
|
|
|
* Implications: must not return SplitterOrView that is splitter.
|
|
|
|
*/
|
2010-03-16 07:48:35 +00:00
|
|
|
Core::Internal::SplitterOrView *UAVGadgetManager::currentSplitterOrView() const
|
|
|
|
{
|
2010-03-19 15:28:11 +00:00
|
|
|
if (!m_d->m_splitterOrView) // this is only for startup
|
|
|
|
return 0;
|
2010-03-25 18:33:58 +00:00
|
|
|
SplitterOrView *view = m_d->m_currentGadget ?
|
|
|
|
m_d->m_splitterOrView->findView(m_d->m_currentGadget) :
|
2010-03-19 15:28:11 +00:00
|
|
|
0;
|
2010-03-16 07:48:35 +00:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2010-03-25 18:33:58 +00:00
|
|
|
IUAVGadget *UAVGadgetManager::currentGadget() const
|
2010-03-16 07:48:35 +00:00
|
|
|
{
|
2010-03-25 18:33:58 +00:00
|
|
|
return m_d->m_currentGadget;
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::emptyView(Core::Internal::UAVGadgetView *view)
|
|
|
|
{
|
|
|
|
if (!view)
|
|
|
|
return;
|
|
|
|
|
2010-03-25 18:33:58 +00:00
|
|
|
IUAVGadget *uavGadget = view->gadget();
|
2010-03-16 07:48:35 +00:00
|
|
|
// emit uavGadgetAboutToClose(uavGadget);
|
2010-03-25 18:33:58 +00:00
|
|
|
removeGadget(uavGadget);
|
|
|
|
view->removeGadget();
|
2010-03-16 07:48:35 +00:00
|
|
|
// emit uavGadgetsClosed(uavGadgets);
|
|
|
|
}
|
|
|
|
|
2010-03-19 15:28:11 +00:00
|
|
|
|
2010-03-16 07:48:35 +00:00
|
|
|
void UAVGadgetManager::closeView(Core::Internal::UAVGadgetView *view)
|
|
|
|
{
|
|
|
|
if (!view)
|
|
|
|
return;
|
2010-03-19 15:28:11 +00:00
|
|
|
SplitterOrView *splitterOrView = m_d->m_splitterOrView->findView(view);
|
|
|
|
Q_ASSERT(splitterOrView);
|
|
|
|
Q_ASSERT(splitterOrView->view() == view);
|
|
|
|
if (splitterOrView == m_d->m_splitterOrView)
|
2010-03-16 07:48:35 +00:00
|
|
|
return;
|
|
|
|
|
2010-03-27 19:24:21 +00:00
|
|
|
IUAVGadget *gadget = view->gadget();
|
2010-04-06 09:26:20 +00:00
|
|
|
emptyView(view);
|
2010-03-27 19:24:21 +00:00
|
|
|
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
|
|
|
im->removeGadget(gadget);
|
|
|
|
|
2010-03-16 07:48:35 +00:00
|
|
|
SplitterOrView *splitter = m_d->m_splitterOrView->findSplitter(splitterOrView);
|
2010-03-25 18:33:58 +00:00
|
|
|
Q_ASSERT(splitterOrView->hasGadget() == false);
|
2010-03-19 15:28:11 +00:00
|
|
|
Q_ASSERT(splitter->isSplitter() == true);
|
2010-03-16 07:48:35 +00:00
|
|
|
splitterOrView->hide();
|
|
|
|
delete splitterOrView;
|
|
|
|
|
|
|
|
splitter->unsplit();
|
|
|
|
|
|
|
|
SplitterOrView *newCurrent = splitter->findFirstView();
|
2010-03-19 15:28:11 +00:00
|
|
|
Q_ASSERT(newCurrent);
|
|
|
|
if (newCurrent)
|
2010-03-25 18:33:58 +00:00
|
|
|
setCurrentGadget(newCurrent->gadget());
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
2010-03-27 19:24:21 +00:00
|
|
|
void UAVGadgetManager::addGadgetToContext(IUAVGadget *gadget)
|
2010-03-16 07:48:35 +00:00
|
|
|
{
|
2010-03-27 19:24:21 +00:00
|
|
|
if (!gadget)
|
2010-03-16 07:48:35 +00:00
|
|
|
return;
|
2010-03-27 19:24:21 +00:00
|
|
|
m_d->m_core->addContextObject(gadget);
|
2010-03-16 07:48:35 +00:00
|
|
|
|
2010-03-19 15:28:11 +00:00
|
|
|
// emit uavGadgetOpened(uavGadget);
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
2010-03-27 19:24:21 +00:00
|
|
|
void UAVGadgetManager::removeGadget(IUAVGadget *gadget)
|
2010-03-16 07:48:35 +00:00
|
|
|
{
|
2010-03-27 19:24:21 +00:00
|
|
|
if (!gadget)
|
2010-03-16 07:48:35 +00:00
|
|
|
return;
|
2010-03-27 19:24:21 +00:00
|
|
|
m_d->m_core->removeContextObject(qobject_cast<IContext*>(gadget));
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::ensureUAVGadgetManagerVisible()
|
|
|
|
{
|
|
|
|
if (!isVisible())
|
2010-03-17 08:06:18 +00:00
|
|
|
m_d->m_core->modeManager()->activateMode(m_uavGadgetMode->uniqueModeName());
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::updateActions()
|
|
|
|
{
|
2010-03-27 19:24:21 +00:00
|
|
|
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
|
|
|
return;
|
2010-03-19 15:28:11 +00:00
|
|
|
if (!m_d->m_splitterOrView) // this is only for startup
|
|
|
|
return;
|
2010-03-16 07:48:35 +00:00
|
|
|
// Splitting is only possible when the toolbars are shown
|
2010-03-21 16:50:00 +00:00
|
|
|
bool shown = m_d->m_showToolbarsAction->isChecked();
|
2010-03-16 07:48:35 +00:00
|
|
|
bool hasSplitter = m_d->m_splitterOrView->isSplitter();
|
2010-03-21 16:50:00 +00:00
|
|
|
m_d->m_removeCurrentSplitAction->setEnabled(shown && hasSplitter);
|
|
|
|
m_d->m_removeAllSplitsAction->setEnabled(shown && hasSplitter);
|
|
|
|
m_d->m_gotoOtherSplitAction->setEnabled(shown && hasSplitter);
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray UAVGadgetManager::saveState() const
|
|
|
|
{
|
|
|
|
QByteArray bytes;
|
2010-03-21 16:50:00 +00:00
|
|
|
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
|
|
|
|
|
|
|
stream << QByteArray("UAVGadgetManagerV1");
|
|
|
|
|
|
|
|
stream << m_showToolbars;
|
|
|
|
|
|
|
|
stream << m_d->m_splitterOrView->saveState();
|
2010-03-16 07:48:35 +00:00
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UAVGadgetManager::restoreState(const QByteArray &state)
|
|
|
|
{
|
2010-03-21 16:50:00 +00:00
|
|
|
removeAllSplits();
|
2010-03-27 19:24:21 +00:00
|
|
|
|
|
|
|
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
2010-04-06 09:26:20 +00:00
|
|
|
IUAVGadget *gadget = m_d->m_splitterOrView->view()->gadget();
|
2010-03-21 16:50:00 +00:00
|
|
|
emptyView(m_d->m_splitterOrView->view());
|
2010-04-06 09:26:20 +00:00
|
|
|
im->removeGadget(gadget);
|
2010-03-21 16:50:00 +00:00
|
|
|
QDataStream stream(state);
|
|
|
|
|
|
|
|
QByteArray version;
|
|
|
|
stream >> version;
|
|
|
|
|
|
|
|
if (version != "UAVGadgetManagerV1")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
stream >> m_showToolbars;
|
|
|
|
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
|
|
|
|
QByteArray splitterstates;
|
|
|
|
stream >> splitterstates;
|
|
|
|
m_d->m_splitterOrView->restoreState(splitterstates);
|
|
|
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
2010-03-16 07:48:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-21 16:50:00 +00:00
|
|
|
|
2010-03-16 07:48:35 +00:00
|
|
|
void UAVGadgetManager::saveSettings()
|
|
|
|
{
|
2010-03-21 16:50:00 +00:00
|
|
|
QString defaultUAVGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/DefaultSettings";
|
|
|
|
QString uavGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/Settings";
|
|
|
|
|
|
|
|
QSettings *qs = m_d->m_core->settings();
|
|
|
|
// The idea is to have a default setting that is only written once
|
2010-03-24 19:48:24 +00:00
|
|
|
if (!qs->contains(defaultUAVGadgetManagerKey))
|
|
|
|
qs->setValue(defaultUAVGadgetManagerKey, saveState().toBase64());
|
2010-03-21 16:50:00 +00:00
|
|
|
else
|
2010-03-24 19:48:24 +00:00
|
|
|
qs->setValue(uavGadgetManagerKey, saveState().toBase64());
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::readSettings()
|
|
|
|
{
|
2010-03-21 16:50:00 +00:00
|
|
|
QString defaultUAVGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/DefaultSettings";
|
|
|
|
QString uavGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/Settings";
|
|
|
|
|
|
|
|
QSettings *qs = m_d->m_core->settings();
|
|
|
|
QString key("");
|
2010-03-24 19:48:24 +00:00
|
|
|
if (qs->contains(uavGadgetManagerKey))
|
|
|
|
key = uavGadgetManagerKey;
|
|
|
|
else if (qs->contains(defaultUAVGadgetManagerKey))
|
|
|
|
key = defaultUAVGadgetManagerKey;
|
2010-03-21 16:50:00 +00:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
const QVariant &managerSettings = qs->value(key);
|
|
|
|
restoreState(QByteArray::fromBase64(managerSettings.toByteArray()));
|
|
|
|
showToolbars(m_showToolbars);
|
|
|
|
updateActions();
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::split(Qt::Orientation orientation)
|
|
|
|
{
|
2010-03-17 08:06:18 +00:00
|
|
|
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
|
|
|
return;
|
2010-03-19 15:28:11 +00:00
|
|
|
|
2010-03-25 18:33:58 +00:00
|
|
|
IUAVGadget *uavGadget = m_d->m_currentGadget;
|
2010-03-19 15:28:11 +00:00
|
|
|
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);
|
2010-03-25 18:33:58 +00:00
|
|
|
setCurrentGadget(next->gadget());
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::split()
|
|
|
|
{
|
|
|
|
split(Qt::Vertical);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::splitSideBySide()
|
|
|
|
{
|
|
|
|
split(Qt::Horizontal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::removeCurrentSplit()
|
|
|
|
{
|
2010-03-17 08:06:18 +00:00
|
|
|
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
|
|
|
return;
|
2010-03-16 07:48:35 +00:00
|
|
|
|
2010-03-19 15:28:11 +00:00
|
|
|
SplitterOrView *viewToClose = currentSplitterOrView();
|
|
|
|
if (viewToClose == m_d->m_splitterOrView)
|
2010-03-16 07:48:35 +00:00
|
|
|
return;
|
|
|
|
closeView(viewToClose->view());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::removeAllSplits()
|
|
|
|
{
|
2010-03-17 08:06:18 +00:00
|
|
|
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
|
|
|
return;
|
2010-03-19 15:28:11 +00:00
|
|
|
|
2010-03-16 07:48:35 +00:00
|
|
|
if (!m_d->m_splitterOrView->isSplitter())
|
|
|
|
return;
|
2010-03-25 18:33:58 +00:00
|
|
|
IUAVGadget *uavGadget = m_d->m_currentGadget;
|
2010-03-27 19:24:21 +00:00
|
|
|
QList<IUAVGadget*> gadgets = m_d->m_splitterOrView->gadgets();
|
|
|
|
gadgets.removeOne(uavGadget);
|
|
|
|
|
2010-03-25 18:33:58 +00:00
|
|
|
m_d->m_currentGadget = 0; // trigger update below
|
2010-03-16 07:48:35 +00:00
|
|
|
m_d->m_splitterOrView->unsplitAll();
|
2010-03-25 18:33:58 +00:00
|
|
|
m_d->m_splitterOrView->view()->setGadget(uavGadget);
|
|
|
|
setCurrentGadget(uavGadget);
|
2010-04-06 09:26:20 +00:00
|
|
|
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
|
|
|
foreach (IUAVGadget *g, gadgets) {
|
|
|
|
im->removeGadget(g);
|
|
|
|
}
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UAVGadgetManager::gotoOtherSplit()
|
|
|
|
{
|
2010-03-17 08:06:18 +00:00
|
|
|
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
|
|
|
return;
|
2010-03-19 15:28:11 +00:00
|
|
|
|
2010-03-16 07:48:35 +00:00
|
|
|
if (m_d->m_splitterOrView->isSplitter()) {
|
2010-03-19 15:28:11 +00:00
|
|
|
SplitterOrView *currentView = currentSplitterOrView();
|
2010-03-16 07:48:35 +00:00
|
|
|
SplitterOrView *view = m_d->m_splitterOrView->findNextView(currentView);
|
|
|
|
if (!view)
|
|
|
|
view = m_d->m_splitterOrView->findFirstView();
|
|
|
|
if (view) {
|
2010-03-25 18:33:58 +00:00
|
|
|
setCurrentGadget(view->gadget());
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-21 16:50:00 +00:00
|
|
|
void UAVGadgetManager::showToolbars(bool show)
|
2010-03-16 07:48:35 +00:00
|
|
|
{
|
2010-03-17 08:06:18 +00:00
|
|
|
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
2010-03-19 15:28:11 +00:00
|
|
|
return;
|
|
|
|
|
2010-03-21 16:50:00 +00:00
|
|
|
m_d->m_showToolbarsAction->setChecked(show);
|
|
|
|
m_showToolbars = show;
|
2010-03-19 15:28:11 +00:00
|
|
|
SplitterOrView *next = m_d->m_splitterOrView->findFirstView();
|
|
|
|
do {
|
2010-03-21 16:50:00 +00:00
|
|
|
next->view()->showToolbar(show);
|
2010-03-19 15:28:11 +00:00
|
|
|
next = m_d->m_splitterOrView->findNextView(next);
|
|
|
|
} while (next);
|
|
|
|
|
2010-03-21 16:50:00 +00:00
|
|
|
m_d->m_splitAction->setEnabled(show);
|
|
|
|
m_d->m_splitSideBySideAction->setEnabled(show);
|
|
|
|
m_d->m_removeCurrentSplitAction->setEnabled(show);
|
|
|
|
m_d->m_removeAllSplitsAction->setEnabled(show);
|
|
|
|
m_d->m_gotoOtherSplitAction->setEnabled(show);
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|
|
|
|
//===================UAVGadgetClosingCoreListener======================
|
|
|
|
|
|
|
|
UAVGadgetClosingCoreListener::UAVGadgetClosingCoreListener(UAVGadgetManager *em)
|
|
|
|
: m_em(em)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UAVGadgetClosingCoreListener::coreAboutToClose()
|
|
|
|
{
|
|
|
|
// Do not ask for files to save.
|
|
|
|
// MainWindow::closeEvent has already done that.
|
2010-03-19 15:28:11 +00:00
|
|
|
return true;
|
2010-03-16 07:48:35 +00:00
|
|
|
}
|