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);
48 connect(this, &QQuickItem::visibleChanged, this, &MirSurfaceItem::updateMirSurfaceVisibility);
51MirSurfaceItem::~MirSurfaceItem()
53// qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << (void*)(this) << name();
57void MirSurfaceItem::printComponentErrors()
59 QList<QQmlError> errors = m_qmlContentComponent->errors();
60 for (int i = 0; i < errors.count(); ++i) {
61 qDebug() << errors[i];
65Mir::Type MirSurfaceItem::type() const
68 return m_qmlSurface->type();
70 return Mir::UnknownType;
74Mir::State MirSurfaceItem::surfaceState() const
77 return m_qmlSurface->state();
79 return Mir::UnknownState;
83QString MirSurfaceItem::name() const
86 return m_qmlSurface->name();
92bool MirSurfaceItem::live() const
95 return m_qmlSurface->live();
101Mir::OrientationAngle MirSurfaceItem::orientationAngle() const
104 return m_qmlSurface->orientationAngle();
110void MirSurfaceItem::setOrientationAngle(Mir::OrientationAngle angle)
115 if (m_qmlSurface->orientationAngle() == angle)
118 m_qmlSurface->setOrientationAngle(angle);
120 QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
121 orientationProp.write(QVariant::fromValue(m_qmlSurface->orientationAngle()));
124void MirSurfaceItem::updateScreenshot(QUrl screenshotUrl)
127 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
128 screenshotSource.write(QVariant::fromValue(screenshotUrl));
132void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
134 if (status == QQmlComponent::Ready) {
135 createQmlContentItem();
139void MirSurfaceItem::createQmlContentItem()
141// qDebug() << "MirSurfaceItem::createQmlContentItem()";
143 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
144 m_qmlItem->setParentItem(this);
146 setImplicitWidth(m_qmlItem->implicitWidth());
147 setImplicitHeight(m_qmlItem->implicitHeight());
150 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
151 screenshotSource.write(QVariant::fromValue(m_qmlSurface->screenshotUrl()));
155void MirSurfaceItem::touchEvent(QTouchEvent * event)
157 if (event->touchPointStates() & Qt::TouchPointPressed) {
159 Q_EMIT touchPressCountChanged(m_touchPressCount);
160 } else if (event->touchPointStates() & Qt::TouchPointReleased) {
161 ++m_touchReleaseCount;
162 Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
166void MirSurfaceItem::mousePressEvent(QMouseEvent * event)
171void MirSurfaceItem::mouseMoveEvent(QMouseEvent * event)
176void MirSurfaceItem::mouseReleaseEvent(QMouseEvent * event)
181void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
183// qDebug().nospace() << "MirSurfaceItem::setSurface() this=" << (void*)(this)
184// << " name=" << name()
185// << " surface=" << surface;
187 if (m_qmlSurface == surface) {
195 delete m_qmlContentComponent;
196 m_qmlContentComponent = nullptr;
198 disconnect(m_qmlSurface, nullptr, this, nullptr);
199 m_qmlSurface->unregisterView((qintptr)this);
202 m_qmlSurface = static_cast<MirSurface*>(surface);
205 m_qmlSurface->registerView((qintptr)this);
207 m_qmlSurface->setActiveFocus(hasActiveFocus());
210 updateMirSurfaceVisibility();
212 connect(m_qmlSurface, &MirSurface::orientationAngleChanged, this, &MirSurfaceItem::orientationAngleChanged);
213 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
214 connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
215 connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
217 // The assumptions I make here really should hold.
218 QQuickView *quickView =
219 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
221 QUrl qmlComponentFilePath;
222 if (!m_qmlSurface->qmlFilePath().isEmpty()) {
223 qmlComponentFilePath = m_qmlSurface->qmlFilePath();
225 qmlComponentFilePath = QUrl("qrc:///Unity/Application/MirSurfaceItem.qml");
228 m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlComponentFilePath);
230 switch (m_qmlContentComponent->status()) {
231 case QQmlComponent::Ready:
232 createQmlContentItem();
234 case QQmlComponent::Loading:
235 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
236 this, &MirSurfaceItem::onComponentStatusChanged);
238 case QQmlComponent::Error:
239 printComponentErrors();
240 qFatal("MirSurfaceItem: failed to create content component.");
243 qFatal("MirSurfaceItem: Unhandled component status");
247 Q_EMIT surfaceChanged(m_qmlSurface);
250void MirSurfaceItem::itemChange(ItemChange change, const ItemChangeData & value)
252 if (change == QQuickItem::ItemActiveFocusHasChanged) {
254 m_qmlSurface->setActiveFocus(value.boolValue);
259void MirSurfaceItem::updateMirSurfaceVisibility()
261 if (!m_qmlSurface) return;
263 m_qmlSurface->setViewVisibility((qintptr)this, isVisible());
266void MirSurfaceItem::setConsumesInput(bool value)
268 if (m_consumesInput != value) {
269 m_consumesInput = value;
270 Q_EMIT consumesInputChanged(value);
274int MirSurfaceItem::surfaceWidth() const
276 return m_surfaceWidth;
279void MirSurfaceItem::setSurfaceWidth(int value)
281 if (value != -1 && m_surfaceWidth != value) {
282 m_surfaceWidth = value;
283 Q_EMIT surfaceWidthChanged(m_surfaceWidth);
288int MirSurfaceItem::surfaceHeight() const
290 return m_surfaceHeight;
293void MirSurfaceItem::setSurfaceHeight(int value)
295 if (value != -1 && m_surfaceHeight != value) {
296 m_surfaceHeight = value;
297 Q_EMIT surfaceHeightChanged(m_surfaceHeight);
302void MirSurfaceItem::updateSurfaceSize()
304 if (m_qmlSurface && m_surfaceWidth > 0 && m_surfaceHeight > 0) {
305 m_qmlSurface->resize(m_surfaceWidth, m_surfaceHeight);
309void MirSurfaceItem::setFillMode(FillMode value)
311 if (value != m_fillMode) {
313 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