mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-21 08:28:44 +00:00
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
|
||||
#include <QtGui/QTabWidget>
|
||||
#include <QtGui/QGridLayout>
|
||||
|
||||
namespace Core
|
||||
{
|
||||
|
||||
struct ContextManagerPrivate
|
||||
{
|
||||
explicit ContextManagerPrivate(QTabWidget *tabWidget);
|
||||
explicit ContextManagerPrivate(ExtensionSystem::IPluginManager *pluginManager, QTabWidget *tabWidget);
|
||||
ExtensionSystem::IPluginManager *m_pluginManager;
|
||||
QTabWidget *m_tabWidget;
|
||||
QVector<IContext *> 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<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)
|
||||
{
|
||||
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
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
// Project includes
|
||||
#include "core_global.h"
|
||||
|
||||
#include "../../extension_system/iplugin_manager.h"
|
||||
|
||||
// Qt includes
|
||||
#include <QtCore/QObject>
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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<IContext *> listContexts = m_pluginManager->getObjects<IContext>();
|
||||
|
||||
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<IContext *>(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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -87,7 +87,7 @@ public:
|
|||
}
|
||||
virtual QString trName() const
|
||||
{
|
||||
return tr("LandscapeEditor");
|
||||
return tr("Landscape Editor");
|
||||
}
|
||||
virtual QIcon icon() const
|
||||
{
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include "../core/imenu_manager.h"
|
||||
#include "../core/core_constants.h"
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/debug.h>
|
||||
|
||||
// Qt includes
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
|
@ -34,12 +37,12 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
|
|||
{
|
||||
m_ui.setupUi(this);
|
||||
createMenus();
|
||||
// readSettings();
|
||||
readSettings();
|
||||
}
|
||||
|
||||
LandscapeEditorWindow::~LandscapeEditorWindow()
|
||||
{
|
||||
// writeSettings();
|
||||
writeSettings();
|
||||
}
|
||||
|
||||
void LandscapeEditorWindow::createMenus()
|
||||
|
|
Loading…
Reference in a new issue