on 02d6bc0 help sign in
113 lines 2.9 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;
32class ScreensConfiguration;
34class Screens : public QAbstractListModel
36 Q_OBJECT
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 Q_PROPERTY(QVariant activeScreen READ activeScreen WRITE activateScreen NOTIFY activeScreenChanged)
40public:
41 enum ItemRoles {
42 ScreenRole = Qt::UserRole + 1
43 };
45 virtual ~Screens();
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;
52 Q_INVOKABLE int indexOf(Screen*) const;
53 Q_INVOKABLE Screen* get(int index) const;
55 int count() const;
56 QVariant activeScreen() const;
58 bool isSyncing() const { return m_syncing; }
60 const QVector<Screen*>& list() const { return m_screens; }
62public Q_SLOTS:
63 void activateScreen(const QVariant& index);
65Q_SIGNALS:
66 void countChanged();
67 void activeScreenChanged();
69 void screenAdded(Screen* screen);
70 void screenRemoved(Screen* screen);
72protected:
73 Screens(const QSharedPointer<qtmir::Screens>& model);
75 QVector<Screen*> m_screens;
76 const QSharedPointer<qtmir::Screens> m_wrapped;
77 bool m_syncing;
79 friend class ProxyScreens;
80};
82class ConcreteScreens : public Screens
84 Q_OBJECT
85public:
86 explicit ConcreteScreens(const QSharedPointer<qtmir::Screens>& model, ScreensConfiguration* config);
87 ~ConcreteScreens();
89 Q_INVOKABLE ProxyScreens *createProxy();
90 Q_INVOKABLE void sync(Screens *proxy);
92 static ConcreteScreens *self();
94protected Q_SLOTS:
95 void onScreenAdded(qtmir::Screen *screen);
96 void onScreenRemoved(qtmir::Screen *screen);
98private:
99 ScreensConfiguration* m_config;
101 static ConcreteScreens* m_self;
102};
104class ProxyScreens : public Screens
106public:
107 explicit ProxyScreens(Screens*const screens);
109private:
110 const QPointer<Screens> m_original;
111};
113#endif // SCREENS_H