summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/accessible/qaccessible.cpp2
-rw-r--r--src/gui/doc/snippets/code/doc_src_coordsys.cpp2
-rw-r--r--src/gui/doc/snippets/code/doc_src_qtgui.pro4
-rw-r--r--src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp4
-rw-r--r--src/gui/doc/snippets/overview/using-qt-gui.cmake2
-rw-r--r--src/gui/doc/src/coordsys.qdoc9
-rw-r--r--src/gui/doc/src/dontdocument.qdoc66
-rw-r--r--src/gui/doc/src/qtgui.qdoc23
-rw-r--r--src/gui/image/qicon.cpp2
-rw-r--r--src/gui/image/qpicture.cpp4
-rw-r--r--src/gui/itemmodels/qstandarditemmodel.cpp2
-rw-r--r--src/gui/kernel/qevent.cpp14
-rw-r--r--src/gui/kernel/qhighdpiscaling.cpp50
-rw-r--r--src/gui/kernel/qhighdpiscaling_p.h176
-rw-r--r--src/gui/kernel/qopenglcontext.cpp4
-rw-r--r--src/gui/kernel/qpalette.cpp5
-rw-r--r--src/gui/kernel/qplatformtheme.cpp4
-rw-r--r--src/gui/kernel/qplatformwindow.cpp12
-rw-r--r--src/gui/kernel/qwindow.cpp20
-rw-r--r--src/gui/kernel/qwindow_p.h2
-rw-r--r--src/gui/opengl/qopengltextureuploader.cpp50
-rw-r--r--src/gui/painting/qbezier.cpp6
-rw-r--r--src/gui/painting/qdrawhelper_sse4.cpp18
-rw-r--r--src/gui/painting/qpaintengine_raster_p.h2
-rw-r--r--src/gui/painting/qpainterpath.cpp57
-rw-r--r--src/gui/text/qfontdatabase.cpp52
-rw-r--r--src/gui/text/qtextdocument.cpp2
-rw-r--r--src/gui/text/qtextengine.cpp3
-rw-r--r--src/gui/text/qtextobject.cpp4
-rw-r--r--src/gui/text/qtextodfwriter.cpp88
-rw-r--r--src/gui/vulkan/qvulkaninstance.cpp2
31 files changed, 415 insertions, 276 deletions
diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp
index 46dec7f28d..6b825fa001 100644
--- a/src/gui/accessible/qaccessible.cpp
+++ b/src/gui/accessible/qaccessible.cpp
@@ -526,7 +526,7 @@ static void qAccessibleCleanup()
to it.
If the key and the QObject does not have a corresponding
- QAccessibleInterface, a null-pointer will be returned.
+ QAccessibleInterface, \nullptr will be returned.
Installed factories are called by queryAccessibilityInterface() until
one provides an interface.
diff --git a/src/gui/doc/snippets/code/doc_src_coordsys.cpp b/src/gui/doc/snippets/code/doc_src_coordsys.cpp
index 7c53d9e731..147c146b44 100644
--- a/src/gui/doc/snippets/code/doc_src_coordsys.cpp
+++ b/src/gui/doc/snippets/code/doc_src_coordsys.cpp
@@ -52,6 +52,7 @@
QPainter painter(this);
painter.setPen(Qt::darkGreen);
+// Using the (x y w h) overload
painter.drawRect(1, 2, 6, 4);
//! [0]
@@ -69,6 +70,7 @@ QPainter painter(this);
painter.setRenderHint(
QPainter::Antialiasing);
painter.setPen(Qt::darkGreen);
+// Using the (x y w h) overload
painter.drawRect(1, 2, 6, 4);
//! [2]
diff --git a/src/gui/doc/snippets/code/doc_src_qtgui.pro b/src/gui/doc/snippets/code/doc_src_qtgui.pro
index e705555336..a5eb5b576c 100644
--- a/src/gui/doc/snippets/code/doc_src_qtgui.pro
+++ b/src/gui/doc/snippets/code/doc_src_qtgui.pro
@@ -1,7 +1,3 @@
-#! [0]
-#include <QtGui>
-#! [0]
-
#! [1]
QT -= gui
#! [1]
diff --git a/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp b/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp
index 4266da0a11..a7e22e549d 100644
--- a/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp
+++ b/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp
@@ -50,8 +50,8 @@
//! [0]
QStandardItemModel model(4, 4);
-for (int row = 0; row < 4; ++row) {
- for (int column = 0; column < 4; ++column) {
+for (int row = 0; row < model.rowCount(); ++row) {
+ for (int column = 0; column < model.columnCount(); ++column) {
QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
model.setItem(row, column, item);
}
diff --git a/src/gui/doc/snippets/overview/using-qt-gui.cmake b/src/gui/doc/snippets/overview/using-qt-gui.cmake
new file mode 100644
index 0000000000..aecfa458a0
--- /dev/null
+++ b/src/gui/doc/snippets/overview/using-qt-gui.cmake
@@ -0,0 +1,2 @@
+find_package(Qt5 COMPONENTS Gui REQUIRED)
+target_link_libraries(mytarget Qt5::Gui)
diff --git a/src/gui/doc/src/coordsys.qdoc b/src/gui/doc/src/coordsys.qdoc
index 1856428361..1018b2122b 100644
--- a/src/gui/doc/src/coordsys.qdoc
+++ b/src/gui/doc/src/coordsys.qdoc
@@ -70,8 +70,15 @@
\li \inlineimage coordinatesystem-rect.png
\li \inlineimage coordinatesystem-line.png
\row
- \li QRect(1, 2, 6, 4)
+ \li QRect(QPoint(1, 2), QPoint(7, 6))
+ \li QLine(QPoint(2, 7), QPoint(6, 1))
+ \row
+ \li
\li QLine(2, 7, 6, 1)
+ \row
+ \li QRect(QPoint(1, 2), QSize(6, 4))
+ \row
+ \li QRect(1, 2, 6, 4)
\endtable
\section2 Aliased Painting
diff --git a/src/gui/doc/src/dontdocument.qdoc b/src/gui/doc/src/dontdocument.qdoc
new file mode 100644
index 0000000000..b360acefc1
--- /dev/null
+++ b/src/gui/doc/src/dontdocument.qdoc
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \dontdocument (QTypeInfo QScreenOrientationChangeEvent QApplicationStateChangeEvent
+ QImageTextKeyLang QMetaTypeId QAbstractUndoItem
+ QOpenGLVersionStatus
+ QOpenGLVersionFunctionsBackend
+ QOpenGLVersionFunctionsStorage
+ QOpenGLFunctions_1_0_CoreBackend
+ QOpenGLFunctions_1_1_CoreBackend
+ QOpenGLFunctions_1_2_CoreBackend
+ QOpenGLFunctions_1_3_CoreBackend
+ QOpenGLFunctions_1_4_CoreBackend
+ QOpenGLFunctions_1_5_CoreBackend
+ QOpenGLFunctions_2_0_CoreBackend
+ QOpenGLFunctions_2_1_CoreBackend
+ QOpenGLFunctions_3_0_CoreBackend
+ QOpenGLFunctions_3_1_CoreBackend
+ QOpenGLFunctions_3_2_CoreBackend
+ QOpenGLFunctions_3_3_CoreBackend
+ QOpenGLFunctions_4_0_CoreBackend
+ QOpenGLFunctions_4_1_CoreBackend
+ QOpenGLFunctions_4_2_CoreBackend
+ QOpenGLFunctions_4_3_CoreBackend
+ QOpenGLFunctions_4_4_CoreBackend
+ QOpenGLFunctions_4_5_CoreBackend
+ QOpenGLFunctions_1_0_DeprecatedBackend
+ QOpenGLFunctions_1_1_DeprecatedBackend
+ QOpenGLFunctions_1_2_DeprecatedBackend
+ QOpenGLFunctions_1_3_DeprecatedBackend
+ QOpenGLFunctions_1_4_DeprecatedBackend
+ QOpenGLFunctions_2_0_DeprecatedBackend
+ QOpenGLFunctions_3_0_DeprecatedBackend
+ QOpenGLFunctions_3_3_DeprecatedBackend
+ QOpenGLFunctions_4_5_DeprecatedBackend
+ QTextFrameLayoutData QPlatformDropQtResponse QPlatformDragQtResponse
+ QPlatformOffscreenSurface QColorDialogOptions QFontDialogOptions
+ QFileDialogOptions QMessageDialogOptions QMessageDialogOptions::CustomButton
+ QPlatformSessionManager QPlatformIntegrationPlugin QPlatformMenuItem
+ QPlatformMenu QPlatformMenuBar QPlatformTextureList)
+*/
diff --git a/src/gui/doc/src/qtgui.qdoc b/src/gui/doc/src/qtgui.qdoc
index 53fd55bd39..c4e7d32de1 100644
--- a/src/gui/doc/src/qtgui.qdoc
+++ b/src/gui/doc/src/qtgui.qdoc
@@ -40,18 +40,6 @@
These classes are used internally by Qt's user interface technologies
and can also be used directly, for instance to write applications using
low-level OpenGL ES graphics APIs.
-
- To include the definitions of the module's classes, use the
- following directive:
-
- \snippet code/doc_src_qtgui.pro 0
-
- \if !defined(qtforpython)
- If you use \l qmake to build your projects, \l{Qt GUI} is included by
- default. To disable Qt GUI, add the following line to your \c .pro file:
-
- \snippet code/doc_src_qtgui.pro 1
- \endif
*/
/*!
@@ -69,14 +57,15 @@
higher level API's, like Qt Quick, that are much more suitable
than the enablers found in the Qt GUI module.
- \section1 Getting Started
+ \if !defined(qtforpython)
- To include the definitions of the module's classes, use the
- following directive:
+ \include module-use.qdocinc using qt module
+ \quotefile overview/using-qt-gui.cmake
- \snippet code/doc_src_qtgui.pro 0
+ See also the \l[QtDoc]{Building with CMake} overview.
+
+ \section2 Building with qmake
- \if !defined(qtforpython)
If you use \l qmake to build your projects, Qt GUI is included by
default. To disable Qt GUI, add the following line to your \c .pro file:
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index c3c4b24678..80fa65daac 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -1523,7 +1523,7 @@ QDebug operator<<(QDebug dbg, const QIcon &i)
foo@3x.png, then foo@2x, then fall back to foo.png if not found.
\a sourceDevicePixelRatio will be set to the value of N if the argument is
- a non-null pointer
+ not \nullptr
*/
QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
qreal *sourceDevicePixelRatio)
diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp
index 56b82abcfa..bba36b09cd 100644
--- a/src/gui/image/qpicture.cpp
+++ b/src/gui/image/qpicture.cpp
@@ -1485,8 +1485,8 @@ static QPictureHandler *get_picture_handler(const char *format)
\a format is used to select a handler to write a QPicture; \a header
is used to select a handler to read an picture file.
- If \a readPicture is a null pointer, the QPictureIO will not be able
- to read pictures in \a format. If \a writePicture is a null pointer,
+ If \a readPicture is \nullptr, the QPictureIO will not be able
+ to read pictures in \a format. If \a writePicture is \nullptr,
the QPictureIO will not be able to write pictures in \a format. If
both are null, the QPictureIO object is valid but useless.
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp
index 3e3c7a6211..2390c62b9f 100644
--- a/src/gui/itemmodels/qstandarditemmodel.cpp
+++ b/src/gui/itemmodels/qstandarditemmodel.cpp
@@ -1846,7 +1846,7 @@ bool QStandardItem::hasChildren() const
item) takes ownership of \a item. If necessary, the row count and column
count are increased to fit the item.
- \note Passing a null pointer as \a item removes the item.
+ \note Passing \nullptr as \a item removes the item.
\sa child()
*/
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 7123c4d8ba..e7a320f3a4 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -97,35 +97,35 @@ QEnterEvent::~QEnterEvent()
/*!
\fn QPoint QEnterEvent::globalPos() const
- Returns the global position of the widget \e{at the time of the event}.
+ Returns the global position of the mouse cursor \e{at the time of the event}.
*/
/*!
\fn int QEnterEvent::globalX() const
- Returns the global position on the X-axis of the mouse cursor relative to the the widget.
+ Returns the global position on the X-axis of the mouse cursor \e{at the time of the event}.
*/
/*!
\fn int QEnterEvent::globalY() const
- Returns the global position on the Y-axis of the mouse cursor relative to the the widget.
+ Returns the global position on the Y-axis of the mouse cursor \e{at the time of the event}.
*/
/*!
- \fn QPoint QEnterEvent::localPos() const
+ \fn QPointF QEnterEvent::localPos() const
Returns the mouse cursor's position relative to the receiving widget.
*/
/*!
\fn QPoint QEnterEvent::pos() const
- Returns the position of the mouse cursor in global screen coordinates.
+ Returns the position of the mouse cursor relative to the receiving widget.
*/
/*!
- \fn QPoint QEnterEvent::screenPos() const
+ \fn QPointF QEnterEvent::screenPos() const
Returns the position of the mouse cursor relative to the receiving screen.
*/
/*!
- \fn QPoint QEnterEvent::windowPos() const
+ \fn QPointF QEnterEvent::windowPos() const
Returns the position of the mouse cursor relative to the receiving window.
*/
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp
index 22e46e0851..4f8e9a3817 100644
--- a/src/gui/kernel/qhighdpiscaling.cpp
+++ b/src/gui/kernel/qhighdpiscaling.cpp
@@ -41,7 +41,9 @@
#include "qguiapplication.h"
#include "qscreen.h"
#include "qplatformintegration.h"
+#include "qplatformwindow.h"
#include "private/qscreen_p.h"
+#include <private/qguiapplication_p.h>
#include <QtCore/qdebug.h>
@@ -376,6 +378,46 @@ QPoint QHighDpiScaling::mapPositionFromNative(const QPoint &pos, const QPlatform
return (pos - topLeft) / scaleFactor + topLeft;
}
+QPoint QHighDpiScaling::mapPositionToGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window)
+{
+ QPoint globalPosCandidate = pos + windowGlobalPosition;
+ if (QGuiApplicationPrivate::screen_list.size() <= 1)
+ return globalPosCandidate;
+
+ // The global position may be outside device independent screen geometry
+ // in cases where a window spans screens. Detect this case and map via
+ // native coordinates to the correct screen.
+ auto currentScreen = window->screen();
+ if (currentScreen && !currentScreen->geometry().contains(globalPosCandidate)) {
+ auto nativeGlobalPos = QHighDpi::toNativePixels(globalPosCandidate, currentScreen);
+ if (auto actualPlatformScreen = currentScreen->handle()->screenForPosition(nativeGlobalPos))
+ return QHighDpi::fromNativePixels(nativeGlobalPos, actualPlatformScreen->screen());
+ }
+
+ return globalPosCandidate;
+}
+
+QPoint QHighDpiScaling::mapPositionFromGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window)
+{
+ QPoint windowPosCandidate = pos - windowGlobalPosition;
+ if (QGuiApplicationPrivate::screen_list.size() <= 1)
+ return windowPosCandidate;
+
+ // Device independent global (screen) space may discontiguous when high-dpi scaling
+ // is active. This means that the normal subtracting of the window global position from the
+ // position-to-be-mapped may not work in cases where a window spans multiple screens.
+ // Map both positions to native global space (using the correct screens), subtract there,
+ // and then map the difference back using the scale factor for the window.
+ QScreen *posScreen = QGuiApplication::screenAt(pos);
+ if (posScreen && posScreen != window->screen()) {
+ QPoint nativePos = QHighDpi::toNativePixels(pos, posScreen);
+ QPoint windowNativePos = window->handle()->geometry().topLeft();
+ return QHighDpi::fromNativeLocalPosition(nativePos - windowNativePos, window);
+ }
+
+ return windowPosCandidate;
+}
+
qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen)
{
qreal factor = qreal(1.0);
@@ -450,5 +492,13 @@ QPoint QHighDpiScaling::origin(const QPlatformScreen *platformScreen)
return platformScreen->geometry().topLeft();
}
+QPoint QHighDpiScaling::origin(const QWindow *window)
+{
+ if (window && window->isTopLevel() && window->screen())
+ return window->screen()->geometry().topLeft();
+
+ return QPoint(0, 0);
+}
+
#endif //QT_NO_HIGHDPISCALING
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h
index 83fc9452c5..dfc6abf5ba 100644
--- a/src/gui/kernel/qhighdpiscaling_p.h
+++ b/src/gui/kernel/qhighdpiscaling_p.h
@@ -83,8 +83,11 @@ public:
static qreal factor(const QPlatformScreen *platformScreen);
static QPoint origin(const QScreen *screen);
static QPoint origin(const QPlatformScreen *platformScreen);
- static QPoint mapPositionFromNative(const QPoint &pos, const QPlatformScreen *platformScreen);
+ static QPoint origin(const QWindow *window);
static QPoint mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen);
+ static QPoint mapPositionFromNative(const QPoint &pos, const QPlatformScreen *platformScreen);
+ static QPoint mapPositionToGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window);
+ static QPoint mapPositionFromGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window);
static QDpi logicalDpi();
private:
@@ -201,94 +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)
-{
- 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)
-{
- if (window && window->isTopLevel() && window->screen()) {
- return fromNativePixels(pixelRect, window->screen());
- } else {
- const qreal scaleFactor = QHighDpiScaling::factor(window);
- return QRect(pixelRect.topLeft() / scaleFactor, fromNative(pixelRect.size(), scaleFactor));
- }
-}
-
-inline QRectF toNativePixels(const QRectF &pointRect, 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);
+ 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)
-{
- if (window && window->isTopLevel() && window->screen()) {
- return toNativePixels(pointRect, window->screen());
- } else {
- const qreal scaleFactor = QHighDpiScaling::factor(window);
- return QRect(pointRect.topLeft() * scaleFactor, 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)
-{
- if (window && window->isTopLevel() && window->screen()) {
- return fromNativePixels(pixelRect, window->screen());
- } else {
- const qreal scaleFactor = QHighDpiScaling::factor(window);
- return QRectF(pixelRect.topLeft() / scaleFactor, pixelRect.size() / scaleFactor);
- }
-}
-
-inline QRectF toNativePixels(const QRectF &pointRect, const QWindow *window)
-{
- if (window && window->isTopLevel() && window->screen()) {
- return toNativePixels(pointRect, window->screen());
- } else {
- const qreal scaleFactor = QHighDpiScaling::factor(window);
- return QRectF(pointRect.topLeft() * scaleFactor, pointRect.size() * scaleFactor);
- }
-}
-
inline QSize fromNativePixels(const QSize &pixelSize, const QWindow *window)
{
return pixelSize / QHighDpiScaling::factor(window);
@@ -309,56 +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)
{
- if (window && window->isTopLevel() && window->screen())
- return fromNativePixels(pixelPoint, window->screen());
- else
- return pixelPoint / QHighDpiScaling::factor(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)
{
- if (window && window->isTopLevel() && window->screen())
- return toNativePixels(pointPoint, window->screen());
- else
- return pointPoint * QHighDpiScaling::factor(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)
-{
- if (window && window->isTopLevel() && window->screen())
- return fromNativePixels(pixelPoint, window->screen());
- else
- return pixelPoint / QHighDpiScaling::factor(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)
-{
- if (window && window->isTopLevel() && window->screen())
- return toNativePixels(pointPoint, window->screen());
- else
- return pointPoint * QHighDpiScaling::factor(window);
+ return toNative(pointPoint, QHighDpiScaling::factor(context), QHighDpiScaling::origin(context));
}
inline QMargins fromNativePixels(const QMargins &pixelMargins, const QWindow *window)
@@ -423,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)
-{
- if (!QHighDpiScaling::isActive())
- return pointValue;
-
- return pointValue * QHighDpiScaling::factor(window);
-}
-
-template <typename T>
-T toNativePixels(const T &pointValue, const QScreen *screen)
+template <typename T, typename C>
+T toNativePixels(const T &pointValue, const C *context)
{
if (!QHighDpiScaling::isActive())
return pointValue;
- return pointValue * QHighDpiScaling::factor(screen);
+ return pointValue * QHighDpiScaling::factor(context);
}
-
// Any QVector<T> where T has operator/()
template <typename T>
QVector<T> fromNativePixels(const QVector<T> &pixelValues, const QWindow *window)
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index bf3403f2e4..5bc6e27eb2 100644
--- a/src/gui/kernel/qopenglcontext.cpp
+++ b/src/gui/kernel/qopenglcontext.cpp
@@ -787,7 +787,7 @@ QOpenGLExtraFunctions *QOpenGLContext::extraFunctions() const
to the non-template function.
Note that requests for function objects of other versions or profiles can fail and
- in doing so will return a null pointer. Situations in which creation of the functions
+ in doing so will return \nullptr. Situations in which creation of the functions
object can fail are if the request cannot be satisfied due to asking for functions
that are not in the version or profile of this context. For example:
@@ -1330,7 +1330,7 @@ bool QOpenGLContext::supportsThreadedOpenGL()
\since 5.5
Returns the application-wide shared OpenGL context, if present.
- Otherwise, returns a null pointer.
+ Otherwise, returns \nullptr.
This is useful if you need to upload OpenGL objects (buffers, textures,
etc.) before creating or showing a QOpenGLWidget or QQuickWidget.
diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp
index b4383c5bfc..193fd9590d 100644
--- a/src/gui/kernel/qpalette.cpp
+++ b/src/gui/kernel/qpalette.cpp
@@ -1008,6 +1008,8 @@ QDataStream &operator<<(QDataStream &s, const QPalette &p)
max = QPalette::HighlightedText + 1;
else if (s.version() <= QDataStream::Qt_4_3)
max = QPalette::AlternateBase + 1;
+ else if (s.version() <= QDataStream::Qt_5_11)
+ max = QPalette::ToolTipText + 1;
for (int r = 0; r < max; r++)
s << p.d->br[grp][r];
}
@@ -1048,6 +1050,9 @@ QDataStream &operator>>(QDataStream &s, QPalette &p)
} else if (s.version() <= QDataStream::Qt_4_3) {
p = QPalette();
max = QPalette::AlternateBase + 1;
+ } else if (s.version() <= QDataStream::Qt_5_11) {
+ p = QPalette();
+ max = QPalette::ToolTipText + 1;
}
QBrush tmp;
diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp
index 277d976dde..f906f808d8 100644
--- a/src/gui/kernel/qplatformtheme.cpp
+++ b/src/gui/kernel/qplatformtheme.cpp
@@ -471,6 +471,8 @@ QVariant QPlatformTheme::themeHint(ThemeHint hint) const
return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ItemViewActivateItemOnSingleClick);
case QPlatformTheme::UiEffects:
return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::UiEffects);
+ case QPlatformTheme::ShowShortcutsInContextMenus:
+ return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ShowShortcutsInContextMenus);
default:
return QPlatformTheme::defaultThemeHint(hint);
}
@@ -521,7 +523,7 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint)
case QPlatformTheme::StyleNames:
return QVariant(QStringList());
case QPlatformTheme::ShowShortcutsInContextMenus:
- return QVariant(false);
+ return QVariant(true);
case TextCursorWidth:
return QVariant(1);
case DropShadow:
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp
index 562289a8c9..4e95751397 100644
--- a/src/gui/kernel/qplatformwindow.cpp
+++ b/src/gui/kernel/qplatformwindow.cpp
@@ -705,14 +705,20 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w,
w, defaultWidth, defaultHeight);
return QRect(initialGeometry.topLeft(), QHighDpi::toNative(size, factor));
}
- const QScreen *screen = effectiveScreen(w);
+ const auto *wp = qt_window_private(const_cast<QWindow*>(w));
+ const bool position = wp->positionAutomatic && w->type() != Qt::Popup;
+ if (!position && !wp->resizeAutomatic)
+ return initialGeometry;
+ const QScreen *screen = wp->positionAutomatic
+ ? effectiveScreen(w)
+ : QGuiApplication::screenAt(initialGeometry.center());
if (!screen)
return initialGeometry;
- const auto *wp = qt_window_private(const_cast<QWindow*>(w));
+ // initialGeometry refers to window's screen
QRect rect(QHighDpi::fromNativePixels(initialGeometry, w));
if (wp->resizeAutomatic)
rect.setSize(fixInitialSize(rect.size(), w, defaultWidth, defaultHeight));
- if (wp->positionAutomatic && w->type() != Qt::Popup) {
+ if (position) {
const QRect availableGeometry = screen->availableGeometry();
// Center unless the geometry ( + unknown window frame) is too large for the screen).
if (rect.height() < (availableGeometry.height() * 8) / 9
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 590e2a85bb..ed516c0eed 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -218,6 +218,12 @@ QWindow::~QWindow()
QGuiApplicationPrivate::window_list.removeAll(this);
if (!QGuiApplicationPrivate::is_app_closing)
QGuiApplicationPrivate::instance()->modalWindowList.removeOne(this);
+
+ // focus_window is normally cleared in destroy(), but the window may in
+ // some cases end up becoming the focus window again. Clear it again
+ // here as a workaround. See QTBUG-75326.
+ if (QGuiApplicationPrivate::focus_window == this)
+ QGuiApplicationPrivate::focus_window = 0;
}
void QWindowPrivate::init(QScreen *targetScreen)
@@ -1682,9 +1688,9 @@ void QWindow::setGeometry(const QRect &rect)
chicken and egg problem here: we cannot convert to native coordinates
before we know which screen we are on.
*/
-QScreen *QWindowPrivate::screenForGeometry(const QRect &newGeometry)
+QScreen *QWindowPrivate::screenForGeometry(const QRect &newGeometry) const
{
- Q_Q(QWindow);
+ Q_Q(const QWindow);
QScreen *currentScreen = q->screen();
QScreen *fallback = currentScreen;
QPoint center = newGeometry.center();
@@ -2554,6 +2560,10 @@ QPoint QWindow::mapToGlobal(const QPoint &pos) const
&& (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapToGlobal(QHighDpi::toNativeLocalPosition(pos, this)), this);
}
+
+ if (QHighDpiScaling::isActive())
+ return QHighDpiScaling::mapPositionToGlobal(pos, d->globalPosition(), this);
+
return pos + d->globalPosition();
}
@@ -2574,6 +2584,10 @@ QPoint QWindow::mapFromGlobal(const QPoint &pos) const
&& (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobal(QHighDpi::toNativeLocalPosition(pos, this)), this);
}
+
+ if (QHighDpiScaling::isActive())
+ return QHighDpiScaling::mapPositionFromGlobal(pos, d->globalPosition(), this);
+
return pos - d->globalPosition();
}
@@ -2862,7 +2876,7 @@ void QWindow::setVulkanInstance(QVulkanInstance *instance)
}
/*!
- \return the associated Vulkan instance or \c null if there is none.
+ \return the associated Vulkan instance if any was set, otherwise \nullptr.
*/
QVulkanInstance *QWindow::vulkanInstance() const
{
diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h
index b8fa77bef0..5367d93e84 100644
--- a/src/gui/kernel/qwindow_p.h
+++ b/src/gui/kernel/qwindow_p.h
@@ -148,7 +148,7 @@ public:
void connectToScreen(QScreen *topLevelScreen);
void disconnectFromScreen();
void emitScreenChangedRecursion(QScreen *newScreen);
- QScreen *screenForGeometry(const QRect &rect);
+ QScreen *screenForGeometry(const QRect &rect) const;
void setTransientParent(QWindow *parent);
virtual void clearFocusObject();
diff --git a/src/gui/opengl/qopengltextureuploader.cpp b/src/gui/opengl/qopengltextureuploader.cpp
index b8b532b3d0..d9d5403cf3 100644
--- a/src/gui/opengl/qopengltextureuploader.cpp
+++ b/src/gui/opengl/qopengltextureuploader.cpp
@@ -77,8 +77,20 @@
#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
#endif
-#ifndef GL_TEXTURE_SWIZZLE_RGBA
-#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46
+#ifndef GL_TEXTURE_SWIZZLE_R
+#define GL_TEXTURE_SWIZZLE_R 0x8E42
+#endif
+
+#ifndef GL_TEXTURE_SWIZZLE_G
+#define GL_TEXTURE_SWIZZLE_G 0x8E43
+#endif
+
+#ifndef GL_TEXTURE_SWIZZLE_B
+#define GL_TEXTURE_SWIZZLE_B 0x8E44
+#endif
+
+#ifndef GL_TEXTURE_SWIZZLE_A
+#define GL_TEXTURE_SWIZZLE_A 0x8E45
#endif
#ifndef GL_SRGB
@@ -128,11 +140,13 @@ qsizetype QOpenGLTextureUploader::textureImage(GLenum target, const QImage &imag
#endif
} else if (funcs->hasOpenGLExtension(QOpenGLExtensions::TextureSwizzle)) {
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
- GLint swizzle[4] = { GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
- funcs->glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
+ funcs->glTexParameteri(target, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
+ funcs->glTexParameteri(target, GL_TEXTURE_SWIZZLE_B, GL_RED);
#else
- GLint swizzle[4] = { GL_GREEN, GL_BLUE, GL_ALPHA, GL_RED };
- funcs->glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
+ funcs->glTexParameteri(target, GL_TEXTURE_SWIZZLE_R, GL_GREEN);
+ funcs->glTexParameteri(target, GL_TEXTURE_SWIZZLE_G, GL_BLUE);
+ funcs->glTexParameteri(target, GL_TEXTURE_SWIZZLE_B, GL_ALPHA);
+ funcs->glTexParameteri(target, GL_TEXTURE_SWIZZLE_A, GL_RED);
#endif
externalFormat = internalFormat = GL_RGBA;
pixelType = GL_UNSIGNED_BYTE;
@@ -164,12 +178,12 @@ qsizetype QOpenGLTextureUploader::textureImage(GLenum target, const QImage &imag
externalFormat = GL_BGRA;
internalFormat = GL_RGB10_A2;
targetFormat = image.format();
- } else if (funcs->hasOpenGLExtension(QOpenGLExtensions::TextureSwizzle) && (isOpenGL12orBetter || isOpenGLES3orBetter)) {
+ } else if (funcs->hasOpenGLExtension(QOpenGLExtensions::TextureSwizzle)) {
+ funcs->glTexParameteri(target, GL_TEXTURE_SWIZZLE_B, GL_RED);
+ funcs->glTexParameteri(target, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
pixelType = GL_UNSIGNED_INT_2_10_10_10_REV;
externalFormat = GL_RGBA;
internalFormat = GL_RGB10_A2;
- GLint swizzle[4] = { GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
- funcs->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
targetFormat = image.format();
}
break;
@@ -227,8 +241,10 @@ qsizetype QOpenGLTextureUploader::textureImage(GLenum target, const QImage &imag
pixelType = GL_UNSIGNED_BYTE;
targetFormat = image.format();
} else if (funcs->hasOpenGLExtension(QOpenGLExtensions::TextureSwizzle)) {
- GLint swizzle[4] = { GL_ZERO, GL_ZERO, GL_ZERO, GL_RED };
- funcs->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_ALPHA);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_ZERO);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_ZERO);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ZERO);
externalFormat = internalFormat = GL_RED;
pixelType = GL_UNSIGNED_BYTE;
targetFormat = image.format();
@@ -247,8 +263,10 @@ qsizetype QOpenGLTextureUploader::textureImage(GLenum target, const QImage &imag
pixelType = GL_UNSIGNED_BYTE;
targetFormat = image.format();
} else if (funcs->hasOpenGLExtension(QOpenGLExtensions::TextureSwizzle)) {
- GLint swizzle[4] = { GL_RED, GL_RED, GL_RED, GL_ONE };
- funcs->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_RED);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ONE);
externalFormat = internalFormat = GL_RED;
pixelType = GL_UNSIGNED_BYTE;
targetFormat = image.format();
@@ -267,8 +285,10 @@ qsizetype QOpenGLTextureUploader::textureImage(GLenum target, const QImage &imag
pixelType = GL_UNSIGNED_SHORT;
targetFormat = image.format();
} else if (funcs->hasOpenGLExtension(QOpenGLExtensions::TextureSwizzle)) {
- GLint swizzle[4] = { GL_RED, GL_RED, GL_RED, GL_ONE };
- funcs->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_RED);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
+ funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ONE);
externalFormat = internalFormat = GL_RED;
pixelType = GL_UNSIGNED_SHORT;
targetFormat = image.format();
diff --git a/src/gui/painting/qbezier.cpp b/src/gui/painting/qbezier.cpp
index ddd1d997f2..8cda4b4072 100644
--- a/src/gui/painting/qbezier.cpp
+++ b/src/gui/painting/qbezier.cpp
@@ -261,9 +261,9 @@ static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offse
static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
{
int map[4];
- bool p1_p2_equal = (orig->x1 == orig->x2 && orig->y1 == orig->y2);
- bool p2_p3_equal = (orig->x2 == orig->x3 && orig->y2 == orig->y3);
- bool p3_p4_equal = (orig->x3 == orig->x4 && orig->y3 == orig->y4);
+ bool p1_p2_equal = qFuzzyCompare(orig->x1, orig->x2) && qFuzzyCompare(orig->y1, orig->y2);
+ bool p2_p3_equal = qFuzzyCompare(orig->x2, orig->x3) && qFuzzyCompare(orig->y2, orig->y3);
+ bool p3_p4_equal = qFuzzyCompare(orig->x3, orig->x4) && qFuzzyCompare(orig->y3, orig->y4);
QPointF points[4];
int np = 0;
diff --git a/src/gui/painting/qdrawhelper_sse4.cpp b/src/gui/painting/qdrawhelper_sse4.cpp
index d9a687b1b4..e387026972 100644
--- a/src/gui/painting/qdrawhelper_sse4.cpp
+++ b/src/gui/painting/qdrawhelper_sse4.cpp
@@ -156,6 +156,17 @@ template<bool RGBA, bool RGBx>
static inline void convertARGBFromARGB32PM_sse4(uint *buffer, const uint *src, int count)
{
int i = 0;
+ if ((_MM_GET_EXCEPTION_MASK() & _MM_MASK_INVALID) == 0) {
+ for (; i < count; ++i) {
+ uint v = qUnpremultiply(src[i]);
+ if (RGBx)
+ v = 0xff000000 | v;
+ if (RGBA)
+ v = ARGB2RGBA(v);
+ buffer[i] = v;
+ }
+ return;
+ }
const __m128i alphaMask = _mm_set1_epi32(0xff000000);
const __m128i rgbaMask = _mm_setr_epi8(2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15);
const __m128i zero = _mm_setzero_si128();
@@ -223,6 +234,13 @@ template<bool RGBA>
static inline void convertARGBFromRGBA64PM_sse4(uint *buffer, const QRgba64 *src, int count)
{
int i = 0;
+ if ((_MM_GET_EXCEPTION_MASK() & _MM_MASK_INVALID) == 0) {
+ for (; i < count; ++i) {
+ const QRgba64 v = src[i].unpremultiplied();
+ buffer[i] = RGBA ? toRgba8888(v) : toArgb32(v);
+ }
+ return;
+ }
const __m128i alphaMask = _mm_set1_epi64x(qint64(Q_UINT64_C(0xffff) << 48));
const __m128i alphaMask32 = _mm_set1_epi32(0xff000000);
const __m128i rgbaMask = _mm_setr_epi8(2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15);
diff --git a/src/gui/painting/qpaintengine_raster_p.h b/src/gui/painting/qpaintengine_raster_p.h
index 881144d1c2..5d527207a4 100644
--- a/src/gui/painting/qpaintengine_raster_p.h
+++ b/src/gui/painting/qpaintengine_raster_p.h
@@ -448,7 +448,7 @@ public:
void resetBuffer(int val=0);
- uchar *scanLine(int y) { Q_ASSERT(y>=0); Q_ASSERT(y<m_height); return m_buffer + y * bytes_per_line; }
+ uchar *scanLine(int y) { Q_ASSERT(y>=0); Q_ASSERT(y<m_height); return m_buffer + y * qsizetype(bytes_per_line); }
#ifndef QT_NO_DEBUG
QImage bufferImage() const;
diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp
index 42f94d038f..cbe34c2857 100644
--- a/src/gui/painting/qpainterpath.cpp
+++ b/src/gui/painting/qpainterpath.cpp
@@ -71,6 +71,24 @@
QT_BEGIN_NAMESPACE
+static inline bool isValidCoord(qreal c)
+{
+ if (sizeof(qreal) >= sizeof(double))
+ return qIsFinite(c) && fabs(c) < 1e128;
+ else
+ return qIsFinite(c) && fabsf(float(c)) < 1e16f;
+}
+
+static bool hasValidCoords(QPointF p)
+{
+ return isValidCoord(p.x()) && isValidCoord(p.y());
+}
+
+static bool hasValidCoords(QRectF r)
+{
+ return isValidCoord(r.x()) && isValidCoord(r.y()) && isValidCoord(r.width()) && isValidCoord(r.height());
+}
+
struct QPainterPathPrivateDeleter
{
static inline void cleanup(QPainterPathPrivate *d)
@@ -724,9 +742,9 @@ void QPainterPath::moveTo(const QPointF &p)
printf("QPainterPath::moveTo() (%.2f,%.2f)\n", p.x(), p.y());
#endif
- if (!qt_is_finite(p.x()) || !qt_is_finite(p.y())) {
+ if (!hasValidCoords(p)) {
#ifndef QT_NO_DEBUG
- qWarning("QPainterPath::moveTo: Adding point where x or y is NaN or Inf, ignoring call");
+ qWarning("QPainterPath::moveTo: Adding point with invalid coordinates, ignoring call");
#endif
return;
}
@@ -774,9 +792,9 @@ void QPainterPath::lineTo(const QPointF &p)
printf("QPainterPath::lineTo() (%.2f,%.2f)\n", p.x(), p.y());
#endif
- if (!qt_is_finite(p.x()) || !qt_is_finite(p.y())) {
+ if (!hasValidCoords(p)) {
#ifndef QT_NO_DEBUG
- qWarning("QPainterPath::lineTo: Adding point where x or y is NaN or Inf, ignoring call");
+ qWarning("QPainterPath::lineTo: Adding point with invalid coordinates, ignoring call");
#endif
return;
}
@@ -833,10 +851,9 @@ void QPainterPath::cubicTo(const QPointF &c1, const QPointF &c2, const QPointF &
c1.x(), c1.y(), c2.x(), c2.y(), e.x(), e.y());
#endif
- if (!qt_is_finite(c1.x()) || !qt_is_finite(c1.y()) || !qt_is_finite(c2.x()) || !qt_is_finite(c2.y())
- || !qt_is_finite(e.x()) || !qt_is_finite(e.y())) {
+ if (!hasValidCoords(c1) || !hasValidCoords(c2) || !hasValidCoords(e)) {
#ifndef QT_NO_DEBUG
- qWarning("QPainterPath::cubicTo: Adding point where x or y is NaN or Inf, ignoring call");
+ qWarning("QPainterPath::cubicTo: Adding point with invalid coordinates, ignoring call");
#endif
return;
}
@@ -890,9 +907,9 @@ void QPainterPath::quadTo(const QPointF &c, const QPointF &e)
c.x(), c.y(), e.x(), e.y());
#endif
- if (!qt_is_finite(c.x()) || !qt_is_finite(c.y()) || !qt_is_finite(e.x()) || !qt_is_finite(e.y())) {
+ if (!hasValidCoords(c) || !hasValidCoords(e)) {
#ifndef QT_NO_DEBUG
- qWarning("QPainterPath::quadTo: Adding point where x or y is NaN or Inf, ignoring call");
+ qWarning("QPainterPath::quadTo: Adding point with invalid coordinates, ignoring call");
#endif
return;
}
@@ -961,10 +978,9 @@ void QPainterPath::arcTo(const QRectF &rect, qreal startAngle, qreal sweepLength
rect.x(), rect.y(), rect.width(), rect.height(), startAngle, sweepLength);
#endif
- if ((!qt_is_finite(rect.x()) && !qt_is_finite(rect.y())) || !qt_is_finite(rect.width()) || !qt_is_finite(rect.height())
- || !qt_is_finite(startAngle) || !qt_is_finite(sweepLength)) {
+ if (!hasValidCoords(rect) || !isValidCoord(startAngle) || !isValidCoord(sweepLength)) {
#ifndef QT_NO_DEBUG
- qWarning("QPainterPath::arcTo: Adding arc where a parameter is NaN or Inf, ignoring call");
+ qWarning("QPainterPath::arcTo: Adding point with invalid coordinates, ignoring call");
#endif
return;
}
@@ -1067,9 +1083,9 @@ QPointF QPainterPath::currentPosition() const
*/
void QPainterPath::addRect(const QRectF &r)
{
- if (!qt_is_finite(r.x()) || !qt_is_finite(r.y()) || !qt_is_finite(r.width()) || !qt_is_finite(r.height())) {
+ if (!hasValidCoords(r)) {
#ifndef QT_NO_DEBUG
- qWarning("QPainterPath::addRect: Adding rect where a parameter is NaN or Inf, ignoring call");
+ qWarning("QPainterPath::addRect: Adding point with invalid coordinates, ignoring call");
#endif
return;
}
@@ -1147,10 +1163,9 @@ void QPainterPath::addPolygon(const QPolygonF &polygon)
*/
void QPainterPath::addEllipse(const QRectF &boundingRect)
{
- if (!qt_is_finite(boundingRect.x()) || !qt_is_finite(boundingRect.y())
- || !qt_is_finite(boundingRect.width()) || !qt_is_finite(boundingRect.height())) {
+ if (!hasValidCoords(boundingRect)) {
#ifndef QT_NO_DEBUG
- qWarning("QPainterPath::addEllipse: Adding ellipse where a parameter is NaN or Inf, ignoring call");
+ qWarning("QPainterPath::addEllipse: Adding point with invalid coordinates, ignoring call");
#endif
return;
}
@@ -2501,6 +2516,7 @@ QDataStream &operator<<(QDataStream &s, const QPainterPath &p)
*/
QDataStream &operator>>(QDataStream &s, QPainterPath &p)
{
+ bool errorDetected = false;
int size;
s >> size;
@@ -2519,10 +2535,11 @@ QDataStream &operator>>(QDataStream &s, QPainterPath &p)
s >> x;
s >> y;
Q_ASSERT(type >= 0 && type <= 3);
- if (!qt_is_finite(x) || !qt_is_finite(y)) {
+ if (!isValidCoord(qreal(x)) || !isValidCoord(qreal(y))) {
#ifndef QT_NO_DEBUG
- qWarning("QDataStream::operator>>: NaN or Inf element found in path, skipping it");
+ qWarning("QDataStream::operator>>: Invalid QPainterPath coordinates read, skipping it");
#endif
+ errorDetected = true;
continue;
}
QPainterPath::Element elm = { qreal(x), qreal(y), QPainterPath::ElementType(type) };
@@ -2535,6 +2552,8 @@ QDataStream &operator>>(QDataStream &s, QPainterPath &p)
p.d_func()->fillRule = Qt::FillRule(fillRule);
p.d_func()->dirtyBounds = true;
p.d_func()->dirtyControlBounds = true;
+ if (errorDetected)
+ p = QPainterPath(); // Better than to return path with possibly corrupt datastructure, which would likely cause crash
return s;
}
#endif // QT_NO_DATASTREAM
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 6dad5196e8..bc7d379157 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -38,7 +38,7 @@
****************************************************************************/
#include "qfontdatabase.h"
-#include "qdebug.h"
+#include "qloggingcategory.h"
#include "qalgorithms.h"
#include "qguiapplication.h"
#include "qvarlengtharray.h" // here or earlier - workaround for VC++6
@@ -59,25 +59,13 @@
#include <stdlib.h>
#include <algorithm>
-
-// #define QFONTDATABASE_DEBUG
-#ifdef QFONTDATABASE_DEBUG
-# define FD_DEBUG qDebug
-#else
-# define FD_DEBUG if (false) qDebug
-#endif
-
-// #define FONT_MATCH_DEBUG
-#ifdef FONT_MATCH_DEBUG
-# define FM_DEBUG qDebug
-#else
-# define FM_DEBUG if (false) qDebug
-#endif
-
#include <qtgui_tracepoints_p.h>
QT_BEGIN_NAMESPACE
+Q_LOGGING_CATEGORY(lcFontDb, "qt.text.font.db")
+Q_LOGGING_CATEGORY(lcFontMatch, "qt.text.font.match")
+
#define SMOOTH_SCALABLE 0xffff
#if defined(QT_BUILD_INTERNAL)
@@ -745,7 +733,7 @@ void qt_registerFont(const QString &familyName, const QString &stylename,
const QSupportedWritingSystems &writingSystems, void *handle)
{
QFontDatabasePrivate *d = privateDb();
-// qDebug() << "Adding font" << familyName << weight << style << pixelSize << antialiased;
+ qCDebug(lcFontDb) << "Adding font" << familyName << weight << style << pixelSize << "aa" << antialiased << "fixed" << fixedPitch;
QtFontStyle::Key styleKey;
styleKey.style = style;
styleKey.weight = weight;
@@ -1080,7 +1068,7 @@ static QtFontStyle *bestStyle(QtFontFoundry *foundry, const QtFontStyle::Key &st
}
}
- FM_DEBUG( " best style has distance 0x%x", dist );
+ qCDebug(lcFontMatch, " best style has distance 0x%x", dist );
return foundry->styles[best];
}
@@ -1099,20 +1087,20 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
desc->size = 0;
- FM_DEBUG(" REMARK: looking for best foundry for family '%s' [%d]", family->name.toLatin1().constData(), family->count);
+ qCDebug(lcFontMatch, " REMARK: looking for best foundry for family '%s' [%d]", family->name.toLatin1().constData(), family->count);
for (int x = 0; x < family->count; ++x) {
QtFontFoundry *foundry = family->foundries[x];
if (!foundry_name.isEmpty() && foundry->name.compare(foundry_name, Qt::CaseInsensitive) != 0)
continue;
- FM_DEBUG(" looking for matching style in foundry '%s' %d",
+ qCDebug(lcFontMatch, " looking for matching style in foundry '%s' %d",
foundry->name.isEmpty() ? "-- none --" : foundry->name.toLatin1().constData(), foundry->count);
QtFontStyle *style = bestStyle(foundry, styleKey, styleName);
if (!style->smoothScalable && (styleStrategy & QFont::ForceOutline)) {
- FM_DEBUG(" ForceOutline set, but not smoothly scalable");
+ qCDebug(lcFontMatch, " ForceOutline set, but not smoothly scalable");
continue;
}
@@ -1123,7 +1111,7 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
if (!(styleStrategy & QFont::ForceOutline)) {
size = style->pixelSize(pixelSize);
if (size) {
- FM_DEBUG(" found exact size match (%d pixels)", size->pixelSize);
+ qCDebug(lcFontMatch, " found exact size match (%d pixels)", size->pixelSize);
px = size->pixelSize;
}
}
@@ -1132,7 +1120,7 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
if (!size && style->smoothScalable && ! (styleStrategy & QFont::PreferBitmap)) {
size = style->pixelSize(SMOOTH_SCALABLE);
if (size) {
- FM_DEBUG(" found smoothly scalable font (%d pixels)", pixelSize);
+ qCDebug(lcFontMatch, " found smoothly scalable font (%d pixels)", pixelSize);
px = pixelSize;
}
}
@@ -1141,7 +1129,7 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
if (!size && style->bitmapScalable && (styleStrategy & QFont::PreferMatch)) {
size = style->pixelSize(0);
if (size) {
- FM_DEBUG(" found bitmap scalable font (%d pixels)", pixelSize);
+ qCDebug(lcFontMatch, " found bitmap scalable font (%d pixels)", pixelSize);
px = pixelSize;
}
}
@@ -1165,12 +1153,12 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
if (d < distance) {
distance = d;
size = style->pixelSizes + x;
- FM_DEBUG(" best size so far: %3d (%d)", size->pixelSize, pixelSize);
+ qCDebug(lcFontMatch, " best size so far: %3d (%d)", size->pixelSize, pixelSize);
}
}
if (!size) {
- FM_DEBUG(" no size supports the script we want");
+ qCDebug(lcFontMatch, " no size supports the script we want");
continue;
}
@@ -1205,7 +1193,7 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
this_score += qAbs(px - pixelSize);
if (this_score < score) {
- FM_DEBUG(" found a match: score %x best score so far %x",
+ qCDebug(lcFontMatch, " found a match: score %x best score so far %x",
this_score, score);
score = this_score;
@@ -1213,7 +1201,7 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
desc->style = style;
desc->size = size;
} else {
- FM_DEBUG(" score %x no better than best %x", this_score, score);
+ qCDebug(lcFontMatch, " score %x no better than best %x", this_score, score);
}
}
@@ -1246,7 +1234,7 @@ static int match(int script, const QFontDef &request,
char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p';
- FM_DEBUG("QFontDatabase::match\n"
+ qCDebug(lcFontMatch, "QFontDatabase::match\n"
" request:\n"
" family: %s [%s], script: %d\n"
" weight: %d, style: %d\n"
@@ -2684,7 +2672,7 @@ QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script)
QFontCache::Key key(request, script, multi ? 1 : 0);
engine = fontCache->findEngine(key);
if (engine) {
- FM_DEBUG("Cache hit level 1");
+ qCDebug(lcFontMatch, "Cache hit level 1");
return engine;
}
@@ -2713,7 +2701,7 @@ QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script)
else
blackListed.append(index);
} else {
- FM_DEBUG(" NO MATCH FOUND\n");
+ qCDebug(lcFontMatch, " NO MATCH FOUND\n");
}
if (!engine) {
@@ -2757,7 +2745,7 @@ QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script)
if (!engine)
engine = new QFontEngineBox(request.pixelSize);
- FM_DEBUG("returning box engine");
+ qCDebug(lcFontMatch, "returning box engine");
}
return engine;
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index fd3473b32e..4e5ba8e038 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -1358,6 +1358,8 @@ QTextCursor QTextDocument::find(const QString &subString, int from, FindFlags op
blockOffset = 0;
}
} else {
+ if (blockOffset == block.length() - 1)
+ --blockOffset; // make sure to skip end-of-paragraph character
while (block.isValid()) {
if (findInBlock(block, subString, blockOffset, options, &cursor))
return cursor;
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 22c93d7ec2..2da13289bf 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -1383,11 +1383,12 @@ void QTextEngine::shapeText(int item) const
if (QChar::isHighSurrogate(ucs4) && i + 1 < itemLength) {
uint low = string[i + 1];
if (QChar::isLowSurrogate(low)) {
+ // high part never changes in simple casing
+ uc[i] = ucs4;
++i;
ucs4 = QChar::surrogateToUcs4(ucs4, low);
ucs4 = si.analysis.flags == QScriptAnalysis::Lowercase ? QChar::toLower(ucs4)
: QChar::toUpper(ucs4);
- // high part never changes in simple casing
uc[i] = QChar::lowSurrogate(ucs4);
}
} else {
diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp
index 18c5a4f3dd..547b21c02e 100644
--- a/src/gui/text/qtextobject.cpp
+++ b/src/gui/text/qtextobject.cpp
@@ -1316,8 +1316,8 @@ QTextList *QTextBlock::textList() const
/*!
\since 4.1
- Returns a pointer to a QTextBlockUserData object if previously set with
- setUserData() or a null pointer.
+ Returns a pointer to a QTextBlockUserData object,
+ if one has been set with setUserData(), or \nullptr.
*/
QTextBlockUserData *QTextBlock::userData() const
{
diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp
index a62e7e425a..9721243454 100644
--- a/src/gui/text/qtextodfwriter.cpp
+++ b/src/gui/text/qtextodfwriter.cpp
@@ -43,6 +43,7 @@
#include "qtextodfwriter_p.h"
+#include <QImageReader>
#include <QImageWriter>
#include <QTextListFormat>
#include <QTextList>
@@ -410,6 +411,29 @@ void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &bloc
writer.writeEndElement(); // list-item
}
+static bool probeImageData(QIODevice *device, QImage *image, QString *mimeType, qreal *width, qreal *height)
+{
+ QImageReader reader(device);
+ const QByteArray format = reader.format().toLower();
+ if (format == "png") {
+ *mimeType = QStringLiteral("image/png");
+ } else if (format == "jpg") {
+ *mimeType = QStringLiteral("image/jpg");
+ } else if (format == "svg") {
+ *mimeType = QStringLiteral("image/svg+xml");
+ } else {
+ *image = reader.read();
+ return false;
+ }
+
+ const QSize size = reader.size();
+
+ *width = size.width();
+ *height = size.height();
+
+ return true;
+}
+
void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextFragment &fragment) const
{
writer.writeStartElement(drawNS, QString::fromLatin1("frame"));
@@ -420,47 +444,73 @@ void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextF
QTextImageFormat imageFormat = fragment.charFormat().toImageFormat();
writer.writeAttribute(drawNS, QString::fromLatin1("name"), imageFormat.name());
+ QByteArray data;
+ QString mimeType;
+ qreal width = 0;
+ qreal height = 0;
+
QImage image;
QString name = imageFormat.name();
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
name.prepend(QLatin1String("qrc"));
QUrl url = QUrl(name);
- const QVariant data = m_document->resource(QTextDocument::ImageResource, url);
- if (data.type() == QVariant::Image) {
- image = qvariant_cast<QImage>(data);
- } else if (data.type() == QVariant::ByteArray) {
- image.loadFromData(data.toByteArray());
- }
-
- if (image.isNull()) {
- if (image.isNull()) { // try direct loading
- name = imageFormat.name(); // remove qrc:/ prefix again
- image.load(name);
+ const QVariant variant = m_document->resource(QTextDocument::ImageResource, url);
+ if (variant.type() == QVariant::Image) {
+ image = qvariant_cast<QImage>(variant);
+ } else if (variant.type() == QVariant::ByteArray) {
+ data = variant.toByteArray();
+
+ QBuffer buffer(&data);
+ buffer.open(QIODevice::ReadOnly);
+ probeImageData(&buffer, &image, &mimeType, &width, &height);
+ } else {
+ // try direct loading
+ QFile file(imageFormat.name());
+ if (file.open(QIODevice::ReadOnly) && !probeImageData(&file, &image, &mimeType, &width, &height)) {
+ file.seek(0);
+ data = file.readAll();
}
}
if (! image.isNull()) {
QBuffer imageBytes;
- QString filename = m_strategy->createUniqueImageName();
+
int imgQuality = imageFormat.quality();
if (imgQuality >= 100 || imgQuality < 0 || image.hasAlphaChannel()) {
QImageWriter imageWriter(&imageBytes, "png");
imageWriter.write(image);
- m_strategy->addFile(filename, QString::fromLatin1("image/png"), imageBytes.data());
+
+ data = imageBytes.data();
+ mimeType = QStringLiteral("image/png");
} else {
// Write images without alpha channel as jpg with quality set by QTextImageFormat
QImageWriter imageWriter(&imageBytes, "jpg");
imageWriter.setQuality(imgQuality);
imageWriter.write(image);
- m_strategy->addFile(filename, QString::fromLatin1("image/jpg"), imageBytes.data());
+
+ data = imageBytes.data();
+ mimeType = QStringLiteral("image/jpg");
}
- // get the width/height from the format.
- qreal width = imageFormat.hasProperty(QTextFormat::ImageWidth)
- ? imageFormat.width() : image.width();
+
+ width = image.width();
+ height = image.height();
+ }
+
+ if (!data.isEmpty()) {
+ if (imageFormat.hasProperty(QTextFormat::ImageWidth)) {
+ width = imageFormat.width();
+ }
+ if (imageFormat.hasProperty(QTextFormat::ImageHeight)) {
+ height = imageFormat.height();
+ }
+
+ QString filename = m_strategy->createUniqueImageName();
+
+ m_strategy->addFile(filename, mimeType, data);
+
writer.writeAttribute(svgNS, QString::fromLatin1("width"), pixelToPoint(width));
- qreal height = imageFormat.hasProperty(QTextFormat::ImageHeight)
- ? imageFormat.height() : image.height();
writer.writeAttribute(svgNS, QString::fromLatin1("height"), pixelToPoint(height));
+ writer.writeAttribute(textNS, QStringLiteral("anchor-type"), QStringLiteral("as-char"));
writer.writeStartElement(drawNS, QString::fromLatin1("image"));
writer.writeAttribute(xlinkNS, QString::fromLatin1("href"), filename);
writer.writeEndElement(); // image
diff --git a/src/gui/vulkan/qvulkaninstance.cpp b/src/gui/vulkan/qvulkaninstance.cpp
index 9895fec2ca..2941bfd01f 100644
--- a/src/gui/vulkan/qvulkaninstance.cpp
+++ b/src/gui/vulkan/qvulkaninstance.cpp
@@ -614,7 +614,7 @@ VkResult QVulkanInstance::errorCode() const
}
/*!
- \return the VkInstance handle this QVulkanInstance wraps, or \c null if
+ \return the VkInstance handle this QVulkanInstance wraps, or \nullptr if
create() has not yet been successfully called and no existing instance has
been provided via setVkInstance().
*/