File indexing completed on 2024-04-28 16:55:00
0001 /* 0002 SPDX-FileCopyrightText: 2021 Cyril Rossi <cyril.rossi@enioka.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QAbstractTableModel> 0010 #include <QHash> 0011 #include <QObject> 0012 #include <QQmlApplicationEngine> 0013 #include <QQuickView> 0014 0015 #include <plasma/containment.h> 0016 #include <plasma/plasma.h> 0017 0018 namespace KActivities 0019 { 0020 class Consumer; 0021 class Info; 0022 } 0023 0024 class ShellCorona; 0025 class ShellContainmentModel; 0026 0027 class ScreenPoolModel : public QAbstractListModel 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 enum ScreenPoolModelRoles { ScreenIdRole = Qt::UserRole + 1, ScreenNameRole, ContainmentsRole, PrimaryRole, EnabledRole }; 0033 0034 public: 0035 explicit ScreenPoolModel(ShellCorona *corona, QObject *parent = nullptr); 0036 ~ScreenPoolModel() override; 0037 0038 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0039 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0040 QHash<int, QByteArray> roleNames() const override; 0041 0042 public Q_SLOTS: 0043 void load(); 0044 void remove(int screenId); 0045 0046 private: 0047 ShellCorona *m_corona; 0048 struct Data { 0049 int id; 0050 QString name; 0051 bool primary; 0052 bool enabled; 0053 }; 0054 QTimer *m_reloadTimer = nullptr; 0055 QVector<Data> m_screens; 0056 QVector<ShellContainmentModel *> m_containments; 0057 }; 0058 0059 class ShellContainmentModel : public QAbstractListModel 0060 { 0061 Q_OBJECT 0062 0063 Q_PROPERTY(ScreenPoolModel *screenPoolModel READ screenPoolModel CONSTANT) 0064 0065 public: 0066 enum ShellContainmentModelRoles { 0067 ContainmentIdRole = Qt::UserRole + 1, 0068 NameRole, 0069 ScreenRole, 0070 EdgeRole, 0071 EdgePositionRole, 0072 PanelCountAtRightRole, 0073 PanelCountAtTopRole, 0074 PanelCountAtLeftRole, 0075 PanelCountAtBottomRole, 0076 ActivityRole, 0077 IsActiveRole, 0078 ImageSourceRole, 0079 DestroyedRole 0080 }; 0081 0082 public: 0083 explicit ShellContainmentModel(ShellCorona *corona, int screenId, ScreenPoolModel *parent = nullptr); 0084 ~ShellContainmentModel() override; 0085 0086 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0087 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0088 QHash<int, QByteArray> roleNames() const override; 0089 0090 ScreenPoolModel *screenPoolModel() const; 0091 0092 Q_INVOKABLE void remove(int contId); 0093 Q_INVOKABLE void moveContainementToScreen(unsigned int contId, int newScreen); 0094 0095 bool findContainment(unsigned int containmentId) const; 0096 0097 void loadActivitiesInfos(); 0098 0099 public Q_SLOTS: 0100 void load(); 0101 0102 private: 0103 static QString plasmaLocationToString(const Plasma::Types::Location location); 0104 static QString containmentTypeToString(const Plasma::Types::ContainmentType containmentType); 0105 0106 Plasma::Containment *containmentById(unsigned int id); 0107 QString containmentPreview(Plasma::Containment *containment); 0108 0109 private: 0110 int m_screenId = -1; 0111 ShellCorona *m_corona; 0112 struct Data { 0113 unsigned int id; 0114 QString name; 0115 int screen; 0116 Plasma::Types::Location edge; 0117 QString activity; 0118 bool changed = false; 0119 bool isActive = true; 0120 QString image; 0121 const Plasma::Containment *containment; 0122 }; 0123 QTimer *m_reloadTimer = nullptr; 0124 QVector<Data> m_containments; 0125 ScreenPoolModel *m_screenPoolModel; 0126 QHash<QString, KActivities::Info *> m_activitiesInfos; 0127 KActivities::Consumer *m_activityConsumer; 0128 QHash<int, QHash<Plasma::Types::Location, QList<int>>> m_edgeCount; 0129 }; 0130 0131 class ShellContainmentConfig : public QQmlApplicationEngine 0132 { 0133 Q_OBJECT 0134 0135 public: 0136 ShellContainmentConfig(ShellCorona *corona, QWindow *parent = nullptr); 0137 ~ShellContainmentConfig() override; 0138 0139 void init(); 0140 0141 private: 0142 ShellCorona *m_corona; 0143 ScreenPoolModel *m_model; 0144 };