]> git.sesse.net Git - kdenlive/blob - src/colorscopes/abstractgfxscopewidget.cpp
Reorganize and cleanup build structure
[kdenlive] / src / colorscopes / abstractgfxscopewidget.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 "abstractgfxscopewidget.h"
12 #include "renderer.h"
13 #include "monitormanager.h"
14
15 #include <QtConcurrentRun>
16 #include <QFuture>
17 #include <QColor>
18 #include <QMenu>
19 #include <QMouseEvent>
20 #include <QPainter>
21
22 // Uncomment for debugging.
23 //#define DEBUG_AGSW
24
25 #ifdef DEBUG_AGSW
26 #include <QDebug>
27 #endif
28
29 const int REALTIME_FPS = 30;
30
31 AbstractGfxScopeWidget::AbstractGfxScopeWidget(MonitorManager *manager, bool trackMouse, QWidget *parent) :
32         AbstractScopeWidget(trackMouse, parent),
33         m_manager(manager)
34 {
35     m_activeRender = m_manager->activeRenderer();
36
37     bool b = true;
38     if (m_activeRender != NULL)
39         b &= connect(m_activeRender, SIGNAL(frameUpdated(QImage)), this, SLOT(slotRenderZoneUpdated(QImage)));
40     Q_ASSERT(b);
41 }
42
43 AbstractGfxScopeWidget::~AbstractGfxScopeWidget() { }
44
45 QImage AbstractGfxScopeWidget::renderScope(uint accelerationFactor)
46 {
47     return renderGfxScope(accelerationFactor, m_scopeImage);
48 }
49
50 void AbstractGfxScopeWidget::mouseReleaseEvent(QMouseEvent *event)
51 {
52     if (!m_aAutoRefresh->isChecked() && m_activeRender) {
53         m_activeRender->sendFrameUpdate();
54     }
55     AbstractScopeWidget::mouseReleaseEvent(event);
56 }
57
58
59 ///// Slots /////
60
61 void AbstractGfxScopeWidget::slotActiveMonitorChanged()
62 {
63     if (m_activeRender) {
64         if (m_activeRender == m_manager->activeRenderer()) return;
65         bool b = m_activeRender->disconnect(this);
66         Q_ASSERT(b);
67     }
68     m_activeRender = m_manager->activeRenderer();
69
70     if (m_activeRender) {
71 #ifdef DEBUG_AGSW
72     qDebug() << "Active monitor has changed in " << widgetName() << ". Is the clip monitor active now? " << m_activeRender->name();
73 #endif
74         bool b = connect(m_activeRender, SIGNAL(frameUpdated(QImage)), this, SLOT(slotRenderZoneUpdated(QImage)));
75         Q_ASSERT(b);
76     }
77
78     // Update the scope for the new monitor.
79     forceUpdate(true);
80 }
81
82 void AbstractGfxScopeWidget::slotClearMonitor()
83 {
84     m_activeRender = NULL;
85 }
86
87 void AbstractGfxScopeWidget::slotRenderZoneUpdated(QImage frame)
88 {
89     m_scopeImage = frame;
90     AbstractScopeWidget::slotRenderZoneUpdated();
91 }
92
93 void AbstractGfxScopeWidget::slotAutoRefreshToggled(bool autoRefresh)
94 {
95     if (autoRefresh && m_activeRender) {
96         m_activeRender->sendFrameUpdate();
97     }
98 }
99
100
101 #ifdef DEBUG_AGSW
102 #undef DEBUG_AGSW
103 #endif