2 * Copyright (C) 2015 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/>.
20#include <QGuiApplication>
24Q_DECLARE_METATYPE(QScreen*)
26Screens::Screens(QObject *parent) :
27 QAbstractListModel(parent)
30 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
31 if (!ok) screenCount = 1;
32 QPoint lastPoint(0,0);
33 for (int i = 0; i < screenCount; ++i) {
34 auto screen = new Screen();
35 screen->enabled = i == 0;
36 screen->name = QString("Monitor %1").arg(i);
37 screen->sizes = { QSize(640,480), QSize(1024,748), QSize(1280,1024), QSize(1440,900), QSize(1920,1080) };
38 screen->geometry = QRect(lastPoint.x(), lastPoint.y(), 1024, 786 );
39 m_screenList.append(screen);
41 lastPoint.rx() += screen->geometry.width();
45Screens::~Screens() noexcept
47 qDeleteAll(m_screenList);
51QHash<int, QByteArray> Screens::roleNames() const
53 QHash<int, QByteArray> roles;
54 roles[ScreenRole] = "screen";
55 roles[OutputTypeRole] = "outputType";
56 roles[EnabledRole] = "enabled";
57 roles[NameRole] = "name";
58 roles[ScaleRole] = "scale";
59 roles[FormFactorRole] = "formFactor";
60 roles[GeometryRole] = "geometry";
61 roles[SizesRole] = "sizes";
65QVariant Screens::data(const QModelIndex &index, int role) const
67 if (!index.isValid() || index.row() >= m_screenList.size()) {
73 return QVariant::fromValue(m_screenList.at(index.row())->qScreen);
75 return m_screenList.at(index.row())->outputTypes;
77 return m_screenList.at(index.row())->enabled;
79 return m_screenList.at(index.row())->name;
81 return m_screenList.at(index.row())->scale;
83 return m_screenList.at(index.row())->formFactor;
85 return m_screenList.at(index.row())->geometry;
89 auto availableSizes = m_screenList.at(index.row())->sizes;
90 Q_FOREACH(auto size, availableSizes) {
91 sizes.append(QVariant(size));
100int Screens::rowCount(const QModelIndex &) const
105int Screens::count() const
107 return m_screenList.size();
110void Screens::activateScreen(int)
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