From d306700e6edf6a10dbe77283341e11c905d6a65b Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Sat, 12 Feb 2011 14:11:55 +0200 Subject: [PATCH] Changed: #1206 Update core and example plugin. Update camera control panel. --- .../object_viewer_qt/src/camera_control.cpp | 4 + .../3d/object_viewer_qt/src/main_window.cpp | 1 + .../src/plugins/core/CMakeLists.txt | 3 +- .../src/plugins/core/core_plugin.cpp | 40 ++- .../src/plugins/core/iapp_page.h | 2 +- .../src/plugins/core/main_window.cpp | 3 +- .../src/plugins/core/main_window.h | 9 +- .../src/plugins/core/qtwin.cpp | 241 ++++++++++++++++++ .../object_viewer_qt/src/plugins/core/qtwin.h | 37 +++ .../src/plugins/example/CMakeLists.txt | 5 +- .../src/plugins/example/plugin1.cpp | 80 +++--- .../src/plugins/example/plugin1.h | 50 +++- .../plugins/{core => example}/qnel_widget.cpp | 36 +-- .../plugins/{core => example}/qnel_widget.h | 4 - .../src/plugins/example/simple_viewer.cpp | 42 +++ .../src/plugins/example/simple_viewer.h | 43 ++++ 16 files changed, 498 insertions(+), 102 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/core/qtwin.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/core/qtwin.h rename code/nel/tools/3d/object_viewer_qt/src/plugins/{core => example}/qnel_widget.cpp (71%) rename code/nel/tools/3d/object_viewer_qt/src/plugins/{core => example}/qnel_widget.h (95%) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/camera_control.cpp b/code/nel/tools/3d/object_viewer_qt/src/camera_control.cpp index 2216fb88d..72b04129e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/camera_control.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/camera_control.cpp @@ -52,6 +52,7 @@ CCameraItem::CCameraItem(const QString &name): CCameraItem::~CCameraItem() { + Modules::objView().getScene()->deleteCamera(_camera); } void CCameraItem::setActive(bool active) @@ -182,6 +183,9 @@ CCameraControl::CCameraControl(QWidget *parent) CCameraControl::~CCameraControl() { + for(int i = 0; i < _cameraList.size(); ++i) + delete _cameraList[i]; + _cameraList.clear(); } void CCameraControl::setEditMode() diff --git a/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp index 5a75e7423..2176a6f93 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp @@ -145,6 +145,7 @@ CMainWindow::~CMainWindow() delete _TuneTimerDialog; delete _ParticleControlDialog; delete _ParticleWorkspaceDialog; + delete _cameraControl; if (_isSoundInitialized) Modules::sound().releaseGraphics(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt index a3de7e231..2ff8e894d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/CMakeLists.txt @@ -12,7 +12,6 @@ SET(OVQT_CORE_PLUGIN_HDR core_plugin.h main_window.h settings_dialog.h - qnel_widget.h search_paths_settings_page.h plugin_view_dialog.h) @@ -37,7 +36,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) ADD_LIBRARY(ovqt_plugin_core MODULE ${SRC} ${OVQT_CORE_PLUGIN_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_CORE_PLUGIN_RC_SRCS} ${OVQT_CORE_PLUGIN_UI_HDRS}) -TARGET_LINK_LIBRARIES(ovqt_plugin_core nelmisc nel3d ${QT_LIBRARIES}) +TARGET_LINK_LIBRARIES(ovqt_plugin_core nelmisc ${QT_LIBRARIES}) NL_DEFAULT_PROPS(ovqt_plugin_core "NeL, Tools, 3D: Object Viewer Qt Plugin: Core") NL_ADD_RUNTIME_FLAGS(ovqt_plugin_core) 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 164badf83..40ced76e5 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 @@ -15,8 +15,18 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +// Project includes #include "core_plugin.h" +#include "settings_dialog.h" +#include "core_constants.h" +#include "search_paths_settings_page.h" +#include "../../extension_system/iplugin_spec.h" +#include "qtwin.h" +// NeL includes +#include "nel/misc/debug.h" + +// Qt includes #include #include #include @@ -24,13 +34,6 @@ #include #include -#include "../../extension_system/iplugin_spec.h" - -#include "settings_dialog.h" -#include "core_constants.h" -#include "search_paths_settings_page.h" -#include "nel/misc/debug.h" - using namespace Core; bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString) @@ -45,8 +48,6 @@ bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStr return false; } - //_mainWindow = new CMainWindow(_plugMan); - //_mainWindow->show(); _plugMan->addObject(new CSearchPathsSettingsPage(wnd)); return true; } @@ -67,11 +68,30 @@ void CorePlugin::extensionsInitialized() connect(newAction, SIGNAL(triggered()), this, SLOT(execSettings())); connect(newAction2, SIGNAL(triggered()), _pluginView, SLOT(show())); + + _mainWindow = new CMainWindow(_plugMan); +#ifdef Q_WS_X11 + _mainWindow->setAttribute(Qt::WA_TranslucentBackground); + _mainWindow->setAttribute(Qt::WA_NoSystemBackground, false); + QPalette pal = _mainWindow->palette(); + QColor bg = pal.window().color(); + bg.setAlpha(180); + pal.setColor(QPalette::Window, bg); + _mainWindow->setPalette(pal); + _mainWindow->ensurePolished(); // workaround Oxygen filling the background + _mainWindow->setAttribute(Qt::WA_StyledBackground, false); +#endif + if (QtWin::isCompositionEnabled()) + { + QtWin::extendFrameIntoClientArea(_mainWindow); + _mainWindow->setContentsMargins(0, 0, 0, 0); + } + _mainWindow->show(); } void CorePlugin::shutdown() { - //delete _mainWindow; + delete _mainWindow; delete _pluginView; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/iapp_page.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/iapp_page.h index bdcd1191f..49e9ea265 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/iapp_page.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/iapp_page.h @@ -45,7 +45,7 @@ public: virtual QIcon icon() const = 0; /// The widget will be destroyed by the widget hierarchy when the main window closes - virtual QWidget *widget(QWidget *parent) = 0; + virtual QWidget *widget() = 0; }; } // namespace Core 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 89d5d48a0..fe75db99c 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 @@ -38,6 +38,7 @@ CMainWindow::CMainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget setObjectName(Constants::MAIN_WINDOW); _tabWidget = new QTabWidget(this); + _tabWidget->setTabPosition(QTabWidget::South); setCentralWidget(_tabWidget); QList listObjects = _pluginManager->allObjects(); @@ -56,7 +57,7 @@ CMainWindow::CMainWindow(ExtensionSystem::IPluginManager *pluginManager, QWidget QGridLayout *gridLayout = new QGridLayout(tabWidget); gridLayout->setObjectName(QString::fromUtf8("gridLayout_") + appPage->id()); gridLayout->setContentsMargins(0, 0, 0, 0); - gridLayout->addWidget(appPage->widget(tabWidget), 0, 0, 1, 1); + gridLayout->addWidget(appPage->widget(), 0, 0, 1, 1); } setDockNestingEnabled(true); 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 49c668b14..517da92d2 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 @@ -18,17 +18,16 @@ #ifndef MAIN_WINDOW_H #define MAIN_WINDOW_H +// Project includes +#include "../../extension_system/iplugin.h" +#include "plugin_view_dialog.h" + // STL includes // Qt includes #include #include -// Project includes -#include "qnel_widget.h" -#include "../../extension_system/iplugin.h" -#include "plugin_view_dialog.h" - namespace Core { class CSettingsDialog; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/qtwin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/qtwin.cpp new file mode 100644 index 000000000..dc0fb6cf0 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/qtwin.cpp @@ -0,0 +1,241 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Use, modification and distribution is allowed without limitation, +** warranty, liability or support of any kind. +** +****************************************************************************/ + +#include "qtwin.h" +#include +#include +#include +#include +#include + +#ifdef Q_WS_WIN + +#include + +// Blur behind data structures +#define DWM_BB_ENABLE 0x00000001 // fEnable has been specified +#define DWM_BB_BLURREGION 0x00000002 // hRgnBlur has been specified +#define DWM_BB_TRANSITIONONMAXIMIZED 0x00000004 // fTransitionOnMaximized has been specified +#define WM_DWMCOMPOSITIONCHANGED 0x031E // Composition changed window message + +typedef struct _DWM_BLURBEHIND +{ + DWORD dwFlags; + BOOL fEnable; + HRGN hRgnBlur; + BOOL fTransitionOnMaximized; +} DWM_BLURBEHIND, *PDWM_BLURBEHIND; + +typedef struct _MARGINS +{ + int cxLeftWidth; + int cxRightWidth; + int cyTopHeight; + int cyBottomHeight; +} MARGINS, *PMARGINS; + +typedef HRESULT (WINAPI *PtrDwmIsCompositionEnabled)(BOOL* pfEnabled); +typedef HRESULT (WINAPI *PtrDwmExtendFrameIntoClientArea)(HWND hWnd, const MARGINS* pMarInset); +typedef HRESULT (WINAPI *PtrDwmEnableBlurBehindWindow)(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind); +typedef HRESULT (WINAPI *PtrDwmGetColorizationColor)(DWORD *pcrColorization, BOOL *pfOpaqueBlend); + +static PtrDwmIsCompositionEnabled pDwmIsCompositionEnabled= 0; +static PtrDwmEnableBlurBehindWindow pDwmEnableBlurBehindWindow = 0; +static PtrDwmExtendFrameIntoClientArea pDwmExtendFrameIntoClientArea = 0; +static PtrDwmGetColorizationColor pDwmGetColorizationColor = 0; + + +/* + * Internal helper class that notifies windows if the + * DWM compositing state changes and updates the widget + * flags correspondingly. + */ +class WindowNotifier : public QWidget +{ +public: + WindowNotifier() + { + winId(); + } + void addWidget(QWidget *widget) + { + widgets.append(widget); + } + void removeWidget(QWidget *widget) + { + widgets.removeAll(widget); + } + bool winEvent(MSG *message, long *result); + +private: + QWidgetList widgets; +}; + +static bool resolveLibs() +{ + if (!pDwmIsCompositionEnabled) + { + QLibrary dwmLib(QString::fromAscii("dwmapi")); + pDwmIsCompositionEnabled =(PtrDwmIsCompositionEnabled)dwmLib.resolve("DwmIsCompositionEnabled"); + pDwmExtendFrameIntoClientArea = (PtrDwmExtendFrameIntoClientArea)dwmLib.resolve("DwmExtendFrameIntoClientArea"); + pDwmEnableBlurBehindWindow = (PtrDwmEnableBlurBehindWindow)dwmLib.resolve("DwmEnableBlurBehindWindow"); + pDwmGetColorizationColor = (PtrDwmGetColorizationColor)dwmLib.resolve("DwmGetColorizationColor"); + } + return pDwmIsCompositionEnabled != 0; +} + +#endif + +/*! + * Chekcs and returns true if Windows DWM composition + * is currently enabled on the system. + * + * To get live notification on the availability of + * this feature, you will currently have to + * reimplement winEvent() on your widget and listen + * for the WM_DWMCOMPOSITIONCHANGED event to occur. + * + */ +bool QtWin::isCompositionEnabled() +{ +#ifdef Q_WS_WIN + if (resolveLibs()) + { + HRESULT hr = S_OK; + BOOL isEnabled = false; + hr = pDwmIsCompositionEnabled(&isEnabled); + if (SUCCEEDED(hr)) + return isEnabled; + } +#endif + return false; +} + +/*! + * Enables Blur behind on a Widget. + * + * \a enable tells if the blur should be enabled or not + */ +bool QtWin::enableBlurBehindWindow(QWidget *widget, bool enable) +{ + Q_ASSERT(widget); + bool result = false; +#ifdef Q_WS_WIN + if (resolveLibs()) + { + DWM_BLURBEHIND bb = {0}; + HRESULT hr = S_OK; + bb.fEnable = enable; + bb.dwFlags = DWM_BB_ENABLE; + bb.hRgnBlur = NULL; + widget->setAttribute(Qt::WA_TranslucentBackground, enable); + widget->setAttribute(Qt::WA_NoSystemBackground, enable); + hr = pDwmEnableBlurBehindWindow(widget->winId(), &bb); + if (SUCCEEDED(hr)) + { + result = true; + windowNotifier()->addWidget(widget); + } + } +#endif + return result; +} + +/*! + * ExtendFrameIntoClientArea. + * + * This controls the rendering of the frame inside the window. + * Note that passing margins of -1 (the default value) will completely + * remove the frame from the window. + * + * \note you should not call enableBlurBehindWindow before calling + * this functions + * + * \a enable tells if the blur should be enabled or not + */ +bool QtWin::extendFrameIntoClientArea(QWidget *widget, int left, int top, int right, int bottom) +{ + + Q_ASSERT(widget); + Q_UNUSED(left); + Q_UNUSED(top); + Q_UNUSED(right); + Q_UNUSED(bottom); + + bool result = false; +#ifdef Q_WS_WIN + if (resolveLibs()) + { + QLibrary dwmLib(QString::fromAscii("dwmapi")); + HRESULT hr = S_OK; + MARGINS m = {left, top, right, bottom}; + hr = pDwmExtendFrameIntoClientArea(widget->winId(), &m); + if (SUCCEEDED(hr)) + { + result = true; + windowNotifier()->addWidget(widget); + } + widget->setAttribute(Qt::WA_TranslucentBackground, result); + } +#endif + return result; +} + +/*! + * Returns the current colorizationColor for the window. + * + * \a enable tells if the blur should be enabled or not + */ +QColor QtWin::colorizatinColor() +{ + QColor resultColor = QApplication::palette().window().color(); + +#ifdef Q_WS_WIN + if (resolveLibs()) + { + DWORD color = 0; + BOOL opaque = FALSE; + QLibrary dwmLib(QString::fromAscii("dwmapi")); + HRESULT hr = S_OK; + hr = pDwmGetColorizationColor(&color, &opaque); + if (SUCCEEDED(hr)) + resultColor = QColor(color); + } +#endif + return resultColor; +} + +#ifdef Q_WS_WIN +WindowNotifier *QtWin::windowNotifier() +{ + static WindowNotifier *windowNotifierInstance = 0; + if (!windowNotifierInstance) + windowNotifierInstance = new WindowNotifier; + return windowNotifierInstance; +} + + +/* Notify all enabled windows that the DWM state changed */ +bool WindowNotifier::winEvent(MSG *message, long *result) +{ + if (message && message->message == WM_DWMCOMPOSITIONCHANGED) + { + bool compositionEnabled = QtWin::isCompositionEnabled(); + Q_FOREACH(QWidget * widget, widgets) + { + if (widget) + { + widget->setAttribute(Qt::WA_NoSystemBackground, compositionEnabled); + } + widget->update(); + } + } + return QWidget::winEvent(message, result); +} +#endif diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/qtwin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/qtwin.h new file mode 100644 index 000000000..039fa3f8d --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/qtwin.h @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Use, modification and distribution is allowed without limitation, +** warranty, liability or support of any kind. +** +****************************************************************************/ + +#ifndef QTWIN_H +#define QTWIN_H + +#include +#include +/** + * This is a helper class for using the Desktop Window Manager + * functionality on Windows 7 and Windows Vista. On other platforms + * these functions will simply not do anything. + */ + +class WindowNotifier; + +class QtWin +{ +public: + static bool enableBlurBehindWindow(QWidget *widget, bool enable = true); + static bool extendFrameIntoClientArea(QWidget *widget, + int left = -1, int top = -1, + int right = -1, int bottom = -1); + static bool isCompositionEnabled(); + static QColor colorizatinColor(); + +private: + static WindowNotifier *windowNotifier(); +}; + +#endif // QTWIN_H 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 e6d75ad11..9afe59a2b 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 @@ -10,7 +10,10 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin. ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) 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 ${CMAKE_CURRENT_SOURCE_DIR}/../core/ioptions_page.h) SET(OVQT_PLUG_EXAMPLE_UIS example_settings_page.ui) @@ -29,7 +32,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) ADD_LIBRARY(ovqt_plugin_example MODULE ${SRC} ${OVQT_PLUG_EXAMPLE_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_PLUG_EXAMPLE_UI_HDRS}) -TARGET_LINK_LIBRARIES(ovqt_plugin_example nelmisc ${QT_LIBRARIES}) +TARGET_LINK_LIBRARIES(ovqt_plugin_example nelmisc nel3d ${QT_LIBRARIES}) NL_DEFAULT_PROPS(ovqt_plugin_example "NeL, Tools, 3D: Object Viewer Qt Plugin: Example") NL_ADD_RUNTIME_FLAGS(ovqt_plugin_example) 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 18896b19d..a93a8b95c 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 @@ -1,18 +1,23 @@ -#include "plugin1.h" - -#include -#include -#include -#include -#include -#include - - -#include "../../extension_system/iplugin_spec.h" -#include "example_settings_page.h" -#include "nel/misc/debug.h" - -using namespace Plugin; +// Project includes +#include "plugin1.h" +#include "example_settings_page.h" +#include "simple_viewer.h" +#include "../core/iapp_page.h" +#include "../../extension_system/iplugin_spec.h" + +// NeL includes +#include "nel/misc/debug.h" + +// Qt includes +#include +#include +#include +#include +#include +#include + +namespace Plugin +{ bool MyPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString) { @@ -32,6 +37,7 @@ bool MyPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStrin *errorString = tr("Not found QMenu Help."); return false; } + _plugMan->addObject(new CExampleAppPage()); return true; } @@ -42,7 +48,7 @@ void MyPlugin::extensionsInitialized() helpMenu->addSeparator(); QAction *newAction = helpMenu->addAction("MyPlugin"); - + connect(newAction, SIGNAL(triggered()), this, SLOT(execMessageBox())); } @@ -50,7 +56,7 @@ void MyPlugin::execMessageBox() { QMainWindow *wnd = qobject_cast(objectByName("CMainWindow")); nlassert(wnd); - + QMessageBox msgBox; msgBox.setText(wnd->objectName() + QString(": width=%1,height=%2").arg(wnd->width()).arg(wnd->height())); msgBox.exec(); @@ -81,30 +87,32 @@ QString MyPlugin::vendor() const return "dnk-88"; } -QString MyPlugin::description() const +QString MyPlugin::description() const { return "Example ovqt plugin."; } - -QList MyPlugin::dependencies() const -{ - return QList(); -} - -QObject* MyPlugin::objectByName(const QString &name) const -{ + +QList MyPlugin::dependencies() const +{ + return QList(); +} + +QObject* MyPlugin::objectByName(const QString &name) const +{ Q_FOREACH (QObject *qobj, _plugMan->allObjects()) if (qobj->objectName() == name) - return qobj; - return 0; -} - -ExtensionSystem::IPluginSpec *MyPlugin::pluginByName(const QString &name) const -{ + return qobj; + return 0; +} + +ExtensionSystem::IPluginSpec *MyPlugin::pluginByName(const QString &name) const +{ Q_FOREACH (ExtensionSystem::IPluginSpec *spec, _plugMan->plugins()) if (spec->name() == name) return spec; - return 0; -} - -Q_EXPORT_PLUGIN(MyPlugin) + return 0; +} + +} + +Q_EXPORT_PLUGIN(Plugin::MyPlugin) \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.h index cba55f5e0..291d3238f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.h @@ -1,11 +1,17 @@ #ifndef PLUGIN1_H #define PLUGIN1_H +// Project includes #include "../../extension_system/iplugin.h" +#include "simple_viewer.h" +#include "../core/iapp_page.h" +// NeL includes #include "nel/misc/app_context.h" +// Qt includes #include +#include namespace NLMISC { @@ -17,7 +23,7 @@ namespace ExtensionSystem class IPluginSpec; } -namespace Plugin +namespace Plugin { class MyPlugin : public QObject, public ExtensionSystem::IPlugin @@ -31,26 +37,52 @@ public: void setNelContext(NLMISC::INelContext *nelContext); - QString name() const; - QString version() const; - QString vendor() const; + QString name() const; + QString version() const; + QString vendor() const; QString description() const; - QList dependencies() const; - - QObject *objectByName(const QString &name) const; + QList dependencies() const; + + QObject *objectByName(const QString &name) const; ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const; private Q_SLOTS: void execMessageBox(); -protected: - NLMISC::CLibraryContext *_LibContext; +protected: + NLMISC::CLibraryContext *_LibContext; private: ExtensionSystem::IPluginManager *_plugMan; }; +class CExampleAppPage: public QObject, public Core::IAppPage +{ + Q_OBJECT + Q_INTERFACES(Core::IAppPage) +public: + CExampleAppPage(QObject *parent = 0): QObject(parent) {} + virtual ~CExampleAppPage() {} + + virtual QString id() const + { + return QLatin1String("ExampleAppPage"); + } + virtual QString trName() const + { + return tr("SimpleViewer"); + } + virtual QIcon icon() const + { + return QIcon(); + } + virtual QWidget *widget() + { + return new CSimpleViewer(); + } +}; + } // namespace Plugin #endif // PLUGIN1_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/qnel_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/qnel_widget.cpp similarity index 71% rename from code/nel/tools/3d/object_viewer_qt/src/plugins/core/qnel_widget.cpp rename to code/nel/tools/3d/object_viewer_qt/src/plugins/example/qnel_widget.cpp index a422ec5d1..d2db23883 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/qnel_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/qnel_widget.cpp @@ -38,6 +38,9 @@ QNLWidget::QNLWidget(QWidget *parent) _initialized(false), _interval(25) { + setMouseTracking(true); + setFocusPolicy(Qt::StrongFocus); + init(); _mainTimer = new QTimer(this); connect(_mainTimer, SIGNAL(timeout()), this, SLOT(updateRender())); @@ -110,39 +113,6 @@ void QNLWidget::showEvent(QShowEvent *showEvent) _mainTimer->stop(); } -#if defined(NL_OS_WINDOWS) || defined(NL_OS_MAC) -// Qt does not provide wheel events through winEvent() and macEvent() (but it -// does through x11Event(), which is inconsistent...) -// Workaround is to handle wheel events like implemented below. -// -// TODO: this is not a clean solution, because all but wheel events are -// handled using winEvent(), x11Event(), macEvent(). But this seems to be a -// limitation of current (4.7.1) Qt versions. (see e.g. qapplication_mac.mm) -void QNLWidget::wheelEvent(QWheelEvent *event) -{ - // Get relative positions. - float fX = 1.0f - (float)event->pos().x() / this->width(); - float fY = 1.0f - (float)event->pos().y() / this->height(); - - // Get the buttons currently pressed. - uint32 buttons = NLMISC::noButton; - if(event->buttons() & Qt::LeftButton) buttons |= NLMISC::leftButton; - if(event->buttons() & Qt::RightButton) buttons |= NLMISC::rightButton; - if(event->buttons() & Qt::MidButton) buttons |= NLMISC::middleButton; - if(event->modifiers() & Qt::ControlModifier) buttons |= NLMISC::ctrlButton; - if(event->modifiers() & Qt::ShiftModifier) buttons |= NLMISC::shiftButton; - if(event->modifiers() & Qt::AltModifier) buttons |= NLMISC::altButton; - - if(event->delta() > 0) - _driver->EventServer.postEvent( - new NLMISC::CEventMouseWheel(-fX, fY, (NLMISC::TMouseButton)buttons, true, NULL)); - else - _driver->EventServer.postEvent( - new NLMISC::CEventMouseWheel(-fX, fY, (NLMISC::TMouseButton)buttons, false, NULL)); -} -#endif // defined(NL_OS_WINDOWS) || defined(NL_OS_MAC) - - #if defined(NL_OS_WINDOWS) typedef bool (*winProc)(NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/qnel_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/qnel_widget.h similarity index 95% rename from code/nel/tools/3d/object_viewer_qt/src/plugins/core/qnel_widget.h rename to code/nel/tools/3d/object_viewer_qt/src/plugins/example/qnel_widget.h index a8238fa39..0473f819d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/qnel_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/qnel_widget.h @@ -65,10 +65,6 @@ private Q_SLOTS: protected: virtual void showEvent(QShowEvent *showEvent); -#if defined(NL_OS_WINDOWS) || defined(NL_OS_MAC) - virtual void wheelEvent(QWheelEvent *event); -#endif - #if defined(NL_OS_WINDOWS) virtual bool winEvent(MSG *message, long *result); #elif defined(NL_OS_MAC) 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 new file mode 100644 index 000000000..bbf9df80e --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.cpp @@ -0,0 +1,42 @@ +// 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 . + +#include "simple_viewer.h" + +// Qt includes +#include +#include + +// NeL includes + +// Project includes + +namespace Plugin +{ + +CSimpleViewer::CSimpleViewer(QWidget *parent) + : QWidget(parent) +{ + QGridLayout *gridLayout = new QGridLayout(this); + gridLayout->setObjectName(QString::fromUtf8("gridLayoutSimpleViewer")); + gridLayout->setContentsMargins(0, 0, 0, 0); + NLQT::QNLWidget *_nelWidget = new NLQT::QNLWidget(this); + gridLayout->addWidget(_nelWidget, 0, 0, 1, 1); +} + + +} /* 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 new file mode 100644 index 000000000..e9d83cfa3 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h @@ -0,0 +1,43 @@ +// 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 . + + +#ifndef SIMPLE_VIEWER_H +#define SIMPLE_VIEWER_H + +// Project includes +#include "qnel_widget.h" + +// Qt includes +#include + +class QWidget; + +namespace Plugin +{ + +class CSimpleViewer : public QWidget +{ + Q_OBJECT +public: + CSimpleViewer(QWidget *parent = 0); + virtual ~CSimpleViewer() {} +}; + +} // namespace Plugin + +#endif // SIMPLE_VIEWER_H