]> git.sesse.net Git - kdenlive/commitdiff
Bezier spline widget: use DragValue instead of SpinBoxes, range 0-1 with 3 decimals...
authorTill Theato <root@ttill.de>
Sat, 5 Mar 2011 21:46:48 +0000 (21:46 +0000)
committerTill Theato <root@ttill.de>
Sat, 5 Mar 2011 21:46:48 +0000 (21:46 +0000)
DragValue: enable custom steps

svn path=/trunk/kdenlive/; revision=5477

src/beziercurve/beziersplinewidget.cpp
src/beziercurve/beziersplinewidget.h
src/dragvalue.cpp
src/dragvalue.h
src/widgets/bezierspline_ui.ui

index f351420b040ea7c0288941331d15ea3c539a8db9..1e286441ecd5309709a51d2a99c5796f1fdf890b 100644 (file)
 
 #include "beziersplinewidget.h"
 #include "colortools.h"
+#include "dragvalue.h"
 #include "kdenlivesettings.h"
 
 #include <QVBoxLayout>
 
 #include <KIcon>
+#include <KLocale>
 
 
 BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) :
@@ -45,6 +47,34 @@ BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) :
     m_ui.buttonShowAllHandles->setIcon(KIcon("draw-bezier-curves"));
     m_ui.widgetPoint->setEnabled(false);
 
+    m_pX = new DragValue(i18n("In"), 0, 3, -1, QString(), false, this);
+    m_pX->setRange(0, 1);
+    m_pX->setStep(0.001);
+    m_pY = new DragValue(i18n("Out"), 0, 3, -1, QString(), false, this);
+    m_pY->setRange(0, 1);
+    m_pY->setStep(0.001);
+    m_h1X = new DragValue(i18n("X"), 0, 3, -1, QString(), false, this);
+    m_h1X->setRange(-2, 2);
+    m_h1X->setStep(0.001);
+    m_h1Y = new DragValue(i18n("Y"), 0, 3, -1, QString(), false, this);
+    m_h1Y->setRange(-2, 2);
+    m_h1Y->setStep(0.001);
+    m_h2X = new DragValue(i18n("X"), 0, 3, -1, QString(), false, this);
+    m_h2X->setRange(-2, 2);
+    m_h2X->setStep(0.001);
+    m_h2Y = new DragValue(i18n("Y"), 0, 3, -1, QString(), false, this);
+    m_h2Y->setRange(-2, 2);
+    m_h2Y->setStep(0.001);
+
+    m_ui.layoutP->addWidget(m_pX);
+    m_ui.layoutP->addWidget(m_pY);
+    m_ui.layoutH1->addWidget(new QLabel(i18n("Handle 1:")));
+    m_ui.layoutH1->addWidget(m_h1X);
+    m_ui.layoutH1->addWidget(m_h1Y);
+    m_ui.layoutH2->addWidget(new QLabel(i18n("Handle 2:")));
+    m_ui.layoutH2->addWidget(m_h2X);
+    m_ui.layoutH2->addWidget(m_h2Y);
+
     CubicBezierSpline s;
     s.fromString(spline);
     m_edit.setSpline(s);
@@ -52,12 +82,12 @@ BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) :
     connect(&m_edit, SIGNAL(modified()), this, SIGNAL(modified()));
     connect(&m_edit, SIGNAL(currentPoint(const BPoint&)), this, SLOT(slotUpdatePointEntries(const BPoint&)));
 
-    connect(m_ui.spinPX, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointP()));
-    connect(m_ui.spinPY, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointP()));
-    connect(m_ui.spinH1X, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointH1()));
-    connect(m_ui.spinH1Y, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointH1()));
-    connect(m_ui.spinH2X, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointH2()));
-    connect(m_ui.spinH2Y, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointH2()));
+    connect(m_pX, SIGNAL(valueChanged(double, bool)), this, SLOT(slotUpdatePointP()));
+    connect(m_pY, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointP()));
+    connect(m_h1X, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH1()));
+    connect(m_h1Y, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH1()));
+    connect(m_h2X, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH2()));
+    connect(m_h2Y, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH2()));
 
     connect(m_ui.buttonLinkHandles, SIGNAL(toggled(bool)), this, SLOT(slotSetHandlesLinked(bool)));
     connect(m_ui.buttonZoomIn, SIGNAL(clicked()), &m_edit, SLOT(slotZoomIn()));
@@ -99,6 +129,8 @@ void BezierSplineWidget::slotShowPixmap(bool show)
     KdenliveSettings::setBezier_showpixmap(show);
     if (show && (int)m_mode < 6)
         m_edit.setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(m_edit.size(), (ColorTools::ColorsRGB)((int)m_mode), 1, palette().background().color().rgb())));
+//     else if (show && m_mode == ModeHue)
+//         m_edit.setPixmap(QPixmap::fromImage(ColorTools::hsvHueShiftPlane(m_edit.size(), 200, 200, 0, 360)));
     else
         m_edit.setPixmap(QPixmap());
 }
@@ -110,12 +142,24 @@ void BezierSplineWidget::slotUpdatePointEntries(const BPoint &p)
         m_ui.widgetPoint->setEnabled(false);
     } else {
         m_ui.widgetPoint->setEnabled(true);
-        m_ui.spinPX->setValue(qRound(p.p.x() * 255));
-        m_ui.spinPY->setValue(qRound(p.p.y() * 255));
-        m_ui.spinH1X->setValue(qRound(p.h1.x() * 255));
-        m_ui.spinH1Y->setValue(qRound(p.h1.y() * 255));
-        m_ui.spinH2X->setValue(qRound(p.h2.x() * 255));
-        m_ui.spinH2Y->setValue(qRound(p.h2.y() * 255));
+        m_pX->blockSignals(true);
+        m_pY->blockSignals(true);
+        m_h1X->blockSignals(true);
+        m_h1Y->blockSignals(true);
+        m_h2X->blockSignals(true);
+        m_h2Y->blockSignals(true);
+        m_pX->setValue(p.p.x());
+        m_pY->setValue(p.p.y());
+        m_h1X->setValue(p.h1.x());
+        m_h1Y->setValue(p.h1.y());
+        m_h2X->setValue(p.h2.x());
+        m_h2Y->setValue(p.h2.y());
+        m_pX->blockSignals(false);
+        m_pY->blockSignals(false);
+        m_h1X->blockSignals(false);
+        m_h1Y->blockSignals(false);
+        m_h2X->blockSignals(false);
+        m_h2Y->blockSignals(false);
         m_ui.buttonLinkHandles->setChecked(p.handlesLinked);
     }
     blockSignals(false);
@@ -125,7 +169,7 @@ void BezierSplineWidget::slotUpdatePointP()
 {
     BPoint p = m_edit.getCurrentPoint();
 
-    p.setP(QPointF(m_ui.spinPX->value() / 255., m_ui.spinPY->value() / 255.));
+    p.setP(QPointF(m_pX->value(), m_pY->value()));
 
     m_edit.updateCurrentPoint(p);
 }
@@ -134,7 +178,7 @@ void BezierSplineWidget::slotUpdatePointH1()
 {
     BPoint p = m_edit.getCurrentPoint();
 
-    p.setH1(QPointF(m_ui.spinH1X->value() / 255., m_ui.spinH1Y->value() / 255.));
+    p.setH1(QPointF(m_h1X->value(), m_h1Y->value()));
 
     m_edit.updateCurrentPoint(p);
 }
@@ -143,7 +187,7 @@ void BezierSplineWidget::slotUpdatePointH2()
 {
     BPoint p = m_edit.getCurrentPoint();
 
-    p.setH2(QPointF(m_ui.spinH2X->value() / 255., m_ui.spinH2Y->value() / 255.));
+    p.setH2(QPointF(m_h2X->value(), m_h2Y->value()));
 
     m_edit.updateCurrentPoint(p);
 }
index e871725317ff9e56e242b180beece55975e34a17..ee8935fcd51d8059ba38c2b5ef2dfdd61ced08bf 100644 (file)
@@ -26,6 +26,8 @@
 #include <QtCore>
 #include <QWidget>
 
+class DragValue;
+
 class BezierSplineWidget : public QWidget
 {
     Q_OBJECT
@@ -68,6 +70,12 @@ private slots:
 
 private:
     Ui::BezierSpline_UI m_ui;
+    DragValue *m_pX;
+    DragValue *m_pY;
+    DragValue *m_h1X;
+    DragValue *m_h1Y;
+    DragValue *m_h2X;
+    DragValue *m_h2Y;
     BezierSplineEditor m_edit;
     CurveModes m_mode;
     bool m_showPixmap;
index 9ba6f2e59eabb0efb92eec9bb1175772c71f1784..dd4b3cd59e5e8083d12f2a7208051bf5d485f12a 100644 (file)
@@ -41,6 +41,7 @@
 #include <KLocalizedString>
 #include <KGlobalSettings>
 
+
 DragValue::DragValue(const QString &label, double defaultValue, int decimals, int id, const QString suffix, bool showSlider, QWidget* parent) :
         QWidget(parent),
         m_maximum(100),
@@ -210,9 +211,13 @@ void DragValue::setPrecision(int /*precision*/)
         m_edit->setValidator(new QDoubleValidator(m_minimum, m_maximum, precision, this));*/
 }
 
-void DragValue::setStep(qreal /*step*/)
+void DragValue::setStep(qreal step)
 {
-    //m_step = step;
+    m_label->setStep(step);
+    if (m_intEdit)
+        m_intEdit->setSingleStep(step);
+    else
+        m_doubleEdit->setSingleStep(step);
 }
 
 void DragValue::slotReset()
@@ -383,7 +388,7 @@ void CustomLabel::mouseMoveEvent(QMouseEvent* e)
                 if (KdenliveSettings::dragvalue_mode() == 2)
                     diff = (diff > 0 ? 1 : -1) * pow(diff, 2);
 
-                int nv = m_value + diff / m_step;
+                double nv = m_value + diff * m_step;
                 if (nv != m_value) setNewValue(nv, KdenliveSettings::dragvalue_directupdate());
             }
             else {
@@ -424,13 +429,13 @@ void CustomLabel::mouseReleaseEvent(QMouseEvent* e)
 void CustomLabel::wheelEvent(QWheelEvent* e)
 {
     if (e->delta() > 0) {
-        if (e->modifiers() == Qt::ControlModifier) slotValueInc(10);
-        else if (e->modifiers() == Qt::AltModifier) slotValueInc(1.0 / m_precision);
+        if (e->modifiers() == Qt::ControlModifier) slotValueInc(m_step * 10);
+        else if (e->modifiers() == Qt::AltModifier) slotValueInc(m_step / m_precision);
         else slotValueInc();
     }
     else {
-        if (e->modifiers() == Qt::ControlModifier) slotValueDec(10);
-        else if (e->modifiers() == Qt::AltModifier) slotValueDec(1.0 / m_precision);
+        if (e->modifiers() == Qt::ControlModifier) slotValueDec(m_step * 10);
+        else if (e->modifiers() == Qt::AltModifier) slotValueDec(m_step / m_precision);
         else slotValueDec();
     }
     e->accept();
@@ -459,5 +464,10 @@ void CustomLabel::setNewValue(double value, bool update)
     emit valueChanged(value, update);
 }
 
+void CustomLabel::setStep(double step)
+{
+    m_step = step;
+}
+
 #include "dragvalue.moc"
 
index 95b95bde86db630636aa24c8713a0362b7684095..53adb2b8b3e639c2785584eb463e2283807ef50f 100644 (file)
@@ -40,6 +40,7 @@ class CustomLabel : public QProgressBar
 public:
     CustomLabel(const QString &label, bool showSlider = true, int precision = 0, QWidget *parent = 0);
     void setProgressValue(double value);
+    void setStep(double step);
     
 protected:
     //virtual void mouseDoubleClickEvent(QMouseEvent * event);
index efac92ae9237d240262bc6b08f0f2f3634d636d8..276fbb2a3b30fe2385580433ac7b2f6a4728d0c1 100644 (file)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>345</width>
-    <height>67</height>
+    <height>75</height>
    </rect>
   </property>
   <property name="windowTitle">
    </property>
    <item row="1" column="0" colspan="9">
     <widget class="QWidget" name="widgetPoint" native="true">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Maximum">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
      <layout class="QGridLayout" name="gridLayout_2">
       <property name="margin">
        <number>0</number>
@@ -29,7 +35,7 @@
       <property name="spacing">
        <number>0</number>
       </property>
-      <item row="0" column="0" colspan="9">
+      <item row="0" column="0" colspan="7">
        <widget class="QWidget" name="widget" native="true">
         <layout class="QHBoxLayout" name="horizontalLayout">
          <property name="margin">
           </spacer>
          </item>
          <item>
-          <widget class="QSpinBox" name="spinPX">
-           <property name="toolTip">
-            <string>Point In</string>
-           </property>
-           <property name="maximum">
-            <number>255</number>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QLabel" name="label">
-           <property name="text">
-            <string>Point</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QSpinBox" name="spinPY">
-           <property name="toolTip">
-            <string>Point Out</string>
-           </property>
-           <property name="maximum">
-            <number>255</number>
-           </property>
-          </widget>
+          <layout class="QHBoxLayout" name="layoutP"/>
          </item>
          <item>
           <spacer name="horizontalSpacer_2">
         </layout>
        </widget>
       </item>
-      <item row="1" column="0">
-       <widget class="QSpinBox" name="spinH1X">
-        <property name="toolTip">
-         <string>Handle 1 X</string>
-        </property>
-        <property name="minimum">
-         <number>-100</number>
-        </property>
-        <property name="maximum">
-         <number>400</number>
-        </property>
-       </widget>
-      </item>
-      <item row="1" column="1">
-       <widget class="QLabel" name="label_2">
-        <property name="toolTip">
-         <string>Handle 1</string>
-        </property>
-        <property name="text">
-         <string>H1</string>
-        </property>
-       </widget>
-      </item>
       <item row="1" column="2">
-       <widget class="QSpinBox" name="spinH1Y">
-        <property name="toolTip">
-         <string>Handle 1 Y</string>
-        </property>
-        <property name="minimum">
-         <number>-100</number>
-        </property>
-        <property name="maximum">
-         <number>400</number>
-        </property>
-        <property name="value">
-         <number>0</number>
-        </property>
-       </widget>
-      </item>
-      <item row="1" column="3">
        <spacer name="horizontalSpacer_3">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
        </spacer>
       </item>
-      <item row="1" column="4">
+      <item row="1" column="3">
        <widget class="QToolButton" name="buttonLinkHandles">
         <property name="toolTip">
          <string>Link the handles' position.&lt;br /&gt;Results in a natural spline.</string>
         </property>
        </widget>
       </item>
-      <item row="1" column="5">
+      <item row="1" column="4">
        <spacer name="horizontalSpacer_4">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
        </spacer>
       </item>
-      <item row="1" column="6">
-       <widget class="QSpinBox" name="spinH2X">
-        <property name="toolTip">
-         <string>Handle 2 X</string>
-        </property>
-        <property name="minimum">
-         <number>-100</number>
-        </property>
-        <property name="maximum">
-         <number>400</number>
-        </property>
-       </widget>
-      </item>
-      <item row="1" column="7">
-       <widget class="QLabel" name="label_3">
-        <property name="toolTip">
-         <string>Handle 2</string>
-        </property>
-        <property name="text">
-         <string>H2</string>
-        </property>
-       </widget>
+      <item row="1" column="1">
+       <layout class="QHBoxLayout" name="layoutH1"/>
       </item>
-      <item row="1" column="8">
-       <widget class="QSpinBox" name="spinH2Y">
-        <property name="toolTip">
-         <string>Handle 2 Y</string>
-        </property>
-        <property name="minimum">
-         <number>-100</number>
-        </property>
-        <property name="maximum">
-         <number>400</number>
-        </property>
-       </widget>
+      <item row="1" column="5">
+       <layout class="QHBoxLayout" name="layoutH2"/>
       </item>
      </layout>
     </widget>