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 ***************************************************************************/
16 #include "rgbparade.h"
17 #include "rgbparadegenerator.h"
19 RGBParade::RGBParade(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent) :
20 AbstractGfxScopeWidget(projMonitor, clipMonitor, true, parent)
22 ui = new Ui::RGBParade_UI();
25 ui->paintMode->addItem(i18n("RGB"), QVariant(RGBParadeGenerator::PaintMode_RGB));
26 ui->paintMode->addItem(i18n("White"), QVariant(RGBParadeGenerator::PaintMode_White));
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()));
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()));
41 b &= connect(ui->paintMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceUpdateScope()));
42 b &= connect(this, SIGNAL(signalMousePositionChanged()), this, SLOT(forceUpdateHUD()));
45 m_rgbParadeGenerator = new RGBParadeGenerator();
49 RGBParade::~RGBParade()
54 delete m_rgbParadeGenerator;
59 void RGBParade::readConfig()
61 AbstractGfxScopeWidget::readConfig();
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));
70 void RGBParade::writeConfig()
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());
81 QString RGBParade::widgetName() const { return "RGB Parade"; }
83 QRect RGBParade::scopeRect()
85 QPoint topleft(offset, ui->verticalSpacer->geometry().y() + 2*offset);
86 return QRect(topleft, QPoint(this->size().width() - offset, this->size().height() - offset));
89 QImage RGBParade::renderHUD(uint)
91 QImage hud(m_scopeRect.size(), QImage::Format_ARGB32);
92 hud.fill(qRgba(0,0,0,0));
94 QPainter davinci(&hud);
95 davinci.setPen(penLight);
97 int x = scopeRect().width()-30;
99 davinci.drawText(x, scopeRect().height()-RGBParadeGenerator::distBottom, "0");
100 davinci.drawText(x, 10, "255");
102 if (scopeRect().height() > 0 && m_mouseWithinWidget) {
104 int y = m_mousePos.y() - scopeRect().y();
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);
110 // Make the value stick to the line unless it is at the top/bottom of the scope
112 const int bottom = 20+RGBParadeGenerator::distBottom;
116 } else if (valY > scopeRect().height()-bottom) {
117 valY = scopeRect().height()-bottom;
119 int val = 255*(1-((float)y/(scopeRect().height()-RGBParadeGenerator::distBottom)));
120 davinci.drawText(x, valY, QVariant(val).toString());
123 emit signalHUDRenderingFinished(1, 1);
127 QImage RGBParade::renderGfxScope(uint accelerationFactor, const QImage qimage)
129 QTime start = QTime::currentTime();
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);
139 QImage RGBParade::renderBackground(uint) { return QImage(); }
141 bool RGBParade::isHUDDependingOnInput() const { return false; }
142 bool RGBParade::isScopeDependingOnInput() const { return true; }
143 bool RGBParade::isBackgroundDependingOnInput() const { return false; }