From 65a6861476610fc801d626ecf296a06ce2a5ee4b Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Sun, 9 Nov 2014 01:16:30 +0100 Subject: [PATCH] Migrate BusyIndicator to QtQuick.Controls Comes with a test for the seamless pause/resume REVIEW: 121070 --- .../plasmacomponents/qml/BusyIndicator.qml | 47 +++-------------- .../qml/styles/BusyIndicatorStyle.qml | 52 +++++++++++++++++++ tests/components/busyindicator.qml | 37 +++++++++++++ 3 files changed, 95 insertions(+), 41 deletions(-) create mode 100644 src/declarativeimports/plasmacomponents/qml/styles/BusyIndicatorStyle.qml create mode 100644 tests/components/busyindicator.qml diff --git a/src/declarativeimports/plasmacomponents/qml/BusyIndicator.qml b/src/declarativeimports/plasmacomponents/qml/BusyIndicator.qml index 61197ea67..39201bc3f 100644 --- a/src/declarativeimports/plasmacomponents/qml/BusyIndicator.qml +++ b/src/declarativeimports/plasmacomponents/qml/BusyIndicator.qml @@ -1,6 +1,7 @@ /* * Copyright (C) 2010 by Artur Duque de Souza * Copyright (C) 2011 by Daker Fernandes Pinheiro +* Copyright (C) 2014 by Kai Uwe Broulik * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -19,26 +20,17 @@ */ 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, * 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. * - * @inherit QtQuick.Item + * @inherit QtQuick.Controls.BusyIndicator */ -Item { - id: busy - - /** - * This property holds whether the busy animation is running. - * - * The default value is false. - */ - property bool running: false - - // Plasma API +BusyIndicator { /** * Set this property if you don't want to apply a filter to smooth * the busy icon while animating. @@ -51,33 +43,6 @@ Item { implicitWidth: 52 implicitHeight: 52 - // Should use animation's pause to keep the - // rotation smooth when running changes but - // it has lot's of side effects on - // initialization. - onRunningChanged: { - rotationAnimation.from = rotation; - rotationAnimation.to = rotation + 360; - } + style: Styles.BusyIndicatorStyle {} - 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 - } } diff --git a/src/declarativeimports/plasmacomponents/qml/styles/BusyIndicatorStyle.qml b/src/declarativeimports/plasmacomponents/qml/styles/BusyIndicatorStyle.qml new file mode 100644 index 000000000..3fb89f6d6 --- /dev/null +++ b/src/declarativeimports/plasmacomponents/qml/styles/BusyIndicatorStyle.qml @@ -0,0 +1,52 @@ +/* +* Copyright (C) 2014 Kai Uwe Broulik +* +* 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 + } + } +} diff --git a/tests/components/busyindicator.qml b/tests/components/busyindicator.qml new file mode 100644 index 000000000..7a38418b3 --- /dev/null +++ b/tests/components/busyindicator.qml @@ -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" + } + } + + } + +}