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"
22#include <QGuiApplication>
24#include <QQmlProperty>
30MirSurfaceItem::MirSurfaceItem(const QString& name,
31 MirSurfaceItem::Type type,
32 MirSurfaceItem::State state,
33 const QUrl& screenshot,
34 const QUrl& qmlFileUrl,
42 , m_orientation(Qt::PortraitOrientation)
43 , m_touchPressCount(0)
44 , m_touchReleaseCount(0)
46 , m_screenshotUrl(screenshot)
48 qDebug() << "MirSurfaceItem::MirSurfaceItem() " << this->name();
50 setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton |
51 Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::ExtraButton3 | Qt::ExtraButton4 |
52 Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 |
53 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
54 Qt::ExtraButton12 | Qt::ExtraButton13);
56 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
58 connect(this, &QQuickItem::focusChanged,
59 this, &MirSurfaceItem::onFocusChanged);
61 // The assumptions I make here really should hold.
62 QQuickView *quickView =
63 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
65 m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlFileUrl);
67 switch (m_qmlContentComponent->status()) {
68 case QQmlComponent::Ready:
69 createQmlContentItem();
71 case QQmlComponent::Loading:
72 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
73 this, &MirSurfaceItem::onComponentStatusChanged);
75 case QQmlComponent::Error:
76 printComponentErrors();
77 qFatal("MirSurfaceItem: failed to create content component.");
80 qFatal("MirSurfaceItem: Unhandled component status");
84MirSurfaceItem::~MirSurfaceItem()
86 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
88 m_session->setSurface(nullptr);
92void MirSurfaceItem::printComponentErrors()
94 QList<QQmlError> errors = m_qmlContentComponent->errors();
95 for (int i = 0; i < errors.count(); ++i) {
96 qDebug() << errors[i];
100void MirSurfaceItem::release()
102 qDebug() << "MirSurfaceItem::release " << name();
105 m_session->setSurface(nullptr);
112void MirSurfaceItem::setOrientation(const Qt::ScreenOrientation orientation)
114 if (m_orientation == orientation)
117 m_orientation = orientation;
119 QQmlProperty orientationProp(m_qmlItem, "orientation");
120 orientationProp.write(QVariant::fromValue(orientation));
122 Q_EMIT orientationChanged();
125void MirSurfaceItem::setSession(Session* session)
130void MirSurfaceItem::setScreenshot(const QUrl& screenshot)
132 m_screenshotUrl = screenshot;
134 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
135 screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
139void MirSurfaceItem::setLive(bool live)
141 if (m_live != live) {
143 Q_EMIT liveChanged(m_live);
147void MirSurfaceItem::onFocusChanged()
150 // Causes a crash in tst_Shell.qml, inside the mock Unity.Application itself.
151 // Didn't have time to debug yet.
152 //Q_EMIT inputMethodDismissed();
156void MirSurfaceItem::setState(MirSurfaceItem::State newState)
158 if (newState != m_state) {
160 Q_EMIT stateChanged(newState);
164void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
166 if (status == QQmlComponent::Ready) {
167 createQmlContentItem();
171void MirSurfaceItem::createQmlContentItem()
173 qDebug() << "MirSurfaceItem::createQmlContentItem()";
175 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
176 m_qmlItem->setParentItem(this);
178 setImplicitWidth(m_qmlItem->implicitWidth());
179 setImplicitHeight(m_qmlItem->implicitHeight());
182 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
183 screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
187void MirSurfaceItem::touchEvent(QTouchEvent * event)
189 if (event->touchPointStates() & Qt::TouchPointPressed) {
191 Q_EMIT touchPressCountChanged(m_touchPressCount);
192 // Causes a crash in tst_Shell.qml, inside the mock Unity.Application itself.
193 // Didn't have time to debug yet.
194 // Q_EMIT inputMethodRequested();
195 } else if (event->touchPointStates() & Qt::TouchPointReleased) {
196 ++m_touchReleaseCount;
197 Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
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