TracksView.h 4.37 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"
36

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

class GraphicsTrack : public QGraphicsWidget
{
    Q_OBJECT

public:
45
46
47
48
49
50
51
52
53
    enum Type
    {
        Video,
        Audio
    };
    GraphicsTrack( Type type, QGraphicsItem* parent = 0 ) : QGraphicsWidget( parent )
    {
        m_type = type;
    }
Ludovic Fauvet's avatar
Ludovic Fauvet committed
54
55
56
57

protected:
    virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* = 0 )
    {
58
59
60
61
        if ( m_type == Video )
            painter->setBrush( Qt::green );
        else
            painter->setBrush( Qt::blue );
62
        painter->setPen( Qt::transparent );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
63
64
        painter->drawRect( rect() );
    }
65
66
67

private:
    Type m_type;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
68
69
};

70
class TracksView : public QGraphicsView
71
{
72
73
    Q_OBJECT

74
public:
75
    TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, QWidget* parent = 0 );
76
    void setDuration( int duration );
77
78
    int duration() const { return m_projectDuration; }
    int tracksHeight() const { return m_tracksHeight; }
79
    unsigned int tracksCount() const { return m_tracksCount; }
80
    void setCursorPos( int pos );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
81
    int cursorPos();
82
    GraphicsCursorItem* tracksCursor() const { return m_cursorLine; }
83
    //FIXME: this should probably take a Clip* as a parameter doesn't it ?
84
    void addClip( Media* clip, const QPoint& point );
85
    void setScale( double scaleFactor );
86
87

protected:
88
89
90
91
92
93
94
95
    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
96
97
    virtual void            dragLeaveEvent( QDragLeaveEvent* event );
    virtual void            dropEvent( QDropEvent* event );
98

99
private slots:
100
    void                    ensureCursorVisible();
101
    void                    updateDuration();
102

103
private:
Ludovic Fauvet's avatar
Ludovic Fauvet committed
104
105
106
    void                    createLayout();
    void                    addVideoTrack();
    void                    addAudioTrack();
107
    void                    moveMediaItem( AbstractGraphicsMediaItem* item, QPoint position );
108
109
110
111
112
113
    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
114
115
116
    QGraphicsLinearLayout*  m_layout;
    int                     m_numVideoTrack;
    int                     m_numAudioTrack;
117
    MainWorkflow*           m_mainWorkflow;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
118
    GraphicsMovieItem*      m_dragItem;
119
    QGraphicsWidget*        m_separator;
120

Ludovic Fauvet's avatar
Ludovic Fauvet committed
121
signals:
122
123
124
    void                    zoomIn();
    void                    zoomOut();
    void                    durationChanged( int duration );
125
126
};

127
#endif // TRACKSVIEW_H