]> git.sesse.net Git - kdenlive/blob - src/beziercurve/beziersplinewidget.cpp
Use QLatin1String
[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 <KLocalizedString>
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(QLatin1String("insert-link")));
42     m_ui.buttonZoomIn->setIcon(KIcon(QLatin1String("zoom-in")));
43     m_ui.buttonZoomOut->setIcon(KIcon(QLatin1String("zoom-out")));
44     m_ui.buttonGridChange->setIcon(KIcon(QLatin1String("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(QLatin1String("view-refresh")));
47     m_ui.buttonShowAllHandles->setIcon(KIcon(QLatin1String("draw-bezier-curves")));
48     m_ui.widgetPoint->setEnabled(false);
49
50     m_pX = new DragValue(i18n("In"), 0, 3, 0, 1, -1, QString(), false, this);
51     m_pX->setStep(0.001);
52     m_pY = new DragValue(i18n("Out"), 0, 3, 0, 1, -1, QString(), false, this);
53     m_pY->setStep(0.001);
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);
62
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);
71
72     CubicBezierSpline s;
73     s.fromString(spline);
74     m_edit.setSpline(s);
75
76     connect(&m_edit, SIGNAL(modified()), this, SIGNAL(modified()));
77     connect(&m_edit, SIGNAL(currentPoint(BPoint)), this, SLOT(slotUpdatePointEntries(BPoint)));
78
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)));
85
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)));
93
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());
98 }
99
100 QString BezierSplineWidget::spline() const
101 {
102     return m_edit.spline().toString();
103 }
104
105 void BezierSplineWidget::setMode(BezierSplineWidget::CurveModes mode)
106 {
107     if (m_mode != mode) {
108         m_mode = mode;
109         if (m_showPixmap)
110             slotShowPixmap();
111     }
112 }
113
114 void BezierSplineWidget::slotGridChange()
115 {
116     m_edit.setGridLines((m_edit.gridLines() + 1) % 9);
117     KdenliveSettings::setBezier_gridlines(m_edit.gridLines());
118 }
119
120 void BezierSplineWidget::slotShowPixmap(bool show)
121 {
122     if (m_showPixmap != show) {
123         m_showPixmap = show;
124         KdenliveSettings::setBezier_showpixmap(show);
125         if (show && (int)m_mode < 6)
126             m_edit.setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(m_edit.size(), (ColorTools::ColorsRGB)((int)m_mode), 1, palette().background().color().rgb())));
127         else if (show && m_mode == ModeHue)
128             m_edit.setPixmap(QPixmap::fromImage(ColorTools::hsvCurvePlane(m_edit.size(), QColor::fromHsv(200, 200, 200), ColorTools::COM_H, ColorTools::COM_H)));
129         else
130             m_edit.setPixmap(QPixmap());
131     }
132 }
133
134 void BezierSplineWidget::slotUpdatePointEntries(const BPoint &p)
135 {
136     blockSignals(true);
137     if (p == BPoint()) {
138         m_ui.widgetPoint->setEnabled(false);
139     } else {
140         m_ui.widgetPoint->setEnabled(true);
141         m_pX->blockSignals(true);
142         m_pY->blockSignals(true);
143         m_h1X->blockSignals(true);
144         m_h1Y->blockSignals(true);
145         m_h2X->blockSignals(true);
146         m_h2Y->blockSignals(true);
147         m_pX->setValue(p.p.x());
148         m_pY->setValue(p.p.y());
149         m_h1X->setValue(p.h1.x());
150         m_h1Y->setValue(p.h1.y());
151         m_h2X->setValue(p.h2.x());
152         m_h2Y->setValue(p.h2.y());
153         m_pX->blockSignals(false);
154         m_pY->blockSignals(false);
155         m_h1X->blockSignals(false);
156         m_h1Y->blockSignals(false);
157         m_h2X->blockSignals(false);
158         m_h2Y->blockSignals(false);
159         m_ui.buttonLinkHandles->setChecked(p.handlesLinked);
160     }
161     blockSignals(false);
162 }
163
164 void BezierSplineWidget::slotUpdatePointP(double value, bool final)
165 {
166     Q_UNUSED(value)
167
168     BPoint p = m_edit.getCurrentPoint();
169
170     p.setP(QPointF(m_pX->value(), m_pY->value()));
171
172     m_edit.updateCurrentPoint(p, final);
173 }
174
175 void BezierSplineWidget::slotUpdatePointH1(double value, bool final)
176 {
177     Q_UNUSED(value)
178
179     BPoint p = m_edit.getCurrentPoint();
180
181     p.setH1(QPointF(m_h1X->value(), m_h1Y->value()));
182
183     m_edit.updateCurrentPoint(p, final);
184 }
185
186 void BezierSplineWidget::slotUpdatePointH2(double value, bool final)
187 {
188     Q_UNUSED(value)
189
190     BPoint p = m_edit.getCurrentPoint();
191
192     p.setH2(QPointF(m_h2X->value(), m_h2Y->value()));
193
194     m_edit.updateCurrentPoint(p, final);
195 }
196
197 void BezierSplineWidget::slotSetHandlesLinked(bool linked)
198 {
199     BPoint p = m_edit.getCurrentPoint();
200     p.handlesLinked = linked;
201     m_edit.updateCurrentPoint(p);
202 }
203
204 void BezierSplineWidget::slotResetSpline()
205 {
206     m_edit.setSpline(CubicBezierSpline());
207 }
208
209 void BezierSplineWidget::slotShowAllHandles(bool show)
210 {
211     m_edit.setShowAllHandles(show);
212     KdenliveSettings::setBezier_showallhandles(show);
213 }
214
215 #include "beziersplinewidget.moc"