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"
22 #include "kdenlivesettings.h"
26 #include <QPaintEvent>
28 VideoPreviewContainer::VideoPreviewContainer(QWidget *parent) :
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);
41 VideoPreviewContainer::~VideoPreviewContainer()
43 qDeleteAll(m_imageQueue);
47 void VideoPreviewContainer::resizeEvent( QResizeEvent * /*event*/ )
52 void VideoPreviewContainer::setRatio(double ratio)
59 void VideoPreviewContainer::updateDisplayZone()
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);
70 int diff = (rect.width() - paintW) / 2;
71 rect.adjust(diff, 0, 0, 0);
72 rect.setWidth(paintW);
78 void VideoPreviewContainer::setImage(QImage img)
80 if (m_imageQueue.count() > 2) {
81 delete m_imageQueue.takeLast();
83 m_imageQueue.prepend(new QImage(img));
87 void VideoPreviewContainer::stop()
89 //m_refreshTimer.stop();
90 qDeleteAll(m_imageQueue);
94 void VideoPreviewContainer::start()
96 //m_refreshTimer.start();
100 void VideoPreviewContainer::paintEvent(QPaintEvent *event)
102 if (m_imageQueue.isEmpty()) return;
103 QImage *img = m_imageQueue.takeFirst();
104 QPainter painter(this);
106 painter.fillRect(event->rect(), QColor(KdenliveSettings::window_background()));
109 painter.drawImage(m_displayRect, *img);