From 830a7f20bf7b412b668fb088d2cdc72fcff38cd1 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 18 Jul 2013 15:55:55 +0200 Subject: [PATCH] improvements of the control media bar --- src/domain/UBGraphicsItemDelegate.cpp | 11 +--- src/domain/UBGraphicsMediaItemDelegate.cpp | 59 ++++++++++++---------- src/domain/UBGraphicsMediaItemDelegate.h | 2 +- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index f1ef9606..ab73d0ad 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -1120,8 +1120,7 @@ void MediaTimer::addPoint(QPolygon &a, const QPoint &p) a.setPoint(n, p); } -void MediaTimer::paint(QPainter *p, - const QStyleOptionGraphicsItem *option, QWidget *widget) +void MediaTimer::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); @@ -1300,10 +1299,6 @@ QPainterPath DelegateMediaControl::shape() const void DelegateMediaControl::positionHandles() { - QRectF selfRect = rect(); - selfRect.setHeight(parentItem()->boundingRect().height()); - setRect(selfRect); - QTime tTotal; tTotal = tTotal.addMSecs(mTotalTimeInMs); mLCDTimerArea.setHeight(parentItem()->boundingRect().height()); @@ -1329,10 +1324,6 @@ void DelegateMediaControl::positionHandles() mLCDTimerArea.setWidth(timerWidth); lcdTimer->setRect(mLCDTimerArea); - // not the best solution, but it works. - lcdTimer->positionHandles(); - mLCDTimerArea = lcdTimer->rect(); - // ------------------------------------- lcdTimer->setPos(rect().width() - mLCDTimerArea.width(), 0); diff --git a/src/domain/UBGraphicsMediaItemDelegate.cpp b/src/domain/UBGraphicsMediaItemDelegate.cpp index d27d7154..80a97842 100644 --- a/src/domain/UBGraphicsMediaItemDelegate.cpp +++ b/src/domain/UBGraphicsMediaItemDelegate.cpp @@ -44,6 +44,7 @@ UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pD | GF_RESPECT_RATIO | GF_TOOLBAR_USED | GF_SHOW_CONTENT_SOURCE) + , mPlayPauseButton(NULL) , mMedia(pMedia) , mToolBarShowTimer(NULL) , m_iToolBarShowingInterval(5000) @@ -88,40 +89,42 @@ void UBGraphicsMediaItemDelegate::hideToolBar() void UBGraphicsMediaItemDelegate::buildButtons() { - mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); - connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause())); + if(!mPlayPauseButton){ + mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); + connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause())); - mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); - connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop())); + mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); + connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop())); - mMediaControl = new DelegateMediaControl(delegated(), mToolBarItem); - mMediaControl->setFlag(QGraphicsItem::ItemIsSelectable, true); - UBGraphicsItem::assignZValue(mMediaControl, delegated()->zValue()); + mMediaControl = new DelegateMediaControl(delegated(), mToolBarItem); + mMediaControl->setFlag(QGraphicsItem::ItemIsSelectable, true); + UBGraphicsItem::assignZValue(mMediaControl, delegated()->zValue()); - if (delegated()->isMuted()) - mMuteButton = new DelegateButton(":/images/soundOff.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); - else - mMuteButton = new DelegateButton(":/images/soundOn.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); + if (delegated()->isMuted()) + mMuteButton = new DelegateButton(":/images/soundOff.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); + else + mMuteButton = new DelegateButton(":/images/soundOn.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); - connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute())); - connect(mMuteButton, SIGNAL(clicked(bool)), this, SLOT(toggleMute())); // for changing button image + connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute())); + connect(mMuteButton, SIGNAL(clicked(bool)), this, SLOT(toggleMute())); // for changing button image - mToolBarButtons << mPlayPauseButton << mStopButton << mMuteButton; + mToolBarButtons << mPlayPauseButton << mStopButton << mMuteButton; - mToolBarItem->setItemsOnToolBar(QList() << mPlayPauseButton << mStopButton << mMediaControl << mMuteButton); - mToolBarItem->setVisibleOnBoard(true); - mToolBarItem->setShifting(false); + mToolBarItem->setItemsOnToolBar(QList() << mPlayPauseButton << mStopButton << mMediaControl << mMuteButton ); + mToolBarItem->setVisibleOnBoard(true); + mToolBarItem->setShifting(false); - if (mToolBarShowTimer) - { - connect(mPlayPauseButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start())); - connect(mStopButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start())); - connect(mMediaControl, SIGNAL(used()), mToolBarShowTimer, SLOT(start())); - connect(mMuteButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start())); - } + if (mToolBarShowTimer) + { + connect(mPlayPauseButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start())); + connect(mStopButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start())); + connect(mMediaControl, SIGNAL(used()), mToolBarShowTimer, SLOT(start())); + connect(mMuteButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start())); + } - positionHandles(); + positionHandles(); + } } UBGraphicsMediaItemDelegate::~UBGraphicsMediaItemDelegate() @@ -149,12 +152,12 @@ void UBGraphicsMediaItemDelegate::positionHandles() mToolBarItem->setRect(toolBarRect); } - int toolBarButtons= 0; + int toolBarButtonsWidth = 0; foreach (DelegateButton* button, mToolBarButtons) - toolBarButtons += button->boundingRect().width() + mToolBarItem->getElementsPadding(); + toolBarButtonsWidth += button->boundingRect().width() + mToolBarItem->getElementsPadding(); QRectF mediaItemRect = mMediaControl->rect(); - mediaItemRect.setWidth(mediaItem->boundingRect().width() - toolBarButtons); + mediaItemRect.setWidth(mediaItem->boundingRect().width() - toolBarButtonsWidth); mediaItemRect.setHeight(mToolBarItem->boundingRect().height()); mMediaControl->setRect(mediaItemRect); diff --git a/src/domain/UBGraphicsMediaItemDelegate.h b/src/domain/UBGraphicsMediaItemDelegate.h index 9ac65c93..5fe8038a 100644 --- a/src/domain/UBGraphicsMediaItemDelegate.h +++ b/src/domain/UBGraphicsMediaItemDelegate.h @@ -81,4 +81,4 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate int m_iToolBarShowingInterval; }; -#endif /* UBGRAPHICSMEDIAITEMDELEGATE_H_ */ \ No newline at end of file +#endif /* UBGRAPHICSMEDIAITEMDELEGATE_H_ */