TracksView.h 4.68 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
36
#include "MainWorkflow.h"
#include "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

protected:
94
95
96
97
98
99
100
101
    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
102
103
    virtual void            dragLeaveEvent( QDragLeaveEvent* event );
    virtual void            dropEvent( QDropEvent* event );
104

105
private slots:
106
    void                    ensureCursorVisible();
107
    void                    updateDuration();
108

109
private:
Ludovic Fauvet's avatar
Ludovic Fauvet committed
110
111
112
    void                    createLayout();
    void                    addVideoTrack();
    void                    addAudioTrack();
113
    void                    moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position );
114
115
116
117
118
119
    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
120
121
122
    QGraphicsLinearLayout*  m_layout;
    int                     m_numVideoTrack;
    int                     m_numAudioTrack;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
123
    int                     m_videoTracksCounter;
124
    MainWorkflow*           m_mainWorkflow;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
125
    GraphicsMovieItem*      m_dragItem;
126
    QGraphicsWidget*        m_separator;
127

Ludovic Fauvet's avatar
Ludovic Fauvet committed
128
129
130
131
132
    // Mouse actions on Medias
    bool                    m_actionMove;
    int                     m_actionRelativeX;
    AbstractGraphicsMediaItem* m_actionItem;

Ludovic Fauvet's avatar
Ludovic Fauvet committed
133
signals:
134
135
136
    void                    zoomIn();
    void                    zoomOut();
    void                    durationChanged( int duration );
137
138
};

139
#endif // TRACKSVIEW_H