Permalink
Browse files

qmlui: handle video attributes change

Also:
- fix custom/original geometry switch
- do not go fullscreen if the requested screen is not available
  • Loading branch information...
mcallegari committed Nov 25, 2018
1 parent c7f628b commit 1066c6587668c57f8453f0e629830daaac812168
@@ -33,28 +33,35 @@ Rectangle
// array of IDs of the contents currently playing
property var mediaArray: []
property var mediaItems: []
function addVideo(vContent)
{
videoComponent.createObject(ctxRoot, { "video": vContent });
var item = videoComponent.createObject(ctxRoot, { "video": vContent });
if (videoComponent.status !== Component.Ready)
console.log("Video component is not ready !!")
mediaArray.push(vContent.id)
mediaItems.push(item)
}
function addPicture(pContent)
{
pictureComponent.createObject(ctxRoot, { "picture": pContent });
var item = pictureComponent.createObject(ctxRoot, { "picture": pContent });
if (pictureComponent.status !== Component.Ready)
console.log("Picture component is not ready !!")
mediaArray.push(pContent.id)
mediaItems.push(item)
}
function removeContent(id)
{
var cIdx = mediaArray.indexOf(id)
if (cIdx > -1)
{
mediaItems[cIdx].stopPlayback()
mediaArray.splice(cIdx, 1)
mediaItems.splice(cIdx, 1)
}
console.log("Removing content with ID: " + id + ", count: " + mediaArray.length)
@@ -79,25 +86,31 @@ Rectangle
Rectangle
{
id: videoRect
//anchors.fill: parent
objectName: "media-" + video.id
color: "black"
opacity: video ? video.intensity : 1.0
z: video ? video.zIndex : 1
opacity: video.intensity
z: video.zIndex
property VideoFunction video: null
property vector3d rotation: video.rotation
property rect geometry: video.customGeometry
function stopPlayback()
{
player.stop()
}
onVideoChanged:
{
if (video.customGeometry.width !== 0 && video.customGeometry.height !== 0)
if (geometry.width !== 0 && geometry.height !== 0)
{
if (video.fullscreen)
{
x = video.customGeometry.x
y = video.customGeometry.y
x = Qt.binding(function() { return geometry.x })
y = Qt.binding(function() { return geometry.y })
}
width = video.customGeometry.width
height = video.customGeometry.height
width = Qt.binding(function() { return geometry.width })
height = Qt.binding(function() { return geometry.height })
}
else
anchors.fill = parent
@@ -110,23 +123,23 @@ Rectangle
Rotation
{
origin.x: width / 2
origin.y: video.rotation.x > 0 ? height : 0
origin.y: rotation.x > 0 ? height : 0
axis { x: 1; y: 0; z: 0 }
angle: video.rotation.x
angle: rotation.x
},
Rotation
{
origin.x: video.rotation.y > 0 ? 0 : width
origin.x: rotation.y > 0 ? 0 : width
origin.y: height / 2
axis { x: 0; y: 1; z: 0 }
angle: video.rotation.y
angle: rotation.y
},
Rotation
{
origin.x: width / 2
origin.y: height / 2
axis { x: 0; y: 0; z: 1 }
angle: video.rotation.z
angle: rotation.z
}
]
@@ -159,22 +172,27 @@ Rectangle
Image
{
objectName: "media-" + picture.id
opacity: picture.intensity
z: picture.zIndex
property VideoFunction picture: null
property vector3d rotation: picture.rotation
property rect geometry: picture.customGeometry
opacity: picture ? picture.intensity : 1.0
z: picture ? picture.zIndex : 2
function stopPlayback() { }
onPictureChanged:
{
if (picture.customGeometry.width !== 0 && picture.customGeometry.height !== 0)
if (geometry.width !== 0 && geometry.height !== 0)
{
if (picture.fullscreen)
{
x = picture.customGeometry.x
y = picture.customGeometry.y
x = Qt.binding(function() { return geometry.x })
y = Qt.binding(function() { return geometry.y })
}
width = picture.customGeometry.width
height = picture.customGeometry.height
width = Qt.binding(function() { return geometry.width })
height = Qt.binding(function() { return geometry.height })
}
else
anchors.fill = parent
@@ -187,23 +205,23 @@ Rectangle
Rotation
{
origin.x: width / 2
origin.y: picture.rotation.x > 0 ? height : 0
origin.y: rotation.x > 0 ? height : 0
axis { x: 1; y: 0; z: 0 }
angle: picture.rotation.x
angle: rotation.x
},
Rotation
{
origin.x: picture.rotation.y > 0 ? 0 : width
origin.x: rotation.y > 0 ? 0 : width
origin.y: height / 2
axis { x: 0; y: 1; z: 0 }
angle: picture.rotation.y
angle: rotation.y
},
Rotation
{
origin.x: width / 2
origin.y: height / 2
axis { x: 0; y: 0; z: 1 }
angle: picture.rotation.z
angle: rotation.z
}
]
}
@@ -294,12 +294,7 @@ Rectangle
onToggled:
{
if (checked)
{
geomXSpin.value = 0
geomYSpin.value = 0
geomWSpin.value = 0
geomHSpin.value = 0
}
videoEditor.customGeometry = Qt.rect(0, 0, 0, 0)
}
}
RobotoText
@@ -124,6 +124,8 @@ VideoContent::VideoContent(Video *video, VideoProvider *parent)
connect(m_video, SIGNAL(sourceChanged(QString)),
this, SLOT(slotDetectResolution()));
connect(m_video, SIGNAL(attributeChanged(int,qreal)),
this, SLOT(slotAttributeChanged(int,qreal)));
}
quint32 VideoContent::id() const
@@ -147,18 +149,25 @@ void VideoContent::destroyContext()
void VideoContent::playContent()
{
QScreen *vScreen = nullptr;
if (m_video->fullscreen())
m_viewContext = m_provider->fullscreenContext();
if (m_video->isPicture())
{
m_geometry.setSize(m_video->resolution());
}
else if (!m_video->customGeometry().isNull())
{
m_geometry = m_video->customGeometry();
}
qDebug() << "Video screen:" << m_video->screen() << ", geometry:" << m_geometry;
if (m_viewContext == nullptr)
{
QList<QScreen *> screens = QGuiApplication::screens();
QScreen *vScreen = nullptr;
if (m_video->screen() < screens.count())
vScreen = screens.at(m_video->screen());
@@ -197,7 +206,7 @@ void VideoContent::playContent()
m_viewContext->setFlags(m_viewContext->flags() | Qt::WindowStaysOnTopHint);
if (m_video->fullscreen())
if (vScreen && m_video->fullscreen())
{
m_provider->setFullscreenContext(m_viewContext);
m_viewContext->showFullScreen();
@@ -232,6 +241,90 @@ void VideoContent::slotDetectResolution()
m_mediaPlayer->setMedia(QUrl::fromLocalFile(sourceURL));
}
QVariant VideoContent::getAttribute(quint32 id, const char *propName)
{
QQuickItem *item = qobject_cast<QQuickItem*>(m_viewContext->findChild<QQuickItem*>(QString("media-%1").arg(id)));
if (item)
return item->property(propName);
return QVariant();
}
void VideoContent::updateAttribute(quint32 id, const char *propName, QVariant value)
{
QQuickItem *item = qobject_cast<QQuickItem*>(m_viewContext->findChild<QQuickItem*>(QString("media-%1").arg(id)));
if (item)
item->setProperty(propName, value);
}
void VideoContent::slotAttributeChanged(int attrIndex, qreal value)
{
switch (attrIndex)
{
case Video::XRotation:
{
QVector3D rot = m_video->rotation();
rot.setX(float(value));
updateAttribute(m_video->id(), "rotation", rot);
}
break;
case Video::YRotation:
{
QVector3D rot = m_video->rotation();
rot.setY(float(value));
updateAttribute(m_video->id(), "rotation", rot);
}
break;
case Video::ZRotation:
{
QVector3D rot = m_video->rotation();
rot.setZ(float(value));
updateAttribute(m_video->id(), "rotation", rot);
}
break;
case Video::XPosition:
{
qreal xDelta = qreal(m_viewContext->width()) * (value / 100.0);
QVariant var = getAttribute(m_video->id(), "geometry");
QRect currGeom = var.isNull() ? m_geometry : var.toRect();
QRect geom(m_geometry.x() + int(xDelta), currGeom.y(),
currGeom.width(), currGeom.height());
updateAttribute(m_video->id(), "geometry", geom);
}
break;
case Video::YPosition:
{
qreal yDelta = qreal(m_viewContext->height()) * (value / 100.0);
QVariant var = getAttribute(m_video->id(), "geometry");
QRect currGeom = var.isNull() ? m_geometry : var.toRect();
QRect geom(currGeom.x(), m_geometry.y() + int(yDelta),
currGeom.width(), currGeom.height());
updateAttribute(m_video->id(), "geometry", geom);
}
break;
case Video::WidthScale:
{
QVariant var = getAttribute(m_video->id(), "geometry");
QRect geom = var.isNull() ? m_geometry : var.toRect();
qreal newWidth = qreal(m_geometry.width()) * (value / 100.0);
geom.setWidth(int(newWidth));
updateAttribute(m_video->id(), "geometry", geom);
}
break;
case Video::HeightScale:
{
QVariant var = getAttribute(m_video->id(), "geometry");
QRect geom = var.isNull() ? m_geometry : var.toRect();
qreal newHeight = qreal(m_geometry.height()) * (value / 100.0);
geom.setHeight(int(newHeight));
updateAttribute(m_video->id(), "geometry", geom);
}
break;
default:
break;
}
}
void VideoContent::slotMetaDataChanged(const QString &key, const QVariant &value)
{
if (key == "Resolution")
@@ -74,8 +74,13 @@ class VideoContent: public QObject
void playContent();
void stopContent();
protected:
QVariant getAttribute(quint32 id, const char *propName);
void updateAttribute(quint32 id, const char *propName, QVariant value);
public slots:
void slotDetectResolution();
void slotAttributeChanged(int attrIndex, qreal value);
protected slots:
void slotMetaDataChanged(const QString &key, const QVariant &value);

0 comments on commit 1066c65

Please sign in to comment.