]> git.sesse.net Git - kdenlive/blob - src/abstractmonitor.cpp
Some update for decklink capture & use mlt_threads for proxies
[kdenlive] / src / abstractmonitor.cpp
1 /***************************************************************************
2  *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #include "abstractmonitor.h"
22 #include "kdenlivesettings.h"
23
24 #include <KDebug>
25
26 #include <QPaintEvent>
27
28 VideoPreviewContainer::VideoPreviewContainer(QWidget *parent) :
29     QFrame(parent),
30     m_dar(1.0),
31     m_refresh(false)
32 {
33     setFrameShape(QFrame::NoFrame);
34     setFocusPolicy(Qt::ClickFocus);
35     setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
36     connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(update()));
37     m_refreshTimer.setSingleShot(false);
38     m_refreshTimer.setInterval(200);
39 }
40
41 VideoPreviewContainer::~VideoPreviewContainer()
42 {
43     qDeleteAll(m_imageQueue);
44 }
45
46 //virtual
47 void VideoPreviewContainer::resizeEvent( QResizeEvent * /*event*/ )
48 {
49     updateDisplayZone();
50 }
51
52 void VideoPreviewContainer::setRatio(double ratio)
53 {
54     m_dar = ratio;
55     updateDisplayZone();
56 }
57
58
59 void VideoPreviewContainer::updateDisplayZone()
60 {
61     QRect rect = this->frameRect();
62     int paintW = rect.height() * m_dar + 0.5;
63     if (paintW > rect.width()) {
64         int paintH = rect.width() / m_dar + 0.5;
65         int diff = (rect.height() - paintH)  / 2;
66         rect.adjust(0, diff, 0, 0);
67         rect.setHeight(paintH);
68     }
69     else {
70         int diff = (rect.width() - paintW)  / 2;
71         rect.adjust(diff, 0, 0, 0);
72         rect.setWidth(paintW);
73     }
74     m_displayRect = rect;
75     m_refresh = true;
76 }
77
78 void VideoPreviewContainer::setImage(QImage img)
79 {
80     if (m_imageQueue.count() > 2) {
81         delete m_imageQueue.takeLast();
82     }
83     m_imageQueue.prepend(new QImage(img));
84     update();
85 }
86
87 void VideoPreviewContainer::stop()
88 {
89     //m_refreshTimer.stop();
90     qDeleteAll(m_imageQueue);
91     m_imageQueue.clear();
92 }
93
94 void VideoPreviewContainer::start()
95 {
96     //m_refreshTimer.start();
97 }
98
99 // virtual
100 void VideoPreviewContainer::paintEvent(QPaintEvent *event)
101 {
102     if (m_imageQueue.isEmpty()) return;
103     QImage *img = m_imageQueue.takeFirst();
104     QPainter painter(this);
105     if (m_refresh) {
106         painter.fillRect(event->rect(), QColor(KdenliveSettings::window_background()));
107         m_refresh = false;
108     }
109     painter.drawImage(m_displayRect, *img);
110     delete img;
111 }
112
113