Commit bbc08be4d74abbefe08c4905dc9847f124f4e07d
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 | #include <QApplication> | 1 | #include <QApplication> |
| 2 | #include <QLabel> | 2 | #include <QLabel> |
| 3 | #include <QElapsedTimer> | 3 | #include <QElapsedTimer> |
| 4 | +#include <QWaitCondition> | ||
| 5 | +#include <QMutex> | ||
| 4 | #include <opencv2/imgproc/imgproc.hpp> | 6 | #include <opencv2/imgproc/imgproc.hpp> |
| 5 | #include <openbr/openbr_plugin.h> | 7 | #include <openbr/openbr_plugin.h> |
| 6 | 8 | ||
| @@ -47,20 +49,39 @@ QImage toQImage(const Mat &mat) | @@ -47,20 +49,39 @@ QImage toQImage(const Mat &mat) | ||
| 47 | return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); | 49 | return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); |
| 48 | } | 50 | } |
| 49 | 51 | ||
| 52 | + | ||
| 50 | // Provides slots for manipulating a QLabel, but does not inherit from QWidget. | 53 | // Provides slots for manipulating a QLabel, but does not inherit from QWidget. |
| 51 | // Therefore, it can be moved to the main thread if not created there initially | 54 | // Therefore, it can be moved to the main thread if not created there initially |
| 52 | // since god forbid you create a QWidget subclass in not the main thread. | 55 | // since god forbid you create a QWidget subclass in not the main thread. |
| 53 | class GUIProxy : public QObject | 56 | class GUIProxy : public QObject |
| 54 | { | 57 | { |
| 55 | Q_OBJECT | 58 | Q_OBJECT |
| 59 | + QMutex lock; | ||
| 60 | + QWaitCondition wait; | ||
| 61 | + | ||
| 56 | public: | 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 | GUIProxy() | 74 | GUIProxy() |
| 60 | { | 75 | { |
| 61 | window = NULL; | 76 | window = NULL; |
| 62 | } | 77 | } |
| 63 | 78 | ||
| 79 | + void waitForKey() | ||
| 80 | + { | ||
| 81 | + QMutexLocker locker(&lock); | ||
| 82 | + wait.wait(&lock); | ||
| 83 | + } | ||
| 84 | + | ||
| 64 | public slots: | 85 | public slots: |
| 65 | 86 | ||
| 66 | void showImage(const QPixmap & input) | 87 | void showImage(const QPixmap & input) |
| @@ -74,6 +95,13 @@ public slots: | @@ -74,6 +95,13 @@ public slots: | ||
| 74 | delete window; | 95 | delete window; |
| 75 | window = new QLabel(); | 96 | window = new QLabel(); |
| 76 | window->setVisible(true); | 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,9 +116,13 @@ class Show2Transform : public TimeVaryingTransform | ||
| 88 | { | 116 | { |
| 89 | Q_OBJECT | 117 | Q_OBJECT |
| 90 | public: | 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 | Q_PROPERTY(QStringList keys READ get_keys WRITE set_keys RESET reset_keys STORED false) | 122 | Q_PROPERTY(QStringList keys READ get_keys WRITE set_keys RESET reset_keys STORED false) |
| 92 | BR_PROPERTY(QStringList, keys, QStringList("FrameNumber")) | 123 | BR_PROPERTY(QStringList, keys, QStringList("FrameNumber")) |
| 93 | 124 | ||
| 125 | + | ||
| 94 | Show2Transform() : TimeVaryingTransform(false, false) | 126 | Show2Transform() : TimeVaryingTransform(false, false) |
| 95 | { | 127 | { |
| 96 | // Create our GUI proxy | 128 | // Create our GUI proxy |
| @@ -144,6 +176,11 @@ public: | @@ -144,6 +176,11 @@ public: | ||
| 144 | // by the main thread isn't damaged when we update displayBuffer | 176 | // by the main thread isn't damaged when we update displayBuffer |
| 145 | // later. | 177 | // later. |
| 146 | emit updateImage(displayBuffer.copy(displayBuffer.rect())); | 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 | } |