summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-07-01 14:07:27 +0200
committerPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-07-01 12:30:10 +0000
commit5bfb6ce4bf5b090dc88463a2e7a4aae3ef10fe09 (patch)
treeea9f7c0e6bbc546684684c216a34d808ab8a9f86 /src/gui
parentb93264a6f1b41db2c8f865e452b687390c6897a8 (diff)
Add QPointF/QRectF scale functionswip/highdpi
Change-Id: I91c5afc061e91c6088398d039c1c1fd3d79254ca Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qhighdpiscaling_p.h38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h
index d2d8262b1d..6fe44ecac4 100644
--- a/src/gui/kernel/qhighdpiscaling_p.h
+++ b/src/gui/kernel/qhighdpiscaling_p.h
@@ -93,6 +93,16 @@ private:
namespace QHighDpi {
+inline QPointF fromNative(const QPointF &pos, qreal scaleFactor, const QPointF &origin)
+{
+ return (pos - origin) / scaleFactor + origin;
+}
+
+inline QPointF toNative(const QPointF &pos, qreal scaleFactor, const QPointF &origin)
+{
+ return (pos - origin) * scaleFactor + origin;
+}
+
inline QPoint fromNative(const QPoint &pos, qreal scaleFactor, const QPoint &origin)
{
return (pos - origin) / scaleFactor + origin;
@@ -115,7 +125,7 @@ inline QPoint toNative(const QPoint &pos, qreal scaleFactor)
inline QSize fromNative(const QSize &size, qreal scaleFactor)
{
- return size / scaleFactor; // TODO: ### round up ###
+ return size / scaleFactor; // TODO: should we round up?
}
inline QSize toNative(const QSize &size, qreal scaleFactor)
@@ -123,6 +133,16 @@ inline QSize toNative(const QSize &size, qreal scaleFactor)
return size * scaleFactor;
}
+inline QSizeF fromNative(const QSizeF &size, qreal scaleFactor)
+{
+ return size / scaleFactor;
+}
+
+inline QSizeF toNative(const QSizeF &size, qreal scaleFactor)
+{
+ return size * scaleFactor;
+}
+
inline QRect fromNative(const QRect &rect, qreal scaleFactor, const QPoint &origin)
{
return QRect(fromNative(rect.topLeft(), scaleFactor, origin), fromNative(rect.size(), scaleFactor));
@@ -212,8 +232,10 @@ inline QRect fromNativePixels(const QRect &pixelRect, const QWindow *window)
inline QRectF toNativePixels(const QRectF &pointRect, const QScreen *screen)
{
- //########
- return toNativePixels(pointRect.toRect(), screen);
+ const qreal scaleFactor = QHighDpiScaling::factor(screen);
+ const QPoint origin = QHighDpiScaling::origin(screen);
+ return QRectF(toNative(pointRect.topLeft(), scaleFactor, origin),
+ toNative(pointRect.size(), scaleFactor));
}
inline QRect toNativePixels(const QRect &pointRect, const QWindow *window)
@@ -228,8 +250,10 @@ inline QRect toNativePixels(const QRect &pointRect, const QWindow *window)
inline QRectF fromNativePixels(const QRectF &pixelRect, const QScreen *screen)
{
- //########
- return fromNativePixels(pixelRect.toRect(), screen);
+ const qreal scaleFactor = QHighDpiScaling::factor(screen);
+ const QPoint origin = QHighDpiScaling::origin(screen);
+ return QRectF(fromNative(pixelRect.topLeft(), scaleFactor, origin),
+ fromNative(pixelRect.size(), scaleFactor));
}
inline QRectF fromNativePixels(const QRectF &pixelRect, const QWindow *window)
@@ -300,7 +324,7 @@ inline QPoint toNativePixels(const QPoint &pointPoint, const QWindow *window)
inline QPointF fromNativePixels(const QPointF &pixelPoint, const QScreen *screen)
{
- return fromNativePixels(pixelPoint.toPoint(), screen); //###############
+ return fromNative(pixelPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen));
}
inline QPointF fromNativePixels(const QPointF &pixelPoint, const QWindow *window)
@@ -313,7 +337,7 @@ inline QPointF fromNativePixels(const QPointF &pixelPoint, const QWindow *window
inline QPointF toNativePixels(const QPointF &pointPoint, const QScreen *screen)
{
- return toNativePixels(pointPoint.toPoint(), screen); //###########
+ return toNative(pointPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen));
}
inline QPointF toNativePixels(const QPointF &pointPoint, const QWindow *window)