Fixed: workaround for OVQT mouse wheel on Windows and Mac
This commit is contained in:
parent
e316e95579
commit
6f388b05a6
2 changed files with 37 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue