@@ -15,7 +15,6 @@
17#include "MirSurfaceItem.h"
17#include "MirSurfaceItem.h"
20#include <paths.h>
19#include <paths.h>
@@ -27,69 +26,30 @@
28#include <QDebug>
27#include <QDebug>
30−MirSurfaceItem::MirSurfaceItem(const QString& name,
29+using namespace unity::shell::application;
31− MirSurfaceItem::Type type,
30+
32− MirSurfaceItem::State state,
33− const QUrl& screenshot,
34− const QString &qmlFilePath,
35− QQuickItem *parent)
31+MirSurfaceItem::MirSurfaceItem(QQuickItem *parent)
36− : QQuickItem(parent)
32+ : MirSurfaceItemInterface(parent)
37− , m_session(nullptr)
33+ , m_qmlSurface(nullptr)
42− , m_orientationAngle(Angle0)
43 , m_qmlItem(nullptr)
34 , m_qmlItem(nullptr)
44− , m_screenshotUrl(screenshot)
35+ , m_consumesInput(false)
45 , m_touchPressCount(0)
38 , m_touchPressCount(0)
46 , m_touchReleaseCount(0)
39 , m_touchReleaseCount(0)
41+ qDebug() << "MirSurfaceItem::MirSurfaceItem() " << (void*)(this) << name();
48 setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton |
42 setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton |
49 Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::ExtraButton3 | Qt::ExtraButton4 |
43 Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::ExtraButton3 | Qt::ExtraButton4 |
50 Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 |
44 Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 |
51 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
45 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
52 Qt::ExtraButton12 | Qt::ExtraButton13);
46 Qt::ExtraButton12 | Qt::ExtraButton13);
54− QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
56− // The assumptions I make here really should hold.
57− QQuickView *quickView =
58− qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
60− QString qmlComponentFilePath;
61− if (!qmlFilePath.isEmpty()) {
62− qmlComponentFilePath.append(qmlFilePath);
64− qmlComponentFilePath = QString("%1/Unity/Application/MirSurfaceItem.qml")
65− .arg(mockPluginsDir());
68− m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlComponentFilePath);
70− switch (m_qmlContentComponent->status()) {
71− case QQmlComponent::Ready:
72− createQmlContentItem();
74− case QQmlComponent::Loading:
75− connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
76− this, &MirSurfaceItem::onComponentStatusChanged);
78− case QQmlComponent::Error:
79− printComponentErrors();
80− qFatal("MirSurfaceItem: failed to create content component.");
83− qFatal("MirSurfaceItem: Unhandled component status");
87MirSurfaceItem::~MirSurfaceItem()
49MirSurfaceItem::~MirSurfaceItem()
89− qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
51+ qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << (void*)(this) << name();
91− m_session->setSurface(nullptr);
52+ setSurface(nullptr);
95void MirSurfaceItem::printComponentErrors()
55void MirSurfaceItem::printComponentErrors()
@@ -100,58 +60,70 @@ void MirSurfaceItem::printComponentErrors()
103−void MirSurfaceItem::release()
63+Mir::Type MirSurfaceItem::type() const
105− qDebug() << "MirSurfaceItem::release " << name();
65+ if (m_qmlSurface) {
106−
66+ return m_qmlSurface->type();
107− if (m_session) {
67+ } else {
108− m_session->setSurface(nullptr);
68+ return Mir::UnknownType;
115−void MirSurfaceItem::setOrientationAngle(OrientationAngle angle)
72+Mir::State MirSurfaceItem::surfaceState() const
117− if (m_orientationAngle == angle)
74+ if (m_qmlSurface) {
118− return;
75+ return m_qmlSurface->state();
120− m_orientationAngle = angle;
77+ return Mir::UnknownState;
122− QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
123− orientationProp.write(QVariant::fromValue(m_orientationAngle));
125− Q_EMIT orientationAngleChanged(m_orientationAngle);
128−void MirSurfaceItem::setSession(Session* session)
81+QString MirSurfaceItem::name() const
130− m_session = session;
83+ if (m_qmlSurface) {
84+ return m_qmlSurface->name();
133−void MirSurfaceItem::setScreenshot(const QUrl& screenshot)
90+bool MirSurfaceItem::live() const
135− m_screenshotUrl = screenshot;
92+ if (m_qmlSurface) {
136− if (m_qmlItem) {
93+ return m_qmlSurface->live();
137− QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
94+ } else {
138− screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
95+ return false;
142−void MirSurfaceItem::setLive(bool live)
99+Mir::OrientationAngle MirSurfaceItem::orientationAngle() const
144− if (m_live != live) {
101+ if (m_qmlSurface) {
145− m_live = live;
102+ return m_qmlSurface->orientationAngle();
146− Q_EMIT liveChanged(m_live);
103+ } else {
150−void MirSurfaceItem::setState(MirSurfaceItem::State newState)
108+void MirSurfaceItem::setOrientationAngle(Mir::OrientationAngle angle)
152− if (newState != m_state) {
110+ if (!m_qmlSurface)
153− m_state = newState;
111+ return;
154− Q_EMIT stateChanged(newState);
112+
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()));
122+void MirSurfaceItem::updateScreenshot(QUrl screenshotUrl)
125+ QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
126+ screenshotSource.write(QVariant::fromValue(screenshotUrl));
@@ -174,7 +146,7 @@ void MirSurfaceItem::createQmlContentItem()
176 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
148 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
177− screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
149+ screenshotSource.write(QVariant::fromValue(m_qmlSurface->screenshotUrl()));
@@ -188,3 +160,124 @@ void MirSurfaceItem::touchEvent(QTouchEvent * event)
188 Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
160 Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
164+void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
166+ qDebug().nospace() << "MirSurfaceItem::setSurface() this=" << (void*)(this)
167+ << " name=" << name()
168+ << " surface=" << surface;
170+ if (m_qmlSurface == surface) {
176+ m_qmlItem = nullptr;
178+ delete m_qmlContentComponent;
179+ m_qmlContentComponent = nullptr;
181+ disconnect(m_qmlSurface, nullptr, this, nullptr);
182+ m_qmlSurface->decrementViewCount();
185+ m_qmlSurface = static_cast<MirSurface*>(surface);
188+ m_qmlSurface->incrementViewCount();
190+ m_qmlSurface->setActiveFocus(hasActiveFocus());
192+ updateSurfaceSize();
194+ connect(m_qmlSurface, &MirSurface::orientationAngleChanged, this, &MirSurfaceItem::orientationAngleChanged);
195+ connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
196+ connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
197+ connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
199+ // The assumptions I make here really should hold.
200+ QQuickView *quickView =
201+ qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
203+ QString qmlComponentFilePath;
204+ if (!m_qmlSurface->qmlFilePath().isEmpty()) {
205+ qmlComponentFilePath.append(m_qmlSurface->qmlFilePath());
207+ qmlComponentFilePath = QString("%1/Unity/Application/MirSurfaceItem.qml")
208+ .arg(mockPluginsDir());
211+ m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlComponentFilePath);
213+ switch (m_qmlContentComponent->status()) {
214+ case QQmlComponent::Ready:
215+ createQmlContentItem();
217+ case QQmlComponent::Loading:
218+ connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
219+ this, &MirSurfaceItem::onComponentStatusChanged);
221+ case QQmlComponent::Error:
222+ printComponentErrors();
223+ qFatal("MirSurfaceItem: failed to create content component.");
226+ qFatal("MirSurfaceItem: Unhandled component status");
230+ Q_EMIT surfaceChanged(m_qmlSurface);
233+void MirSurfaceItem::itemChange(ItemChange change, const ItemChangeData & value)
235+ if (change == QQuickItem::ItemActiveFocusHasChanged) {
237+ m_qmlSurface->setActiveFocus(value.boolValue);
242+void MirSurfaceItem::setConsumesInput(bool value)
244+ if (m_consumesInput != value) {
245+ m_consumesInput = value;
246+ Q_EMIT consumesInputChanged(value);
250+int MirSurfaceItem::surfaceWidth() const
252+ return m_surfaceWidth;
255+void MirSurfaceItem::setSurfaceWidth(int value)
257+ if (m_surfaceWidth != value) {
258+ m_surfaceWidth = value;
259+ Q_EMIT surfaceWidthChanged(m_surfaceWidth);
260+ updateSurfaceSize();
264+int MirSurfaceItem::surfaceHeight() const
266+ return m_surfaceHeight;
269+void MirSurfaceItem::setSurfaceHeight(int value)
271+ if (m_surfaceHeight != value) {
272+ m_surfaceHeight = value;
273+ Q_EMIT surfaceHeightChanged(m_surfaceHeight);
274+ updateSurfaceSize();
278+void MirSurfaceItem::updateSurfaceSize()
280+ if (m_qmlSurface && m_surfaceWidth > 0 && m_surfaceHeight > 0) {
281+ m_qmlSurface->resize(m_surfaceWidth, m_surfaceHeight);