@@ -1,119 +1,284 @@
1import QtQuick 2.0
1import QtQuick 2.0
2import Ubuntu.Components 1.1
2import Ubuntu.Components 1.1
3+import QtGraphicalEffects 1.0
5 id: swipeToAct
6 id: swipeToAct
7− width: parent.width
8+ width: parent.width
8− height: childrenRect.height
9+ height: childrenRect.height
10− property alias leftText: leftLabel.text
11− property alias rightText: rightLabel.text
13 signal leftTriggered()
11 signal leftTriggered()
14 signal rightTriggered()
12 signal rightTriggered()
16− readonly property double redH: 0.991
14+ readonly property double sliderHeight: 6
17− readonly property double redS: 0.892
15+ readonly property double gap: units.gu(1)
18− readonly property double redL: 0.563
19− readonly property double greenH: 0.386
20− readonly property double greenS: 1.0
21− readonly property double greenL: 0.316
16+ readonly property double halfWay: mouseArea.drag.maximumX / 2
22− readonly property double sliderHeight: 4
23− readonly property color lightGrey: "#eaeaea"
24− readonly property color black: "#000000"
25− readonly property color textColor: "#ffffff"
28− id: row
19+ id: gradient
20+ width: parent.width * 5
21+ height: units.gu(sliderHeight)
25+ start: Qt.point(parent.x, parent.y)
26+ end: Qt.point(parent.width, parent.y)
28+ GradientStop { position: 0.0; color: UbuntuColors.red }
29+ GradientStop { position: 0.2; color: UbuntuColors.red }
30+ GradientStop { position: 0.4; color: "#dddddd" }
31+ GradientStop { position: 0.6; color: "#dddddd" }
32+ GradientStop { position: 0.8; color: UbuntuColors.green }
33+ GradientStop { position: 1.0; color: UbuntuColors.green }
39+ id: effectSourceGradient
41+ width: gradient.width
42+ height: gradient.height
43+ sourceRect: Qt.rect(0.4 * gradient.width * (slider.x / halfWay), 0, mask.width, mask.height)
30 width: parent.width
51 width: parent.width
36− property double scale: width / ((row.width - slider.width) / 2)
37− color: Qt.hsla(redH, redS * (scale < 1.0 ? scale : 1.0), redL, 1.0)
38− opacity: scale < 1.0 ? scale : 1.0
40− height: units.gu(sliderHeight)
52+ height: units.gu(sliderHeight)
41− Label {
53+ borderSource: "none"
42− id: leftLabel
54+ visible: false
44− anchors.centerIn: parent
50− UbuntuShape {
57+ ShaderEffectSource {
51− id: slider
58+ id: effectSourceMask
53− Behavior on x {
66+ ShaderEffect {
54− id: xBehavior
67+ width: parent.width
68+ height: units.gu(sliderHeight)
69+ property variant mask: effectSourceMask
70+ property variant gradient: effectSourceGradient
72+ uniform highp mat4 qt_Matrix;
73+ attribute highp vec4 qt_Vertex;
74+ attribute highp vec2 qt_MultiTexCoord0;
75+ varying highp vec2 coord;
77+ coord = qt_MultiTexCoord0;
78+ gl_Position = qt_Matrix * qt_Vertex;
81+ varying highp vec2 coord;
82+ uniform sampler2D mask;
83+ uniform sampler2D gradient;
85+ lowp vec4 texMask = texture2D(mask, coord);
86+ lowp vec4 texGradient = texture2D(gradient, coord);
87+ gl_FragColor = texGradient.rgba * texMask.a ;
56− UbuntuNumberAnimation {
90+ Row {
57− duration: UbuntuAnimation.FastDuration
91+ id: row
58− easing.type: Easing.OutBounce
92+ anchors.fill: parent
103+ color: UbuntuColors.red
106+ target: innerLeftShape
107+ color: UbuntuColors.red
118+ target: innerLeftShape
119+ color: UbuntuColors.red
127+ borderSource: "none"
128+ opacity: slider.x <= halfWay ? 1.0 : 1.0 - ((slider.x - halfWay) / halfWay)
131+ anchors.centerIn: parent
132+ borderSource: "none"
133+ width: parent.width - units.gu(.5)
134+ height: parent.height - units.gu(.5)
137+ anchors.centerIn: parent
147+ width: (row.width - (leftShape.width + slider.width + rightShape.width + 4 * row.spacing)) / 2
62− onXChanged: {
152+ UbuntuShape {
63− if (x === 0.0) {
153+ id: slider
158+ UbuntuNumberAnimation {
159+ duration: UbuntuAnimation.FastDuration
160+ easing.type: Easing.OutBounce
66− if (x === row.width - slider.width) {
168+ if (x === row.width - slider.width) {
67− leftTriggered()
169+ rightTriggered()
72− x: (row.width - slider.width) / 2
74− height: units.gu(sliderHeight)
177+ borderSource: "none"
179+ anchors.fill: parent
181+ anchors.leftMargin: units.gu(.5)
182+ anchors.rightMargin: units.gu(.5)
184+ anchors.verticalCenter: parent.verticalCenter
190+ anchors.verticalCenter: parent.verticalCenter
200+ width: leftSpacer.width
78− UbuntuShape {
205+ UbuntuShape {
79− id: rightShape
206+ id: rightShape
81− property double scale: width / ((row.width - slider.width) / 2)
208+ State {
82− color: Qt.hsla(greenH, greenS * (scale < 1.0 ? scale : 1.0), greenL, 1.0)
209+ name: "normal"
83− opacity: scale < 1.0 ? scale : 1.0
210+ PropertyChanges {
84− x: slider.x + slider.width
211+ target: rightShape
85− width: row.width - (leftShape.width + slider.width)
212+ color: UbuntuColors.green
215+ target: innerRightShape
216+ color: UbuntuColors.green
227+ target: innerRightShape
228+ color: UbuntuColors.green
236+ borderSource: "none"
237+ opacity: slider.x >= halfWay ? 1.0 : slider.x / halfWay
240+ anchors.centerIn: parent
241+ borderSource: "none"
242+ width: parent.width - units.gu(.5)
86− height: units.gu(sliderHeight)
243+ height: parent.height - units.gu(.5)
88− id: rightLabel
245+ Icon {
90− anchors.centerIn: parent
246+ anchors.centerIn: parent
91− color: textColor
247+ width: units.gu(2)
92− fontSize: "medium"
248+ height: units.gu(2)
97− MouseArea {
255+ MouseArea {
98− id: mouseArea
256+ id: mouseArea
100− anchors.fill: row
258+ anchors.fill: row
101− drag.target: slider
259+ drag.target: slider
102− drag.axis: Drag.XAxis
260+ drag.axis: Drag.XAxis
103− drag.minimumX: 0
261+ drag.minimumX: 0
104− drag.maximumX: row.width - slider.width
262+ drag.maximumX: row.width - slider.width
106− onReleased: {
264+ onReleased: {
107− if (slider.x !== 0 || slider.x !== row.width - slider.width) {
265+ if (slider.x !== drag.minimumX || slider.x !== drag.maximumX) {
108− slider.x = (row.width - slider.width) / 2
266+ slider.x = halfWay
110− if (slider.x < units.gu(.5)) {
268+ if (slider.x === drag.minimumX) {
111− slider.x = 0
269+ slider.x = drag.minimumX
272+ leftShape.state = "selected"
113− if (slider.x > row.width - slider.width - units.gu(.5)) {
274+ if (slider.x === drag.maximumX) {
114− slider.x = row.width - slider.width
275+ slider.x = drag.maximumX
278+ rightShape.state = "selected"