Commit 1a69b14d authored by Ludovic Fauvet's avatar Ludovic Fauvet
Browse files

Code cleanup (and mostly fixed)

parent 9fc5f2b6
......@@ -46,7 +46,6 @@ TracksView::TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, QWidg
m_numAudioTrack = 0;
m_numVideoTrack = 0;
m_videoTracksCounter = MAX_TRACKS - 1;
m_dragItem = NULL;
m_actionMove = false;
m_actionRelativeX = -1;
......@@ -103,14 +102,13 @@ void TracksView::createLayout()
void TracksView::addVideoTrack()
{
GraphicsTrack* track = new GraphicsTrack( GraphicsTrack::Video, m_videoTracksCounter );
GraphicsTrack* track = new GraphicsTrack( GraphicsTrack::Video, m_numVideoTrack );
track->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
track->setPreferredHeight( m_tracksHeight );
track->setContentsMargins( 0, 0, 0, 0 );
m_layout->insertItem( 0, track );
QApplication::processEvents(); //FIXME This is a bit hackish
m_numVideoTrack++;
m_videoTracksCounter--;
m_scene->invalidate();
//FIXME this should maybe go elsewhere
setSceneRect( m_layout->contentsRect().adjusted( 0, 0, 100, 100 ) );
......@@ -174,9 +172,18 @@ void TracksView::moveMediaItem( const QUuid& uuid, unsigned int track, qint64 ti
void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position )
{
int track = (unsigned int)( mapToScene( position ).y() / m_tracksHeight );
GraphicsTrack* track = NULL;
QList<QGraphicsItem*> list = items( position );
for ( int i = 0; i < list.size(); ++i )
{
track = qgraphicsitem_cast<GraphicsTrack*>( list.at(i) );
if (track) break;
}
if (!track) return;
qreal time = ( mapToScene( position ).x() + 0.5 );
moveMediaItem( item, track, (int)time);
moveMediaItem( item, track->trackNumber(), (int)time);
}
void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, int track, int time )
......@@ -186,10 +193,12 @@ void TracksView::moveMediaItem( AbstractGraphicsMediaItem* item, int track, int
else if ( track > m_numVideoTrack - 1)
track = m_numVideoTrack - 1;
//qDebug() << ">>>>>> Move track number" << track;
QPointF oldPos = item->pos();
QGraphicsItem* oldParent = item->parentItem();
// Check for vertical collisions
item->setParentItem( m_layout->itemAt( track )->graphicsItem() );
item->setParentItem( m_layout->itemAt( m_numVideoTrack - track - 1 )->graphicsItem() );
bool continueSearch = true;
while ( continueSearch )
{
......
......@@ -44,12 +44,13 @@ class GraphicsTrack : public QGraphicsWidget
Q_OBJECT
public:
enum Type
enum { Type = UserType + 2 };
enum MediaType
{
Video,
Audio
};
GraphicsTrack( Type type, int trackNumber, QGraphicsItem* parent = 0 ) : QGraphicsWidget( parent )
GraphicsTrack( MediaType type, int trackNumber, QGraphicsItem* parent = 0 ) : QGraphicsWidget( parent )
{
m_type = type;
m_trackNumber = trackNumber;
......@@ -58,6 +59,7 @@ public:
{
return m_trackNumber;
}
virtual int type() const { return Type; }
protected:
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* = 0 )
......@@ -71,7 +73,7 @@ protected:
}
private:
Type m_type;
MediaType m_type;
int m_trackNumber;
};
......@@ -125,7 +127,6 @@ private:
QGraphicsLinearLayout* m_layout;
int m_numVideoTrack;
int m_numAudioTrack;
int m_videoTracksCounter;
MainWorkflow* m_mainWorkflow;
GraphicsMovieItem* m_dragItem;
QGraphicsWidget* m_separator;
......
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