From: Steinar H. Gunderson Date: Wed, 6 Jun 2018 20:53:13 +0000 (+0200) Subject: Make the JPEG frames update on demand. X-Git-Tag: 1.8.0~76^2~289 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=95658a64fb67f9bd624c12dece3a8e1c325a3e56;p=nageru Make the JPEG frames update on demand. --- diff --git a/jpeg_frame_view.cpp b/jpeg_frame_view.cpp index 55a4857..9427d2b 100644 --- a/jpeg_frame_view.cpp +++ b/jpeg_frame_view.cpp @@ -1,5 +1,7 @@ #include "jpeg_frame_view.h" +#include "post_to_main_thread.h" + #include #include @@ -15,13 +17,26 @@ JPEGFrameView::JPEGFrameView(QWidget *parent) setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); } -void JPEGFrameView::update() +void JPEGFrameView::update_frame() { - item.setPixmap(QPixmap(QString::fromStdString(filename_for_frame(stream_idx, pts)))); - fitInView(&item, Qt::KeepAspectRatio); + dirty = true; + post_to_main_thread([this]{ + hide(); + show(); + }); } void JPEGFrameView::resizeEvent(QResizeEvent *event) { fitInView(&item, Qt::KeepAspectRatio); } + +void JPEGFrameView::paintEvent(QPaintEvent *event) +{ + if (dirty) { + dirty = false; + item.setPixmap(QPixmap(QString::fromStdString(filename_for_frame(stream_idx, pts)))); + fitInView(&item, Qt::KeepAspectRatio); + } + QGraphicsView::paintEvent(event); +} diff --git a/jpeg_frame_view.h b/jpeg_frame_view.h index 219ee58..60c97d9 100644 --- a/jpeg_frame_view.h +++ b/jpeg_frame_view.h @@ -17,20 +17,22 @@ public: { this->stream_idx = stream_idx; this->pts = pts; - update(); + update_frame(); } protected: void resizeEvent(QResizeEvent *event) override; + void paintEvent(QPaintEvent *event) override; private: - void update(); + void update_frame(); QGraphicsPixmapItem item; QGraphicsScene scene; unsigned stream_idx; int64_t pts; + bool dirty = false; }; #endif // !defined(_JPEG_FRAME_VIEW_H)