Go to the documentation of this file.00001 #ifndef DEVICE_TO_LOGICAL_H
00002 #define DEVICE_TO_LOGICAL_H
00003 #include <QWidget>
00004 #include <QPainter>
00005 #include <vcg/space/point2.h>
00006
00007 template < class ValueType>
00008 inline ValueType QTLogicalToDevice( QWidget *qw, const ValueType &value)
00009 {
00010 #if QT_VERSION >= 0x050000
00011 return value*qw->devicePixelRatio() ;
00012 #else
00013 Q_UNUSED(qw);
00014 return value;
00015 #endif
00016 }
00017
00018 template < class ValueType>
00019 inline ValueType QTLogicalToDevice( QPainter *qp, const ValueType &value)
00020 {
00021 #if QT_VERSION >= 0x050000
00022 return value*qp->device()->devicePixelRatio() ;
00023 #else
00024 Q_UNUSED(qp);
00025 return value;
00026 #endif
00027 }
00028
00029 template < class ValueType>
00030 inline ValueType QTDeviceToLogical( QWidget *qw, const ValueType &value)
00031 {
00032 #if QT_VERSION >= 0x050000
00033 return value/qw->devicePixelRatio() ;
00034 #else
00035 Q_UNUSED(qw);
00036 return value;
00037 #endif
00038 }
00039
00040 template < class ValueType>
00041 inline ValueType QTDeviceToLogical( QPainter *qp, const ValueType &value)
00042 {
00043 #if QT_VERSION >= 0x050000
00044 return value/qp->device()->devicePixelRatio() ;
00045 #else
00046 Q_UNUSED(qp);
00047 return value;
00048 #endif
00049 }
00050
00051 inline vcg::Point2f QTLogicalToOpenGL( QWidget *qw, const QPoint &p)
00052 {
00053 return vcg::Point2f(QTLogicalToDevice(qw,p.x()), QTLogicalToDevice(qw,qw->height()-p.y()));
00054 }
00055
00056
00057 inline int QTDeviceHeight(QWidget *qw) {return QTLogicalToDevice(qw,qw->height());}
00058 inline int QTDeviceWidth(QWidget *qw) {return QTLogicalToDevice(qw,qw->width());}
00059 #endif // DEVICE_TO_LOGICAL_H