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

GCS/coreplugin: Changes to remember layout of views when GCS is closed.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@359 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-03-21 16:50:00 +00:00 committed by ephy
parent 20f29b40e4
commit bfdeb32fef
12 changed files with 177 additions and 219 deletions

View File

@ -41,7 +41,6 @@ using namespace Core::Internal;
CorePlugin::CorePlugin() : CorePlugin::CorePlugin() :
m_mainWindow(new MainWindow) m_mainWindow(new MainWindow)
// m_uavGadgetMode(0)
{ {
} }
@ -69,21 +68,27 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
void CorePlugin::extensionsInitialized() void CorePlugin::extensionsInitialized()
{ {
// Workspace 1
UAVGadgetMode *uavGadgetMode; UAVGadgetMode *uavGadgetMode;
UAVGadgetManager *m_uavGadgetManager = new UAVGadgetManager(CoreImpl::instance(), m_mainWindow); UAVGadgetManager *m_uavGadgetManager;
m_uavGadgetManager = new UAVGadgetManager(CoreImpl::instance(), m_mainWindow);
m_uavGadgetManager->hide(); m_uavGadgetManager->hide();
uavGadgetMode = new UAVGadgetMode(m_uavGadgetManager, QString("Mode 1"), uavGadgetMode = new UAVGadgetMode(m_uavGadgetManager, QString(tr("Workspace 1")),
QIcon(":/core/images/openpilot_logo_64.png"), 90, QString("Mode1")); QIcon(":/core/images/openpilot_logo_64.png"), 90, QString("Mode1"));
m_uavGadgetManager->setUAVGadgetMode(uavGadgetMode); m_uavGadgetManager->setUAVGadgetMode(uavGadgetMode);
m_uavGadgetModes.append(uavGadgetMode); m_uavGadgetModes.append(uavGadgetMode);
addObject(uavGadgetMode); addObject(uavGadgetMode);
m_mainWindow->addUAVGadgetManager(m_uavGadgetManager);
// Workspace 2
m_uavGadgetManager = new UAVGadgetManager(CoreImpl::instance(), m_mainWindow); m_uavGadgetManager = new UAVGadgetManager(CoreImpl::instance(), m_mainWindow);
m_uavGadgetManager->hide(); m_uavGadgetManager->hide();
uavGadgetMode = new UAVGadgetMode(m_uavGadgetManager, QString("Mode 2"), uavGadgetMode = new UAVGadgetMode(m_uavGadgetManager, QString(tr("Workspace 2")),
QIcon(":/core/images/plus.png"), 60, QString("Mode2")); QIcon(":/core/images/plus.png"), 60, QString("Mode2"));
m_uavGadgetManager->setUAVGadgetMode(uavGadgetMode); m_uavGadgetManager->setUAVGadgetMode(uavGadgetMode);
m_uavGadgetModes.append(uavGadgetMode); m_uavGadgetModes.append(uavGadgetMode);
addObject(uavGadgetMode); addObject(uavGadgetMode);
m_mainWindow->addUAVGadgetManager(m_uavGadgetManager);
m_mainWindow->extensionsInitialized(); m_mainWindow->extensionsInitialized();
} }

View File

@ -79,9 +79,9 @@ QSize FancyTabBar::tabSizeHint(bool minimum) const
boldFont.setBold(true); boldFont.setBold(true);
QFontMetrics fm(boldFont); QFontMetrics fm(boldFont);
int spacing = 6; int spacing = 6;
int width = 60 + spacing + 2; int width = 90 + spacing + 2;
int iconHeight = minimum ? 0 : 32; int iconHeight = minimum ? 0 : 16;
return QSize(width, iconHeight + spacing + fm.height()); return QSize(width, iconHeight + spacing + fm.height());
} }

View File

@ -48,15 +48,16 @@ public:
virtual QList<int> context() const = 0; virtual QList<int> context() const = 0;
virtual QWidget *widget() = 0; virtual QWidget *widget() = 0;
virtual QString contextHelpId() const { return QString(); } virtual QString contextHelpId() const { return QString(); }
virtual QString gadgetKind() { return m_gadgetKind; }
// virtual void saveConfiguration() = 0; // virtual void saveConfiguration() = 0;
// virtual void loadConfiguration(QString ) = 0; // virtual void loadConfiguration(QString ) = 0;
// virtual QStringList getConfigurationNames() = 0; // virtual QStringList getConfigurationNames() = 0;
virtual QWidget *toolBar() = 0; virtual QWidget *toolBar() = 0;
virtual void setIndex(int index) { m_index = index; } virtual QByteArray saveState() { return 0; }
virtual int index() { return m_index; } virtual void restoreState(QByteArray state) { }
private: protected:
int m_index; QString m_gadgetKind;
}; };
} // namespace Core } // namespace Core

View File

@ -48,7 +48,11 @@ public:
virtual ~IUAVGadgetFactory() {} virtual ~IUAVGadgetFactory() {}
virtual IUAVGadget *createUAVGadget(QWidget *parent) = 0; virtual IUAVGadget *createUAVGadget(QWidget *parent) = 0;
virtual QString name() = 0; virtual QString gadgetKind() const { return m_gadgetKind; }
virtual QString name() const { return m_name; }
protected:
QString m_name;
QString m_gadgetKind;
}; };
} // namespace Core } // namespace Core

View File

@ -113,7 +113,6 @@ MainWindow::MainWindow() :
m_variableManager(new VariableManager(this)), m_variableManager(new VariableManager(this)),
m_viewManager(0), m_viewManager(0),
m_modeManager(0), m_modeManager(0),
m_uavGadgetManager(0),
m_connectionManager(0), m_connectionManager(0),
m_mimeDatabase(new MimeDatabase), m_mimeDatabase(new MimeDatabase),
// m_rightPaneWidget(0), // m_rightPaneWidget(0),
@ -172,8 +171,6 @@ MainWindow::MainWindow() :
m_viewManager = new ViewManager(this); m_viewManager = new ViewManager(this);
m_messageManager = new MessageManager; m_messageManager = new MessageManager;
// m_uavGadgetManager = new UAVGadgetManager(m_coreImpl, this);
// m_uavGadgetManager->hide();
setCentralWidget(m_modeStack); setCentralWidget(m_modeStack);
connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*,QWidget*)), connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*,QWidget*)),
@ -728,15 +725,20 @@ VariableManager *MainWindow::variableManager() const
return m_variableManager; return m_variableManager;
} }
ConnectionManager *MainWindow::connectionManager() const ConnectionManager *MainWindow::connectionManager() const
{ {
return m_connectionManager; return m_connectionManager;
} }
UAVGadgetManager *MainWindow::uavGadgetManager() const void MainWindow::addUAVGadgetManager(UAVGadgetManager *manager)
{ {
return m_uavGadgetManager; if (!m_uavGadgetManagers.contains(manager))
m_uavGadgetManagers.append(manager);
}
QList<UAVGadgetManager*> MainWindow::uavGadgetManagers() const
{
return m_uavGadgetManagers;
} }
ModeManager *MainWindow::modeManager() const ModeManager *MainWindow::modeManager() const
@ -870,7 +872,7 @@ void MainWindow::readSettings()
if (geom.isValid()) { if (geom.isValid()) {
setGeometry(geom.toRect()); setGeometry(geom.toRect());
} else { } else {
resize(1024, 700); resize(750, 400);
} }
if (m_settings->value(QLatin1String(maxKey), false).toBool()) if (m_settings->value(QLatin1String(maxKey), false).toBool())
setWindowState(Qt::WindowMaximized); setWindowState(Qt::WindowMaximized);
@ -878,6 +880,9 @@ void MainWindow::readSettings()
m_settings->endGroup(); m_settings->endGroup();
foreach (UAVGadgetManager *manager, m_uavGadgetManagers) {
manager->readSettings();
}
// m_rightPaneWidget->readSettings(m_settings); // m_rightPaneWidget->readSettings(m_settings);
} }
@ -900,6 +905,9 @@ void MainWindow::writeSettings()
m_viewManager->saveSettings(m_settings); m_viewManager->saveSettings(m_settings);
m_actionManager->saveSettings(m_settings); m_actionManager->saveSettings(m_settings);
foreach (UAVGadgetManager *manager, m_uavGadgetManagers) {
manager->saveSettings();
}
} }
void MainWindow::addAdditionalContext(int context) void MainWindow::addAdditionalContext(int context)

View File

@ -92,7 +92,8 @@ public:
Core::ActionManager *actionManager() const; Core::ActionManager *actionManager() const;
Core::UniqueIDManager *uniqueIDManager() const; Core::UniqueIDManager *uniqueIDManager() const;
Core::MessageManager *messageManager() const; Core::MessageManager *messageManager() const;
Core::UAVGadgetManager *uavGadgetManager() const; void addUAVGadgetManager(Core::UAVGadgetManager *manager);
QList<Core::UAVGadgetManager*> uavGadgetManagers() const;
Core::ConnectionManager *connectionManager() const; Core::ConnectionManager *connectionManager() const;
Core::VariableManager *variableManager() const; Core::VariableManager *variableManager() const;
Core::ModeManager *modeManager() const; Core::ModeManager *modeManager() const;
@ -166,7 +167,7 @@ private:
VariableManager *m_variableManager; VariableManager *m_variableManager;
ViewManager *m_viewManager; ViewManager *m_viewManager;
ModeManager *m_modeManager; ModeManager *m_modeManager;
UAVGadgetManager *m_uavGadgetManager; QList<UAVGadgetManager*> m_uavGadgetManagers;
ConnectionManager *m_connectionManager; ConnectionManager *m_connectionManager;
MimeDatabase *m_mimeDatabase; MimeDatabase *m_mimeDatabase;
FancyTabWidget *m_modeStack; FancyTabWidget *m_modeStack;

View File

@ -113,7 +113,7 @@ void UAVGadgetManagerPlaceHolder::currentModeChanged(Core::IMode *mode)
if (m_mode == mode) { if (m_mode == mode) {
m_current = this; m_current = this;
layout()->addWidget(gm); layout()->addWidget(gm);
gm->hideToolbars(gm->toolbarsHidden()); gm->showToolbars(gm->toolbarsShown());
gm->show(); gm->show();
} }
} }
@ -133,7 +133,7 @@ struct UAVGadgetManagerPrivate {
ICore *m_core; ICore *m_core;
// actions // actions
static QAction *m_hideToolbarsAction; static QAction *m_showToolbarsAction;
static QAction *m_splitAction; static QAction *m_splitAction;
static QAction *m_splitSideBySideAction; static QAction *m_splitSideBySideAction;
static QAction *m_removeCurrentSplitAction; static QAction *m_removeCurrentSplitAction;
@ -144,7 +144,7 @@ struct UAVGadgetManagerPrivate {
}; };
} }
QAction *UAVGadgetManagerPrivate::m_hideToolbarsAction = 0; QAction *UAVGadgetManagerPrivate::m_showToolbarsAction = 0;
QAction *UAVGadgetManagerPrivate::m_splitAction = 0; QAction *UAVGadgetManagerPrivate::m_splitAction = 0;
QAction *UAVGadgetManagerPrivate::m_splitSideBySideAction = 0; QAction *UAVGadgetManagerPrivate::m_splitSideBySideAction = 0;
QAction *UAVGadgetManagerPrivate::m_removeCurrentSplitAction = 0; QAction *UAVGadgetManagerPrivate::m_removeCurrentSplitAction = 0;
@ -165,7 +165,7 @@ UAVGadgetManagerPrivate::~UAVGadgetManagerPrivate()
UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) : UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
QWidget(parent), QWidget(parent),
m_hidden(false), m_showToolbars(false),
m_d(new UAVGadgetManagerPrivate(core, parent)) m_d(new UAVGadgetManagerPrivate(core, parent))
{ {
@ -180,13 +180,13 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
ActionContainer *mwindow = am->actionContainer(Constants::M_WINDOW); ActionContainer *mwindow = am->actionContainer(Constants::M_WINDOW);
Command *cmd; Command *cmd;
// The actions m_d->m_hideToolbarsAction etc are common to all instances of UAVGadgetManager // The actions m_d->m_showToolbarsAction etc are common to all instances of UAVGadgetManager
// which means that they share the menu items/signals in the Window menu. // 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 // 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. // 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 // The first UAVGadgetManager creates the actions, and the following just use them
// (This also implies that they share the same context.) // (This also implies that they share the same context.)
if (m_d->m_hideToolbarsAction == 0) if (m_d->m_showToolbarsAction == 0)
{ {
//Window menu separators //Window menu separators
QAction *tmpaction = new QAction(this); QAction *tmpaction = new QAction(this);
@ -194,9 +194,9 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
cmd = am->registerAction(tmpaction, QLatin1String("OpenPilot.Window.Sep.Split"), uavGadgetManagerContext); cmd = am->registerAction(tmpaction, QLatin1String("OpenPilot.Window.Sep.Split"), uavGadgetManagerContext);
mwindow->addAction(cmd, Constants::G_WINDOW_HIDE_TOOLBAR); mwindow->addAction(cmd, Constants::G_WINDOW_HIDE_TOOLBAR);
m_d->m_hideToolbarsAction = new QAction(tr("Hide toolbars"), this); m_d->m_showToolbarsAction = new QAction(tr("Show toolbars"), this);
m_d->m_hideToolbarsAction->setCheckable(true); m_d->m_showToolbarsAction->setCheckable(true);
cmd = am->registerAction(m_d->m_hideToolbarsAction, Constants::HIDE_TOOLBARS, uavGadgetManagerContext); cmd = am->registerAction(m_d->m_showToolbarsAction, Constants::HIDE_TOOLBARS, uavGadgetManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F10"))); cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F10")));
mwindow->addAction(cmd, Constants::G_WINDOW_HIDE_TOOLBAR); mwindow->addAction(cmd, Constants::G_WINDOW_HIDE_TOOLBAR);
@ -206,7 +206,7 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
cmd = am->registerAction(tmpaction2, QLatin1String("OpenPilot.Window.Sep.Split2"), uavGadgetManagerContext); cmd = am->registerAction(tmpaction2, QLatin1String("OpenPilot.Window.Sep.Split2"), uavGadgetManagerContext);
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT); mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
} }
connect(m_d->m_hideToolbarsAction, SIGNAL(triggered(bool)), this, SLOT(hideToolbars(bool))); connect(m_d->m_showToolbarsAction, SIGNAL(triggered(bool)), this, SLOT(showToolbars(bool)));
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
QString prefix = tr("Meta+Shift"); QString prefix = tr("Meta+Shift");
@ -269,6 +269,7 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
layout->setSpacing(0); layout->setSpacing(0);
layout->addWidget(m_d->m_splitterOrView); layout->addWidget(m_d->m_splitterOrView);
showToolbars(m_showToolbars);
updateActions(); updateActions();
} }
@ -410,11 +411,11 @@ void UAVGadgetManager::updateActions()
if (!m_d->m_splitterOrView) // this is only for startup if (!m_d->m_splitterOrView) // this is only for startup
return; return;
// Splitting is only possible when the toolbars are shown // Splitting is only possible when the toolbars are shown
bool hidden = m_d->m_hideToolbarsAction->isChecked(); bool shown = m_d->m_showToolbarsAction->isChecked();
bool hasSplitter = m_d->m_splitterOrView->isSplitter(); bool hasSplitter = m_d->m_splitterOrView->isSplitter();
m_d->m_removeCurrentSplitAction->setEnabled(!hidden && hasSplitter); m_d->m_removeCurrentSplitAction->setEnabled(shown && hasSplitter);
m_d->m_removeAllSplitsAction->setEnabled(!hidden && hasSplitter); m_d->m_removeAllSplitsAction->setEnabled(shown && hasSplitter);
m_d->m_gotoOtherSplitAction->setEnabled(!hidden && hasSplitter); m_d->m_gotoOtherSplitAction->setEnabled(shown && hasSplitter);
} }
UAVGadgetFactoryList UAVGadgetManager::uavGadgetFactories() const UAVGadgetFactoryList UAVGadgetManager::uavGadgetFactories() const
@ -428,123 +429,74 @@ UAVGadgetFactoryList UAVGadgetManager::uavGadgetFactories() const
QByteArray UAVGadgetManager::saveState() const QByteArray UAVGadgetManager::saveState() const
{ {
QByteArray bytes; QByteArray bytes;
// QDataStream stream(&bytes, QIODevice::WriteOnly); QDataStream stream(&bytes, QIODevice::WriteOnly);
//
// stream << QByteArray("UAVGadgetManagerV4"); stream << QByteArray("UAVGadgetManagerV1");
//
// QList<IUAVGadget *> uavGadgets = openedUAVGadgets(); stream << m_showToolbars;
// foreach (IUAVGadget *uavGadget, uavGadgets) {
// if (!uavGadget->file()->fileName().isEmpty()) { stream << m_d->m_splitterOrView->saveState();
// 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; return bytes;
} }
bool UAVGadgetManager::restoreState(const QByteArray &state) bool UAVGadgetManager::restoreState(const QByteArray &state)
{ {
// closeAllUAVGadgets(true); removeAllSplits();
// removeAllSplits(); emptyView(m_d->m_splitterOrView->view());
// QDataStream stream(state); QDataStream stream(state);
// qDebug() << Q_FUNC_INFO;
// QByteArray version;
// stream >> version; QByteArray version;
// stream >> version;
// if (version != "UAVGadgetManagerV4")
// return false; if (version != "UAVGadgetManagerV1")
// return false;
// QMap<QString, QVariant> uavGadgetstates;
// stream >> m_showToolbars;
// QApplication::setOverrideCursor(Qt::WaitCursor);
// QApplication::setOverrideCursor(Qt::WaitCursor);
// stream >> uavGadgetstates;
// QByteArray splitterstates;
// QMapIterator<QString, QVariant> i(uavGadgetstates); stream >> splitterstates;
// while (i.hasNext()) { m_d->m_splitterOrView->restoreState(splitterstates);
// i.next();
// m_d->m_uavGadgetStates.insert(i.key(), i.value()); QApplication::restoreOverrideCursor();
// }
//
// 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; return true;
} }
void UAVGadgetManager::saveSettings() void UAVGadgetManager::saveSettings()
{ {
// SettingsDatabase *settings = m_d->m_core->settingsDatabase(); QString defaultUAVGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/DefaultSettings";
// settings->setValue(QLatin1String(documentStatesKey), m_d->m_uavGadgetStates); QString uavGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/Settings";
// settings->setValue(QLatin1String(externalUAVGadgetKey), m_d->m_externalUAVGadget);
// settings->setValue(QLatin1String(reloadBehaviorKey), m_d->m_reloadBehavior); QSettings *qs = m_d->m_core->settings();
// The idea is to have a default setting that is only written once
if (!qs->contains(defaultUAVGadgetManagerKey.toLatin1()))
qs->setValue(defaultUAVGadgetManagerKey.toLatin1(), saveState().toBase64());
else
qs->setValue(uavGadgetManagerKey.toLatin1(), saveState().toBase64());
} }
void UAVGadgetManager::readSettings() void UAVGadgetManager::readSettings()
{ {
// // Backward compatibility to old locations for these settings QString defaultUAVGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/DefaultSettings";
// QSettings *qs = m_d->m_core->settings(); QString uavGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/Settings";
// if (qs->contains(QLatin1String(documentStatesKey))) {
// m_d->m_uavGadgetStates = qs->value(QLatin1String(documentStatesKey)) QSettings *qs = m_d->m_core->settings();
// .value<QMap<QString, QVariant> >(); QString key("");
// qs->remove(QLatin1String(documentStatesKey)); if (qs->contains(uavGadgetManagerKey.toLatin1()))
// } key = uavGadgetManagerKey.toLatin1();
// if (qs->contains(QLatin1String(externalUAVGadgetKey))) { else if (qs->contains(defaultUAVGadgetManagerKey.toLatin1()))
// m_d->m_externalUAVGadget = qs->value(QLatin1String(externalUAVGadgetKey)).toString(); key = defaultUAVGadgetManagerKey.toLatin1();
// qs->remove(QLatin1String(externalUAVGadgetKey)); else
// } return;
// const QVariant &managerSettings = qs->value(key);
// SettingsDatabase *settings = m_d->m_core->settingsDatabase(); restoreState(QByteArray::fromBase64(managerSettings.toByteArray()));
// if (settings->contains(QLatin1String(documentStatesKey))) showToolbars(m_showToolbars);
// m_d->m_uavGadgetStates = settings->value(QLatin1String(documentStatesKey)) updateActions();
// .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) void UAVGadgetManager::split(Qt::Orientation orientation)
@ -616,24 +568,24 @@ void UAVGadgetManager::gotoOtherSplit()
} }
} }
void UAVGadgetManager::hideToolbars(bool hide) void UAVGadgetManager::showToolbars(bool show)
{ {
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode) if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
return; return;
m_d->m_hideToolbarsAction->setChecked(hide); m_d->m_showToolbarsAction->setChecked(show);
m_hidden = hide; m_showToolbars = show;
SplitterOrView *next = m_d->m_splitterOrView->findFirstView(); SplitterOrView *next = m_d->m_splitterOrView->findFirstView();
do { do {
next->view()->hideToolbar(hide); next->view()->showToolbar(show);
next = m_d->m_splitterOrView->findNextView(next); next = m_d->m_splitterOrView->findNextView(next);
} while (next); } while (next);
m_d->m_splitAction->setEnabled(!hide); m_d->m_splitAction->setEnabled(show);
m_d->m_splitSideBySideAction->setEnabled(!hide); m_d->m_splitSideBySideAction->setEnabled(show);
m_d->m_removeCurrentSplitAction->setEnabled(!hide); m_d->m_removeCurrentSplitAction->setEnabled(show);
m_d->m_removeAllSplitsAction->setEnabled(!hide); m_d->m_removeAllSplitsAction->setEnabled(show);
m_d->m_gotoOtherSplitAction->setEnabled(!hide); m_d->m_gotoOtherSplitAction->setEnabled(show);
} }
//===================UAVGadgetClosingCoreListener====================== //===================UAVGadgetClosingCoreListener======================

View File

@ -103,7 +103,7 @@ public:
void saveSettings(); void saveSettings();
void readSettings(); void readSettings();
bool toolbarsHidden() { return m_hidden; } bool toolbarsShown() { return m_showToolbars; }
UAVGadgetFactoryList uavGadgetFactories() const; UAVGadgetFactoryList uavGadgetFactories() const;
@ -120,7 +120,7 @@ public slots:
void removeCurrentSplit(); void removeCurrentSplit();
void removeAllSplits(); void removeAllSplits();
void gotoOtherSplit(); void gotoOtherSplit();
void hideToolbars(bool hide); void showToolbars(bool show);
private: private:
void addUAVGadget(IUAVGadget *gadget); void addUAVGadget(IUAVGadget *gadget);
@ -130,7 +130,7 @@ private:
void emptyView(Core::Internal::UAVGadgetView *view); void emptyView(Core::Internal::UAVGadgetView *view);
Core::Internal::SplitterOrView *currentSplitterOrView() const; Core::Internal::SplitterOrView *currentSplitterOrView() const;
bool m_hidden; bool m_showToolbars;
UAVGadgetManagerPrivate *m_d; UAVGadgetManagerPrivate *m_d;
Core::Internal::UAVGadgetMode *m_uavGadgetMode; Core::Internal::UAVGadgetMode *m_uavGadgetMode;

View File

@ -86,8 +86,8 @@ UAVGadgetView::UAVGadgetView(UAVGadgetManager *uavGadgetManager, IUAVGadget *uav
int index = 0; int index = 0;
foreach(Core::IUAVGadgetFactory *factory, fl) foreach(Core::IUAVGadgetFactory *factory, fl)
{ {
m_uavGadgetList->addItem(factory->name()); m_uavGadgetList->addItem(factory->name(), factory->gadgetKind());
if (factory->name() == QString("EmptyGadget")) if (factory->gadgetKind() == QString("EmptyGadget"))
m_defaultIndex = index; m_defaultIndex = index;
++index; ++index;
} }
@ -135,9 +135,9 @@ bool UAVGadgetView::hasUAVGadget(IUAVGadget *uavGadget) const
return (m_uavGadget == uavGadget); return (m_uavGadget == uavGadget);
} }
void UAVGadgetView::hideToolbar(bool hide) void UAVGadgetView::showToolbar(bool show)
{ {
m_top->setHidden(hide); m_top->setHidden(!show);
} }
void UAVGadgetView::closeView() void UAVGadgetView::closeView()
@ -180,7 +180,9 @@ void UAVGadgetView::setUAVGadget(IUAVGadget *uavGadget)
tl->addWidget(m_uavGadget->widget()); tl->addWidget(m_uavGadget->widget());
m_uavGadget->widget()->setParent(this); m_uavGadget->widget()->setParent(this);
m_uavGadget->widget()->show(); m_uavGadget->widget()->show();
m_uavGadgetList->setCurrentIndex(m_uavGadget->index()); int index = indexOfGadgetKind(m_uavGadget->gadgetKind());
Q_ASSERT(index >= 0);
m_uavGadgetList->setCurrentIndex(index);
// updateToolBar(); // updateToolBar();
} }
@ -201,17 +203,22 @@ void UAVGadgetView::updateToolBar()
void UAVGadgetView::listSelectionActivated(int index) void UAVGadgetView::listSelectionActivated(int index)
{ {
if (m_uavGadget && m_uavGadget->index() == index) if (index < 0 || m_uavGadgetManager->uavGadgetFactories().count() == 0)
return;
if (m_uavGadgetManager->uavGadgetFactories().count() == 0)
return; return;
IUAVGadgetFactory *factory = m_uavGadgetManager->uavGadgetFactories().at(index); IUAVGadgetFactory *factory = m_uavGadgetManager->uavGadgetFactories().at(index);
if (m_uavGadget && m_uavGadget->gadgetKind() == factory->gadgetKind())
return;
IUAVGadget *gadget = factory->createUAVGadget(this); IUAVGadget *gadget = factory->createUAVGadget(this);
gadget->setIndex(index);
setUAVGadget(gadget); setUAVGadget(gadget);
m_uavGadgetManager->setCurrentUAVGadget(gadget); m_uavGadgetManager->setCurrentUAVGadget(gadget);
} }
int UAVGadgetView::indexOfGadgetKind(QString gadgetKind)
{
return m_uavGadgetList->findData(gadgetKind);
}
SplitterOrView::SplitterOrView(UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget, bool isRoot) : SplitterOrView::SplitterOrView(UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget, bool isRoot) :
m_uavGadgetManager(uavGadgetManager), m_uavGadgetManager(uavGadgetManager),
m_isRoot(isRoot) m_isRoot(isRoot)
@ -251,7 +258,7 @@ void SplitterOrView::paintEvent(QPaintEvent *event)
// if (hasUAVGadget()) // if (hasUAVGadget())
// return; // return;
if (m_uavGadgetManager->toolbarsHidden()) if (m_uavGadgetManager->toolbarsShown())
return; return;
// Discreet indication where an uavGadget would be if there is none // Discreet indication where an uavGadget would be if there is none
@ -523,64 +530,43 @@ void SplitterOrView::unsplit()
QByteArray SplitterOrView::saveState() const QByteArray SplitterOrView::saveState() const
{ {
QByteArray bytes; QByteArray bytes;
// QDataStream stream(&bytes, QIODevice::WriteOnly); QDataStream stream(&bytes, QIODevice::WriteOnly);
//
// if (m_splitter) { if (m_splitter) {
// stream << QByteArray("splitter") stream << QByteArray("splitter")
// << (qint32)m_splitter->orientation() << (qint32)m_splitter->orientation()
// << m_splitter->saveState() << m_splitter->saveState()
// << static_cast<SplitterOrView*>(m_splitter->widget(0))->saveState() << static_cast<SplitterOrView*>(m_splitter->widget(0))->saveState()
// << static_cast<SplitterOrView*>(m_splitter->widget(1))->saveState(); << static_cast<SplitterOrView*>(m_splitter->widget(1))->saveState();
// } else { } else {
// IUAVGadget* e = uavGadget(); if (uavGadget())
// UAVGadgetManager *em = CoreImpl::instance()->uavGadgetManager(); stream << QByteArray("uavGadget") << uavGadget()->gadgetKind() << uavGadget()->saveState();
// }
// if (e && e == em->uavGadget()) {
// 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; return bytes;
} }
void SplitterOrView::restoreState(const QByteArray &state) void SplitterOrView::restoreState(const QByteArray &state)
{ {
// QDataStream stream(state); QDataStream stream(state);
// QByteArray mode; QByteArray mode;
// stream >> mode; stream >> mode;
// if (mode == "splitter") { if (mode == "splitter") {
// qint32 orientation; qint32 orientation;
// QByteArray splitter, first, second; QByteArray splitter, first, second;
// stream >> orientation >> splitter >> first >> second; stream >> orientation >> splitter >> first >> second;
// split((Qt::Orientation)orientation); split((Qt::Orientation)orientation);
// m_splitter->restoreState(splitter); m_splitter->restoreState(splitter);
// static_cast<SplitterOrView*>(m_splitter->widget(0))->restoreState(first); static_cast<SplitterOrView*>(m_splitter->widget(0))->restoreState(first);
// static_cast<SplitterOrView*>(m_splitter->widget(1))->restoreState(second); static_cast<SplitterOrView*>(m_splitter->widget(1))->restoreState(second);
// } else if (mode == "uavGadget" || mode == "currentuavGadget") { } else if (mode == "uavGadget") {
// UAVGadgetManager *em = CoreImpl::instance()->uavGadgetManager(); QString gadgetKind;
// QString fileName; QByteArray uavGadgetState;
// QByteArray kind; stream >> gadgetKind >> uavGadgetState;
// QByteArray uavGadgetState; m_view = new UAVGadgetView(m_uavGadgetManager, 0);
// stream >> fileName >> kind >> uavGadgetState; int index = m_view->indexOfGadgetKind(gadgetKind);
// IUAVGadget *e = em->openUAVGadget(view(), fileName, kind, Core::UAVGadgetManager::IgnoreNavigationHistory m_view->listSelectionActivated(index);
// | Core::UAVGadgetManager::NoActivate); m_layout->addWidget(m_view);
// m_layout->setCurrentWidget(m_view);
// if (!e) { uavGadget()->restoreState(uavGadgetState);
// 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->setUAVGadget(e);
// }
// }
} }

View File

@ -70,12 +70,11 @@ public:
IUAVGadget *uavGadget() const; IUAVGadget *uavGadget() const;
void setUAVGadget(IUAVGadget *uavGadget); void setUAVGadget(IUAVGadget *uavGadget);
bool hasUAVGadget(IUAVGadget *uavGadget) const; bool hasUAVGadget(IUAVGadget *uavGadget) const;
void hideToolbar(bool hide); int indexOfGadgetKind(QString gadgetKind);
void showToolbar(bool show);
public slots: public slots:
void closeView(); void closeView();
private slots:
void listSelectionActivated(int index); void listSelectionActivated(int index);
private: private:

View File

@ -36,6 +36,7 @@
#include "rightpane.h" #include "rightpane.h"
#include "iuavgadget.h" #include "iuavgadget.h"
#include <QDebug>
#include <QtCore/QLatin1String> #include <QtCore/QLatin1String>
#include <QtGui/QHBoxLayout> #include <QtGui/QHBoxLayout>
#include <QtGui/QWidget> #include <QtGui/QWidget>
@ -66,8 +67,8 @@ UAVGadgetMode::UAVGadgetMode(UAVGadgetManager *uavGadgetManager, QString name, Q
// this shouldn't happen // this shouldn't happen
m_uniqueName = uniqueName + QString::number(quint64(this)); m_uniqueName = uniqueName + QString::number(quint64(this));
} }
QByteArray ba = m_uniqueName.toLatin1(); m_uniqueNameBA = m_uniqueName.toLatin1();
m_uniqueNameC = ba.data(); m_uniqueNameC = m_uniqueNameBA.data();
connect(modeManager, SIGNAL(currentModeChanged(Core::IMode*)), connect(modeManager, SIGNAL(currentModeChanged(Core::IMode*)),
this, SLOT(grabUAVGadgetManager(Core::IMode*))); this, SLOT(grabUAVGadgetManager(Core::IMode*)));
m_widget->setFocusProxy(m_uavGadgetManager); m_widget->setFocusProxy(m_uavGadgetManager);

View File

@ -75,6 +75,7 @@ private:
int m_priority; int m_priority;
QVBoxLayout *m_layout; QVBoxLayout *m_layout;
QString m_uniqueName; QString m_uniqueName;
QByteArray m_uniqueNameBA;
const char *m_uniqueNameC; const char *m_uniqueNameC;
}; };