| 1 |
/* |
| 2 |
* Copyright 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 Lesser 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 Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
import QtQuick 2.4 |
| 18 |
import Lomiri.Components 1.3 |
| 19 |
|
| 20 |
Rectangle { |
| 21 |
id: progressBarStyle |
| 22 |
|
| 23 |
property color foregroundColor: styledItem.enabled |
| 24 |
? theme.palette.normal.activity |
| 25 |
: theme.palette.disabled.activity |
| 26 |
color: styledItem.enabled |
| 27 |
? theme.palette.normal.base |
| 28 |
: theme.palette.disabled.base |
| 29 |
|
| 30 |
implicitWidth: units.gu(36) |
| 31 |
implicitHeight: units.gu(0.4) |
| 32 |
clip: true |
| 33 |
|
| 34 |
property real progress: styledItem.indeterminate ? 0.0 |
| 35 |
: styledItem.value / (styledItem.maximumValue - styledItem.minimumValue) |
| 36 |
|
| 37 |
Rectangle { |
| 38 |
id: strip |
| 39 |
anchors { |
| 40 |
top: parent.top |
| 41 |
left: !styledItem.indeterminate ? parent.left : undefined |
| 42 |
bottom: parent.bottom |
| 43 |
} |
| 44 |
color: foregroundColor |
| 45 |
width: styledItem.indeterminate |
| 46 |
? MathUtils.clamp(parent.width / 4, units.gu(1), units.gu(30)) |
| 47 |
: parent.width * progressBarStyle.progress |
| 48 |
|
| 49 |
property int duration: LomiriAnimation.SleepyDuration |
| 50 |
property int easing: Easing.InOutQuad |
| 51 |
readonly property bool animateStrip: |
| 52 |
styledItem.enabled && styledItem.visible |
| 53 |
&& styledItem.indeterminate |
| 54 |
// animate only after style completion! |
| 55 |
&& animated && !reverseAnimate |
| 56 |
property bool reverseAnimate: false |
| 57 |
|
| 58 |
NumberAnimation on width { |
| 59 |
duration: LomiriAnimation.SlowDuration |
| 60 |
easing.type: strip.easing |
| 61 |
running: !styledItem.indeterminate && styledItem.enabled && styledItem.visible |
| 62 |
} |
| 63 |
|
| 64 |
state: animateStrip ? "animate" : "" |
| 65 |
|
| 66 |
// reversible doesn't work, so we need animatiomns for both transitions |
| 67 |
// note: we cannot use XAnimator as there will be a point when |
| 68 |
// there will be two animators altering (running) the x property at the |
| 69 |
// same time, which causes SIGSEG |
| 70 |
transitions: [ |
| 71 |
Transition { |
| 72 |
from: "" |
| 73 |
to: "animate" |
| 74 |
SequentialAnimation { |
| 75 |
NumberAnimation { |
| 76 |
target: strip |
| 77 |
property: "x" |
| 78 |
duration: strip.duration |
| 79 |
easing.type: strip.easing |
| 80 |
from: -strip.width |
| 81 |
to: progressBarStyle.width |
| 82 |
} |
| 83 |
ScriptAction { script: strip.reverseAnimate = true; } |
| 84 |
} |
| 85 |
}, |
| 86 |
Transition { |
| 87 |
from: "animate" |
| 88 |
to: "" |
| 89 |
SequentialAnimation { |
| 90 |
NumberAnimation { |
| 91 |
target: strip |
| 92 |
property: "x" |
| 93 |
duration: strip.duration |
| 94 |
easing.type: strip.easing |
| 95 |
to: -strip.width |
| 96 |
from: progressBarStyle.width |
| 97 |
} |
| 98 |
ScriptAction { script: strip.reverseAnimate = false; } |
| 99 |
} |
| 100 |
} |
| 101 |
] |
| 102 |
} |
| 103 |
} |