diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp index a681d8975..a1c3dced0 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp @@ -70,7 +70,7 @@ void CorePlugin::extensionsInitialized() } else { - _mainWindow = new CMainWindow(_plugMan); + _mainWindow = new CMainWindow(this); #ifdef Q_WS_X11 _mainWindow->setAttribute(Qt::WA_TranslucentBackground); _mainWindow->setAttribute(Qt::WA_NoSystemBackground, false); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icore_listener.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icore_listener.h new file mode 100644 index 000000000..c37ba3366 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icore_listener.h @@ -0,0 +1,56 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. +// +// 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 ICORE_LISTENER_H +#define ICORE_LISTENER_H + +#include + +class QWidget; + +namespace Core +{ +/** +@interface ICoreListener +@brief The ICoreListener is an interface for providing a hook for plugins to veto on close event emitted from +the core plugin. +@details You implement this interface if you want to prevent the closing of the whole application. +If the application window requests a close, then first ICoreListener::closeMainWindow() is called +(in arbitrary order) on all registered objects implementing this interface. +If one if these calls returns false, the process is aborted and the event is ignored. If all calls return +true, the corresponding signal is emitted and the event is accepted/performed. + +You need to add your implementing object to the plugin managers objects: +PluginManager->addObject(yourImplementingObject); +Don't forget to remove the object again at deconstruction (e.g. in the destructor of +your plugin) +*/ +class ICoreListener +{ +public: + virtual ~ICoreListener() {} + + /// Return false from the implemented method if you want to prevent the event. + virtual bool closeMainWindow() const = 0; +}; + +} // namespace Core + +Q_DECLARE_INTERFACE(Core::ICoreListener, "dev.ryzom.com.ICoreListener/0.1") + +#endif // ICORE_LISTENER_H 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 b077b25c2..ce94a738e 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 @@ -17,7 +17,9 @@ // Project includes #include "main_window.h" +#include "core_plugin.h" #include "iapp_page.h" +#include "icore_listener.h" #include "core_constants.h" #include "settings_dialog.h" @@ -29,11 +31,12 @@ namespace Core { -CMainWindow::CMainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget *parent) +CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent) : QMainWindow(parent), _lastDir(".") { - _pluginManager = pluginManager; + _corePlugin = corePlugin; + _pluginManager = _corePlugin->pluginManager(); setObjectName(Constants::MAIN_WINDOW); @@ -41,14 +44,7 @@ CMainWindow::CMainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget _tabWidget->setTabPosition(QTabWidget::South); setCentralWidget(_tabWidget); - QList listObjects = _pluginManager->allObjects(); - QList listAppPages; - Q_FOREACH(QObject *obj, listObjects) - { - IAppPage *appPage = dynamic_cast(obj); - if (appPage) - listAppPages.append(appPage); - } + QList listAppPages = _corePlugin->getObjects(); Q_FOREACH(IAppPage *appPage, listAppPages) { @@ -98,6 +94,15 @@ void CMainWindow::about() void CMainWindow::closeEvent(QCloseEvent *event) { + QList listeners = _corePlugin->getObjects(); + Q_FOREACH(ICoreListener *listener, listeners) + { + if (!listener->closeMainWindow()) + { + event->ignore(); + return; + } + } QMainWindow::closeEvent(event); } @@ -160,12 +165,6 @@ void CMainWindow::createMenus() _helpMenu->addAction(_aboutAction); _helpMenu->addAction(_aboutQtAction); _helpMenu->addAction(_pluginViewAction); - - _pluginManager->addObject(_fileMenu); - _pluginManager->addObject(_editMenu); - _pluginManager->addObject(_viewMenu); - _pluginManager->addObject(_toolsMenu); - _pluginManager->addObject(_helpMenu); } void CMainWindow::createStatusBar() 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 3f2555d82..e394e85d7 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 @@ -31,13 +31,14 @@ namespace Core { class CSettingsDialog; +class CorePlugin; class CMainWindow : public QMainWindow { Q_OBJECT public: - CMainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget *parent = 0); + CMainWindow(CorePlugin *corePlugin, QWidget *parent = 0); ~CMainWindow(); inline QSettings *settings() const @@ -61,6 +62,7 @@ private: ExtensionSystem::IPluginManager *_pluginManager; ExtensionSystem::CPluginView *_pluginView; + CorePlugin *_corePlugin; QPalette _originalPalette; QString _lastDir; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt index 9afe59a2b..d14b42806 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt @@ -14,6 +14,7 @@ SET(OVQT_PLUG_EXAMPLE_HDR plugin1.h simple_viewer.h example_settings_page.h ${CMAKE_CURRENT_SOURCE_DIR}/../core/iapp_page.h + ${CMAKE_CURRENT_SOURCE_DIR}/../core/icore_listener.h ${CMAKE_CURRENT_SOURCE_DIR}/../core/ioptions_page.h) SET(OVQT_PLUG_EXAMPLE_UIS example_settings_page.ui) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp index a8974478e..07185c5fa 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp @@ -26,6 +26,7 @@ bool MyPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStrin _plugMan->addObject(new CExampleSettingsPage(this)); _plugMan->addObject(new CExampleAppPage(this)); + _plugMan->addObject(new CCoreListener(this)); return true; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.cpp index bbf9df80e..e128710c4 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.cpp @@ -20,6 +20,7 @@ // Qt includes #include #include +#include // NeL includes @@ -38,5 +39,16 @@ CSimpleViewer::CSimpleViewer(QWidget *parent) gridLayout->addWidget(_nelWidget, 0, 0, 1, 1); } +bool CCoreListener::closeMainWindow() const +{ + int ret = QMessageBox::question(0, tr("Example close event hook"), + tr("Do you want to close window?"), + QMessageBox::Yes | QMessageBox::No); + + if (ret == QMessageBox::Yes) + return true; + else + return false; +} } /* namespace Plugin */ \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h index e9d83cfa3..cb3c1cf87 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h @@ -21,6 +21,7 @@ // Project includes #include "qnel_widget.h" +#include "../core/icore_listener.h" // Qt includes #include @@ -38,6 +39,17 @@ public: virtual ~CSimpleViewer() {} }; +class CCoreListener : public QObject, public Core::ICoreListener +{ + Q_OBJECT + Q_INTERFACES(Core::ICoreListener) +public: + CCoreListener(QObject *parent = 0): QObject(parent) {} + virtual ~CCoreListener() {} + + virtual bool closeMainWindow() const; +}; + } // namespace Plugin #endif // SIMPLE_VIEWER_H