2011-07-25 05:14:51 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2011-12-22 11:53:15 +01:00
|
|
|
/**Documented API
|
2011-10-31 05:49:21 +01:00
|
|
|
Inherits:
|
|
|
|
Item
|
|
|
|
|
2011-11-06 22:24:03 +01:00
|
|
|
Imports:
|
2011-10-31 05:49:21 +01:00
|
|
|
QtQuick 1.0
|
|
|
|
org.kde.plasma.core
|
|
|
|
|
|
|
|
Description:
|
|
|
|
It is a simple progressBar which is using the plasma theme.
|
2011-12-19 17:47:42 +01:00
|
|
|
Some operations take a period of time to be performed and the user needs a confirmation that the operation is still ongoing. If the user does not get any confirmation, they might suspect that they did something wrong or that the device has broken. A progress bar is one of available mechanisms for providing this reassurance to the user.
|
2011-10-31 05:49:21 +01:00
|
|
|
|
|
|
|
Properties:
|
2011-12-19 17:47:42 +01:00
|
|
|
* real minimumValue:
|
|
|
|
Minimum Value for the progressBar
|
2011-10-31 05:49:21 +01:00
|
|
|
|
2011-12-19 17:47:42 +01:00
|
|
|
* real maximumValue:
|
|
|
|
Maximum value for the progressBar
|
2011-10-31 05:49:21 +01:00
|
|
|
|
2011-12-19 17:47:42 +01:00
|
|
|
real value:
|
|
|
|
Current value of the progressBar
|
2011-10-31 05:49:21 +01:00
|
|
|
|
2011-12-19 17:47:42 +01:00
|
|
|
* bool indeterminate:
|
|
|
|
Indicates whether the operation's duration is known or not. The property can have the following values:
|
|
|
|
true - the operation's duration is unknown, so the progress bar is animated. The value, minimum, and maximum properties are ignored.
|
|
|
|
false - the operation's duration is known, so the progress bar is drawn to indicate progress between the minimum and maximum values.
|
|
|
|
The default value is false.
|
2011-10-31 05:49:21 +01:00
|
|
|
|
2011-12-19 17:47:42 +01:00
|
|
|
* int orientation:
|
|
|
|
Orientation of the progressBar:
|
|
|
|
Qt.Horizontal or
|
|
|
|
Qt.Vertical
|
2011-10-31 05:49:21 +01:00
|
|
|
**/
|
|
|
|
|
2011-07-25 05:14:51 +02:00
|
|
|
import QtQuick 1.0
|
|
|
|
import org.kde.plasma.core 0.1 as PlasmaCore
|
2011-11-14 14:36:36 +01:00
|
|
|
import org.kde.qtextracomponents 0.1
|
2011-07-25 05:14:51 +02:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: progressBar
|
|
|
|
|
|
|
|
// Common API
|
|
|
|
property alias minimumValue: range.minimumValue
|
|
|
|
property alias maximumValue: range.maximumValue
|
|
|
|
property alias value: range.value
|
|
|
|
property alias indeterminate: indeterminateAnimation.running
|
|
|
|
|
|
|
|
// Plasma API
|
|
|
|
property int orientation: Qt.Horizontal
|
|
|
|
|
|
|
|
width: 100
|
|
|
|
height: 20
|
|
|
|
opacity: enabled ? 1.0 : 0.5
|
|
|
|
|
2011-09-13 21:21:29 +02:00
|
|
|
RangeModel {
|
2011-07-25 05:14:51 +02:00
|
|
|
id: range
|
|
|
|
|
|
|
|
// default values
|
|
|
|
minimumValue: 0.0
|
|
|
|
maximumValue: 1.0
|
|
|
|
value: 0
|
|
|
|
|
|
|
|
positionAtMinimum: 0
|
2012-05-28 14:46:51 +02:00
|
|
|
positionAtMaximum: backgroundPixmapItem.width
|
2011-07-25 05:14:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: contents
|
|
|
|
|
2011-11-14 14:36:36 +01:00
|
|
|
property bool _isVertical: orientation == Qt.Vertical
|
2012-08-10 18:42:16 +02:00
|
|
|
property int _tileWidth: width
|
2011-11-14 14:36:36 +01:00
|
|
|
|
2011-07-25 05:14:51 +02:00
|
|
|
width: _isVertical ? progressBar.height : progressBar.width
|
|
|
|
height: _isVertical ? progressBar.width : progressBar.height
|
|
|
|
rotation: _isVertical ? 90 : 0
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
2011-11-14 14:36:36 +01:00
|
|
|
Timer {
|
|
|
|
id: resizeTimer
|
|
|
|
repeat: false
|
|
|
|
interval: 0
|
|
|
|
running: false
|
|
|
|
onTriggered: {
|
2012-08-10 18:42:16 +02:00
|
|
|
contents._tileWidth = Math.floor(contents.width/(Math.floor(contents.width/(contents.height/1.6))))
|
|
|
|
|
|
|
|
|
2012-06-21 16:01:24 +02:00
|
|
|
if (barFrameSvg.hasElement("hint-bar-stretch")) {
|
|
|
|
barFrameSvg.resizeFrame(Qt.size(barPixmapItem.width, barPixmapItem.height))
|
|
|
|
} else {
|
2012-08-10 18:42:16 +02:00
|
|
|
barFrameSvg.resizeFrame(Qt.size(contents._tileWidth, contents.height))
|
2012-06-21 16:01:24 +02:00
|
|
|
}
|
2011-11-14 14:36:36 +01:00
|
|
|
barPixmapItem.pixmap = barFrameSvg.framePixmap()
|
2012-06-21 16:01:24 +02:00
|
|
|
|
|
|
|
if (backgroundFrameSvg.hasElement("hint-bar-stretch")) {
|
|
|
|
backgroundFrameSvg.resizeFrame(Qt.size(backgroundPixmapItem.width, backgroundPixmapItem.height))
|
|
|
|
} else {
|
2012-08-10 18:42:16 +02:00
|
|
|
backgroundFrameSvg.resizeFrame(Qt.size(contents._tileWidth, contents.height))
|
2012-06-21 16:01:24 +02:00
|
|
|
}
|
2011-11-14 14:36:36 +01:00
|
|
|
backgroundPixmapItem.pixmap = backgroundFrameSvg.framePixmap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PlasmaCore.FrameSvg {
|
|
|
|
id: barFrameSvg
|
|
|
|
Component.onCompleted: {
|
|
|
|
barFrameSvg.setImagePath("widgets/bar_meter_horizontal")
|
|
|
|
barFrameSvg.setElementPrefix("bar-active")
|
|
|
|
resizeTimer.restart()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PlasmaCore.FrameSvg {
|
|
|
|
id: backgroundFrameSvg
|
|
|
|
Component.onCompleted: {
|
|
|
|
backgroundFrameSvg.setImagePath("widgets/bar_meter_horizontal")
|
|
|
|
backgroundFrameSvg.setElementPrefix("bar-inactive")
|
|
|
|
resizeTimer.restart()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QPixmapItem {
|
|
|
|
id: backgroundPixmapItem
|
2012-08-10 18:16:26 +02:00
|
|
|
anchors.fill: parent
|
2012-08-10 18:42:16 +02:00
|
|
|
fillMode: QPixmapItem.TileHorizontally
|
2011-11-14 14:36:36 +01:00
|
|
|
onWidthChanged: resizeTimer.restart()
|
|
|
|
onHeightChanged: resizeTimer.restart()
|
2011-07-25 05:14:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-14 14:36:36 +01:00
|
|
|
QPixmapItem {
|
|
|
|
id: barPixmapItem
|
2012-08-10 18:42:16 +02:00
|
|
|
fillMode: QPixmapItem.TileHorizontally
|
|
|
|
width: indeterminate ? contents._tileWidth*2 : range.position
|
2011-07-25 05:14:51 +02:00
|
|
|
height: contents.height
|
2011-11-14 14:36:36 +01:00
|
|
|
|
2011-07-25 05:14:51 +02:00
|
|
|
visible: indeterminate || value > 0
|
2012-08-10 18:16:26 +02:00
|
|
|
onWidthChanged: resizeTimer.restart()
|
2012-08-16 01:51:17 +02:00
|
|
|
onHeightChanged: resizeTimer.restart()
|
2011-07-25 05:14:51 +02:00
|
|
|
|
|
|
|
SequentialAnimation {
|
|
|
|
id: indeterminateAnimation
|
|
|
|
|
|
|
|
loops: Animation.Infinite
|
|
|
|
|
2012-05-28 14:43:02 +02:00
|
|
|
onRunningChanged: {
|
|
|
|
if (!running) {
|
|
|
|
barPixmapItem.x = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-25 05:14:51 +02:00
|
|
|
PropertyAnimation {
|
2011-11-14 14:36:36 +01:00
|
|
|
target: barPixmapItem
|
2011-07-25 05:14:51 +02:00
|
|
|
property: "x"
|
|
|
|
duration: 800
|
|
|
|
to: 0
|
|
|
|
}
|
|
|
|
PropertyAnimation {
|
2011-11-14 14:36:36 +01:00
|
|
|
target: barPixmapItem
|
2011-07-25 05:14:51 +02:00
|
|
|
property: "x"
|
|
|
|
duration: 800
|
2011-11-14 14:36:36 +01:00
|
|
|
to: backgroundPixmapItem.width - barPixmapItem.width
|
2011-07-25 05:14:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|