Lomiri
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 
26 class ProxyScreen;
27 class ProxyScreens;
28 class ScreenConfig;
29 
30 class Screen: public QObject
31 {
32  Q_OBJECT
33 
34  Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
35  Q_PROPERTY(bool used READ used NOTIFY usedChanged)
36  Q_PROPERTY(QString name READ name NOTIFY nameChanged)
37  Q_PROPERTY(qtmir::OutputTypes outputType READ outputType NOTIFY outputTypeChanged)
38  Q_PROPERTY(float scale READ scale NOTIFY scaleChanged)
39  Q_PROPERTY(qtmir::FormFactor formFactor READ formFactor NOTIFY formFactorChanged)
40  Q_PROPERTY(MirPowerMode powerMode READ powerMode NOTIFY powerModeChanged)
41  Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged)
42  Q_PROPERTY(QPoint position READ position NOTIFY positionChanged)
43  Q_PROPERTY(uint currentModeIndex READ currentModeIndex NOTIFY currentModeIndexChanged)
44  Q_PROPERTY(QQmlListProperty<qtmir::ScreenMode> availableModes READ availableModes NOTIFY availableModesChanged)
45  Q_PROPERTY(QSizeF physicalSize READ physicalSize NOTIFY physicalSizeChanged)
46  Q_PROPERTY(QString outputTypeName READ outputTypeName NOTIFY outputTypeChanged)
47  Q_PROPERTY(WorkspaceModel* workspaces READ workspaces CONSTANT)
48  Q_PROPERTY(Workspace* currentWorkspace READ currentWorkspace WRITE setCurrentWorkspace2 NOTIFY currentWorkspaceChanged)
49 public:
50  bool used() const;
51  QString name() const;
52  float scale() const;
53  QSizeF physicalSize() const;
54  qtmir::FormFactor formFactor() const;
55  qtmir::OutputTypes outputType() const;
56  MirPowerMode powerMode() const;
57  Qt::ScreenOrientation orientation() const;
58  QPoint position() const;
59  QQmlListProperty<qtmir::ScreenMode> availableModes();
60  uint currentModeIndex() const;
61  bool isActive() const;
62  void setActive(bool active);
63  QScreen* qscreen() const;
64  QString outputTypeName() const;
65 
66  Q_INVOKABLE bool isSameAs(Screen*) const;
67 
68  Q_INVOKABLE ScreenConfig *beginConfiguration() const;
69  Q_INVOKABLE bool applyConfiguration(ScreenConfig *configuration);
70 
71  virtual WorkspaceModel* workspaces() const = 0;
72  virtual Workspace *currentWorkspace() const = 0;
73  virtual void setCurrentWorkspace(Workspace* workspace) = 0;
74 
75  void sync(Screen* proxy);
76 
77  qtmir::Screen* wrapped() const { return m_wrapped; }
78 
79 public Q_SLOTS:
80  void activate();
81 
82 Q_SIGNALS:
83  void usedChanged();
84  void nameChanged();
85  void outputTypeChanged();
86  void outputTypeNameChanged();
87  void scaleChanged();
88  void formFactorChanged();
89  void powerModeChanged();
90  void orientationChanged();
91  void positionChanged();
92  void currentModeIndexChanged();
93  void physicalSizeChanged();
94  void availableModesChanged();
95  void activeChanged(bool active);
96  void currentWorkspaceChanged(Workspace*);
97 
98 protected:
99  Screen(QObject* parent = 0);
100 
101  void connectToScreen(qtmir::Screen* screen);
102  void connectToScreen(Screen* screen);
103 
104 private:
105  void setCurrentWorkspace2(Workspace* workspace);
106 
107 protected:
108  QPointer<qtmir::Screen> m_wrapped;
109 };
110 
111 
112 class ConcreteScreen : public Screen
113 {
114  Q_OBJECT
115 public:
116  explicit ConcreteScreen(qtmir::Screen*const wrapped);
117 
118  // From qtmir::Screen
119  WorkspaceModel* workspaces() const override;
120  Workspace *currentWorkspace() const override;
121  void setCurrentWorkspace(Workspace* workspace) override;
122 
123 protected:
124  void resetCurrentWorkspace();
125 
126  const QScopedPointer<WorkspaceModel> m_workspaces;
127  QPointer<Workspace> m_currentWorspace;
128 };
129 
130 class ProxyScreen : public Screen
131 {
132  Q_OBJECT
133 public:
134  explicit ProxyScreen(Screen*const screen, ProxyScreens* screens);
135 
136  // From qtmir::Screen
137  WorkspaceModel* workspaces() const override;
138  Workspace *currentWorkspace() const override;
139  void setCurrentWorkspace(Workspace* workspace) override;
140 
141  Screen* proxyObject() const { return m_original.data(); }
142 
143  bool isSyncing() const;
144 
145 private:
146  const QScopedPointer<WorkspaceModel> m_workspaces;
147  const QPointer<Screen> m_original;
148  const ProxyScreens* m_screens;
149  QPointer<Workspace> m_currentWorspace;
150 };
151 
152 class ScreenConfig: public QObject
153 {
154  Q_OBJECT
155  Q_PRIVATE_PROPERTY(m_config, bool valid MEMBER used CONSTANT)
156  Q_PRIVATE_PROPERTY(m_config, bool used MEMBER used)
157  Q_PRIVATE_PROPERTY(m_config, float scale MEMBER scale)
158  Q_PRIVATE_PROPERTY(m_config, qtmir::FormFactor formFactor MEMBER formFactor)
159  Q_PRIVATE_PROPERTY(m_config, uint currentModeIndex MEMBER currentModeIndex)
160  Q_PRIVATE_PROPERTY(m_config, QPoint position MEMBER topLeft)
161 
162 public:
163  ScreenConfig(qtmir::ScreenConfiguration*);
164  ~ScreenConfig();
165 
166  qtmir::ScreenConfiguration* m_config;
167 };
168 
169 #endif // SCREEN_H