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.
preferencesAboutTextFull
Craig Watson 9 years ago
parent 427cdbb68d
commit ce521ede11
  1. 8
      OpenBoard.pro
  2. 81
      src/domain/UBGraphicsMediaItem.cpp
  3. 15
      src/domain/UBGraphicsMediaItem.h
  4. 6
      src/domain/UBGraphicsScene.cpp

@ -9,9 +9,9 @@ CONFIG += debug_and_release \
VERSION_MAJ = 1 VERSION_MAJ = 1
VERSION_MIN = 02 VERSION_MIN = 1
VERSION_TYPE = r # a = alpha, b = beta, rc = release candidate, r = release, other => error VERSION_TYPE = a # a = alpha, b = beta, rc = release candidate, r = release, other => error
VERSION_PATCH = 10 VERSION_PATCH = 0
VERSION = "$${VERSION_MAJ}.$${VERSION_MIN}.$${VERSION_TYPE}.$${VERSION_PATCH}" VERSION = "$${VERSION_MAJ}.$${VERSION_MIN}.$${VERSION_TYPE}.$${VERSION_PATCH}"
VERSION = $$replace(VERSION, "\\.r", "") VERSION = $$replace(VERSION, "\\.r", "")
@ -138,7 +138,7 @@ macx {
CONFIG(debug, debug|release):CONFIG += x86_64 CONFIG(debug, debug|release):CONFIG += x86_64
QMAKE_MAC_SDK = macosx QMAKE_MAC_SDK = macosx
QMAKE_MACOSX_DEPLOYMENT_TARGET = "10.10" QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.10
QMAKE_CXXFLAGS += -Wno-overloaded-virtual QMAKE_CXXFLAGS += -Wno-overloaded-virtual
#VERSION_RC_PATH = "$$BUILD_DIR/version_rc" #VERSION_RC_PATH = "$$BUILD_DIR/version_rc"

@ -35,11 +35,14 @@
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "core/memcheck.h" #include "core/memcheck.h"
#include <QGraphicsVideoItem>
bool UBGraphicsMediaItem::sIsMutedByDefault = false; bool UBGraphicsMediaItem::sIsMutedByDefault = false;
UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent) UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent)
: UBGraphicsProxyWidget(parent) : UBGraphicsProxyWidget(parent)
, mVideoWidget(NULL) , mDummyVideoWidget(NULL)
, mVideoItem(NULL)
, mAudioWidget(NULL) , mAudioWidget(NULL)
, mMuted(sIsMutedByDefault) , mMuted(sIsMutedByDefault)
, mMutedByUserAction(sIsMutedByDefault) , mMutedByUserAction(sIsMutedByDefault)
@ -62,19 +65,18 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
mMediaObject->setNotifyInterval(50); mMediaObject->setNotifyInterval(50);
mVideoWidget = new QVideoWidget(); // owned and destructed by the scene ... mDummyVideoWidget = new QWidget(); // owned and destructed by the scene ...
mDummyVideoWidget->resize(320,240);
mDummyVideoWidget->setMinimumSize(320, 240);
mDummyVideoWidget->setWindowOpacity(0.0);
mMediaObject->setVideoOutput(mVideoWidget); mVideoItem = new QGraphicsVideoItem();
if(mVideoWidget->sizeHint() == QSize(1,1)){ mMediaObject->setVideoOutput(mVideoItem);
mVideoWidget->resize(320,240);
}
mVideoWidget->setMinimumSize(320,240); mVideoItem->setSize(QSize(320,240));
haveLinkedImage = true; haveLinkedImage = true;
} }
else if (mediaPath.toLower().contains("audios")) 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. // delegate should be created earler because we setWidget calls resize event for graphics proxy widgt.
// resize uses delegate. // resize uses delegate.
if (mediaType_Video == mMediaType) if (mediaType_Video == mMediaType)
setWidget(mVideoWidget); setWidget(mDummyVideoWidget);
else else
setWidget(mAudioWidget); 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<QTransform>(value));
else if (mVideoItem && change == QGraphicsItem::ItemPositionChange)
mVideoItem->setPos(qvariant_cast<QPointF>(value));
return UBGraphicsProxyWidget::itemChange(change, 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));
}

@ -43,6 +43,8 @@
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBFileSystemUtils.h"
class QGraphicsVideoItem;
class UBGraphicsMediaItem : public UBGraphicsProxyWidget class UBGraphicsMediaItem : public UBGraphicsProxyWidget
{ {
Q_OBJECT Q_OBJECT
@ -87,9 +89,9 @@ public:
return mMuted; return mMuted;
} }
QVideoWidget* videoWidget() const QGraphicsVideoItem * videoItem() const
{ {
return mVideoWidget; return mVideoItem;
} }
bool hasLinkedImage(){return haveLinkedImage;} bool hasLinkedImage(){return haveLinkedImage;}
@ -106,6 +108,12 @@ public:
void setSelected(bool selected); 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: public slots:
@ -123,7 +131,8 @@ protected:
virtual void clearSource(); virtual void clearSource();
QMediaPlayer *mMediaObject; QMediaPlayer *mMediaObject;
QVideoWidget *mVideoWidget; QWidget *mDummyVideoWidget;
QGraphicsVideoItem *mVideoItem;
QWidget *mAudioWidget; QWidget *mAudioWidget;

@ -31,6 +31,7 @@
#include <QtWebKit> #include <QtWebKit>
#include <QtSvg> #include <QtSvg>
#include <QGraphicsView> #include <QGraphicsView>
#include <QGraphicsVideoItem>
#include "frameworks/UBGeometryUtils.h" #include "frameworks/UBGeometryUtils.h"
#include "frameworks/UBPlatformUtils.h" #include "frameworks/UBPlatformUtils.h"
@ -1328,6 +1329,11 @@ UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool s
addItem(mediaItem); addItem(mediaItem);
if (mediaItem->videoItem()) {
addItem(mediaItem->videoItem());
mediaItem->videoItem()->show();
}
mediaItem->show(); mediaItem->show();
if (mUndoRedoStackEnabled) { //should be deleted after scene own undo stack implemented if (mUndoRedoStackEnabled) { //should be deleted after scene own undo stack implemented

Loading…
Cancel
Save