]> git.sesse.net Git - kdenlive/blob - src/monitorscene.cpp
d0a512027d53fd208b9918341f4d64ef4db1dd22
[kdenlive] / src / monitorscene.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Till Theato (root@ttill.de)                     *
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 "monitorscene.h"
22 #include "renderer.h"
23 #include "kdenlivesettings.h"
24
25 #include <QGraphicsView>
26 #include <QGraphicsPixmapItem>
27 #include <QtCore>
28
29 MonitorScene::MonitorScene(Render *renderer, QObject* parent) :
30         QGraphicsScene(parent),
31         m_renderer(renderer)
32 {
33 }
34
35 void MonitorScene::setUp()
36 {
37     setBackgroundBrush(QBrush(QColor(KdenliveSettings::window_background().name())));
38
39     QPen framepen(Qt::DotLine);
40     framepen.setColor(Qt::red);
41
42     m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_renderer->renderWidth(), m_renderer->renderHeight()));
43     m_frameBorder->setPen(framepen);
44     m_frameBorder->setZValue(-9);
45     m_frameBorder->setBrush(Qt::transparent);
46     m_frameBorder->setFlags(0);
47     addItem(m_frameBorder);
48
49     m_lastUpdate.start();
50     m_background = new QGraphicsPixmapItem();
51     m_background->setZValue(-10);
52     m_background->setFlags(0);
53     QPixmap bg(m_renderer->renderWidth(), m_renderer->renderHeight());
54     bg.fill();
55     m_background->setPixmap(bg);
56     addItem(m_background);
57
58     connect(m_renderer, SIGNAL(rendererPosition(int)), this, SLOT(slotUpdateBackground()));
59     connect(m_renderer, SIGNAL(frameUpdated(int)), this, SLOT(slotUpdateBackground()));
60     slotUpdateBackground();
61 }
62
63 void MonitorScene::slotUpdateBackground()
64 {
65     if (views().count() > 0 && views().at(0)->isVisible()) {
66         if (m_lastUpdate.elapsed() > 200) {
67             m_background->setPixmap(QPixmap::fromImage(m_renderer->extractFrame(m_renderer->seekFramePosition())));
68             views().at(0)->fitInView(m_frameBorder, Qt::KeepAspectRatio);
69             views().at(0)->centerOn(m_frameBorder);
70             m_lastUpdate.start();
71         }
72     }
73 }
74
75 void MonitorScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
76 {
77     QGraphicsScene::mousePressEvent(event);
78 }
79
80
81 void MonitorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
82 {
83     QGraphicsScene::mouseReleaseEvent(event);
84     emit actionFinished();
85 }
86
87 #include "monitorscene.moc"