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() :
m_mainWindow(new MainWindow)
// m_uavGadgetMode(0)
{
}
@ -69,21 +68,27 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
void CorePlugin::extensionsInitialized()
{
// Workspace 1
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();
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"));
m_uavGadgetManager->setUAVGadgetMode(uavGadgetMode);
m_uavGadgetModes.append(uavGadgetMode);
addObject(uavGadgetMode);
m_mainWindow->addUAVGadgetManager(m_uavGadgetManager);
// Workspace 2
m_uavGadgetManager = new UAVGadgetManager(CoreImpl::instance(), m_mainWindow);
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"));
m_uavGadgetManager->setUAVGadgetMode(uavGadgetMode);
m_uavGadgetModes.append(uavGadgetMode);
addObject(uavGadgetMode);
m_mainWindow->addUAVGadgetManager(m_uavGadgetManager);
m_mainWindow->extensionsInitialized();
}

View File

@ -79,9 +79,9 @@ QSize FancyTabBar::tabSizeHint(bool minimum) const
boldFont.setBold(true);
QFontMetrics fm(boldFont);
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());
}
@ -336,7 +336,7 @@ FancyTabWidget::FancyTabWidget(QWidget *parent)
vlayout->setSpacing(0);
vlayout->addLayout(m_modesStack);
vlayout->addWidget(m_selectionWidget);
//vlayout->addWidget(m_statusBar); //status bar is not used for now
// vlayout->addWidget(m_statusBar); //status bar is not used for now
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->setMargin(0);

View File

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

View File

@ -48,7 +48,11 @@ public:
virtual ~IUAVGadgetFactory() {}
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

View File

@ -113,7 +113,6 @@ MainWindow::MainWindow() :
m_variableManager(new VariableManager(this)),
m_viewManager(0),
m_modeManager(0),
m_uavGadgetManager(0),
m_connectionManager(0),
m_mimeDatabase(new MimeDatabase),
// m_rightPaneWidget(0),
@ -172,8 +171,6 @@ MainWindow::MainWindow() :
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*)),
@ -728,15 +725,20 @@ VariableManager *MainWindow::variableManager() const
return m_variableManager;
}
ConnectionManager *MainWindow::connectionManager() const
{
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
@ -870,7 +872,7 @@ void MainWindow::readSettings()
if (geom.isValid()) {
setGeometry(geom.toRect());
} else {
resize(1024, 700);
resize(750, 400);
}
if (m_settings->value(QLatin1String(maxKey), false).toBool())
setWindowState(Qt::WindowMaximized);
@ -878,7 +880,10 @@ void MainWindow::readSettings()
m_settings->endGroup();
// m_rightPaneWidget->readSettings(m_settings);
foreach (UAVGadgetManager *manager, m_uavGadgetManagers) {
manager->readSettings();
}
// m_rightPaneWidget->readSettings(m_settings);
}
void MainWindow::writeSettings()
@ -900,6 +905,9 @@ void MainWindow::writeSettings()
m_viewManager->saveSettings(m_settings);
m_actionManager->saveSettings(m_settings);
foreach (UAVGadgetManager *manager, m_uavGadgetManagers) {
manager->saveSettings();
}
}
void MainWindow::addAdditionalContext(int context)

View File

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

View File

@ -113,7 +113,7 @@ void UAVGadgetManagerPlaceHolder::currentModeChanged(Core::IMode *mode)
if (m_mode == mode) {
m_current = this;
layout()->addWidget(gm);
gm->hideToolbars(gm->toolbarsHidden());
gm->showToolbars(gm->toolbarsShown());
gm->show();
}
}
@ -133,7 +133,7 @@ struct UAVGadgetManagerPrivate {
ICore *m_core;
// actions
static QAction *m_hideToolbarsAction;
static QAction *m_showToolbarsAction;
static QAction *m_splitAction;
static QAction *m_splitSideBySideAction;
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_splitSideBySideAction = 0;
QAction *UAVGadgetManagerPrivate::m_removeCurrentSplitAction = 0;
@ -165,7 +165,7 @@ UAVGadgetManagerPrivate::~UAVGadgetManagerPrivate()
UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
QWidget(parent),
m_hidden(false),
m_showToolbars(false),
m_d(new UAVGadgetManagerPrivate(core, parent))
{
@ -180,13 +180,13 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
ActionContainer *mwindow = am->actionContainer(Constants::M_WINDOW);
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.
// That is, they all connect their slots to the same signal and have to check in the slot
// if the current mode is their mode, otherwise they just ignore the signal.
// The first UAVGadgetManager creates the actions, and the following just use them
// (This also implies that they share the same context.)
if (m_d->m_hideToolbarsAction == 0)
if (m_d->m_showToolbarsAction == 0)
{
//Window menu separators
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);
mwindow->addAction(cmd, Constants::G_WINDOW_HIDE_TOOLBAR);
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);
m_d->m_showToolbarsAction = new QAction(tr("Show toolbars"), this);
m_d->m_showToolbarsAction->setCheckable(true);
cmd = am->registerAction(m_d->m_showToolbarsAction, Constants::HIDE_TOOLBARS, uavGadgetManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F10")));
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);
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
QString prefix = tr("Meta+Shift");
@ -269,6 +269,7 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
layout->setSpacing(0);
layout->addWidget(m_d->m_splitterOrView);
showToolbars(m_showToolbars);
updateActions();
}
@ -410,11 +411,11 @@ void UAVGadgetManager::updateActions()
if (!m_d->m_splitterOrView) // this is only for startup
return;
// Splitting is only possible when the toolbars are shown
bool hidden = m_d->m_hideToolbarsAction->isChecked();
bool shown = m_d->m_showToolbarsAction->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);
m_d->m_removeCurrentSplitAction->setEnabled(shown && hasSplitter);
m_d->m_removeAllSplitsAction->setEnabled(shown && hasSplitter);
m_d->m_gotoOtherSplitAction->setEnabled(shown && hasSplitter);
}
UAVGadgetFactoryList UAVGadgetManager::uavGadgetFactories() const
@ -428,123 +429,74 @@ UAVGadgetFactoryList UAVGadgetManager::uavGadgetFactories() const
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();
QDataStream stream(&bytes, QIODevice::WriteOnly);
stream << QByteArray("UAVGadgetManagerV1");
stream << m_showToolbars;
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();
removeAllSplits();
emptyView(m_d->m_splitterOrView->view());
QDataStream stream(state);
qDebug() << Q_FUNC_INFO;
QByteArray version;
stream >> version;
if (version != "UAVGadgetManagerV1")
return false;
stream >> m_showToolbars;
QApplication::setOverrideCursor(Qt::WaitCursor);
QByteArray splitterstates;
stream >> splitterstates;
m_d->m_splitterOrView->restoreState(splitterstates);
QApplication::restoreOverrideCursor();
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);
QString defaultUAVGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/DefaultSettings";
QString uavGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/Settings";
QSettings *qs = m_d->m_core->settings();
// The idea is to have a default setting that is only written once
if (!qs->contains(defaultUAVGadgetManagerKey.toLatin1()))
qs->setValue(defaultUAVGadgetManagerKey.toLatin1(), saveState().toBase64());
else
qs->setValue(uavGadgetManagerKey.toLatin1(), saveState().toBase64());
}
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();
QString defaultUAVGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/DefaultSettings";
QString uavGadgetManagerKey = QString("UAVGadgetManager/") + m_uavGadgetMode->uniqueModeName() + "/Settings";
QSettings *qs = m_d->m_core->settings();
QString key("");
if (qs->contains(uavGadgetManagerKey.toLatin1()))
key = uavGadgetManagerKey.toLatin1();
else if (qs->contains(defaultUAVGadgetManagerKey.toLatin1()))
key = defaultUAVGadgetManagerKey.toLatin1();
else
return;
const QVariant &managerSettings = qs->value(key);
restoreState(QByteArray::fromBase64(managerSettings.toByteArray()));
showToolbars(m_showToolbars);
updateActions();
}
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)
return;
m_d->m_hideToolbarsAction->setChecked(hide);
m_hidden = hide;
m_d->m_showToolbarsAction->setChecked(show);
m_showToolbars = show;
SplitterOrView *next = m_d->m_splitterOrView->findFirstView();
do {
next->view()->hideToolbar(hide);
next->view()->showToolbar(show);
next = m_d->m_splitterOrView->findNextView(next);
} while (next);
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->setEnabled(show);
m_d->m_splitSideBySideAction->setEnabled(show);
m_d->m_removeCurrentSplitAction->setEnabled(show);
m_d->m_removeAllSplitsAction->setEnabled(show);
m_d->m_gotoOtherSplitAction->setEnabled(show);
}
//===================UAVGadgetClosingCoreListener======================

View File

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

View File

@ -86,8 +86,8 @@ UAVGadgetView::UAVGadgetView(UAVGadgetManager *uavGadgetManager, IUAVGadget *uav
int index = 0;
foreach(Core::IUAVGadgetFactory *factory, fl)
{
m_uavGadgetList->addItem(factory->name());
if (factory->name() == QString("EmptyGadget"))
m_uavGadgetList->addItem(factory->name(), factory->gadgetKind());
if (factory->gadgetKind() == QString("EmptyGadget"))
m_defaultIndex = index;
++index;
}
@ -135,9 +135,9 @@ bool UAVGadgetView::hasUAVGadget(IUAVGadget *uavGadget) const
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()
@ -180,7 +180,9 @@ void UAVGadgetView::setUAVGadget(IUAVGadget *uavGadget)
tl->addWidget(m_uavGadget->widget());
m_uavGadget->widget()->setParent(this);
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();
}
@ -201,17 +203,22 @@ void UAVGadgetView::updateToolBar()
void UAVGadgetView::listSelectionActivated(int index)
{
if (m_uavGadget && m_uavGadget->index() == index)
return;
if (m_uavGadgetManager->uavGadgetFactories().count() == 0)
if (index < 0 || m_uavGadgetManager->uavGadgetFactories().count() == 0)
return;
IUAVGadgetFactory *factory = m_uavGadgetManager->uavGadgetFactories().at(index);
if (m_uavGadget && m_uavGadget->gadgetKind() == factory->gadgetKind())
return;
IUAVGadget *gadget = factory->createUAVGadget(this);
gadget->setIndex(index);
setUAVGadget(gadget);
m_uavGadgetManager->setCurrentUAVGadget(gadget);
}
int UAVGadgetView::indexOfGadgetKind(QString gadgetKind)
{
return m_uavGadgetList->findData(gadgetKind);
}
SplitterOrView::SplitterOrView(UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget, bool isRoot) :
m_uavGadgetManager(uavGadgetManager),
m_isRoot(isRoot)
@ -251,7 +258,7 @@ void SplitterOrView::paintEvent(QPaintEvent *event)
// if (hasUAVGadget())
// return;
if (m_uavGadgetManager->toolbarsHidden())
if (m_uavGadgetManager->toolbarsShown())
return;
// Discreet indication where an uavGadget would be if there is none
@ -523,64 +530,43 @@ void SplitterOrView::unsplit()
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->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");
// }
// }
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 {
if (uavGadget())
stream << QByteArray("uavGadget") << uavGadget()->gadgetKind() << uavGadget()->saveState();
}
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->setUAVGadget(e);
// }
// }
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") {
QString gadgetKind;
QByteArray uavGadgetState;
stream >> gadgetKind >> uavGadgetState;
m_view = new UAVGadgetView(m_uavGadgetManager, 0);
int index = m_view->indexOfGadgetKind(gadgetKind);
m_view->listSelectionActivated(index);
m_layout->addWidget(m_view);
m_layout->setCurrentWidget(m_view);
uavGadget()->restoreState(uavGadgetState);
}
}

View File

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

View File

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

View File

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