X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fbeziercurve%2Fbeziersplinewidget.cpp;h=f61e65f9242e5c25b83d5941c2e7516bc56fd528;hb=4fba89810f9bc0bbf7f3e1c286a1d868d88918f3;hp=d6469c71fbe38607c5058efe74937389419ece78;hpb=255f094da6bb19faa9fe51daa30de6db296145ff;p=kdenlive diff --git a/src/beziercurve/beziersplinewidget.cpp b/src/beziercurve/beziersplinewidget.cpp index d6469c71..f61e65f9 100644 --- a/src/beziercurve/beziersplinewidget.cpp +++ b/src/beziercurve/beziersplinewidget.cpp @@ -18,15 +18,19 @@ #include "beziersplinewidget.h" #include "colortools.h" +#include "dragvalue.h" #include "kdenlivesettings.h" #include #include +#include + BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) : QWidget(parent), - m_mode(ModeRed) + m_mode(ModeRGB), + m_showPixmap(true) { QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(&m_edit); @@ -35,37 +39,65 @@ BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) : layout->addWidget(widget); m_ui.buttonLinkHandles->setIcon(KIcon("insert-link")); - 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.buttonShowPixmap->setIcon(QIcon(QPixmap::fromImage(ColorTools::rgbCurvePlane(QSize(16, 16), ColorTools::COL_Luma, 0.8)))); + m_ui.buttonResetSpline->setIcon(KIcon("view-refresh")); + m_ui.buttonShowAllHandles->setIcon(KIcon("draw-bezier-curves")); m_ui.widgetPoint->setEnabled(false); + m_pX = new DragValue(i18n("In"), 0, 3, 0, 1, -1, QString(), false, this); + m_pX->setStep(0.001); + m_pY = new DragValue(i18n("Out"), 0, 3, 0, 1, -1, QString(), false, this); + m_pY->setStep(0.001); + m_h1X = new DragValue(i18n("X"), 0, 3, -2, 2, -1, QString(), false, this); + m_h1X->setStep(0.001); + m_h1Y = new DragValue(i18n("Y"), 0, 3, -2, 2, -1, QString(), false, this); + m_h1Y->setStep(0.001); + m_h2X = new DragValue(i18n("X"), 0, 3, -2, 2, -1, QString(), false, this); + m_h2X->setStep(0.001); + m_h2Y = new DragValue(i18n("Y"), 0, 3, -2, 2, -1, QString(), false, this); + 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); connect(&m_edit, SIGNAL(modified()), this, SIGNAL(modified())); - connect(&m_edit, SIGNAL(currentPoint(const BPoint&)), this, SLOT(slotUpdatePoint(const BPoint&))); + connect(&m_edit, SIGNAL(currentPoint(BPoint)), this, SLOT(slotUpdatePointEntries(BPoint))); - connect(m_ui.spinPX, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline())); - connect(m_ui.spinPY, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline())); - connect(m_ui.spinH1X, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline())); - connect(m_ui.spinH1Y, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline())); - connect(m_ui.spinH2X, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline())); - connect(m_ui.spinH2Y, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline())); + connect(m_pX, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointP(double,bool))); + connect(m_pY, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointP(double,bool))); + connect(m_h1X, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH1(double,bool))); + connect(m_h1Y, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH1(double,bool))); + connect(m_h2X, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH2(double,bool))); + connect(m_h2Y, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH2(double,bool))); + connect(m_ui.buttonLinkHandles, SIGNAL(toggled(bool)), this, SLOT(slotSetHandlesLinked(bool))); 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()), this, SLOT(slotGridChange())); connect(m_ui.buttonShowPixmap, SIGNAL(toggled(bool)), this, SLOT(slotShowPixmap(bool))); + connect(m_ui.buttonResetSpline, SIGNAL(clicked()), this, SLOT(slotResetSpline())); + connect(m_ui.buttonShowAllHandles, SIGNAL(toggled(bool)), this, SLOT(slotShowAllHandles(bool))); m_edit.setGridLines(KdenliveSettings::bezier_gridlines()); m_ui.buttonShowPixmap->setChecked(KdenliveSettings::bezier_showpixmap()); + slotShowPixmap(m_ui.buttonShowPixmap->isChecked()); + m_ui.buttonShowAllHandles->setChecked(KdenliveSettings::bezier_showallhandles()); } -QString BezierSplineWidget::spline() +QString BezierSplineWidget::spline() const { return m_edit.spline().toString(); } @@ -87,53 +119,97 @@ void BezierSplineWidget::slotGridChange() void BezierSplineWidget::slotShowPixmap(bool show) { - m_showPixmap = show; - KdenliveSettings::setBezier_showpixmap(show); - if (show) - m_edit.setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(m_edit.size(), (ColorTools::ColorsRGB)((int)m_mode), 0.8))); - else - m_edit.setPixmap(QPixmap()); + if (m_showPixmap != show) { + m_showPixmap = 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::hsvCurvePlane(m_edit.size(), QColor::fromHsv(200, 200, 200), ColorTools::COM_H, ColorTools::COM_H))); + else + m_edit.setPixmap(QPixmap()); + } } -void BezierSplineWidget::slotUpdatePoint(const BPoint &p) +void BezierSplineWidget::slotUpdatePointEntries(const BPoint &p) { blockSignals(true); if (p == BPoint()) { 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); } -void BezierSplineWidget::slotUpdateSpline() +void BezierSplineWidget::slotUpdatePointP(double value, bool final) { + Q_UNUSED(value) + BPoint p = m_edit.getCurrentPoint(); - // check for every value, so we do not lose too much info through rounding - if (m_ui.spinPX->value() != qRound(p.p.x() * 255)) - p.p.setX(m_ui.spinPX->value() / 255.); - if (m_ui.spinPY->value() != qRound(p.p.y() * 255)) - p.p.setY(m_ui.spinPY->value() / 255.); + p.setP(QPointF(m_pX->value(), m_pY->value())); + + m_edit.updateCurrentPoint(p, final); +} + +void BezierSplineWidget::slotUpdatePointH1(double value, bool final) +{ + Q_UNUSED(value) + + BPoint p = m_edit.getCurrentPoint(); + + p.setH1(QPointF(m_h1X->value(), m_h1Y->value())); + + m_edit.updateCurrentPoint(p, final); +} + +void BezierSplineWidget::slotUpdatePointH2(double value, bool final) +{ + Q_UNUSED(value) - if (m_ui.spinH1X->value() != qRound(p.h1.x() * 255)) - p.h1.setX(m_ui.spinH1X->value() / 255.); - if (m_ui.spinH1Y->value() != qRound(p.h1.y() * 255)) - p.h1.setY(m_ui.spinH1Y->value() / 255.); + BPoint p = m_edit.getCurrentPoint(); - if (m_ui.spinH2X->value() != qRound(p.h2.x() * 255)) - p.h2.setX(m_ui.spinH2X->value() / 255.); - if (m_ui.spinH2Y->value() != qRound(p.h2.y() * 255)) - p.h2.setY(m_ui.spinH2Y->value() / 255.); + p.setH2(QPointF(m_h2X->value(), m_h2Y->value())); + m_edit.updateCurrentPoint(p, final); +} + +void BezierSplineWidget::slotSetHandlesLinked(bool linked) +{ + BPoint p = m_edit.getCurrentPoint(); + p.handlesLinked = linked; m_edit.updateCurrentPoint(p); - emit modified(); +} + +void BezierSplineWidget::slotResetSpline() +{ + m_edit.setSpline(CubicBezierSpline()); +} + +void BezierSplineWidget::slotShowAllHandles(bool show) +{ + m_edit.setShowAllHandles(show); + KdenliveSettings::setBezier_showallhandles(show); } #include "beziersplinewidget.moc"