on 17872af help sign in
101 lines 2.9 kB history raw
1/*
2 * Copyright (C) 2016-2017 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"
18#include "Screen.h"
20// qtmirserver
21#include <qtmir/qtmir.h>
22#include <qtmir/screens.h>
23#include <QGuiApplication>
25// Qt
26#include <QScreen>
27#include <QWindow>
29Screens::Screens(QObject *parent)
30 : QAbstractListModel(parent)
32 bool ok = false;
33 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
34 if (!ok) screenCount = 1;
35 QPoint lastPoint(0,0);
36 for (int i = 0; i < screenCount; ++i) {
37 auto screen = new Screen();
38 screen->m_id = qtmir::OutputId{i};
39 screen->m_active = i == 0;
40 screen->m_name = QString("Monitor %1").arg(i);
41 screen->m_position = QPoint(lastPoint.x(), lastPoint.y());
42 screen->m_sizes.append(new qtmir::ScreenMode(50, QSize(640,480)));
43 screen->m_sizes.append(new qtmir::ScreenMode(60, QSize(1280,1024)));
44 screen->m_sizes.append(new qtmir::ScreenMode(60, QSize(1440,900)));
45 screen->m_sizes.append(new qtmir::ScreenMode(60, QSize(1920,1080)));
46 screen->m_currentModeIndex = 3;
47 screen->m_physicalSize = QSize(800,568);
48 m_screenList.append(screen);
50 lastPoint.rx() += screen->m_sizes[screen->m_currentModeIndex]->size.width();
51 }
54QHash<int, QByteArray> Screens::roleNames() const
56 QHash<int, QByteArray> roles;
57 roles[ScreenRole] = "screen";
58 return roles;
61QVariant Screens::data(const QModelIndex &index, int role) const
63 if (!index.isValid() || index.row() >= m_screenList.size()) {
64 return QVariant();
65 }
67 switch(role) {
68 case ScreenRole:
69 return QVariant::fromValue(m_screenList.at(index.row()));
70 } // switch
72 return QVariant();
75int Screens::rowCount(const QModelIndex &) const
77 return count();
80int Screens::count() const
82 return m_screenList.size();
85QVariant Screens::activeScreen() const
87 for (int i = 0; i < m_screenList.count(); i++) {
88 if (m_screenList[i]->isActive()) return i;
89 }
90 return QVariant();
93void Screens::activateScreen(const QVariant& vindex)
95 bool ok = false;
96 int index = vindex.toInt(&ok);
97 if (!ok || index < 0 || m_screenList.count() <= index) return;
99 auto screen = m_screenList.at(index);
100 screen->setActive(true);