diff --git a/wrap/qt/device_to_logical.h b/wrap/qt/device_to_logical.h new file mode 100644 index 00000000..95d13980 --- /dev/null +++ b/wrap/qt/device_to_logical.h @@ -0,0 +1,37 @@ +#ifndef DEVICE_TO_LOGICAL_H +#define DEVICE_TO_LOGICAL_H +#include +template < class ValueType> +inline ValueType QTLogicalToDevice( QWidget *qw, const ValueType &value) +{ +#if QT_VERSION >= 0x050000 + return value*qw->devicePixelRatio() ; +#else + Q_UNUSED(qw); + return value; +#endif +} + +template < class ValueType> +inline ValueType QTLogicalToDevice( QPainter *qp, const ValueType &value) +{ +#if QT_VERSION >= 0x050000 + return value*qp->device()->devicePixelRatio() ; +#else + Q_UNUSED(qp); + return value; +#endif +} + +template < class ValueType> +inline ValueType QTDeviceToLogical( QPainter *qp, const ValueType &value) +{ +#if QT_VERSION >= 0x050000 + return value/qp->device()->devicePixelRatio() ; +#else + Q_UNUSED(qp); + return value; +#endif +} + +#endif // DEVICE_TO_LOGICAL_H diff --git a/wrap/qt/gl_label.h b/wrap/qt/gl_label.h index 86c06764..10f39b89 100755 --- a/wrap/qt/gl_label.h +++ b/wrap/qt/gl_label.h @@ -25,6 +25,7 @@ #include #include +#include #include #include namespace vcg @@ -33,7 +34,8 @@ namespace vcg */ class glLabel { - public: + + public: class Mode { public: @@ -64,7 +66,7 @@ namespace vcg private: static void enter2D(QPainter *painter) { - glPushAttrib(GL_ENABLE_BIT); + glPushAttrib(GL_ENABLE_BIT|GL_VIEWPORT_BIT); glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -84,7 +86,6 @@ namespace vcg glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); - //checkGLError::qDebug("glLabel"); } public: @@ -134,6 +135,7 @@ namespace vcg base.setX(-textBox.width() -qfm.maxWidth()); painter->drawText(base,text); glLabel::exit2D(painter); + glViewport(view[0],view[1],view[2],view[3]); } static void render(QPainter *painter, const vcg::Point3f &p, const QString &text) @@ -162,7 +164,8 @@ namespace vcg painter->setRenderHint(QPainter::TextAntialiasing); painter->setPen(vcg::ColorConverter::ToQColor(m.color)); painter->setFont(m.qFont); - painter->translate(QPointF(winx,view[3]-winy)); + painter->translate(QPointF(QTDeviceToLogical(painter,winx), + QTDeviceToLogical(painter,view[3]-winy))); painter->rotate(m.angle); QPoint base(0,qfm.ascent()/2); if(m.rightAlign) diff --git a/wrap/qt/trackball.h b/wrap/qt/trackball.h index 089d225b..866e6988 100644 --- a/wrap/qt/trackball.h +++ b/wrap/qt/trackball.h @@ -23,19 +23,14 @@ #ifndef QT_TRACKBALL_H #define QT_TRACKBALL_H +#include /// Transforms the event coordintates (that are device independent) /// into the expected framebuffer coordinates (e.g.in opengl pixels) /// This is necessary because trackball works in the viewport coord systems. - inline float QT2VCG_X( QWidget *qw, QMouseEvent *e) { -#if QT_VERSION >= 0x050000 - return e->x ()*qw->devicePixelRatio() ; -#else - Q_UNUSED(qw); - return e->x (); -#endif + return QTLogicalToDevice(qw,e->x()); } /// Transforms the event coordintates (that are device independent) @@ -44,11 +39,7 @@ inline float QT2VCG_X( QWidget *qw, QMouseEvent *e) inline float QT2VCG_Y( QWidget *qw, QMouseEvent *e) { -#if QT_VERSION >= 0x050000 - return (qw->height () - e->y ())*qw->devicePixelRatio() ; -#else - return qw->height () - e->y (); -#endif + return QTLogicalToDevice(qw,qw->height () - e->y ()); } /// Takes a QT MouseButton, some QT KeyboardModifiers and returns the equivalent Trackball::Button