]> git.sesse.net Git - kdenlive/blob - src/beziercurve/beziersplinewidget.cpp
Bezier Spline: Add checkable button show all handles: Whether to show handles for...
[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 "kdenlivesettings.h"
22
23 #include <QVBoxLayout>
24
25 #include <KIcon>
26
27
28 BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) :
29         QWidget(parent),
30         m_mode(ModeRGB),
31         m_showPixmap(true)
32 {
33     QVBoxLayout *layout = new QVBoxLayout(this);
34     layout->addWidget(&m_edit);
35     QWidget *widget = new QWidget(this);
36     m_ui.setupUi(widget);
37     layout->addWidget(widget);
38
39     m_ui.buttonLinkHandles->setIcon(KIcon("insert-link"));
40     m_ui.buttonZoomIn->setIcon(KIcon("zoom-in"));
41     m_ui.buttonZoomOut->setIcon(KIcon("zoom-out"));
42     m_ui.buttonGridChange->setIcon(KIcon("view-grid"));
43     m_ui.buttonShowPixmap->setIcon(QIcon(QPixmap::fromImage(ColorTools::rgbCurvePlane(QSize(16, 16), ColorTools::COL_Luma, 0.8))));
44     m_ui.buttonResetSpline->setIcon(KIcon("view-refresh"));
45     m_ui.buttonShowAllHandles->setIcon(KIcon("draw-bezier-curves"));
46     m_ui.widgetPoint->setEnabled(false);
47
48     CubicBezierSpline s;
49     s.fromString(spline);
50     m_edit.setSpline(s);
51
52     connect(&m_edit, SIGNAL(modified()), this, SIGNAL(modified()));
53     connect(&m_edit, SIGNAL(currentPoint(const BPoint&)), this, SLOT(slotUpdatePointEntries(const BPoint&)));
54
55     connect(m_ui.spinPX, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointP()));
56     connect(m_ui.spinPY, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointP()));
57     connect(m_ui.spinH1X, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointH1()));
58     connect(m_ui.spinH1Y, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointH1()));
59     connect(m_ui.spinH2X, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointH2()));
60     connect(m_ui.spinH2Y, SIGNAL(editingFinished()), this, SLOT(slotUpdatePointH2()));
61
62     connect(m_ui.buttonLinkHandles, SIGNAL(toggled(bool)), this, SLOT(slotSetHandlesLinked(bool)));
63     connect(m_ui.buttonZoomIn, SIGNAL(clicked()), &m_edit, SLOT(slotZoomIn()));
64     connect(m_ui.buttonZoomOut, SIGNAL(clicked()), &m_edit, SLOT(slotZoomOut()));
65     connect(m_ui.buttonGridChange, SIGNAL(clicked()), this, SLOT(slotGridChange()));
66     connect(m_ui.buttonShowPixmap, SIGNAL(toggled(bool)), this, SLOT(slotShowPixmap(bool)));
67     connect(m_ui.buttonResetSpline, SIGNAL(clicked()), this, SLOT(slotResetSpline()));
68     connect(m_ui.buttonShowAllHandles, SIGNAL(toggled(bool)), this, SLOT(slotShowAllHandles(bool)));
69
70     m_edit.setGridLines(KdenliveSettings::bezier_gridlines());
71     m_ui.buttonShowPixmap->setChecked(KdenliveSettings::bezier_showpixmap());
72     m_ui.buttonShowAllHandles->setChecked(KdenliveSettings::bezier_showallhandles());
73 }
74
75 QString BezierSplineWidget::spline()
76 {
77     return m_edit.spline().toString();
78 }
79
80 void BezierSplineWidget::setMode(BezierSplineWidget::CurveModes mode)
81 {
82     if (m_mode != mode) {
83         m_mode = mode;
84         if (m_showPixmap)
85             slotShowPixmap();
86     }
87 }
88
89 void BezierSplineWidget::slotGridChange()
90 {
91     m_edit.setGridLines((m_edit.gridLines() + 1) % 9);
92     KdenliveSettings::setBezier_gridlines(m_edit.gridLines());
93 }
94
95 void BezierSplineWidget::slotShowPixmap(bool show)
96 {
97     m_showPixmap = show;
98     KdenliveSettings::setBezier_showpixmap(show);
99     if (show && (m_mode == ModeRed || m_mode == ModeGreen || m_mode == ModeBlue || m_mode == ModeLuma ))
100         m_edit.setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(m_edit.size(), (ColorTools::ColorsRGB)((int)(m_mode == ModeLuma ? int(m_mode) - 1 : m_mode)))));
101     else
102         m_edit.setPixmap(QPixmap());
103 }
104
105 void BezierSplineWidget::slotUpdatePointEntries(const BPoint &p)
106 {
107     blockSignals(true);
108     if (p == BPoint()) {
109         m_ui.widgetPoint->setEnabled(false);
110     } else {
111         m_ui.widgetPoint->setEnabled(true);
112         m_ui.spinPX->setValue(qRound(p.p.x() * 255));
113         m_ui.spinPY->setValue(qRound(p.p.y() * 255));
114         m_ui.spinH1X->setValue(qRound(p.h1.x() * 255));
115         m_ui.spinH1Y->setValue(qRound(p.h1.y() * 255));
116         m_ui.spinH2X->setValue(qRound(p.h2.x() * 255));
117         m_ui.spinH2Y->setValue(qRound(p.h2.y() * 255));
118         m_ui.buttonLinkHandles->setChecked(p.handlesLinked);
119     }
120     blockSignals(false);
121 }
122
123 void BezierSplineWidget::slotUpdatePointP()
124 {
125     BPoint p = m_edit.getCurrentPoint();
126
127     p.setP(QPointF(m_ui.spinPX->value() / 255., m_ui.spinPY->value() / 255.));
128
129     m_edit.updateCurrentPoint(p);
130 }
131
132 void BezierSplineWidget::slotUpdatePointH1()
133 {
134     BPoint p = m_edit.getCurrentPoint();
135
136     p.setH1(QPointF(m_ui.spinH1X->value() / 255., m_ui.spinH1Y->value() / 255.));
137
138     m_edit.updateCurrentPoint(p);
139 }
140
141 void BezierSplineWidget::slotUpdatePointH2()
142 {
143     BPoint p = m_edit.getCurrentPoint();
144
145     p.setH2(QPointF(m_ui.spinH2X->value() / 255., m_ui.spinH2Y->value() / 255.));
146
147     m_edit.updateCurrentPoint(p);
148 }
149
150 void BezierSplineWidget::slotSetHandlesLinked(bool linked)
151 {
152     BPoint p = m_edit.getCurrentPoint();
153     p.handlesLinked = linked;
154     m_edit.updateCurrentPoint(p);
155 }
156
157 void BezierSplineWidget::slotResetSpline()
158 {
159     m_edit.setSpline(CubicBezierSpline());
160 }
161
162 void BezierSplineWidget::slotShowAllHandles(bool show)
163 {
164     m_edit.setShowAllHandles(show);
165     KdenliveSettings::setBezier_showallhandles(show);
166 }
167
168 #include "beziersplinewidget.moc"