Skip to content

Commit

Permalink
QHighDpi: Remove fromNativePixels()/toNativePixels() overloads
Browse files Browse the repository at this point in the history
Replace QWindow / QScreen / QPlatformScreen overloads with template
functions that take a generic context argument.

The API now no longer supports implicit conversions from
QPointer<QWindow> to QWindow *, add explicit data()
call to usage in qxcbdrag.cpp.

Change-Id: I63d7f16f6356873280df58f4e7c924bf0b0eca5b
Reviewed-by: Friedemann Kleint <[email protected]>
  • Loading branch information
Morten Johan Sørvig committed May 22, 2019
1 parent ea9469f commit 3386b87
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 117 deletions.
151 changes: 35 additions & 116 deletions src/gui/kernel/qhighdpiscaling_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,86 +204,42 @@ inline QPointF toNativeLocalPosition(const QPointF &pos, const QWindow *window)
return pos * scaleFactor;
}

inline QRect fromNativePixels(const QRect &pixelRect, const QPlatformScreen *platformScreen)
template <typename C>
inline QRect fromNativePixels(const QRect &pixelRect, const C *context)
{
const qreal scaleFactor = QHighDpiScaling::factor(platformScreen);
const QPoint origin = QHighDpiScaling::origin(platformScreen);
const qreal scaleFactor = QHighDpiScaling::factor(context);
const QPoint origin = QHighDpiScaling::origin(context);
return QRect(fromNative(pixelRect.topLeft(), scaleFactor, origin),
fromNative(pixelRect.size(), scaleFactor));
}

inline QRect toNativePixels(const QRect &pointRect, const QPlatformScreen *platformScreen)
template <typename C>
inline QRect toNativePixels(const QRect &pointRect, const C *context)
{
const qreal scaleFactor = QHighDpiScaling::factor(platformScreen);
const QPoint origin = QHighDpiScaling::origin(platformScreen);
const qreal scaleFactor = QHighDpiScaling::factor(context);
const QPoint origin = QHighDpiScaling::origin(context);
return QRect(toNative(pointRect.topLeft(), scaleFactor, origin),
toNative(pointRect.size(), scaleFactor));
}

inline QRect fromNativePixels(const QRect &pixelRect, const QScreen *screen)
template <typename C>
inline QRectF toNativePixels(const QRectF &pointRect, const C *context)
{
const qreal scaleFactor = QHighDpiScaling::factor(screen);
const QPoint origin = QHighDpiScaling::origin(screen);
return QRect(fromNative(pixelRect.topLeft(), scaleFactor, origin),
fromNative(pixelRect.size(), scaleFactor));
}

inline QRect toNativePixels(const QRect &pointRect, const QScreen *screen)
{
const qreal scaleFactor = QHighDpiScaling::factor(screen);
const QPoint origin = QHighDpiScaling::origin(screen);
return QRect(toNative(pointRect.topLeft(), scaleFactor, origin),
toNative(pointRect.size(), scaleFactor));
}

inline QRect fromNativePixels(const QRect &pixelRect, const QWindow *window)
{
const qreal scaleFactor = QHighDpiScaling::factor(window);
const QPoint origin = QHighDpiScaling::origin(window);
return QRect(fromNative(pixelRect.topLeft(), scaleFactor, origin),
fromNative(pixelRect.size(), scaleFactor));
}

inline QRectF toNativePixels(const QRectF &pointRect, const QScreen *screen)
{
const qreal scaleFactor = QHighDpiScaling::factor(screen);
const QPoint origin = QHighDpiScaling::origin(screen);
const qreal scaleFactor = QHighDpiScaling::factor(context);
const QPoint origin = QHighDpiScaling::origin(context);
return QRectF(toNative(pointRect.topLeft(), scaleFactor, origin),
toNative(pointRect.size(), scaleFactor));
}

inline QRect toNativePixels(const QRect &pointRect, const QWindow *window)
{
const qreal scaleFactor = QHighDpiScaling::factor(window);
const QPoint origin = QHighDpiScaling::origin(window);
return QRect(toNative(pointRect.topLeft(), scaleFactor, origin),
toNative(pointRect.size(), scaleFactor));
toNative(pointRect.size(), scaleFactor));
}

inline QRectF fromNativePixels(const QRectF &pixelRect, const QScreen *screen)
template <typename C>
inline QRectF fromNativePixels(const QRectF &pixelRect, const C *context)
{
const qreal scaleFactor = QHighDpiScaling::factor(screen);
const QPoint origin = QHighDpiScaling::origin(screen);
const qreal scaleFactor = QHighDpiScaling::factor(context);
const QPoint origin = QHighDpiScaling::origin(context);
return QRectF(fromNative(pixelRect.topLeft(), scaleFactor, origin),
fromNative(pixelRect.size(), scaleFactor));
}

inline QRectF fromNativePixels(const QRectF &pixelRect, const QWindow *window)
{
const qreal scaleFactor = QHighDpiScaling::factor(window);
const QPoint origin = QHighDpiScaling::origin(window);
return QRectF(fromNative(pixelRect.topLeft(), scaleFactor, origin),
fromNative(pixelRect.size(), scaleFactor));
}

inline QRectF toNativePixels(const QRectF &pointRect, const QWindow *window)
{
const qreal scaleFactor = QHighDpiScaling::factor(window);
const QPoint origin = QHighDpiScaling::origin(window);
return QRectF(toNative(pointRect.topLeft(), scaleFactor, origin),
toNative(pointRect.size(), scaleFactor));
}

inline QSize fromNativePixels(const QSize &pixelSize, const QWindow *window)
{
return pixelSize / QHighDpiScaling::factor(window);
Expand All @@ -304,44 +260,28 @@ inline QSizeF toNativePixels(const QSizeF &pointSize, const QWindow *window)
return pointSize * QHighDpiScaling::factor(window);
}

inline QPoint fromNativePixels(const QPoint &pixelPoint, const QScreen *screen)
{
return fromNative(pixelPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen));
}

inline QPoint fromNativePixels(const QPoint &pixelPoint, const QWindow *window)
{
return fromNative(pixelPoint, QHighDpiScaling::factor(window), QHighDpiScaling::origin(window));
}

inline QPoint toNativePixels(const QPoint &pointPoint, const QScreen *screen)
template <typename C>
inline QPoint fromNativePixels(const QPoint &pixelPoint, const C *context)
{
return toNative(pointPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen));
return fromNative(pixelPoint, QHighDpiScaling::factor(context), QHighDpiScaling::origin(context));
}

inline QPoint toNativePixels(const QPoint &pointPoint, const QWindow *window)
template <typename C>
inline QPoint toNativePixels(const QPoint &pointPoint, const C *context)
{
return toNative(pointPoint, QHighDpiScaling::factor(window), QHighDpiScaling::origin(window));
return toNative(pointPoint, QHighDpiScaling::factor(context), QHighDpiScaling::origin(context));
}

inline QPointF fromNativePixels(const QPointF &pixelPoint, const QScreen *screen)
template <typename C>
inline QPointF fromNativePixels(const QPointF &pixelPoint, const C *context)
{
return fromNative(pixelPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen));
return fromNative(pixelPoint, QHighDpiScaling::factor(context), QHighDpiScaling::origin(context));
}

inline QPointF fromNativePixels(const QPointF &pixelPoint, const QWindow *window)
template <typename C>
inline QPointF toNativePixels(const QPointF &pointPoint, const C *context)
{
return fromNative(pixelPoint, QHighDpiScaling::factor(window), QHighDpiScaling::origin(window));
}

inline QPointF toNativePixels(const QPointF &pointPoint, const QScreen *screen)
{
return toNative(pointPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen));
}

inline QPointF toNativePixels(const QPointF &pointPoint, const QWindow *window)
{
return toNative(pointPoint, QHighDpiScaling::factor(window), QHighDpiScaling::origin(window));
return toNative(pointPoint, QHighDpiScaling::factor(context), QHighDpiScaling::origin(context));
}

inline QMargins fromNativePixels(const QMargins &pixelMargins, const QWindow *window)
Expand Down Expand Up @@ -406,47 +346,26 @@ inline QRegion toNativeLocalRegion(const QRegion &pointRegion, const QWindow *wi
}

// Any T that has operator/()
template <typename T>
T fromNativePixels(const T &pixelValue, const QWindow *window)
{
if (!QHighDpiScaling::isActive())
return pixelValue;

return pixelValue / QHighDpiScaling::factor(window);

}

//##### ?????
template <typename T>
T fromNativePixels(const T &pixelValue, const QScreen *screen)
template <typename T, typename C>
T fromNativePixels(const T &pixelValue, const C *context)
{
if (!QHighDpiScaling::isActive())
return pixelValue;

return pixelValue / QHighDpiScaling::factor(screen);
return pixelValue / QHighDpiScaling::factor(context);

}

// Any T that has operator*()
template <typename T>
T toNativePixels(const T &pointValue, const QWindow *window)
template <typename T, typename C>
T toNativePixels(const T &pointValue, const C *context)
{
if (!QHighDpiScaling::isActive())
return pointValue;

return pointValue * QHighDpiScaling::factor(window);
return pointValue * QHighDpiScaling::factor(context);
}

template <typename T>
T toNativePixels(const T &pointValue, const QScreen *screen)
{
if (!QHighDpiScaling::isActive())
return pointValue;

return pointValue * QHighDpiScaling::factor(screen);
}


// Any QVector<T> where T has operator/()
template <typename T>
QVector<T> fromNativePixels(const QVector<T> &pixelValues, const QWindow *window)
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/platforms/xcb/qxcbdrag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void QXcbDrag::startDrag()
if (connection()->mouseGrabber() == nullptr)
shapedPixmapWindow()->setMouseGrabEnabled(true);

auto nativePixelPos = QHighDpi::toNativePixels(QCursor::pos(), initiatorWindow);
auto nativePixelPos = QHighDpi::toNativePixels(QCursor::pos(), initiatorWindow.data());
move(nativePixelPos, QGuiApplication::mouseButtons(), QGuiApplication::keyboardModifiers());
}

Expand Down

0 comments on commit 3386b87

Please sign in to comment.