Skip to content

Commit

Permalink
update vo template
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jun 16, 2013
1 parent 54f34ef commit 754c137
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
33 changes: 14 additions & 19 deletions templates/vo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class %CLASS%Private : public VideoRendererPrivate
}
~%CLASS%Private() {
}
virtual void setupQuality() {}
};

%CLASS%::%CLASS%(QWidget *parent, Qt::WindowFlags f):
Expand Down Expand Up @@ -49,11 +50,20 @@ void %CLASS%::convertData(const QByteArray &data)
Q_UNUSED(locker);
}

ool %CLASS%::needUpdateBackground() const
{
return VideoRenderer::needUpdateBackground();
}

void %CLASS%::drawBackground()
{
}

bool %CLASS%::needDrawFrame() const
{
return VideoRenderer::needDrawFrame();
}

void %CLASS%::drawFrame()
{
//assume that the image data is already scaled to out_size(NOT renderer size!)
Expand All @@ -66,26 +76,11 @@ void %CLASS%::drawFrame()

void %CLASS%::paintEvent(QPaintEvent *)
{
DPTR_D(%CLASS%);
{
//lock is required only when drawing the frame
QMutexLocker locker(&d.img_mutex);
Q_UNUSED(locker);
//begin paint. how about QPainter::beginNativePainting()?
//fill background color when necessary, e.g. renderer is resized, image is null
//we access d.data which will be modified in AVThread, so must be protected
if ((d.update_background && d.out_rect != rect()) || d.data.isEmpty()) {
d.update_background = false;
//fill background color. DO NOT return, you must continue drawing
drawBackground();
}
//DO NOT return if no data. we should draw other things
//NOTE: if data is not copyed in convertData, you should always call drawFrame()
if (!d.data.isEmpty()) {
drawFrame();
}
}
//DPTR_D(%CLASS%);
//d.painter->begin(this); //Widget painting can only begin as a result of a paintEvent
handlePaintEvent();
//end paint. how about QPainter::endNativePainting()?
//d.painter->end();
}

void %CLASS%::resizeEvent(QResizeEvent *e)
Expand Down
2 changes: 2 additions & 0 deletions templates/vo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ class Q_EXPORT %CLASS% : public QWidget, public VideoRenderer
*/
protected:
virtual void convertData(const QByteArray &data);
virtual bool needUpdateBackground() const;
//TODO: abstract draw image and font. too many drawXXX()
//called in paintEvent before drawFrame() when required
virtual void drawBackground();
virtual bool needDrawFrame() const; //TODO: no virtual func. it's a solution for temporary
//draw the current frame using the current paint engine. called by paintEvent()
virtual void drawFrame();
/*usually you don't need to reimplement paintEvent, just drawXXX() is ok. unless you want do all
Expand Down

0 comments on commit 754c137

Please sign in to comment.