]> git.sesse.net Git - kdenlive/commitdiff
Bezier Spline: Add checkable button show all handles: Whether to show handles for...
authorTill Theato <root@ttill.de>
Thu, 6 Jan 2011 10:43:18 +0000 (10:43 +0000)
committerTill Theato <root@ttill.de>
Thu, 6 Jan 2011 10:43:18 +0000 (10:43 +0000)
svn path=/trunk/kdenlive/; revision=5277

src/beziercurve/beziersplineeditor.cpp
src/beziercurve/beziersplineeditor.h
src/beziercurve/beziersplinewidget.cpp
src/beziercurve/beziersplinewidget.h
src/kdenlivesettings.kcfg
src/widgets/bezierspline_ui.ui

index 0b39b11e083409a215b9da93c920e245567efa69..eeaae3b0ae9edbbca9c0fd290e5b1cd59505716f 100644 (file)
@@ -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;
index 0320e3197f36f1542289365235f99d038b757363..819ac4f50c66f3943cb314217919bfc5151295e5 100644 (file)
@@ -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:
index d22fc02f80aca3eccc0ab7006f04541f2ba7b226..04ec3b64ef72025f58a278e59167f0c7279de6aa 100644 (file)
 
 #include <KIcon>
 
+
 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"
index ccdff1983d5fd103297a6c918b75d0b1cbf2f844..e871725317ff9e56e242b180beece55975e34a17 100644 (file)
@@ -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;
index 2688ed73d0a27be78725d7e0841ce62fa4e10a35..2f4f5d3828af7dc25fcb33b94d7a1355905951bc 100644 (file)
       <label>Should a background indicating the changes caused by curve manipulation be shown.</label>
       <default>true</default>
     </entry>
+
+    <entry name="bezier_showallhandles" type="Bool">
+      <label>Show handles for all points or only for the selected one.</label>
+      <default>true</default>
+    </entry>
   </group>
 
 
index 8727ad9f1af51db2b6b95d4c3d6e1c093e480528..f7c5f0b2ba50a12a8259fbff176b149bc80dcf2d 100644 (file)
@@ -14,7 +14,7 @@
    <string>Form</string>
   </property>
   <layout class="QGridLayout" name="gridLayout">
-   <item row="1" column="0" colspan="7">
+   <item row="1" column="0" colspan="8">
     <widget class="QWidget" name="widgetPoint" native="true">
      <layout class="QGridLayout" name="gridLayout_2">
       <property name="margin">
      <property name="checkable">
       <bool>true</bool>
      </property>
+     <property name="checked">
+      <bool>true</bool>
+     </property>
      <property name="autoRaise">
       <bool>true</bool>
      </property>
      </property>
     </widget>
    </item>
-   <item row="2" column="6">
+   <item row="2" column="7">
     <spacer name="spacer">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
     </widget>
    </item>
+   <item row="2" column="6">
+    <widget class="QToolButton" name="buttonShowAllHandles">
+     <property name="toolTip">
+      <string>Show handles for all points or only for the selected one</string>
+     </property>
+     <property name="text">
+      <string>...</string>
+     </property>
+     <property name="checkable">
+      <bool>true</bool>
+     </property>
+     <property name="checked">
+      <bool>true</bool>
+     </property>
+     <property name="autoRaise">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>