Yet more changes and addition to improve compatibility with high dpi devices (like retina)

This commit is contained in:
Paolo Cignoni 2013-12-16 11:34:17 +00:00
parent 999d442dda
commit 78c58e8d14
3 changed files with 47 additions and 16 deletions

View File

@ -0,0 +1,37 @@
#ifndef DEVICE_TO_LOGICAL_H
#define DEVICE_TO_LOGICAL_H
#include <QPainter>
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

View File

@ -25,6 +25,7 @@
#include <QMessageBox>
#include <wrap/qt/col_qt_convert.h>
#include <wrap/qt/device_to_logical.h>
#include <wrap/qt/checkGLError.h>
#include <QPainter>
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)

View File

@ -23,19 +23,14 @@
#ifndef QT_TRACKBALL_H
#define QT_TRACKBALL_H
#include <wrap/qt/device_to_logical.h>
/// 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