QHighDpi: Remove fromNativePixels()/toNativePixels() overloads

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 <Friedemann.Kleint@qt.io>
This commit is contained in:
Morten Johan Sørvig 2019-03-04 22:33:58 +01:00
parent ea9469f2b6
commit 3386b875dd
2 changed files with 36 additions and 117 deletions

View File

@ -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));
toNative(pointRect.size(), scaleFactor));
}
inline QRect toNativePixels(const QRect &pointRect, const QWindow *window)
template <typename C>
inline QRectF fromNativePixels(const QRectF &pixelRect, const C *context)
{
const qreal scaleFactor = QHighDpiScaling::factor(window);
const QPoint origin = QHighDpiScaling::origin(window);
return QRect(toNative(pointRect.topLeft(), scaleFactor, origin),
toNative(pointRect.size(), scaleFactor));
}
inline QRectF fromNativePixels(const QRectF &pixelRect, 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(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);
@ -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)
template <typename C>
inline QPoint fromNativePixels(const QPoint &pixelPoint, const C *context)
{
return fromNative(pixelPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen));
return fromNative(pixelPoint, QHighDpiScaling::factor(context), QHighDpiScaling::origin(context));
}
inline QPoint fromNativePixels(const QPoint &pixelPoint, const QWindow *window)
template <typename C>
inline QPoint toNativePixels(const QPoint &pointPoint, const C *context)
{
return fromNative(pixelPoint, QHighDpiScaling::factor(window), QHighDpiScaling::origin(window));
return toNative(pointPoint, QHighDpiScaling::factor(context), QHighDpiScaling::origin(context));
}
inline QPoint toNativePixels(const QPoint &pointPoint, const QScreen *screen)
template <typename C>
inline QPointF fromNativePixels(const QPointF &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 QPointF toNativePixels(const QPointF &pointPoint, const C *context)
{
return toNative(pointPoint, QHighDpiScaling::factor(window), QHighDpiScaling::origin(window));
}
inline QPointF fromNativePixels(const QPointF &pixelPoint, const QScreen *screen)
{
return fromNative(pixelPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen));
}
inline QPointF fromNativePixels(const QPointF &pixelPoint, const QWindow *window)
{
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)
@ -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)
template <typename T, typename C>
T fromNativePixels(const T &pixelValue, const C *context)
{
if (!QHighDpiScaling::isActive())
return pixelValue;
return pixelValue / QHighDpiScaling::factor(window);
}
//##### ?????
template <typename T>
T fromNativePixels(const T &pixelValue, const QScreen *screen)
{
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)

View File

@ -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());
}