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