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 "kdenlivesettings.h"
23 #include <QVBoxLayout>
27 BezierSplineWidget::BezierSplineWidget(const QString& spline, QWidget* parent) :
31 QVBoxLayout *layout = new QVBoxLayout(this);
32 layout->addWidget(&m_edit);
33 QWidget *widget = new QWidget(this);
35 layout->addWidget(widget);
37 m_ui.buttonLinkHandles->setIcon(KIcon("insert-link"));
38 m_ui.buttonLinkHandles->setEnabled(false);
39 m_ui.buttonZoomIn->setIcon(KIcon("zoom-in"));
40 m_ui.buttonZoomOut->setIcon(KIcon("zoom-out"));
41 m_ui.buttonGridChange->setIcon(KIcon("view-grid"));
42 m_ui.buttonShowPixmap->setIcon(QIcon(QPixmap::fromImage(ColorTools::rgbCurvePlane(QSize(16, 16), ColorTools::COL_Luma, 0.8))));
43 m_ui.widgetPoint->setEnabled(false);
49 connect(&m_edit, SIGNAL(modified()), this, SIGNAL(modified()));
50 connect(&m_edit, SIGNAL(currentPoint(const BPoint&)), this, SLOT(slotUpdatePoint(const BPoint&)));
52 connect(m_ui.spinPX, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline()));
53 connect(m_ui.spinPY, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline()));
54 connect(m_ui.spinH1X, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline()));
55 connect(m_ui.spinH1Y, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline()));
56 connect(m_ui.spinH2X, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline()));
57 connect(m_ui.spinH2Y, SIGNAL(editingFinished()), this, SLOT(slotUpdateSpline()));
59 connect(m_ui.buttonZoomIn, SIGNAL(clicked()), &m_edit, SLOT(slotZoomIn()));
60 connect(m_ui.buttonZoomOut, SIGNAL(clicked()), &m_edit, SLOT(slotZoomOut()));
61 connect(m_ui.buttonGridChange, SIGNAL(clicked()), this, SLOT(slotGridChange()));
62 connect(m_ui.buttonShowPixmap, SIGNAL(toggled(bool)), this, SLOT(slotShowPixmap(bool)));
64 m_edit.setGridLines(KdenliveSettings::bezier_gridlines());
65 m_ui.buttonShowPixmap->setChecked(KdenliveSettings::bezier_showpixmap());
68 QString BezierSplineWidget::spline()
70 return m_edit.spline().toString();
73 void BezierSplineWidget::setMode(BezierSplineWidget::CurveModes mode)
82 void BezierSplineWidget::slotGridChange()
84 m_edit.setGridLines((m_edit.gridLines() + 1) % 9);
85 KdenliveSettings::setBezier_gridlines(m_edit.gridLines());
88 void BezierSplineWidget::slotShowPixmap(bool show)
91 KdenliveSettings::setBezier_showpixmap(show);
93 m_edit.setPixmap(QPixmap::fromImage(ColorTools::rgbCurvePlane(m_edit.size(), (ColorTools::ColorsRGB)((int)m_mode), 0.8)));
95 m_edit.setPixmap(QPixmap());
98 void BezierSplineWidget::slotUpdatePoint(const BPoint &p)
102 m_ui.widgetPoint->setEnabled(false);
104 m_ui.widgetPoint->setEnabled(true);
105 m_ui.spinPX->setValue(qRound(p.p.x() * 255));
106 m_ui.spinPY->setValue(qRound(p.p.y() * 255));
107 m_ui.spinH1X->setValue(qRound(p.h1.x() * 255));
108 m_ui.spinH1Y->setValue(qRound(p.h1.y() * 255));
109 m_ui.spinH2X->setValue(qRound(p.h2.x() * 255));
110 m_ui.spinH2Y->setValue(qRound(p.h2.y() * 255));
115 void BezierSplineWidget::slotUpdateSpline()
117 BPoint p = m_edit.getCurrentPoint();
119 // check for every value, so we do not lose too much info through rounding
120 if (m_ui.spinPX->value() != qRound(p.p.x() * 255))
121 p.p.setX(m_ui.spinPX->value() / 255.);
122 if (m_ui.spinPY->value() != qRound(p.p.y() * 255))
123 p.p.setY(m_ui.spinPY->value() / 255.);
125 if (m_ui.spinH1X->value() != qRound(p.h1.x() * 255))
126 p.h1.setX(m_ui.spinH1X->value() / 255.);
127 if (m_ui.spinH1Y->value() != qRound(p.h1.y() * 255))
128 p.h1.setY(m_ui.spinH1Y->value() / 255.);
130 if (m_ui.spinH2X->value() != qRound(p.h2.x() * 255))
131 p.h2.setX(m_ui.spinH2X->value() / 255.);
132 if (m_ui.spinH2Y->value() != qRound(p.h2.y() * 255))
133 p.h2.setY(m_ui.spinH2Y->value() / 255.);
135 m_edit.updateCurrentPoint(p);
139 #include "beziersplinewidget.moc"