Changed: #1303 Completed work on the context manager.
This commit is contained in:
parent
1f52dfb05a
commit
03475c59b2
6 changed files with 62 additions and 38 deletions
|
@ -24,27 +24,36 @@
|
||||||
|
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QtGui/QTabWidget>
|
#include <QtGui/QTabWidget>
|
||||||
|
#include <QtGui/QGridLayout>
|
||||||
|
|
||||||
namespace Core
|
namespace Core
|
||||||
{
|
{
|
||||||
|
|
||||||
struct ContextManagerPrivate
|
struct ContextManagerPrivate
|
||||||
{
|
{
|
||||||
explicit ContextManagerPrivate(QTabWidget *tabWidget);
|
explicit ContextManagerPrivate(ExtensionSystem::IPluginManager *pluginManager, QTabWidget *tabWidget);
|
||||||
|
ExtensionSystem::IPluginManager *m_pluginManager;
|
||||||
QTabWidget *m_tabWidget;
|
QTabWidget *m_tabWidget;
|
||||||
QVector<IContext *> m_contexts;
|
QVector<IContext *> m_contexts;
|
||||||
int m_oldCurrent;
|
int m_oldCurrent;
|
||||||
};
|
};
|
||||||
|
|
||||||
ContextManagerPrivate::ContextManagerPrivate(QTabWidget *tabWidget)
|
ContextManagerPrivate::ContextManagerPrivate(ExtensionSystem::IPluginManager *pluginManager, QTabWidget *tabWidget)
|
||||||
: m_tabWidget(tabWidget),
|
: m_pluginManager(pluginManager),
|
||||||
|
m_tabWidget(tabWidget),
|
||||||
m_oldCurrent(-1)
|
m_oldCurrent(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextManager::ContextManager(QTabWidget *tabWidget)
|
ContextManager::ContextManager(ExtensionSystem::IPluginManager *pluginManager, QTabWidget *tabWidget)
|
||||||
: d(new ContextManagerPrivate(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()
|
ContextManager::~ContextManager()
|
||||||
|
@ -75,16 +84,52 @@ void ContextManager::activateContext(const QString &id)
|
||||||
d->m_tabWidget->setCurrentIndex(index);
|
d->m_tabWidget->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContextManager::objectAdded(QObject *obj)
|
||||||
|
{
|
||||||
|
IContext *context = qobject_cast<IContext *>(obj);
|
||||||
|
if (context)
|
||||||
|
addContextObject(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContextManager::aboutToRemoveObject(QObject *obj)
|
||||||
|
{
|
||||||
|
IContext *context = qobject_cast<IContext *>(obj);
|
||||||
|
if (context)
|
||||||
|
removeContextObject(context);
|
||||||
|
}
|
||||||
|
|
||||||
void ContextManager::addContextObject(IContext *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)
|
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)
|
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
|
int ContextManager::indexOf(const QString &id) const
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
// Project includes
|
// Project includes
|
||||||
#include "core_global.h"
|
#include "core_global.h"
|
||||||
|
|
||||||
|
#include "../../extension_system/iplugin_manager.h"
|
||||||
|
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
|
@ -38,7 +40,7 @@ class CORE_EXPORT ContextManager : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ContextManager(QTabWidget *tabWidget);
|
explicit ContextManager(ExtensionSystem::IPluginManager *pluginManager, QTabWidget *tabWidget);
|
||||||
virtual ~ContextManager();
|
virtual ~ContextManager();
|
||||||
|
|
||||||
Core::IContext* currentContext() const;
|
Core::IContext* currentContext() const;
|
||||||
|
@ -52,6 +54,8 @@ public Q_SLOTS:
|
||||||
void activateContext(const QString &id);
|
void activateContext(const QString &id);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
void objectAdded(QObject *obj);
|
||||||
|
void aboutToRemoveObject(QObject *obj);
|
||||||
void addContextObject(IContext *context);
|
void addContextObject(IContext *context);
|
||||||
void removeContextObject(IContext *context);
|
void removeContextObject(IContext *context);
|
||||||
void currentTabChanged(int index);
|
void currentTabChanged(int index);
|
||||||
|
|
|
@ -65,7 +65,7 @@ MainWindow::MainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget *
|
||||||
m_tabWidget->setDocumentMode(true);
|
m_tabWidget->setDocumentMode(true);
|
||||||
setCentralWidget(m_tabWidget);
|
setCentralWidget(m_tabWidget);
|
||||||
|
|
||||||
m_contextManager = new ContextManager(m_tabWidget);
|
m_contextManager = new ContextManager(m_pluginManager, m_tabWidget);
|
||||||
|
|
||||||
setDockNestingEnabled(true);
|
setDockNestingEnabled(true);
|
||||||
m_originalPalette = QApplication::palette();
|
m_originalPalette = QApplication::palette();
|
||||||
|
@ -96,14 +96,6 @@ bool MainWindow::initialize(QString *errorString)
|
||||||
|
|
||||||
void MainWindow::extensionsInitialized()
|
void MainWindow::extensionsInitialized()
|
||||||
{
|
{
|
||||||
QList<IContext *> listContexts = m_pluginManager->getObjects<IContext>();
|
|
||||||
|
|
||||||
Q_FOREACH(IContext *context, listContexts)
|
|
||||||
{
|
|
||||||
addContextObject(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(m_pluginManager, SIGNAL(objectAdded(QObject *)), this, SLOT(checkObject(QObject *)));
|
|
||||||
readSettings();
|
readSettings();
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
@ -132,13 +124,6 @@ void MainWindow::open()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::checkObject(QObject *obj)
|
|
||||||
{
|
|
||||||
IContext *context = qobject_cast<IContext *>(obj);
|
|
||||||
if (context)
|
|
||||||
addContextObject(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MainWindow::showOptionsDialog(const QString &group,
|
bool MainWindow::showOptionsDialog(const QString &group,
|
||||||
const QString &page,
|
const QString &page,
|
||||||
QWidget *parent)
|
QWidget *parent)
|
||||||
|
@ -177,16 +162,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
event->accept();
|
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()
|
void MainWindow::createActions()
|
||||||
{
|
{
|
||||||
m_openAction = new QAction(tr("&Open..."), this);
|
m_openAction = new QAction(tr("&Open..."), this);
|
||||||
|
|
|
@ -62,15 +62,12 @@ public Q_SLOTS:
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void open();
|
void open();
|
||||||
void checkObject(QObject *obj);
|
|
||||||
void about();
|
void about();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void closeEvent(QCloseEvent *event);
|
virtual void closeEvent(QCloseEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addContextObject(IContext *appPage);
|
|
||||||
|
|
||||||
void createActions();
|
void createActions();
|
||||||
void createMenus();
|
void createMenus();
|
||||||
void createStatusBar();
|
void createStatusBar();
|
||||||
|
|
|
@ -87,7 +87,7 @@ public:
|
||||||
}
|
}
|
||||||
virtual QString trName() const
|
virtual QString trName() const
|
||||||
{
|
{
|
||||||
return tr("LandscapeEditor");
|
return tr("Landscape Editor");
|
||||||
}
|
}
|
||||||
virtual QIcon icon() const
|
virtual QIcon icon() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
#include "../core/imenu_manager.h"
|
#include "../core/imenu_manager.h"
|
||||||
#include "../core/core_constants.h"
|
#include "../core/core_constants.h"
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/debug.h>
|
||||||
|
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
|
|
||||||
|
@ -34,12 +37,12 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
createMenus();
|
createMenus();
|
||||||
// readSettings();
|
readSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
LandscapeEditorWindow::~LandscapeEditorWindow()
|
LandscapeEditorWindow::~LandscapeEditorWindow()
|
||||||
{
|
{
|
||||||
// writeSettings();
|
writeSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LandscapeEditorWindow::createMenus()
|
void LandscapeEditorWindow::createMenus()
|
||||||
|
|
Loading…
Reference in a new issue