]> git.sesse.net Git - kdenlive/blob - src/colorscopes/abstractgfxscopewidget.cpp
Complete rewrite of the video4linux capture to use MLT, in progress.
[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         bool b = m_activeRender->disconnect(this);
66         Q_ASSERT(b);
67     }
68
69     m_activeRender = m_manager->activeRenderer();
70 #ifdef DEBUG_AGSW
71     qDebug() << "Active monitor has changed in " << widgetName() << ". Is the clip monitor active now? " << m_activeRender->name();
72 #endif
73
74     //b &= connect(m_activeRender, SIGNAL(rendererPosition(int)), this, SLOT(slotRenderZoneUpdated()));
75     if (m_activeRender) {
76         bool b = connect(m_activeRender, SIGNAL(frameUpdated(QImage)), this, SLOT(slotRenderZoneUpdated(QImage)));
77         Q_ASSERT(b);
78     }
79
80     // Update the scope for the new monitor.
81     forceUpdate(true);
82 }
83
84 void AbstractGfxScopeWidget::slotRenderZoneUpdated(QImage frame)
85 {
86     m_scopeImage = frame;
87     AbstractScopeWidget::slotRenderZoneUpdated();
88 }
89
90 void AbstractGfxScopeWidget::slotAutoRefreshToggled(bool autoRefresh)
91 {
92     if (autoRefresh && m_activeRender) {
93         m_activeRender->sendFrameUpdate();
94     }
95 }
96
97
98 #ifdef DEBUG_AGSW
99 #undef DEBUG_AGSW
100 #endif