2 * Copyright (C) 2016 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 "videooutput.h"
18#include "mediaplayer.h"
23#include <QQmlComponent>
24#include <QGuiApplication>
25#include <QQmlProperty>
28VideoOutput::VideoOutput(QQuickItem *parent)
31 , m_qmlContentComponent(nullptr)
36void VideoOutput::setSource(QObject *source)
38 if (m_source != source) {
39 if (m_source) disconnect(m_source, 0, this, 0);
42 Q_EMIT sourceChanged();
44 MediaPlayer* mediaPlayer = qobject_cast<MediaPlayer*>(source);
46 connect(mediaPlayer, &MediaPlayer::positionChanged, this, &VideoOutput::updateProperties);
47 connect(mediaPlayer, &MediaPlayer::playbackStateChanged, this, &VideoOutput::updateProperties);
48 connect(mediaPlayer->metaData(), SIGNAL(metaDataChanged()), this, SLOT(updateProperties()));
53void VideoOutput::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
55 if (change == QQuickItem::ItemSceneChange && !m_qmlContentComponent) {
56 QWindowList list = QGuiApplication::topLevelWindows();
57 if (list.isEmpty()) return;
59 // The assumptions I make here really should hold.
60 QQuickView *quickView =
61 qobject_cast<QQuickView*>(list[0]);
63 m_qmlContentComponent = new QQmlComponent(quickView->engine(),
64 QString("%1/QtMultimedia/VideoSurface.qml").arg(mockPluginsDir()));
66 switch (m_qmlContentComponent->status()) {
67 case QQmlComponent::Ready:
68 createQmlContentItem();
70 case QQmlComponent::Loading:
71 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
72 this, &VideoOutput::onComponentStatusChanged);
74 case QQmlComponent::Error:
75 printComponentErrors();
76 qFatal("VideoOutput: failed to create content component.");
79 qFatal("VideoOutput: Unhandled component status");
82 QQuickItem::itemChange(change, value);
85void VideoOutput::printComponentErrors()
87 QList<QQmlError> errors = m_qmlContentComponent->errors();
88 for (int i = 0; i < errors.count(); ++i) {
89 qDebug() << errors[i];
93void VideoOutput::onComponentStatusChanged(QQmlComponent::Status status)
95 if (status == QQmlComponent::Ready) {
96 createQmlContentItem();
100void VideoOutput::createQmlContentItem()
102 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
103 m_qmlItem->setParentItem(this);
108void VideoOutput:: updateProperties()
110 if (!m_qmlItem) return;
112 MediaPlayer* mediaPlayer = qobject_cast<MediaPlayer*>(m_source);
113 if (!mediaPlayer) return;
115 QQmlProperty playbackStateProperty(m_qmlItem, "playbackState");
116 playbackStateProperty.write(QVariant::fromValue<int>(mediaPlayer->playbackState()));
118 QQmlProperty positionProperty(m_qmlItem, "position");
119 positionProperty.write(QVariant::fromValue(mediaPlayer->position()));
121 QQmlProperty propResSource(mediaPlayer->metaData(), "resolution");
122 QQmlProperty propResDest(m_qmlItem, "resolution");
124 if (propResSource.isValid() && propResDest.isValid()) {
125 propResDest.write(propResSource.read());
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