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"
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_orientationAngle(Angle0)
44 , m_screenshotUrl(screenshot)
45 , m_touchPressCount(0)
46 , m_touchReleaseCount(0)
48 setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton |
49 Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::ExtraButton3 | Qt::ExtraButton4 |
50 Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 |
51 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
52 Qt::ExtraButton12 | Qt::ExtraButton13);
54 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
56 // The assumptions I make here really should hold.
57 QQuickView *quickView =
58 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
60 m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlFileUrl);
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));
173void MirSurfaceItem::touchEvent(QTouchEvent * event)
175 if (event->touchPointStates() & Qt::TouchPointPressed) {
177 Q_EMIT touchPressCountChanged(m_touchPressCount);
178 } else if (event->touchPointStates() & Qt::TouchPointReleased) {
179 ++m_touchReleaseCount;
180 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