first prototype of icons in desktop

This commit is contained in:
Marco Martin 2019-07-30 13:39:07 +02:00
parent 2f0bc852ba
commit 71948fd9f3
4 changed files with 130 additions and 85 deletions

View file

@ -182,6 +182,8 @@ QVariant ApplicationListModel::data(const QModelIndex &index, int role) const
return m_applicationList.at(index.row()).entryPath; return m_applicationList.at(index.row()).entryPath;
case ApplicationOriginalRowRole: case ApplicationOriginalRowRole:
return index.row(); return index.row();
case ApplicationOnDesktopRole:
return m_applicationList.at(index.row()).desktop;
default: default:
return QVariant(); return QVariant();
@ -221,7 +223,7 @@ void ApplicationListModel::setFavoriteItem(int row, bool favorite)
} }
data.favorite = favorite; data.favorite = favorite;
qWarning()<<m_applicationList[row].favorite;
emit dataChanged(index(row, 0), index(row, 0)); emit dataChanged(index(row, 0), index(row, 0));
} }
@ -237,6 +239,7 @@ void ApplicationListModel::setDesktopItem(int row, bool desktop)
} }
data.desktop = desktop; data.desktop = desktop;
qWarning()<<m_applicationList[row].desktop;
emit dataChanged(index(row, 0), index(row, 0)); emit dataChanged(index(row, 0), index(row, 0));
} }

View file

@ -43,6 +43,8 @@ ContainmentLayoutManager.ItemContainer {
opacity: dragging ? 0.4 : 1 opacity: dragging ? 0.4 : 1
editModeCondition: model.ApplicationOnDesktopRole ? ContainmentLayoutManager.ItemContainer.AfterPressAndHold: ContainmentLayoutManager.ItemContainer.Manual
onDraggingChanged: { onDraggingChanged: {
if (dragging) { if (dragging) {
var pos = dragDelegate.parent.mapFromItem(delegate, 0, 0); var pos = dragDelegate.parent.mapFromItem(delegate, 0, 0);
@ -71,10 +73,17 @@ ContainmentLayoutManager.ItemContainer {
} }
onPressAndHold: { onPressAndHold: {
if (model.ApplicationOnDesktopRole) {
mouse.accepted = false
return
}
delegate.dragging = true; delegate.dragging = true;
} }
onReleased: delegate.dragging = false; onReleased: {
delegate.dragging = false;
}
onCanceled: delegate.dragging = false; onCanceled: delegate.dragging = false;
@ -85,12 +94,20 @@ ContainmentLayoutManager.ItemContainer {
var newRow = 0; var newRow = 0;
// Put it in the favorites strip
if (favoriteStrip.contains(favoriteStrip.mapFromItem(dragDelegate, dragDelegate.width/2, dragDelegate.height/2))) { if (favoriteStrip.contains(favoriteStrip.mapFromItem(dragDelegate, dragDelegate.width/2, dragDelegate.height/2))) {
newRow = Math.floor((dragDelegate.x + dragDelegate.width/2) / dragDelegate.width); newRow = Math.floor((dragDelegate.x + dragDelegate.width/2) / dragDelegate.width);
// Put it on desktop
} else if (appletsLayout.contains(appletsLayout.mapFromItem(dragDelegate, dragDelegate.width/2, dragDelegate.height/2))) {
plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, true);
return;
// Put it in the general view
} else { } 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; 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.setDesktopItem(index, false);
plasmoid.nativeInterface.applicationListModel.moveItem(modelData.index, newRow); plasmoid.nativeInterface.applicationListModel.moveItem(modelData.index, newRow);
} }

View file

@ -25,6 +25,7 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons 2.0 import org.kde.kquickcontrolsaddons 2.0
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
Controls.Control { Controls.Control {
id: root id: root
@ -39,6 +40,7 @@ Controls.Control {
readonly property int cellWidth: applicationsFlow.width / Math.floor(applicationsFlow.width / ((availableCellHeight - reservedSpaceForLabel) + units.smallSpacing*4)) readonly property int cellWidth: applicationsFlow.width / Math.floor(applicationsFlow.width / ((availableCellHeight - reservedSpaceForLabel) + units.smallSpacing*4))
readonly property int cellHeight: availableCellHeight - topPadding readonly property int cellHeight: availableCellHeight - topPadding
property ContainmentLayoutManager.AppletsLayout appletsLayout
property FavoriteStrip favoriteStrip property FavoriteStrip favoriteStrip
signal externalDragStarted signal externalDragStarted
@ -110,7 +112,15 @@ Controls.Control {
width: root.cellWidth width: root.cellWidth
height: root.cellHeight height: root.cellHeight
dragDelegate: dragDelegateItem dragDelegate: dragDelegateItem
parent: index < favoriteStrip.count ? favoriteStrip.contentItem : applicationsFlow parent: {
if (model.ApplicationOnDesktopRole) {
return appletsLayout;
}
if (index < favoriteStrip.count) {
return favoriteStrip.contentItem;
}
return applicationsFlow;
}
} }
} }
} }

View file

@ -46,112 +46,127 @@ Text {
target: plasmoid target: plasmoid
onEditModeChanged: { onEditModeChanged: {
appletsLayout.editMode = plasmoid.editMode appletsLayout.editMode = plasmoid.editMode
if (plasmoid.editMode) {
menuRepeater.freeLayout();
} else {
menuRepeater.relayout();
}
} }
} }
Flickable { Flickable {
id: mainFlickable id: mainFlickable
anchors.fill: parent anchors {
fill: parent
// bottomMargin: favoriteStrip.height
}
bottomMargin: favoriteStrip.height bottomMargin: favoriteStrip.height
contentWidth: width contentWidth: width
contentHeight: appletsLayout.height contentHeight: flickableContents.height
interactive: !plasmoid.editMode interactive: !plasmoid.editMode
DragDrop.DropArea { ColumnLayout {
id: flickableContents
width: parent.width width: parent.width
height: mainFlickable.height + launcher.height DragDrop.DropArea {
Layout.fillWidth: true
Layout.preferredHeight: mainFlickable.height //TODO: multiple widgets pages
onDragEnter: { onDragEnter: {
event.accept(event.proposedAction); event.accept(event.proposedAction);
} }
onDragMove: { onDragMove: {
appletsLayout.showPlaceHolderAt( appletsLayout.showPlaceHolderAt(
Qt.rect(event.x - appletsLayout.defaultItemWidth / 2, Qt.rect(event.x - appletsLayout.defaultItemWidth / 2,
event.y - appletsLayout.defaultItemHeight / 2, event.y - appletsLayout.defaultItemHeight / 2,
appletsLayout.defaultItemWidth, appletsLayout.defaultItemWidth,
appletsLayout.defaultItemHeight) 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
anchors.fill: parent
configKey: width > height ? "ItemGeometries" : "ItemGeometriesVertical"
containment: plasmoid
editModeCondition: plasmoid.immutable
? ContainmentLayoutManager.AppletsLayout.Manual
: ContainmentLayoutManager.AppletsLayout.AfterPressAndHold
// Sets the containment in edit mode when we go in edit mode as well
onEditModeChanged: plasmoid.editMode = editMode
minimumItemWidth: units.gridUnit * 3
minimumItemHeight: minimumItemWidth
defaultItemWidth: units.gridUnit * 6
defaultItemHeight: defaultItemWidth
cellWidth: units.iconSizes.small
cellHeight: cellWidth
acceptsAppletCallback: function(applet, x, y) {
print("Applet: "+applet+" "+x+" "+y)
return true;
} }
appletContainerComponent: ContainmentLayoutManager.BasicAppletContainer { onDragLeave: {
id: appletContainer appletsLayout.hidePlaceHolder();
configOverlayComponent: ConfigOverlay {} }
onEditModeChanged: {
if (editMode) { preventStealing: true
plasmoid.editMode = true;
onDrop: {
plasmoid.processMimeData(event.mimeData,
event.x - appletsLayout.placeHolder.width / 2, event.y - appletsLayout.placeHolder.height / 2);
event.accept(event.proposedAction);
appletsLayout.hidePlaceHolder();
}
PlasmaCore.Svg {
id: arrowsSvg
imagePath: "widgets/arrows"
colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
}
PlasmaCore.SvgItem {
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
bottomMargin: favoriteStrip.height
}
z: 2
svg: arrowsSvg
elementId: "up-arrow"
width: units.iconSizes.large
height: width
}
ContainmentLayoutManager.AppletsLayout {
id: appletsLayout
anchors.fill: parent
configKey: width > height ? "ItemGeometriesHorizontal" : "ItemGeometriesVertical"
containment: plasmoid
editModeCondition: plasmoid.immutable
? ContainmentLayoutManager.AppletsLayout.Manual
: ContainmentLayoutManager.AppletsLayout.AfterPressAndHold
// Sets the containment in edit mode when we go in edit mode as well
onEditModeChanged: plasmoid.editMode = editMode
minimumItemWidth: units.gridUnit * 3
minimumItemHeight: minimumItemWidth
defaultItemWidth: units.gridUnit * 6
defaultItemHeight: defaultItemWidth
cellWidth: units.iconSizes.small
cellHeight: cellWidth
acceptsAppletCallback: function(applet, x, y) {
print("Applet: "+applet+" "+x+" "+y)
return true;
}
appletContainerComponent: ContainmentLayoutManager.BasicAppletContainer {
id: appletContainer
configOverlayComponent: ConfigOverlay {}
onEditModeChanged: {
if (editMode) {
plasmoid.editMode = true;
}
} }
} }
}
placeHolder: ContainmentLayoutManager.PlaceHolder {} placeHolder: ContainmentLayoutManager.PlaceHolder {}
Launcher.LauncherGrid {
id: launcher
favoriteStrip: favoriteStrip
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
}
} }
} }
Launcher.LauncherGrid {
id: launcher
Layout.fillWidth: true
favoriteStrip: favoriteStrip
appletsLayout: appletsLayout
}
} }
} }
Launcher.FavoriteStrip { Launcher.FavoriteStrip {
id: favoriteStrip id: favoriteStrip
anchors.horizontalCenter: parent.horizontalCenter
width: Math.min(root.width, units.gridUnit * 30)
launcherGrid: launcher launcherGrid: launcher
anchors { y: Math.max(0, root.height - height - mainFlickable.contentY)
left: parent.left
right: parent.right
bottom: parent.bottom
}
} }
} }