Added: #1303 Added initial context manager.

This commit is contained in:
dnk-88 2011-05-26 15:35:04 +03:00
parent 1721bc51d2
commit 1f52dfb05a
9 changed files with 205 additions and 3 deletions

View file

@ -18,15 +18,18 @@ SET(OVQT_CORE_PLUGIN_HDR
core.h core.h
main_window.h main_window.h
menu_manager.h menu_manager.h
context_manager.h
settings_dialog.h settings_dialog.h
search_paths_settings_page.h search_paths_settings_page.h
general_settings_page.h general_settings_page.h
plugin_view_dialog.h) plugin_view_dialog.h
)
SET(OVQT_CORE_PLUGIN_UIS settings_dialog.ui SET(OVQT_CORE_PLUGIN_UIS settings_dialog.ui
plugin_view_dialog.ui plugin_view_dialog.ui
general_settings_page.ui general_settings_page.ui
search_paths_settings_page.ui) search_paths_settings_page.ui
)
SET(OVQT_CORE_PLUGIN_RCS core.qrc) SET(OVQT_CORE_PLUGIN_RCS core.qrc)

View file

@ -0,0 +1,101 @@
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
//
// 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 <http://www.gnu.org/licenses/>.
// Project includes
#include "context_manager.h"
#include "icontext.h"
// NeL includes
#include <nel/misc/debug.h>
// Qt includes
#include <QtGui/QTabWidget>
namespace Core
{
struct ContextManagerPrivate
{
explicit ContextManagerPrivate(QTabWidget *tabWidget);
QTabWidget *m_tabWidget;
QVector<IContext *> 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 */

View file

@ -0,0 +1,67 @@
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
//
// 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 <http://www.gnu.org/licenses/>.
#ifndef CONTEXT_MANAGER_H
#define CONTEXT_MANAGER_H
// Project includes
#include "core_global.h"
// Qt includes
#include <QtCore/QObject>
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

View file

@ -18,6 +18,7 @@
#include "core.h" #include "core.h"
#include "imenu_manager.h" #include "imenu_manager.h"
#include "context_manager.h"
#include "main_window.h" #include "main_window.h"
#include "../../extension_system/iplugin_manager.h" #include "../../extension_system/iplugin_manager.h"
@ -54,6 +55,11 @@ IMenuManager *CoreImpl::menuManager() const
return m_mainWindow->menuManager(); return m_mainWindow->menuManager();
} }
ContextManager *CoreImpl::contextManager() const
{
return m_mainWindow->contextManager();
}
QSettings *CoreImpl::settings() const QSettings *CoreImpl::settings() const
{ {
return m_mainWindow->settings(); return m_mainWindow->settings();

View file

@ -38,6 +38,7 @@ public:
QWidget *parent = 0); QWidget *parent = 0);
virtual IMenuManager *menuManager() const; virtual IMenuManager *menuManager() const;
virtual ContextManager *contextManager() const;
virtual QSettings *settings() const; virtual QSettings *settings() const;
virtual QMainWindow *mainWindow() const; virtual QMainWindow *mainWindow() const;

View file

@ -56,6 +56,16 @@ public:
/// The widget will be destroyed by the widget hierarchy when the main window closes /// The widget will be destroyed by the widget hierarchy when the main window closes
virtual QWidget *widget() = 0; virtual QWidget *widget() = 0;
virtual bool open()
{
return false;
}
virtual bool help()
{
return false;
}
}; };
} // namespace Core } // namespace Core

View file

@ -36,6 +36,7 @@ class IPluginManager;
namespace Core namespace Core
{ {
class IMenuManager; class IMenuManager;
class ContextManager;
class CORE_EXPORT ICore : public QObject class CORE_EXPORT ICore : public QObject
{ {
@ -52,6 +53,7 @@ public:
QWidget *parent = 0) = 0; QWidget *parent = 0) = 0;
virtual IMenuManager *menuManager() const = 0; virtual IMenuManager *menuManager() const = 0;
virtual ContextManager *contextManager() const = 0;
virtual QSettings *settings() const = 0; virtual QSettings *settings() const = 0;
virtual QMainWindow *mainWindow() const = 0; virtual QMainWindow *mainWindow() const = 0;

View file

@ -20,6 +20,7 @@
#include "icontext.h" #include "icontext.h"
#include "icore_listener.h" #include "icore_listener.h"
#include "menu_manager.h" #include "menu_manager.h"
#include "context_manager.h"
#include "core.h" #include "core.h"
#include "core_constants.h" #include "core_constants.h"
#include "settings_dialog.h" #include "settings_dialog.h"
@ -38,6 +39,7 @@ MainWindow::MainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget *
: QMainWindow(parent), : QMainWindow(parent),
m_pluginManager(0), m_pluginManager(0),
m_menuManager(0), m_menuManager(0),
m_contextManager(0),
m_coreImpl(0), m_coreImpl(0),
m_lastDir("."), m_lastDir("."),
m_settings(0) m_settings(0)
@ -59,10 +61,12 @@ MainWindow::MainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget *
m_tabWidget = new QTabWidget(this); m_tabWidget = new QTabWidget(this);
m_tabWidget->setTabPosition(QTabWidget::South); m_tabWidget->setTabPosition(QTabWidget::South);
m_tabWidget->setMovable(true); m_tabWidget->setMovable(false);
m_tabWidget->setDocumentMode(true); m_tabWidget->setDocumentMode(true);
setCentralWidget(m_tabWidget); setCentralWidget(m_tabWidget);
m_contextManager = new ContextManager(m_tabWidget);
setDockNestingEnabled(true); setDockNestingEnabled(true);
m_originalPalette = QApplication::palette(); m_originalPalette = QApplication::palette();
@ -109,6 +113,11 @@ IMenuManager *MainWindow::menuManager() const
return m_menuManager; return m_menuManager;
} }
ContextManager *MainWindow::contextManager() const
{
return m_contextManager;
}
QSettings *MainWindow::settings() const QSettings *MainWindow::settings() const
{ {
return m_settings; return m_settings;

View file

@ -35,6 +35,7 @@ class CorePlugin;
class IContext; class IContext;
class IMenuManager; class IMenuManager;
class MenuManager; class MenuManager;
class ContextManager;
class CoreImpl; class CoreImpl;
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
@ -49,6 +50,7 @@ public:
void extensionsInitialized(); void extensionsInitialized();
IMenuManager *menuManager() const; IMenuManager *menuManager() const;
ContextManager *contextManager() const;
QSettings *settings() const; QSettings *settings() const;
ExtensionSystem::IPluginManager *pluginManager() const; ExtensionSystem::IPluginManager *pluginManager() const;
@ -80,6 +82,7 @@ private:
ExtensionSystem::IPluginManager *m_pluginManager; ExtensionSystem::IPluginManager *m_pluginManager;
ExtensionSystem::CPluginView *m_pluginView; ExtensionSystem::CPluginView *m_pluginView;
MenuManager *m_menuManager; MenuManager *m_menuManager;
ContextManager *m_contextManager;
CoreImpl *m_coreImpl; CoreImpl *m_coreImpl;
QPalette m_originalPalette; QPalette m_originalPalette;