File indexing completed on 2024-10-13 08:01:32
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QAbstractListModel> 0010 #include <QScreen> 0011 #include <QSet> 0012 0013 class Output 0014 { 0015 public: 0016 enum OutputType { 0017 Unknown, 0018 Laptop, 0019 Monitor, 0020 Television, 0021 Workspace, 0022 Virtual, 0023 Region, 0024 }; 0025 0026 Output(OutputType outputType, QScreen *screen, const QString &display, const QString &uniqueId, const QString &name) 0027 : m_outputType(outputType) 0028 , m_screen(screen) 0029 , m_display(display) 0030 , m_uniqueId(uniqueId) 0031 , m_name(name) 0032 { 0033 } 0034 0035 QScreen *screen() const 0036 { 0037 return m_screen; 0038 } 0039 0040 QString name() const 0041 { 0042 return m_name; 0043 } 0044 0045 QString iconName() const 0046 { 0047 switch (m_outputType) { 0048 case Laptop: 0049 return QStringLiteral("computer-laptop"); 0050 case Television: 0051 return QStringLiteral("video-television"); 0052 default: 0053 return QStringLiteral("video-display"); 0054 } 0055 } 0056 0057 QString display() const 0058 { 0059 return m_display; 0060 } 0061 0062 QString uniqueId() const 0063 { 0064 return m_uniqueId; 0065 } 0066 0067 OutputType outputType() const 0068 { 0069 return m_outputType; 0070 } 0071 0072 private: 0073 OutputType m_outputType; 0074 QScreen *m_screen = nullptr; 0075 QString m_display; 0076 QString m_uniqueId; 0077 QString m_name; 0078 }; 0079 0080 class OutputsModel : public QAbstractListModel 0081 { 0082 Q_OBJECT 0083 Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY hasSelectionChanged) 0084 public: 0085 enum Option { 0086 None = 0, 0087 WorkspaceIncluded = 0x1, 0088 VirtualIncluded = 0x2, 0089 RegionIncluded = 0x4, 0090 }; 0091 Q_ENUM(Option) 0092 Q_DECLARE_FLAGS(Options, Option) 0093 0094 enum Roles { 0095 ScreenRole = Qt::UserRole, 0096 NameRole, 0097 }; 0098 0099 OutputsModel(Options o, QObject *parent); 0100 ~OutputsModel() override; 0101 0102 int rowCount(const QModelIndex &parent = {}) const override; 0103 QHash<int, QByteArray> roleNames() const override; 0104 QVariant data(const QModelIndex &index, int role) const override; 0105 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 0106 0107 const Output &outputAt(int row) const; 0108 QList<Output> selectedOutputs() const; 0109 bool hasSelection() const 0110 { 0111 return !m_selectedRows.isEmpty(); 0112 } 0113 0114 public Q_SLOTS: 0115 void clearSelection(); 0116 0117 Q_SIGNALS: 0118 void hasSelectionChanged(); 0119 0120 private: 0121 QList<Output> m_outputs; 0122 QSet<quint32> m_selectedRows; 0123 };