2 * Copyright (C) 2016-2017 Canonical, Ltd.
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.
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.
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/>.
21#include <qtmir/qtmir.h>
22#include <qtmir/screens.h>
23#include <QGuiApplication>
29Screens::Screens(QObject *parent)
30 : QAbstractListModel(parent)
31 , m_wrapped(qtmir::get_screen_model())
33 if (qGuiApp->platformName() != QLatin1String("mirserver")) {
34 qCritical("Not using 'mirserver' QPA plugin. Using qGuiApp may produce unknown results.");
37 connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &Screens::onScreenAdded);
38 connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &Screens::onScreenRemoved);
39 connect(m_wrapped.data(), &qtmir::Screens::activeScreenChanged, this, &Screens::activeScreenChanged);
41 Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
42 m_screenList.push_back(new Screen(screen));
46QHash<int, QByteArray> Screens::roleNames() const
48 QHash<int, QByteArray> roles;
49 roles[ScreenRole] = "screen";
53QVariant Screens::data(const QModelIndex &index, int role) const
55 if (!index.isValid() || index.row() >= m_screenList.size()) {
61 return QVariant::fromValue(m_screenList.at(index.row()));
67int Screens::rowCount(const QModelIndex &) const
72int Screens::count() const
74 return m_screenList.size();
77QVariant Screens::activeScreen() const
79 for (int i = 0; i < m_screenList.count(); i++) {
80 if (m_screenList[i]->isActive()) return i;
85void Screens::activateScreen(const QVariant& vindex)
88 int index = vindex.toInt(&ok);
89 if (!ok || index < 0 || m_screenList.count() <= index) return;
91 auto screen = m_screenList.at(index);
92 screen->setActive(true);
95void Screens::onScreenAdded(qtmir::Screen *screen)
97 Q_FOREACH(auto screenWrapper, m_screenList) {
98 if (screenWrapper->wrapped() == screen) return;
101 beginInsertRows(QModelIndex(), count(), count());
102 auto screenWrapper(new Screen(screen));
103 m_screenList.push_back(screenWrapper);
105 Q_EMIT screenAdded(screenWrapper);
106 Q_EMIT countChanged();
109void Screens::onScreenRemoved(qtmir::Screen *screen)
112 QMutableListIterator<Screen*> iter(m_screenList);
113 while(iter.hasNext()) {
114 auto screenWrapper = iter.next();
115 if (screenWrapper->wrapped() == screen) {
117 beginRemoveRows(QModelIndex(), index, index);
121 Q_EMIT screenRemoved(screenWrapper);
122 Q_EMIT countChanged();
124 screenWrapper->deleteLater();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list