mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-28 22:53:09 +00:00
kinda working again
This commit is contained in:
parent
6c8ae2501a
commit
2f0bc852ba
6 changed files with 91 additions and 273 deletions
|
|
@ -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<int, QByteArray> 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()<<m_applicationList[row].favorite;
|
||||
emit dataChanged(index(row, 0), index(row, 0));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,10 +60,12 @@ public:
|
|||
|
||||
enum Roles {
|
||||
ApplicationNameRole = Qt::UserRole + 1,
|
||||
ApplicationIconRole = Qt::UserRole + 2,
|
||||
ApplicationStorageIdRole = Qt::UserRole + 3,
|
||||
ApplicationEntryPathRole = Qt::UserRole + 4,
|
||||
ApplicationOriginalRowRole = Qt::UserRole + 6
|
||||
ApplicationIconRole,
|
||||
ApplicationStorageIdRole,
|
||||
ApplicationEntryPathRole,
|
||||
ApplicationOriginalRowRole,
|
||||
ApplicationFavoriteRole,
|
||||
ApplicationOnDesktopRole
|
||||
};
|
||||
|
||||
QStringList appOrder() const;
|
||||
|
|
|
|||
|
|
@ -25,31 +25,28 @@ import org.kde.plasma.core 2.0 as PlasmaCore
|
|||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||
import org.kde.kquickcontrolsaddons 2.0
|
||||
|
||||
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
|
||||
|
||||
Controls.Control {
|
||||
ContainmentLayoutManager.ItemContainer {
|
||||
id: delegate
|
||||
|
||||
z: dragging ? 1 : 0
|
||||
|
||||
property var modelData: typeof model !== "undefined" ? model : null
|
||||
property bool dragging
|
||||
property Controls.Control dragDelegate
|
||||
property ContainmentLayoutManager.ItemContainer dragDelegate
|
||||
|
||||
Drag.active: false
|
||||
Drag.hotSpot.x: delegate.width/2
|
||||
Drag.hotSpot.y: delegate.height/2
|
||||
Drag.mimeData: { "text/uri-list": modelData ? "file://" + modelData.ApplicationDesktopRole : "" }
|
||||
Drag.dragType: Drag.Automatic
|
||||
|
||||
leftPadding: units.smallSpacing*2
|
||||
topPadding: units.smallSpacing*2
|
||||
rightPadding: units.smallSpacing*2
|
||||
bottomPadding: units.smallSpacing*2
|
||||
leftPadding: units.smallSpacing * 2
|
||||
topPadding: units.smallSpacing * 2
|
||||
rightPadding: units.smallSpacing * 2
|
||||
bottomPadding: units.smallSpacing * 2
|
||||
|
||||
opacity: dragging ? 0.4 : 1
|
||||
|
||||
onDraggingChanged: {
|
||||
if (dragging) {
|
||||
var pos = dragDelegate.parent.mapFromItem(delegate, 0, 0);
|
||||
dragDelegate.parent = delegate.parent.parent;
|
||||
dragDelegate.x = delegate.x
|
||||
dragDelegate.y = delegate.y
|
||||
dragDelegate.modelData = model;
|
||||
|
|
@ -59,6 +56,7 @@ Controls.Control {
|
|||
root.reorderingApps = false;
|
||||
}
|
||||
}
|
||||
|
||||
contentItem: MouseArea {
|
||||
drag.target: dragging ? dragDelegate : null
|
||||
|
||||
|
|
@ -85,20 +83,13 @@ Controls.Control {
|
|||
return;
|
||||
}
|
||||
|
||||
if (dragDelegate.x + dragDelegate.width < 0
|
||||
|| dragDelegate.y + dragDelegate.height < 0
|
||||
|| dragDelegate.x > 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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,182 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue