]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/proxguiqt.cpp
1 //-----------------------------------------------------------------------------
2 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
3 // at your option, any later version. See the LICENSE.txt file for the text of
5 //-----------------------------------------------------------------------------
7 //-----------------------------------------------------------------------------
10 #include <QPainterPath>
14 #include <QCloseEvent>
15 #include <QMouseEvent>
20 #include "proxguiqt.h"
23 void ProxGuiQT::ShowGraphWindow(void)
25 emit
ShowGraphWindowSignal();
28 void ProxGuiQT::RepaintGraphWindow(void)
30 emit
RepaintGraphWindowSignal();
33 void ProxGuiQT::HideGraphWindow(void)
35 emit
HideGraphWindowSignal();
38 void ProxGuiQT::_ShowGraphWindow(void)
44 plotwidget
= new ProxWidget();
49 void ProxGuiQT::_RepaintGraphWindow(void)
51 if (!plotapp
|| !plotwidget
)
57 void ProxGuiQT::_HideGraphWindow(void)
59 if (!plotapp
|| !plotwidget
)
65 void ProxGuiQT::MainLoop()
67 plotapp
= new QApplication(argc
, argv
);
69 connect(this, SIGNAL(ShowGraphWindowSignal()), this, SLOT(_ShowGraphWindow()));
70 connect(this, SIGNAL(RepaintGraphWindowSignal()), this, SLOT(_RepaintGraphWindow()));
71 connect(this, SIGNAL(HideGraphWindowSignal()), this, SLOT(_HideGraphWindow()));
76 ProxGuiQT::ProxGuiQT(int argc
, char **argv
) : plotapp(NULL
), plotwidget(NULL
),
77 argc(argc
), argv(argv
)
81 ProxGuiQT::~ProxGuiQT(void)
95 void ProxWidget::paintEvent(QPaintEvent
*event
)
97 QPainter
painter(this);
98 QPainterPath penPath
, whitePath
, greyPath
, lightgreyPath
, cursorAPath
, cursorBPath
;
100 QBrush
brush(QColor(100, 255, 100));
101 QPen
pen(QColor(100, 255, 100));
103 painter
.setFont(QFont("Arial", 10));
109 if (CursorAPos
> GraphTraceLen
)
111 if(CursorBPos
> GraphTraceLen
)
116 painter
.fillRect(r
, QColor(0, 0, 0));
118 whitePath
.moveTo(r
.left() + 40, r
.top());
119 whitePath
.lineTo(r
.left() + 40, r
.bottom());
121 int zeroHeight
= r
.top() + (r
.bottom() - r
.top()) / 2;
123 greyPath
.moveTo(r
.left(), zeroHeight
);
124 greyPath
.lineTo(r
.right(), zeroHeight
);
125 painter
.setPen(QColor(100, 100, 100));
126 painter
.drawPath(greyPath
);
128 // plot X and Y grid lines
130 if ((PlotGridX
> 0) && ((PlotGridX
* GraphPixelsPerPoint
) > 1)) {
131 for(i
= 40; i
< r
.right(); i
+= (int)(PlotGridX
* GraphPixelsPerPoint
)) {
132 //SelectObject(hdc, GreyPenLite);
133 //MoveToEx(hdc, r.left + i, r.top, NULL);
134 //LineTo(hdc, r.left + i, r.bottom);
135 lightgreyPath
.moveTo(r
.left()+i
,r
.top());
136 lightgreyPath
.lineTo(r
.left()+i
,r
.bottom());
137 painter
.drawPath(lightgreyPath
);
140 if ((PlotGridY
> 0) && ((PlotGridY
* GraphPixelsPerPoint
) > 1)){
141 for(i
= 0; i
< ((r
.top() + r
.bottom())>>1); i
+= (int)(PlotGridY
* GraphPixelsPerPoint
)) {
142 lightgreyPath
.moveTo(r
.left() + 40,zeroHeight
+ i
);
143 lightgreyPath
.lineTo(r
.right(),zeroHeight
+ i
);
144 painter
.drawPath(lightgreyPath
);
145 lightgreyPath
.moveTo(r
.left() + 40,zeroHeight
- i
);
146 lightgreyPath
.lineTo(r
.right(),zeroHeight
- i
);
147 painter
.drawPath(lightgreyPath
);
152 (GraphTraceLen
- (int)((r
.right() - r
.left() - 40) / GraphPixelsPerPoint
));
156 if(GraphStart
> startMax
) {
157 GraphStart
= startMax
;
162 for(i
= GraphStart
; ; i
++) {
163 if(i
>= GraphTraceLen
) {
166 if(fabs((double)GraphBuffer
[i
]) > absYMax
) {
167 absYMax
= (int)fabs((double)GraphBuffer
[i
]);
169 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
175 absYMax
= (int)(absYMax
*1.2 + 1);
177 // number of points that will be plotted
178 int span
= (int)((r
.right() - r
.left()) / GraphPixelsPerPoint
);
179 // one label every 100 pixels, let us say
180 int labels
= (r
.right() - r
.left() - 40) / 100;
181 if(labels
<= 0) labels
= 1;
182 int pointsPerLabel
= span
/ labels
;
183 if(pointsPerLabel
<= 0) pointsPerLabel
= 1;
190 for(i
= GraphStart
; ; i
++) {
191 if(i
>= GraphTraceLen
) {
194 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
195 if(x
> r
.right() + GraphPixelsPerPoint
) {
199 int y
= GraphBuffer
[i
];
209 y
= (y
* (r
.top() - r
.bottom()) / (2*absYMax
)) + zeroHeight
;
210 if(i
== GraphStart
) {
211 penPath
.moveTo(x
, y
);
213 penPath
.lineTo(x
, y
);
216 if(GraphPixelsPerPoint
> 10) {
217 QRect
f(QPoint(x
- 3, y
- 3),QPoint(x
+ 3, y
+ 3));
218 painter
.fillRect(f
, brush
);
221 if(((i
- GraphStart
) % pointsPerLabel
== 0) && i
!= GraphStart
) {
222 whitePath
.moveTo(x
, zeroHeight
- 3);
223 whitePath
.lineTo(x
, zeroHeight
+ 3);
226 sprintf(str
, "+%d", (i
- GraphStart
));
228 painter
.setPen(QColor(255, 255, 255));
230 QFontMetrics
metrics(painter
.font());
231 size
= metrics
.boundingRect(str
);
232 painter
.drawText(x
- (size
.right() - size
.left()), zeroHeight
+ 9, str
);
237 if(i
== CursorAPos
|| i
== CursorBPos
) {
238 QPainterPath
*cursorPath
;
240 if(i
== CursorAPos
) {
241 cursorPath
= &cursorAPath
;
243 cursorPath
= &cursorBPath
;
245 cursorPath
->moveTo(x
, r
.top());
246 cursorPath
->lineTo(x
, r
.bottom());
247 penPath
.moveTo(x
, y
);
255 painter
.setPen(QColor(255, 255, 255));
256 painter
.drawPath(whitePath
);
258 painter
.drawPath(penPath
);
259 painter
.setPen(QColor(255, 255, 0));
260 painter
.drawPath(cursorAPath
);
261 painter
.setPen(QColor(255, 0, 255));
262 painter
.drawPath(cursorBPath
);
265 sprintf(str
, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f] zoom=%.3f CursorA=%d [%d] CursorB=%d [%d]",
266 GraphStart
, yMax
, yMin
, yMean
, n
, GraphTraceLen
,
267 CursorBPos
- CursorAPos
, (CursorBPos
- CursorAPos
)/CursorScaleFactor
,GraphPixelsPerPoint
,CursorAPos
,GraphBuffer
[CursorAPos
],CursorBPos
,GraphBuffer
[CursorBPos
]);
269 painter
.setPen(QColor(255, 255, 255));
270 painter
.drawText(50, r
.bottom() - 20, str
);
273 ProxWidget::ProxWidget(QWidget
*parent
) : QWidget(parent
), GraphStart(0), GraphPixelsPerPoint(1)
277 QPalette
palette(QColor(0,0,0,0));
278 palette
.setColor(QPalette::WindowText
, QColor(255,255,255));
279 palette
.setColor(QPalette::Text
, QColor(255,255,255));
280 palette
.setColor(QPalette::Button
, QColor(100, 100, 100));
282 setAutoFillBackground(true);
285 void ProxWidget::closeEvent(QCloseEvent
*event
)
291 void ProxWidget::mouseMoveEvent(QMouseEvent
*event
)
295 x
= (int)(x
/ GraphPixelsPerPoint
);
297 if((event
->buttons() & Qt::LeftButton
)) {
299 } else if (event
->buttons() & Qt::RightButton
) {
307 void ProxWidget::keyPressEvent(QKeyEvent
*event
)
309 switch(event
->key()) {
311 if(GraphPixelsPerPoint
<= 50) {
312 GraphPixelsPerPoint
*= 2;
317 if(GraphPixelsPerPoint
>= 0.02) {
318 GraphPixelsPerPoint
/= 2;
323 if(GraphPixelsPerPoint
< 20) {
324 GraphStart
+= (int)(20 / GraphPixelsPerPoint
);
331 if(GraphPixelsPerPoint
< 20) {
332 GraphStart
-= (int)(20 / GraphPixelsPerPoint
);
339 QWidget::keyPressEvent(event
);