@ -236,9 +236,7 @@ UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
QVariant UBGraphicsItemDelegate : : itemChange ( QGraphicsItem : : GraphicsItemChange change , const QVariant & value )
QVariant UBGraphicsItemDelegate : : itemChange ( QGraphicsItem : : GraphicsItemChange change , const QVariant & value )
{
{
if ( change = = QGraphicsItem : : ItemChildAddedChange ) {
if ( change = = QGraphicsItem : : ItemSelectedHasChanged ) {
} else if ( change = = QGraphicsItem : : ItemSelectedHasChanged ) {
bool ok ;
bool ok ;
bool selected = value . toUInt ( & ok ) ;
bool selected = value . toUInt ( & ok ) ;
if ( ok ) {
if ( ok ) {
@ -286,6 +284,8 @@ bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
{
mDragStartPosition = event - > pos ( ) ;
mDragStartPosition = event - > pos ( ) ;
mMoved = false ;
startUndoStep ( ) ;
startUndoStep ( ) ;
if ( ! delegated ( ) - > isSelected ( ) )
if ( ! delegated ( ) - > isSelected ( ) )
@ -315,6 +315,7 @@ bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
}
mDrag - > exec ( ) ;
mDrag - > exec ( ) ;
mDragPixmap = QPixmap ( ) ;
mDragPixmap = QPixmap ( ) ;
mMoved = true ;
return true ;
return true ;
}
}
return false ;
return false ;
@ -439,22 +440,9 @@ void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible)
void UBGraphicsItemDelegate : : remove ( bool canUndo )
void UBGraphicsItemDelegate : : remove ( bool canUndo )
{
{
/*UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mDelegated->scene());
if ( scene & & canUndo )
{
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( scene , mDelegated , 0 ) ;
UBApplication : : undoStack - > push ( uc ) ;
}
mDelegated - > hide ( ) ; */
UBGraphicsScene * scene = dynamic_cast < UBGraphicsScene * > ( mDelegated - > scene ( ) ) ;
UBGraphicsScene * scene = dynamic_cast < UBGraphicsScene * > ( mDelegated - > scene ( ) ) ;
if ( scene )
if ( scene )
{
{
// bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control;
// showHide(shownOnDisplay);
// updateFrame();
// updateButtons();
if ( mFrame & & ! mFrame - > scene ( ) & & mDelegated - > scene ( ) )
if ( mFrame & & ! mFrame - > scene ( ) & & mDelegated - > scene ( ) )
{
{
mDelegated - > scene ( ) - > addItem ( mFrame ) ;
mDelegated - > scene ( ) - > addItem ( mFrame ) ;
@ -734,7 +722,7 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated)
mDelegated - > scene ( ) - > addItem ( mDeleteButton ) ;
mDelegated - > scene ( ) - > addItem ( mDeleteButton ) ;
}
}
if ( showUpdated /*&& mFrame->isResizing()*/ )
if ( showUpdated )
mDeleteButton - > show ( ) ;
mDeleteButton - > show ( ) ;
int i = 1 , j = 0 , k = 0 ;
int i = 1 , j = 0 , k = 0 ;
@ -785,7 +773,6 @@ UBGraphicsToolBarItem::UBGraphicsToolBarItem(QGraphicsItem * parent) :
rect . setWidth ( parent - > boundingRect ( ) . width ( ) ) ;
rect . setWidth ( parent - > boundingRect ( ) . width ( ) ) ;
this - > setRect ( rect ) ;
this - > setRect ( rect ) ;
// setBrush(QColor(UBSettings::paletteColor));
setPen ( Qt : : NoPen ) ;
setPen ( Qt : : NoPen ) ;
hide ( ) ;
hide ( ) ;
@ -826,25 +813,29 @@ MediaTimer::MediaTimer(QGraphicsItem * parent): QGraphicsRectItem(parent)
{
{
val = 0 ;
val = 0 ;
smallPoint = false ;
smallPoint = false ;
setNumDigits ( 4 ) ;
setNumDigits ( 6 ) ;
}
}
MediaTimer : : ~ MediaTimer ( )
MediaTimer : : ~ MediaTimer ( )
{ }
{ }
void MediaTimer : : positionHandles ( )
{
digitSpace = smallPoint ? 2 : 1 ;
ySegLen = rect ( ) . height ( ) * 5 / 12 ;
xSegLen = ySegLen * 2 / 3 ;
segLen = xSegLen ;
xAdvance = segLen * ( 5 + digitSpace ) / 5 ;
xOffset = ( rect ( ) . width ( ) - ndigits * xAdvance + segLen / 5 ) / 2 ;
yOffset = rect ( ) . height ( ) - ySegLen * 2 ;
setRect ( rect ( ) . x ( ) , rect ( ) . y ( ) , xOffset + xAdvance * ndigits , rect ( ) . height ( ) ) ;
}
void MediaTimer : : drawString ( const QString & s , QPainter & p ,
void MediaTimer : : drawString ( const QString & s , QPainter & p ,
QBitArray * newPoints , bool newString )
QBitArray * newPoints , bool newString )
{
{
QPoint pos ;
QPoint pos ;
int digitSpace = smallPoint ? 2 : 1 ;
int xSegLen = ( rect ( ) . width ( ) / 1 ) * 5 / ( ndigits * ( 5 + digitSpace ) + digitSpace ) ;
int ySegLen = rect ( ) . height ( ) * 5 / 12 ;
int segLen = ySegLen > xSegLen ? xSegLen : ySegLen ;
int xAdvance = segLen * ( 5 + digitSpace ) / 5 ;
int xOffset = rect ( ) . x ( ) + ( rect ( ) . width ( ) / 1 - ndigits * xAdvance + segLen / 5 ) / 2 ;
int yOffset = ( rect ( ) . height ( ) - segLen * 2 ) / 2 ;
for ( int i = 0 ; i < ndigits ; i + + ) {
for ( int i = 0 ; i < ndigits ; i + + ) {
pos = QPoint ( xOffset + xAdvance * i , yOffset ) ;
pos = QPoint ( xOffset + xAdvance * i , yOffset ) ;
if ( newString )
if ( newString )
@ -1090,10 +1081,6 @@ void MediaTimer::paint(QPainter *p,
Q_UNUSED ( option ) ;
Q_UNUSED ( option ) ;
Q_UNUSED ( widget ) ;
Q_UNUSED ( widget ) ;
QFont f = p - > font ( ) ;
f . setPointSizeF ( f . pointSizeF ( ) ) ;
p - > setFont ( f ) ;
if ( smallPoint )
if ( smallPoint )
drawString ( digitStr , * p , & points , false ) ;
drawString ( digitStr , * p , & points , false ) ;
else
else
@ -1178,7 +1165,7 @@ void MediaTimer::setNumDigits(int numDigits)
numDigits = 0 ;
numDigits = 0 ;
}
}
if ( digitStr . isNull ( ) ) { // from constructor
if ( digitStr . isNull ( ) ) { // from constructor
ndigits = numDigits ;
ndigits = numDigits + numDigits / 2 - 1 ;
digitStr . fill ( QLatin1Char ( ' ' ) , ndigits ) ;
digitStr . fill ( QLatin1Char ( ' ' ) , ndigits ) ;
points . fill ( 0 , ndigits ) ;
points . fill ( 0 , ndigits ) ;
digitStr [ ndigits - 1 ] = QLatin1Char ( ' 0 ' ) ; // "0" is the default number
digitStr [ ndigits - 1 ] = QLatin1Char ( ' 0 ' ) ; // "0" is the default number
@ -1208,6 +1195,7 @@ void MediaTimer::setNumDigits(int numDigits)
ndigits = numDigits ;
ndigits = numDigits ;
update ( ) ;
update ( ) ;
}
}
positionHandles ( ) ;
}
}
DelegateMediaControl : : DelegateMediaControl ( UBGraphicsMediaItem * pDelegated , QGraphicsItem * parent )
DelegateMediaControl : : DelegateMediaControl ( UBGraphicsMediaItem * pDelegated , QGraphicsItem * parent )
@ -1238,13 +1226,6 @@ void DelegateMediaControl::paint(QPainter *painter,
QPainterPath path ;
QPainterPath path ;
mLCDTimerArea . setHeight ( rect ( ) . height ( ) ) ;
mLCDTimerArea . setWidth ( rect ( ) . height ( ) ) ;
mSeecArea . setWidth ( rect ( ) . width ( ) - mLCDTimerArea . width ( ) - 2 ) ;
mSeecArea . setHeight ( rect ( ) . height ( ) - 2 * mSeecAreaBorderHeight ) ;
mSeecArea . setY ( mSeecAreaBorderHeight ) ;
path . addRoundedRect ( mSeecArea , mSeecArea . height ( ) / 2 , mSeecArea . height ( ) / 2 ) ;
path . addRoundedRect ( mSeecArea , mSeecArea . height ( ) / 2 , mSeecArea . height ( ) / 2 ) ;
painter - > fillPath ( path , brush ( ) ) ;
painter - > fillPath ( path , brush ( ) ) ;
@ -1274,28 +1255,59 @@ QPainterPath DelegateMediaControl::shape() const
void DelegateMediaControl : : positionHandles ( )
void DelegateMediaControl : : positionHandles ( )
{
{
mLCDTimerArea . setWidth ( parentItem ( ) - > boundingRect ( ) . height ( ) ) ;
QRectF selfRect = rect ( ) ;
selfRect . setHeight ( parentItem ( ) - > boundingRect ( ) . height ( ) ) ;
setRect ( selfRect ) ;
QTime tTotal ;
tTotal = tTotal . addMSecs ( mTotalTimeInMs ) ;
mLCDTimerArea . setHeight ( parentItem ( ) - > boundingRect ( ) . height ( ) ) ;
mLCDTimerArea . setHeight ( parentItem ( ) - > boundingRect ( ) . height ( ) ) ;
int digitsCount = 2 ;
int timerWidth = mLCDTimerArea . height ( ) ;
mDisplayFormat = " ss " ;
if ( tTotal . minute ( ) > 0 )
{
mDisplayFormat = " mm: " + mDisplayFormat ;
digitsCount + = 3 ;
timerWidth + = mLCDTimerArea . height ( ) * 0.5 ;
}
if ( tTotal . hour ( ) > 0 )
{
mDisplayFormat = " hh: " + mDisplayFormat ;
digitsCount + = 3 ;
timerWidth + = mLCDTimerArea . height ( ) ;
}
lcdTimer - > setNumDigits ( digitsCount ) ;
mLCDTimerArea . setWidth ( timerWidth ) ;
lcdTimer - > setRect ( mLCDTimerArea ) ;
lcdTimer - > setRect ( mLCDTimerArea ) ;
lcdTimer - > setPos ( mSeecArea . width ( ) - mLCDTimerArea . width ( ) , 0 ) ;
// not the best solution, but it works.
lcdTimer - > positionHandles ( ) ;
mLCDTimerArea = lcdTimer - > rect ( ) ;
// -------------------------------------
lcdTimer - > setPos ( rect ( ) . width ( ) - mLCDTimerArea . width ( ) , 0 ) ;
mSeecAreaBorderHeight = rect ( ) . height ( ) / 20 ;
mSeecAreaBorderHeight = rect ( ) . height ( ) / 20 ;
mSeecArea . setWidth ( rect ( ) . width ( ) - mLCDTimerArea . width ( ) - 2 ) ;
mSeecArea . setWidth ( rect ( ) . width ( ) - mLCDTimerArea . width ( ) - 2 ) ;
mSeecArea . setHeight ( rect ( ) . height ( ) - 2 * mSeecAreaBorderHeight ) ;
mSeecArea . setHeight ( rect ( ) . height ( ) - 2 * mSeecAreaBorderHeight ) ;
mSeecArea . setY ( mSeecAreaBorderHeight ) ;
mSeecArea . setY ( mSeecAreaBorderHeight ) ;
QRectF selfRect = rect ( ) ;
selfRect . setHeight ( parentItem ( ) - > boundingRect ( ) . height ( ) ) ;
setRect ( selfRect ) ;
lcdTimer - > setPos ( rect ( ) . width ( ) - mLCDTimerArea . width ( ) , 0 ) ;
}
}
void DelegateMediaControl : : update ( )
void DelegateMediaControl : : update ( )
{
{
QTime t ;
QTime tCurrent ;
t = t . addMSecs ( mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs ) ;
tCurrent = tCurrent . addMSecs ( mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs ) ;
lcdTimer - > display ( t . toString ( " m:ss " ) ) ;
lcdTimer - > display ( tCurrent . toString ( mDisplayFormat ) ) ;
QGraphicsRectItem : : update ( ) ;
QGraphicsRectItem : : update ( ) ;
}
}
@ -1309,8 +1321,12 @@ void DelegateMediaControl::updateTicker(qint64 time )
void DelegateMediaControl : : totalTimeChanged ( qint64 newTotalTime )
void DelegateMediaControl : : totalTimeChanged ( qint64 newTotalTime )
{
{
if ( mTotalTimeInMs ! = newTotalTime )
{
mTotalTimeInMs = newTotalTime ;
mTotalTimeInMs = newTotalTime ;
positionHandles ( ) ;
update ( ) ;
update ( ) ;
}
}
}
@ -1347,7 +1363,7 @@ void DelegateMediaControl::seekToMousePos(QPointF mousePos)
qreal frameWidth = rect ( ) . height ( ) / 2 ;
qreal frameWidth = rect ( ) . height ( ) / 2 ;
minX = frameWidth ;
minX = frameWidth ;
length = mSeecArea . width ( ) - lcdTimer - > rect ( ) . width ( ) ;
length = mSeecArea . width ( ) - mSeecArea . height ( ) ;
qreal mouseX = mousePos . x ( ) ;
qreal mouseX = mousePos . x ( ) ;
if ( mouseX > = ( mSeecArea . width ( ) - mSeecArea . height ( ) / 2 ) )
if ( mouseX > = ( mSeecArea . width ( ) - mSeecArea . height ( ) / 2 ) )