on 8fdf9a4 help sign in
106 lines 2.6 kB history raw
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 */
17#ifndef UNITY_SCREENS_H
18#define UNITY_SCREENS_H
20#include <QAbstractListModel>
21#include <QSharedPointer>
22#include <QPointer>
24namespace qtmir
26class Screen;
27class Screens;
30class Screen;
31class ProxyScreens;
33class Screens : public QAbstractListModel
35 Q_OBJECT
36 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 Q_PROPERTY(QVariant activeScreen READ activeScreen WRITE activateScreen NOTIFY activeScreenChanged)
39public:
40 enum ItemRoles {
41 ScreenRole = Qt::UserRole + 1
42 };
44 ~Screens();
46 /* QAbstractItemModel */
47 QHash<int, QByteArray> roleNames() const override;
48 QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
49 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
51 int count() const;
52 QVariant activeScreen() const;
54 bool isSyncing() const { return m_syncing; }
56 const QVector<Screen*>& list() const { return m_screens; }
58public Q_SLOTS:
59 void activateScreen(const QVariant& index);
61Q_SIGNALS:
62 void countChanged();
63 void activeScreenChanged();
65 void screenAdded(Screen* screen);
66 void screenRemoved(Screen* screen);
68protected:
69 Screens(const QSharedPointer<qtmir::Screens>& model);
71 QVector<Screen*> m_screens;
72 const QSharedPointer<qtmir::Screens> m_wrapped;
73 bool m_syncing;
75 friend class ProxyScreens;
76};
78class ConcreteScreens : public Screens
80 Q_OBJECT
81public:
82 explicit ConcreteScreens(const QSharedPointer<qtmir::Screens>& model);
84 Q_INVOKABLE ProxyScreens *createProxy();
85 Q_INVOKABLE void sync(Screens *proxy);
87 static ConcreteScreens *self();
89protected Q_SLOTS:
90 void onScreenAdded(qtmir::Screen *screen);
91 void onScreenRemoved(qtmir::Screen *screen);
93private:
94 static ConcreteScreens* m_self;
95};
97class ProxyScreens : public Screens
99public:
100 explicit ProxyScreens(Screens*const screens);
102private:
103 const QPointer<Screens> m_original;
104};
106#endif // SCREENS_H