Warning, file /plasma/xdg-desktop-portal-kde/src/outputsmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 "waylandintegration.h" 0010 #include <QAbstractListModel> 0011 #include <QSet> 0012 0013 class Output 0014 { 0015 public: 0016 Output(WaylandIntegration::WaylandOutput::OutputType outputType, 0017 int waylandOutputName, 0018 const QString &display, 0019 const QString &uniqueId, 0020 const QString &name) 0021 : m_outputType(outputType) 0022 , m_waylandOutputName(waylandOutputName) 0023 , m_display(display) 0024 , m_uniqueId(uniqueId) 0025 , m_name(name) 0026 { 0027 } 0028 0029 int waylandOutputName() const 0030 { 0031 return m_waylandOutputName; 0032 } 0033 0034 QString name() const 0035 { 0036 return m_name; 0037 } 0038 0039 QString iconName() const 0040 { 0041 switch (m_outputType) { 0042 case WaylandIntegration::WaylandOutput::Laptop: 0043 return QStringLiteral("computer-laptop"); 0044 case WaylandIntegration::WaylandOutput::Television: 0045 return QStringLiteral("video-television"); 0046 default: 0047 case WaylandIntegration::WaylandOutput::Monitor: 0048 return QStringLiteral("video-display"); 0049 } 0050 } 0051 0052 QString display() const 0053 { 0054 return m_display; 0055 } 0056 0057 QString uniqueId() const 0058 { 0059 return m_uniqueId; 0060 } 0061 0062 WaylandIntegration::WaylandOutput::OutputType outputType() const 0063 { 0064 return m_outputType; 0065 } 0066 0067 private: 0068 WaylandIntegration::WaylandOutput::OutputType m_outputType; 0069 int m_waylandOutputName; 0070 QString m_display; 0071 QString m_uniqueId; 0072 QString m_name; 0073 }; 0074 0075 class OutputsModel : public QAbstractListModel 0076 { 0077 Q_OBJECT 0078 Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY hasSelectionChanged) 0079 public: 0080 enum Option { 0081 None = 0, 0082 WorkspaceIncluded = 0x1, 0083 VirtualIncluded = 0x2, 0084 }; 0085 Q_ENUM(Option) 0086 Q_DECLARE_FLAGS(Options, Option) 0087 0088 enum Roles { 0089 OutputNameRole = Qt::UserRole, 0090 NameRole, 0091 }; 0092 0093 OutputsModel(Options o, QObject *parent); 0094 ~OutputsModel() override; 0095 0096 int rowCount(const QModelIndex &parent = {}) const override; 0097 QHash<int, QByteArray> roleNames() const override; 0098 QVariant data(const QModelIndex &index, int role) const override; 0099 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 0100 0101 const Output &outputAt(int row) const; 0102 QList<Output> selectedOutputs() const; 0103 bool hasSelection() const 0104 { 0105 return !m_selectedRows.isEmpty(); 0106 } 0107 0108 public Q_SLOTS: 0109 void clearSelection(); 0110 0111 Q_SIGNALS: 0112 void hasSelectionChanged(); 0113 0114 private: 0115 QList<Output> m_outputs; 0116 QSet<quint32> m_selectedRows; 0117 };