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

GCS/coreplugin: First addition of "splittable views" layout manager

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@323 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-03-16 07:48:35 +00:00 committed by ephy
parent b15c803328
commit 0a347bf8b4
18 changed files with 2448 additions and 221 deletions

View File

@ -59,7 +59,9 @@ const char * const GCS_REVISION_STR = "";
//modes
const char * const MODE_WELCOME = "Welcome";
const char * const MODE_UAVGADGET = "Mode 1";
const int P_MODE_WELCOME = 100;
const int P_MODE_UAVGADGET = 90;
//menubar
const char * const MENU_BAR = "GCS.MenuBar";
@ -80,6 +82,8 @@ const char * const M_HELP = "GCS.Menu.Help";
const char * const C_GLOBAL = "Global Context";
const int C_GLOBAL_ID = 0;
const char * const C_WELCOME_MODE = "Core.WelcomeMode";
const char * const C_UAVGADGET_MODE = "Core.UAVGadgetMode";
const char * const C_UAVGADGETMANAGER = "Core.UAVGadgetManager";
const char * const C_NAVIGATION_PANE = "Core.NavigationPane";
const char * const C_PROBLEM_PANE = "Core.ProblemPane";
@ -118,6 +122,7 @@ const char * const REMOVE_ALL_SPLITS = "GCS.RemoveAllSplits";
const char * const GOTO_OTHER_SPLIT = "GCS.GotoOtherSplit";
const char * const SAVEASDEFAULT = "GCS.SaveAsDefaultLayout";
const char * const RESTOREDEFAULT = "GCS.RestoreDefaultLayout";
const char * const HIDE_TOOLBARS = "GCS.HideToolbars";
const char * const CLOSE = "GCS.Close";
const char * const CLOSEALL = "GCS.CloseAll";
const char * const CLOSEOTHERS = "GCS.CloseOthers";
@ -180,6 +185,7 @@ const char * const G_WINDOW_PANES = "GCS.Group.Window.Panes";
const char * const G_WINDOW_SPLIT = "GCS.Group.Window.Split";
const char * const G_WINDOW_NAVIGATE = "GCS.Group.Window.Navigate";
const char * const G_WINDOW_OTHER = "GCS.Group.Window.Other";
const char * const G_WINDOW_HIDE_TOOLBAR = "GCS.Group.Window.Hide";
// help groups (global)
const char * const G_HELP_HELP = "GCS.Group.Help.Help";

View File

@ -87,6 +87,12 @@ MessageManager *CoreImpl::messageManager() const
return m_mainwindow->messageManager();
}
UAVGadgetManager *CoreImpl::uavGadgetManager() const
{
return m_mainwindow->uavGadgetManager();
}
VariableManager *CoreImpl::variableManager() const
{
return m_mainwindow->variableManager();

View File

@ -55,6 +55,7 @@ public:
ActionManager *actionManager() const;
UniqueIDManager *uniqueIDManager() const;
MessageManager *messageManager() const;
UAVGadgetManager *uavGadgetManager() const;
VariableManager *variableManager() const;
ModeManager *modeManager() const;
MimeDatabase *mimeDatabase() const;

View File

@ -29,6 +29,8 @@
#include "coreplugin.h"
#include "mainwindow.h"
#include "modemanager.h"
#include "uavgadgetmode.h"
#include "uavgadgetmanager.h"
#include <extensionsystem/pluginmanager.h>
@ -37,13 +39,17 @@
using namespace Core::Internal;
CorePlugin::CorePlugin() :
m_mainWindow(new MainWindow)
m_mainWindow(new MainWindow),
m_uavGadgetMode(0)
{
}
CorePlugin::~CorePlugin()
{
if (m_uavGadgetMode) {
removeObject(m_uavGadgetMode);
delete m_uavGadgetMode;
}
delete m_mainWindow;
}
@ -51,7 +57,11 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
Q_UNUSED(arguments)
const bool success = m_mainWindow->init(errorMessage);
if (success) {
UAVGadgetManager *uavGadgetManager = m_mainWindow->uavGadgetManager();
m_uavGadgetMode = new UAVGadgetMode(uavGadgetManager);
addObject(m_uavGadgetMode);
}
return success;
}

View File

@ -34,7 +34,7 @@
namespace Core {
namespace Internal {
class EditMode;
class UAVGadgetMode;
class MainWindow;
class CorePlugin : public ExtensionSystem::IPlugin
@ -54,6 +54,7 @@ public slots:
private:
MainWindow *m_mainWindow;
UAVGadgetMode *m_uavGadgetMode;
};
} // namespace Internal

View File

@ -11,8 +11,10 @@ include(../../libs/utils/utils.pri)
include(../../shared/scriptwrapper/scriptwrapper.pri)
include(coreplugin_dependencies.pri)
INCLUDEPATH += dialogs \
uavgadgetmanager \
actionmanager
DEPENDPATH += dialogs \
uavgadgetmanager \
actionmanager
SOURCES += mainwindow.cpp \
tabpositionindicator.cpp \
@ -24,6 +26,10 @@ SOURCES += mainwindow.cpp \
messageoutputwindow.cpp \
viewmanager.cpp \
versiondialog.cpp \
iuavgadget.cpp \
uavgadgetmode.cpp \
uavgadgetmanager/uavgadgetmanager.cpp \
uavgadgetmanager/uavgadgetview.cpp \
actionmanager/actionmanager.cpp \
actionmanager/command.cpp \
actionmanager/actioncontainer.cpp \
@ -58,6 +64,11 @@ HEADERS += mainwindow.h \
messagemanager.h \
messageoutputwindow.h \
viewmanager.h \
iuavgadget.h \
uavgadgetmode.h \
iuavgadgetfactory.h \
uavgadgetmanager/uavgadgetmanager.h \
uavgadgetmanager/uavgadgetview.h \
actionmanager/actioncontainer.h \
actionmanager/actionmanager.h \
actionmanager/command.h \

View File

@ -49,6 +49,7 @@ class ModeManager;
class SettingsDatabase;
class UniqueIDManager;
class VariableManager;
class UAVGadgetManager;
class CORE_EXPORT ICore : public QObject
{
@ -75,6 +76,7 @@ public:
virtual MessageManager *messageManager() const = 0;
virtual VariableManager *variableManager() const = 0;
virtual ModeManager *modeManager() const = 0;
virtual UAVGadgetManager *uavGadgetManager() const = 0;
virtual MimeDatabase *mimeDatabase() const = 0;
virtual QSettings *settings() const = 0;

View File

@ -0,0 +1,44 @@
/**
******************************************************************************
*
* @file iuavgadget.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 "iuavgadget.h"
/*!
\class Core::IUAVGadget
\brief The IUAVGadget is an interface for uav gadgets.
Classes that implement this interface are for example .
Guidelines for implementing:
\list
\o to be filled in...
\endlist
\sa Core::IUAVGadgetFactory Core::IContext
*/

View File

@ -0,0 +1,60 @@
/**
******************************************************************************
*
* @file iuavgadget.h
* @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
*/
#ifndef IUAVGADGET_H
#define IUAVGADGET_H
#include <coreplugin/icontext.h>
#include <coreplugin/core_global.h>
QT_BEGIN_NAMESPACE
class QWidget;
QT_END_NAMESPACE
namespace Core {
class CORE_EXPORT IUAVGadget : public IContext
{
Q_OBJECT
public:
IUAVGadget(QObject *parent = 0) : IContext(parent) {}
virtual ~IUAVGadget() {}
virtual QList<int> context() const = 0;
virtual QWidget *widget() = 0;
virtual QString contextHelpId() const { return QString(); }
// virtual void saveConfiguration() = 0;
// virtual void loadConfiguration(QString ) = 0;
// virtual QStringList getConfigurationNames() = 0;
virtual QWidget *toolBar() = 0;
};
} // namespace Core
#endif // IUAVGADGET_H

View File

@ -0,0 +1,56 @@
/**
******************************************************************************
*
* @file iuavgadgetfactory.h
* @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
*/
#ifndef IUAVGADGETFACTORY_H
#define IUAVGADGETFACTORY_H
#include "core_global.h"
#include <QtCore/QObject>
QT_BEGIN_NAMESPACE
class QStringList;
QT_END_NAMESPACE
namespace Core {
class IUAVGadget;
class CORE_EXPORT IUAVGadgetFactory : public QObject
{
Q_OBJECT
public:
IUAVGadgetFactory(QObject *parent = 0) : QObject(parent) {}
virtual ~IUAVGadgetFactory() {}
virtual IUAVGadget *createUAVGadget(QWidget *parent) = 0;
virtual QString name() = 0;
};
} // namespace Core
#endif // IUAVGADGETFACTORY_H

View File

@ -41,6 +41,7 @@
#include "outputpane.h"
#include "plugindialog.h"
#include "shortcutsettings.h"
#include "uavgadgetmanager.h"
#include "settingsdialog.h"
#include "variablemanager.h"
@ -111,6 +112,7 @@ MainWindow::MainWindow() :
m_variableManager(new VariableManager(this)),
m_viewManager(0),
m_modeManager(0),
m_uavGadgetManager(0),
m_mimeDatabase(new MimeDatabase),
m_rightPaneWidget(0),
m_versionDialog(0),
@ -137,6 +139,7 @@ MainWindow::MainWindow() :
QCoreApplication::setApplicationName(QLatin1String("OpenPilotGCS"));
QCoreApplication::setApplicationVersion(QLatin1String(Core::Constants::GCS_VERSION_LONG));
QCoreApplication::setOrganizationName(QLatin1String("OpenPilot"));
QCoreApplication::setOrganizationDomain(QLatin1String("openpilot.org"));
QSettings::setDefaultFormat(QSettings::IniFormat);
QString baseName = qApp->style()->objectName();
#ifdef Q_WS_X11
@ -167,8 +170,11 @@ MainWindow::MainWindow() :
//m_modeManager->addWidget(m_progressManager->progressView());
m_viewManager = new ViewManager(this);
m_messageManager = new MessageManager;
m_uavGadgetManager = new UAVGadgetManager(m_coreImpl, this);
m_uavGadgetManager->hide();
setCentralWidget(m_modeStack);
connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*,QWidget*)),
this, SLOT(updateFocusWidget(QWidget*,QWidget*)));
@ -719,6 +725,11 @@ VariableManager *MainWindow::variableManager() const
return m_variableManager;
}
UAVGadgetManager *MainWindow::uavGadgetManager() const
{
return m_uavGadgetManager;
}
ModeManager *MainWindow::modeManager() const
{
return m_modeManager;

View File

@ -57,6 +57,7 @@ class UniqueIDManager;
class VariableManager;
class ViewManagerInterface;
class IMode;
class UAVGadgetManager;
namespace Internal {
@ -90,6 +91,7 @@ public:
Core::ActionManager *actionManager() const;
Core::UniqueIDManager *uniqueIDManager() const;
Core::MessageManager *messageManager() const;
Core::UAVGadgetManager *uavGadgetManager() const;
Core::VariableManager *variableManager() const;
Core::ModeManager *modeManager() const;
Core::MimeDatabase *mimeDatabase() const;
@ -162,6 +164,7 @@ private:
VariableManager *m_variableManager;
ViewManager *m_viewManager;
ModeManager *m_modeManager;
UAVGadgetManager *m_uavGadgetManager;
MimeDatabase *m_mimeDatabase;
FancyTabWidget *m_modeStack;
RightPaneWidget *m_rightPaneWidget;

View File

@ -0,0 +1,866 @@
/**
******************************************************************************
*
* @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"
#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=====================
UAVGadgetManagerPlaceHolder *UAVGadgetManagerPlaceHolder::m_current = 0;
UAVGadgetManagerPlaceHolder::UAVGadgetManagerPlaceHolder(Core::IMode *mode, QWidget *parent)
: QWidget(parent), m_mode(mode)
{
setLayout(new QVBoxLayout);
layout()->setMargin(0);
connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode *)),
this, SLOT(currentModeChanged(Core::IMode *)));
currentModeChanged(Core::ModeManager::instance()->currentMode());
}
UAVGadgetManagerPlaceHolder::~UAVGadgetManagerPlaceHolder()
{
if (m_current == this) {
UAVGadgetManager::instance()->setParent(0);
UAVGadgetManager::instance()->hide();
}
}
void UAVGadgetManagerPlaceHolder::currentModeChanged(Core::IMode *mode)
{
if (m_current == this) {
m_current = 0;
UAVGadgetManager::instance()->setParent(0);
UAVGadgetManager::instance()->hide();
}
if (m_mode == mode) {
m_current = this;
layout()->addWidget(UAVGadgetManager::instance());
UAVGadgetManager::instance()->show();
}
}
UAVGadgetManagerPlaceHolder* UAVGadgetManagerPlaceHolder::current()
{
return m_current;
}
// ---------------- UAVGadgetManager
namespace Core {
struct UAVGadgetManagerPrivate {
explicit UAVGadgetManagerPrivate(ICore *core, QWidget *parent);
~UAVGadgetManagerPrivate();
Internal::UAVGadgetView *m_view;
Internal::SplitterOrView *m_splitterOrView;
QPointer<IUAVGadget> m_currentUAVGadget;
QPointer<SplitterOrView> m_currentView;
ICore *m_core;
// actions
QAction *m_hideToolbarsAction;
QAction *m_splitAction;
QAction *m_splitSideBySideAction;
QAction *m_removeCurrentSplitAction;
QAction *m_removeAllSplitsAction;
QAction *m_gotoOtherSplitAction;
QAction *m_closeCurrentUAVGadgetAction;
Internal::UAVGadgetClosingCoreListener *m_coreListener;
};
}
UAVGadgetManagerPrivate::UAVGadgetManagerPrivate(ICore *core, QWidget *parent) :
m_view(0),
m_splitterOrView(0),
m_core(core),
m_closeCurrentUAVGadgetAction(new QAction(UAVGadgetManager::tr("Close"), parent)),
m_coreListener(0)
{
}
UAVGadgetManagerPrivate::~UAVGadgetManagerPrivate()
{
}
UAVGadgetManager *UAVGadgetManager::m_instance = 0;
/*static Command *createSeparator(ActionManager *am, QObject *parent,
const QString &name,
const QList<int> &context)
{
QAction *tmpaction = new QAction(parent);
tmpaction->setSeparator(true);
Command *cmd = am->registerAction(tmpaction, name, context);
return cmd;
}*/
UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
QWidget(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 *)),
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);
ActionManager *am = m_d->m_core->actionManager();
//Window Menu
ActionContainer *mwindow = am->actionContainer(Constants::M_WINDOW);
//Window menu separators
QAction *tmpaction = new QAction(this);
tmpaction->setSeparator(true);
Command *cmd = am->registerAction(tmpaction, QLatin1String("OpenPilot.Window.Sep.Split"), uavGadgetManagerContext);
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
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"));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_d->m_hideToolbarsAction, SIGNAL(triggered(bool)), this, SLOT(hideToolbars(bool)));
// //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);
//Close Action
// //qDebug() << Q_FUNC_INFO << "close cmd" << m_d->m_closeCurrentUAVGadgetAction;
cmd = am->registerAction(m_d->m_closeCurrentUAVGadgetAction, Constants::CLOSE, uavGadgetManagerContext);
// cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+W")));
cmd->setAttribute(Core::Command::CA_UpdateText);
cmd->setDefaultText(m_d->m_closeCurrentUAVGadgetAction->text());
connect(m_d->m_closeCurrentUAVGadgetAction, SIGNAL(triggered()), this, SLOT(closeUAVGadget()));
#ifdef Q_WS_MAC
QString prefix = tr("Meta+E");
#else
QString prefix = tr("Ctrl+E");
#endif
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)));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_d->m_splitAction, SIGNAL(triggered()), this, SLOT(split()));
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)));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_d->m_splitSideBySideAction, SIGNAL(triggered()), this, SLOT(splitSideBySide()));
m_d->m_removeCurrentSplitAction = new QAction(tr("Remove Current Split"), this);
cmd = am->registerAction(m_d->m_removeCurrentSplitAction, Constants::REMOVE_CURRENT_SPLIT, uavGadgetManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("%1,0").arg(prefix)));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_d->m_removeCurrentSplitAction, SIGNAL(triggered()), this, SLOT(removeCurrentSplit()));
m_d->m_removeAllSplitsAction = new QAction(tr("Remove All Splits"), this);
cmd = am->registerAction(m_d->m_removeAllSplitsAction, Constants::REMOVE_ALL_SPLITS, uavGadgetManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("%1,1").arg(prefix)));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_d->m_removeAllSplitsAction, SIGNAL(triggered()), this, SLOT(removeAllSplits()));
m_d->m_gotoOtherSplitAction = new QAction(tr("Goto Other Split"), this);
cmd = am->registerAction(m_d->m_gotoOtherSplitAction, Constants::GOTO_OTHER_SPLIT, uavGadgetManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("%1,o").arg(prefix)));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_d->m_gotoOtherSplitAction, SIGNAL(triggered()), this, SLOT(gotoOtherSplit()));
// other setup
m_d->m_splitterOrView = new SplitterOrView(0, true);
m_d->m_view = m_d->m_splitterOrView->view();
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
layout->addWidget(m_d->m_splitterOrView);
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()
{
//qDebug() << Q_FUNC_INFO;
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::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;
IUAVGadget *uavGadget = context ? qobject_cast<IUAVGadget*>(context) : 0;
if (uavGadget) {
setCurrentUAVGadget(uavGadget);
} else {
updateActions();
}
}
void UAVGadgetManager::setCurrentUAVGadget(IUAVGadget *uavGadget)
{
//qDebug() << Q_FUNC_INFO;
if (uavGadget)
setCurrentView(0);
if (m_d->m_currentUAVGadget == uavGadget)
return;
m_d->m_currentUAVGadget = uavGadget;
if (uavGadget) {
if (SplitterOrView *splitterOrView = m_d->m_splitterOrView->findView(uavGadget))
splitterOrView->view()->setCurrentUAVGadget(uavGadget);
}
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();
}
Core::Internal::SplitterOrView *UAVGadgetManager::currentSplitterOrView() const
{
SplitterOrView *view = m_d->m_currentView;
if (!view)
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;
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;
// 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);
SplitterOrView *splitter = m_d->m_splitterOrView->findSplitter(splitterOrView);
Q_ASSERT(splitterOrView->hasUAVGadgets() == false);
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;
}
void UAVGadgetManager::addUAVGadget(IUAVGadget *uavGadget)
{
//qDebug() << Q_FUNC_INFO;
if (!uavGadget)
return;
m_d->m_core->addContextObject(uavGadget);
// emit uavGadgetOpened(uavGadget);
}
void UAVGadgetManager::ensureUAVGadgetManagerVisible()
{
//qDebug() << Q_FUNC_INFO;
if (!isVisible())
m_d->m_core->modeManager()->activateMode(Constants::MODE_UAVGADGET);
}
void UAVGadgetManager::updateActions()
{
//qDebug() << Q_FUNC_INFO;
// Splitting is only possible when the toolbars are shown
bool hidden = m_d->m_hideToolbarsAction->isChecked();
bool hasSplitter = m_d->m_splitterOrView->isSplitter();
m_d->m_removeCurrentSplitAction->setEnabled(!hidden && hasSplitter);
m_d->m_removeAllSplitsAction->setEnabled(!hidden && hasSplitter);
m_d->m_gotoOtherSplitAction->setEnabled(!hidden && hasSplitter);
}
QByteArray UAVGadgetManager::saveState() const
{
QByteArray bytes;
// QDataStream stream(&bytes, QIODevice::WriteOnly);
//
// stream << QByteArray("UAVGadgetManagerV4");
//
// QList<IUAVGadget *> uavGadgets = openedUAVGadgets();
// foreach (IUAVGadget *uavGadget, uavGadgets) {
// if (!uavGadget->file()->fileName().isEmpty()) {
// QByteArray state = uavGadget->saveState();
// if (!state.isEmpty())
// m_d->m_uavGadgetStates.insert(uavGadget->file()->fileName(), QVariant(state));
// }
// }
//
// stream << m_d->m_uavGadgetStates;
//
// QList<OpenUAVGadgetsModel::Entry> entries = m_d->m_uavGadgetModel->entries();
// stream << entries.count();
//
// foreach (OpenUAVGadgetsModel::Entry entry, entries) {
// stream << entry.fileName() << entry.displayName() << entry.kind();
// }
//
// stream << m_d->m_splitterOrView->saveState();
return bytes;
}
bool UAVGadgetManager::restoreState(const QByteArray &state)
{
// closeAllUAVGadgets(true);
// removeAllSplits();
// QDataStream stream(state);
//
// QByteArray version;
// stream >> version;
//
// if (version != "UAVGadgetManagerV4")
// return false;
//
// QMap<QString, QVariant> uavGadgetstates;
//
// QApplication::setOverrideCursor(Qt::WaitCursor);
//
// stream >> uavGadgetstates;
//
// QMapIterator<QString, QVariant> i(uavGadgetstates);
// while (i.hasNext()) {
// i.next();
// m_d->m_uavGadgetStates.insert(i.key(), i.value());
// }
//
// int uavGadgetCount = 0;
// stream >> uavGadgetCount;
// while (--uavGadgetCount >= 0) {
// QString fileName;
// stream >> fileName;
// QString displayName;
// stream >> displayName;
// QByteArray kind;
// stream >> kind;
//
// if (!fileName.isEmpty() && !displayName.isEmpty()){
// m_d->m_uavGadgetModel->addRestoredUAVGadget(fileName, displayName, kind);
// }
// }
//
// QByteArray splitterstates;
// stream >> splitterstates;
// m_d->m_splitterOrView->restoreState(splitterstates);
//
// // splitting and stuff results in focus trouble, that's why we set the focus again after restoration
// ensureUAVGadgetManagerVisible();
// if (m_d->m_currentUAVGadget) {
// m_d->m_currentUAVGadget->widget()->setFocus();
// } else if (Core::Internal::SplitterOrView *view = currentSplitterOrView()) {
// if (IUAVGadget *e = view->uavGadget())
// e->widget()->setFocus();
// else if (view->view())
// view->view()->setFocus();
// }
//
// QApplication::restoreOverrideCursor();
return true;
}
void UAVGadgetManager::saveSettings()
{
// SettingsDatabase *settings = m_d->m_core->settingsDatabase();
// settings->setValue(QLatin1String(documentStatesKey), m_d->m_uavGadgetStates);
// settings->setValue(QLatin1String(externalUAVGadgetKey), m_d->m_externalUAVGadget);
// settings->setValue(QLatin1String(reloadBehaviorKey), m_d->m_reloadBehavior);
}
void UAVGadgetManager::readSettings()
{
// // Backward compatibility to old locations for these settings
// QSettings *qs = m_d->m_core->settings();
// if (qs->contains(QLatin1String(documentStatesKey))) {
// m_d->m_uavGadgetStates = qs->value(QLatin1String(documentStatesKey))
// .value<QMap<QString, QVariant> >();
// qs->remove(QLatin1String(documentStatesKey));
// }
// if (qs->contains(QLatin1String(externalUAVGadgetKey))) {
// m_d->m_externalUAVGadget = qs->value(QLatin1String(externalUAVGadgetKey)).toString();
// qs->remove(QLatin1String(externalUAVGadgetKey));
// }
//
// SettingsDatabase *settings = m_d->m_core->settingsDatabase();
// if (settings->contains(QLatin1String(documentStatesKey)))
// m_d->m_uavGadgetStates = settings->value(QLatin1String(documentStatesKey))
// .value<QMap<QString, QVariant> >();
// if (settings->contains(QLatin1String(externalUAVGadgetKey)))
// m_d->m_externalUAVGadget = settings->value(QLatin1String(externalUAVGadgetKey)).toString();
//
// if (settings->contains(QLatin1String(reloadBehaviorKey)))
// m_d->m_reloadBehavior = (IFile::ReloadBehavior)settings->value(QLatin1String(reloadBehaviorKey)).toInt();
}
void UAVGadgetManager::split(Qt::Orientation orientation)
{
//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()) {
view->split(orientation);
}
updateActions();
}
void UAVGadgetManager::split()
{
//qDebug() << Q_FUNC_INFO;
split(Qt::Vertical);
}
void UAVGadgetManager::splitSideBySide()
{
//qDebug() << Q_FUNC_INFO;
split(Qt::Horizontal);
}
void UAVGadgetManager::removeCurrentSplit()
{
//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)
return;
closeView(viewToClose->view());
updateActions();
}
void UAVGadgetManager::removeAllSplits()
{
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);
}
void UAVGadgetManager::gotoOtherSplit()
{
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 *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);
}
}
}
}
void UAVGadgetManager::hideToolbars(bool 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 = 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======================
UAVGadgetClosingCoreListener::UAVGadgetClosingCoreListener(UAVGadgetManager *em)
: m_em(em)
{
}
bool UAVGadgetClosingCoreListener::coreAboutToClose()
{
// Do not ask for files to save.
// MainWindow::closeEvent has already done that.
return m_em->closeAllUAVGadgets();
}

View File

@ -0,0 +1,175 @@
/**
******************************************************************************
*
* @file uavgadgetmanager.h
* @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
*/
#ifndef UAVGADGETMANAGER_H
#define UAVGADGETMANAGER_H
#include "../core_global.h"
#include <coreplugin/icorelistener.h>
#include <QtGui/QWidget>
#include <QtCore/QList>
#include <QtCore/QPointer>
QT_BEGIN_NAMESPACE
class QSettings;
class QModelIndex;
QT_END_NAMESPACE
namespace Core {
class IContext;
class ICore;
class IUAVGadget;
class IUAVGadgetFactory;
class IMode;
struct UAVGadgetManagerPrivate;
namespace Internal {
class UAVGadgetView;
class SplitterOrView;
class UAVGadgetClosingCoreListener;
} // namespace Internal
class CORE_EXPORT UAVGadgetManagerPlaceHolder : public QWidget
{
Q_OBJECT
public:
UAVGadgetManagerPlaceHolder(Core::IMode *mode, QWidget *parent = 0);
~UAVGadgetManagerPlaceHolder();
static UAVGadgetManagerPlaceHolder* current();
private slots:
void currentModeChanged(Core::IMode *);
private:
Core::IMode *m_mode;
static UAVGadgetManagerPlaceHolder* m_current;
};
class CORE_EXPORT UAVGadgetManager : public QWidget
{
Q_OBJECT
public:
typedef QList<IUAVGadgetFactory*> UAVGadgetFactoryList;
explicit UAVGadgetManager(ICore *core, QWidget *parent);
virtual ~UAVGadgetManager();
void init();
static UAVGadgetManager *instance() { return m_instance; }
void ensureUAVGadgetManagerVisible();
IUAVGadget *currentUAVGadget() const;
IUAVGadget *activateUAVGadget(IUAVGadget *gadget);
bool closeUAVGadgets(const QList<IUAVGadget *> uavGadgetsToClose);
QByteArray saveState() const;
bool restoreState(const QByteArray &state);
void saveSettings();
void readSettings();
UAVGadgetFactoryList uavGadgetFactories() const;
signals:
public slots:
bool closeAllUAVGadgets();
void closeUAVGadget();
private slots:
void handleContextChange(Core::IContext *context);
void updateActions();
public slots:
void split(Qt::Orientation orientation);
void split();
void splitSideBySide();
void removeCurrentSplit();
void removeAllSplits();
void gotoOtherSplit();
void hideToolbars(bool hide);
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;
static UAVGadgetManager *m_instance;
UAVGadgetManagerPrivate *m_d;
friend class Core::Internal::SplitterOrView;
friend class Core::Internal::UAVGadgetView;
};
} // namespace Core
//===================UAVGadgetClosingCoreListener======================
namespace Core {
namespace Internal {
class UAVGadgetClosingCoreListener : public ICoreListener
{
Q_OBJECT
public:
UAVGadgetClosingCoreListener(UAVGadgetManager *em);
bool uavGadgetAboutToClose(IUAVGadget *gadget);
bool coreAboutToClose();
private:
UAVGadgetManager *m_em;
};
} // namespace Internal
} // namespace Core
#endif // UAVGADGETMANAGER_H

View File

@ -0,0 +1,618 @@
/**
******************************************************************************
*
* @file uavgadgetview.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 "uavgadgetview.h"
#include "uavgadgetmanager.h"
#include "iuavgadget.h"
#include "coreimpl.h"
#include "minisplitter.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
#include <QtCore/QDebug>
#include <QtGui/QApplication>
#include <QtGui/QComboBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QMouseEvent>
#include <QtGui/QPainter>
#include <QtGui/QStyle>
#include <QtGui/QStyleOption>
#include <QtGui/QToolButton>
#include <QtGui/QMenu>
#include <QtGui/QClipboard>
#ifdef Q_WS_MAC
#include <qmacstyle_mac.h>
#endif
Q_DECLARE_METATYPE(Core::IUAVGadget *)
using namespace Core;
using namespace Core::Internal;
// ================UAVGadgetView====================
UAVGadgetView::UAVGadgetView(IUAVGadget *uavGadget, QWidget *parent) :
QWidget(parent),
m_uavGadget(uavGadget),
m_toolBar(new QWidget),
m_defaultToolBar(new QWidget(this)),
m_uavGadgetList(new QComboBox),
m_closeButton(new QToolButton)
{
//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);
m_defaultToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_activeToolBar = m_defaultToolBar;
QHBoxLayout *toolBarLayout = new QHBoxLayout;
toolBarLayout->setMargin(0);
toolBarLayout->setSpacing(0);
toolBarLayout->addWidget(m_defaultToolBar);
m_toolBar->setLayout(toolBarLayout);
m_toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_closeButton->setAutoRaise(true);
m_closeButton->setIcon(QIcon(":/core/images/closebutton.png"));
QHBoxLayout *toplayout = new QHBoxLayout;
toplayout->setSpacing(0);
toplayout->setMargin(0);
toplayout->addWidget(m_uavGadgetList);
toplayout->addWidget(m_toolBar, 1); // Custom toolbar stretches
toplayout->addWidget(m_closeButton);
m_top = new Utils::StyledBar;
m_top->setLayout(toplayout);
tl->addWidget(m_top);
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();
}
UAVGadgetView::~UAVGadgetView()
{
}
bool UAVGadgetView::hasUAVGadget(IUAVGadget *uavGadget) const
{
return (m_uavGadget == uavGadget);
}
void UAVGadgetView::hideToolbar(bool hide)
{
m_top->setHidden(hide);
}
void UAVGadgetView::closeView()
{
// m_top->hide();
UAVGadgetManager *gm = CoreImpl::instance()->uavGadgetManager();
gm->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) {
m_activeToolBar = m_defaultToolBar;
m_activeToolBar->setVisible(true);
}
m_toolBar->layout()->removeWidget(toolBar);
toolBar->setVisible(false);
toolBar->setParent(0);
}
setCurrentUAVGadget(0);
}
IUAVGadget *UAVGadgetView::currentUAVGadget() const
{
//qDebug() << Q_FUNC_INFO;
return m_uavGadget;
}
void UAVGadgetView::setCurrentUAVGadget(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;
}
// m_uavGadgetList->setCurrentIndex(m_model->indexOf(uavGadget).row());
updateToolBar();
}
void UAVGadgetView::updateToolBar()
{
//qDebug() << Q_FUNC_INFO;
if (!m_uavGadget)
return;
QWidget *toolBar = m_uavGadget->toolBar();
if (!toolBar)
toolBar = m_defaultToolBar;
if (m_activeToolBar == toolBar)
return;
toolBar->setVisible(true);
m_activeToolBar->setVisible(false);
m_activeToolBar = toolBar;
}
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);
}*/
}
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(Core::IUAVGadget *uavGadget, bool isRoot)
{
//qDebug() << Q_FUNC_INFO << uavGadget << isRoot;
m_isRoot = isRoot;
// //qDebug() << Q_FUNC_INFO << uavGadget << isRoot;
m_view = new UAVGadgetView(uavGadget);
m_layout = new QStackedLayout(this);
m_splitter = 0;
m_layout->addWidget(m_view);
}
SplitterOrView::~SplitterOrView()
{
delete m_view;
m_view = 0;
delete m_splitter;
m_splitter = 0;
}
void SplitterOrView::mousePressEvent(QMouseEvent *e)
{
//qDebug() << Q_FUNC_INFO;
if (e->button() != Qt::LeftButton)
return;
setFocus(Qt::MouseFocusReason);
CoreImpl::instance()->uavGadgetManager()->setCurrentView(this);
}
void SplitterOrView::paintEvent(QPaintEvent *)
{
// //qDebug() << Q_FUNC_INFO;
if (CoreImpl::instance()->uavGadgetManager()->currentSplitterOrView() != this)
return;
if (!m_view || hasUAVGadgets())
return;
// Discreet indication where an uavGadget would be if there is none
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(Qt::NoPen);
QColor shadeBrush(Qt::black);
shadeBrush.setAlpha(10);
painter.setBrush(shadeBrush);
const int r = 3;
painter.drawRoundedRect(rect().adjusted(r, r, -r, -r), r * 2, r * 2);
#if 0
if (hasFocus()) {
#ifdef Q_WS_MAC
// With QMacStyle, we have to draw our own focus rect, since I didn't find
// a way to draw the nice mac focus rect _inside_ this widget
if (qobject_cast<QMacStyle *>(style())) {
painter.setPen(Qt::DotLine);
painter.setBrush(Qt::NoBrush);
painter.setOpacity(0.75);
painter.drawRect(rect());
} else {
#endif
QStyleOptionFocusRect option;
option.initFrom(this);
option.backgroundColor = palette().color(QPalette::Background);
// Some styles require a certain state flag in order to draw the focus rect
option.state |= QStyle::State_KeyboardFocusChange;
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter);
#ifdef Q_WS_MAC
}
#endif
}
#endif
}
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)))
if (SplitterOrView *result = splitterOrView->findFirstView())
return result;
}
return 0;
}
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;
}
SplitterOrView *SplitterOrView::findView(Core::IUAVGadget *uavGadget)
{
//qDebug() << Q_FUNC_INFO;
if (!uavGadget || hasUAVGadget(uavGadget))
return this;
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->findView(uavGadget))
return result;
}
}
return 0;
}
SplitterOrView *SplitterOrView::findView(UAVGadgetView *view)
{
//qDebug() << Q_FUNC_INFO;
if (view == m_view)
return this;
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->findView(view))
return result;
}
}
return 0;
}
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))) {
if (splitterOrView->hasUAVGadget(uavGadget))
return this;
if (SplitterOrView *result = splitterOrView->findSplitter(uavGadget))
return result;
}
}
}
return 0;
}
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))) {
if (splitterOrView == child)
return this;
if (SplitterOrView *result = splitterOrView->findSplitter(child))
return result;
}
}
}
return 0;
}
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;
}
if (this == view) {
*found = true;
return 0;
}
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->findNextView_helper(view, found))
return result;
}
}
}
return 0;
}
QSize SplitterOrView::minimumSizeHint() const
{
// //qDebug() << Q_FUNC_INFO;
if (m_splitter)
return m_splitter->minimumSizeHint();
return QSize(64, 64);
}
QSplitter *SplitterOrView::takeSplitter()
{
//qDebug() << Q_FUNC_INFO;
QSplitter *oldSplitter = m_splitter;
if (m_splitter)
m_layout->removeWidget(m_splitter);
m_splitter = 0;
return oldSplitter;
}
UAVGadgetView *SplitterOrView::takeView()
{
//qDebug() << Q_FUNC_INFO;
UAVGadgetView *oldView = m_view;
if (m_view)
m_layout->removeWidget(m_view);
m_view = 0;
return oldView;
}
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);
UAVGadgetManager *gm = CoreImpl::instance()->uavGadgetManager();
Core::IUAVGadget *e = m_view->currentUAVGadget();
SplitterOrView *view = 0;
SplitterOrView *otherView = 0;
if (e) {
m_view->removeUAVGadget();
m_splitter->addWidget((view = new SplitterOrView(e)));
m_splitter->addWidget((otherView = new SplitterOrView()));
} else {
m_splitter->addWidget((otherView = new SplitterOrView()));
m_splitter->addWidget((view = new SplitterOrView()));
}
// QWidget *w = m_layout->currentWidget();
m_layout->setCurrentWidget(m_splitter);
// m_layout->removeWidget(w);
if (m_view && !m_isRoot) {
gm->emptyView(m_view);
delete m_view;
m_view = 0;
}
gm->setCurrentView(view);
}
void SplitterOrView::unsplitAll()
{
//qDebug() << Q_FUNC_INFO;
m_splitter->hide();
m_layout->removeWidget(m_splitter); // workaround Qt bug
unsplitAll_helper();
delete m_splitter;
m_splitter = 0;
}
void SplitterOrView::unsplitAll_helper()
{
//qDebug() << Q_FUNC_INFO;
if (!m_isRoot && m_view)
CoreImpl::instance()->uavGadgetManager()->emptyView(m_view);
if (m_splitter) {
for (int i = 0; i < m_splitter->count(); ++i) {
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) {
splitterOrView->unsplitAll_helper();
}
}
}
}
void SplitterOrView::unsplit()
{
//qDebug() << Q_FUNC_INFO;
if (!m_splitter)
return;
Q_ASSERT(m_splitter->count() == 1);
UAVGadgetManager *em = CoreImpl::instance()->uavGadgetManager();
SplitterOrView *childSplitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(0));
QSplitter *oldSplitter = m_splitter;
m_splitter = 0;
if (childSplitterOrView->isSplitter()) {
Q_ASSERT(childSplitterOrView->view() == 0);
m_splitter = childSplitterOrView->takeSplitter();
m_layout->addWidget(m_splitter);
m_layout->setCurrentWidget(m_splitter);
} else {
UAVGadgetView *childView = childSplitterOrView->view();
Q_ASSERT(childView);
if (m_view) {
if (IUAVGadget *e = childView->currentUAVGadget()) {
childView->removeUAVGadget();
m_view->setCurrentUAVGadget(e);
}
em->emptyView(childView);
} else {
m_view = childSplitterOrView->takeView();
m_layout->addWidget(m_view);
}
m_layout->setCurrentWidget(m_view);
}
delete oldSplitter;
em->setCurrentView(findFirstView());
}
QByteArray SplitterOrView::saveState() const
{
QByteArray bytes;
/* QDataStream stream(&bytes, QIODevice::WriteOnly);
if (m_splitter) {
stream << QByteArray("splitter")
<< (qint32)m_splitter->orientation()
<< m_splitter->saveState()
<< static_cast<SplitterOrView*>(m_splitter->widget(0))->saveState()
<< static_cast<SplitterOrView*>(m_splitter->widget(1))->saveState();
} else {
IUAVGadget* e = uavGadget();
UAVGadgetManager *em = CoreImpl::instance()->uavGadgetManager();
if (e && e == em->currentUAVGadget()) {
stream << QByteArray("currentuavGadget")
<< e->file()->fileName() << e->kind() << e->saveState();
} else if (e) {
stream << QByteArray("uavGadget")
<< e->file()->fileName() << e->kind() << e->saveState();
} else {
stream << QByteArray("empty");
}
}*/
return bytes;
}
void SplitterOrView::restoreState(const QByteArray &state)
{
/* QDataStream stream(state);
QByteArray mode;
stream >> mode;
if (mode == "splitter") {
qint32 orientation;
QByteArray splitter, first, second;
stream >> orientation >> splitter >> first >> second;
split((Qt::Orientation)orientation);
m_splitter->restoreState(splitter);
static_cast<SplitterOrView*>(m_splitter->widget(0))->restoreState(first);
static_cast<SplitterOrView*>(m_splitter->widget(1))->restoreState(second);
} else if (mode == "uavGadget" || mode == "currentuavGadget") {
UAVGadgetManager *em = CoreImpl::instance()->uavGadgetManager();
QString fileName;
QByteArray kind;
QByteArray uavGadgetState;
stream >> fileName >> kind >> uavGadgetState;
IUAVGadget *e = em->openUAVGadget(view(), fileName, kind, Core::UAVGadgetManager::IgnoreNavigationHistory
| Core::UAVGadgetManager::NoActivate);
if (!e) {
QModelIndex idx = em->openedUAVGadgetsModel()->firstRestoredUAVGadget();
if (idx.isValid())
em->activateUAVGadget(idx, view(), Core::UAVGadgetManager::IgnoreNavigationHistory
| Core::UAVGadgetManager::NoActivate);
}
if (e) {
e->restoreState(uavGadgetState);
if (mode == "currentuavGadget")
em->setCurrentUAVGadget(e);
}
}*/
}

View File

@ -0,0 +1,152 @@
/**
******************************************************************************
*
* @file uavgadgetview.h
* @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
*/
#ifndef UAVGADGETVIEW_H
#define UAVGADGETVIEW_H
#include <QtCore/QList>
#include <QtCore/QString>
#include <QtCore/QSettings>
#include <QtGui/QWidget>
#include <QtGui/QAction>
#include <QtGui/QSplitter>
#include <QtGui/QVBoxLayout>
#include <QtGui/QStackedLayout>
#include <QtCore/QPointer>
QT_BEGIN_NAMESPACE
class QComboBox;
class QToolButton;
class QLabel;
class QVBoxLayout;
QT_END_NAMESPACE
namespace Utils {
class StyledBar;
}
namespace Core {
class IUAVGadget;
namespace Internal {
class UAVGadgetView : public QWidget
{
Q_OBJECT
public:
UAVGadgetView(IUAVGadget *uavGadget = 0, QWidget *parent = 0);
virtual ~UAVGadgetView();
void removeUAVGadget();
IUAVGadget *currentUAVGadget() const;
void setCurrentUAVGadget(IUAVGadget *uavGadget);
bool hasUAVGadget(IUAVGadget *uavGadget) const;
void hideToolbar(bool hide);
public slots:
void updateActionShortcuts();
void closeView();
private slots:
void listSelectionActivated(int index);
private:
void updateToolBar();
IUAVGadget *m_uavGadget;
QWidget *m_toolBar;
QWidget *m_defaultToolBar;
QWidget *m_currentToolBar;
QWidget *m_activeToolBar;
QComboBox *m_uavGadgetList;
QToolButton *m_closeButton;
Utils::StyledBar *m_top;
QVBoxLayout *tl; // top layout
};
class SplitterOrView : public QWidget
{
Q_OBJECT
public:
SplitterOrView(Core::IUAVGadget *uavGadget = 0, bool root = false);
~SplitterOrView();
void split(Qt::Orientation orientation);
void unsplit();
inline bool isView() const { return m_view != 0; }
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 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 UAVGadgetView *view() const { return m_view; }
inline QSplitter *splitter() const { return m_splitter; }
QSplitter *takeSplitter();
UAVGadgetView *takeView();
QByteArray saveState() const;
void restoreState(const QByteArray &);
SplitterOrView *findView(Core::IUAVGadget *uavGadget);
SplitterOrView *findView(UAVGadgetView *view);
SplitterOrView *findFirstView();
SplitterOrView *findEmptyView();
SplitterOrView *findSplitter(Core::IUAVGadget *uavGadget);
SplitterOrView *findSplitter(SplitterOrView *child);
SplitterOrView *findNextView(SplitterOrView *view);
QSize sizeHint() const { return minimumSizeHint(); }
QSize minimumSizeHint() const;
void unsplitAll();
protected:
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *e);
private:
void unsplitAll_helper();
SplitterOrView *findNextView_helper(SplitterOrView *view, bool *found);
public:
bool m_isRoot;
private:
QStackedLayout *m_layout;
UAVGadgetView *m_view;
QSplitter *m_splitter;
};
}
}
#endif // UAVGADGETVIEW_H

View File

@ -0,0 +1,129 @@
/**
******************************************************************************
*
* @file uavgadgetmode.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 "uavgadgetmode.h"
#include "uavgadgetmanager.h"
#include "coreconstants.h"
#include "modemanager.h"
#include "uniqueidmanager.h"
#include "minisplitter.h"
#include "outputpane.h"
#include "rightpane.h"
#include "iuavgadget.h"
#include <QtCore/QLatin1String>
#include <QtGui/QIcon>
#include <QtGui/QHBoxLayout>
#include <QtGui/QWidget>
#include <QtGui/QSplitter>
using namespace Core;
using namespace Core::Internal;
UAVGadgetMode::UAVGadgetMode(UAVGadgetManager *uavGadgetManager) :
m_uavGadgetManager(uavGadgetManager),
m_widget(new QWidget),
m_layout(new QVBoxLayout)
{
m_layout->setSpacing(0);
m_layout->setMargin(0);
m_widget->setLayout(m_layout);
m_layout->insertWidget(0, new Core::UAVGadgetManagerPlaceHolder(this));
// MiniSplitter *rightPaneSplitter = new MiniSplitter;
// rightPaneSplitter->insertWidget(0, rightSplitWidget);
// rightPaneSplitter->insertWidget(1, new RightPanePlaceHolder(this));
// rightPaneSplitter->setStretchFactor(0, 1);
// rightPaneSplitter->setStretchFactor(1, 0);
//
// MiniSplitter *splitter = new MiniSplitter;
// splitter->setOrientation(Qt::Vertical);
// splitter->insertWidget(0, rightPaneSplitter);
// splitter->insertWidget(1, new Core::OutputPanePlaceHolder(this));
// splitter->setStretchFactor(0, 3);
// splitter->setStretchFactor(1, 0);
//
// m_splitter->insertWidget(0, new NavigationWidgetPlaceHolder(this));
// m_splitter->insertWidget(1, splitter);
// m_splitter->setStretchFactor(0, 0);
// m_splitter->setStretchFactor(1, 1);
ModeManager *modeManager = ModeManager::instance();
connect(modeManager, SIGNAL(currentModeChanged(Core::IMode*)),
this, SLOT(grabUAVGadgetManager(Core::IMode*)));
m_widget->setFocusProxy(m_uavGadgetManager);
}
UAVGadgetMode::~UAVGadgetMode()
{
// Make sure the uavGadget manager does not get deleted
m_uavGadgetManager->setParent(0);
delete m_widget;
}
QString UAVGadgetMode::name() const
{
return tr("UavGadget");
}
QIcon UAVGadgetMode::icon() const
{
return QIcon(QLatin1String(":/core/images/openpilot_logo_64.png"));
}
int UAVGadgetMode::priority() const
{
return Constants::P_MODE_UAVGADGET;
}
QWidget* UAVGadgetMode::widget()
{
return m_widget;
}
const char* UAVGadgetMode::uniqueModeName() const
{
return Constants::MODE_UAVGADGET;
}
QList<int> UAVGadgetMode::context() const
{
static QList<int> contexts = QList<int>() <<
UniqueIDManager::instance()->uniqueIdentifier(Constants::C_UAVGADGET_MODE) <<
UniqueIDManager::instance()->uniqueIdentifier(Constants::C_UAVGADGETMANAGER);
return contexts;
}
void UAVGadgetMode::grabUAVGadgetManager(Core::IMode *mode)
{
if (mode != this)
return;
if (m_uavGadgetManager->currentUAVGadget())
m_uavGadgetManager->currentUAVGadget()->widget()->setFocus();
}

View File

@ -0,0 +1,76 @@
/**
******************************************************************************
*
* @file uavgadgetmode.h
* @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
*/
#ifndef UAVGADGETMODE_H
#define UAVGADGETMODE_H
#include <coreplugin/imode.h>
#include <QtCore/QObject>
QT_BEGIN_NAMESPACE
class QSplitter;
class QWidget;
class QVBoxLayout;
QT_END_NAMESPACE
namespace Core {
class UAVGadgetManager;
namespace Internal {
class UAVGadgetMode : public Core::IMode
{
Q_OBJECT
public:
UAVGadgetMode(UAVGadgetManager *uavGadgetManager);
~UAVGadgetMode();
// IMode
QString name() const;
QIcon icon() const;
int priority() const;
QWidget* widget();
const char* uniqueModeName() const;
QList<int> context() const;
private slots:
void grabUAVGadgetManager(Core::IMode *mode);
private:
UAVGadgetManager *m_uavGadgetManager;
QWidget *m_widget;
QVBoxLayout *m_layout;
};
} // namespace Internal
} // namespace Core
#endif // UAVGADGETMODE_H