]> git.sesse.net Git - kdenlive/blob - src/beziercurve/beziersplineeditor.h
4660fca894cd39551ed1dede97609b7d85a5d6ae
[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     BezierSplineEditor(QWidget* parent = 0);
33     virtual ~BezierSplineEditor();
34
35     CubicBezierSpline spline();
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     void updateCurrentPoint(const BPoint &p);
43
44     /** @brief Number of lines used in grid. */
45     int gridLines();
46
47     /** @brief Sets the number of grid lines to draw (in one direction) to @param lines. */
48     void setGridLines(int lines);
49
50     /** @brief Sets the background pixmap to @param pixmap. */
51     void setPixmap(const QPixmap &pixmap);
52
53     /** @brief Sets the property showAllHandles to @param show.
54      *
55      * showAllHandles: Whether to show only handles for the selected point for all points. */
56     void setShowAllHandles(bool show);
57
58 public slots:
59     void slotZoomIn();
60     void slotZoomOut();
61
62 protected:
63     void paintEvent(QPaintEvent *event);
64     void mousePressEvent(QMouseEvent *event);
65     void mouseReleaseEvent(QMouseEvent * event);
66     void mouseMoveEvent(QMouseEvent * event);
67     void mouseDoubleClickEvent(QMouseEvent *event);
68     void leaveEvent(QEvent *event);
69     void resizeEvent(QResizeEvent *event);
70
71 private:
72     CubicBezierSpline m_spline;
73     enum modes { ModeDrag, ModeNormal };
74     enum point_types { PTypeH1, PTypeP, PTypeH2 };
75     modes m_mode;
76     int m_zoomLevel;
77     int m_gridLines;
78     /** Whether to show handles for all points or only for the selected one. */
79     bool m_showAllHandles;
80     /** Background */
81     QPixmap m_pixmap;
82     /** A copy of m_pixmap but scaled to fit the size of the edit region */
83     QPixmap *m_pixmapCache;
84     /** Whether we have to regenerate the pixmap cache because the pixmap or the size of the edit region changed. */
85     bool m_pixmapIsDirty;
86
87     int m_currentPointIndex;
88     point_types m_currentPointType;
89     double m_grabOffsetX;
90     double m_grabOffsetY;
91     /** selected point before it was modified by dragging (at the time of the mouse press) */
92     BPoint m_grabPOriginal;
93     /** point with the index currentPointIndex + 1 at the time of the mouse press */
94     BPoint m_grabPNext;
95     /** point with the index currentPointIndex - 1 at the time of the mouse press */
96     BPoint m_grabPPrevious;
97
98     /** @brief Finds the point nearest to @param p and returns it's index.
99      * @param sel Is filled with the type of the closest point (h1, p, h2)
100      *
101      * If no point is near enough -1 is returned. */
102     int nearestPointInRange(QPointF p, int wWidth, int wHeight, point_types *sel);
103
104 signals:
105     void modified();
106     void currentPoint(const BPoint &p);
107 };
108
109 #endif