From 025808816e02188c4212184667f7348cfa20167b Mon Sep 17 00:00:00 2001 From: Thomas Pietrzak Date: Tue, 26 Mar 2013 15:05:29 +0000 Subject: [PATCH] =?utf8?q?Expe=20cod=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@109 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- TactileMenus/SetupMenu.cpp | 28 ++++++ TactileMenus/SetupMenu.h | 24 +++++ TactileMenus/SetupMenu.ui | 12 +-- TactileMenus/TMenu.cpp | 38 +++++--- TactileMenus/TMenu.h | 10 +++ TactileMenus/TactileMenus.cpp | 143 +++++++++++++++++++++++++++--- TactileMenus/TactileMenus.h | 27 +++++- TactileMenus/TactileMenus.vcxproj | 48 +++++++++- TactileMenus/main.cpp | 4 +- TactileMenus/tactilemenus.ui | 7 ++ 10 files changed, 306 insertions(+), 35 deletions(-) create mode 100644 TactileMenus/SetupMenu.cpp create mode 100644 TactileMenus/SetupMenu.h diff --git a/TactileMenus/SetupMenu.cpp b/TactileMenus/SetupMenu.cpp new file mode 100644 index 0000000..99f7d41 --- /dev/null +++ b/TactileMenus/SetupMenu.cpp @@ -0,0 +1,28 @@ +#include "SetupMenu.h" + + +SetupMenu::SetupMenu(QWidget *parent, Qt::WFlags flags) +: QMainWindow(parent, flags) +{ + setupUi(this); + + connect(_start, SIGNAL(clicked()), this, SLOT(init())); +} + + +SetupMenu::~SetupMenu(void) +{ +} + +void SetupMenu::init() +{ + _tactileMenus = new TactileMenus(); + _tactileMenus->init(_user->text(), _condition->currentText(), + _nbItems->value(), _repetitions->value(), + _widths->value(), _marginStep->value(), + _hoverFeedback->checkState() == Qt::Checked, + _leaveFeedback->checkState() == Qt::Checked, + _triggerFeedback->checkState() == Qt::Checked); + _tactileMenus->show(); + this->hide(); +} \ No newline at end of file diff --git a/TactileMenus/SetupMenu.h b/TactileMenus/SetupMenu.h new file mode 100644 index 0000000..3987319 --- /dev/null +++ b/TactileMenus/SetupMenu.h @@ -0,0 +1,24 @@ +#ifndef __SETUPMENU__ +#define __SETUPMENU__ + +#include +#include "ui_SetupMenu.h" + +#include "TactileMenus.h" + +class SetupMenu: public QMainWindow, public Ui::SetupMenu +{ + Q_OBJECT + + public: + SetupMenu(QWidget *parent = NULL, Qt::WFlags flags = NULL); + ~SetupMenu(); + + public slots: + void init(); + + private: + TactileMenus *_tactileMenus; +}; + +#endif diff --git a/TactileMenus/SetupMenu.ui b/TactileMenus/SetupMenu.ui index c252aaf..c49073b 100644 --- a/TactileMenus/SetupMenu.ui +++ b/TactileMenus/SetupMenu.ui @@ -1,13 +1,13 @@ - MainWindow - + SetupMenu + 0 0 252 - 256 + 260 @@ -89,7 +89,7 @@ 100 - 10 + 2 @@ -123,7 +123,7 @@ 1 - 10 + 20 @@ -178,7 +178,7 @@ - + 12 diff --git a/TactileMenus/TMenu.cpp b/TactileMenus/TMenu.cpp index c12c962..1d234c7 100644 --- a/TactileMenus/TMenu.cpp +++ b/TactileMenus/TMenu.cpp @@ -4,18 +4,7 @@ TMenu::TMenu(TactonPlayer *tactonPlayer, QWidget *parent) :QMenu(parent), _tactonPlayer(tactonPlayer) { - this->setStyleSheet(" QMenu {\ - background-color: #bbbbbb;\ - border: 1px solid black;\ - font-size: 30pt;\ - }\ - QMenu::item {\ - background-color: transparent;\ - padding: 10px 50px 10px 50px;\ - }\ - QMenu::item:selected {\ - background-color: #eeeeee;\ - }"); + setWidth(0); } @@ -28,5 +17,28 @@ void TMenu::mouseReleaseEvent(QMouseEvent * event) QAction *a; if ((a = activeAction()) != NULL) a->trigger(); + else + emit cancelled(); close(); -} \ No newline at end of file +} + +void TMenu::leaveEvent (QEvent *) +{ + emit left(); +} + +void TMenu::setWidth(int w) +{ + this->setStyleSheet(" QMenu {\ + background-color: #bbbbbb;\ + border: 1px solid black;\ + font-size: 30pt;\ + }\ + QMenu::item {\ + background-color: transparent;\ + padding: 0px " + QString::number(w) + "px 0px " + QString::number(w) + "px;\ + }\ + QMenu::item:selected {\ + background-color: #eeeeee;\ + }"); +} diff --git a/TactileMenus/TMenu.h b/TactileMenus/TMenu.h index 28d0e8c..5680a46 100644 --- a/TactileMenus/TMenu.h +++ b/TactileMenus/TMenu.h @@ -8,11 +8,21 @@ class TMenu : public QMenu { + Q_OBJECT + public: TMenu(TactonPlayer *_tactonPlayer, QWidget *parent=NULL); ~TMenu(); void mouseReleaseEvent(QMouseEvent * event); + void leaveEvent (QEvent *); + + void setWidth(int w); + + signals: + void left(); + void cancelled(); + private: TactonPlayer *_tactonPlayer; diff --git a/TactileMenus/TactileMenus.cpp b/TactileMenus/TactileMenus.cpp index 7310d17..941325d 100644 --- a/TactileMenus/TactileMenus.cpp +++ b/TactileMenus/TactileMenus.cpp @@ -2,9 +2,10 @@ #include #include +#include TactileMenus::TactileMenus(QWidget *parent, Qt::WFlags flags) - : QMainWindow(parent, flags), _menu(NULL) + : QMainWindow(parent, flags), _menu(NULL), _signalMapper(NULL), _currenttrial(0) { setupUi(this); QWidget::showMaximized(); @@ -18,42 +19,160 @@ TactileMenus::TactileMenus(QWidget *parent, Qt::WFlags flags) qDebug() << "Cannot find the touchscreen or the wristband"; _tactonPlayer = NULL; } +} + +TactileMenus::~TactileMenus() +{ + if (_tactonPlayer) + delete _tactonPlayer; + + if (_signalMapper) + delete _signalMapper; +} + +void TactileMenus::init(QString user, QString condition, + int nbItems, int repetitions, + int widths, int marginStep, + bool hoverFeedback, bool leaveFeedback, bool triggerFeedback) +{ + //store values + _user = user; + _condition = condition; + _nbItems = nbItems; + _repetitions = repetitions; + _widths = widths; + _marginStep = marginStep; + _hoverFeedback = hoverFeedback; + _leaveFeedback = leaveFeedback; + _triggerFeedback = triggerFeedback; - _menu = new TMenu(_tactonPlayer, this); + //populate menu + _menu = new TMenu(_tactonPlayer, this); _signalMapper = new QSignalMapper(this); - for (int i = 1 ; i < 8 ; i++) + for (int i = 1 ; i <= nbItems ; i++) { QAction *a = new QAction(QString::number(i), this); _menu->addAction(a); connect(a, SIGNAL(triggered()), _signalMapper, SLOT(map())); - connect(a, SIGNAL(hovered()), this, SLOT(pouet())); + + //activate hover feedback + if (hoverFeedback) + connect(a, SIGNAL(hovered()), this, SLOT(pouet())); _signalMapper->setMapping(a, i); } - connect(_signalMapper, SIGNAL(mapped(int)), this, SLOT(execute(int))); -} + //log when release out of the menu + connect(_menu, SIGNAL(cancelled()), this, SLOT(menuCancel())); + //leave feedback + if (leaveFeedback) + connect(_menu, SIGNAL(left()), this, SLOT(pouet())); -TactileMenus::~TactileMenus() + //create log file + QString date = QDate::currentDate().toString("yyyy-MM-dd") + "-" + QTime::currentTime().toString("HH-mm-ss"); + QString logfilename = user + "-" + condition + "-" + QString::number(repetitions) + "-" + QString::number(nbItems) + "-" + QString::number(widths) + "-" + QString::number(marginStep) + "-" + date + ".csv"; + _logfile = fopen(logfilename.toStdString().c_str(), "w"); + qDebug() << "log: " << logfilename; + if (_logfile) + fprintf(_logfile, "TotalTime,SelectionTime,User,Condition,Block,HFeedback,LFeedback,TFeedback,Width,Item,Selected\n"); + + + //generate the block + // /!\ currently we only manage 1 direction + for (int i = 0 ; i < repetitions ; i++) + { + QList > temp; + //generate the block + for (int j = 1 ; j <= nbItems ; j++) + for (int k = 0 ; k < widths ; k++) + temp.push_back(QPair(j, k * marginStep)); + //shuffle + for (int j = 0; j < temp.count(); j++) + temp.swap(j, (rand() % (temp.count() - j)) + j); + //add the block to the trial + _trials.append(temp); + } + _progress->setMaximum(_trials.size()); + + _timer.start(); + _timer2.start(); + + runTrial(); +} + +void TactileMenus::runTrial() { - if (_tactonPlayer) - delete _tactonPlayer; + _text->setText(QString::number(_trials.at(_currenttrial).first)); + _menu->setWidth(_trials.at(_currenttrial).second); + _timer.restart(); + //_timer2.restart(); +} + +void TactileMenus::log(int val) +{ + if (_logfile) + fprintf(_logfile, "%lld,%lld,%s,%s,%d,%d,%d,%d,%d,%d,%d\n", + _timer.elapsed(), + _timer2.elapsed(), + _user.toStdString().c_str(), + _condition.toStdString().c_str(), + _currenttrial / _repetitions, + _hoverFeedback, + _leaveFeedback, + _triggerFeedback, + _trials.at(_currenttrial).second, + _trials.at(_currenttrial).first, + val); } void TactileMenus::mousePressEvent(QMouseEvent *evt) { //pouet(); - _menu->exec(evt->globalPos()); + if (_currenttrial < _trials.size()) + { + _menu->exec(evt->globalPos()); + //timer2 is for selection time + _timer2.restart(); + } +} + +void TactileMenus::menuCancel() +{ + //log outside the menu + log(-1); +// _timer2.restart(); } void TactileMenus::execute(int val) { - if (_tactonPlayer) + log(val); + + //feedback? + if (_triggerFeedback && _tactonPlayer) _tactonPlayer->play(Tacton(0x0f, 15, 250, 255)); - _text->setText(QString::number(val)); + + //No progress if it is not the right item + if (val != _trials.at(_currenttrial).first) + return; + + _currenttrial++; + _progress->setValue(_currenttrial); + + if (_currenttrial >= _trials.size()) + { + _text->setText("Finished"); + if (_logfile) + { + fclose(_logfile); + _logfile = NULL; + } + return; + } + + runTrial(); } void TactileMenus::pouet() diff --git a/TactileMenus/TactileMenus.h b/TactileMenus/TactileMenus.h index 95935ad..61c4d38 100644 --- a/TactileMenus/TactileMenus.h +++ b/TactileMenus/TactileMenus.h @@ -5,6 +5,7 @@ #include "ui_tactilemenus.h" #include "TMenu.h" #include +#include #include @@ -17,19 +18,43 @@ class TactileMenus : public QMainWindow, public Ui::TactileMenusClass ~TactileMenus(); void mousePressEvent(QMouseEvent * event); - //void mouseReleaseEvent(QMouseEvent * event); + + void init(QString user, QString condition, + int nbItems, int repetitions, + int widths, int marginStep, + bool hoverFeedback, bool leaveFeedback, bool triggerFeedback); public slots: void execute(int); void pouet(); + void menuCancel(); signals: void selected(int); private: + void runTrial(); + void log(int val); + TMenu *_menu; QSignalMapper *_signalMapper; TactonPlayer *_tactonPlayer; + + //setup variables + QString _user; + QString _condition; + int _nbItems; + int _repetitions; + int _widths; + int _marginStep; + bool _hoverFeedback; + bool _leaveFeedback; + bool _triggerFeedback; + + FILE *_logfile; + QList > _trials; + int _currenttrial; + QElapsedTimer _timer, _timer2; }; #endif // TACTILEMENUS_H diff --git a/TactileMenus/TactileMenus.vcxproj b/TactileMenus/TactileMenus.vcxproj index 89d8b16..a3911d0 100644 --- a/TactileMenus/TactileMenus.vcxproj +++ b/TactileMenus/TactileMenus.vcxproj @@ -77,19 +77,32 @@ + + true + true + + true + + + true + true + + true + + @@ -119,8 +132,28 @@ + - + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing SetupMenu.h... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_GUI_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing SetupMenu.h... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" + + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing TMenu.h... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_GUI_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing TMenu.h... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" + @@ -135,6 +168,19 @@ "$(QTDIR)\bin\rcc.exe" -name "%(Filename)" -no-compress "%(FullPath)" -o .\GeneratedFiles\qrc_%(Filename).cpp + + + Document + $(QTDIR)\bin\uic.exe;%(AdditionalInputs) + Uic%27ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h;%(Outputs) + "$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_%(Filename).h" "%(FullPath)" + $(QTDIR)\bin\uic.exe;%(AdditionalInputs) + Uic%27ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h;%(Outputs) + "$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_%(Filename).h" "%(FullPath)" + + diff --git a/TactileMenus/main.cpp b/TactileMenus/main.cpp index b82a5f6..56fed6b 100644 --- a/TactileMenus/main.cpp +++ b/TactileMenus/main.cpp @@ -1,10 +1,10 @@ -#include "TactileMenus.h" +#include "SetupMenu.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); - TactileMenus w; + SetupMenu w; w.show(); return a.exec(); } diff --git a/TactileMenus/tactilemenus.ui b/TactileMenus/tactilemenus.ui index e20d7fd..718fed1 100644 --- a/TactileMenus/tactilemenus.ui +++ b/TactileMenus/tactilemenus.ui @@ -45,6 +45,13 @@ + + + + 0 + + + -- 2.30.2