From e986569ef9b33836c49dd0a9528d0742c54a914a Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 24 Nov 2012 18:38:56 +0100 Subject: [PATCH] Fixed: Wrong EOL --- .../src/plugins/core/context_manager.cpp | 332 +++++++++--------- 1 file changed, 166 insertions(+), 166 deletions(-) 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 d1aa6cb14..8355b5cb8 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 @@ -1,167 +1,167 @@ -// 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" -#include "main_window.h" - -// NeL includes -#include - -// Qt includes -#include -#include - -namespace Core -{ - -struct ContextManagerPrivate -{ - explicit ContextManagerPrivate(Core::MainWindow *mainWindow, QTabWidget *tabWidget); - Core::MainWindow *m_mainWindow; - QTabWidget *m_tabWidget; - QVector m_contexts; - int m_oldCurrent; -}; - -ContextManagerPrivate::ContextManagerPrivate(Core::MainWindow *mainWindow, QTabWidget *tabWidget) - : m_mainWindow(mainWindow), - m_tabWidget(tabWidget), - m_oldCurrent(-1) -{ -} - -ContextManager::ContextManager(Core::MainWindow *mainWindow, QTabWidget *tabWidget) - : d(new ContextManagerPrivate(mainWindow, tabWidget)) -{ - QObject::connect(d->m_mainWindow->pluginManager(), SIGNAL(objectAdded(QObject *)), - this, SLOT(objectAdded(QObject *))); - QObject::connect(d->m_mainWindow->pluginManager(), SIGNAL(aboutToRemoveObject(QObject *)), - this, SLOT(aboutToRemoveObject(QObject *))); - - QObject::connect(d->m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int))); -} - -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::registerUndoStack(QUndoStack *stack) -{ - nlassert(stack); - d->m_mainWindow->undoGroup()->addStack(stack); -} - -void ContextManager::unregisterUndoStack(QUndoStack *stack) -{ - nlassert(stack); - d->m_mainWindow->undoGroup()->removeStack(stack); -} - -void ContextManager::activateContext(const QString &id) -{ - const int index = indexOf(id); - if (index >= 0) - d->m_tabWidget->setCurrentIndex(index); -} - -void ContextManager::updateCurrentContext() -{ - d->m_mainWindow->updateContext(currentContext()); -} - -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); - d->m_mainWindow->addContextObject(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) -{ - d->m_mainWindow->removeContextObject(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 -{ - 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).toUtf8().constData()); - return -1; -} - +// 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" +#include "main_window.h" + +// NeL includes +#include + +// Qt includes +#include +#include + +namespace Core +{ + +struct ContextManagerPrivate +{ + explicit ContextManagerPrivate(Core::MainWindow *mainWindow, QTabWidget *tabWidget); + Core::MainWindow *m_mainWindow; + QTabWidget *m_tabWidget; + QVector m_contexts; + int m_oldCurrent; +}; + +ContextManagerPrivate::ContextManagerPrivate(Core::MainWindow *mainWindow, QTabWidget *tabWidget) + : m_mainWindow(mainWindow), + m_tabWidget(tabWidget), + m_oldCurrent(-1) +{ +} + +ContextManager::ContextManager(Core::MainWindow *mainWindow, QTabWidget *tabWidget) + : d(new ContextManagerPrivate(mainWindow, tabWidget)) +{ + QObject::connect(d->m_mainWindow->pluginManager(), SIGNAL(objectAdded(QObject *)), + this, SLOT(objectAdded(QObject *))); + QObject::connect(d->m_mainWindow->pluginManager(), SIGNAL(aboutToRemoveObject(QObject *)), + this, SLOT(aboutToRemoveObject(QObject *))); + + QObject::connect(d->m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int))); +} + +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::registerUndoStack(QUndoStack *stack) +{ + nlassert(stack); + d->m_mainWindow->undoGroup()->addStack(stack); +} + +void ContextManager::unregisterUndoStack(QUndoStack *stack) +{ + nlassert(stack); + d->m_mainWindow->undoGroup()->removeStack(stack); +} + +void ContextManager::activateContext(const QString &id) +{ + const int index = indexOf(id); + if (index >= 0) + d->m_tabWidget->setCurrentIndex(index); +} + +void ContextManager::updateCurrentContext() +{ + d->m_mainWindow->updateContext(currentContext()); +} + +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); + d->m_mainWindow->addContextObject(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) +{ + d->m_mainWindow->removeContextObject(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 +{ + 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).toUtf8().constData()); + return -1; +} + } /* namespace Core */ \ No newline at end of file