shift-shell/containments/homescreen/package/contents/ui/launcher/HomeDelegate.qml

220 lines
7.7 KiB
QML
Raw Normal View History

/*
* Copyright 2019 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
*/
import QtQuick 2.4
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.3 as Controls
2019-08-26 12:15:06 +00:00
import QtGraphicalEffects 1.6
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PC3
import org.kde.kquickcontrolsaddons 2.0
2019-07-30 10:20:21 +00:00
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
2019-08-22 14:59:30 +00:00
import org.kde.phone.homescreen 1.0
import "private" as Private
2019-07-30 10:20:21 +00:00
ContainmentLayoutManager.ItemContainer {
id: delegate
2019-08-30 09:07:31 +00:00
z: dragActive ? 1 : 0
property var modelData: typeof model !== "undefined" ? model : null
Layout.minimumWidth: appletsLayout.cellWidth
Layout.minimumHeight: appletsLayout.cellHeight
key: model.applicationUniqueId
property ContainmentLayoutManager.AppletsLayout appletsLayout
property int reservedSpaceForLabel
2019-08-22 11:14:28 +00:00
property real dragCenterX
property real dragCenterY
2020-02-11 15:14:54 +00:00
property alias iconItem: icon
2019-08-22 11:14:28 +00:00
editModeCondition: ContainmentLayoutManager.ItemContainer.AfterPressAndHold
2019-08-29 11:45:01 +00:00
2019-12-20 06:44:15 +00:00
signal launch(int x, int y, var source, string title)
function syncDelegateGeometry() {
if (!applicationRunning) {
return;
}
if (!MobileShell.HomeScreenControls.taskSwitcherVisible) {
plasmoid.nativeInterface.applicationListModel.setMinimizedDelegate(index, delegate);
} else {
plasmoid.nativeInterface.applicationListModel.unsetMinimizedDelegate(index, delegate);
}
}
readonly property bool applicationRunning: model.applicationRunning
onApplicationRunningChanged: {
syncDelegateGeometry();
}
Connections {
target: mainFlickable
function onCancelEditModeForItemsRequested() {
cancelEdit()
}
function onContentYChanged() {
syncDelegateGeometry()
}
}
Connections {
target: MobileShell.HomeScreenControls
function onTaskSwitcherVisibleChanged() {
syncDelegateGeometry();
}
}
Connections {
target: appletsLayout
function onAppletsLayoutInteracted() {
removeButton.hide();
}
}
2019-08-01 16:41:42 +00:00
onDragActiveChanged: {
2019-08-29 11:45:01 +00:00
launcherDragManager.active = dragActive
2019-08-01 16:41:42 +00:00
if (dragActive) {
2019-08-22 11:14:28 +00:00
// Must be 0, 0 as at this point dragCenterX and dragCenterY are on the drag before"
launcherDragManager.startDrag(delegate);
2019-08-27 15:12:32 +00:00
launcherDragManager.currentlyDraggedDelegate = delegate;
removeButton.show();
mouseArea.enabled = true;
2019-08-22 11:14:28 +00:00
} else {
launcherDragManager.dropItem(delegate, dragCenterX, dragCenterY);
2019-08-22 11:14:28 +00:00
plasmoid.editMode = false;
editMode = false;
plasmoid.fullRepresentationItem.stopScroll();
2019-08-27 15:12:32 +00:00
launcherDragManager.currentlyDraggedDelegate = null;
forceActiveFocus();
2019-08-01 16:41:42 +00:00
}
}
2019-07-30 10:20:21 +00:00
2019-08-01 16:41:42 +00:00
onUserDrag: {
2019-08-22 11:14:28 +00:00
dragCenterX = dragCenter.x;
dragCenterY = dragCenter.y;
2019-08-23 09:23:46 +00:00
launcherDragManager.dragItem(delegate, dragCenter.x, dragCenter.y);
delegate.width = appletsLayout.cellWidth;
delegate.height = appletsLayout.cellHeight;
2019-08-27 10:13:00 +00:00
var pos = plasmoid.fullRepresentationItem.mapFromItem(delegate, dragCenter.x, dragCenter.y);
//SCROLL LEFT
if (pos.x < plasmoid.availableScreenRect.x + units.gridUnit) {
plasmoid.fullRepresentationItem.scrollLeft();
//SCROLL RIGHT
} else if (pos.x > plasmoid.availableScreenRect.x + plasmoid.availableScreenRect.width - units.gridUnit) {
plasmoid.fullRepresentationItem.scrollRight();
//DON't SCROLL
} else {
plasmoid.fullRepresentationItem.stopScroll();
}
2019-08-01 16:41:42 +00:00
}
contentItem: MouseArea {
id: mouseArea
onClicked: {
if (modelData.applicationRunning) {
delegate.launch(0, 0, "", modelData.applicationName);
} else {
delegate.launch(delegate.x + (units.smallSpacing * 2), delegate.y + (units.smallSpacing * 2), icon.source, modelData.applicationName);
}
plasmoid.nativeInterface.applicationListModel.setMinimizedDelegate(index, delegate);
plasmoid.nativeInterface.applicationListModel.runApplication(modelData.applicationStorageId);
}
2019-10-10 11:56:35 +00:00
2019-09-18 13:00:34 +00:00
//preventStealing: true
ColumnLayout {
anchors {
fill: parent
leftMargin: units.smallSpacing * 2
topMargin: units.smallSpacing * 2
rightMargin: units.smallSpacing * 2
bottomMargin: units.smallSpacing * 2
}
spacing: 0
2019-07-30 10:20:21 +00:00
PlasmaCore.IconItem {
id: icon
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
Layout.fillWidth: true
Layout.minimumHeight: Math.min(units.iconSizes.large, parent.height - delegate.reservedSpaceForLabel)
2019-08-29 09:50:49 +00:00
Layout.preferredHeight: Layout.minimumHeight
usesPlasmaTheme: false
2020-03-20 00:58:46 +00:00
source: modelData ? modelData.applicationIcon : ""
Rectangle {
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
}
visible: model.applicationRunning
radius: width
width: units.smallSpacing
height: width
color: theme.highlightColor
}
//TODO: in loader?
Private.DelegateRemoveButton {
id: removeButton
}
}
PC3.Label {
id: label
visible: text.length > 0
Layout.fillWidth: true
Layout.preferredHeight: delegate.reservedSpaceForLabel
2019-10-14 14:10:08 +00:00
wrapMode: Text.WordWrap
Layout.alignment: Qt.AlignTop
2019-10-17 09:40:25 +00:00
Layout.leftMargin: -parent.anchors.leftMargin + units.smallSpacing
Layout.rightMargin: -parent.anchors.rightMargin + units.smallSpacing
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignTop
maximumLineCount: 2
2020-02-14 12:36:29 +00:00
elide: Text.ElideRight
2020-03-20 00:58:46 +00:00
text: model.applicationName
2020-02-14 12:36:29 +00:00
2019-10-09 14:21:46 +00:00
//FIXME: export smallestReadableFont
2019-10-17 09:40:25 +00:00
font.pointSize: theme.defaultFont.pointSize * 0.9
2020-03-20 00:58:46 +00:00
color: "white"//model.applicationLocation == ApplicationListModel.Desktop ? "white" : theme.textColor
2019-08-26 12:15:06 +00:00
2020-03-20 00:58:46 +00:00
layer.enabled: true//model.applicationLocation == ApplicationListModel.Desktop
2019-08-26 12:15:06 +00:00
layer.effect: DropShadow {
horizontalOffset: 0
verticalOffset: 2
radius: 8.0
samples: 16
cached: true
2020-02-06 15:56:02 +00:00
color: Qt.rgba(0, 0, 0, 1)
2019-08-26 12:15:06 +00:00
}
}
Item {Layout.fillHeight:true}
}
}
}