From ce521ede116f7186e134dae4725f8b26a9554934 Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Thu, 3 Dec 2015 13:32:40 +0100 Subject: [PATCH] Video fixed on OS X QVideoWidget had to be abandoned in favour of QGraphicsVideoItem. This is because UBGraphicsMediaItem, i.e the class representing a media (audio or video) object on the board, is a QGraphicsProxyWidget, and is used to embed a QWidget into the Scene. With Phonon's video widget, it was possible to embed the video widget in this ProxyWidget. This is no longer possible (except on Windows, for some reason), so this commit is a workaround, to use a QGraphicsVideoItem instead of a QVideoWidget while modifying the rest of the class hierarchy as little as possible. Ultimately, a cleaner solution (not making UBGraphicsMediaItem inherit QGraphicsProxyWidget, for example) may be desirable. --- OpenBoard.pro | 8 +-- src/domain/UBGraphicsMediaItem.cpp | 83 ++++++++++++++++++++++++++---- src/domain/UBGraphicsMediaItem.h | 15 ++++-- src/domain/UBGraphicsScene.cpp | 6 +++ 4 files changed, 94 insertions(+), 18 deletions(-) diff --git a/OpenBoard.pro b/OpenBoard.pro index b6802c50..a9e2b737 100644 --- a/OpenBoard.pro +++ b/OpenBoard.pro @@ -9,9 +9,9 @@ CONFIG += debug_and_release \ VERSION_MAJ = 1 -VERSION_MIN = 02 -VERSION_TYPE = r # a = alpha, b = beta, rc = release candidate, r = release, other => error -VERSION_PATCH = 10 +VERSION_MIN = 1 +VERSION_TYPE = a # a = alpha, b = beta, rc = release candidate, r = release, other => error +VERSION_PATCH = 0 VERSION = "$${VERSION_MAJ}.$${VERSION_MIN}.$${VERSION_TYPE}.$${VERSION_PATCH}" VERSION = $$replace(VERSION, "\\.r", "") @@ -138,7 +138,7 @@ macx { CONFIG(debug, debug|release):CONFIG += x86_64 QMAKE_MAC_SDK = macosx - QMAKE_MACOSX_DEPLOYMENT_TARGET = "10.10" + QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.10 QMAKE_CXXFLAGS += -Wno-overloaded-virtual #VERSION_RC_PATH = "$$BUILD_DIR/version_rc" diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp index 7d6edabc..ec3bcd57 100644 --- a/src/domain/UBGraphicsMediaItem.cpp +++ b/src/domain/UBGraphicsMediaItem.cpp @@ -35,11 +35,14 @@ #include "board/UBBoardController.h" #include "core/memcheck.h" +#include + bool UBGraphicsMediaItem::sIsMutedByDefault = false; UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent) : UBGraphicsProxyWidget(parent) - , mVideoWidget(NULL) + , mDummyVideoWidget(NULL) + , mVideoItem(NULL) , mAudioWidget(NULL) , mMuted(sIsMutedByDefault) , mMutedByUserAction(sIsMutedByDefault) @@ -62,19 +65,18 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte mMediaObject->setNotifyInterval(50); - mVideoWidget = new QVideoWidget(); // owned and destructed by the scene ... - - mMediaObject->setVideoOutput(mVideoWidget); + mDummyVideoWidget = new QWidget(); // owned and destructed by the scene ... + mDummyVideoWidget->resize(320,240); + mDummyVideoWidget->setMinimumSize(320, 240); + mDummyVideoWidget->setWindowOpacity(0.0); + + mVideoItem = new QGraphicsVideoItem(); - if(mVideoWidget->sizeHint() == QSize(1,1)){ - mVideoWidget->resize(320,240); - } + mMediaObject->setVideoOutput(mVideoItem); - mVideoWidget->setMinimumSize(320,240); + mVideoItem->setSize(QSize(320,240)); haveLinkedImage = true; - - } else if (mediaPath.toLower().contains("audios")) { @@ -98,7 +100,7 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte // delegate should be created earler because we setWidget calls resize event for graphics proxy widgt. // resize uses delegate. if (mediaType_Video == mMediaType) - setWidget(mVideoWidget); + setWidget(mDummyVideoWidget); else setWidget(mAudioWidget); @@ -165,6 +167,13 @@ QVariant UBGraphicsMediaItem::itemChange(GraphicsItemChange change, const QVaria } } + // Pass on geometry and position changes to the videoItem + else if (mVideoItem && change == QGraphicsItem::ItemTransformChange) + mVideoItem->setTransform(qvariant_cast(value)); + + else if (mVideoItem && change == QGraphicsItem::ItemPositionChange) + mVideoItem->setPos(qvariant_cast(value)); + return UBGraphicsProxyWidget::itemChange(change, value); } @@ -330,3 +339,55 @@ void UBGraphicsMediaItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } +void UBGraphicsMediaItem::setPos(const QPointF &pos) +{ + QGraphicsItem::setPos(pos); + if (mVideoItem) + mVideoItem->setPos(pos); +} + +void UBGraphicsMediaItem::setPos(qreal x, qreal y) +{ + setPos(QPointF(x, y)); +} + + +void UBGraphicsMediaItem::setTransform(const QTransform &matrix, bool combine) +{ + QGraphicsItem::setTransform(matrix, combine); + + if (mVideoItem) + mVideoItem->setTransform(matrix, combine); +} + +void UBGraphicsMediaItem::resize(const QSizeF & pSize) +{ + // Resize the video, then the rest of the Item + + if (mVideoItem) { + qreal sizeX = 0; + qreal sizeY = 0; + + QSizeF minimumItemSize(mDummyVideoWidget->minimumSize()); + if (minimumItemSize.width() > pSize.width()) + sizeX = minimumItemSize.width(); + else + sizeX = pSize.width(); + + if (minimumItemSize.height() > pSize.height()) + sizeY = minimumItemSize.height(); + else + sizeY = pSize.height(); + + mVideoItem->setSize(QSizeF (sizeX, sizeY)); + } + + UBGraphicsProxyWidget::resize(pSize); +} + +void UBGraphicsMediaItem::resize(qreal w, qreal h) +{ + UBGraphicsMediaItem::resize(QSizeF(w, h)); +} + + diff --git a/src/domain/UBGraphicsMediaItem.h b/src/domain/UBGraphicsMediaItem.h index a0e9bcda..5846075b 100644 --- a/src/domain/UBGraphicsMediaItem.h +++ b/src/domain/UBGraphicsMediaItem.h @@ -43,6 +43,8 @@ #include "board/UBBoardController.h" #include "frameworks/UBFileSystemUtils.h" +class QGraphicsVideoItem; + class UBGraphicsMediaItem : public UBGraphicsProxyWidget { Q_OBJECT @@ -87,9 +89,9 @@ public: return mMuted; } - QVideoWidget* videoWidget() const + QGraphicsVideoItem * videoItem() const { - return mVideoWidget; + return mVideoItem; } bool hasLinkedImage(){return haveLinkedImage;} @@ -106,6 +108,12 @@ public: void setSelected(bool selected); + virtual void setPos(const QPointF &pos); + virtual void setPos(qreal x, qreal y); + virtual void setTransform(const QTransform &matrix, bool combine = false); + virtual void resize(qreal w, qreal h); + virtual void resize(const QSizeF & pSize); + public slots: @@ -123,7 +131,8 @@ protected: virtual void clearSource(); QMediaPlayer *mMediaObject; - QVideoWidget *mVideoWidget; + QWidget *mDummyVideoWidget; + QGraphicsVideoItem *mVideoItem; QWidget *mAudioWidget; diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 78284a86..63197044 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "frameworks/UBGeometryUtils.h" #include "frameworks/UBPlatformUtils.h" @@ -1328,6 +1329,11 @@ UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool s addItem(mediaItem); + if (mediaItem->videoItem()) { + addItem(mediaItem->videoItem()); + mediaItem->videoItem()->show(); + } + mediaItem->show(); if (mUndoRedoStackEnabled) { //should be deleted after scene own undo stack implemented