diff options
author | Liang Qi <liang.qi@qt.io> | 2018-10-25 07:21:05 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-10-25 07:21:53 +0200 |
commit | e28e91ae99b8c3859899e04cc9370534c7c7b86d (patch) | |
tree | cca81b1e745be4f25aab78e8e917c2324594e539 /src/gui | |
parent | 5ea233ca6782eb27adf596515cb66ef3dadc1d5e (diff) | |
parent | ebfad73b4e44fe6db8059200da105b4b87888718 (diff) |
Merge remote-tracking branch 'origin/5.12' into dev
Conflicts:
src/corelib/animation/qpropertyanimation.cpp
src/gui/image/qicon.cpp
tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
Change-Id: I3698172b7b44ebb487cb38f50fd2c4a9f8a35b21
Diffstat (limited to 'src/gui')
48 files changed, 879 insertions, 458 deletions
diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp index 6b48f573b2..a3f53e149b 100644 --- a/src/gui/accessible/qaccessible.cpp +++ b/src/gui/accessible/qaccessible.cpp @@ -1309,14 +1309,7 @@ QColor QAccessibleInterface::backgroundColor() const For example to notify about a focus change when re-implementing QWidget::setFocus, the event could be used as follows: - \code - void MyWidget::setFocus(Qt::FocusReason reason) - { - // handle custom focus setting... - QAccessibleEvent event(f, QAccessible::Focus); - QAccessible::updateAccessibility(&event); - } - \endcode + \snippet code/src_gui_accessible_qaccessible.cpp 2 To enable in process screen readers, all events must be sent after the change has happened. */ @@ -1826,14 +1819,7 @@ void QAccessibleInterface::virtual_hook(int /*id*/, void * /*data*/) Qt's QLineEdit for example has its accessibility support implemented in QAccessibleLineEdit. - \code -void *QAccessibleLineEdit::interface_cast(QAccessible::InterfaceType t) -{ - if (t == QAccessible::TextInterface) - return static_cast<QAccessibleTextInterface*>(this); - return QAccessibleWidget::interface_cast(t); -} - \endcode + \snippet code/src_gui_accessible_qaccessible.cpp 3 \sa QAccessible::InterfaceType, QAccessibleTextInterface, QAccessibleValueInterface, QAccessibleActionInterface, diff --git a/src/gui/animation/qguivariantanimation.cpp b/src/gui/animation/qguivariantanimation.cpp index b72764e048..a5b6d8b95c 100644 --- a/src/gui/animation/qguivariantanimation.cpp +++ b/src/gui/animation/qguivariantanimation.cpp @@ -38,8 +38,6 @@ ****************************************************************************/ #include <QtGui/qtguiglobal.h> -#ifndef QT_NO_ANIMATION - #include <QtCore/qvariantanimation.h> #include <private/qvariantanimation_p.h> #include <QtGui/qcolor.h> @@ -90,5 +88,3 @@ static void qUnregisterGuiGetInterpolator() Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator) QT_END_NAMESPACE - -#endif //QT_NO_ANIMATION diff --git a/src/gui/configure.json b/src/gui/configure.json index 4741ed345a..0332631ec8 100644 --- a/src/gui/configure.json +++ b/src/gui/configure.json @@ -1577,7 +1577,7 @@ }, "multiprocess": { "label": "Multi process", - "description": "Provides support for detecting the desktop environment, launching external processes and opening URLs.", + "purpose": "Provides support for detecting the desktop environment, launching external processes and opening URLs.", "section": "Utilities", "condition": "!config.integrity", "output": [ "privateFeature" ] diff --git a/src/gui/doc/snippets/code/src_gui_accessible_qaccessible.cpp b/src/gui/doc/snippets/code/src_gui_accessible_qaccessible.cpp index 98d40c94f9..2fd76d08c7 100644 --- a/src/gui/doc/snippets/code/src_gui_accessible_qaccessible.cpp +++ b/src/gui/doc/snippets/code/src_gui_accessible_qaccessible.cpp @@ -51,3 +51,21 @@ //! [1] typedef QAccessibleInterface* myFactoryFunction(const QString &key, QObject *); //! [1] + +//! [2] +void MyWidget::setFocus(Qt::FocusReason reason) +{ + // handle custom focus setting... + QAccessibleEvent event(f, QAccessible::Focus); + QAccessible::updateAccessibility(&event); +} +//! [2] + +//! [3] +void *QAccessibleLineEdit::interface_cast(QAccessible::InterfaceType t) +{ + if (t == QAccessible::TextInterface) + return static_cast<QAccessibleTextInterface*>(this); + return QAccessibleWidget::interface_cast(t); +} +//! [3] diff --git a/src/gui/doc/snippets/code/src_gui_math3d_qquaternion.cpp b/src/gui/doc/snippets/code/src_gui_math3d_qquaternion.cpp new file mode 100644 index 0000000000..b5cd00d5aa --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_math3d_qquaternion.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QVector3D result = q.rotatedVector(vector); +//! [0] + +//! [1] + QVector3D result = (q * QQuaternion(0, vector) * q.conjugated()).vector(); +//! [1] diff --git a/src/gui/doc/snippets/code/src_gui_opengl_qopenglbuffer.cpp b/src/gui/doc/snippets/code/src_gui_opengl_qopenglbuffer.cpp new file mode 100644 index 0000000000..4a4a6fe16d --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_opengl_qopenglbuffer.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + QOpenGLBuffer buffer1(QOpenGLBuffer::IndexBuffer); + buffer1.create(); + + QOpenGLBuffer buffer2 = buffer1; +//! [0] + +//! [1] + QOpenGLBuffer::release(QOpenGLBuffer::VertexBuffer); +//! [1] diff --git a/src/gui/doc/snippets/code/src_gui_opengl_qopengldebug.cpp b/src/gui/doc/snippets/code/src_gui_opengl_qopengldebug.cpp new file mode 100644 index 0000000000..4ab84deb3e --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_opengl_qopengldebug.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWidgets module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + GLenum error = GL_NO_ERROR; + do { + error = glGetError(); + if (error != GL_NO_ERROR) + // handle the error + } while (error != GL_NO_ERROR); +//! [0] + +//! [1] + QSurfaceFormat format; + // asks for a OpenGL 3.2 debug context using the Core profile + format.setMajorVersion(3); + format.setMinorVersion(2); + format.setProfile(QSurfaceFormat::CoreProfile); + format.setOption(QSurfaceFormat::DebugContext); + + QOpenGLContext *context = new QOpenGLContext; + context->setFormat(format); + context->create(); +//! [1] + +//! [2] + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this); + + logger->initialize(); // initializes in the current context, i.e. ctx +//! [2] + +//! [3] + ctx->hasExtension(QByteArrayLiteral("GL_KHR_debug")) +//! [3] + +//! [4] + const QList<QOpenGLDebugMessage> messages = logger->loggedMessages(); + for (const QOpenGLDebugMessage &message : messages) + qDebug() << message; +//! [4] + +//! [5] + connect(logger, &QOpenGLDebugLogger::messageLogged, receiver, &LogHandler::handleLoggedMessage); + logger->startLogging(); +//! [5] + +//! [6] + QOpenGLDebugMessage message = + QOpenGLDebugMessage::createApplicationMessage(QStringLiteral("Custom message")); + + logger->logMessage(message); +//! [6] diff --git a/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp b/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp new file mode 100644 index 0000000000..68a20dcb7c --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + class MyGLWindow : public QWindow, protected QOpenGLFunctions + { + Q_OBJECT + public: + MyGLWindow(QScreen *screen = 0); + + protected: + void initializeGL(); + void paintGL(); + + QOpenGLContext *m_context; + }; + + MyGLWindow(QScreen *screen) + : QWindow(screen), QOpenGLWidget(parent) + { + setSurfaceType(OpenGLSurface); + create(); + + // Create an OpenGL context + m_context = new QOpenGLContext; + m_context->create(); + + // Setup scene and render it + initializeGL(); + paintGL(); + } + + void MyGLWindow::initializeGL() + { + m_context->makeCurrent(this); + initializeOpenGLFunctions(); + } +//! [0] + +//! [1] + void MyGLWindow::paintGL() + { + m_context->makeCurrent(this); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, textureId); + ... + m_context->swapBuffers(this); + m_context->doneCurrent(); + } +//! [1] + +//! [2] + QOpenGLFunctions glFuncs(QOpenGLContext::currentContext()); + glFuncs.glActiveTexture(GL_TEXTURE1); +//! [2] + +//! [3] + QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); + glFuncs->glActiveTexture(GL_TEXTURE1); +//! [3] + +//! [4] + QOpenGLFunctions funcs(QOpenGLContext::currentContext()); + bool npot = funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures); +//! [4] diff --git a/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp b/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp index b48e9e8610..b9a8d8d90e 100644 --- a/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp +++ b/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp @@ -68,3 +68,31 @@ mailto:user@foo.com?subject=Test&body=Just a test //! [2] QDesktopServices::openUrl(QUrl("file:///C:/Documents and Settings/All Users/Desktop", QUrl::TolerantMode)); //! [2] + +//! [3] +<key>LSApplicationQueriesSchemes</key> +<array> + <string>https</string> +</array> +//! [3] + +//! [4] +<key>CFBundleURLTypes</key> +<array> + <dict> + <key>CFBundleURLSchemes</key> + <array> + <string>myapp</string> + </array> + </dict> +</array> +//! [4] + +//! [5] +QDesktopServices::storageLocation(QDesktopServices::DataLocation) +//! [5] + +//! [6] +QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + + "/data/organization/application" +//! [6] diff --git a/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanfunctions.cpp b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanfunctions.cpp new file mode 100644 index 0000000000..77c5444df5 --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanfunctions.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + void Window::render() + { + QVulkanInstance *inst = vulkanInstance(); + QVulkanFunctions *f = inst->functions(); + ... + VkResult err = f->vkAllocateCommandBuffers(device, &cmdBufInfo, &cmdBuf); + ... + } +//! [0] + +//! [1] + void Window::render() + { + QVulkanInstance *inst = vulkanInstance(); + QVulkanDeviceFunctions *df = inst->deviceFunctions(device); + VkResult err = df->vkAllocateCommandBuffers(device, &cmdBufInfo, &cmdBuf); + ... + } +//! [1] diff --git a/src/gui/doc/snippets/code/src_gui_vulkan_qvulkaninstance.cpp b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkaninstance.cpp new file mode 100644 index 0000000000..50afe7c0ff --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkaninstance.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + int main(int argc, char **argv) + { + QGuiApplication app(argc, argv); + + QVulkanInstance inst; + if (!inst.create()) + return 1; + + ... + window->setVulkanInstance(&inst); + window->show(); + + return app.exec(); + } +//! [0] + +//! [1] + QVulkanInstance inst; + + // Enable validation layer, if supported. Messages go to qDebug by default. + inst.setLayers(QByteArrayList() << "VK_LAYER_LUNARG_standard_validation"); + + bool ok = inst.create(); + if (!ok) + ... // Vulkan not available + if (!inst.layers().contains("VK_LAYER_LUNARG_standard_validation")) + ... // validation layer not available +//! [1] + +//! [2] + QVulkanInstance inst; + + if (inst.supportedLayers().contains("VK_LAYER_LUNARG_standard_validation")) + ... + + bool ok = inst.create(); + ... +//! [2] + +//! [3] + class VulkanWindow : public QWindow + { + public: + VulkanWindow() { + setSurfaceType(VulkanSurface); + } + + void exposeEvent(QExposeEvent *) { + if (isExposed()) { + if (!m_initialized) { + m_initialized = true; + // initialize device, swapchain, etc. + QVulkanInstance *inst = vulkanInstance(); + QVulkanFunctions *f = inst->functions(); + uint32_t devCount = 0; + f->vkEnumeratePhysicalDevices(inst->vkInstance(), &devCount, nullptr); + ... + // build the first frame + render(); + } + } + } + + bool event(QEvent *e) { + if (e->type == QEvent::UpdateRequest) + render(); + return QWindow::event(e); + } + + void render() { + ... + requestUpdate(); // render continuously + } + + private: + bool m_initialized = false; + }; + + int main(int argc, char **argv) + { + QGuiApplication app(argc, argv); + + QVulkanInstance inst; + if (!inst.create()) { + qWarning("Vulkan not available"); + return 1; + } + + VulkanWindow window; + window.showMaximized(); + + return app.exec(); + + } +//! [3] diff --git a/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanwindow.cpp b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanwindow.cpp new file mode 100644 index 0000000000..65eca4a77f --- /dev/null +++ b/src/gui/doc/snippets/code/src_gui_vulkan_qvulkanwindow.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] + class VulkanRenderer : public QVulkanWindowRenderer + { + public: + VulkanRenderer(QVulkanWindow *w) : m_window(w) { } + + void initResources() override + { + m_devFuncs = m_window->vulkanInstance()->deviceFunctions(m_window->device()); + ... + } + void initSwapChainResources() override { ... } + void releaseSwapChainResources() override { ... } + void releaseResources() override { ... } + + void startNextFrame() override + { + VkCommandBuffer cmdBuf = m_window->currentCommandBuffer(); + ... + m_devFuncs->vkCmdBeginRenderPass(...); + ... + m_window->frameReady(); + } + + private: + QVulkanWindow *m_window; + QVulkanDeviceFunctions *m_devFuncs; + }; + + class VulkanWindow : public QVulkanWindow + { + public: + QVulkanWindowRenderer *createRenderer() override { + return new VulkanRenderer(this); + } + }; + + int main(int argc, char *argv[]) + { + QGuiApplication app(argc, argv); + + QVulkanInstance inst; + // enable the standard validation layers, when available + inst.setLayers(QByteArrayList() << "VK_LAYER_LUNARG_standard_validation"); + if (!inst.create()) + qFatal("Failed to create Vulkan instance: %d", inst.errorCode()); + + VulkanWindow w; + w.setVulkanInstance(&inst); + w.showMaximized(); + + return app.exec(); + } +//! [0] + +//! [1] + class Renderer { + ... + VkDescriptorBufferInfo m_uniformBufInfo[QVulkanWindow::MAX_CONCURRENT_FRAME_COUNT]; + }; + + void Renderer::startNextFrame() + { + VkDescriptorBufferInfo &uniformBufInfo(m_uniformBufInfo[m_window->currentFrame()]); + ... + } +//! [1] + +//! [2] + class Renderer { + ... + VkDescriptorBufferInfo m_uniformBufInfo[QVulkanWindow::MAX_CONCURRENT_FRAME_COUNT]; + }; + + void Renderer::startNextFrame() + { + const int count = m_window->concurrentFrameCount(); + for (int i = 0; i < count; ++i) + m_uniformBufInfo[i] = ... + ... + } +//! [2] diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 759d6f3cbf..06c9cd3939 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -45,7 +45,7 @@ include(painting/painting.pri) include(util/util.pri) include(math3d/math3d.pri) include(opengl/opengl.pri) -include(animation/animation.pri) +qtConfig(animation): include(animation/animation.pri) include(itemmodels/itemmodels.pri) include(vulkan/vulkan.pri) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 5907d69f87..285cdf790a 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -47,8 +47,10 @@ #include "private/qiconloader_p.h" #include "qpainter.h" #include "qfileinfo.h" +#if QT_CONFIG(mimetype) #include <qmimedatabase.h> #include <qmimetype.h> +#endif #include "qpixmapcache.h" #include "qvariant.h" #include "qcache.h" @@ -1079,10 +1081,10 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State QFileInfo info(fileName); QString suffix = info.suffix(); -#ifndef QT_NO_MIMETYPE +#if QT_CONFIG(mimetype) if (suffix.isEmpty()) suffix = QMimeDatabase().mimeTypeForFile(info).preferredSuffix(); // determination from contents -#endif // !QT_NO_MIMETYPE +#endif // mimetype QIconEngine *engine = iconEngineFromSuffix(fileName, suffix); d = new QIconPrivate(engine ? engine : new QPixmapIconEngine); } diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 636cacfb9c..421362dd9e 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -3750,7 +3750,9 @@ QDataStream &operator>>(QDataStream &s, QImage &image) return s; } } - image = QImageReader(s.device(), 0).read(); + image = QImageReader(s.device(), s.version() == 1 ? "bmp" : "png").read(); + if (image.isNull() && s.version() >= 5) + s.setStatus(QDataStream::ReadPastEnd); return s; } #endif // QT_NO_DATASTREAM diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 6d358984d6..0fb1d808e5 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -165,6 +165,7 @@ #endif #include <private/qimagereaderwriterhelpers_p.h> +#include <qtgui_tracepoints_p.h> #include <algorithm> @@ -1250,7 +1251,18 @@ bool QImageReader::read(QImage *image) d->handler->setOption(QImageIOHandler::Quality, d->quality); // read the image - if (!d->handler->read(image)) { + if (Q_TRACE_ENABLED(QImageReader_read_before_reading)) { + QString fileName = QStringLiteral("unknown"); + if (QFile *file = qobject_cast<QFile *>(d->device)) + fileName = file->fileName(); + Q_TRACE(QImageReader_read_before_reading, this, fileName); + } + + const bool result = d->handler->read(image); + + Q_TRACE(QImageReader_read_after_reading, this, result); + + if (!result) { d->imageReaderError = InvalidDataError; d->errorString = QImageReader::tr("Unable to read image data"); return false; diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp index 010760de4c..7d17b7d5ef 100644 --- a/src/gui/image/qmovie.cpp +++ b/src/gui/image/qmovie.cpp @@ -379,7 +379,7 @@ QFrameInfo QMoviePrivate::infoForFrame(int frameNumber) } if (frameNumber > greatestFrameNumber) greatestFrameNumber = frameNumber; - QPixmap aPixmap = QPixmap::fromImage(anImage); + QPixmap aPixmap = QPixmap::fromImage(std::move(anImage)); int aDelay = reader->nextImageDelay(); return QFrameInfo(aPixmap, aDelay); } else if (frameNumber != 0) { @@ -405,7 +405,7 @@ QFrameInfo QMoviePrivate::infoForFrame(int frameNumber) return QFrameInfo(); // Invalid } greatestFrameNumber = i; - QPixmap aPixmap = QPixmap::fromImage(anImage); + QPixmap aPixmap = QPixmap::fromImage(std::move(anImage)); int aDelay = reader->nextImageDelay(); QFrameInfo info(aPixmap, aDelay); // Cache it! diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index 7aa221948e..7eede5ee26 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -636,7 +636,7 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) if (d->formatMajor <= 5) { s >> ia >> i_8; painter->drawPolygon(ia, i_8 ? Qt::WindingFill : Qt::OddEvenFill); - a.clear(); + ia.clear(); } else { s >> a >> i_8; painter->drawPolygon(a, i_8 ? Qt::WindingFill : Qt::OddEvenFill); @@ -647,10 +647,10 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) s >> ia; QPainterPath path; Q_ASSERT(ia.size() == 4); - path.moveTo(ia.at(0)); - path.cubicTo(ia.at(1), ia.at(2), ia.at(3)); + path.moveTo(ia.value(0)); + path.cubicTo(ia.value(1), ia.value(2), ia.value(3)); painter->strokePath(path, painter->pen()); - a.clear(); + ia.clear(); } break; case QPicturePrivate::PdcDrawText: @@ -730,7 +730,7 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) int index; s >> r >> index >> sr; Q_ASSERT(index < d->pixmap_list.size()); - pixmap = d->pixmap_list.at(index); + pixmap = d->pixmap_list.value(index); } else { s >> r >> pixmap >> sr; } @@ -744,7 +744,7 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) int index; s >> r >> index >> p; Q_ASSERT(index < d->pixmap_list.size()); - pixmap = d->pixmap_list.at(index); + pixmap = d->pixmap_list.value(index); } else { s >> r >> pixmap >> p; } @@ -765,7 +765,7 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) int index; s >> r >> index >> sr >> ul; Q_ASSERT(index < d->image_list.size()); - image = d->image_list.at(index); + image = d->image_list.value(index); } else { s >> r >> image >> sr >> ul; } @@ -817,7 +817,7 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) int index; s >> index; Q_ASSERT(index < d->pen_list.size()); - pen = d->pen_list.at(index); + pen = d->pen_list.value(index); } else { s >> pen; } @@ -828,7 +828,7 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) int index; s >> index; Q_ASSERT(index < d->brush_list.size()); - brush = d->brush_list.at(index); + brush = d->brush_list.value(index); } else { s >> brush; } @@ -910,7 +910,7 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) break; default: qWarning("QPicture::play: Invalid command %d", c); - if (len) // skip unknown command + if (len > 0) // skip unknown command s.device()->seek(s.device()->pos()+len); } #if defined(QT_DEBUG) @@ -1075,7 +1075,8 @@ bool QPicturePrivate::checkFormat() char mf_id[4]; // picture header tag s.readRawData(mf_id, 4); // read actual tag - if (memcmp(mf_id, qt_mfhdr_tag, 4) != 0) { // wrong header id + int bufSize = pictb.buffer().size(); + if (memcmp(mf_id, qt_mfhdr_tag, 4) != 0 || bufSize < 12) { // wrong header id or size qWarning("QPicturePaintEngine::checkFormat: Incorrect header"); pictb.close(); return false; diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index 242d8cd63b..13129e214b 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -99,12 +99,13 @@ public: }; QPngHandlerPrivate(QPngHandler *qq) - : gamma(0.0), fileGamma(0.0), quality(2), png_ptr(0), info_ptr(0), end_info(0), state(Ready), q(qq) + : gamma(0.0), fileGamma(0.0), quality(50), compression(50), png_ptr(0), info_ptr(0), end_info(0), state(Ready), q(qq) { } float gamma; float fileGamma; - int quality; + int quality; // quality is used for backward compatibility, maps to compression + int compression; QString description; QSize scaledSize; QStringList readTexts; @@ -161,11 +162,11 @@ public: void setGamma(float); bool writeImage(const QImage& img, int x, int y); - bool writeImage(const QImage& img, volatile int quality, const QString &description, int x, int y); + bool writeImage(const QImage& img, volatile int compression_in, const QString &description, int x, int y); bool writeImage(const QImage& img) { return writeImage(img, 0, 0); } - bool writeImage(const QImage& img, int quality, const QString &description) - { return writeImage(img, quality, description, 0, 0); } + bool writeImage(const QImage& img, int compression, const QString &description) + { return writeImage(img, compression, description, 0, 0); } QIODevice* device() { return dev; } @@ -814,7 +815,7 @@ bool QPNGImageWriter::writeImage(const QImage& image, int off_x, int off_y) return writeImage(image, -1, QString(), off_x, off_y); } -bool QPNGImageWriter::writeImage(const QImage& image, volatile int quality_in, const QString &description, +bool QPNGImageWriter::writeImage(const QImage& image, volatile int compression_in, const QString &description, int off_x_in, int off_y_in) { QPoint offset = image.offset(); @@ -842,13 +843,13 @@ bool QPNGImageWriter::writeImage(const QImage& image, volatile int quality_in, c return false; } - int quality = quality_in; - if (quality >= 0) { - if (quality > 9) { - qWarning("PNG: Quality %d out of range", quality); - quality = 9; + int compression = compression_in; + if (compression >= 0) { + if (compression > 9) { + qWarning("PNG: Compression %d out of range", compression); + compression = 9; } - png_set_compression_level(png_ptr, quality); + png_set_compression_level(png_ptr, compression); } png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn); @@ -1067,15 +1068,21 @@ bool QPNGImageWriter::writeImage(const QImage& image, volatile int quality_in, c } static bool write_png_image(const QImage &image, QIODevice *device, - int quality, float gamma, const QString &description) + int compression, int quality, float gamma, const QString &description) { + // quality is used for backward compatibility, maps to compression + QPNGImageWriter writer(device); - if (quality >= 0) { - quality = qMin(quality, 100); - quality = (100-quality) * 9 / 91; // map [0,100] -> [9,0] - } + if (compression >= 0) + compression = qMin(compression, 100); + else if (quality >= 0) + compression = 100 - qMin(quality, 100); + + if (compression >= 0) + compression = (compression * 9) / 91; // map [0,100] -> [0,9] + writer.setGamma(gamma); - return writer.writeImage(image, quality, description); + return writer.writeImage(image, compression, description); } QPngHandler::QPngHandler() @@ -1122,7 +1129,7 @@ bool QPngHandler::read(QImage *image) bool QPngHandler::write(const QImage &image) { - return write_png_image(image, device(), d->quality, d->gamma, d->description); + return write_png_image(image, device(), d->compression, d->quality, d->gamma, d->description); } bool QPngHandler::supportsOption(ImageOption option) const @@ -1131,6 +1138,7 @@ bool QPngHandler::supportsOption(ImageOption option) const || option == Description || option == ImageFormat || option == Quality + || option == CompressionRatio || option == Size || option == ScaledSize; } @@ -1146,6 +1154,8 @@ QVariant QPngHandler::option(ImageOption option) const return d->gamma == 0.0 ? d->fileGamma : d->gamma; else if (option == Quality) return d->quality; + else if (option == CompressionRatio) + return d->compression; else if (option == Description) return d->description; else if (option == Size) @@ -1164,6 +1174,8 @@ void QPngHandler::setOption(ImageOption option, const QVariant &value) d->gamma = value.toFloat(); else if (option == Quality) d->quality = value.toInt(); + else if (option == CompressionRatio) + d->compression = value.toInt(); else if (option == Description) d->description = value.toString(); else if (option == ScaledSize) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 34f453341f..e5657000cf 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -211,7 +211,7 @@ QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = 0; static qreal fontSmoothingGamma = 1.7; extern void qRegisterGuiVariant(); -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) extern void qRegisterGuiGetInterpolator(); #endif @@ -1528,7 +1528,7 @@ void QGuiApplicationPrivate::init() // trigger registering of QVariant's GUI types qRegisterGuiVariant(); -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) // trigger registering of animation interpolators qRegisterGuiGetInterpolator(); #endif diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 17a18f3c9a..944e7d6139 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -546,6 +546,9 @@ void QWindowPrivate::create(bool recursive, WId nativeHandle) QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated); QGuiApplication::sendEvent(q, &e); + + if (updateRequestPending) + platformWindow->requestUpdate(); } void QWindowPrivate::clearFocusObject() diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 07ece5689e..67e1283462 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -57,6 +57,7 @@ QT_BEGIN_NAMESPACE QElapsedTimer QWindowSystemInterfacePrivate::eventTime; bool QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = false; +bool QWindowSystemInterfacePrivate::platformFiltersEvents = false; bool QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse = true; QWaitCondition QWindowSystemInterfacePrivate::eventsFlushed; QMutex QWindowSystemInterfacePrivate::flushEventMutex; @@ -1047,10 +1048,15 @@ bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFla int nevents = 0; while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) { - QWindowSystemInterfacePrivate::WindowSystemEvent *event = - (flags & QEventLoop::ExcludeUserInputEvents) ? - QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() : - QWindowSystemInterfacePrivate::getWindowSystemEvent(); + QWindowSystemInterfacePrivate::WindowSystemEvent *event = nullptr; + + if (QWindowSystemInterfacePrivate::platformFiltersEvents) { + event = QWindowSystemInterfacePrivate::getWindowSystemEvent(); + } else { + event = flags & QEventLoop::ExcludeUserInputEvents ? + QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() : + QWindowSystemInterfacePrivate::getWindowSystemEvent(); + } if (!event) break; @@ -1089,6 +1095,21 @@ bool QWindowSystemInterface::nonUserInputEventsQueued() return QWindowSystemInterfacePrivate::nonUserInputEventsQueued(); } +/*! + Platforms that implement UserInputEvent filtering at native event level must + set this property to \c true. The default is \c false, which means that event + filtering logic is handled by QWindowSystemInterface. Doing the filtering in + platform plugins is necessary when supporting AbstractEventDispatcher::filterNativeEvent(), + which should respect flags that were passed to event dispatcher's processEvents() + call. + + \since 5.12 +*/ +void QWindowSystemInterface::setPlatformFiltersEvents(bool enable) +{ + QWindowSystemInterfacePrivate::platformFiltersEvents = enable; +} + // --------------------- QtTestLib support --------------------- // The following functions are used by testlib, and need to be synchronous to avoid diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index 6bf6ee645c..1dde9130ac 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -292,6 +292,7 @@ public: static void deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags); static int windowSystemEventsQueued(); static bool nonUserInputEventsQueued(); + static void setPlatformFiltersEvents(bool enable); }; #ifndef QT_NO_DEBUG_STREAM diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index 492f559f22..9cb4e191cc 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -525,6 +525,7 @@ public: public: static QElapsedTimer eventTime; static bool synchronousWindowSystemEvents; + static bool platformFiltersEvents; static QWaitCondition eventsFlushed; static QMutex flushEventMutex; diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp index fe1b0425a8..899ec12eb3 100644 --- a/src/gui/math3d/qquaternion.cpp +++ b/src/gui/math3d/qquaternion.cpp @@ -325,15 +325,11 @@ void QQuaternion::normalize() Rotates \a vector with this quaternion to produce a new vector in 3D space. The following code: - \code - QVector3D result = q.rotatedVector(vector); - \endcode + \snippet code/src_gui_math3d_qquaternion.cpp 0 is equivalent to the following: - \code - QVector3D result = (q * QQuaternion(0, vector) * q.conjugated()).vector(); - \endcode + \snippet code/src_gui_math3d_qquaternion.cpp 1 */ QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const { diff --git a/src/gui/opengl/qopenglbuffer.cpp b/src/gui/opengl/qopenglbuffer.cpp index 000494244d..537097c09f 100644 --- a/src/gui/opengl/qopenglbuffer.cpp +++ b/src/gui/opengl/qopenglbuffer.cpp @@ -63,12 +63,7 @@ QT_BEGIN_NAMESPACE QOpenGLBuffer objects can be copied around as a reference to the underlying OpenGL buffer object: - \code - QOpenGLBuffer buffer1(QOpenGLBuffer::IndexBuffer); - buffer1.create(); - - QOpenGLBuffer buffer2 = buffer1; - \endcode + \snippet code/src_gui_opengl_qopenglbuffer.cpp 0 QOpenGLBuffer performs a shallow copy when objects are copied in this manner, but does not implement copy-on-write semantics. The original @@ -484,9 +479,7 @@ void QOpenGLBuffer::release() been bound to the context but wants to make sure that it is released. - \code - QOpenGLBuffer::release(QOpenGLBuffer::VertexBuffer); - \endcode + \snippet code/src_gui_opengl_qopenglbuffer.cpp 1 */ void QOpenGLBuffer::release(QOpenGLBuffer::Type type) { diff --git a/src/gui/opengl/qopengldebug.cpp b/src/gui/opengl/qopengldebug.cpp index 7072db5af4..2e628a2bd5 100644 --- a/src/gui/opengl/qopengldebug.cpp +++ b/src/gui/opengl/qopengldebug.cpp @@ -89,16 +89,7 @@ QT_BEGIN_NAMESPACE call. Moreover, OpenGL errors stack up, therefore glGetError should always be used in a loop like this: - \code - - GLenum error = GL_NO_ERROR; - do { - error = glGetError(); - if (error != GL_NO_ERROR) - // handle the error - } while (error != GL_NO_ERROR); - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 0 If you try to clear the error stack, make sure not just keep going until GL_NO_ERROR is returned but also break on GL_CONTEXT_LOST as that error @@ -125,20 +116,7 @@ QT_BEGIN_NAMESPACE to create a debug context from Qt, you must set the QSurfaceFormat::DebugContext format option on the QSurfaceFormat used to create the QOpenGLContext object: - \code - - QSurfaceFormat format; - // asks for a OpenGL 3.2 debug context using the Core profile - format.setMajorVersion(3); - format.setMinorVersion(2); - format.setProfile(QSurfaceFormat::CoreProfile); - format.setOption(QSurfaceFormat::DebugContext); - - QOpenGLContext *context = new QOpenGLContext; - context->setFormat(format); - context->create(); - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 1 Note that requesting a 3.2 OpenGL Core Profile is just for the example's purposes; this class is not tied to any specific OpenGL or OpenGL ES @@ -152,24 +130,13 @@ QT_BEGIN_NAMESPACE object), and like the other OpenGL functions in Qt you \e{must} initialize it before usage by calling initialize() whilst there is a current OpenGL context: - \code - - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this); - - logger->initialize(); // initializes in the current context, i.e. ctx - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 2 Note that the \c{GL_KHR_debug} extension \e{must} be available in the context in order to access the messages logged by OpenGL. You can check the presence of this extension by calling: - \code - - ctx->hasExtension(QByteArrayLiteral("GL_KHR_debug")) - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 3 where \c{ctx} is a valid QOpenGLContext. If the extension is not available, initialize() will return false. @@ -179,13 +146,7 @@ QT_BEGIN_NAMESPACE OpenGL implementations keep an internal log of debug messages. Messages stored in this log can be retrieved by using the loggedMessages() function: - \code - - const QList<QOpenGLDebugMessage> messages = logger->loggedMessages(); - for (const QOpenGLDebugMessage &message : messages) - qDebug() << message; - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 4 The internal log has a limited size; when it fills up, older messages will get discarded to make room for the new incoming messages. When you call @@ -203,12 +164,7 @@ QT_BEGIN_NAMESPACE you need to connect a suitable slot to the messageLogged() signal, and start logging by calling startLogging(): - \code - - connect(logger, &QOpenGLDebugLogger::messageLogged, receiver, &LogHandler::handleLoggedMessage); - logger->startLogging(); - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 5 Similarly, logging can be disabled at any time by calling the stopLogging() function. @@ -259,14 +215,7 @@ QT_BEGIN_NAMESPACE \l{QOpenGLDebugMessage::}{createThirdPartyMessage()}, and then inserting it into the log by calling logMessage(): - \code - - QOpenGLDebugMessage message = - QOpenGLDebugMessage::createApplicationMessage(QStringLiteral("Custom message")); - - logger->logMessage(message); - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 6 Note that OpenGL implementations have a vendor-specific limit to the length of the messages that can be inserted in the debug log. You can retrieve diff --git a/src/gui/opengl/qopenglengineshadermanager.cpp b/src/gui/opengl/qopenglengineshadermanager.cpp index b7bac2728a..1e5a10c99c 100644 --- a/src/gui/opengl/qopenglengineshadermanager.cpp +++ b/src/gui/opengl/qopenglengineshadermanager.cpp @@ -256,9 +256,13 @@ QOpenGLEngineSharedShaders::QOpenGLEngineSharedShaders(QOpenGLContext* context) QByteArray fragSource; // Compile up the simple shader: +#ifdef Q_OS_WASM + vertexSource.append(qShaderSnippets[PositionOnlyVertexShader]); + vertexSource.append(qShaderSnippets[MainVertexShader]); +#else vertexSource.append(qShaderSnippets[MainVertexShader]); vertexSource.append(qShaderSnippets[PositionOnlyVertexShader]); - +#endif fragSource.append(qShaderSnippets[MainFragmentShader]); fragSource.append(qShaderSnippets[ShockingPinkSrcFragmentShader]); @@ -384,9 +388,13 @@ QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QO fragSource.append(qShaderSnippets[prog.maskFragShader]); QByteArray vertexSource; +#ifdef Q_OS_WASM + vertexSource.append(qShaderSnippets[prog.positionVertexShader]); + vertexSource.append(qShaderSnippets[prog.mainVertexShader]); +#else vertexSource.append(qShaderSnippets[prog.mainVertexShader]); vertexSource.append(qShaderSnippets[prog.positionVertexShader]); - +#endif QScopedPointer<QOpenGLShaderProgram> shaderProgram(new QOpenGLShaderProgram); CachedShader shaderCache(fragSource, vertexSource); diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp index 4f48604a88..b4ff21f3fd 100644 --- a/src/gui/opengl/qopenglfunctions.cpp +++ b/src/gui/opengl/qopenglfunctions.cpp @@ -90,65 +90,18 @@ void CLASS::init(QOpenGLContext *context) \ that need it. The recommended way to use QOpenGLFunctions is by direct inheritance: - \code - class MyGLWindow : public QWindow, protected QOpenGLFunctions - { - Q_OBJECT - public: - MyGLWindow(QScreen *screen = 0); - - protected: - void initializeGL(); - void paintGL(); - - QOpenGLContext *m_context; - }; - - MyGLWindow(QScreen *screen) - : QWindow(screen), QOpenGLWidget(parent) - { - setSurfaceType(OpenGLSurface); - create(); - - // Create an OpenGL context - m_context = new QOpenGLContext; - m_context->create(); - - // Setup scene and render it - initializeGL(); - paintGL(); - } - - void MyGLWindow::initializeGL() - { - m_context->makeCurrent(this); - initializeOpenGLFunctions(); - } - \endcode + \snippet code/src_gui_opengl_qopenglfunctions.cpp 0 The \c{paintGL()} function can then use any of the OpenGL ES 2.0 functions without explicit resolution, such as glActiveTexture() in the following example: - \code - void MyGLWindow::paintGL() - { - m_context->makeCurrent(this); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, textureId); - ... - m_context->swapBuffers(this); - m_context->doneCurrent(); - } - \endcode + \snippet code/src_gui_opengl_qopenglfunctions.cpp 1 QOpenGLFunctions can also be used directly for ad-hoc invocation of OpenGL ES 2.0 functions on all platforms: - \code - QOpenGLFunctions glFuncs(QOpenGLContext::currentContext()); - glFuncs.glActiveTexture(GL_TEXTURE1); - \endcode + \snippet code/src_gui_opengl_qopenglfunctions.cpp 2 An alternative approach is to query the context's associated QOpenGLFunctions instance. This is somewhat faster than the previous @@ -157,10 +110,7 @@ void CLASS::init(QOpenGLContext *context) \ resolving happens only once for a given context, regardless of the number of QOpenGLFunctions instances initialized for it. - \code - QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); - glFuncs->glActiveTexture(GL_TEXTURE1); - \endcode + \snippet code/src_gui_opengl_qopenglfunctions.cpp 3 QOpenGLFunctions provides wrappers for all OpenGL ES 2.0 functions, including the common subset of OpenGL 1.x and ES @@ -175,10 +125,7 @@ void CLASS::init(QOpenGLContext *context) \ feature. For example, the following checks if non power of two textures are available: - \code - QOpenGLFunctions funcs(QOpenGLContext::currentContext()); - bool npot = funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures); - \endcode + \snippet code/src_gui_opengl_qopenglfunctions.cpp 4 \sa QOpenGLContext, QSurfaceFormat */ diff --git a/src/gui/opengl/qopenglprogrambinarycache.cpp b/src/gui/opengl/qopenglprogrambinarycache.cpp index 0f03101329..c96021a969 100644 --- a/src/gui/opengl/qopenglprogrambinarycache.cpp +++ b/src/gui/opengl/qopenglprogrambinarycache.cpp @@ -63,7 +63,7 @@ Q_DECLARE_LOGGING_CATEGORY(DBG_SHADER_CACHE) #endif const quint32 BINSHADER_MAGIC = 0x5174; -const quint32 BINSHADER_VERSION = 0x2; +const quint32 BINSHADER_VERSION = 0x3; const quint32 BINSHADER_QTVERSION = QT_VERSION; namespace { @@ -120,7 +120,7 @@ QString QOpenGLProgramBinaryCache::cacheFileName(const QByteArray &cacheKey) con return m_cacheDir + QString::fromUtf8(cacheKey); } -#define BASE_HEADER_SIZE (int(3 * sizeof(quint32))) +#define BASE_HEADER_SIZE (int(4 * sizeof(quint32))) #define FULL_HEADER_SIZE(stringsSize) (BASE_HEADER_SIZE + 12 + stringsSize + 8) #define PADDING_SIZE(fullHeaderSize) (((fullHeaderSize + 3) & ~3) - fullHeaderSize) @@ -159,6 +159,10 @@ bool QOpenGLProgramBinaryCache::verifyHeader(const QByteArray &buf) const qCDebug(DBG_SHADER_CACHE, "Qt version does not match"); return false; } + if (readUInt(&p) != sizeof(quintptr)) { + qCDebug(DBG_SHADER_CACHE, "Architecture does not match"); + return false; + } return true; } @@ -371,6 +375,7 @@ void QOpenGLProgramBinaryCache::save(const QByteArray &cacheKey, uint programId) writeUInt(&p, BINSHADER_MAGIC); writeUInt(&p, BINSHADER_VERSION); writeUInt(&p, BINSHADER_QTVERSION); + writeUInt(&p, sizeof(quintptr)); writeStr(&p, info.glvendor); writeStr(&p, info.glrenderer); diff --git a/src/gui/opengl/qopengltextureglyphcache.cpp b/src/gui/opengl/qopengltextureglyphcache.cpp index 556d52ef99..e3cbba955d 100644 --- a/src/gui/opengl/qopengltextureglyphcache.cpp +++ b/src/gui/opengl/qopengltextureglyphcache.cpp @@ -344,15 +344,25 @@ void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height) { QString source; +#ifdef Q_OS_WASM + source.append(QLatin1String(isCoreProfile ? qopenglslUntransformedPositionVertexShader_core : qopenglslUntransformedPositionVertexShader)); + source.append(QLatin1String(isCoreProfile ? qopenglslMainWithTexCoordsVertexShader_core : qopenglslMainWithTexCoordsVertexShader)); +#else source.append(QLatin1String(isCoreProfile ? qopenglslMainWithTexCoordsVertexShader_core : qopenglslMainWithTexCoordsVertexShader)); source.append(QLatin1String(isCoreProfile ? qopenglslUntransformedPositionVertexShader_core : qopenglslUntransformedPositionVertexShader)); +#endif m_blitProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, source); } { QString source; +#ifdef Q_OS_WASM + source.append(QLatin1String(isCoreProfile ? qopenglslImageSrcFragmentShader_core : qopenglslImageSrcFragmentShader)); + source.append(QLatin1String(isCoreProfile ? qopenglslMainFragmentShader_core : qopenglslMainFragmentShader)); +#else source.append(QLatin1String(isCoreProfile ? qopenglslMainFragmentShader_core : qopenglslMainFragmentShader)); source.append(QLatin1String(isCoreProfile ? qopenglslImageSrcFragmentShader_core : qopenglslImageSrcFragmentShader)); +#endif m_blitProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, source); } diff --git a/src/gui/painting/qimagescale.cpp b/src/gui/painting/qimagescale.cpp index 96da5e029c..8a5274bd37 100644 --- a/src/gui/painting/qimagescale.cpp +++ b/src/gui/painting/qimagescale.cpp @@ -239,7 +239,6 @@ static QImageScaleInfo* QImageScale::qimageCalcScaleInfo(const QImage &img, isi = new QImageScaleInfo; if (!isi) return 0; - memset(isi, 0, sizeof(QImageScaleInfo)); isi->xup_yup = (qAbs(dw) >= sw) + ((qAbs(dh) >= sh) << 1); diff --git a/src/gui/painting/qimagescale_p.h b/src/gui/painting/qimagescale_p.h index 415623a575..244d681718 100644 --- a/src/gui/painting/qimagescale_p.h +++ b/src/gui/painting/qimagescale_p.h @@ -61,10 +61,11 @@ QImage qSmoothScaleImage(const QImage &img, int w, int h); namespace QImageScale { struct QImageScaleInfo { - int *xpoints; - const unsigned int **ypoints; - int *xapoints, *yapoints; - int xup_yup; + int *xpoints{nullptr}; + const unsigned int **ypoints{nullptr}; + int *xapoints{nullptr}; + int *yapoints{nullptr}; + int xup_yup{0}; }; } diff --git a/src/gui/painting/qpagedpaintdevice.cpp b/src/gui/painting/qpagedpaintdevice.cpp index 613a686848..72b2834470 100644 --- a/src/gui/painting/qpagedpaintdevice.cpp +++ b/src/gui/painting/qpagedpaintdevice.cpp @@ -290,7 +290,8 @@ QPagedPaintDevicePrivate *QPagedPaintDevice::dd() \value PdfVersion_A1b A PDF/A-1b compatible document is produced. - \since 5.10 + \value PdfVersion_1_6 A PDF 1.6 compatible document is produced. + This value was added in Qt 5.12. */ /*! diff --git a/src/gui/painting/qpagedpaintdevice.h b/src/gui/painting/qpagedpaintdevice.h index c8957edab8..1c37c17fa3 100644 --- a/src/gui/painting/qpagedpaintdevice.h +++ b/src/gui/painting/qpagedpaintdevice.h @@ -213,7 +213,7 @@ public: Envelope10 = Comm10E }; - enum PdfVersion { PdfVersion_1_4, PdfVersion_A1b }; + enum PdfVersion { PdfVersion_1_4, PdfVersion_A1b, PdfVersion_1_6 }; // ### Qt6 Make these virtual bool setPageLayout(const QPageLayout &pageLayout); diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index 2574a00838..c5ccf0003d 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -2476,7 +2476,7 @@ QDataStream &operator>>(QDataStream &s, QPainterPath &p) s >> p.d_func()->cStart; int fillRule; s >> fillRule; - Q_ASSERT(fillRule == Qt::OddEvenFill || Qt::WindingFill); + Q_ASSERT(fillRule == Qt::OddEvenFill || fillRule == Qt::WindingFill); p.d_func()->fillRule = Qt::FillRule(fillRule); p.d_func()->dirtyBounds = true; p.d_func()->dirtyControlBounds = true; diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 4fd0d3c8fe..b410e9b900 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -71,6 +71,11 @@ static const bool do_compress = true; // Can't use it though, as gs generates completely wrong images if this is true. static const bool interpolateImages = false; +static void initResources() +{ + Q_INIT_RESOURCE(qpdf); +} + QT_BEGIN_NAMESPACE inline QPaintEngine::PaintEngineFeatures qt_pdf_decide_features() @@ -1446,6 +1451,7 @@ QPdfEnginePrivate::QPdfEnginePrivate() grayscale(false), m_pageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(10, 10, 10, 10)) { + initResources(); resolution = 1200; currentObject = 1; currentPage = 0; @@ -1541,7 +1547,14 @@ void QPdfEnginePrivate::writeHeader() { addXrefEntry(0,false); - xprintf("%%PDF-1.4\n"); + static const QHash<QPdfEngine::PdfVersion, const char *> mapping { + {QPdfEngine::Version_1_4, "1.4"}, + {QPdfEngine::Version_A1b, "1.4"}, + {QPdfEngine::Version_1_6, "1.6"} + }; + const char *verStr = mapping.value(pdfVersion, "1.4"); + + xprintf("%%PDF-%s\n", verStr); xprintf("%%\303\242\303\243\n"); writeInfo(); @@ -1874,6 +1887,19 @@ void QPdfEnginePrivate::embedFont(QFontSubset *font) } } +qreal QPdfEnginePrivate::calcUserUnit() const +{ + // PDF standards < 1.6 support max 200x200in pages (no UserUnit) + if (pdfVersion < QPdfEngine::Version_1_6) + return 1.0; + + const int maxLen = qMax(currentPage->pageSize.width(), currentPage->pageSize.height()); + if (maxLen <= 14400) + return 1.0; // for pages up to 200x200in (14400x14400 units) use default scaling + + // for larger pages, rescale units so we can have up to 381x381km + return qMin(maxLen / 14400.0, 75000.0); +} void QPdfEnginePrivate::writeFonts() { @@ -1896,6 +1922,8 @@ void QPdfEnginePrivate::writePage() uint resources = requestObject(); uint annots = requestObject(); + qreal userUnit = calcUserUnit(); + addXrefEntry(pages.constLast()); xprintf("<<\n" "/Type /Page\n" @@ -1903,12 +1931,16 @@ void QPdfEnginePrivate::writePage() "/Contents %d 0 R\n" "/Resources %d 0 R\n" "/Annots %d 0 R\n" - "/MediaBox [0 0 %d %d]\n" - ">>\n" - "endobj\n", + "/MediaBox [0 0 %f %f]\n", pageRoot, pageStream, resources, annots, // make sure we use the pagesize from when we started the page, since the user may have changed it - currentPage->pageSize.width(), currentPage->pageSize.height()); + currentPage->pageSize.width() / userUnit, currentPage->pageSize.height() / userUnit); + + if (pdfVersion >= QPdfEngine::Version_1_6) + xprintf("/UserUnit %f\n", userUnit); + + xprintf(">>\n" + "endobj\n"); addXrefEntry(resources); xprintf("<<\n" @@ -2977,8 +3009,9 @@ void QPdfEnginePrivate::drawTextItem(const QPointF &p, const QTextItemInt &ti) QTransform QPdfEnginePrivate::pageMatrix() const { - qreal scale = 72./resolution; - QTransform tmp(scale, 0.0, 0.0, -scale, 0.0, m_pageLayout.fullRectPoints().height()); + qreal userUnit = calcUserUnit(); + qreal scale = 72. / userUnit / resolution; + QTransform tmp(scale, 0.0, 0.0, -scale, 0.0, m_pageLayout.fullRectPoints().height() / userUnit); if (m_pageLayout.mode() != QPageLayout::FullPageMode) { QRect r = m_pageLayout.paintRectPixels(resolution); tmp.translate(r.left(), r.top()); diff --git a/src/gui/painting/qpdf_p.h b/src/gui/painting/qpdf_p.h index 5a909f2ede..e2526de67d 100644 --- a/src/gui/painting/qpdf_p.h +++ b/src/gui/painting/qpdf_p.h @@ -171,7 +171,8 @@ public: enum PdfVersion { Version_1_4, - Version_A1b + Version_A1b, + Version_1_6 }; QPdfEngine(); @@ -300,6 +301,7 @@ private: void writePageRoot(); void writeFonts(); void embedFont(QFontSubset *font); + qreal calcUserUnit() const; QVector<int> xrefPositions; QDataStream* stream; diff --git a/src/gui/painting/qpdfwriter.cpp b/src/gui/painting/qpdfwriter.cpp index 5f0fad2a4e..258939a763 100644 --- a/src/gui/painting/qpdfwriter.cpp +++ b/src/gui/painting/qpdfwriter.cpp @@ -170,11 +170,17 @@ void QPdfWriter::setPdfVersion(PdfVersion version) { Q_D(QPdfWriter); + static const QHash<QPdfWriter::PdfVersion, QPdfEngine::PdfVersion> engineMapping { + {QPdfWriter::PdfVersion_1_4, QPdfEngine::Version_1_4}, + {QPdfWriter::PdfVersion_A1b, QPdfEngine::Version_A1b}, + {QPdfWriter::PdfVersion_1_6, QPdfEngine::Version_1_6} + }; + if (d->pdfVersion == version) return; d->pdfVersion = version; - d->engine->setPdfVersion(d->pdfVersion == QPdfWriter::PdfVersion_1_4 ? QPdfEngine::Version_1_4 : QPdfEngine::Version_A1b); + d->engine->setPdfVersion(engineMapping.value(version, QPdfEngine::Version_1_4)); } /*! diff --git a/src/gui/painting/qtriangulator.cpp b/src/gui/painting/qtriangulator.cpp index 6d57eba123..9be3eeaffd 100644 --- a/src/gui/painting/qtriangulator.cpp +++ b/src/gui/painting/qtriangulator.cpp @@ -472,7 +472,7 @@ class QInt64Set { public: inline QInt64Set(int capacity = 64); - inline ~QInt64Set() {if (m_array) delete[] m_array;} + inline ~QInt64Set() {delete[] m_array;} inline bool isValid() const {return m_array;} void insert(quint64 key); bool contains(quint64 key) const; @@ -493,10 +493,7 @@ inline QInt64Set::QInt64Set(int capacity) { m_capacity = primeForCount(capacity); m_array = new quint64[m_capacity]; - if (m_array) - clear(); - else - m_capacity = 0; + clear(); } bool QInt64Set::rehash(int capacity) @@ -506,28 +503,19 @@ bool QInt64Set::rehash(int capacity) m_capacity = capacity; m_array = new quint64[m_capacity]; - if (m_array) { - clear(); - if (oldArray) { - for (int i = 0; i < oldCapacity; ++i) { - if (oldArray[i] != UNUSED) - insert(oldArray[i]); - } - delete[] oldArray; - } - return true; - } else { - m_capacity = oldCapacity; - m_array = oldArray; - return false; + clear(); + for (int i = 0; i < oldCapacity; ++i) { + if (oldArray[i] != UNUSED) + insert(oldArray[i]); } + delete[] oldArray; + return true; } void QInt64Set::insert(quint64 key) { if (m_count > 3 * m_capacity / 4) rehash(primeForCount(2 * m_capacity)); - Q_ASSERT_X(m_array, "QInt64Hash<T>::insert", "Hash set not allocated."); int index = int(key % m_capacity); for (int i = 0; i < m_capacity; ++i) { index += i; @@ -546,7 +534,6 @@ void QInt64Set::insert(quint64 key) bool QInt64Set::contains(quint64 key) const { - Q_ASSERT_X(m_array, "QInt64Hash<T>::contains", "Hash set not allocated."); int index = int(key % m_capacity); for (int i = 0; i < m_capacity; ++i) { index += i; @@ -562,7 +549,6 @@ bool QInt64Set::contains(quint64 key) const inline void QInt64Set::clear() { - Q_ASSERT_X(m_array, "QInt64Hash<T>::clear", "Hash set not allocated."); for (int i = 0; i < m_capacity; ++i) m_array[i] = UNUSED; m_count = 0; diff --git a/src/gui/qtgui.tracepoints b/src/gui/qtgui.tracepoints index 2c232a0af8..aed6c35c03 100644 --- a/src/gui/qtgui.tracepoints +++ b/src/gui/qtgui.tracepoints @@ -8,3 +8,6 @@ QFontDatabase_addApplicationFont(const QString &filename) QFontDatabase_load(const QString &family, int pointSize) QFontDatabase_loadEngine(const QString &family, int pointSize) QFontDatabasePrivate_addAppFont(const QString &fileName) + +QImageReader_read_before_reading(QImageReader *reader, const QString &filename) +QImageReader_read_after_reading(QImageReader *reader, bool result) diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index 1c454b0fca..8e317d5b97 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -2742,8 +2742,10 @@ bool Parser::parseFunction(QString *name, QString *args) { *name = lexem(); name->chop(1); + // until(RPAREN) needs FUNCTION token at index-1 to work properly + int start = index; skipSpace(); - const int start = index; + std::swap(start, index); if (!until(RPAREN)) return false; for (int i = start; i < index - 1; ++i) args->append(symbols.at(i).lexem()); diff --git a/src/gui/text/qfontdatabase.h b/src/gui/text/qfontdatabase.h index e6aef493bd..80b092f177 100644 --- a/src/gui/text/qfontdatabase.h +++ b/src/gui/text/qfontdatabase.h @@ -160,8 +160,8 @@ private: static void createDatabase(); static void parseFontName(const QString &name, QString &foundry, QString &family); static QString resolveFontFamilyAlias(const QString &family); - static QFontEngine *findFont(const QFontDef &request, int script); - static void load(const QFontPrivate *d, int script); + static QFontEngine *findFont(const QFontDef &request, int script /* QChar::Script */); + static void load(const QFontPrivate *d, int script /* QChar::Script */); friend struct QFontDef; friend class QFontPrivate; diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 64623c86df..9b0b0ec0d5 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -1849,7 +1849,7 @@ QFontEngine *QFontEngineMulti::loadEngine(int at) // info about the actual script of the characters may have been discarded, // so we do not check for writing system support, but instead just load // the family indiscriminately. - if (QFontEngine *engine = QFontDatabase::findFont(request, QFontDatabase::Any)) { + if (QFontEngine *engine = QFontDatabase::findFont(request, QChar::Script_Common)) { engine->fontDef.weight = request.weight; if (request.style > QFont::StyleNormal) engine->fontDef.style = request.style; diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp index de9d087c21..b6eac91478 100644 --- a/src/gui/util/qdesktopservices.cpp +++ b/src/gui/util/qdesktopservices.cpp @@ -187,12 +187,7 @@ void QOpenUrlHandlerRegistry::handlerDestroyed(QObject *handler) \l{https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl}{canOpenURL(_:)}. For example, the following lines enable URLs with the HTTPS scheme: - \code - <key>LSApplicationQueriesSchemes</key> - <array> - <string>https</string> - </array> - \endcode + \snippet code/src_gui_util_qdesktopservices.cpp 3 \sa setUrlHandler() */ @@ -252,17 +247,7 @@ bool QDesktopServices::openUrl(const QUrl &url) To use this function for receiving data from other apps on iOS you also need to add the custom scheme to the \c CFBundleURLSchemes list in your Info.plist file: - \code - <key>CFBundleURLTypes</key> - <array> - <dict> - <key>CFBundleURLSchemes</key> - <array> - <string>myapp</string> - </array> - </dict> - </array> - \endcode + \snippet code/src_gui_util_qdesktopservices.cpp 4 For more information, see the Apple Developer Documentation for \l{https://developer.apple.com/documentation/uikit/core_app/allowing_apps_and_websites_to_link_to_your_content/communicating_with_other_apps_using_custom_urls?language=objc}{Communicating with Other Apps Using Custom URLs}. @@ -346,14 +331,9 @@ void QDesktopServices::unsetUrlHandler(const QString &scheme) wasn't called, while in Qt 5 it defaults to the name of the executable. Therefore, if you still need to access the Qt 4 path (for example for data migration to Qt 5), replace - \code - QDesktopServices::storageLocation(QDesktopServices::DataLocation) - \endcode + \snippet code/src_gui_util_qdesktopservices.cpp 5 with - \code - QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + - "/data/organization/application" - \endcode + \snippet code/src_gui_util_qdesktopservices.cpp 6 (assuming an organization name and an application name were set). */ diff --git a/src/gui/vulkan/qvulkanfunctions.cpp b/src/gui/vulkan/qvulkanfunctions.cpp index c5f9616d20..73dbeb9ab6 100644 --- a/src/gui/vulkan/qvulkanfunctions.cpp +++ b/src/gui/vulkan/qvulkanfunctions.cpp @@ -66,16 +66,7 @@ QT_BEGIN_NAMESPACE The typical usage is the following: - \code - void Window::render() - { - QVulkanInstance *inst = vulkanInstance(); - QVulkanFunctions *f = inst->functions(); - ... - VkResult err = f->vkAllocateCommandBuffers(device, &cmdBufInfo, &cmdBuf); - ... - } - \endcode + \snippet code/src_gui_vulkan_qvulkanfunctions.cpp 0 \note Windowing system interface (WSI) specifics and extensions are excluded. This class only covers core Vulkan commands, with the exception @@ -118,15 +109,7 @@ QT_BEGIN_NAMESPACE The typical usage is the following: - \code - void Window::render() - { - QVulkanInstance *inst = vulkanInstance(); - QVulkanDeviceFunctions *df = inst->deviceFunctions(device); - VkResult err = df->vkAllocateCommandBuffers(device, &cmdBufInfo, &cmdBuf); - ... - } - \endcode + \snippet code/src_gui_vulkan_qvulkanfunctions.cpp 1 The QVulkanDeviceFunctions object specific to the provided VkDevice is created when QVulkanInstance::deviceFunctions() is first called with the diff --git a/src/gui/vulkan/qvulkaninstance.cpp b/src/gui/vulkan/qvulkaninstance.cpp index 8236d9625a..000c2b8caa 100644 --- a/src/gui/vulkan/qvulkaninstance.cpp +++ b/src/gui/vulkan/qvulkaninstance.cpp @@ -97,22 +97,7 @@ QT_BEGIN_NAMESPACE calling QWindow::setVulkanInstance(). Thus a typical application pattern is the following: - \code - int main(int argc, char **argv) - { - QGuiApplication app(argc, argv); - - QVulkanInstance inst; - if (!inst.create()) - return 1; - - ... - window->setVulkanInstance(&inst); - window->show(); - - return app.exec(); - } - \endcode + \snippet code/src_gui_vulkan_qvulkaninstance.cpp 0 \section1 Configuration @@ -138,31 +123,12 @@ QT_BEGIN_NAMESPACE For example, to enable the standard validation layers, one could do the following: - \code - QVulkanInstance inst; - - // Enable validation layer, if supported. Messages go to qDebug by default. - inst.setLayers(QByteArrayList() << "VK_LAYER_LUNARG_standard_validation"); - - bool ok = inst.create(); - if (!ok) - ... // Vulkan not available - if (!inst.layers().contains("VK_LAYER_LUNARG_standard_validation")) - ... // validation layer not available - \endcode + \snippet code/src_gui_vulkan_qvulkaninstance.cpp 1 Or, alternatively, to make decisions before attempting to create a Vulkan instance: - \code - QVulkanInstance inst; - - if (inst.supportedLayers().contains("VK_LAYER_LUNARG_standard_validation")) - ... - - bool ok = inst.create(); - ... - \endcode + \snippet code/src_gui_vulkan_qvulkaninstance.cpp 2 \section1 Adopting an Existing Instance @@ -229,62 +195,7 @@ QT_BEGIN_NAMESPACE The following is the basic outline of creating a Vulkan-capable QWindow: - \code - class VulkanWindow : public QWindow - { - public: - VulkanWindow() { - setSurfaceType(VulkanSurface); - } - - void exposeEvent(QExposeEvent *) { - if (isExposed()) { - if (!m_initialized) { - m_initialized = true; - // initialize device, swapchain, etc. - QVulkanInstance *inst = vulkanInstance(); - QVulkanFunctions *f = inst->functions(); - uint32_t devCount = 0; - f->vkEnumeratePhysicalDevices(inst->vkInstance(), &devCount, nullptr); - ... - // build the first frame - render(); - } - } - } - - bool event(QEvent *e) { - if (e->type == QEvent::UpdateRequest) - render(); - return QWindow::event(e); - } - - void render() { - ... - requestUpdate(); // render continuously - } - - private: - bool m_initialized = false; - }; - - int main(int argc, char **argv) - { - QGuiApplication app(argc, argv); - - QVulkanInstance inst; - if (!inst.create()) { - qWarning("Vulkan not available"); - return 1; - } - - VulkanWindow window; - window.showMaximized(); - - return app.exec(); - - } - \endcode + \snippet code/src_gui_vulkan_qvulkaninstance.cpp 3 \note In addition to expose, a well-behaving window implementation will also have to take care of additional events like resize and diff --git a/src/gui/vulkan/qvulkanwindow.cpp b/src/gui/vulkan/qvulkanwindow.cpp index 2e65ab49c5..6d12377a60 100644 --- a/src/gui/vulkan/qvulkanwindow.cpp +++ b/src/gui/vulkan/qvulkanwindow.cpp @@ -74,60 +74,7 @@ Q_LOGGING_CATEGORY(lcGuiVk, "qt.vulkan") A typical application using QVulkanWindow may look like the following: - \code - class VulkanRenderer : public QVulkanWindowRenderer - { - public: - VulkanRenderer(QVulkanWindow *w) : m_window(w) { } - - void initResources() override - { - m_devFuncs = m_window->vulkanInstance()->deviceFunctions(m_window->device()); - ... - } - void initSwapChainResources() override { ... } - void releaseSwapChainResources() override { ... } - void releaseResources() override { ... } - - void startNextFrame() override - { - VkCommandBuffer cmdBuf = m_window->currentCommandBuffer(); - ... - m_devFuncs->vkCmdBeginRenderPass(...); - ... - m_window->frameReady(); - } - - private: - QVulkanWindow *m_window; - QVulkanDeviceFunctions *m_devFuncs; - }; - - class VulkanWindow : public QVulkanWindow - { - public: - QVulkanWindowRenderer *createRenderer() override { - return new VulkanRenderer(this); - } - }; - - int main(int argc, char *argv[]) - { - QGuiApplication app(argc, argv); - - QVulkanInstance inst; - // enable the standard validation layers, when available - inst.setLayers(QByteArrayList() << "VK_LAYER_LUNARG_standard_validation"); - if (!inst.create()) - qFatal("Failed to create Vulkan instance: %d", inst.errorCode()); - - VulkanWindow w; - w.setVulkanInstance(&inst); - w.showMaximized(); - - return app.exec(); - } - \endcode + \snippet code/src_gui_vulkan_qvulkanwindow.cpp 0 As it can be seen in the example, the main patterns in QVulkanWindow usage are: @@ -2439,18 +2386,7 @@ VkFramebuffer QVulkanWindow::currentFramebuffer() const concurrentFrameCount(). Such arrays can then be indexed by the value returned from this function. - \code - class Renderer { - ... - VkDescriptorBufferInfo m_uniformBufInfo[QVulkanWindow::MAX_CONCURRENT_FRAME_COUNT]; - }; - - void Renderer::startNextFrame() - { - VkDescriptorBufferInfo &uniformBufInfo(m_uniformBufInfo[m_window->currentFrame()]); - ... - } - \endcode + \snippet code/src_gui_vulkan_qvulkanwindow.cpp 1 \note This function must only be called from within startNextFrame() and, in case of asynchronous command generation, up until the call to frameReady(). @@ -2477,20 +2413,7 @@ int QVulkanWindow::currentFrame() const \note The value is constant for the entire lifetime of the QVulkanWindow. - \code - class Renderer { - ... - VkDescriptorBufferInfo m_uniformBufInfo[QVulkanWindow::MAX_CONCURRENT_FRAME_COUNT]; - }; - - void Renderer::startNextFrame() - { - const int count = m_window->concurrentFrameCount(); - for (int i = 0; i < count; ++i) - m_uniformBufInfo[i] = ... - ... - } - \endcode + \snippet code/src_gui_vulkan_qvulkanwindow.cpp 2 \sa currentFrame() */ |