]> git.sesse.net Git - kdenlive/blob - src/histogram.cpp
* Scopes: Configuration is saved now.
[kdenlive] / src / histogram.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 <QTime>
13 #include "histogramgenerator.h"
14 #include "histogram.h"
15 #include "renderer.h"
16
17 Histogram::Histogram(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent) :
18     AbstractScopeWidget(projMonitor, clipMonitor, parent)
19 {
20     ui = new Ui::Histogram_UI();
21     ui->setupUi(this);
22     init();
23
24     ui->cbY->setChecked(true);
25     ui->cbR->setChecked(true);
26     ui->cbG->setChecked(true);
27     ui->cbB->setChecked(true);
28
29
30     m_aUnscaled = new QAction(i18n("Unscaled"), this);
31     m_aUnscaled->setCheckable(true);
32     m_menu->addSeparator();
33     m_menu->addAction(m_aUnscaled);
34
35     bool b = true;
36     b &= connect(ui->cbY, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
37     b &= connect(ui->cbR, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
38     b &= connect(ui->cbG, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
39     b &= connect(ui->cbB, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
40     b &= connect(m_aUnscaled, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
41     Q_ASSERT(b);
42
43 }
44
45 Histogram::~Histogram()
46 {
47     delete ui;
48     delete m_aUnscaled;
49 }
50
51 QString Histogram::widgetName() const { return QString("Histogram"); }
52
53 bool Histogram::isHUDDependingOnInput() const { return false; }
54 bool Histogram::isScopeDependingOnInput() const { return true; }
55 bool Histogram::isBackgroundDependingOnInput() const { return false; }
56
57 QRect Histogram::scopeRect()
58 {
59     qDebug() << "According to the spacer, the top left point is " << ui->verticalSpacer->geometry().x() << "/" << ui->verticalSpacer->geometry().y();
60     QPoint topleft(offset, offset+ ui->verticalSpacer->geometry().y());
61     return QRect(topleft, this->rect().size() - QSize(topleft.x() + offset, topleft.y() + offset));
62 }
63
64 QImage Histogram::renderHUD(uint)
65 {
66     emit signalHUDRenderingFinished(0, 1);
67     return QImage();
68 }
69 QImage Histogram::renderScope(uint accelFactor, QImage qimage)
70 {
71     QTime start = QTime::currentTime();
72     start.start();
73
74     const int componentFlags =   (ui->cbY->isChecked() ? 1 : 0) * HistogramGenerator::ComponentY
75                                | (ui->cbR->isChecked() ? 1 : 0) * HistogramGenerator::ComponentR
76                                | (ui->cbG->isChecked() ? 1 : 0) * HistogramGenerator::ComponentG
77                                | (ui->cbB->isChecked() ? 1 : 0) * HistogramGenerator::ComponentB;
78
79     QImage histogram = m_histogramGenerator->calculateHistogram(m_scopeRect.size(), qimage,
80                                                        componentFlags, m_aUnscaled->isChecked(), accelFactor);
81
82     emit signalScopeRenderingFinished(start.elapsed(), accelFactor);
83     return histogram;
84 }
85 QImage Histogram::renderBackground(uint)
86 {
87     emit signalBackgroundRenderingFinished(0, 1);
88     return QImage();
89 }