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::indexOf(Screen *screen) const
72 return m_screens.indexOf(screen);
75Screen *Screens::get(int index) const
77 return m_screens.at(index);
80int Screens::count() const
82 return m_screens.size();
85QVariant Screens::activeScreen() const
87 for (int i = 0; i < m_screens.count(); i++) {
88 if (m_screens[i]->isActive()) return i;
93void Screens::activateScreen(const QVariant& vindex)
96 int index = vindex.toInt(&ok);
97 if (!ok || index < 0 || m_screens.count() <= index) return;
99 auto screen = m_screens.at(index);
100 screen->setActive(true);
104ConcreteScreens::ConcreteScreens(const QSharedPointer<qtmir::Screens> &model, ScreensConfiguration* config)
109 connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &ConcreteScreens::onScreenAdded);
110 connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &ConcreteScreens::onScreenRemoved);
111 connect(m_wrapped.data(), &qtmir::Screens::activeScreenChanged, this, &ConcreteScreens::activeScreenChanged);
113 Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
114 auto screenWrapper(new ConcreteScreen(screen));
115 m_config->load(screenWrapper);
117 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
118 m_screens.push_back(screenWrapper);
122ConcreteScreens::~ConcreteScreens()
124 Q_FOREACH(Screen* screen, m_screens) {
125 m_config->save(screen);
130ConcreteScreens *ConcreteScreens::self()
132 return ConcreteScreens::m_self;
135ProxyScreens *ConcreteScreens::createProxy()
137 return new ProxyScreens(this);
140void ConcreteScreens::sync(ProxyScreens *proxy)
143 proxy->setSyncing(true);
145 const auto& proxyList = proxy->list();
146 for (int i = 0; i < m_screens.count() && i < proxyList.count(); ++i) {
147 m_screens[i]->sync(proxyList[i]);
150 proxy->setSyncing(false);
153void ConcreteScreens::onScreenAdded(qtmir::Screen *added)
155 Q_FOREACH(auto screenWrapper, m_screens) {
156 if (screenWrapper->wrapped() == added) return;
159 beginInsertRows(QModelIndex(), count(), count());
160 auto screenWrapper(new ConcreteScreen(added));
161 m_config->load(screenWrapper);
163 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
164 m_screens.push_back(screenWrapper);
166 Q_EMIT screenAdded(screenWrapper);
167 Q_EMIT countChanged();
170void ConcreteScreens::onScreenRemoved(qtmir::Screen *removed)
173 QMutableVectorIterator<Screen*> iter(m_screens);
174 while(iter.hasNext()) {
175 auto screenWrapper = iter.next();
176 if (screenWrapper->wrapped() == removed) {
177 m_config->save(screenWrapper);
179 beginRemoveRows(QModelIndex(), index, index);
183 Q_EMIT screenRemoved(screenWrapper);
184 Q_EMIT countChanged();
186 screenWrapper->deleteLater();
194ProxyScreens::ProxyScreens(Screens * const screens)
195 : Screens(screens->m_wrapped)
196 , m_original(screens)
199 connect(screens, &Screens::screenAdded, this, [this](Screen *added) {
200 Q_FOREACH(auto screen, m_screens) {
201 auto proxy = static_cast<ProxyScreen*>(screen);
202 if (proxy->proxyObject() == added) return;
205 beginInsertRows(QModelIndex(), count(), count());
206 auto screenWrapper(new ProxyScreen(added, this));
207 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
208 m_screens.push_back(screenWrapper);
210 Q_EMIT screenAdded(screenWrapper);
211 Q_EMIT countChanged();
214 connect(screens, &Screens::screenRemoved, this, [this](Screen *removed) {
216 QMutableVectorIterator<Screen*> iter(m_screens);
217 while(iter.hasNext()) {
218 auto proxy = static_cast<ProxyScreen*>(iter.next());
219 if (proxy->proxyObject() == removed) {
221 beginRemoveRows(QModelIndex(), index, index);
225 Q_EMIT screenRemoved(proxy);
226 Q_EMIT countChanged();
235 Q_FOREACH(Screen* screen, screens->list()) {
236 auto screenWrapper(new ProxyScreen(screen, this));
237 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
238 m_screens.push_back(screenWrapper);
242void 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