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