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 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
39 // The virtual keyboard (input method) has a big transparent area so that
40 // content behind it show through
41 setFillColor(Qt::transparent);
43 connect(this, &QQuickItem::focusChanged,
44 this, &MirSurfaceItem::onFocusChanged);
47MirSurfaceItem::~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);
60void MirSurfaceItem::paint(QPainter * painter)
62 if (!m_img.isNull()) {
63 painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
67void 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);
85void MirSurfaceItem::setApplication(ApplicationInfo* application)
87 m_application = application;
90void 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);
107void MirSurfaceItem::removeChildSurface(MirSurfaceItem* surface)
109 if (m_children.contains(surface)) {
110 m_children.removeOne(surface);
111 Q_EMIT childSurfacesChanged();
115void MirSurfaceItem::addChildSurface(MirSurfaceItem* surface)
117 m_children.append(surface);
118 Q_EMIT childSurfacesChanged();
121QList<MirSurfaceItem*> MirSurfaceItem::childSurfaceList()
126QQmlListProperty<MirSurfaceItem> MirSurfaceItem::childSurfaces()
128 return QQmlListProperty<MirSurfaceItem>(this,
130 MirSurfaceItem::childSurfaceCount,
131 MirSurfaceItem::childSurfaceAt);
134int MirSurfaceItem::childSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop)
136 MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
137 return p->m_children.count();
140MirSurfaceItem* MirSurfaceItem::childSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index)
142 MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
144 if (index < 0 || index >= p->m_children.count())
146 return p->m_children[index];
150void MirSurfaceItem::touchEvent(QTouchEvent * event)
152 if (event->type() == QEvent::TouchBegin && hasFocus()) {
153 Q_EMIT inputMethodRequested();
154 m_haveInputMethod = true;
158void MirSurfaceItem::onFocusChanged()
160 if (!hasFocus() && m_haveInputMethod) {
161 Q_EMIT inputMethodDismissed();
162 m_haveInputMethod = false;
166void MirSurfaceItem::setState(MirSurfaceItem::State newState)
168 if (newState != m_state) {
170 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