| 1 |
/* |
| 2 |
* Copyright (C) 2016 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 version 3 as |
| 6 |
* published by the Free Software Foundation. |
| 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 |
* Authored-by: Florian Boucault <[email protected]> |
| 17 |
*/ |
| 18 |
import QtQuick 2.4 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
|
| 21 |
AbstractButton { |
| 22 |
id: stepper |
| 23 |
|
| 24 |
property color backgroundColor |
| 25 |
property color foregroundColor |
| 26 |
property color contourColor |
| 27 |
property color highlightColor |
| 28 |
property int counter |
| 29 |
property int layoutDirection: Qt.LeftToRight |
| 30 |
property bool active |
| 31 |
|
| 32 |
enabled: counter > 0 |
| 33 |
opacity: active ? 1.0 : 0.0 |
| 34 |
width: active ? row.width + row.anchors.leftMargin + row.anchors.rightMargin : 0 |
| 35 |
Behavior on opacity { |
| 36 |
LomiriNumberAnimation { duration: LomiriAnimation.FastDuration } |
| 37 |
} |
| 38 |
Behavior on width { |
| 39 |
LomiriNumberAnimation { duration: LomiriAnimation.FastDuration } |
| 40 |
} |
| 41 |
activeFocusOnPress: false |
| 42 |
|
| 43 |
Timer { |
| 44 |
id: repeatClickTimer |
| 45 |
interval: 100 |
| 46 |
running: stepper.pressed |
| 47 |
repeat: true |
| 48 |
onTriggered: stepper.clicked() |
| 49 |
} |
| 50 |
|
| 51 |
Rectangle { |
| 52 |
anchors { |
| 53 |
top: parent.top |
| 54 |
bottom: parent.bottom |
| 55 |
} |
| 56 |
width: stepper.width |
| 57 |
color: stepper.highlightColor |
| 58 |
visible: stepper.pressed |
| 59 |
opacity: visible ? 1.0 : 0.0 |
| 60 |
Behavior on opacity { |
| 61 |
LomiriNumberAnimation { duration: LomiriAnimation.FastDuration } |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
Row { |
| 66 |
id: row |
| 67 |
anchors { |
| 68 |
top: parent.top |
| 69 |
bottom: parent.bottom |
| 70 |
left: parent.left |
| 71 |
leftMargin: units.gu(1) |
| 72 |
} |
| 73 |
spacing: units.gu(1) |
| 74 |
LayoutMirroring.enabled: stepper.layoutDirection == Qt.RightToLeft |
| 75 |
LayoutMirroring.childrenInherit: true |
| 76 |
|
| 77 |
Icon { |
| 78 |
anchors.verticalCenter: parent.verticalCenter |
| 79 |
source: Qt.resolvedUrl("tab_stepper.png") |
| 80 |
color: enabled ? stepper.foregroundColor : stepper.contourColor |
| 81 |
scale: LayoutMirroring.enabled ? -1.0 : 1.0 |
| 82 |
asynchronous: true |
| 83 |
width: units.gu(1) |
| 84 |
} |
| 85 |
|
| 86 |
Label { |
| 87 |
anchors.verticalCenter: parent.verticalCenter |
| 88 |
textSize: Label.Small |
| 89 |
text: stepper.counter |
| 90 |
color: enabled ? stepper.foregroundColor : stepper.contourColor |
| 91 |
} |
| 92 |
|
| 93 |
Item { |
| 94 |
width: 1 |
| 95 |
height: 1 |
| 96 |
} |
| 97 |
} |
| 98 |
} |