Unity 8
Screens.h
1 /*
2  * Copyright (C) 2016 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 UNITY_SCREENS_H
18 #define UNITY_SCREENS_H
19 
20 #include <QAbstractListModel>
21 #include <QSharedPointer>
22 #include <QPointer>
23 
24 namespace qtmir
25 {
26 class Screen;
27 class Screens;
28 }
29 
30 class Screen;
31 class ProxyScreens;
32 class ScreensConfiguration;
33 
34 class Screens : public QAbstractListModel
35 {
36  Q_OBJECT
37  Q_PROPERTY(int count READ count NOTIFY countChanged)
38  Q_PROPERTY(QVariant activeScreen READ activeScreen WRITE activateScreen NOTIFY activeScreenChanged)
39 
40 public:
41  enum ItemRoles {
42  ScreenRole = Qt::UserRole + 1
43  };
44 
45  virtual ~Screens();
46 
47  /* QAbstractItemModel */
48  QHash<int, QByteArray> roleNames() const override;
49  QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
50  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
51 
52  Q_INVOKABLE int indexOf(Screen*) const;
53  Q_INVOKABLE Screen* get(int index) const;
54 
55  int count() const;
56  QVariant activeScreen() const;
57 
58  const QVector<Screen*>& list() const { return m_screens; }
59 
60 public Q_SLOTS:
61  void activateScreen(const QVariant& index);
62 
63 Q_SIGNALS:
64  void countChanged();
65  void activeScreenChanged();
66 
67  void screenAdded(Screen* screen);
68  void screenRemoved(Screen* screen);
69 
70 protected:
71  Screens(const QSharedPointer<qtmir::Screens>& model);
72 
73  QVector<Screen*> m_screens;
74  const QSharedPointer<qtmir::Screens> m_wrapped;
75 
76  friend class ProxyScreens;
77 };
78 
79 class ConcreteScreens : public Screens
80 {
81  Q_OBJECT
82 public:
83  explicit ConcreteScreens(const QSharedPointer<qtmir::Screens>& model, ScreensConfiguration* config);
84  ~ConcreteScreens();
85 
86  Q_INVOKABLE ProxyScreens *createProxy();
87  Q_INVOKABLE void sync(ProxyScreens *proxy);
88 
89  static ConcreteScreens *self();
90 
91 protected Q_SLOTS:
92  void onScreenAdded(qtmir::Screen *screen);
93  void onScreenRemoved(qtmir::Screen *screen);
94 
95 private:
96  ScreensConfiguration* m_config;
97 
98  static ConcreteScreens* m_self;
99 };
100 
101 class ProxyScreens : public Screens
102 {
103 public:
104  explicit ProxyScreens(Screens*const screens);
105 
106  void setSyncing(bool syncing);
107  bool isSyncing() const { return m_syncing; }
108 
109 private:
110  const QPointer<Screens> m_original;
111  bool m_syncing;
112 };
113 
114 #endif // SCREENS_H
Definition: Screens.h:24