Commit fdd49102 authored by Thiago Santini's avatar Thiago Santini

Starts Log Widget

parent 3d3367c7
......@@ -33,7 +33,8 @@ SOURCES +=\
$${TOP}/src/gaze-estimation/Homography.cpp \
$${TOP}/src/DataRecorder.cpp \
$${TOP}/src/NetworkStream.cpp \
$${TOP}/src/Reference.cpp
$${TOP}/src/Reference.cpp \
$${TOP}/src/LogWidget.cpp
HEADERS += \
$${TOP}/src/MainWindow.h\
......@@ -56,12 +57,14 @@ HEADERS += \
$${TOP}/src/gaze-estimation/Homography.h \
$${TOP}/src/DataRecorder.h \
$${TOP}/src/NetworkStream.h \
$${TOP}/src/Reference.h
$${TOP}/src/Reference.h \
$${TOP}/src/LogWidget.h
FORMS += \
$${TOP}/src/MainWindow.ui \
$${TOP}/src/CameraWidget.ui \
$${TOP}/src/GazeEstimationWidget.ui
$${TOP}/src/GazeEstimationWidget.ui \
src/LogWidget.ui
RESOURCES += \
$${TOP}/resources.qrc
......
......@@ -6,5 +6,6 @@
<file>icons/fieldWidget.png</file>
<file>icons/EyeRecToo.png</file>
<file>icons/gazeEstimationWidget.png</file>
<file>icons/logWidget.png</file>
</qresource>
</RCC>
#include "LogWidget.h"
#include "ui_LogWidget.h"
LogWidget::LogWidget(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::LogWidget)
{
ui->setupUi(this);
setWindowTitle("Log Widget");
setWindowIcon(QIcon(":/icons/logWidget.png"));
}
LogWidget::~LogWidget()
{
delete ui;
}
void LogWidget::appendMessage(const QString &msg)
{
ui->log->appendPlainText(msg.trimmed());
}
#ifndef LOGWIDGET_H
#define LOGWIDGET_H
#include <QMainWindow>
namespace Ui {
class LogWidget;
}
class LogWidget : public QMainWindow
{
Q_OBJECT
public:
explicit LogWidget(QWidget *parent = 0);
~LogWidget();
public slots:
void appendMessage(const QString &msg);
private:
Ui::LogWidget *ui;
};
#endif // LOGWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LogWidget</class>
<widget class="QMainWindow" name="LogWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>240</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPlainTextEdit" name="log">
<property name="font">
<font>
<family>Courier New</family>
</font>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>20</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
......@@ -34,6 +34,12 @@ MainWindow::MainWindow(QWidget *parent) :
ui->blinker->hide();
logWidget = new LogWidget();
logWidget->show();
logWidget->move(cfg.logWidgetPos);
logWidget->resize(cfg.logWidgetSize);
gLogWidget = logWidget;
/*
* WARNING: DO NOT REMOVE THIS CALL to QCameraInfo::availableCameras()
* Logically, its meaningless, but it guarantees that DirectShow will work
......@@ -138,6 +144,8 @@ void MainWindow::closeEvent(QCloseEvent *event)
cfg.mainWindowPos = pos();
cfg.mainWindowSize = size();
cfg.logWidgetPos = logWidget->pos();
cfg.logWidgetSize = logWidget->size();
cfg.leftEyeWidgetPos = lEyeWidget->pos();
cfg.leftEyeWidgetSize = lEyeWidget->size();
cfg.rightEyeWidgetPos = rEyeWidget->pos();
......@@ -182,6 +190,11 @@ void MainWindow::closeEvent(QCloseEvent *event)
if (networkStream)
networkStream->deleteLater();
if (logWidget) {
gLogWidget = NULL;
logWidget->deleteLater();
}
if (settings)
settings->deleteLater();
......@@ -375,6 +388,11 @@ void MainWindow::on_gazeEstimation_clicked()
widgetButtonReact(gazeEstimationWidget, ui->gazeEstimation->isChecked());
}
void MainWindow::on_log_clicked()
{
widgetButtonReact(logWidget, ui->log->isChecked());
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
if (event->isAutoRepeat())
......@@ -524,3 +542,4 @@ void MainWindow::checkForOpenH264()
qInfo() << "Video encoder:" << (gHasOpenH264 ? "OpenH264" : "DivX");
}
......@@ -21,6 +21,8 @@
#include "Reference.h"
#include "LogWidget.h"
#include "utils.h"
class MainWindowConfig
......@@ -29,6 +31,8 @@ public:
MainWindowConfig() :
mainWindowPos( QPoint(0,0) ),
mainWindowSize( QSize(100, 100)),
logWidgetPos( QPoint(0,0) ),
logWidgetSize( QSize(640, 240)),
leftEyeWidgetPos( QPoint(0,0) ),
leftEyeWidgetSize( QSize(320,240) ),
rightEyeWidgetPos( QPoint(0,0) ),
......@@ -43,6 +47,8 @@ public:
QPoint mainWindowPos;
QSize mainWindowSize;
QPoint logWidgetPos;
QSize logWidgetSize;
QPoint leftEyeWidgetPos;
QSize leftEyeWidgetSize;
QPoint rightEyeWidgetPos;
......@@ -59,6 +65,8 @@ public:
settings->sync();
settings->setValue("mainWindowPos", mainWindowPos);
settings->setValue("mainWindowSize", mainWindowSize);
settings->setValue("logWidgetPos", logWidgetPos);
settings->setValue("logWidgetSize", logWidgetSize);
settings->setValue("leftEyeWidgetPos", leftEyeWidgetPos);
settings->setValue("leftEyeWidgetSize", leftEyeWidgetSize);
settings->setValue("rightEyeWidgetPos", rightEyeWidgetPos);
......@@ -76,6 +84,8 @@ public:
settings->sync();
set(settings, "mainWindowPos", mainWindowPos);
set(settings, "mainWindowSize", mainWindowSize);
set(settings, "logWidgetPos", logWidgetPos);
set(settings, "logWidgetSize", logWidgetSize);
set(settings, "leftEyeWidgetPos", leftEyeWidgetPos);
set(settings, "leftEyeWidgetSize", leftEyeWidgetSize);
set(settings, "rightEyeWidgetPos", rightEyeWidgetPos);
......@@ -119,6 +129,7 @@ private:
QThread *journalThread;
DataRecorderThread *journal;
NetworkStream * networkStream;
LogWidget *logWidget;
QElapsedTimer elapsedTime;
int elapsedTimeUpdateTimer;
......@@ -151,6 +162,7 @@ private slots:
void menuOption(QAction*);
void showReferencesDialog();
void showAboutDialog();
void on_log_clicked();
};
#endif // MAINWINDOW_H
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>252</width>
<width>319</width>
<height>371</height>
</rect>
</property>
......@@ -393,6 +393,56 @@
<string>Widgets</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1">
<widget class="QPushButton" name="rightEyeCam">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="toolTip">
<string>Toggle Right Eye Cam Widget</string>
</property>
<property name="statusTip">
<string/>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/icons/rEyeWidget.png</normaloff>:/icons/rEyeWidget.png</iconset>
</property>
<property name="iconSize">
<size>
<width>33</width>
<height>33</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="leftEyeCam">
<property name="sizePolicy">
......@@ -452,8 +502,8 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="rightEyeCam">
<item row="0" column="2">
<widget class="QPushButton" name="fieldCam">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -473,7 +523,7 @@
</size>
</property>
<property name="toolTip">
<string>Toggle Right Eye Cam Widget</string>
<string>Toggle Field Cam Widget</string>
</property>
<property name="statusTip">
<string/>
......@@ -486,7 +536,7 @@
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/icons/rEyeWidget.png</normaloff>:/icons/rEyeWidget.png</iconset>
<normaloff>:/icons/fieldWidget.png</normaloff>:/icons/fieldWidget.png</iconset>
</property>
<property name="iconSize">
<size>
......@@ -502,8 +552,8 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="fieldCam">
<item row="0" column="3">
<widget class="QPushButton" name="gazeEstimation">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -523,7 +573,7 @@
</size>
</property>
<property name="toolTip">
<string>Toggle Field Cam Widget</string>
<string>Toggle Gaze Estimation Widget</string>
</property>
<property name="statusTip">
<string/>
......@@ -536,7 +586,7 @@
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/icons/fieldWidget.png</normaloff>:/icons/fieldWidget.png</iconset>
<normaloff>:/icons/gazeEstimationWidget.png</normaloff>:/icons/gazeEstimationWidget.png</iconset>
</property>
<property name="iconSize">
<size>
......@@ -552,8 +602,11 @@
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="gazeEstimation">
<item row="0" column="4">
<widget class="QPushButton" name="log">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -573,20 +626,14 @@
</size>
</property>
<property name="toolTip">
<string>Toggle Gaze Estimation Widget</string>
</property>
<property name="statusTip">
<string/>
</property>
<property name="whatsThis">
<string/>
<string>Toggle Log Widget</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/icons/gazeEstimationWidget.png</normaloff>:/icons/gazeEstimationWidget.png</iconset>
<normaloff>:/icons/logWidget.png</normaloff>:/icons/logWidget.png</iconset>
</property>
<property name="iconSize">
<size>
......@@ -614,7 +661,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>252</width>
<width>319</width>
<height>20</height>
</rect>
</property>
......
......@@ -20,6 +20,9 @@ QTextStream gLogStream;
std::atomic<bool> gRecording(false);
bool gHasOpenH264 = false;
LogWidget *gLogWidget = NULL;
std::vector<QString> gLogBuffer;
/*
* Utility functions
*/
......@@ -88,6 +91,16 @@ void logMessages(QtMsgType type, const QMessageLogContext &context, const QStrin
if (gLogStream.status() == QTextStream::Ok)
gLogStream << str.c_str();
if (gLogWidget) {
if (gLogBuffer.size() > 0) {
for (auto s=gLogBuffer.begin(); s!=gLogBuffer.end(); s++)
QMetaObject::invokeMethod( gLogWidget, "appendMessage", Q_ARG( const QString&, *s ) );
gLogBuffer.clear();
}
QMetaObject::invokeMethod( gLogWidget, "appendMessage", Q_ARG( const QString&, QString(str.c_str())) );
} else
gLogBuffer.push_back( QString(str.c_str()) );
std::cout.flush();
gLogStream.flush();
}
......
......@@ -24,6 +24,8 @@
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d.hpp>
#include "LogWidget.h"
/*
* Global variables
*/
......@@ -96,4 +98,7 @@ template<typename T> void set(const QSettings *settings, const QString key, T &v
void loadSoundEffect(QSoundEffect &effect, QString fileName);
extern LogWidget *gLogWidget;
extern std::vector<QString> gLogBuffer;
#endif // UTILS_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment