I fixed this in our quarter fork:
https://grey.colorado.edu/emergent/index.php/Coin3d — mostly in revision 33 — attaching the diffs in case this is helpful in porting over to SoQt. all the stuff about devicepixelratio.. Cheers,
- Randy
root@shadow:/usr/local/Coin3d/quarter/ # svn -r 33:32 diff
Index: include/Quarter/QuarterWidget.h
===================================================================
--- include/Quarter/QuarterWidget.h (revision 33)
+++ include/Quarter/QuarterWidget.h (revision 32)
@@ -74,7 +74,6 @@
Q_PROPERTY(TransparencyType transparencyType READ transparencyType WRITE setTransparencyType)
Q_PROPERTY(RenderMode renderMode READ renderMode WRITE setRenderMode)
Q_PROPERTY(StereoMode stereoMode READ stereoMode WRITE setStereoMode)
- Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged)
Q_ENUMS(TransparencyType)
Q_ENUMS(RenderMode)
@@ -128,8 +127,6 @@
void setBackgroundColor(const QColor & color);
QColor backgroundColor(void) const;
- qreal devicePixelRatio(void) const;
-
void resetNavigationModeFile(void);
void setNavigationModeFile(const QUrl & url = QUrl(DEFAULT_NAVIGATIONFILE));
const QUrl & navigationModeFile(void) const;
@@ -190,15 +187,11 @@
void setStereoMode(StereoMode mode);
void setTransparencyType(TransparencyType type);
-signals:
- void devicePixelRatioChanged(qreal dev_pixel_ratio);
-
protected:
virtual void resizeGL(int width, int height);
virtual void initializeGL(void);
virtual void paintGL(void);
virtual void actualRedraw(void);
- virtual bool updateDevicePixelRatio(void);
private:
void constructor(const QT_GL_WIDGET * sharewidget);
Index: include/Quarter/devices/InputDevice.h
===================================================================
--- include/Quarter/devices/InputDevice.h (revision 33)
+++ include/Quarter/devices/InputDevice.h (revision 32)
@@ -32,11 +32,9 @@
namespace SIM { namespace Coin3D { namespace Quarter {
-class QuarterWidget;
-
class QUARTER_DLL_API InputDevice {
public:
- InputDevice(QuarterWidget* quarter);
+ InputDevice(void);
virtual ~InputDevice() {}
/*!
@@ -52,7 +50,6 @@
protected:
SbVec2s mousepos;
SbVec2s windowsize;
- QuarterWidget* quarter;
};
}}} // namespace
Index: include/Quarter/devices/Keyboard.h
===================================================================
--- include/Quarter/devices/Keyboard.h (revision 33)
+++ include/Quarter/devices/Keyboard.h (revision 32)
@@ -33,7 +33,7 @@
class QUARTER_DLL_API Keyboard : public InputDevice {
public:
- Keyboard(QuarterWidget* quarter);
+ Keyboard(void);
virtual ~Keyboard();
virtual const SoEvent * translateEvent(QEvent * event);
Index: include/Quarter/devices/SpaceNavigatorDevice.h
===================================================================
--- include/Quarter/devices/SpaceNavigatorDevice.h (revision 33)
+++ include/Quarter/devices/SpaceNavigatorDevice.h (revision 32)
@@ -33,7 +33,7 @@
class QUARTER_DLL_API SpaceNavigatorDevice : public InputDevice {
public:
- SpaceNavigatorDevice(QuarterWidget* quarter);
+ SpaceNavigatorDevice(void);
virtual ~SpaceNavigatorDevice();
virtual const SoEvent * translateEvent(QEvent * event);
Index: include/Quarter/devices/Mouse.h
===================================================================
--- include/Quarter/devices/Mouse.h (revision 33)
+++ include/Quarter/devices/Mouse.h (revision 32)
@@ -28,13 +28,12 @@
class QEvent;
class SoEvent;
-class QuarterWidget;
namespace SIM { namespace Coin3D { namespace Quarter {
class QUARTER_DLL_API Mouse : public InputDevice {
public:
- Mouse(QuarterWidget* quarter);
+ Mouse(void);
virtual ~Mouse();
virtual const SoEvent * translateEvent(QEvent * event);
Index: src/Quarter/Keyboard.cpp
===================================================================
--- src/Quarter/Keyboard.cpp (revision 33)
+++ src/Quarter/Keyboard.cpp (revision 32)
@@ -41,8 +41,7 @@
#define PRIVATE(obj) obj->pimpl
-Keyboard::Keyboard(QuarterWidget* quart) :
- InputDevice(quart)
+Keyboard::Keyboard(void)
{
PRIVATE(this) = new KeyboardP(this);
}
Index: src/Quarter/QuarterWidgetP.cpp
===================================================================
--- src/Quarter/QuarterWidgetP.cpp (revision 33)
+++ src/Quarter/QuarterWidgetP.cpp (revision 32)
@@ -72,7 +72,6 @@
interactionmodeenabled(false),
clearzbuffer(true),
clearwindow(true),
- device_pixel_ratio(1.0),
addactions(true)
{
this->cachecontext = findCacheContext(masterptr, sharewidget);
Index: src/Quarter/QuarterWidgetP.h
===================================================================
--- src/Quarter/QuarterWidgetP.h (revision 33)
+++ src/Quarter/QuarterWidgetP.h (revision 32)
@@ -90,7 +90,6 @@
bool processdelayqueue;
QUrl navigationModeFile;
SoScXMLStateMachine * currentStateMachine;
- qreal device_pixel_ratio;
static void rendercb(void * userdata, SoRenderManager *);
static void prerendercb(void * userdata, SoRenderManager * manager);
Index: src/Quarter/InputDevice.cpp
===================================================================
--- src/Quarter/InputDevice.cpp (revision 33)
+++ src/Quarter/InputDevice.cpp (revision 32)
@@ -23,7 +23,6 @@
#include <Quarter/devices/InputDevice.h>
#include <QInputEvent>
#include <Inventor/events/SoEvents.h>
-#include <Quarter/QuarterWidget.h>
using namespace SIM::Coin3D::Quarter;
@@ -35,8 +34,7 @@
devices.
*/
-InputDevice::InputDevice(QuarterWidget* quart) :
- quarter(quart)
+InputDevice::InputDevice(void)
{
this->mousepos = SbVec2s(0, 0);
}
Index: src/Quarter/SpaceNavigatorDevice.cpp
===================================================================
--- src/Quarter/SpaceNavigatorDevice.cpp (revision 33)
+++ src/Quarter/SpaceNavigatorDevice.cpp (revision 32)
@@ -72,8 +72,7 @@
#define PRIVATE(obj) obj->pimpl
using namespace SIM::Coin3D::Quarter;
-SpaceNavigatorDevice::SpaceNavigatorDevice(QuarterWidget* quart) :
- InputDevice(quart)
+SpaceNavigatorDevice::SpaceNavigatorDevice()
{
PRIVATE(this) = new SpaceNavigatorDeviceP(this);
Index: src/Quarter/QuarterWidget.cpp
===================================================================
--- src/Quarter/QuarterWidget.cpp (revision 33)
+++ src/Quarter/QuarterWidget.cpp (revision 32)
@@ -456,23 +456,6 @@
}
/*!
- \property QuarterWidget::devicePixelRatio
-
- \copydetails QuarterWidget::devicePixelRatio
-*/
-
-/*!
- The ratio between logical and physical pixel sizes -- obtained from the window that
-the widget is located within, and updated whenver any change occurs, emitting a devicePixelRatioChanged signal. Only available for version Qt 5.6 and above (will be 1.0 for all previous versions)
- */
-
-qreal
-QuarterWidget::devicePixelRatio(void) const
-{
- return PRIVATE(this)->device_pixel_ratio;
-}
-
-/*!
Sets the Inventor scenegraph to be rendered
*/
void
@@ -674,16 +657,15 @@
this->getSoRenderManager()->reinitialize();
}
-
-bool
-QuarterWidget::updateDevicePixelRatio(void) {
+/*!
+ Overridden from QGLWidget to resize the Coin scenegraph
+ */
+void
+QuarterWidget::resizeGL(int width, int height)
+{
#ifdef QT_OPEN_GL_WIDGET
- qreal dev_pix_ratio = 1.0;
- QWidget* winwidg = window();
- QWindow* win = NULL;
- if(winwidg) {
- win = winwidg->windowHandle();
- }
+ float dev_pix_ratio = 1.0f;
+ QWindow* win = windowHandle();
if(win) {
dev_pix_ratio = win->devicePixelRatio();
}
@@ -690,28 +672,9 @@
else {
dev_pix_ratio = ((QGuiApplication*)QGuiApplication::instance())->devicePixelRatio();
}
- if(PRIVATE(this)->device_pixel_ratio != dev_pix_ratio) {
- PRIVATE(this)->device_pixel_ratio = dev_pix_ratio;
- emit devicePixelRatioChanged(dev_pix_ratio);
- return true;
- }
-#endif
- return false;
-}
-
-/*!
- Overridden from QGLWidget to resize the Coin scenegraph
- */
-void
-QuarterWidget::resizeGL(int width, int height)
-{
-#ifdef QT_OPEN_GL_WIDGET
- updateDevicePixelRatio();
- qreal dev_pix_ratio = devicePixelRatio();
width = (int)(dev_pix_ratio * width);
height = (int)(dev_pix_ratio * height);
#endif
-
SbViewportRegion vp(width, height);
PRIVATE(this)->sorendermanager->setViewportRegion(vp);
PRIVATE(this)->soeventmanager->setViewportRegion(vp);
@@ -723,17 +686,6 @@
void
QuarterWidget::paintGL(void)
{
-#ifdef QT_OPEN_GL_WIDGET
- if(updateDevicePixelRatio()) {
- qreal dev_pix_ratio = devicePixelRatio();
- int width = (int)(dev_pix_ratio * this->width());
- int height = (int)(dev_pix_ratio * this->height());
- SbViewportRegion vp(width, height);
- PRIVATE(this)->sorendermanager->setViewportRegion(vp);
- PRIVATE(this)->soeventmanager->setViewportRegion(vp);
- }
-#endif
-
assert(this->isValid() && "No valid GL context found!");
// We might have to process the delay queue here since we don't know
// if paintGL() is called from Qt, and we might have some sensors
Index: src/Quarter/EventFilter.cpp
===================================================================
--- src/Quarter/EventFilter.cpp (revision 33)
+++ src/Quarter/EventFilter.cpp (revision 32)
@@ -67,7 +67,9 @@
SbVec2s mousepos(event->pos().x(), this->windowsize[1] - event->pos().y() - 1);
// the following corrects for high-dpi displays (e.g., mac retina)
- mousepos *= quarterwidget->devicePixelRatio();
+#if (QT_VERSION >= 0x050000)
+ mousepos *= ((QGuiApplication*)QGuiApplication::instance())->devicePixelRatio();
+#endif
foreach(InputDevice * device, this->devices) {
device->setMousePosition(mousepos);
}
@@ -86,19 +88,17 @@
{
PRIVATE(this) = new EventFilterP;
- QuarterWidget* quarter = dynamic_cast<QuarterWidget *>(parent);
-
- PRIVATE(this)->quarterwidget = quarter;
+ PRIVATE(this)->quarterwidget = dynamic_cast<QuarterWidget *>(parent);
assert(PRIVATE(this)->quarterwidget);
PRIVATE(this)->windowsize = SbVec2s(PRIVATE(this)->quarterwidget->width(),
PRIVATE(this)->quarterwidget->height());
- PRIVATE(this)->devices += new Mouse(quarter);
- PRIVATE(this)->devices += new Keyboard(quarter);
+ PRIVATE(this)->devices += new Mouse;
+ PRIVATE(this)->devices += new Keyboard;
#ifdef HAVE_SPACENAV_LIB
- PRIVATE(this)->devices += new SpaceNavigatorDevice(quarter);
+ PRIVATE(this)->devices += new SpaceNavigatorDevice;
#endif // HAVE_SPACENAV_LIB
}
Index: src/Quarter/Mouse.cpp
===================================================================
--- src/Quarter/Mouse.cpp (revision 33)
+++ src/Quarter/Mouse.cpp (revision 32)
@@ -32,8 +32,6 @@
#include <QEvent>
#include <QSize>
#include <QWheelEvent>
-#include <Quarter/QuarterWidget.h>
-
#if (QT_VERSION >= 0x050000)
#include <QGuiApplication>
#endif
@@ -76,8 +74,7 @@
#define PRIVATE(obj) obj->pimpl
#define PUBLIC(obj) obj->publ
-Mouse::Mouse(QuarterWidget* quart) :
- InputDevice(quart)
+Mouse::Mouse(void)
{
PRIVATE(this) = new MouseP(this);
}
@@ -128,7 +125,9 @@
assert(this->windowsize[1] != -1);
SbVec2s pos(event->pos().x(), this->windowsize[1] - event->pos().y() - 1);
// the following corrects for high-dpi displays (e.g., mac retina)
- pos *= publ->quarter->devicePixelRatio();
+#if (QT_VERSION >= 0x050000)
+ pos *= ((QGuiApplication*)QGuiApplication::instance())->devicePixelRatio();
+#endif
this->location2->setPosition(pos);
this->mousebutton->setPosition(pos);
return this->location2;
@@ -140,7 +139,9 @@
PUBLIC(this)->setModifiers(this->mousebutton, 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)
- pos *= publ->quarter->devicePixelRatio();
+#if (QT_VERSION >= 0x050000)
+ pos *= ((QGuiApplication*)QGuiApplication::instance())->devicePixelRatio();
+#endif
this->location2->setPosition(pos);
this->mousebutton->setPosition(pos);
@@ -163,7 +164,9 @@
PUBLIC(this)->setModifiers(this->mousebutton, 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)
- pos *= publ->quarter->devicePixelRatio();
+#if (QT_VERSION >= 0x050000)
+ pos *= ((QGuiApplication*)QGuiApplication::instance())->devicePixelRatio();
+#endif
this->location2->setPosition(pos);
this->mousebutton->setPosition(pos);