]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - linux/proxguiqt.cpp
2 #include <QPainterPath>
11 #include "proxguiqt.h"
14 void ProxGuiQT::ShowGraphWindow(void)
16 emit
ShowGraphWindowSignal();
19 void ProxGuiQT::RepaintGraphWindow(void)
21 emit
RepaintGraphWindowSignal();
24 void ProxGuiQT::HideGraphWindow(void)
26 emit
HideGraphWindowSignal();
29 void ProxGuiQT::_ShowGraphWindow(void)
35 plotwidget
= new ProxWidget();
40 void ProxGuiQT::_RepaintGraphWindow(void)
42 if (!plotapp
|| !plotwidget
)
48 void ProxGuiQT::_HideGraphWindow(void)
50 if (!plotapp
|| !plotwidget
)
56 void ProxGuiQT::MainLoop()
58 plotapp
= new QApplication(argc
, argv
);
60 connect(this, SIGNAL(ShowGraphWindowSignal()), this, SLOT(_ShowGraphWindow()));
61 connect(this, SIGNAL(RepaintGraphWindowSignal()), this, SLOT(_RepaintGraphWindow()));
62 connect(this, SIGNAL(HideGraphWindowSignal()), this, SLOT(_HideGraphWindow()));
67 ProxGuiQT::ProxGuiQT(int argc
, char **argv
) : plotapp(NULL
), plotwidget(NULL
),
68 argc(argc
), argv(argv
)
72 ProxGuiQT::~ProxGuiQT(void)
86 void ProxWidget::paintEvent(QPaintEvent
*event
)
88 QPainter
painter(this);
89 QPainterPath penPath
, whitePath
, greyPath
, lightgreyPath
, cursorAPath
, cursorBPath
;
91 QBrush
brush(QColor(100, 255, 100));
92 QPen
pen(QColor(100, 255, 100));
94 painter
.setFont(QFont("Arial", 10));
100 if (CursorAPos
> GraphTraceLen
)
102 if(CursorBPos
> GraphTraceLen
)
107 painter
.fillRect(r
, QColor(0, 0, 0));
109 whitePath
.moveTo(r
.left() + 40, r
.top());
110 whitePath
.lineTo(r
.left() + 40, r
.bottom());
112 int zeroHeight
= r
.top() + (r
.bottom() - r
.top()) / 2;
114 greyPath
.moveTo(r
.left(), zeroHeight
);
115 greyPath
.lineTo(r
.right(), zeroHeight
);
116 painter
.setPen(QColor(100, 100, 100));
117 painter
.drawPath(greyPath
);
119 // plot X and Y grid lines
121 if ((PlotGridX
> 0) && ((PlotGridX
* GraphPixelsPerPoint
) > 1)) {
122 for(i
= 40; i
< r
.right(); i
+= (int)(PlotGridX
* GraphPixelsPerPoint
)) {
123 //SelectObject(hdc, GreyPenLite);
124 //MoveToEx(hdc, r.left + i, r.top, NULL);
125 //LineTo(hdc, r.left + i, r.bottom);
126 lightgreyPath
.moveTo(r
.left()+i
,r
.top());
127 lightgreyPath
.lineTo(r
.left()+i
,r
.bottom());
128 painter
.drawPath(lightgreyPath
);
131 if ((PlotGridY
> 0) && ((PlotGridY
* GraphPixelsPerPoint
) > 1)){
132 for(i
= 0; i
< ((r
.top() + r
.bottom())>>1); i
+= (int)(PlotGridY
* GraphPixelsPerPoint
)) {
133 lightgreyPath
.moveTo(r
.left() + 40,zeroHeight
+ i
);
134 lightgreyPath
.lineTo(r
.right(),zeroHeight
+ i
);
135 painter
.drawPath(lightgreyPath
);
136 lightgreyPath
.moveTo(r
.left() + 40,zeroHeight
- i
);
137 lightgreyPath
.lineTo(r
.right(),zeroHeight
- i
);
138 painter
.drawPath(lightgreyPath
);
143 (GraphTraceLen
- (int)((r
.right() - r
.left() - 40) / GraphPixelsPerPoint
));
147 if(GraphStart
> startMax
) {
148 GraphStart
= startMax
;
153 for(i
= GraphStart
; ; i
++) {
154 if(i
>= GraphTraceLen
) {
157 if(fabs((double)GraphBuffer
[i
]) > absYMax
) {
158 absYMax
= (int)fabs((double)GraphBuffer
[i
]);
160 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
166 absYMax
= (int)(absYMax
*1.2 + 1);
168 // number of points that will be plotted
169 int span
= (int)((r
.right() - r
.left()) / GraphPixelsPerPoint
);
170 // one label every 100 pixels, let us say
171 int labels
= (r
.right() - r
.left() - 40) / 100;
172 if(labels
<= 0) labels
= 1;
173 int pointsPerLabel
= span
/ labels
;
174 if(pointsPerLabel
<= 0) pointsPerLabel
= 1;
181 for(i
= GraphStart
; ; i
++) {
182 if(i
>= GraphTraceLen
) {
185 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
186 if(x
> r
.right() + GraphPixelsPerPoint
) {
190 int y
= GraphBuffer
[i
];
200 y
= (y
* (r
.top() - r
.bottom()) / (2*absYMax
)) + zeroHeight
;
201 if(i
== GraphStart
) {
202 penPath
.moveTo(x
, y
);
204 penPath
.lineTo(x
, y
);
207 if(GraphPixelsPerPoint
> 10) {
208 QRect
f(QPoint(x
- 3, y
- 3),QPoint(x
+ 3, y
+ 3));
209 painter
.fillRect(f
, brush
);
212 if(((i
- GraphStart
) % pointsPerLabel
== 0) && i
!= GraphStart
) {
213 whitePath
.moveTo(x
, zeroHeight
- 3);
214 whitePath
.lineTo(x
, zeroHeight
+ 3);
217 sprintf(str
, "+%d", (i
- GraphStart
));
219 painter
.setPen(QColor(255, 255, 255));
221 QFontMetrics
metrics(painter
.font());
222 size
= metrics
.boundingRect(str
);
223 painter
.drawText(x
- (size
.right() - size
.left()), zeroHeight
+ 9, str
);
228 if(i
== CursorAPos
|| i
== CursorBPos
) {
229 QPainterPath
*cursorPath
;
231 if(i
== CursorAPos
) {
232 cursorPath
= &cursorAPath
;
234 cursorPath
= &cursorBPath
;
236 cursorPath
->moveTo(x
, r
.top());
237 cursorPath
->lineTo(x
, r
.bottom());
238 penPath
.moveTo(x
, y
);
246 painter
.setPen(QColor(255, 255, 255));
247 painter
.drawPath(whitePath
);
249 painter
.drawPath(penPath
);
250 painter
.setPen(QColor(255, 255, 0));
251 painter
.drawPath(cursorAPath
);
252 painter
.setPen(QColor(255, 0, 255));
253 painter
.drawPath(cursorBPath
);
256 sprintf(str
, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f] zoom=%.3f CursorA=%d [%d] CursorB=%d [%d]",
257 GraphStart
, yMax
, yMin
, yMean
, n
, GraphTraceLen
,
258 CursorBPos
- CursorAPos
, (CursorBPos
- CursorAPos
)/CursorScaleFactor
,GraphPixelsPerPoint
,CursorAPos
,GraphBuffer
[CursorAPos
],CursorBPos
,GraphBuffer
[CursorBPos
]);
260 painter
.setPen(QColor(255, 255, 255));
261 painter
.drawText(50, r
.bottom() - 20, str
);
264 ProxWidget::ProxWidget(QWidget
*parent
) : QWidget(parent
), GraphStart(0), GraphPixelsPerPoint(1)
268 QPalette
palette(QColor(0,0,0,0));
269 palette
.setColor(QPalette::WindowText
, QColor(255,255,255));
270 palette
.setColor(QPalette::Text
, QColor(255,255,255));
271 palette
.setColor(QPalette::Button
, QColor(100, 100, 100));
273 setAutoFillBackground(true);
276 void ProxWidget::closeEvent(QCloseEvent
*event
)
282 void ProxWidget::mouseMoveEvent(QMouseEvent
*event
)
286 x
= (int)(x
/ GraphPixelsPerPoint
);
288 if((event
->buttons() & Qt::LeftButton
)) {
290 } else if (event
->buttons() & Qt::RightButton
) {
298 void ProxWidget::keyPressEvent(QKeyEvent
*event
)
300 switch(event
->key()) {
302 if(GraphPixelsPerPoint
<= 50) {
303 GraphPixelsPerPoint
*= 2;
308 if(GraphPixelsPerPoint
>= 0.02) {
309 GraphPixelsPerPoint
/= 2;
314 if(GraphPixelsPerPoint
< 20) {
315 GraphStart
+= (int)(20 / GraphPixelsPerPoint
);
322 if(GraphPixelsPerPoint
< 20) {
323 GraphStart
-= (int)(20 / GraphPixelsPerPoint
);
330 QWidget::keyPressEvent(event
);