]> git.sesse.net Git - kdenlive/blob - src/scopes/colorscopes/abstractgfxscopewidget.cpp
Preparing for scope manager (merge from Granjow's work in refactoring)
[kdenlive] / src / scopes / 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 = true;
66         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