diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index c18bf0b1..6b4cceb7 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -296,6 +296,8 @@ class UBGraphicsItemDelegate : public QObject void setUBFlags(UBGraphicsFlags pf); void setUBFlag(UBGraphicsFlags pf, bool set = true); + virtual void showToolBar() {} + signals: void showOnDisplayChanged(bool shown); void lockChanged(bool locked); diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp index 8c61a874..daa5e84d 100644 --- a/src/domain/UBGraphicsMediaItem.cpp +++ b/src/domain/UBGraphicsMediaItem.cpp @@ -80,19 +80,12 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte setFlag(ItemIsMovable, true); setFlag(ItemSendsGeometryChanges, true); - setAcceptHoverEvents(true); - connect(mMediaObject, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), Delegate(), SLOT(mediaStatusChanged(QMediaPlayer::MediaStatus))); connect(mMediaObject, SIGNAL(stateChanged(QMediaPlayer::State)), Delegate(), SLOT(mediaStateChanged(QMediaPlayer::State))); - /* - connect(mMediaObject, static_cast(&QMediaPlayer::error), - Delegate(), &UBGraphicsMediaItemDelegate::mediaError); - */ - connect(mMediaObject, SIGNAL(positionChanged(qint64)), Delegate(), SLOT(updateTicker(qint64))); @@ -104,6 +97,9 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte connect(mMediaObject, SIGNAL(videoAvailableChanged(bool)), this, SLOT(hasMediaChanged(bool))); + + connect(mMediaObject, static_cast(&QMediaPlayer::error), + this, &UBGraphicsMediaItem::mediaError); } UBGraphicsAudioItem::UBGraphicsAudioItem(const QUrl &pMediaFileUrl, QGraphicsItem *parent) @@ -133,11 +129,13 @@ UBGraphicsVideoItem::UBGraphicsVideoItem(const QUrl &pMediaFileUrl, QGraphicsIte setMinimumSize(QSize(320, 240)); setSize(320, 240); - connect(mVideoItem, SIGNAL(nativeSizeChanged(QSizeF)), this, SLOT(videoSizeChanged(QSizeF))); haveLinkedImage = true; + + setAcceptHoverEvents(true); + update(); } @@ -179,8 +177,7 @@ QVariant UBGraphicsMediaItem::itemChange(GraphicsItemChange change, const QVaria return QGraphicsRectItem::itemChange(change, newValue); } - else - return QGraphicsRectItem::itemChange(change, value); + return QGraphicsRectItem::itemChange(change, value); } void UBGraphicsMediaItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -293,8 +290,7 @@ void UBGraphicsMediaItem::setMute(bool bMute) void UBGraphicsMediaItem::hasMediaChanged(bool hasMedia) { - if(hasMedia && mMediaObject->isSeekable()) - { + if(hasMedia && mMediaObject->isSeekable()) { mMediaObject->setPosition(mInitialPos); UBGraphicsMediaItemDelegate *med = dynamic_cast(Delegate()); @@ -345,7 +341,6 @@ void UBGraphicsMediaItem::stop() void UBGraphicsMediaItem::togglePlayPause() { - if (mMediaObject->state() == QMediaPlayer::StoppedState) mMediaObject->play(); @@ -374,10 +369,12 @@ void UBGraphicsMediaItem::togglePlayPause() mMediaObject->setMedia(mediaFileUrl()); mMediaObject->play(); } +} - if (mMediaObject->error()) - qDebug() << "Error appeared." << mMediaObject->errorString(); - +void UBGraphicsMediaItem::mediaError(QMediaPlayer::Error errorCode) +{ + if (errorCode != QMediaPlayer::NoError) + UBApplication::showMessage(mMediaObject->errorString()); } void UBGraphicsMediaItem::copyItemParameters(UBItem *copy) const @@ -403,14 +400,11 @@ void UBGraphicsMediaItem::copyItemParameters(UBItem *copy) const void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (Delegate()) - { + if (Delegate()) { Delegate()->mousePressEvent(event); - if (parentItem() && UBGraphicsGroupContainerItem::Type == parentItem()->type()) - { + if (parentItem() && UBGraphicsGroupContainerItem::Type == parentItem()->type()) { UBGraphicsGroupContainerItem *group = qgraphicsitem_cast(parentItem()); - if (group) - { + if (group) { QGraphicsItem *curItem = group->getCurrentItem(); if (curItem && this != curItem) group->deselectCurrentItem(); @@ -418,7 +412,6 @@ void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event) this->setSelected(true); Delegate()->positionHandles(); } - } } @@ -504,7 +497,34 @@ void UBGraphicsVideoItem::setSize(int width, int height) void UBGraphicsVideoItem::videoSizeChanged(QSizeF newSize) { - this->setSize(newSize.width(), newSize.height()); + /* Depending on the platform, video size information becomes available + * at different times (either when the file is loaded, or when playback + * begins), so this slot is needed to resize the video item as soon as + * the information is available. + */ + + + // Don't resize the video item when playback has finished + if (mMediaObject->mediaStatus() != QMediaPlayer::EndOfMedia) + this->setSize(newSize.width(), newSize.height()); } + +void UBGraphicsVideoItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + // Display the seek bar + Delegate()->showToolBar(); + QGraphicsRectItem::hoverEnterEvent(event); +} + +void UBGraphicsVideoItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ + Delegate()->showToolBar(); + QGraphicsRectItem::hoverMoveEvent(event); +} + +void UBGraphicsVideoItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + QGraphicsRectItem::hoverLeaveEvent(event); +} diff --git a/src/domain/UBGraphicsMediaItem.h b/src/domain/UBGraphicsMediaItem.h index a7c4540c..98897dff 100644 --- a/src/domain/UBGraphicsMediaItem.h +++ b/src/domain/UBGraphicsMediaItem.h @@ -117,6 +117,9 @@ public slots: virtual void stop(); virtual void togglePlayPause(); +protected slots: + void mediaError(QMediaPlayer::Error errorCode); + protected: virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); @@ -177,6 +180,10 @@ public slots: protected: QGraphicsVideoItem *mVideoItem; + + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); }; diff --git a/src/domain/UBGraphicsMediaItemDelegate.cpp b/src/domain/UBGraphicsMediaItemDelegate.cpp index 374c1336..f04ee641 100644 --- a/src/domain/UBGraphicsMediaItemDelegate.cpp +++ b/src/domain/UBGraphicsMediaItemDelegate.cpp @@ -71,6 +71,18 @@ bool UBGraphicsMediaItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *even return UBGraphicsItemDelegate::mousePressEvent(event); } +/** + * @brief Show the toolbar (play/pause, seek, mute). + * + * The toolbar then auto-hides after a set amount of time. + */ +void UBGraphicsMediaItemDelegate::showToolBar() +{ + mToolBarItem->show(); + if (mToolBarShowTimer) + mToolBarShowTimer->start(); +} + void UBGraphicsMediaItemDelegate::hideToolBar() { mToolBarItem->hide(); @@ -108,11 +120,10 @@ void UBGraphicsMediaItemDelegate::buildButtons() mToolBarItem->setShifting(false); if (!mToolBarShowTimer) { - if (delegated()->hasLinkedImage()) { mToolBarShowTimer = new QTimer(); - connect(mToolBarShowTimer, SIGNAL(timeout()), this, SLOT(hideToolBar())); mToolBarShowTimer->setInterval(m_iToolBarShowingInterval); + connect(mToolBarShowTimer, SIGNAL(timeout()), this, SLOT(hideToolBar())); } } @@ -181,13 +192,6 @@ void UBGraphicsMediaItemDelegate::remove(bool canUndo) if (delegated()) delegated()->stop(); - /* - if (delegated()->videoItem()) { - UBGraphicsScene* scene = dynamic_cast(mDelegated->scene()); - scene->removeItem(delegated()->videoItem()); - } - */ - UBGraphicsItemDelegate::remove(canUndo); } @@ -232,15 +236,6 @@ void UBGraphicsMediaItemDelegate::mediaStateChanged(QMediaPlayer::State state) updatePlayPauseState(); } -void UBGraphicsMediaItemDelegate::mediaError(QMediaPlayer::Error error) -{ - // Possible errors are NoError, ResourceError, FormatError, NetworkError, AccessDeniedError, - // ServiceMissingError - Q_UNUSED(error); - - qDebug() << "Error appeared.";// << mMedia->errorString(); -} - void UBGraphicsMediaItemDelegate::updatePlayPauseState() { @@ -253,9 +248,6 @@ void UBGraphicsMediaItemDelegate::updatePlayPauseState() void UBGraphicsMediaItemDelegate::updateTicker(qint64 time) { - // TODO: duration() getter for UBGMediaItem - // make sure that all delegate()->mediaObject() calls are removed. 'tis dirty. - mMediaControl->totalTimeChanged(delegated()->mediaDuration()); mMediaControl->updateTicker(time); } @@ -270,7 +262,6 @@ void UBGraphicsMediaItemDelegate::showHide(bool show) { QVariant showFlag = QVariant(show ? UBItemLayerType::Object : UBItemLayerType::Control); showHideRecurs(showFlag, mDelegated); - // TODO: call showHideRecurs on the videoItem too (from UBGMI?) mDelegated->update(); emit showOnDisplayChanged(show); diff --git a/src/domain/UBGraphicsMediaItemDelegate.h b/src/domain/UBGraphicsMediaItemDelegate.h index f36c7343..31097cc0 100644 --- a/src/domain/UBGraphicsMediaItemDelegate.h +++ b/src/domain/UBGraphicsMediaItemDelegate.h @@ -50,6 +50,8 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate bool mousePressEvent(QGraphicsSceneMouseEvent* event); + void showToolBar(); + public slots: void toggleMute(); @@ -58,7 +60,6 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate void mediaStatusChanged(QMediaPlayer::MediaStatus status); void mediaStateChanged(QMediaPlayer::State state); - void mediaError(QMediaPlayer::Error error); protected slots: