]> git.sesse.net Git - kdenlive/blob - src/keyframehelper.cpp
small ui update for autotrack / obscure filter
[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 #include <QMouseEvent>
21 #include <QStylePainter>
22
23 #include <KDebug>
24 #include <KGlobalSettings>
25
26 #include "keyframehelper.h"
27 #include "definitions.h"
28
29
30 KeyframeHelper::KeyframeHelper(QWidget *parent)
31         : QWidget(parent), m_geom(NULL), m_position(0), m_scale(0) {
32     setFont(KGlobalSettings::toolBarFont());
33 }
34
35 // virtual
36 void KeyframeHelper::mousePressEvent(QMouseEvent * event) {
37     m_position = event->x() / m_scale;
38     emit positionChanged(m_position);
39     update();
40 }
41
42 // virtual
43 void KeyframeHelper::mouseMoveEvent(QMouseEvent * event) {
44     m_position = event->x() / m_scale;
45     m_position = qMax(0, m_position);
46     m_position = qMin(m_length, m_position);
47     emit positionChanged(m_position);
48     update();
49 }
50
51
52 // virtual
53 void KeyframeHelper::wheelEvent(QWheelEvent * e) {
54     if (e->delta() < 0) m_position = m_position - 1;
55     else m_position = m_position + 1;
56     m_position = qMax(0, m_position);
57     m_position = qMin(m_length, m_position);
58     emit positionChanged(m_position);
59     update();
60     /*    int delta = 1;
61         if (e->modifiers() == Qt::ControlModifier) delta = m_timecode.fps();
62         if (e->delta() < 0) delta = 0 - delta;
63         m_view->moveCursorPos(delta);
64     */
65 }
66
67 // virtual
68 void KeyframeHelper::paintEvent(QPaintEvent *e) {
69     QStylePainter p(this);
70     const QRectF clipRect = e->rect();
71     p.setClipRect(clipRect);
72     m_scale = (double) width() / m_length;
73     if (m_geom != NULL) {
74         int pos = 0;
75         p.setPen(QColor(255, 20, 20));
76         Mlt::GeometryItem item;
77         while (true) {
78             if (m_geom->next_key(&item, pos) == 1) break;
79             pos = item.frame();
80             int scaledPos = pos * m_scale;
81             p.drawLine(scaledPos, 0, scaledPos, 10);
82             //p.fillRect(QRect(scaledPos - 1, 0, 2, 15), QBrush(QColor(255, 20, 20)));
83             pos++;
84         }
85     }
86     p.setPen(palette().dark().color());
87     p.drawLine(clipRect.x(), 5, clipRect.right(), 5);
88
89     // draw pointer
90     QPolygon pa(3);
91     const int cursor = m_position * m_scale;
92     pa.setPoints(3, cursor - 5, 11, cursor + 5, 11, cursor/*+0*/, 6);
93     p.setBrush(palette().dark().color());
94     p.drawPolygon(pa);
95
96
97 }
98
99 const int KeyframeHelper::value() const {
100     return m_position;
101 }
102
103 void KeyframeHelper::setValue(const int pos) {
104     if (pos == m_position || m_geom == NULL) return;
105     m_position = pos;
106     update();
107 }
108
109 void KeyframeHelper::setKeyGeometry(Mlt::Geometry *geom, const int length) {
110     m_geom = geom;
111     m_length = length;
112     update();
113 }
114
115 #include "keyframehelper.moc"