on xenial help sign in
Add "rotate" button to tst_DragHandle
6982cb7Daniel d'Andrada
tests/qmltests/Components/tst_DragHandle.qml+71−56
@@ -29,62 +29,67 @@ import Ubuntu.Gestures 0.1
29 */
29 */
30Item {
30Item {
31 id: root
31 id: root
32− width: 700
32+ width: units.gu(70)
33− height: 500
33+ height: units.gu(70)
34
34
35 property var dragHandle
35 property var dragHandle
36
36
37 property bool stretch: false
37 property bool stretch: false
38 property real hintDisplacement: 0
38 property real hintDisplacement: 0
39
39
40− VerticalShowable {
40+ Item {
41− onDragHandleRecognizedGesture: { root.dragHandle = dragHandle }
41+ id: baseItem
42− stretch: root.stretch
42+ anchors.fill: parent
43− hintDisplacement: root.hintDisplacement
44− }
45−
46− HorizontalShowable {
47− onDragHandleRecognizedGesture: { root.dragHandle = dragHandle }
48− stretch: root.stretch
49− hintDisplacement: root.hintDisplacement
50− }
51
43
52− // Visually mark drag threshold
44+ VerticalShowable {
53− Rectangle {
45+ onDragHandleRecognizedGesture: { root.dragHandle = dragHandle }
54− color: "black"
46+ stretch: root.stretch
55− width: 2
47+ hintDisplacement: root.hintDisplacement
56− height: parent.height
48+ }
57
49
58− visible: dragHandle !== undefined && Direction.isHorizontal(dragHandle.direction)
50+ HorizontalShowable {
51+ onDragHandleRecognizedGesture: { root.dragHandle = dragHandle }
52+ stretch: root.stretch
53+ hintDisplacement: root.hintDisplacement
54+ }
59
55
56+ // Visually mark drag threshold
57+ Rectangle {
58+ color: "black"
59+ width: 2
60+ height: parent.height
61+
62+ visible: dragHandle !== undefined && Direction.isHorizontal(dragHandle.direction)
63+
60− x: {
64+ x: {
61− if (dragHandle) {
65+ if (dragHandle) {
62− if (dragHandle.direction === Direction.Rightwards) {
66+ if (dragHandle.direction === Direction.Rightwards) {
67+ dragHandle.edgeDragEvaluator.dragThreshold;
68+ } else {
63− dragHandle.edgeDragEvaluator.dragThreshold;
69+ parent.width - dragHandle.edgeDragEvaluator.dragThreshold;
70+ }
64 } else {
71 } else {
65− parent.width - dragHandle.edgeDragEvaluator.dragThreshold;
72+ 0
66 }
73 }
67− } else {
68− 0
69 }
74 }
70 }
75 }
71− }
72− Rectangle {
76+ Rectangle {
73− color: "black";
77+ color: "black";
74− height: 2
78+ height: 2
75− width: parent.width
79+ width: parent.width
76−
80+
77− visible: dragHandle !== undefined && Direction.isVertical(dragHandle.direction)
81+ visible: dragHandle !== undefined && Direction.isVertical(dragHandle.direction)
78−
82+
79− y: {
83+ y: {
80− if (dragHandle) {
84+ if (dragHandle) {
81− if (dragHandle.direction === Direction.Downwards) {
85+ if (dragHandle.direction === Direction.Downwards) {
86+ dragHandle.edgeDragEvaluator.dragThreshold;
87+ } else {
82− dragHandle.edgeDragEvaluator.dragThreshold;
88+ parent.height - dragHandle.edgeDragEvaluator.dragThreshold;
89+ }
83 } else {
90 } else {
84− parent.height - dragHandle.edgeDragEvaluator.dragThreshold;
91+ 0
85 }
92 }
86− } else {
87− 0
88 }
93 }
89 }
94 }
90 }
95 }
@@ -119,27 +124,37 @@ Item {
119 }
124 }
120 }
125 }
121
126
122− TestButton {
127+ Row {
123− id: stretchButton
124 anchors.bottom: parent.bottom
128 anchors.bottom: parent.bottom
125 anchors.left: parent.left
129 anchors.left: parent.left
126 anchors.margins: units.gu(1)
130 anchors.margins: units.gu(1)
131+ spacing: units.gu(1)
127
132
133+ Button {
134+ id: stretchButton
128− text: root.stretch ? "stretch" : "move"
135+ text: root.stretch ? "stretch" : "move"
129− onClicked: { root.stretch = !root.stretch; }
136+ onClicked: { root.stretch = !root.stretch; }
130− }
137+ }
131
138
132− TestButton {
139+ Button {
133− anchors.bottom: parent.bottom
140+ text: root.hintDisplacement > 0 ? "hint" : "no hint"
134− anchors.left: stretchButton.right
141+ onClicked: {
135− anchors.margins: units.gu(1)
142+ if (root.hintDisplacement > 0) {
143+ root.hintDisplacement = 0;
144+ } else {
145+ root.hintDisplacement = units.gu(6);
146+ }
147+ }
148+ }
136
149
137− text: root.hintDisplacement > 0 ? "hint" : "no hint"
150+ Button {
151+ text: "rotation: " + baseItem.rotation
138− onClicked: {
152+ onClicked: {
139− if (root.hintDisplacement > 0) {
153+ if (baseItem.rotation === 0.0) {
140− root.hintDisplacement = 0;
154+ baseItem.rotation = 90.0
141− } else {
155+ } else {
142− root.hintDisplacement = units.gu(6);
156+ baseItem.rotation = 0.0
157+ }
143 }
158 }
144 }
159 }
145 }
160 }
tests/qmltests/Components/tst_DragHandle/TestButton.qmldeleted−41
@@ -1,41 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−import Ubuntu.Components 0.1
19−
20−Rectangle {
21− id: rect
22− width: childrenRect.width
23− height: childrenRect.height
24−
25− property alias text: textComponent.text
26−
27− signal clicked
28−
29− color: "yellow"
30− Text {
31− id: textComponent
32− font.pixelSize: units.gu(2)
33− text: root.stretch ? "stretch" : "move"
34− MouseArea {
35− anchors.fill: parent
36− onClicked: {
37− rect.clicked()
38− }
39− }
40− }
41−}