mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
support model reordering
the order is still not saved/restored
This commit is contained in:
parent
bb4d3e321e
commit
c0d4d075af
4 changed files with 41 additions and 9 deletions
|
|
@ -19,7 +19,7 @@ MouseArea {
|
|||
}
|
||||
onPositionChanged: {
|
||||
if (root.drag.target) {
|
||||
print("New position: " +(Math.round(GridView.view.width / GridView.view.cellWidth) * Math.round(root.y / GridView.view.cellHeight) + Math.round(root.x / GridView.view.cellWidth)))
|
||||
appListModel.setOrder(model.ApplicationOriginalRowRole, (Math.round(GridView.view.width / GridView.view.cellWidth) * Math.round(root.y / GridView.view.cellHeight) + Math.round(root.x / GridView.view.cellWidth)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ Item {
|
|||
property alias appletsSpace: applicationsView.headerItem
|
||||
property int buttonHeight: width/4
|
||||
|
||||
SatelliteComponents.ApplicationListModel {
|
||||
id: appListModel
|
||||
}
|
||||
|
||||
Containment.onAppletAdded: {
|
||||
var container = appletContainerComponent.createObject(appletsSpace.layout)
|
||||
container.visible = true
|
||||
|
|
@ -88,12 +92,11 @@ Item {
|
|||
|
||||
cellWidth: root.buttonHeight
|
||||
cellHeight: cellWidth
|
||||
model: PlasmaCore.SortFilterModel {
|
||||
sourceModel: SatelliteComponents.ApplicationListModel {
|
||||
id: appListModel
|
||||
}
|
||||
sortRole: "ApplicationNameRole"
|
||||
}
|
||||
model: appListModel
|
||||
/* PlasmaCore.SortFilterModel {
|
||||
sourceModel: appListModel
|
||||
sortRole: "ApplicationOrderRole"
|
||||
}*/
|
||||
snapMode: GridView.SnapToRow
|
||||
//clip: true
|
||||
delegate: HomeLauncher {}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ QHash<int, QByteArray> ApplicationListModel::roleNames() const
|
|||
roleNames[ApplicationIconRole] = "ApplicationIconRole";
|
||||
roleNames[ApplicationStorageIdRole] = "ApplicationStorageIdRole";
|
||||
roleNames[ApplicationEntryPathRole] = "ApplicationEntryPathRole";
|
||||
roleNames[ApplicationOrderRole] = "ApplicationOrderRole";
|
||||
roleNames[ApplicationOriginalRowRole] = "ApplicationOriginalRowRole";
|
||||
|
||||
return roleNames;
|
||||
}
|
||||
|
|
@ -87,6 +89,7 @@ void ApplicationListModel::loadApplications()
|
|||
data.icon = plugin.icon();
|
||||
data.storageId = service->storageId();
|
||||
data.entryPath = plugin.entryPath();
|
||||
data.order = 99;
|
||||
m_applicationList << data;
|
||||
}
|
||||
}
|
||||
|
|
@ -115,6 +118,10 @@ QVariant ApplicationListModel::data(const QModelIndex &index, int role) const
|
|||
return m_applicationList.at(index.row()).storageId;
|
||||
case ApplicationEntryPathRole:
|
||||
return m_applicationList.at(index.row()).entryPath;
|
||||
case ApplicationOrderRole:
|
||||
return m_applicationList.at(index.row()).order;
|
||||
case ApplicationOriginalRowRole:
|
||||
return index.row();
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
|
|
@ -130,7 +137,24 @@ int ApplicationListModel::rowCount(const QModelIndex &parent) const
|
|||
return m_applicationList.count();
|
||||
}
|
||||
|
||||
void ApplicationListModel::runApplication(const QString &storageId) {
|
||||
Q_INVOKABLE void ApplicationListModel::setOrder(int row, int destination)
|
||||
{
|
||||
if (row < 0 || destination < 0 || row >= m_applicationList.length() ||
|
||||
destination >= m_applicationList.length() || row == destination) {
|
||||
return;
|
||||
}
|
||||
if (destination > row) {
|
||||
++destination;
|
||||
}
|
||||
|
||||
beginMoveRows(QModelIndex(), row, row, QModelIndex(), destination);
|
||||
ApplicationData data = m_applicationList.takeAt(row);
|
||||
m_applicationList.insert(destination, data);
|
||||
endMoveRows();
|
||||
}
|
||||
|
||||
void ApplicationListModel::runApplication(const QString &storageId)
|
||||
{
|
||||
if (storageId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ struct ApplicationData {
|
|||
QString icon;
|
||||
QString storageId;
|
||||
QString entryPath;
|
||||
int order;
|
||||
};
|
||||
|
||||
class ApplicationListModel : public QAbstractListModel {
|
||||
|
|
@ -55,9 +56,13 @@ public:
|
|||
ApplicationNameRole = Qt::UserRole + 1,
|
||||
ApplicationIconRole = Qt::UserRole + 2,
|
||||
ApplicationStorageIdRole = Qt::UserRole + 3,
|
||||
ApplicationEntryPathRole = Qt::UserRole + 4
|
||||
ApplicationEntryPathRole = Qt::UserRole + 4,
|
||||
ApplicationOrderRole = Qt::UserRole + 5,
|
||||
ApplicationOriginalRowRole = Qt::UserRole + 6
|
||||
};
|
||||
|
||||
Q_INVOKABLE void setOrder(int row, int order);
|
||||
|
||||
Q_INVOKABLE void runApplication(const QString &storageId);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
|
|||
Loading…
Reference in a new issue