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

348 lines
11 KiB
QML
Raw Normal View History

/*
2019-09-04 16:39:31 +00:00
* Copyright 2019 Marco Martin <mart@kde.org>
*
2019-09-04 16:39:31 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 or
* (at your option) any later version.
*
2019-09-04 16:39:31 +00:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details
*
2019-09-04 16:39:31 +00:00
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
2019-09-04 16:39:31 +00:00
import QtQuick 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
2019-09-04 16:39:31 +00:00
import "launcher" as Launcher
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
import org.kde.phone.homescreen 1.0
Item {
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
//Autoscroll related functions
function scrollUp() {
autoScrollTimer.scrollDown = false;
autoScrollTimer.running = true;
scrollUpIndicator.opacity = 1;
scrollDownIndicator.opacity = 0;
}
function scrollDown() {
autoScrollTimer.scrollDown = true;
autoScrollTimer.running = true;
scrollUpIndicator.opacity = 0;
scrollDownIndicator.opacity = 1;
}
function stopScroll() {
autoScrollTimer.running = false;
scrollUpIndicator.opacity = 0;
scrollDownIndicator.opacity = 0;
}
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
}
2020-07-21 10:35:50 +00:00
plasmoid.nativeInterface.applicationListModel.maxFavoriteCount = Math.max(4, Math.floor(Math.min(width, height) / launcher.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: {
componentComplete = true;
recalculateMaxFavoriteCount()
}
Timer {
id: autoScrollTimer
property bool scrollDown: true
repeat: true
2015-04-11 09:26:55 +00:00
interval: 1500
onTriggered: {
2019-09-04 16:39:31 +00:00
scrollAnim.to = scrollDown ?
//Scroll down
Math.min(mainFlickable.contentItem.height - root.height, mainFlickable.contentY + root.height/2) :
//Scroll up
Math.max(0, mainFlickable.contentY - root.height/2);
2015-04-11 09:26:55 +00:00
scrollAnim.running = true;
}
}
2019-09-04 16:39:31 +00:00
Connections {
target: plasmoid
onEditModeChanged: {
appletsLayout.editMode = plasmoid.editMode
}
}
2019-09-04 16:39:31 +00:00
Launcher.LauncherDragManager {
id: launcherDragManager
anchors.fill: parent
2019-09-04 16:39:31 +00:00
z: 2
appletsLayout: appletsLayout
launcherGrid: launcher
favoriteStrip: favoriteStrip
}
2019-09-04 16:39:31 +00:00
Flickable {
id: mainFlickable
width: parent.width
2020-02-06 15:56:02 +00:00
clip: true
2019-09-04 16:39:31 +00:00
anchors {
fill: parent
2020-02-05 19:25:52 +00:00
topMargin: plasmoid.availableScreenRect.y
2020-02-06 20:21:08 +00:00
bottomMargin: favoriteStrip.height + plasmoid.screenGeometry.height - plasmoid.availableScreenRect.height - plasmoid.availableScreenRect.y
2015-03-18 14:45:48 +00:00
}
2019-09-04 16:39:31 +00:00
2020-02-06 15:56:02 +00:00
//bottomMargin: favoriteStrip.height
2019-09-04 16:39:31 +00:00
contentWidth: width
contentHeight: flickableContents.height
interactive: !plasmoid.editMode && !launcherDragManager.active
signal cancelEditModeForItemsRequested
onDragStarted: cancelEditModeForItemsRequested()
onDragEnded: cancelEditModeForItemsRequested()
onFlickStarted: cancelEditModeForItemsRequested()
onFlickEnded: cancelEditModeForItemsRequested()
2019-09-04 16:39:31 +00:00
PlasmaComponents.ScrollBar.vertical: PlasmaComponents.ScrollBar {
id: scrollabr
opacity: mainFlickable.moving
interactive: false
enabled: false
2019-09-04 16:39:31 +00:00
Behavior on opacity {
OpacityAnimator {
duration: units.longDuration * 2
easing.type: Easing.InOutQuad
}
}
2015-04-11 09:26:55 +00:00
}
2019-09-04 16:39:31 +00:00
NumberAnimation {
id: scrollAnim
target: mainFlickable
properties: "contentY"
duration: units.longDuration
easing.type: Easing.InOutQuad
2015-04-11 09:26:55 +00:00
}
2019-09-04 16:39:31 +00:00
Column {
id: flickableContents
width: mainFlickable.width
2020-02-06 15:56:02 +00:00
spacing: 0
2015-04-11 09:26:55 +00:00
2019-09-04 16:39:31 +00:00
DragDrop.DropArea {
anchors {
left: parent.left
right: parent.right
}
2020-02-06 15:56:02 +00:00
height: mainFlickable.height //TODO: multiple widgets pages
2019-09-04 16:39:31 +00:00
onDragEnter: {
event.accept(event.proposedAction);
}
onDragMove: {
appletsLayout.showPlaceHolderAt(
Qt.rect(event.x - appletsLayout.defaultItemWidth / 2,
event.y - appletsLayout.defaultItemHeight / 2,
appletsLayout.defaultItemWidth,
appletsLayout.defaultItemHeight)
);
}
2019-09-04 16:39:31 +00:00
onDragLeave: {
appletsLayout.hidePlaceHolder();
}
2019-09-04 16:39:31 +00:00
preventStealing: true
onDrop: {
plasmoid.processMimeData(event.mimeData,
event.x - appletsLayout.placeHolder.width / 2, event.y - appletsLayout.placeHolder.height / 2);
event.accept(event.proposedAction);
appletsLayout.hidePlaceHolder();
}
2019-09-04 16:39:31 +00:00
PlasmaCore.Svg {
id: arrowsSvg
imagePath: "widgets/arrows"
colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
}
2019-09-04 16:39:31 +00:00
PlasmaCore.IconItem {
z: 9
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
2015-04-11 10:40:54 +00:00
}
2019-09-04 16:39:31 +00:00
source: "arrow-up"
width: units.iconSizes.medium
height: width
colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
2019-09-04 16:39:31 +00:00
MouseArea {
anchors {
fill: parent
margins: -units.smallSpacing
}
2019-09-04 16:39:31 +00:00
onClicked: mainFlickable.flick(0, -mainFlickable.height)
}
}
2015-02-25 18:38:34 +00:00
2019-09-04 16:39:31 +00:00
ContainmentLayoutManager.AppletsLayout {
id: appletsLayout
2019-09-04 16:39:31 +00:00
anchors.fill: parent
2015-03-05 15:53:58 +00:00
2019-09-04 16:39:31 +00:00
cellWidth: Math.floor(width / launcher.columns)
cellHeight: launcher.cellHeight
2015-03-11 12:10:43 +00:00
2019-09-04 16:39:31 +00:00
configKey: width > height ? "ItemGeometriesHorizontal" : "ItemGeometriesVertical"
containment: plasmoid
editModeCondition: plasmoid.immutable
? ContainmentLayoutManager.AppletsLayout.Manual
: ContainmentLayoutManager.AppletsLayout.AfterPressAndHold
// Sets the containment in edit mode when we go in edit mode as well
onEditModeChanged: plasmoid.editMode = editMode
minimumItemWidth: units.gridUnit * 3
minimumItemHeight: minimumItemWidth
defaultItemWidth: units.gridUnit * 6
defaultItemHeight: defaultItemWidth
//cellWidth: units.iconSizes.small
//cellHeight: cellWidth
acceptsAppletCallback: function(applet, x, y) {
print("Applet: "+applet+" "+x+" "+y)
return true;
}
2019-09-04 16:39:31 +00:00
appletContainerComponent: ContainmentLayoutManager.BasicAppletContainer {
id: appletContainer
configOverlayComponent: ConfigOverlay {}
onEditModeChanged: {
launcherDragManager.active = dragActive || editMode;
}
onDragActiveChanged: {
launcherDragManager.active = dragActive || editMode;
}
}
2019-09-04 16:39:31 +00:00
placeHolder: ContainmentLayoutManager.PlaceHolder {}
}
}
2015-03-13 13:58:18 +00:00
2019-09-04 16:39:31 +00:00
Launcher.LauncherGrid {
id: launcher
anchors {
2019-09-04 16:39:31 +00:00
left: parent.left
right: parent.right
2015-03-05 16:28:24 +00:00
}
2020-07-16 12:51:58 +00:00
onLaunched: {
scrollAnim.to = 0;
scrollAnim.restart();
}
2019-09-04 16:39:31 +00:00
favoriteStrip: favoriteStrip
appletsLayout: appletsLayout
2015-03-05 16:28:24 +00:00
}
}
}
2019-09-04 16:39:31 +00:00
ScrollIndicator {
id: scrollUpIndicator
anchors {
top: parent.top
topMargin: units.gridUnit * 2
}
elementId: "up-arrow"
}
ScrollIndicator {
id: scrollDownIndicator
anchors {
bottom: favoriteStrip.top
bottomMargin: units.gridUnit
}
elementId: "down-arrow"
}
2020-02-06 15:56:02 +00:00
Rectangle {
anchors {
left: parent.left
right: parent.right
bottom: favoriteStrip.top
leftMargin: units.gridUnit
rightMargin: units.gridUnit
}
height: 1
2020-02-08 10:30:28 +00:00
gradient: Gradient {
orientation: Gradient.Horizontal
GradientStop { position: 0.0; color: Qt.rgba(1, 1, 1, 0) }
GradientStop { position: 0.15; color: Qt.rgba(1, 1, 1, 0.5) }
GradientStop { position: 0.5; color: Qt.rgba(1, 1, 1, 1) }
GradientStop { position: 0.85; color: Qt.rgba(1, 1, 1, 0.5) }
GradientStop { position: 1.0; color: Qt.rgba(1, 1, 1, 0) }
}
2020-02-06 15:56:02 +00:00
opacity: mainFlickable.contentY > 0 ? 0.6 : 0
Behavior on opacity {
OpacityAnimator {
duration: units.longDuration * 2
easing.type: Easing.InOutQuad
}
}
}
2020-02-08 10:30:28 +00:00
MouseArea {
anchors.fill:favoriteStrip
property real oldMouseY
onPressed: oldMouseY = mouse.y
onPositionChanged: {
mainFlickable.contentY -= mouse.y - oldMouseY;
oldMouseY = mouse.y;
}
2020-07-22 13:18:52 +00:00
onReleased: {
mainFlickable.flick(0, 1)
}
}
2019-09-04 16:39:31 +00:00
Launcher.FavoriteStrip {
id: favoriteStrip
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
bottomMargin: plasmoid.screenGeometry.height - plasmoid.availableScreenRect.height - plasmoid.availableScreenRect.y
}
appletsLayout: appletsLayout
launcherGrid: launcher
//y: Math.max(krunner.inputHeight, root.height - height - mainFlickable.contentY)
}
}
2019-09-04 16:39:31 +00:00