]> git.sesse.net Git - kdenlive/commitdiff
Allow to reset single effect parameters:
authorTill Theato <root@ttill.de>
Sun, 22 Aug 2010 09:08:27 +0000 (09:08 +0000)
committerTill Theato <root@ttill.de>
Sun, 22 Aug 2010 09:08:27 +0000 (09:08 +0000)
http://www.kdenlive.org/mantis/view.php?id=1753

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

src/doubleparameterwidget.cpp
src/doubleparameterwidget.h
src/effectstackedit.cpp
src/keyframeedit.cpp

index 28d32f161855f8da8813de9a485061ec3c2501b5..f876c07cb54e4f758f761992d4d9d9a046a17202 100644 (file)
 #include <QLabel>
 #include <QSlider>
 #include <QSpinBox>
+#include <QToolButton>
 
+#include <KIcon>
+#include <KLocalizedString>
 
-DoubleParameterWidget::DoubleParameterWidget(const QString &name, int value, int min, int max, const QString suffix, QWidget *parent) :
-        QWidget(parent)
+
+DoubleParameterWidget::DoubleParameterWidget(const QString &name, int value, int min, int max, int defaultValue, const QString suffix, QWidget *parent) :
+        QWidget(parent),
+        m_default(defaultValue)
 {
     QHBoxLayout *layout = new QHBoxLayout(this);
 
@@ -41,12 +46,20 @@ DoubleParameterWidget::DoubleParameterWidget(const QString &name, int value, int
 
     m_spinBox = new QSpinBox(this);
     m_spinBox->setRange(min, max);
+    m_spinBox->setKeyboardTracking(false);
     if (!suffix.isEmpty())
         m_spinBox->setSuffix(suffix);
     layout->addWidget(m_spinBox);
 
+    QToolButton *reset = new QToolButton(this);
+    reset->setAutoRaise(true);
+    reset->setIcon(KIcon("edit-undo"));
+    reset->setToolTip(i18n("Reset to default value"));
+    layout->addWidget(reset);
+
     connect(m_slider,  SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
     connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
+    connect(reset,     SIGNAL(clicked(bool)),     this, SLOT(slotReset()));
 
     m_spinBox->setValue(value);
 }
@@ -70,10 +83,14 @@ int DoubleParameterWidget::getValue()
     return m_spinBox->value();
 }
 
-
 void DoubleParameterWidget::setName(const QString& name)
 {
     m_name->setText(name);
 }
 
-#include "doubleparameterwidget.moc"
\ No newline at end of file
+void DoubleParameterWidget::slotReset()
+{
+    m_spinBox->setValue(m_default);
+}
+
+#include "doubleparameterwidget.moc"
index 448bbc8786ccaaec20acbdf3e918597c8121239f..23e757c8a0cb3028317291157f7c5f05aca5ddaa 100644 (file)
@@ -44,9 +44,10 @@ public:
     * @param value Value of the parameter
     * @param min Minimum value
     * @param max maximum value
+    * @param defaultValue Value used when using reset functionality
     * @param suffix (optional) Suffix to display in spinbox
     * @param parent (optional) Parent Widget */
-    DoubleParameterWidget(const QString &name, int value, int min, int max, const QString suffix = QString(), QWidget* parent = 0);
+    DoubleParameterWidget(const QString &name, int value, int min, int max, int defaultValue, const QString suffix = QString(), QWidget* parent = 0);
     /** @brief Updates the label to display @param name. */
     void setName(const QString &name);
     /** @brief Gets the parameter's value. */
@@ -56,7 +57,12 @@ public slots:
     /** @brief Sets the value to @param value. */
     void setValue(int value);
 
+private slots:
+    /** @brief Sets value to m_default. */
+    void slotReset();
+
 private:
+    int m_default;
     QLabel *m_name;
     QSlider *m_slider;
     QSpinBox *m_spinBox;
index 4bf8b97152245c6a1c7ea015e6572736665de801..5b87920d7570c8b3fd45487f2468aa0eb21c3a7c 100644 (file)
@@ -217,7 +217,8 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, int pos, int in, in
             else
                 max = pa.attribute("max").toInt();
 
-            DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, (int)(value.toDouble() + 0.5), min, max, pa.attribute("suffix", QString()), this);
+            DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, (int)(value.toDouble() + 0.5), min, max,
+                                                                           pa.attribute("default").toInt(), pa.attribute("suffix"), this);
             m_vbox->addWidget(doubleparam);
             m_valueItems[paramName] = doubleparam;
             connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters()));
index 71f9dde1409f5a343923a12f8f054ddaa0e2a8cf..b18d39fe11107001fb025158b080fff1f9ecf968 100644 (file)
@@ -16,6 +16,7 @@
  ***************************************************************************/
 
 #include "keyframeedit.h"
+#include "doubleparameterwidget.h"
 #include "kdenlivesettings.h"
 
 #include <KDebug>
@@ -89,11 +90,12 @@ void KeyframeEdit::addParameter(QDomElement e)
     int columnId = keyframe_list->columnCount();
     keyframe_list->insertColumn(columnId);
     keyframe_list->setHorizontalHeaderItem(columnId, new QTableWidgetItem(paramName));
-    m_slidersLayout->addWidget(new QLabel(paramName), columnId, 0);
-    QSlider *sl = new QSlider(Qt::Horizontal, this);
-    sl->setRange(m_params.at(columnId).attribute("min").toInt(), m_params.at(columnId).attribute("max").toInt());
-    connect(sl, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int)));
-    m_slidersLayout->addWidget(sl, columnId, 1);
+
+    DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, 0,
+                                                                   m_params.at(columnId).attribute("min").toInt(), m_params.at(columnId).attribute("max").toInt(),
+                                                                   m_params.at(columnId).attribute("default").toInt(), m_params.at(columnId).attribute("suffix"), this);
+    connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int)));
+    m_slidersLayout->addWidget(doubleparam, columnId, 0);
 
     QStringList frames = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
     for (int i = 0; i < frames.count(); i++) {
@@ -132,13 +134,14 @@ void KeyframeEdit::setupParam()
     kDebug() << " INSERT COL: " << col << ", " << paramName;
     keyframe_list->insertColumn(col);
     keyframe_list->setHorizontalHeaderItem(col, new QTableWidgetItem(paramName));
-    m_slidersLayout = new QGridLayout;
-    m_slidersLayout->addWidget(new QLabel(paramName), 0, 0);
-    QSlider *sl = new QSlider(Qt::Horizontal, this);
-    sl->setRange(m_params.at(0).attribute("min").toInt(), m_params.at(0).attribute("max").toInt());
-    connect(sl, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int)));
-    m_slidersLayout->addWidget(sl, 0, 1);
-    param_sliders->setLayout(m_slidersLayout);
+    m_slidersLayout = new QGridLayout(param_sliders);
+
+    DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, 0,
+                                                                   m_params.at(0).attribute("min").toInt(), m_params.at(0).attribute("max").toInt(),
+                                                                   m_params.at(0).attribute("default").toInt(), m_params.at(0).attribute("suffix"), this);
+    connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int)));
+    m_slidersLayout->addWidget(doubleparam, 0, 0);
+
     keyframe_list->setSelectionBehavior(QAbstractItemView::SelectRows);
     keyframe_list->setSelectionMode(QAbstractItemView::SingleSelection);
 
@@ -333,12 +336,12 @@ void KeyframeEdit::slotAdjustKeyframeInfo(bool seek)
     keyframe_pos->setValue(getPos(item->row()));
     keyframe_pos->blockSignals(false);
     for (int col = 0; col < keyframe_list->columnCount(); col++) {
-        QSlider *sl = static_cast <QSlider*>(m_slidersLayout->itemAtPosition(col, 1)->widget());
-        if (!sl)
+        DoubleParameterWidget *doubleparam = static_cast <DoubleParameterWidget*>(m_slidersLayout->itemAtPosition(col, 0)->widget());
+        if (!doubleparam)
             continue;
-        sl->blockSignals(true);
-        sl->setValue(keyframe_list->item(item->row(), col)->text().toInt());
-        sl->blockSignals(false);
+        doubleparam->blockSignals(true);
+        doubleparam->setValue(keyframe_list->item(item->row(), col)->text().toInt());
+        doubleparam->blockSignals(false);
     }
     if (KdenliveSettings::keyframeseek() && seek)
         emit seekToPos(keyframe_pos->value() - m_min);
@@ -357,10 +360,10 @@ void KeyframeEdit::slotAdjustKeyframeValue(int /*value*/)
 {
     QTableWidgetItem *item = keyframe_list->currentItem();
     for (int col = 0; col < keyframe_list->columnCount(); col++) {
-        QSlider *sl = static_cast <QSlider*>(m_slidersLayout->itemAtPosition(col, 1)->widget());
-        if (!sl)
+        DoubleParameterWidget *doubleparam = static_cast <DoubleParameterWidget*>(m_slidersLayout->itemAtPosition(col, 0)->widget());
+        if (!doubleparam)
             continue;
-        int val = sl->value();
+        int val = doubleparam->getValue();
         QTableWidgetItem *nitem = keyframe_list->item(item->row(), col);
         if (nitem->text().toInt() != val)
             nitem->setText(QString::number(val));