From 16eaec15e8878c4edaadeada6d3a42aa0bf1bc96 Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Mon, 25 Jan 2016 13:15:50 +0100 Subject: Doc: Corrected display qml code in photosurface.qdoc Change-Id: Ic4e0dcc6bd91921cfea68e0cfe805e8369f58618 Task-number: QTBUG-49810 Reviewed-by: Martin Smith --- examples/quick/demos/photosurface/doc/src/photosurface.qdoc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/quick/demos/photosurface/doc/src/photosurface.qdoc b/examples/quick/demos/photosurface/doc/src/photosurface.qdoc index 52466843b4..a032d730eb 100644 --- a/examples/quick/demos/photosurface/doc/src/photosurface.qdoc +++ b/examples/quick/demos/photosurface/doc/src/photosurface.qdoc @@ -116,6 +116,7 @@ \quotefromfile demos/photosurface/photosurface.qml \skipto Rectangle + \printuntil Component.onCompleted \printuntil } \section1 Handling Pinch Gestures @@ -123,6 +124,7 @@ We use a PinchArea that contains a MouseArea in the photo frames to handle dragging, rotation and pinch zooming of the frame: + \skipto PinchArea \printuntil onPinchStarted We use the \c pinch group property to control how the photo frames react to @@ -137,13 +139,13 @@ frame is controlled in the \c onEntered signal handler to highlight the selected image: + \skipto MouseArea \printuntil onEntered To enable you to test the example on the desktop, we use the MouseArea's \c onWheel signal handler to simulate pinch gestures by using a mouse: - \printuntil photoFrame.y - \printuntil } + \printuntil photoFrame.scale \printuntil } \printuntil } -- cgit v1.2.3 From 67c4017054baf394062ab4f869d9ca9d299d3354 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 27 Jan 2016 12:07:50 +0100 Subject: stocqt example: Choose font depending on platform. The example used the font "Open Sans" which is only available on UNIX platforms and causes it to look baroque on WinRT. Add a settings file specifying the font and override via file selector. Change-Id: I1a9284d928ac57289d75b5fb9477849ac518787b Reviewed-by: Simon Hausmann --- .../demos/stocqt/content/+windows/Settings.qml | 46 ++++++++++++++++++++++ examples/quick/demos/stocqt/content/Button.qml | 3 +- examples/quick/demos/stocqt/content/Settings.qml | 46 ++++++++++++++++++++++ examples/quick/demos/stocqt/content/StockChart.qml | 5 ++- examples/quick/demos/stocqt/content/StockInfo.qml | 11 +++--- .../quick/demos/stocqt/content/StockListView.qml | 11 +++--- .../demos/stocqt/content/StockSettingsPanel.qml | 9 +++-- examples/quick/demos/stocqt/content/qmldir | 10 +++++ examples/quick/demos/stocqt/stocqt.qrc | 3 ++ 9 files changed, 127 insertions(+), 17 deletions(-) create mode 100644 examples/quick/demos/stocqt/content/+windows/Settings.qml create mode 100644 examples/quick/demos/stocqt/content/Settings.qml create mode 100644 examples/quick/demos/stocqt/content/qmldir (limited to 'examples') diff --git a/examples/quick/demos/stocqt/content/+windows/Settings.qml b/examples/quick/demos/stocqt/content/+windows/Settings.qml new file mode 100644 index 0000000000..1d4d7edcee --- /dev/null +++ b/examples/quick/demos/stocqt/content/+windows/Settings.qml @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://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$ +** +****************************************************************************/ + +pragma Singleton +import QtQml 2.0 + +QtObject { + property string fontFamily: "Arial" +} diff --git a/examples/quick/demos/stocqt/content/Button.qml b/examples/quick/demos/stocqt/content/Button.qml index e85a5d41c5..4ef86a2cc3 100644 --- a/examples/quick/demos/stocqt/content/Button.qml +++ b/examples/quick/demos/stocqt/content/Button.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import "." Rectangle { id: button @@ -54,7 +55,7 @@ Rectangle { } Text { anchors.centerIn: parent - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 19 font.weight: Font.DemiBold color: button.buttonEnabled ? "#000000" : "#14aaff" diff --git a/examples/quick/demos/stocqt/content/Settings.qml b/examples/quick/demos/stocqt/content/Settings.qml new file mode 100644 index 0000000000..39e1c4c241 --- /dev/null +++ b/examples/quick/demos/stocqt/content/Settings.qml @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://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$ +** +****************************************************************************/ + +pragma Singleton +import QtQml 2.0 + +QtObject { + property string fontFamily: "Open Sans" +} diff --git a/examples/quick/demos/stocqt/content/StockChart.qml b/examples/quick/demos/stocqt/content/StockChart.qml index bbe5b77d0c..147f513456 100644 --- a/examples/quick/demos/stocqt/content/StockChart.qml +++ b/examples/quick/demos/stocqt/content/StockChart.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import "." Rectangle { id: chart @@ -135,7 +136,7 @@ Rectangle { Text { id: fromDate color: "#000000" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 8 anchors.left: parent.left anchors.bottom: parent.bottom @@ -145,7 +146,7 @@ Rectangle { Text { id: toDate color: "#000000" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 8 anchors.right: parent.right anchors.rightMargin: canvas.tickMargin diff --git a/examples/quick/demos/stocqt/content/StockInfo.qml b/examples/quick/demos/stocqt/content/StockInfo.qml index 50f6b9107e..3c5ee196f2 100644 --- a/examples/quick/demos/stocqt/content/StockInfo.qml +++ b/examples/quick/demos/stocqt/content/StockInfo.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import "." Rectangle { id: root @@ -60,7 +61,7 @@ Rectangle { Text { id: stockIdText color: "#000000" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 28 font.weight: Font.DemiBold text: root.stock.stockId @@ -69,7 +70,7 @@ Rectangle { Text { id: price color: "#6d6d6d" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 28 font.weight: Font.DemiBold text: parseFloat(Math.round(root.stock.stockPrice * 100) / 100).toFixed(2); @@ -79,7 +80,7 @@ Rectangle { Text { id: stockNameText color: "#0c0c0c" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 16 width: stockColumn.width elide: Text.ElideRight @@ -96,7 +97,7 @@ Rectangle { id: priceChange horizontalAlignment: Text.AlignRight color: root.stock.stockPriceChanged < 0 ? "#d40000" : "#328930" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 18 text: parseFloat(Math.round(root.stock.stockPriceChanged * 100) / 100).toFixed(2); } @@ -105,7 +106,7 @@ Rectangle { id: priceChangePercentage horizontalAlignment: Text.AlignRight color: root.stock.stockPriceChanged < 0 ? "#d40000" : "#328930" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 18 font.weight: Font.DemiBold text: "(" + diff --git a/examples/quick/demos/stocqt/content/StockListView.qml b/examples/quick/demos/stocqt/content/StockListView.qml index 470531a21e..d1f735fde3 100644 --- a/examples/quick/demos/stocqt/content/StockListView.qml +++ b/examples/quick/demos/stocqt/content/StockListView.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import "." Rectangle { id: root @@ -144,7 +145,7 @@ Rectangle { width: 125 height: 40 color: "#000000" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 20 font.weight: Font.Bold verticalAlignment: Text.AlignVCenter @@ -160,7 +161,7 @@ Rectangle { width: 190 height: 40 color: "#000000" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 20 font.bold: true horizontalAlignment: Text.AlignRight @@ -178,7 +179,7 @@ Rectangle { width: 135 height: 40 color: "#328930" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 20 font.bold: true horizontalAlignment: Text.AlignRight @@ -200,7 +201,7 @@ Rectangle { width: 330 height: 30 color: "#000000" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 16 font.bold: false elide: Text.ElideRight @@ -217,7 +218,7 @@ Rectangle { width: 120 height: 30 color: "#328930" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 18 font.bold: false horizontalAlignment: Text.AlignRight diff --git a/examples/quick/demos/stocqt/content/StockSettingsPanel.qml b/examples/quick/demos/stocqt/content/StockSettingsPanel.qml index 7d71355b31..0c34e453de 100644 --- a/examples/quick/demos/stocqt/content/StockSettingsPanel.qml +++ b/examples/quick/demos/stocqt/content/StockSettingsPanel.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import "." Rectangle { id: root @@ -62,7 +63,7 @@ Rectangle { anchors.left: root.left anchors.top: root.top color: "#000000" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 19 text: "Open" } @@ -73,7 +74,7 @@ Rectangle { anchors.top: openText.bottom anchors.topMargin: 10 color: "#000000" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 19 text: "Close" } @@ -84,7 +85,7 @@ Rectangle { anchors.top: closeText.bottom anchors.topMargin: 10 color: "#000000" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 19 text: "High" } @@ -95,7 +96,7 @@ Rectangle { anchors.top: highText.bottom anchors.topMargin: 10 color: "#000000" - font.family: "Open Sans" + font.family: Settings.fontFamily font.pointSize: 19 text: "Low" } diff --git a/examples/quick/demos/stocqt/content/qmldir b/examples/quick/demos/stocqt/content/qmldir new file mode 100644 index 0000000000..bcfa27b484 --- /dev/null +++ b/examples/quick/demos/stocqt/content/qmldir @@ -0,0 +1,10 @@ +singleton Settings 1.0 Settings.qml +Button 1.0 Button.qml +CheckBox 1.0 CheckBox.qml +StockChart 1.0 StockChart.qml +StockInfo 1.0 StockInfo.qml +StockListModel 1.0 StockListModel.qml +StockListView 1.0 StockListView.qml +StockModel 1.0 StockModel.qml +StockSettingsPanel 1.0 StockSettingsPanel.qml +StockView 1.0 StockView.qml diff --git a/examples/quick/demos/stocqt/stocqt.qrc b/examples/quick/demos/stocqt/stocqt.qrc index ee5dd0c24f..920e56d4d0 100644 --- a/examples/quick/demos/stocqt/stocqt.qrc +++ b/examples/quick/demos/stocqt/stocqt.qrc @@ -1,6 +1,7 @@ stocqt.qml + content/qmldir content/Button.qml content/CheckBox.qml content/StockChart.qml @@ -13,5 +14,7 @@ content/images/icon-left-arrow.png content/StockSettingsPanel.qml content/StockInfo.qml + content/Settings.qml + content/+windows/Settings.qml -- cgit v1.2.3 From 666bc731a0ba930ca0cfda18daf836913fd91361 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 26 Jan 2016 16:49:31 +0100 Subject: photosurface demo: Improve handling of image directories. Make it possible to pass URLs on the command line. If no argument is given and the pictures location as returned by QStandardPaths exists and has contents, show it, Otherwise, show the file dialog as was before. Set context properties containing pictures location, image name filters and initial URL. Derive the image filter string from QImageReader/QMimeDatabase. Change-Id: I89bdff27416bf8ef725aa4e17853b2f634cf059b Reviewed-by: Shawn Rutledge --- examples/quick/demos/photosurface/main.cpp | 66 +++++++++++++++++++++- examples/quick/demos/photosurface/photosurface.qml | 21 ++++++- 2 files changed, 84 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/quick/demos/photosurface/main.cpp b/examples/quick/demos/photosurface/main.cpp index 3058238494..9456694032 100644 --- a/examples/quick/demos/photosurface/main.cpp +++ b/examples/quick/demos/photosurface/main.cpp @@ -44,9 +44,28 @@ #include #endif #include +#include #include +#include +#include +#include +#include +#include +#include +#include #include +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); + } + return result; +} + int main(int argc, char* argv[]) { // The reason to use QApplication is that QWidget-based dialogs @@ -58,6 +77,51 @@ int main(int argc, char* argv[]) QGuiApplication app(argc, argv); #endif QQuickWindow::setDefaultAlphaBuffer(true); - QQmlApplicationEngine engine(QUrl("qrc:///photosurface.qml")); + + QCoreApplication::setApplicationName(QStringLiteral("Photosurface")); + QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); + QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); + QCommandLineParser parser; + parser.setApplicationDescription(QStringLiteral("Qt Quick Demo - Photo Surface")); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument(QStringLiteral("directory"), + QStringLiteral("The image directory or URL to show.")); + parser.process(app); + + QUrl initialUrl; + if (!parser.positionalArguments().isEmpty()) { + initialUrl = QUrl::fromUserInput(parser.positionalArguments().first(), + QDir::currentPath(), QUrl::AssumeLocalFile); + if (!initialUrl.isValid()) { + qWarning().nospace() << "Invalid argument: \"" + << parser.positionalArguments().first() << "\": " << initialUrl.errorString(); + return 1; + } + } + + const QStringList nameFilters = imageNameFilters(); + + QQmlApplicationEngine engine; + QQmlContext *context = engine.rootContext(); + + QUrl picturesLocationUrl = QUrl::fromLocalFile(QDir::homePath()); + const QStringList picturesLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); + if (!picturesLocations.isEmpty()) { + picturesLocationUrl = QUrl::fromLocalFile(picturesLocations.first()); + if (initialUrl.isEmpty() + && !QDir(picturesLocations.first()).entryInfoList(nameFilters, QDir::Files).isEmpty()) { + initialUrl = picturesLocationUrl; + } + } + + context->setContextProperty(QStringLiteral("contextPicturesLocation"), picturesLocationUrl); + context->setContextProperty(QStringLiteral("contextInitialUrl"), initialUrl); + context->setContextProperty(QStringLiteral("contextImageNameFilters"), nameFilters); + + engine.load(QUrl("qrc:///photosurface.qml")); + if (engine.rootObjects().isEmpty()) + return -1; + return app.exec(); } diff --git a/examples/quick/demos/photosurface/photosurface.qml b/examples/quick/demos/photosurface/photosurface.qml index 22cef62157..d8a424e8f8 100644 --- a/examples/quick/demos/photosurface/photosurface.qml +++ b/examples/quick/demos/photosurface/photosurface.qml @@ -56,6 +56,7 @@ Window { id: fileDialog title: "Choose a folder with some images" selectFolder: true + folder: picturesLocation onAccepted: folderModel.folder = fileUrl + "/" } @@ -69,7 +70,7 @@ Window { id: folderModel objectName: "folderModel" showDirs: false - nameFilters: ["*.png", "*.jpg", "*.gif"] + nameFilters: imageNameFilters } Rectangle { id: photoFrame @@ -255,5 +256,21 @@ Window { Shortcut { sequence: StandardKey.Quit; onActivated: Qt.quit() } - Component.onCompleted: fileDialog.open() + Component.onCompleted: { + if (typeof contextInitialUrl !== 'undefined') { + // Launched from C++ with context properties set. + imageNameFilters = contextImageNameFilters; + picturesLocation = contextPicturesLocation; + if (contextInitialUrl == "") + fileDialog.open(); + else + folderModel.folder = contextInitialUrl + "/"; + } else { + // Launched via QML viewer without context properties set. + fileDialog.open(); + } + } + + property var imageNameFilters : ["*.png", "*.jpg", "*.gif"]; + property string picturesLocation : ""; } -- cgit v1.2.3