QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
graphicsvideowidget.cpp
00001 /*
00002     Copyright (C) 2012 Collabora Ltd. <info@collabora.com>
00003       @author George Kiagiadakis <george.kiagiadakis@collabora.com>
00004 
00005     This library is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU Lesser General Public License as published
00007     by the Free Software Foundation; either version 2.1 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 #include "graphicsvideowidget.h"
00019 #include "graphicsvideosurface_p.h"
00020 #include "../../QGlib/signal.h"
00021 
00022 namespace QGst {
00023 namespace Ui {
00024 
00025 GraphicsVideoWidget::GraphicsVideoWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags)
00026     : QGraphicsWidget(parent, wFlags)
00027 {
00028     setFlag(QGraphicsItem::ItemHasNoContents, false);
00029 }
00030 
00031 GraphicsVideoWidget::~GraphicsVideoWidget()
00032 {
00033     setSurface(0);
00034 }
00035 
00036 GraphicsVideoSurface *GraphicsVideoWidget::surface() const
00037 {
00038     return m_surface.data();
00039 }
00040 
00041 void GraphicsVideoWidget::setSurface(GraphicsVideoSurface *surface)
00042 {
00043     if (m_surface) {
00044         m_surface.data()->d->items.remove(this);
00045     }
00046 
00047     m_surface = surface;
00048 
00049     if (m_surface) {
00050         m_surface.data()->d->items.insert(this);
00051     }
00052 }
00053 
00054 void GraphicsVideoWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
00055 {
00056     Q_UNUSED(option);
00057 
00058     QRectF r = rect();
00059 
00060     if (!m_surface || m_surface.data()->d->videoSink.isNull() ||
00061         widget != m_surface.data()->d->view->viewport()
00062     ) {
00063         painter->fillRect(r, Qt::black);
00064     } else {
00065         QGlib::emit<void>(m_surface.data()->d->videoSink, "paint",
00066                           (void*)painter, r.x(), r.y(), r.width(), r.height());
00067     }
00068 }
00069 
00070 } // namespace Ui
00071 } // namespace QGst