]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/proxguiqt.cpp
f0038683ba8d152503649b812d852dea5288837c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
9 //-----------------------------------------------------------------------------
12 #include <QPainterPath>
16 #include <QCloseEvent>
17 #include <QMouseEvent>
22 #include "proxguiqt.h"
25 void ProxGuiQT::ShowGraphWindow(void)
27 emit
ShowGraphWindowSignal();
30 void ProxGuiQT::RepaintGraphWindow(void)
32 emit
RepaintGraphWindowSignal();
35 void ProxGuiQT::HideGraphWindow(void)
37 emit
HideGraphWindowSignal();
40 void ProxGuiQT::_ShowGraphWindow(void)
46 plotwidget
= new ProxWidget();
51 void ProxGuiQT::_RepaintGraphWindow(void)
53 if (!plotapp
|| !plotwidget
)
59 void ProxGuiQT::_HideGraphWindow(void)
61 if (!plotapp
|| !plotwidget
)
67 void ProxGuiQT::MainLoop()
69 plotapp
= new QApplication(argc
, argv
);
71 connect(this, SIGNAL(ShowGraphWindowSignal()), this, SLOT(_ShowGraphWindow()));
72 connect(this, SIGNAL(RepaintGraphWindowSignal()), this, SLOT(_RepaintGraphWindow()));
73 connect(this, SIGNAL(HideGraphWindowSignal()), this, SLOT(_HideGraphWindow()));
78 ProxGuiQT::ProxGuiQT(int argc
, char **argv
) : plotapp(NULL
), plotwidget(NULL
),
79 argc(argc
), argv(argv
)
83 ProxGuiQT::~ProxGuiQT(void)
97 void ProxWidget::paintEvent(QPaintEvent
*event
)
99 QPainter
painter(this);
100 QPainterPath penPath
, whitePath
, greyPath
, lightgreyPath
, cursorAPath
, cursorBPath
;
102 QBrush
brush(QColor(100, 255, 100));
103 QPen
pen(QColor(100, 255, 100));
105 painter
.setFont(QFont("Arial", 10));
111 if (CursorAPos
> GraphTraceLen
)
113 if(CursorBPos
> GraphTraceLen
)
118 painter
.fillRect(r
, QColor(0, 0, 0));
120 whitePath
.moveTo(r
.left() + 40, r
.top());
121 whitePath
.lineTo(r
.left() + 40, r
.bottom());
123 int zeroHeight
= r
.top() + (r
.bottom() - r
.top()) / 2;
125 greyPath
.moveTo(r
.left(), zeroHeight
);
126 greyPath
.lineTo(r
.right(), zeroHeight
);
127 painter
.setPen(QColor(100, 100, 100));
128 painter
.drawPath(greyPath
);
130 // plot X and Y grid lines
132 if ((PlotGridX
> 0) && ((PlotGridX
* GraphPixelsPerPoint
) > 1)) {
133 for(i
= 40; i
< r
.right(); i
+= (int)(PlotGridX
* GraphPixelsPerPoint
)) {
134 //SelectObject(hdc, GreyPenLite);
135 //MoveToEx(hdc, r.left + i, r.top, NULL);
136 //LineTo(hdc, r.left + i, r.bottom);
137 lightgreyPath
.moveTo(r
.left()+i
,r
.top());
138 lightgreyPath
.lineTo(r
.left()+i
,r
.bottom());
139 painter
.drawPath(lightgreyPath
);
142 if ((PlotGridY
> 0) && ((PlotGridY
* GraphPixelsPerPoint
) > 1)){
143 for(i
= 0; i
< ((r
.top() + r
.bottom())>>1); i
+= (int)(PlotGridY
* GraphPixelsPerPoint
)) {
144 lightgreyPath
.moveTo(r
.left() + 40,zeroHeight
+ i
);
145 lightgreyPath
.lineTo(r
.right(),zeroHeight
+ i
);
146 painter
.drawPath(lightgreyPath
);
147 lightgreyPath
.moveTo(r
.left() + 40,zeroHeight
- i
);
148 lightgreyPath
.lineTo(r
.right(),zeroHeight
- i
);
149 painter
.drawPath(lightgreyPath
);
154 (GraphTraceLen
- (int)((r
.right() - r
.left() - 40) / GraphPixelsPerPoint
));
158 if(GraphStart
> startMax
) {
159 GraphStart
= startMax
;
164 for(i
= GraphStart
; ; i
++) {
165 if(i
>= GraphTraceLen
) {
168 if(fabs((double)GraphBuffer
[i
]) > absYMax
) {
169 absYMax
= (int)fabs((double)GraphBuffer
[i
]);
171 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
177 absYMax
= (int)(absYMax
*1.2 + 1);
179 // number of points that will be plotted
180 int span
= (int)((r
.right() - r
.left()) / GraphPixelsPerPoint
);
181 // one label every 100 pixels, let us say
182 int labels
= (r
.right() - r
.left() - 40) / 100;
183 if(labels
<= 0) labels
= 1;
184 int pointsPerLabel
= span
/ labels
;
185 if(pointsPerLabel
<= 0) pointsPerLabel
= 1;
192 for(i
= GraphStart
; ; i
++) {
193 if(i
>= GraphTraceLen
) {
196 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
197 if(x
> r
.right() + GraphPixelsPerPoint
) {
201 int y
= GraphBuffer
[i
];
211 y
= (y
* (r
.top() - r
.bottom()) / (2*absYMax
)) + zeroHeight
;
212 if(i
== GraphStart
) {
213 penPath
.moveTo(x
, y
);
215 penPath
.lineTo(x
, y
);
218 if(GraphPixelsPerPoint
> 10) {
219 QRect
f(QPoint(x
- 3, y
- 3),QPoint(x
+ 3, y
+ 3));
220 painter
.fillRect(f
, brush
);
223 if(((i
- GraphStart
) % pointsPerLabel
== 0) && i
!= GraphStart
) {
224 whitePath
.moveTo(x
, zeroHeight
- 3);
225 whitePath
.lineTo(x
, zeroHeight
+ 3);
228 sprintf(str
, "+%d", (i
- GraphStart
));
230 painter
.setPen(QColor(255, 255, 255));
232 QFontMetrics
metrics(painter
.font());
233 size
= metrics
.boundingRect(str
);
234 painter
.drawText(x
- (size
.right() - size
.left()), zeroHeight
+ 9, str
);
239 if(i
== CursorAPos
|| i
== CursorBPos
) {
240 QPainterPath
*cursorPath
;
242 if(i
== CursorAPos
) {
243 cursorPath
= &cursorAPath
;
245 cursorPath
= &cursorBPath
;
247 cursorPath
->moveTo(x
, r
.top());
248 cursorPath
->lineTo(x
, r
.bottom());
249 penPath
.moveTo(x
, y
);
257 painter
.setPen(QColor(255, 255, 255));
258 painter
.drawPath(whitePath
);
260 painter
.drawPath(penPath
);
261 painter
.setPen(QColor(255, 255, 0));
262 painter
.drawPath(cursorAPath
);
263 painter
.setPen(QColor(255, 0, 255));
264 painter
.drawPath(cursorBPath
);
267 sprintf(str
, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f] zoom=%.3f CursorA=%d [%d] CursorB=%d [%d]",
268 GraphStart
, yMax
, yMin
, yMean
, n
, GraphTraceLen
,
269 CursorBPos
- CursorAPos
, (CursorBPos
- CursorAPos
)/CursorScaleFactor
,GraphPixelsPerPoint
,CursorAPos
,GraphBuffer
[CursorAPos
],CursorBPos
,GraphBuffer
[CursorBPos
]);
271 painter
.setPen(QColor(255, 255, 255));
272 painter
.drawText(50, r
.bottom() - 20, str
);
275 ProxWidget::ProxWidget(QWidget
*parent
) : QWidget(parent
), GraphStart(0), GraphPixelsPerPoint(1)
279 QPalette
palette(QColor(0,0,0,0));
280 palette
.setColor(QPalette::WindowText
, QColor(255,255,255));
281 palette
.setColor(QPalette::Text
, QColor(255,255,255));
282 palette
.setColor(QPalette::Button
, QColor(100, 100, 100));
284 setAutoFillBackground(true);
287 void ProxWidget::closeEvent(QCloseEvent
*event
)
293 void ProxWidget::mouseMoveEvent(QMouseEvent
*event
)
297 x
= (int)(x
/ GraphPixelsPerPoint
);
299 if((event
->buttons() & Qt::LeftButton
)) {
301 } else if (event
->buttons() & Qt::RightButton
) {
309 void ProxWidget::keyPressEvent(QKeyEvent
*event
)
311 switch(event
->key()) {
313 if(GraphPixelsPerPoint
<= 50) {
314 GraphPixelsPerPoint
*= 2;
319 if(GraphPixelsPerPoint
>= 0.02) {
320 GraphPixelsPerPoint
/= 2;
325 if(GraphPixelsPerPoint
< 20) {
326 GraphStart
+= (int)(20 / GraphPixelsPerPoint
);
333 if(GraphPixelsPerPoint
< 20) {
334 GraphStart
-= (int)(20 / GraphPixelsPerPoint
);
341 QWidget::keyPressEvent(event
);