@@ -15,8 +15,10 @@
17#include "MirSurfaceItem.h"
17#include "MirSurfaceItem.h"
18+#include "ApplicationInfo.h"
19#include <QPainter>
20#include <QPainter>
21MirSurfaceItem::MirSurfaceItem(const QString& name,
23MirSurfaceItem::MirSurfaceItem(const QString& name,
22 MirSurfaceItem::Type type,
24 MirSurfaceItem::Type type,
@@ -24,12 +26,16 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
24 const QUrl& screenshot,
26 const QUrl& screenshot,
25 QQuickItem *parent)
27 QQuickItem *parent)
26 : QQuickPaintedItem(parent)
28 : QQuickPaintedItem(parent)
29+ , m_application(nullptr)
27 , m_name(name)
30 , m_name(name)
28 , m_type(type)
31 , m_type(type)
29 , m_state(state)
32 , m_state(state)
30 , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
33 , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
34+ , m_parentSurface(nullptr)
31 , m_haveInputMethod(false)
35 , m_haveInputMethod(false)
37+ QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
33 // The virtual keyboard (input method) has a big transparent area so that
39 // The virtual keyboard (input method) has a big transparent area so that
34 // content behind it show through
40 // content behind it show through
35 setFillColor(Qt::transparent);
41 setFillColor(Qt::transparent);
@@ -38,6 +44,19 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
38 this, &MirSurfaceItem::onFocusChanged);
44 this, &MirSurfaceItem::onFocusChanged);
47+MirSurfaceItem::~MirSurfaceItem()
49+ QList<MirSurfaceItem*> children(m_children);
50+ for (MirSurfaceItem* child : children) {
51+ child->setParentSurface(nullptr);
54+ m_parentSurface->removeChildSurface(this);
57+ m_application->setSurface(nullptr);
41void MirSurfaceItem::paint(QPainter * painter)
60void MirSurfaceItem::paint(QPainter * painter)
43 if (!m_img.isNull()) {
62 if (!m_img.isNull()) {
@@ -45,6 +64,91 @@ void MirSurfaceItem::paint(QPainter * painter)
67+void MirSurfaceItem::release()
69+ QList<MirSurfaceItem*> children(m_children);
70+ for (MirSurfaceItem* child : children) {
73+ if (m_parentSurface) {
74+ m_parentSurface->removeChildSurface(this);
78+ m_application->setSurface(nullptr);
85+void MirSurfaceItem::setApplication(ApplicationInfo* application)
87+ m_application = application;
90+void MirSurfaceItem::setParentSurface(MirSurfaceItem* surface)
92+ if (m_parentSurface == surface || surface == this)
95+ if (m_parentSurface) {
96+ m_parentSurface->removeChildSurface(this);
99+ m_parentSurface = surface;
101+ if (m_parentSurface) {
102+ m_parentSurface->addChildSurface(this);
104+ Q_EMIT parentSurfaceChanged(surface);
107+void MirSurfaceItem::removeChildSurface(MirSurfaceItem* surface)
109+ if (m_children.contains(surface)) {
110+ m_children.removeOne(surface);
111+ Q_EMIT childSurfacesChanged();
115+void MirSurfaceItem::addChildSurface(MirSurfaceItem* surface)
117+ m_children.append(surface);
118+ Q_EMIT childSurfacesChanged();
121+void MirSurfaceItem::foreachChildSurface(std::function<void(MirSurfaceItem*)> f) const
123+ for(MirSurfaceItem* child : m_children) {
128+QQmlListProperty<MirSurfaceItem> MirSurfaceItem::childSurfaces()
130+ return QQmlListProperty<MirSurfaceItem>(this,
132+ MirSurfaceItem::childSurfaceCount,
133+ MirSurfaceItem::childSurfaceAt);
136+int MirSurfaceItem::childSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop)
138+ MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
139+ return p->m_children.count();
142+MirSurfaceItem* MirSurfaceItem::childSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index)
144+ MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
146+ if (index < 0 || index >= p->m_children.count())
148+ return p->m_children[index];
48void MirSurfaceItem::touchEvent(QTouchEvent * event)
152void MirSurfaceItem::touchEvent(QTouchEvent * event)
50 if (event->type() == QEvent::TouchBegin && hasFocus()) {
154 if (event->type() == QEvent::TouchBegin && hasFocus()) {