]> git.sesse.net Git - kdenlive/blob - src/beziercurve/beziersplinewidget.cpp
Hue background enabled in Bézier widget, shearing option added for HSV planes
[kdenlive] / src / beziercurve / beziersplinewidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Till Theato (root@ttill.de)                     *
3  *   This file is part of Kdenlive (www.kdenlive.org).                     *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
18
19 #include "beziersplinewidget.h"
20 #include "colortools.h"
21 #include "dragvalue.h"
22 #include "kdenlivesettings.h"
23
24 #include <QVBoxLayout>
25
26 #include <KIcon>
27 #include <KLocale>
28
29
30 BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) :
31         QWidget(parent),
32         m_mode(ModeRGB),
33         m_showPixmap(true)
34 {
35     QVBoxLayout *layout = new QVBoxLayout(this);
36     layout->addWidget(&m_edit);
37     QWidget *widget = new QWidget(this);
38     m_ui.setupUi(widget);
39     layout->addWidget(widget);
40
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);
49
50     m_pX = new DragValue(i18n("In"), 0, 3, -1, QString(), false, this);
51     m_pX->setRange(0, 1);
52     m_pX->setStep(0.001);
53     m_pY = new DragValue(i18n("Out"), 0, 3, -1, QString(), false, this);
54     m_pY->setRange(0, 1);
55     m_pY->setStep(0.001);
56     m_h1X = new DragValue(i18n("X"), 0, 3, -1, QString(), false, this);
57     m_h1X->setRange(-2, 2);
58     m_h1X->setStep(0.001);
59     m_h1Y = new DragValue(i18n("Y"), 0, 3, -1, QString(), false, this);
60     m_h1Y->setRange(-2, 2);
61     m_h1Y->setStep(0.001);
62     m_h2X = new DragValue(i18n("X"), 0, 3, -1, QString(), false, this);
63     m_h2X->setRange(-2, 2);
64     m_h2X->setStep(0.001);
65     m_h2Y = new DragValue(i18n("Y"), 0, 3, -1, QString(), false, this);
66     m_h2Y->setRange(-2, 2);
67     m_h2Y->setStep(0.001);
68
69     m_ui.layoutP->addWidget(m_pX);
70     m_ui.layoutP->addWidget(m_pY);
71     m_ui.layoutH1->addWidget(new QLabel(i18n("Handle 1:")));
72     m_ui.layoutH1->addWidget(m_h1X);
73     m_ui.layoutH1->addWidget(m_h1Y);
74     m_ui.layoutH2->addWidget(new QLabel(i18n("Handle 2:")));
75     m_ui.layoutH2->addWidget(m_h2X);
76     m_ui.layoutH2->addWidget(m_h2Y);
77
78     CubicBezierSpline s;
79     s.fromString(spline);
80     m_edit.setSpline(s);
81
82     connect(&m_edit, SIGNAL(modified()), this, SIGNAL(modified()));
83     connect(&m_edit, SIGNAL(currentPoint(const BPoint&)), this, SLOT(slotUpdatePointEntries(const BPoint&)));
84
85     connect(m_pX, SIGNAL(valueChanged(double, bool)), this, SLOT(slotUpdatePointP(double, bool)));
86     connect(m_pY, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointP(double, bool)));
87     connect(m_h1X, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH1(double, bool)));
88     connect(m_h1Y, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH1(double, bool)));
89     connect(m_h2X, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH2(double, bool)));
90     connect(m_h2Y, SIGNAL(valueChanged(double,bool)), this, SLOT(slotUpdatePointH2(double, bool)));
91
92     connect(m_ui.buttonLinkHandles, SIGNAL(toggled(bool)), this, SLOT(slotSetHandlesLinked(bool)));
93     connect(m_ui.buttonZoomIn, SIGNAL(clicked()), &m_edit, SLOT(slotZoomIn()));
94     connect(m_ui.buttonZoomOut, SIGNAL(clicked()), &m_edit, SLOT(slotZoomOut()));
95     connect(m_ui.buttonGridChange, SIGNAL(clicked()), this, SLOT(slotGridChange()));
96     connect(m_ui.buttonShowPixmap, SIGNAL(toggled(bool)), this, SLOT(slotShowPixmap(bool)));
97     connect(m_ui.buttonResetSpline, SIGNAL(clicked()), this, SLOT(slotResetSpline()));
98     connect(m_ui.buttonShowAllHandles, SIGNAL(toggled(bool)), this, SLOT(slotShowAllHandles(bool)));
99
100     m_edit.setGridLines(KdenliveSettings::bezier_gridlines());
101     m_ui.buttonShowPixmap->setChecked(KdenliveSettings::bezier_showpixmap());
102     slotShowPixmap(m_ui.buttonShowPixmap->isChecked());
103     m_ui.buttonShowAllHandles->setChecked(KdenliveSettings::bezier_showallhandles());
104 }
105
106 QString BezierSplineWidget::spline()
107 {
108     return m_edit.spline().toString();
109 }
110
111 void BezierSplineWidget::setMode(BezierSplineWidget::CurveModes mode)
112 {
113     if (m_mode != mode) {
114         m_mode = mode;
115         if (m_showPixmap)
116             slotShowPixmap();
117     }
118 }
119
120 void BezierSplineWidget::slotGridChange()
121 {
122     m_edit.setGridLines((m_edit.gridLines() + 1) % 9);
123     KdenliveSettings::setBezier_gridlines(m_edit.gridLines());
124 }
125
126 void BezierSplineWidget::slotShowPixmap(bool show)
127 {
128     m_showPixmap = show;
129     KdenliveSettings::setBezier_showpixmap(show);
130     if (show && (int)m_mode < 6)
131         m_edit.setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(m_edit.size(), (ColorTools::ColorsRGB)((int)m_mode), 1, palette().background().color().rgb())));
132      else if (show && m_mode == ModeHue)
133          m_edit.setPixmap(QPixmap::fromImage(ColorTools::hsvCurvePlane(m_edit.size(), QColor::fromHsv(200, 200, 200), ColorTools::COM_H, ColorTools::COM_H)));
134     else
135         m_edit.setPixmap(QPixmap());
136 }
137
138 void BezierSplineWidget::slotUpdatePointEntries(const BPoint &p)
139 {
140     blockSignals(true);
141     if (p == BPoint()) {
142         m_ui.widgetPoint->setEnabled(false);
143     } else {
144         m_ui.widgetPoint->setEnabled(true);
145         m_pX->blockSignals(true);
146         m_pY->blockSignals(true);
147         m_h1X->blockSignals(true);
148         m_h1Y->blockSignals(true);
149         m_h2X->blockSignals(true);
150         m_h2Y->blockSignals(true);
151         m_pX->setValue(p.p.x());
152         m_pY->setValue(p.p.y());
153         m_h1X->setValue(p.h1.x());
154         m_h1Y->setValue(p.h1.y());
155         m_h2X->setValue(p.h2.x());
156         m_h2Y->setValue(p.h2.y());
157         m_pX->blockSignals(false);
158         m_pY->blockSignals(false);
159         m_h1X->blockSignals(false);
160         m_h1Y->blockSignals(false);
161         m_h2X->blockSignals(false);
162         m_h2Y->blockSignals(false);
163         m_ui.buttonLinkHandles->setChecked(p.handlesLinked);
164     }
165     blockSignals(false);
166 }
167
168 void BezierSplineWidget::slotUpdatePointP(double value, bool final)
169 {
170     Q_UNUSED(value)
171
172     BPoint p = m_edit.getCurrentPoint();
173
174     p.setP(QPointF(m_pX->value(), m_pY->value()));
175
176     m_edit.updateCurrentPoint(p, final);
177 }
178
179 void BezierSplineWidget::slotUpdatePointH1(double value, bool final)
180 {
181     Q_UNUSED(value)
182
183     BPoint p = m_edit.getCurrentPoint();
184
185     p.setH1(QPointF(m_h1X->value(), m_h1Y->value()));
186
187     m_edit.updateCurrentPoint(p, final);
188 }
189
190 void BezierSplineWidget::slotUpdatePointH2(double value, bool final)
191 {
192     Q_UNUSED(value)
193
194     BPoint p = m_edit.getCurrentPoint();
195
196     p.setH2(QPointF(m_h2X->value(), m_h2Y->value()));
197
198     m_edit.updateCurrentPoint(p, final);
199 }
200
201 void BezierSplineWidget::slotSetHandlesLinked(bool linked)
202 {
203     BPoint p = m_edit.getCurrentPoint();
204     p.handlesLinked = linked;
205     m_edit.updateCurrentPoint(p);
206 }
207
208 void BezierSplineWidget::slotResetSpline()
209 {
210     m_edit.setSpline(CubicBezierSpline());
211 }
212
213 void BezierSplineWidget::slotShowAllHandles(bool show)
214 {
215     m_edit.setShowAllHandles(show);
216     KdenliveSettings::setBezier_showallhandles(show);
217 }
218
219 #include "beziersplinewidget.moc"