1
/***************************************************************************
2
* Copyright (C) 2003,2005,2006 by Martin Koller *
4
* This file is part of the KDE Control Center Module for Joysticks *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20
***************************************************************************/
21
#include "poswidget.h"
27
#define MAX_POINTS 500
29
//-----------------------------------------------------------------
31
PosWidget::PosWidget(QWidget *parent)
32
: QWidget(parent), x(0), y(0), trace(false)
34
setMinimumSize(XY_WIDTH, XY_WIDTH);
35
setMaximumSize(XY_WIDTH, XY_WIDTH);
38
palette.setColor(backgroundRole(), Qt::white);
42
//-----------------------------------------------------------------
44
void PosWidget::paintEvent(QPaintEvent *)
49
paint.drawRect(0, 0, width()-1, height()-1);
50
paint.setPen(Qt::gray);
53
paint.drawLine(XY_WIDTH/2, 1,
54
XY_WIDTH/2, XY_WIDTH - 2);
56
paint.drawLine(1, XY_WIDTH/2,
57
XY_WIDTH - 2, XY_WIDTH/2);
59
// draw the trace of previous points
62
paint.setPen(Qt::black);
64
for (int i = 0; i < tracePoints.count()-2; i++)
65
paint.drawLine(tracePoints[i], tracePoints[i+1]);
67
if ( tracePoints.count() > 0 )
68
paint.drawLine(tracePoints[tracePoints.count()-1], QPoint(x, y));
71
// draw the current position marker
72
paint.setPen(Qt::blue);
74
paint.drawLine(x - MARK_WIDTH/2, y - MARK_WIDTH/2,
75
x + MARK_WIDTH/2, y + MARK_WIDTH/2);
77
paint.drawLine(x - MARK_WIDTH/2, y + MARK_WIDTH/2,
78
x + MARK_WIDTH/2, y - MARK_WIDTH/2);
81
//-----------------------------------------------------------------
83
void PosWidget::changeX(int newX)
85
// transform coordinates from joystick to widget coordinates
86
newX = int((newX/65535.0)*XY_WIDTH + XY_WIDTH/2);
88
if ( x == newX ) return; // avoid unnecessary redraw
92
tracePoints.append(QPoint(x, y));
93
if ( tracePoints.count() == MAX_POINTS )
94
tracePoints.removeFirst();
101
//-----------------------------------------------------------------
103
void PosWidget::changeY(int newY)
105
// transform coordinates from joystick to widget coordinates
106
newY = int((newY/65535.0)*XY_WIDTH + XY_WIDTH/2);
108
if ( y == newY ) return; // avoid unnecessary redraw
112
tracePoints.append(QPoint(x, y));
113
if ( tracePoints.count() == MAX_POINTS )
114
tracePoints.removeFirst();
121
//-----------------------------------------------------------------
123
void PosWidget::showTrace(bool t)
131
//-----------------------------------------------------------------
133
#include "poswidget.moc"