]> git.sesse.net Git - kdenlive/blob - src/beziercurve/beziersplineeditor.h
Integrate with the required MLT hooks for getting Movit to work.
[kdenlive] / src / beziercurve / beziersplineeditor.h
1 /***************************************************************************
2  *   Copyright (C) 2010 by Till Theato (root@ttill.de)                     *
3  *   This file is part of Kdenlive (www.kdenlive.org).                     *
4  *                                                                         *
5  *   Kdenlive is free software: you can redistribute it and/or modify      *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation, either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   Kdenlive is distributed in the hope that it will be useful,           *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with Kdenlive.  If not, see <http://www.gnu.org/licenses/>.     *
17  ***************************************************************************/
18
19 #ifndef BEZIERSPLINEEDITOR_H
20 #define BEZIERSPLINEEDITOR_H
21
22 #include "cubicbezierspline.h"
23
24 #include <QtCore>
25 #include <QWidget>
26
27 class BezierSplineEditor : public QWidget
28 {
29     Q_OBJECT
30
31 public:
32     explicit BezierSplineEditor(QWidget* parent = 0);
33     ~BezierSplineEditor();
34
35     CubicBezierSpline spline() const;
36     void setSpline(const CubicBezierSpline &spline);
37
38     /** @brief Returns the selected point or else BPoint. */
39     BPoint getCurrentPoint();
40
41     /** @brief Replaces current point with @param p (index stays the same).
42      * @param final (default = true) emit signal modified? */
43     void updateCurrentPoint(const BPoint &p, bool final = true);
44
45     /** @brief Number of lines used in grid. */
46     int gridLines() const;
47
48     /** @brief Sets the number of grid lines to draw (in one direction) to @param lines. */
49     void setGridLines(int lines);
50
51     /** @brief Sets the background pixmap to @param pixmap. */
52     void setPixmap(const QPixmap &pixmap);
53
54     /** @brief Sets the property showAllHandles to @param show.
55      *
56      * showAllHandles: Whether to show only handles for the selected point for all points. */
57     void setShowAllHandles(bool show);
58
59 public slots:
60     void slotZoomIn();
61     void slotZoomOut();
62
63 protected:
64     void paintEvent(QPaintEvent *event);
65     void mousePressEvent(QMouseEvent *event);
66     void mouseReleaseEvent(QMouseEvent * event);
67     void mouseMoveEvent(QMouseEvent * event);
68     void mouseDoubleClickEvent(QMouseEvent *event);
69     void leaveEvent(QEvent *event);
70     void resizeEvent(QResizeEvent *event);
71
72 private:
73     CubicBezierSpline m_spline;
74     enum modes { ModeDrag, ModeNormal };
75     enum point_types { PTypeH1, PTypeP, PTypeH2 };
76     modes m_mode;
77     int m_zoomLevel;
78     int m_gridLines;
79     /** Whether to show handles for all points or only for the selected one. */
80     bool m_showAllHandles;
81     /** Background */
82     QPixmap m_pixmap;
83     /** A copy of m_pixmap but scaled to fit the size of the edit region */
84     QPixmap *m_pixmapCache;
85     /** Whether we have to regenerate the pixmap cache because the pixmap or the size of the edit region changed. */
86     bool m_pixmapIsDirty;
87
88     int m_currentPointIndex;
89     point_types m_currentPointType;
90     double m_grabOffsetX;
91     double m_grabOffsetY;
92     /** selected point before it was modified by dragging (at the time of the mouse press) */
93     BPoint m_grabPOriginal;
94     /** point with the index currentPointIndex + 1 at the time of the mouse press */
95     BPoint m_grabPNext;
96     /** point with the index currentPointIndex - 1 at the time of the mouse press */
97     BPoint m_grabPPrevious;
98
99     /** @brief Finds the point nearest to @param p and returns it's index.
100      * @param sel Is filled with the type of the closest point (h1, p, h2)
101      *
102      * If no point is near enough -1 is returned. */
103     int nearestPointInRange(const QPointF &p, int wWidth, int wHeight, point_types *sel);
104
105 signals:
106     void modified();
107     void currentPoint(const BPoint &p);
108 };
109
110 #endif