homescreens/folio: Prevent items from being added to favourites area if it's full

Fixes https://invent.kde.org/plasma/plasma-mobile/-/issues/323
This commit is contained in:
Devin Lin 2024-03-06 08:44:17 -05:00
parent e84989afee
commit 95d3be0531
3 changed files with 19 additions and 0 deletions

View file

@ -328,6 +328,11 @@ void DragState::onDelegateDragPositionOverFavouritesChanged()
m_favouritesInsertBetweenTimer->stop();
}
// ignore this event if the favourites area is full already
if (FavouritesModel::self()->isFull()) {
return;
}
// ignore widget drop delegates (since they can't be placed in the favourites)
if (m_dropDelegate && m_dropDelegate->type() == FolioDelegate::Widget) {
return;

View file

@ -171,6 +171,17 @@ FolioDelegate *FavouritesModel::getEntryAt(int row)
return m_delegates[row].delegate;
}
bool FavouritesModel::isFull() const
{
bool isLocationBottom = HomeScreenState::self()->favouritesBarLocation() == HomeScreenState::Bottom;
if (isLocationBottom) {
return m_delegates.size() >= HomeScreenState::self()->pageColumns();
} else {
return m_delegates.size() >= HomeScreenState::self()->pageRows();
}
}
int FavouritesModel::getGhostEntryPosition()
{
for (int i = 0; i < m_delegates.size(); i++) {

View file

@ -43,6 +43,9 @@ public:
bool addEntry(int row, FolioDelegate *delegate);
FolioDelegate *getEntryAt(int row);
// whether the dock is full, we can't add any more items
bool isFull() const;
// for use with drag and drop, as the delegate is dragged around
// ghost - fake delegate exists at an index, so a gap is created
// invisible - existing delegate looks like it doesn't exist