]> git.sesse.net Git - kdenlive/blob - src/abstractmonitor.cpp
Complete rewrite of the video4linux capture to use MLT, in progress.
[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
24 VideoPreviewContainer::VideoPreviewContainer(QWidget *parent) :
25     QFrame(parent),
26     m_image(new QImage())
27 {
28     setFrameShape(QFrame::NoFrame);
29     setFocusPolicy(Qt::ClickFocus);
30     setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
31 }
32
33
34 void VideoPreviewContainer::setImage(QImage img)
35 {
36         if (m_image) delete m_image;
37         m_image = new QImage(img);
38         update();
39 }
40
41 // virtual
42 void VideoPreviewContainer::paintEvent(QPaintEvent */*event*/)
43 {
44         if (m_image->isNull()) return;
45         QPainter painter(this);
46         double ar = (double) m_image->width() / m_image->height();
47         QRect rect = this->frameRect();
48         int paintW = rect.height() * ar + 0.5;
49         if (paintW > rect.width()) {
50             paintW = rect.width() / ar + 0.5;
51             int diff = (rect.height() - paintW)  / 2;
52             rect.adjust(0, diff, 0, 0);
53             rect.setHeight(paintW);
54         }
55         else {
56             int diff = (rect.width() - paintW)  / 2;
57             rect.adjust(diff, 0, 0, 0);
58             rect.setWidth(paintW);
59         }
60
61         painter.drawImage(rect, *m_image);
62 }
63
64