Lomiri
Loading...
Searching...
No Matches
Screen.h
1/*
2 * Copyright (C) 2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef SCREEN_H
18#define SCREEN_H
19
20#include <qtmir/screen.h>
21#include <QScopedPointer>
22#include <QPointer>
23
24#include "WorkspaceModel.h"
25
26class ProxyScreen;
27class ProxyScreens;
28class ScreenConfig;
29
30class Screen: public QObject
31{
32 Q_OBJECT
33
34public:
35 enum FormFactor {
36 Unknown = qtmir::FormFactorUnknown,
37 Phone = qtmir::FormFactorPhone,
38 Tablet = qtmir::FormFactorTablet,
39 Monitor = qtmir::FormFactorMonitor,
40 TV = qtmir::FormFactorTV,
41 Projector = qtmir::FormFactorProjector,
42 };
43 Q_ENUM(FormFactor)
44
45 Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
46 Q_PROPERTY(bool used READ used NOTIFY usedChanged)
47 Q_PROPERTY(QString name READ name NOTIFY nameChanged)
48 Q_PROPERTY(qtmir::OutputTypes outputType READ outputType NOTIFY outputTypeChanged)
49 Q_PROPERTY(float scale READ scale NOTIFY scaleChanged)
50 Q_PROPERTY(Screen::FormFactor formFactor READ formFactor NOTIFY formFactorChanged)
51 Q_PROPERTY(MirPowerMode powerMode READ powerMode NOTIFY powerModeChanged)
52 Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged)
53 Q_PROPERTY(QPoint position READ position NOTIFY positionChanged)
54 Q_PROPERTY(uint currentModeIndex READ currentModeIndex NOTIFY currentModeIndexChanged)
55 Q_PROPERTY(QQmlListProperty<qtmir::ScreenMode> availableModes READ availableModes NOTIFY availableModesChanged)
56 Q_PROPERTY(QSizeF physicalSize READ physicalSize NOTIFY physicalSizeChanged)
57 Q_PROPERTY(QString outputTypeName READ outputTypeName NOTIFY outputTypeChanged)
58 Q_PROPERTY(WorkspaceModel* workspaces READ workspaces CONSTANT)
59 Q_PROPERTY(Workspace* currentWorkspace READ currentWorkspace WRITE setCurrentWorkspace2 NOTIFY currentWorkspaceChanged)
60
61 bool used() const;
62 QString name() const;
63 float scale() const;
64 QSizeF physicalSize() const;
65 Screen::FormFactor formFactor() const;
66 qtmir::OutputTypes outputType() const;
67 MirPowerMode powerMode() const;
68 Qt::ScreenOrientation orientation() const;
69 QPoint position() const;
70 QQmlListProperty<qtmir::ScreenMode> availableModes();
71 uint currentModeIndex() const;
72 bool isActive() const;
73 void setActive(bool active);
74 QScreen* qscreen() const;
75 QString outputTypeName() const;
76
77 Q_INVOKABLE bool isSameAs(Screen*) const;
78
79 Q_INVOKABLE ScreenConfig *beginConfiguration() const;
80 Q_INVOKABLE bool applyConfiguration(ScreenConfig *configuration);
81
82 virtual WorkspaceModel* workspaces() const = 0;
83 virtual Workspace *currentWorkspace() const = 0;
84 virtual void setCurrentWorkspace(Workspace* workspace) = 0;
85
86 void sync(Screen* proxy);
87
88 qtmir::Screen* wrapped() const { return m_wrapped; }
89
90public Q_SLOTS:
91 void activate();
92
93Q_SIGNALS:
94 void usedChanged();
95 void nameChanged();
96 void outputTypeChanged();
97 void outputTypeNameChanged();
98 void scaleChanged();
99 void formFactorChanged();
100 void powerModeChanged();
101 void orientationChanged();
102 void positionChanged();
103 void currentModeIndexChanged();
104 void physicalSizeChanged();
105 void availableModesChanged();
106 void activeChanged(bool active);
107 void currentWorkspaceChanged(Workspace*);
108
109protected:
110 Screen(QObject* parent = 0);
111
112 void connectToScreen(qtmir::Screen* screen);
113 void connectToScreen(Screen* screen);
114
115private:
116 void setCurrentWorkspace2(Workspace* workspace);
117
118protected:
119 QPointer<qtmir::Screen> m_wrapped;
120};
121
122
123class ConcreteScreen : public Screen
124{
125 Q_OBJECT
126public:
127 explicit ConcreteScreen(qtmir::Screen*const wrapped);
128
129 // From qtmir::Screen
130 WorkspaceModel* workspaces() const override;
131 Workspace *currentWorkspace() const override;
132 void setCurrentWorkspace(Workspace* workspace) override;
133
134protected:
135 void resetCurrentWorkspace();
136
137 const QScopedPointer<WorkspaceModel> m_workspaces;
138 QPointer<Workspace> m_currentWorspace;
139};
140
141class ProxyScreen : public Screen
142{
143 Q_OBJECT
144public:
145 explicit ProxyScreen(Screen*const screen, ProxyScreens* screens);
146
147 // From qtmir::Screen
148 WorkspaceModel* workspaces() const override;
149 Workspace *currentWorkspace() const override;
150 void setCurrentWorkspace(Workspace* workspace) override;
151
152 Screen* proxyObject() const { return m_original.data(); }
153
154 bool isSyncing() const;
155
156private:
157 const QScopedPointer<WorkspaceModel> m_workspaces;
158 const QPointer<Screen> m_original;
159 const ProxyScreens* m_screens;
160 QPointer<Workspace> m_currentWorspace;
161};
162
163class ScreenConfig: public QObject
164{
165 Q_OBJECT
166 Q_PRIVATE_PROPERTY(m_config, bool valid MEMBER used CONSTANT)
167 Q_PRIVATE_PROPERTY(m_config, bool used MEMBER used)
168 Q_PRIVATE_PROPERTY(m_config, float scale MEMBER scale)
169 Q_PRIVATE_PROPERTY(m_config, qtmir::FormFactor formFactor MEMBER formFactor)
170 Q_PRIVATE_PROPERTY(m_config, uint currentModeIndex MEMBER currentModeIndex)
171 Q_PRIVATE_PROPERTY(m_config, QPoint position MEMBER topLeft)
172
173public:
174 ScreenConfig(qtmir::ScreenConfiguration*);
175 ~ScreenConfig();
176
177 qtmir::ScreenConfiguration* m_config;
178};
179
180#endif // SCREEN_H