diff options
author | Ken Moore <ken@ixsystems.com> | 2017-10-12 10:43:44 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-10-12 10:43:44 -0400 |
commit | 86f326b3890f232debfb4b2dbcb86d860bf5ae0c (patch) | |
tree | b78aca7f59c15553036bcbb6e6d66a6ddc0509f0 /src-qt5/core/libLumina | |
parent | Add some color to the "Warp" starfield. (diff) | |
parent | Added framework to play video when the mouse is put over them. Breaks (diff) | |
download | lumina-86f326b3890f232debfb4b2dbcb86d860bf5ae0c.tar.gz lumina-86f326b3890f232debfb4b2dbcb86d860bf5ae0c.tar.bz2 lumina-86f326b3890f232debfb4b2dbcb86d860bf5ae0c.zip |
Merge branch 'master' of github.com:trueos/lumina
Diffstat (limited to 'src-qt5/core/libLumina')
-rw-r--r-- | src-qt5/core/libLumina/LVideoLabel.cpp | 61 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LVideoLabel.h | 30 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LVideoLabel.pri | 8 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LVideoSurface.cpp | 23 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LVideoSurface.h | 11 |
5 files changed, 118 insertions, 15 deletions
diff --git a/src-qt5/core/libLumina/LVideoLabel.cpp b/src-qt5/core/libLumina/LVideoLabel.cpp new file mode 100644 index 00000000..20b2cad4 --- /dev/null +++ b/src-qt5/core/libLumina/LVideoLabel.cpp @@ -0,0 +1,61 @@ +#include "LVideoLabel.h" + +LVideoLabel::LVideoLabel(QString file, bool video) : QLabel(){ + this->setScaledContents(true); + if(video) { + mediaPlayer = new QMediaPlayer(this, QMediaPlayer::VideoSurface); + thumbnail = QPixmap(); + entered = false; + surface = new LVideoSurface(this); + mediaPlayer->setVideoOutput(surface); + mediaPlayer->setMedia(QUrl("file://" + file)); + mediaPlayer->setPlaybackRate(3); + mediaPlayer->setMuted(true); + mediaPlayer->play(); + mediaPlayer->pause(); + this->connect(surface, SIGNAL(frameReceived(QPixmap)), this, SLOT(stopVideo(QPixmap))); + this->connect(mediaPlayer, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(setDuration(QMediaPlayer::MediaStatus))); + this->connect(this, SIGNAL(rollOver()), surface, SLOT(switchRollOver())); + }else{ + thumbnail = QPixmap(file); + this->setPixmap(thumbnail); + } +} + +LVideoLabel::~LVideoLabel() { + mediaPlayer->deleteLater(); + surface->deleteLater(); +} + +void LVideoLabel::stopVideo(QPixmap pix) { + if(!entered) { + if(thumbnail.isNull()) + thumbnail = QPixmap(pix.scaledToHeight(64)); + this->setPixmap(thumbnail); + mediaPlayer->pause(); + }else { + this->setPixmap(QPixmap(pix.scaledToHeight(64))); + } +} + +void LVideoLabel::setDuration(QMediaPlayer::MediaStatus status) { + if(status == QMediaPlayer::BufferedMedia) { + mediaPlayer->setPosition(mediaPlayer->duration() / 2); + mediaPlayer->play(); + } +} + +void LVideoLabel::enterEvent(QEvent *event) { + entered=true; + emit rollOver(); + mediaPlayer->setPosition(0); + mediaPlayer->play(); + QLabel::enterEvent(event); +} + +void LVideoLabel::leaveEvent(QEvent *event) { + entered=false; + mediaPlayer->setPosition(mediaPlayer->duration() / 2); + emit rollOver(); + QLabel::leaveEvent(event); +} diff --git a/src-qt5/core/libLumina/LVideoLabel.h b/src-qt5/core/libLumina/LVideoLabel.h new file mode 100644 index 00000000..fd293200 --- /dev/null +++ b/src-qt5/core/libLumina/LVideoLabel.h @@ -0,0 +1,30 @@ +#ifndef LVIDEOLABEL_H +#define LVIDEOLABEL_H + +#include <QLabel> +#include <QMediaPlayer> +#include "LVideoSurface.h" + +//class LVideoSurface; + +class LVideoLabel : public QLabel { + Q_OBJECT + public: + LVideoLabel(QString, bool); + ~LVideoLabel(); + protected: + void enterEvent(QEvent*); + void leaveEvent(QEvent*); + signals: + void rollOver(); + public slots: + void stopVideo(QPixmap); + void setDuration(QMediaPlayer::MediaStatus); + private: + QMediaPlayer *mediaPlayer; + LVideoSurface *surface; + QVideoWidget *videoPlayer; + QPixmap thumbnail; + bool entered; +}; +#endif diff --git a/src-qt5/core/libLumina/LVideoLabel.pri b/src-qt5/core/libLumina/LVideoLabel.pri new file mode 100644 index 00000000..f609df08 --- /dev/null +++ b/src-qt5/core/libLumina/LVideoLabel.pri @@ -0,0 +1,8 @@ +QT *= multimedia + +HEADERS *= $${PWD}/LVideoLabel.h +SOURCES *= $${PWD}/LVideoLabel.cpp + +INCLUDEPATH *= ${PWD} + +include(LVideoSurface.pri) diff --git a/src-qt5/core/libLumina/LVideoSurface.cpp b/src-qt5/core/libLumina/LVideoSurface.cpp index bd6b2c95..e3e87667 100644 --- a/src-qt5/core/libLumina/LVideoSurface.cpp +++ b/src-qt5/core/libLumina/LVideoSurface.cpp @@ -3,10 +3,12 @@ LVideoSurface::LVideoSurface(QObject *parent) : QAbstractVideoSurface(parent) { frameImage = QPixmap(); + entered = false; } bool LVideoSurface::present(const QVideoFrame &frame) { - if(!frameImage.isNull()) { + //qDebug() << surfaceFormat().pixelFormat() << frame.pixelFormat() << surfaceFormat().frameSize() << frame.size(); + if(!frameImage.isNull() && !entered) { emit frameReceived(frameImage); return true; } @@ -15,9 +17,10 @@ bool LVideoSurface::present(const QVideoFrame &frame) { //qDebug() << "Recording Frame" << frame.pixelFormat(); QVideoFrame icon(frame); icon.map(QAbstractVideoBuffer::ReadOnly); + //qDebug() << icon.width() << icon.height(); QImage img(icon.bits(), icon.width(), icon.height(), icon.bytesPerLine(), QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat())); - if(frameImage.isNull()) + if((frameImage.isNull() && !entered) or entered) frameImage = QPixmap::fromImage(img.copy(img.rect())); icon.unmap(); @@ -33,26 +36,22 @@ QList<QVideoFrame::PixelFormat> LVideoSurface::supportedPixelFormats(QAbstractVi << QVideoFrame::Format_RGB565 << QVideoFrame::Format_RGB555 << QVideoFrame::Format_BGRA32 << QVideoFrame::Format_BGR32; } -/*bool VideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const { - const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat()); - const QSize size = format.frameSize(); - - return imageFormat != QImage::Format_Invalid && !size.isEmpty() && format.handleType() == QAbstractVideoBuffer::NoHandle; +void LVideoSurface::stop() { + QAbstractVideoSurface::stop(); } -void VideoSurface::stop() { - QAbstractVideoSurface::stop(); +void LVideoSurface::switchRollOver() { + entered = !entered; } -bool VideoSurface::start(const QVideoSurfaceFormat &format) { +bool LVideoSurface::start(const QVideoSurfaceFormat &format) { const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat()); const QSize size = format.frameSize(); if (imageFormat != QImage::Format_Invalid && !size.isEmpty()) { - this->imageFormat = imageFormat; QAbstractVideoSurface::start(format); return true; } else { return false; } -}*/ +} diff --git a/src-qt5/core/libLumina/LVideoSurface.h b/src-qt5/core/libLumina/LVideoSurface.h index 42a140d9..7a3dcaad 100644 --- a/src-qt5/core/libLumina/LVideoSurface.h +++ b/src-qt5/core/libLumina/LVideoSurface.h @@ -1,3 +1,6 @@ +#ifndef LVIDEOSURFACE_H +#define LVIDEOSURFACE_H + #include <QAbstractVideoSurface> #include <QVideoSurfaceFormat> #include <QPixmap> @@ -10,12 +13,14 @@ class LVideoSurface : public QAbstractVideoSurface { LVideoSurface(QObject *parent=0); virtual bool present(const QVideoFrame&); virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType) const; - /*virtual QList<QVidebool isFormatSupported(const QVideoSurfaceFormat &format) const; bool start(const QVideoSurfaceFormat &format); - void stop();*/ + void stop(); signals: void frameReceived(QPixmap); + public slots: + void switchRollOver(); private: QPixmap frameImage; - //QImage::Format imageFormat; + bool entered; }; +#endif |