parent
7ee53b07ad
commit
50a237306f
File diff suppressed because it is too large
Load Diff
@ -1,336 +1,351 @@ |
|||||||
/*
|
/*
|
||||||
* This program is free software: you can redistribute it and/or modify |
* This program is free software: you can redistribute it and/or modify |
||||||
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
||||||
* the Free Software Foundation, either version 3 of the License, or |
* the Free Software Foundation, either version 3 of the License, or |
||||||
* (at your option) any later version. |
* (at your option) any later version. |
||||||
* |
* |
||||||
* This program is distributed in the hope that it will be useful, |
* This program is distributed in the hope that it will be useful, |
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
* GNU General Public License for more details. |
* GNU General Public License for more details. |
||||||
* |
* |
||||||
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/ |
*/ |
||||||
|
|
||||||
#include <QtGui> |
#include <QtGui> |
||||||
#include <QtSvg> |
#include <QtSvg> |
||||||
|
|
||||||
#include "UBGraphicsVideoItemDelegate.h" |
#include "UBGraphicsVideoItemDelegate.h" |
||||||
|
|
||||||
#include "UBGraphicsScene.h" |
#include "UBGraphicsScene.h" |
||||||
|
|
||||||
#include "core/UBSettings.h" |
#include "core/UBSettings.h" |
||||||
#include "core/UBApplication.h" |
#include "core/UBApplication.h" |
||||||
#include "core/UBApplicationController.h" |
#include "core/UBApplicationController.h" |
||||||
#include "core/UBDisplayManager.h" |
#include "core/UBDisplayManager.h" |
||||||
|
|
||||||
#include "domain/UBGraphicsVideoItem.h" |
#include "domain/UBGraphicsVideoItem.h" |
||||||
#include "domain/UBGraphicsDelegateFrame.h" |
#include "domain/UBGraphicsDelegateFrame.h" |
||||||
|
|
||||||
#include "core/memcheck.h" |
#include "core/memcheck.h" |
||||||
|
|
||||||
UBGraphicsVideoItemDelegate::UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent) |
UBGraphicsVideoItemDelegate::UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent) |
||||||
: UBGraphicsItemDelegate(pDelegated, parent, true, false) |
: UBGraphicsItemDelegate(pDelegated, parent, true, false) |
||||||
, mMedia(pMedia) |
, mMedia(pMedia) |
||||||
{ |
{ |
||||||
// NOOP
|
// NOOP
|
||||||
} |
} |
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::buildButtons() |
void UBGraphicsVideoItemDelegate::buildButtons() |
||||||
{ |
{ |
||||||
mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mFrame); |
mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
||||||
|
|
||||||
mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mFrame); |
mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
||||||
mStopButton->hide(); |
|
||||||
|
mVideoControl = new DelegateVideoControl(delegated(), mToolBarItem); |
||||||
if (delegated()->isMuted()) |
UBGraphicsItem::assignZValue(mVideoControl, delegated()->zValue()); |
||||||
mMuteButton = new DelegateButton(":/images/soundOff.svg", mDelegated, mFrame); |
mVideoControl->setFlag(QGraphicsItem::ItemIsSelectable, true); |
||||||
else |
|
||||||
mMuteButton = new DelegateButton(":/images/soundOn.svg", mDelegated, mFrame); |
if (delegated()->isMuted()) |
||||||
|
mMuteButton = new DelegateButton(":/images/soundOff.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
||||||
mMuteButton->hide(); |
else |
||||||
|
mMuteButton = new DelegateButton(":/images/soundOn.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
||||||
mVideoControl = new DelegateVideoControl(delegated(), mFrame); |
|
||||||
UBGraphicsItem::assignZValue(mVideoControl, delegated()->zValue()); |
connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause())); |
||||||
mVideoControl->setFlag(QGraphicsItem::ItemIsSelectable, true); |
connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop())); |
||||||
|
connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute())); |
||||||
connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause())); |
connect(mMuteButton, SIGNAL(clicked(bool)), this, SLOT(toggleMute())); |
||||||
connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop())); |
|
||||||
connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute())); |
mButtons << mPlayPauseButton << mStopButton << mMuteButton; |
||||||
connect(mMuteButton, SIGNAL(clicked(bool)), this, SLOT(toggleMute())); |
|
||||||
|
QList<QGraphicsItem*> itemsOnToolBar; |
||||||
mButtons << mPlayPauseButton << mStopButton << mMuteButton; |
itemsOnToolBar << mPlayPauseButton << mStopButton << mVideoControl << mMuteButton; |
||||||
|
mToolBarItem->setItemsOnToolBar(itemsOnToolBar); |
||||||
mMedia->setTickInterval(50); |
|
||||||
|
mMedia->setTickInterval(50); |
||||||
connect(mMedia, SIGNAL(stateChanged (Phonon::State, Phonon::State)), this, SLOT(mediaStateChanged (Phonon::State, Phonon::State))); |
|
||||||
connect(mMedia, SIGNAL(finished()), this, SLOT(updatePlayPauseState())); |
connect(mMedia, SIGNAL(stateChanged (Phonon::State, Phonon::State)), this, SLOT(mediaStateChanged (Phonon::State, Phonon::State))); |
||||||
connect(mMedia, SIGNAL(tick(qint64)), this, SLOT(updateTicker(qint64))); |
connect(mMedia, SIGNAL(finished()), this, SLOT(updatePlayPauseState())); |
||||||
connect(mMedia, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64))); |
connect(mMedia, SIGNAL(tick(qint64)), this, SLOT(updateTicker(qint64))); |
||||||
|
connect(mMedia, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64))); |
||||||
} |
|
||||||
|
mToolBarItem->setVisibleOnBoard(true); |
||||||
|
mToolBarItem->setShifting(false); |
||||||
UBGraphicsVideoItemDelegate::~UBGraphicsVideoItemDelegate() |
} |
||||||
{ |
|
||||||
//NOOP
|
|
||||||
} |
UBGraphicsVideoItemDelegate::~UBGraphicsVideoItemDelegate() |
||||||
|
{ |
||||||
|
//NOOP
|
||||||
void UBGraphicsVideoItemDelegate::positionHandles() |
} |
||||||
{ |
|
||||||
UBGraphicsItemDelegate::positionHandles(); |
|
||||||
|
void UBGraphicsVideoItemDelegate::positionHandles() |
||||||
if (mDelegated->isSelected()) |
{ |
||||||
{ |
UBGraphicsItemDelegate::positionHandles(); |
||||||
qreal scaledFrameWidth = mFrameWidth * mAntiScaleRatio; |
|
||||||
|
if (mDelegated->isSelected()) |
||||||
|
{ |
||||||
qreal width = mFrame->rect().width(); |
qreal scaledFrameWidth = mFrameWidth * mAntiScaleRatio; |
||||||
qreal height = mFrame->rect().height(); |
|
||||||
|
int offset = 0; |
||||||
qreal x = mFrame->rect().left(); |
foreach (DelegateButton* button, mButtons) |
||||||
qreal y = mFrame->rect().top(); |
{ |
||||||
|
if (button->getSection() == Qt::TitleBarArea) |
||||||
mVideoControl->setRect(x + 2 * scaledFrameWidth |
offset += button->boundingRect().width() * mAntiScaleRatio; |
||||||
, y + height - 3 * scaledFrameWidth |
} |
||||||
, width - 4 * scaledFrameWidth |
|
||||||
, 2 * scaledFrameWidth); |
mVideoControl->setRect(mVideoControl->rect().x() |
||||||
|
, scaledFrameWidth/6 - 0.5 |
||||||
if (!mVideoControl->scene()) |
, (mToolBarItem->rect().width() - 35 - offset) / mAntiScaleRatio
|
||||||
{ |
, (2 * scaledFrameWidth) / mAntiScaleRatio); |
||||||
mVideoControl->setParentItem(mFrame);//update parent for the case the item has been previously removed from scene
|
|
||||||
mDelegated->scene()->addItem(mVideoControl); |
offset += (mVideoControl->rect().width() + 5) * mAntiScaleRatio; |
||||||
} |
mMuteButton->setPos(offset, 0); |
||||||
|
|
||||||
mVideoControl->setAntiScale(mAntiScaleRatio); |
if (!mVideoControl->scene()) |
||||||
mVideoControl->setZValue(delegated()->zValue()); |
{ |
||||||
mVideoControl->show(); |
mVideoControl->setParentItem(mToolBarItem);//update parent for the case the item has been previously removed from scene
|
||||||
} |
mDelegated->scene()->addItem(mVideoControl); |
||||||
else |
} |
||||||
{ |
|
||||||
mVideoControl->hide(); |
mVideoControl->setAntiScale(mAntiScaleRatio); |
||||||
} |
mVideoControl->setZValue(delegated()->zValue()); |
||||||
} |
mVideoControl->show(); |
||||||
|
} |
||||||
|
else |
||||||
void UBGraphicsVideoItemDelegate::remove(bool canUndo) |
{ |
||||||
{ |
mVideoControl->hide(); |
||||||
if (delegated() && delegated()->mediaObject()) |
} |
||||||
delegated()->mediaObject()->stop(); |
} |
||||||
|
|
||||||
QGraphicsScene* scene = mDelegated->scene(); |
|
||||||
|
void UBGraphicsVideoItemDelegate::remove(bool canUndo) |
||||||
scene->removeItem(mVideoControl); |
{ |
||||||
|
if (delegated() && delegated()->mediaObject()) |
||||||
UBGraphicsItemDelegate::remove(canUndo); |
delegated()->mediaObject()->stop(); |
||||||
} |
|
||||||
|
QGraphicsScene* scene = mDelegated->scene(); |
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::toggleMute() |
scene->removeItem(mVideoControl); |
||||||
{ |
|
||||||
if (delegated()->isMuted()) |
UBGraphicsItemDelegate::remove(canUndo); |
||||||
mMuteButton->setFileName(":/images/soundOff.svg"); |
} |
||||||
else |
|
||||||
mMuteButton->setFileName(":/images/soundOn.svg"); |
|
||||||
|
void UBGraphicsVideoItemDelegate::toggleMute() |
||||||
} |
{ |
||||||
|
if (delegated()->isMuted()) |
||||||
|
mMuteButton->setFileName(":/images/soundOff.svg"); |
||||||
UBGraphicsVideoItem* UBGraphicsVideoItemDelegate::delegated() |
else |
||||||
{ |
mMuteButton->setFileName(":/images/soundOn.svg"); |
||||||
return static_cast<UBGraphicsVideoItem*>(mDelegated); |
|
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::togglePlayPause() |
UBGraphicsVideoItem* UBGraphicsVideoItemDelegate::delegated() |
||||||
{ |
{ |
||||||
if (delegated() && delegated()->mediaObject()) { |
return static_cast<UBGraphicsVideoItem*>(mDelegated); |
||||||
|
} |
||||||
Phonon::MediaObject* media = delegated()->mediaObject(); |
|
||||||
if (media->state() == Phonon::StoppedState) { |
|
||||||
media->play(); |
void UBGraphicsVideoItemDelegate::togglePlayPause() |
||||||
} else if (media->state() == Phonon::PlayingState) { |
{ |
||||||
if (media->remainingTime() <= 0) { |
if (delegated() && delegated()->mediaObject()) { |
||||||
media->stop(); |
|
||||||
media->play(); |
Phonon::MediaObject* media = delegated()->mediaObject(); |
||||||
} else { |
if (media->state() == Phonon::StoppedState) { |
||||||
media->pause(); |
media->play(); |
||||||
if(delegated()->scene()) |
} else if (media->state() == Phonon::PlayingState) { |
||||||
delegated()->scene()->setModified(true); |
if (media->remainingTime() <= 0) { |
||||||
} |
media->stop(); |
||||||
} else if (media->state() == Phonon::PausedState) { |
media->play(); |
||||||
if (media->remainingTime() <= 0) { |
} else { |
||||||
media->stop(); |
media->pause(); |
||||||
} |
if(delegated()->scene()) |
||||||
media->play(); |
delegated()->scene()->setModified(true); |
||||||
} else if ( media->state() == Phonon::LoadingState ) { |
} |
||||||
delegated()->mediaObject()->setCurrentSource(delegated()->mediaFileUrl()); |
} else if (media->state() == Phonon::PausedState) { |
||||||
media->play(); |
if (media->remainingTime() <= 0) { |
||||||
} else if (media->state() == Phonon::ErrorState){ |
media->stop(); |
||||||
qDebug() << "Error appeared." << media->errorString(); |
} |
||||||
} |
media->play(); |
||||||
} |
} else if ( media->state() == Phonon::LoadingState ) { |
||||||
} |
delegated()->mediaObject()->setCurrentSource(delegated()->mediaFileUrl()); |
||||||
|
media->play(); |
||||||
void UBGraphicsVideoItemDelegate::mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate ) |
} else if (media->state() == Phonon::ErrorState){ |
||||||
{ |
qDebug() << "Error appeared." << media->errorString(); |
||||||
Q_UNUSED(newstate); |
} |
||||||
Q_UNUSED(oldstate); |
} |
||||||
updatePlayPauseState(); |
} |
||||||
} |
|
||||||
|
void UBGraphicsVideoItemDelegate::mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate ) |
||||||
|
{ |
||||||
void UBGraphicsVideoItemDelegate::updatePlayPauseState() |
Q_UNUSED(newstate); |
||||||
{ |
Q_UNUSED(oldstate); |
||||||
Phonon::MediaObject* media = delegated()->mediaObject(); |
updatePlayPauseState(); |
||||||
|
} |
||||||
if (media->state() == Phonon::PlayingState) |
|
||||||
mPlayPauseButton->setFileName(":/images/pause.svg"); |
|
||||||
else |
void UBGraphicsVideoItemDelegate::updatePlayPauseState() |
||||||
mPlayPauseButton->setFileName(":/images/play.svg"); |
{ |
||||||
} |
Phonon::MediaObject* media = delegated()->mediaObject(); |
||||||
|
|
||||||
|
if (media->state() == Phonon::PlayingState) |
||||||
void UBGraphicsVideoItemDelegate::updateTicker(qint64 time) |
mPlayPauseButton->setFileName(":/images/pause.svg"); |
||||||
{ |
else |
||||||
Phonon::MediaObject* media = delegated()->mediaObject(); |
mPlayPauseButton->setFileName(":/images/play.svg"); |
||||||
mVideoControl->totalTimeChanged(media->totalTime()); |
} |
||||||
|
|
||||||
mVideoControl->updateTicker(time); |
|
||||||
} |
void UBGraphicsVideoItemDelegate::updateTicker(qint64 time) |
||||||
|
{ |
||||||
|
Phonon::MediaObject* media = delegated()->mediaObject(); |
||||||
void UBGraphicsVideoItemDelegate::totalTimeChanged(qint64 newTotalTime) |
mVideoControl->totalTimeChanged(media->totalTime()); |
||||||
{ |
|
||||||
mVideoControl->totalTimeChanged(newTotalTime); |
mVideoControl->updateTicker(time); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
DelegateVideoControl::DelegateVideoControl(UBGraphicsVideoItem* pDelegated, QGraphicsItem * parent) |
void UBGraphicsVideoItemDelegate::totalTimeChanged(qint64 newTotalTime) |
||||||
: QGraphicsRectItem(parent) |
{ |
||||||
, mDelegate(pDelegated) |
mVideoControl->totalTimeChanged(newTotalTime); |
||||||
, mDisplayCurrentTime(false) |
} |
||||||
, mAntiScale(1.0) |
|
||||||
, mCurrentTimeInMs(0) |
|
||||||
, mTotalTimeInMs(0) |
DelegateVideoControl::DelegateVideoControl(UBGraphicsVideoItem* pDelegated, QGraphicsItem * parent) |
||||||
{ |
: QGraphicsRectItem(parent) |
||||||
setAcceptedMouseButtons(Qt::LeftButton); |
, mDelegate(pDelegated) |
||||||
|
, mDisplayCurrentTime(false) |
||||||
setBrush(QBrush(UBSettings::paletteColor)); |
, mAntiScale(1.0) |
||||||
setPen(Qt::NoPen); |
, mCurrentTimeInMs(0) |
||||||
setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); |
, mTotalTimeInMs(0) |
||||||
} |
, mStartWidth(200) |
||||||
|
{ |
||||||
|
setAcceptedMouseButtons(Qt::LeftButton); |
||||||
void DelegateVideoControl::paint(QPainter *painter, |
|
||||||
const QStyleOptionGraphicsItem *option, QWidget *widget) |
setBrush(QBrush(Qt::white)); |
||||||
{ |
setPen(Qt::NoPen); |
||||||
Q_UNUSED(option); |
setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); |
||||||
Q_UNUSED(widget); |
|
||||||
|
QRectF rect = this->rect(); |
||||||
painter->fillPath(shape(), brush()); |
rect.setWidth(mStartWidth); |
||||||
|
this->setRect(rect); |
||||||
qreal frameWidth = rect().height() / 2; |
} |
||||||
int position = frameWidth; |
|
||||||
|
|
||||||
if (mTotalTimeInMs > 0) |
void DelegateVideoControl::paint(QPainter *painter, |
||||||
{ |
const QStyleOptionGraphicsItem *option, QWidget *widget) |
||||||
position = frameWidth + (rect().width() - (2 * frameWidth)) / mTotalTimeInMs * mCurrentTimeInMs; |
{ |
||||||
} |
Q_UNUSED(option); |
||||||
|
Q_UNUSED(widget); |
||||||
int radius = rect().height() / 6; |
|
||||||
QRectF r(rect().x() + position - radius, rect().y() + (rect().height() / 4) - radius, radius * 2, radius * 2); |
painter->fillPath(shape(), brush()); |
||||||
|
|
||||||
painter->setBrush(UBSettings::documentViewLightColor); |
qreal frameWidth = rect().height() / 2; |
||||||
painter->drawEllipse(r); |
int position = frameWidth; |
||||||
|
|
||||||
if(mDisplayCurrentTime) |
if (mTotalTimeInMs > 0) |
||||||
{ |
{ |
||||||
painter->setBrush(UBSettings::paletteColor); |
position = frameWidth + (rect().width() - (2 * frameWidth)) / mTotalTimeInMs * mCurrentTimeInMs; |
||||||
painter->setPen(QPen(Qt::NoPen)); |
} |
||||||
QRectF balloon(rect().x() + position - frameWidth, rect().y() - (frameWidth * 1.2), 2 * frameWidth, frameWidth); |
|
||||||
painter->drawRoundedRect(balloon, frameWidth/2, frameWidth/2); |
int radius = rect().height() / 6; |
||||||
|
QRectF r(rect().x() + position - radius, rect().y() + (rect().height() / 4) - radius, radius * 2, radius * 2); |
||||||
QTime t; |
|
||||||
t = t.addMSecs(mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs); |
painter->setBrush(UBSettings::documentViewLightColor); |
||||||
QFont f = painter->font(); |
painter->drawEllipse(r); |
||||||
f.setPointSizeF(f.pointSizeF() * mAntiScale); |
|
||||||
painter->setFont(f); |
if(mDisplayCurrentTime) |
||||||
painter->setPen(Qt::white); |
{ |
||||||
painter->drawText(balloon, Qt::AlignCenter, t.toString("m:ss")); |
painter->setBrush(UBSettings::paletteColor); |
||||||
} |
painter->setPen(QPen(Qt::NoPen)); |
||||||
} |
mBalloon.setRect(rect().x() + position - frameWidth, rect().y() - (frameWidth * 1.2), 2 * frameWidth, frameWidth); |
||||||
|
painter->drawRoundedRect(mBalloon, frameWidth/2, frameWidth/2); |
||||||
|
|
||||||
QPainterPath DelegateVideoControl::shape() const |
QTime t; |
||||||
{ |
t = t.addMSecs(mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs); |
||||||
QPainterPath path; |
QFont f = painter->font(); |
||||||
QRectF r = rect().adjusted(0,0,0,- rect().height() / 2); |
f.setPointSizeF(f.pointSizeF() * mAntiScale); |
||||||
path.addRoundedRect(r, rect().height() / 4, rect().height() / 4); |
painter->setFont(f); |
||||||
return path; |
painter->setPen(Qt::white); |
||||||
} |
painter->drawText(mBalloon, Qt::AlignCenter, t.toString("m:ss")); |
||||||
|
} |
||||||
|
} |
||||||
void DelegateVideoControl::updateTicker(qint64 time ) |
|
||||||
{ |
|
||||||
mCurrentTimeInMs = time; |
QPainterPath DelegateVideoControl::shape() const |
||||||
update(); |
{ |
||||||
} |
QPainterPath path; |
||||||
|
QRectF r = rect().adjusted(0,0,0,- rect().height() / 2); |
||||||
|
path.addRoundedRect(r, rect().height() / 4, rect().height() / 4); |
||||||
void DelegateVideoControl::totalTimeChanged(qint64 newTotalTime) |
return path; |
||||||
{ |
} |
||||||
mTotalTimeInMs = newTotalTime; |
|
||||||
update(); |
|
||||||
} |
void DelegateVideoControl::updateTicker(qint64 time ) |
||||||
|
{ |
||||||
|
mCurrentTimeInMs = time; |
||||||
void DelegateVideoControl::mousePressEvent(QGraphicsSceneMouseEvent *event) |
update(); |
||||||
{ |
} |
||||||
mDisplayCurrentTime = true; |
|
||||||
seekToMousePos(event->pos()); |
|
||||||
update(); |
void DelegateVideoControl::totalTimeChanged(qint64 newTotalTime) |
||||||
event->accept(); |
{ |
||||||
} |
mTotalTimeInMs = newTotalTime; |
||||||
|
update(); |
||||||
|
} |
||||||
void DelegateVideoControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
||||||
{ |
|
||||||
seekToMousePos(event->pos()); |
void DelegateVideoControl::mousePressEvent(QGraphicsSceneMouseEvent *event) |
||||||
update(); |
{ |
||||||
event->accept(); |
mDisplayCurrentTime = true; |
||||||
} |
seekToMousePos(event->pos()); |
||||||
|
update(); |
||||||
|
event->accept(); |
||||||
void DelegateVideoControl::seekToMousePos(QPointF mousePos) |
} |
||||||
{ |
|
||||||
qreal minX, length; |
|
||||||
qreal frameWidth = rect().height() / 2; |
void DelegateVideoControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
||||||
|
{ |
||||||
minX = rect().x() + frameWidth; |
if (shape().contains(event->pos() - QPointF(mBalloon.width()/2,0))
|
||||||
length = rect().width() - (2 * frameWidth); |
&& shape().contains(event->pos() + QPointF(mBalloon.width()/2,0))) |
||||||
|
{
|
||||||
qreal mouseX = mousePos.x(); |
seekToMousePos(event->pos()); |
||||||
|
update(); |
||||||
if (mTotalTimeInMs > 0 && length > 0 && mDelegate |
event->accept(); |
||||||
&& mDelegate->mediaObject() && mDelegate->mediaObject()->isSeekable()) |
} |
||||||
{ |
} |
||||||
qint64 tickPos = mTotalTimeInMs / length * (mouseX - minX); |
|
||||||
mDelegate->mediaObject()->seek(tickPos); |
|
||||||
|
void DelegateVideoControl::seekToMousePos(QPointF mousePos) |
||||||
//OSX is a bit lazy
|
{ |
||||||
updateTicker(tickPos); |
qreal minX, length; |
||||||
} |
qreal frameWidth = rect().height() / 2; |
||||||
} |
|
||||||
|
minX = rect().x() + frameWidth; |
||||||
void DelegateVideoControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
length = rect().width() - (2 * frameWidth); |
||||||
{ |
|
||||||
mDisplayCurrentTime = false; |
qreal mouseX = mousePos.x(); |
||||||
update(); |
|
||||||
event->accept(); |
if (mTotalTimeInMs > 0 && length > 0 && mDelegate |
||||||
} |
&& mDelegate->mediaObject() && mDelegate->mediaObject()->isSeekable()) |
||||||
|
{ |
||||||
|
qint64 tickPos = mTotalTimeInMs / length * (mouseX - minX); |
||||||
|
mDelegate->mediaObject()->seek(tickPos); |
||||||
|
|
||||||
|
//OSX is a bit lazy
|
||||||
|
updateTicker(tickPos); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void DelegateVideoControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
||||||
|
{ |
||||||
|
mDisplayCurrentTime = false; |
||||||
|
update(); |
||||||
|
event->accept(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,114 +1,116 @@ |
|||||||
/*
|
/*
|
||||||
* This program is free software: you can redistribute it and/or modify |
* This program is free software: you can redistribute it and/or modify |
||||||
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
||||||
* the Free Software Foundation, either version 3 of the License, or |
* the Free Software Foundation, either version 3 of the License, or |
||||||
* (at your option) any later version. |
* (at your option) any later version. |
||||||
* |
* |
||||||
* This program is distributed in the hope that it will be useful, |
* This program is distributed in the hope that it will be useful, |
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
* GNU General Public License for more details. |
* GNU General Public License for more details. |
||||||
* |
* |
||||||
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/ |
*/ |
||||||
|
|
||||||
#ifndef UBGRAPHICSVIDEOITEMDELEGATE_H_ |
#ifndef UBGRAPHICSVIDEOITEMDELEGATE_H_ |
||||||
#define UBGRAPHICSVIDEOITEMDELEGATE_H_ |
#define UBGRAPHICSVIDEOITEMDELEGATE_H_ |
||||||
|
|
||||||
#include <QtGui> |
#include <QtGui> |
||||||
#include <phonon/MediaObject> |
#include <phonon/MediaObject> |
||||||
|
|
||||||
#include "core/UB.h" |
#include "core/UB.h" |
||||||
#include "UBGraphicsItemDelegate.h" |
#include "UBGraphicsItemDelegate.h" |
||||||
|
|
||||||
class QGraphicsSceneMouseEvent; |
class QGraphicsSceneMouseEvent; |
||||||
class QGraphicsItem; |
class QGraphicsItem; |
||||||
class UBGraphicsVideoItem; |
class UBGraphicsVideoItem; |
||||||
|
|
||||||
class DelegateVideoControl: public QGraphicsRectItem |
class DelegateVideoControl: public QGraphicsRectItem |
||||||
{ |
{ |
||||||
public: |
public: |
||||||
|
|
||||||
DelegateVideoControl(UBGraphicsVideoItem* pDelegated, QGraphicsItem * parent = 0); |
DelegateVideoControl(UBGraphicsVideoItem* pDelegated, QGraphicsItem * parent = 0); |
||||||
|
|
||||||
virtual ~DelegateVideoControl() |
virtual ~DelegateVideoControl() |
||||||
{ |
{ |
||||||
// NOOP
|
// NOOP
|
||||||
} |
} |
||||||
|
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
||||||
QWidget *widget); |
QWidget *widget); |
||||||
|
|
||||||
QPainterPath shape() const; |
QPainterPath shape() const; |
||||||
|
|
||||||
void setAntiScale(qreal antiScale){ mAntiScale = antiScale; } |
void setAntiScale(qreal antiScale){ mAntiScale = antiScale; } |
||||||
|
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); |
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); |
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); |
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); |
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
||||||
|
|
||||||
void updateTicker(qint64 time); |
void updateTicker(qint64 time); |
||||||
void totalTimeChanged( qint64 newTotalTime); |
void totalTimeChanged( qint64 newTotalTime); |
||||||
|
|
||||||
protected: |
protected: |
||||||
|
|
||||||
|
|
||||||
void seekToMousePos(QPointF mousePos); |
void seekToMousePos(QPointF mousePos); |
||||||
|
|
||||||
UBGraphicsVideoItem* mDelegate; |
UBGraphicsVideoItem* mDelegate; |
||||||
bool mDisplayCurrentTime; |
bool mDisplayCurrentTime; |
||||||
|
|
||||||
qreal mAntiScale; |
qreal mAntiScale; |
||||||
qint64 mCurrentTimeInMs; |
qint64 mCurrentTimeInMs; |
||||||
qint64 mTotalTimeInMs; |
qint64 mTotalTimeInMs; |
||||||
|
|
||||||
}; |
private: |
||||||
|
int mStartWidth; |
||||||
|
QRectF mBalloon; |
||||||
class UBGraphicsVideoItemDelegate : public UBGraphicsItemDelegate |
}; |
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
|
class UBGraphicsVideoItemDelegate : public UBGraphicsItemDelegate |
||||||
public: |
{ |
||||||
UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent = 0); |
Q_OBJECT |
||||||
virtual ~UBGraphicsVideoItemDelegate(); |
|
||||||
|
public: |
||||||
virtual void positionHandles(); |
UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent = 0); |
||||||
|
virtual ~UBGraphicsVideoItemDelegate(); |
||||||
public slots: |
|
||||||
|
virtual void positionHandles(); |
||||||
void toggleMute(); |
|
||||||
void updateTicker(qint64 time); |
public slots: |
||||||
|
|
||||||
protected slots: |
void toggleMute(); |
||||||
|
void updateTicker(qint64 time); |
||||||
virtual void remove(bool canUndo = true); |
|
||||||
|
protected slots: |
||||||
void togglePlayPause(); |
|
||||||
|
virtual void remove(bool canUndo = true); |
||||||
void mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate ); |
|
||||||
|
void togglePlayPause(); |
||||||
void updatePlayPauseState(); |
|
||||||
|
void mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate ); |
||||||
void totalTimeChanged( qint64 newTotalTime); |
|
||||||
|
void updatePlayPauseState(); |
||||||
protected: |
|
||||||
|
void totalTimeChanged( qint64 newTotalTime); |
||||||
virtual void buildButtons(); |
|
||||||
|
protected: |
||||||
private: |
|
||||||
|
virtual void buildButtons(); |
||||||
UBGraphicsVideoItem* delegated(); |
|
||||||
|
private: |
||||||
DelegateButton* mPlayPauseButton; |
|
||||||
DelegateButton* mStopButton; |
UBGraphicsVideoItem* delegated(); |
||||||
DelegateButton* mMuteButton; |
|
||||||
DelegateVideoControl *mVideoControl; |
DelegateButton* mPlayPauseButton; |
||||||
|
DelegateButton* mStopButton; |
||||||
Phonon::MediaObject* mMedia; |
DelegateButton* mMuteButton; |
||||||
|
DelegateVideoControl *mVideoControl; |
||||||
}; |
|
||||||
|
Phonon::MediaObject* mMedia; |
||||||
|
}; |
||||||
#endif /* UBGRAPHICSVIDEOITEMDELEGATE_H_ */ |
|
||||||
|
|
||||||
|
#endif /* UBGRAPHICSVIDEOITEMDELEGATE_H_ */ |
||||||
|
Loading…
Reference in new issue