mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-04 02:34:45 +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: {
|
onPositionChanged: {
|
||||||
if (root.drag.target) {
|
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 alias appletsSpace: applicationsView.headerItem
|
||||||
property int buttonHeight: width/4
|
property int buttonHeight: width/4
|
||||||
|
|
||||||
|
SatelliteComponents.ApplicationListModel {
|
||||||
|
id: appListModel
|
||||||
|
}
|
||||||
|
|
||||||
Containment.onAppletAdded: {
|
Containment.onAppletAdded: {
|
||||||
var container = appletContainerComponent.createObject(appletsSpace.layout)
|
var container = appletContainerComponent.createObject(appletsSpace.layout)
|
||||||
container.visible = true
|
container.visible = true
|
||||||
|
|
@ -88,12 +92,11 @@ Item {
|
||||||
|
|
||||||
cellWidth: root.buttonHeight
|
cellWidth: root.buttonHeight
|
||||||
cellHeight: cellWidth
|
cellHeight: cellWidth
|
||||||
model: PlasmaCore.SortFilterModel {
|
model: appListModel
|
||||||
sourceModel: SatelliteComponents.ApplicationListModel {
|
/* PlasmaCore.SortFilterModel {
|
||||||
id: appListModel
|
sourceModel: appListModel
|
||||||
}
|
sortRole: "ApplicationOrderRole"
|
||||||
sortRole: "ApplicationNameRole"
|
}*/
|
||||||
}
|
|
||||||
snapMode: GridView.SnapToRow
|
snapMode: GridView.SnapToRow
|
||||||
//clip: true
|
//clip: true
|
||||||
delegate: HomeLauncher {}
|
delegate: HomeLauncher {}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ QHash<int, QByteArray> ApplicationListModel::roleNames() const
|
||||||
roleNames[ApplicationIconRole] = "ApplicationIconRole";
|
roleNames[ApplicationIconRole] = "ApplicationIconRole";
|
||||||
roleNames[ApplicationStorageIdRole] = "ApplicationStorageIdRole";
|
roleNames[ApplicationStorageIdRole] = "ApplicationStorageIdRole";
|
||||||
roleNames[ApplicationEntryPathRole] = "ApplicationEntryPathRole";
|
roleNames[ApplicationEntryPathRole] = "ApplicationEntryPathRole";
|
||||||
|
roleNames[ApplicationOrderRole] = "ApplicationOrderRole";
|
||||||
|
roleNames[ApplicationOriginalRowRole] = "ApplicationOriginalRowRole";
|
||||||
|
|
||||||
return roleNames;
|
return roleNames;
|
||||||
}
|
}
|
||||||
|
|
@ -87,6 +89,7 @@ void ApplicationListModel::loadApplications()
|
||||||
data.icon = plugin.icon();
|
data.icon = plugin.icon();
|
||||||
data.storageId = service->storageId();
|
data.storageId = service->storageId();
|
||||||
data.entryPath = plugin.entryPath();
|
data.entryPath = plugin.entryPath();
|
||||||
|
data.order = 99;
|
||||||
m_applicationList << data;
|
m_applicationList << data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -115,6 +118,10 @@ QVariant ApplicationListModel::data(const QModelIndex &index, int role) const
|
||||||
return m_applicationList.at(index.row()).storageId;
|
return m_applicationList.at(index.row()).storageId;
|
||||||
case ApplicationEntryPathRole:
|
case ApplicationEntryPathRole:
|
||||||
return m_applicationList.at(index.row()).entryPath;
|
return m_applicationList.at(index.row()).entryPath;
|
||||||
|
case ApplicationOrderRole:
|
||||||
|
return m_applicationList.at(index.row()).order;
|
||||||
|
case ApplicationOriginalRowRole:
|
||||||
|
return index.row();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
@ -130,7 +137,24 @@ int ApplicationListModel::rowCount(const QModelIndex &parent) const
|
||||||
return m_applicationList.count();
|
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()) {
|
if (storageId.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ struct ApplicationData {
|
||||||
QString icon;
|
QString icon;
|
||||||
QString storageId;
|
QString storageId;
|
||||||
QString entryPath;
|
QString entryPath;
|
||||||
|
int order;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ApplicationListModel : public QAbstractListModel {
|
class ApplicationListModel : public QAbstractListModel {
|
||||||
|
|
@ -55,9 +56,13 @@ public:
|
||||||
ApplicationNameRole = Qt::UserRole + 1,
|
ApplicationNameRole = Qt::UserRole + 1,
|
||||||
ApplicationIconRole = Qt::UserRole + 2,
|
ApplicationIconRole = Qt::UserRole + 2,
|
||||||
ApplicationStorageIdRole = Qt::UserRole + 3,
|
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_INVOKABLE void runApplication(const QString &storageId);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue