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)
46 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
48 // The assumptions I make here really should hold.
49 QQuickView *quickView =
50 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
52 QString qmlComponentFilePath;
53 if (!qmlFilePath.isEmpty()) {
54 qmlComponentFilePath.append(qmlFilePath);
56 qmlComponentFilePath = QString("%1/Unity/Application/MirSurfaceItem.qml")
57 .arg(mockPluginsDir());
60 m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlComponentFilePath);
62 switch (m_qmlContentComponent->status()) {
63 case QQmlComponent::Ready:
64 createQmlContentItem();
66 case QQmlComponent::Loading:
67 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
68 this, &MirSurfaceItem::onComponentStatusChanged);
70 case QQmlComponent::Error:
71 printComponentErrors();
72 qFatal("MirSurfaceItem: failed to create content component.");
75 qFatal("MirSurfaceItem: Unhandled component status");
79MirSurfaceItem::~MirSurfaceItem()
81 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
83 m_session->setSurface(nullptr);
87void MirSurfaceItem::printComponentErrors()
89 QList<QQmlError> errors = m_qmlContentComponent->errors();
90 for (int i = 0; i < errors.count(); ++i) {
91 qDebug() << errors[i];
95void MirSurfaceItem::release()
97 qDebug() << "MirSurfaceItem::release " << name();
100 m_session->setSurface(nullptr);
107void MirSurfaceItem::setOrientationAngle(OrientationAngle angle)
109 if (m_orientationAngle == angle)
112 m_orientationAngle = angle;
114 QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
115 orientationProp.write(QVariant::fromValue(m_orientationAngle));
117 Q_EMIT orientationAngleChanged(m_orientationAngle);
120void MirSurfaceItem::setSession(Session* session)
125void MirSurfaceItem::setScreenshot(const QUrl& screenshot)
127 m_screenshotUrl = screenshot;
129 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
130 screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
134void MirSurfaceItem::setLive(bool live)
136 if (m_live != live) {
138 Q_EMIT liveChanged(m_live);
142void MirSurfaceItem::setState(MirSurfaceItem::State newState)
144 if (newState != m_state) {
146 Q_EMIT stateChanged(newState);
150void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
152 if (status == QQmlComponent::Ready) {
153 createQmlContentItem();
157void MirSurfaceItem::createQmlContentItem()
159 qDebug() << "MirSurfaceItem::createQmlContentItem()";
161 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
162 m_qmlItem->setParentItem(this);
164 setImplicitWidth(m_qmlItem->implicitWidth());
165 setImplicitHeight(m_qmlItem->implicitHeight());
168 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
169 screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
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