Index: sources/view/VEventSpy.cpp =================================================================== diff -u -r9d8a60eb984003d3f7814cbe507b1b37f519bc80 -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 --- sources/view/VEventSpy.cpp (.../VEventSpy.cpp) (revision 9d8a60eb984003d3f7814cbe507b1b37f519bc80) +++ sources/view/VEventSpy.cpp (.../VEventSpy.cpp) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) @@ -1,33 +1,39 @@ /*! * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * Copyright (c) 2020-2024 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * - * \file VEventSpy.cpp - * \author (last) Behrouz NematiPour - * \date (last) 16-Oct-2020 - * \author (original) Behrouz NematiPour - * \date (original) 23-Aug-2020 + * \file VEventSpy.cpp + * \author (last) Behrouz NematiPour + * \date (last) 08-Jun-2022 + * \author (original) Behrouz NematiPour + * \date (original) 23-Aug-2020 * */ #include "VEventSpy.h" // Qt #include #include +#include // Project #include "GuiGlobals.h" -#include "Logger.h" +#include "FileHandler.h" +#include "DeviceController.h" +#include "BluetoothInterface.h" +#undef DEBUG_BCUFF_MIMIC + // 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 *) { @@ -36,11 +42,11 @@ void VEventSpy::initConnections() { - // coco begin validated: this code has been manually tested. + // disabled coco begin validated: this code has been manually tested. // This should never happen with the current design and usage. // put here for developer safety if (Gui::_viewer) { - // coco end + // disabled coco end QObject::connect(Gui::_viewer , SIGNAL( eventSpy(QEvent*)), this , SLOT(onEventSpy(QEvent*))); } @@ -56,7 +62,7 @@ QEvent::Type mType = vEvent->type(); switch (mType) { - // coco begin validated: this code has been manually tested. + // disabled coco begin validated: this code has been manually tested. // the only intention of this code is to be used for EMC testing and has been tested and is working fine. // Mouse case QEvent::Type::MouseButtonDblClick : mouseEventSpy(vEvent, "mD"); break; @@ -70,7 +76,11 @@ case QEvent::Type::TouchUpdate : touchEventSpy(vEvent, "tU"); break; case QEvent::Type::TouchCancel : touchEventSpy(vEvent, "tC"); break; case QEvent::Type::TouchEnd : touchEventSpy(vEvent, "tE"); break; - // coco end + + // Keyboard + case QEvent::Type::KeyPress : keybdEventSpy(vEvent ); break; + + // disabled coco end default : break; @@ -87,7 +97,7 @@ * \param vEvent - mouse event * \param vTypeName - mouse button type name */ -// coco begin validated: this code has been manually tested. +// disabled coco begin validated: this code has been manually tested. // the only intention of this code is to be used for EMC testing and has been tested and is working fine. void VEventSpy::mouseEventSpy(QEvent *vEvent, const QString &vTypeName) { @@ -128,23 +138,23 @@ .arg(y, 4, 10, QChar('0'))); #endif } -// coco end +// disabled coco end -// coco begin validated: this code has been manually tested. +// disabled coco begin validated: this code has been manually tested. // the only intention of this code is to be used for EMC testing and has been tested and is working fine. /*! * \brief VEventSpy::doMouseReset * \details mouse event count reset */ void VEventSpy::doMouseReset() { mouseCount(0); } -// coco end +// disabled coco end /*! * \brief VEventSpy::touchEventSpy * \param vEvent - touch event * \param vTypeName - The type of the QEvent which has been shortened e.g. tB: TouchBegin */ -// coco begin validated: this code has been manually tested. +// disabled coco begin validated: this code has been manually tested. // the only intention of this code is to be used for EMC testing and has been tested and is working fine. void VEventSpy::touchEventSpy(QEvent *vEvent, const QString &vTypeName) { @@ -171,13 +181,61 @@ } LOG_DEBUG( vTypeName + logString ); } -// coco end +// disabled coco end -// coco begin validated: this code has been manually tested. +// disabled coco begin validated: this code has been manually tested. // the only intention of this code is to be used for EMC testing and has been tested and is working fine. /*! * \brief VEventSpy::doTouchReset * \details touch event counter reset */ void VEventSpy::doTouchReset() { touchCount(0); } -// coco end +// disabled coco end + + +// disabled 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); + switch (keyEvent->key()) { + case 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); + } + break; + +#ifdef DEBUG_BCUFF_MIMIC + case Qt::Key_F11: { + static quint16 systolic, diastolic, pulserate ; + _BluetoothInterface.mimic( ++systolic, ++diastolic, ++pulserate); + } + break; +#endif + + default: + break; + } +} +// disabled coco end