MainWindow.cpp 19.6 KB
Newer Older
Thiago Santini's avatar
Thiago Santini committed
1 2 3
#include "MainWindow.h"
#include "ui_MainWindow.h"

4
// TODO: factor config aware class into ERWidget
5

Thiago Santini's avatar
Thiago Santini committed
6 7 8 9 10 11 12
void MainWindow::createExtraMenus()
{
    ui->menuBar->addAction("References");
    ui->menuBar->addAction("About");
}

MainWindow::MainWindow(QWidget *parent) :
13
	ERWidget(parent),
Thiago Santini's avatar
Thiago Santini committed
14 15 16 17 18 19
    lEyeWidget(NULL),
    rEyeWidget(NULL),
    fieldWidget(NULL),
    synchronizer(NULL),
    ui(new Ui::MainWindow)
{
20
	ui->setupUi(this);
21
//#define EYEREC
22
#ifdef EYEREC
Thiago Santini's avatar
Thiago Santini committed
23 24 25 26 27 28 29 30 31 32 33

    createExtraMenus();
    connect(ui->menuBar, SIGNAL(triggered(QAction*)), this, SLOT(menuOption(QAction*)) );

    settings = new QSettings(gCfgDir + "/" + "EyeRecToo", QSettings::IniFormat);
    cfg.load(settings);

    setWindowTitle(QString("EyeRecToo v%1").arg(GIT_VERSION));
    setWindowIcon(QIcon(":/icons/EyeRecToo.png"));

    if (!cfg.workingDirectory.isEmpty())
34 35
		setWorkingDirectory(cfg.workingDirectory);
	ui->pwd->setText(QDir::currentPath());
Thiago Santini's avatar
Thiago Santini committed
36

37
	ui->blinker->hide();
Thiago Santini's avatar
Thiago Santini committed
38

Thiago Santini's avatar
Thiago Santini committed
39
    logWidget = new LogWidget();
40
    setupWidget(logWidget, cfg.logWidgetPos, cfg.logWidgetSize, cfg.logWidgetVisible, ui->log);
41
	gLogWidget = logWidget;
Thiago Santini's avatar
Thiago Santini committed
42

Thiago Santini's avatar
Thiago Santini committed
43 44 45 46 47 48
    /*
     * WARNING: DO NOT REMOVE THIS CALL to QCameraInfo::availableCameras()
     * Logically, its meaningless, but it guarantees that DirectShow will work
     * properly by CoInitializing it in the main thread.
     */
    volatile QList<QCameraInfo> tmp = QCameraInfo::availableCameras();
Thiago Santini's avatar
Thiago Santini committed
49 50 51
	Q_UNUSED(tmp);

	gPerformanceMonitor.setFrameDrop(true);
Thiago Santini's avatar
Thiago Santini committed
52 53 54 55 56 57

    /*
     * Asynchronous elements
     */
    lEyeWidget = new CameraWidget("LeftEye", ImageProcessor::Eye);
    lEyeWidget->setWindowIcon(QIcon(":/icons/lEyeWidget.png"));
58 59
	setupWidget(lEyeWidget, cfg.leftEyeWidgetPos, cfg.leftEyeWidgetSize, cfg.leftEyeWidgetVisible, ui->leftEyeCam);
	QThread::msleep(200);
Thiago Santini's avatar
Thiago Santini committed
60 61
    rEyeWidget = new CameraWidget("RightEye", ImageProcessor::Eye);
    rEyeWidget->setWindowIcon(QIcon(":/icons/rEyeWidget.png"));
62
    setupWidget(rEyeWidget, cfg.rightEyeWidgetPos, cfg.rightEyeWidgetSize, cfg.rightEyeWidgetVisible, ui->rightEyeCam);
63
	QThread::msleep(200);
Thiago Santini's avatar
Thiago Santini committed
64 65
    fieldWidget = new CameraWidget("Field", ImageProcessor::Field);
    fieldWidget->setWindowIcon(QIcon(":/icons/fieldWidget.png"));
66
    setupWidget(fieldWidget, cfg.fieldWidgetPos, cfg.fieldWidgetSize, cfg.fieldWidgetVisible, ui->fieldCam);
Thiago Santini's avatar
Thiago Santini committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

    /*
     * Synchronizer
     */
    synchronizer = new Synchronizer();
    connect(lEyeWidget,  SIGNAL(newData(EyeData)),
            synchronizer, SLOT(newLeftEyeData(EyeData)), Qt::QueuedConnection);
    connect(rEyeWidget,  SIGNAL(newData(EyeData)),
            synchronizer, SLOT(newRightEyeData(EyeData)) );
    connect(fieldWidget, SIGNAL(newData(FieldData)),
            synchronizer, SLOT(newFieldData(FieldData)) );

    /*
     * Synchronous elements
     */
    gazeEstimationWidget = new GazeEstimationWidget();
83
    setupWidget(gazeEstimationWidget, cfg.gazeEstimationWidgetPos, cfg.gazeEstimationWidgetSize, cfg.gazeEstimationWidgetVisible, ui->gazeEstimation);
Thiago Santini's avatar
Thiago Santini committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    connect(synchronizer, SIGNAL(newData(DataTuple)),
            gazeEstimationWidget, SIGNAL(inDataTuple(DataTuple)) );
    connect(fieldWidget, SIGNAL(newClick(Timestamp,QPoint,QSize)),
            gazeEstimationWidget, SIGNAL(newClick(Timestamp,QPoint,QSize)) );

    connect(gazeEstimationWidget, SIGNAL(outDataTuple(DataTuple)),
            fieldWidget, SLOT(preview(DataTuple)) );

    journalThread = new QThread();
    journalThread->setObjectName("Journal");
    journalThread->start();
    journalThread->setPriority(QThread::NormalPriority);
    journal = new DataRecorderThread("Journal", DataTuple().header());
    journal->moveToThread(journalThread);
    QMetaObject::invokeMethod(journal, "create");

    networkStream = new NetworkStream();

    networkStream->start(2002);
    connect(gazeEstimationWidget, SIGNAL(outDataTuple(DataTuple)), networkStream, SLOT(push(DataTuple)) );

105
    performanceMonitorWidget = new PerformanceMonitorWidget();
106
    setupWidget(performanceMonitorWidget, cfg.performanceMonitorWidgetPos, cfg.performanceMonitorWidgetSize, cfg.performanceMonitorWidgetVisible, ui->performanceMonitor);
107

Thiago Santini's avatar
Thiago Santini committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    // GUI to Widgets signals
    connect(this, SIGNAL(startRecording()),
            lEyeWidget, SLOT(startRecording()) );
    connect(this, SIGNAL(stopRecording()),
            lEyeWidget, SLOT(stopRecording()) );
    connect(this, SIGNAL(startRecording()),
            rEyeWidget, SLOT(startRecording()) );
    connect(this, SIGNAL(stopRecording()),
            rEyeWidget, SLOT(stopRecording()) );
    connect(this, SIGNAL(startRecording()),
            fieldWidget, SLOT(startRecording()) );
    connect(this, SIGNAL(stopRecording()),
            fieldWidget, SLOT(stopRecording()) );
//    connect(this, SIGNAL(startRecording()), calibrationWidget, SLOT(startRecording()) );
//    connect(this, SIGNAL(stopRecording()), calibrationWidget, SLOT(stopRecording()) );
    connect(this, SIGNAL(startRecording()),
            journal, SIGNAL(startRecording()) );
    connect(this, SIGNAL(stopRecording()),
126
			journal, SIGNAL(stopRecording()) );
Thiago Santini's avatar
Thiago Santini committed
127 128 129

    loadSoundEffect(recStartSound, "rec-start.wav");
    loadSoundEffect(recStopSound, "rec-stop.wav");
130

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
	setupWidget(this, cfg.mainWindowPos, cfg.mainWindowSize, true);

	// Commands
	connect(&commandManager, SIGNAL(toggleCalibration()),
			gazeEstimationWidget, SLOT(toggleCalibration()) );
	connect(&commandManager, SIGNAL(enableMarkerCollection()),
			gazeEstimationWidget, SLOT(enableMarkerCollection()) );
	connect(&commandManager, SIGNAL(disableMarkerCollection()),
			gazeEstimationWidget, SLOT(disableMarkerCollection()) );
	connect(&commandManager, SIGNAL(toggleRecording()),
			this, SLOT(toggleRecording()) );
	connect(&commandManager, SIGNAL(freezeCameraImages()),
			this, SLOT(freezeCameraImages()) );
	connect(&commandManager, SIGNAL(unfreezeCameraImages()),
			this, SLOT(unfreezeCameraImages()) );
146
#else
Thiago Santini's avatar
Thiago Santini committed
147
	gPerformanceMonitor.setFrameDrop(false);
148 149 150 151
	evaluation = new Evaluation();
	evaluation->show();
	QMetaObject::invokeMethod(evaluation, "run", Qt::QueuedConnection);
#endif
Thiago Santini's avatar
Thiago Santini committed
152 153 154 155 156 157 158 159 160 161
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::closeEvent(QCloseEvent *event)
{
162
#ifdef EYEREC
163 164 165 166 167 168 169
    if (ui->recordingToggle->isChecked()) {
        ui->recordingToggle->setChecked(false);
        on_recordingToggle_clicked();
        // should be equivalent, but just in case click() is connected with a
        // queued connection in the future :-)
        // ui->recordingToggle->click();
    }
Thiago Santini's avatar
Thiago Santini committed
170 171

    cfg.mainWindowPos = pos();
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
	cfg.mainWindowSize = size();
	cfg.logWidgetPos = logWidget->pos();
	cfg.logWidgetSize = logWidget->size();
	cfg.logWidgetVisible = logWidget->isVisible();
	cfg.leftEyeWidgetPos = lEyeWidget->pos();
	cfg.leftEyeWidgetSize = lEyeWidget->size();
	cfg.leftEyeWidgetVisible = lEyeWidget->isVisible();
	cfg.rightEyeWidgetPos = rEyeWidget->pos();
	cfg.rightEyeWidgetSize = rEyeWidget->size();
	cfg.rightEyeWidgetVisible = rEyeWidget->isVisible();
	cfg.fieldWidgetPos = fieldWidget->pos();
	cfg.fieldWidgetSize = fieldWidget->size();
	cfg.fieldWidgetVisible = fieldWidget->isVisible();
	cfg.gazeEstimationWidgetPos = gazeEstimationWidget->pos();
	cfg.gazeEstimationWidgetSize = gazeEstimationWidget->size();
	cfg.gazeEstimationWidgetVisible = gazeEstimationWidget->isVisible();
	cfg.performanceMonitorWidgetPos = performanceMonitorWidget->pos();
	cfg.performanceMonitorWidgetSize = performanceMonitorWidget->size();
	cfg.performanceMonitorWidgetVisible = performanceMonitorWidget->isVisible();
Thiago Santini's avatar
Thiago Santini committed
191 192 193 194
    cfg.workingDirectory = QDir::currentPath();
    if (settings)
        cfg.save(settings);

195
    qInfo() << "Closing Left Eye Widget...";
Thiago Santini's avatar
Thiago Santini committed
196 197 198 199 200
    if ( lEyeWidget ) {
        lEyeWidget->close();
        lEyeWidget->deleteLater();
        lEyeWidget = NULL;
    }
201
    qInfo() << "Closing Right Eye Widget...";
Thiago Santini's avatar
Thiago Santini committed
202 203 204 205 206
    if ( rEyeWidget ) {
        rEyeWidget->close();
        rEyeWidget->deleteLater();
        rEyeWidget = NULL;
    }
207
    qInfo() << "Closing Field Widget...";
Thiago Santini's avatar
Thiago Santini committed
208 209 210 211 212 213
    if ( fieldWidget ) {
        fieldWidget->close();
        fieldWidget->deleteLater();
        fieldWidget = NULL;
    }

214
    qInfo() << "Closing Gaze Estimation Widget...";
Thiago Santini's avatar
Thiago Santini committed
215 216 217 218 219 220 221 222 223
    if (gazeEstimationWidget) {
        gazeEstimationWidget->close();
        gazeEstimationWidget->deleteLater();
    }

    qInfo() << "Stoping network stream...";
    if (networkStream)
        networkStream->deleteLater();

224
	gPerformanceMonitor.report();
225 226 227 228 229 230 231 232 233

    qInfo() << "Closing Performance Monitor Widget...";
    if (performanceMonitorWidget) {
        performanceMonitorWidget->close();
        performanceMonitorWidget->deleteLater();
        performanceMonitorWidget = NULL;
    }


234
    qInfo() << "Closing Log Widget...";
Thiago Santini's avatar
Thiago Santini committed
235 236
    if (logWidget) {
        gLogWidget = NULL;
237
        logWidget->close();
Thiago Santini's avatar
Thiago Santini committed
238
        logWidget->deleteLater();
239
        logWidget = NULL;
Thiago Santini's avatar
Thiago Santini committed
240 241
    }

242 243 244 245 246 247 248 249 250 251 252 253
    qInfo() << "Stopping journal and synchronizer";
    if (journal) {
        journal->deleteLater();
        journal = NULL;
    }

    if (synchronizer) {
        synchronizer->deleteLater();
        synchronizer = NULL;
    }

    if (settings) {
Thiago Santini's avatar
Thiago Santini committed
254
        settings->deleteLater();
255
        settings = NULL;
256 257 258 259 260 261 262 263
	}
#else
	if ( evaluation ) {
		evaluation->close();
		evaluation->deleteLater();
		evaluation = NULL;
	}
#endif
Thiago Santini's avatar
Thiago Santini committed
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384

    event->accept();
}

void MainWindow::setWorkingDirectory(QString dir)
{
    previousPwd = QDir::currentPath();
    QDir::setCurrent(dir);
    ui->pwd->setText(dir);
    qInfo() << "PWD set to" << dir;
}

void MainWindow::on_changePwdButton_clicked()
{
    QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
                                                 QDir::currentPath(),
                                                 QFileDialog::ShowDirsOnly
                                                 | QFileDialog::DontResolveSymlinks);

    if (!dir.isEmpty()) {
        setWorkingDirectory(dir);
    }

}

void MainWindow::setSubjectName(QString newSubjectName)
{
    QRegExp re("[a-zA-Z0-9-_]*");
    Q_ASSERT(re.isValid());

    if (!re.exactMatch(newSubjectName)) {
        QMessageBox::warning(NULL,
             "Invalid subject name.",
             QString("Invalid name: \"%1\".\n\nSubject names may contain only letters, numbers, dashes (-), and underscores (_).\nIn regex terms: %2").arg(newSubjectName,re.pattern()),
             QMessageBox::Ok,
             QMessageBox::NoButton
             );
        return;
    }

    ui->subject->setText(newSubjectName);
    if (newSubjectName.isEmpty())
        ui->changeSubjectButton->setText("Set");
    else
        ui->changeSubjectButton->setText("Change");

    qInfo() << "Subject set to" << newSubjectName;
}

void MainWindow::on_changeSubjectButton_clicked()
{
    QString newSubjectName = QInputDialog::getText(this, "Set subject", "Subject name:",  QLineEdit::Normal, QString(), NULL, Qt::CustomizeWindowHint);
    setSubjectName(newSubjectName);
}

bool MainWindow::setupSubjectDirectory()
{
    QString subject = ui->subject->text();

    if (subject.isEmpty()) {
        QString tmpSubjectName = QString::number(QDateTime::currentMSecsSinceEpoch()/1000);
        QMessageBox msgBox(this);
        QPushButton *continueButton = msgBox.addButton("Start Anyway", QMessageBox::ActionRole);
        QPushButton *addButton = msgBox.addButton("Add Subject", QMessageBox::ActionRole);
        QPushButton *cancelButton = msgBox.addButton("Cancel", QMessageBox::ActionRole);
        msgBox.setText(QString("Currently there is no test subject.\nIf record is started, subject will be set to %1.\t").arg(tmpSubjectName));
        msgBox.exec();
        if (msgBox.clickedButton() == continueButton)
            setSubjectName(tmpSubjectName);
        else if (msgBox.clickedButton() == addButton)
            on_changeSubjectButton_clicked();
        else if (msgBox.clickedButton() == cancelButton)
            return false;

        if (ui->subject->text().isEmpty()) // smartass user still entered an empty string, show him who's the boss
            setSubjectName(tmpSubjectName);
    }

    QString path = QDir::currentPath() + "/" + ui->subject->text();

    unsigned int recording = 0;
    if ( QDir( path ).exists() ) {
        QDirIterator it(path);
        while (it.hasNext()) {
            QRegExp re("[0-9]*");
            QString subDir = it.next();
            subDir = subDir.mid(path.size()+1);
            if (re.exactMatch(subDir)) {
                unsigned int subDirRecId = subDir.toInt();
                if (subDirRecId > recording)
                    recording = subDirRecId;
            }
        }
    }
    recording++;

    path += "/" + QString::number(recording);

    previousPwd = QDir().currentPath();
    QDir().mkpath(path);
    setWorkingDirectory(path);

    return true;
}

void MainWindow::on_recordingToggle_clicked()
{
    if (ui->recordingToggle->isChecked()) {
        if (!setupSubjectDirectory()) {
            ui->recordingToggle->setChecked(false);
            return;
        }
        qInfo() << "Record starting (Subject:" << ui->subject->text() << ")";
        ui->changeSubjectButton->setEnabled(false);
        ui->changePwdButton->setEnabled(false);
        emit startRecording();
        ui->recordingToggle->setText("Finish");
        connect(gazeEstimationWidget, SIGNAL(outDataTuple(DataTuple)),
                journal, SIGNAL(newData(DataTuple)) );
        QTimer::singleShot(500, this, SLOT(effectiveRecordingStart())); // TODO: right now we wait a predefined amount of time; ideally, we should wait for an ack from everyone involved
        ui->recordingToggle->setEnabled(false);
Thiago Santini's avatar
Thiago Santini committed
385
        recStartSound.play();
Thiago Santini's avatar
Thiago Santini committed
386 387 388 389 390 391 392 393 394 395 396 397 398
    } else {
        qInfo() << "Record stopped (Subject:" << ui->subject->text() << ")";
        emit stopRecording();
        disconnect(gazeEstimationWidget, SIGNAL(outDataTuple(DataTuple)),
                journal, SIGNAL(newData(DataTuple)) );
        killTimer(elapsedTimeUpdateTimer);
        elapsedTime.invalidate();
        ui->elapsedTime->setText("00:00:00");
        ui->recordingToggle->setText("Start");
        ui->blinker->hide();
        setWorkingDirectory(previousPwd);
        ui->changeSubjectButton->setEnabled(true);
        ui->changePwdButton->setEnabled(true);
Thiago Santini's avatar
Thiago Santini committed
399
        recStopSound.play();
Thiago Santini's avatar
Thiago Santini committed
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
    }
}
void MainWindow::effectiveRecordingStart()
{
    elapsedTime.restart();
    elapsedTimeUpdateTimer = startTimer(500);
    ui->recordingToggle->setEnabled(true);
    qInfo() << "Record started.";
}

void MainWindow::timerEvent(QTimerEvent* event)
{
    if (event->timerId() == elapsedTimeUpdateTimer) {
        ui->elapsedTime->setText(QDateTime::fromTime_t((elapsedTime.elapsed()/1000+0.5), Qt::UTC).toString("hh:mm:ss"));

        if (ui->blinker->isVisible())
            ui->blinker->hide();
        else
            ui->blinker->show();
    }
}

void MainWindow::widgetButtonReact(QMainWindow *window, bool checked)
{
    if (!window)
        return;

    if (checked) {
        window->show();
        window->raise();
430
        window->activateWindow();
431
        window->setFocus();
Thiago Santini's avatar
Thiago Santini committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
    } else
        window->hide();
}

void MainWindow::on_leftEyeCam_clicked()
{
    widgetButtonReact(lEyeWidget, ui->leftEyeCam->isChecked());
}

void MainWindow::on_rightEyeCam_clicked()
{
    widgetButtonReact(rEyeWidget, ui->rightEyeCam->isChecked());
}

void MainWindow::on_fieldCam_clicked()
{
    widgetButtonReact(fieldWidget, ui->fieldCam->isChecked());
}

void MainWindow::on_gazeEstimation_clicked()
{
    widgetButtonReact(gazeEstimationWidget, ui->gazeEstimation->isChecked());
}

Thiago Santini's avatar
Thiago Santini committed
456 457 458 459 460
void MainWindow::on_log_clicked()
{
    widgetButtonReact(logWidget, ui->log->isChecked());
}

461 462 463 464 465
void MainWindow::on_performanceMonitor_clicked()
{
    widgetButtonReact(performanceMonitorWidget, ui->performanceMonitor->isChecked());
}

466
void MainWindow::freezeCameraImages()
Thiago Santini's avatar
Thiago Santini committed
467
{
468 469 470
	disconnect(gazeEstimationWidget, SIGNAL(outDataTuple(DataTuple)),
		fieldWidget, SLOT(preview(DataTuple)) );
	// TODO: freeze eye cameras
Thiago Santini's avatar
Thiago Santini committed
471 472
}

473
void MainWindow::unfreezeCameraImages()
Thiago Santini's avatar
Thiago Santini committed
474
{
475 476 477
	connect(gazeEstimationWidget, SIGNAL(outDataTuple(DataTuple)),
		fieldWidget, SLOT(preview(DataTuple)) );
	// TODO: unfreeze eye cameras
Thiago Santini's avatar
Thiago Santini committed
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
}

void MainWindow::menuOption(QAction* action)
{
    if (action->text().toLower() == "references")
        showReferencesDialog();
    if (action->text().toLower() == "about")
        showAboutDialog();
}

void MainWindow::showReferencesDialog()
{
    ReferenceList::add( "Santini et al.",
        "EyeRecToo: Open-source Software for Real-time Pervasive Head-mounted Eye Tracking",
        "VISAPP", "2017a",
        "http://www.scitepress.org/DigitalLibrary/PublicationsDetail.aspx?ID=gLeoir7PxnI=&t=1"
    );
    ReferenceList::add( "Santini et al.",
        "CalibMe: Fast and Unsupervised Eye Tracker Calibration for Gaze-Based Pervasive Human-Computer Interaction",
        "CHI", "2017b",
Thiago Santini's avatar
Thiago Santini committed
498
        "http://dl.acm.org/citation.cfm?id=3025453.3025950"
Thiago Santini's avatar
Thiago Santini committed
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
    );
    ReferenceList::add( "Fuhl et al.",
        "ElSe: Ellipse Selection for Robust Pupil Detection in Real-World Environments",
        "ETRA", "2016",
        "http://dl.acm.org/citation.cfm?id=2857505"
    );
    ReferenceList::add( "Fuhl et al.",
        "ExCuSe: Robust Pupil Detection in Real-World Scenarios",
        "LNCS", "2015",
        "https://link.springer.com/chapter/10.1007/978-3-319-23192-1_4"
    );
#ifdef STARBURST
    ReferenceList::add( "Li et al.",
        "Starburst: A Hybrid Algorithm for Video-based Eye Tracking Combining Feature-based and Model-based Approaches",
        "CVPR", "2005",
        "http://ieeexplore.ieee.org/abstract/document/1565386/"
    );
#endif
#ifdef SWIRSKI
    ReferenceList::add( "Swirski et al.",
        "Robust real-time pupil tracking in highly off-axis images",
        "ETRA", "2012",
        "http://dl.acm.org/citation.cfm?id=2168585"
    );
#endif
    ReferenceList::add( "Garrido-Jurado et al.",
        "Automatic generation and detection of highly reliable fiducial markers under occlusion",
        "Pattern Recognition", "2014",
        "http://dl.acm.org/citation.cfm?id=2589359"
    );
    ReferenceList::add( "Bradski et al.",
        "OpenCV",
        "Dr. Dobb’s Journal of Software Tools", "2000",
        "http://www.drdobbs.com/open-source/the-opencv-library/184404319"
    );
    ReferenceList::add( "Qt Project",
        "Qt Framework",
        "Online", "2017",
        "http://www.qt.io"
    );

    QString msg("EyeRecToo utilizes methods developed by multiple people. ");
    msg.append("This section provides a list of these methods so you can easily cite the ones you use :-)<br><br><br>");
    QMessageBox::information(this, "References", msg.append(ReferenceList::text()), QMessageBox::NoButton);
}

void MainWindow::showAboutDialog()
{
    QString msg = QString("EyeRecToo v%1<br><br>").arg(GIT_VERSION);
    msg.append("Contact: <a href=\"mailto:thiago.santini@uni-tuebingen.de?Subject=[EyeRecToo] Contact\" target=\"_top\">thiago.santini@uni-tuebingen.de</a><br><br>");
    msg.append("Copyright &copy; 2017 University of Tübingen");
    QMessageBox::about(this, "About", msg);
}
552

553
void MainWindow::setupWidget(ERWidget *widget, QPoint &position, const QSize &size, const bool &visible, QPushButton *button)
554 555 556 557 558 559 560 561 562
{
    // Sanitize position first
    bool inScreen = false;
    for (int i = 0; i < QApplication::desktop()->screenCount(); i++)
        inScreen |= QApplication::desktop()->screenGeometry(i).contains(position, true);

    if (!inScreen)
        position = QApplication::desktop()->screenGeometry().topLeft();

563 564
	widget->move(position);
	widget->resize(size);
565 566

    if (visible)
567
		widget->show();
568

569
	if (button) {
570
		button->setChecked(visible);
571 572 573
		connect(widget, SIGNAL(closed(bool)),
				button, SLOT(setChecked(bool)) );
	}
574 575 576 577 578

	connect(widget, SIGNAL(keyPress(QKeyEvent*)),
			&commandManager, SLOT(keyPress(QKeyEvent*)) );
	connect(widget, SIGNAL(keyRelease(QKeyEvent*)),
			&commandManager, SLOT(keyRelease(QKeyEvent*)) );
579

580
}
581 582 583 584 585 586 587 588 589

void MainWindow::toggleRecording()
{
	if ( ! ui->recordingToggle->isChecked()) {
		if (ui->subject->text().isEmpty()) // Unset remote recording
			setSubjectName("remote");
	}
	ui->recordingToggle->click();
}