1 /***************************************************************************
2 * Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #include "abstractmonitor.h"
25 VideoPreviewContainer::VideoPreviewContainer(QWidget *parent) :
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);
36 VideoPreviewContainer::~VideoPreviewContainer()
38 qDeleteAll(m_imageQueue);
42 void VideoPreviewContainer::setImage(QImage img)
44 if (m_imageQueue.count() > 2) {
45 delete m_imageQueue.takeLast();//replace(10, new QImage(img));
47 m_imageQueue.prepend(new QImage(img));
50 void VideoPreviewContainer::stop()
52 m_refreshTimer.stop();
53 qDeleteAll(m_imageQueue);
57 void VideoPreviewContainer::start()
59 m_refreshTimer.start();
63 void VideoPreviewContainer::paintEvent(QPaintEvent */*event*/)
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);
78 int diff = (rect.width() - paintW) / 2;
79 rect.adjust(diff, 0, 0, 0);
80 rect.setWidth(paintW);
83 painter.drawImage(rect, *img);