2 * Copyright (C) 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"
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_orientationAngle(Angle0)
44 , m_screenshotUrl(screenshot)
45 , m_touchPressCount(0)
46 , m_touchReleaseCount(0)
48 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
50 // The assumptions I make here really should hold.
51 QQuickView *quickView =
52 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
54 QString qmlComponentFilePath;
55 if (!qmlFilePath.isEmpty()) {
56 qmlComponentFilePath.append(qmlFilePath);
58 qmlComponentFilePath = QString("%1/Unity/Application/MirSurfaceItem.qml")
59 .arg(mockPluginsDir());
62 m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlComponentFilePath);
64 switch (m_qmlContentComponent->status()) {
65 case QQmlComponent::Ready:
66 createQmlContentItem();
68 case QQmlComponent::Loading:
69 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
70 this, &MirSurfaceItem::onComponentStatusChanged);
72 case QQmlComponent::Error:
73 printComponentErrors();
74 qFatal("MirSurfaceItem: failed to create content component.");
77 qFatal("MirSurfaceItem: Unhandled component status");
81MirSurfaceItem::~MirSurfaceItem()
83 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
85 m_session->setSurface(nullptr);
89void MirSurfaceItem::printComponentErrors()
91 QList<QQmlError> errors = m_qmlContentComponent->errors();
92 for (int i = 0; i < errors.count(); ++i) {
93 qDebug() << errors[i];
97void MirSurfaceItem::release()
99 qDebug() << "MirSurfaceItem::release " << name();
102 m_session->setSurface(nullptr);
109void MirSurfaceItem::setOrientationAngle(OrientationAngle angle)
111 if (m_orientationAngle == angle)
114 m_orientationAngle = angle;
116 QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
117 orientationProp.write(QVariant::fromValue(m_orientationAngle));
119 Q_EMIT orientationAngleChanged(m_orientationAngle);
122void MirSurfaceItem::setSession(Session* session)
127void MirSurfaceItem::setScreenshot(const QUrl& screenshot)
129 m_screenshotUrl = screenshot;
131 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
132 screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
136void MirSurfaceItem::setLive(bool live)
138 if (m_live != live) {
140 Q_EMIT liveChanged(m_live);
144void MirSurfaceItem::setState(MirSurfaceItem::State newState)
146 if (newState != m_state) {
148 Q_EMIT stateChanged(newState);
152void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
154 if (status == QQmlComponent::Ready) {
155 createQmlContentItem();
159void MirSurfaceItem::createQmlContentItem()
161 qDebug() << "MirSurfaceItem::createQmlContentItem()";
163 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
164 m_qmlItem->setParentItem(this);
166 setImplicitWidth(m_qmlItem->implicitWidth());
167 setImplicitHeight(m_qmlItem->implicitHeight());
170 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
171 screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
175void MirSurfaceItem::touchEvent(QTouchEvent * event)
177 if (event->touchPointStates() & Qt::TouchPointPressed) {
179 Q_EMIT touchPressCountChanged(m_touchPressCount);
180 } else if (event->touchPointStates() & Qt::TouchPointReleased) {
181 ++m_touchReleaseCount;
182 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