From 93f443a55cdce0c1e0ed20cff8a114f2d9a5af24 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Thu, 26 May 2011 15:35:04 +0300 Subject: [PATCH] Added: #1303 Added initial context manager. --HG-- branch : gsoc2011-worldeditorqt --- .../src/plugins/core/CMakeLists.txt | 7 +- .../src/plugins/core/context_manager.cpp | 101 ++++++++++++++++++ .../src/plugins/core/context_manager.h | 67 ++++++++++++ .../src/plugins/core/core.cpp | 6 ++ .../object_viewer_qt/src/plugins/core/core.h | 1 + .../src/plugins/core/icontext.h | 10 ++ .../object_viewer_qt/src/plugins/core/icore.h | 2 + .../src/plugins/core/main_window.cpp | 11 +- .../src/plugins/core/main_window.h | 3 + 9 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt index 06095790b..3140f02fb 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt @@ -18,15 +18,18 @@ SET(OVQT_CORE_PLUGIN_HDR core.h main_window.h menu_manager.h + context_manager.h settings_dialog.h search_paths_settings_page.h general_settings_page.h - plugin_view_dialog.h) + plugin_view_dialog.h +) SET(OVQT_CORE_PLUGIN_UIS settings_dialog.ui plugin_view_dialog.ui general_settings_page.ui - search_paths_settings_page.ui) + search_paths_settings_page.ui +) SET(OVQT_CORE_PLUGIN_RCS core.qrc) 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 new file mode 100644 index 000000000..5e3d2864c --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.cpp @@ -0,0 +1,101 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Project includes +#include "context_manager.h" +#include "icontext.h" + +// NeL includes +#include + +// Qt includes +#include + +namespace Core +{ + +struct ContextManagerPrivate +{ + explicit ContextManagerPrivate(QTabWidget *tabWidget); + QTabWidget *m_tabWidget; + QVector m_contexts; + int m_oldCurrent; +}; + +ContextManagerPrivate::ContextManagerPrivate(QTabWidget *tabWidget) + : m_tabWidget(tabWidget), + m_oldCurrent(-1) +{ +} + +ContextManager::ContextManager(QTabWidget *tabWidget) + : d(new ContextManagerPrivate(tabWidget)) +{ +} + +ContextManager::~ContextManager() +{ + delete d; +} + +Core::IContext* ContextManager::currentContext() const +{ + int currentIndex = d->m_tabWidget->currentIndex(); + if (currentIndex < 0) + return 0; + return d->m_contexts.at(currentIndex); +} + +Core::IContext* ContextManager::context(const QString &id) const +{ + const int index = indexOf(id); + if (index >= 0) + return d->m_contexts.at(index); + return 0; +} + +void ContextManager::activateContext(const QString &id) +{ + const int index = indexOf(id); + if (index >= 0) + d->m_tabWidget->setCurrentIndex(index); +} + +void ContextManager::addContextObject(IContext *context) +{ +} + +void ContextManager::removeContextObject(IContext *context) +{ +} + +void ContextManager::currentTabChanged(int index) +{ +} + +int ContextManager::indexOf(const QString &id) const +{ + for (int i = 0; i < d->m_contexts.count(); ++i) + { + if (d->m_contexts.at(i)->id() == id) + return i; + } + nlwarning(QString("Warning, no such context: %1").arg(id).toStdString().c_str()); + return -1; +} + +} /* namespace Core */ \ No newline at end of file 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 new file mode 100644 index 000000000..c0d4a2209 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.h @@ -0,0 +1,67 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef CONTEXT_MANAGER_H +#define CONTEXT_MANAGER_H + +// Project includes +#include "core_global.h" + +// Qt includes +#include + +QT_BEGIN_NAMESPACE +class QTabWidget; +QT_END_NAMESPACE + +namespace Core +{ +class IContext; +struct ContextManagerPrivate; + +class CORE_EXPORT ContextManager : public QObject +{ + Q_OBJECT + +public: + explicit ContextManager(QTabWidget *tabWidget); + virtual ~ContextManager(); + + Core::IContext* currentContext() const; + Core::IContext* context(const QString &id) const; + +Q_SIGNALS: + // the default argument '=0' is important for connects without the oldContext argument. + void currentContextChanged(Core::IContext *context, Core::IContext *oldContext = 0); + +public Q_SLOTS: + void activateContext(const QString &id); + +private Q_SLOTS: + void addContextObject(IContext *context); + void removeContextObject(IContext *context); + void currentTabChanged(int index); + +private: + int indexOf(const QString &id) const; + + ContextManagerPrivate *d; +}; + +} // namespace Core + +#endif // CONTEXT_MANAGER_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core.cpp index 6c681f15a..fa61b5700 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core.cpp @@ -18,6 +18,7 @@ #include "core.h" #include "imenu_manager.h" +#include "context_manager.h" #include "main_window.h" #include "../../extension_system/iplugin_manager.h" @@ -54,6 +55,11 @@ IMenuManager *CoreImpl::menuManager() const return m_mainWindow->menuManager(); } +ContextManager *CoreImpl::contextManager() const +{ + return m_mainWindow->contextManager(); +} + QSettings *CoreImpl::settings() const { return m_mainWindow->settings(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core.h index d3b25b918..2613a06a5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core.h @@ -38,6 +38,7 @@ public: QWidget *parent = 0); virtual IMenuManager *menuManager() const; + virtual ContextManager *contextManager() const; virtual QSettings *settings() const; virtual QMainWindow *mainWindow() const; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icontext.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icontext.h index 776246d8d..c012b5a0c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icontext.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icontext.h @@ -56,6 +56,16 @@ public: /// The widget will be destroyed by the widget hierarchy when the main window closes virtual QWidget *widget() = 0; + + virtual bool open() + { + return false; + } + + virtual bool help() + { + return false; + } }; } // namespace Core diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icore.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icore.h index 71f075973..13b22bfa5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icore.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icore.h @@ -36,6 +36,7 @@ class IPluginManager; namespace Core { class IMenuManager; +class ContextManager; class CORE_EXPORT ICore : public QObject { @@ -52,6 +53,7 @@ public: QWidget *parent = 0) = 0; virtual IMenuManager *menuManager() const = 0; + virtual ContextManager *contextManager() const = 0; virtual QSettings *settings() const = 0; virtual QMainWindow *mainWindow() const = 0; 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 e048aa80b..4d7ffc35e 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 @@ -20,6 +20,7 @@ #include "icontext.h" #include "icore_listener.h" #include "menu_manager.h" +#include "context_manager.h" #include "core.h" #include "core_constants.h" #include "settings_dialog.h" @@ -38,6 +39,7 @@ MainWindow::MainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget * : QMainWindow(parent), m_pluginManager(0), m_menuManager(0), + m_contextManager(0), m_coreImpl(0), m_lastDir("."), m_settings(0) @@ -59,10 +61,12 @@ MainWindow::MainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget * m_tabWidget = new QTabWidget(this); m_tabWidget->setTabPosition(QTabWidget::South); - m_tabWidget->setMovable(true); + m_tabWidget->setMovable(false); m_tabWidget->setDocumentMode(true); setCentralWidget(m_tabWidget); + m_contextManager = new ContextManager(m_tabWidget); + setDockNestingEnabled(true); m_originalPalette = QApplication::palette(); @@ -109,6 +113,11 @@ IMenuManager *MainWindow::menuManager() const return m_menuManager; } +ContextManager *MainWindow::contextManager() const +{ + return m_contextManager; +} + QSettings *MainWindow::settings() const { return m_settings; 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 4cc24e5eb..61ebddf30 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 @@ -35,6 +35,7 @@ class CorePlugin; class IContext; class IMenuManager; class MenuManager; +class ContextManager; class CoreImpl; class MainWindow : public QMainWindow @@ -49,6 +50,7 @@ public: void extensionsInitialized(); IMenuManager *menuManager() const; + ContextManager *contextManager() const; QSettings *settings() const; ExtensionSystem::IPluginManager *pluginManager() const; @@ -80,6 +82,7 @@ private: ExtensionSystem::IPluginManager *m_pluginManager; ExtensionSystem::CPluginView *m_pluginView; MenuManager *m_menuManager; + ContextManager *m_contextManager; CoreImpl *m_coreImpl; QPalette m_originalPalette;