Changed: #1206 Update core and example plugin.

This commit is contained in:
dnk-88 2011-02-21 16:26:24 +02:00
parent 903597d102
commit 3d06de12ff
23 changed files with 552 additions and 224 deletions

View file

@ -57,7 +57,7 @@ FOREACH(LANGUAGE ${LANGUAGES})
ADD_CUSTOM_COMMAND (OUTPUT ${QM} COMMAND ${QT_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS})
ENDFOREACH()
ADD_CUSTOM_TARGET (translations COMMAND ${QT_LUPDATE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} -recursive -ts ${TRANSLATIONS})
ADD_CUSTOM_TARGET (translations COMMAND ${QT_LUPDATE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} -recursive -no-obsolete -ts ${TRANSLATIONS})
ADD_CUSTOM_COMMAND (TARGET translations COMMAND ${QT_LRELEASE_EXECUTABLE} ${TRANSLATIONS})
SOURCE_GROUP(QtResources FILES ${OBJECT_VIEWER_UIS} ${OBJECT_VIEWER_RCS})

View file

@ -40,6 +40,9 @@
// Project includes
#include "modules.h"
#include "extension_system/iplugin_spec.h"
#include "extension_system/plugin_manager.h"
static const char *appNameC = "ObjectViewerQt";
// nel_qt log file name
#define NLQT_LOG_FILE "nel_qt.log"
@ -82,6 +85,29 @@ CFileDisplayer *s_FileDisplayer = NULL;
# endif
#endif
#ifdef Q_OS_WIN
static void displayError(const QString &t) // No console on Windows.
{
QMessageBox::critical(0, QLatin1String(appNameC), t);
}
#else
static void displayError(const QString &t)
{
qCritical("%s", qPrintable(t));
}
#endif
static inline QString msgCoreLoadFailure(const QString &why)
{
return QCoreApplication::translate("Application", "Failed to load Core plugin: %1").arg(why);
}
#define OVQT_OLD true
sint main(int argc, char **argv)
{
// go nel!
@ -111,8 +137,9 @@ sint main(int argc, char **argv)
splash->setPixmap(QPixmap(":/images/nel_ide_load.png"));
splash->show();
QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings *settings = new QSettings(QSettings::IniFormat, QSettings::UserScope,
QLatin1String("Ryzom Core"), QLatin1String("ObjectViewerQt"));
QLatin1String("RyzomCore"), QLatin1String(appNameC));
QTranslator translator;
QTranslator qtTranslator;
@ -128,6 +155,7 @@ sint main(int argc, char **argv)
CLibrary::addLibPath((qApp->applicationDirPath() + QString("/../PlugIns/nel")).toStdString());
#endif
#if defined(OVQT_OLD)
Modules::init();
Modules::plugMan().setSettings(settings);
@ -161,5 +189,57 @@ sint main(int argc, char **argv)
splash->finish(&Modules::mainWin());
int result = app.exec();
Modules::release();
#else
ExtensionSystem::CPluginManager pluginManager;
pluginManager.setSettings(settings);
QStringList pluginPaths;
#if !defined(NL_OS_MAC)
pluginPaths << QString("./plugins");
#else
pluginPaths << qApp->applicationDirPath() + QString("/../PlugIns/ovqt");
#endif
pluginManager.setPluginPaths(pluginPaths);
pluginManager.loadPlugins();
splash->hide();
const QList<ExtensionSystem::IPluginSpec *> plugins = pluginManager.plugins();
ExtensionSystem::IPluginSpec *corePlugin = 0;
Q_FOREACH(ExtensionSystem::IPluginSpec *spec, plugins)
{
if (spec->name() == QLatin1String("Core"))
{
corePlugin = spec;
break;
}
}
if (!corePlugin)
{
QDir absolutePluginPaths(pluginPaths.join(QLatin1String(",")));
QString absolutePaths = absolutePluginPaths.absolutePath();
const QString reason = QCoreApplication::translate("Application", "Could not find ovqt_plugin_core in %1").arg(absolutePaths);
displayError(msgCoreLoadFailure(reason));
return 1;
}
if (corePlugin->hasError())
{
displayError(msgCoreLoadFailure(corePlugin->errorString()));
return 1;
}
QStringList errors;
Q_FOREACH (ExtensionSystem::IPluginSpec *spec, pluginManager.plugins())
if (spec->hasError())
errors.append(spec->fileName() + " : " + spec->errorString());
if (!errors.isEmpty())
QMessageBox::warning(0, QCoreApplication::translate("Application", "Object Viewer Qt - Plugin loader messages"),
errors.join(QString::fromLatin1("\n\n")));
int result = app.exec();
#endif
return result;
}

View file

@ -9,10 +9,13 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.
${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h)
SET(OVQT_CORE_PLUGIN_HDR
icore.h
icontext.h
imenu_manager.h
icore_listener.h
ioptions_page.h
core_plugin.h
core.h
main_window.h
menu_manager.h
settings_dialog.h

View file

@ -0,0 +1,66 @@
// 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/>.
#include "core.h"
#include "imenu_manager.h"
#include "main_window.h"
static Core::CoreImpl *m_coreInstance = 0;
namespace Core
{
ICore *ICore::instance()
{
return m_coreInstance;
}
CoreImpl::CoreImpl(MainWindow *mainWindow)
{
m_mainWindow = mainWindow;
m_coreInstance = this;
}
CoreImpl::~CoreImpl()
{
m_coreInstance = 0;
}
bool CoreImpl::showOptionsDialog(const QString &group,
const QString &page,
QWidget *parent)
{
return m_mainWindow->showOptionsDialog(group, page, parent);
}
IMenuManager *CoreImpl::menuManager() const
{
return m_mainWindow->menuManager();
}
QSettings *CoreImpl::settings() const
{
return m_mainWindow->settings();
}
QMainWindow *CoreImpl::mainWindow() const
{
return m_mainWindow;
}
} // namespace Core

View file

@ -0,0 +1,52 @@
// 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 CORE_H
#define CORE_H
#include "icore.h"
namespace Core
{
class MainWindow;
class CoreImpl : public ICore
{
Q_OBJECT
public:
CoreImpl(MainWindow *mainWindow);
virtual ~CoreImpl();
virtual bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(),
QWidget *parent = 0);
virtual IMenuManager *menuManager() const;
virtual QSettings *settings() const;
virtual QMainWindow *mainWindow() const;
private:
MainWindow *m_mainWindow;
friend class MainWindow;
};
} // namespace Core
#endif // CORE_H

View file

@ -48,13 +48,15 @@ CorePlugin::~CorePlugin()
}
qDeleteAll(_autoReleaseObjects);
_autoReleaseObjects.clear();
if (_oldOVQT)
delete _mainWindow;
}
bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString)
{
Q_UNUSED(errorString);
_plugMan = pluginManager;
_oldOVQT = false;
// for old ovqt
QMainWindow *wnd = qobject_cast<QMainWindow *>(_plugMan->objectByName("CMainWindow"));
@ -72,11 +74,11 @@ bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStr
connect(newAction, SIGNAL(triggered()), this, SLOT(execSettings()));
connect(newAction2, SIGNAL(triggered()), _pluginView, SLOT(show()));
_oldOVQT = true;
_oldOVQT = false;
}
else
{
_mainWindow = new CMainWindow(this);
_mainWindow = new MainWindow(pluginManager);
#ifdef Q_WS_X11
_mainWindow->setAttribute(Qt::WA_TranslucentBackground);
_mainWindow->setAttribute(Qt::WA_NoSystemBackground, false);
@ -93,7 +95,9 @@ bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStr
QtWin::extendFrameIntoClientArea(_mainWindow);
_mainWindow->setContentsMargins(0, 0, 0, 0);
}
_mainWindow->show();
_oldOVQT = true;
bool success = _mainWindow->initialize(errorString);
return success;
}
addAutoReleasedObject(new CSearchPathsSettingsPage(this));
@ -103,20 +107,18 @@ bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStr
void CorePlugin::extensionsInitialized()
{
_pluginView = new ExtensionSystem::CPluginView(_plugMan);
if (_oldOVQT)
_mainWindow->extensionsInitialized();
}
void CorePlugin::shutdown()
{
if (!_oldOVQT)
{
delete _mainWindow;
delete _pluginView;
}
}
void CorePlugin::execSettings()
{
CSettingsDialog settingsDialog(this);
CSettingsDialog settingsDialog(_plugMan);
settingsDialog.show();
settingsDialog.execDialog();
}

View file

@ -75,7 +75,7 @@ private Q_SLOTS:
private:
ExtensionSystem::IPluginManager *_plugMan;
ExtensionSystem::CPluginView *_pluginView;
CMainWindow *_mainWindow;
MainWindow *_mainWindow;
QList<QObject *> _autoReleaseObjects;
bool _oldOVQT;
};

View file

@ -15,25 +15,35 @@
// 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 IAPP_PAGE_H
#define IAPP_PAGE_H
#ifndef ICONTEXT_H
#define ICONTEXT_H
// Project includes
#include "core_global.h"
// Qt includes
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtGui/QIcon>
QT_BEGIN_NAMESPACE
class QWidget;
QT_END_NAMESPACE
namespace Core
{
/**
@interface IAppPage
@brief The IAppPage is an interface for providing app pages in main window.
@interface IContext
@brief The IContext is an interface for providing tab pages in main window.
@details You need to subclass this interface and put an instance of your subclass
into the plugin manager object pool.
*/
class IAppPage
class CORE_EXPORT IContext: public QObject
{
Q_OBJECT
public:
virtual ~IAppPage() {}
IContext(QObject *parent = 0): QObject(parent) {}
virtual ~IContext() {}
/// id() is a unique identifier for referencing this page
virtual QString id() const = 0;
@ -50,6 +60,4 @@ public:
} // namespace Core
Q_DECLARE_INTERFACE(Core::IAppPage, "dev.ryzom.com.IAppPage/0.1")
#endif // IAPP_PAGE_H
#endif // ICONTEXT_H

View file

@ -0,0 +1,60 @@
// 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_H
#define ICORE_H
#include "core_global.h"
#include <QtCore/QObject>
QT_BEGIN_NAMESPACE
class QMainWindow;
class QSettings;
QT_END_NAMESPACE
namespace Core
{
class IMenuManager;
class CORE_EXPORT ICore : public QObject
{
Q_OBJECT
public:
ICore() {}
virtual ~ICore() {}
static ICore *instance();
virtual bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(),
QWidget *parent = 0) = 0;
virtual IMenuManager *menuManager() const = 0;
virtual QSettings *settings() const = 0;
virtual QMainWindow *mainWindow() const = 0;
Q_SIGNALS:
void closeMainWindow();
};
} // namespace Core
#endif // ICORE_H

View file

@ -17,10 +17,10 @@
// Project includes
#include "main_window.h"
#include "menu_manager.h"
#include "core_plugin.h"
#include "iapp_page.h"
#include "icontext.h"
#include "icore_listener.h"
#include "menu_manager.h"
#include "core.h"
#include "core_constants.h"
#include "settings_dialog.h"
@ -28,94 +28,117 @@
#include <nel/misc/debug.h>
// Qt includes
#include <QtCore/QCoreApplication>
#include <QtGui/QtGui>
namespace Core
{
CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent)
MainWindow::MainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget *parent)
: QMainWindow(parent),
_pluginManager(0),
_corePlugin(0),
_menuManager(0),
_lastDir("."),
_settings(0)
m_pluginManager(0),
m_menuManager(0),
m_coreImpl(0),
m_lastDir("."),
m_settings(0)
{
_corePlugin = corePlugin;
_pluginManager = _corePlugin->pluginManager();
_settings = _pluginManager->settings();
QCoreApplication::setApplicationName(QLatin1String("ObjectViewerQt"));
QCoreApplication::setApplicationVersion(QLatin1String(Core::Constants::OVQT_VERSION_LONG));
QCoreApplication::setOrganizationName(QLatin1String("RyzomCore"));
setObjectName(Constants::MAIN_WINDOW);
setWindowIcon(QIcon(Constants::ICON_NEL));
setWindowTitle(tr("Object Viewer Qt"));
_menuManager = new MenuManager(this);
_menuManager->setMenuBar(menuBar());
_pluginManager->addObject(_menuManager);
m_pluginManager = pluginManager;
m_settings = m_pluginManager->settings();
m_coreImpl = new CoreImpl(this);
_tabWidget = new QTabWidget(this);
_tabWidget->setTabPosition(QTabWidget::South);
setCentralWidget(_tabWidget);
m_menuManager = new MenuManager(this);
m_menuManager->setMenuBar(menuBar());
QList<IAppPage *> listAppPages = _pluginManager->getObjects<IAppPage>();
Q_FOREACH(IAppPage *appPage, listAppPages)
{
addAppPage(appPage);
}
m_tabWidget = new QTabWidget(this);
m_tabWidget->setTabPosition(QTabWidget::South);
setCentralWidget(m_tabWidget);
setDockNestingEnabled(true);
_originalPalette = QApplication::palette();
m_originalPalette = QApplication::palette();
createDialogs();
createActions();
createMenus();
createStatusBar();
}
MainWindow::~MainWindow()
{
m_pluginManager->removeObject(m_coreImpl);
m_pluginManager->removeObject(m_menuManager);
delete m_coreImpl;
m_coreImpl = 0;
}
bool MainWindow::initialize(QString *errorString)
{
Q_UNUSED(errorString);
m_pluginManager->addObject(m_coreImpl);
m_pluginManager->addObject(m_menuManager);
return true;
}
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();
setWindowIcon(QIcon(Constants::ICON_NEL));
setWindowTitle(tr("Object Viewer Qt"));
connect(_pluginManager, SIGNAL(objectAdded(QObject *)), this, SLOT(checkObject(QObject *)));
show();
}
CMainWindow::~CMainWindow()
IMenuManager *MainWindow::menuManager() const
{
return m_menuManager;
}
IMenuManager *CMainWindow::menuManager() const
QSettings *MainWindow::settings() const
{
return _menuManager;
return m_settings;
}
void CMainWindow::checkObject(QObject *obj)
void MainWindow::checkObject(QObject *obj)
{
IAppPage *appPage = qobject_cast<IAppPage *>(obj);
if (appPage)
addAppPage(appPage);
IContext *context = qobject_cast<IContext *>(obj);
if (context)
addContextObject(context);
}
bool CMainWindow::showOptionsDialog(const QString &group,
bool MainWindow::showOptionsDialog(const QString &group,
const QString &page,
QWidget *parent)
{
if (!parent)
parent = this;
CSettingsDialog _settingsDialog(_corePlugin, group, page, parent);
_settingsDialog.show();
return _settingsDialog.execDialog();
CSettingsDialog settingsDialog(m_pluginManager, group, page, parent);
settingsDialog.show();
return settingsDialog.execDialog();
}
void CMainWindow::about()
void MainWindow::about()
{
QMessageBox::about(this, tr("About Object Viewer Qt"),
tr("<h2>Object Viewer Qt NG</h2>"
"<p> Author: dnk-88 <p>Compiled on %1 %2").arg(__DATE__).arg(__TIME__));
}
void CMainWindow::closeEvent(QCloseEvent *event)
void MainWindow::closeEvent(QCloseEvent *event)
{
QList<ICoreListener *> listeners = _pluginManager->getObjects<ICoreListener>();
QList<ICoreListener *> listeners = m_pluginManager->getObjects<ICoreListener>();
Q_FOREACH(ICoreListener *listener, listeners)
{
if (!listener->closeMainWindow())
@ -124,112 +147,122 @@ void CMainWindow::closeEvent(QCloseEvent *event)
return;
}
}
Q_EMIT m_coreImpl->closeMainWindow();
writeSettings();
event->accept();
}
void CMainWindow::addAppPage(IAppPage *appPage)
void MainWindow::addContextObject(IContext *context)
{
QWidget *tabWidget = new QWidget(_tabWidget);
_tabWidget->addTab(tabWidget, appPage->icon(), appPage->trName());
QWidget *tabWidget = new QWidget(m_tabWidget);
m_tabWidget->addTab(tabWidget, context->icon(), context->trName());
QGridLayout *gridLayout = new QGridLayout(tabWidget);
gridLayout->setObjectName(QString::fromUtf8("gridLayout_") + appPage->id());
gridLayout->setObjectName(QString::fromUtf8("gridLayout_") + context->id());
gridLayout->setContentsMargins(0, 0, 0, 0);
gridLayout->addWidget(appPage->widget(), 0, 0, 1, 1);
gridLayout->addWidget(context->widget(), 0, 0, 1, 1);
}
void CMainWindow::createActions()
void MainWindow::createActions()
{
_openAction = new QAction(tr("&Open..."), this);
_openAction->setIcon(QIcon(":/images/open-file.png"));
_openAction->setShortcut(QKeySequence::Open);
_openAction->setStatusTip(tr("Open an existing file"));
menuManager()->registerAction(_openAction, Constants::OPEN);
// connect(_openAction, SIGNAL(triggered()), this, SLOT(open()));
m_openAction = new QAction(tr("&Open..."), this);
m_openAction->setIcon(QIcon(":/images/open-file.png"));
m_openAction->setShortcut(QKeySequence::Open);
m_openAction->setStatusTip(tr("Open an existing file"));
menuManager()->registerAction(m_openAction, Constants::OPEN);
// connect(m_openAction, SIGNAL(triggered()), this, SLOT(open()));
_exitAction = new QAction(tr("E&xit"), this);
_exitAction->setShortcut(tr("Ctrl+Q"));
_exitAction->setStatusTip(tr("Exit the application"));
menuManager()->registerAction(_exitAction, Constants::EXIT);
connect(_exitAction, SIGNAL(triggered()), this, SLOT(close()));
m_exitAction = new QAction(tr("E&xit"), this);
m_exitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
m_exitAction->setStatusTip(tr("Exit the application"));
menuManager()->registerAction(m_exitAction, Constants::EXIT);
connect(m_exitAction, SIGNAL(triggered()), this, SLOT(close()));
_settingsAction = new QAction(tr("&Settings"), this);
_settingsAction->setIcon(QIcon(":/images/preferences.png"));
_settingsAction->setStatusTip(tr("Open the settings dialog"));
menuManager()->registerAction(_settingsAction, Constants::SETTINGS);
connect(_settingsAction, SIGNAL(triggered()), this, SLOT(showOptionsDialog()));
m_settingsAction = new QAction(tr("&Settings"), this);
m_settingsAction->setIcon(QIcon(":/images/preferences.png"));
m_settingsAction->setShortcut(QKeySequence::Preferences);
m_settingsAction->setStatusTip(tr("Open the settings dialog"));
menuManager()->registerAction(m_settingsAction, Constants::SETTINGS);
connect(m_settingsAction, SIGNAL(triggered()), this, SLOT(showOptionsDialog()));
_aboutAction = new QAction(tr("&About"), this);
_aboutAction->setStatusTip(tr("Show the application's About box"));
menuManager()->registerAction(_aboutAction, Constants::ABOUT);
connect(_aboutAction, SIGNAL(triggered()), this, SLOT(about()));
m_aboutAction = new QAction(tr("&About"), this);
m_aboutAction->setStatusTip(tr("Show the application's About box"));
menuManager()->registerAction(m_aboutAction, Constants::ABOUT);
connect(m_aboutAction, SIGNAL(triggered()), this, SLOT(about()));
_aboutQtAction = new QAction(tr("About &Qt"), this);
_aboutQtAction->setStatusTip(tr("Show the Qt library's About box"));
menuManager()->registerAction(_aboutQtAction, Constants::ABOUT_QT);
connect(_aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
m_aboutQtAction = new QAction(tr("About &Qt"), this);
m_aboutQtAction->setStatusTip(tr("Show the Qt library's About box"));
menuManager()->registerAction(m_aboutQtAction, Constants::ABOUT_QT);
connect(m_aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
_pluginViewAction = new QAction(tr("About &Plugins"), this);
_pluginViewAction->setStatusTip(tr("Show the plugin view dialog"));
menuManager()->registerAction(_pluginViewAction, Constants::ABOUT_PLUGINS);
connect(_pluginViewAction, SIGNAL(triggered()), _pluginView, SLOT(show()));
m_pluginViewAction = new QAction(tr("About &Plugins"), this);
m_pluginViewAction->setStatusTip(tr("Show the plugin view dialog"));
menuManager()->registerAction(m_pluginViewAction, Constants::ABOUT_PLUGINS);
connect(m_pluginViewAction, SIGNAL(triggered()), m_pluginView, SLOT(show()));
#ifdef Q_WS_MAC
m_exitAction->setMenuRole(QAction::QuitRole);
m_settingsAction->setMenuRole(QAction::PreferencesRole);
m_aboutAction->setMenuRole(QAction::AboutRole);
m_aboutQtAction->setMenuRole(QAction::AboutQtRole);
m_pluginViewAction->setMenuRole(QAction::ApplicationSpecificRole);
#endif
}
void CMainWindow::createMenus()
void MainWindow::createMenus()
{
_fileMenu = menuBar()->addMenu(tr("&File"));
menuManager()->registerMenu(_fileMenu, Constants::M_FILE);
_fileMenu->addSeparator();
_fileMenu->addAction(_exitAction);
m_fileMenu = menuBar()->addMenu(tr("&File"));
menuManager()->registerMenu(m_fileMenu, Constants::M_FILE);
m_fileMenu->addSeparator();
m_fileMenu->addAction(m_exitAction);
_editMenu = menuBar()->addMenu(tr("&Edit"));
menuManager()->registerMenu(_editMenu, Constants::M_EDIT);
m_editMenu = menuBar()->addMenu(tr("&Edit"));
menuManager()->registerMenu(m_editMenu, Constants::M_EDIT);
_viewMenu = menuBar()->addMenu(tr("&View"));
menuManager()->registerMenu(_viewMenu, Constants::M_VIEW);
m_viewMenu = menuBar()->addMenu(tr("&View"));
menuManager()->registerMenu(m_viewMenu, Constants::M_VIEW);
_toolsMenu = menuBar()->addMenu(tr("&Tools"));
menuManager()->registerMenu(_toolsMenu, Constants::M_TOOLS);
m_toolsMenu = menuBar()->addMenu(tr("&Tools"));
menuManager()->registerMenu(m_toolsMenu, Constants::M_TOOLS);
_toolsMenu->addSeparator();
m_toolsMenu->addSeparator();
_toolsMenu->addAction(_settingsAction);
m_toolsMenu->addAction(m_settingsAction);
menuBar()->addSeparator();
_helpMenu = menuBar()->addMenu(tr("&Help"));
menuManager()->registerMenu(_helpMenu, Constants::M_HELP);
_helpMenu->addAction(_aboutAction);
_helpMenu->addAction(_aboutQtAction);
_helpMenu->addAction(_pluginViewAction);
m_helpMenu = menuBar()->addMenu(tr("&Help"));
menuManager()->registerMenu(m_helpMenu, Constants::M_HELP);
m_helpMenu->addAction(m_aboutAction);
m_helpMenu->addAction(m_aboutQtAction);
m_helpMenu->addAction(m_pluginViewAction);
}
void CMainWindow::createStatusBar()
void MainWindow::createStatusBar()
{
statusBar()->showMessage(tr("StatusReady"));
}
void CMainWindow::createDialogs()
void MainWindow::createDialogs()
{
_pluginView = new ExtensionSystem::CPluginView(_pluginManager, this);
m_pluginView = new ExtensionSystem::CPluginView(m_pluginManager, this);
}
void CMainWindow::readSettings()
void MainWindow::readSettings()
{
_settings->beginGroup("MainWindowSettings");
restoreState(_settings->value("QtWindowState").toByteArray());
restoreGeometry(_settings->value("QtWindowGeometry").toByteArray());
_settings->endGroup();
m_settings->beginGroup("MainWindow");
restoreState(m_settings->value("WindowState").toByteArray());
restoreGeometry(m_settings->value("WindowGeometry").toByteArray());
m_settings->endGroup();
}
void CMainWindow::writeSettings()
void MainWindow::writeSettings()
{
_settings->beginGroup("MainWindowSettings");
_settings->setValue("QtWindowState", saveState());
_settings->setValue("QtWindowGeometry", saveGeometry());
_settings->endGroup();
m_settings->beginGroup("MainWindow");
m_settings->setValue("WindowState", saveState());
m_settings->setValue("WindowGeometry", saveGeometry());
m_settings->endGroup();
}
} /* namespace Core */

View file

@ -32,31 +32,39 @@ namespace Core
{
class CSettingsDialog;
class CorePlugin;
class IAppPage;
class IContext;
class IMenuManager;
class MenuManager;
class CoreImpl;
class CMainWindow : public QMainWindow
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
CMainWindow(CorePlugin *corePlugin, QWidget *parent = 0);
~CMainWindow();
MainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget *parent = 0);
~MainWindow();
bool initialize(QString *errorString);
void extensionsInitialized();
IMenuManager *menuManager() const;
QSettings *settings() const;
private Q_SLOTS:
void checkObject(QObject *obj);
public Q_SLOTS:
bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(),
QWidget *parent = 0);
private Q_SLOTS:
void checkObject(QObject *obj);
void about();
protected:
virtual void closeEvent(QCloseEvent *event);
private:
void addAppPage(IAppPage *appPage);
void addContextObject(IContext *appPage);
void createActions();
void createMenus();
@ -66,35 +74,35 @@ private:
void readSettings();
void writeSettings();
ExtensionSystem::IPluginManager *_pluginManager;
ExtensionSystem::CPluginView *_pluginView;
CorePlugin *_corePlugin;
MenuManager *_menuManager;
ExtensionSystem::IPluginManager *m_pluginManager;
ExtensionSystem::CPluginView *m_pluginView;
MenuManager *m_menuManager;
CoreImpl *m_coreImpl;
QPalette _originalPalette;
QString _lastDir;
QPalette m_originalPalette;
QString m_lastDir;
QSettings *_settings;
QSettings *m_settings;
QTimer *_mainTimer;
QTimer *_statusBarTimer;
QTimer *m_mainTimer;
QTimer *m_statusBarTimer;
QTabWidget *_tabWidget;
QTabWidget *m_tabWidget;
QMenu *_fileMenu;
QMenu *_editMenu;
QMenu *_viewMenu;
QMenu *_toolsMenu;
QMenu *_helpMenu;
QMenu *m_fileMenu;
QMenu *m_editMenu;
QMenu *m_viewMenu;
QMenu *m_toolsMenu;
QMenu *m_helpMenu;
QAction *_openAction;
QAction *_exitAction;
QAction *_settingsAction;
QAction *_pluginViewAction;
QAction *_aboutAction;
QAction *_aboutQtAction;
QAction *m_openAction;
QAction *m_exitAction;
QAction *m_settingsAction;
QAction *m_pluginViewAction;
QAction *m_aboutAction;
QAction *m_aboutQtAction;
};/* class CMainWindow */
};/* class MainWindow */
} /* namespace Core */

View file

@ -18,7 +18,6 @@
// Project includes
#include "settings_dialog.h"
#include "core_plugin.h"
#include "ioptions_page.h"
// Qt includes
@ -36,7 +35,7 @@ Q_DECLARE_METATYPE(PageData);
namespace Core
{
CSettingsDialog::CSettingsDialog(CorePlugin *corePlugin,
CSettingsDialog::CSettingsDialog(ExtensionSystem::IPluginManager *pluginManager,
const QString &categoryId,
const QString &pageId,
QWidget *parent)
@ -45,7 +44,7 @@ CSettingsDialog::CSettingsDialog(CorePlugin *corePlugin,
{
_ui.setupUi(this);
_plugMan = corePlugin->pluginManager();
_plugMan = pluginManager;
QString initialCategory = categoryId;
QString initialPage = pageId;

View file

@ -25,11 +25,10 @@
#include <QtCore/QList>
// Project includes
#include "../../extension_system/iplugin.h"
#include "../../extension_system/iplugin_manager.h"
namespace Core
{
class CorePlugin;
class IOptionsPage;
/**
@ -41,7 +40,7 @@ class CSettingsDialog: public QDialog
Q_OBJECT
public:
CSettingsDialog(CorePlugin *corePlugin,
CSettingsDialog(ExtensionSystem::IPluginManager *pluginManager,
const QString &initialCategory = QString(),
const QString &initialPage = QString(),
QWidget *parent = 0);

View file

@ -12,8 +12,7 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.
SET(OVQT_PLUG_EXAMPLE_HDR plugin1.h
qnel_widget.h
simple_viewer.h
example_settings_page.h
${CMAKE_CURRENT_SOURCE_DIR}/../core/iapp_page.h)
example_settings_page.h)
SET(OVQT_PLUG_EXAMPLE_UIS example_settings_page.ui)

View file

@ -2,7 +2,7 @@
#include "plugin1.h"
#include "example_settings_page.h"
#include "simple_viewer.h"
#include "../core/iapp_page.h"
#include "../core/icore.h"
#include "../core/core_constants.h"
#include "../core/imenu_manager.h"
#include "../../extension_system/iplugin_spec.h"
@ -36,19 +36,20 @@ bool MyPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStrin
_plugMan = pluginManager;
addAutoReleasedObject(new CExampleSettingsPage(this));
addAutoReleasedObject(new CExampleAppPage(this));
addAutoReleasedObject(new CExampleContext(this));
addAutoReleasedObject(new CCoreListener(this));
return true;
}
void MyPlugin::extensionsInitialized()
{
Core::IMenuManager *menuManager = 0;
menuManager = _plugMan->getObject<Core::IMenuManager>();
if (menuManager == 0)
nlinfo("error menu manager");
Core::ICore *core = Core::ICore::instance();
if (core == 0)
nlinfo("This not ovqt ng");
else
{
Core::IMenuManager *menuManager = core->menuManager();
//menuManager = _plugMan->getObject<Core::IMenuManager>();
QAction *exampleAction1 = new QAction("Example1", this);
QAction *exampleAction2 = new QAction("Example2", this);
QAction *aboutQtAction = menuManager->action(Core::Constants::ABOUT_QT);

View file

@ -3,8 +3,8 @@
// Project includes
#include "../../extension_system/iplugin.h"
#include "../core/icontext.h"
#include "simple_viewer.h"
#include "../core/iapp_page.h"
// NeL includes
#include "nel/misc/app_context.h"
@ -58,17 +58,16 @@ private:
QList<QObject *> _autoReleaseObjects;
};
class CExampleAppPage: public QObject, public Core::IAppPage
class CExampleContext: public Core::IContext
{
Q_OBJECT
Q_INTERFACES(Core::IAppPage)
public:
CExampleAppPage(QObject *parent = 0): QObject(parent) {}
virtual ~CExampleAppPage() {}
CExampleContext(QObject *parent = 0): IContext(parent) {}
virtual ~CExampleContext() {}
virtual QString id() const
{
return QLatin1String("ExampleAppPage");
return QLatin1String("ExampleContext");
}
virtual QString trName() const
{

View file

@ -34,16 +34,16 @@ namespace NLQT
QNLWidget::QNLWidget(QWidget *parent)
: QWidget(parent),
_driver(NULL),
_initialized(false),
_interval(25)
m_driver(NULL),
m_initialized(false),
m_interval(25)
{
setMouseTracking(true);
setFocusPolicy(Qt::StrongFocus);
init();
_mainTimer = new QTimer(this);
connect(_mainTimer, SIGNAL(timeout()), this, SLOT(updateRender()));
m_mainTimer = new QTimer(this);
connect(m_mainTimer, SIGNAL(timeout()), this, SLOT(updateRender()));
}
QNLWidget::~QNLWidget()
@ -54,49 +54,59 @@ QNLWidget::~QNLWidget()
void QNLWidget::init()
{
// create the driver
_driver = NL3D::UDriver::createDriver(NULL, false, NULL);
nlassert(_driver);
m_driver = NL3D::UDriver::createDriver(NULL, false, NULL);
nlassert(m_driver);
// initialize the nel 3d viewport
_driver->setDisplay((nlWindow)winId(), NL3D::UDriver::CMode(width(), height(), 32));
m_driver->setDisplay((nlWindow)winId(), NL3D::UDriver::CMode(width(), height(), 32));
// set the cache size for the font manager(in bytes)
_driver->setFontManagerMaxMemory(2097152);
m_driver->setFontManagerMaxMemory(2097152);
_initialized = true;
m_initialized = true;
}
void QNLWidget::release()
{
_mainTimer->stop();
delete _mainTimer;
if (_initialized)
m_mainTimer->stop();
delete m_mainTimer;
if (m_initialized)
{
_driver->release();
delete _driver;
_driver = NULL;
m_driver->release();
delete m_driver;
m_driver = NULL;
}
}
void QNLWidget::setInterval(int msec)
{
_interval = msec;
_mainTimer->setInterval(msec);
m_interval = msec;
m_mainTimer->setInterval(msec);
}
void QNLWidget::updateRender()
{
if (isVisible())
{
if (_initialized)
_driver->EventServer.pump();
if (_initialized && !_driver->isLost())
{
_driver->activate();
_driver->clearBuffers(NLMISC::CRGBA(125,12,58));
if (m_initialized)
m_driver->EventServer.pump();
Q_EMIT updateData();
// Calc FPS
static sint64 lastTime = NLMISC::CTime::getPerformanceTime ();
sint64 newTime = NLMISC::CTime::getPerformanceTime ();
m_fps = float(1.0 / NLMISC::CTime::ticksToSecond (newTime-lastTime));
lastTime = newTime;
if (m_initialized && !m_driver->isLost())
{
//_driver->activate();
m_driver->clearBuffers(NLMISC::CRGBA(125,12,58));
Q_EMIT updatePreRender();
Q_EMIT updatePostRender();
// swap 3d buffers
_driver->swapBuffers();
m_driver->swapBuffers();
}
}
}
@ -106,11 +116,11 @@ void QNLWidget::showEvent(QShowEvent *showEvent)
QWidget::showEvent(showEvent);
if (isVisible())
{
_driver->activate();
_mainTimer->start(_interval);
m_driver->activate();
m_mainTimer->start(m_interval);
}
else
_mainTimer->stop();
m_mainTimer->stop();
}
#if defined(NL_OS_WINDOWS)
@ -119,9 +129,9 @@ typedef bool (*winProc)(NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM w
bool QNLWidget::winEvent(MSG *message, long *result)
{
if (_driver && _driver->isActive())
if (m_driver && m_driver->isActive())
{
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser *>(_driver)->getDriver();
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser *>(m_driver)->getDriver();
if (driver)
{
winProc proc = (winProc)driver->getWindowProc();
@ -141,9 +151,9 @@ bool QNLWidget::macEvent(EventHandlerCallRef caller, EventRef event)
if(caller)
nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt");
if (_driver && _driver->isActive())
if (m_driver && m_driver->isActive())
{
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser *>(_driver)->getDriver();
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser *>(m_driver)->getDriver();
if (driver)
{
cocoaProc proc = (cocoaProc)driver->getWindowProc();
@ -160,9 +170,9 @@ typedef bool (*x11Proc)(NL3D::IDriver *drv, XEvent *e);
bool QNLWidget::x11Event(XEvent *event)
{
if (_driver && _driver->isActive())
if (m_driver && m_driver->isActive())
{
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser *>(_driver)->getDriver();
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser *>(m_driver)->getDriver();
if (driver)
{
x11Proc proc = (x11Proc)driver->getWindowProc();

View file

@ -54,10 +54,19 @@ public:
/// Set the update interval renderer
void setInterval(int msec);
float getFPS() const
{
return m_fps;
}
virtual QPaintEngine* paintEngine() const
{
return NULL;
}
Q_SIGNALS:
void updateData();
void updatePreRender();
void updatePostRender();
private Q_SLOTS:
void updateRender();
@ -80,10 +89,11 @@ private:
QNLWidget(const QNLWidget &);
QNLWidget &operator=(const QNLWidget &);
NL3D::UDriver *_driver;
QTimer *_mainTimer;
bool _initialized;
int _interval;
NL3D::UDriver *m_driver;
QTimer *m_mainTimer;
bool m_initialized;
int m_interval;
float m_fps;
}; /* class QNLWidget */

View file

@ -9,8 +9,7 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.
${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h)
SET(OVQT_PLUG_LOG_HDR log_plugin.h
log_settings_page.h
${CMAKE_CURRENT_SOURCE_DIR}/../core/iapp_page.h)
log_settings_page.h)
SET(OVQT_PLUG_LOG_UIS log_form.ui
log_settings_page.ui)