diff options
Diffstat (limited to 'examples')
62 files changed, 987 insertions, 190 deletions
diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.cpp b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.cpp index 965e5152c1..d963b6d1b4 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.cpp +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.cpp @@ -41,7 +41,7 @@ #include "pieslice.h" PieChart::PieChart(QQuickItem *parent) - : QQuickItem(parent) + : QQuickItem(parent), m_pieSlice(0) { } diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.cpp b/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.cpp index ceb0041ec8..50c018e33e 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.cpp +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.cpp @@ -42,7 +42,7 @@ #include <QPainter> PieSlice::PieSlice(QQuickItem *parent) - : QQuickPaintedItem(parent) + : QQuickPaintedItem(parent), m_fromAngle(0), m_angleSpan(0) { } diff --git a/examples/quick/demos/demos.pro b/examples/quick/demos/demos.pro index 9aac7bf6f7..0644b81a22 100644 --- a/examples/quick/demos/demos.pro +++ b/examples/quick/demos/demos.pro @@ -7,7 +7,5 @@ SUBDIRS = samegame \ photosurface \ stocqt -qtHaveModule(xmlpatterns): SUBDIRS += rssnews +qtHaveModule(xmlpatterns): SUBDIRS += rssnews photoviewer -EXAMPLE_FILES = \ - photoviewer diff --git a/examples/quick/demos/photosurface/main.cpp b/examples/quick/demos/photosurface/main.cpp index 9456694032..b9d093df40 100644 --- a/examples/quick/demos/photosurface/main.cpp +++ b/examples/quick/demos/photosurface/main.cpp @@ -59,9 +59,11 @@ static QStringList imageNameFilters() { QStringList result; QMimeDatabase mimeDatabase; - foreach (const QByteArray &m, QImageReader::supportedMimeTypes()) { - foreach (const QString &suffix, mimeDatabase.mimeTypeForName(m).suffixes()) - result.append(QStringLiteral("*.") + suffix); + const auto supportedMimeTypes = QImageReader::supportedMimeTypes(); + for (const QByteArray &m : supportedMimeTypes) { + const auto suffixes = mimeDatabase.mimeTypeForName(m).suffixes(); + for (const QString &suffix : suffixes) + result.append(QLatin1String("*.") + suffix); } return result; } diff --git a/examples/quick/demos/photoviewer/deployment.pri b/examples/quick/demos/photoviewer/deployment.pri deleted file mode 100644 index 0d58a25c61..0000000000 --- a/examples/quick/demos/photoviewer/deployment.pri +++ /dev/null @@ -1,19 +0,0 @@ -android { - x86 { - target.path = /libs/x86 - } else: armeabi-v7a { - target.path = /libs/armeabi-v7a - } else { - target.path = /libs/armeabi - } - export(target.path) - INSTALLS += target -} else:unix { - isEmpty(target.path) { - target.path = /opt/$${TARGET}/bin - export(target.path) - } - INSTALLS += target -} - -export(INSTALLS) diff --git a/examples/quick/demos/photoviewer/photoviewer.pro b/examples/quick/demos/photoviewer/photoviewer.pro index 704e2ce003..4bfdb86f31 100644 --- a/examples/quick/demos/photoviewer/photoviewer.pro +++ b/examples/quick/demos/photoviewer/photoviewer.pro @@ -15,8 +15,5 @@ TRANSLATIONS += i18n/qml_fr.ts \ RESOURCES += qml.qrc -# Additional import path used to resolve QML modules in Qt Creator's code model -QML_IMPORT_PATH = - -# Default rules for deployment. -include(deployment.pri) +target.path = $$[QT_INSTALL_EXAMPLES]/quick/demos/photoviewer +INSTALLS += target diff --git a/examples/quick/demos/samegame/samegame.pro b/examples/quick/demos/samegame/samegame.pro index e041dd61dd..0f01654d46 100644 --- a/examples/quick/demos/samegame/samegame.pro +++ b/examples/quick/demos/samegame/samegame.pro @@ -7,4 +7,4 @@ RESOURCES += samegame.qrc target.path = $$[QT_INSTALL_EXAMPLES]/quick/demos/samegame INSTALLS += target -!contains(sql-drivers, sqlite): QTPLUGIN += qsqlite +!qtConfig(sql-sqlite): QTPLUGIN += qsqlite diff --git a/examples/quick/embeddedinwidgets/main.cpp b/examples/quick/embeddedinwidgets/main.cpp index 96b0df7e13..91147772ba 100644 --- a/examples/quick/embeddedinwidgets/main.cpp +++ b/examples/quick/embeddedinwidgets/main.cpp @@ -103,7 +103,8 @@ void MainWindow::quickViewStatusChanged(QQuickView::Status status) { if (status == QQuickView::Error) { QStringList errors; - foreach (const QQmlError &error, m_quickView->errors()) + const auto viewErrors = m_quickView->errors(); + for (const QQmlError &error : viewErrors) errors.append(error.toString()); statusBar()->showMessage(errors.join(QStringLiteral(", "))); } diff --git a/examples/quick/quick.pro b/examples/quick/quick.pro index b164bf4f5b..445dfb0fab 100644 --- a/examples/quick/quick.pro +++ b/examples/quick/quick.pro @@ -27,7 +27,7 @@ SUBDIRS = quick-accessibility \ demos #OpenGL Support Required -contains(QT_CONFIG, opengl(es1|es2)?) { +qtConfig(opengl(es1|es2)?) { SUBDIRS += \ textureprovider \ rendercontrol diff --git a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp index 078d8e7e03..ea6c7f2f9a 100644 --- a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp +++ b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp @@ -40,6 +40,7 @@ #include "mainwindow.h" #include "fbitem.h" +#include <QCoreApplication> #include <QVBoxLayout> #include <QGroupBox> #include <QRadioButton> diff --git a/examples/quick/quickwidgets/quickwidget/customgl.qml b/examples/quick/quickwidgets/quickwidget/customgl.qml new file mode 100644 index 0000000000..81e33e1ac9 --- /dev/null +++ b/examples/quick/quickwidgets/quickwidget/customgl.qml @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QuickWidgetExample 1.0 + +Rectangle { + color: "lightGray" + + FbItem { + anchors.fill: parent + anchors.margins: 10 + } + + Text { + anchors.left: parent.left + anchors.bottom: parent.bottom + anchors.margins: 15 + text: "QQuickFramebufferObject with animated clear color" + color: "white" + } +} diff --git a/examples/quick/quickwidgets/quickwidget/fbitem.cpp b/examples/quick/quickwidgets/quickwidget/fbitem.cpp new file mode 100644 index 0000000000..fc2a4ea7ad --- /dev/null +++ b/examples/quick/quickwidgets/quickwidget/fbitem.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "fbitem.h" +#include <QtGui/QOpenGLFramebufferObject> +#include <QtGui/QOpenGLContext> +#include <QtGui/QOpenGLFunctions> +#include <QtCore/QDebug> + +#ifndef QT_NO_OPENGL +class FbRenderer : public QQuickFramebufferObject::Renderer +{ +public: + FbRenderer() : c(0), dir(1) { } + + // The lifetime of the FBO and this class depends on how QQuickWidget + // manages the scenegraph and context when it comes to showing and hiding + // the widget. The actual behavior is proven by the debug prints. + ~FbRenderer() { + qDebug("FbRenderer destroyed"); + } + + void render() { + QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); + f->glClearColor(c, 0, 0, 1); + f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + c += 0.01f * dir; + if (c >= 1.0f || c <= 0.0f) + dir *= -1; + update(); + } + + QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) { + qDebug() << "Creating FBO" << size; + QOpenGLFramebufferObjectFormat format; + format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + return new QOpenGLFramebufferObject(size, format); + } + +private: + float c; + int dir; +}; +#endif + +QQuickFramebufferObject::Renderer *FbItem::createRenderer() const +{ +#ifndef QT_NO_OPENGL + return new FbRenderer; +#else + return nullptr; +#endif +} diff --git a/examples/quick/quickwidgets/quickwidget/fbitem.h b/examples/quick/quickwidgets/quickwidget/fbitem.h new file mode 100644 index 0000000000..59280eb3b8 --- /dev/null +++ b/examples/quick/quickwidgets/quickwidget/fbitem.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FBITEM_H +#define FBITEM_H + +#include <QtQuick/QQuickFramebufferObject> + +class FbItem : public QQuickFramebufferObject +{ + Q_OBJECT +public: + Renderer *createRenderer() const; +}; + +#endif diff --git a/examples/quick/quickwidgets/quickwidget/main.cpp b/examples/quick/quickwidgets/quickwidget/main.cpp index 65258d958e..590f29ed29 100644 --- a/examples/quick/quickwidgets/quickwidget/main.cpp +++ b/examples/quick/quickwidgets/quickwidget/main.cpp @@ -41,6 +41,7 @@ #include <QQuickWidget> #include <QQmlError> #include <QtWidgets> +#include "fbitem.h" class MainWindow : public QMainWindow { Q_OBJECT @@ -52,6 +53,7 @@ private slots: void sceneGraphError(QQuickWindow::SceneGraphError error, const QString &message); void grabToFile(); void renderToFile(); + void createQuickWidgetsInTabs(QMdiArea *mdiArea); private: QQuickWidget *m_quickWidget; @@ -74,7 +76,7 @@ MainWindow::MainWindow() QLCDNumber *lcd = new QLCDNumber; lcd->display(1337); lcd->setMinimumSize(250,100); - centralWidget ->addSubWindow(lcd); + centralWidget->addSubWindow(lcd); QUrl source("qrc:quickwidget/rotatingsquare.qml"); @@ -86,21 +88,50 @@ MainWindow::MainWindow() m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView ); m_quickWidget->setSource(source); - centralWidget ->addSubWindow(m_quickWidget); + centralWidget->addSubWindow(m_quickWidget); setCentralWidget(centralWidget); QMenu *fileMenu = menuBar()->addMenu(tr("&File")); - fileMenu->addAction(tr("Grab to imFage"), this, &MainWindow::grabToFile); + fileMenu->addAction(tr("Grab to image"), this, &MainWindow::grabToFile); fileMenu->addAction(tr("Render to pixmap"), this, &MainWindow::renderToFile); fileMenu->addAction(tr("Quit"), qApp, &QCoreApplication::quit); + + QMenu *windowMenu = menuBar()->addMenu(tr("&Window")); + windowMenu->addAction(tr("Add tab widget"), this, + [this, centralWidget] { createQuickWidgetsInTabs(centralWidget); }); +} + +void MainWindow::createQuickWidgetsInTabs(QMdiArea *mdiArea) +{ + QTabWidget *tabWidget = new QTabWidget; + + const QSize size(400, 400); + + QQuickWidget *w = new QQuickWidget; + w->resize(size); + w->setResizeMode(QQuickWidget::SizeRootObjectToView); + w->setSource(QUrl("qrc:quickwidget/rotatingsquaretab.qml")); + + tabWidget->addTab(w, tr("Plain Quick content")); + + w = new QQuickWidget; + w->resize(size); + w->setResizeMode(QQuickWidget::SizeRootObjectToView); + w->setSource(QUrl("qrc:quickwidget/customgl.qml")); + + tabWidget->addTab(w, tr("Custom OpenGL drawing")); + + mdiArea->addSubWindow(tabWidget); + tabWidget->show(); } void MainWindow::quickWidgetStatusChanged(QQuickWidget::Status status) { if (status == QQuickWidget::Error) { QStringList errors; - foreach (const QQmlError &error, m_quickWidget->errors()) + const auto widgetErrors = m_quickWidget->errors(); + for (const QQmlError &error : widgetErrors) errors.append(error.toString()); statusBar()->showMessage(errors.join(QStringLiteral(", "))); } @@ -139,6 +170,8 @@ int main(int argc, char **argv) { QApplication app(argc, argv); + qmlRegisterType<FbItem>("QuickWidgetExample", 1, 0, "FbItem"); + MainWindow mainWindow; mainWindow.show(); diff --git a/examples/quick/quickwidgets/quickwidget/quickwidget.pro b/examples/quick/quickwidgets/quickwidget/quickwidget.pro index 04fb5541a7..5be006f7fa 100644 --- a/examples/quick/quickwidgets/quickwidget/quickwidget.pro +++ b/examples/quick/quickwidgets/quickwidget/quickwidget.pro @@ -3,7 +3,8 @@ QT += core gui quick widgets quickwidgets TARGET = quickwidget TEMPLATE = app -SOURCES += main.cpp +SOURCES += main.cpp fbitem.cpp +HEADERS += fbitem.h RESOURCES += quickwidget.qrc diff --git a/examples/quick/quickwidgets/quickwidget/quickwidget.qrc b/examples/quick/quickwidgets/quickwidget/quickwidget.qrc index c073b7b80d..85a49b75ca 100644 --- a/examples/quick/quickwidgets/quickwidget/quickwidget.qrc +++ b/examples/quick/quickwidgets/quickwidget/quickwidget.qrc @@ -1,5 +1,7 @@ <RCC> <qresource prefix="/quickwidget"> <file>rotatingsquare.qml</file> + <file>rotatingsquaretab.qml</file> + <file>customgl.qml</file> </qresource> </RCC> diff --git a/examples/quick/quickwidgets/quickwidget/rotatingsquaretab.qml b/examples/quick/quickwidgets/quickwidget/rotatingsquaretab.qml new file mode 100644 index 0000000000..51c17b9ffb --- /dev/null +++ b/examples/quick/quickwidgets/quickwidget/rotatingsquaretab.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + gradient: Gradient { + GradientStop { position: 0; color: "steelblue" } + GradientStop { position: 1; color: "black" } + } + + Rectangle { + property int d: 100 + id: square + width: d + height: d + anchors.centerIn: parent + color: "green" + NumberAnimation on rotation { from: 360; to: 0; duration: 4000; loops: Animation.Infinite; } + } + + Text { + anchors.centerIn: parent + text: "Qt Quick running in a tab widget" + color: "purple" + font.bold: true + font.pointSize: 14 + } +} diff --git a/examples/quick/rendercontrol/window_multithreaded.cpp b/examples/quick/rendercontrol/window_multithreaded.cpp index 4df3488ab3..013ee7c208 100644 --- a/examples/quick/rendercontrol/window_multithreaded.cpp +++ b/examples/quick/rendercontrol/window_multithreaded.cpp @@ -356,16 +356,16 @@ void WindowMultiThreaded::run() disconnect(m_qmlComponent, &QQmlComponent::statusChanged, this, &WindowMultiThreaded::run); if (m_qmlComponent->isError()) { - QList<QQmlError> errorList = m_qmlComponent->errors(); - foreach (const QQmlError &error, errorList) + const QList<QQmlError> errorList = m_qmlComponent->errors(); + for (const QQmlError &error : errorList) qWarning() << error.url() << error.line() << error; return; } QObject *rootObject = m_qmlComponent->create(); if (m_qmlComponent->isError()) { - QList<QQmlError> errorList = m_qmlComponent->errors(); - foreach (const QQmlError &error, errorList) + const QList<QQmlError> errorList = m_qmlComponent->errors(); + for (const QQmlError &error : errorList) qWarning() << error.url() << error.line() << error; return; } diff --git a/examples/quick/rendercontrol/window_singlethreaded.cpp b/examples/quick/rendercontrol/window_singlethreaded.cpp index 45f2635ca4..ef8f2fed43 100644 --- a/examples/quick/rendercontrol/window_singlethreaded.cpp +++ b/examples/quick/rendercontrol/window_singlethreaded.cpp @@ -209,16 +209,16 @@ void WindowSingleThreaded::run() disconnect(m_qmlComponent, &QQmlComponent::statusChanged, this, &WindowSingleThreaded::run); if (m_qmlComponent->isError()) { - QList<QQmlError> errorList = m_qmlComponent->errors(); - foreach (const QQmlError &error, errorList) + const QList<QQmlError> errorList = m_qmlComponent->errors(); + for (const QQmlError &error : errorList) qWarning() << error.url() << error.line() << error; return; } QObject *rootObject = m_qmlComponent->create(); if (m_qmlComponent->isError()) { - QList<QQmlError> errorList = m_qmlComponent->errors(); - foreach (const QQmlError &error, errorList) + const QList<QQmlError> errorList = m_qmlComponent->errors(); + for (const QQmlError &error : errorList) qWarning() << error.url() << error.line() << error; return; } diff --git a/examples/quick/scenegraph/graph/linenode.cpp b/examples/quick/scenegraph/graph/linenode.cpp index 473be7da17..992e2d44c9 100644 --- a/examples/quick/scenegraph/graph/linenode.cpp +++ b/examples/quick/scenegraph/graph/linenode.cpp @@ -56,7 +56,7 @@ class LineShader : public QSGSimpleMaterialShader<LineMaterial> QSG_DECLARE_SIMPLE_SHADER(LineShader, LineMaterial) public: - LineShader() { + LineShader() : id_color(-1), id_spread(-1), id_size(-1) { setShaderSourceFile(QOpenGLShader::Vertex, ":/scenegraph/graph/shaders/line.vsh"); setShaderSourceFile(QOpenGLShader::Fragment, ":/scenegraph/graph/shaders/line.fsh"); } diff --git a/examples/quick/scenegraph/graph/noisynode.cpp b/examples/quick/scenegraph/graph/noisynode.cpp index bc273cf632..834151599b 100644 --- a/examples/quick/scenegraph/graph/noisynode.cpp +++ b/examples/quick/scenegraph/graph/noisynode.cpp @@ -61,7 +61,7 @@ class NoisyShader : public QSGSimpleMaterialShader<NoisyMaterial> QSG_DECLARE_SIMPLE_SHADER(NoisyShader, NoisyMaterial) public: - NoisyShader() { + NoisyShader() : id_color(-1), id_texture(-1), id_textureSize(-1) { setShaderSourceFile(QOpenGLShader::Vertex, ":/scenegraph/graph/shaders/noisy.vsh"); setShaderSourceFile(QOpenGLShader::Fragment, ":/scenegraph/graph/shaders/noisy.fsh"); } diff --git a/examples/quick/scenegraph/rendernode/customrenderitem.cpp b/examples/quick/scenegraph/rendernode/customrenderitem.cpp index 433f3c5a1e..2465f4cbc7 100644 --- a/examples/quick/scenegraph/rendernode/customrenderitem.cpp +++ b/examples/quick/scenegraph/rendernode/customrenderitem.cpp @@ -44,6 +44,7 @@ #include "openglrenderer.h" #include "d3d12renderer.h" +#include "softwarerenderer.h" CustomRenderItem::CustomRenderItem(QQuickItem *parent) : QQuickItem(parent) @@ -70,6 +71,10 @@ QSGNode *CustomRenderItem::updatePaintNode(QSGNode *node, UpdatePaintNodeData *) n = new D3D12RenderNode(this); break; #endif + case QSGRendererInterface::Software: + n = new SoftwareRenderNode(this); + break; + default: return nullptr; } diff --git a/examples/quick/scenegraph/rendernode/d3d12renderer.cpp b/examples/quick/scenegraph/rendernode/d3d12renderer.cpp index bc03720407..d35f82a76a 100644 --- a/examples/quick/scenegraph/rendernode/d3d12renderer.cpp +++ b/examples/quick/scenegraph/rendernode/d3d12renderer.cpp @@ -78,7 +78,7 @@ void D3D12RenderNode::releaseResources() void D3D12RenderNode::init() { QSGRendererInterface *rif = m_item->window()->rendererInterface(); - m_device = static_cast<ID3D12Device *>(rif->getResource(QSGRendererInterface::Device)); + m_device = static_cast<ID3D12Device *>(rif->getResource(m_item->window(), QSGRendererInterface::Device)); Q_ASSERT(m_device); D3D12_ROOT_PARAMETER rootParameter; @@ -153,7 +153,20 @@ void D3D12RenderNode::init() psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psoDesc.DSVFormat = DXGI_FORMAT_D24_UNORM_S8_UINT; // not in use due to !DepthEnable, but this would be the correct format otherwise - psoDesc.SampleDesc.Count = 1; + // We are rendering on the default render target so if the QuickWindow/View + // has requested samples > 0 then we have to follow suit. + const uint samples = qMax(1, m_item->window()->format().samples()); + psoDesc.SampleDesc.Count = samples; + if (samples > 1) { + D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS msaaInfo = {}; + msaaInfo.Format = psoDesc.RTVFormats[0]; + msaaInfo.SampleCount = samples; + if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &msaaInfo, sizeof(msaaInfo)))) { + if (msaaInfo.NumQualityLevels > 0) + psoDesc.SampleDesc.Quality = msaaInfo.NumQualityLevels - 1; + } + } + if (FAILED(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pipelineState)))) { qWarning("Failed to create graphics pipeline state"); return; @@ -222,7 +235,7 @@ void D3D12RenderNode::render(const RenderState *state) init(); QSGRendererInterface *rif = m_item->window()->rendererInterface(); - ID3D12GraphicsCommandList *commandList = static_cast<ID3D12GraphicsCommandList *>(rif->getResource(QSGRendererInterface::CommandList)); + ID3D12GraphicsCommandList *commandList = static_cast<ID3D12GraphicsCommandList *>(rif->getResource(m_item->window(), QSGRendererInterface::CommandList)); Q_ASSERT(commandList); const int msize = 16 * sizeof(float); @@ -257,4 +270,14 @@ void D3D12RenderNode::render(const RenderState *state) // No need to reimplement changedStates() because no relevant commands are // added to the command list in render(). +QSGRenderNode::RenderingFlags D3D12RenderNode::flags() const +{ + return BoundedRectRendering | DepthAwareRendering; +} + +QRectF D3D12RenderNode::rect() const +{ + return QRect(0, 0, m_item->width(), m_item->height()); +} + #endif // HAS_D3D12 diff --git a/examples/quick/scenegraph/rendernode/d3d12renderer.h b/examples/quick/scenegraph/rendernode/d3d12renderer.h index a81db0f398..f13a1d451c 100644 --- a/examples/quick/scenegraph/rendernode/d3d12renderer.h +++ b/examples/quick/scenegraph/rendernode/d3d12renderer.h @@ -60,6 +60,8 @@ public: void render(const RenderState *state) override; void releaseResources() override; + RenderingFlags flags() const override; + QRectF rect() const override; private: void init(); diff --git a/examples/quick/scenegraph/rendernode/main.cpp b/examples/quick/scenegraph/rendernode/main.cpp index 9128cdc5be..3e1714313e 100644 --- a/examples/quick/scenegraph/rendernode/main.cpp +++ b/examples/quick/scenegraph/rendernode/main.cpp @@ -49,6 +49,13 @@ int main(int argc, char **argv) qmlRegisterType<CustomRenderItem>("SceneGraphRendering", 2, 0, "CustomRenderItem"); QQuickView view; + + if (QCoreApplication::arguments().contains(QStringLiteral("--multisample"))) { + QSurfaceFormat fmt; + fmt.setSamples(4); + view.setFormat(fmt); + } + view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///scenegraph/rendernode/main.qml")); view.resize(1024, 768); diff --git a/examples/quick/scenegraph/rendernode/main.qml b/examples/quick/scenegraph/rendernode/main.qml index a91656dfaa..7c8d82181f 100644 --- a/examples/quick/scenegraph/rendernode/main.qml +++ b/examples/quick/scenegraph/rendernode/main.qml @@ -90,7 +90,10 @@ Item { anchors.margins: 20 wrapMode: Text.WordWrap property int api: GraphicsInfo.api - text: "Custom rendering via the graphics API " + (api === GraphicsInfo.OpenGL ? "OpenGL" : (api === GraphicsInfo.Direct3D12 ? "Direct3D 12" : "")) + text: "Custom rendering via the graphics API " + + (api === GraphicsInfo.OpenGL ? "OpenGL" + : api === GraphicsInfo.Direct3D12 ? "Direct3D 12" + : api === GraphicsInfo.Software ? "Software" : "") color: "yellow" } } diff --git a/examples/quick/scenegraph/rendernode/openglrenderer.cpp b/examples/quick/scenegraph/rendernode/openglrenderer.cpp index 3eff70cb42..3de864b7b9 100644 --- a/examples/quick/scenegraph/rendernode/openglrenderer.cpp +++ b/examples/quick/scenegraph/rendernode/openglrenderer.cpp @@ -97,8 +97,6 @@ void OpenGLRenderNode::init() const int VERTEX_SIZE = 6 * sizeof(GLfloat); - // A fully featured renderer should also take inheritedOpacity() into account - // and blend, but ignore that for now. static GLfloat colors[] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, @@ -140,6 +138,8 @@ void OpenGLRenderNode::render(const RenderState *state) m_program->enableAttributeArray(0); m_program->enableAttributeArray(1); + // Note that clipping (scissor or stencil) is ignored in this example. + f->glEnable(GL_BLEND); f->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); @@ -151,4 +151,14 @@ QSGRenderNode::StateFlags OpenGLRenderNode::changedStates() const return BlendState; } +QSGRenderNode::RenderingFlags OpenGLRenderNode::flags() const +{ + return BoundedRectRendering | DepthAwareRendering; +} + +QRectF OpenGLRenderNode::rect() const +{ + return QRect(0, 0, m_item->width(), m_item->height()); +} + #endif // QT_NO_OPENGL diff --git a/examples/quick/scenegraph/rendernode/openglrenderer.h b/examples/quick/scenegraph/rendernode/openglrenderer.h index 28d528e617..92cc2bc72b 100644 --- a/examples/quick/scenegraph/rendernode/openglrenderer.h +++ b/examples/quick/scenegraph/rendernode/openglrenderer.h @@ -45,6 +45,8 @@ #ifndef QT_NO_OPENGL +QT_BEGIN_NAMESPACE + class QQuickItem; class QOpenGLShaderProgram; class QOpenGLBuffer; @@ -58,6 +60,8 @@ public: void render(const RenderState *state) override; void releaseResources() override; StateFlags changedStates() const override; + RenderingFlags flags() const override; + QRectF rect() const override; private: void init(); @@ -69,6 +73,8 @@ private: QOpenGLBuffer *m_vbo = nullptr; }; +QT_END_NAMESPACE + #endif // QT_NO_OPENGL #endif diff --git a/examples/quick/scenegraph/rendernode/rendernode.pro b/examples/quick/scenegraph/rendernode/rendernode.pro index d7ae715a7d..851d5927bd 100644 --- a/examples/quick/scenegraph/rendernode/rendernode.pro +++ b/examples/quick/scenegraph/rendernode/rendernode.pro @@ -1,10 +1,12 @@ QT += qml quick HEADERS += customrenderitem.h \ - openglrenderer.h + openglrenderer.h \ + softwarerenderer.h SOURCES += customrenderitem.cpp \ openglrenderer.cpp \ + softwarerenderer.cpp \ main.cpp RESOURCES += rendernode.qrc diff --git a/examples/quick/scenegraph/rendernode/softwarerenderer.cpp b/examples/quick/scenegraph/rendernode/softwarerenderer.cpp new file mode 100644 index 0000000000..06e406874a --- /dev/null +++ b/examples/quick/scenegraph/rendernode/softwarerenderer.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "softwarerenderer.h" +#include <QQuickItem> +#include <QQuickWindow> +#include <QSGRendererInterface> +#include <QPainter> + +SoftwareRenderNode::SoftwareRenderNode(QQuickItem *item) + : m_item(item) +{ +} + +SoftwareRenderNode::~SoftwareRenderNode() +{ + releaseResources(); +} + +void SoftwareRenderNode::releaseResources() +{ +} + +void SoftwareRenderNode::render(const RenderState *renderState) +{ + QSGRendererInterface *rif = m_item->window()->rendererInterface(); + QPainter *p = static_cast<QPainter *>(rif->getResource(m_item->window(), QSGRendererInterface::Painter)); + Q_ASSERT(p); + + p->setTransform(matrix()->toTransform()); + p->setOpacity(inheritedOpacity()); + const QRegion *clipRegion = renderState->clipRegion(); + if (clipRegion && !clipRegion->isEmpty()) + p->setClipRegion(*clipRegion, Qt::IntersectClip); + + const QPointF p0(m_item->width() - 1, m_item->height() - 1); + const QPointF p1(0, 0); + const QPointF p2(0, m_item->height() - 1); + QPainterPath path(p0); + path.lineTo(p1); + path.lineTo(p2); + path.closeSubpath(); + + QLinearGradient gradient(QPointF(0, 0), QPointF(m_item->width(), m_item->height())); + gradient.setColorAt(0, Qt::green); + gradient.setColorAt(1, Qt::red); + + p->fillPath(path, gradient); +} + +QSGRenderNode::StateFlags SoftwareRenderNode::changedStates() const +{ + return 0; +} + +QSGRenderNode::RenderingFlags SoftwareRenderNode::flags() const +{ + return BoundedRectRendering; +} + +QRectF SoftwareRenderNode::rect() const +{ + return QRect(0, 0, m_item->width(), m_item->height()); +} diff --git a/examples/quick/scenegraph/rendernode/softwarerenderer.h b/examples/quick/scenegraph/rendernode/softwarerenderer.h new file mode 100644 index 0000000000..e91ca92d88 --- /dev/null +++ b/examples/quick/scenegraph/rendernode/softwarerenderer.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SOFTWARERENDERER_H +#define SOFTWARERENDERER_H + +#include <qsgrendernode.h> +#include <QQuickItem> + +class SoftwareRenderNode : public QSGRenderNode +{ +public: + SoftwareRenderNode(QQuickItem *item); + ~SoftwareRenderNode(); + + void render(const RenderState *state) override; + void releaseResources() override; + StateFlags changedStates() const override; + RenderingFlags flags() const override; + QRectF rect() const override; + +private: + QQuickItem *m_item; +}; + +#endif diff --git a/examples/quick/scenegraph/scenegraph.pro b/examples/quick/scenegraph/scenegraph.pro index 1015d7be3d..e13e8198b0 100644 --- a/examples/quick/scenegraph/scenegraph.pro +++ b/examples/quick/scenegraph/scenegraph.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs -contains(QT_CONFIG, opengl(es1|es2)?) { +qtConfig(opengl(es1|es2)?) { SUBDIRS += \ graph \ simplematerial \ diff --git a/examples/quick/scenegraph/sgengine/window.cpp b/examples/quick/scenegraph/sgengine/window.cpp index 2e4a70d2af..759bbf1fcd 100644 --- a/examples/quick/scenegraph/sgengine/window.cpp +++ b/examples/quick/scenegraph/sgengine/window.cpp @@ -187,7 +187,7 @@ void Window::update() void Window::sync() { QList<QSharedPointer<Item> > validItems; - foreach (QSharedPointer<Item> item, m_items) { + for (QSharedPointer<Item> item : qAsConst(m_items)) { if (!item->isDone()) { validItems.append(item); item->sync(); diff --git a/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc b/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc index 278f154781..d6eb711929 100644 --- a/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc +++ b/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc @@ -102,8 +102,8 @@ state and we use it to update the shader program with the current color. The previous state is passed in as a second parameter so that the user can update only that which has changed. In our - usecase, where all the colors are different, the updateState will - be called once for every node. + use case, where all the colors are different, the updateState() + function will be called once for every node. \snippet scenegraph/simplematerial/simplematerial.cpp 7 diff --git a/examples/quick/scenegraph/textureinthread/main.cpp b/examples/quick/scenegraph/textureinthread/main.cpp index 22550cd22b..61d1c5e6dc 100644 --- a/examples/quick/scenegraph/textureinthread/main.cpp +++ b/examples/quick/scenegraph/textureinthread/main.cpp @@ -82,7 +82,7 @@ int main(int argc, char **argv) // As the render threads make use of our QGuiApplication object // to clean up gracefully, wait for them to finish before // QGuiApp is taken off the heap. - foreach (QThread *t, ThreadRenderer::threads) { + for (QThread *t : qAsConst(ThreadRenderer::threads)) { t->wait(); delete t; } diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/blur.frag b/examples/quick/shadereffects/content/shaders/+hlsl/blur.frag new file mode 100644 index 0000000000..481a238d2a --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/+hlsl/blur.frag @@ -0,0 +1,18 @@ +cbuffer ConstantBuffer : register(b0) +{ + float4x4 qt_Matrix; + float qt_Opacity; + float2 delta; +}; + +Texture2D source : register(t0); +SamplerState sourceSampler : register(s0); + +float4 main(float4 position : SV_POSITION, float2 coord : TEXCOORD0) : SV_TARGET +{ + return (0.0538 * source.Sample(sourceSampler, coord - 3.182 * delta) + + 0.3229 * source.Sample(sourceSampler, coord - 1.364 * delta) + + 0.2466 * source.Sample(sourceSampler, coord) + + 0.3229 * source.Sample(sourceSampler, coord + 1.364 * delta) + + 0.0538 * source.Sample(sourceSampler, coord + 3.182 * delta)) * qt_Opacity; +} diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/colorize.frag b/examples/quick/shadereffects/content/shaders/+hlsl/colorize.frag new file mode 100644 index 0000000000..d6e65b6b10 --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/+hlsl/colorize.frag @@ -0,0 +1,17 @@ +cbuffer ConstantBuffer : register(b0) +{ + float4x4 qt_Matrix; + float qt_Opacity; + float4 tint; +}; + +Texture2D source : register(t0); +SamplerState sourceSampler : register(s0); + +float4 main(float4 position : SV_POSITION, float2 coord : TEXCOORD0) : SV_TARGET +{ + float4 c = source.Sample(sourceSampler, coord); + float lo = min(min(c.x, c.y), c.z); + float hi = max(max(c.x, c.y), c.z); + return float4(lerp(float3(lo, lo, lo), float3(hi, hi, hi), tint.xyz), c.w) * qt_Opacity; +} diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/genie.vert b/examples/quick/shadereffects/content/shaders/+hlsl/genie.vert new file mode 100644 index 0000000000..40876e7996 --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/+hlsl/genie.vert @@ -0,0 +1,31 @@ +cbuffer ConstantBuffer : register(b0) +{ + float4x4 qt_Matrix; + float qt_Opacity; + float bend; + float minimize; + float side; + float width; + float height; +}; + +struct PSInput +{ + float4 position : SV_POSITION; + float2 coord : TEXCOORD0; +}; + +PSInput main(float4 position : POSITION, float2 coord : TEXCOORD0) +{ + PSInput result; + result.coord = coord; + + float4 pos = position; + pos.y = lerp(position.y, height, minimize); + float t = pos.y / height; + t = (3.0 - 2.0 * t) * t * t; + pos.x = lerp(position.x, side * width, t * bend); + result.position = mul(qt_Matrix, pos); + + return result; +} diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/outline.frag b/examples/quick/shadereffects/content/shaders/+hlsl/outline.frag new file mode 100644 index 0000000000..b6e7e51f35 --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/+hlsl/outline.frag @@ -0,0 +1,21 @@ +cbuffer ConstantBuffer : register(b0) +{ + float4x4 qt_Matrix; + float qt_Opacity; + float2 delta; +}; + +Texture2D source : register(t0); +SamplerState sourceSampler : register(s0); + +float4 main(float4 position : SV_POSITION, float2 coord : TEXCOORD0) : SV_TARGET +{ + float4 tl = source.Sample(sourceSampler, coord - delta); + float4 tr = source.Sample(sourceSampler, coord + float2(delta.x, -delta.y)); + float4 bl = source.Sample(sourceSampler, coord - float2(delta.x, -delta.y)); + float4 br = source.Sample(sourceSampler, coord + delta); + float4 gx = (tl + bl) - (tr + br); + float4 gy = (tl + tr) - (bl + br); + return float4(0.0, 0.0, 0.0, + clamp(dot(sqrt(gx * gx + gy * gy), float4(1.0, 1.0, 1.0, 1.0)), 0.0, 1.0) * qt_Opacity); +} diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/shadow.frag b/examples/quick/shadereffects/content/shaders/+hlsl/shadow.frag new file mode 100644 index 0000000000..a86a25e007 --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/+hlsl/shadow.frag @@ -0,0 +1,20 @@ +cbuffer ConstantBuffer : register(b0) +{ + float4x4 qt_Matrix; + float qt_Opacity; + float2 offset; + float2 delta; + float darkness; +}; + +Texture2D source : register(t0); +SamplerState sourceSampler : register(s0); +Texture2D shadow : register(t1); +SamplerState shadowSampler : register(s1); + +float4 main(float4 position : SV_POSITION, float2 coord : TEXCOORD0) : SV_TARGET +{ + float4 fg = source.Sample(sourceSampler, coord); + float4 bg = shadow.Sample(shadowSampler, coord + delta); + return (fg + float4(0.0, 0.0, 0.0, darkness * bg.a) * (1.0 - fg.a)) * qt_Opacity; +} diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/wobble.frag b/examples/quick/shadereffects/content/shaders/+hlsl/wobble.frag new file mode 100644 index 0000000000..c28612a2fd --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/+hlsl/wobble.frag @@ -0,0 +1,17 @@ +cbuffer ConstantBuffer : register(b0) +{ + float4x4 qt_Matrix; + float qt_Opacity; + float amplitude; + float frequency; + float time; +}; + +Texture2D source : register(t0); +SamplerState sourceSampler : register(s0); + +float4 main(float4 position : SV_POSITION, float2 coord : TEXCOORD0) : SV_TARGET +{ + float2 p = sin(time + frequency * coord); + return source.Sample(sourceSampler, coord + amplitude * float2(p.y, -p.x)) * qt_Opacity; +} diff --git a/examples/quick/shadereffects/content/shaders/blur.frag b/examples/quick/shadereffects/content/shaders/blur.frag new file mode 100644 index 0000000000..9173945eed --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/blur.frag @@ -0,0 +1,14 @@ +uniform lowp float qt_Opacity; +uniform sampler2D source; +uniform highp vec2 delta; + +varying highp vec2 qt_TexCoord0; + +void main() +{ + gl_FragColor =(0.0538 * texture2D(source, qt_TexCoord0 - 3.182 * delta) + + 0.3229 * texture2D(source, qt_TexCoord0 - 1.364 * delta) + + 0.2466 * texture2D(source, qt_TexCoord0) + + 0.3229 * texture2D(source, qt_TexCoord0 + 1.364 * delta) + + 0.0538 * texture2D(source, qt_TexCoord0 + 3.182 * delta)) * qt_Opacity; +} diff --git a/examples/quick/shadereffects/content/shaders/colorize.frag b/examples/quick/shadereffects/content/shaders/colorize.frag new file mode 100644 index 0000000000..1219ef2460 --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/colorize.frag @@ -0,0 +1,12 @@ +uniform sampler2D source; +uniform lowp vec4 tint; +uniform lowp float qt_Opacity; + +varying highp vec2 qt_TexCoord0; + +void main() { + lowp vec4 c = texture2D(source, qt_TexCoord0); + lowp float lo = min(min(c.x, c.y), c.z); + lowp float hi = max(max(c.x, c.y), c.z); + gl_FragColor = qt_Opacity * vec4(mix(vec3(lo), vec3(hi), tint.xyz), c.w); +} diff --git a/examples/quick/shadereffects/content/shaders/genie.vert b/examples/quick/shadereffects/content/shaders/genie.vert new file mode 100644 index 0000000000..3ce371819f --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/genie.vert @@ -0,0 +1,21 @@ +attribute highp vec4 qt_Vertex; +attribute highp vec2 qt_MultiTexCoord0; + +uniform highp mat4 qt_Matrix; +uniform highp float bend; +uniform highp float minimize; +uniform highp float side; +uniform highp float width; +uniform highp float height; + +varying highp vec2 qt_TexCoord0; + +void main() { + qt_TexCoord0 = qt_MultiTexCoord0; + highp vec4 pos = qt_Vertex; + pos.y = mix(qt_Vertex.y, height, minimize); + highp float t = pos.y / height; + t = (3. - 2. * t) * t * t; + pos.x = mix(qt_Vertex.x, side * width, t * bend); + gl_Position = qt_Matrix * pos; +} diff --git a/examples/quick/shadereffects/content/shaders/outline.frag b/examples/quick/shadereffects/content/shaders/outline.frag new file mode 100644 index 0000000000..9b46719873 --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/outline.frag @@ -0,0 +1,16 @@ +uniform sampler2D source; +uniform highp vec2 delta; +uniform highp float qt_Opacity; + +varying highp vec2 qt_TexCoord0; + +void main() { + lowp vec4 tl = texture2D(source, qt_TexCoord0 - delta); + lowp vec4 tr = texture2D(source, qt_TexCoord0 + vec2(delta.x, -delta.y)); + lowp vec4 bl = texture2D(source, qt_TexCoord0 - vec2(delta.x, -delta.y)); + lowp vec4 br = texture2D(source, qt_TexCoord0 + delta); + mediump vec4 gx = (tl + bl) - (tr + br); + mediump vec4 gy = (tl + tr) - (bl + br); + gl_FragColor.xyz = vec3(0.); + gl_FragColor.w = clamp(dot(sqrt(gx * gx + gy * gy), vec4(1.)), 0., 1.) * qt_Opacity; +} diff --git a/examples/quick/shadereffects/content/shaders/shadow.frag b/examples/quick/shadereffects/content/shaders/shadow.frag new file mode 100644 index 0000000000..8650ee4f4c --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/shadow.frag @@ -0,0 +1,14 @@ +uniform lowp float qt_Opacity; +uniform highp vec2 offset; +uniform sampler2D source; +uniform sampler2D shadow; +uniform highp float darkness; +uniform highp vec2 delta; + +varying highp vec2 qt_TexCoord0; + +void main() { + lowp vec4 fg = texture2D(source, qt_TexCoord0); + lowp vec4 bg = texture2D(shadow, qt_TexCoord0 + delta); + gl_FragColor = (fg + vec4(0., 0., 0., darkness * bg.a) * (1. - fg.a)) * qt_Opacity; +} diff --git a/examples/quick/shadereffects/content/shaders/wobble.frag b/examples/quick/shadereffects/content/shaders/wobble.frag new file mode 100644 index 0000000000..fedbb68254 --- /dev/null +++ b/examples/quick/shadereffects/content/shaders/wobble.frag @@ -0,0 +1,13 @@ +uniform lowp float qt_Opacity; +uniform highp float amplitude; +uniform highp float frequency; +uniform highp float time; +uniform sampler2D source; + +varying highp vec2 qt_TexCoord0; + +void main() +{ + highp vec2 p = sin(time + frequency * qt_TexCoord0); + gl_FragColor = texture2D(source, qt_TexCoord0 + amplitude * vec2(p.y, -p.x)) * qt_Opacity; +} diff --git a/examples/quick/shadereffects/doc/src/shadereffects.qdoc b/examples/quick/shadereffects/doc/src/shadereffects.qdoc index dc2a2681f5..7b1d68ebb5 100644 --- a/examples/quick/shadereffects/doc/src/shadereffects.qdoc +++ b/examples/quick/shadereffects/doc/src/shadereffects.qdoc @@ -51,6 +51,21 @@ shader: \snippet shadereffects/shadereffects.qml fragment + In order to support multiple graphics APIs, not just OpenGL, the shader + source is not embedded into QML. Instead, file selectors are used to select + the correct variant at runtime. Based on the Qt Quick backend in use, Qt + will automatically select either \c{shaders/wobble.frag} with the GLSL + source code or \c{shaders/+hlsl/wobble.frag} with the HLSL source code. + + \note For simplicity shader source code is used in all variants of the + files. However, with the Direct3D backend of Qt Quick pre-compiled shaders + are also supported. For example, try the following commands in the + \c{content/shaders/+hlsl} directory: \c{move wobble.frag wobble.frag.src} + followed by \c{fxc /E main /T ps_5_0 /Fo wobble.frag wobble.frag.src}. Now + \c wobble.frag contains Direct3D bytecode and that is what gets shipped + with the application instead of the shader source. Further changes are not + necessary, the application will function like before. + You can use any custom property on the ShaderEffect in your shader. This makes animated shader code very easy: \snippet shadereffects/shadereffects.qml properties diff --git a/examples/quick/shadereffects/shadereffects.qml b/examples/quick/shadereffects/shadereffects.qml index 926394ed0f..0c24a7bbf2 100644 --- a/examples/quick/shadereffects/shadereffects.qml +++ b/examples/quick/shadereffects/shadereffects.qml @@ -101,7 +101,7 @@ Rectangle { height: 140 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter - font.pixelSize: 120 + font.pixelSize: 118 font.family: "Times" color: "blue" text: "Qt" @@ -128,17 +128,7 @@ Rectangle { property real time: 0 NumberAnimation on time { loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 600 } //! [fragment] - fragmentShader: - "uniform lowp float qt_Opacity;" + - "uniform highp float amplitude;" + - "uniform highp float frequency;" + - "uniform highp float time;" + - "uniform sampler2D source;" + - "varying highp vec2 qt_TexCoord0;" + - "void main() {" + - " highp vec2 p = sin(time + frequency * qt_TexCoord0);" + - " gl_FragColor = texture2D(source, qt_TexCoord0 + amplitude * vec2(p.y, -p.x)) * qt_Opacity;" + - "}" + fragmentShader: "qrc:shadereffects/content/shaders/wobble.frag" //! [fragment] Slider { id: wobbleSlider @@ -163,32 +153,10 @@ Rectangle { height: theItem.height property variant delta: Qt.size(1.0 / width, 0.0) property variant source: theSource - fragmentShader: " - uniform lowp float qt_Opacity; - uniform sampler2D source; - uniform highp vec2 delta; - varying highp vec2 qt_TexCoord0; - void main() { - gl_FragColor =(0.0538 * texture2D(source, qt_TexCoord0 - 3.182 * delta) - + 0.3229 * texture2D(source, qt_TexCoord0 - 1.364 * delta) - + 0.2466 * texture2D(source, qt_TexCoord0) - + 0.3229 * texture2D(source, qt_TexCoord0 + 1.364 * delta) - + 0.0538 * texture2D(source, qt_TexCoord0 + 3.182 * delta)) * qt_Opacity; - }" + fragmentShader: "qrc:shadereffects/content/shaders/blur.frag" } } - fragmentShader: " - uniform lowp float qt_Opacity; - uniform sampler2D source; - uniform highp vec2 delta; - varying highp vec2 qt_TexCoord0; - void main() { - gl_FragColor =(0.0538 * texture2D(source, qt_TexCoord0 - 3.182 * delta) - + 0.3229 * texture2D(source, qt_TexCoord0 - 1.364 * delta) - + 0.2466 * texture2D(source, qt_TexCoord0) - + 0.3229 * texture2D(source, qt_TexCoord0 + 1.364 * delta) - + 0.0538 * texture2D(source, qt_TexCoord0 + 3.182 * delta)) * qt_Opacity; - }" + fragmentShader: "qrc:shadereffects/content/shaders/blur.frag" } } property real angle: 0 @@ -196,19 +164,7 @@ Rectangle { NumberAnimation on angle { loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 6000 } property variant delta: Qt.size(offset.x / width, offset.y / height) property real darkness: shadowSlider.value - fragmentShader: " - uniform lowp float qt_Opacity; - uniform highp vec2 offset; - uniform sampler2D source; - uniform sampler2D shadow; - uniform highp float darkness; - uniform highp vec2 delta; - varying highp vec2 qt_TexCoord0; - void main() { - lowp vec4 fg = texture2D(source, qt_TexCoord0); - lowp vec4 bg = texture2D(shadow, qt_TexCoord0 + delta); - gl_FragColor = (fg + vec4(0., 0., 0., darkness * bg.a) * (1. - fg.a)) * qt_Opacity; - }" + fragmentShader: "qrc:shadereffects/content/shaders/shadow.frag" Slider { id: shadowSlider anchors.left: parent.left @@ -222,38 +178,14 @@ Rectangle { height: 160 property variant source: theSource property variant delta: Qt.size(0.5 / width, 0.5 / height) - fragmentShader: " - uniform sampler2D source; - uniform highp vec2 delta; - uniform highp float qt_Opacity; - varying highp vec2 qt_TexCoord0; - void main() { - lowp vec4 tl = texture2D(source, qt_TexCoord0 - delta); - lowp vec4 tr = texture2D(source, qt_TexCoord0 + vec2(delta.x, -delta.y)); - lowp vec4 bl = texture2D(source, qt_TexCoord0 - vec2(delta.x, -delta.y)); - lowp vec4 br = texture2D(source, qt_TexCoord0 + delta); - mediump vec4 gx = (tl + bl) - (tr + br); - mediump vec4 gy = (tl + tr) - (bl + br); - gl_FragColor.xyz = vec3(0.); - gl_FragColor.w = clamp(dot(sqrt(gx * gx + gy * gy), vec4(1.)), 0., 1.) * qt_Opacity; - }" + fragmentShader: "qrc:shadereffects/content/shaders/outline.frag" } ShaderEffect { width: 160 height: 160 property variant source: theSource property color tint: root.sliderToColor(colorizeSlider.value) - fragmentShader: " - uniform sampler2D source; - uniform lowp vec4 tint; - uniform lowp float qt_Opacity; - varying highp vec2 qt_TexCoord0; - void main() { - lowp vec4 c = texture2D(source, qt_TexCoord0); - lowp float lo = min(min(c.x, c.y), c.z); - lowp float hi = max(max(c.x, c.y), c.z); - gl_FragColor = qt_Opacity * vec4(mix(vec3(lo), vec3(hi), tint.xyz), c.w); - }" + fragmentShader: "qrc:shadereffects/content/shaders/colorize.frag" Slider { id: colorizeSlider anchors.left: parent.left @@ -288,25 +220,7 @@ Rectangle { //! [properties] //! [vertex] mesh: Qt.size(10, 10) - vertexShader: " - uniform highp mat4 qt_Matrix; - uniform highp float bend; - uniform highp float minimize; - uniform highp float side; - uniform highp float width; - uniform highp float height; - attribute highp vec4 qt_Vertex; - attribute highp vec2 qt_MultiTexCoord0; - varying highp vec2 qt_TexCoord0; - void main() { - qt_TexCoord0 = qt_MultiTexCoord0; - highp vec4 pos = qt_Vertex; - pos.y = mix(qt_Vertex.y, height, minimize); - highp float t = pos.y / height; - t = (3. - 2. * t) * t * t; - pos.x = mix(qt_Vertex.x, side * width, t * bend); - gl_Position = qt_Matrix * pos; - }" + vertexShader: "qrc:shadereffects/content/shaders/genie.vert" //! [vertex] Slider { id: genieSlider diff --git a/examples/quick/shadereffects/shadereffects.qrc b/examples/quick/shadereffects/shadereffects.qrc index ff296a0155..e66b98a6df 100644 --- a/examples/quick/shadereffects/shadereffects.qrc +++ b/examples/quick/shadereffects/shadereffects.qrc @@ -4,5 +4,17 @@ <file>content/face-smile.png</file> <file>content/qt-logo.png</file> <file>content/Slider.qml</file> + <file>content/shaders/wobble.frag</file> + <file>content/shaders/+hlsl/wobble.frag</file> + <file>content/shaders/blur.frag</file> + <file>content/shaders/+hlsl/blur.frag</file> + <file>content/shaders/shadow.frag</file> + <file>content/shaders/+hlsl/shadow.frag</file> + <file>content/shaders/outline.frag</file> + <file>content/shaders/+hlsl/outline.frag</file> + <file>content/shaders/colorize.frag</file> + <file>content/shaders/+hlsl/colorize.frag</file> + <file>content/shaders/genie.vert</file> + <file>content/shaders/+hlsl/genie.vert</file> </qresource> </RCC> diff --git a/examples/quick/shared/Label.qml b/examples/quick/shared/Label.qml new file mode 100644 index 0000000000..ea4bef5415 --- /dev/null +++ b/examples/quick/shared/Label.qml @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Text { + SystemPalette { id: palette } + color: palette.text +} diff --git a/examples/quick/shared/quick_shared.qrc b/examples/quick/shared/quick_shared.qrc index ea7e0fdd89..21f393a64d 100644 --- a/examples/quick/shared/quick_shared.qrc +++ b/examples/quick/shared/quick_shared.qrc @@ -4,6 +4,7 @@ <file>SimpleLauncherDelegate.qml</file> <file>Button.qml</file> <file>CheckBox.qml</file> + <file>Label.qml</file> <file>TextField.qml</file> <file>images/back.png</file> <file>images/next.png</file> diff --git a/examples/quick/shared/shared.qrc b/examples/quick/shared/shared.qrc index 7e0c66c34b..89b3ff757e 100644 --- a/examples/quick/shared/shared.qrc +++ b/examples/quick/shared/shared.qrc @@ -6,6 +6,7 @@ <file>Slider.qml</file> <file>images/slider_handle.png</file> <file>CheckBox.qml</file> + <file>Label.qml</file> <file>TabSet.qml</file> <file>TextField.qml</file> <file>images/back.png</file> diff --git a/examples/quick/textureprovider/etcprovider.cpp b/examples/quick/textureprovider/etcprovider.cpp index c713cf1ffd..de8eb12366 100644 --- a/examples/quick/textureprovider/etcprovider.cpp +++ b/examples/quick/textureprovider/etcprovider.cpp @@ -98,7 +98,7 @@ unsigned short getPaddedHeight(ETCHeader *pHeader) EtcTexture::EtcTexture() : m_texture_id(0), m_uploaded(false) { - + initializeOpenGLFunctions(); } EtcTexture::~EtcTexture() @@ -109,8 +109,10 @@ EtcTexture::~EtcTexture() int EtcTexture::textureId() const { - if (m_texture_id == 0) - glGenTextures(1, &const_cast<EtcTexture *>(this)->m_texture_id); + if (m_texture_id == 0) { + EtcTexture *texture = const_cast<EtcTexture*>(this); + texture->glGenTextures(1, &texture->m_texture_id); + } return m_texture_id; } diff --git a/examples/quick/textureprovider/etcprovider.h b/examples/quick/textureprovider/etcprovider.h index 75903963e4..44d5d6f53e 100644 --- a/examples/quick/textureprovider/etcprovider.h +++ b/examples/quick/textureprovider/etcprovider.h @@ -51,7 +51,7 @@ #ifndef ETCPROVIDER_H #define ETCPROVIDER_H -#include <qopengl.h> +#include <QOpenGLFunctions> #include <QQuickImageProvider> #include <QtQuick/QSGTexture> #include <QUrl> @@ -71,7 +71,7 @@ private: QUrl m_baseUrl; }; -class EtcTexture : public QSGTexture +class EtcTexture : public QSGTexture, protected QOpenGLFunctions { Q_OBJECT public: diff --git a/examples/quick/window/AllScreens.qml b/examples/quick/window/AllScreens.qml new file mode 100644 index 0000000000..83a6c5f958 --- /dev/null +++ b/examples/quick/window/AllScreens.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.3 +import QtQuick.Window 2.3 +import "../shared" as Shared + +Column { + id: root + spacing: 8 + + Shared.Label { + text: "Total number of screens: " + screenInfo.count + font.bold: true + } + + Flow { + spacing: 12 + width: parent.width + + Repeater { + id: screenInfo + model: Qt.application.screens + Shared.Label { + lineHeight: 1.5 + text: name + "\n" + virtualX + ", " + virtualY + " " + modelData.width + "x" + modelData.height + } + } + } + + Component.onCompleted: { + var screens = Qt.application.screens; + for (var i = 0; i < screens.length; ++i) + console.log("screen " + screens[i].name + " has geometry " + + screens[i].virtualX + ", " + screens[i].virtualY + " " + + screens[i].width + "x" + screens[i].height) + } +} diff --git a/examples/quick/window/ScreenInfo.qml b/examples/quick/window/CurrentScreen.qml index ee0a31c794..c65baab1f4 100644 --- a/examples/quick/window/ScreenInfo.qml +++ b/examples/quick/window/CurrentScreen.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -40,6 +40,7 @@ import QtQuick 2.3 import QtQuick.Window 2.1 +import "../shared" as Shared Item { id: root @@ -70,32 +71,35 @@ Item { y: spacing //! [screen] - Text { + Shared.Label { text: "Screen \"" + Screen.name + "\":" font.bold: true } Item { width: 1; height: 1 } // spacer - Text { text: "dimensions" } - Text { text: Screen.width + "x" + Screen.height } + Shared.Label { text: "dimensions" } + Shared.Label { text: Screen.width + "x" + Screen.height } - Text { text: "pixel density" } - Text { text: Screen.pixelDensity.toFixed(2) + " dots/mm (" + (Screen.pixelDensity * 25.4).toFixed(2) + " dots/inch)" } + Shared.Label { text: "pixel density" } + Shared.Label { text: Screen.pixelDensity.toFixed(2) + " dots/mm (" + (Screen.pixelDensity * 25.4).toFixed(2) + " dots/inch)" } - Text { text: "logical pixel density" } - Text { text: Screen.logicalPixelDensity.toFixed(2) + " dots/mm (" + (Screen.logicalPixelDensity * 25.4).toFixed(2) + " dots/inch)" } + Shared.Label { text: "logical pixel density" } + Shared.Label { text: Screen.logicalPixelDensity.toFixed(2) + " dots/mm (" + (Screen.logicalPixelDensity * 25.4).toFixed(2) + " dots/inch)" } - Text { text: "device pixel ratio" } - Text { text: Screen.devicePixelRatio.toFixed(2) } + Shared.Label { text: "device pixel ratio" } + Shared.Label { text: Screen.devicePixelRatio.toFixed(2) } - Text { text: "available virtual desktop" } - Text { text: Screen.desktopAvailableWidth + "x" + Screen.desktopAvailableHeight } + Shared.Label { text: "available virtual desktop" } + Shared.Label { text: Screen.desktopAvailableWidth + "x" + Screen.desktopAvailableHeight } - Text { text: "orientation" } - Text { text: orientationToString(Screen.orientation) + " (" + Screen.orientation + ")" } + Shared.Label { text: "position in virtual desktop" } + Shared.Label { text: Screen.virtualX + ", " + Screen.virtualY } - Text { text: "primary orientation" } - Text { text: orientationToString(Screen.primaryOrientation) + " (" + Screen.primaryOrientation + ")" } + Shared.Label { text: "orientation" } + Shared.Label { text: orientationToString(Screen.orientation) + " (" + Screen.orientation + ")" } + + Shared.Label { text: "primary orientation" } + Shared.Label { text: orientationToString(Screen.primaryOrientation) + " (" + Screen.primaryOrientation + ")" } //! [screen] } } diff --git a/examples/quick/window/Splash.qml b/examples/quick/window/Splash.qml index 083c3babc8..3baf207992 100644 --- a/examples/quick/window/Splash.qml +++ b/examples/quick/window/Splash.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. diff --git a/examples/quick/window/doc/src/window.qdoc b/examples/quick/window/doc/src/window.qdoc index 5cd51beceb..2028b31383 100644 --- a/examples/quick/window/doc/src/window.qdoc +++ b/examples/quick/window/doc/src/window.qdoc @@ -73,7 +73,7 @@ \l Screen has several properties which are generally useful to applications which need to rotate some content when the screen orientation changes, to position windows on the screen or to convert real units to - logical pixel units. ScreenInfo.qml (which is displayed inline in + logical pixel units. CurrentScreen.qml (which is displayed inline in window.qml, or can be run by itself with qmlscene) simply displays the property values, while the splash screen uses them to center the window on the screen. diff --git a/examples/quick/window/main.cpp b/examples/quick/window/main.cpp index bacf52af15..ee8855cbc8 100644 --- a/examples/quick/window/main.cpp +++ b/examples/quick/window/main.cpp @@ -49,7 +49,8 @@ int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); - foreach (QScreen * screen, QGuiApplication::screens()) + const auto screens = QGuiApplication::screens(); + for (QScreen *screen : screens) screen->setOrientationUpdateMask(Qt::LandscapeOrientation | Qt::PortraitOrientation | Qt::InvertedLandscapeOrientation | Qt::InvertedPortraitOrientation); QQmlEngine engine; diff --git a/examples/quick/window/window.qml b/examples/quick/window/window.qml index d50bce61b3..d27ab3d0a3 100644 --- a/examples/quick/window/window.qml +++ b/examples/quick/window/window.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtQuick.Window 2.1 +import QtQuick.Window 2.3 import "../shared" as Shared QtObject { @@ -47,7 +47,7 @@ QtObject { property SystemPalette palette: SystemPalette { } property var controlWindow: Window { - width: visibilityLabel.implicitWidth * 1.2 + width: col.implicitWidth + defaultSpacing * 2 height: col.implicitHeight + defaultSpacing * 2 color: palette.window title: "Control Window" @@ -57,7 +57,7 @@ QtObject { anchors.margins: defaultSpacing spacing: defaultSpacing property real cellWidth: col.width / 3 - spacing - Text { text: "Control the second window:" } + Shared.Label { text: "Control the second window:" } Grid { id: grid columns: 3 @@ -121,18 +121,23 @@ QtObject { } return "unknown"; } - Text { + Shared.Label { id: visibilityLabel text: "second window is " + (testWindow.visible ? "visible" : "invisible") + " and has visibility " + parent.visibilityToString(testWindow.visibility) } Rectangle { - id: horizontalRule - color: "black" + color: palette.text width: parent.width height: 1 } - ScreenInfo { } + CurrentScreen { } + Rectangle { + color: palette.text + width: parent.width + height: 1 + } + AllScreens { width: parent.width } } } @@ -145,7 +150,7 @@ QtObject { Rectangle { anchors.fill: parent anchors.margins: defaultSpacing - Text { + Shared.Label { anchors.centerIn: parent text: "Second Window" } diff --git a/examples/quick/window/window.qrc b/examples/quick/window/window.qrc index dc211bdaaf..89d1de1b1f 100644 --- a/examples/quick/window/window.qrc +++ b/examples/quick/window/window.qrc @@ -2,6 +2,7 @@ <qresource prefix="/window"> <file>window.qml</file> <file>Splash.qml</file> - <file>ScreenInfo.qml</file> + <file>CurrentScreen.qml</file> + <file>AllScreens.qml</file> </qresource> </RCC> |