diff options
Diffstat (limited to 'examples/quick')
-rw-r--r-- | examples/quick/demos/photosurface/doc/src/photosurface.qdoc | 6 | ||||
-rw-r--r-- | examples/quick/demos/photosurface/main.cpp | 66 | ||||
-rw-r--r-- | examples/quick/demos/photosurface/photosurface.qml | 21 | ||||
-rw-r--r-- | examples/quick/demos/stocqt/content/+windows/Settings.qml | 46 | ||||
-rw-r--r-- | examples/quick/demos/stocqt/content/Button.qml | 3 | ||||
-rw-r--r-- | examples/quick/demos/stocqt/content/Settings.qml | 46 | ||||
-rw-r--r-- | examples/quick/demos/stocqt/content/StockChart.qml | 5 | ||||
-rw-r--r-- | examples/quick/demos/stocqt/content/StockInfo.qml | 11 | ||||
-rw-r--r-- | examples/quick/demos/stocqt/content/StockListView.qml | 11 | ||||
-rw-r--r-- | examples/quick/demos/stocqt/content/StockSettingsPanel.qml | 9 | ||||
-rw-r--r-- | examples/quick/demos/stocqt/content/qmldir | 10 | ||||
-rw-r--r-- | examples/quick/demos/stocqt/stocqt.qrc | 3 |
12 files changed, 215 insertions, 22 deletions
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 } 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 <QtGui/QGuiApplication> #endif #include <QtQml/QQmlApplicationEngine> +#include <QtQml/QQmlContext> #include <QtQuick/QQuickWindow> +#include <QtGui/QImageReader> +#include <QtCore/QCommandLineParser> +#include <QtCore/QCommandLineOption> +#include <QtCore/QDebug> +#include <QtCore/QDir> +#include <QtCore/QMimeDatabase> +#include <QtCore/QStandardPaths> #include <QtCore/QUrl> +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 : ""; } 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 @@ <RCC> <qresource prefix="/demos/stocqt"> <file>stocqt.qml</file> + <file>content/qmldir</file> <file>content/Button.qml</file> <file>content/CheckBox.qml</file> <file>content/StockChart.qml</file> @@ -13,5 +14,7 @@ <file>content/images/icon-left-arrow.png</file> <file>content/StockSettingsPanel.qml</file> <file>content/StockInfo.qml</file> + <file>content/Settings.qml</file> + <file>content/+windows/Settings.qml</file> </qresource> </RCC> |