diff --git a/containments/homescreen2/applicationlistmodel.cpp b/containments/homescreen2/applicationlistmodel.cpp index b048e172..59517649 100644 --- a/containments/homescreen2/applicationlistmodel.cpp +++ b/containments/homescreen2/applicationlistmodel.cpp @@ -243,7 +243,19 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location) } if (location == Favorites) { + if (row >= m_maxFavoriteCount) { + return; + } m_favorites.insert(row, data.storageId); + + int i = 0; + + if (m_applicationList[m_maxFavoriteCount].location == Favorites) { + m_applicationList[m_maxFavoriteCount].location = Grid; + m_favorites.pop_back(); + emit dataChanged(index(m_maxFavoriteCount, 0), index(m_maxFavoriteCount, 0)); + } + m_homeScreen->config().writeEntry("Favorites", m_favorites); emit favoriteCountChanged(); } else if (data.location == Favorites) { @@ -311,5 +323,35 @@ void ApplicationListModel::runApplication(const QString &storageId) KRun::runService(*service, QList(), nullptr); } +int ApplicationListModel::maxFavoriteCount() const +{ + return m_maxFavoriteCount; +} + +void ApplicationListModel::setMaxFavoriteCount(int count) +{ + if (m_maxFavoriteCount == count) { + return; + } + + if (m_maxFavoriteCount > count) { + while (m_favorites.size() > count) { + m_favorites.pop_back(); + } + + int i = 0; + for (auto &app : m_applicationList) { + if (i >= count && app.location == Favorites) { + app.location = Grid; + } + ++i; + } + } + + m_maxFavoriteCount = count; + + emit maxFavoriteCountChanged(); +} + #include "moc_applicationlistmodel.cpp" diff --git a/containments/homescreen2/applicationlistmodel.h b/containments/homescreen2/applicationlistmodel.h index f9027e6e..270eb07f 100644 --- a/containments/homescreen2/applicationlistmodel.h +++ b/containments/homescreen2/applicationlistmodel.h @@ -45,6 +45,7 @@ class ApplicationListModel : public QAbstractListModel { Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(int favoriteCount READ favoriteCount NOTIFY favoriteCountChanged) + Q_PROPERTY(int maxFavoriteCount READ maxFavoriteCount WRITE setMaxFavoriteCount NOTIFY maxFavoriteCountChanged) public: enum LauncherLocation { @@ -74,6 +75,9 @@ public: int count() const { return m_applicationList.count(); } int favoriteCount() const { return m_favorites.count();} + int maxFavoriteCount() const; + void setMaxFavoriteCount(int count); + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; Qt::ItemFlags flags(const QModelIndex &index) const override; @@ -94,11 +98,13 @@ public Q_SLOTS: Q_SIGNALS: void countChanged(); void favoriteCountChanged(); + void maxFavoriteCountChanged(); private: QList m_applicationList; HomeScreen *m_homeScreen = nullptr; + int m_maxFavoriteCount = 5; QStringList m_appOrder; QStringList m_favorites; QSet m_desktopItems; diff --git a/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml b/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml index 006cb183..2b3d8a76 100644 --- a/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml +++ b/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml @@ -48,7 +48,7 @@ Item { // Put it in the favorites strip if (newContainer == favoriteStrip) { - var pos = favoriteStrip.mapFromItem(delegate, 0, 0); + var pos = favoriteStrip.flow.mapFromItem(delegate, 0, 0); newRow = Math.floor((pos.x + dragCenterX) / delegate.width); plasmoid.nativeInterface.applicationListModel.setLocation(delegate.modelData.index, ApplicationListModel.Favorites); @@ -229,7 +229,9 @@ Item { return; } - if (item.x + dragCenterX < child.x + child.width / 2) { + var pos = container.flow.mapFromItem(item, dragCenterX, dragCenterY); + + if (pos.x + dragCenterX < child.x + child.width / 2) { putInContainerLayout(item, container); plasmoid.nativeInterface.stackBefore(item, child); } else { diff --git a/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml b/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml index 8e661af0..b2705df2 100644 --- a/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml +++ b/containments/homescreen2/package/contents/ui/launcher/LauncherGrid.qml @@ -50,7 +50,8 @@ LauncherContainer { width: root.cellWidth height: root.cellHeight - parent: { + parent: parentFromLocation + property Item parentFromLocation: { switch (model.ApplicationLocationRole) { case ApplicationListModel.Desktop: return appletsLayout; @@ -60,6 +61,17 @@ LauncherContainer { return root.flow; } } + onParentFromLocationChanged: { + if (!editMode && parent != parentFromLocation) { + parent = parentFromLocation; + if (model.ApplicationLocationRole == ApplicationListModel.Favorites) { + plasmoid.nativeInterface.stackBefore(delegate, parentFromLocation.children[index]); + + } else if (model.ApplicationLocationRole == ApplicationListModel.Grid) { + plasmoid.nativeInterface.stackBefore(delegate, parentFromLocation.children[Math.max(0, index - plasmoid.nativeInterface.applicationListModel.favoriteCount)]); + } + } + } } } }