Commit 9523c80927ab9aed9ef209a5474f1caf8ff4e734

Authored by Charles Otto
1 parent 3152b940

Preliminary version of a transform that asks the user a yes/no question about an image

Showing 1 changed file with 107 additions and 0 deletions
openbr/plugins/gui.cpp
... ... @@ -143,6 +143,51 @@ private:
143 143  
144 144 };
145 145  
  146 +class PromptWindow : public DisplayWindow
  147 +{
  148 + bool eventFilter(QObject * obj, QEvent * event)
  149 + {
  150 + if (event->type() == QEvent::KeyPress)
  151 + {
  152 + event->accept();
  153 +
  154 + QKeyEvent * key_event = dynamic_cast<QKeyEvent *> (event);
  155 + if (key_event == NULL) {
  156 + qDebug("failed to donwcast key event");
  157 + return true;
  158 + }
  159 +
  160 + QString text = key_event->text();
  161 +
  162 + text =text.toLower();
  163 + if (text == "y" || text == "n")
  164 + {
  165 + gotString = key_event->text();
  166 + wait.wakeAll();
  167 + }
  168 + else qDebug("Please answer y/n");
  169 +
  170 + return true;
  171 + } else {
  172 + return QObject::eventFilter(obj, event);
  173 + }
  174 + }
  175 +
  176 +public:
  177 + QString waitForKeyPress()
  178 + {
  179 + QMutexLocker locker(&lock);
  180 + wait.wait(&lock);
  181 +
  182 + return gotString;
  183 + }
  184 +
  185 +private:
  186 + QString gotString;
  187 +
  188 +
  189 +};
  190 +
146 191  
147 192 // I want a template class that doesn't look like a template class
148 193 class NominalCreation
... ... @@ -382,6 +427,68 @@ public:
382 427  
383 428 BR_REGISTER(Transform, ManualTransform)
384 429  
  430 +
  431 +/*!
  432 + * \ingroup transforms
  433 + * \brief Display an image, and asks a yes/no question about it
  434 + * \author Charles Otto \cite caotto
  435 + */
  436 +class SurveyTransform : public ShowTransform
  437 +{
  438 + Q_OBJECT
  439 +
  440 +public:
  441 + Q_PROPERTY(QString question READ get_question WRITE set_question RESET reset_question STORED false)
  442 + BR_PROPERTY(QString, question, "Yes/No")
  443 +
  444 + Q_PROPERTY(QString propertyName READ get_propertyName WRITE set_propertyName RESET reset_propertyName STORED false)
  445 + BR_PROPERTY(QString, propertyName, "answer")
  446 +
  447 +
  448 + void projectUpdate(const TemplateList &src, TemplateList &dst)
  449 + {
  450 + if (Globals->parallelism > 1)
  451 + qFatal("SurveyTransform cannot execute in parallel.");
  452 +
  453 + dst = src;
  454 +
  455 + if (src.empty())
  456 + return;
  457 +
  458 + for (int i = 0; i < dst.size(); i++) {
  459 + foreach(const cv::Mat &m, dst[i]) {
  460 + qImageBuffer = toQImage(m);
  461 + displayBuffer->convertFromImage(qImageBuffer);
  462 +
  463 + emit updateImage(displayBuffer->copy(displayBuffer->rect()));
  464 +
  465 + // Blocking wait for a key-press
  466 + if (this->waitInput) {
  467 + QString answer = p_window->waitForKeyPress();
  468 +
  469 + dst[i].file.set(this->propertyName, answer);
  470 + }
  471 + }
  472 + }
  473 + }
  474 + PromptWindow * p_window;
  475 +
  476 +
  477 + void init()
  478 + {
  479 + if (!Globals->useGui)
  480 + return;
  481 +
  482 + initActual<PromptWindow>();
  483 + p_window = (PromptWindow *) window;
  484 +
  485 + emit changeTitle(this->question);
  486 + }
  487 +};
  488 +
  489 +BR_REGISTER(Transform, SurveyTransform)
  490 +
  491 +
385 492 class FPSLimit : public TimeVaryingTransform
386 493 {
387 494 Q_OBJECT
... ...