shift-shell/containments/homescreen/applicationlistmodel.h

95 lines
2.6 KiB
C
Raw Normal View History

/*
* Copyright (C) 2014 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* or (at your option) any later version, as published by the Free
* Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef APPLICATIONLISTMODEL_H
#define APPLICATIONLISTMODEL_H
// Qt
#include <QObject>
#include <QSortFilterProxyModel>
#include <QList>
2019-09-04 16:39:31 +00:00
#include "homescreen.h"
class QString;
2019-09-04 16:39:31 +00:00
class ApplicationListModel;
class ApplicationListModel : public QSortFilterProxyModel {
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
2019-09-04 16:39:31 +00:00
Q_PROPERTY(int favoriteCount READ favoriteCount NOTIFY favoriteCountChanged)
Q_PROPERTY(int maxFavoriteCount READ maxFavoriteCount WRITE setMaxFavoriteCount NOTIFY maxFavoriteCountChanged)
public:
2019-09-04 16:39:31 +00:00
enum LauncherLocation {
Grid = 0,
Favorites,
Desktop
};
Q_ENUM(LauncherLocation)
enum Roles {
SortKeyRole = Qt::UserRole + 100,
2019-09-04 16:39:31 +00:00
ApplicationLocationRole
};
ApplicationListModel(HomeScreen *parent = nullptr);
2018-12-31 03:13:55 +00:00
~ApplicationListModel() override;
void loadSettings();
int count() const { return rowCount(); }
2019-09-04 16:39:31 +00:00
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;
2018-12-31 03:13:55 +00:00
Qt::ItemFlags flags(const QModelIndex &index) const override;
2015-04-21 12:14:33 +00:00
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
2019-09-04 16:39:31 +00:00
Q_INVOKABLE void setLocation(int row, LauncherLocation location);
2015-03-05 14:39:51 +00:00
Q_INVOKABLE void moveItem(int row, int order);
Q_INVOKABLE void runApplication(const QString &storageId);
public Q_SLOTS:
Q_SIGNALS:
void countChanged();
2019-09-04 16:39:31 +00:00
void favoriteCountChanged();
void maxFavoriteCountChanged();
private:
2019-09-04 16:39:31 +00:00
HomeScreen *m_homeScreen = nullptr;
int m_maxFavoriteCount = 0;
int m_urlRole = 0;
QStringList m_appOrder;
2019-09-04 16:39:31 +00:00
QStringList m_favorites;
QSet<QString> m_desktopItems;
QHash<QString, int> m_appPositions;
};
#endif // APPLICATIONLISTMODEL_H