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"
24 VideoPreviewContainer::VideoPreviewContainer(QWidget *parent) :
28 setFrameShape(QFrame::NoFrame);
29 setFocusPolicy(Qt::ClickFocus);
30 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
34 void VideoPreviewContainer::setImage(QImage img)
36 if (m_image) delete m_image;
37 m_image = new QImage(img);
42 void VideoPreviewContainer::paintEvent(QPaintEvent */*event*/)
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);
56 int diff = (rect.width() - paintW) / 2;
57 rect.adjust(diff, 0, 0, 0);
58 rect.setWidth(paintW);
61 painter.drawImage(rect, *m_image);