]> git.sesse.net Git - kdenlive/blob - src/rgbparade.cpp
RGB Parade changes:
[kdenlive] / src / 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 "rgbparadegenerator.h"
18
19 RGBParade::RGBParade(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent) :
20         AbstractScopeWidget(projMonitor, clipMonitor, 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     AbstractScopeWidget::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", true));
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     if (scopeRect().height() > 0 && m_mouseWithinWidget) {
92         QImage hud(m_scopeRect.size(), QImage::Format_ARGB32);
93         hud.fill(qRgba(0,0,0,0));
94
95         QPainter davinci(&hud);
96         davinci.setPen(penLight);
97
98         int x = scopeRect().width()-30;
99         int y = m_mousePos.y() - scopeRect().y();
100
101         // Draw a horizontal line through the current mouse position
102         // and show the value of the waveform there
103         davinci.drawLine(0, y, scopeRect().size().width()-RGBParadeGenerator::distRight, y);
104
105         int val = 255*(1-((float)y/(scopeRect().height()-RGBParadeGenerator::distBottom)));
106         davinci.drawText(x, scopeRect().height()/2, QVariant(val).toString());
107
108         emit signalHUDRenderingFinished(1, 1);
109         return hud;
110     } else {
111         emit signalHUDRenderingFinished(1, 1);
112         return QImage();
113     }
114 }
115 QImage RGBParade::renderScope(uint accelerationFactor, QImage qimage)
116 {
117     QTime start = QTime::currentTime();
118     start.start();
119
120     int paintmode = ui->paintMode->itemData(ui->paintMode->currentIndex()).toInt();
121     QImage parade = m_rgbParadeGenerator->calculateRGBParade(m_scopeRect.size(), qimage, (RGBParadeGenerator::PaintMode) paintmode,
122                                                     m_aAxis->isChecked(), m_aGradRef->isChecked(), accelerationFactor);
123     emit signalScopeRenderingFinished(start.elapsed(), accelerationFactor);
124     return parade;
125 }
126 QImage RGBParade::renderBackground(uint) { return QImage(); }
127
128 bool RGBParade::isHUDDependingOnInput() const { return false; }
129 bool RGBParade::isScopeDependingOnInput() const { return true; }
130 bool RGBParade::isBackgroundDependingOnInput() const { return false; }