Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/BusyIndicator.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2018 Oleg Chernovskiy <adonai@xaker.ru> 0003 SPDX-FileCopyrightText: 2018 The Qt Company Ltd. 0004 SPDX-FileCopyrightText: 2022 ivan tkachenko <me@ratijas.tk> 0005 0006 SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later 0007 */ 0008 0009 import QtQuick 2.15 0010 import QtQuick.Templates 2.15 as T 0011 import org.kde.kirigami 2.20 as Kirigami 0012 0013 T.BusyIndicator { 0014 id: control 0015 0016 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, 0017 implicitContentWidth + leftPadding + rightPadding) 0018 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, 0019 implicitContentHeight + topPadding + bottomPadding) 0020 0021 // BusyIndicator doesn't need padding since it has no background. 0022 // A Control containing a BusyIndicator can have padding instead 0023 // (e.g., a ToolBar, a Page or maybe a widget in a Plasma panel). 0024 padding: 0 0025 0026 hoverEnabled: false 0027 0028 contentItem: Item { 0029 /* Binding on `visible` implicitly takes care of `control.visible`, 0030 * `control.running` and `opacity > 0` at once. 0031 * Also, don't animate at all if the user has disabled animations. 0032 */ 0033 property bool animationRunning: visible && Kirigami.Units.longDuration > 1 0034 0035 /* implicitWidth and implicitHeight won't work unless they come 0036 * from a child of the contentItem. No idea why. 0037 */ 0038 implicitWidth: Kirigami.Units.gridUnit * 2 0039 implicitHeight: Kirigami.Units.gridUnit * 2 0040 0041 // We can't bind directly to opacity, as Animator won't update its value immediately. 0042 visible: control.running || opacityAnimator.running 0043 opacity: control.running ? 1 : 0 0044 Behavior on opacity { 0045 OpacityAnimator { 0046 id: opacityAnimator 0047 duration: Kirigami.Units.shortDuration 0048 easing.type: Easing.OutCubic 0049 } 0050 } 0051 0052 // sync all busy animations so they start at a common place in the rotation 0053 onAnimationRunningChanged: startOrStopAnimation(); 0054 0055 function startOrStopAnimation() { 0056 if (rotationAnimator.running === animationRunning) { 0057 return; 0058 } 0059 if (animationRunning) { 0060 const date = new Date; 0061 const ms = date.valueOf(); 0062 const startAngle = ((ms % rotationAnimator.duration) / rotationAnimator.duration) * 360; 0063 rotationAnimator.from = startAngle; 0064 rotationAnimator.to = startAngle + 360 0065 } 0066 rotationAnimator.running = animationRunning; 0067 } 0068 0069 Kirigami.Icon { 0070 /* Do not use `anchors.fill: parent` in here or else 0071 * the aspect ratio won't always be 1:1. 0072 */ 0073 anchors.centerIn: parent 0074 width: Math.min(parent.width, parent.height) 0075 height: width 0076 0077 source: "process-working-symbolic" 0078 smooth: true 0079 0080 RotationAnimator on rotation { 0081 id: rotationAnimator 0082 from: 0 0083 to: 360 0084 // Not using a standard duration value because we don't want the 0085 // animation to spin faster or slower based on the user's animation 0086 // scaling preferences; it doesn't make sense in this context 0087 duration: 2000 0088 loops: Animation.Infinite 0089 // Initially false, will be set as appropriate after 0090 // initialization. Can't be bound declaratively due to the 0091 // procedural nature of to/from adjustments: order of 0092 // assignments is crucial, as animator won't use new to/from 0093 // values while running. 0094 running: false 0095 } 0096 } 0097 0098 Component.onCompleted: startOrStopAnimation(); 0099 } 0100 }