TracksView.h 4.99 KB
Newer Older
1
/*****************************************************************************
2
 * TracksView.h: QGraphicsView that contains the TracksScene
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Ludovic Fauvet <etix@l0cal.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.
 *****************************************************************************/

23
24
#ifndef TRACKSVIEW_H
#define TRACKSVIEW_H
25

26
#include <QWidget>
27
#include <QGraphicsView>
28
#include <QGraphicsLineItem>
Ludovic Fauvet's avatar
Ludovic Fauvet committed
29
30
#include <QGraphicsLinearLayout>
#include <QGraphicsWidget>
Ludovic Fauvet's avatar
Ludovic Fauvet committed
31
#include <QWheelEvent>
Ludovic Fauvet's avatar
Ludovic Fauvet committed
32
#include <QGraphicsSceneDragDropEvent>
33
#include "Media.h"
34
#include "GraphicsCursorItem.h"
35
#include "Workflow/MainWorkflow.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
36
#include "Workflow/TrackWorkflow.h"
37

Ludovic Fauvet's avatar
Ludovic Fauvet committed
38
class GraphicsMovieItem;
39
class AbstractGraphicsMediaItem;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
40
41
42
43
44
45

class GraphicsTrack : public QGraphicsWidget
{
    Q_OBJECT

public:
46
47
48
49
50
    enum Type
    {
        Video,
        Audio
    };
51
    GraphicsTrack( Type type, int trackNumber, QGraphicsItem* parent = 0 ) : QGraphicsWidget( parent )
52
53
    {
        m_type = type;
54
55
56
57
58
        m_trackNumber = trackNumber;
    }
    int trackNumber()
    {
        return m_trackNumber;
59
    }
Ludovic Fauvet's avatar
Ludovic Fauvet committed
60
61
62
63

protected:
    virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* = 0 )
    {
64
65
66
67
        if ( m_type == Video )
            painter->setBrush( Qt::green );
        else
            painter->setBrush( Qt::blue );
68
        painter->setPen( Qt::transparent );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
69
70
        painter->drawRect( rect() );
    }
71
72
73

private:
    Type m_type;
74
    int m_trackNumber;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
75
76
};

77
class TracksView : public QGraphicsView
78
{
79
80
    Q_OBJECT

81
public:
82
    TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, QWidget* parent = 0 );
83
    void setDuration( int duration );
84
85
    int duration() const { return m_projectDuration; }
    int tracksHeight() const { return m_tracksHeight; }
86
    unsigned int tracksCount() const { return m_tracksCount; }
87
    void setCursorPos( int pos );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
88
    int cursorPos();
89
    GraphicsCursorItem* tracksCursor() const { return m_cursorLine; }
90
    void setScale( double scaleFactor );
91
    QList<AbstractGraphicsMediaItem*> mediaItems( const QPoint& pos );
92

93
94
95
public slots:
    void                    moveMediaItem( const QUuid& uuid, int track, int time );

96
protected:
97
98
99
100
101
102
103
104
    virtual void            resizeEvent( QResizeEvent* event );
    virtual void            drawBackground( QPainter* painter, const QRectF& rect );
    virtual void            mouseMoveEvent( QMouseEvent* event );
    virtual void            mousePressEvent( QMouseEvent* event );
    virtual void            mouseReleaseEvent( QMouseEvent* event );
    virtual void            wheelEvent( QWheelEvent* event );
    virtual void            dragEnterEvent( QDragEnterEvent* event );
    virtual void            dragMoveEvent( QDragMoveEvent* event );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
105
106
    virtual void            dragLeaveEvent( QDragLeaveEvent* event );
    virtual void            dropEvent( QDropEvent* event );
107

108
private slots:
109
    void                    ensureCursorVisible();
110
    void                    updateDuration();
111

112
private:
Ludovic Fauvet's avatar
Ludovic Fauvet committed
113
114
115
    void                    createLayout();
    void                    addVideoTrack();
    void                    addAudioTrack();
116
    void                    moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position );
117
    void                    moveMediaItem( AbstractGraphicsMediaItem* item, int track, int time );
118
119
120
121
122
123
    QGraphicsScene*         m_scene;
    int                     m_tracksHeight;
    unsigned int            m_tracksCount;
    int                     m_projectDuration;
    int                     m_fps;
    GraphicsCursorItem*     m_cursorLine;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
124
125
126
    QGraphicsLinearLayout*  m_layout;
    int                     m_numVideoTrack;
    int                     m_numAudioTrack;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
127
    int                     m_videoTracksCounter;
128
    MainWorkflow*           m_mainWorkflow;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
129
    GraphicsMovieItem*      m_dragItem;
130
    QGraphicsWidget*        m_separator;
131

Ludovic Fauvet's avatar
Ludovic Fauvet committed
132
133
134
135
136
    // Mouse actions on Medias
    bool                    m_actionMove;
    int                     m_actionRelativeX;
    AbstractGraphicsMediaItem* m_actionItem;

Ludovic Fauvet's avatar
Ludovic Fauvet committed
137
signals:
138
139
140
    void                    zoomIn();
    void                    zoomOut();
    void                    durationChanged( int duration );
141
    void                    clipMoved( const QUuid& uuid, int oldTrack, int newTrack, qint64 start );
142
143
};

144
#endif // TRACKSVIEW_H