Migrate BusyIndicator to QtQuick.Controls

Comes with a test for the seamless pause/resume

REVIEW: 121070
This commit is contained in:
Kai Uwe Broulik 2014-11-09 01:16:30 +01:00
parent 2c65e911e8
commit 65a6861476
3 changed files with 95 additions and 41 deletions

View File

@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2010 by Artur Duque de Souza <asouzakde.org> * Copyright (C) 2010 by Artur Duque de Souza <asouzakde.org>
* 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
@ -19,26 +20,17 @@
*/ */
import QtQuick 2.2 import QtQuick 2.2
import org.kde.plasma.core 2.0 as PlasmaCore import QtQuick.Controls 1.2
import "styles" as Styles
/** /**
* A simple busy indicator, * A simple busy indicator,
* It is used to indicate a task whose duration is unknown. If the task * It is used to indicate a task whose duration is unknown. If the task
* duration/number of steps is known, a ProgressBar should be used instead. * duration/number of steps is known, a ProgressBar should be used instead.
* *
* @inherit QtQuick.Item * @inherit QtQuick.Controls.BusyIndicator
*/ */
Item { BusyIndicator {
id: busy
/**
* This property holds whether the busy animation is running.
*
* The default value is false.
*/
property bool running: false
// Plasma API
/** /**
* Set this property if you don't want to apply a filter to smooth * Set this property if you don't want to apply a filter to smooth
* the busy icon while animating. * the busy icon while animating.
@ -51,33 +43,6 @@ Item {
implicitWidth: 52 implicitWidth: 52
implicitHeight: 52 implicitHeight: 52
// Should use animation's pause to keep the style: Styles.BusyIndicatorStyle {}
// rotation smooth when running changes but
// it has lot's of side effects on
// initialization.
onRunningChanged: {
rotationAnimation.from = rotation;
rotationAnimation.to = rotation + 360;
}
RotationAnimator on rotation {
id: rotationAnimation
from: 0
to: 360
duration: 1500
running: busy.running
loops: Animation.Infinite
}
PlasmaCore.SvgItem {
id: widget
svg: PlasmaCore.Svg { imagePath: "widgets/busywidget" }
elementId: "busywidget"
anchors.centerIn: parent
width: Math.min(busy.width, busy.height)
height: width
smooth: !running || smoothAnimation
}
} }

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2014 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 Library 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.2
import org.kde.plasma.core 2.0 as PlasmaCore
BusyIndicatorStyle {
indicator: PlasmaCore.SvgItem {
svg: PlasmaCore.Svg { imagePath: "widgets/busywidget" }
elementId: "busywidget"
anchors.centerIn: parent
width: Math.min(control.width, control.height)
height: width
smooth: !control.running || control.smoothAnimation
Connections {
target: control
onRunningChanged: {
rotationAnimator.from = rotation
rotationAnimator.to = rotation + 360
}
}
RotationAnimator on rotation {
id: rotationAnimator
from: 0
to: 360
duration: 1500
running: control.running
loops: Animation.Infinite
}
}
}

View File

@ -0,0 +1,37 @@
import QtQuick 2.0
import org.kde.plasma.components 2.0 as PlasmaComponents
Rectangle {
width: 600
height: 300
color: "white"
Column {
anchors.fill: parent
anchors.margins: 20
spacing: 20
PlasmaComponents.Label {
width: parent.width
wrapMode: Text.WordWrap
text: "When checking and unchecking the checkbox, " +
"the busy indicator should resume where it has " +
"paused and not glitch around"
}
Row {
spacing: 20
PlasmaComponents.BusyIndicator {
running: runningButton.checked
}
PlasmaComponents.CheckBox {
id: runningButton
text: "Running"
}
}
}
}