on e84df84 help sign in
189 lines 3.9 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_viewCount(0)
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;
76void MirSurface::setLive(bool live)
78// qDebug().nospace() << "MirSurface::setLive("<<live<<") " << name();
79 if (live == m_live)
80 return;
82 m_live = live;
83 Q_EMIT liveChanged(live);
85 if (!m_live && m_viewCount == 0) {
86 deleteLater();
87 }
90QUrl MirSurface::qmlFilePath() const
92 return m_qmlFilePath;
95QUrl MirSurface::screenshotUrl() const
97 return m_screenshotUrl;
100void MirSurface::setScreenshotUrl(QUrl screenshotUrl)
102 if (screenshotUrl == m_screenshotUrl)
103 return;
105 m_screenshotUrl = screenshotUrl;
106 Q_EMIT screenshotUrlChanged(screenshotUrl);
109Mir::OrientationAngle MirSurface::orientationAngle() const
111 return m_orientationAngle;
114void MirSurface::setOrientationAngle(Mir::OrientationAngle angle)
116 if (angle == m_orientationAngle)
117 return;
119 m_orientationAngle = angle;
120 Q_EMIT orientationAngleChanged(angle);
123void MirSurface::incrementViewCount()
125 ++m_viewCount;
126// qDebug().nospace() << "MirSurface::incrementViewCount() viewCount(after)=" << m_viewCount << " " << name();
129void MirSurface::decrementViewCount()
131 --m_viewCount;
132// qDebug().nospace() << "MirSurface::decrementViewCount() viewCount(after)=" << m_viewCount << " " << name();
134 Q_ASSERT(m_viewCount >= 0);
136 if (!m_live && m_viewCount == 0) {
137 deleteLater();
138 }
141int MirSurface::viewCount() const
143 return m_viewCount;
146bool MirSurface::activeFocus() const
148 return m_activeFocus;
151void MirSurface::setActiveFocus(bool value)
153 if (m_activeFocus == value)
154 return;
156 m_activeFocus = value;
158 Q_EMIT activeFocusChanged(value);
161int MirSurface::width() const
163 return m_width;
166int MirSurface::height() const
168 return m_height;
171void MirSurface::resize(int width, int height)
173 bool changed = false;
174 if (width != m_width) {
175 m_width = width;
176 Q_EMIT widthChanged();
177 changed = true;
178 }
180 if (m_height != height) {
181 m_height = height;
182 Q_EMIT heightChanged();
183 changed = true;
184 }
186 if (changed) {
187 Q_EMIT sizeChanged(QSize(width, height));
188 }