mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-03 18:24:46 +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 (location == Favorites) {
|
||||||
|
if (row >= m_maxFavoriteCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_favorites.insert(row, data.storageId);
|
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);
|
m_homeScreen->config().writeEntry("Favorites", m_favorites);
|
||||||
emit favoriteCountChanged();
|
emit favoriteCountChanged();
|
||||||
} else if (data.location == Favorites) {
|
} else if (data.location == Favorites) {
|
||||||
|
|
@ -311,5 +323,35 @@ void ApplicationListModel::runApplication(const QString &storageId)
|
||||||
KRun::runService(*service, QList<QUrl>(), nullptr);
|
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"
|
#include "moc_applicationlistmodel.cpp"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ class ApplicationListModel : public QAbstractListModel {
|
||||||
|
|
||||||
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
||||||
Q_PROPERTY(int favoriteCount READ favoriteCount NOTIFY favoriteCountChanged)
|
Q_PROPERTY(int favoriteCount READ favoriteCount NOTIFY favoriteCountChanged)
|
||||||
|
Q_PROPERTY(int maxFavoriteCount READ maxFavoriteCount WRITE setMaxFavoriteCount NOTIFY maxFavoriteCountChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum LauncherLocation {
|
enum LauncherLocation {
|
||||||
|
|
@ -74,6 +75,9 @@ public:
|
||||||
int count() const { return m_applicationList.count(); }
|
int count() const { return m_applicationList.count(); }
|
||||||
int favoriteCount() const { return m_favorites.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;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
|
@ -94,11 +98,13 @@ public Q_SLOTS:
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void countChanged();
|
void countChanged();
|
||||||
void favoriteCountChanged();
|
void favoriteCountChanged();
|
||||||
|
void maxFavoriteCountChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ApplicationData> m_applicationList;
|
QList<ApplicationData> m_applicationList;
|
||||||
|
|
||||||
HomeScreen *m_homeScreen = nullptr;
|
HomeScreen *m_homeScreen = nullptr;
|
||||||
|
int m_maxFavoriteCount = 5;
|
||||||
QStringList m_appOrder;
|
QStringList m_appOrder;
|
||||||
QStringList m_favorites;
|
QStringList m_favorites;
|
||||||
QSet<QString> m_desktopItems;
|
QSet<QString> m_desktopItems;
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ Item {
|
||||||
|
|
||||||
// Put it in the favorites strip
|
// Put it in the favorites strip
|
||||||
if (newContainer == favoriteStrip) {
|
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);
|
newRow = Math.floor((pos.x + dragCenterX) / delegate.width);
|
||||||
|
|
||||||
plasmoid.nativeInterface.applicationListModel.setLocation(delegate.modelData.index, ApplicationListModel.Favorites);
|
plasmoid.nativeInterface.applicationListModel.setLocation(delegate.modelData.index, ApplicationListModel.Favorites);
|
||||||
|
|
@ -229,7 +229,9 @@ Item {
|
||||||
return;
|
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);
|
putInContainerLayout(item, container);
|
||||||
plasmoid.nativeInterface.stackBefore(item, child);
|
plasmoid.nativeInterface.stackBefore(item, child);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,8 @@ LauncherContainer {
|
||||||
width: root.cellWidth
|
width: root.cellWidth
|
||||||
height: root.cellHeight
|
height: root.cellHeight
|
||||||
|
|
||||||
parent: {
|
parent: parentFromLocation
|
||||||
|
property Item parentFromLocation: {
|
||||||
switch (model.ApplicationLocationRole) {
|
switch (model.ApplicationLocationRole) {
|
||||||
case ApplicationListModel.Desktop:
|
case ApplicationListModel.Desktop:
|
||||||
return appletsLayout;
|
return appletsLayout;
|
||||||
|
|
@ -60,6 +61,17 @@ LauncherContainer {
|
||||||
return root.flow;
|
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