2 * Author - Bertrand Songis <bsongis@gmail.com>
4 * Based on th9x -> http://code.google.com/p/th9x/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #ifndef XCURSORWIDGET_H
17 #define XCURSORWIDGET_H
22 class xcursorWidget
: public QWidget
{
28 explicit xcursorWidget(QWidget
* parent
= 0):
35 virtual void mousePressEvent(QMouseEvent
* event
)
37 float p1x
[] = {20,27,45,56,50,26};
38 float p1y
[] = {59,50,52,59,71,72};
39 float p2x
[] = {23,30,46,55,47,28};
40 float p2y
[] = {107,99,100,106,117,117};
41 float p3x
[] = {24,32,46,57,46,29};
42 float p3y
[] = {154,144,146,156,167,166};
47 if (event
->button()==Qt::LeftButton
) {
48 if (pnpoly(6,p1x
,p1y
,(float)x
,(float)y
)==1) {
49 setStyleSheet("background:url(:/images/x9l1.png);");
50 emit
buttonPressed(Qt::Key_PageUp
);
52 else if (pnpoly(6,p2x
,p2y
,(float)x
,(float)y
)==1) {
53 setStyleSheet("background:url(:/images/x9l2.png);");
54 emit
buttonPressed(Qt::Key_PageDown
);
56 else if (pnpoly(6,p3x
,p3y
,(float)x
,(float)y
)==1) {
57 setStyleSheet("background:url(:/images/x9l3.png);");
58 emit
buttonPressed(Qt::Key_Escape
);
59 } else if ((x
>90 && x
<118) && (y
>177 && y
<197)) {
60 setStyleSheet("background:url(:/images/x9l4.png);");
61 emit
buttonPressed(Qt::Key_Print
);
64 // QWidget::mousePressEvent(event);
67 virtual void mouseReleaseEvent(QMouseEvent
* event
)
69 setStyleSheet("background:url(:/images/x9l0.png);");
70 emit
buttonPressed(0);
72 //QWidget::mouseReleaseEvent(event);
75 void paintEvent(QPaintEvent
*)
80 style()->drawPrimitive(QStyle::PE_Widget
, &opt
, &p
, this);
83 inline int pnpoly(int nvert
, float *vertx
, float *verty
, float testx
, float testy
)
86 for (i
= 0, j
= nvert
-1; i
< nvert
; j
= i
++) {
87 if ( ((verty
[i
]>testy
) != (verty
[j
]>testy
)) && (testx
< (vertx
[j
]-vertx
[i
]) * (testy
-verty
[i
]) / (verty
[j
]-verty
[i
]) + vertx
[i
]) )
94 void buttonPressed(int button
);
99 #endif /* CURSORWIDGET_H */