]> git.sesse.net Git - kdenlive/blob - src/keyframehelper.cpp
Reformat initializer lists in all constructors.
[kdenlive] / src / keyframehelper.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #include "keyframehelper.h"
22 #include "definitions.h"
23
24 #include <KDebug>
25 #include <KGlobalSettings>
26
27 #include <QMouseEvent>
28 #include <QStylePainter>
29
30
31 KeyframeHelper::KeyframeHelper(QWidget *parent) :
32         QWidget(parent),
33         m_geom(NULL),
34         m_position(0),
35         m_scale(0)
36 {
37     setFont(KGlobalSettings::toolBarFont());
38 }
39
40 // virtual
41 void KeyframeHelper::mousePressEvent(QMouseEvent * event)
42 {
43     m_position = event->x() / m_scale;
44     emit positionChanged(m_position);
45     update();
46 }
47
48 // virtual
49 void KeyframeHelper::mouseMoveEvent(QMouseEvent * event)
50 {
51     m_position = event->x() / m_scale;
52     m_position = qMax(0, m_position);
53     m_position = qMin(m_length, m_position);
54     emit positionChanged(m_position);
55     update();
56 }
57
58
59 // virtual
60 void KeyframeHelper::wheelEvent(QWheelEvent * e)
61 {
62     if (e->delta() < 0) m_position = m_position - 1;
63     else m_position = m_position + 1;
64     m_position = qMax(0, m_position);
65     m_position = qMin(m_length, m_position);
66     emit positionChanged(m_position);
67     update();
68     /*    int delta = 1;
69         if (e->modifiers() == Qt::ControlModifier) delta = m_timecode.fps();
70         if (e->delta() < 0) delta = 0 - delta;
71         m_view->moveCursorPos(delta);
72     */
73 }
74
75 // virtual
76 void KeyframeHelper::paintEvent(QPaintEvent *e)
77 {
78     QStylePainter p(this);
79     const QRectF clipRect = e->rect();
80     p.setClipRect(clipRect);
81     m_scale = (double) width() / m_length;
82     if (m_geom != NULL) {
83         int pos = 0;
84         p.setPen(QColor(255, 20, 20));
85         Mlt::GeometryItem item;
86         while (true) {
87             if (m_geom->next_key(&item, pos) == 1) break;
88             pos = item.frame();
89             int scaledPos = pos * m_scale;
90             // draw keyframes
91             p.drawLine(scaledPos, 6, scaledPos, 10);
92             // draw pointer
93             QPolygon pa(3);
94             pa.setPoints(3, scaledPos - 4, 0, scaledPos + 4, 0, scaledPos, 4);
95             p.setBrush(QColor(255, 20, 20));
96             p.drawPolygon(pa);
97             //p.fillRect(QRect(scaledPos - 1, 0, 2, 15), QBrush(QColor(255, 20, 20)));
98             pos++;
99         }
100     }
101     p.setPen(palette().dark().color());
102     p.drawLine(clipRect.x(), 5, clipRect.right(), 5);
103
104     // draw pointer
105     QPolygon pa(3);
106     const int cursor = m_position * m_scale;
107     pa.setPoints(3, cursor - 5, 11, cursor + 5, 11, cursor, 6);
108     p.setBrush(palette().dark().color());
109     p.drawPolygon(pa);
110
111
112 }
113
114 int KeyframeHelper::value() const
115 {
116     return m_position;
117 }
118
119 void KeyframeHelper::setValue(const int pos)
120 {
121     if (pos == m_position || m_geom == NULL) return;
122     m_position = pos;
123     update();
124 }
125
126 void KeyframeHelper::setKeyGeometry(Mlt::Geometry *geom, const int length)
127 {
128     m_geom = geom;
129     m_length = length;
130     update();
131 }
132
133 #include "keyframehelper.moc"