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(ProxyScreens *proxy)
133 proxy->setSyncing(true);
135 const auto& proxyList = proxy->list();
136 for (int i = 0; i < m_screens.count() && i < proxyList.count(); ++i) {
137 m_screens[i]->sync(proxyList[i]);
140 proxy->setSyncing(true);
143void ConcreteScreens::onScreenAdded(qtmir::Screen *added)
145 Q_FOREACH(auto screenWrapper, m_screens) {
146 if (screenWrapper->wrapped() == added) return;
149 beginInsertRows(QModelIndex(), count(), count());
150 auto screenWrapper(new ConcreteScreen(added));
151 m_config->load(screenWrapper);
153 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
154 m_screens.push_back(screenWrapper);
156 Q_EMIT screenAdded(screenWrapper);
157 Q_EMIT countChanged();
160void ConcreteScreens::onScreenRemoved(qtmir::Screen *removed)
163 QMutableVectorIterator<Screen*> iter(m_screens);
164 while(iter.hasNext()) {
165 auto screenWrapper = iter.next();
166 if (screenWrapper->wrapped() == removed) {
167 m_config->save(screenWrapper);
169 beginRemoveRows(QModelIndex(), index, index);
173 Q_EMIT screenRemoved(screenWrapper);
174 Q_EMIT countChanged();
176 screenWrapper->deleteLater();
184ProxyScreens::ProxyScreens(Screens * const screens)
185 : Screens(screens->m_wrapped)
186 , m_original(screens)
189 connect(screens, &Screens::screenAdded, this, [this](Screen *added) {
190 Q_FOREACH(auto screen, m_screens) {
191 auto proxy = static_cast<ProxyScreen*>(screen);
192 if (proxy->proxyObject() == added) return;
195 beginInsertRows(QModelIndex(), count(), count());
196 auto screenWrapper(new ProxyScreen(added, this));
197 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
198 m_screens.push_back(screenWrapper);
200 Q_EMIT screenAdded(screenWrapper);
201 Q_EMIT countChanged();
204 connect(screens, &Screens::screenRemoved, this, [this](Screen *removed) {
206 QMutableVectorIterator<Screen*> iter(m_screens);
207 while(iter.hasNext()) {
208 auto proxy = static_cast<ProxyScreen*>(iter.next());
209 if (proxy->proxyObject() == removed) {
211 beginRemoveRows(QModelIndex(), index, index);
215 Q_EMIT screenRemoved(proxy);
216 Q_EMIT countChanged();
225 Q_FOREACH(Screen* screen, screens->list()) {
226 auto screenWrapper(new ProxyScreen(screen, this));
227 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
228 m_screens.push_back(screenWrapper);
232void ProxyScreens::setSyncing(bool syncing)
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