on xenial help sign in
Added parentSurface & childSurfaces
01aa324Nick Dedekind
tests/mocks/Unity/Application/MirSurfaceItem.cpp+51
@@ -28,13 +28,64 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
28 , m_type(type)
28 , m_type(type)
29 , m_state(state)
29 , m_state(state)
30 , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
30 , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
31+ , m_parentSurface(nullptr)
31{
32{
32 setFillColor(Qt::white);
33 setFillColor(Qt::white);
33}
34}
34
35
36+MirSurfaceItem::~MirSurfaceItem()
37+{
38+ QList<MirSurfaceItem*> children(m_children);
39+ for (MirSurfaceItem* child : children) {
40+ child->setParentSurface(nullptr);
41+ }
42+ if (m_parentSurface)
43+ m_parentSurface->removeChildSurface(this);
44+}
45+
35void MirSurfaceItem::paint(QPainter * painter)
46void MirSurfaceItem::paint(QPainter * painter)
36{
47{
37 if (!m_img.isNull()) {
48 if (!m_img.isNull()) {
38 painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
49 painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
39 }
50 }
40}
51}
52+
53+void MirSurfaceItem::setParentSurface(MirSurfaceItem* surface)
54+{
55+ if (m_parentSurface == surface || surface == this)
56+ return;
57+
58+ if (m_parentSurface) {
59+ m_parentSurface->removeChildSurface(this);
60+ }
61+
62+ m_parentSurface = surface;
63+
64+ if (m_parentSurface) {
65+ m_parentSurface->addChildSurface(this);
66+ }
67+ Q_EMIT parentSurfaceChanged(surface);
68+}
69+
70+void MirSurfaceItem::removeChildSurface(MirSurfaceItem* surface)
71+{
72+ if (m_children.contains(surface)) {
73+ m_children.removeOne(surface);
74+ Q_EMIT childSurfacesChanged();
75+ }
76+}
77+
78+void MirSurfaceItem::addChildSurface(MirSurfaceItem* surface)
79+{
80+ m_children.append(surface);
81+ Q_EMIT childSurfacesChanged();
82+}
83+
84+QList<QObject*> MirSurfaceItem::childSurfaces() const
85+{
86+ QList<QObject*> children;
87+ for(MirSurfaceItem* child : m_children) {
88+ children.append(child);
89+ }
90+ return children;
91+}
tests/mocks/Unity/Application/MirSurfaceItem.h+14
@@ -29,6 +29,8 @@ class MirSurfaceItem : public QQuickPaintedItem
29 Q_PROPERTY(Type type READ type NOTIFY typeChanged)
29 Q_PROPERTY(Type type READ type NOTIFY typeChanged)
30 Q_PROPERTY(State state READ state NOTIFY stateChanged)
30 Q_PROPERTY(State state READ state NOTIFY stateChanged)
31 Q_PROPERTY(QString name READ name NOTIFY nameChanged)
31 Q_PROPERTY(QString name READ name NOTIFY nameChanged)
32+ Q_PROPERTY(MirSurfaceItem* parentSurface READ parentSurface NOTIFY parentSurfaceChanged)
33+ Q_PROPERTY(QList<QObject*> childSurfaces READ childSurfaces NOTIFY childSurfacesChanged)
32
34
33public:
35public:
34 enum Type {
36 enum Type {
@@ -56,27 +58,39 @@ public:
56 State state,
58 State state,
57 const QUrl& screenshot,
59 const QUrl& screenshot,
58 QQuickItem *parent = 0);
60 QQuickItem *parent = 0);
61+ ~MirSurfaceItem();
59
62
60 //getters
63 //getters
61 Type type() const { return m_type; }
64 Type type() const { return m_type; }
62 State state() const { return m_state; }
65 State state() const { return m_state; }
63 QString name() const { return m_name; }
66 QString name() const { return m_name; }
67+ MirSurfaceItem* parentSurface() const { return m_parentSurface; }
68+ QList<QObject*> childSurfaces() const;
64
69
65 Q_INVOKABLE void release() {}
70 Q_INVOKABLE void release() {}
66
71
67 void paint(QPainter * painter) override;
72 void paint(QPainter * painter) override;
68
73
74+ void setParentSurface(MirSurfaceItem* item);
75+
69Q_SIGNALS:
76Q_SIGNALS:
70 void typeChanged(Type);
77 void typeChanged(Type);
71 void stateChanged(State);
78 void stateChanged(State);
72 void nameChanged(QString);
79 void nameChanged(QString);
80+ void parentSurfaceChanged(MirSurfaceItem*);
81+ void childSurfacesChanged();
73
82
74private:
83private:
84+ void addChildSurface(MirSurfaceItem* surface);
85+ void removeChildSurface(MirSurfaceItem* surface);
75
86
76 const QString m_name;
87 const QString m_name;
77 const Type m_type;
88 const Type m_type;
78 const State m_state;
89 const State m_state;
79 const QImage m_img;
90 const QImage m_img;
91+
92+ MirSurfaceItem* m_parentSurface;
93+ QList<MirSurfaceItem*> m_children;
80};
94};
81
95
82Q_DECLARE_METATYPE(MirSurfaceItem*)
96Q_DECLARE_METATYPE(MirSurfaceItem*)
tests/mocks/Unity/Application/SurfaceManager.cpp+16
@@ -1,3 +1,19 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
1#include "SurfaceManager.h"
17#include "SurfaceManager.h"
2
18
3SurfaceManager *SurfaceManager::the_surface_manager = nullptr;
19SurfaceManager *SurfaceManager::the_surface_manager = nullptr;
tests/mocks/Unity/Application/SurfaceManager.h+17
@@ -1,7 +1,24 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
1#ifndef SURFACEMANAGER_H
17#ifndef SURFACEMANAGER_H
2#define SURFACEMANAGER_H
18#define SURFACEMANAGER_H
3
19
4#include <QObject>
20#include <QObject>
21+#include <QDBusAbstractAdaptor>
5
22
6class MirSurfaceItem;
23class MirSurfaceItem;
7
24