2 * Copyright (C) 2016-2017 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/>.
18#include "ScreensConfiguration.h"
20#include "WorkspaceManager.h"
23#include <qtmir/screens.h>
24#include <QGuiApplication>
31ConcreteScreens* ConcreteScreens::m_self{nullptr};
33Screens::Screens(const QSharedPointer<qtmir::Screens>& model)
40 qDeleteAll(m_screens);
44QHash<int, QByteArray> Screens::roleNames() const
46 QHash<int, QByteArray> roles;
47 roles[ScreenRole] = "screen";
51QVariant Screens::data(const QModelIndex &index, int role) const
53 if (!index.isValid() || index.row() >= m_screens.size()) {
59 return QVariant::fromValue(m_screens.at(index.row()));
65int Screens::rowCount(const QModelIndex &) const
70int Screens::count() const
72 return m_screens.size();
75QVariant Screens::activeScreen() const
77 for (int i = 0; i < m_screens.count(); i++) {
78 if (m_screens[i]->isActive()) return i;
83void Screens::activateScreen(const QVariant& vindex)
86 int index = vindex.toInt(&ok);
87 if (!ok || index < 0 || m_screens.count() <= index) return;
89 auto screen = m_screens.at(index);
90 screen->setActive(true);
94ConcreteScreens::ConcreteScreens(const QSharedPointer<qtmir::Screens> &model, ScreensConfiguration* config)
99 connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &ConcreteScreens::onScreenAdded);
100 connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &ConcreteScreens::onScreenRemoved);
101 connect(m_wrapped.data(), &qtmir::Screens::activeScreenChanged, this, &ConcreteScreens::activeScreenChanged);
103 Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
104 auto screenWrapper(new ConcreteScreen(screen));
105 m_config->load(screenWrapper);
107 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
108 m_screens.push_back(screenWrapper);
112ConcreteScreens::~ConcreteScreens()
114 Q_FOREACH(Screen* screen, m_screens) {
115 m_config->save(screen);
120ConcreteScreens *ConcreteScreens::self()
122 return ConcreteScreens::m_self;
125ProxyScreens *ConcreteScreens::createProxy()
127 return new ProxyScreens(this);
130void ConcreteScreens::sync(Screens *proxy)
134 for (auto screen : m_screens) {
135 screen->setSyncing(true);
138 const auto& proxyList = proxy->list();
139 for (int i = 0; i < m_screens.count() && i < proxyList.count(); ++i) {
140 m_screens[i]->sync(proxyList[i]);
143 for (auto screen : m_screens) {
144 screen->setSyncing(false);
148void ConcreteScreens::onScreenAdded(qtmir::Screen *added)
150 Q_FOREACH(auto screenWrapper, m_screens) {
151 if (screenWrapper->wrapped() == added) return;
154 beginInsertRows(QModelIndex(), count(), count());
155 auto screenWrapper(new ConcreteScreen(added));
156 m_config->load(screenWrapper);
158 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
159 m_screens.push_back(screenWrapper);
161 Q_EMIT screenAdded(screenWrapper);
162 Q_EMIT countChanged();
165void ConcreteScreens::onScreenRemoved(qtmir::Screen *removed)
168 QMutableVectorIterator<Screen*> iter(m_screens);
169 while(iter.hasNext()) {
170 auto screenWrapper = iter.next();
171 if (screenWrapper->wrapped() == removed) {
172 m_config->save(screenWrapper);
174 beginRemoveRows(QModelIndex(), index, index);
178 Q_EMIT screenRemoved(screenWrapper);
179 Q_EMIT countChanged();
181 screenWrapper->deleteLater();
189ProxyScreens::ProxyScreens(Screens * const screens)
190 : Screens(screens->m_wrapped)
191 , m_original(screens)
193 connect(screens, &Screens::screenAdded, this, [this](Screen *added) {
194 Q_FOREACH(auto screen, m_screens) {
195 auto proxy = static_cast<ProxyScreen*>(screen);
196 if (proxy->proxyObject() == added) return;
199 beginInsertRows(QModelIndex(), count(), count());
200 auto screenWrapper(new ProxyScreen(added));
201 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
202 m_screens.push_back(screenWrapper);
204 Q_EMIT screenAdded(screenWrapper);
205 Q_EMIT countChanged();
208 connect(screens, &Screens::screenRemoved, this, [this](Screen *removed) {
210 QMutableVectorIterator<Screen*> iter(m_screens);
211 while(iter.hasNext()) {
212 auto proxy = static_cast<ProxyScreen*>(iter.next());
213 if (proxy->proxyObject() == removed) {
215 beginRemoveRows(QModelIndex(), index, index);
219 Q_EMIT screenRemoved(proxy);
220 Q_EMIT countChanged();
229 Q_FOREACH(Screen* screen, screens->list()) {
230 auto screenWrapper(new ProxyScreen(screen));
231 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
232 m_screens.push_back(new ProxyScreen(screen));
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