2013-12-16 12:34:17 +01:00
|
|
|
#ifndef DEVICE_TO_LOGICAL_H
|
|
|
|
#define DEVICE_TO_LOGICAL_H
|
2013-12-16 13:14:53 +01:00
|
|
|
#include <QWidget>
|
2013-12-16 12:34:17 +01:00
|
|
|
#include <QPainter>
|
2014-02-07 12:08:28 +01:00
|
|
|
#include <vcg/space/point2.h>
|
|
|
|
|
2013-12-16 12:34:17 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2014-04-28 15:30:27 +02:00
|
|
|
template < class ValueType>
|
|
|
|
inline ValueType QTDeviceToLogical( QWidget *qw, const ValueType &value)
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
return value/qw->devicePixelRatio() ;
|
|
|
|
#else
|
|
|
|
Q_UNUSED(qw);
|
|
|
|
return value;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-12-16 12:34:17 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-12-16 17:21:05 +01:00
|
|
|
inline vcg::Point2f QTLogicalToOpenGL( QWidget *qw, const QPoint &p)
|
|
|
|
{
|
|
|
|
return vcg::Point2f(QTLogicalToDevice(qw,p.x()), QTLogicalToDevice(qw,qw->height()-p.y()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline int QTDeviceHeight(QWidget *qw) {return QTLogicalToDevice(qw,qw->height());}
|
|
|
|
inline int QTDeviceWidth(QWidget *qw) {return QTLogicalToDevice(qw,qw->width());}
|
2013-12-16 12:34:17 +01:00
|
|
|
#endif // DEVICE_TO_LOGICAL_H
|