1 /***************************************************************************
2 * Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com) *
3 * This file is part of kdenlive. See www.kdenlive.org. *
5 * This program 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 ***************************************************************************/
11 #include "colorplaneexport.h"
12 #include <KMessageBox>
19 const QString EXTENSION_PNG = ".png";
20 const int SCALE_RANGE = 80;
22 ColorPlaneExport::ColorPlaneExport(QWidget *parent) :
27 m_colorTools = new ColorTools();
29 tResX->setText("800");
30 tResY->setText("800");
32 cbColorspace->addItem(i18n("YUV UV plane"), QVariant(ColorPlaneExport::CPE_YUV));
33 cbColorspace->addItem(i18n("YUV Y plane"), QVariant(ColorPlaneExport::CPE_YUV_Y));
34 cbColorspace->addItem(i18n("Modified YUV (Chroma)"), QVariant(ColorPlaneExport::CPE_YUV_MOD));
35 cbColorspace->addItem(i18n("YCbCr CbCr plane"), QVariant(ColorPlaneExport::CPE_YPbPr));
36 cbColorspace->addItem(i18n("RGB plane, one component varying"), QVariant(ColorPlaneExport::CPE_RGB_CURVE));
37 cbColorspace->addItem(i18n("HSV Hue Shift"), QVariant(ColorPlaneExport::CPE_HSV_HUESHIFT));
39 sliderColor->setSliderPosition(128);
44 sliderScaling->setInvertedAppearance(true);
45 sliderScaling->setRange(0, 80);
46 sliderScaling->setSliderPosition(50);
48 connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotExportPlane()));
49 connect(tResX, SIGNAL(textChanged(QString)), this, SLOT(slotValidate()));
50 connect(tResY, SIGNAL(textChanged(QString)), this, SLOT(slotValidate()));
51 connect(kurlrequester, SIGNAL(textChanged(QString)), this, SLOT(slotValidate()));
52 connect(sliderColor, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateDisplays()));
53 connect(sliderScaling, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateDisplays()));
54 connect(cbColorspace, SIGNAL(currentIndexChanged(int)), this, SLOT(slotColormodeChanged()));
56 kurlrequester->setUrl(KUrl("/tmp/yuv-plane.png"));
58 slotColormodeChanged();
62 ColorPlaneExport::~ColorPlaneExport()
69 ///// Helper functions /////
71 void ColorPlaneExport::enableSliderScaling(const bool &enable)
73 sliderScaling->setEnabled(enable);
74 lblScaling->setEnabled(enable);
75 lblScaleNr->setEnabled(enable);
78 void ColorPlaneExport::enableSliderColor(const bool &enable)
80 sliderColor->setEnabled(enable);
81 lblSliderName->setEnabled(enable);
82 lblColNr->setEnabled(enable);
85 void ColorPlaneExport::enableCbVariant(const bool &enable)
87 cbVariant->setEnabled(enable);
88 lblVariant->setEnabled(enable);
90 while (cbVariant->count() > 0) {
91 cbVariant->removeItem(0);
100 void ColorPlaneExport::slotUpdateDisplays()
102 m_scaling = 1 - (float)sliderScaling->value()/100;
104 switch(cbColorspace->itemData(cbColorspace->currentIndex()).toInt()){
106 lblScaleNr->setText(QChar(0xb1) + QString::number(sliderScaling->value(), 'f', 2));;
108 case CPE_HSV_HUESHIFT:
109 lblScaleNr->setText(QString::number(sliderScaling->value()));
112 lblScaleNr->setText("0..." + QString::number(m_scaling, 'f', 2));
116 switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
118 lblColNr->setText(i18n("%1°", QString::number(sliderColor->value())));
121 lblColNr->setText(QString::number(sliderColor->value()));
125 lblSize->setText(i18n("%1 px", QVariant(tResX->text()).toInt()*QVariant(tResY->text()).toInt()));
128 void ColorPlaneExport::slotValidate()
133 nr = QVariant(tResX->text()).toInt(&ok);
136 nr = QVariant(tResY->text()).toInt(&ok);
140 ok = kurlrequester->text().trimmed().length() > 0;
142 qDebug() << "File given: " << ok;
147 buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
149 buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
152 slotUpdateDisplays();
155 void ColorPlaneExport::slotExportPlane()
158 qDebug() << "Exporting plane now to " << kurlrequester->text();
160 QString lower = kurlrequester->text().toLower();
162 qDebug() << "Lower: " << lower;
164 if (!lower.endsWith(".png") && !lower.endsWith(".jpg") && !lower.endsWith(".tif") && !lower.endsWith(".tiff")) {
165 if (KMessageBox::questionYesNo(this, i18n("File has no extension. Add extension (%1)?", EXTENSION_PNG)) == KMessageBox::Yes) {
166 kurlrequester->setUrl(KUrl(kurlrequester->text() + ".png"));
170 QSize size(QVariant(tResX->text()).toInt(), QVariant(tResY->text()).toInt());
171 switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
173 img = m_colorTools->yuvColorWheel(size, sliderColor->value(), m_scaling, false, false);
176 img = m_colorTools->yuvVerticalPlane(size, sliderColor->value(), m_scaling);
179 img = m_colorTools->yuvColorWheel(size, sliderColor->value(), m_scaling, true, false);
182 img = m_colorTools->rgbCurvePlane(size, (ColorTools::ColorsRGB) (cbVariant->itemData(cbVariant->currentIndex()).toInt()),
183 (double)sliderScaling->value()/255);
186 img = m_colorTools->yPbPrColorWheel(size, sliderColor->value(), m_scaling, false);
188 case CPE_HSV_HUESHIFT:
189 img = m_colorTools->hsvHueShiftPlane(size, sliderColor->value(), sliderScaling->value(), -180, 180);
192 img.save(kurlrequester->text());
195 void ColorPlaneExport::slotColormodeChanged()
198 qDebug() << "Color mode changed to " << cbColorspace->itemData(cbColorspace->currentIndex()).toInt();
200 lblScaling->setText(i18n("Scaling"));
201 sliderScaling->setInvertedAppearance(true);
202 switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
206 enableSliderScaling(true);
207 enableSliderColor(true);
208 enableCbVariant(false);
209 sliderColor->setRange(0,255);
210 sliderColor->setPageStep(128);
211 lblSliderName->setText(i18n("Y value"));
212 lblSliderName->setToolTip(i18n("The Y value describes the brightness of the colors."));
216 qDebug() << "Changing slider range.";
218 enableSliderScaling(true);
219 enableSliderColor(true);
220 enableCbVariant(false);
221 sliderColor->setMaximum(321);
222 sliderColor->setRange(0,179);
223 sliderColor->setPageStep(90);
224 lblSliderName->setText(i18n("UV angle"));
225 lblSliderName->setToolTip(i18n("Angle through the UV plane, with all possible Y values."));
228 enableSliderScaling(true);
229 enableSliderColor(false);
230 enableCbVariant(true);
231 sliderScaling->setRange(1,255);
232 sliderScaling->setValue(255);
233 cbVariant->addItem(i18n("Red"), QVariant(ColorTools::COL_R));
234 cbVariant->addItem(i18n("Green"), QVariant(ColorTools::COL_G));
235 cbVariant->addItem(i18n("Blue"), QVariant(ColorTools::COL_B));
236 cbVariant->addItem(i18n("Luma"), QVariant(ColorTools::COL_Luma));
238 case CPE_HSV_HUESHIFT:
239 enableSliderScaling(true);
240 enableSliderColor(true);
241 enableCbVariant(false);
242 sliderScaling->setRange(0,255);
243 sliderScaling->setValue(200);
244 sliderScaling->setInvertedAppearance(false);
245 sliderColor->setRange(0,255);
246 sliderColor->setValue(200);
247 lblSliderName->setText(i18n("HSV Saturation"));
248 lblScaling->setText(i18n("HSV Value"));
251 enableSliderScaling(false);
252 enableSliderColor(false);
253 enableCbVariant(true);
254 cbVariant->addItem(i18n("Red"), QVariant(ColorTools::COL_R));
255 cbVariant->addItem(i18n("Green"), QVariant(ColorTools::COL_G));
256 cbVariant->addItem(i18n("Blue"), QVariant(ColorTools::COL_B));
257 cbVariant->addItem(i18n("Luma"), QVariant(ColorTools::COL_Luma));
261 slotUpdateDisplays();