SANKORE-613

Frame buttons
Part 1: changes in toolbars
preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent 62a82e1daa
commit 83212cc494
  1. 1596
      src/domain/UBGraphicsDelegateFrame.cpp
  2. 80
      src/domain/UBGraphicsItemDelegate.cpp
  3. 34
      src/domain/UBGraphicsItemDelegate.h
  4. 14
      src/domain/UBGraphicsTextItemDelegate.cpp
  5. 687
      src/domain/UBGraphicsVideoItemDelegate.cpp
  6. 230
      src/domain/UBGraphicsVideoItemDelegate.h

File diff suppressed because it is too large Load Diff

@ -37,6 +37,9 @@
#include "UBGraphicsWidgetItem.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsTextItem.h"
#include "domain/UBGraphicsAudioItem.h"
#include "domain/UBGraphicsVideoItem.h"
#include "web/UBWebController.h"
@ -93,6 +96,8 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec
void UBGraphicsItemDelegate::init()
{
mToolBarItem = new UBGraphicsToolBarItem(delegated());
mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio);
mFrame->hide();
mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true);
@ -123,10 +128,13 @@ void UBGraphicsItemDelegate::init()
foreach(DelegateButton* button, mButtons)
{
if (button->getSection() != Qt::TitleBarArea)
{
button->hide();
button->setFlag(QGraphicsItem::ItemIsSelectable, true);
}
}
}
UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
@ -292,13 +300,20 @@ void UBGraphicsItemDelegate::positionHandles()
updateButtons(true);
if (mToolBarItem->isVisibleOnBoard())
{
updateToolBar();
mToolBarItem->show();
}
} else {
foreach(DelegateButton* button, mButtons)
button->hide();
mFrame->hide();
mToolBarItem->hide();
}
}
void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible)
{
if (visible) {
@ -335,6 +350,7 @@ void UBGraphicsItemDelegate::remove(bool canUndo)
scene->removeItem(mFrame);
scene->removeItem(mDelegated);
scene->removeItem(mToolBarItem);
if (canUndo)
{
@ -577,14 +593,16 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated)
int i = 1, j = 0, k = 0;
while ((i + j + k) < mButtons.size()) {
DelegateButton* button = mButtons[i + j];
button->setParentItem(mFrame);
button->setTransform(tr);
if (button->getSection() == Qt::TopLeftSection) {
button->setParentItem(mFrame);
button->setPos(topX + (i++ * 1.6 * mFrameWidth * mAntiScaleRatio), topY);
button->setTransform(tr);
} else if (button->getSection() == Qt::BottomLeftSection) {
button->setParentItem(mFrame);
button->setPos(bottomX + (++j * 1.6 * mFrameWidth * mAntiScaleRatio), bottomY);
} else if (button->getSection() == Qt::NoSection) {
button->setTransform(tr);
} else if (button->getSection() == Qt::TitleBarArea || button->getSection() == Qt::NoSection){
++k;
}
if (!button->scene())
@ -599,9 +617,65 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated)
}
}
void UBGraphicsItemDelegate::updateToolBar()
{
QTransform transformForToolbarButtons;
transformForToolbarButtons.scale(mAntiScaleRatio, 1);
QRectF toolBarRect = mToolBarItem->rect();
toolBarRect.setWidth(delegated()->boundingRect().width() - 10);
mToolBarItem->setRect(toolBarRect);
if (mToolBarItem->isShifting())
mToolBarItem->setPos(delegated()->boundingRect().bottomLeft() + QPointF(5 * mAntiScaleRatio, 0));
else mToolBarItem->setPos(delegated()->boundingRect().bottomLeft() - QPointF(-5 * mAntiScaleRatio, mToolBarItem->rect().height() * 1.1 * mAntiScaleRatio));
int offsetOnToolBar = 5 * mAntiScaleRatio;
QList<QGraphicsItem*> itemList = mToolBarItem->itemsOnToolBar();
foreach (QGraphicsItem* item, itemList)
{
item->setPos(offsetOnToolBar, 0);
offsetOnToolBar += (item->boundingRect().width() + 5) * mAntiScaleRatio;
item->setTransform(transformForToolbarButtons);
item->show();
}
mToolBarItem->setOffsetOnToolBar(offsetOnToolBar);
QTransform tr;
tr.scale(1, mAntiScaleRatio);
mToolBarItem->setTransform(tr);
}
void UBGraphicsItemDelegate::setButtonsVisible(bool visible)
{
foreach(DelegateButton* pButton, mButtons){
pButton->setVisible(visible);
}
}
UBGraphicsToolBarItem::UBGraphicsToolBarItem(QGraphicsItem * parent) :
QGraphicsRectItem(parent),
mShifting(true),
mVisible(false),
mMinWidth(200)
{
QRectF rect = this->rect();
rect.setHeight(26);
this->setRect(rect);
setBrush(QColor(UBSettings::paletteColor));
setPen(Qt::NoPen);
hide();
}
void UBGraphicsToolBarItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QPainterPath path;
path.addRoundedRect(rect(), 10, 10);
painter->fillPath(path, brush());
}

@ -84,6 +84,31 @@ class DelegateButton: public QGraphicsSvgItem
};
class UBGraphicsToolBarItem : public QGraphicsRectItem, public QObject
{
public:
UBGraphicsToolBarItem(QGraphicsItem * parent = 0);
virtual ~UBGraphicsToolBarItem() {};
bool isVisibleOnBoard() const { return mVisible; }
void setVisibleOnBoard(bool visible) { mVisible = visible; }
bool isShifting() const { return mShifting; }
void setShifting(bool shifting) { mShifting = shifting; }
int offsetOnToolBar() const { return mOffsetOnToolBar; }
void setOffsetOnToolBar(int pOffset) { mOffsetOnToolBar = pOffset; }
QList<QGraphicsItem*> itemsOnToolBar() const { return mItemsOnToolBar; }
void setItemsOnToolBar(QList<QGraphicsItem*> itemsOnToolBar) { mItemsOnToolBar = itemsOnToolBar;}
int minWidth() { return mMinWidth; }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
private:
bool mShifting;
bool mVisible;
int mOffsetOnToolBar;
int mMinWidth;
QList<QGraphicsItem*> mItemsOnToolBar;
};
class UBGraphicsItemDelegate : public QObject
{
@ -138,6 +163,10 @@ class UBGraphicsItemDelegate : public QObject
void setButtonsVisible(bool visible);
UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; }
qreal antiScaleRatio() const { return mAntiScaleRatio; }
signals:
void showOnDisplayChanged(bool shown);
void lockChanged(bool locked);
@ -183,12 +212,17 @@ class UBGraphicsItemDelegate : public QObject
QList<DelegateButton*> mButtons;
UBGraphicsToolBarItem* mToolBarItem;
protected slots:
virtual void gotoContentSource(bool checked);
private:
void updateFrame();
void updateButtons(bool showUpdated = false);
void updateToolBar();
QPointF mOffset;
QTransform mPreviousTransform;

@ -94,17 +94,21 @@ void UBGraphicsTextItemDelegate::buildButtons()
{
UBGraphicsItemDelegate::buildButtons();
mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame, Qt::TopLeftSection);
mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mFrame, Qt::TopLeftSection);
mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::TopLeftSection);
mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame, Qt::TopLeftSection);
mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
connect(mFontButton, SIGNAL(clicked(bool)), this, SLOT(pickFont()));
connect(mColorButton, SIGNAL(clicked(bool)), this, SLOT(pickColor()));
connect(mDecreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(decreaseSize()));
connect(mIncreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(increaseSize()));
mButtons << mFontButton << mColorButton << mDecreaseSizeButton << mIncreaseSizeButton;
QList<QGraphicsItem*> itemsOnToolBar;
itemsOnToolBar << mFontButton << mColorButton << mDecreaseSizeButton << mIncreaseSizeButton;
mToolBarItem->setItemsOnToolBar(itemsOnToolBar);
mToolBarItem->setVisibleOnBoard(true);
}
void UBGraphicsTextItemDelegate::contentsChanged()

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

Loading…
Cancel
Save