2015-02-25 18:26:04 +00:00
|
|
|
/*
|
2021-03-01 20:03:25 +00:00
|
|
|
* SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
|
2021-12-25 01:17:08 +00:00
|
|
|
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
|
2015-02-25 18:26:04 +00:00
|
|
|
*
|
2021-03-01 20:03:25 +00:00
|
|
|
* SPDX-License-Identifier: LGPL-2.0-or-later
|
2015-02-25 18:26:04 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-12-25 01:17:08 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
import QtQuick.Window 2.15
|
2015-02-25 18:38:34 +00:00
|
|
|
import QtQuick.Layouts 1.1
|
2015-02-25 18:26:04 +00:00
|
|
|
|
|
|
|
|
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
|
2015-02-25 18:26:04 +00:00
|
|
|
|
2021-03-18 14:07:33 +00:00
|
|
|
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 {
|
2015-02-25 18:26:04 +00:00
|
|
|
id: root
|
2019-09-04 16:39:31 +00:00
|
|
|
width: 640
|
|
|
|
|
height: 480
|
2015-02-25 18:26:04 +00:00
|
|
|
|
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
|
|
|
}
|
2021-12-25 01:17:08 +00:00
|
|
|
HomeScreenComponents.ApplicationListModel.maxFavoriteCount = Math.max(4, Math.floor(Math.min(width, height) / homescreen.homeScreenContents.appletsLayout.cellWidth));
|
2015-06-20 23:08:46 +00:00
|
|
|
}
|
2021-02-15 10:44:48 +00:00
|
|
|
|
2019-09-04 16:39:31 +00:00
|
|
|
//END functions
|
2015-06-20 23:08:46 +00:00
|
|
|
|
2021-10-29 01:54:52 +00:00
|
|
|
//BEGIN API implementation
|
2021-10-29 00:11:01 +00:00
|
|
|
Connections {
|
|
|
|
|
target: MobileShell.HomeScreenControls
|
|
|
|
|
|
|
|
|
|
property real lastRequestedPosition: 0
|
2021-12-25 01:17:08 +00:00
|
|
|
|
2021-10-29 00:11:01 +00:00
|
|
|
function onResetHomeScreenPosition() {
|
2021-12-25 01:17:08 +00:00
|
|
|
homescreen.flickablePages.scrollToPage(0);
|
|
|
|
|
homescreen.appDrawer.close();
|
2021-10-29 00:11:01 +00:00
|
|
|
}
|
2021-12-25 01:17:08 +00:00
|
|
|
|
2021-10-29 00:11:01 +00:00
|
|
|
function onSnapHomeScreenPosition() {
|
|
|
|
|
if (lastRequestedPosition < 0) {
|
2021-12-25 01:17:08 +00:00
|
|
|
homescreen.appDrawer.open();
|
2021-10-29 00:11:01 +00:00
|
|
|
} else {
|
2021-12-25 01:17:08 +00:00
|
|
|
homescreen.appDrawer.close();
|
2021-10-29 00:11:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-25 01:17:08 +00:00
|
|
|
|
2021-10-29 00:11:01 +00:00
|
|
|
function onRequestRelativeScroll(pos) {
|
2021-12-25 01:17:08 +00:00
|
|
|
homescreen.appDrawer.offset -= pos.y;
|
2021-10-29 00:11:01 +00:00
|
|
|
lastRequestedPosition = pos.y;
|
|
|
|
|
}
|
2021-12-25 01:17:08 +00:00
|
|
|
|
2021-10-24 04:16:38 +00:00
|
|
|
function onHideHomeScreen(animate) {
|
|
|
|
|
if (animate) {
|
|
|
|
|
opacityAnimation.to = 0;
|
|
|
|
|
opacityAnimation.restart();
|
|
|
|
|
} else {
|
2021-12-25 01:17:08 +00:00
|
|
|
homescreen.opacity = 0;
|
2021-10-24 04:16:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-25 01:17:08 +00:00
|
|
|
|
2021-10-24 04:16:38 +00:00
|
|
|
function onShowHomeScreen(animate) {
|
|
|
|
|
if (animate) {
|
|
|
|
|
opacityAnimation.to = 1;
|
|
|
|
|
opacityAnimation.restart();
|
|
|
|
|
} else {
|
2021-12-25 01:17:08 +00:00
|
|
|
homescreen.opacity = 1;
|
2021-10-24 04:16:38 +00:00
|
|
|
}
|
2021-10-18 03:50:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-25 01:17:08 +00:00
|
|
|
|
|
|
|
|
Plasmoid.onScreenChanged: {
|
|
|
|
|
if (plasmoid.screen == 0) {
|
|
|
|
|
MobileShell.HomeScreenControls.homeScreen = root
|
|
|
|
|
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
|
|
|
|
2021-10-29 01:54:52 +00:00
|
|
|
//END API implementation
|
2021-10-29 00:11:01 +00:00
|
|
|
|
2019-09-04 16:39:31 +00:00
|
|
|
property bool componentComplete: false
|
|
|
|
|
onWidthChanged: recalculateMaxFavoriteCount()
|
2021-12-25 01:17:08 +00:00
|
|
|
onHeightChanged: recalculateMaxFavoriteCount()
|
2021-10-29 00:11:01 +00:00
|
|
|
|
2019-09-04 16:39:31 +00:00
|
|
|
Component.onCompleted: {
|
2021-03-18 14:07:33 +00:00
|
|
|
// 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();
|
|
|
|
|
|
2021-10-29 00:11:01 +00:00
|
|
|
// set API variables
|
2020-07-22 15:17:10 +00:00
|
|
|
if (plasmoid.screen == 0) {
|
2021-10-29 00:11:01 +00:00
|
|
|
MobileShell.HomeScreenControls.homeScreen = root;
|
|
|
|
|
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()
|
2021-10-18 18:56:37 +00:00
|
|
|
|
|
|
|
|
// ensure the gestures work immediately on load
|
|
|
|
|
forceActiveFocus();
|
2015-03-05 12:37:39 +00:00
|
|
|
}
|
2021-10-18 18:56:37 +00:00
|
|
|
|
2021-10-16 03:17:32 +00:00
|
|
|
Plasmoid.onActivated: {
|
|
|
|
|
console.log("Triggered!", plasmoid.nativeInterface.showingDesktop)
|
2021-12-25 01:17:08 +00:00
|
|
|
homescreen.activate();
|
2019-09-04 16:39:31 +00:00
|
|
|
}
|
2021-10-18 18:56:37 +00:00
|
|
|
|
2021-12-25 01:17:08 +00:00
|
|
|
HomeScreen {
|
|
|
|
|
id: homescreen
|
2021-10-18 18:56:37 +00:00
|
|
|
anchors.fill: parent
|
2021-12-25 01:17:08 +00:00
|
|
|
|
|
|
|
|
opacity: 1
|
|
|
|
|
NumberAnimation on opacity {
|
|
|
|
|
id: opacityAnimation
|
|
|
|
|
duration: PlasmaCore.Units.longDuration
|
|
|
|
|
}
|
2021-10-18 18:56:37 +00:00
|
|
|
}
|
2015-06-20 21:45:19 +00:00
|
|
|
}
|
2019-09-04 16:39:31 +00:00
|
|
|
|