/*! * * 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) 08-Jun-2022 * \author (original) Behrouz NematiPour * \date (original) 23-Aug-2020 * */ #include "VEventSpy.h" // Qt #include #include #include // Project #include "GuiGlobals.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 *) { initConnections(); } void VEventSpy::initConnections() { // This should never happen with the current design and usage. // put here for developer safety if (Gui::_viewer) { QObject::connect(Gui::_viewer , SIGNAL( eventSpy(QEvent*)), this , SLOT(onEventSpy(QEvent*))); } } /*! * \brief VEventSpy::onEventSpy * \details the event handler slot which receives all the events of the UI from Gui::_viewer * depending on type of the event calls corresponding method. * \param vEvent - the event */ void VEventSpy::onEventSpy(QEvent *vEvent) { QEvent::Type mType = vEvent->type(); switch (mType) { // 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; case QEvent::Type::MouseButtonPress : mouseEventSpy(vEvent, "mP"); break; case QEvent::Type::MouseButtonRelease : mouseEventSpy(vEvent, "mR"); break; case QEvent::Type::MouseMove : mouseEventSpy(vEvent, "mM"); break; case QEvent::Type::MouseTrackingChange : mouseEventSpy(vEvent, "mT"); break; // Touch case QEvent::Type::TouchBegin : touchEventSpy(vEvent, "tB"); break; 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; default : break; } emit eventSpy(mType); } /*! * \brief VEventSpy::mouseEventSpy * \details Mouse event spy * 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 comment of the #define SPY_MOUSE_EVENT * \param vEvent - mouse event * \param vTypeName - mouse button type name */ // 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) { #ifndef SPY_MOUSE_EVENT Q_UNUSED(vEvent) Q_UNUSED(vTypeName) #else QMouseEvent *mouseEvent = static_cast(vEvent); int x = mouseEvent->x(); int y = mouseEvent->y(); mouseCount( _mouseCount + 1 ); mousePoint(QPoint(x, y)); QString btn; switch (mouseEvent->button()) { case Qt::LeftButton : btn = "L"; break; case Qt::RightButton : btn = "R"; break; case Qt::MiddleButton : btn = "M"; break; case Qt::BackButton : btn = "B"; break; case Qt::NoButton : btn = "_"; break; default : break; } QString mdf; switch (mouseEvent->modifiers()) { case Qt::NoModifier : mdf = "_"; break; case Qt::ShiftModifier : mdf = "S"; break; case Qt::ControlModifier: mdf = "C"; break; case Qt::AltModifier : mdf = "A"; break; case Qt::MetaModifier : mdf = "M"; break; case Qt::KeypadModifier : mdf = "#"; break; default : break; } LOG_DEBUG( btn + vTypeName + mdf + QString(",%1,%2") .arg(x, 4, 10, QChar('0')) .arg(y, 4, 10, QChar('0'))); #endif } // the only intention of this code is to be used for EMC testing. /*! * \brief VEventSpy::doMouseReset * \details mouse event count reset */ void VEventSpy::doMouseReset() { mouseCount(0); } /*! * \brief VEventSpy::touchEventSpy * \param vEvent - touch event * \param vTypeName - The type of the QEvent which has been shortened e.g. tB: TouchBegin */ // the only intention of this code is to be used for EMC testing. void VEventSpy::touchEventSpy(QEvent *vEvent, const QString &vTypeName) { QTouchEvent *touchEvent = static_cast(vEvent); const QList &points = touchEvent->points(); QString logString; int c = points.count(); touchCount ( _touchCount + 1 ); touchPoints( c ); logString += ',' + QString::number(c); for (auto point : points) { QString state; switch (point.state()) { case QEventPoint::State::Pressed : state = "P"; break; // The touch point is now pressed. case QEventPoint::State::Updated : state = "M"; break; // The touch point moved. case QEventPoint::State::Stationary : state = "S"; break; // The touch point did not move. case QEventPoint::State::Released : state = "R"; break; // The touch point was released. default : break; } QPointF pos = point.globalPosition(); logString += QString(",%1,%2,%3").arg(state).arg(pos.x()).arg(pos.y()); } LOG_DEBUG( vTypeName + logString ); } // the only intention of this code is to be used for EMC. /*! * \brief VEventSpy::doTouchReset * \details touch event counter reset */ void VEventSpy::doTouchReset() { touchCount(0); } // the only intention of this code is to be used for testing. /*! * \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; } }