Commit aa5755f5 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Abstract*Items: Merging code.

parent 75c19620
......@@ -47,6 +47,8 @@ AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( Clip* clip ) :
m_height( 0 ),
m_muted( false )
{
setFlags( QGraphicsItem::ItemIsSelectable );
m_clipHelper = new ClipHelper( clip );
// Adjust the width
setWidth( clip->length() );
......@@ -54,6 +56,7 @@ AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( Clip* clip ) :
connect( m_clipHelper, SIGNAL( lengthUpdated() ), this, SLOT( adjustLength() ) );
connect( clip, SIGNAL( unloaded( Clip* ) ),
this, SLOT( clipDestroyed( Clip* ) ), Qt::DirectConnection );
setAcceptHoverEvents( true );
}
AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( ClipHelper* ch ) :
......@@ -66,12 +69,14 @@ AbstractGraphicsMediaItem::AbstractGraphicsMediaItem( ClipHelper* ch ) :
m_height( 0 ),
m_muted( false )
{
setFlags( QGraphicsItem::ItemIsSelectable );
// Adjust the width
setWidth( ch->length() );
// Automatically adjust future changes
connect( ch, SIGNAL( lengthUpdated() ), this, SLOT( adjustLength() ) );
connect( ch->clip(), SIGNAL( unloaded( Clip* ) ),
this, SLOT( clipDestroyed( Clip* ) ), Qt::DirectConnection );
setAcceptHoverEvents( true );
}
AbstractGraphicsMediaItem::~AbstractGraphicsMediaItem()
......@@ -351,3 +356,63 @@ AbstractGraphicsMediaItem::setEmphasized( bool value )
else
setScale( 1.0 );
}
void
AbstractGraphicsMediaItem::hoverEnterEvent( QGraphicsSceneHoverEvent* event )
{
TracksView* tv = tracksView();
if ( tv )
{
switch ( tv->tool() )
{
case TOOL_DEFAULT:
setCursor( Qt::OpenHandCursor );
break;
case TOOL_CUT:
setCursor( QCursor( QPixmap( ":/images/editcut" ) ) );
break;
}
}
QGraphicsItem::hoverEnterEvent( event );
}
void
AbstractGraphicsMediaItem::hoverMoveEvent( QGraphicsSceneHoverEvent* event )
{
if ( !tracksView() ) return;
if ( tracksView()->tool() == TOOL_DEFAULT )
{
if ( resizeZone( event->pos() ) )
setCursor( Qt::SizeHorCursor );
else
setCursor( Qt::OpenHandCursor );
}
}
void
AbstractGraphicsMediaItem::mousePressEvent( QGraphicsSceneMouseEvent* event )
{
if ( !tracksView() ) return;
if ( tracksView()->tool() == TOOL_DEFAULT )
{
if ( resizeZone( event->pos() ) )
setCursor( Qt::SizeHorCursor );
else
setCursor( Qt::ClosedHandCursor );
}
else if ( tracksView()->tool() == TOOL_CUT )
emit split( this, qRound64( event->pos().x() ) );
}
void
AbstractGraphicsMediaItem::mouseReleaseEvent( QGraphicsSceneMouseEvent* event )
{
Q_UNUSED( event );
if ( !tracksView() ) return;
if ( tracksView()->tool() == TOOL_DEFAULT )
setCursor( Qt::OpenHandCursor );
}
......@@ -153,7 +153,11 @@ protected:
*/
void setHeight( qint64 height );
virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* event );
virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* event );
virtual void hoverEnterEvent( QGraphicsSceneHoverEvent* event );
virtual void hoverMoveEvent( QGraphicsSceneHoverEvent* event );
virtual void mousePressEvent( QGraphicsSceneMouseEvent* event );
virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
protected slots:
/**
......@@ -184,6 +188,14 @@ private:
bool m_muted;
QColor m_itemColor;
signals:
/**
* \brief Emitted when the item detect a cut request.
* \param self A pointer to the sender.
* \param frame Frame's number where the cut takes place.
*/
void split( AbstractGraphicsMediaItem* self, qint64 frame );
};
#endif // ABSTRACTGRAPHICSMEDIAITEM_H
......@@ -37,15 +37,12 @@
GraphicsAudioItem::GraphicsAudioItem( Clip* clip ) :
AbstractGraphicsMediaItem( clip )
{
setFlags( QGraphicsItem::ItemIsSelectable );
QTime length = QTime().addMSecs( clip->getMedia()->lengthMS() );
QString tooltip( tr( "<p style='white-space:pre'><b>Name:</b> %1"
"<br><b>Length:</b> %2" )
.arg( clip->getMedia()->fileName() )
.arg( length.toString("hh:mm:ss.zzz") ) );
setToolTip( tooltip );
setAcceptHoverEvents( true );
}
GraphicsAudioItem::GraphicsAudioItem( ClipHelper* ch ) :
......@@ -179,58 +176,3 @@ void GraphicsAudioItem::paintTitle( QPainter* painter, const QStyleOptionGraphic
painter->setPen( Qt::white );
painter->drawText( mapped, Qt::AlignVCenter, fm.elidedText( text, Qt::ElideRight, mapped.width() ) );
}
void GraphicsAudioItem::hoverEnterEvent( QGraphicsSceneHoverEvent* event )
{
TracksView* tv = Timeline::getInstance()->tracksView();
if ( tv )
{
switch ( tv->tool() )
{
case TOOL_DEFAULT:
setCursor( Qt::OpenHandCursor );
break;
case TOOL_CUT:
setCursor( QCursor( QPixmap( ":/images/editcut" ) ) );
break;
}
}
AbstractGraphicsMediaItem::hoverEnterEvent( event );
}
void GraphicsAudioItem::hoverLeaveEvent( QGraphicsSceneHoverEvent* event )
{
AbstractGraphicsMediaItem::hoverLeaveEvent( event );
}
void GraphicsAudioItem::hoverMoveEvent( QGraphicsSceneHoverEvent* event )
{
if ( !tracksView() ) return;
if ( tracksView()->tool() == TOOL_DEFAULT )
{
if ( resizeZone( event->pos() ) )
setCursor( Qt::SizeHorCursor );
else
setCursor( Qt::OpenHandCursor );
}
}
void GraphicsAudioItem::mousePressEvent( QGraphicsSceneMouseEvent* event )
{
TracksView* tv = Timeline::getInstance()->tracksView();
if ( tv->tool() == TOOL_DEFAULT )
setCursor( Qt::ClosedHandCursor );
else if ( tv->tool() == TOOL_CUT )
emit split( this, qRound64( event->pos().x() ) );
}
void GraphicsAudioItem::mouseReleaseEvent( QGraphicsSceneMouseEvent* event )
{
Q_UNUSED( event );
TracksView* tv = Timeline::getInstance()->tracksView();
if ( tv->tool() == TOOL_DEFAULT )
setCursor( Qt::OpenHandCursor );
}
......@@ -67,19 +67,6 @@ protected:
* \param option Painting options.
*/
void paintTitle( QPainter* painter, const QStyleOptionGraphicsItem* option );
virtual void hoverEnterEvent( QGraphicsSceneHoverEvent* event );
virtual void hoverLeaveEvent( QGraphicsSceneHoverEvent* event );
virtual void hoverMoveEvent( QGraphicsSceneHoverEvent* event );
virtual void mousePressEvent( QGraphicsSceneMouseEvent* event );
virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
signals:
/**
* \brief Emitted when the item detect a cut request.
* \param self A pointer to the sender.
* \param frame Frame's number where the cut takes place.
*/
void split( AbstractGraphicsMediaItem* self, qint64 frame );
};
#endif // GRAPHICSAUDIOITEM_H
......@@ -37,29 +37,23 @@
GraphicsMovieItem::GraphicsMovieItem( Clip* clip ) :
AbstractGraphicsMediaItem( clip )
{
setFlags( QGraphicsItem::ItemIsSelectable );
QTime length = QTime().addMSecs( clip->getMedia()->lengthMS() );
QString tooltip( tr( "<p style='white-space:pre'><b>Name:</b> %1"
"<br><b>Length:</b> %2" )
.arg( clip->getMedia()->fileName() )
.arg( length.toString("hh:mm:ss.zzz") ) );
setToolTip( tooltip );
setAcceptHoverEvents( true );
}
GraphicsMovieItem::GraphicsMovieItem( ClipHelper* ch ) :
AbstractGraphicsMediaItem( ch )
{
setFlags( QGraphicsItem::ItemIsSelectable );
QTime length = QTime().addMSecs( ch->clip()->getMedia()->lengthMS() );
QString tooltip( tr( "<p style='white-space:pre'><b>Name:</b> %1"
"<br><b>Length:</b> %2" )
.arg( ch->clip()->getMedia()->fileName() )
.arg( length.toString("hh:mm:ss.zzz") ) );
setToolTip( tooltip );
setAcceptHoverEvents( true );
}
GraphicsMovieItem::~GraphicsMovieItem()
......@@ -178,65 +172,3 @@ void GraphicsMovieItem::paintTitle( QPainter* painter, const QStyleOptionGraphic
painter->setPen( Qt::white );
painter->drawText( mapped, Qt::AlignVCenter, fm.elidedText( text, Qt::ElideRight, mapped.width() ) );
}
void GraphicsMovieItem::hoverEnterEvent( QGraphicsSceneHoverEvent* event )
{
TracksView* tv = Timeline::getInstance()->tracksView();
if ( tv )
{
switch ( tv->tool() )
{
case TOOL_DEFAULT:
setCursor( Qt::OpenHandCursor );
break;
case TOOL_CUT:
setCursor( QCursor( QPixmap( ":/images/editcut" ) ) );
break;
}
}
AbstractGraphicsMediaItem::hoverEnterEvent( event );
}
void GraphicsMovieItem::hoverLeaveEvent( QGraphicsSceneHoverEvent* event )
{
AbstractGraphicsMediaItem::hoverLeaveEvent( event );
}
void GraphicsMovieItem::hoverMoveEvent( QGraphicsSceneHoverEvent* event )
{
if ( !tracksView() ) return;
if ( tracksView()->tool() == TOOL_DEFAULT )
{
if ( resizeZone( event->pos() ) )
setCursor( Qt::SizeHorCursor );
else
setCursor( Qt::OpenHandCursor );
}
}
void GraphicsMovieItem::mousePressEvent( QGraphicsSceneMouseEvent* event )
{
if ( !tracksView() ) return;
if ( tracksView()->tool() == TOOL_DEFAULT )
{
if ( resizeZone( event->pos() ) )
setCursor( Qt::SizeHorCursor );
else
setCursor( Qt::ClosedHandCursor );
}
else if ( tracksView()->tool() == TOOL_CUT )
emit split( this, qRound64( event->pos().x() ) );
}
void GraphicsMovieItem::mouseReleaseEvent( QGraphicsSceneMouseEvent* event )
{
Q_UNUSED( event );
if ( !tracksView() ) return;
if ( tracksView()->tool() == TOOL_DEFAULT )
setCursor( Qt::OpenHandCursor );
}
......@@ -68,19 +68,5 @@ protected:
* \param option Painting options.
*/
void paintTitle( QPainter* painter, const QStyleOptionGraphicsItem* option );
virtual void hoverEnterEvent( QGraphicsSceneHoverEvent* event );
virtual void hoverLeaveEvent( QGraphicsSceneHoverEvent* event );
virtual void hoverMoveEvent( QGraphicsSceneHoverEvent* event );
virtual void mousePressEvent( QGraphicsSceneMouseEvent* event );
virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
signals:
/**
* \brief Emitted when the item detect a cut request.
* \param self A pointer to the sender.
* \param frame Frame's number where the cut takes place.
*/
void split( AbstractGraphicsMediaItem* self, qint64 frame );
};
#endif // GRAPHICSMOVIEITEM_H
......@@ -136,8 +136,7 @@ EmphasizedTrackItem::boundingRect() const
}
void
EmphasizedTrackItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
EmphasizedTrackItem::paint(QPainter *painter, const QStyleOptionGraphicsItem* , QWidget* )
{
painter->setBrush( QBrush( Qt::darkBlue ));
painter->drawRect( boundingRect() );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment