1
/***************************************************************************
2
* Copyright (C) 2008 Nokia Corporation *
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 3 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, see <http://www.gnu.org/licenses/>. *
16
**************************************************************************/
18
#include "videoscene.h"
19
#include <QtGui/QLabel>
22
#include "videoglframe.h"
23
#include "videotoolbar.h"
25
#ifndef GL_MULTISAMPLE
26
#define GL_MULTISAMPLE 0x809D
29
VideoScene::VideoScene()
30
: m_backgroundColor(25, 25, 25),m_pToolbar(nullptr)
33
// QPointF pos(10, 10);
34
// foreach (QGraphicsItem *item, items()) {
35
// item->setFlag(QGraphicsItem::ItemIsMovable);
36
// item->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
38
// const QRectF rect = item->boundingRect();
39
// item->setPos(pos.x() - rect.x(), pos.y() - rect.y());
40
// pos += QPointF(0, 10 + rect.height());
43
// QRadialGradient gradient(40, 40, 40, 40, 40);
44
// gradient.setColorAt(0.2, Qt::yellow);
45
// gradient.setColorAt(1, Qt::transparent);
47
// m_lightItem = new QGraphicsRectItem(0, 0, 80, 80);
48
// m_lightItem->setPen(Qt::NoPen);
49
// m_lightItem->setBrush(gradient);
50
// m_lightItem->setFlag(QGraphicsItem::ItemIsMovable);
51
// m_lightItem->setPos(800, 200);
52
// addItem(m_lightItem);
55
void VideoScene::drawBackground(QPainter *painter, const QRectF& rect)
58
glClearColor(m_backgroundColor.redF(), m_backgroundColor.greenF(), m_backgroundColor.blueF(), 1.0f);
59
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
61
foreach(VideoGLFrame* frm, m_lFrames) {
62
frm->paintEvent(painter);
66
void VideoScene::setBackgroundColor()
68
// const QColor color = QColorDialog::getColor(m_backgroundColor);
69
// if (color.isValid()) {
70
// m_backgroundColor = color;
75
void VideoScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
77
QGraphicsScene::mouseMoveEvent(event);
78
if (event->isAccepted())
80
if (event->buttons() & Qt::LeftButton) {
84
foreach(VideoGLFrame* frm, m_lFrames) {
85
const QPointF diff = event->pos() - frm->anchor();
86
if (event->buttons() & Qt::LeftButton) {
87
frm->setRotX(frm->rotX()+diff.y()/5.0f);
88
frm->setRotY(frm->rotY()+diff.x()/5.0f);
89
} else if (event->buttons() & Qt::RightButton) {
90
frm->setRotZ(frm->rotZ()+diff.x()/5.0f);
93
frm->setAnchor(event->pos());
97
void VideoScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
99
QGraphicsScene::mousePressEvent(event);
100
if (event->isAccepted())
105
foreach(VideoGLFrame* frm, m_lFrames) {
106
frm->setAnchor(event->pos());
110
void VideoScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
112
QGraphicsScene::mouseReleaseEvent(event);
113
if (event->isAccepted())
120
void VideoScene::wheelEvent(QGraphicsSceneWheelEvent *event)
122
QGraphicsScene::wheelEvent(event);
123
if (event->isAccepted())
127
foreach(VideoGLFrame* frm, m_lFrames) {
128
frm->setScale(frm->scale() +(event->delta() > 0 ?1:-1)*frm->scale()*0.1f);
133
void VideoScene::frameChanged()
138
void VideoScene::setToolbar(VideoToolbar* tb)
141
addWidget(m_pToolbar);
144
void VideoScene::addFrame(VideoGLFrame* frame)
147
m_pToolbar->resizeToolbar();