Skip to content

Commit

Permalink
Merge pull request wang-bin#912 from appdoo/graphicsitemrenderer_fix
Browse files Browse the repository at this point in the history
fixed thread handling, saved painter state
  • Loading branch information
wang-bin authored Jul 3, 2017
2 parents 3b4dd4b 27c00ef commit 30dbe47
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
36 changes: 30 additions & 6 deletions widgets/GraphicsItemRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 34,7 @@ typedef float GLfloat;
#include <QEvent>
#include <QKeyEvent>
#include <QGraphicsSceneEvent>
#include <QtCore/QCoreApplication>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtGui/QSurface>
#endif
Expand Down Expand Up @@ -126,7 127,9 @@ bool GraphicsItemRenderer::receiveFrame(const VideoFrame& frame)
{
preparePixmap(frame);
}
scene()->update(sceneBoundingRect()); //TODO: thread?
// moved to event
// scene()->update(sceneBoundingRect()); //TODO: thread?
QCoreApplication::postEvent(this, new QEvent(QEvent::User));
//update(); //does not cause an immediate paint. my not redraw.
return true;
}
Expand Down Expand Up @@ -173,7 176,16 @@ void GraphicsItemRenderer::paint(QPainter *painter, const QStyleOptionGraphicsIt
} else {
qWarning("FilterContext not available!");
}
// save painter state, switch to native opengl painting
painter->save();
painter->beginNativePainting();

handlePaintEvent();

// end native painting, restore state
painter->endNativePainting();
painter->restore();

d.painter = 0; //painter may be not available outside this function
if (ctx)
ctx->painter = 0;
Expand Down Expand Up @@ -290,15 302,27 @@ bool GraphicsItemRenderer::onSetSaturation(qreal s)
#if CONFIG_GRAPHICSWIDGET
bool GraphicsItemRenderer::event(QEvent *event)
{
setFocus(); //WHY: Force focus
QEvent::Type type = event->type();
qDebug("GraphicsItemRenderer event type = %d", type);
if (type == QEvent::KeyPress) {
qDebug("KeyPress Event. key=%d", static_cast<QKeyEvent*>(event)->key());
if (e->type() == QEvent::User) {
scene()->update(sceneBoundingRect());
}
else {
setFocus(); //WHY: Force focus
QEvent::Type type = event->type();
qDebug("GraphicsItemRenderer event type = %d", type);
if (type == QEvent::KeyPress) {
qDebug("KeyPress Event. key=%d", static_cast<QKeyEvent*>(event)->key());
}
}
return true;
}
#else
bool GraphicsItemRenderer::event(QEvent *event)
{
if (event->type() != QEvent::User)
return GraphicsWidget::event(event);
scene()->update(sceneBoundingRect());
return true;
}
/*simply passes event to QGraphicsWidget::event(). you should not have to
*reimplement sceneEvent() in a subclass of QGraphicsWidget.
*/
Expand Down
1 change: 1 addition & 0 deletions widgets/QtAVWidgets/GraphicsItemRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 104,7 @@ class Q_AVWIDGETS_EXPORT GraphicsItemRenderer : public GraphicsWidget, public QP
#if CONFIG_GRAPHICSWIDGET
bool event(QEvent *event) Q_DECL_OVERRIDE;
#else
bool event(QEvent *event) Q_DECL_OVERRIDE;
//bool sceneEvent(QEvent *event) Q_DECL_OVERRIDE;
#endif //CONFIG_GRAPHICSWIDGET

Expand Down

0 comments on commit 30dbe47

Please sign in to comment.