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 ***************************************************************************/
12 #include <QMouseEvent>
18 #include "waveformgenerator.h"
21 const QSize Waveform::m_textWidth(35,0);
23 Waveform::Waveform(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent) :
24 AbstractScopeWidget(projMonitor, clipMonitor, true, parent)
26 ui = new Ui::Waveform_UI();
29 ui->paintMode->addItem(i18n("Yellow"), QVariant(WaveformGenerator::PaintMode_Yellow));
30 ui->paintMode->addItem(i18n("White"), QVariant(WaveformGenerator::PaintMode_White));
31 ui->paintMode->addItem(i18n("Green"), QVariant(WaveformGenerator::PaintMode_Green));
34 m_aRec601 = new QAction(i18n("Rec. 601"), this);
35 m_aRec601->setCheckable(true);
36 m_aRec709 = new QAction(i18n("Rec. 709"), this);
37 m_aRec709->setCheckable(true);
38 m_agRec = new QActionGroup(this);
39 m_agRec->addAction(m_aRec601);
40 m_agRec->addAction(m_aRec709);
41 m_menu->addSeparator()->setText(i18n("Luma mode"));
42 m_menu->addAction(m_aRec601);
43 m_menu->addAction(m_aRec709);
47 b &= connect(ui->paintMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceUpdateScope()));
48 b &= connect(this, SIGNAL(signalMousePositionChanged()), this, SLOT(forceUpdateHUD()));
49 b &= connect(m_aRec601, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
50 b &= connect(m_aRec709, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
54 m_waveformGenerator = new WaveformGenerator();
61 delete m_waveformGenerator;
67 void Waveform::readConfig()
69 AbstractScopeWidget::readConfig();
71 KSharedConfigPtr config = KGlobal::config();
72 KConfigGroup scopeConfig(config, configName());
73 ui->paintMode->setCurrentIndex(scopeConfig.readEntry("paintmode", 0));
74 m_aRec601->setChecked(scopeConfig.readEntry("rec601", false));
75 m_aRec709->setChecked(!m_aRec601->isChecked());
78 void Waveform::writeConfig()
80 KSharedConfigPtr config = KGlobal::config();
81 KConfigGroup scopeConfig(config, configName());
82 scopeConfig.writeEntry("paintmode", ui->paintMode->currentIndex());
83 scopeConfig.writeEntry("rec601", m_aRec601->isChecked());
88 QRect Waveform::scopeRect()
90 // Distance from top/left/right
93 QPoint topleft(offset, ui->verticalSpacer->geometry().y()+offset);
95 return QRect(topleft, this->size() - QSize(offset+topleft.x(), offset+topleft.y()));
99 ///// Implemented methods /////
101 QString Waveform::widgetName() const { return QString("Waveform"); }
102 bool Waveform::isHUDDependingOnInput() const { return false; }
103 bool Waveform::isScopeDependingOnInput() const { return true; }
104 bool Waveform::isBackgroundDependingOnInput() const { return false; }
106 QImage Waveform::renderHUD(uint)
108 QImage hud(m_scopeRect.size(), QImage::Format_ARGB32);
109 hud.fill(qRgba(0,0,0,0));
111 QPainter davinci(&hud);
112 davinci.setPen(penLight);
114 int x = scopeRect().width()-m_textWidth.width()+3;
115 int y = m_mousePos.y() - scopeRect().y();
117 if (scopeRect().height() > 0 && m_mouseWithinWidget) {
118 // Draw a horizontal line through the current mouse position
119 // and show the value of the waveform there
120 davinci.drawLine(0, y, scopeRect().size().width()-m_textWidth.width(), y);
122 // Make the value stick to the line unless it is at the top/bottom of the scope
124 const int bottom = 20;
128 } else if (valY > scopeRect().height()-bottom) {
129 valY = scopeRect().height()-bottom;
131 int val = 255*(1-(float)y/scopeRect().height());
132 davinci.drawText(x, valY, QVariant(val).toString());
134 davinci.drawText(x, scopeRect().height(), "0");
135 davinci.drawText(x, 10, "255");
137 emit signalHUDRenderingFinished(0, 1);
141 QImage Waveform::renderScope(uint accelFactor, QImage qimage)
143 QTime start = QTime::currentTime();
146 int paintmode = ui->paintMode->itemData(ui->paintMode->currentIndex()).toInt();
147 WaveformGenerator::Rec rec = m_aRec601->isChecked() ? WaveformGenerator::Rec_601 : WaveformGenerator::Rec_709;
148 QImage wave = m_waveformGenerator->calculateWaveform(scopeRect().size() - m_textWidth, qimage, (WaveformGenerator::PaintMode) paintmode,
149 true, rec, accelFactor);
151 emit signalScopeRenderingFinished(start.elapsed(), 1);
155 QImage Waveform::renderBackground(uint)
157 emit signalBackgroundRenderingFinished(0, 1);