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 ***************************************************************************/
20 #include <QMouseEvent>
21 #include <QStylePainter>
26 #include <KGlobalSettings>
28 #include "keyframehelper.h"
30 #include "definitions.h"
33 KeyframeHelper::KeyframeHelper(QWidget *parent)
34 : QWidget(parent), m_geom(NULL) {
35 setFont(KGlobalSettings::toolBarFont());
40 void KeyframeHelper::mousePressEvent(QMouseEvent * event) {
41 /* if (event->button() == Qt::RightButton) {
42 m_contextMenu->exec(event->globalPos());
45 m_view->activateMonitor();
46 int pos = (int)((event->x() + offset()));
47 m_moveCursor = RULER_CURSOR;
48 if (event->y() > 10) {
49 if (qAbs(pos - m_zoneStart * m_factor) < 4) m_moveCursor = RULER_START;
50 else if (qAbs(pos - (m_zoneStart + (m_zoneEnd - m_zoneStart) / 2) * m_factor) < 4) m_moveCursor = RULER_MIDDLE;
51 else if (qAbs(pos - m_zoneEnd * m_factor) < 4) m_moveCursor = RULER_END;
53 if (m_moveCursor == RULER_CURSOR)
54 m_view->setCursorPos((int) pos / m_factor);
59 void KeyframeHelper::mouseMoveEvent(QMouseEvent * event) {
60 /* if (event->buttons() == Qt::LeftButton) {
61 int pos = (int)((event->x() + offset()) / m_factor);
63 if (m_moveCursor == RULER_CURSOR) {
64 m_view->setCursorPos(pos);
66 } else if (m_moveCursor == RULER_START) m_zoneStart = pos;
67 else if (m_moveCursor == RULER_END) m_zoneEnd = pos;
68 else if (m_moveCursor == RULER_MIDDLE) {
69 int move = pos - (m_zoneStart + (m_zoneEnd - m_zoneStart) / 2);
73 m_view->setDocumentModified();
76 int pos = (int)((event->x() + offset()));
77 if (event->y() <= 10) setCursor(Qt::ArrowCursor);
78 else if (qAbs(pos - m_zoneStart * m_factor) < 4) setCursor(KCursor("left_side", Qt::SizeHorCursor));
79 else if (qAbs(pos - m_zoneEnd * m_factor) < 4) setCursor(KCursor("right_side", Qt::SizeHorCursor));
80 else if (qAbs(pos - (m_zoneStart + (m_zoneEnd - m_zoneStart) / 2) * m_factor) < 4) setCursor(Qt::SizeHorCursor);
81 else setCursor(Qt::ArrowCursor);
88 void KeyframeHelper::wheelEvent(QWheelEvent * e) {
90 if (e->modifiers() == Qt::ControlModifier) delta = m_timecode.fps();
91 if (e->delta() < 0) delta = 0 - delta;
92 m_view->moveCursorPos(delta);
97 void KeyframeHelper::paintEvent(QPaintEvent *e) {
98 QStylePainter p(this);
99 p.setClipRect(e->rect());
101 if (m_geom != NULL) {
103 Mlt::GeometryItem item;
104 for (int i = 0; i < m_geom->length(); i++) {
105 m_geom->next_key(&item, pos);
107 kDebug() << "++ PAINTING POS: " << pos;
108 int scaledPos = pos * width() / m_length;
109 p.fillRect(QRect(scaledPos - 1, 0, 2, 15), QBrush(QColor(255, 20, 20)));
115 void KeyframeHelper::setKeyGeometry(Mlt::Geometry *geom, const int length) {
118 kDebug() << "KEYFRAMES: " << m_geom->length() << ", TRANS SOZE: " << m_length;
122 #include "keyframehelper.moc"