]> git.sesse.net Git - kdenlive/blob - src/scopes/colorscopes/rgbparade.cpp
Const'ref
[kdenlive] / src / scopes / colorscopes / rgbparade.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 <QMenu>
12 #include <QPainter>
13 #include <QRect>
14 #include <QTime>
15 #include "rgbparade.h"
16 #include "colorcorrection/rgbparadegenerator.h"
17
18 RGBParade::RGBParade(QWidget *parent) :
19         AbstractGfxScopeWidget(true, parent)
20 {
21     ui = new Ui::RGBParade_UI();
22     ui->setupUi(this);
23
24     ui->paintMode->addItem(i18n("RGB"), QVariant(RGBParadeGenerator::PaintMode_RGB));
25     ui->paintMode->addItem(i18n("White"), QVariant(RGBParadeGenerator::PaintMode_White));
26
27     bool b = true;
28
29     m_menu->addSeparator();
30     m_aAxis = new QAction(i18n("Draw axis"), this);
31     m_aAxis->setCheckable(true);
32     m_menu->addAction(m_aAxis);
33     b &= connect(m_aAxis, SIGNAL(changed()), this, SLOT(forceUpdateScope()));
34
35     m_aGradRef = new QAction(i18n("Gradient reference line"), this);
36     m_aGradRef->setCheckable(true);
37     m_menu->addAction(m_aGradRef);
38     b &= connect(m_aGradRef, SIGNAL(changed()), this, SLOT(forceUpdateScope()));
39
40     b &= connect(ui->paintMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceUpdateScope()));
41     b &= connect(this, SIGNAL(signalMousePositionChanged()), this, SLOT(forceUpdateHUD()));
42     Q_ASSERT(b);
43
44     m_rgbParadeGenerator = new RGBParadeGenerator();
45     init();
46 }
47
48 RGBParade::~RGBParade()
49 {
50     writeConfig();
51
52     delete ui;
53     delete m_rgbParadeGenerator;
54     delete m_aAxis;
55     delete m_aGradRef;
56 }
57
58 void RGBParade::readConfig()
59 {
60     AbstractGfxScopeWidget::readConfig();
61
62     KSharedConfigPtr config = KGlobal::config();
63     KConfigGroup scopeConfig(config, configName());
64     ui->paintMode->setCurrentIndex(scopeConfig.readEntry("paintmode", 0));
65     m_aAxis->setChecked(scopeConfig.readEntry("axis", false));
66     m_aGradRef->setChecked(scopeConfig.readEntry("gradref", false));
67 }
68
69 void RGBParade::writeConfig()
70 {
71     KSharedConfigPtr config = KGlobal::config();
72     KConfigGroup scopeConfig(config, configName());
73     scopeConfig.writeEntry("paintmode", ui->paintMode->currentIndex());
74     scopeConfig.writeEntry("axis", m_aAxis->isChecked());
75     scopeConfig.writeEntry("gradref", m_aGradRef->isChecked());
76     scopeConfig.sync();
77 }
78
79
80 QString RGBParade::widgetName() const { return "RGB Parade"; }
81
82 QRect RGBParade::scopeRect()
83 {
84     QPoint topleft(offset, ui->verticalSpacer->geometry().y() + 2*offset);
85     return QRect(topleft, QPoint(this->size().width() - offset, this->size().height() - offset));
86 }
87
88 QImage RGBParade::renderHUD(uint)
89 {
90     QImage hud(m_scopeRect.size(), QImage::Format_ARGB32);
91     hud.fill(qRgba(0,0,0,0));
92
93     QPainter davinci(&hud);
94     davinci.setPen(penLight);
95
96     int x = scopeRect().width()-30;
97
98     davinci.drawText(x, scopeRect().height()-RGBParadeGenerator::distBottom, "0");
99     davinci.drawText(x, 10, "255");
100
101     if (scopeRect().height() > 0 && m_mouseWithinWidget) {
102
103         int y = m_mousePos.y() - scopeRect().y();
104
105         // Draw a horizontal line through the current mouse position
106         // and show the value of the waveform there
107         davinci.drawLine(0, y, scopeRect().size().width()-RGBParadeGenerator::distRight, y);
108
109         // Make the value stick to the line unless it is at the top/bottom of the scope
110         const int top = 30;
111         const int bottom = 20+RGBParadeGenerator::distBottom;
112         int valY = y+5;
113         if (valY < top) {
114             valY = top;
115         } else if (valY > scopeRect().height()-bottom) {
116             valY = scopeRect().height()-bottom;
117         }
118         int val = 255*(1-((float)y/(scopeRect().height()-RGBParadeGenerator::distBottom)));
119         davinci.drawText(x, valY, QVariant(val).toString());
120     }
121
122     emit signalHUDRenderingFinished(1, 1);
123     return hud;
124 }
125
126 QImage RGBParade::renderGfxScope(uint accelerationFactor, const QImage &qimage)
127 {
128     QTime start = QTime::currentTime();
129     start.start();
130
131     int paintmode = ui->paintMode->itemData(ui->paintMode->currentIndex()).toInt();
132     QImage parade = m_rgbParadeGenerator->calculateRGBParade(m_scopeRect.size(), qimage, (RGBParadeGenerator::PaintMode) paintmode,
133                                                     m_aAxis->isChecked(), m_aGradRef->isChecked(), accelerationFactor);
134     emit signalScopeRenderingFinished(start.elapsed(), accelerationFactor);
135     return parade;
136 }
137
138 QImage RGBParade::renderBackground(uint)
139 {
140     return QImage();
141 }
142
143 bool RGBParade::isHUDDependingOnInput() const
144 {
145     return false;
146 }
147
148 bool RGBParade::isScopeDependingOnInput() const
149 {
150     return true;
151 }
152
153 bool RGBParade::isBackgroundDependingOnInput() const
154 {
155     return false;
156 }
157