From 2e32324007fbf1a991d7d60083e0dff6ba981eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Skowro=C5=84ski?= Date: Wed, 9 Aug 2017 22:49:58 +0200 Subject: [PATCH] Fix some more Quarter High DPI Display issues. Partially fixes #3130 (the offset issue). Related to issue #2968. Ported from code by Randall O'Reilly. https://grey.colorado.edu/svn/coin3d/quarter/trunk/ --- src/Gui/Quarter/EventFilter.cpp | 11 ++++++----- src/Gui/Quarter/InputDevice.cpp | 6 ++++++ src/Gui/Quarter/Keyboard.cpp | 6 ++++++ src/Gui/Quarter/Mouse.cpp | 12 +++++++++--- src/Gui/Quarter/QuarterWidget.cpp | 9 +++++++++ src/Gui/Quarter/SpaceNavigatorDevice.cpp | 16 ++++++++++++++++ src/Gui/Quarter/devices/InputDevice.h | 3 +++ src/Gui/Quarter/devices/Keyboard.h | 1 + src/Gui/Quarter/devices/Mouse.h | 1 + src/Gui/Quarter/devices/SpaceNavigatorDevice.h | 1 + 10 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/Gui/Quarter/EventFilter.cpp b/src/Gui/Quarter/EventFilter.cpp index 060882e2a7..557ee49358 100644 --- a/src/Gui/Quarter/EventFilter.cpp +++ b/src/Gui/Quarter/EventFilter.cpp @@ -79,7 +79,7 @@ public: SbVec2s mousepos(event->pos().x(), this->windowsize[1] - event->pos().y() - 1); // the following corrects for high-dpi displays (e.g. mac retina) #if QT_VERSION >= 0x050000 - mousepos *= ((QGuiApplication*)QGuiApplication::instance())->devicePixelRatio(); + mousepos *= quarterwidget->devicePixelRatio(); #endif foreach(InputDevice * device, this->devices) { device->setMousePosition(mousepos); @@ -98,17 +98,18 @@ EventFilter::EventFilter(QObject * parent) { PRIVATE(this) = new EventFilterP; - PRIVATE(this)->quarterwidget = dynamic_cast(parent); + QuarterWidget* quarter = dynamic_cast(parent); + PRIVATE(this)->quarterwidget = quarter; assert(PRIVATE(this)->quarterwidget); PRIVATE(this)->windowsize = SbVec2s(PRIVATE(this)->quarterwidget->width(), PRIVATE(this)->quarterwidget->height()); - PRIVATE(this)->devices += new Mouse; - PRIVATE(this)->devices += new Keyboard; + PRIVATE(this)->devices += new Mouse(quarter); + PRIVATE(this)->devices += new Keyboard(quarter); #ifdef HAVE_SPACENAV_LIB - PRIVATE(this)->devices += new SpaceNavigatorDevice; + PRIVATE(this)->devices += new SpaceNavigatorDevice(quarter); #endif // HAVE_SPACENAV_LIB } diff --git a/src/Gui/Quarter/InputDevice.cpp b/src/Gui/Quarter/InputDevice.cpp index d7562a0d6b..69a6e74e43 100644 --- a/src/Gui/Quarter/InputDevice.cpp +++ b/src/Gui/Quarter/InputDevice.cpp @@ -53,11 +53,17 @@ InputDevice::InputDevice(void) this->mousepos = SbVec2s(0, 0); } +InputDevice::InputDevice(QuarterWidget *quarter) : quarter(quarter) +{ + this->mousepos = SbVec2s(0, 0); +} + /*! Sets the mouseposition \param[in] pos position of mouse in pixelcoordinates */ + void InputDevice::setMousePosition(const SbVec2s & pos) { diff --git a/src/Gui/Quarter/Keyboard.cpp b/src/Gui/Quarter/Keyboard.cpp index 49ebc987aa..b7fbf9f028 100644 --- a/src/Gui/Quarter/Keyboard.cpp +++ b/src/Gui/Quarter/Keyboard.cpp @@ -60,6 +60,12 @@ Keyboard::Keyboard(void) PRIVATE(this) = new KeyboardP(this); } +Keyboard::Keyboard(QuarterWidget* quarter) : + InputDevice(quarter) +{ + PRIVATE(this) = new KeyboardP(this); +} + Keyboard::~Keyboard() { delete PRIVATE(this); diff --git a/src/Gui/Quarter/Mouse.cpp b/src/Gui/Quarter/Mouse.cpp index bb02cb96ff..41cc5b5c46 100644 --- a/src/Gui/Quarter/Mouse.cpp +++ b/src/Gui/Quarter/Mouse.cpp @@ -95,6 +95,12 @@ Mouse::Mouse(void) PRIVATE(this) = new MouseP(this); } +Mouse::Mouse(QuarterWidget *quarter) : + InputDevice(quarter) +{ + PRIVATE(this) = new MouseP(this); +} + Mouse::~Mouse() { delete PRIVATE(this); @@ -142,7 +148,7 @@ MouseP::mouseMoveEvent(QMouseEvent * event) SbVec2s pos(event->pos().x(), this->windowsize[1] - event->pos().y() - 1); // the following corrects for high-dpi displays (e.g. mac retina) #if QT_VERSION >= 0x050000 - pos *= ((QGuiApplication*)QGuiApplication::instance())->devicePixelRatio(); + pos *= publ->quarter->devicePixelRatio(); #endif this->location2->setPosition(pos); this->mousebutton->setPosition(pos); @@ -156,7 +162,7 @@ MouseP::mouseWheelEvent(QWheelEvent * event) SbVec2s pos(event->pos().x(), PUBLIC(this)->windowsize[1] - event->pos().y() - 1); // the following corrects for high-dpi displays (e.g. mac retina) #if QT_VERSION >= 0x050000 - pos *= ((QGuiApplication*)QGuiApplication::instance())->devicePixelRatio(); + pos *= publ->quarter->devicePixelRatio(); #endif this->location2->setPosition(pos); this->mousebutton->setPosition(pos); @@ -181,7 +187,7 @@ MouseP::mouseButtonEvent(QMouseEvent * event) SbVec2s pos(event->pos().x(), PUBLIC(this)->windowsize[1] - event->pos().y() - 1); // the following corrects for high-dpi displays (e.g. mac retina) #if QT_VERSION >= 0x050000 - pos *= ((QGuiApplication*)QGuiApplication::instance())->devicePixelRatio(); + pos *= publ->quarter->devicePixelRatio(); #endif this->location2->setPosition(pos); this->mousebutton->setPosition(pos); diff --git a/src/Gui/Quarter/QuarterWidget.cpp b/src/Gui/Quarter/QuarterWidget.cpp index 571771a4e0..c2e1f805ae 100644 --- a/src/Gui/Quarter/QuarterWidget.cpp +++ b/src/Gui/Quarter/QuarterWidget.cpp @@ -835,6 +835,15 @@ void QuarterWidget::resizeEvent(QResizeEvent* event) */ void QuarterWidget::paintEvent(QPaintEvent* event) { + if(updateDevicePixelRatio()) { + qreal dev_pix_ratio = devicePixelRatio(); + int width = static_cast(dev_pix_ratio * this->width()); + int height = static_cast(dev_pix_ratio * this->height()); + SbViewportRegion vp(width, height); + PRIVATE(this)->sorendermanager->setViewportRegion(vp); + PRIVATE(this)->soeventmanager->setViewportRegion(vp); + } + std::clock_t begin = std::clock(); if(!initialized) { diff --git a/src/Gui/Quarter/SpaceNavigatorDevice.cpp b/src/Gui/Quarter/SpaceNavigatorDevice.cpp index cf49e80e85..14fe49e871 100644 --- a/src/Gui/Quarter/SpaceNavigatorDevice.cpp +++ b/src/Gui/Quarter/SpaceNavigatorDevice.cpp @@ -101,6 +101,22 @@ SpaceNavigatorDevice::SpaceNavigatorDevice() #endif // HAVE_SPACENAV_LIB } +SpaceNavigatorDevice::SpaceNavigatorDevice(QuarterWidget *quarter) : + InputDevice(quarter) +{ + PRIVATE(this) = new SpaceNavigatorDeviceP(this); + +#ifdef HAVE_SPACENAV_LIB + PRIVATE(this)->hasdevice = + spnav_x11_open(QX11Info::display(), PRIVATE(this)->windowid) == -1 ? false : true; + + // FIXME: Use a debugmessage mechanism instead? (20101020 handegar) + if (!PRIVATE(this)->hasdevice) { + fprintf(stderr, "Quarter:: Could not hook up to Spacenav device.\n"); + } + +#endif // HAVE_SPACENAV_LIB +} SpaceNavigatorDevice::~SpaceNavigatorDevice() { diff --git a/src/Gui/Quarter/devices/InputDevice.h b/src/Gui/Quarter/devices/InputDevice.h index 9e7d1eb46b..e09105e6f7 100644 --- a/src/Gui/Quarter/devices/InputDevice.h +++ b/src/Gui/Quarter/devices/InputDevice.h @@ -35,6 +35,7 @@ #include #include +#include class QEvent; class SoEvent; @@ -44,6 +45,7 @@ namespace SIM { namespace Coin3D { namespace Quarter { class QUARTER_DLL_API InputDevice { public: + InputDevice(QuarterWidget * quarter); InputDevice(void); virtual ~InputDevice() {} @@ -60,6 +62,7 @@ public: protected: SbVec2s mousepos; SbVec2s windowsize; + QuarterWidget* quarter; }; }}} // namespace diff --git a/src/Gui/Quarter/devices/Keyboard.h b/src/Gui/Quarter/devices/Keyboard.h index f00b371bef..8284798881 100644 --- a/src/Gui/Quarter/devices/Keyboard.h +++ b/src/Gui/Quarter/devices/Keyboard.h @@ -43,6 +43,7 @@ namespace SIM { namespace Coin3D { namespace Quarter { class QUARTER_DLL_API Keyboard : public InputDevice { public: + Keyboard(QuarterWidget* quarter); Keyboard(void); virtual ~Keyboard(); diff --git a/src/Gui/Quarter/devices/Mouse.h b/src/Gui/Quarter/devices/Mouse.h index 0308694fbf..49405368c2 100644 --- a/src/Gui/Quarter/devices/Mouse.h +++ b/src/Gui/Quarter/devices/Mouse.h @@ -43,6 +43,7 @@ namespace SIM { namespace Coin3D { namespace Quarter { class QUARTER_DLL_API Mouse : public InputDevice { public: + Mouse(QuarterWidget* quarter); Mouse(void); virtual ~Mouse(); diff --git a/src/Gui/Quarter/devices/SpaceNavigatorDevice.h b/src/Gui/Quarter/devices/SpaceNavigatorDevice.h index ac4b88ffcf..30224f6446 100644 --- a/src/Gui/Quarter/devices/SpaceNavigatorDevice.h +++ b/src/Gui/Quarter/devices/SpaceNavigatorDevice.h @@ -42,6 +42,7 @@ namespace SIM { namespace Coin3D { namespace Quarter { class QUARTER_DLL_API SpaceNavigatorDevice : public InputDevice { public: + SpaceNavigatorDevice(QuarterWidget* quarter); SpaceNavigatorDevice(void); virtual ~SpaceNavigatorDevice(); virtual const SoEvent * translateEvent(QEvent * event);