Commit 3dee491df2d2ed23f1826823466d2ba81beacdb1

Authored by Scott Klum
1 parent 42ae191d

Working subject viewers

openbr/gui/faceviewer.cpp
... ... @@ -73,8 +73,7 @@ void FaceViewer::setFile(const File &file_)
73 73 landmarks.append(QPointF());
74 74 nearestLandmark = -1;
75 75  
76   - FaceViewer::refreshImage();
77   - //QtConcurrent::run(this, &FaceViewer::refreshImage);
  76 + QtConcurrent::run(this, &FaceViewer::refreshImage);
78 77 }
79 78  
80 79 void FaceViewer::refreshImage()
... ...
openbr/gui/subjectviewer.cpp
1 1 #include "subjectviewer.h"
2 2  
3   -SubjectViewer::SubjectViewer()
  3 +using namespace br;
  4 +
  5 +SubjectViewer::SubjectViewer(QWidget *parent)
  6 + : TemplateViewer(parent)
  7 +{
  8 + files = FileList();
  9 + currentIndex = 0;
  10 +}
  11 +
  12 +void SubjectViewer::setFiles(const FileList &files)
  13 +{
  14 + if (files.isEmpty()) return;
  15 +
  16 + currentIndex = 0;
  17 + this->files = files;
  18 + TemplateViewer::setFile(this->files[currentIndex]);
  19 +}
  20 +
  21 +void SubjectViewer::wheelEvent(QWheelEvent *event)
4 22 {
  23 + QPoint numDegrees = event->angleDelta();
  24 +
  25 + if (numDegrees.y() < 0 && currentIndex > 0)
  26 + TemplateViewer::setFile(this->files[--currentIndex]);
  27 + else if (numDegrees.y() > 0 && currentIndex < files.size()-1)
  28 + TemplateViewer::setFile(this->files[++currentIndex]);
  29 +
  30 + event->accept();
5 31 }
... ...
openbr/gui/subjectviewer.h
1 1 #ifndef SUBJECTVIEWER_H
2 2 #define SUBJECTVIEWER_H
3 3  
4   -class SubjectViewer : public FaceViewer
  4 +#include <QList>
  5 +
  6 +#include <openbr/openbr_plugin.h>
  7 +#include <openbr/gui/templateviewer.h>
  8 +
  9 +namespace br
  10 +{
  11 +
  12 +class BR_EXPORT SubjectViewer : public TemplateViewer
5 13 {
  14 + FileList files;
  15 + int currentIndex;
  16 +
6 17 public:
7   - SubjectViewer();
  18 + explicit SubjectViewer(QWidget *parent = 0);
  19 +
  20 +public slots:
  21 + void setFiles(const FileList &files);
  22 +
  23 +protected slots:
  24 + void wheelEvent(QWheelEvent *);
8 25 };
9 26  
  27 +}
  28 +
10 29 #endif // SUBJECTVIEWER_H
... ...
openbr/gui/subjectviewergrid.cpp
1 1 #include "subjectviewergrid.h"
2 2  
  3 +using namespace br;
  4 +
3 5 SubjectViewerGrid::SubjectViewerGrid(QWidget *parent) :
4   - TemplateViewerGrid(parent)
  6 + QWidget(parent)
  7 +{
  8 + setLayout(&gridLayout);
  9 +}
  10 +
  11 +void SubjectViewerGrid::setFiles(const QList<FileList> &files)
5 12 {
  13 + const int size = std::max(1, (int)ceil(sqrt((float)files.size())));
  14 + while (subjectViewers.size() < size*size) {
  15 + subjectViewers.append(QSharedPointer<SubjectViewer>(new SubjectViewer()));
  16 + connect(subjectViewers.last().data(), SIGNAL(newInput(br::File)), this, SIGNAL(newInput(br::File)));
  17 + connect(subjectViewers.last().data(), SIGNAL(newInput(QImage)), this, SIGNAL(newInput(QImage)));
  18 + connect(subjectViewers.last().data(), SIGNAL(newMousePoint(QPointF)), this, SIGNAL(newMousePoint(QPointF)));
  19 + connect(subjectViewers.last().data(), SIGNAL(selectedInput(br::File)), this, SIGNAL(selectedInput(br::File)));
  20 + }
  21 +
  22 + { // Clear layout
  23 + QLayoutItem *child;
  24 + while ((child = gridLayout.takeAt(0)) != 0)
  25 + child->widget()->setVisible(false);
  26 + }
  27 +
  28 + for (int i=0; i<subjectViewers.size(); i++) {
  29 + if (i < size*size) {
  30 + gridLayout.addWidget(subjectViewers[i].data(), i/size, i%size, 1, 1);
  31 + subjectViewers[i]->setVisible(true);
  32 + }
  33 +
  34 + if (i < files.size()) {
  35 + subjectViewers[i]->setFiles(files[i]);
  36 + } else {
  37 + subjectViewers[i]->setDefaultText("<b>"+ (size > 1 ? QString() : QString("Drag Photo or Folder Here")) +"</b>");
  38 + subjectViewers[i]->setFiles(FileList());
  39 + }
  40 +
  41 + subjectViewers[i]->setEditable(files.size() == 1);
  42 + }
6 43 }
... ...
openbr/gui/subjectviewergrid.h
1 1 #ifndef SUBJECTVIEWERGRID_H
2 2 #define SUBJECTVIEWERGRID_H
3 3  
4   -class SubjectViewerGrid : public TemplateViewerGrid
  4 +#include <QObject>
  5 +#include <QGridLayout>
  6 +#include <QSharedPointer>
  7 +
  8 +#include <openbr/openbr_plugin.h>
  9 +
  10 +#include "subjectviewer.h"
  11 +
  12 +namespace br
  13 +{
  14 +
  15 +class BR_EXPORT SubjectViewerGrid : public QWidget
5 16 {
6 17 Q_OBJECT
  18 +
  19 + QGridLayout gridLayout;
  20 + QList< QSharedPointer<SubjectViewer> >subjectViewers;
  21 +
7 22 public:
8 23 explicit SubjectViewerGrid(QWidget *parent = 0);
9 24  
10   -signals:
11   -
12 25 public slots:
  26 + void setFiles(const QList<br::FileList> &file);
13 27  
14 28 };
15 29  
  30 +}
  31 +
16 32 #endif // SUBJECTVIEWERGRID_H
... ...