2 * Copyright (C) 2014-2015 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"
21#include <QGuiApplication>
24#include <QQmlProperty>
30using namespace unity::shell::application;
32MirSurfaceItem::MirSurfaceItem(QQuickItem *parent)
33 : MirSurfaceItemInterface(parent)
34 , m_qmlSurface(nullptr)
36 , m_consumesInput(false)
39 , m_touchPressCount(0)
40 , m_touchReleaseCount(0)
41 , m_mousePressCount(0)
42 , m_mouseReleaseCount(0)
44// qDebug() << "MirSurfaceItem::MirSurfaceItem() " << (void*)(this) << name();
45 setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton |
46 Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::ExtraButton3 | Qt::ExtraButton4 |
47 Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 |
48 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
49 Qt::ExtraButton12 | Qt::ExtraButton13);
51 connect(this, &QQuickItem::visibleChanged, this, &MirSurfaceItem::updateMirSurfaceVisibility);
54MirSurfaceItem::~MirSurfaceItem()
56// qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << (void*)(this) << name();
60void MirSurfaceItem::printComponentErrors()
62 QList<QQmlError> errors = m_qmlContentComponent->errors();
63 for (int i = 0; i < errors.count(); ++i) {
64 qDebug() << errors[i];
68Mir::Type MirSurfaceItem::type() const
71 return m_qmlSurface->type();
73 return Mir::UnknownType;
77Mir::State MirSurfaceItem::surfaceState() const
80 return m_qmlSurface->state();
82 return Mir::UnknownState;
86QString MirSurfaceItem::name() const
89 return m_qmlSurface->name();
95bool MirSurfaceItem::live() const
98 return m_qmlSurface->live();
104Mir::ShellChrome MirSurfaceItem::shellChrome() const
107 return m_qmlSurface->shellChrome();
109 return Mir::NormalChrome;
113Mir::OrientationAngle MirSurfaceItem::orientationAngle() const
116 return m_qmlSurface->orientationAngle();
122void MirSurfaceItem::setOrientationAngle(Mir::OrientationAngle angle)
127 if (m_qmlSurface->orientationAngle() == angle)
130 m_qmlSurface->setOrientationAngle(angle);
132 QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
133 orientationProp.write(QVariant::fromValue(m_qmlSurface->orientationAngle()));
136void MirSurfaceItem::updateScreenshot(QUrl screenshotUrl)
139 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
140 screenshotSource.write(QVariant::fromValue(screenshotUrl));
144void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
146 if (status == QQmlComponent::Ready) {
147 createQmlContentItem();
151void MirSurfaceItem::createQmlContentItem()
153// qDebug() << "MirSurfaceItem::createQmlContentItem()";
155 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
156 m_qmlItem->setParentItem(this);
158 setImplicitWidth(m_qmlItem->implicitWidth());
159 setImplicitHeight(m_qmlItem->implicitHeight());
162 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
163 screenshotSource.write(QVariant::fromValue(m_qmlSurface->screenshotUrl()));
167void MirSurfaceItem::touchEvent(QTouchEvent * event)
169 if (event->type() == QEvent::TouchBegin) {
170 m_touchTrail.clear();
173 if (event->touchPointStates() & Qt::TouchPointPressed) {
175 Q_EMIT touchPressCountChanged(m_touchPressCount);
176 } else if (event->touchPointStates() & Qt::TouchPointReleased) {
177 ++m_touchReleaseCount;
178 Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
181 Q_FOREACH(QTouchEvent::TouchPoint touchPoint, event->touchPoints()) {
182 QString id(touchPoint.id());
183 QVariantList list = m_touchTrail[id].toList();
184 list.append(QVariant::fromValue(touchPoint.pos()));
185 if (list.count() > 100) list.pop_front();
186 m_touchTrail[id] = list;
190 QQmlProperty touchTrail(m_qmlItem, "touchTrail");
191 touchTrail.write(m_touchTrail);
195void MirSurfaceItem::mousePressEvent(QMouseEvent * event)
198 Q_EMIT mousePressCountChanged(m_mousePressCount);
202void MirSurfaceItem::mouseMoveEvent(QMouseEvent * event)
207void MirSurfaceItem::mouseReleaseEvent(QMouseEvent * event)
209 m_mouseReleaseCount++;
210 Q_EMIT mouseReleaseCountChanged(m_mouseReleaseCount);
214void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
216// qDebug().nospace() << "MirSurfaceItem::setSurface() this=" << (void*)(this)
217// << " name=" << name()
218// << " surface=" << surface;
220 if (m_qmlSurface == surface) {
228 delete m_qmlContentComponent;
229 m_qmlContentComponent = nullptr;
231 disconnect(m_qmlSurface, nullptr, this, nullptr);
232 m_qmlSurface->unregisterView((qintptr)this);
235 m_qmlSurface = static_cast<MirSurface*>(surface);
238 m_qmlSurface->registerView((qintptr)this);
240 m_qmlSurface->setActiveFocus(hasActiveFocus());
243 updateMirSurfaceVisibility();
245 connect(m_qmlSurface, &MirSurface::orientationAngleChanged, this, &MirSurfaceItem::orientationAngleChanged);
246 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
247 connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
248 connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
250 QUrl qmlComponentFilePath;
251 if (!m_qmlSurface->qmlFilePath().isEmpty()) {
252 qmlComponentFilePath = m_qmlSurface->qmlFilePath();
254 qmlComponentFilePath = QUrl("qrc:///Unity/Application/MirSurfaceItem.qml");
257 m_qmlContentComponent = new QQmlComponent(QQmlEngine::contextForObject(parent())->engine(), qmlComponentFilePath);
259 switch (m_qmlContentComponent->status()) {
260 case QQmlComponent::Ready:
261 createQmlContentItem();
263 case QQmlComponent::Loading:
264 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
265 this, &MirSurfaceItem::onComponentStatusChanged);
267 case QQmlComponent::Error:
268 printComponentErrors();
269 qFatal("MirSurfaceItem: failed to create content component.");
272 qFatal("MirSurfaceItem: Unhandled component status");
276 Q_EMIT surfaceChanged(m_qmlSurface);
279void MirSurfaceItem::itemChange(ItemChange change, const ItemChangeData & value)
281 if (change == QQuickItem::ItemActiveFocusHasChanged) {
283 m_qmlSurface->setActiveFocus(value.boolValue);
288void MirSurfaceItem::updateMirSurfaceVisibility()
290 if (!m_qmlSurface) return;
292 m_qmlSurface->setViewVisibility((qintptr)this, isVisible());
295void MirSurfaceItem::setConsumesInput(bool value)
297 if (m_consumesInput != value) {
298 m_consumesInput = value;
299 Q_EMIT consumesInputChanged(value);
303int MirSurfaceItem::surfaceWidth() const
305 return m_surfaceWidth;
308void MirSurfaceItem::setSurfaceWidth(int value)
310 if (value != -1 && m_surfaceWidth != value) {
311 m_surfaceWidth = value;
312 Q_EMIT surfaceWidthChanged(m_surfaceWidth);
317int MirSurfaceItem::surfaceHeight() const
319 return m_surfaceHeight;
322void MirSurfaceItem::setSurfaceHeight(int value)
324 if (value != -1 && m_surfaceHeight != value) {
325 m_surfaceHeight = value;
326 Q_EMIT surfaceHeightChanged(m_surfaceHeight);
331void MirSurfaceItem::updateSurfaceSize()
333 if (m_qmlSurface && m_surfaceWidth > 0 && m_surfaceHeight > 0) {
334 m_qmlSurface->resize(m_surfaceWidth, m_surfaceHeight);
338void MirSurfaceItem::setFillMode(FillMode value)
340 if (value != m_fillMode) {
342 Q_EMIT fillModeChanged(m_fillMode);
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