on 00a2ef4 help sign in
216 lines 4.6 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "MirSurface.h"
19#include <QDebug>
21MirSurface::MirSurface(const QString& name,
22 Mir::Type type,
23 Mir::State state,
24 const QUrl& screenshot,
25 const QUrl &qmlFilePath)
26 : unity::shell::application::MirSurfaceInterface(nullptr)
27 , m_name(name)
28 , m_type(type)
29 , m_state(state)
30 , m_orientationAngle(Mir::Angle0)
31 , m_screenshotUrl(screenshot)
32 , m_qmlFilePath(qmlFilePath)
33 , m_live(true)
34 , m_visible(true)
35 , m_activeFocus(false)
36 , m_width(-1)
37 , m_height(-1)
39// qDebug() << "MirSurface::MirSurface() " << name;
42MirSurface::~MirSurface()
44// qDebug() << "MirSurface::~MirSurface() " << name();
47QString MirSurface::name() const
49 return m_name;
52Mir::Type MirSurface::type() const
54 return m_type;
57Mir::State MirSurface::state() const
59 return m_state;
62void MirSurface::setState(Mir::State state)
64 if (state == m_state)
65 return;
67 m_state = state;
68 Q_EMIT stateChanged(state);
71bool MirSurface::live() const
73 return m_live;
76bool MirSurface::visible() const
78 return m_visible;
81void MirSurface::setLive(bool live)
83// qDebug().nospace() << "MirSurface::setLive("<<live<<") " << name();
84 if (live == m_live)
85 return;
87 m_live = live;
88 Q_EMIT liveChanged(live);
90 if (!m_live && m_views.count() == 0) {
91 deleteLater();
92 }
95QUrl MirSurface::qmlFilePath() const
97 return m_qmlFilePath;
100QUrl MirSurface::screenshotUrl() const
102 return m_screenshotUrl;
105void MirSurface::setScreenshotUrl(QUrl screenshotUrl)
107 if (screenshotUrl == m_screenshotUrl)
108 return;
110 m_screenshotUrl = screenshotUrl;
111 Q_EMIT screenshotUrlChanged(screenshotUrl);
114Mir::OrientationAngle MirSurface::orientationAngle() const
116 return m_orientationAngle;
119void MirSurface::setOrientationAngle(Mir::OrientationAngle angle)
121 if (angle == m_orientationAngle)
122 return;
124 m_orientationAngle = angle;
125 Q_EMIT orientationAngleChanged(angle);
130void MirSurface::registerView(qintptr viewId)
132 m_views.insert(viewId, MirSurface::View{false});
133// qDebug().nospace() << "MirSurface[" << name() << "]::registerView(" << viewId << ")"
134// << " after=" << m_views.count();
137void MirSurface::unregisterView(qintptr viewId)
139// qDebug().nospace() << "MirSurface[" << name() << "]::unregisterView(" << viewId << ")"
140// << " after=" << m_views.count() << " live=" << m_live;
141 m_views.remove(viewId);
142 if (!m_live && m_views.count() == 0) {
143 deleteLater();
144 }
145 updateVisibility();
148void MirSurface::setViewVisibility(qintptr viewId, bool visible)
150 if (!m_views.contains(viewId)) return;
152 m_views[viewId].visible = visible;
153 updateVisibility();
156void MirSurface::updateVisibility()
158 bool newVisible = false;
159 QHashIterator<qintptr, View> i(m_views);
160 while (i.hasNext()) {
161 i.next();
162 newVisible |= i.value().visible;
163 }
165 if (newVisible != visible()) {
166// qDebug().nospace() << "MirSurface[" << name() << "]::updateVisibility(" << newVisible << ")";
168 m_visible = newVisible;
169 Q_EMIT visibleChanged(m_visible);
170 }
173bool MirSurface::activeFocus() const
175 return m_activeFocus;
178void MirSurface::setActiveFocus(bool value)
180 if (m_activeFocus == value)
181 return;
183 m_activeFocus = value;
185 Q_EMIT activeFocusChanged(value);
188int MirSurface::width() const
190 return m_width;
193int MirSurface::height() const
195 return m_height;
198void MirSurface::resize(int width, int height)
200 bool changed = false;
201 if (width != m_width) {
202 m_width = width;
203 Q_EMIT widthChanged();
204 changed = true;
205 }
207 if (m_height != height) {
208 m_height = height;
209 Q_EMIT heightChanged();
210 changed = true;
211 }
213 if (changed) {
214 Q_EMIT sizeChanged(QSize(width, height));
215 }