Changeset View
Changeset View
Standalone View
Standalone View
kcm/output_model.h
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright © 2019 Roman Gilg <subdiff@gmail.com> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or modify | ||||
5 | it under the terms of the GNU General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or | ||||
7 | (at your option) any later version. | ||||
8 | | ||||
9 | This program is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | GNU General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU General Public License | ||||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | *********************************************************************/ | ||||
17 | #pragma once | ||||
18 | | ||||
19 | #include <kscreen/config.h> | ||||
20 | #include <kscreen/output.h> | ||||
21 | | ||||
22 | #include <QAbstractListModel> | ||||
23 | #include <QPoint> | ||||
24 | | ||||
25 | class ConfigHandler; | ||||
26 | | ||||
27 | class OutputModel : public QAbstractListModel | ||||
28 | { | ||||
29 | Q_OBJECT | ||||
30 | public: | ||||
31 | enum OutputRoles { | ||||
32 | EnabledRole = Qt::UserRole + 1, | ||||
33 | PrimaryRole, | ||||
34 | SizeRole, | ||||
35 | PositionRole, | ||||
36 | NormalizedPositionRole, | ||||
37 | RotationRole, | ||||
38 | ScaleRole, | ||||
39 | ResolutionIndexRole, | ||||
40 | ResolutionsRole, | ||||
41 | RefreshRateIndexRole, | ||||
42 | RefreshRatesRole | ||||
43 | }; | ||||
44 | | ||||
45 | explicit OutputModel (ConfigHandler *configHandler); | ||||
46 | ~OutputModel() override = default; | ||||
47 | | ||||
48 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
49 | QVariant data(const QModelIndex &index, | ||||
50 | int role = Qt::DisplayRole) const override; | ||||
51 | bool setData(const QModelIndex &index, | ||||
52 | const QVariant &value, | ||||
53 | int role = Qt::EditRole) override; | ||||
54 | | ||||
55 | void add(const KScreen::OutputPtr &output); | ||||
56 | void remove(int outputId); | ||||
57 | | ||||
58 | bool normalizePositions(); | ||||
59 | bool positionsNormalized() const; | ||||
60 | | ||||
61 | Q_SIGNALS: | ||||
62 | void positionChanged(); | ||||
63 | void sizeChanged(); | ||||
64 | void changed(); | ||||
65 | | ||||
66 | protected: | ||||
67 | QHash<int, QByteArray> roleNames() const override; | ||||
68 | | ||||
69 | private: | ||||
70 | struct Output { | ||||
71 | Output() {} | ||||
72 | Output(const Output &output) | ||||
73 | : ptr(output.ptr) | ||||
74 | , pos(output.pos) | ||||
75 | {} | ||||
76 | Output(KScreen::OutputPtr _ptr, const QPoint &_pos) | ||||
77 | : ptr(_ptr) | ||||
78 | , pos(_pos) | ||||
79 | {} | ||||
80 | KScreen::OutputPtr ptr; | ||||
81 | QPoint pos; | ||||
82 | }; | ||||
83 | | ||||
84 | void roleChanged(int outputId, OutputRoles role); | ||||
85 | void updatePositions(); | ||||
86 | void updateOrder(); | ||||
87 | QPoint originDelta() const; | ||||
88 | | ||||
89 | /** | ||||
90 | * @brief Snaps moved output to others | ||||
91 | * @param output the moved output | ||||
92 | * @param dest the desired destination to be adjusted by snapping | ||||
93 | */ | ||||
94 | void snap(const Output &output, QPoint &dest); | ||||
95 | | ||||
96 | bool setResolution(int outputIndex, int resIndex); | ||||
97 | bool setRefreshRate(int outputIndex, int refIndex); | ||||
98 | bool setRotation(int outputIndex, KScreen::Output::Rotation rotation); | ||||
99 | int resolutionIndex(const KScreen::OutputPtr &output) const; | ||||
100 | int refreshRateIndex(const KScreen::OutputPtr &output) const; | ||||
101 | QVariantList resolutionsStrings(const KScreen::OutputPtr &output) const; | ||||
102 | QVector<QSize> resolutions(const KScreen::OutputPtr &output) const; | ||||
103 | QVector<float> refreshRates(const KScreen::OutputPtr &output) const; | ||||
104 | | ||||
105 | QVector<Output> m_outputs; | ||||
106 | | ||||
107 | ConfigHandler *m_config; | ||||
108 | }; |