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"
13 #include <KMessageBox>
15 const QString EXTENSION_PNG = ".png";
16 const int SCALE_RANGE = 80;
18 ColorPlaneExport::ColorPlaneExport(QWidget *parent) :
23 m_colorTools = new ColorTools();
25 tResX->setText("800");
26 tResY->setText("800");
28 cbColorspace->addItem(i18n("YUV"), QVariant(CPE_YUV));
29 cbColorspace->addItem(i18n("Modified YUV (Chroma)"), QVariant(CPE_YUV_MOD));
31 sliderColor->setSliderPosition(128);
36 sliderScaling->setInvertedAppearance(true);
37 sliderScaling->setRange(0, 80);
38 sliderScaling->setSliderPosition(50);
40 connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotExportPlane()));
41 connect(tResX, SIGNAL(textChanged(QString)), this, SLOT(slotValidate()));
42 connect(tResY, SIGNAL(textChanged(QString)), this, SLOT(slotValidate()));
43 connect(kurlrequester, SIGNAL(textChanged(QString)), this, SLOT(slotValidate()));
44 connect(sliderColor, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateDisplays()));
45 connect(sliderScaling, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateDisplays()));
47 kurlrequester->setText("/tmp/yuv-plane.png");
49 slotColormodeChanged();
53 ColorPlaneExport::~ColorPlaneExport()
58 void ColorPlaneExport::slotUpdateDisplays()
60 m_scaling = 1 - (float)sliderScaling->value()/100;
62 lblScaleNr->setText("0..." + QString::number(m_scaling, 'f', 2));
63 lblColNr->setText(QString::number(sliderColor->value()));
65 lblSize->setText(i18n("%1 px", QVariant(tResX->text()).toInt()*QVariant(tResY->text()).toInt()));
68 void ColorPlaneExport::slotValidate()
73 nr = QVariant(tResX->text()).toInt(&ok);
76 nr = QVariant(tResY->text()).toInt(&ok);
80 ok = kurlrequester->text().trimmed().length() > 0;
81 qDebug() << "File given: " << ok;
85 buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
87 buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
93 void ColorPlaneExport::slotExportPlane()
95 qDebug() << "Exporting plane now to " << kurlrequester->text();
96 QString lower = kurlrequester->text().toLower();
97 qDebug() << "Lower: " << lower;
98 if (!lower.endsWith(".png") && !lower.endsWith(".jpg") && !lower.endsWith(".tif") && !lower.endsWith(".tiff")) {
99 if (KMessageBox::questionYesNo(this, i18n("File has no extension. Add extension (%1)?", EXTENSION_PNG)) == KMessageBox::Yes) {
100 kurlrequester->setText(kurlrequester->text() + ".png");
104 QSize size(QVariant(tResX->text()).toInt(), QVariant(tResY->text()).toInt());
105 switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
107 img = m_colorTools->yuvColorWheel(size, sliderColor->value(), m_scaling, false, false);
110 img = m_colorTools->yuvColorWheel(size, sliderColor->value(), m_scaling, true, false);
113 img.save(kurlrequester->text());
116 void ColorPlaneExport::slotColormodeChanged()
118 switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
121 sliderColor->setVisible(true);
122 sliderColor->setRange(0,255);
125 sliderColor->setVisible(false);