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 "MirSurfaceItemModel.h"
19#include "ApplicationInfo.h"
24MirSurfaceItem::MirSurfaceItem(const QString& name,
25 MirSurfaceItem::Type type,
26 MirSurfaceItem::State state,
27 const QUrl& screenshot,
29 : QQuickPaintedItem(parent)
30 , m_application(nullptr)
34 , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
35 , m_parentSurface(nullptr)
36 , m_children(new MirSurfaceItemModel(this))
37 , m_haveInputMethod(false)
39 qDebug() << "MirSurfaceItem::MirSurfaceItem() " << this->name();
41 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
43 // The virtual keyboard (input method) has a big transparent area so that
44 // content behind it show through
45 setFillColor(Qt::transparent);
47 connect(this, &QQuickItem::focusChanged,
48 this, &MirSurfaceItem::onFocusChanged);
51MirSurfaceItem::~MirSurfaceItem()
53 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
54 Q_EMIT aboutToBeDestroyed();
56 QList<MirSurfaceItem*> children(m_children->list());
57 for (MirSurfaceItem* child : children) {
60 if (m_parentSurface) {
61 m_parentSurface->removeChildSurface(this);
64 m_application->removeSurface(this);
69void MirSurfaceItem::paint(QPainter * painter)
71 if (!m_img.isNull()) {
72 painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
76void MirSurfaceItem::release()
78 qDebug() << "MirSurfaceItem::release " << name();
80 if (m_parentSurface) {
81 m_parentSurface->removeChildSurface(this);
85 m_application->removeSurface(this);
92void MirSurfaceItem::setApplication(ApplicationInfo* application)
94 m_application = application;
97void MirSurfaceItem::setParentSurface(MirSurfaceItem* surface)
99 if (m_parentSurface == surface || surface == this)
102 m_parentSurface = surface;
103 Q_EMIT parentSurfaceChanged(surface);
106void MirSurfaceItem::addChildSurface(MirSurfaceItem* surface)
108 insertChildSurface(m_children->count(), surface);
111void MirSurfaceItem::insertChildSurface(uint index, MirSurfaceItem* surface)
113 qDebug() << "MirSurfaceItem::insertChildSurface - " << surface->name() << " to " << name() << " @ " << index;
115 surface->setParentSurface(this);
116 m_children->insertSurface(index, surface);
119void MirSurfaceItem::removeChildSurface(MirSurfaceItem* surface)
121 qDebug() << "MirSurfaceItem::removeChildSurface - " << surface->name() << " from " << name();
123 if (m_children->contains(surface)) {
124 m_children->removeSurface(surface);
125 surface->setParentSurface(nullptr);
129MirSurfaceItemModel* MirSurfaceItem::childSurfaces() const
135void MirSurfaceItem::touchEvent(QTouchEvent * event)
137 if (event->type() == QEvent::TouchBegin && hasFocus()) {
138 Q_EMIT inputMethodRequested();
139 m_haveInputMethod = true;
143void MirSurfaceItem::onFocusChanged()
145 if (!hasFocus() && m_haveInputMethod) {
146 Q_EMIT inputMethodDismissed();
147 m_haveInputMethod = false;
151void MirSurfaceItem::setState(MirSurfaceItem::State newState)
153 if (newState != m_state) {
155 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