Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Makefile
GeneratedFiles/
Objects/
*.user
build
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Assuming Qt5 dev libraries and headers are already installed.

### Operation

The UI places 5 buttons along the top of the screen.
The UI places 8 buttons along the edges of the screen.

You can test with a real USB mouse connected or by using the
touchscreen directly.
Expand All @@ -29,7 +29,6 @@ Then run the app
$ export DISPLAY=:0.0 (if not already set)
$ ./tspress


### Run without X

$ ./tspress -platform linuxfb -plugin evdevtouch
Expand Down
47 changes: 45 additions & 2 deletions tspress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
#include <qevent.h>
#include <qpainter.h>

#include <qdebug.h>

#define MIN_WIDTH_FOR_BUTTONS 400

TsPress::TsPress(QWidget *parent)
: QMainWindow(parent)
{
setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
setAttribute(Qt::WA_AcceptTouchEvents);

m_down.setX(-1);
m_up.setX(-1);
Expand All @@ -62,15 +65,15 @@ void TsPress::onPressed(int btn)

void TsPress::mousePressEvent(QMouseEvent *event)
{
m_which->setText(QString("Down: %1, %2").arg(event->position().x()).arg(event->position().y()));
m_which->setText(QString("Down: %1, %2").arg(event->pos().x()).arg(event->pos().y()));
m_down = event->pos();
m_up.setX(-1);
update();
}

void TsPress::mouseReleaseEvent(QMouseEvent *event)
{
m_which->setText(QString("Up: %1, %2").arg(event->position().x()).arg(event->position().y()));
m_which->setText(QString("Up: %1, %2").arg(event->pos().x()).arg(event->pos().y()));
m_up = event->pos();
update();
}
Expand Down Expand Up @@ -207,3 +210,43 @@ void TsPress::layoutWindow()
setCentralWidget(widget);
}

namespace {

QString toString(Qt::TouchPointState state){
switch (state) {
case Qt::TouchPointPressed: return "Pressed";
case Qt::TouchPointMoved: return "Moved";
case Qt::TouchPointStationary: return "Stationary";
case Qt::TouchPointReleased: return "Released";
default: return "???";
}
}

}

bool TsPress::event(QEvent* event)
{
QString type;

switch (event->type()) {
case QEvent::TouchBegin: type ="Begin"; break;
case QEvent::TouchUpdate: type = "Update"; break;
case QEvent::TouchEnd: type ="End"; break;
default: return QMainWindow::event(event);
}

const auto e = static_cast<QTouchEvent*>(event);
qInfo() << e << ":" << e->type() << e->device() << e->target() << e->window() << "time:" << e->timestamp()
<< "\n points" << e->touchPoints()
<< "\n states:" << e->touchPointStates()
<< "\n modifiers" << e->modifiers();

auto str = QString("%1 %2 (%3 point(s))\n").arg(type, e->device()->name()).arg(e->touchPoints().count());

for (const auto &p: e->touchPoints()) {
str += QString("(%0,%1 %2)").arg(p.pos().x()).arg(p.pos().y()).arg(toString(p.state()));
}
m_which->setText(str);
return true;

}
9 changes: 6 additions & 3 deletions tspress.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#ifndef TSPRESS_H
#define TSPRESS_H

class QTouchEvent;

#include <qmainwindow.h>
#include <qpushbutton.h>
#include <qlist.h>
Expand All @@ -48,9 +50,10 @@ public slots:
void onPressed(int btn);

protected:
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
void paintEvent(QPaintEvent *) override;
bool event(QEvent *) override;

private:
void layoutWindow();
Expand Down