diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.cpp index 5e3d2864c..b0a13aee6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.cpp @@ -24,27 +24,36 @@ // Qt includes #include +#include namespace Core { struct ContextManagerPrivate { - explicit ContextManagerPrivate(QTabWidget *tabWidget); + explicit ContextManagerPrivate(ExtensionSystem::IPluginManager *pluginManager, QTabWidget *tabWidget); + ExtensionSystem::IPluginManager *m_pluginManager; QTabWidget *m_tabWidget; QVector m_contexts; int m_oldCurrent; }; -ContextManagerPrivate::ContextManagerPrivate(QTabWidget *tabWidget) - : m_tabWidget(tabWidget), +ContextManagerPrivate::ContextManagerPrivate(ExtensionSystem::IPluginManager *pluginManager, QTabWidget *tabWidget) + : m_pluginManager(pluginManager), + m_tabWidget(tabWidget), m_oldCurrent(-1) { } -ContextManager::ContextManager(QTabWidget *tabWidget) - : d(new ContextManagerPrivate(tabWidget)) +ContextManager::ContextManager(ExtensionSystem::IPluginManager *pluginManager, QTabWidget *tabWidget) + : d(new ContextManagerPrivate(pluginManager, tabWidget)) { + QObject::connect(d->m_pluginManager, SIGNAL(objectAdded(QObject *)), + this, SLOT(objectAdded(QObject *))); + QObject::connect(d->m_pluginManager, SIGNAL(aboutToRemoveObject(QObject *)), + this, SLOT(aboutToRemoveObject(QObject *))); + + QObject::connect(d->m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int))); } ContextManager::~ContextManager() @@ -75,16 +84,52 @@ void ContextManager::activateContext(const QString &id) d->m_tabWidget->setCurrentIndex(index); } +void ContextManager::objectAdded(QObject *obj) +{ + IContext *context = qobject_cast(obj); + if (context) + addContextObject(context); +} + +void ContextManager::aboutToRemoveObject(QObject *obj) +{ + IContext *context = qobject_cast(obj); + if (context) + removeContextObject(context); +} + void ContextManager::addContextObject(IContext *context) { + d->m_contexts.push_back(context); + + QWidget *tabWidget = new QWidget(d->m_tabWidget); + d->m_tabWidget->addTab(tabWidget, context->icon(), context->trName()); + QGridLayout *gridLayout = new QGridLayout(tabWidget); + gridLayout->setObjectName(QString::fromUtf8("gridLayout_") + context->id()); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(context->widget(), 0, 0, 1, 1); } void ContextManager::removeContextObject(IContext *context) { + const int index = indexOf(context->id()); + QWidget *widget = d->m_tabWidget->widget(index); + d->m_tabWidget->removeTab(index); + d->m_contexts.remove(index); + delete widget; } void ContextManager::currentTabChanged(int index) { + if (index >= 0) + { + IContext *context = d->m_contexts.at(index); + IContext *oldContext = 0; + if (d->m_oldCurrent >= 0) + oldContext = d->m_contexts.at(d->m_oldCurrent); + d->m_oldCurrent = index; + Q_EMIT currentContextChanged(context, oldContext); + } } int ContextManager::indexOf(const QString &id) const diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.h index c0d4a2209..5264617a3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.h @@ -21,6 +21,8 @@ // Project includes #include "core_global.h" +#include "../../extension_system/iplugin_manager.h" + // Qt includes #include @@ -38,7 +40,7 @@ class CORE_EXPORT ContextManager : public QObject Q_OBJECT public: - explicit ContextManager(QTabWidget *tabWidget); + explicit ContextManager(ExtensionSystem::IPluginManager *pluginManager, QTabWidget *tabWidget); virtual ~ContextManager(); Core::IContext* currentContext() const; @@ -52,6 +54,8 @@ public Q_SLOTS: void activateContext(const QString &id); private Q_SLOTS: + void objectAdded(QObject *obj); + void aboutToRemoveObject(QObject *obj); void addContextObject(IContext *context); void removeContextObject(IContext *context); void currentTabChanged(int index); 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 4d7ffc35e..a4bc542b2 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 @@ -65,7 +65,7 @@ MainWindow::MainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget * m_tabWidget->setDocumentMode(true); setCentralWidget(m_tabWidget); - m_contextManager = new ContextManager(m_tabWidget); + m_contextManager = new ContextManager(m_pluginManager, m_tabWidget); setDockNestingEnabled(true); m_originalPalette = QApplication::palette(); @@ -96,14 +96,6 @@ bool MainWindow::initialize(QString *errorString) void MainWindow::extensionsInitialized() { - QList listContexts = m_pluginManager->getObjects(); - - Q_FOREACH(IContext *context, listContexts) - { - addContextObject(context); - } - - connect(m_pluginManager, SIGNAL(objectAdded(QObject *)), this, SLOT(checkObject(QObject *))); readSettings(); show(); } @@ -132,13 +124,6 @@ void MainWindow::open() { } -void MainWindow::checkObject(QObject *obj) -{ - IContext *context = qobject_cast(obj); - if (context) - addContextObject(context); -} - bool MainWindow::showOptionsDialog(const QString &group, const QString &page, QWidget *parent) @@ -177,16 +162,6 @@ void MainWindow::closeEvent(QCloseEvent *event) event->accept(); } -void MainWindow::addContextObject(IContext *context) -{ - QWidget *tabWidget = new QWidget(m_tabWidget); - m_tabWidget->addTab(tabWidget, context->icon(), context->trName()); - QGridLayout *gridLayout = new QGridLayout(tabWidget); - gridLayout->setObjectName(QString::fromUtf8("gridLayout_") + context->id()); - gridLayout->setContentsMargins(0, 0, 0, 0); - gridLayout->addWidget(context->widget(), 0, 0, 1, 1); -} - void MainWindow::createActions() { m_openAction = new QAction(tr("&Open..."), this); 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 61ebddf30..8c4a4aafe 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 @@ -62,15 +62,12 @@ public Q_SLOTS: private Q_SLOTS: void open(); - void checkObject(QObject *obj); void about(); protected: virtual void closeEvent(QCloseEvent *event); private: - void addContextObject(IContext *appPage); - void createActions(); void createMenus(); void createStatusBar(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.h index 3b7df3777..bd5040843 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.h @@ -87,7 +87,7 @@ public: } virtual QString trName() const { - return tr("LandscapeEditor"); + return tr("Landscape Editor"); } virtual QIcon icon() const { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp index 1588f6252..ef4f81a1c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp @@ -23,6 +23,9 @@ #include "../core/imenu_manager.h" #include "../core/core_constants.h" +// NeL includes +#include + // Qt includes #include @@ -34,12 +37,12 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent) { m_ui.setupUi(this); createMenus(); -// readSettings(); + readSettings(); } LandscapeEditorWindow::~LandscapeEditorWindow() { -// writeSettings(); + writeSettings(); } void LandscapeEditorWindow::createMenus()