From 6f388b05a612315bbf4a3022b2079403fdac95b6 Mon Sep 17 00:00:00 2001 From: rti Date: Tue, 14 Dec 2010 18:13:53 +0100 Subject: [PATCH] Fixed: workaround for OVQT mouse wheel on Windows and Mac --- .../src/graphics_viewport.cpp | 33 +++++++++++++++++++ .../object_viewer_qt/src/graphics_viewport.h | 4 +++ 2 files changed, 37 insertions(+) diff --git a/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.cpp b/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.cpp index 2ea99c576..dc8a81dc8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.cpp @@ -116,6 +116,39 @@ void CGraphicsViewport::resizeEvent(QResizeEvent *resizeEvent) Modules::objView().setSizeViewport(resizeEvent->size().width(), resizeEvent->size().height()); } +#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 CGraphicsViewport::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) + Modules::objView().getDriver()->EventServer.postEvent( + new NLMISC::CEventMouseWheel(-fX, fY, (NLMISC::TMouseButton)buttons, true, NULL)); + else + Modules::objView().getDriver()->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/graphics_viewport.h b/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.h index b49734776..6dd6632c7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.h +++ b/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.h @@ -80,6 +80,10 @@ private Q_SLOTS: protected: virtual void resizeEvent(QResizeEvent *resizeEvent); +#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)