-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathlcdwidget.cpp
64 lines (50 loc) · 1.46 KB
/
lcdwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "lcdwidget.h"
#include "core/keypad.h"
#include "qtkeypadbridge.h"
#include "qmlbridge.h"
#include "qtframebuffer.h"
LCDWidget::LCDWidget(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
{
setMinimumSize(320, 240);
connect(&refresh_timer, SIGNAL(timeout()), this, SLOT(update()));
refresh_timer.setInterval(1000 / 30); // 30 fps
}
void LCDWidget::mousePressEvent(QMouseEvent *event)
{
the_qml_bridge->setTouchpadState((qreal)event->x() / width(), (qreal)event->y() / height(), true, event->button() == Qt::RightButton);
}
void LCDWidget::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton)
keypad.touchpad_down = keypad.touchpad_contact = false;
else
keypad.touchpad_contact = false;
the_qml_bridge->touchpadStateChanged();
keypad.kpc.gpio_int_active |= 0x800;
keypad_int_check();
}
void LCDWidget::mouseMoveEvent(QMouseEvent *event)
{
the_qml_bridge->setTouchpadState((qreal)event->x() / width(), (qreal)event->y() / height(), keypad.touchpad_contact, keypad.touchpad_down);
}
void LCDWidget::showEvent(QShowEvent *e)
{
QWidget::showEvent(e);
refresh_timer.start();
}
void LCDWidget::hideEvent(QHideEvent *e)
{
QWidget::hideEvent(e);
refresh_timer.stop();
}
void LCDWidget::closeEvent(QCloseEvent *e)
{
QWidget::closeEvent(e);
emit closed();
}
void LCDWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
paintFramebuffer(&painter);
}