From daeb7e290bcadae72e34ea8f84aed02908bcc839 Mon Sep 17 00:00:00 2001 From: Till Theato Date: Sun, 2 Jan 2011 12:59:00 +0000 Subject: [PATCH] Bezier Spline: Add grid. Number of lines in the grid can be increased with a button. After 8 lines are reached the number is set to 0 (lines mod 9). svn path=/trunk/kdenlive/; revision=5238 --- src/beziercurve/beziersplineeditor.cpp | 28 ++++++++++++++++++++++---- src/beziercurve/beziersplineeditor.h | 2 ++ src/beziercurve/beziersplinewidget.cpp | 2 ++ src/widgets/bezierspline_ui.ui | 21 +++++++++++++++---- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/beziercurve/beziersplineeditor.cpp b/src/beziercurve/beziersplineeditor.cpp index 291a3d82..af5b26ab 100644 --- a/src/beziercurve/beziersplineeditor.cpp +++ b/src/beziercurve/beziersplineeditor.cpp @@ -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 */ diff --git a/src/beziercurve/beziersplineeditor.h b/src/beziercurve/beziersplineeditor.h index 68fb7b6e..b4dfe7ae 100644 --- a/src/beziercurve/beziersplineeditor.h +++ b/src/beziercurve/beziersplineeditor.h @@ -40,6 +40,7 @@ public: public slots: void slotZoomIn(); void slotZoomOut(); + void slotGridChange(); protected: //void keyPressEvent(QKeyEvent *event); @@ -56,6 +57,7 @@ private: enum point_types { PTypeH1, PTypeP, PTypeH2 }; modes m_mode; int m_zoomLevel; + int m_gridLines; int m_currentPointIndex; point_types m_currentPointType; double m_grabOffsetX; diff --git a/src/beziercurve/beziersplinewidget.cpp b/src/beziercurve/beziersplinewidget.cpp index b2491c75..36eb6cc7 100644 --- a/src/beziercurve/beziersplinewidget.cpp +++ b/src/beziercurve/beziersplinewidget.cpp @@ -35,6 +35,7 @@ BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) : m_ui.buttonLinkHandles->setEnabled(false); m_ui.buttonZoomIn->setIcon(KIcon("zoom-in")); m_ui.buttonZoomOut->setIcon(KIcon("zoom-out")); + m_ui.buttonGridChange->setIcon(KIcon("view-grid")); m_ui.widgetPoint->setEnabled(false); CubicBezierSpline s; @@ -53,6 +54,7 @@ BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) : connect(m_ui.buttonZoomIn, SIGNAL(clicked()), &m_edit, SLOT(slotZoomIn())); connect(m_ui.buttonZoomOut, SIGNAL(clicked()), &m_edit, SLOT(slotZoomOut())); + connect(m_ui.buttonGridChange, SIGNAL(clicked()), &m_edit, SLOT(slotGridChange())); } QString BezierSplineWidget::spline() diff --git a/src/widgets/bezierspline_ui.ui b/src/widgets/bezierspline_ui.ui index e0cbb66a..53c6e909 100644 --- a/src/widgets/bezierspline_ui.ui +++ b/src/widgets/bezierspline_ui.ui @@ -14,7 +14,7 @@ Form - + @@ -199,7 +199,7 @@ - + ... @@ -209,7 +209,7 @@ - + ... @@ -219,7 +219,7 @@ - + Qt::Horizontal @@ -232,6 +232,19 @@ + + + + Increases the number of lines in the grid.<br />After 8 lines it will begin from 0 again. + + + ... + + + true + + + -- 2.39.2