Package dialogs examples into a single executable
authorShawn Rutledge <shawn.rutledge@digia.com>
Mon, 27 May 2013 16:44:34 +0000 (18:44 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 28 May 2013 08:08:51 +0000 (10:08 +0200)
Introduced tabs and added the C++ boilerplate launcher.

Change-Id: Ibb49a182e3928aba5dced097d5307eb7d1f4b42d
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
12 files changed:
examples/quick/dialogs/ColorDialogs.qml
examples/quick/dialogs/FileDialogs.qml
examples/quick/dialogs/dialogs.pro [new file with mode: 0644]
examples/quick/dialogs/dialogs.qml [new file with mode: 0644]
examples/quick/dialogs/dialogs.qrc [new file with mode: 0644]
examples/quick/dialogs/main.cpp [new file with mode: 0644]
examples/quick/quick.pro
examples/quick/shared/TabSet.qml [new file with mode: 0644]
examples/quick/shared/images/tab.png [new file with mode: 0644]
examples/quick/shared/qmldir
examples/quick/shared/shared.h
examples/quick/shared/shared.qrc

index 7817c8e..f3d253a 100644 (file)
@@ -46,8 +46,8 @@ Rectangle {
     width: 320
     height: 200
     color: palette.window
-
     SystemPalette { id: palette }
+    clip: true
 
     ColorDialog {
         id: colorDialog
@@ -62,7 +62,7 @@ Rectangle {
 
     Column {
         anchors.fill: parent
-        anchors.margins: 8
+        anchors.margins: 12
         spacing: 8
         Text {
             font.bold: true
@@ -106,4 +106,38 @@ Rectangle {
             }
         }
     }
+
+    Rectangle {
+        anchors {
+            left: parent.left
+            right: parent.right
+            bottom: parent.bottom
+        }
+        height: 50
+        color: Qt.darker(palette.window, 1.1)
+        border.color: Qt.darker(palette.window, 1.3)
+        Row {
+            spacing: 6
+            anchors.verticalCenter: parent.verticalCenter
+            anchors.left: parent.left
+            anchors.leftMargin: 12
+            height: parent.height - 6
+            width: parent.width
+            Button {
+                text: "Open"
+                anchors.verticalCenter: parent.verticalCenter
+                onClicked: colorDialog.open()
+            }
+            Button {
+                text: "Close"
+                anchors.verticalCenter: parent.verticalCenter
+                onClicked: colorDialog.close()
+            }
+            Button {
+                text: "set to green"
+                anchors.verticalCenter: parent.verticalCenter
+                onClicked: colorDialog.color = "green"
+            }
+        }
+    }
 }
index a6df29b..8ed64b0 100644 (file)
@@ -43,43 +43,11 @@ import QtQuick.Dialogs 1.0
 import "../shared"
 
 Rectangle {
-
     width: 580
-    height: 360
+    height: 400
     color: palette.window
     SystemPalette { id: palette }
-
-    Rectangle {
-        id: toolbar
-        width: parent.width
-        height: 40
-        color: Qt.darker(palette.window, 1.1)
-        border.color: Qt.darker(palette.window, 1.3)
-        Row {
-            spacing: 6
-            anchors.verticalCenter: parent.verticalCenter
-            anchors.left: parent.left
-            anchors.leftMargin: 8
-            height: parent.height - 6
-            width: parent.width
-            Button {
-                text: "Open"
-                anchors.verticalCenter: parent.verticalCenter
-                onClicked: fileDialog.open()
-            }
-            Button {
-                text: "Close"
-                anchors.verticalCenter: parent.verticalCenter
-                onClicked: fileDialog.close()
-            }
-            Button {
-                text: "/tmp"
-                anchors.verticalCenter: parent.verticalCenter
-                // TODO: QTBUG-29814 This isn't portable, but we don't expose QDir::tempPath to QML yet.
-                onClicked: fileDialog.folder = "/tmp"
-            }
-        }
-    }
+    clip: true
 
     FileDialog {
         id: fileDialog
@@ -97,10 +65,8 @@ Rectangle {
     }
 
     Column {
-        anchors.left: parent.left
-        anchors.right: parent.right
-        anchors.top: toolbar.bottom
-        anchors.margins: 8
+        anchors.fill: parent
+        anchors.margins: 12
         spacing: 8
         Text {
             color: palette.windowText
@@ -163,4 +129,39 @@ Rectangle {
             wrapMode: Text.Wrap
         }
     }
+
+    Rectangle {
+        anchors {
+            left: parent.left
+            right: parent.right
+            bottom: parent.bottom
+        }
+        height: 50
+        color: Qt.darker(palette.window, 1.1)
+        border.color: Qt.darker(palette.window, 1.3)
+        Row {
+            spacing: 6
+            anchors.verticalCenter: parent.verticalCenter
+            anchors.left: parent.left
+            anchors.leftMargin: 12
+            height: parent.height - 6
+            width: parent.width
+            Button {
+                text: "Open"
+                anchors.verticalCenter: parent.verticalCenter
+                onClicked: fileDialog.open()
+            }
+            Button {
+                text: "Close"
+                anchors.verticalCenter: parent.verticalCenter
+                onClicked: fileDialog.close()
+            }
+            Button {
+                text: "go to /tmp"
+                anchors.verticalCenter: parent.verticalCenter
+                // TODO: QTBUG-29814 This isn't portable, but we don't expose QDir::tempPath to QML yet.
+                onClicked: fileDialog.folder = "/tmp"
+            }
+        }
+    }
 }
diff --git a/examples/quick/dialogs/dialogs.pro b/examples/quick/dialogs/dialogs.pro
new file mode 100644 (file)
index 0000000..b76f396
--- /dev/null
@@ -0,0 +1,17 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+RESOURCES += dialogs.qrc ../shared/shared.qrc
+
+OTHER_FILES += \
+    dialogs.qml \
+    FileDialogs.qml \
+    ColorDialogs.qml
+
+EXAMPLE_FILES = \
+    FileDialogs.qml \
+    ColorDialogs.qml
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/dialogs
+INSTALLS += target
diff --git a/examples/quick/dialogs/dialogs.qml b/examples/quick/dialogs/dialogs.qml
new file mode 100644 (file)
index 0000000..b5f9841
--- /dev/null
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc and its Subsidiary(-ies) 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 "../shared"
+
+TabSet {
+    width: 580
+    height: 440
+
+    FileDialogs {
+        property string title: "File Dialog"
+        anchors.fill: parent
+        color: "#e3e3e3" // to match tab.png
+    }
+
+    ColorDialogs {
+        property string title: "Color Dialog"
+        anchors.fill: parent
+        color: "#e3e3e3" // to match tab.png
+    }
+}
diff --git a/examples/quick/dialogs/dialogs.qrc b/examples/quick/dialogs/dialogs.qrc
new file mode 100644 (file)
index 0000000..efebfe4
--- /dev/null
@@ -0,0 +1,7 @@
+<RCC>
+    <qresource prefix="/dialogs">
+        <file>dialogs.qml</file>
+        <file>FileDialogs.qml</file>
+        <file>ColorDialogs.qml</file>
+    </qresource>
+</RCC>
diff --git a/examples/quick/dialogs/main.cpp b/examples/quick/dialogs/main.cpp
new file mode 100644 (file)
index 0000000..bbf0c48
--- /dev/null
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc and its Subsidiary(-ies) 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 "../shared/shared.h"
+DECLARATIVE_EXAMPLE_MAIN(dialogs/dialogs)
index 2d8acb3..311e264 100644 (file)
@@ -20,6 +20,7 @@ SUBDIRS = accessibility \
             customitems \
             imageprovider \
             window \
+            dialogs \
             particles \
             demos
 
diff --git a/examples/quick/shared/TabSet.qml b/examples/quick/shared/TabSet.qml
new file mode 100644 (file)
index 0000000..10263a7
--- /dev/null
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc and its Subsidiary(-ies) 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
+
+Item {
+    id: tabWidget
+
+    // Setting the default property to stack.children means any child items
+    // of the TabWidget are actually added to the 'stack' item's children.
+    // See the "Property Binding"
+    // documentation for details on default properties.
+    default property alias content: stack.children
+
+    property int current: 0
+
+    onCurrentChanged: setZOrders()
+    Component.onCompleted: setZOrders()
+
+    function setZOrders() {
+        for (var i = 0; i < stack.children.length; ++i)
+            stack.children[i].z = (i == current ? 1 : 0)
+    }
+
+    Row {
+        id: header
+
+        Repeater {
+            model: stack.children.length
+            delegate: Rectangle {
+                width: tabWidget.width / stack.children.length; height: 36
+
+                Rectangle {
+                    width: parent.width; height: 1
+                    anchors { bottom: parent.bottom; bottomMargin: 1 }
+                    color: "#acb2c2"
+                }
+                BorderImage {
+                    anchors { fill: parent; leftMargin: 2; topMargin: 5; rightMargin: 1 }
+                    border { left: 7; right: 7 }
+                    source: "images/tab.png"
+                    visible: tabWidget.current == index
+                }
+                Text {
+                    horizontalAlignment: Qt.AlignHCenter; verticalAlignment: Qt.AlignVCenter
+                    anchors.fill: parent
+                    text: stack.children[index].title
+                    elide: Text.ElideRight
+                    font.bold: tabWidget.current == index
+                }
+                MouseArea {
+                    anchors.fill: parent
+                    onClicked: tabWidget.current = index
+                }
+            }
+        }
+    }
+
+    Item {
+        id: stack
+        width: tabWidget.width
+        anchors.top: header.bottom; anchors.bottom: tabWidget.bottom
+    }
+}
diff --git a/examples/quick/shared/images/tab.png b/examples/quick/shared/images/tab.png
new file mode 100644 (file)
index 0000000..ad80216
Binary files /dev/null and b/examples/quick/shared/images/tab.png differ
index cc4eb3c..4f7c505 100644 (file)
@@ -3,3 +3,4 @@ CheckBox 2.1 CheckBox.qml
 LauncherList 2.0 LauncherList.qml
 SimpleLauncherDelegate 2.0 SimpleLauncherDelegate.qml
 Slider 2.0 Slider.qml
+TabSet 2.1 TabSet.qml
index eab15f3..c59e858 100644 (file)
@@ -47,9 +47,9 @@
     QQuickView view;\
     view.connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));\
     view.setSource(QUrl("qrc:///" #NAME ".qml")); \
+    view.setResizeMode(QQuickView::SizeRootObjectToView);\
     if (QGuiApplication::platformName() == QLatin1String("qnx") || \
           QGuiApplication::platformName() == QLatin1String("eglfs")) {\
-        view.setResizeMode(QQuickView::SizeRootObjectToView);\
         view.showFullScreen();\
     } else {\
         view.show();\
index 8912c17..6aaeca5 100644 (file)
@@ -6,9 +6,11 @@
         <file>Slider.qml</file>
         <file>images/slider_handle.png</file>
         <file>CheckBox.qml</file>
+        <file>TabSet.qml</file>
         <file>images/back.png</file>
         <file>images/next.png</file>
         <file>images/qt-logo.png</file>
         <file>images/checkmark.png</file>
+        <file>images/tab.png</file>
     </qresource>
 </RCC>