]> git.sesse.net Git - kdenlive/blob - src/abstractmonitor.cpp
Second part of the capture rewrite. Decklink capture now seems to work with latest MLT
[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
23 #include <KDebug>
24
25 VideoPreviewContainer::VideoPreviewContainer(QWidget *parent) :
26     QFrame(parent)
27 {
28     setFrameShape(QFrame::NoFrame);
29     setFocusPolicy(Qt::ClickFocus);
30     setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
31     connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(update()));
32     m_refreshTimer.setSingleShot(false);
33     m_refreshTimer.setInterval(200);
34 }
35
36 VideoPreviewContainer::~VideoPreviewContainer()
37 {
38     qDeleteAll(m_imageQueue);
39 }
40
41
42 void VideoPreviewContainer::setImage(QImage img)
43 {
44     if (m_imageQueue.count() > 2) {
45         delete m_imageQueue.takeLast();//replace(10, new QImage(img));
46     }
47     m_imageQueue.prepend(new QImage(img));
48 }
49
50 void VideoPreviewContainer::stop()
51 {
52     m_refreshTimer.stop();
53     qDeleteAll(m_imageQueue);
54     m_imageQueue.clear();
55 }
56
57 void VideoPreviewContainer::start()
58 {
59     m_refreshTimer.start();
60 }
61
62 // virtual
63 void VideoPreviewContainer::paintEvent(QPaintEvent */*event*/)
64 {
65         if (m_imageQueue.isEmpty()) return;
66         QImage *img = m_imageQueue.takeFirst();
67         QPainter painter(this);
68         double ar = (double) img->width() / img->height();
69         QRect rect = this->frameRect();
70         int paintW = rect.height() * ar + 0.5;
71         if (paintW > rect.width()) {
72             paintW = rect.width() / ar + 0.5;
73             int diff = (rect.height() - paintW)  / 2;
74             rect.adjust(0, diff, 0, 0);
75             rect.setHeight(paintW);
76         }
77         else {
78             int diff = (rect.width() - paintW)  / 2;
79             rect.adjust(diff, 0, 0, 0);
80             rect.setWidth(paintW);
81         }
82
83         painter.drawImage(rect, *img);
84         delete img;
85 }
86
87