Index: sources/view/VEventSpy.cpp =================================================================== diff -u -r9d8a60eb984003d3f7814cbe507b1b37f519bc80 -r052c794d6a8db55a2fbfdad172275af073ee54c3 --- sources/view/VEventSpy.cpp (.../VEventSpy.cpp) (revision 9d8a60eb984003d3f7814cbe507b1b37f519bc80) +++ sources/view/VEventSpy.cpp (.../VEventSpy.cpp) (revision 052c794d6a8db55a2fbfdad172275af073ee54c3) @@ -17,17 +17,21 @@ // Qt #include #include +#include // Project #include "GuiGlobals.h" #include "Logger.h" +#include "FileHandler.h" +#include "DeviceController.h" // if needs to spy on the mouse events // (which is happening on the desktop only since there is not mouse attached to the device) // remove the #define comment line below. // #define SPY_MOUSE_EVENT using namespace View; +using namespace Storage; VEventSpy::VEventSpy(QObject *) { @@ -70,6 +74,10 @@ case QEvent::Type::TouchUpdate : touchEventSpy(vEvent, "tU"); break; case QEvent::Type::TouchCancel : touchEventSpy(vEvent, "tC"); break; case QEvent::Type::TouchEnd : touchEventSpy(vEvent, "tE"); break; + + // Keyboard + case QEvent::Type::KeyPress : keybdEventSpy(vEvent ); break; + // coco end default : break; @@ -181,3 +189,37 @@ */ void VEventSpy::doTouchReset() { touchCount(0); } // coco end + + +// coco begin validated: this code has been manually tested. +// the only intention of this code is to be used for testing and has been tested and is working fine. +/*! + * \brief VEventSpy::keybdEventSpy + * \param vEvent + */ +void VEventSpy::keybdEventSpy(QEvent *vEvent) { + const char *datetimeFormat = "yyyyMMdd-HHmmss"; + static bool firstEntry = true; + static bool folderAvailable = false; + static QString dateTime = QDateTime::currentDateTime().toString(datetimeFormat); + QString currentDateTime = QDateTime::currentDateTime().toString(datetimeFormat); + if ( firstEntry ) { // we will only need to check for the folder once in application life time. + folderAvailable = FileHandler::makeFolder(QString(USB_Mount_Point) + Screenshot_Base_Path_Name); + if ( ! folderAvailable ) { + LOG_DEBUG(QString("Folder is not available for screenshot [%1]").arg(Storage::Screenshot_Base_Path_Name)); + } + } + + if ( ! folderAvailable ) return; + if ( ! firstEntry && dateTime == currentDateTime ) return; // prevents user to request more than 1 screen shot per second (defined by date time format.) + dateTime = currentDateTime; + + firstEntry = false; + QKeyEvent *keyEvent = static_cast(vEvent); + if (keyEvent->key() == Qt::Key_F12) { + QImage screenshotImage = Gui::_viewer->grabWindow(); // this has to be called in Gui Thread regarding the Qt doc + QString screenshotFileName = Storage::USB_Mount_Point + QString(Storage::Screenshot_Base_Path_Name) + currentDateTime + ".png"; + _DeviceController.doScreenshot(screenshotImage, screenshotFileName); + } +} +// coco end