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.

165 lines
5.7 KiB
QML
Raw Normal View History

/*
2021-03-01 20:03:25 +00:00
* SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
*
2021-03-01 20:03:25 +00:00
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
2019-09-04 16:39:31 +00:00
import QtQuick 2.12
2020-07-22 15:17:10 +00:00
import QtQuick.Window 2.12
2015-02-25 18:38:34 +00:00
import QtQuick.Layouts 1.1
2019-09-04 16:39:31 +00:00
import QtGraphicalEffects 1.0
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.draganddrop 2.0 as DragDrop
import org.kde.plasma.private.mobilehomescreencomponents 0.1 as HomeScreenComponents
2019-09-04 16:39:31 +00:00
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
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
property Item toolBox
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) / homeScreenContents.appletsLayout.cellWidth));
2015-06-20 23:08:46 +00:00
}
2019-09-04 16:39:31 +00:00
//END functions
2015-06-20 23:08:46 +00:00
2019-09-04 16:39:31 +00:00
property bool componentComplete: false
onWidthChanged: recalculateMaxFavoriteCount()
onHeightChanged:recalculateMaxFavoriteCount()
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();
2020-07-22 15:17:10 +00:00
if (plasmoid.screen == 0) {
MobileShell.HomeScreenControls.homeScreen = root
MobileShell.HomeScreenControls.homeScreenWindow = root.Window.window
}
2019-09-04 16:39:31 +00:00
componentComplete = true;
recalculateMaxFavoriteCount()
}
2020-07-22 15:17:10 +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
}
}
Connections {
property real lastRequestedPosition: 0
2020-07-22 15:17:10 +00:00
target: MobileShell.HomeScreenControls
function onResetHomeScreenPosition() {
mainFlickable.scrollToPage(0);
appDrawer.close();
2020-07-22 15:17:10 +00:00
}
function onSnapHomeScreenPosition() {
2021-04-13 12:03:05 +00:00
if (lastRequestedPosition < 0) {
appDrawer.open();
} else {
appDrawer.close();
}
}
2021-04-13 12:03:05 +00:00
function onRequestRelativeScroll(pos) {
appDrawer.offset -= pos.y;
lastRequestedPosition = pos.y;
}
2020-07-22 15:17:10 +00:00
}
HomeScreenComponents.FlickablePages {
2019-09-04 16:39:31 +00:00
id: mainFlickable
2019-09-04 16:39:31 +00:00
anchors {
fill: parent
topMargin: plasmoid.availableScreenRect.y
2021-04-12 13:38:11 +00:00
bottomMargin: plasmoid.screenGeometry.height - plasmoid.availableScreenRect.height - plasmoid.availableScreenRect.y
2015-03-18 14:45:48 +00:00
}
2020-08-13 09:17:06 +00:00
2021-04-08 16:57:20 +00:00
//TODO: favorite strip disappearing with everything else
footer: favoriteStrip
appletsLayout: homeScreenContents.appletsLayout
appDrawer: appDrawer
contentWidth: Math.max(width, width * Math.ceil(homeScreenContents.itemsBoundingRect.width/width)) + (homeScreenContents.launcherDragManager.active ? width : 0)
showAddPageIndicator: homeScreenContents.launcherDragManager.active
dragGestureEnabled: root.focus && appDrawer.status !== HomeScreenComponents.AppDrawer.Status.Open && !appletsLayout.editMode && !plasmoid.editMode && !homeScreenContents.launcherDragManager.active
HomeScreenComponents.HomeScreenContents {
id: homeScreenContents
width: mainFlickable.width * 100
favoriteStrip: favoriteStrip
2015-03-05 16:28:24 +00:00
}
}
2019-09-04 16:39:31 +00:00
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 (appDrawer.status !== HomeScreenComponents.AppDrawer.Status.Open) {
mainFlickable.currentIndex = 0
appDrawer.open()
} else {
plasmoid.nativeInterface.showingDesktop = false
appDrawer.close()
}
}
HomeScreenComponents.AppDrawer {
id: appDrawer
anchors.fill: parent
topPadding: plasmoid.availableScreenRect.y
2021-04-12 13:38:11 +00:00
bottomPadding: plasmoid.screenGeometry.height - plasmoid.availableScreenRect.height - plasmoid.availableScreenRect.y
rightPadding: plasmoid.screenGeometry.width - plasmoid.availableScreenRect.width - plasmoid.availableScreenRect.x
closedPositionOffset: favoriteStrip.height
2019-09-04 16:39:31 +00:00
}
HomeScreenComponents.FavoriteStrip {
2019-09-04 16:39:31 +00:00
id: favoriteStrip
2021-04-12 13:16:41 +00:00
appletsLayout: homeScreenContents.appletsLayout
visible: flow.children.length > 0 || homeScreenContents.launcherDragManager.active || homeScreenContents.containsDrag
opacity: homeScreenContents.launcherDragManager.active && HomeScreenComponents.ApplicationListModel.favoriteCount >= HomeScreenComponents.ApplicationListModel.maxFavoriteCount ? 0.3 : 1
TapHandler {
target: favoriteStrip
onTapped: {
//Hides icons close button
homeScreenContents.appletsLayout.appletsLayoutInteracted();
homeScreenContents.appletsLayout.editMode = false;
}
onLongPressed: homeScreenContents.appletsLayout.editMode = true;
onPressedChanged: root.focus = true;
}
2019-09-04 16:39:31 +00:00
}
}
2019-09-04 16:39:31 +00:00