on xenial help sign in
Added parentSurface & childSurfaces
commit01aa324915a773cae7222317074e234b92564ed6 authorNick Dedekind <nicholas.dedekind@gmail.com> dateSat 19 Jul 2014, 12:43 (12 years ago) parent18bed51
4 files changed+98
tests/mocks/Unity/Application/MirSurfaceItem.cpp+51 tests/mocks/Unity/Application/MirSurfaceItem.h+14 tests/mocks/Unity/Application/SurfaceManager.cpp+16 tests/mocks/Unity/Application/SurfaceManager.h+17
tests/mocks/Unity/Application/MirSurfaceItem.cpp+51
@@ -28,13 +28,64 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
2828 , m_type(type)
2929 , m_state(state)
3030 , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
31+ , m_parentSurface(nullptr)
3132{
3233 setFillColor(Qt::white);
3334}
3435
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+
3546void MirSurfaceItem::paint(QPainter * painter)
3647{
3748 if (!m_img.isNull()) {
3849 painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
3950 }
4051}
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
2929 Q_PROPERTY(Type type READ type NOTIFY typeChanged)
3030 Q_PROPERTY(State state READ state NOTIFY stateChanged)
3131 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)
3234
3335public:
3436 enum Type {
@@ -56,27 +58,39 @@ public:
5658 State state,
5759 const QUrl& screenshot,
5860 QQuickItem *parent = 0);
61+ ~MirSurfaceItem();
5962
6063 //getters
6164 Type type() const { return m_type; }
6265 State state() const { return m_state; }
6366 QString name() const { return m_name; }
67+ MirSurfaceItem* parentSurface() const { return m_parentSurface; }
68+ QList<QObject*> childSurfaces() const;
6469
6570 Q_INVOKABLE void release() {}
6671
6772 void paint(QPainter * painter) override;
6873
74+ void setParentSurface(MirSurfaceItem* item);
75+
6976Q_SIGNALS:
7077 void typeChanged(Type);
7178 void stateChanged(State);
7279 void nameChanged(QString);
80+ void parentSurfaceChanged(MirSurfaceItem*);
81+ void childSurfacesChanged();
7382
7483private:
84+ void addChildSurface(MirSurfaceItem* surface);
85+ void removeChildSurface(MirSurfaceItem* surface);
7586
7687 const QString m_name;
7788 const Type m_type;
7889 const State m_state;
7990 const QImage m_img;
91+
92+ MirSurfaceItem* m_parentSurface;
93+ QList<MirSurfaceItem*> m_children;
8094};
8195
8296Q_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+
117#include "SurfaceManager.h"
218
319SurfaceManager *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+
117#ifndef SURFACEMANAGER_H
218#define SURFACEMANAGER_H
319
420#include <QObject>
21+#include <QDBusAbstractAdaptor>
522
623class MirSurfaceItem;
724