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