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 setAttribute(Qt::WA_PaintOnScreen);
36 setAttribute(Qt::WA_OpaquePaintEvent);
37 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
38 connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(update()));
39 m_refreshTimer.setSingleShot(false);
40 m_refreshTimer.setInterval(200);
43 VideoPreviewContainer::~VideoPreviewContainer()
45 qDeleteAll(m_imageQueue);
49 void VideoPreviewContainer::resizeEvent( QResizeEvent * /*event*/ )
54 void VideoPreviewContainer::setRatio(double ratio)
61 void VideoPreviewContainer::updateDisplayZone()
63 QRect rect = this->frameRect();
64 int paintW = rect.height() * m_dar + 0.5;
65 if (paintW > rect.width()) {
66 int paintH = rect.width() / m_dar + 0.5;
67 int diff = (rect.height() - paintH) / 2;
68 rect.adjust(0, diff, 0, 0);
69 rect.setHeight(paintH);
72 int diff = (rect.width() - paintW) / 2;
73 rect.adjust(diff, 0, 0, 0);
74 rect.setWidth(paintW);
80 void VideoPreviewContainer::setImage(QImage img)
82 if (m_imageQueue.count() > 2) {
83 delete m_imageQueue.takeLast();
85 m_imageQueue.prepend(new QImage(img));
89 void VideoPreviewContainer::stop()
91 //m_refreshTimer.stop();
92 qDeleteAll(m_imageQueue);
96 void VideoPreviewContainer::start()
98 //m_refreshTimer.start();
102 void VideoPreviewContainer::paintEvent(QPaintEvent *event)
104 if (m_imageQueue.isEmpty()) return;
105 QImage *img = m_imageQueue.takeFirst();
106 QPainter painter(this);
108 painter.fillRect(event->rect(), QColor(KdenliveSettings::window_background()));
111 painter.drawImage(m_displayRect, *img);