1 /***************************************************************************
2 * Copyright (C) 2010 by Till Theato (root@ttill.de) *
3 * This file is part of Kdenlive (www.kdenlive.org). *
5 * Kdenlive is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * Kdenlive is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with Kdenlive. If not, see <http://www.gnu.org/licenses/>. *
17 ***************************************************************************/
19 #include "beziersplinewidget.h"
20 #include "colortools.h"
21 #include "dragvalue.h"
22 #include "kdenlivesettings.h"
24 #include <QVBoxLayout>
30 BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) :
35 QVBoxLayout *layout = new QVBoxLayout(this);
36 layout->addWidget(&m_edit);
37 QWidget *widget = new QWidget(this);
39 layout->addWidget(widget);
41 m_ui.buttonLinkHandles->setIcon(KIcon("insert-link"));
42 m_ui.buttonZoomIn->setIcon(KIcon("zoom-in"));
43 m_ui.buttonZoomOut->setIcon(KIcon("zoom-out"));
44 m_ui.buttonGridChange->setIcon(KIcon("view-grid"));
45 m_ui.buttonShowPixmap->setIcon(QIcon(QPixmap::fromImage(ColorTools::rgbCurvePlane(QSize(16, 16), ColorTools::COL_Luma, 0.8))));
46 m_ui.buttonResetSpline->setIcon(KIcon("view-refresh"));
47 m_ui.buttonShowAllHandles->setIcon(KIcon("draw-bezier-curves"));
48 m_ui.widgetPoint->setEnabled(false);
50 m_pX = new DragValue(i18n("In"), 0, 3, 0, 1, -1, QString(), false, this);
52 m_pY = new DragValue(i18n("Out"), 0, 3, 0, 1, -1, QString(), false, this);
54 m_h1X = new DragValue(i18n("X"), 0, 3, -2, 2, -1, QString(), false, this);
55 m_h1X->setStep(0.001);
56 m_h1Y = new DragValue(i18n("Y"), 0, 3, -2, 2, -1, QString(), false, this);
57 m_h1Y->setStep(0.001);
58 m_h2X = new DragValue(i18n("X"), 0, 3, -2, 2, -1, QString(), false, this);
59 m_h2X->setStep(0.001);
60 m_h2Y = new DragValue(i18n("Y"), 0, 3, -2, 2, -1, QString(), false, this);
61 m_h2Y->setStep(0.001);
63 m_ui.layoutP->addWidget(m_pX);
64 m_ui.layoutP->addWidget(m_pY);
65 m_ui.layoutH1->addWidget(new QLabel(i18n("Handle 1:")));
66 m_ui.layoutH1->addWidget(m_h1X);
67 m_ui.layoutH1->addWidget(m_h1Y);
68 m_ui.layoutH2->addWidget(new QLabel(i18n("Handle 2:")));
69 m_ui.layoutH2->addWidget(m_h2X);
70 m_ui.layoutH2->addWidget(m_h2Y);
76 connect(&m_edit, SIGNAL(modified()), this, SIGNAL(modified()));
77 connect(&m_edit, SIGNAL(currentPoint(const BPoint&)), this, SLOT(slotUpdatePointEntries(const BPoint&)));
79 connect(m_pX, SIGNAL(valueChanged(double, bool)), this, SLOT(slotUpdatePointP(double, bool)));
80 connect(m_pY, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointP(double, bool)));
81 connect(m_h1X, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH1(double, bool)));
82 connect(m_h1Y, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH1(double, bool)));
83 connect(m_h2X, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH2(double, bool)));
84 connect(m_h2Y, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH2(double, bool)));
86 connect(m_ui.buttonLinkHandles, SIGNAL(toggled(bool)), this, SLOT(slotSetHandlesLinked(bool)));
87 connect(m_ui.buttonZoomIn, SIGNAL(clicked()), &m_edit, SLOT(slotZoomIn()));
88 connect(m_ui.buttonZoomOut, SIGNAL(clicked()), &m_edit, SLOT(slotZoomOut()));
89 connect(m_ui.buttonGridChange, SIGNAL(clicked()), this, SLOT(slotGridChange()));
90 connect(m_ui.buttonShowPixmap, SIGNAL(toggled(bool)), this, SLOT(slotShowPixmap(bool)));
91 connect(m_ui.buttonResetSpline, SIGNAL(clicked()), this, SLOT(slotResetSpline()));
92 connect(m_ui.buttonShowAllHandles, SIGNAL(toggled(bool)), this, SLOT(slotShowAllHandles(bool)));
94 m_edit.setGridLines(KdenliveSettings::bezier_gridlines());
95 m_ui.buttonShowPixmap->setChecked(KdenliveSettings::bezier_showpixmap());
96 slotShowPixmap(m_ui.buttonShowPixmap->isChecked());
97 m_ui.buttonShowAllHandles->setChecked(KdenliveSettings::bezier_showallhandles());
100 QString BezierSplineWidget::spline()
102 return m_edit.spline().toString();
105 void BezierSplineWidget::setMode(BezierSplineWidget::CurveModes mode)
107 if (m_mode != mode) {
114 void BezierSplineWidget::slotGridChange()
116 m_edit.setGridLines((m_edit.gridLines() + 1) % 9);
117 KdenliveSettings::setBezier_gridlines(m_edit.gridLines());
120 void BezierSplineWidget::slotShowPixmap(bool show)
123 KdenliveSettings::setBezier_showpixmap(show);
124 if (show && (int)m_mode < 6)
125 m_edit.setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(m_edit.size(), (ColorTools::ColorsRGB)((int)m_mode), 1, palette().background().color().rgb())));
126 else if (show && m_mode == ModeHue)
127 m_edit.setPixmap(QPixmap::fromImage(ColorTools::hsvCurvePlane(m_edit.size(), QColor::fromHsv(200, 200, 200), ColorTools::COM_H, ColorTools::COM_H)));
129 m_edit.setPixmap(QPixmap());
132 void BezierSplineWidget::slotUpdatePointEntries(const BPoint &p)
136 m_ui.widgetPoint->setEnabled(false);
138 m_ui.widgetPoint->setEnabled(true);
139 m_pX->blockSignals(true);
140 m_pY->blockSignals(true);
141 m_h1X->blockSignals(true);
142 m_h1Y->blockSignals(true);
143 m_h2X->blockSignals(true);
144 m_h2Y->blockSignals(true);
145 m_pX->setValue(p.p.x());
146 m_pY->setValue(p.p.y());
147 m_h1X->setValue(p.h1.x());
148 m_h1Y->setValue(p.h1.y());
149 m_h2X->setValue(p.h2.x());
150 m_h2Y->setValue(p.h2.y());
151 m_pX->blockSignals(false);
152 m_pY->blockSignals(false);
153 m_h1X->blockSignals(false);
154 m_h1Y->blockSignals(false);
155 m_h2X->blockSignals(false);
156 m_h2Y->blockSignals(false);
157 m_ui.buttonLinkHandles->setChecked(p.handlesLinked);
162 void BezierSplineWidget::slotUpdatePointP(double value, bool final)
166 BPoint p = m_edit.getCurrentPoint();
168 p.setP(QPointF(m_pX->value(), m_pY->value()));
170 m_edit.updateCurrentPoint(p, final);
173 void BezierSplineWidget::slotUpdatePointH1(double value, bool final)
177 BPoint p = m_edit.getCurrentPoint();
179 p.setH1(QPointF(m_h1X->value(), m_h1Y->value()));
181 m_edit.updateCurrentPoint(p, final);
184 void BezierSplineWidget::slotUpdatePointH2(double value, bool final)
188 BPoint p = m_edit.getCurrentPoint();
190 p.setH2(QPointF(m_h2X->value(), m_h2Y->value()));
192 m_edit.updateCurrentPoint(p, final);
195 void BezierSplineWidget::slotSetHandlesLinked(bool linked)
197 BPoint p = m_edit.getCurrentPoint();
198 p.handlesLinked = linked;
199 m_edit.updateCurrentPoint(p);
202 void BezierSplineWidget::slotResetSpline()
204 m_edit.setSpline(CubicBezierSpline());
207 void BezierSplineWidget::slotShowAllHandles(bool show)
209 m_edit.setShowAllHandles(show);
210 KdenliveSettings::setBezier_showallhandles(show);
213 #include "beziersplinewidget.moc"