diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-11-18 20:34:17 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-12-01 16:14:00 +0000 |
commit | 15fab6e8f81c7fd643f7c4e6a7979a2f66ec4060 (patch) | |
tree | 1a3f41d98465c970108876cf2372f544f10a160f /examples | |
parent | 4ba00f0054ffd183377fd420b35ef7a388c0bcfe (diff) |
Side Panel example
Task-number: QTBUG-53169
Change-Id: I1d84d2fc9cbfce0fa71703f469bb6d5030e41d67
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/quickcontrols2/quickcontrols2.pro | 3 | ||||
-rw-r--r-- | examples/quickcontrols2/sidepanel/doc/images/qtquickcontrols2-sidepanel-landscape.png | bin | 0 -> 58907 bytes | |||
-rw-r--r-- | examples/quickcontrols2/sidepanel/doc/images/qtquickcontrols2-sidepanel-portrait.png | bin | 0 -> 32492 bytes | |||
-rw-r--r-- | examples/quickcontrols2/sidepanel/doc/src/qtquickcontrols2-sidepanel.qdoc | 81 | ||||
-rw-r--r-- | examples/quickcontrols2/sidepanel/images/qt-logo.png | bin | 0 -> 2695 bytes | |||
-rw-r--r-- | examples/quickcontrols2/sidepanel/images/qt-logo@2x.png | bin | 0 -> 5521 bytes | |||
-rw-r--r-- | examples/quickcontrols2/sidepanel/images/qt-logo@3x.png | bin | 0 -> 8166 bytes | |||
-rw-r--r-- | examples/quickcontrols2/sidepanel/images/qt-logo@4x.png | bin | 0 -> 11600 bytes | |||
-rw-r--r-- | examples/quickcontrols2/sidepanel/sidepanel.cpp | 55 | ||||
-rw-r--r-- | examples/quickcontrols2/sidepanel/sidepanel.pro | 13 | ||||
-rw-r--r-- | examples/quickcontrols2/sidepanel/sidepanel.qml | 170 |
11 files changed, 321 insertions, 1 deletions
diff --git a/examples/quickcontrols2/quickcontrols2.pro b/examples/quickcontrols2/quickcontrols2.pro index 458d10db..f8548ec8 100644 --- a/examples/quickcontrols2/quickcontrols2.pro +++ b/examples/quickcontrols2/quickcontrols2.pro @@ -3,4 +3,5 @@ SUBDIRS += \ gallery \ chattutorial \ texteditor \ - contactlist + contactlist \ + sidepanel diff --git a/examples/quickcontrols2/sidepanel/doc/images/qtquickcontrols2-sidepanel-landscape.png b/examples/quickcontrols2/sidepanel/doc/images/qtquickcontrols2-sidepanel-landscape.png Binary files differnew file mode 100644 index 00000000..73ad4307 --- /dev/null +++ b/examples/quickcontrols2/sidepanel/doc/images/qtquickcontrols2-sidepanel-landscape.png diff --git a/examples/quickcontrols2/sidepanel/doc/images/qtquickcontrols2-sidepanel-portrait.png b/examples/quickcontrols2/sidepanel/doc/images/qtquickcontrols2-sidepanel-portrait.png Binary files differnew file mode 100644 index 00000000..ad23add5 --- /dev/null +++ b/examples/quickcontrols2/sidepanel/doc/images/qtquickcontrols2-sidepanel-portrait.png diff --git a/examples/quickcontrols2/sidepanel/doc/src/qtquickcontrols2-sidepanel.qdoc b/examples/quickcontrols2/sidepanel/doc/src/qtquickcontrols2-sidepanel.qdoc new file mode 100644 index 00000000..822b25a4 --- /dev/null +++ b/examples/quickcontrols2/sidepanel/doc/src/qtquickcontrols2-sidepanel.qdoc @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example sidepanel + \title Qt Quick Controls 2 - Side Panel + \ingroup qtquickcontrols2-examples + \brief A non-closable persistent side panel with Drawer + + This example demonstrates how \l Drawer can be used as a non-closable + persistent side panel. + + \raw HTML + <div class="table"><table style="background:transparent; border:0px"> + <tr><td style="border:0px"> + \endraw + \image qtquickcontrols2-sidepanel-portrait.png + \caption An interactive Drawer in portrait mode + \raw HTML + </td><td style="border:0px"> + \endraw + \image qtquickcontrols2-sidepanel-landscape.png + \caption A non-interactive Drawer in landscape mode + \raw HTML + </td></tr> + </table></div> + \endraw + + When the application is in portrait mode, the drawer is an interactive + side panel that can be swiped open from the left edge. It appears on + top of the content, and blocks user interaction through its modal + background. When the application is in landscape mode, the drawer and + the content are laid out side by side. + + The current orientation of the application is determined by comparing + the width and height of the window: + + \snippet sidepanel/sidepanel.qml orientation + + This is used to specify whether the drawer is \l {Popup::}{modal} and + \l {Drawer::}{interactive}, and to configure its \l {Drawer::}{position} + and \l {Popup::visible}{visibility} accordingly. + + \quotefromfile sidepanel/sidepanel.qml + \skipto Drawer + \printline Drawer + \dots 8 + \codeline + \skipto modal + \printuntil visible + \dots 8 + \skipuntil ScrollIndicator + \skipuntil } + \printline } + + \include examples-run.qdocinc +*/ diff --git a/examples/quickcontrols2/sidepanel/images/qt-logo.png b/examples/quickcontrols2/sidepanel/images/qt-logo.png Binary files differnew file mode 100644 index 00000000..90e6f905 --- /dev/null +++ b/examples/quickcontrols2/sidepanel/images/qt-logo.png diff --git a/examples/quickcontrols2/sidepanel/images/qt-logo@2x.png b/examples/quickcontrols2/sidepanel/images/qt-logo@2x.png Binary files differnew file mode 100644 index 00000000..22d111ad --- /dev/null +++ b/examples/quickcontrols2/sidepanel/images/qt-logo@2x.png diff --git a/examples/quickcontrols2/sidepanel/images/qt-logo@3x.png b/examples/quickcontrols2/sidepanel/images/qt-logo@3x.png Binary files differnew file mode 100644 index 00000000..627746cd --- /dev/null +++ b/examples/quickcontrols2/sidepanel/images/qt-logo@3x.png diff --git a/examples/quickcontrols2/sidepanel/images/qt-logo@4x.png b/examples/quickcontrols2/sidepanel/images/qt-logo@4x.png Binary files differnew file mode 100644 index 00000000..dc62286d --- /dev/null +++ b/examples/quickcontrols2/sidepanel/images/qt-logo@4x.png diff --git a/examples/quickcontrols2/sidepanel/sidepanel.cpp b/examples/quickcontrols2/sidepanel/sidepanel.cpp new file mode 100644 index 00000000..acff3f34 --- /dev/null +++ b/examples/quickcontrols2/sidepanel/sidepanel.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl("qrc:/sidepanel.qml")); + if (engine.rootObjects().isEmpty()) + return -1; + + return app.exec(); +} diff --git a/examples/quickcontrols2/sidepanel/sidepanel.pro b/examples/quickcontrols2/sidepanel/sidepanel.pro new file mode 100644 index 00000000..e2fc4aff --- /dev/null +++ b/examples/quickcontrols2/sidepanel/sidepanel.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +TARGET = sidepanel +QT += quick + +SOURCES += \ + sidepanel.cpp + +RESOURCES += \ + sidepanel.qml \ + $$files(images/*.png) + +target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/sidepanel +INSTALLS += target diff --git a/examples/quickcontrols2/sidepanel/sidepanel.qml b/examples/quickcontrols2/sidepanel/sidepanel.qml new file mode 100644 index 00000000..d35356e3 --- /dev/null +++ b/examples/quickcontrols2/sidepanel/sidepanel.qml @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** 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.6 +import QtQuick.Controls 2.2 +import QtQuick.Controls.Material 2.2 + +ApplicationWindow { + id: window + width: 360 + height: 520 + visible: true + title: qsTr("Side Panel") + + //! [orientation] + readonly property bool inPortrait: window.width < window.height + //! [orientation] + + ToolBar { + id: overlayHeader + + z: 1 + width: parent.width + parent: window.overlay + + Label { + id: label + anchors.centerIn: parent + text: "Qt Quick Controls 2" + } + } + + Drawer { + id: drawer + + y: overlayHeader.height + width: window.width / 2 + height: window.height - overlayHeader.height + + modal: inPortrait + interactive: inPortrait + position: inPortrait ? 0 : 1 + visible: !inPortrait + + ListView { + id: listView + anchors.fill: parent + + headerPositioning: ListView.OverlayHeader + header: Pane { + id: header + z: 2 + width: parent.width + + contentHeight: logo.height + + Image { + id: logo + width: parent.width + source: "images/qt-logo.png" + fillMode: implicitWidth > width ? Image.PreserveAspectFit : Image.Pad + } + + MenuSeparator { + parent: header + width: parent.width + anchors.verticalCenter: parent.bottom + visible: !listView.atYBeginning + } + } + + footer: ItemDelegate { + id: footer + text: qsTr("Footer") + width: parent.width + + MenuSeparator { + parent: footer + width: parent.width + anchors.verticalCenter: parent.top + } + } + + model: 10 + + delegate: ItemDelegate { + text: qsTr("Title %1").arg(index + 1) + width: parent.width + } + + ScrollIndicator.vertical: ScrollIndicator { } + } + } + + Flickable { + id: flickable + + anchors.fill: parent + anchors.topMargin: overlayHeader.height + anchors.leftMargin: !inPortrait ? drawer.width : undefined + + topMargin: 20 + bottomMargin: 20 + contentHeight: column.height + + Column { + id: column + spacing: 20 + anchors.margins: 20 + anchors.left: parent.left + anchors.right: parent.right + + Label { + font.pixelSize: 22 + width: parent.width + elide: Label.ElideRight + horizontalAlignment: Qt.AlignHCenter + text: qsTr("Side Panel Example") + } + + Label { + width: parent.width + wrapMode: Label.WordWrap + text: qsTr("This example demonstrates how Drawer can be used as a non-closable persistent side panel.\n\n" + + "When the application is in portrait mode, the drawer is an interactive side panel that can " + + "be swiped open from the left edge. When the application is in landscape mode, the drawer " + + "and the content are laid out side by side.\n\nThe application is currently in %1 mode.").arg(inPortrait ? qsTr("portrait") : qsTr("landscape")) + } + } + + ScrollIndicator.vertical: ScrollIndicator { } + } +} |