]> git.sesse.net Git - nageru/commitdiff
Make the JPEG frames update on demand.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 6 Jun 2018 20:53:13 +0000 (22:53 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 6 Jun 2018 20:53:13 +0000 (22:53 +0200)
jpeg_frame_view.cpp
jpeg_frame_view.h

index 55a48575cfb5dfcb56a73120c0745a85258c23b9..9427d2be4496a34df8697268a7a97b2587c8b5c5 100644 (file)
@@ -1,5 +1,7 @@
 #include "jpeg_frame_view.h"
 
+#include "post_to_main_thread.h"
+
 #include <QGraphicsPixmapItem>
 #include <QPixmap>
 
@@ -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);
+}
index 219ee5817c679784141bf31f0c8b14fca4e736a7..60c97d97392de5b6c9f55396f697457a33d55702 100644 (file)
@@ -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)