Skip to content

Commit

Permalink
virtual VideoRenderer.widget()/graphicsItem() is reasonable
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Feb 8, 2014
1 parent 54f50b1 commit 5938bc2
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 44 deletions.
3 changes: 1 addition & 2 deletions src/Direct2DRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -29,7 +29,6 @@ Direct2DRenderer::Direct2DRenderer(QWidget *parent, Qt::WindowFlags f):
QWidget(parent, f),VideoRenderer(*new Direct2DRendererPrivate())
{
DPTR_INIT_PRIVATE(Direct2DRenderer);
d_func().widget_holder = this;
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
/* To rapidly update custom widgets that constantly paint over their entire areas with
Expand Down
3 changes: 1 addition & 2 deletions src/GDIRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -33,7 +33,6 @@ GDIRenderer::GDIRenderer(QWidget *parent, Qt::WindowFlags f):
QWidget(parent, f),VideoRenderer(*new GDIRendererPrivate())
{
DPTR_INIT_PRIVATE(GDIRenderer);
d_func().widget_holder = this;
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
/* To rapidly update custom widgets that constantly paint over their entire areas with
Expand Down
3 changes: 1 addition & 2 deletions src/GLWidgetRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -158,7 +158,6 @@ GLWidgetRenderer::GLWidgetRenderer(QWidget *parent, const QGLWidget* shareWidget
{
DPTR_INIT_PRIVATE(GLWidgetRenderer);
DPTR_D(GLWidgetRenderer);
d_func().widget_holder = this;
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
/* To rapidly update custom widgets that constantly paint over their entire areas with
Expand Down
4 changes: 1 addition & 3 deletions src/GraphicsItemRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -33,7 +33,6 @@ namespace QtAV {
GraphicsItemRenderer::GraphicsItemRenderer(QGraphicsItem * parent)
:GraphicsWidget(parent),QPainterRenderer(*new GraphicsItemRendererPrivate())
{
d_func().item_holder = this;
setFlag(ItemIsFocusable); //receive key events
//setAcceptHoverEvents(true);
#if CONFIG_GRAPHICSWIDGET
Expand All @@ -44,7 +43,6 @@ GraphicsItemRenderer::GraphicsItemRenderer(QGraphicsItem * parent)
GraphicsItemRenderer::GraphicsItemRenderer(GraphicsItemRendererPrivate &d, QGraphicsItem *parent)
:GraphicsWidget(parent),QPainterRenderer(d)
{
d_func().item_holder = this;
setFlag(ItemIsFocusable); //receive key events
//setAcceptHoverEvents(true);
#if CONFIG_GRAPHICSWIDGET
Expand Down
3 changes: 2 additions & 1 deletion src/QtAV/Direct2DRenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -45,6 +45,7 @@ class Q_AV_EXPORT Direct2DRenderer : public QWidget, public VideoRenderer
* return 0 and set this flag
*/
virtual QPaintEngine* paintEngine() const;
virtual QWidget* widget() { return this; }
protected:
virtual bool receiveFrame(const VideoFrame& frame);
virtual bool needUpdateBackground() const;
Expand Down
3 changes: 2 additions & 1 deletion src/QtAV/GDIRenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -45,6 +45,7 @@ class Q_AV_EXPORT GDIRenderer : public QWidget, public VideoRenderer
* true: paintEngine.getDC(), double buffer is enabled by defalut.
* false: GetDC(winId()), no double buffer, should reimplement paintEngine()
*/
virtual QWidget* widget() { return this; }
protected:
virtual bool receiveFrame(const VideoFrame& frame);
virtual bool needUpdateBackground() const;
Expand Down
3 changes: 2 additions & 1 deletion src/QtAV/GLWidgetRenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -36,6 +36,7 @@ class Q_AV_EXPORT GLWidgetRenderer : public QGLWidget, public VideoRenderer, pub
public:
GLWidgetRenderer(QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
virtual VideoRendererId id() const;
virtual QWidget* widget() { return this; }

protected:
virtual bool receiveFrame(const VideoFrame& frame);
Expand Down
3 changes: 2 additions & 1 deletion src/QtAV/GraphicsItemRenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -45,6 +45,7 @@ class Q_AV_EXPORT GraphicsItemRenderer : public GraphicsWidget, public QPainterR

QRectF boundingRect() const;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
virtual QGraphicsItem* graphicsItem() { return this; }

protected:
GraphicsItemRenderer(GraphicsItemRendererPrivate& d, QGraphicsItem *parent);
Expand Down
14 changes: 11 additions & 3 deletions src/QtAV/VideoRenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -140,8 +140,16 @@ class Q_AV_EXPORT VideoRenderer : public AVOutput
*/
QPointF mapFromFrame(const QPointF& p) const;

QWidget* widget();
QGraphicsItem* graphicsItem();
/*!
* \brief widget
* \return default is 0. A QWidget subclass can return \a this
*/
virtual QWidget* widget() { return 0; }
/*!
* \brief graphicsItem
* \return default is 0. A QGraphicsItem subclass can return \a this
*/
virtual QGraphicsItem* graphicsItem() { return 0; }

//TODO: enable/disable = new a default for this vo engine or push back/remove from list
//filter: null means disable
Expand Down
3 changes: 2 additions & 1 deletion src/QtAV/WidgetRenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -35,6 +35,7 @@ class Q_AV_EXPORT WidgetRenderer : public QWidget, public QPainterRenderer
public:
explicit WidgetRenderer(QWidget *parent = 0, Qt::WindowFlags f = 0);
virtual VideoRendererId id() const;
virtual QWidget* widget() { return this; }
signals:
void imageReady();
protected:
Expand Down
3 changes: 2 additions & 1 deletion src/QtAV/XVRenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -47,6 +47,7 @@ class Q_AV_EXPORT XVRenderer : public QWidget, public VideoRenderer
* true: paintEngine is QPainter. Painting with QPainter support double buffer
* false: no double buffer, should reimplement paintEngine() to return 0 to avoid flicker
*/
virtual QWidget* widget() { return this; }
protected:
virtual bool receiveFrame(const VideoFrame& frame);
virtual bool needUpdateBackground() const;
Expand Down
10 changes: 1 addition & 9 deletions src/QtAV/private/VideoRenderer_p.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -54,8 +54,6 @@ class Q_AV_EXPORT VideoRendererPrivate : public AVOutputPrivate
, out_aspect_ratio_mode(VideoRenderer::VideoAspectRatio)
, out_aspect_ratio(0)
, quality(VideoRenderer::QualityBest)
, widget_holder(0)
, item_holder(0)
, osd_filter(0)
, subtitle_filter(0)
, default_event_filter(true)
Expand All @@ -64,7 +62,6 @@ class Q_AV_EXPORT VideoRendererPrivate : public AVOutputPrivate
//conv.setOutFormat(PIX_FMT_BGR32); //TODO: why not RGB32?
}
virtual ~VideoRendererPrivate(){
widget_holder = 0;
}
void computeOutParameters(qreal outAspectRatio) {
qreal rendererAspectRatio = qreal(renderer_width)/qreal(renderer_height);
Expand Down Expand Up @@ -109,11 +106,6 @@ class Q_AV_EXPORT VideoRendererPrivate : public AVOutputPrivate
//out_rect: the displayed video frame out_rect in the renderer
QRect out_rect; //TODO: out_out_rect
QRectF roi;
/* Stores but not own the ptr if renderer is a subclass of QWidget.
* Some operations are based on QWidget
*/
QWidget *widget_holder;
QGraphicsItem *item_holder;

Filter *osd_filter, *subtitle_filter; //should be at the end of list and draw top level
bool default_event_filter;
Expand Down
12 changes: 1 addition & 11 deletions src/VideoRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -253,16 +253,6 @@ QPointF VideoRenderer::mapFromFrame(const QPointF &p) const
return QPointF(rendererWidth()/2, rendererHeight()/2) + delta / zoom;
}

QWidget* VideoRenderer::widget()
{
return d_func().widget_holder;
}

QGraphicsItem* VideoRenderer::graphicsItem()
{
return d_func().item_holder;
}

OSDFilter *VideoRenderer::setOSDFilter(OSDFilter *filter)
{
DPTR_D(VideoRenderer);
Expand Down
4 changes: 1 addition & 3 deletions src/WidgetRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -32,7 +32,6 @@ WidgetRenderer::WidgetRenderer(QWidget *parent, Qt::WindowFlags f) :
QWidget(parent, f),QPainterRenderer(*new WidgetRendererPrivate())
{
DPTR_D(WidgetRenderer);
d.widget_holder = this;
d.painter = new QPainter();
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
Expand All @@ -55,7 +54,6 @@ WidgetRenderer::WidgetRenderer(QWidget *parent, Qt::WindowFlags f) :
WidgetRenderer::WidgetRenderer(WidgetRendererPrivate &d, QWidget *parent, Qt::WindowFlags f)
:QWidget(parent, f),QPainterRenderer(d)
{
d.widget_holder = this;
d.painter = new QPainter();
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
Expand Down
3 changes: 1 addition & 2 deletions src/XVRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -32,7 +32,6 @@ XVRenderer::XVRenderer(QWidget *parent, Qt::WindowFlags f):
, VideoRenderer(*new XVRendererPrivate())
{
DPTR_INIT_PRIVATE(XVRenderer);
d_func().widget_holder = this;
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
/* To rapidly update custom widgets that constantly paint over their entire areas with
Expand Down
1 change: 0 additions & 1 deletion templates/vo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class %CLASS%Private : public VideoRendererPrivate
, VideoRenderer(*new %CLASS%Private())
{
DPTR_INIT_PRIVATE(%CLASS%);
d_func().widget_holder = this;
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
//setAttribute(Qt::WA_OpaquePaintEvent);
Expand Down
1 change: 1 addition & 0 deletions templates/vo.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Q_AV_EXPORT %CLASS% : public QWidget, public VideoRenderer
* true: paintEngine is QPainter. Painting with QPainter support double buffer
* false: no double buffer, should reimplement paintEngine() to return 0 to avoid flicker
*/
virtual QWidget* widget() { return this; }
protected:
virtual void convertData(const QByteArray &data);
virtual bool needUpdateBackground() const;
Expand Down

0 comments on commit 5938bc2

Please sign in to comment.