mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
concept of maxFavoritescount
never go over that number of favorites when over, the last favorite will be de-favoritized
This commit is contained in:
parent
cbc62cfda4
commit
7a827c7b06
4 changed files with 65 additions and 3 deletions
|
|
@ -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<QUrl>(), 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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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<ApplicationData> m_applicationList;
|
||||
|
||||
HomeScreen *m_homeScreen = nullptr;
|
||||
int m_maxFavoriteCount = 5;
|
||||
QStringList m_appOrder;
|
||||
QStringList m_favorites;
|
||||
QSet<QString> m_desktopItems;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue