From 8c1b75a777db827627e04441d0438ed5a106c3ce Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 22 Aug 2019 16:59:30 +0200 Subject: [PATCH] single role for location --- .../homescreen2/applicationlistmodel.cpp | 46 ++++++------------- .../homescreen2/applicationlistmodel.h | 34 ++++++++------ containments/homescreen2/homescreen.cpp | 2 +- .../package/contents/ui/launcher/Delegate.qml | 15 +++--- .../ui/launcher/LauncherDragManager.qml | 15 +++--- .../contents/ui/launcher/LauncherGrid.qml | 8 +++- .../homescreen2/package/contents/ui/main.qml | 2 + 7 files changed, 58 insertions(+), 64 deletions(-) diff --git a/containments/homescreen2/applicationlistmodel.cpp b/containments/homescreen2/applicationlistmodel.cpp index 34f8a9c0..4df94f88 100644 --- a/containments/homescreen2/applicationlistmodel.cpp +++ b/containments/homescreen2/applicationlistmodel.cpp @@ -58,8 +58,7 @@ QHash ApplicationListModel::roleNames() const roleNames[ApplicationStorageIdRole] = "ApplicationStorageIdRole"; roleNames[ApplicationEntryPathRole] = "ApplicationEntryPathRole"; roleNames[ApplicationOriginalRowRole] = "ApplicationOriginalRowRole"; - roleNames[ApplicationFavoriteRole] = "ApplicationFavoriteRole"; - roleNames[ApplicationOnDesktopRole] = "ApplicationOnDesktopRole"; + roleNames[ApplicationLocationRole] = "ApplicationLocationRole"; return roleNames; } @@ -146,14 +145,14 @@ void ApplicationListModel::loadApplications() auto it = m_appPositions.constFind(service->storageId()); if (it != m_appPositions.constEnd()) { //TODO: proper bookmarks - data.favorite = (*it) < 6; + data.location = (*it) < 6 ? Favorites : Grid; orderedList[*it] = data; } else { //TODO: proper bookmarks - data.favorite = ++i + m_appPositions.size() < 6; + data.location = (++i + m_appPositions.size() < 6) ? Favorites : Grid; unorderedList << data; } - if (data.favorite) { + if (data.location == Favorites) { ++m_favoriteCount; } emit favoriteCountChanged(); @@ -194,10 +193,8 @@ QVariant ApplicationListModel::data(const QModelIndex &index, int role) const return m_applicationList.at(index.row()).entryPath; case ApplicationOriginalRowRole: return index.row(); - case ApplicationOnDesktopRole: - return m_applicationList.at(index.row()).desktop; - case ApplicationFavoriteRole: - return m_applicationList.at(index.row()).favorite; + case ApplicationLocationRole: + return m_applicationList.at(index.row()).location; default: return QVariant(); @@ -225,43 +222,26 @@ void ApplicationListModel::moveRow(const QModelIndex& /* sourceParent */, int so moveItem(sourceRow, destinationChild); } -void ApplicationListModel::setFavoriteItem(int row, bool favorite) +void ApplicationListModel::setLocation(int row, LauncherLocation location) { if (row < 0 || row >= m_applicationList.length()) { return; } ApplicationData &data = m_applicationList[row]; - if (data.favorite == favorite) { + if (data.location == location) { return; } - setDesktopItem(row, false); - data.favorite = favorite; - - if (data.favorite) { + if (location == Favorites) { ++m_favoriteCount; - } else { + emit favoriteCountChanged(); + } else if (data.location == Favorites) { m_favoriteCount = qMax(0, m_favoriteCount - 1); - } - emit favoriteCountChanged(); - - emit dataChanged(index(row, 0), index(row, 0)); -} - -void ApplicationListModel::setDesktopItem(int row, bool desktop) -{ - if (row < 0 || row >= m_applicationList.length()) { - return; + emit favoriteCountChanged(); } - ApplicationData &data = m_applicationList[row]; - if (data.desktop == desktop) { - return; - } - - setFavoriteItem(row, false); - data.desktop = desktop; + data.location = location; emit dataChanged(index(row, 0), index(row, 0)); } diff --git a/containments/homescreen2/applicationlistmodel.h b/containments/homescreen2/applicationlistmodel.h index e7a84167..e1419f79 100644 --- a/containments/homescreen2/applicationlistmodel.h +++ b/containments/homescreen2/applicationlistmodel.h @@ -27,13 +27,14 @@ class QString; +class ApplicationListModel; + struct ApplicationData { QString name; QString icon; QString storageId; QString entryPath; - bool favorite = false; - bool desktop = false; + int location = 0; //FIXME }; class ApplicationListModel : public QAbstractListModel { @@ -44,6 +45,22 @@ class ApplicationListModel : public QAbstractListModel { Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged) public: + enum LauncherLocation { + Grid = 0, + Favorites, + Desktop + }; + Q_ENUM(LauncherLocation) + + enum Roles { + ApplicationNameRole = Qt::UserRole + 1, + ApplicationIconRole, + ApplicationStorageIdRole, + ApplicationEntryPathRole, + ApplicationOriginalRowRole, + ApplicationLocationRole + }; + ApplicationListModel(QObject *parent = nullptr); ~ApplicationListModel() override; @@ -60,21 +77,10 @@ public: QHash roleNames() const Q_DECL_OVERRIDE; - enum Roles { - ApplicationNameRole = Qt::UserRole + 1, - ApplicationIconRole, - ApplicationStorageIdRole, - ApplicationEntryPathRole, - ApplicationOriginalRowRole, - ApplicationFavoriteRole, //TODO: a single role for parent - ApplicationOnDesktopRole - }; - QStringList appOrder() const; void setAppOrder(const QStringList &order); - Q_INVOKABLE void setFavoriteItem(int row, bool favorite); - Q_INVOKABLE void setDesktopItem(int row, bool desktop); + Q_INVOKABLE void setLocation(int row, LauncherLocation location); Q_INVOKABLE void moveItem(int row, int order); diff --git a/containments/homescreen2/homescreen.cpp b/containments/homescreen2/homescreen.cpp index ca92a3e7..567ee8c0 100644 --- a/containments/homescreen2/homescreen.cpp +++ b/containments/homescreen2/homescreen.cpp @@ -27,7 +27,7 @@ HomeScreen::HomeScreen(QObject *parent, const QVariantList &args) : Plasma::Containment(parent, args) { - qmlRegisterType(); + qmlRegisterUncreatableType("org.kde.phone.homescreen", 1, 0, "ApplicationListModel", QStringLiteral("Cannot create item of type ApplicationListModel")); m_applicationListModel = new ApplicationListModel(this); setHasConfigurationInterface(true); } diff --git a/containments/homescreen2/package/contents/ui/launcher/Delegate.qml b/containments/homescreen2/package/contents/ui/launcher/Delegate.qml index 909ea454..6e44d468 100644 --- a/containments/homescreen2/package/contents/ui/launcher/Delegate.qml +++ b/containments/homescreen2/package/contents/ui/launcher/Delegate.qml @@ -27,6 +27,8 @@ import org.kde.kquickcontrolsaddons 2.0 import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager +import org.kde.phone.homescreen 1.0 + ContainmentLayoutManager.ItemContainer { id: delegate @@ -72,23 +74,22 @@ ContainmentLayoutManager.ItemContainer { var pos = favoriteStrip.mapFromItem(delegate, 0, 0); newRow = Math.floor((pos.x + dragCenter.x) / delegate.width); - plasmoid.nativeInterface.applicationListModel.setFavoriteItem(index, true); - + plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Favorites); // Put it on desktop } else if (newContainer == appletsLayout) { var pos = appletsLayout.mapFromItem(delegate, 0, 0); - plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, true); - delegate.x = pos.x - delegate.y = pos.y + plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Desktop); + print("!!!!!!!!!!!!"+pos.x+" "+pos.y) + // delegate.x = pos.x + // delegate.y = pos.y return; // Put it in the general view } else { newRow = Math.round(newContainer.flow.width / delegate.width) * Math.floor((delegate.y + dragCenter.y) / delegate.height) + Math.floor((delegate.x + dragCenter.x) / delegate.width) + favoriteStrip.count; - plasmoid.nativeInterface.applicationListModel.setFavoriteItem(index, false); - plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, false); + plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Grid); } launcherDragManager.showSpacer(delegate, dragCenter.x, dragCenter.y); diff --git a/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml b/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml index 52b3ad4a..b7c8c8ba 100644 --- a/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml +++ b/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml @@ -60,7 +60,7 @@ QtObject { function changeContainer(item, container) { var pos; - +print("$$$$$$$$"+container) if (container == appletsLayout) { pos = container.mapFromItem(item, 0, 0); item.parent = container; @@ -75,7 +75,7 @@ QtObject { function putInContainerLayout(item, container) { var pos = container.contentItem.mapFromItem(item, 0, 0); - +print("££££££££££££££££"+container) if (container == appletsLayout) { item.parent = container; } else { @@ -125,6 +125,12 @@ QtObject { var container = containerForItem(item, dragCenterX, dragCenterY); raiseContainer(container); +print("&&&&&&&&&&&"+container) + if (container == appletsLayout) { + spacer.visible = false; + changeContainer(item, container); + return; + } var child = nearestChild(item, dragCenterX, dragCenterY, container); @@ -134,11 +140,6 @@ QtObject { return; } - if (container == appletsLayout) { - changeContainer(item, container); - return; - } - spacer.visible = false; spacer.parent = container.flow diff --git a/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml b/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml index c13b6b69..f0eb37a8 100644 --- a/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml +++ b/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml @@ -27,6 +27,8 @@ import org.kde.kquickcontrolsaddons 2.0 import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager +import org.kde.phone.homescreen 1.0 + LauncherContainer { id: root @@ -46,16 +48,18 @@ LauncherContainer { height: root.cellHeight parent: { - if (model.ApplicationOnDesktopRole) { + if (model.ApplicationLocationRole == ApplicationListModel.Desktop) { return appletsLayout; } - if (model.ApplicationFavoriteRole) { + + if (model.ApplicationLocationRole == ApplicationListModel.Favorites) { if (editMode) { return favoriteStrip.contentItem; } else { return favoriteStrip.flow; } } + if (editMode) { return flowParent; } else { diff --git a/containments/homescreen2/package/contents/ui/main.qml b/containments/homescreen2/package/contents/ui/main.qml index d73a0a84..7f752bba 100644 --- a/containments/homescreen2/package/contents/ui/main.qml +++ b/containments/homescreen2/package/contents/ui/main.qml @@ -30,6 +30,8 @@ import "launcher" as Launcher import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager +import org.kde.phone.homescreen 1.0 + Item { id: root width: 640