mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-28 11:50:53 +00:00
Changed: #1193 Added the ICoreListener which is the interface for providing a hook for plugins to veto on close event emitted from
the core plugin.
This commit is contained in:
parent
d8d5269f98
commit
b0f6962f4c
8 changed files with 101 additions and 18 deletions
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef ICORE_LISTENER_H
|
||||
#define ICORE_LISTENER_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
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
|
|
@ -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<QObject *> listObjects = _pluginManager->allObjects();
|
||||
QList<IAppPage *> listAppPages;
|
||||
Q_FOREACH(QObject *obj, listObjects)
|
||||
{
|
||||
IAppPage *appPage = dynamic_cast<IAppPage *>(obj);
|
||||
if (appPage)
|
||||
listAppPages.append(appPage);
|
||||
}
|
||||
QList<IAppPage *> listAppPages = _corePlugin->getObjects<IAppPage>();
|
||||
|
||||
Q_FOREACH(IAppPage *appPage, listAppPages)
|
||||
{
|
||||
|
@ -98,6 +94,15 @@ void CMainWindow::about()
|
|||
|
||||
void CMainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
QList<ICoreListener *> listeners = _corePlugin->getObjects<ICoreListener>();
|
||||
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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
// Qt includes
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QGridLayout>
|
||||
#include <QtGui/QMessageBox>
|
||||
|
||||
// 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 */
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
// Project includes
|
||||
#include "qnel_widget.h"
|
||||
#include "../core/icore_listener.h"
|
||||
|
||||
// Qt includes
|
||||
#include <QtCore/QObject>
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue