From: Jean-Baptiste Mardelle Date: Tue, 8 Feb 2011 22:24:26 +0000 (+0000) Subject: Commit my changes to Till's slider widget for effect stack X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=7c7ab29f851cbc41b3738744eb12061e43976f84;p=kdenlive Commit my changes to Till's slider widget for effect stack svn path=/trunk/kdenlive/; revision=5384 --- diff --git a/src/doubleparameterwidget.cpp b/src/doubleparameterwidget.cpp index 96a80c0d..65baf591 100644 --- a/src/doubleparameterwidget.cpp +++ b/src/doubleparameterwidget.cpp @@ -1,4 +1,4 @@ -/*************************************************************************** +/************************************************************************** * Copyright (C) 2010 by Till Theato (root@ttill.de) * * * * This program is free software; you can redistribute it and/or modify * @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -31,100 +30,78 @@ #include -DoubleParameterWidget::DoubleParameterWidget(const QString &name, int value, int min, int max, int defaultValue, const QString &comment, const QString suffix, QWidget *parent) : +DoubleParameterWidget::DoubleParameterWidget(const QString &name, int value, int min, int max, int defaultValue, const QString &comment, int id, const QString suffix, QWidget *parent) : QWidget(parent), - m_default(defaultValue) + m_commentLabel(NULL) { + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum); QGridLayout *layout = new QGridLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); - - m_name = new QLabel(name, this); - layout->addWidget(m_name, 0, 0); - - m_slider = new QSlider(Qt::Horizontal, this); - m_slider->setRange(min, max); - //m_slider->setPageStep((max - min) / 10); - layout->addWidget(m_slider, 0, 1); - - m_dragVal = new DragValue(this); + + m_dragVal = new DragValue(name, defaultValue, id, suffix, this); m_dragVal->setRange(min, max); m_dragVal->setPrecision(0); - layout->addWidget(m_dragVal, 0, 2); - - 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, 0, 2); - m_spinBox->setHidden(true); - - QToolButton *reset = new QToolButton(this); - reset->setAutoRaise(true); - reset->setIcon(KIcon("edit-undo")); - reset->setToolTip(i18n("Reset to default value")); - layout->addWidget(reset, 0, 3); - - m_commentLabel = new QLabel(comment, this); - m_commentLabel->setWordWrap(true); - m_commentLabel->setTextFormat(Qt::RichText); - m_commentLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop); - m_commentLabel->setFrameShape(QFrame::StyledPanel); - m_commentLabel->setFrameShadow(QFrame::Raised); - m_commentLabel->setHidden(true); - layout->addWidget(m_commentLabel, 1, 0, 1, -1); - - connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int))); - connect(m_dragVal, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotSetValue(qreal, bool))); - connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(setValue(int))); - connect(reset, SIGNAL(clicked(bool)), this, SLOT(slotReset())); - - //m_spinBox->setValue(value); + layout->addWidget(m_dragVal, 0, 1); + + if (!comment.isEmpty()) { + m_commentLabel = new QLabel(comment, this); + m_commentLabel->setWordWrap(true); + m_commentLabel->setTextFormat(Qt::RichText); + m_commentLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop); + m_commentLabel->setFrameShape(QFrame::StyledPanel); + m_commentLabel->setFrameShadow(QFrame::Raised); + m_commentLabel->setHidden(true); + layout->addWidget(m_commentLabel, 1, 0, 1, -1); + } + connect(m_dragVal, SIGNAL(valueChanged(int, bool)), this, SLOT(slotSetValue(int, bool))); + connect(m_dragVal, SIGNAL(inTimeline(int)), this, SIGNAL(setInTimeline(int))); m_dragVal->setValue(value); } +int DoubleParameterWidget::spinSize() +{ + return m_dragVal->spinSize(); +} + +void DoubleParameterWidget::setSpinSize(int width) +{ + m_dragVal->setSpinSize(width); +} + void DoubleParameterWidget::setValue(int value) { - m_slider->blockSignals(true); - m_spinBox->blockSignals(true); m_dragVal->blockSignals(true); - - m_slider->setValue(value); - m_spinBox->setValue(value); m_dragVal->setValue(value); - - m_slider->blockSignals(false); - m_spinBox->blockSignals(false); m_dragVal->blockSignals(false); - - emit valueChanged(value); + //emit valueChanged(value); } -void DoubleParameterWidget::slotSetValue(qreal value, bool final) +void DoubleParameterWidget::slotSetValue(int value, bool final) { - if (final) - setValue((int)value); + if (final) { + emit valueChanged(value); + } } int DoubleParameterWidget::getValue() { - return m_spinBox->value(); + return m_dragVal->value(); } -void DoubleParameterWidget::setName(const QString& name) +void DoubleParameterWidget::slotReset() { - m_name->setText(name); + m_dragVal->slotReset(); } -void DoubleParameterWidget::slotReset() +void DoubleParameterWidget::setInTimelineProperty(bool intimeline) { - setValue(m_default); + m_dragVal->setInTimelineProperty(intimeline); } void DoubleParameterWidget::slotShowComment( bool show) { - if (m_commentLabel->text() != QString()) { + if (m_commentLabel) { m_commentLabel->setVisible(show); if (show) layout()->setContentsMargins(0, 0, 0, 15); diff --git a/src/doubleparameterwidget.h b/src/doubleparameterwidget.h index f7d529b5..31ef445d 100644 --- a/src/doubleparameterwidget.h +++ b/src/doubleparameterwidget.h @@ -23,6 +23,7 @@ #include + class QLabel; class QSlider; class QSpinBox; @@ -49,13 +50,15 @@ public: * @param comment A comment explaining the parameter. Will be shown for the tooltip. * @param suffix (optional) Suffix to display in spinbox * @param parent (optional) Parent Widget */ - DoubleParameterWidget(const QString &name, int value, int min, int max, int defaultValue, const QString &comment, const QString suffix = QString(), QWidget* parent = 0); - - /** @brief Updates the label to display @param name. */ - void setName(const QString &name); + DoubleParameterWidget(const QString &name, int value, int min, int max, int defaultValue, const QString &comment, int id, const QString suffix = QString(), QWidget* parent = 0); /** @brief Gets the parameter's value. */ int getValue(); + /** @brief Set the inTimeline property to paint widget with other colors. */ + void setInTimelineProperty(bool intimeline); + /** @brief Returns minimum size for QSpinBox, used to set all spinboxes to the same width. */ + int spinSize(); + void setSpinSize(int width); public slots: /** @brief Sets the value to @param value. */ @@ -68,10 +71,9 @@ private slots: /** @brief Shows/Hides the comment label. */ void slotShowComment(bool show); - void slotSetValue(qreal value, bool final); + void slotSetValue(int value, bool final); private: - int m_default; QLabel *m_name; QSlider *m_slider; QSpinBox *m_spinBox; @@ -80,6 +82,8 @@ private: signals: void valueChanged(int); + /** @brief User wants to see this parameter in timeline. */ + void setInTimeline(int); }; #endif diff --git a/src/dragvalue.cpp b/src/dragvalue.cpp index 39b40fba..02c03d7f 100644 --- a/src/dragvalue.cpp +++ b/src/dragvalue.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (C) 2011 by Till Theato (root@ttill.de) * + * Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org) * * This file is part of Kdenlive (www.kdenlive.org). * * * * Kdenlive is free software: you can redistribute it and/or modify * @@ -32,62 +33,75 @@ #include #include #include +#include +#include +#include -#include +#include #include +#include -DragValue::DragValue(QWidget* parent) : +DragValue::DragValue(const QString &label, int defaultValue, int id, const QString suffix, QWidget* parent) : QWidget(parent), m_maximum(100), m_minimum(0), m_precision(2), - m_step(1), - m_dragMode(false) + m_default(defaultValue), + m_id(id) { - setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); setFocusPolicy(Qt::StrongFocus); setContextMenuPolicy(Qt::CustomContextMenu); - - QHBoxLayout *l = new QHBoxLayout(this); + + QHBoxLayout *l = new QHBoxLayout; l->setSpacing(0); - l->setMargin(0); - - m_edit = new QLineEdit(this); - m_edit->setValidator(new QDoubleValidator(m_minimum, m_maximum, m_precision, this)); - m_edit->setAlignment(Qt::AlignCenter); - m_edit->setEnabled(false); + l->setContentsMargins(0, 0, 0, 0); + m_label = new CustomLabel(label, this); + m_label->setCursor(Qt::PointingHandCursor); + m_label->setRange(m_minimum, m_maximum); + l->addWidget(m_label); + m_edit = new KIntSpinBox(this); + if (!suffix.isEmpty()) m_edit->setSuffix(suffix); + + m_edit->setButtonSymbols(QAbstractSpinBox::NoButtons); + m_edit->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + m_edit->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding); + m_edit->setRange(m_minimum, m_maximum); l->addWidget(m_edit); + connect(m_edit, SIGNAL(valueChanged(int)), this, SLOT(slotSetValue(int))); + connect(m_label, SIGNAL(valueChanged(int,bool)), this, SLOT(setValue(int,bool))); + setLayout(l); + m_label->setMaximumHeight(m_edit->sizeHint().height()); m_menu = new QMenu(this); - - m_nonlinearScale = new QAction(i18n("Nonlinear scale"), this); - m_nonlinearScale->setCheckable(true); - m_nonlinearScale->setChecked(KdenliveSettings::dragvalue_nonlinear()); - m_menu->addAction(m_nonlinearScale); - + + m_scale = new KSelectAction(i18n("Scaling"), this); + m_scale->addAction(i18n("Normal scale")); + m_scale->addAction(i18n("Pixel scale")); + m_scale->addAction(i18n("Nonlinear scale")); + m_scale->setCurrentItem(KdenliveSettings::dragvalue_mode()); + m_menu->addAction(m_scale); + m_directUpdate = new QAction(i18n("Direct update"), this); m_directUpdate->setCheckable(true); m_directUpdate->setChecked(KdenliveSettings::dragvalue_directupdate()); m_menu->addAction(m_directUpdate); - - QPalette p = palette(); - KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme())); - QColor bg = scheme.background(KColorScheme::LinkBackground).color(); - QColor fg = scheme.foreground(KColorScheme::LinkText).color(); - QColor editbg = scheme.background(KColorScheme::ActiveBackground).color(); - QColor editfg = scheme.foreground(KColorScheme::ActiveText).color(); - QString stylesheet(QString("QLineEdit { background-color: rgb(%1, %2, %3); border: 1px solid rgb(%1, %2, %3); border-radius: 5px; padding: 0px; color: rgb(%4, %5, %6); } QLineEdit::disabled { color: rgb(%4, %5, %6); }") - .arg(bg.red()).arg(bg.green()).arg(bg.blue()) - .arg(fg.red()).arg(fg.green()).arg(fg.blue())); - stylesheet.append(QString("QLineEdit::focus, QLineEdit::enabled { background-color: rgb(%1, %2, %3); color: rgb(%4, %5, %6); }") - .arg(editbg.red()).arg(editbg.green()).arg(editbg.blue()) - .arg(editfg.red()).arg(editfg.green()).arg(editfg.blue())); - setStyleSheet(stylesheet); - - updateMaxWidth(); + + QAction *reset = new QAction(KIcon("edit-undo"), i18n("Reset value"), this); + connect(reset, SIGNAL(triggered()), this, SLOT(slotReset())); + m_menu->addAction(reset); + + if (m_id > -1) { + QAction *timeline = new QAction(KIcon("go-jump"), i18n("Show %1 in timeline", label), this); + connect(timeline, SIGNAL(triggered()), this, SLOT(slotSetInTimeline())); + connect(m_label, SIGNAL(setInTimeline()), this, SLOT(slotSetInTimeline())); + m_menu->addAction(timeline); + } + + m_label->setRange(m_minimum, m_maximum); connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(slotShowContextMenu(const QPoint&))); - connect(m_nonlinearScale, SIGNAL(triggered(bool)), this, SLOT(slotSetNonlinearScale(bool))); + connect(m_scale, SIGNAL(triggered(int)), this, SLOT(slotSetScaleMode(int))); connect(m_directUpdate, SIGNAL(triggered(bool)), this, SLOT(slotSetDirectUpdate(bool))); connect(m_edit, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished())); @@ -97,10 +111,25 @@ DragValue::~DragValue() { delete m_edit; delete m_menu; - delete m_nonlinearScale; + delete m_scale; delete m_directUpdate; } +int DragValue::spinSize() +{ + return m_edit->sizeHint().width(); +} + +void DragValue::setSpinSize(int width) +{ + m_edit->setMinimumWidth(width); +} + +void DragValue::slotSetInTimeline() +{ + emit inTimeline(m_id); +} + int DragValue::precision() const { return m_precision; @@ -118,155 +147,216 @@ qreal DragValue::minimum() const qreal DragValue::value() const { - return m_edit->text().toDouble(); + return m_edit->value(); } void DragValue::setMaximum(qreal max) { m_maximum = max; - updateMaxWidth(); + m_label->setRange(m_minimum, m_maximum); + m_edit->setRange(m_minimum, m_maximum); } void DragValue::setMinimum(qreal min) { m_minimum = min; - updateMaxWidth(); + m_label->setRange(m_minimum, m_maximum); + m_edit->setRange(m_minimum, m_maximum); } void DragValue::setRange(qreal min, qreal max) { m_maximum = max; m_minimum = min; - updateMaxWidth(); + m_label->setRange(m_minimum, m_maximum); + m_edit->setRange(m_minimum, m_maximum); } -void DragValue::setPrecision(int precision) +void DragValue::setPrecision(int /*precision*/) { - m_precision = precision; + //TODO: Not implemented, in case we need double value, we should replace the KIntSpinBox with KDoubleNumInput... + /*m_precision = precision; if (precision == 0) m_edit->setValidator(new QIntValidator(m_minimum, m_maximum, this)); else - m_edit->setValidator(new QDoubleValidator(m_minimum, m_maximum, precision, this)); + 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_step = step; } -void DragValue::setValue(qreal value, bool final) +void DragValue::slotReset() { - value = qBound(m_minimum, value, m_maximum); + m_edit->blockSignals(true); + m_edit->setValue(m_default); + m_label->setValue(m_default); + m_edit->blockSignals(false); + emit valueChanged(m_default, true); +} - m_edit->setText(QString::number(value, 'f', m_precision)); +void DragValue::slotSetValue(int value) +{ + setValue(value, KdenliveSettings::dragvalue_directupdate()); +} +void DragValue::setValue(int value, bool final) +{ + value = qBound(m_minimum, value, m_maximum); + m_edit->blockSignals(true); + m_edit->setValue(value); + m_edit->blockSignals(false); + m_label->setValue(value); emit valueChanged(value, final); } -void DragValue::mousePressEvent(QMouseEvent* e) +void DragValue::focusInEvent(QFocusEvent* e) { - if (e->button() == Qt::LeftButton) { - m_dragStartPosition = m_dragLastPosition = e->pos(); - m_dragMode = true; - e->accept(); + if (e->reason() == Qt::TabFocusReason || e->reason() == Qt::BacktabFocusReason) { + //m_edit->setEnabled(true); + m_edit->setFocus(e->reason()); + } else { + QWidget::focusInEvent(e); } } -void DragValue::mouseMoveEvent(QMouseEvent* e) +void DragValue::slotEditingFinished() { - if (m_dragMode && (e->pos() - m_dragStartPosition).manhattanLength() >= QApplication::startDragDistance()) { - int diff = e->x() - m_dragLastPosition.x(); + qreal value = m_edit->value(); + m_edit->clearFocus(); + emit valueChanged(value, true); +} - if (e->modifiers() == Qt::ControlModifier) - diff *= 2; - else if (e->modifiers() == Qt::ShiftModifier) - diff /= 2; - if (KdenliveSettings::dragvalue_nonlinear()) - diff = (diff > 0 ? 1 : -1) * pow(diff, 2); +void DragValue::slotShowContextMenu(const QPoint& pos) +{ + // values might have been changed by another object of this class + m_scale->setCurrentItem(KdenliveSettings::dragvalue_mode()); + m_directUpdate->setChecked(KdenliveSettings::dragvalue_directupdate()); + m_menu->exec(mapToGlobal(pos)); +} - setValue(value() + diff / m_step, KdenliveSettings::dragvalue_directupdate()); - m_dragLastPosition = e->pos(); - e->accept(); - } +void DragValue::slotSetScaleMode(int mode) +{ + KdenliveSettings::setDragvalue_mode(mode); } -void DragValue::mouseReleaseEvent(QMouseEvent* e) +void DragValue::slotSetDirectUpdate(bool directUpdate) { - m_dragMode = false; - if (m_dragLastPosition == m_dragStartPosition) { - // value was not changed through dragging (mouse position stayed the same since mousePressEvent) - m_edit->setEnabled(true); - m_edit->setFocus(Qt::MouseFocusReason); - } else { - setValue(value(), true); - m_dragLastPosition = m_dragStartPosition; - e->accept(); - } + KdenliveSettings::setDragvalue_directupdate(directUpdate); } -void DragValue::wheelEvent(QWheelEvent* e) +void DragValue::setInTimelineProperty(bool intimeline) { - if (e->delta() > 0) - slotValueInc(); - else - slotValueDec(); + if (m_label->property("inTimeline").toBool() == intimeline) return; + m_label->setProperty("inTimeline", intimeline); + m_edit->setProperty("inTimeline", intimeline); + style()->unpolish(m_label); + style()->polish(m_label); + m_label->update(); + style()->unpolish(m_edit); + style()->polish(m_edit); + m_edit->update(); } -void DragValue::focusInEvent(QFocusEvent* e) +CustomLabel::CustomLabel(const QString &label, QWidget* parent) : + QProgressBar(parent), + m_dragMode(false), + m_step(1) + { - if (e->reason() == Qt::TabFocusReason || e->reason() == Qt::BacktabFocusReason) { - m_edit->setEnabled(true); - m_edit->setFocus(e->reason()); - } else { - QWidget::focusInEvent(e); - } + setFormat(" " + label); + setFocusPolicy(Qt::ClickFocus); + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum); + setRange(0, 100); + setValue(0); + setFont(KGlobalSettings::toolBarFont()); } -void DragValue::slotValueInc() +void CustomLabel::mousePressEvent(QMouseEvent* e) { - setValue(m_edit->text().toDouble() + m_step); + if (e->button() == Qt::LeftButton) { + m_dragStartPosition = m_dragLastPosition = e->pos(); + e->accept(); + } + else QWidget::mousePressEvent(e); } -void DragValue::slotValueDec() +void CustomLabel::mouseMoveEvent(QMouseEvent* e) { - setValue(m_edit->text().toDouble() - m_step); + if ((e->pos() - m_dragStartPosition).manhattanLength() >= QApplication::startDragDistance()) { + m_dragMode = true; + if (KdenliveSettings::dragvalue_mode() > 0) { + int diff = e->x() - m_dragLastPosition.x(); + + if (e->modifiers() == Qt::ControlModifier) + diff *= 2; + else if (e->modifiers() == Qt::ShiftModifier) + diff /= 2; + if (KdenliveSettings::dragvalue_mode() == 2) + diff = (diff > 0 ? 1 : -1) * pow(diff, 2); + + int nv = value() + diff / m_step; + if (nv != value()) setNewValue(nv, KdenliveSettings::dragvalue_directupdate()); + } + else { + int nv = minimum() + ((double) maximum() - minimum()) / width() * e->pos().x(); + if (nv != value()) setNewValue(nv, KdenliveSettings::dragvalue_directupdate()); + } + m_dragLastPosition = e->pos(); + e->accept(); + } + else QWidget::mouseMoveEvent(e); } -void DragValue::slotEditingFinished() +void CustomLabel::mouseReleaseEvent(QMouseEvent* e) { - qreal value = m_edit->text().toDouble(); - m_edit->setEnabled(false); - emit valueChanged(value, true); + if (e->modifiers() == Qt::ControlModifier) { + emit setInTimeline(); + e->accept(); + return; + } + if (m_dragMode) { + setNewValue(value(), true); + m_dragLastPosition = m_dragStartPosition; + e->accept(); + } + else { + setNewValue((int) (minimum() + ((double)maximum() - minimum()) / width() * e->pos().x()), KdenliveSettings::dragvalue_directupdate()); + m_dragLastPosition = m_dragStartPosition; + e->accept(); + } + m_dragMode = false; } -void DragValue::updateMaxWidth() +void CustomLabel::wheelEvent(QWheelEvent* e) { - int val = (int)(log10(qAbs(m_maximum) > qAbs(m_minimum) ? qAbs(m_maximum) : qAbs(m_minimum)) + .5); - val += m_precision; - if (m_precision) - val += 1; - if (m_minimum < 0) - val += 1; - QFontMetrics fm = m_edit->fontMetrics(); - m_edit->setMaximumWidth(fm.width(QString().rightJustified(val, '8'))); + if (e->delta() > 0) { + if (e->modifiers() == Qt::ControlModifier) slotValueInc(10); + else slotValueInc(); + } + else { + if (e->modifiers() == Qt::ControlModifier) slotValueDec(10); + else slotValueDec(); + } + e->accept(); } -void DragValue::slotShowContextMenu(const QPoint& pos) +void CustomLabel::slotValueInc(int factor) { - // values might have been changed by another object of this class - m_nonlinearScale->setChecked(KdenliveSettings::dragvalue_nonlinear()); - m_directUpdate->setChecked(KdenliveSettings::dragvalue_directupdate()); - m_menu->exec(mapToGlobal(pos)); + setNewValue((int) (value() + m_step * factor), true); } -void DragValue::slotSetNonlinearScale(bool nonlinear) +void CustomLabel::slotValueDec(int factor) { - KdenliveSettings::setDragvalue_nonlinear(nonlinear); + setNewValue((int) (value() - m_step * factor), true); } -void DragValue::slotSetDirectUpdate(bool directUpdate) +void CustomLabel::setNewValue(int value, bool update) { - KdenliveSettings::setDragvalue_directupdate(directUpdate); + setValue(value); + emit valueChanged(value, update); } #include "dragvalue.moc" + diff --git a/src/dragvalue.h b/src/dragvalue.h index 9fc3543c..9b89ee31 100644 --- a/src/dragvalue.h +++ b/src/dragvalue.h @@ -20,12 +20,47 @@ #define DRAGVALUE_H_ #include +#include +#include +#include +#include class QValidator; class QToolButton; class QLineEdit; class QAction; class QMenu; +class KSelectAction; + + +class CustomLabel : public QProgressBar +{ + Q_OBJECT +public: + CustomLabel(const QString &label, QWidget *parent = 0); + +protected: + //virtual void mouseDoubleClickEvent(QMouseEvent * event); + virtual void mousePressEvent(QMouseEvent * event); + virtual void mouseReleaseEvent(QMouseEvent *event); + virtual void mouseMoveEvent(QMouseEvent *event); + //virtual void paintEvent(QPaintEvent *event); + virtual void wheelEvent(QWheelEvent * event); + +private: + QPoint m_dragStartPosition; + QPoint m_dragLastPosition; + bool m_dragMode; + double m_step; + //QStyleOptionProgressBarV2 m_progressOptions; + void slotValueInc(int factor = 1); + void slotValueDec(int factor = 1); + void setNewValue(int, bool); + +signals: + void valueChanged(int, bool); + void setInTimeline(); +}; /** * @brief A widget for modifing numbers by dragging, using the mouse wheel or entering them with the keyboard. @@ -36,7 +71,7 @@ class DragValue : public QWidget Q_OBJECT public: - DragValue(QWidget* parent = 0); + DragValue(const QString &label, int defaultValue, int id, const QString suffix, QWidget* parent = 0); virtual ~DragValue(); /** @brief Returns the precision = number of decimals */ @@ -59,14 +94,22 @@ public: /** @brief Returns the current value */ qreal value() const; - + /** @brief Change the "inTimeline" property to paint the intimeline widget differently. */ + void setInTimelineProperty(bool intimeline); + /** @brief Returns minimum size for QSpinBox, used to set all spinboxes to the same width. */ + int spinSize(); + /** @brief Sets the minimum size for QSpinBox, used to set all spinboxes to the same width. */ + void setSpinSize(int width); + public slots: /** @brief Sets the value (forced to be in the valid range) and emits valueChanged. */ - void setValue(qreal value, bool final = true); + void setValue(int value, bool final = true); + /** @brief Resets to default value */ + void slotReset(); signals: - void valueChanged(qreal value, bool final); - + void valueChanged(int value, bool final = true); + void inTimeline(int); @@ -75,39 +118,37 @@ signals: */ protected: - virtual void mousePressEvent(QMouseEvent *e); + /*virtual void mousePressEvent(QMouseEvent *e); virtual void mouseMoveEvent(QMouseEvent *e); - virtual void mouseReleaseEvent(QMouseEvent *e); + virtual void mouseReleaseEvent(QMouseEvent *e);*/ /** @brief Forwards tab focus to lineedit since it is disabled. */ virtual void focusInEvent(QFocusEvent *e); //virtual void keyPressEvent(QKeyEvent *e); - virtual void wheelEvent(QWheelEvent *e); + //virtual void wheelEvent(QWheelEvent *e); + //virtual void paintEvent( QPaintEvent * event ); private slots: - void slotValueInc(); - void slotValueDec(); + void slotEditingFinished(); - void slotSetNonlinearScale(bool nonlinear); + void slotSetScaleMode(int mode); void slotSetDirectUpdate(bool directUpdate); void slotShowContextMenu(const QPoint &pos); + void slotSetValue(int value); + void slotSetInTimeline(); private: - qreal m_maximum; - qreal m_minimum; + int m_maximum; + int m_minimum; int m_precision; - qreal m_step; - QLineEdit *m_edit; - QPoint m_dragStartPosition; - QPoint m_dragLastPosition; - bool m_dragMode; + KIntSpinBox *m_edit; + int m_default; QMenu *m_menu; - QAction *m_nonlinearScale; + KSelectAction *m_scale; QAction *m_directUpdate; - - /** @brief Sets the maximum width of the widget so that there is enough space for the widest possible value. */ - void updateMaxWidth(); + CustomLabel *m_label; + int m_id; }; #endif diff --git a/src/effectstackedit.cpp b/src/effectstackedit.cpp index 7acae5dd..3c38a39c 100644 --- a/src/effectstackedit.cpp +++ b/src/effectstackedit.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -84,13 +85,23 @@ EffectStackEdit::EffectStackEdit(Monitor *monitor, QWidget *parent) : setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setFrameStyle(QFrame::NoFrame); setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding)); - + + QPalette p = palette(); + KColorScheme scheme(p.currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme())); + QColor dark_bg = scheme.shade(KColorScheme::DarkShade); + QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color(); + QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color(); + QColor light_bg = scheme.shade(KColorScheme::LightShade); + QColor mid_bg = scheme.shade(KColorScheme::DarkShade); + + QString stylesheet(QString("QProgressBar:horizontal {border: 1px solid %5;border-radius:0px;border-top-left-radius: 4px;border-bottom-left-radius: 4px;border-right: 0px;background:%4;padding: 0px;text-align:left center} QProgressBar:horizontal:hover {border: 1px solid %3;border-right: 0px;} QProgressBar::chunk:horizontal {background: %5;} QProgressBar::chunk:horizontal:hover {background: %3;} QProgressBar:horizontal[inTimeline=\"true\"] { border: 1px solid %2;border-right: 0px;background: %4;padding: 0px;text-align:left center } QProgressBar::chunk:horizontal[inTimeline=\"true\"] {background: %2;} QSpinBox {border: 1px solid %1;border-top-right-radius: 4px;border-bottom-right-radius: 4px;padding-right:0px;} QSpinBox::down-button {width:0px;padding:0px;} QSpinBox::up-button {width:0px;padding:0px;} QSpinBox[inTimeline=\"true\"]{ border: 1px solid %2;} QSpinBox:hover {border: 1px solid %3;} ").arg(dark_bg.name()).arg(selected_bg.name()).arg(hover_bg.name()).arg(light_bg.name()).arg(mid_bg.name())); + setStyleSheet(stylesheet); + setWidget(m_baseWidget); setWidgetResizable(true); m_vbox = new QVBoxLayout(m_baseWidget); m_vbox->setContentsMargins(0, 0, 0, 0); - m_vbox->setSpacing(0); - //wid->show(); + m_vbox->setSpacing(2); } EffectStackEdit::~EffectStackEdit() @@ -257,7 +268,7 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, int pos, int in, in max = pa.attribute("max").toInt(); DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, (int)(value.toDouble() + 0.5), min, max, - pa.attribute("default").toInt(), comment, pa.attribute("suffix"), this); + pa.attribute("default").toInt(), comment, -1, pa.attribute("suffix"), this); m_vbox->addWidget(doubleparam); m_valueItems[paramName] = doubleparam; connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(collectAllParameters())); @@ -516,6 +527,16 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, int pos, int in, in if (m_keyframeEditor) m_keyframeEditor->checkVisibleParam(); + + // Make sure all doubleparam spinboxes have the same width, looks much better + QList allWidgets = findChildren(); + int minSize = 0; + for (int i = 0; i < allWidgets.count(); i++) { + if (minSize < allWidgets.at(i)->spinSize()) minSize = allWidgets.at(i)->spinSize(); + } + for (int i = 0; i < allWidgets.count(); i++) { + allWidgets.at(i)->setSpinSize(minSize); + } } wipeInfo EffectStackEdit::getWipeInfo(QString value) diff --git a/src/effectstackview.cpp b/src/effectstackview.cpp index 944e2841..4f08611f 100644 --- a/src/effectstackview.cpp +++ b/src/effectstackview.cpp @@ -49,9 +49,11 @@ EffectStackView::EffectStackView(Monitor *monitor, QWidget *parent) : m_ui.setupUi(this); QVBoxLayout *vbox1 = new QVBoxLayout(m_ui.frame); m_effectedit = new EffectStackEdit(monitor, m_ui.frame); - vbox1->setContentsMargins(0, 0, 0, 0); + vbox1->setContentsMargins(2, 0, 2, 0); vbox1->setSpacing(0); vbox1->addWidget(m_effectedit); + m_ui.splitter->setStretchFactor(0, 0); + m_ui.splitter->setStretchFactor(1, 200); //m_ui.region_url->fileDialog()->setFilter(ProjectList::getExtensions()); //m_ui.effectlist->horizontalHeader()->setVisible(false); @@ -177,9 +179,9 @@ void EffectStackView::slotClipItemSelected(ClipItem* c, int ix) m_clipref = c; if (c) { QString cname = m_clipref->clipName(); - if (cname.length() > 20) { + if (cname.length() > 30) { m_ui.checkAll->setToolTip(i18n("Effects for %1").arg(cname)); - cname.truncate(17); + cname.truncate(27); m_ui.checkAll->setText(i18n("Effects for %1").arg(cname) + "..."); } else { m_ui.checkAll->setToolTip(QString()); diff --git a/src/kdenlivesettings.kcfg b/src/kdenlivesettings.kcfg index cf96dad3..1ff03bef 100644 --- a/src/kdenlivesettings.kcfg +++ b/src/kdenlivesettings.kcfg @@ -522,6 +522,10 @@ false + + + 0 + false diff --git a/src/keyframeedit.cpp b/src/keyframeedit.cpp index b9318291..f502b69c 100644 --- a/src/keyframeedit.cpp +++ b/src/keyframeedit.cpp @@ -24,8 +24,6 @@ #include #include -#include -#include KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode tc, int activeKeyframe, QWidget* parent) : QWidget(parent), @@ -55,8 +53,11 @@ KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode t m_position = new PositionEdit(i18n("Position"), 0, 0, 1, tc, widgetTable); ((QGridLayout*)widgetTable->layout())->addWidget(m_position, 3, 0, 1, -1); - m_showButtons = new QButtonGroup(this); m_slidersLayout = new QGridLayout(param_sliders); + //m_slidersLayout->setSpacing(0); + + m_slidersLayout->setContentsMargins(0, 0, 0, 0); + m_slidersLayout->setVerticalSpacing(2); keyframe_list->setSelectionBehavior(QAbstractItemView::SelectRows); keyframe_list->setSelectionMode(QAbstractItemView::SingleSelection); addParameter(e, activeKeyframe); @@ -68,7 +69,6 @@ KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode t connect(buttonKeyframes, SIGNAL(clicked()), this, SLOT(slotKeyframeMode())); connect(buttonResetKeyframe, SIGNAL(clicked()), this, SLOT(slotResetKeyframe())); connect(m_position, SIGNAL(parameterChanged(int)), this, SLOT(slotAdjustKeyframePos(int))); - connect(m_showButtons, SIGNAL(buttonClicked(int)), this, SLOT(slotUpdateVisibleParameter(int))); //connect(keyframe_list, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotSaveCurrentParam(QTreeWidgetItem *, int))); @@ -110,27 +110,21 @@ void KeyframeEdit::addParameter(QDomElement e, int activeKeyframe) QString comment; if (!commentElem.isNull()) comment = i18n(commentElem.text().toUtf8().data()); - + int columnId = keyframe_list->columnCount(); keyframe_list->insertColumn(columnId); keyframe_list->setHorizontalHeaderItem(columnId, new QTableWidgetItem(paramName)); 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(), comment, m_params.at(columnId).attribute("suffix"), this); + m_params.at(columnId).attribute("default").toInt(), comment, columnId, m_params.at(columnId).attribute("suffix"), this); connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int))); connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool))); + connect(doubleparam, SIGNAL(setInTimeline(int)), this, SLOT(slotUpdateVisibleParameter(int))); m_slidersLayout->addWidget(doubleparam, columnId, 0); - - QRadioButton *radio = new QRadioButton(this); - radio->setToolTip(i18n("Show %1 in timeline").arg(paramName)); - m_showButtons->addButton(radio, columnId); - if (e.attribute("intimeline") == "1") - radio->setChecked(true); - - QVBoxLayout *radioLayout = new QVBoxLayout; - radioLayout->addWidget(radio, 0, Qt::AlignTop); - m_slidersLayout->addLayout(radioLayout, columnId, 1); + if (e.attribute("intimeline") == "1") { + doubleparam->setInTimelineProperty(true); + } QStringList frames = e.attribute("keyframes").split(";", QString::SkipEmptyParts); for (int i = 0; i < frames.count(); i++) { @@ -438,8 +432,17 @@ void KeyframeEdit::slotResetKeyframe() void KeyframeEdit::slotUpdateVisibleParameter(int id, bool update) { - for (int i = 0; i < m_params.count(); ++i) - m_params[i].setAttribute("intimeline", (i == id ? "1" : "0")); + for (int i = 0; i < m_params.count(); ++i) { + m_params[i].setAttribute("intimeline", (i == id ? "1" : "0")); + } + for (int col = 0; col < keyframe_list->columnCount(); col++) { + DoubleParameterWidget *doubleparam = static_cast (m_slidersLayout->itemAtPosition(col, 0)->widget()); + if (!doubleparam) + continue; + doubleparam->setInTimelineProperty(col == id); + //kDebug()<<"// PARAM: "<(m_slidersLayout->itemAtPosition(0, 1)->layout()->itemAt(0)->widget()); - if (radio) - radio->setChecked(true); } #include "keyframeedit.moc" diff --git a/src/keyframeedit.h b/src/keyframeedit.h index 1d323b9d..9c8716a2 100644 --- a/src/keyframeedit.h +++ b/src/keyframeedit.h @@ -114,7 +114,6 @@ private: QList m_params; Timecode m_timecode; QGridLayout *m_slidersLayout; - QButtonGroup *m_showButtons; PositionEdit *m_position; private slots: diff --git a/src/widgets/effectstack_ui.ui b/src/widgets/effectstack_ui.ui index d38805d3..22d77703 100644 --- a/src/widgets/effectstack_ui.ui +++ b/src/widgets/effectstack_ui.ui @@ -6,8 +6,8 @@ 0 0 - 458 - 255 + 207 + 228 @@ -16,18 +16,56 @@ 0 - + + + 0 + + + 0 + + + + false + + + + 0 + 0 + + + + + + + true + + + false + + + + + + + + + + true + + + true + + + + Qt::Horizontal - - - - 2 - - + + + @@ -46,121 +84,109 @@ - - - - N - - - QToolButton::InstantPopup - - - true - - - - - - - false - - - Up - - - true - - - - - - - false - - - Dw - - - true - - - - - - - false - - - R - - - true - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 40 - 20 - - - - - - - - false - - - E - - - true - - - - - - - false - - - D - - - true - - - - - - - false - - - - - - true - - - false - - + + + + + + N + + + QToolButton::InstantPopup + + + true + + + + + + + false + + + Up + + + true + + + + + + + false + + + Dw + + + true + + + + + + + false + + + R + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + false + + + E + + + true + + + + + + + false + + + D + + + true + + + + - - - + + + @@ -170,33 +196,7 @@ - - - - - - - true - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - +