SANKORE-613

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

@ -390,6 +390,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QSizeF newSize = resizableItem->size() + incVector; QSizeF newSize = resizableItem->size() + incVector;
if (!(mDelegate->getToolBarItem()->isVisibleOnBoard()
&& (newSize.width() < mDelegate->getToolBarItem()->minWidth() / mDelegate->antiScaleRatio()
|| newSize.height() < mDelegate->getToolBarItem()->minWidth() / mDelegate->antiScaleRatio() * 3/4)))
resizableItem->resize(newSize); resizableItem->resize(newSize);
} }
} }
@ -579,6 +582,11 @@ void UBGraphicsDelegateFrame::setVisible(bool visible)
void UBGraphicsDelegateFrame::positionHandles() void UBGraphicsDelegateFrame::positionHandles()
{ {
QRectF itemRect = delegated()->boundingRect(); QRectF itemRect = delegated()->boundingRect();
if (mDelegate->getToolBarItem()->isVisibleOnBoard()
&& mDelegate->getToolBarItem()->isShifting())
itemRect.setHeight(itemRect.height() + mDelegate->getToolBarItem()->rect().height() * mDelegate->antiScaleRatio() * 1.1);
QTransform itemTransform = delegated()->sceneTransform(); QTransform itemTransform = delegated()->sceneTransform();
QPointF topLeft = itemTransform.map(itemRect.topLeft()); QPointF topLeft = itemTransform.map(itemRect.topLeft());
QPointF topRight = itemTransform.map(itemRect.topRight()); QPointF topRight = itemTransform.map(itemRect.topRight());

@ -37,6 +37,9 @@
#include "UBGraphicsWidgetItem.h" #include "UBGraphicsWidgetItem.h"
#include "domain/UBAbstractWidget.h" #include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsTextItem.h"
#include "domain/UBGraphicsAudioItem.h"
#include "domain/UBGraphicsVideoItem.h"
#include "web/UBWebController.h" #include "web/UBWebController.h"
@ -93,6 +96,8 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec
void UBGraphicsItemDelegate::init() void UBGraphicsItemDelegate::init()
{ {
mToolBarItem = new UBGraphicsToolBarItem(delegated());
mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio);
mFrame->hide(); mFrame->hide();
mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true);
@ -122,11 +127,14 @@ void UBGraphicsItemDelegate::init()
buildButtons(); buildButtons();
foreach(DelegateButton* button, mButtons) foreach(DelegateButton* button, mButtons)
{
if (button->getSection() != Qt::TitleBarArea)
{ {
button->hide(); button->hide();
button->setFlag(QGraphicsItem::ItemIsSelectable, true); button->setFlag(QGraphicsItem::ItemIsSelectable, true);
} }
} }
}
UBGraphicsItemDelegate::~UBGraphicsItemDelegate() UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
@ -292,13 +300,20 @@ void UBGraphicsItemDelegate::positionHandles()
updateButtons(true); updateButtons(true);
if (mToolBarItem->isVisibleOnBoard())
{
updateToolBar();
mToolBarItem->show();
}
} else { } else {
foreach(DelegateButton* button, mButtons) foreach(DelegateButton* button, mButtons)
button->hide(); button->hide();
mFrame->hide(); mFrame->hide();
mToolBarItem->hide();
} }
} }
void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible) void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible)
{ {
if (visible) { if (visible) {
@ -335,6 +350,7 @@ void UBGraphicsItemDelegate::remove(bool canUndo)
scene->removeItem(mFrame); scene->removeItem(mFrame);
scene->removeItem(mDelegated); scene->removeItem(mDelegated);
scene->removeItem(mToolBarItem);
if (canUndo) if (canUndo)
{ {
@ -577,14 +593,16 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated)
int i = 1, j = 0, k = 0; int i = 1, j = 0, k = 0;
while ((i + j + k) < mButtons.size()) { while ((i + j + k) < mButtons.size()) {
DelegateButton* button = mButtons[i + j]; DelegateButton* button = mButtons[i + j];
button->setParentItem(mFrame);
button->setTransform(tr);
if (button->getSection() == Qt::TopLeftSection) { if (button->getSection() == Qt::TopLeftSection) {
button->setParentItem(mFrame);
button->setPos(topX + (i++ * 1.6 * mFrameWidth * mAntiScaleRatio), topY); button->setPos(topX + (i++ * 1.6 * mFrameWidth * mAntiScaleRatio), topY);
button->setTransform(tr);
} else if (button->getSection() == Qt::BottomLeftSection) { } else if (button->getSection() == Qt::BottomLeftSection) {
button->setParentItem(mFrame);
button->setPos(bottomX + (++j * 1.6 * mFrameWidth * mAntiScaleRatio), bottomY); 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; ++k;
} }
if (!button->scene()) 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) void UBGraphicsItemDelegate::setButtonsVisible(bool visible)
{ {
foreach(DelegateButton* pButton, mButtons){ foreach(DelegateButton* pButton, mButtons){
pButton->setVisible(visible); 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 class UBGraphicsItemDelegate : public QObject
{ {
@ -138,6 +163,10 @@ class UBGraphicsItemDelegate : public QObject
void setButtonsVisible(bool visible); void setButtonsVisible(bool visible);
UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; }
qreal antiScaleRatio() const { return mAntiScaleRatio; }
signals: signals:
void showOnDisplayChanged(bool shown); void showOnDisplayChanged(bool shown);
void lockChanged(bool locked); void lockChanged(bool locked);
@ -183,12 +212,17 @@ class UBGraphicsItemDelegate : public QObject
QList<DelegateButton*> mButtons; QList<DelegateButton*> mButtons;
UBGraphicsToolBarItem* mToolBarItem;
protected slots: protected slots:
virtual void gotoContentSource(bool checked); virtual void gotoContentSource(bool checked);
private: private:
void updateFrame(); void updateFrame();
void updateButtons(bool showUpdated = false); void updateButtons(bool showUpdated = false);
void updateToolBar();
QPointF mOffset; QPointF mOffset;
QTransform mPreviousTransform; QTransform mPreviousTransform;

@ -94,17 +94,21 @@ void UBGraphicsTextItemDelegate::buildButtons()
{ {
UBGraphicsItemDelegate::buildButtons(); UBGraphicsItemDelegate::buildButtons();
mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame, Qt::TopLeftSection); mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mFrame, Qt::TopLeftSection); mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::TopLeftSection); mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame, Qt::TopLeftSection); mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
connect(mFontButton, SIGNAL(clicked(bool)), this, SLOT(pickFont())); connect(mFontButton, SIGNAL(clicked(bool)), this, SLOT(pickFont()));
connect(mColorButton, SIGNAL(clicked(bool)), this, SLOT(pickColor())); connect(mColorButton, SIGNAL(clicked(bool)), this, SLOT(pickColor()));
connect(mDecreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(decreaseSize())); connect(mDecreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(decreaseSize()));
connect(mIncreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(increaseSize())); 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() void UBGraphicsTextItemDelegate::contentsChanged()

@ -39,22 +39,19 @@ UBGraphicsVideoItemDelegate::UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pD
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();
if (delegated()->isMuted()) mVideoControl = new DelegateVideoControl(delegated(), mToolBarItem);
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()); UBGraphicsItem::assignZValue(mVideoControl, delegated()->zValue());
mVideoControl->setFlag(QGraphicsItem::ItemIsSelectable, true); 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(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause()));
connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop())); connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop()));
connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute())); connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute()));
@ -62,6 +59,10 @@ void UBGraphicsVideoItemDelegate::buildButtons()
mButtons << mPlayPauseButton << mStopButton << mMuteButton; mButtons << mPlayPauseButton << mStopButton << mMuteButton;
QList<QGraphicsItem*> itemsOnToolBar;
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(stateChanged (Phonon::State, Phonon::State)), this, SLOT(mediaStateChanged (Phonon::State, Phonon::State)));
@ -69,6 +70,8 @@ void UBGraphicsVideoItemDelegate::buildButtons()
connect(mMedia, SIGNAL(tick(qint64)), this, SLOT(updateTicker(qint64))); connect(mMedia, SIGNAL(tick(qint64)), this, SLOT(updateTicker(qint64)));
connect(mMedia, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64))); connect(mMedia, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64)));
mToolBarItem->setVisibleOnBoard(true);
mToolBarItem->setShifting(false);
} }
@ -86,21 +89,24 @@ void UBGraphicsVideoItemDelegate::positionHandles()
{ {
qreal scaledFrameWidth = mFrameWidth * mAntiScaleRatio; qreal scaledFrameWidth = mFrameWidth * mAntiScaleRatio;
int offset = 0;
foreach (DelegateButton* button, mButtons)
{
if (button->getSection() == Qt::TitleBarArea)
offset += button->boundingRect().width() * mAntiScaleRatio;
}
qreal width = mFrame->rect().width(); mVideoControl->setRect(mVideoControl->rect().x()
qreal height = mFrame->rect().height(); , scaledFrameWidth/6 - 0.5
, (mToolBarItem->rect().width() - 35 - offset) / mAntiScaleRatio
qreal x = mFrame->rect().left(); , (2 * scaledFrameWidth) / mAntiScaleRatio);
qreal y = mFrame->rect().top();
mVideoControl->setRect(x + 2 * scaledFrameWidth offset += (mVideoControl->rect().width() + 5) * mAntiScaleRatio;
, y + height - 3 * scaledFrameWidth mMuteButton->setPos(offset, 0);
, width - 4 * scaledFrameWidth
, 2 * scaledFrameWidth);
if (!mVideoControl->scene()) if (!mVideoControl->scene())
{ {
mVideoControl->setParentItem(mFrame);//update parent for the case the item has been previously removed from scene mVideoControl->setParentItem(mToolBarItem);//update parent for the case the item has been previously removed from scene
mDelegated->scene()->addItem(mVideoControl); mDelegated->scene()->addItem(mVideoControl);
} }
@ -215,12 +221,17 @@ DelegateVideoControl::DelegateVideoControl(UBGraphicsVideoItem* pDelegated, QGra
, mAntiScale(1.0) , mAntiScale(1.0)
, mCurrentTimeInMs(0) , mCurrentTimeInMs(0)
, mTotalTimeInMs(0) , mTotalTimeInMs(0)
, mStartWidth(200)
{ {
setAcceptedMouseButtons(Qt::LeftButton); setAcceptedMouseButtons(Qt::LeftButton);
setBrush(QBrush(UBSettings::paletteColor)); setBrush(QBrush(Qt::white));
setPen(Qt::NoPen); setPen(Qt::NoPen);
setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
QRectF rect = this->rect();
rect.setWidth(mStartWidth);
this->setRect(rect);
} }
@ -250,8 +261,8 @@ void DelegateVideoControl::paint(QPainter *painter,
{ {
painter->setBrush(UBSettings::paletteColor); painter->setBrush(UBSettings::paletteColor);
painter->setPen(QPen(Qt::NoPen)); painter->setPen(QPen(Qt::NoPen));
QRectF balloon(rect().x() + position - frameWidth, rect().y() - (frameWidth * 1.2), 2 * frameWidth, frameWidth); mBalloon.setRect(rect().x() + position - frameWidth, rect().y() - (frameWidth * 1.2), 2 * frameWidth, frameWidth);
painter->drawRoundedRect(balloon, frameWidth/2, frameWidth/2); painter->drawRoundedRect(mBalloon, frameWidth/2, frameWidth/2);
QTime t; QTime t;
t = t.addMSecs(mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs); t = t.addMSecs(mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs);
@ -259,7 +270,7 @@ void DelegateVideoControl::paint(QPainter *painter,
f.setPointSizeF(f.pointSizeF() * mAntiScale); f.setPointSizeF(f.pointSizeF() * mAntiScale);
painter->setFont(f); painter->setFont(f);
painter->setPen(Qt::white); painter->setPen(Qt::white);
painter->drawText(balloon, Qt::AlignCenter, t.toString("m:ss")); painter->drawText(mBalloon, Qt::AlignCenter, t.toString("m:ss"));
} }
} }
@ -298,9 +309,13 @@ void DelegateVideoControl::mousePressEvent(QGraphicsSceneMouseEvent *event)
void DelegateVideoControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event) 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()); seekToMousePos(event->pos());
update(); update();
event->accept(); event->accept();
}
} }

@ -63,6 +63,9 @@ class DelegateVideoControl: public QGraphicsRectItem
qint64 mCurrentTimeInMs; qint64 mCurrentTimeInMs;
qint64 mTotalTimeInMs; qint64 mTotalTimeInMs;
private:
int mStartWidth;
QRectF mBalloon;
}; };
@ -107,7 +110,6 @@ class UBGraphicsVideoItemDelegate : public UBGraphicsItemDelegate
DelegateVideoControl *mVideoControl; DelegateVideoControl *mVideoControl;
Phonon::MediaObject* mMedia; Phonon::MediaObject* mMedia;
}; };

Loading…
Cancel
Save