TracksRuler.h 3.51 KB
Newer Older
1 2 3
/*****************************************************************************
 * TracksRuler.h: Timeline ruler
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * 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.
 *****************************************************************************/

#ifndef TRACKSRULER_H
#define TRACKSRULER_H

#include <QWidget>
#include <QPaintEvent>
28
#include <QString>
29
#include "TracksView.h"
30 31

const int FRAME_SIZE = 90;
32
static const int FIX_WIDTH = 30; /* widget width in pixel */
33 34 35 36 37 38 39 40 41 42 43 44 45 46
static const int LINE_END = (FIX_WIDTH - 3);
static const int END_MARK_LENGTH = (FIX_WIDTH - 8);
static const int BIG_MARK_LENGTH = (END_MARK_LENGTH * 3 / 4);
static const int BIG_MARK_X2 = LINE_END;
static const int BIG_MARK_X1 = (BIG_MARK_X2 - BIG_MARK_LENGTH);
static const int MIDDLE_MARK_LENGTH = (END_MARK_LENGTH / 2);
static const int MIDDLE_MARK_X2 = LINE_END;
static const int MIDDLE_MARK_X1 = (MIDDLE_MARK_X2 - MIDDLE_MARK_LENGTH);
static const int LITTLE_MARK_LENGTH = (MIDDLE_MARK_LENGTH / 2);
static const int LITTLE_MARK_X2 = LINE_END;
static const int LITTLE_MARK_X1 = (LITTLE_MARK_X2 - LITTLE_MARK_LENGTH);

static const int LABEL_SIZE = 9;

47 48 49
/**
 * \brief Timeline's ruler widget
 */
50 51 52 53 54
class TracksRuler : public QWidget
{
    Q_OBJECT

public:
55
    TracksRuler( TracksView* tracksView, QWidget* parent = 0 );
56 57 58 59
    /**
     * \brief Change the duration of the project.
     * \param duration Duration in frames.
     */
60
    void setDuration( int duration );
61 62 63 64
    /**
     * \brief Compute the spacing between the marks.
     * \param rate Zoom factor
     */
65
    void setPixelPerMark( double rate );
66 67 68
    /**
     * \brief Scaling steps.
     */
69
    static const int comboScale[];
70 71 72
    /**
     * \brief Offset of the current position.
     */
73
    int offset() const { return m_offset; }
74 75

public slots:
76 77 78 79
    /**
     * \brief Scroll the content of the ruler.
     * \param pos Position in frames.
     */
80 81 82 83
    void moveRuler( int pos );

protected:
    virtual void paintEvent( QPaintEvent* e );
84 85
    virtual void mousePressEvent( QMouseEvent* event );
    virtual void mouseMoveEvent( QMouseEvent* event );
86 87

private:
88 89 90 91 92
    /**
     * \brief Generate the timecode for the specified frame.
     * \param frames The frame number.
     * \return The timecode as a QString.
     */
93
    QString getTimeCode( int frames ) const;
94 95 96
    /**
     * \brief Return a pointer to the TracksView.
     */
97
    TracksView* m_tracksView;
98 99 100 101 102 103 104 105 106
    int m_duration;
    int m_fps;
    int m_offset;
    double m_factor;
    double m_scale;
    double m_textSpacing;
    int m_littleMarkDistance;
    int m_mediumMarkDistance;
    int m_bigMarkDistance;
107 108

signals:
109 110 111
    /**
     * \brief Emitted when the user is seeking.
     */
112
    void        frameChanged( qint64, Vlmc::FrameChangedReason );
113 114 115
};

#endif // TRACKSRULER_H