]> git.sesse.net Git - kdenlive/blob - src/colorplaneexport.cpp
Vectorscope changes:
[kdenlive] / src / colorplaneexport.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com)      *
3  *   This file is part of kdenlive. See www.kdenlive.org.                  *
4  *                                                                         *
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  ***************************************************************************/
10
11 #include "colorplaneexport.h"
12 #include <QDebug>
13 #include <KMessageBox>
14
15 const QString EXTENSION_PNG = ".png";
16 const int SCALE_RANGE = 80;
17
18 ColorPlaneExport::ColorPlaneExport(QWidget *parent) :
19     QDialog(parent)
20 {
21     setupUi(this);
22
23     m_colorTools = new ColorTools();
24
25     tResX->setText("800");
26     tResY->setText("800");
27
28     cbColorspace->addItem(i18n("YUV"), QVariant(CPE_YUV));
29     cbColorspace->addItem(i18n("Modified YUV (Chroma)"), QVariant(CPE_YUV_MOD));
30
31     sliderColor->setSliderPosition(128);
32
33     // 0  -> 1
34     // 50 -> 0.5
35     // 80 -> 0.2
36     sliderScaling->setInvertedAppearance(true);
37     sliderScaling->setRange(0, 80);
38     sliderScaling->setSliderPosition(50);
39
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()));
46
47     kurlrequester->setText("/tmp/yuv-plane.png");
48
49     slotColormodeChanged();
50     slotValidate();
51 }
52
53 ColorPlaneExport::~ColorPlaneExport()
54 {
55     delete m_colorTools;
56 }
57
58 void ColorPlaneExport::slotUpdateDisplays()
59 {
60     m_scaling = 1 - (float)sliderScaling->value()/100;
61
62     lblScaleNr->setText("0..." + QString::number(m_scaling, 'f', 2));
63     lblColNr->setText(QString::number(sliderColor->value()));
64
65     lblSize->setText(i18n("%1 px", QVariant(tResX->text()).toInt()*QVariant(tResY->text()).toInt()));
66 }
67
68 void ColorPlaneExport::slotValidate()
69 {
70     bool ok;
71     int nr;
72
73     nr = QVariant(tResX->text()).toInt(&ok);
74     ok = ok && nr > 0;
75     if (ok) {
76         nr = QVariant(tResY->text()).toInt(&ok);
77         ok = ok && nr > 0;
78     }
79     if (ok) {
80         ok = kurlrequester->text().trimmed().length() > 0;
81         qDebug() << "File given: " << ok;
82     }
83
84     if (ok) {
85         buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
86     } else {
87         buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
88     }
89
90     slotUpdateDisplays();
91 }
92
93 void ColorPlaneExport::slotExportPlane()
94 {
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");
101         }
102     }
103     QImage img;
104     QSize size(QVariant(tResX->text()).toInt(), QVariant(tResY->text()).toInt());
105     switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
106     case CPE_YUV:
107         img = m_colorTools->yuvColorWheel(size, sliderColor->value(), m_scaling, false, false);
108         break;
109     case CPE_YUV_MOD:
110         img = m_colorTools->yuvColorWheel(size, sliderColor->value(), m_scaling, true, false);
111         break;
112     }
113     img.save(kurlrequester->text());
114 }
115
116 void ColorPlaneExport::slotColormodeChanged()
117 {
118     switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
119     case CPE_YUV:
120     case CPE_YUV_MOD:
121         sliderColor->setVisible(true);
122         sliderColor->setRange(0,255);
123         break;
124     default:
125         sliderColor->setVisible(false);
126         break;
127     }
128 }