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 <QApplication>
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
    enum { Type = UserType + 2 };
    enum MediaType
48 49 50 51
    {
        Video,
        Audio
    };
52
    GraphicsTrack( MediaType type, int trackNumber, QGraphicsItem* parent = 0 ) : QGraphicsWidget( parent )
53 54
    {
        m_type = type;
55 56 57 58 59
        m_trackNumber = trackNumber;
    }
    int trackNumber()
    {
        return m_trackNumber;
60
    }
61
    virtual int type() const { return Type; }
Ludovic Fauvet's avatar
Ludovic Fauvet committed
62 63 64 65

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

private:
75
    MediaType m_type;
76
    int m_trackNumber;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
77 78
};

79
class TracksView : public QGraphicsView
80
{
81 82
    Q_OBJECT

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

95
public slots:
96
    void                    moveMediaItem( const QUuid& uuid, unsigned int track, qint64 time );
97

98
protected:
99 100 101 102 103 104 105 106
    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
107 108
    virtual void            dragLeaveEvent( QDragLeaveEvent* event );
    virtual void            dropEvent( QDropEvent* event );
109

110
private slots:
111
    void                    ensureCursorVisible();
112
    void                    updateDuration();
113

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

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

Ludovic Fauvet's avatar
Ludovic Fauvet committed
139
signals:
140 141 142
    void                    zoomIn();
    void                    zoomOut();
    void                    durationChanged( int duration );
143 144
};

145
#endif // TRACKSVIEW_H