From 2f0bc852baef342139731b483bdb39cac75a4c35 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 30 Jul 2019 12:20:21 +0200 Subject: [PATCH] kinda working again --- .../homescreen2/applicationlistmodel.cpp | 5 + .../homescreen2/applicationlistmodel.h | 10 +- .../package/contents/ui/launcher/Delegate.qml | 42 ++-- .../contents/ui/launcher/LauncherGrid.qml | 17 +- .../contents/ui/launcher/LauncherScroller.qml | 182 ------------------ .../homescreen2/package/contents/ui/main.qml | 108 ++++++----- 6 files changed, 91 insertions(+), 273 deletions(-) delete mode 100644 containments/homescreen2/package/contents/ui/launcher/LauncherScroller.qml diff --git a/containments/homescreen2/applicationlistmodel.cpp b/containments/homescreen2/applicationlistmodel.cpp index 20670807..8fb71751 100644 --- a/containments/homescreen2/applicationlistmodel.cpp +++ b/containments/homescreen2/applicationlistmodel.cpp @@ -43,6 +43,8 @@ ApplicationListModel::ApplicationListModel(QObject *parent) //can't use the new syntax as this signal is overloaded connect(KSycoca::self(), SIGNAL(databaseChanged(const QStringList &)), this, SLOT(sycocaDbChanged(const QStringList &))); + //here or delayed? + loadApplications(); } ApplicationListModel::~ApplicationListModel() @@ -56,6 +58,8 @@ QHash ApplicationListModel::roleNames() const roleNames[ApplicationStorageIdRole] = "ApplicationStorageIdRole"; roleNames[ApplicationEntryPathRole] = "ApplicationEntryPathRole"; roleNames[ApplicationOriginalRowRole] = "ApplicationOriginalRowRole"; + roleNames[ApplicationFavoriteRole] = "ApplicationFavoriteRole"; + roleNames[ApplicationOnDesktopRole] = "ApplicationOnDesktopRole"; return roleNames; } @@ -217,6 +221,7 @@ void ApplicationListModel::setFavoriteItem(int row, bool favorite) } data.favorite = favorite; +qWarning()< applicationsFlow.width - || dragDelegate.y > applicationsFlow.height) { - dragging = false; - delegate.grabToImage(function(result) { - root.externalDragStarted(); - delegate.Drag.imageSource = result.url; - delegate.Drag.active = true; - }) - return; - } + var newRow = 0; - var newRow = Math.round(applicationsFlow.width / dragDelegate.width) * Math.floor((dragDelegate.y+dragDelegate.height/2) / dragDelegate.height) + Math.floor((dragDelegate.x+dragDelegate.width/2) / dragDelegate.width); + if (favoriteStrip.contains(favoriteStrip.mapFromItem(dragDelegate, dragDelegate.width/2, dragDelegate.height/2))) { + newRow = Math.floor((dragDelegate.x + dragDelegate.width/2) / dragDelegate.width); + } else { + newRow = Math.round(applicationsFlow.width / dragDelegate.width) * Math.floor((dragDelegate.y + dragDelegate.height/2) / dragDelegate.height) + Math.floor((dragDelegate.x + dragDelegate.width/2) / dragDelegate.width) + favoriteStrip.count; + } plasmoid.nativeInterface.applicationListModel.moveItem(modelData.index, newRow); } @@ -106,6 +97,7 @@ Controls.Control { ColumnLayout { anchors.fill: parent spacing: 0 + PlasmaCore.IconItem { id: icon diff --git a/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml b/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml index bc841c59..04326910 100644 --- a/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml +++ b/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml @@ -39,6 +39,8 @@ Controls.Control { readonly property int cellWidth: applicationsFlow.width / Math.floor(applicationsFlow.width / ((availableCellHeight - reservedSpaceForLabel) + units.smallSpacing*4)) readonly property int cellHeight: availableCellHeight - topPadding + property FavoriteStrip favoriteStrip + signal externalDragStarted signal dragPositionChanged(point pos) @@ -53,19 +55,6 @@ Controls.Control { id: frame imagePath: "widgets/background" anchors.fill: parent - - Rectangle { - y: root.cellHeight + frame.margins.top - color: theme.textColor - opacity: 0.3 - height: 1 - anchors { - left: parent.left - right: parent.right - leftMargin: frame.margins.left - rightMargin: frame.margins.right - } - } } contentItem: Item { @@ -84,6 +73,7 @@ Controls.Control { width: root.cellWidth height: root.cellHeight onYChanged: dragPositionChanged(Qt.point(x, y)) + opacity: 1 visible: modelData !== null } @@ -120,6 +110,7 @@ Controls.Control { width: root.cellWidth height: root.cellHeight dragDelegate: dragDelegateItem + parent: index < favoriteStrip.count ? favoriteStrip.contentItem : applicationsFlow } } } diff --git a/containments/homescreen2/package/contents/ui/launcher/LauncherScroller.qml b/containments/homescreen2/package/contents/ui/launcher/LauncherScroller.qml deleted file mode 100644 index 33a228fe..00000000 --- a/containments/homescreen2/package/contents/ui/launcher/LauncherScroller.qml +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2019 Marco Martin - * - * 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 - -import org.kde.plasma.plasmoid 2.0 -import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.plasma.components 2.0 as PlasmaComponents -import org.kde.kquickcontrolsaddons 2.0 - - -MouseArea { - id: root - - property alias availableCellHeight: launcherGrid.availableCellHeight - property alias contentY: mainFlickable.contentY - property alias contentHeight: mainFlickable.contentHeight - property alias topMargin: mainFlickable.topMargin - property int leftPadding - property int rightPadding - signal movementEnded - signal externalDragStarted - - drag.filterChildren: true - - onClicked: closeAnim.restart() - -//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; - } -//END functions - - Timer { - id: autoScrollTimer - property bool scrollDown: true - repeat: true - interval: 1500 - onTriggered: { - //reordering launcher icons - if (launcherGrid.reorderingApps) { - 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); - - } else { - stopScroll(); - } - scrollAnim.running = true; - } - } - - NumberAnimation { - id: scrollAnim - target: mainFlickable - property: "contentY" - duration: units.longDuration - easing.type: Easing.InOutQuad - } - - PlasmaCore.Svg { - id: arrowsSvg - imagePath: "widgets/arrows" - } - PlasmaCore.SvgItem { - id: scrollUpIndicator - anchors { - horizontalCenter: parent.horizontalCenter - top: parent.top - topMargin: 300 - } - z: 2 - opacity: 0 - svg: arrowsSvg - elementId: "up-arrow" - width: units.iconSizes.large - height: width - Behavior on opacity { - OpacityAnimator { - duration: 1000 - easing.type: Easing.InOutQuad - } - } - } - PlasmaCore.SvgItem { - id: scrollDownIndicator - anchors { - horizontalCenter: parent.horizontalCenter - bottom: parent.bottom - bottomMargin: units.gridUnit * 2 - } - z: 2 - opacity: 0 - svg: arrowsSvg - elementId: "down-arrow" - width: units.iconSizes.large - height: width - Behavior on opacity { - OpacityAnimator { - duration: 1000 - easing.type: Easing.InOutQuad - } - } - } - - Flickable { - id: mainFlickable - anchors{ - fill: parent - leftMargin: root.leftPadding - rightMargin: root.rightPadding - } - contentWidth: width - contentHeight: launcherGrid.height - onMovementEnded: root.movementEnded(); - onFlickEnded: root.movementEnded(); - LauncherGrid { - id: launcherGrid - width: parent.width - onExternalDragStarted: root.externalDragStarted() - onDragPositionChanged: { - pos = mapToItem(root, pos.x, pos.y); - - if (pos.y < root.height /3) { - scrollUp(); - } else if (pos.y > root.height / 3 * 2) { - scrollDown(); - } else { - stopScroll(); - } - } - } - } - - PlasmaComponents.ScrollBar { - anchors { - top: parent.top - right: parent.right - bottom: parent.bottom - topMargin: Math.max(0, -mainFlickable.contentY) + units.smallSpacing*2 - rightMargin: root.rightPadding + units.smallSpacing * 2 - } - interactive: false - flickableItem: mainFlickable - } -} diff --git a/containments/homescreen2/package/contents/ui/main.qml b/containments/homescreen2/package/contents/ui/main.qml index f1ef4b5b..98d14f70 100644 --- a/containments/homescreen2/package/contents/ui/main.qml +++ b/containments/homescreen2/package/contents/ui/main.qml @@ -37,63 +37,66 @@ Item { property Item toolBox - DragDrop.DropArea { - anchors.fill: parent - - //TODO type safety? - property Item appletsArea - onDragEnter: { - event.accept(event.proposedAction); - } - onDragMove: { - appletsLayout.showPlaceHolderAt( - Qt.rect(event.x - appletsLayout.defaultItemWidth / 2, - event.y - appletsLayout.defaultItemHeight / 2, - appletsLayout.defaultItemWidth, - appletsLayout.defaultItemHeight) - ); - } - - onDragLeave: { - appletsLayout.hidePlaceHolder(); - } - - 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(); - } - Text { text:"Edit Mode" color: "white" visible: plasmoid.editMode } - Connections { - target: plasmoid - onEditModeChanged: { - appletsLayout.editMode = plasmoid.editMode - if (plasmoid.editMode) { - menuRepeater.freeLayout(); - } else { - menuRepeater.relayout(); - } + Connections { + target: plasmoid + onEditModeChanged: { + appletsLayout.editMode = plasmoid.editMode + if (plasmoid.editMode) { + menuRepeater.freeLayout(); + } else { + menuRepeater.relayout(); } } + } - Flickable { - anchors.fill: parent - contentWidth: width - contentHeight: appletsLayout.height - interactive: !plasmoid.editMode + Flickable { + id: mainFlickable + anchors.fill: parent + + bottomMargin: favoriteStrip.height + contentWidth: width + contentHeight: appletsLayout.height + interactive: !plasmoid.editMode + + DragDrop.DropArea { + width: parent.width + height: mainFlickable.height + launcher.height + + onDragEnter: { + event.accept(event.proposedAction); + } + onDragMove: { + appletsLayout.showPlaceHolderAt( + Qt.rect(event.x - appletsLayout.defaultItemWidth / 2, + event.y - appletsLayout.defaultItemHeight / 2, + appletsLayout.defaultItemWidth, + appletsLayout.defaultItemHeight) + ); + } + + onDragLeave: { + appletsLayout.hidePlaceHolder(); + } + + 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(); + } ContainmentLayoutManager.AppletsLayout { id: appletsLayout - width: parent.width - height: 500 + launcher.height + + anchors.fill: parent + configKey: width > height ? "ItemGeometries" : "ItemGeometriesVertical" containment: plasmoid editModeCondition: plasmoid.immutable @@ -131,6 +134,7 @@ Text { Launcher.LauncherGrid { id: launcher + favoriteStrip: favoriteStrip anchors { left: parent.left right: parent.right @@ -139,9 +143,15 @@ Text { } } } - Controls.Button { - text: "load" - onClicked: menuRepeater.model = plasmoid.nativeInterface.applicationListModel + } + Launcher.FavoriteStrip { + id: favoriteStrip + launcherGrid: launcher + anchors { + left: parent.left + right: parent.right + bottom: parent.bottom } } } +