]> git.sesse.net Git - kdenlive/blob - src/keyframehelper.cpp
First steps to a working composite transition
[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 <KIcon>
25 #include <KCursor>
26 #include <KGlobalSettings>
27
28 #include "keyframehelper.h"
29
30 #include "definitions.h"
31
32
33 KeyframeHelper::KeyframeHelper(QWidget *parent)
34         : QWidget(parent), m_geom(NULL) {
35     setFont(KGlobalSettings::toolBarFont());
36
37 }
38
39 // virtual
40 void KeyframeHelper::mousePressEvent(QMouseEvent * event) {
41     /*    if (event->button() == Qt::RightButton) {
42             m_contextMenu->exec(event->globalPos());
43             return;
44         }
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;
52         }
53         if (m_moveCursor == RULER_CURSOR)
54             m_view->setCursorPos((int) pos / m_factor);
55     */
56 }
57
58 // virtual
59 void KeyframeHelper::mouseMoveEvent(QMouseEvent * event) {
60     /*    if (event->buttons() == Qt::LeftButton) {
61             int pos = (int)((event->x() + offset()) / m_factor);
62             if (pos < 0) pos = 0;
63             if (m_moveCursor == RULER_CURSOR) {
64                 m_view->setCursorPos(pos);
65                 return;
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);
70                 m_zoneStart += move;
71                 m_zoneEnd += move;
72             }
73             m_view->setDocumentModified();
74             update();
75         } else {
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);
82         }
83     */
84 }
85
86
87 // virtual
88 void KeyframeHelper::wheelEvent(QWheelEvent * e) {
89     /*    int delta = 1;
90         if (e->modifiers() == Qt::ControlModifier) delta = m_timecode.fps();
91         if (e->delta() < 0) delta = 0 - delta;
92         m_view->moveCursorPos(delta);
93     */
94 }
95
96 // virtual
97 void KeyframeHelper::paintEvent(QPaintEvent *e) {
98     QStylePainter p(this);
99     p.setClipRect(e->rect());
100
101     if (m_geom != NULL) {
102         int pos = 0;
103         Mlt::GeometryItem item;
104         for (int i = 0; i < m_geom->length(); i++) {
105             m_geom->next_key(&item, pos);
106             pos = item.frame();
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)));
110             pos++;
111         }
112     }
113 }
114
115 void KeyframeHelper::setKeyGeometry(Mlt::Geometry *geom, const int length) {
116     m_geom = geom;
117     m_length = length;
118     kDebug() << "KEYFRAMES: " << m_geom->length() << ", TRANS SOZE: " << m_length;
119     update();
120 }
121
122 #include "keyframehelper.moc"