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