shift-shell/containments/homescreen/package/contents/ui/main.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

226 lines
6.8 KiB
QML
Raw Normal View History

/*
2021-03-01 20:03:25 +00:00
* SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
*
2021-03-01 20:03:25 +00:00
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.15
import QtQuick.Window 2.15
2015-02-25 18:38:34 +00:00
import QtQuick.Layouts 1.1
import org.kde.taskmanager 0.1 as TaskManager
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
2019-09-04 16:39:31 +00:00
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.private.mobilehomescreencomponents 0.1 as HomeScreenComponents
2020-07-22 15:17:10 +00:00
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
2021-03-18 17:34:37 +00:00
FocusScope {
id: root
2019-09-04 16:39:31 +00:00
width: 640
height: 480
2015-06-20 23:08:46 +00:00
//BEGIN functions
2015-07-09 11:29:26 +00:00
2019-09-04 16:39:31 +00:00
function recalculateMaxFavoriteCount() {
if (!componentComplete) {
return;
2015-10-15 13:26:23 +00:00
}
HomeScreenComponents.ApplicationListModel.maxFavoriteCount = Math.max(4, Math.floor(Math.min(width, height) / homescreen.homeScreenContents.favoriteStrip.cellWidth));
2015-06-20 23:08:46 +00:00
}
function triggerHomeScreen() {
MobileShell.HomeScreenControls.resetHomeScreenPosition();
taskSwitcher.visible = false; // will trigger homescreen open
2022-01-03 05:25:33 +00:00
searchWidget.close();
taskSwitcher.minimizeAll();
}
2019-09-04 16:39:31 +00:00
//END functions
2015-06-20 23:08:46 +00:00
//BEGIN API implementation
Connections {
target: MobileShell.HomeScreenControls
property real lastRequestedPosition: 0
function onOpenHomeScreen() {
root.triggerHomeScreen();
}
function onResetHomeScreenPosition() {
2021-12-31 02:11:21 +00:00
homescreen.homeScreenState.animateGoToPageIndex(0, PlasmaCore.Units.longDuration);
homescreen.homeScreenState.closeAppDrawer();
}
function onSnapHomeScreenPosition() {
if (lastRequestedPosition < 0) {
homescreen.homeScreenState.openAppDrawer();
} else {
homescreen.homeScreenState.closeAppDrawer();
}
}
function onRequestRelativeScroll(pos) {
// TODO
//homescreen.appDrawer.offset -= pos.y;
//lastRequestedPosition = pos.y;
}
function onOpenAppLaunchAnimation(splashIcon, title, x, y, sourceIconSize) {
startupFeedback.open(splashIcon, title, x, y, sourceIconSize);
}
function onCloseAppLaunchAnimation() {
startupFeedback.close();
}
2021-10-18 03:50:59 +00:00
}
Plasmoid.onScreenChanged: {
if (plasmoid.screen == 0) {
MobileShell.HomeScreenControls.taskSwitcher = taskSwitcher;
MobileShell.HomeScreenControls.homeScreenWindow = root.Window.window;
}
}
Window.onWindowChanged: {
if (plasmoid.screen == 0) {
MobileShell.HomeScreenControls.homeScreenWindow = root.Window.window;
}
}
2021-10-18 03:50:59 +00:00
//END API implementation
2019-09-04 16:39:31 +00:00
property bool componentComplete: false
onWidthChanged: recalculateMaxFavoriteCount()
onHeightChanged: recalculateMaxFavoriteCount()
2019-09-04 16:39:31 +00:00
Component.onCompleted: {
// ApplicationListModel doesn't have a plasmoid as is not the one that should be doing writing
HomeScreenComponents.ApplicationListModel.loadApplications();
HomeScreenComponents.FavoritesModel.applet = plasmoid;
HomeScreenComponents.FavoritesModel.loadApplications();
// set API variables
2020-07-22 15:17:10 +00:00
if (plasmoid.screen == 0) {
MobileShell.HomeScreenControls.taskSwitcher = taskSwitcher;
MobileShell.HomeScreenControls.homeScreenWindow = root.Window.window;
2020-07-22 15:17:10 +00:00
}
2019-09-04 16:39:31 +00:00
componentComplete = true;
recalculateMaxFavoriteCount()
// ensure the gestures work immediately on load
forceActiveFocus();
}
Plasmoid.onActivated: {
console.log("Triggered!", plasmoid.nativeInterface.showingDesktop)
// there's a couple of steps:
// - minimize windows
// - open app drawer
// - restore windows
if (!plasmoid.nativeInterface.showingDesktop) {
plasmoid.nativeInterface.showingDesktop = true;
} else if (homescreen.homeScreenState.currentView === MobileShell.HomeScreenState.PageView) {
homescreen.homeScreenState.openAppDrawer()
} else {
plasmoid.nativeInterface.showingDesktop = false
homescreen.homeScreenState.closeAppDrawer()
}
2019-09-04 16:39:31 +00:00
}
2022-01-03 05:25:33 +00:00
// control the opacity of both the search and homescreen components
property real homeScreenOpacity: 1
NumberAnimation on homeScreenOpacity {
id: opacityAnimation
duration: PlasmaCore.Units.longDuration
}
// homescreen component
HomeScreenComponents.HomeScreen {
id: homescreen
anchors.fill: parent
2022-01-03 05:25:33 +00:00
opacity: root.homeScreenOpacity * (1 - searchWidget.openFactor)
// make the homescreen not interactable when task switcher or startup feedback is on
interactive: !taskSwitcher.visible && !startupFeedback.visible
2022-01-03 05:25:33 +00:00
}
// search component
MobileShell.KRunnerWidget {
id: searchWidget
anchors.fill: parent
opacity: root.homeScreenOpacity
visible: openFactor > 0
}
Connections {
target: homescreen.homeScreenState
function onSwipeDownGestureBegin() {
searchWidget.startGesture();
}
function onSwipeDownGestureEnd() {
searchWidget.endGesture();
}
function onSwipeDownGestureOffset(offset) {
searchWidget.updateGestureOffset(-offset);
}
}
// task switcher component
TaskManager.VirtualDesktopInfo {
id: virtualDesktopInfo
}
TaskManager.ActivityInfo {
id: activityInfo
}
MobileShell.TaskSwitcher {
id: taskSwitcher
tasksModel: TaskManager.TasksModel {
groupMode: TaskManager.TasksModel.GroupDisabled
screenGeometry: plasmoid.screenGeometry
sortMode: TaskManager.TasksModel.SortAlpha
virtualDesktop: virtualDesktopInfo.currentDesktop
activity: activityInfo.currentActivity
}
anchors.fill: parent
// hide homescreen elements to make use of wallpaper
onVisibleChanged: {
if (visible) {
startupFeedback.visible = false;
// only animate if going from homescreen
if (taskSwitcher.wasInActiveTask) {
opacityAnimation.to = 0;
opacityAnimation.restart();
} else {
2022-01-03 05:25:33 +00:00
root.homeScreenOpacity = 0;
}
} else {
opacityAnimation.to = 1;
opacityAnimation.restart();
}
}
}
// start app animation component
MobileShell.StartupFeedback {
id: startupFeedback
anchors.fill: parent
}
}
2019-09-04 16:39:31 +00:00