Add touch support to simulation
This commit is contained in:
@@ -197,6 +197,7 @@ void SimulatedUIWidget::setLcd(LcdWidget * lcd)
|
||||
m_backLight = 0;
|
||||
|
||||
m_lcd->setBackgroundColor(m_backlightColors.at(m_backLight));
|
||||
connect(m_lcd, &LcdWidget::touchEvent, m_simulator, &SimulatorInterface::touchEvent);
|
||||
}
|
||||
|
||||
void SimulatedUIWidget::connectScrollActions()
|
||||
|
||||
@@ -144,6 +144,7 @@ class SimulatorInterface : public QObject
|
||||
virtual void setTrainerInput(unsigned int inputNumber, int16_t value) = 0;
|
||||
virtual void setInputValue(int type, uint8_t index, int16_t value) = 0;
|
||||
virtual void rotaryEncoderEvent(int steps) = 0;
|
||||
virtual void touchEvent(int type, int x, int y) = 0;
|
||||
virtual void setTrainerTimeout(uint16_t ms) = 0;
|
||||
virtual void sendTelemetry(const QByteArray data) = 0;
|
||||
virtual void setLuaStateReloadPermanentScripts() = 0;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <QElapsedTimer>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "appdata.h"
|
||||
#include "appdebugmessagehandler.h"
|
||||
@@ -41,6 +42,12 @@ class LcdWidget : public QWidget
|
||||
|
||||
public:
|
||||
|
||||
enum TouchEvent {
|
||||
TouchUp=0,
|
||||
TouchDown,
|
||||
TouchSlide
|
||||
};
|
||||
|
||||
LcdWidget(QWidget * parent = 0):
|
||||
QWidget(parent),
|
||||
lcdBuf(NULL),
|
||||
@@ -117,6 +124,9 @@ class LcdWidget : public QWidget
|
||||
}
|
||||
}
|
||||
|
||||
signals:
|
||||
void touchEvent(int type, int x, int y);
|
||||
|
||||
protected:
|
||||
|
||||
int lcdWidth;
|
||||
@@ -213,12 +223,26 @@ class LcdWidget : public QWidget
|
||||
|
||||
}
|
||||
|
||||
void paintEvent(QPaintEvent*)
|
||||
void paintEvent(QPaintEvent*) override
|
||||
{
|
||||
QPainter p(this);
|
||||
doPaint(p);
|
||||
}
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *event) override
|
||||
{
|
||||
emit touchEvent(TouchSlide, event->pos().x(), event->pos().y());
|
||||
}
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override
|
||||
{
|
||||
emit touchEvent(TouchDown, event->pos().x(), event->pos().y());
|
||||
}
|
||||
|
||||
void mouseReleaseEvent(QMouseEvent *event) override
|
||||
{
|
||||
emit touchEvent(TouchUp, event->pos().x(), event->pos().y());
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _LCDWIDGET_H_
|
||||
|
||||
@@ -299,6 +299,51 @@ void OpenTxSimulator::rotaryEncoderEvent(int steps)
|
||||
#endif // defined(ROTARY_ENCODER_NAVIGATION)
|
||||
}
|
||||
|
||||
void OpenTxSimulator::touchEvent(int type, int x, int y)
|
||||
{
|
||||
switch (type) {
|
||||
case TouchDown:
|
||||
TRACE_WINDOWS("[Mouse Press] %d %d", x, y);
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
touchState.event = TE_DOWN;
|
||||
touchState.startX = touchState.x = x;
|
||||
touchState.startY = touchState.y = y;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case TouchUp:
|
||||
TRACE_WINDOWS("[Mouse Release] %d %d", x, y);
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
if (touchState.event == TE_DOWN) {
|
||||
touchState.event = TE_UP;
|
||||
touchState.x = touchState.startX;
|
||||
touchState.y = touchState.startY;
|
||||
} else {
|
||||
touchState.event = TE_SLIDE_END;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case TouchSlide:
|
||||
TRACE_WINDOWS("[Mouse Move] %d %d", x, y);
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
touchState.deltaX += x - touchState.x;
|
||||
touchState.deltaY += y - touchState.y;
|
||||
if (touchState.event == TE_SLIDE ||
|
||||
abs(touchState.deltaX) >= SLIDE_RANGE ||
|
||||
abs(touchState.deltaY) >= SLIDE_RANGE) {
|
||||
touchState.event = TE_SLIDE;
|
||||
touchState.x = x;
|
||||
touchState.y = y;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenTxSimulator::setTrainerTimeout(uint16_t ms)
|
||||
{
|
||||
ppmInputValidityTimer = ms;
|
||||
|
||||
@@ -35,6 +35,12 @@ class DLLEXPORT OpenTxSimulator : public SimulatorInterface
|
||||
|
||||
public:
|
||||
|
||||
enum TouchEvent {
|
||||
TouchUp=0,
|
||||
TouchDown,
|
||||
TouchSlide
|
||||
};
|
||||
|
||||
OpenTxSimulator();
|
||||
virtual ~OpenTxSimulator();
|
||||
|
||||
@@ -64,6 +70,7 @@ class DLLEXPORT OpenTxSimulator : public SimulatorInterface
|
||||
virtual void setTrainerInput(unsigned int inputNumber, int16_t value);
|
||||
virtual void setInputValue(int type, uint8_t index, int16_t value);
|
||||
virtual void rotaryEncoderEvent(int steps);
|
||||
virtual void touchEvent(int type, int x, int y);
|
||||
virtual void setTrainerTimeout(uint16_t ms);
|
||||
virtual void sendTelemetry(const QByteArray data);
|
||||
virtual void setLuaStateReloadPermanentScripts();
|
||||
|
||||
Reference in New Issue
Block a user