2 * Copyright (C) 2014 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"
18#include "ApplicationInfo.h"
23MirSurfaceItem::MirSurfaceItem(const QString& name,
24 MirSurfaceItem::Type type,
25 MirSurfaceItem::State state,
26 const QUrl& screenshot,
28 : QQuickPaintedItem(parent)
29 , m_application(nullptr)
33 , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
34 , m_parentSurface(nullptr)
35 , m_haveInputMethod(false)
37 qDebug() << "MirSurfaceItem::MirSurfaceItem() " << this->name();
39 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
41 // The virtual keyboard (input method) has a big transparent area so that
42 // content behind it show through
43 setFillColor(Qt::transparent);
45 connect(this, &QQuickItem::focusChanged,
46 this, &MirSurfaceItem::onFocusChanged);
49MirSurfaceItem::~MirSurfaceItem()
51 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
53 QList<MirSurfaceItem*> children(m_children);
54 for (MirSurfaceItem* child : children) {
55 child->setParentSurface(nullptr);
58 m_parentSurface->removeChildSurface(this);
61 m_application->removeSurface(this);
64void MirSurfaceItem::paint(QPainter * painter)
66 if (!m_img.isNull()) {
67 painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
71void MirSurfaceItem::release()
73 QList<MirSurfaceItem*> children(m_children);
74 for (MirSurfaceItem* child : children) {
77 if (m_parentSurface) {
78 m_parentSurface->removeChildSurface(this);
82 m_application->removeSurface(this);
89void MirSurfaceItem::setApplication(ApplicationInfo* application)
91 m_application = application;
94void MirSurfaceItem::setParentSurface(MirSurfaceItem* surface)
96 if (m_parentSurface == surface || surface == this)
99 if (m_parentSurface) {
100 m_parentSurface->removeChildSurface(this);
103 m_parentSurface = surface;
105 if (m_parentSurface) {
106 m_parentSurface->addChildSurface(this);
108 Q_EMIT parentSurfaceChanged(surface);
111void MirSurfaceItem::addChildSurface(MirSurfaceItem* surface)
113 qDebug() << "MirSurfaceItem::addChildSurface " << surface->name() << " to " << name();
115 m_children.append(surface);
116 Q_EMIT childSurfacesChanged();
119void MirSurfaceItem::removeChildSurface(MirSurfaceItem* surface)
121 qDebug() << "MirSurfaceItem::removeChildSurface " << surface->name() << " from " << name();
123 if (m_children.contains(surface)) {
124 m_children.removeOne(surface);
125 Q_EMIT childSurfacesChanged();
129QList<MirSurfaceItem*> MirSurfaceItem::childSurfaceList()
134QQmlListProperty<MirSurfaceItem> MirSurfaceItem::childSurfaces()
136 return QQmlListProperty<MirSurfaceItem>(this,
138 MirSurfaceItem::childSurfaceCount,
139 MirSurfaceItem::childSurfaceAt);
142int MirSurfaceItem::childSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop)
144 MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
145 return p->m_children.count();
148MirSurfaceItem* MirSurfaceItem::childSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index)
150 MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
152 if (index < 0 || index >= p->m_children.count())
154 return p->m_children[index];
158void MirSurfaceItem::touchEvent(QTouchEvent * event)
160 if (event->type() == QEvent::TouchBegin && hasFocus()) {
161 Q_EMIT inputMethodRequested();
162 m_haveInputMethod = true;
166void MirSurfaceItem::onFocusChanged()
168 if (!hasFocus() && m_haveInputMethod) {
169 Q_EMIT inputMethodDismissed();
170 m_haveInputMethod = false;
174void MirSurfaceItem::setState(MirSurfaceItem::State newState)
176 if (newState != m_state) {
178 Q_EMIT stateChanged(newState);
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