Warning, /plasma/plasma-mobile/components/mobileshell/qml/homescreen/HomeScreen.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2021-2023 Devin Lin <devin@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 import QtQuick 0005 import QtQuick.Window 0006 0007 import org.kde.plasma.plasmoid 0008 import org.kde.taskmanager as TaskManager 0009 0010 import org.kde.plasma.private.mobileshell as MobileShell 0011 import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings 0012 import org.kde.plasma.private.mobileshell.state as MobileShellState 0013 import org.kde.plasma.private.mobileshell.windowplugin as WindowPlugin 0014 0015 /** 0016 * The base homescreen component, implementing features that simplify 0017 * homescreen implementation. 0018 */ 0019 0020 Item { 0021 id: root 0022 0023 /** 0024 * Emitted when an action is triggered to open the homescreen. 0025 */ 0026 signal homeTriggered() 0027 0028 /** 0029 * Emitted when resetting the homescreen position is requested. 0030 */ 0031 signal resetHomeScreenPosition() 0032 0033 /** 0034 * Emitted when moving the homescreen position is requested. 0035 */ 0036 signal requestRelativeScroll(var pos) 0037 0038 /** 0039 * The visual item that is the homescreen. 0040 */ 0041 property alias contentItem: itemContainer.contentItem 0042 0043 /** 0044 * Whether a component is being shown on top of the homescreen within the same 0045 * window. 0046 */ 0047 readonly property bool overlayShown: startupFeedback.visible 0048 0049 /** 0050 * The root PlasmoidItem of the containment this is used into 0051 */ 0052 property PlasmoidItem plasmoidItem 0053 0054 /** 0055 * Margins for the homescreen, taking panels into account. 0056 */ 0057 property real topMargin 0058 property real bottomMargin 0059 property real leftMargin 0060 property real rightMargin 0061 0062 /** 0063 * The opacity value that the homescreen content gets. 0064 */ 0065 readonly property real contentOpacity: itemContainer.opacity 0066 0067 function evaluateMargins() { 0068 topMargin = plasmoidItem.availableScreenRect.y 0069 bottomMargin = root.height - (plasmoidItem.availableScreenRect.y + plasmoidItem.availableScreenRect.height) 0070 leftMargin = plasmoidItem.availableScreenRect.x 0071 rightMargin = root.width - (plasmoidItem.availableScreenRect.x + plasmoidItem.availableScreenRect.width) 0072 } 0073 0074 Connections { 0075 target: Plasmoid 0076 0077 // avoid binding loops with root.height and root.width changing along with the availableScreenRect 0078 function onAvailableScreenRectChanged() { 0079 Qt.callLater(() => root.evaluateMargins()); 0080 } 0081 } 0082 0083 //BEGIN API implementation 0084 0085 Connections { 0086 target: MobileShellState.ShellDBusClient 0087 0088 function onOpenHomeScreenRequested() { 0089 if (WindowPlugin.WindowMaximizedTracker.showingWindow) { 0090 itemContainer.zoomIn(); 0091 } 0092 0093 resetHomeScreenPosition(); 0094 0095 WindowPlugin.WindowUtil.unsetAllMinimizedGeometries(root); 0096 WindowPlugin.WindowUtil.minimizeAll(); 0097 0098 root.homeTriggered(); 0099 } 0100 0101 function onResetHomeScreenPositionRequested() { 0102 root.resetHomeScreenPosition(); 0103 } 0104 0105 function onOpenAppLaunchAnimationRequested(splashIcon, title, x, y, sourceIconSize) { 0106 startupFeedback.open(splashIcon, title, x, y, sourceIconSize); 0107 } 0108 0109 function onCloseAppLaunchAnimationRequested() { 0110 startupFeedback.close(); 0111 } 0112 0113 function onIsTaskSwitcherVisibleChanged() { 0114 if (MobileShellState.ShellDBusClient.isTaskSwitcherVisible) { 0115 itemContainer.zoomOutImmediately(); 0116 } else if (!WindowPlugin.WindowMaximizedTracker.showingWindow) { 0117 itemContainer.zoomIn(); 0118 } 0119 } 0120 } 0121 0122 //END API implementation 0123 0124 Connections { 0125 target: MobileShellState.LockscreenDBusClient 0126 0127 function onLockscreenLocked() { 0128 itemContainer.zoomOut(); 0129 } 0130 0131 function onLockscreenUnlocked() { 0132 // run zoom animation after login 0133 itemContainer.zoomIn(); 0134 } 0135 } 0136 0137 Component.onCompleted: { 0138 // determine the margins used 0139 evaluateMargins(); 0140 } 0141 0142 // homescreen visual component 0143 MobileShell.BaseItem { 0144 id: itemContainer 0145 anchors.fill: parent 0146 0147 // animations 0148 opacity: 0 0149 property real zoomScale: 1 0150 0151 readonly property real zoomScaleOut: 0.8 0152 0153 function zoomIn() { 0154 // don't use check animationsEnabled here, so we ensure the scale and opacity is always 1 when disabled 0155 scaleAnim.to = 1; 0156 scaleAnim.restart(); 0157 opacityAnim.to = 1; 0158 opacityAnim.restart(); 0159 } 0160 0161 function zoomOut() { 0162 scaleAnim.to = zoomScaleOut; 0163 scaleAnim.restart(); 0164 opacityAnim.to = 0; 0165 opacityAnim.restart(); 0166 } 0167 0168 function zoomOutImmediately() { 0169 scaleAnim.stop(); 0170 opacityAnim.stop(); 0171 zoomScale = zoomScaleOut; 0172 opacity = 0; 0173 } 0174 0175 NumberAnimation on opacity { 0176 id: opacityAnim 0177 duration: 300 0178 running: false 0179 } 0180 0181 NumberAnimation on zoomScale { 0182 id: scaleAnim 0183 duration: 600 0184 running: false 0185 easing.type: Easing.OutExpo 0186 } 0187 0188 function evaluateAnimChange() { 0189 // only animate if homescreen is visible 0190 if (!WindowPlugin.WindowMaximizedTracker.showingWindow && !MobileShellState.ShellDBusClient.isTaskSwitcherVisible) { 0191 itemContainer.zoomIn(); 0192 } else { 0193 itemContainer.zoomOut(); 0194 } 0195 } 0196 0197 Connections { 0198 target: WindowPlugin.WindowMaximizedTracker 0199 0200 function onShowingWindowChanged() { 0201 itemContainer.evaluateAnimChange(); 0202 } 0203 } 0204 0205 transform: Scale { 0206 origin.x: itemContainer.width / 2; 0207 origin.y: itemContainer.height / 2; 0208 xScale: itemContainer.zoomScale 0209 yScale: itemContainer.zoomScale 0210 } 0211 } 0212 0213 // start app animation component 0214 MobileShell.StartupFeedback { 0215 id: startupFeedback 0216 z: 999999 0217 anchors.fill: parent 0218 } 0219 }