From: Thomas Pietrzak Date: Wed, 15 Feb 2012 13:39:26 +0000 (+0000) Subject: First import Dwell buttons X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=5f8ad4cb8199cb5f2ba921f828c32c734173eacd;p=dwell.git First import Dwell buttons git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@45 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- 5f8ad4cb8199cb5f2ba921f828c32c734173eacd diff --git a/DwellCursor.sln b/DwellCursor.sln new file mode 100644 index 0000000..fb993bc Binary files /dev/null and b/DwellCursor.sln differ diff --git a/DwellCursor.suo b/DwellCursor.suo new file mode 100644 index 0000000..9d0b21d Binary files /dev/null and b/DwellCursor.suo differ diff --git a/DwellCursor/DwellButton.cpp b/DwellCursor/DwellButton.cpp new file mode 100644 index 0000000..4e7c073 --- /dev/null +++ b/DwellCursor/DwellButton.cpp @@ -0,0 +1,60 @@ +#include "DwellButton.h" + +#include + +QColor DwellButton::_bgcolor = Qt::gray; +QColor DwellButton::_hovercolor = Qt::lightGray; +QColor DwellButton::_validatedcolor = Qt::red; +QColor DwellButton::_targetcolor = Qt::green; +QColor DwellButton::_targethovercolor = Qt::yellow; + +DwellButton::DwellButton(QGraphicsItem *parent) +:QGraphicsRectItem(parent), _active(false) +{ + setBrush(QBrush(_bgcolor)); + setZValue(0); +} + +DwellButton::DwellButton(float posx, float posy, float width, float height, QGraphicsItem *parent) +:QGraphicsRectItem(posx, posy, width, height, parent), _active(false) +{ + setBrush(QBrush(_bgcolor)); + setZValue(0); +} + +DwellButton::DwellButton(QRect pos, QGraphicsItem *parent) +:QGraphicsRectItem(pos, parent), _active(false) +{ + setBrush(QBrush(_bgcolor)); + setZValue(0); +} + +void DwellButton::setActive() +{ + _active = true; + setBrush(QBrush(_targetcolor)); +} + +void DwellButton::hover() +{ + if (_active) + setBrush(QBrush(_targethovercolor)); + else + setBrush(QBrush(_hovercolor)); +} + +void DwellButton::press() +{ + setBrush(QBrush(_validatedcolor)); + emit clicked(); + _active = false; + //disconnect(this); +} + +void DwellButton::leave() +{ + if (_active) + setBrush(QBrush(_targetcolor)); + else + setBrush(QBrush(_bgcolor)); +} diff --git a/DwellCursor/DwellButton.h b/DwellCursor/DwellButton.h new file mode 100644 index 0000000..3af2928 --- /dev/null +++ b/DwellCursor/DwellButton.h @@ -0,0 +1,33 @@ +#ifndef __DWELLBUTTON__ +#define __DWELLBUTTON__ + +#include +#include + +class DwellButton: public QObject, public QGraphicsRectItem +{ + Q_OBJECT + + public: + DwellButton(QGraphicsItem *parent = 0); + DwellButton(float posx, float posy, float width, float height, QGraphicsItem *parent = 0); + DwellButton(QRect pos, QGraphicsItem *parent = 0); + + void setActive(); + + private: + static QColor _bgcolor, _hovercolor, _validatedcolor, _targetcolor, _targethovercolor; + bool _active; + + public slots: + void hover(); + void press(); + void leave(); + + private slots: + + signals: + void clicked(); +}; + +#endif diff --git a/DwellCursor/DwellCursor.vcxproj b/DwellCursor/DwellCursor.vcxproj new file mode 100644 index 0000000..b4d3a4d --- /dev/null +++ b/DwellCursor/DwellCursor.vcxproj @@ -0,0 +1,260 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {2928B2FC-98F8-427E-B0D2-2CEA2DA1FFC9} + Qt4VSv1.0 + + + + Application + + + Application + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + AllRules.ruleset + + + AllRules.ruleset + + + $(SolutionDir)$(ConfigurationName) + $(SolutionDir)$(ConfigurationName) + + + + UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_CORE_LIB;QT_GUI_LIB;%(PreprocessorDefinitions) + $(KINECTSDK10_DIR)\inc;.\GeneratedFiles;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\qtmain;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;.\;%(AdditionalIncludeDirectories) + Disabled + ProgramDatabase + MultiThreadedDebugDLL + false + + + Windows + $(OutDir)\$(ProjectName).exe + $(KINECTSDK10_DIR)\lib\x86;$(QTDIR)\lib;%(AdditionalLibraryDirectories) + true + tactonplayer.lib;Kinect10.lib;qtmaind.lib;QtCored4.lib;QtGuid4.lib;%(AdditionalDependencies) + + + + + UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;%(PreprocessorDefinitions) + $(KINECTSDK10_DIR)\inc;.\GeneratedFiles;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\qtmain;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;.\;%(AdditionalIncludeDirectories) + + + MultiThreadedDLL + false + + + Windows + $(OutDir)\$(ProjectName).exe + $(KINECTSDK10_DIR)\lib\x86;$(QTDIR)\lib;%(AdditionalLibraryDirectories) + false + tactonplayer.lib;Kinect10.lib;qtmain.lib;QtCore4.lib;QtGui4.lib;%(AdditionalDependencies) + + + + + + + + + true + + + true + + + true + + + true + + + true + + + true + + + true + + + + + + + + + true + + + true + + + true + + + true + + + true + + + true + + + true + + + + + + + + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "dwellcursor.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "dwellcursor.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(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)" + + + + + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "ExperimentSetup.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "ExperimentSetup.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "MainView.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "MainView.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "DwellWidget.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "DwellWidget.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "DwellButton.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "DwellButton.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + + + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "KinectInput.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "KinectInput.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "MainScene.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I$(KINECTSDK10_DIR)\inc" "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I." "-I." "-I." "MainScene.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + + + + + Document + %(FullPath);%(AdditionalInputs) + Rcc%27ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp;%(Outputs) + "$(QTDIR)\bin\rcc.exe" -name "%(Filename)" -no-compress "%(FullPath)" -o .\GeneratedFiles\qrc_%(Filename).cpp + %(FullPath);%(AdditionalInputs) + Rcc%27ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp;%(Outputs) + "$(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)" + + + + + + + + + + + \ No newline at end of file diff --git a/DwellCursor/DwellCursor.vcxproj.filters b/DwellCursor/DwellCursor.vcxproj.filters new file mode 100644 index 0000000..b59ed00 --- /dev/null +++ b/DwellCursor/DwellCursor.vcxproj.filters @@ -0,0 +1,148 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;cxx;c;def + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h + + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + + + {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} + qrc;* + false + + + {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} + moc;h;cpp + False + + + {8395e438-d93a-41cb-9c3a-631bdb7f2df0} + cpp;moc + False + + + {d92c74f0-c1ab-4435-b7b0-32ae41c89011} + cpp;moc + False + + + + + Source Files + + + Source Files + + + Generated Files\Debug + + + Generated Files\Release + + + Generated Files + + + Source Files + + + Source Files + + + Generated Files\Debug + + + Generated Files\Release + + + Source Files + + + Generated Files\Debug + + + Generated Files\Release + + + Generated Files\Debug + + + Generated Files\Release + + + Source Files + + + Generated Files\Debug + + + Generated Files\Release + + + Source Files + + + Generated Files\Debug + + + Generated Files\Release + + + Generated Files\Debug + + + Generated Files\Release + + + Source Files + + + + + Header Files + + + Form Files + + + Resource Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Form Files + + + + + Generated Files + + + Generated Files + + + \ No newline at end of file diff --git a/DwellCursor/DwellWidget.cpp b/DwellCursor/DwellWidget.cpp new file mode 100644 index 0000000..7ca041c --- /dev/null +++ b/DwellCursor/DwellWidget.cpp @@ -0,0 +1,181 @@ +#include "DwellWidget.h" + +#include +#include + +#include + +float DwellWidget::_widgetsize = 0.1; +int DwellWidget::_activationduration = 300; +int DwellWidget::_dwellduration = 1500; +int DwellWidget::_validationduration = 200; +int DwellWidget::_hoverduration = 50; + +QColor DwellWidget::_colornormal = Qt::transparent; +QColor DwellWidget::_coloractivated = Qt::darkCyan; + +DwellWidget::DwellWidget(QGraphicsItem * parent) +:_tactonplayer(NULL), + _activationtimeline(_activationduration), + _validationtimeline(_validationduration), + _progressiontimeline(_dwellduration), + _center(0, 0, _widgetsize / 2, _widgetsize / 2, this), + _background(0.0, 0.0, _widgetsize / 2, _widgetsize / 2, this), + _progress(0.0, 0.0, _widgetsize, _widgetsize, this), + _activation(), _validation() +{ +/* + _activationtimeline.setFrameRange(0, 100); + _activation.setItem(&_center); + _activation.setTimeLine(&_activationtimeline); + _activation.setScaleAt(0, 1, 1); + _activation.setPosAt(0 , QPointF(-_widgetsize / 2, -_widgetsize / 2)); + _activation.setScaleAt(1 , 0.5, 0.5); + _activation.setPosAt(1 , QPointF(-_widgetsize / 4, -_widgetsize / 4)); + connect(&_activationtimeline, SIGNAL(finished()), this, SLOT(startdwell())); + */ + _activationtimeline.setFrameRange(0, 100); + _activation.setItem(&_background); + _activation.setTimeLine(&_activationtimeline); + _activation.setScaleAt(0, 1, 1); + _activation.setPosAt(0 , QPointF(-_widgetsize / 4, -_widgetsize / 4)); + _activation.setScaleAt(1 , 2, 2); + _activation.setPosAt(1 , QPointF(-_widgetsize / 2, -_widgetsize / 2)); + connect(&_activationtimeline, SIGNAL(finished()), this, SLOT(startdwell())); + +// _progressiontimeline.setUpdateInterval(_dwellduration / 5760); + _progressiontimeline.setFrameRange(0, 5760); + _progress.setBrush(QBrush(_coloractivated)); + _progress.setStartAngle(90 * 16); + _progress.setSpanAngle(0); + _progress.setPen(QPen(Qt::transparent)); + connect(&_progressiontimeline, SIGNAL(frameChanged(int)), this, SLOT(progress(int))); + connect(&_progressiontimeline, SIGNAL(finished()), this, SLOT(startvalidation())); +/* + _validationtimeline.setFrameRange(0, 300); + _validation.setItem(&_center); + _validation.setTimeLine(&_validationtimeline); + _validation.setScaleAt(0, 0.5, 0.5); + _validation.setPosAt(0 , QPointF(-_widgetsize / 4, -_widgetsize / 4)); + _validation.setScaleAt(0.5 , 1.5, 1.5); + _validation.setPosAt(0.5 , QPointF(-_widgetsize * 3 / 4, -_widgetsize * 3 / 4)); + _validation.setScaleAt(1 , 1, 1); + _validation.setPosAt(1 , QPointF(-_widgetsize / 2, -_widgetsize / 2)); + connect(&_validationtimeline, SIGNAL(finished()), this, SLOT(validation())); +*/ + _validationtimeline.setFrameRange(0, 300); + _validation.setItem(&_center); + _validation.setTimeLine(&_validationtimeline); + _validation.setScaleAt(0, 2, 2); + _validation.setPosAt(0 , QPointF(-_widgetsize / 2, -_widgetsize / 2)); + _validation.setScaleAt(0.5 , 2.5, 2.5); + _validation.setPosAt(0.5 , QPointF(-_widgetsize * 5 / 8, -_widgetsize * 5 / 8)); + _validation.setScaleAt(1 , 1, 1); + _validation.setPosAt(1 , QPointF(-_widgetsize / 4, -_widgetsize / 4)); + connect(&_validationtimeline, SIGNAL(finished()), this, SLOT(validation())); + + _center.setZValue(10); + _center.setPos(QPointF(-_widgetsize / 4, -_widgetsize / 4)); + _progress.setPos(QPointF(-_widgetsize / 2, -_widgetsize / 2)); + _progress.setZValue(1); + _background.setZValue(5); + _background.setPos(QPointF(-_widgetsize / 4, -_widgetsize / 4)); + _background.setBrush(QBrush(Qt::transparent)); +} + +DwellWidget::~DwellWidget() +{ + if (_tactonplayer) + _tactonplayer->stop(); +} + +void DwellWidget::init() +{ +// _tactonplayer = new TactonPlayer("COM4"); + //hover tacton + if (_tactonplayer) + { + _tactonplayer->regist(Tacton(0x0f, _hoverduration / 2, 100, 255)); + //activation tacton + _tactonplayer->regist(Tacton(0x0f, _activationduration / 2, 250, 255)); + //progression tacton + unsigned char animpatterns[8] = {POS2_UP, 0x00, POS2_RIGHT, 0x00, POS2_DOWN, 0x00, POS2_LEFT, 0x00}; + unsigned int animdurations[8] = {_dwellduration / 8, _dwellduration / 8, _dwellduration / 8, _dwellduration / 8, + _dwellduration / 8, _dwellduration / 8, _dwellduration / 8, _dwellduration / 8}; + unsigned int animfrequencies[8] = {250, 250, 250, 250, 250, 250, 250, 250}; + unsigned char animamplitudes[8] = {255, 255, 255, 255, 255, 255, 255, 255}; + _tactonplayer->regist(Tacton(8, animpatterns,animdurations, animfrequencies, animamplitudes)); + //validation tacton + _tactonplayer->regist(Tacton(0x0f, _validationduration / 2, 250, 255)); + } + _lasthover.restart(); +} + +void DwellWidget::hover() +{ + if (_lasthover.elapsed() > _hoverduration) + { + if (_tactonplayer) + _tactonplayer->play(0); + _lasthover.restart(); + } +} + +void DwellWidget::start() +{ +// _currentstate = ACTIVATED; + //_activationpos = + _center.setBrush(QBrush(_coloractivated)); + if (_tactonplayer) + _tactonplayer->play(1); + _activationtimeline.start(); +} + +void DwellWidget::startdwell() +{ + if (_tactonplayer) + _tactonplayer->play(2); + _progressiontimeline.start(); +} + +void DwellWidget::progress(int v) +{ + _progress.setSpanAngle(-v); +} + +void DwellWidget::startvalidation() +{ + if (_tactonplayer) + _tactonplayer->play(3); + _activationtimeline.setCurrentTime(0); + _progressiontimeline.setCurrentTime(0); + _validationtimeline.start(); +} + +void DwellWidget::validation() +{ + emit validated(); + reset(); +} + + +void DwellWidget::interrupt() +{ + _activationtimeline.stop(); + _progressiontimeline.stop(); + _validationtimeline.stop(); + reset(); +} + +void DwellWidget::reset() +{ + disconnect(this, 0, 0, 0); +// _validationtimeline.setCurrentTime(0); + _progressiontimeline.setCurrentTime(0); + _activationtimeline.setCurrentTime(0); + _center.setScale(1); + _background.setScale(1); + _center.setBrush(QBrush(_colornormal)); + _progress.setSpanAngle(0); + this->update(); +} \ No newline at end of file diff --git a/DwellCursor/DwellWidget.h b/DwellCursor/DwellWidget.h new file mode 100644 index 0000000..07bb1a4 --- /dev/null +++ b/DwellCursor/DwellWidget.h @@ -0,0 +1,59 @@ +#ifndef __DWELLWIDGET__ +#define __DWELLWIDGET__ + +#include +#include +#include +#include +#include +#include +#include + +#include + +class DwellWidget: public QObject, public QGraphicsItemGroup +{ + Q_OBJECT + + public: + DwellWidget(QGraphicsItem * parent = 0); + ~DwellWidget(); + + void init(); + + void hover(); + void start(); + void interrupt(); + void reset(); + + private: + TactonPlayer *_tactonplayer; + + QTimeLine _activationtimeline, _validationtimeline, _progressiontimeline; + QGraphicsEllipseItem _center, _background, _progress; + QGraphicsItemAnimation _activation, _validation; + QPointF _activationpos; + + QTime _lasthover; + + static float _widgetsize; + + static int _activationduration; + static int _dwellduration; + static int _validationduration; + static int _hoverduration; + + static QColor _colornormal; + static QColor _coloractivated; + + signals: + void validated(); + + private slots: + void startdwell(); + void startvalidation(); + void validation(); + void progress(int v); +}; + +#endif \ No newline at end of file diff --git a/DwellCursor/ExperimentSetup.cpp b/DwellCursor/ExperimentSetup.cpp new file mode 100644 index 0000000..1959a9e --- /dev/null +++ b/DwellCursor/ExperimentSetup.cpp @@ -0,0 +1,26 @@ +#include "ExperimentSetup.h" + +ExperimentSetup::ExperimentSetup(QWidget *parent, Qt::WFlags flags) + : QMainWindow(parent, flags) +{ + setupUi(this); + + this->layout()->setSizeConstraint(QLayout::SetFixedSize); + + QObject::connect(buttonstart, SIGNAL(clicked()), this, SLOT(runBlock())); +} + +ExperimentSetup::~ExperimentSetup() +{ + +} + +void ExperimentSetup::runBlock(void) +{ + this->hide(); + w.init(username->text(), condition->currentText(), repetitions->value(), + nbx->value(), nby->value(), + buttonssizex->value(), buttonssizey->value(), + spacex->value(), spacey->value()); + w.show(); +} diff --git a/DwellCursor/ExperimentSetup.h b/DwellCursor/ExperimentSetup.h new file mode 100644 index 0000000..522d756 --- /dev/null +++ b/DwellCursor/ExperimentSetup.h @@ -0,0 +1,23 @@ +#ifndef EXPERIMENTSETUP_H +#define EXPERIMENTSETUP_H + +#include +#include "ui_experimentsetup.h" + +#include "dwellcursor.h" +class ExperimentSetup : public QMainWindow, Ui::ExperimentSetupClass +{ + Q_OBJECT + +public: + ExperimentSetup(QWidget *parent = 0, Qt::WFlags flags = 0); + ~ExperimentSetup(); + +private: + DwellCursor w; + +private slots: + void runBlock(); +}; + +#endif diff --git a/DwellCursor/ExperimentSetup.ui b/DwellCursor/ExperimentSetup.ui new file mode 100644 index 0000000..fcec084 --- /dev/null +++ b/DwellCursor/ExperimentSetup.ui @@ -0,0 +1,235 @@ + + + ExperimentSetupClass + + + Qt::NonModal + + + + 0 + 0 + 324 + 277 + + + + Dwell Widgets + + + + + + + + + + + + User: + + + + + + + + + + Repetitions: + + + + + + + 1 + + + 100 + + + 1 + + + + + + + Space x: + + + + + + + Condition: + + + + + + + Nb x: + + + + + + + Nb y: + + + + + + + BtSize x: + + + + + + + BtSize y: + + + + + + + Space y: + + + + + + + 1 + + + 10 + + + 4 + + + + + + + 1 + + + 10 + + + 4 + + + + + + + + Visual only + + + + + Tactile + visual + + + + + + + + 1 + + + 0.100000000000000 + + + 1.600000000000000 + + + 0.100000000000000 + + + 0.200000000000000 + + + + + + + 1 + + + 0.100000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 0.100000000000000 + + + + + + + 1 + + + 10.000000000000000 + + + 0.100000000000000 + + + 1.600000000000000 + + + + + + + 1 + + + 10.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + + + + + + Start experiment + + + + + + + + + + + + diff --git a/DwellCursor/KinectInput.cpp b/DwellCursor/KinectInput.cpp new file mode 100644 index 0000000..dca9d65 --- /dev/null +++ b/DwellCursor/KinectInput.cpp @@ -0,0 +1,99 @@ +#include "KinectInput.h" + +#include + +#define TIMEOUT 100 + +KinectInput::KinectInput() +:_running(false), _skeletonid(-1) +{ + //creates the kinect sensor (id 0) + if(FAILED(NuiCreateSensorByIndex(0, &_kinect))) + { + qDebug() << "Cannot find a KINECT sensor" << endl; + //I should do something else, sucha as an exception + return; + } + + if (_kinect->NuiInitialize(NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX | NUI_INITIALIZE_FLAG_USES_SKELETON) == E_NUI_SKELETAL_ENGINE_BUSY) + { + qDebug() << "Cannot initialize the KINECT sensor" << endl; + return; + } + + //initialize the skeleton tracking + _skeletonEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if(!HasSkeletalEngine(_kinect) || FAILED(_kinect->NuiSkeletonTrackingEnable(_skeletonEvent, 0))) + { + qDebug() << "Cannot Initialize skeleton tracking" << endl; + return; + } +} + +KinectInput::~KinectInput() +{ + NuiShutdown(); + if( _skeletonEvent && ( _skeletonEvent != INVALID_HANDLE_VALUE ) ) + CloseHandle( _skeletonEvent ); +} + +//thread that manages the kinect events +void KinectInput::run() +{ + _running = true; + while(_running) + { + //wait for an event + if (WaitForSingleObject(_skeletonEvent, TIMEOUT) != 0) + continue; + + //get skeleton values + NUI_SKELETON_FRAME SkeletonFrame; + HRESULT hr = _kinect->NuiSkeletonGetNextFrame( 0, &SkeletonFrame ); +// qDebug() << "Kinect frame " << SkeletonFrame.dwFrameNumber; + + //if no skeleton already identified or not tracked anymore, search for one + if (_skeletonid < 0 || SkeletonFrame.SkeletonData[_skeletonid].eTrackingState != NUI_SKELETON_TRACKED) + { + for( int i = 0 ; i < NUI_SKELETON_COUNT ; i++ ) + { + if(SkeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED) + { + _skeletonid = i; + break; + } + } + } + + //no skeleton found + if (_skeletonid < 0) + continue; + + //retrieve information on the skeleton + NUI_SKELETON_DATA &data = SkeletonFrame.SkeletonData[_skeletonid]; + + //checking if we have a skeleton +/* if (data.eTrackingState != NUI_SKELETON_TRACKED) + continue;*/ + + //smooth out the skeleton data + _kinect->NuiTransformSmooth(&SkeletonFrame, NULL); + + + if (data.eSkeletonPositionTrackingState[NUI_SKELETON_POSITION_HAND_RIGHT] == NUI_SKELETON_NOT_TRACKED) + continue; //right hand not detected + else + { +/* float posx, posy; + NuiTransformSkeletonToDepthImageF(data.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT], &posx, &posy); + emit rightHandMove(posx, posy,0);*/ + Vector4 &skelpos = data.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; + emit rightHandMove(skelpos.x, skelpos.y, skelpos.z); + } + } +} + +void KinectInput::stop() +{ + _running = false; +} \ No newline at end of file diff --git a/DwellCursor/KinectInput.h b/DwellCursor/KinectInput.h new file mode 100644 index 0000000..b4bf077 --- /dev/null +++ b/DwellCursor/KinectInput.h @@ -0,0 +1,29 @@ +#ifndef __KINECTINPUT__ +#define __KINECTINPUT__ + +#include +#include +#include +#include + +class KinectInput: public QThread +{ + Q_OBJECT + public: + KinectInput(); + ~KinectInput(); + + void run(); + void stop(); + + private: + INuiSensor* _kinect; + HANDLE _skeletonEvent; + bool _running; + int _skeletonid; + + signals: + void rightHandMove(float x, float y, float z); +}; + +#endif diff --git a/DwellCursor/MainScene.cpp b/DwellCursor/MainScene.cpp new file mode 100644 index 0000000..3bfdc32 Binary files /dev/null and b/DwellCursor/MainScene.cpp differ diff --git a/DwellCursor/MainScene.h b/DwellCursor/MainScene.h new file mode 100644 index 0000000..41c640c --- /dev/null +++ b/DwellCursor/MainScene.h @@ -0,0 +1,58 @@ +#ifndef __MAINSCENE__ +#define __MAINSCENE__ + +#include +#include +#include +#include +#include + +#include "DwellWidget.h" +#include "KinectInput.h" +#include "DwellButton.h" + +#include + +class MainScene: public QGraphicsScene +{ + Q_OBJECT + + public: + MainScene(QObject * parent = 0); + ~MainScene(); + + void init(QString user, QString condition, int repetitions); + + void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent); + void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent); + + void setButtonArray(int x, int y, float sx, float sy, float bsx, float bsy); + + void log(const QString &event, int button, int answer); + int indexOfButton(DwellButton *b) const; + + private: + DwellWidget _dwellwidget; + KinectInput _kinectsensor; + + QTime _enteredtime; + bool _alreadypressed; + DwellButton *_lastitemover; + DwellButton **_buttons; + int _nbbuttonsx, _nbbuttonsy; + QSignalMapper _signalmapper; + + static int _dwelltime; + + //experiment stuff + FILE *_logfile; + QTime _start; + QList _trials; + int _currenttrial; + + private slots: + void displayHandPosition(float x, float y, float z); + void buttonClicked(int n); +}; + +#endif \ No newline at end of file diff --git a/DwellCursor/MainView.cpp b/DwellCursor/MainView.cpp new file mode 100644 index 0000000..2e8c15a --- /dev/null +++ b/DwellCursor/MainView.cpp @@ -0,0 +1,18 @@ +#include "MainView.h" + +MainView::MainView(float sx, float sy, MainScene * scene, QWidget *parent) +:QGraphicsView(scene, parent), _width(sx), _height(sy) +{ + setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); + setMouseTracking(true); + setSceneRect(-sx / 2.0, -sy / 2.0, sx, sy); +} + +MainView::~MainView() +{ +} + +void MainView::resizeEvent(QResizeEvent * event) +{ + fitInView(-_width / 2.0, -_height / 2.0, _width, _height, Qt::KeepAspectRatio); +} diff --git a/DwellCursor/MainView.h b/DwellCursor/MainView.h new file mode 100644 index 0000000..0c6aaaa --- /dev/null +++ b/DwellCursor/MainView.h @@ -0,0 +1,22 @@ +#ifndef __MAINVIEW__ +#define __MAINVIEW__ + +#include + +#include "MainScene.h" + +class MainView: public QGraphicsView +{ + Q_OBJECT + + public: + MainView(float sx, float sy, MainScene * scene, QWidget * parent=0); + ~MainView(); + + private: + void resizeEvent(QResizeEvent * event); + + float _width, _height; +}; + +#endif diff --git a/DwellCursor/dwellcursor.cpp b/DwellCursor/dwellcursor.cpp new file mode 100644 index 0000000..2be2b47 --- /dev/null +++ b/DwellCursor/dwellcursor.cpp @@ -0,0 +1,38 @@ +#include "dwellcursor.h" + +#include + +DwellCursor::DwellCursor(QWidget *parent, Qt::WFlags flags) + : QMainWindow(parent, flags), _sound(new QSound("whitenoise05.wav")) +{ + setupUi(this); + if (_sound) + _sound->setLoops(-1); +} + +DwellCursor::~DwellCursor() +{ +} + +void DwellCursor::init(QString user, QString condition, int repetitions, int nbx, int nby, float bsx, float bsy,float spacex, float spacey) +{ + _user = user; + _condition = condition; + _repetitions = repetitions; + _nbx = nbx; + _nby = nby; + _bsx = bsx; + _bsy = bsy; + _spacex = spacex; + _spacey = spacey; + + if (_sound) + _sound->play(); + + _scene = new MainScene(); + _scene->setButtonArray(nbx, nby, spacex, spacey, bsx, bsy); + _scene->init(user, condition, repetitions); + + _view = new MainView(spacex, spacey, _scene); + setCentralWidget(_view); +} diff --git a/DwellCursor/dwellcursor.h b/DwellCursor/dwellcursor.h new file mode 100644 index 0000000..5fe27fd --- /dev/null +++ b/DwellCursor/dwellcursor.h @@ -0,0 +1,36 @@ +#ifndef DWELLCURSOR_H +#define DWELLCURSOR_H + +#include +#include "ui_dwellcursor.h" +#include +#include "DwellWidget.h" +#include "MainScene.h" +#include "MainView.h" + +class DwellCursor : public QMainWindow, Ui::DwellCursorClass +{ + Q_OBJECT + +public: + DwellCursor(QWidget *parent = 0, Qt::WFlags flags = 0); + ~DwellCursor(); + + void init(QString user, QString condition, int repetitions, int nbx, int nby, float bsx, float bsy, float spacex, float spacey); + void log(QString answer); + +private: + DwellWidget _dwellwidget; + MainScene *_scene; + QGraphicsView *_view; + QSound *_sound; + + QString _user, _condition; + int _repetitions; + int _nbx, _nby; + float _bsx, _bsy; + float _spacex, _spacey; + +}; + +#endif // DWELLCURSOR_H diff --git a/DwellCursor/dwellcursor.qrc b/DwellCursor/dwellcursor.qrc new file mode 100644 index 0000000..2d55f9f --- /dev/null +++ b/DwellCursor/dwellcursor.qrc @@ -0,0 +1,4 @@ + + + + diff --git a/DwellCursor/dwellcursor.ui b/DwellCursor/dwellcursor.ui new file mode 100644 index 0000000..85d861c --- /dev/null +++ b/DwellCursor/dwellcursor.ui @@ -0,0 +1,23 @@ + + + DwellCursorClass + + + + 0 + 0 + 600 + 400 + + + + DwellCursor + + + + + + + + + diff --git a/DwellCursor/main.cpp b/DwellCursor/main.cpp new file mode 100644 index 0000000..5eaf6de --- /dev/null +++ b/DwellCursor/main.cpp @@ -0,0 +1,10 @@ +#include "ExperimentSetup.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ExperimentSetup w; + w.show(); + return a.exec(); +} \ No newline at end of file