1 /***************************************************************************
2 * Copyright (C) 2010 by Till Theato (root@ttill.de) *
3 * This file is part of Kdenlive (www.kdenlive.org). *
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. *
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. *
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 ***************************************************************************/
19 #ifndef BEZIERSPLINEEDITOR_H
20 #define BEZIERSPLINEEDITOR_H
22 #include "cubicbezierspline.h"
27 class BezierSplineEditor : public QWidget
32 BezierSplineEditor(QWidget* parent = 0);
33 virtual ~BezierSplineEditor();
35 CubicBezierSpline spline();
36 void setSpline(const CubicBezierSpline &spline);
38 /** @brief Returns the selected point or else BPoint. */
39 BPoint getCurrentPoint();
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);
45 /** @brief Number of lines used in grid. */
48 /** @brief Sets the number of grid lines to draw (in one direction) to @param lines. */
49 void setGridLines(int lines);
51 /** @brief Sets the background pixmap to @param pixmap. */
52 void setPixmap(const QPixmap &pixmap);
54 /** @brief Sets the property showAllHandles to @param show.
56 * showAllHandles: Whether to show only handles for the selected point for all points. */
57 void setShowAllHandles(bool show);
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);
73 CubicBezierSpline m_spline;
74 enum modes { ModeDrag, ModeNormal };
75 enum point_types { PTypeH1, PTypeP, PTypeH2 };
79 /** Whether to show handles for all points or only for the selected one. */
80 bool m_showAllHandles;
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. */
88 int m_currentPointIndex;
89 point_types m_currentPointType;
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 */
96 /** point with the index currentPointIndex - 1 at the time of the mouse press */
97 BPoint m_grabPPrevious;
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)
102 * If no point is near enough -1 is returned. */
103 int nearestPointInRange(QPointF p, int wWidth, int wHeight, point_types *sel);
107 void currentPoint(const BPoint &p);