Commit bbc08be4d74abbefe08c4905dc9847f124f4e07d

Authored by Charles Otto
1 parent 189d2a1d

Add preliminary support for waitkey in Show2

This is currently implemented by an event filter on the QApplication, which
isn't great, but I couldn't get a QShortcut to work.
Showing 1 changed file with 38 additions and 1 deletions
openbr/plugins/gui.cpp
1 1 #include <QApplication>
2 2 #include <QLabel>
3 3 #include <QElapsedTimer>
  4 +#include <QWaitCondition>
  5 +#include <QMutex>
4 6 #include <opencv2/imgproc/imgproc.hpp>
5 7 #include <openbr/openbr_plugin.h>
6 8  
... ... @@ -47,20 +49,39 @@ QImage toQImage(const Mat &amp;mat)
47 49 return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy();
48 50 }
49 51  
  52 +
50 53 // Provides slots for manipulating a QLabel, but does not inherit from QWidget.
51 54 // Therefore, it can be moved to the main thread if not created there initially
52 55 // since god forbid you create a QWidget subclass in not the main thread.
53 56 class GUIProxy : public QObject
54 57 {
55 58 Q_OBJECT
  59 + QMutex lock;
  60 + QWaitCondition wait;
  61 +
56 62 public:
57   - QLabel * window;
58 63  
  64 + bool eventFilter(QObject * obj, QEvent * event)
  65 + {
  66 + if (event->type() == QEvent::KeyPress)
  67 + {
  68 + wait.wakeAll();
  69 + }
  70 + return QObject::eventFilter(obj, event);
  71 + }
  72 +
  73 + QLabel * window;
59 74 GUIProxy()
60 75 {
61 76 window = NULL;
62 77 }
63 78  
  79 + void waitForKey()
  80 + {
  81 + QMutexLocker locker(&lock);
  82 + wait.wait(&lock);
  83 + }
  84 +
64 85 public slots:
65 86  
66 87 void showImage(const QPixmap & input)
... ... @@ -74,6 +95,13 @@ public slots:
74 95 delete window;
75 96 window = new QLabel();
76 97 window->setVisible(true);
  98 +
  99 + QApplication::instance()->installEventFilter(this);
  100 + Qt::WindowFlags flags = window->windowFlags();
  101 +
  102 + flags = flags & ~Qt::WindowCloseButtonHint;
  103 + window->setWindowFlags(flags);
  104 + window->show();
77 105 }
78 106 };
79 107  
... ... @@ -88,9 +116,13 @@ class Show2Transform : public TimeVaryingTransform
88 116 {
89 117 Q_OBJECT
90 118 public:
  119 + Q_PROPERTY(bool waitInput READ get_waitInput WRITE set_waitInput RESET reset_waitInput STORED false)
  120 + BR_PROPERTY(bool, waitInput, false)
  121 +
91 122 Q_PROPERTY(QStringList keys READ get_keys WRITE set_keys RESET reset_keys STORED false)
92 123 BR_PROPERTY(QStringList, keys, QStringList("FrameNumber"))
93 124  
  125 +
94 126 Show2Transform() : TimeVaryingTransform(false, false)
95 127 {
96 128 // Create our GUI proxy
... ... @@ -144,6 +176,11 @@ public:
144 176 // by the main thread isn't damaged when we update displayBuffer
145 177 // later.
146 178 emit updateImage(displayBuffer.copy(displayBuffer.rect()));
  179 +
  180 + // Blocking wait for a key-press
  181 + if (this->waitInput)
  182 + gui->waitForKey();
  183 +
147 184 }
148 185 }
149 186 }
... ...