From bbc08be4d74abbefe08c4905dc9847f124f4e07d Mon Sep 17 00:00:00 2001 From: Charles Otto Date: Tue, 2 Apr 2013 21:11:23 -0400 Subject: [PATCH] Add preliminary support for waitkey in Show2 --- openbr/plugins/gui.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/openbr/plugins/gui.cpp b/openbr/plugins/gui.cpp index 1bdfaca..c7fdd08 100644 --- a/openbr/plugins/gui.cpp +++ b/openbr/plugins/gui.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include @@ -47,20 +49,39 @@ QImage toQImage(const Mat &mat) return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); } + // Provides slots for manipulating a QLabel, but does not inherit from QWidget. // Therefore, it can be moved to the main thread if not created there initially // since god forbid you create a QWidget subclass in not the main thread. class GUIProxy : public QObject { Q_OBJECT + QMutex lock; + QWaitCondition wait; + public: - QLabel * window; + bool eventFilter(QObject * obj, QEvent * event) + { + if (event->type() == QEvent::KeyPress) + { + wait.wakeAll(); + } + return QObject::eventFilter(obj, event); + } + + QLabel * window; GUIProxy() { window = NULL; } + void waitForKey() + { + QMutexLocker locker(&lock); + wait.wait(&lock); + } + public slots: void showImage(const QPixmap & input) @@ -74,6 +95,13 @@ public slots: delete window; window = new QLabel(); window->setVisible(true); + + QApplication::instance()->installEventFilter(this); + Qt::WindowFlags flags = window->windowFlags(); + + flags = flags & ~Qt::WindowCloseButtonHint; + window->setWindowFlags(flags); + window->show(); } }; @@ -88,9 +116,13 @@ class Show2Transform : public TimeVaryingTransform { Q_OBJECT public: + Q_PROPERTY(bool waitInput READ get_waitInput WRITE set_waitInput RESET reset_waitInput STORED false) + BR_PROPERTY(bool, waitInput, false) + Q_PROPERTY(QStringList keys READ get_keys WRITE set_keys RESET reset_keys STORED false) BR_PROPERTY(QStringList, keys, QStringList("FrameNumber")) + Show2Transform() : TimeVaryingTransform(false, false) { // Create our GUI proxy @@ -144,6 +176,11 @@ public: // by the main thread isn't damaged when we update displayBuffer // later. emit updateImage(displayBuffer.copy(displayBuffer.rect())); + + // Blocking wait for a key-press + if (this->waitInput) + gui->waitForKey(); + } } } -- libgit2 0.21.4