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

Adding a GraphicsEffectItem class.

This handles the effect representation in the timeline.
It currently can't be resized nor moved, or anything else.
parent b62c2856
...@@ -198,6 +198,7 @@ ELSE(NOT WITH_GUI) ...@@ -198,6 +198,7 @@ ELSE(NOT WITH_GUI)
Gui/timeline/AbstractGraphicsMediaItem.cpp Gui/timeline/AbstractGraphicsMediaItem.cpp
Gui/timeline/GraphicsAudioItem.cpp Gui/timeline/GraphicsAudioItem.cpp
Gui/timeline/GraphicsCursorItem.cpp Gui/timeline/GraphicsCursorItem.cpp
Gui/timeline/GraphicsEffectItem.cpp
Gui/timeline/GraphicsMovieItem.cpp Gui/timeline/GraphicsMovieItem.cpp
Gui/timeline/GraphicsTrack.cpp Gui/timeline/GraphicsTrack.cpp
Gui/timeline/Timeline.cpp Gui/timeline/Timeline.cpp
...@@ -271,6 +272,7 @@ ELSE(NOT WITH_GUI) ...@@ -271,6 +272,7 @@ ELSE(NOT WITH_GUI)
Gui/timeline/AbstractGraphicsMediaItem.h Gui/timeline/AbstractGraphicsMediaItem.h
Gui/timeline/GraphicsAudioItem.h Gui/timeline/GraphicsAudioItem.h
Gui/timeline/GraphicsCursorItem.h Gui/timeline/GraphicsCursorItem.h
Gui/timeline/GraphicsEffectItem.h
Gui/timeline/GraphicsMovieItem.h Gui/timeline/GraphicsMovieItem.h
Gui/timeline/GraphicsTrack.h Gui/timeline/GraphicsTrack.h
Gui/timeline/Timeline.h Gui/timeline/Timeline.h
......
...@@ -142,6 +142,10 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem ...@@ -142,6 +142,10 @@ class AbstractGraphicsItem : public QObject, public QGraphicsItem
virtual qint64 maxEnd() const { return -1; } virtual qint64 maxEnd() const { return -1; }
protected: protected:
static const quint32 ZSelected = 4;
static const quint32 ZNotSelected = 3;
static const quint32 RounderRectRadius = 5;
/// This pointer will be set when inserted in the tracksView. /// This pointer will be set when inserted in the tracksView.
TracksView* m_tracksView; TracksView* m_tracksView;
QColor m_itemColor; QColor m_itemColor;
......
...@@ -63,12 +63,14 @@ GraphicsAudioItem::~GraphicsAudioItem() ...@@ -63,12 +63,14 @@ GraphicsAudioItem::~GraphicsAudioItem()
{ {
} }
Workflow::TrackType GraphicsAudioItem::trackType() const Workflow::TrackType
GraphicsAudioItem::trackType() const
{ {
return Workflow::AudioTrack; return Workflow::AudioTrack;
} }
void GraphicsAudioItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* ) void
GraphicsAudioItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* )
{ {
painter->save(); painter->save();
paintRect( painter, option ); paintRect( painter, option );
...@@ -79,7 +81,8 @@ void GraphicsAudioItem::paint( QPainter* painter, const QStyleOptionGraphicsItem ...@@ -79,7 +81,8 @@ void GraphicsAudioItem::paint( QPainter* painter, const QStyleOptionGraphicsItem
painter->restore(); painter->restore();
} }
void GraphicsAudioItem::paintRect( QPainter* painter, const QStyleOptionGraphicsItem* option ) void
GraphicsAudioItem::paintRect( QPainter* painter, const QStyleOptionGraphicsItem* option )
{ {
QRectF drawRect; QRectF drawRect;
bool drawRound; bool drawRound;
...@@ -93,8 +96,8 @@ void GraphicsAudioItem::paintRect( QPainter* painter, const QStyleOptionGraphics ...@@ -93,8 +96,8 @@ void GraphicsAudioItem::paintRect( QPainter* painter, const QStyleOptionGraphics
QTransform viewPortTransform = Timeline::getInstance()->tracksView()->viewportTransform(); QTransform viewPortTransform = Timeline::getInstance()->tracksView()->viewportTransform();
// Determine if a drawing optimization can be used // Determine if a drawing optimization can be used
if ( option->exposedRect.left() > ROUNDED_RECT_RADIUS && if ( option->exposedRect.left() > AbstractGraphicsItem::RounderRectRadius &&
option->exposedRect.right() < boundingRect().right() - ROUNDED_RECT_RADIUS ) option->exposedRect.right() < boundingRect().right() - AbstractGraphicsItem::RounderRectRadius )
{ {
// Optimized: paint only the exposed (horizontal) area // Optimized: paint only the exposed (horizontal) area
drawRect = QRectF( option->exposedRect.left(), drawRect = QRectF( option->exposedRect.left(),
...@@ -124,7 +127,8 @@ void GraphicsAudioItem::paintRect( QPainter* painter, const QStyleOptionGraphics ...@@ -124,7 +127,8 @@ void GraphicsAudioItem::paintRect( QPainter* painter, const QStyleOptionGraphics
painter->setBrush( QBrush( gradient ) ); painter->setBrush( QBrush( gradient ) );
if ( drawRound ) if ( drawRound )
painter->drawRoundedRect( mapped, ROUNDED_RECT_RADIUS, ROUNDED_RECT_RADIUS ); painter->drawRoundedRect( mapped, AbstractGraphicsItem::RounderRectRadius,
AbstractGraphicsItem::RounderRectRadius );
else else
painter->drawRect( mapped ); painter->drawRect( mapped );
...@@ -137,20 +141,22 @@ void GraphicsAudioItem::paintRect( QPainter* painter, const QStyleOptionGraphics ...@@ -137,20 +141,22 @@ void GraphicsAudioItem::paintRect( QPainter* painter, const QStyleOptionGraphics
if ( isSelected() ) if ( isSelected() )
{ {
setZValue( Z_SELECTED ); setZValue( AbstractGraphicsItem::ZSelected );
painter->setPen( Qt::yellow ); painter->setPen( Qt::yellow );
painter->setBrush( Qt::NoBrush ); painter->setBrush( Qt::NoBrush );
mapped.adjust( 0, 0, 0, -1 ); mapped.adjust( 0, 0, 0, -1 );
if ( drawRound ) if ( drawRound )
painter->drawRoundedRect( mapped, ROUNDED_RECT_RADIUS, ROUNDED_RECT_RADIUS ); painter->drawRoundedRect( mapped, AbstractGraphicsItem::RounderRectRadius,
AbstractGraphicsItem::RounderRectRadius);
else else
painter->drawRect( mapped ); painter->drawRect( mapped );
} }
else else
setZValue( Z_NOT_SELECTED ); setZValue( AbstractGraphicsItem::ZSelected );
} }
void GraphicsAudioItem::paintTitle( QPainter* painter, const QStyleOptionGraphicsItem* option ) void
GraphicsAudioItem::paintTitle( QPainter* painter, const QStyleOptionGraphicsItem* option )
{ {
Q_UNUSED( option ); Q_UNUSED( option );
......
...@@ -28,11 +28,6 @@ ...@@ -28,11 +28,6 @@
#include "Clip.h" #include "Clip.h"
#include "TracksView.h" #include "TracksView.h"
#define Z_SELECTED 4
#define Z_NOT_SELECTED 3
#define ROUNDED_RECT_RADIUS 5
/** /**
* \brief Represents an audio item. * \brief Represents an audio item.
*/ */
......
/*****************************************************************************
* GraphicsEffectItem.cpp: Represent an effect in the timeline.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "GraphicsEffectItem.h"
#include "Timeline.h"
#include "TracksView.h"
#include <QPainter>
GraphicsEffectItem::GraphicsEffectItem( Effect *effect ) :
m_effect( effect ),
m_effectHelper( NULL )
{
setOpacity( 0.8 );
}
const QUuid&
GraphicsEffectItem::uuid() const
{
return m_effectHelper->uuid;
}
int
GraphicsEffectItem::type() const
{
return Type;
}
bool
GraphicsEffectItem::expandable() const
{
return true;
}
bool
GraphicsEffectItem::moveable() const
{
return true;
}
bool
GraphicsEffectItem::hasResizeBoundaries() const
{
return false;
}
Workflow::TrackType
GraphicsEffectItem::trackType() const
{
return Workflow::VideoTrack;
}
void
GraphicsEffectItem::paintRect( QPainter* painter, const QStyleOptionGraphicsItem* option )
{
QRectF drawRect;
bool drawRound;
// Disable the matrix transformations
painter->setWorldMatrixEnabled( false );
painter->setRenderHint( QPainter::Antialiasing );
// Get the transformations required to map the text on the viewport
QTransform viewPortTransform = Timeline::getInstance()->tracksView()->viewportTransform();
// Determine if a drawing optimization can be used
if ( option->exposedRect.left() > AbstractGraphicsItem::RounderRectRadius &&
option->exposedRect.right() < boundingRect().right() - AbstractGraphicsItem::RounderRectRadius )
{
// Optimized: paint only the exposed (horizontal) area
drawRect = QRectF( option->exposedRect.left(),
boundingRect().top(),
option->exposedRect.right(),
boundingRect().bottom() );
drawRound = false;
}
else
{
// Unoptimized: the item must be fully repaint
drawRect = boundingRect();
drawRound = true;
}
// Do the transformation
QRectF mapped = deviceTransform( viewPortTransform ).mapRect( drawRect );
QLinearGradient gradient( mapped.topLeft(), mapped.bottomLeft() );
gradient.setColorAt( 0, Qt::darkBlue );
gradient.setColorAt( 1, Qt::blue );
painter->setPen( Qt::NoPen );
painter->setBrush( QBrush( gradient ) );
if ( drawRound )
painter->drawRoundedRect( mapped, AbstractGraphicsItem::RounderRectRadius,
AbstractGraphicsItem::RounderRectRadius );
else
painter->drawRect( mapped );
if ( itemColor().isValid() )
{
QRectF mediaColorRect = mapped.adjusted( 3, 2, -3, -2 );
painter->setPen( QPen( itemColor(), 2 ) );
painter->drawLine( mediaColorRect.topLeft(), mediaColorRect.topRight() );
}
if ( isSelected() )
{
painter->setPen( Qt::yellow );
painter->setBrush( Qt::NoBrush );
mapped.adjust( 0, 0, 0, -1 );
if ( drawRound )
painter->drawRoundedRect( mapped, AbstractGraphicsItem::RounderRectRadius,
AbstractGraphicsItem::RounderRectRadius);
else
painter->drawRect( mapped );
}
}
void
GraphicsEffectItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* )
{
painter->save();
paintRect( painter, option );
painter->restore();
painter->save();
paintTitle( painter, option );
painter->restore();
}
void
GraphicsEffectItem::paintTitle( QPainter* painter, const QStyleOptionGraphicsItem* option )
{
Q_UNUSED( option );
// Disable the matrix transformations
painter->setWorldMatrixEnabled( false );
// Setup the font
QFont f = painter->font();
f.setPointSize( 8 );
painter->setFont( f );
// Initiate the font metrics calculation
QFontMetrics fm( painter->font() );
QString text = m_effect->name();
// Get the transformations required to map the text on the viewport
QTransform viewPortTransform = Timeline::getInstance()->tracksView()->viewportTransform();
// Do the transformation
QRectF mapped = deviceTransform( viewPortTransform ).mapRect( boundingRect() );
// Create an inner rect
mapped.adjust( 2, 2, -2, -2 );
painter->setPen( Qt::white );
painter->drawText( mapped, Qt::AlignVCenter, fm.elidedText( text, Qt::ElideRight, mapped.width() ) );
}
Effect*
GraphicsEffectItem::effect()
{
return m_effect;
}
/*****************************************************************************
* GraphicsEffectItem.h: Represent an effect in the timeline.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef GRAPHICSEFFECTITEM_H
#define GRAPHICSEFFECTITEM_H
#include "AbstractGraphicsItem.h"
#include "EffectsEngine.h"
class QUuid;
class GraphicsEffectItem : public AbstractGraphicsItem
{
public:
enum { Type = UserType + 3 };
GraphicsEffectItem( Effect *effect );
virtual const QUuid& uuid() const;
virtual int type() const;
virtual bool expandable() const;
virtual bool moveable() const;
virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget );
virtual Workflow::TrackType trackType() const;
Effect* effect();
protected:
virtual bool hasResizeBoundaries() const;
/**
* \brief Paint the item's rectangle.
* \param painter Pointer to a QPainter.
* \param option Painting options.
*/
void paintRect( QPainter* painter, const QStyleOptionGraphicsItem* option );
/**
* \brief Paint the item's title.
* \param painter Pointer to a QPainter.
* \param option Painting options.
*/
void paintTitle( QPainter* painter, const QStyleOptionGraphicsItem* option );
private:
Effect *m_effect;
EffectsEngine::EffectHelper *m_effectHelper;
};
#endif // GRAPHICSEFFECTITEM_H
...@@ -90,8 +90,8 @@ void GraphicsMovieItem::paintRect( QPainter* painter, const QStyleOptionGraphics ...@@ -90,8 +90,8 @@ void GraphicsMovieItem::paintRect( QPainter* painter, const QStyleOptionGraphics
QTransform viewPortTransform = Timeline::getInstance()->tracksView()->viewportTransform(); QTransform viewPortTransform = Timeline::getInstance()->tracksView()->viewportTransform();
// Determine if a drawing optimization can be used // Determine if a drawing optimization can be used
if ( option->exposedRect.left() > ROUNDED_RECT_RADIUS && if ( option->exposedRect.left() > AbstractGraphicsItem::RounderRectRadius &&
option->exposedRect.right() < boundingRect().right() - ROUNDED_RECT_RADIUS ) option->exposedRect.right() < boundingRect().right() - AbstractGraphicsItem::RounderRectRadius )
{ {
// Optimized: paint only the exposed (horizontal) area // Optimized: paint only the exposed (horizontal) area
drawRect = QRectF( option->exposedRect.left(), drawRect = QRectF( option->exposedRect.left(),
...@@ -120,7 +120,8 @@ void GraphicsMovieItem::paintRect( QPainter* painter, const QStyleOptionGraphics ...@@ -120,7 +120,8 @@ void GraphicsMovieItem::paintRect( QPainter* painter, const QStyleOptionGraphics
painter->setBrush( QBrush( gradient ) ); painter->setBrush( QBrush( gradient ) );
if ( drawRound ) if ( drawRound )
painter->drawRoundedRect( mapped, ROUNDED_RECT_RADIUS, ROUNDED_RECT_RADIUS ); painter->drawRoundedRect( mapped, AbstractGraphicsItem::RounderRectRadius,
AbstractGraphicsItem::RounderRectRadius );
else else
painter->drawRect( mapped ); painter->drawRect( mapped );
...@@ -133,17 +134,18 @@ void GraphicsMovieItem::paintRect( QPainter* painter, const QStyleOptionGraphics ...@@ -133,17 +134,18 @@ void GraphicsMovieItem::paintRect( QPainter* painter, const QStyleOptionGraphics
if ( isSelected() ) if ( isSelected() )
{ {
setZValue( Z_SELECTED ); setZValue( AbstractGraphicsItem::ZSelected );
painter->setPen( Qt::yellow ); painter->setPen( Qt::yellow );
painter->setBrush( Qt::NoBrush ); painter->setBrush( Qt::NoBrush );
mapped.adjust( 0, 0, 0, -1 ); mapped.adjust( 0, 0, 0, -1 );
if ( drawRound ) if ( drawRound )
painter->drawRoundedRect( mapped, ROUNDED_RECT_RADIUS, ROUNDED_RECT_RADIUS ); painter->drawRoundedRect( mapped, AbstractGraphicsItem::RounderRectRadius,
AbstractGraphicsItem::RounderRectRadius);
else else
painter->drawRect( mapped ); painter->drawRect( mapped );
} }
else else
setZValue( Z_NOT_SELECTED ); setZValue( AbstractGraphicsItem::ZSelected );
} }
void GraphicsMovieItem::paintTitle( QPainter* painter, const QStyleOptionGraphicsItem* option ) void GraphicsMovieItem::paintTitle( QPainter* painter, const QStyleOptionGraphicsItem* option )
......
...@@ -28,11 +28,6 @@ ...@@ -28,11 +28,6 @@
class Clip; class Clip;
#define Z_SELECTED 4
#define Z_NOT_SELECTED 3
#define ROUNDED_RECT_RADIUS 5
/** /**
* \brief Represents a video item. * \brief Represents a video item.
*/ */
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "Library.h" #include "Library.h"
#include "GraphicsMovieItem.h" #include "GraphicsMovieItem.h"
#include "GraphicsAudioItem.h" #include "GraphicsAudioItem.h"
#include "GraphicsEffectItem.h"
#include "GraphicsCursorItem.h" #include "GraphicsCursorItem.h"
#include "GraphicsTrack.h" #include "GraphicsTrack.h"
#include "Media.h" #include "Media.h"
...@@ -301,7 +302,9 @@ TracksView::effectDragEnterEvent( QDragEnterEvent *event ) ...@@ -301,7 +302,9 @@ TracksView::effectDragEnterEvent( QDragEnterEvent *event )
{ {
Effect* effect = EffectsEngine::getInstance()->effect( event->mimeData()->data( "vlmc/effect_name") ); Effect* effect = EffectsEngine::getInstance()->effect( event->mimeData()->data( "vlmc/effect_name") );
if ( effect != NULL ) if ( effect != NULL )
m_dragEffect = effect; {
m_dragEffectItem = new GraphicsEffectItem( effect );
}
else else
qWarning() << "Can't find effect name" << event->mimeData()->data( "vlmc/effect_name"); qWarning() << "Can't find effect name" << event->mimeData()->data( "vlmc/effect_name");
} }
...@@ -353,25 +356,17 @@ TracksView::dragMoveEvent( QDragMoveEvent *event ) ...@@ -353,25 +356,17 @@ TracksView::dragMoveEvent( QDragMoveEvent *event )
moveMediaItem( m_dragVideoItem, event->pos() ); moveMediaItem( m_dragVideoItem, event->pos() );
else if ( m_dragAudioItem != NULL) else if ( m_dragAudioItem != NULL)
moveMediaItem( m_dragAudioItem, event->pos() ); moveMediaItem( m_dragAudioItem, event->pos() );
else if ( m_dragEffect != NULL ) else if ( m_dragEffectItem != NULL )
{ {
//first, some cleaning:
foreach ( AbstractGraphicsMediaItem *item, m_effectEmphasizedItems )
item->setEmphasized( false );
foreach ( GraphicsTrack *item, m_effectEmphasizedTracks )
item->setEmphasized( false );
m_effectEmphasizedItems.clear();
QList<AbstractGraphicsMediaItem*> clips = mediaItems( event->pos() ); QList<AbstractGraphicsMediaItem*> clips = mediaItems( event->pos() );
if ( clips.size() > 0 ) if ( clips.size() > 0 )
{ {
foreach ( AbstractGraphicsMediaItem* item, clips ) AbstractGraphicsMediaItem *item = clips.first();
{ m_dragEffectItem->setWidth( item->clipHelper()->length() );
if ( item->trackType() != Workflow::VideoTrack ) m_dragEffectItem->setStartPos( item->startPos() );
continue ; m_dragEffectItem->setHeight( tracksHeight() / 2 );
m_effectEmphasizedItems.insert( item ); m_dragEffectItem->setTrack( getTrack( m_dragEffectItem->trackType(), 0 ) );
item->setEmphasized( true ); m_dragEffectItem->setZValue( 100 );
}
} }
else else
{ {
...@@ -381,8 +376,11 @@ TracksView::dragMoveEvent( QDragMoveEvent *event ) ...@@ -381,8 +376,11 @@ TracksView::dragMoveEvent( QDragMoveEvent *event )
GraphicsTrack *track = qgraphicsitem_cast<GraphicsTrack*>( item ); GraphicsTrack *track = qgraphicsitem_cast<GraphicsTrack*>( item );
if ( track != NULL && track->mediaType() == Workflow::VideoTrack ) if ( track != NULL && track->mediaType() == Workflow::VideoTrack )
{ {
m_effectEmphasizedTracks.insert( track ); m_dragEffectItem->setWidth( track->maximumWidth() );
track->setEmphasized( true ); m_dragEffectItem->setStartPos( 0 );
m_dragEffectItem->setHeight( tracksHeight() / 2 );
m_dragEffectItem->setTrack( track );
break ;
} }
} }
} }
...@@ -708,16 +706,10 @@ TracksView::dragLeaveEvent( QDragLeaveEvent *event ) ...@@ -708,16 +706,10 @@ TracksView::dragLeaveEvent( QDragLeaveEvent *event )
delete m_dragAudioItem; delete m_dragAudioItem;
delete m_dragVideoItem; delete m_dragVideoItem;
delete m_dragEffectItem;
m_dragAudioItem = NULL; m_dragAudioItem = NULL;
m_dragVideoItem = NULL; m_dragVideoItem = NULL;
m_dragEffect = NULL; //Don't delete the effect. m_dragEffectItem = NULL;
foreach ( AbstractGraphicsMediaItem *item, m_effectEmphasizedItems )
item->setEmphasized( false );
m_effectEmphasizedItems.clear();
foreach ( GraphicsTrack *item, m_effectEmphasizedTracks )
item->setEmphasized( false );
m_effectEmphasizedTracks.clear();
if ( updateDurationNeeded ) if ( updateDurationNeeded )
updateDuration(); updateDuration();
...@@ -770,14 +762,14 @@ TracksView::dropEvent( QDropEvent *event ) ...@@ -770,14 +762,14 @@ TracksView::dropEvent( QDropEvent *event )
m_lastKnownTrack = NULL; m_lastKnownTrack = NULL;
} }
else if ( m_dragEffect != NULL ) else if ( m_dragEffectItem != NULL )
{ {
QList<AbstractGraphicsMediaItem*> clips = mediaItems( event->pos() ); QList<AbstractGraphicsMediaItem*> clips = mediaItems( event->pos() );
if ( clips.size() > 0 ) if ( clips.size() > 0 )
{ {
foreach ( AbstractGraphicsMediaItem *item, clips ) foreach ( AbstractGraphicsMediaItem *item, clips )
{ {
item->clipHelper()->clipWorkflow()->addEffect( m_dragEffect ); item->clipHelper()->clipWorkflow()->addEffect( m_dragEffectItem->effect() );
} }
} }
else else
...@@ -787,13 +779,9 @@ TracksView::dropEvent( QDropEvent *event ) ...@@ -787,13 +779,9 @@ TracksView::dropEvent( QDropEvent *event )
{ {
GraphicsTrack *track = qgraphicsitem_cast<GraphicsTrack*>( item );