From daa8aa9b45555e5f44f2b6008e4cbd4e2628f50c Mon Sep 17 00:00:00 2001 From: Scott Klum Date: Thu, 14 Aug 2014 15:51:35 -0400 Subject: [PATCH] Added gui constructs to facilitate rankRetrieval --- openbr/gui/formcombowidget.cpp | 15 +++++++++++++++ openbr/gui/formcombowidget.h | 34 ++++++++++++++++++++++++++++++++++ openbr/gui/pageflipwidget.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ openbr/gui/pageflipwidget.h | 39 +++++++++++++++++++++++++++++++++++++++ openbr/gui/rangewidget.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ openbr/gui/rangewidget.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ openbr/gui/recognitionbar.cpp | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ openbr/gui/recognitionbar.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 460 insertions(+), 0 deletions(-) create mode 100644 openbr/gui/formcombowidget.cpp create mode 100644 openbr/gui/formcombowidget.h create mode 100644 openbr/gui/pageflipwidget.cpp create mode 100644 openbr/gui/pageflipwidget.h create mode 100644 openbr/gui/rangewidget.cpp create mode 100644 openbr/gui/rangewidget.h create mode 100644 openbr/gui/recognitionbar.cpp create mode 100644 openbr/gui/recognitionbar.h diff --git a/openbr/gui/formcombowidget.cpp b/openbr/gui/formcombowidget.cpp new file mode 100644 index 0000000..63ccb73 --- /dev/null +++ b/openbr/gui/formcombowidget.cpp @@ -0,0 +1,15 @@ +#include "formcombowidget.h" + +using namespace br; + +FormComboWidget::FormComboWidget(const QString &name, QWidget *parent) : + QWidget(parent) +{ + combo = new QComboBox(this); + form = new QFormLayout(this); + + form->addRow(name, combo); + + connect(combo, SIGNAL(activated(QString)), this, SIGNAL(activated(QString))); + connect(combo, SIGNAL(currentIndexChanged(QString)), this, SIGNAL(currentIndexChanged(QString))); +} diff --git a/openbr/gui/formcombowidget.h b/openbr/gui/formcombowidget.h new file mode 100644 index 0000000..5181a7e --- /dev/null +++ b/openbr/gui/formcombowidget.h @@ -0,0 +1,34 @@ +#ifndef BR_FORMCOMBOWIDGET_H +#define BR_FORMCOMBOWIDGET_H + +#include +#include +#include +#include + +#include + +namespace br { + +class BR_EXPORT FormComboWidget : public QWidget +{ + Q_OBJECT + + QStringList items; + QFormLayout *form; + QComboBox *combo; + +public: + explicit FormComboWidget(const QString &name, QWidget *parent = 0); + +public slots: + void addItem(const QString &str) { items.append(str); combo->clear(); combo->addItems(items); } + +signals: + void activated(QString); + void currentIndexChanged(QString); +}; + +} + +#endif // BR_FORMCOMBOWIDGET_H diff --git a/openbr/gui/pageflipwidget.cpp b/openbr/gui/pageflipwidget.cpp new file mode 100644 index 0000000..23f56d4 --- /dev/null +++ b/openbr/gui/pageflipwidget.cpp @@ -0,0 +1,42 @@ +#include "pageflipwidget.h" + +using namespace br; + +PageFlipWidget::PageFlipWidget(QWidget *parent) : + QWidget(parent) +{ + firstPage = new QPushButton(this); + firstPage->setIcon(QIcon(":/arrow-first.png")); + firstPage->setMaximumWidth(30); + firstPage->setToolTip("Go to first page"); + + connect(firstPage, SIGNAL(clicked()), this, SIGNAL(first())); + + previousPage = new QPushButton(this); + previousPage->setIcon(QIcon(":/arrow-left.png")); + previousPage->setMaximumWidth(30); + previousPage->setToolTip("Go to previous page"); + + connect(previousPage, SIGNAL(clicked()), this, SIGNAL(previous())); + + nextPage = new QPushButton(this); + nextPage->setIcon(QIcon(":/arrow-right.png")); + nextPage->setMaximumWidth(30); + nextPage->setToolTip("Go to next page"); + + connect(nextPage, SIGNAL(clicked()), this, SIGNAL(next())); + + lastPage = new QPushButton(this); + lastPage->setIcon(QIcon(":/arrow-last.png")); + lastPage->setMaximumWidth(30); + lastPage->setToolTip("Go to last page"); + + connect(lastPage, SIGNAL(clicked()), this, SIGNAL(last())); + + boxLayout.addWidget(firstPage); + boxLayout.addWidget(previousPage); + boxLayout.addWidget(nextPage); + boxLayout.addWidget(lastPage); + + setLayout(&boxLayout); +} diff --git a/openbr/gui/pageflipwidget.h b/openbr/gui/pageflipwidget.h new file mode 100644 index 0000000..e842ae8 --- /dev/null +++ b/openbr/gui/pageflipwidget.h @@ -0,0 +1,39 @@ +#ifndef BR_PAGEFLIPWIDGET_H +#define BR_PAGEFLIPWIDGET_H + +#include +#include +#include + +#include + +namespace br { + +class BR_EXPORT PageFlipWidget : public QWidget +{ + Q_OBJECT + + QHBoxLayout boxLayout; + + QPushButton *firstPage; + QPushButton *previousPage; + QPushButton *nextPage; + QPushButton *lastPage; + +public: + explicit PageFlipWidget(QWidget *parent = 0); + +signals: + + void first(); + void next(); + void previous(); + void last(); + +public slots: + +}; + +} // namespace br + +#endif // BR_PAGEFLIPWIDGET_H diff --git a/openbr/gui/rangewidget.cpp b/openbr/gui/rangewidget.cpp new file mode 100644 index 0000000..0e152ac --- /dev/null +++ b/openbr/gui/rangewidget.cpp @@ -0,0 +1,47 @@ +#include "rangewidget.h" + +using namespace br; + +RangeWidget::RangeWidget(QWidget *parent) : + QWidget(parent) +{ + hLayout = new QHBoxLayout(); + + validator = new QIntValidator(0,100,this); + + median = new QLineEdit("20", this); + median->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + median->setAlignment(Qt::AlignCenter); + median->setValidator(validator); + + rangeSpin = new QSpinBox(this); + rangeSpin->setValue(0); + rangeSpin->setAlignment(Qt::AlignCenter); + + label = new QLabel(this); + label->setAlignment(Qt::AlignCenter); + label->setText(QString::fromUtf8("±")); + + hLayout->addWidget(median); + hLayout->addWidget(label); + hLayout->addWidget(rangeSpin); + hLayout->setSpacing(0); + + connect(median, SIGNAL(textChanged(QString)), this, SLOT(rangeChanged())); + connect(rangeSpin, SIGNAL(valueChanged(int)), this, SLOT(rangeChanged())); + + vLayout.addLayout(hLayout); + + setLayout(&vLayout); +} + +void RangeWidget::setSingleStep(int step) +{ + rangeSpin->setSingleStep(step); +} + +void RangeWidget::rangeChanged() +{ + emit newRange(median->text().toInt() - rangeSpin->value(), median->text().toInt() + rangeSpin->value()); + emit newRange(); +} diff --git a/openbr/gui/rangewidget.h b/openbr/gui/rangewidget.h new file mode 100644 index 0000000..c280a2f --- /dev/null +++ b/openbr/gui/rangewidget.h @@ -0,0 +1,48 @@ +#ifndef BR_RANGEWIDGET_H +#define BR_RANGEWIDGET_H + +#include +#include +#include +#include +#include +#include + +#include + +namespace br { + +class BR_EXPORT RangeWidget : public QWidget +{ + Q_OBJECT + + QVBoxLayout vLayout; + QHBoxLayout *hLayout; + + QIntValidator *validator; + + QLabel *label; + QLineEdit *median; + QSpinBox *rangeSpin; + +public: + explicit RangeWidget(QWidget *parent = 0); + +signals: + + void newRange(int, int); + void newRange(); + +public slots: + + void emitRange() { rangeChanged(); } + int getLowerBound() const {return median->text().toInt() - rangeSpin->value();} + int getUpperBound() const {return median->text().toInt() + rangeSpin->value();} + void rangeChanged(); + void setSingleStep(int step); + +}; + +} + +#endif // BR_AGERANGEWIDGET_H diff --git a/openbr/gui/recognitionbar.cpp b/openbr/gui/recognitionbar.cpp new file mode 100644 index 0000000..fc3969a --- /dev/null +++ b/openbr/gui/recognitionbar.cpp @@ -0,0 +1,156 @@ +#include "recognitionbar.h" + +#include + +using namespace br; + +RecognitionBar::RecognitionBar(QWidget *parent) : + QToolBar(parent) +{ + setToolButtonStyle(Qt::ToolButtonTextOnly); + + addSeparator(); + + algorithmLabel = new QLabel(this); + algorithmLabel->setAlignment(Qt::AlignCenter); + algorithmLabel->setTextFormat(Qt::RichText); + algorithmLabel->setText(" Algorithm"); + addWidget(algorithmLabel); + + model = new FormComboWidget("Model: ", this); + addWidget(model); + + connect(model, SIGNAL(currentIndexChanged(QString)), this, SIGNAL(newAlgorithm(QString))); + + landmarkCheck = new QCheckBox("Show Landmarks", this); + addWidget(landmarkCheck); + + connect(landmarkCheck, SIGNAL(clicked(bool)), this, SIGNAL(showLandmarks(bool))); + + addSeparator(); + + demographicsLabel = new QLabel(this); + demographicsLabel->setAlignment(Qt::AlignCenter); + demographicsLabel->setTextFormat(Qt::RichText); + demographicsLabel->setText(" Demographics"); + addWidget(demographicsLabel); + + maleCheck = new QCheckBox("Male", this); + addWidget(maleCheck); + femaleCheck = new QCheckBox("Female", this); + addWidget(femaleCheck); + + connect(maleCheck, SIGNAL(clicked()), this, SLOT(genderChanged())); + connect(femaleCheck, SIGNAL(clicked()), this, SLOT(genderChanged())); + + addSeparator(); + + whiteCheck = new QCheckBox("White", this); + addWidget(whiteCheck); + connect(whiteCheck, SIGNAL(clicked()), this, SLOT(raceChanged())); + blackCheck = new QCheckBox("Black", this); + addWidget(blackCheck); + connect(blackCheck, SIGNAL(clicked()), this, SLOT(raceChanged())); + hispanicCheck = new QCheckBox("Hispanic", this); + addWidget(hispanicCheck); + connect(hispanicCheck, SIGNAL(clicked()), this, SLOT(raceChanged())); + asianCheck = new QCheckBox("Oriental/Asian", this); + addWidget(asianCheck); + connect(hispanicCheck, SIGNAL(clicked()), this, SLOT(raceChanged())); + otherCheck = new QCheckBox("Other", this); + addWidget(otherCheck); + connect(otherCheck, SIGNAL(clicked()), this, SLOT(raceChanged())); + + addSeparator(); + + ageCheck = new QCheckBox("Age", this); + addWidget(ageCheck); + connect(ageCheck, SIGNAL(clicked()), this, SLOT(ageRangeChanged())); + + rangeWidget = new RangeWidget(this); + connect(rangeWidget, SIGNAL(newRange(int,int)), this, SLOT(ageRangeChanged())); + addWidget(rangeWidget); + + addSeparator(); + + findLabel = new QLabel(this); + findLabel->setAlignment(Qt::AlignCenter); + findLabel->setTextFormat(Qt::RichText); + findLabel->setText(" Find"); + + addWidget(findLabel); + + searchBox = new SearchBoxWidget(this); + connect(this, SIGNAL(setFiles(br::FileList)), searchBox, SLOT(setFiles(br::FileList))); + connect(searchBox, SIGNAL(newIndex(int)), this, SIGNAL(newIndex(int))); + + addWidget(searchBox); + + metadata = new Metadata(this); + + addWidget(metadata); + + spacer = new QWidget(this); + spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + addWidget(spacer); + + compareButton = new QPushButton(this); + compareButton->setText("Compare"); + compareButton->setIcon(QIcon(":/compare.png")); + addWidget(compareButton); + compareButton->setFocus(); + + connect(compareButton, SIGNAL(clicked()), this, SIGNAL(compare())); + + setOrientation(Qt::Vertical); + + addSeparator(); + + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); +} + +void RecognitionBar::addAlgorithm() +{ + model->addItem(QFileDialog::getOpenFileName(this, "Add a model...", Context::scratchPath())); +} + +void RecognitionBar::genderChanged() +{ + QStringList genders; + + if (maleCheck->isChecked()) genders.push_back(maleCheck->text()[0].toUpper()); + if (femaleCheck->isChecked()) genders.push_back(femaleCheck->text()[0].toUpper()); + + emit newDemographics("GENDER", genders); +} + +void RecognitionBar::raceChanged() +{ + QStringList races; + + if (whiteCheck->isChecked()) races.push_back(whiteCheck->text().toUpper()); + if (blackCheck->isChecked()) races.push_back(blackCheck->text().toUpper()); + if (hispanicCheck->isChecked()) races.push_back(hispanicCheck->text().toUpper()); + if (asianCheck->isChecked()) races.push_back(asianCheck->text().toUpper()); + if (otherCheck->isChecked()) races.push_back(otherCheck->text().toUpper()); + + emit newDemographics("RACE", races); +} + +void RecognitionBar::ageRangeChanged() +{ + QStringList range; + + if (ageCheck->isChecked()) { + int age = rangeWidget->getLowerBound(); + while (age <= rangeWidget->getUpperBound()) { + range.push_back(QString::number(age)); + age++; + } + } + else range.clear(); + + emit newDemographics("Age", range); +} + +#include "moc_recognitionbar.cpp" diff --git a/openbr/gui/recognitionbar.h b/openbr/gui/recognitionbar.h new file mode 100644 index 0000000..d811a68 --- /dev/null +++ b/openbr/gui/recognitionbar.h @@ -0,0 +1,79 @@ +#ifndef BR_RECOGNITIONBAR_H +#define BR_RECOGNITIONBAR_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "formcombowidget.h" +#include "rangewidget.h" +#include "pageflipwidget.h" +#include "searchboxwidget.h" +#include "metadata.h" + +#include + +namespace br +{ + +class BR_EXPORT RecognitionBar : public QToolBar +{ + Q_OBJECT + + QCheckBox *landmarkCheck; + + QCheckBox *maleCheck; + QCheckBox *femaleCheck; + + QCheckBox *whiteCheck; + QCheckBox *blackCheck; + QCheckBox *hispanicCheck; + QCheckBox *asianCheck; + QCheckBox *otherCheck; + + QCheckBox *ageCheck; + + QLabel *demographicsLabel; + QLabel *algorithmLabel; + QLabel *findLabel; + + FormComboWidget *model; + + RangeWidget *rangeWidget; + PageFlipWidget *pageFlipWidget; + SearchBoxWidget *searchBox; + QPushButton *compareButton; + + QWidget *spacer; + +public: + explicit RecognitionBar(QWidget *parent = 0); + + Metadata *metadata; + +public slots: + void addAlgorithm(); + +private slots: + void genderChanged(); + void raceChanged(); + void ageRangeChanged(); + +signals: + void newAlgorithm(QString); + void newDemographics(QString, QStringList); + void newIndex(int); + void setFiles(br::FileList); + void compare(); + + void showLandmarks(bool); +}; + +} // namespace br + +#endif // BR_RECOGNITIONBAR_H -- libgit2 0.21.4