Debian Codegraph @

src/imports/Components/Themes/Ambiance/1.2/ProgressBarStyle.qml

raw
1 /*
2 * Copyright 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 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.2
19
20 Item {
21 id: progressBarStyle
22
23 property color foregroundColor: LomiriColors.orange
24 property color foregroundTextColor: '#FFFFFF'
25 property color backgroundColor: Theme.palette.normal.base
26 property color backgroundTextColor: Theme.palette.normal.baseText
27
28 property var progressBar: styledItem
29
30 implicitWidth: units.gu(38)
31 implicitHeight: units.gu(4)
32
33 LomiriShapeOverlay {
34 id: background
35 anchors.fill: parent
36 backgroundColor: progressBarStyle.backgroundColor
37 overlayColor: foregroundColor
38 overlayRect: Qt.application.layoutDirection == Qt.LeftToRight ?
39 Qt.rect(0.0, 0.0, progressBarStyle.progress, 1.0) :
40 Qt.rect(1.0 - progressBarStyle.progress, 0.0, 1.0, 1.0)
41 }
42
43 property real progress: progressBar.indeterminate ? 0.0
44 : progressBar.value / (progressBar.maximumValue - progressBar.minimumValue)
45
46 Label {
47 id: valueLabel
48 anchors.centerIn: background
49 fontSize: "medium"
50 color: backgroundTextColor
51 text: progressBar.indeterminate ? i18n.dtr("lomiri-ui-toolkit", "In Progress")
52 : "%1%".arg(Number(progressBarStyle.progress * 100.0).toFixed(0))
53 visible: !progressBar.hasOwnProperty("showProgressPercentage") || progressBar.showProgressPercentage
54
55 SequentialAnimation on opacity {
56 loops: Animation.Infinite
57 running: progressBar.indeterminate
58 LomiriNumberAnimation {
59 to: 0.2; duration: LomiriAnimation.BriskDuration
60 }
61 LomiriNumberAnimation {
62 to: 1.0; duration: LomiriAnimation.BriskDuration
63 }
64 }
65 }
66
67 PartialColorize {
68 anchors.fill: valueLabel
69 sourceItem: progressBar.indeterminate ? null : valueLabel
70 leftColor: foregroundTextColor
71 rightColor: backgroundTextColor
72 progress: (progressBarStyle.progress * background.width - valueLabel.x) / valueLabel.width
73 mirror: Qt.application.layoutDirection == Qt.RightToLeft
74 visible: !progressBar.hasOwnProperty("showProgressPercentage") || progressBar.showProgressPercentage
75 }
76 }