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/
This commit is contained in:
committed by
wmayer
parent
33baa4a9f2
commit
2e32324007
@@ -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<QuarterWidget *>(parent);
|
||||
QuarterWidget* quarter = dynamic_cast<QuarterWidget *>(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
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<int>(dev_pix_ratio * this->width());
|
||||
int height = static_cast<int>(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) {
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <Quarter/Basic.h>
|
||||
#include <Inventor/SbVec2s.h>
|
||||
#include <Quarter/QuarterWidget.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user