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.

240 lines
8.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.plasma.extras 2.0 as PlasmaExtra
2019-09-04 16:39:31 +00:00
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()
// ensure the gestures work immediately on load
forceActiveFocus();
}
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) {
root.appDrawer.open();
} else {
root.appDrawer.close();
}
}
2021-04-13 12:03:05 +00:00
function onRequestRelativeScroll(pos) {
root.appDrawer.offset -= pos.y;
2021-04-13 12:03:05 +00:00
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
appletsLayout: homeScreenContents.appletsLayout
appDrawer: root.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 || appDrawer.status !== HomeScreenComponents.AbstractAppDrawer.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
}
footer: HomeScreenComponents.FavoriteStrip {
id: favoriteStrip
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
// listview/gridview header
property int headerHeight: Math.round(PlasmaCore.Units.gridUnit * 3)
property string appDrawerType: "gridview" // gridview/listview
property alias appDrawer: appDrawerLoader.item
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
root.appDrawer.open()
} else {
plasmoid.nativeInterface.showingDesktop = false
root.appDrawer.close()
}
}
Component {
id: headerComponent
PlasmaCore.ColorScope {
colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
RowLayout {
anchors.topMargin: PlasmaCore.Units.smallSpacing
anchors.leftMargin: PlasmaCore.Units.largeSpacing
anchors.rightMargin: PlasmaCore.Units.largeSpacing
anchors.fill: parent
spacing: PlasmaCore.Units.smallSpacing
PlasmaExtra.Heading {
color: "white"
level: 1
text: i18n("Applications")
}
Item { Layout.fillWidth: true }
PlasmaComponents.ToolButton {
icon.name: "view-list-symbolic"
implicitWidth: Math.round(PlasmaCore.Units.gridUnit * 2.1)
implicitHeight: Math.round(PlasmaCore.Units.gridUnit * 2.1)
onClicked: {
if (root.appDrawerType !== "listview") {
root.appDrawerType = "listview";
appDrawer.flickable.goToBeginning(); // jump to top
}
}
}
PlasmaComponents.ToolButton {
icon.name: "view-grid-symbolic"
implicitWidth: Math.round(PlasmaCore.Units.gridUnit * 2.1)
implicitHeight: Math.round(PlasmaCore.Units.gridUnit * 2.1)
onClicked: {
if (root.appDrawerType !== "gridview") {
root.appDrawerType = "gridview";
appDrawer.flickable.goToBeginning(); // jump to top
}
}
}
}
}
2019-09-04 16:39:31 +00:00
}
Component {
id: listViewDrawer
HomeScreenComponents.ListViewAppDrawer {
anchors.fill: parent
topPadding: plasmoid.availableScreenRect.y
bottomPadding: plasmoid.screenGeometry.height - plasmoid.availableScreenRect.height - plasmoid.availableScreenRect.y
closedPositionOffset: favoriteStrip.height
headerItem: Loader {
sourceComponent: headerComponent
}
headerHeight: root.headerHeight
}
2019-09-04 16:39:31 +00:00
}
Component {
id: gridViewDrawer
HomeScreenComponents.GridViewAppDrawer {
anchors.fill: parent
topPadding: plasmoid.availableScreenRect.y
bottomPadding: plasmoid.screenGeometry.height - plasmoid.availableScreenRect.height - plasmoid.availableScreenRect.y
closedPositionOffset: favoriteStrip.height
headerItem: Loader {
sourceComponent: headerComponent
}
headerHeight: root.headerHeight
}
}
Loader {
id: appDrawerLoader
anchors.fill: parent
sourceComponent: appDrawerType === "gridview" ? gridViewDrawer : listViewDrawer
}
}
2019-09-04 16:39:31 +00:00