From c8302a53f8c887d08c7154054bfa4f2436a51e41 Mon Sep 17 00:00:00 2001 From: Till Theato Date: Thu, 6 Jan 2011 10:43:18 +0000 Subject: [PATCH] Bezier Spline: Add checkable button show all handles: Whether to show handles for all points or only for the selected one. svn path=/trunk/kdenlive/; revision=5277 --- src/beziercurve/beziersplineeditor.cpp | 14 +++++++++++--- src/beziercurve/beziersplineeditor.h | 18 ++++++++++++++++++ src/beziercurve/beziersplinewidget.cpp | 13 ++++++++++++- src/beziercurve/beziersplinewidget.h | 2 ++ src/kdenlivesettings.kcfg | 5 +++++ src/widgets/bezierspline_ui.ui | 26 ++++++++++++++++++++++++-- 6 files changed, 72 insertions(+), 6 deletions(-) diff --git a/src/beziercurve/beziersplineeditor.cpp b/src/beziercurve/beziersplineeditor.cpp index 0b39b11e..eeaae3b0 100644 --- a/src/beziercurve/beziersplineeditor.cpp +++ b/src/beziercurve/beziersplineeditor.cpp @@ -27,6 +27,7 @@ BezierSplineEditor::BezierSplineEditor(QWidget* parent) : m_mode(ModeNormal), m_zoomLevel(0), m_gridLines(3), + m_showAllHandles(true), m_pixmapCache(NULL), m_pixmapIsDirty(true), m_currentPointIndex(-1) @@ -101,6 +102,12 @@ void BezierSplineEditor::slotZoomOut() update(); } +void BezierSplineEditor::setShowAllHandles(bool show) +{ + m_showAllHandles = show; + update(); +} + int BezierSplineEditor::gridLines() { return m_gridLines; @@ -228,7 +235,7 @@ void BezierSplineEditor::paintEvent(QPaintEvent* event) p.drawEllipse(QRectF(point.p.x() * wWidth - 3, wHeight - 3 - point.p.y() * wHeight, 6, 6)); - if (i != 0) { + if (i != 0 && (i == m_currentPointIndex || m_showAllHandles)) { #if QT_VERSION >= 0x040600 p.drawConvexPolygon(handle.translated(point.h1.x() * wWidth, wHeight - point.h1.y() * wHeight)); #else @@ -237,7 +244,7 @@ void BezierSplineEditor::paintEvent(QPaintEvent* event) p.drawConvexPolygon(tmp); #endif } - if (i != max) { + if (i != max && (i == m_currentPointIndex || m_showAllHandles)) { #if QT_VERSION >= 0x040600 p.drawConvexPolygon(handle.translated(point.h2.x() * wWidth, wHeight - point.h2.y() * wHeight)); #else @@ -462,7 +469,8 @@ int BezierSplineEditor::nearestPointInRange(QPointF p, int wWidth, int wHeight, ++i; } - if (nearestIndex >= 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]; if (qAbs(p.x() - point[(int)selectedPoint].x()) * wWidth < 5 && qAbs(p.y() - point[(int)selectedPoint].y()) * wHeight < 5) { *sel = selectedPoint; diff --git a/src/beziercurve/beziersplineeditor.h b/src/beziercurve/beziersplineeditor.h index 0320e319..819ac4f5 100644 --- a/src/beziercurve/beziersplineeditor.h +++ b/src/beziercurve/beziersplineeditor.h @@ -35,14 +35,26 @@ public: CubicBezierSpline spline(); void setSpline(const CubicBezierSpline &spline); + /** @brief Returns the selected point or else BPoint. */ BPoint getCurrentPoint(); + + /** @brief Replaces current point with @param p (index stays the same). */ void updateCurrentPoint(const BPoint &p); + /** @brief Number of lines used in grid. */ int gridLines(); + + /** @brief Sets the number of grid lines to draw (in one direction) to @param lines. */ void setGridLines(int lines); + /** @brief Sets the background pixmap to @param pixmap. */ void setPixmap(const QPixmap &pixmap); + /** @brief Sets the property showAllHandles to @param show. + * + * showAllHandles: Whether to show only handles for the selected point for all points. */ + void setShowAllHandles(bool show); + public slots: void slotZoomIn(); void slotZoomOut(); @@ -62,6 +74,8 @@ private: modes m_mode; int m_zoomLevel; int m_gridLines; + /** Whether to show only handles for the selected point for all points. */ + bool m_showAllHandles; QPixmap m_pixmap; QPixmap *m_pixmapCache; bool m_pixmapIsDirty; @@ -74,6 +88,10 @@ private: BPoint m_grabPNext; BPoint m_grabPPrevious; + /** @brief Finds the point nearest to @param p and returns it's index. + * @param sel Is filled with the type of the closest point (h1, p, h2) + * + * If no point is near enough -1 is returned. */ int nearestPointInRange(QPointF p, int wWidth, int wHeight, point_types *sel); signals: diff --git a/src/beziercurve/beziersplinewidget.cpp b/src/beziercurve/beziersplinewidget.cpp index d22fc02f..04ec3b64 100644 --- a/src/beziercurve/beziersplinewidget.cpp +++ b/src/beziercurve/beziersplinewidget.cpp @@ -24,9 +24,11 @@ #include + BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) : QWidget(parent), - m_mode(ModeRGB) + m_mode(ModeRGB), + m_showPixmap(true) { QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(&m_edit); @@ -40,6 +42,7 @@ BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) : m_ui.buttonGridChange->setIcon(KIcon("view-grid")); m_ui.buttonShowPixmap->setIcon(QIcon(QPixmap::fromImage(ColorTools::rgbCurvePlane(QSize(16, 16), ColorTools::COL_Luma, 0.8)))); m_ui.buttonResetSpline->setIcon(KIcon("view-refresh")); + m_ui.buttonShowAllHandles->setIcon(KIcon("draw-bezier-curves")); m_ui.widgetPoint->setEnabled(false); CubicBezierSpline s; @@ -62,9 +65,11 @@ BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) : connect(m_ui.buttonGridChange, SIGNAL(clicked()), this, SLOT(slotGridChange())); connect(m_ui.buttonShowPixmap, SIGNAL(toggled(bool)), this, SLOT(slotShowPixmap(bool))); connect(m_ui.buttonResetSpline, SIGNAL(clicked()), this, SLOT(slotResetSpline())); + connect(m_ui.buttonShowAllHandles, SIGNAL(toggled(bool)), this, SLOT(slotShowAllHandles(bool))); m_edit.setGridLines(KdenliveSettings::bezier_gridlines()); m_ui.buttonShowPixmap->setChecked(KdenliveSettings::bezier_showpixmap()); + m_ui.buttonShowAllHandles->setChecked(KdenliveSettings::bezier_showallhandles()); } QString BezierSplineWidget::spline() @@ -154,4 +159,10 @@ void BezierSplineWidget::slotResetSpline() m_edit.setSpline(CubicBezierSpline()); } +void BezierSplineWidget::slotShowAllHandles(bool show) +{ + m_edit.setShowAllHandles(show); + KdenliveSettings::setBezier_showallhandles(show); +} + #include "beziersplinewidget.moc" diff --git a/src/beziercurve/beziersplinewidget.h b/src/beziercurve/beziersplinewidget.h index ccdff198..e8717253 100644 --- a/src/beziercurve/beziersplinewidget.h +++ b/src/beziercurve/beziersplinewidget.h @@ -64,6 +64,8 @@ private slots: /** @brief Linkes the handles. This will always make them stay in one line through p. */ void slotSetHandlesLinked(bool linked); + void slotShowAllHandles(bool show); + private: Ui::BezierSpline_UI m_ui; BezierSplineEditor m_edit; diff --git a/src/kdenlivesettings.kcfg b/src/kdenlivesettings.kcfg index 2688ed73..2f4f5d38 100644 --- a/src/kdenlivesettings.kcfg +++ b/src/kdenlivesettings.kcfg @@ -499,6 +499,11 @@ true + + + + true + diff --git a/src/widgets/bezierspline_ui.ui b/src/widgets/bezierspline_ui.ui index 8727ad9f..f7c5f0b2 100644 --- a/src/widgets/bezierspline_ui.ui +++ b/src/widgets/bezierspline_ui.ui @@ -14,7 +14,7 @@ Form - + @@ -216,6 +216,9 @@ true + + true + true @@ -254,7 +257,7 @@ - + Qt::Horizontal @@ -280,6 +283,25 @@ + + + + Show handles for all points or only for the selected one + + + ... + + + true + + + true + + + true + + + -- 2.39.2