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 QString &qmlFilePath,
42 , m_orientation(Qt::PortraitOrientation)
43 , m_touchPressCount(0)
44 , m_touchReleaseCount(0)
46 , m_screenshotUrl(screenshot)
48 qDebug() << "MirSurfaceItem::MirSurfaceItem() " << this->name();
50 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
52 connect(this, &QQuickItem::focusChanged,
53 this, &MirSurfaceItem::onFocusChanged);
55 // The assumptions I make here really should hold.
56 QQuickView *quickView =
57 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
59 QString qmlComponentFilePath;
60 if (!qmlFilePath.isEmpty()) {
61 qmlComponentFilePath.append(qmlFilePath);
63 qmlComponentFilePath = QString("%1/Unity/Application/MirSurfaceItem.qml")
64 .arg(mockPluginsDir());
67 m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlComponentFilePath);
69 switch (m_qmlContentComponent->status()) {
70 case QQmlComponent::Ready:
71 createQmlContentItem();
73 case QQmlComponent::Loading:
74 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
75 this, &MirSurfaceItem::onComponentStatusChanged);
77 case QQmlComponent::Error:
78 printComponentErrors();
79 qFatal("MirSurfaceItem: failed to create content component.");
82 qFatal("MirSurfaceItem: Unhandled component status");
86MirSurfaceItem::~MirSurfaceItem()
88 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
90 m_session->setSurface(nullptr);
94void MirSurfaceItem::printComponentErrors()
96 QList<QQmlError> errors = m_qmlContentComponent->errors();
97 for (int i = 0; i < errors.count(); ++i) {
98 qDebug() << errors[i];
102void MirSurfaceItem::release()
104 qDebug() << "MirSurfaceItem::release " << name();
107 m_session->setSurface(nullptr);
114void MirSurfaceItem::setOrientation(const Qt::ScreenOrientation orientation)
116 if (m_orientation == orientation)
119 m_orientation = orientation;
121 QQmlProperty orientationProp(m_qmlItem, "orientation");
122 orientationProp.write(QVariant::fromValue(orientation));
124 Q_EMIT orientationChanged();
127void MirSurfaceItem::setSession(Session* session)
132void MirSurfaceItem::setScreenshot(const QUrl& screenshot)
134 m_screenshotUrl = screenshot;
136 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
137 screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
141void MirSurfaceItem::setLive(bool live)
143 if (m_live != live) {
145 Q_EMIT liveChanged(m_live);
149void MirSurfaceItem::onFocusChanged()
152 // Causes a crash in tst_Shell.qml, inside the mock Unity.Application itself.
153 // Didn't have time to debug yet.
154 //Q_EMIT inputMethodDismissed();
158void MirSurfaceItem::setState(MirSurfaceItem::State newState)
160 if (newState != m_state) {
162 Q_EMIT stateChanged(newState);
166void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
168 if (status == QQmlComponent::Ready) {
169 createQmlContentItem();
173void MirSurfaceItem::createQmlContentItem()
175 qDebug() << "MirSurfaceItem::createQmlContentItem()";
177 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
178 m_qmlItem->setParentItem(this);
180 setImplicitWidth(m_qmlItem->implicitWidth());
181 setImplicitHeight(m_qmlItem->implicitHeight());
184 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
185 screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
189void MirSurfaceItem::touchEvent(QTouchEvent * event)
191 if (event->touchPointStates() & Qt::TouchPointPressed) {
193 Q_EMIT touchPressCountChanged(m_touchPressCount);
194 // Causes a crash in tst_Shell.qml, inside the mock Unity.Application itself.
195 // Didn't have time to debug yet.
196 // Q_EMIT inputMethodRequested();
197 } else if (event->touchPointStates() & Qt::TouchPointReleased) {
198 ++m_touchReleaseCount;
199 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