Migrate ProgressBar to QtQuick.Controls

Test is enhanced to also cover vertical bars. The ProgressBar does not yet use
the vertical assets since Qt just conveniently rotates the bar for us and
apparently just overriding the entire "panel" component is evil

REVIEW: 121085
This commit is contained in:
Kai Uwe Broulik 2014-11-10 22:09:55 +01:00
parent a609b5a237
commit f54ff55bc5
3 changed files with 144 additions and 128 deletions

View File

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com> * Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com>
* Copyright (C) 2014 by Kai Uwe Broulik <kde@privat.broulik.de>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as * it under the terms of the GNU Library General Public License as
@ -18,9 +19,11 @@
*/ */
import QtQuick 2.1 import QtQuick 2.1
import QtQuick.Controls 1.1
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons 2.0 import "styles" as Styles
/** /**
* Simple progressBar using the plasma theme. * Simple progressBar using the plasma theme.
@ -31,120 +34,12 @@ import org.kde.kquickcontrolsaddons 2.0
* the device has broken. A progress bar is one of the available mechanisms for * the device has broken. A progress bar is one of the available mechanisms for
* providing this reassurance to the user. * providing this reassurance to the user.
* *
* @inherit QtQuick.Item * @inherit QtQuick.Controls.ProgressBar
*/ */
Item { ProgressBar {
id: progressBar width: Math.floor(units.gridUnit * (orientation === Qt.Vertical ? 1.6 : 10))
height: Math.floor(units.gridUnit * (orientation === Qt.Vertical ? 10 : 1.6))
// Common API
/** type:real Minimum value for the progressBar */
property alias minimumValue: range.minimumValue
/** type:real Maximum value for the progressBar */
property alias maximumValue: range.maximumValue
/** type:real Current value of the progressBar */
property alias value: range.value
/**
* type:bool
* 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.
*/
property alias indeterminate: indeterminateAnimation.running
// Plasma API
/**
* Orientation of the progressBar: Qt.Horizontal or Qt.Vertical
*/
property int orientation: Qt.Horizontal
width: Math.floor(units.gridUnit * (background._isVertical ? 1.6 : 10))
height: Math.floor(units.gridUnit * (background._isVertical ? 10 : 1.6))
opacity: enabled ? 1.0 : 0.5 opacity: enabled ? 1.0 : 0.5
PlasmaComponents.RangeModel { style: Styles.ProgressBarStyle {}
id: range
// default values
minimumValue: 0.0
maximumValue: 1.0
value: 0
positionAtMinimum: 0
positionAtMaximum: background._isVertical ? background.height : background.width
}
PlasmaCore.FrameSvgItem {
id: background
anchors.centerIn: parent
width: _isVertical ? barSvg.implicitWidth * Math.floor(units.devicePixelRatio) : parent.width
height: _isVertical ? parent.height : barSvg.implicitHeight * Math.floor(units.devicePixelRatio)
imagePath: barSvg.imagePath
prefix: "bar-inactive"
property bool _isVertical: orientation == Qt.Vertical
PlasmaCore.FrameSvgItem {
id: bar
anchors {
left: indeterminate && !background._isVertical ? undefined : parent.left
bottom: indeterminate && background._isVertical ? undefined : parent.bottom
right: background._isVertical ? parent.right : undefined
top: background._isVertical ? undefined : parent.top
}
imagePath: background.imagePath
prefix: "bar-active"
width: Math.max(margins.left + margins.right, (indeterminate ? units.gridUnit*2 : range.position))
height: Math.max(margins.top + margins.bottom, (indeterminate ? units.gridUnit*2 : range.position))
visible: indeterminate || range.position > 0
}
//this can't reference its parent because needs to be loaded before it,
//so never bind background to anything here
PlasmaCore.Svg {
id: barSvg
imagePath: orientation == Qt.Vertical ? "widgets/bar_meter_vertical" : "widgets/bar_meter_horizontal"
property int preferredWidth
property int preferredHeight
onRepaintNeeded: {
preferredWidth = barSvg.elementSize("hint-bar-size").width
preferredHeight = barSvg.elementSize("hint-bar-size").height
}
}
}
SequentialAnimation {
id: indeterminateAnimation
loops: Animation.Infinite
onRunningChanged: {
if (!running) {
barPixmapItem.x = 0
barPixmapItem.y = 0
}
}
PropertyAnimation {
target: bar
property: background._isVertical ? "y" : "x"
duration: 800
to: 0
}
PropertyAnimation {
target: bar
property: background._isVertical ? "y" : "x"
duration: 800
to: background._isVertical ? background.height - bar.height : background.width - bar.width
}
}
Accessible.role: Accessible.ProgressBar
} }

View File

@ -0,0 +1,93 @@
/*
* Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com>
* Copyright (C) 2014 by Kai Uwe Broulik <kde@privat.broulik.de>
*
* 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 2.010-1301, USA.
*/
import QtQuick 2.2
import QtQuick.Controls.Styles 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
ProgressBarStyle {
id: style
readonly property string imagePath: "widgets/bar_meter_horizontal"
readonly property real implicitHeight: barSvg.preferredHeight * Math.floor(units.devicePixelRatio)
PlasmaCore.Svg {
id: barSvg
imagePath: style.imagePath
property int preferredWidth
property int preferredHeight
onRepaintNeeded: {
preferredWidth = barSvg.elementSize("hint-bar-size").width
preferredHeight = barSvg.elementSize("hint-bar-size").height
}
}
background: Item {
PlasmaCore.FrameSvgItem {
anchors.centerIn: parent
width: parent.width
height: style.implicitHeight
imagePath: style.imagePath
prefix: "bar-inactive"
}
}
progress: Item {
PlasmaCore.FrameSvgItem {
id: progressSvg
anchors.verticalCenter: parent.verticalCenter
imagePath: style.imagePath
prefix: "bar-active"
width: control.indeterminate ? units.gridUnit * 2 : Math.max(margins.left + margins.right, parent.width)
height: style.implicitHeight
visible: control.indeterminate || currentProgress > 0
SequentialAnimation {
loops: Animation.Infinite
running: control.indeterminate && control.visible
onRunningChanged: {
if (!running) {
progressSvg.x = 0
}
}
PropertyAnimation {
target: progressSvg
property: "x"
duration: 800
// The progress Item's width might be left over from the previous state
// so we use the control.width/height directly instead
to: control.width - units.gridUnit * 2
}
PropertyAnimation {
target: progressSvg
property: "x"
duration: 800
to: 0
}
}
}
}
}

View File

@ -4,9 +4,12 @@ import org.kde.plasma.components 2.0 as PlasmaComponents
Rectangle { Rectangle {
id: root id: root
property int orientation: orientationCombo.model[orientationCombo.currentIndex].value
color: "white" color: "white"
width: 800 width: 900
height: 500 height: 600
Flow { Flow {
anchors.fill: parent anchors.fill: parent
@ -21,6 +24,7 @@ Rectangle {
minimumValue: 0 minimumValue: 0
maximumValue: 100 maximumValue: 100
value: 0 value: 0
orientation: root.orientation
} }
} }
@ -32,6 +36,7 @@ Rectangle {
minimumValue: 0 minimumValue: 0
maximumValue: 100 maximumValue: 100
value: 50 value: 50
orientation: root.orientation
} }
} }
@ -43,6 +48,7 @@ Rectangle {
minimumValue: 0 minimumValue: 0
maximumValue: 100 maximumValue: 100
value: 100 value: 100
orientation: root.orientation
} }
} }
@ -50,17 +56,23 @@ Rectangle {
Text { Text {
text: "these main bars should look the same width" text: "these main bars should look the same width"
} }
PlasmaComponents.ProgressBar { Flow {
width:100 PlasmaComponents.ProgressBar {
minimumValue: 0 width: orientation === Qt.Vertical ? undefined : 100
maximumValue: 100 height: orientation === Qt.Vertical ? 100 : undefined
value: 50 minimumValue: 0
} maximumValue: 100
PlasmaComponents.Slider { value: 50
width: 100 orientation: root.orientation
minimumValue: 0 }
maximumValue: 100 PlasmaComponents.Slider {
value: 50 width: orientation === Qt.Vertical ? undefined : 100
height: orientation === Qt.Vertical ? 100 : undefined
minimumValue: 0
maximumValue: 100
value: 50
orientation: root.orientation
}
} }
} }
@ -72,6 +84,7 @@ Rectangle {
minimumValue: 0 minimumValue: 0
maximumValue: 100 maximumValue: 100
value: 110 value: 110
orientation: root.orientation
} }
} }
@ -83,6 +96,7 @@ Rectangle {
minimumValue: -100 minimumValue: -100
maximumValue: 100 maximumValue: 100
value: 0 value: 0
orientation: root.orientation
} }
} }
@ -94,6 +108,7 @@ Rectangle {
minimumValue: 0 minimumValue: 0
maximumValue: 100 maximumValue: 100
value: -10 value: -10
orientation: root.orientation
} }
} }
@ -104,6 +119,7 @@ Rectangle {
PlasmaComponents.ProgressBar { PlasmaComponents.ProgressBar {
indeterminate: indeterminateCheckBox.checked indeterminate: indeterminateCheckBox.checked
value: 0.5 value: 0.5
orientation: root.orientation
} }
} }
@ -118,5 +134,17 @@ Rectangle {
} }
} }
Column {
Text {
text: "Slider orientation"
}
PlasmaComponents.ComboBox {
id: orientationCombo
model: [
{text: "Horizontal", value: Qt.Horizontal},
{text: "Vertical", value: Qt.Vertical}
]
}
}
} }
} }