@@ -0,0 +1,92 @@
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>
23+Q_DECLARE_METATYPE(QScreen*)
25+Screens::Screens(QObject *parent) :
26+ QAbstractListModel(parent)
32+ qDeleteAll(m_screenList);
35+QHash<int, QByteArray> Screens::roleNames() const
37+ QHash<int, QByteArray> roles;
38+ roles[ScreenRole] = "screen";
39+ roles[OutputTypeRole] = "outputType";
43+QVariant Screens::data(const QModelIndex &index, int role) const
45+ if (!index.isValid() || index.row() >= m_screenList.size()) {
51+ return QVariant::fromValue(m_screenList.at(index.row()));
53+ return OutputTypes::Unknown;
59+int Screens::rowCount(const QModelIndex &) const
64+int Screens::count() const
66+ return m_screenList.size();
69+void Screens::onScreenAdded(QScreen *screen)
71+ if (m_screenList.contains(screen))
74+ beginInsertRows(QModelIndex(), count(), count());
75+ m_screenList.push_back(screen);
77+ Q_EMIT screenAdded(screen);
78+ Q_EMIT countChanged();
81+void Screens::onScreenRemoved(QScreen *screen)
83+ int index = m_screenList.indexOf(screen);
87+ beginRemoveRows(QModelIndex(), index, index);
88+ m_screenList.removeAt(index);
90+ Q_EMIT screenRemoved(screen);
91+ Q_EMIT countChanged();