aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-09-19 11:46:44 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-09-24 13:24:23 +0200
commitd2d0bfe830330f30913973a79c080d3cc5b00a21 (patch)
treeb711999dc4f93e2aa8dedfd104d6b87744a9ae01 /examples
parentcce0e1f9c27683292741310a730e21e36f123ae0 (diff)
Fix disappearing slider during size/orientation change
Now the slider remains at a position that is equivalent to the old position based on the previous percentage. This change is most commonly triggered during orientation changes on mobile device. That is the reason why the app was converted to a proper Qt project. This way it was possible to test this behavior on Android. Task-number: QTBUG-18423 Change-Id: If05e6a1e42249f90a821c4882021d28cf212fc52 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/quick/customitems/dialcontrol/dialcontrol.pro11
-rw-r--r--examples/quick/customitems/dialcontrol/dialcontrol.qml19
-rw-r--r--examples/quick/customitems/dialcontrol/dialcontrol.qrc12
-rw-r--r--examples/quick/customitems/dialcontrol/main.cpp41
4 files changed, 80 insertions, 3 deletions
diff --git a/examples/quick/customitems/dialcontrol/dialcontrol.pro b/examples/quick/customitems/dialcontrol/dialcontrol.pro
new file mode 100644
index 0000000000..ceb8e239dc
--- /dev/null
+++ b/examples/quick/customitems/dialcontrol/dialcontrol.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = dialcontrol
+
+QT += quick qml
+
+SOURCES += main.cpp
+
+RESOURCES += dialcontrol.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/dialcontrol
+INSTALLS += target
diff --git a/examples/quick/customitems/dialcontrol/dialcontrol.qml b/examples/quick/customitems/dialcontrol/dialcontrol.qml
index f545877655..0bf6d7e68c 100644
--- a/examples/quick/customitems/dialcontrol/dialcontrol.qml
+++ b/examples/quick/customitems/dialcontrol/dialcontrol.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 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.
@@ -39,7 +39,8 @@
****************************************************************************/
//! [imports]
-import QtQuick 2.0
+import QtQuick 2.2
+import QtQuick.Window 2.1
import "content"
//! [imports]
@@ -53,12 +54,13 @@ Rectangle {
Dial {
id: dial
anchors.centerIn: parent
- value: slider.x * 100 / (container.width - 34)
+ value: slider.x * 100 / (container.width - 32)
}
//! [the dial in use]
Rectangle {
id: container
+ property int oldWidth: 0
anchors { bottom: parent.bottom; left: parent.left
right: parent.right; leftMargin: 20; rightMargin: 20
bottomMargin: 10
@@ -73,6 +75,17 @@ Rectangle {
GradientStop { position: 1.0; color: "white" }
}
+ onWidthChanged: {
+ if (oldWidth === 0) {
+ oldWidth = width;
+ return
+ }
+
+ var desiredPercent = slider.x * 100 / (oldWidth - 32)
+ slider.x = desiredPercent * (width - 32) / 100
+ oldWidth = width
+ }
+
Rectangle {
id: slider
x: 1; y: 1; width: 30; height: 14
diff --git a/examples/quick/customitems/dialcontrol/dialcontrol.qrc b/examples/quick/customitems/dialcontrol/dialcontrol.qrc
new file mode 100644
index 0000000000..6433d68bb8
--- /dev/null
+++ b/examples/quick/customitems/dialcontrol/dialcontrol.qrc
@@ -0,0 +1,12 @@
+<RCC>
+ <qresource prefix="/">
+ <file>dialcontrol.qml</file>
+ <file>content/background.png</file>
+ <file>content/Dial.qml</file>
+ <file>content/needle_shadow.png</file>
+ <file>content/needle.png</file>
+ <file>content/overlay.png</file>
+ <file>content/quit.png</file>
+ <file>content/QuitButton.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/customitems/dialcontrol/main.cpp b/examples/quick/customitems/dialcontrol/main.cpp
new file mode 100644
index 0000000000..c72251cde7
--- /dev/null
+++ b/examples/quick/customitems/dialcontrol/main.cpp
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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(dialcontrol)