***************************************************************************/
#include "beziersplineeditor.h"
+#include "kdenlivesettings.h"
#include <QPainter>
#include <QMouseEvent>
BezierSplineEditor::BezierSplineEditor(QWidget* parent) :
- QWidget(parent),
- m_mode(ModeNormal),
- m_zoomLevel(0),
- m_gridLines(3),
- m_showAllHandles(true),
- m_pixmapCache(NULL),
- m_pixmapIsDirty(true),
- m_currentPointIndex(-1)
+ QWidget(parent)
+ , m_mode(ModeNormal)
+ , m_zoomLevel(0)
+ , m_gridLines(3)
+ , m_showAllHandles(true)
+ , m_pixmapCache(NULL)
+ , m_pixmapIsDirty(true)
+ , m_currentPointIndex(-1)
+ , m_currentPointType(PTypeP)
+ , m_grabOffsetX(0)
+ , m_grabOffsetY(0)
{
setMouseTracking(true);
setAutoFillBackground(false);
BezierSplineEditor::~BezierSplineEditor()
{
- if (m_pixmapCache)
- delete m_pixmapCache;
+ delete m_pixmapCache;
}
-CubicBezierSpline BezierSplineEditor::spline()
+CubicBezierSpline BezierSplineEditor::spline() const
{
return m_spline;
}
BPoint BezierSplineEditor::getCurrentPoint()
{
if (m_currentPointIndex >= 0)
- return m_spline.points()[m_currentPointIndex];
+ return m_spline.getPoint(m_currentPointIndex);
else
return BPoint();
}
-void BezierSplineEditor::updateCurrentPoint(const BPoint& p)
+void BezierSplineEditor::updateCurrentPoint(const BPoint& p, bool final)
{
if (m_currentPointIndex >= 0) {
m_spline.setPoint(m_currentPointIndex, p);
// during validation the point might have changed
- emit currentPoint(m_spline.points()[m_currentPointIndex]);
- emit modified();
+ emit currentPoint(m_spline.getPoint(m_currentPointIndex));
+ if (final)
+ emit modified();
update();
}
}
void BezierSplineEditor::paintEvent(QPaintEvent* event)
{
- Q_UNUSED(event);
+ Q_UNUSED(event)
QPainter p(this);
--m_currentPointIndex;
update();
if (m_currentPointIndex >= 0)
- emit currentPoint(m_spline.points()[m_currentPointIndex]);
+ emit currentPoint(m_spline.getPoint(m_currentPointIndex));
else
emit currentPoint(BPoint());
emit modified();
m_currentPointType = selectedPoint;
}
- BPoint point = m_spline.points()[m_currentPointIndex];
+ BPoint point = m_spline.getPoint(m_currentPointIndex);
m_grabPOriginal = point;
if (m_currentPointIndex > 0)
- m_grabPPrevious = m_spline.points()[m_currentPointIndex - 1];
+ m_grabPPrevious = m_spline.getPoint(m_currentPointIndex - 1);
if (m_currentPointIndex < m_spline.points().count() - 1)
- m_grabPNext = m_spline.points()[m_currentPointIndex + 1];
+ m_grabPNext = m_spline.getPoint(m_currentPointIndex + 1);
m_grabOffsetX = point[(int)m_currentPointType].x() - x;
m_grabOffsetY = point[(int)m_currentPointType].y() - y;
double leftX = 0.;
double rightX = 1.;
- BPoint point = m_spline.points()[m_currentPointIndex];
+ BPoint point = m_spline.getPoint(m_currentPointIndex);
switch (m_currentPointType) {
case PTypeH1:
rightX = point.p.x();
if (m_currentPointIndex == 0)
leftX = -4;
else
- leftX = m_spline.points()[m_currentPointIndex - 1].p.x();
+ leftX = m_spline.getPoint(m_currentPointIndex - 1).p.x();
x = qBound(leftX, x, rightX);
point.setH1(QPointF(x, y));
if (m_currentPointIndex == m_spline.points().count() - 1)
rightX = 5;
else
- rightX = m_spline.points()[m_currentPointIndex + 1].p.x();
+ rightX = m_spline.getPoint(m_currentPointIndex + 1).p.x();
x = qBound(leftX, x, rightX);
point.setH2(QPointF(x, y));
m_spline.setPoint(index, m_grabPPrevious);
m_grabPNext = m_grabPPrevious;
if (m_currentPointIndex > 0)
- m_grabPPrevious = m_spline.points()[m_currentPointIndex - 1];
+ m_grabPPrevious = m_spline.getPoint(m_currentPointIndex - 1);
} else {
m_spline.setPoint(index, m_grabPNext);
m_grabPPrevious = m_grabPNext;
if (m_currentPointIndex < m_spline.points().count() - 1)
- m_grabPNext = m_spline.points()[m_currentPointIndex + 1];
+ m_grabPNext = m_spline.getPoint(m_currentPointIndex + 1);
}
}
}
emit currentPoint(point);
+ if (KdenliveSettings::dragvalue_directupdate())
+ emit modified();
update();
}
}
+void BezierSplineEditor::mouseDoubleClickEvent(QMouseEvent* /*event*/)
+{
+ if (m_currentPointIndex >= 0) {
+ BPoint p = m_spline.getPoint(m_currentPointIndex);
+ p.handlesLinked = !p.handlesLinked;
+ m_spline.setPoint(m_currentPointIndex, p);
+ emit currentPoint(p);
+ }
+}
+
void BezierSplineEditor::leaveEvent(QEvent* event)
{
QWidget::leaveEvent(event);
int BezierSplineEditor::nearestPointInRange(QPointF p, int wWidth, int wHeight, BezierSplineEditor::point_types* sel)
{
double nearestDistanceSquared = 1000;
- point_types selectedPoint;
+ point_types selectedPoint = PTypeP;
int nearestIndex = -1;
int i = 0;
if (nearestIndex >= 0 && (nearestIndex == m_currentPointIndex || selectedPoint == PTypeP || m_showAllHandles)) {
// a point was found and it is not a hidden handle
- BPoint point = m_spline.points()[nearestIndex];
+ BPoint point = m_spline.getPoint(nearestIndex);
if (qAbs(p.x() - point[(int)selectedPoint].x()) * wWidth < 5 && qAbs(p.y() - point[(int)selectedPoint].y()) * wHeight < 5) {
*sel = selectedPoint;
return nearestIndex;