]> git.sesse.net Git - kdenlive/blob - src/colorscopes/abstractgfxscopewidget.cpp
275be135610540a8132f086e442a0bdcf17be4d9
[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 "monitor.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(Monitor *projMonitor, Monitor *clipMonitor, bool trackMouse, QWidget *parent) :
33         AbstractScopeWidget(trackMouse, parent),
34         m_projMonitor(projMonitor),
35         m_clipMonitor(clipMonitor)
36
37 {
38     m_activeRender = (m_clipMonitor->isActive()) ? m_clipMonitor->render : m_projMonitor->render;
39
40     bool b = true;
41     b &= connect(m_activeRender, SIGNAL(frameUpdated(QImage)), this, SLOT(slotRenderZoneUpdated(QImage)));
42     Q_ASSERT(b);
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()) {
54         m_activeRender->sendFrameUpdate();
55     }
56     AbstractScopeWidget::mouseReleaseEvent(event);
57 }
58
59
60 ///// Slots /////
61
62 void AbstractGfxScopeWidget::slotActiveMonitorChanged(bool isClipMonitor)
63 {
64 #ifdef DEBUG_AGSW
65     qDebug() << "Active monitor has changed in " << widgetName() << ". Is the clip monitor active now? " << isClipMonitor;
66 #endif
67
68     bool b = m_activeRender->disconnect(this);
69     Q_ASSERT(b);
70
71     m_activeRender = (isClipMonitor) ? m_clipMonitor->render : m_projMonitor->render;
72
73     //b &= connect(m_activeRender, SIGNAL(rendererPosition(int)), this, SLOT(slotRenderZoneUpdated()));
74     b &= connect(m_activeRender, SIGNAL(frameUpdated(QImage)), this, SLOT(slotRenderZoneUpdated(QImage)));
75     Q_ASSERT(b);
76
77     // Update the scope for the new monitor.
78     forceUpdate(true);
79 }
80
81 void AbstractGfxScopeWidget::slotRenderZoneUpdated(QImage frame)
82 {
83     m_scopeImage = frame;
84     AbstractScopeWidget::slotRenderZoneUpdated();
85 }
86
87 void AbstractGfxScopeWidget::slotAutoRefreshToggled(bool autoRefresh)
88 {
89     if (autoRefresh) {
90         m_activeRender->sendFrameUpdate();
91     }
92 }
93
94
95 #ifdef DEBUG_AGSW
96 #undef DEBUG_AGSW
97 #endif