1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #include "keyframehelper.h"
22 #include "definitions.h"
25 #include <KGlobalSettings>
27 #include <QMouseEvent>
28 #include <QStylePainter>
31 KeyframeHelper::KeyframeHelper(QWidget *parent) :
37 setFont(KGlobalSettings::toolBarFont());
41 void KeyframeHelper::mousePressEvent(QMouseEvent * event)
43 m_position = event->x() / m_scale;
44 emit positionChanged(m_position);
49 void KeyframeHelper::mouseMoveEvent(QMouseEvent * event)
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);
60 void KeyframeHelper::wheelEvent(QWheelEvent * e)
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);
69 if (e->modifiers() == Qt::ControlModifier) delta = m_timecode.fps();
70 if (e->delta() < 0) delta = 0 - delta;
71 m_view->moveCursorPos(delta);
76 void KeyframeHelper::paintEvent(QPaintEvent *e)
78 QStylePainter p(this);
79 const QRectF clipRect = e->rect();
80 p.setClipRect(clipRect);
81 m_scale = (double) width() / m_length;
84 p.setPen(QColor(255, 20, 20));
85 Mlt::GeometryItem item;
87 if (m_geom->next_key(&item, pos) == 1) break;
89 int scaledPos = pos * m_scale;
91 p.drawLine(scaledPos, 6, scaledPos, 10);
94 pa.setPoints(3, scaledPos - 4, 0, scaledPos + 4, 0, scaledPos, 4);
95 p.setBrush(QColor(255, 20, 20));
97 //p.fillRect(QRect(scaledPos - 1, 0, 2, 15), QBrush(QColor(255, 20, 20)));
101 p.setPen(palette().dark().color());
102 p.drawLine(clipRect.x(), 5, clipRect.right(), 5);
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());
114 int KeyframeHelper::value() const
119 void KeyframeHelper::setValue(const int pos)
121 if (pos == m_position || m_geom == NULL) return;
126 void KeyframeHelper::setKeyGeometry(Mlt::Geometry *geom, const int length)
133 #include "keyframehelper.moc"