/*! * * Copyright (c) 2019-2020 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) 23-Aug-2020 * \author (original) Behrouz NematiPour * \date (original) 23-Aug-2020 * */ #include "VEventSpy.h" // Qt #include #include // Project #include "guiglobals.h" #include "logger.h" using namespace View; VEventSpy::VEventSpy(QObject *) { initConnections(); } void VEventSpy::initConnections() { // 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 QObject::connect(Gui::_viewer , SIGNAL( eventSpy(QEvent*)), this , SLOT(onEventSpy(QEvent*))); } } void VEventSpy::onEventSpy(QEvent *vEvent) { QEvent::Type mType = vEvent->type(); switch (mType) { // 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; 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; // coco end default : break; } emit eventSpy(mType); } /*! * \brief VEventSpy::mouseEventSpy * \param vEvent * \param typeName */ // 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 &typeName) { 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 + typeName + mdf + QString(",%1,%2") .arg(x, 4, 10, QChar('0')) .arg(y, 4, 10, QChar('0'))); } // coco end // 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::doMouseReset() { mouseCount(0); } // coco end /*! * \brief VEventSpy::touchEventSpy * \param vEvent * \param typeName */ // 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) { QTouchEvent *touchEvent = static_cast(vEvent); const QList &points = touchEvent->touchPoints(); 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 Qt::TouchPointPressed : state = "P"; break; // The touch point is now pressed. case Qt::TouchPointMoved : state = "M"; break; // The touch point moved. case Qt::TouchPointStationary : state = "S"; break; // The touch point did not move. case Qt::TouchPointReleased : state = "R"; break; // The touch point was released. default : break; } QPointF pos = point.screenPos(); logString += QString(",%1,%2,%3").arg(state).arg(pos.x()).arg(pos.y()); } LOG_DEBUG( vTypeName + logString ); } // coco end // 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::doTouchReset() { touchCount(0); } // coco end