vcglib/wrap/qt/device_to_logical.h

60 lines
1.4 KiB
C
Raw Normal View History

#ifndef DEVICE_TO_LOGICAL_H
#define DEVICE_TO_LOGICAL_H
2013-12-16 13:14:53 +01:00
#include <QWidget>
#include <QPainter>
2014-02-07 12:08:28 +01:00
#include <vcg/space/point2.h>
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
}
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
}
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());}
#endif // DEVICE_TO_LOGICAL_H