]> git.sesse.net Git - kdenlive/blobdiff - src/beziercurve/beziersplineeditor.cpp
Bezier Spline: Add grid. Number of lines in the grid can be increased with a button...
[kdenlive] / src / beziercurve / beziersplineeditor.cpp
index 291a3d8248c82bdafc4fa99b76334fe880f564f5..af5b26ab17de8314d4138189e4c46631d77911b1 100644 (file)
@@ -25,6 +25,7 @@
 BezierSplineEditor::BezierSplineEditor(QWidget* parent) :
         QWidget(parent),
         m_zoomLevel(0),
+        m_gridLines(3),
         m_mode(ModeNormal),
         m_currentPointIndex(-1)
 {
@@ -76,6 +77,12 @@ void BezierSplineEditor::slotZoomOut()
     update();
 }
 
+void BezierSplineEditor::slotGridChange()
+{
+    m_gridLines = (m_gridLines + 1) % 9;
+    update();
+}
+
 void BezierSplineEditor::paintEvent(QPaintEvent* event)
 {
     Q_UNUSED(event);
@@ -96,14 +103,27 @@ void BezierSplineEditor::paintEvent(QPaintEvent* event)
     /*p.setPen(QPen(Qt::gray, 1, Qt::SolidLine));
     p.drawLine(QLineF(0, wHeight, wWidth, 0));*/
 
+    p.setPen(QPen(Qt::gray, 1, Qt::SolidLine));
+
+    /*
+     * Borders
+     */
     if (m_zoomLevel != 0) {
-        /*
-         * Borders
-         */
-        p.setPen(QPen(Qt::gray, 1, Qt::SolidLine));
         p.drawRect(offset, offset, wWidth, wHeight);
     }
 
+    /*
+     * Grid
+     */
+    if (m_gridLines != 0) {
+        double stepH = wWidth / (double)(m_gridLines + 1);
+        double stepV = wHeight / (double)(m_gridLines + 1);
+        for (int i = 1; i <= m_gridLines; ++i) {
+            p.drawLine(QLineF(i * stepH, 0, i * stepH, wHeight).translated(offset, offset));
+            p.drawLine(QLineF(0, i * stepV, wWidth, i * stepV).translated(offset, offset));
+        }
+    }
+
     /*
      * Spline
      */