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
0010 import QtQuick.Templates as T
0011 import org.kde.kirigami 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          * and don't animate when window is hidden (which somehow does not
0033          * affect items' visibility).
0034          */
0035         readonly property bool animationShouldBeRunning:
0036             visible
0037             && Window.visibility !== Window.Hidden
0038             && Kirigami.Units.longDuration > 1
0039 
0040         /* implicitWidth and implicitHeight won't work unless they come
0041          * from a child of the contentItem. No idea why.
0042          */
0043         implicitWidth: Kirigami.Units.gridUnit * 2
0044         implicitHeight: Kirigami.Units.gridUnit * 2
0045 
0046         // We can't bind directly to opacity, as Animator won't update its value immediately.
0047         visible: control.running || opacityAnimator.running
0048         opacity: control.running ? 1 : 0
0049         Behavior on opacity {
0050             OpacityAnimator {
0051                 id: opacityAnimator
0052                 duration: Kirigami.Units.shortDuration
0053                 easing.type: Easing.OutCubic
0054             }
0055         }
0056 
0057         // sync all busy animations such that they start at a common place in the rotation
0058         onAnimationShouldBeRunningChanged: startOrStopAnimation();
0059 
0060         function startOrStopAnimation() {
0061             if (rotationAnimator.running === animationShouldBeRunning) {
0062                 return;
0063             }
0064             if (animationShouldBeRunning) {
0065                 const date = new Date;
0066                 const ms = date.valueOf();
0067                 const startAngle = ((ms % rotationAnimator.duration) / rotationAnimator.duration) * 360;
0068                 rotationAnimator.from = startAngle;
0069                 rotationAnimator.to = startAngle + 360
0070             }
0071             rotationAnimator.running = animationShouldBeRunning;
0072         }
0073 
0074         Kirigami.Icon {
0075             /* Do not use `anchors.fill: parent` in here or else
0076              * the aspect ratio won't always be 1:1.
0077              */
0078             anchors.centerIn: parent
0079             width: Math.min(parent.width, parent.height)
0080             height: width
0081 
0082             source: "process-working-symbolic"
0083             smooth: true
0084 
0085             RotationAnimator on rotation {
0086                 id: rotationAnimator
0087                 from: 0
0088                 to: 360
0089                 // Not using a standard duration value because we don't want the
0090                 // animation to spin faster or slower based on the user's animation
0091                 // scaling preferences; it doesn't make sense in this context
0092                 duration: 2000
0093                 loops: Animation.Infinite
0094                 // Initially false, will be set as appropriate after
0095                 // initialization. Can't be bound declaratively due to the
0096                 // procedural nature of to/from adjustments: order of
0097                 // assignments is crucial, as animator won't use new to/from
0098                 // values while running.
0099                 running: false
0100             }
0101         }
0102 
0103         Component.onCompleted: startOrStopAnimation();
0104     }
0105 }