on 0144005 help sign in
117 lines 3.4 kB history raw
1/*
2 * Copyright (C) 2015 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#include "screens.h"
19// Qt
20#include <QGuiApplication>
21#include <QScreen>
22#include <QDebug>
24Q_DECLARE_METATYPE(QScreen*)
26Screens::Screens(QObject *parent) :
27 QAbstractListModel(parent)
29 bool ok = false;
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 if (i == 0) {
37 screen->outputTypes = OutputTypes::LVDS;
38 } else {
39 screen->outputTypes = OutputTypes::HDMIA;
40 }
41 screen->name = QString("Monitor %1").arg(i);
42 screen->sizes = { QSize(640,480), QSize(1024,748), QSize(1280,1024), QSize(1440,900), QSize(1920,1080) };
43 screen->geometry = QRect(lastPoint.x(), lastPoint.y(), 1024, 786 );
44 m_screenList.append(screen);
46 lastPoint.rx() += screen->geometry.width();
47 }
50Screens::~Screens() noexcept
52 qDeleteAll(m_screenList);
53 m_screenList.clear();
56QHash<int, QByteArray> Screens::roleNames() const
58 QHash<int, QByteArray> roles;
59 roles[ScreenRole] = "screen";
60 roles[OutputTypeRole] = "outputType";
61 roles[EnabledRole] = "enabled";
62 roles[NameRole] = "name";
63 roles[ScaleRole] = "scale";
64 roles[FormFactorRole] = "formFactor";
65 roles[GeometryRole] = "geometry";
66 roles[SizesRole] = "sizes";
67 return roles;
70QVariant Screens::data(const QModelIndex &index, int role) const
72 if (!index.isValid() || index.row() >= m_screenList.size()) {
73 return QVariant();
74 }
76 switch(role) {
77 case ScreenRole:
78 return QVariant::fromValue(m_screenList.at(index.row())->qScreen);
79 case OutputTypeRole:
80 return m_screenList.at(index.row())->outputTypes;
81 case EnabledRole:
82 return m_screenList.at(index.row())->enabled;
83 case NameRole:
84 return m_screenList.at(index.row())->name;
85 case ScaleRole:
86 return m_screenList.at(index.row())->scale;
87 case FormFactorRole:
88 return m_screenList.at(index.row())->formFactor;
89 case GeometryRole:
90 return m_screenList.at(index.row())->geometry;
91 case SizesRole:
92 {
93 QVariantList sizes;
94 auto availableSizes = m_screenList.at(index.row())->sizes;
95 Q_FOREACH(auto size, availableSizes) {
96 sizes.append(QVariant(size));
97 }
98 return sizes;
99 }
100 }
102 return QVariant();
105int Screens::rowCount(const QModelIndex &) const
107 return count();
110int Screens::count() const
112 return m_screenList.size();
115void Screens::activateScreen(int)