Commit f5bdd92e authored by Morten Johan Sørvig's avatar Morten Johan Sørvig
Browse files

Move min/max size constrain logic to QPlatformWindow.


This increases the uniformity of the to/fromNativePixels
functions by removing a special case, and avoids pulling
the qwindow_p.h details into qhihgdpiscaling.cpp.

Keep the logic of constraining the device-independent
size.

Change-Id: Id0dae30a7c0170ff2e5d21b94d56719cc900c726
Reviewed-by: default avatarMorten Johan Sørvig <morten.sorvig@theqtcompany.com>
No related merge requests found
Showing with 11 additions and 17 deletions
......@@ -40,7 +40,6 @@
****************************************************************************/
#include "qhighdpiscaling_p.h"
#include "qwindow_p.h" // for QWINDOWSIZE_MAX
#include "qguiapplication.h"
#include "qscreen.h"
#include "qplatformintegration.h"
......@@ -228,15 +227,4 @@ QPoint QHighDpiScaling::origin(const QPlatformScreen *platformScreen)
return platformScreen->geometry().topLeft();
}
Q_GUI_EXPORT QSize QHighDpi::toNativePixelsConstrained(const QSize &size, const QWindow *window)
{
const int width = size.width();
const int height = size.height();
return QSize(width > 0 && width < QWINDOWSIZE_MAX ?
QHighDpi::toNativePixels(width, window) : width,
height > 0 && height < QWINDOWSIZE_MAX ?
QHighDpi::toNativePixels(height, window) : height);
}
QT_END_NAMESPACE
......@@ -284,9 +284,6 @@ inline QSize fromNativePixels(const QSize &pixelSize, const QWindow *window)
return pixelSize / QHighDpiScaling::factor(window);
}
// For converting minimum/maximum sizes of QWindow, limits to 0..QWINDOWSIZE_MAX
Q_GUI_EXPORT QSize toNativePixelsConstrained(const QSize &size, const QWindow *window);
inline QSize toNativePixels(const QSize &pointSize, const QWindow *window)
{
return pointSize * QHighDpiScaling::factor(window);
......
......@@ -496,6 +496,14 @@ QPlatformScreen *QPlatformWindow::screenForGeometry(const QRect &newGeometry) co
return fallback;
}
/*!
Returns a size with both dimentions bounded to [0, QWINDOWSIZE_MAX]
*/
QSize QPlatformWindow::constrainWindowSize(const QSize &size)
{
return size.boundedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
}
/*!
Reimplement this method to set whether the window demands attention
(for example, by flashing the taskbar icon) depending on \a enabled.
......@@ -637,7 +645,7 @@ void QPlatformWindow::requestUpdate()
*/
QSize QPlatformWindow::windowMinimumSize() const
{
return QHighDpi::toNativePixelsConstrained(window()->minimumSize(), window());
return QHighDpi::toNativePixels(constrainWindowSize(window()->minimumSize()), window());
}
/*!
......@@ -645,7 +653,7 @@ QSize QPlatformWindow::windowMinimumSize() const
*/
QSize QPlatformWindow::windowMaximumSize() const
{
return QHighDpi::toNativePixelsConstrained(window()->maximumSize(), window());
return QHighDpi::toNativePixels(constrainWindowSize(window()->maximumSize()), window());
}
/*!
......
......@@ -141,6 +141,7 @@ public:
protected:
static QString formatWindowTitle(const QString &title, const QString &separator);
QPlatformScreen *screenForGeometry(const QRect &newGeometry) const;
static QSize constrainWindowSize(const QSize &size);
QScopedPointer<QPlatformWindowPrivate> d_ptr;
private:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment