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"
21#include <QGuiApplication>
24#include <QQmlProperty>
30using namespace unity::shell::application;
32MirSurfaceItem::MirSurfaceItem(QQuickItem *parent)
33 : MirSurfaceItemInterface(parent)
34 , m_qmlSurface(nullptr)
36 , m_consumesInput(false)
39 , m_touchPressCount(0)
40 , m_touchReleaseCount(0)
41 , m_mousePressCount(0)
42 , m_mouseReleaseCount(0)
44// qDebug() << "MirSurfaceItem::MirSurfaceItem() " << (void*)(this) << name();
45 setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton |
46 Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::ExtraButton3 | Qt::ExtraButton4 |
47 Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 |
48 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
49 Qt::ExtraButton12 | Qt::ExtraButton13);
51 connect(this, &QQuickItem::visibleChanged, this, &MirSurfaceItem::updateMirSurfaceVisibility);
54MirSurfaceItem::~MirSurfaceItem()
56// qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << (void*)(this) << name();
60void MirSurfaceItem::printComponentErrors()
62 QList<QQmlError> errors = m_qmlContentComponent->errors();
63 for (int i = 0; i < errors.count(); ++i) {
64 qDebug() << errors[i];
68Mir::Type MirSurfaceItem::type() const
71 return m_qmlSurface->type();
73 return Mir::UnknownType;
77Mir::State MirSurfaceItem::surfaceState() const
80 return m_qmlSurface->state();
82 return Mir::UnknownState;
86QString MirSurfaceItem::name() const
89 return m_qmlSurface->name();
95bool MirSurfaceItem::live() const
98 return m_qmlSurface->live();
104Mir::OrientationAngle MirSurfaceItem::orientationAngle() const
107 return m_qmlSurface->orientationAngle();
113void MirSurfaceItem::setOrientationAngle(Mir::OrientationAngle angle)
118 if (m_qmlSurface->orientationAngle() == angle)
121 m_qmlSurface->setOrientationAngle(angle);
123 QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
124 orientationProp.write(QVariant::fromValue(m_qmlSurface->orientationAngle()));
127void MirSurfaceItem::updateScreenshot(QUrl screenshotUrl)
130 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
131 screenshotSource.write(QVariant::fromValue(screenshotUrl));
135void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
137 if (status == QQmlComponent::Ready) {
138 createQmlContentItem();
142void MirSurfaceItem::createQmlContentItem()
144// qDebug() << "MirSurfaceItem::createQmlContentItem()";
146 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
147 m_qmlItem->setParentItem(this);
149 setImplicitWidth(m_qmlItem->implicitWidth());
150 setImplicitHeight(m_qmlItem->implicitHeight());
153 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
154 screenshotSource.write(QVariant::fromValue(m_qmlSurface->screenshotUrl()));
158void MirSurfaceItem::touchEvent(QTouchEvent * event)
160 if (event->touchPointStates() & Qt::TouchPointPressed) {
162 Q_EMIT touchPressCountChanged(m_touchPressCount);
163 } else if (event->touchPointStates() & Qt::TouchPointReleased) {
164 ++m_touchReleaseCount;
165 Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
169void MirSurfaceItem::mousePressEvent(QMouseEvent * event)
172 Q_EMIT mousePressCountChanged(m_mousePressCount);
176void MirSurfaceItem::mouseMoveEvent(QMouseEvent * event)
181void MirSurfaceItem::mouseReleaseEvent(QMouseEvent * event)
183 m_mouseReleaseCount++;
184 Q_EMIT mouseReleaseCountChanged(m_mouseReleaseCount);
188void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
190// qDebug().nospace() << "MirSurfaceItem::setSurface() this=" << (void*)(this)
191// << " name=" << name()
192// << " surface=" << surface;
194 if (m_qmlSurface == surface) {
202 delete m_qmlContentComponent;
203 m_qmlContentComponent = nullptr;
205 disconnect(m_qmlSurface, nullptr, this, nullptr);
206 m_qmlSurface->unregisterView((qintptr)this);
209 m_qmlSurface = static_cast<MirSurface*>(surface);
212 m_qmlSurface->registerView((qintptr)this);
214 m_qmlSurface->setActiveFocus(hasActiveFocus());
217 updateMirSurfaceVisibility();
219 connect(m_qmlSurface, &MirSurface::orientationAngleChanged, this, &MirSurfaceItem::orientationAngleChanged);
220 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
221 connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
222 connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
224 QUrl qmlComponentFilePath;
225 if (!m_qmlSurface->qmlFilePath().isEmpty()) {
226 qmlComponentFilePath = m_qmlSurface->qmlFilePath();
228 qmlComponentFilePath = QUrl("qrc:///Unity/Application/MirSurfaceItem.qml");
231 m_qmlContentComponent = new QQmlComponent(QQmlEngine::contextForObject(parent())->engine(), qmlComponentFilePath);
233 switch (m_qmlContentComponent->status()) {
234 case QQmlComponent::Ready:
235 createQmlContentItem();
237 case QQmlComponent::Loading:
238 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
239 this, &MirSurfaceItem::onComponentStatusChanged);
241 case QQmlComponent::Error:
242 printComponentErrors();
243 qFatal("MirSurfaceItem: failed to create content component.");
246 qFatal("MirSurfaceItem: Unhandled component status");
250 Q_EMIT surfaceChanged(m_qmlSurface);
253void MirSurfaceItem::itemChange(ItemChange change, const ItemChangeData & value)
255 if (change == QQuickItem::ItemActiveFocusHasChanged) {
257 m_qmlSurface->setActiveFocus(value.boolValue);
262void MirSurfaceItem::updateMirSurfaceVisibility()
264 if (!m_qmlSurface) return;
266 m_qmlSurface->setViewVisibility((qintptr)this, isVisible());
269void MirSurfaceItem::setConsumesInput(bool value)
271 if (m_consumesInput != value) {
272 m_consumesInput = value;
273 Q_EMIT consumesInputChanged(value);
277int MirSurfaceItem::surfaceWidth() const
279 return m_surfaceWidth;
282void MirSurfaceItem::setSurfaceWidth(int value)
284 if (value != -1 && m_surfaceWidth != value) {
285 m_surfaceWidth = value;
286 Q_EMIT surfaceWidthChanged(m_surfaceWidth);
291int MirSurfaceItem::surfaceHeight() const
293 return m_surfaceHeight;
296void MirSurfaceItem::setSurfaceHeight(int value)
298 if (value != -1 && m_surfaceHeight != value) {
299 m_surfaceHeight = value;
300 Q_EMIT surfaceHeightChanged(m_surfaceHeight);
305void MirSurfaceItem::updateSurfaceSize()
307 if (m_qmlSurface && m_surfaceWidth > 0 && m_surfaceHeight > 0) {
308 m_qmlSurface->resize(m_surfaceWidth, m_surfaceHeight);
312void MirSurfaceItem::setFillMode(FillMode value)
314 if (value != m_fillMode) {
316 Q_EMIT fillModeChanged(m_fillMode);
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