From 2e6743a00b3ae8101f6e0a0032d24dfc88526044 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Sun, 13 Feb 2011 16:02:28 +0200 Subject: [PATCH] Changed: #1193 Added reading and writing settings in core plugin. --- .../src/plugins/core/main_window.cpp | 48 ++++++++++++++++--- .../src/plugins/core/main_window.h | 12 +++-- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp index ce94a738e..601159f8b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp @@ -37,6 +37,7 @@ CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent) { _corePlugin = corePlugin; _pluginManager = _corePlugin->pluginManager(); + _settings = _pluginManager->settings(); setObjectName(Constants::MAIN_WINDOW); @@ -48,12 +49,7 @@ CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent) Q_FOREACH(IAppPage *appPage, listAppPages) { - QWidget *tabWidget = new QWidget(_tabWidget); - _tabWidget->addTab(tabWidget, appPage->icon(), appPage->trName()); - QGridLayout *gridLayout = new QGridLayout(tabWidget); - gridLayout->setObjectName(QString::fromUtf8("gridLayout_") + appPage->id()); - gridLayout->setContentsMargins(0, 0, 0, 0); - gridLayout->addWidget(appPage->widget(), 0, 0, 1, 1); + addAppPage(appPage); } setDockNestingEnabled(true); @@ -65,8 +61,12 @@ CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent) createMenus(); createStatusBar(); + readSettings(); + setWindowIcon(QIcon(Constants::ICON_NEL)); setWindowTitle(tr("Object Viewer Qt")); + + connect(_pluginManager, SIGNAL(objectAdded(QObject *)), this, SLOT(checkObject(QObject *))); } CMainWindow::~CMainWindow() @@ -74,6 +74,13 @@ CMainWindow::~CMainWindow() delete _pluginView; } +void CMainWindow::checkObject(QObject *obj) +{ + IAppPage *appPage = qobject_cast(obj); + if (appPage) + addAppPage(appPage); +} + bool CMainWindow::showOptionsDialog(const QString &group, const QString &page, QWidget *parent) @@ -103,9 +110,22 @@ void CMainWindow::closeEvent(QCloseEvent *event) return; } } + + writeSettings(); + QMainWindow::closeEvent(event); } +void CMainWindow::addAppPage(IAppPage *appPage) +{ + QWidget *tabWidget = new QWidget(_tabWidget); + _tabWidget->addTab(tabWidget, appPage->icon(), appPage->trName()); + QGridLayout *gridLayout = new QGridLayout(tabWidget); + gridLayout->setObjectName(QString::fromUtf8("gridLayout_") + appPage->id()); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(appPage->widget(), 0, 0, 1, 1); +} + void CMainWindow::createActions() { _openAction = new QAction(tr("&Open..."), this); @@ -177,6 +197,22 @@ void CMainWindow::createDialogs() _pluginView = new ExtensionSystem::CPluginView(_pluginManager, this); } +void CMainWindow::readSettings() +{ + _settings->beginGroup("MainWindowSettings"); + restoreState(_settings->value("QtWindowState").toByteArray()); + restoreGeometry(_settings->value("QtWindowGeometry").toByteArray()); + _settings->endGroup(); +} + +void CMainWindow::writeSettings() +{ + _settings->beginGroup("MainWindowSettings"); + _settings->setValue("QtWindowState", saveState()); + _settings->setValue("QtWindowGeometry", saveGeometry()); + _settings->endGroup(); +} + } /* namespace Core */ /* end of file */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h index e394e85d7..4b807dd04 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h @@ -32,6 +32,7 @@ namespace Core { class CSettingsDialog; class CorePlugin; +class IAppPage; class CMainWindow : public QMainWindow { @@ -41,12 +42,8 @@ public: CMainWindow(CorePlugin *corePlugin, QWidget *parent = 0); ~CMainWindow(); - inline QSettings *settings() const - { - return _settings; - } - private Q_SLOTS: + void checkObject(QObject *obj); bool showOptionsDialog(const QString &group = QString(), const QString &page = QString(), QWidget *parent = 0); @@ -55,11 +52,16 @@ protected: virtual void closeEvent(QCloseEvent *event); private: + void addAppPage(IAppPage *appPage); + void createActions(); void createMenus(); void createStatusBar(); void createDialogs(); + void readSettings(); + void writeSettings(); + ExtensionSystem::IPluginManager *_pluginManager; ExtensionSystem::CPluginView *_pluginView; CorePlugin *_corePlugin;