on 87d6679 help sign in
114 lines 2.9 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 <QDebug>
23Screens::Screens(QObject *parent) :
24 QAbstractListModel(parent)
26 bool ok = false;
27 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
28 if (!ok) screenCount = 1;
29 QPoint lastPoint(0,0);
30 for (int i = 0; i < screenCount; ++i) {
31 auto screen = new Screen();
32 screen->m_active = i == 0;
33 screen->m_name = QString("Monitor %1").arg(i);
34 screen->m_position = QPoint(lastPoint.x(), lastPoint.y());
35 screen->m_sizes.append(new ScreenMode(50, QSize(640,480)));
36 screen->m_sizes.append(new ScreenMode(60, QSize(1280,1024)));
37 screen->m_sizes.append(new ScreenMode(60, QSize(1440,900)));
38 screen->m_sizes.append(new ScreenMode(60, QSize(1920,1080)));
39 screen->m_currentModeIndex = 3;
40 screen->m_physicalSize = QSize(300,200);
41 m_screenList.append(screen);
43 lastPoint.rx() += screen->m_sizes[screen->m_currentModeIndex]->size.width();
44 }
47Screens::~Screens() noexcept
49 qDeleteAll(m_screenList);
50 m_screenList.clear();
53QHash<int, QByteArray> Screens::roleNames() const
55 QHash<int, QByteArray> roles;
56 roles[ScreenRole] = "screen";
57 return roles;
60QVariant Screens::data(const QModelIndex &index, int role) const
62 if (!index.isValid() || index.row() >= m_screenList.size()) {
63 return QVariant();
64 }
66 switch(role) {
67 case ScreenRole:
68 return QVariant::fromValue(m_screenList.at(index.row()));
69 }
71 return QVariant();
74int Screens::rowCount(const QModelIndex &) const
76 return count();
79int Screens::count() const
81 return m_screenList.size();
84void Screens::activateScreen(int)
86 qWarning("Not Implemented");
89Screen::Screen(QObject* parent)
90 : QObject(parent)
94Screen::~Screen()
96 qDeleteAll(m_sizes);
97 m_sizes.clear();
100QQmlListProperty<ScreenMode> Screen::availableModes()
102 return QQmlListProperty<ScreenMode>(this, m_sizes);
105Screen *Screen::beginConfiguration()
107 qWarning("Not Implemented");
108 return nullptr;
111void Screen::applyConfiguration()
113 qWarning("Not Implemented");