2 * Copyright (C) 2014-2015 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>
23#include <QQmlProperty>
29using namespace unity::shell::application;
31MirSurfaceItem::MirSurfaceItem(QQuickItem *parent)
32 : MirSurfaceItemInterface(parent)
33 , m_qmlSurface(nullptr)
35 , m_consumesInput(false)
38 , m_touchPressCount(0)
39 , m_touchReleaseCount(0)
41// qDebug() << "MirSurfaceItem::MirSurfaceItem() " << (void*)(this) << name();
42 setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton |
43 Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::ExtraButton3 | Qt::ExtraButton4 |
44 Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 |
45 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
46 Qt::ExtraButton12 | Qt::ExtraButton13);
49MirSurfaceItem::~MirSurfaceItem()
51// qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << (void*)(this) << name();
55void MirSurfaceItem::printComponentErrors()
57 QList<QQmlError> errors = m_qmlContentComponent->errors();
58 for (int i = 0; i < errors.count(); ++i) {
59 qDebug() << errors[i];
63Mir::Type MirSurfaceItem::type() const
66 return m_qmlSurface->type();
68 return Mir::UnknownType;
72Mir::State MirSurfaceItem::surfaceState() const
75 return m_qmlSurface->state();
77 return Mir::UnknownState;
81QString MirSurfaceItem::name() const
84 return m_qmlSurface->name();
90bool MirSurfaceItem::live() const
93 return m_qmlSurface->live();
99Mir::OrientationAngle MirSurfaceItem::orientationAngle() const
102 return m_qmlSurface->orientationAngle();
108void MirSurfaceItem::setOrientationAngle(Mir::OrientationAngle angle)
113 if (m_qmlSurface->orientationAngle() == angle)
116 m_qmlSurface->setOrientationAngle(angle);
118 QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
119 orientationProp.write(QVariant::fromValue(m_qmlSurface->orientationAngle()));
122void MirSurfaceItem::updateScreenshot(QUrl screenshotUrl)
125 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
126 screenshotSource.write(QVariant::fromValue(screenshotUrl));
130void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
132 if (status == QQmlComponent::Ready) {
133 createQmlContentItem();
137void MirSurfaceItem::createQmlContentItem()
139// qDebug() << "MirSurfaceItem::createQmlContentItem()";
141 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
142 m_qmlItem->setParentItem(this);
144 setImplicitWidth(m_qmlItem->implicitWidth());
145 setImplicitHeight(m_qmlItem->implicitHeight());
148 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
149 screenshotSource.write(QVariant::fromValue(m_qmlSurface->screenshotUrl()));
153void MirSurfaceItem::touchEvent(QTouchEvent * event)
155 if (event->touchPointStates() & Qt::TouchPointPressed) {
157 Q_EMIT touchPressCountChanged(m_touchPressCount);
158 } else if (event->touchPointStates() & Qt::TouchPointReleased) {
159 ++m_touchReleaseCount;
160 Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
164void MirSurfaceItem::mousePressEvent(QMouseEvent * event)
169void MirSurfaceItem::mouseMoveEvent(QMouseEvent * event)
174void MirSurfaceItem::mouseReleaseEvent(QMouseEvent * event)
179void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
181// qDebug().nospace() << "MirSurfaceItem::setSurface() this=" << (void*)(this)
182// << " name=" << name()
183// << " surface=" << surface;
185 if (m_qmlSurface == surface) {
193 delete m_qmlContentComponent;
194 m_qmlContentComponent = nullptr;
196 disconnect(m_qmlSurface, nullptr, this, nullptr);
197 m_qmlSurface->decrementViewCount();
200 m_qmlSurface = static_cast<MirSurface*>(surface);
203 m_qmlSurface->incrementViewCount();
205 m_qmlSurface->setActiveFocus(hasActiveFocus());
209 connect(m_qmlSurface, &MirSurface::orientationAngleChanged, this, &MirSurfaceItem::orientationAngleChanged);
210 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
211 connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
212 connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
214 // The assumptions I make here really should hold.
215 QQuickView *quickView =
216 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
218 QUrl qmlComponentFilePath;
219 if (!m_qmlSurface->qmlFilePath().isEmpty()) {
220 qmlComponentFilePath = m_qmlSurface->qmlFilePath();
222 qmlComponentFilePath = QUrl("qrc:///Unity/Application/MirSurfaceItem.qml");
225 m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlComponentFilePath);
227 switch (m_qmlContentComponent->status()) {
228 case QQmlComponent::Ready:
229 createQmlContentItem();
231 case QQmlComponent::Loading:
232 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
233 this, &MirSurfaceItem::onComponentStatusChanged);
235 case QQmlComponent::Error:
236 printComponentErrors();
237 qFatal("MirSurfaceItem: failed to create content component.");
240 qFatal("MirSurfaceItem: Unhandled component status");
244 Q_EMIT surfaceChanged(m_qmlSurface);
247void MirSurfaceItem::itemChange(ItemChange change, const ItemChangeData & value)
249 if (change == QQuickItem::ItemActiveFocusHasChanged) {
251 m_qmlSurface->setActiveFocus(value.boolValue);
256void MirSurfaceItem::setConsumesInput(bool value)
258 if (m_consumesInput != value) {
259 m_consumesInput = value;
260 Q_EMIT consumesInputChanged(value);
264int MirSurfaceItem::surfaceWidth() const
266 return m_surfaceWidth;
269void MirSurfaceItem::setSurfaceWidth(int value)
271 if (value != -1 && m_surfaceWidth != value) {
272 m_surfaceWidth = value;
273 Q_EMIT surfaceWidthChanged(m_surfaceWidth);
278int MirSurfaceItem::surfaceHeight() const
280 return m_surfaceHeight;
283void MirSurfaceItem::setSurfaceHeight(int value)
285 if (value != -1 && m_surfaceHeight != value) {
286 m_surfaceHeight = value;
287 Q_EMIT surfaceHeightChanged(m_surfaceHeight);
292void MirSurfaceItem::updateSurfaceSize()
294 if (m_qmlSurface && m_surfaceWidth > 0 && m_surfaceHeight > 0) {
295 m_qmlSurface->resize(m_surfaceWidth, m_surfaceHeight);
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