2 * Copyright (C) 2014-2016 Canonical, Ltd.
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.
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.
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/>.
17#include "MirSurfaceItem.h"
21#include <QGuiApplication>
24#include <QQmlProperty>
30using namespace unity::shell::application;
32#define MIRSURFACEITEM_DEBUG 0
34#if MIRSURFACEITEM_DEBUG
35#define DEBUG_MSG(params) qDebug().nospace() << "MirSurfaceItem::" << __func__ << " " << params
37#define DEBUG_MSG(params) ((void)0)
40MirSurfaceItem::MirSurfaceItem(QQuickItem *parent)
41 : MirSurfaceItemInterface(parent)
42 , m_qmlSurface(nullptr)
44 , m_consumesInput(false)
47 , m_touchPressCount(0)
48 , m_touchReleaseCount(0)
49 , m_mousePressCount(0)
50 , m_mouseReleaseCount(0)
52 DEBUG_MSG((void*)(this) << name());
53 setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton |
54 Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::ExtraButton3 | Qt::ExtraButton4 |
55 Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 |
56 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
57 Qt::ExtraButton12 | Qt::ExtraButton13);
59 connect(this, &QQuickItem::visibleChanged, this, &MirSurfaceItem::updateMirSurfaceVisibility);
62MirSurfaceItem::~MirSurfaceItem()
64 DEBUG_MSG((void*)(this) << name());
68void MirSurfaceItem::printComponentErrors()
70 QList<QQmlError> errors = m_qmlContentComponent->errors();
71 for (int i = 0; i < errors.count(); ++i) {
72 qDebug() << errors[i];
76Mir::Type MirSurfaceItem::type() const
79 return m_qmlSurface->type();
81 return Mir::UnknownType;
85Mir::State MirSurfaceItem::surfaceState() const
88 return m_qmlSurface->state();
90 return Mir::UnknownState;
94QString MirSurfaceItem::name() const
97 return m_qmlSurface->name();
103bool MirSurfaceItem::live() const
106 return m_qmlSurface->live();
112Mir::ShellChrome MirSurfaceItem::shellChrome() const
115 return m_qmlSurface->shellChrome();
117 return Mir::NormalChrome;
121Mir::OrientationAngle MirSurfaceItem::orientationAngle() const
124 return m_qmlSurface->orientationAngle();
130void MirSurfaceItem::setOrientationAngle(Mir::OrientationAngle angle)
135 if (m_qmlSurface->orientationAngle() == angle)
138 m_qmlSurface->setOrientationAngle(angle);
140 QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
141 orientationProp.write(QVariant::fromValue(m_qmlSurface->orientationAngle()));
144void MirSurfaceItem::updateScreenshot(QUrl screenshotUrl)
147 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
148 screenshotSource.write(QVariant::fromValue(screenshotUrl));
152void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
154 if (status == QQmlComponent::Ready) {
155 createQmlContentItem();
159void MirSurfaceItem::createQmlContentItem()
163 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
164 m_qmlItem->setParentItem(this);
166 setImplicitWidth(m_qmlItem->implicitWidth());
167 setImplicitHeight(m_qmlItem->implicitHeight());
170 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
171 screenshotSource.write(QVariant::fromValue(m_qmlSurface->screenshotUrl()));
175void MirSurfaceItem::touchEvent(QTouchEvent * event)
177 if (event->type() == QEvent::TouchBegin) {
178 m_touchTrail.clear();
181 if (event->touchPointStates() & Qt::TouchPointPressed) {
183 Q_EMIT touchPressCountChanged(m_touchPressCount);
184 } else if (event->touchPointStates() & Qt::TouchPointReleased) {
185 ++m_touchReleaseCount;
186 Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
189 Q_FOREACH(QTouchEvent::TouchPoint touchPoint, event->touchPoints()) {
190 QString id(touchPoint.id());
191 QVariantList list = m_touchTrail[id].toList();
192 list.append(QVariant::fromValue(touchPoint.pos()));
193 if (list.count() > 100) list.pop_front();
194 m_touchTrail[id] = list;
198 QQmlProperty touchTrail(m_qmlItem, "touchTrail");
199 touchTrail.write(m_touchTrail);
203void MirSurfaceItem::mousePressEvent(QMouseEvent * event)
206 Q_EMIT mousePressCountChanged(m_mousePressCount);
210void MirSurfaceItem::mouseMoveEvent(QMouseEvent * event)
215void MirSurfaceItem::mouseReleaseEvent(QMouseEvent * event)
217 m_mouseReleaseCount++;
218 Q_EMIT mouseReleaseCountChanged(m_mouseReleaseCount);
222void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
224 DEBUG_MSG("this=" << (void*)(this) << " name=" << name() << " surface=" << surface);
226 if (m_qmlSurface == surface) {
234 delete m_qmlContentComponent;
235 m_qmlContentComponent = nullptr;
237 disconnect(m_qmlSurface, nullptr, this, nullptr);
238 m_qmlSurface->unregisterView((qintptr)this);
241 m_qmlSurface = static_cast<MirSurface*>(surface);
244 m_qmlSurface->registerView((qintptr)this);
246 m_qmlSurface->setActiveFocus(hasActiveFocus());
249 updateMirSurfaceVisibility();
251 connect(m_qmlSurface, &MirSurface::orientationAngleChanged, this, &MirSurfaceItem::orientationAngleChanged);
252 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
253 connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
254 connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
256 QUrl qmlComponentFilePath;
257 if (!m_qmlSurface->qmlFilePath().isEmpty()) {
258 qmlComponentFilePath = m_qmlSurface->qmlFilePath();
260 qmlComponentFilePath = QUrl("qrc:///Unity/Application/MirSurfaceItem.qml");
263 m_qmlContentComponent = new QQmlComponent(QQmlEngine::contextForObject(parent())->engine(), qmlComponentFilePath);
265 switch (m_qmlContentComponent->status()) {
266 case QQmlComponent::Ready:
267 createQmlContentItem();
269 case QQmlComponent::Loading:
270 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
271 this, &MirSurfaceItem::onComponentStatusChanged);
273 case QQmlComponent::Error:
274 printComponentErrors();
275 qFatal("MirSurfaceItem: failed to create content component.");
278 qFatal("MirSurfaceItem: Unhandled component status");
282 Q_EMIT surfaceChanged(m_qmlSurface);
285void MirSurfaceItem::itemChange(ItemChange change, const ItemChangeData & value)
287 if (change == QQuickItem::ItemActiveFocusHasChanged) {
289 m_qmlSurface->setActiveFocus(value.boolValue);
294void MirSurfaceItem::updateMirSurfaceVisibility()
296 if (!m_qmlSurface) return;
298 m_qmlSurface->setViewVisibility((qintptr)this, isVisible());
301void MirSurfaceItem::setConsumesInput(bool value)
303 if (m_consumesInput != value) {
304 m_consumesInput = value;
305 Q_EMIT consumesInputChanged(value);
309int MirSurfaceItem::surfaceWidth() const
311 return m_surfaceWidth;
314void MirSurfaceItem::setSurfaceWidth(int value)
316 if (value != -1 && m_surfaceWidth != value) {
317 m_surfaceWidth = value;
318 Q_EMIT surfaceWidthChanged(m_surfaceWidth);
323int MirSurfaceItem::surfaceHeight() const
325 return m_surfaceHeight;
328void MirSurfaceItem::setSurfaceHeight(int value)
330 if (value != -1 && m_surfaceHeight != value) {
331 m_surfaceHeight = value;
332 Q_EMIT surfaceHeightChanged(m_surfaceHeight);
337void MirSurfaceItem::updateSurfaceSize()
339 if (m_qmlSurface && m_surfaceWidth > 0 && m_surfaceHeight > 0) {
340 m_qmlSurface->resize(m_surfaceWidth, m_surfaceHeight);
344void MirSurfaceItem::setFillMode(FillMode value)
346 if (value != m_fillMode) {
348 Q_EMIT fillModeChanged(m_fillMode);
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