1 /***************************************************************************
2 * Copyright (C) 2010 by Till Theato (root@ttill.de) *
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 "monitorscene.h"
24 #include <QGraphicsView>
25 #include <QGraphicsPixmapItem>
28 MonitorScene::MonitorScene(Render *renderer, QObject* parent) :
29 QGraphicsScene(parent),
34 void MonitorScene::setUp()
36 setBackgroundBrush(QBrush(QColor(0, 0, 255)));
38 QPen framepen(Qt::DotLine);
39 framepen.setColor(Qt::red);
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);
49 m_background = new QGraphicsPixmapItem();
50 m_background->setZValue(-10);
51 m_background->setFlags(0);
52 QPixmap bg(m_renderer->renderWidth(), m_renderer->renderHeight());
54 m_background->setPixmap(bg);
55 addItem(m_background);
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);
64 void MonitorScene::slotUpdateBackground()
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);
76 void MonitorScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
78 QGraphicsScene::mousePressEvent(event);
82 void MonitorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
84 QGraphicsScene::mouseReleaseEvent(event);
85 emit actionFinished();
88 #include "monitorscene.moc"