mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-28 22:53:09 +00:00
try a different approach to dragging
This commit is contained in:
parent
3bff5cea4b
commit
7ff227a13f
6 changed files with 113 additions and 43 deletions
|
|
@ -11,6 +11,7 @@ target_link_libraries(plasma_containment_phone_homescreen2
|
|||
Qt5::Gui
|
||||
KF5::Plasma
|
||||
Qt5::Qml
|
||||
Qt5::Quick
|
||||
KF5::I18n
|
||||
KF5::Service
|
||||
KF5::KIOWidgets
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <QtQml>
|
||||
#include <QDebug>
|
||||
#include <QQuickItem>
|
||||
|
||||
HomeScreen::HomeScreen(QObject *parent, const QVariantList &args)
|
||||
: Plasma::Containment(parent, args)
|
||||
|
|
@ -39,6 +40,16 @@ ApplicationListModel *HomeScreen::applicationListModel()
|
|||
return m_applicationListModel;
|
||||
}
|
||||
|
||||
void HomeScreen::orderItems(QQuickItem *item1, QQuickItem *item2)
|
||||
{
|
||||
if (!item1 || !item2 || item1->parentItem() != item2->parentItem()) {
|
||||
return;
|
||||
}
|
||||
|
||||
item1->stackBefore(item2);
|
||||
}
|
||||
|
||||
|
||||
K_EXPORT_PLASMA_APPLET_WITH_JSON(homescreen, HomeScreen, "metadata.json")
|
||||
|
||||
#include "homescreen.moc"
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <Plasma/Containment>
|
||||
|
||||
class QQuickItem;
|
||||
class ApplicationListModel;
|
||||
|
||||
class HomeScreen : public Plasma::Containment
|
||||
|
|
@ -37,6 +38,8 @@ public:
|
|||
|
||||
ApplicationListModel *applicationListModel();
|
||||
|
||||
Q_INVOKABLE void orderItems(QQuickItem *item1, QQuickItem *item2);
|
||||
|
||||
private:
|
||||
ApplicationListModel *m_applicationListModel;
|
||||
|
||||
|
|
|
|||
|
|
@ -33,8 +33,9 @@ ContainmentLayoutManager.ItemContainer {
|
|||
z: dragging ? 1 : 0
|
||||
|
||||
property var modelData: typeof model !== "undefined" ? model : null
|
||||
property bool dragging
|
||||
property ContainmentLayoutManager.ItemContainer dragDelegate
|
||||
property ContainmentLayoutManager.ItemContainer beforeItem
|
||||
property Item container
|
||||
property ContainmentLayoutManager.ItemContainer before
|
||||
|
||||
leftPadding: units.smallSpacing * 2
|
||||
topPadding: units.smallSpacing * 2
|
||||
|
|
@ -46,29 +47,29 @@ ContainmentLayoutManager.ItemContainer {
|
|||
editModeCondition: ContainmentLayoutManager.ItemContainer.AfterPressAndHold//model.ApplicationOnDesktopRole ? ContainmentLayoutManager.ItemContainer.AfterPressAndHold: ContainmentLayoutManager.ItemContainer.Manual
|
||||
onEditModeChanged: {//FIXME: remove
|
||||
plasmoid.editMode = editMode
|
||||
if (!editMode) {
|
||||
root.forceLayout();
|
||||
}
|
||||
}
|
||||
onDragActiveChanged: {
|
||||
if (dragActive) {
|
||||
if (container) {
|
||||
container.showSpacerBefore(delegate);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
plasmoid.editMode = false;
|
||||
editMode = false;
|
||||
launcher.forceLayout();
|
||||
favoriteStrip.forceLayout();
|
||||
if (container) {
|
||||
container.forceLayout();
|
||||
container.hideSpacer();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
root.reorderingApps = true;
|
||||
} else {
|
||||
dragDelegate.modelData = null;
|
||||
root.reorderingApps = false;
|
||||
onParentChanged: {
|
||||
if (container) {
|
||||
plasmoid.nativeInterface.orderItems(delegate, before);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,6 +81,7 @@ ContainmentLayoutManager.ItemContainer {
|
|||
if (favoriteStrip.contains(favoriteStrip.mapFromItem(delegate, dragCenter.x, dragCenter.y))) {
|
||||
var pos = favoriteStrip.mapFromItem(delegate, 0, 0);
|
||||
newRow = Math.floor((pos.x + dragCenter.x) / delegate.width);
|
||||
before = favoriteStrip.flow.childAt(delegate.x + dragCenter.x, delegate.y + dragCenter.y);
|
||||
|
||||
// Put it on desktop
|
||||
} else if (appletsLayout.contains(appletsLayout.mapFromItem(delegate, dragCenter.x, dragCenter.y))) {
|
||||
|
|
@ -87,17 +89,23 @@ ContainmentLayoutManager.ItemContainer {
|
|||
plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, true);
|
||||
delegate.x = pos.x
|
||||
delegate.y = pos.y
|
||||
before = null;
|
||||
return;
|
||||
|
||||
// Put it in the general view
|
||||
} else {
|
||||
newRow = Math.round(applicationsFlow.width / delegate.width) * Math.floor((delegate.y + dragCenter.y) / delegate.height) + Math.floor((delegate.x + dragCenter.x) / delegate.width) + favoriteStrip.count;
|
||||
before = applicationsFlow.childAt(delegate.x + dragCenter.x, delegate.y + dragCenter.y);
|
||||
}
|
||||
|
||||
plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, false);
|
||||
|
||||
plasmoid.nativeInterface.applicationListModel.moveItem(modelData.index, newRow);
|
||||
|
||||
if (container) {
|
||||
container.showSpacerBefore(before);
|
||||
}
|
||||
|
||||
//delegate.x = newPosition.x;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,12 +29,23 @@ import org.kde.kquickcontrolsaddons 2.0
|
|||
Controls.Control {
|
||||
id: root
|
||||
|
||||
property alias flow: applicationsFlow
|
||||
|
||||
property Controls.Control launcherGrid
|
||||
readonly property int count: applicationsFlow.width / launcherGrid.cellWidth
|
||||
|
||||
function forceLayout() {
|
||||
applicationsFlow.forceLayout();
|
||||
}
|
||||
|
||||
property Controls.Control launcherGrid
|
||||
readonly property int count: applicationsFlow.width / launcherGrid.cellWidth
|
||||
function showSpacerBefore(item) {
|
||||
spacer.parent = applicationsFlow
|
||||
plasmoid.nativeInterface.orderItems(spacer, item);
|
||||
}
|
||||
|
||||
function hideSpacer() {
|
||||
spacer.parent = flowParent;
|
||||
}
|
||||
|
||||
implicitHeight: applicationsFlow.implicitHeight + frame.margins.top + frame.margins.bottom
|
||||
|
||||
|
|
@ -49,16 +60,30 @@ Controls.Control {
|
|||
anchors.fill: parent
|
||||
}
|
||||
|
||||
contentItem: Flow {
|
||||
id: applicationsFlow
|
||||
contentItem: Item {
|
||||
id: flowParent
|
||||
|
||||
spacing: 0
|
||||
implicitWidth: applicationsFlow.implicitWidth
|
||||
implicitHeight: applicationsFlow.implicitHeight
|
||||
|
||||
move: Transition {
|
||||
NumberAnimation {
|
||||
duration: units.longDuration
|
||||
easing.type: Easing.InOutQuad
|
||||
properties: "x,y"
|
||||
Item {
|
||||
id: spacer
|
||||
width: units.gridUnit * 4
|
||||
height: width
|
||||
}
|
||||
|
||||
Flow {
|
||||
id: applicationsFlow
|
||||
anchors.fill: parent
|
||||
|
||||
spacing: 0
|
||||
|
||||
move: Transition {
|
||||
NumberAnimation {
|
||||
duration: units.longDuration
|
||||
easing.type: Easing.InOutQuad
|
||||
properties: "x,y"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,8 @@ import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutM
|
|||
Controls.Control {
|
||||
id: root
|
||||
|
||||
function forceLayout() {
|
||||
applicationsFlow.forceLayout();
|
||||
}
|
||||
property alias flow: applicationsFlow
|
||||
|
||||
readonly property bool dragging: applicationsFlow.dragData
|
||||
property bool reorderingApps: false
|
||||
|
||||
|
|
@ -49,6 +48,19 @@ Controls.Control {
|
|||
signal externalDragStarted
|
||||
signal dragPositionChanged(point pos)
|
||||
|
||||
function forceLayout() {
|
||||
applicationsFlow.forceLayout();
|
||||
}
|
||||
|
||||
function showSpacerBefore(item) {
|
||||
spacer.parent = applicationsFlow
|
||||
plasmoid.nativeInterface.orderItems(spacer, item);
|
||||
}
|
||||
|
||||
function hideSpacer() {
|
||||
spacer.parent = flowParent;
|
||||
}
|
||||
|
||||
implicitHeight: applicationsFlow.implicitHeight + frame.margins.top + frame.margins.bottom
|
||||
|
||||
leftPadding: frame.margins.left
|
||||
|
|
@ -63,6 +75,7 @@ Controls.Control {
|
|||
}
|
||||
|
||||
contentItem: Item {
|
||||
id: flowParent
|
||||
//NOTE: TextMetrics can't handle multi line
|
||||
Controls.Label {
|
||||
id: metrics
|
||||
|
|
@ -70,19 +83,12 @@ Controls.Control {
|
|||
visible: false
|
||||
}
|
||||
|
||||
//This Delegate is the placeholder for the "drag"
|
||||
//delegate (that is not actual drag and drop
|
||||
Delegate {
|
||||
id: dragDelegateItem
|
||||
z: 999
|
||||
width: root.cellWidth
|
||||
height: root.cellHeight
|
||||
onYChanged: dragPositionChanged(Qt.point(x, y))
|
||||
opacity: 1
|
||||
|
||||
visible: modelData !== null
|
||||
Item {
|
||||
id: spacer
|
||||
width: units.gridUnit * 4
|
||||
height: width
|
||||
visible:parent == applicationsFlow
|
||||
}
|
||||
|
||||
Flow {
|
||||
id: applicationsFlow
|
||||
anchors.fill: parent
|
||||
|
|
@ -114,15 +120,31 @@ Controls.Control {
|
|||
delegate: Delegate {
|
||||
width: root.cellWidth
|
||||
height: root.cellHeight
|
||||
dragDelegate: dragDelegateItem
|
||||
container: {
|
||||
if (model.ApplicationOnDesktopRole) {
|
||||
return null;
|
||||
}
|
||||
if (index < favoriteStrip.count) {
|
||||
return favoriteStrip;
|
||||
}
|
||||
return root;
|
||||
}
|
||||
parent: {
|
||||
if (model.ApplicationOnDesktopRole) {
|
||||
return appletsLayout;
|
||||
}
|
||||
if (index < favoriteStrip.count) {
|
||||
return favoriteStrip.contentItem;
|
||||
if (editMode) {
|
||||
return favoriteStrip.contentItem;
|
||||
} else {
|
||||
return favoriteStrip.flow;
|
||||
}
|
||||
}
|
||||
if (editMode) {
|
||||
return flowParent;
|
||||
} else {
|
||||
return applicationsFlow;
|
||||
}
|
||||
return applicationsFlow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue