]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/proxguiqt.cpp
2 #include <QPainterPath>
12 #include "proxguiqt.h"
15 void ProxGuiQT::ShowGraphWindow(void)
17 emit
ShowGraphWindowSignal();
20 void ProxGuiQT::RepaintGraphWindow(void)
22 emit
RepaintGraphWindowSignal();
25 void ProxGuiQT::HideGraphWindow(void)
27 emit
HideGraphWindowSignal();
30 void ProxGuiQT::_ShowGraphWindow(void)
36 plotwidget
= new ProxWidget();
41 void ProxGuiQT::_RepaintGraphWindow(void)
43 if (!plotapp
|| !plotwidget
)
49 void ProxGuiQT::_HideGraphWindow(void)
51 if (!plotapp
|| !plotwidget
)
57 void ProxGuiQT::MainLoop()
59 plotapp
= new QApplication(argc
, argv
);
61 connect(this, SIGNAL(ShowGraphWindowSignal()), this, SLOT(_ShowGraphWindow()));
62 connect(this, SIGNAL(RepaintGraphWindowSignal()), this, SLOT(_RepaintGraphWindow()));
63 connect(this, SIGNAL(HideGraphWindowSignal()), this, SLOT(_HideGraphWindow()));
68 ProxGuiQT::ProxGuiQT(int argc
, char **argv
) : plotapp(NULL
), plotwidget(NULL
),
69 argc(argc
), argv(argv
)
73 ProxGuiQT::~ProxGuiQT(void)
87 void ProxWidget::paintEvent(QPaintEvent
*event
)
89 QPainter
painter(this);
90 QPainterPath penPath
, whitePath
, greyPath
, lightgreyPath
, cursorAPath
, cursorBPath
;
92 QBrush
brush(QColor(100, 255, 100));
93 QPen
pen(QColor(100, 255, 100));
95 painter
.setFont(QFont("Arial", 10));
101 if (CursorAPos
> GraphTraceLen
)
103 if(CursorBPos
> GraphTraceLen
)
108 painter
.fillRect(r
, QColor(0, 0, 0));
110 whitePath
.moveTo(r
.left() + 40, r
.top());
111 whitePath
.lineTo(r
.left() + 40, r
.bottom());
113 int zeroHeight
= r
.top() + (r
.bottom() - r
.top()) / 2;
115 greyPath
.moveTo(r
.left(), zeroHeight
);
116 greyPath
.lineTo(r
.right(), zeroHeight
);
117 painter
.setPen(QColor(100, 100, 100));
118 painter
.drawPath(greyPath
);
120 // plot X and Y grid lines
122 if ((PlotGridX
> 0) && ((PlotGridX
* GraphPixelsPerPoint
) > 1)) {
123 for(i
= 40; i
< r
.right(); i
+= (int)(PlotGridX
* GraphPixelsPerPoint
)) {
124 //SelectObject(hdc, GreyPenLite);
125 //MoveToEx(hdc, r.left + i, r.top, NULL);
126 //LineTo(hdc, r.left + i, r.bottom);
127 lightgreyPath
.moveTo(r
.left()+i
,r
.top());
128 lightgreyPath
.lineTo(r
.left()+i
,r
.bottom());
129 painter
.drawPath(lightgreyPath
);
132 if ((PlotGridY
> 0) && ((PlotGridY
* GraphPixelsPerPoint
) > 1)){
133 for(i
= 0; i
< ((r
.top() + r
.bottom())>>1); i
+= (int)(PlotGridY
* GraphPixelsPerPoint
)) {
134 lightgreyPath
.moveTo(r
.left() + 40,zeroHeight
+ i
);
135 lightgreyPath
.lineTo(r
.right(),zeroHeight
+ i
);
136 painter
.drawPath(lightgreyPath
);
137 lightgreyPath
.moveTo(r
.left() + 40,zeroHeight
- i
);
138 lightgreyPath
.lineTo(r
.right(),zeroHeight
- i
);
139 painter
.drawPath(lightgreyPath
);
144 (GraphTraceLen
- (int)((r
.right() - r
.left() - 40) / GraphPixelsPerPoint
));
148 if(GraphStart
> startMax
) {
149 GraphStart
= startMax
;
154 for(i
= GraphStart
; ; i
++) {
155 if(i
>= GraphTraceLen
) {
158 if(fabs((double)GraphBuffer
[i
]) > absYMax
) {
159 absYMax
= (int)fabs((double)GraphBuffer
[i
]);
161 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
167 absYMax
= (int)(absYMax
*1.2 + 1);
169 // number of points that will be plotted
170 int span
= (int)((r
.right() - r
.left()) / GraphPixelsPerPoint
);
171 // one label every 100 pixels, let us say
172 int labels
= (r
.right() - r
.left() - 40) / 100;
173 if(labels
<= 0) labels
= 1;
174 int pointsPerLabel
= span
/ labels
;
175 if(pointsPerLabel
<= 0) pointsPerLabel
= 1;
182 for(i
= GraphStart
; ; i
++) {
183 if(i
>= GraphTraceLen
) {
186 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
187 if(x
> r
.right() + GraphPixelsPerPoint
) {
191 int y
= GraphBuffer
[i
];
201 y
= (y
* (r
.top() - r
.bottom()) / (2*absYMax
)) + zeroHeight
;
202 if(i
== GraphStart
) {
203 penPath
.moveTo(x
, y
);
205 penPath
.lineTo(x
, y
);
208 if(GraphPixelsPerPoint
> 10) {
209 QRect
f(QPoint(x
- 3, y
- 3),QPoint(x
+ 3, y
+ 3));
210 painter
.fillRect(f
, brush
);
213 if(((i
- GraphStart
) % pointsPerLabel
== 0) && i
!= GraphStart
) {
214 whitePath
.moveTo(x
, zeroHeight
- 3);
215 whitePath
.lineTo(x
, zeroHeight
+ 3);
218 sprintf(str
, "+%d", (i
- GraphStart
));
220 painter
.setPen(QColor(255, 255, 255));
222 QFontMetrics
metrics(painter
.font());
223 size
= metrics
.boundingRect(str
);
224 painter
.drawText(x
- (size
.right() - size
.left()), zeroHeight
+ 9, str
);
229 if(i
== CursorAPos
|| i
== CursorBPos
) {
230 QPainterPath
*cursorPath
;
232 if(i
== CursorAPos
) {
233 cursorPath
= &cursorAPath
;
235 cursorPath
= &cursorBPath
;
237 cursorPath
->moveTo(x
, r
.top());
238 cursorPath
->lineTo(x
, r
.bottom());
239 penPath
.moveTo(x
, y
);
247 painter
.setPen(QColor(255, 255, 255));
248 painter
.drawPath(whitePath
);
250 painter
.drawPath(penPath
);
251 painter
.setPen(QColor(255, 255, 0));
252 painter
.drawPath(cursorAPath
);
253 painter
.setPen(QColor(255, 0, 255));
254 painter
.drawPath(cursorBPath
);
257 sprintf(str
, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f] zoom=%.3f CursorA=%d [%d] CursorB=%d [%d]",
258 GraphStart
, yMax
, yMin
, yMean
, n
, GraphTraceLen
,
259 CursorBPos
- CursorAPos
, (CursorBPos
- CursorAPos
)/CursorScaleFactor
,GraphPixelsPerPoint
,CursorAPos
,GraphBuffer
[CursorAPos
],CursorBPos
,GraphBuffer
[CursorBPos
]);
261 painter
.setPen(QColor(255, 255, 255));
262 painter
.drawText(50, r
.bottom() - 20, str
);
265 ProxWidget::ProxWidget(QWidget
*parent
) : QWidget(parent
), GraphStart(0), GraphPixelsPerPoint(1)
269 QPalette
palette(QColor(0,0,0,0));
270 palette
.setColor(QPalette::WindowText
, QColor(255,255,255));
271 palette
.setColor(QPalette::Text
, QColor(255,255,255));
272 palette
.setColor(QPalette::Button
, QColor(100, 100, 100));
274 setAutoFillBackground(true);
277 void ProxWidget::closeEvent(QCloseEvent
*event
)
283 void ProxWidget::mouseMoveEvent(QMouseEvent
*event
)
287 x
= (int)(x
/ GraphPixelsPerPoint
);
289 if((event
->buttons() & Qt::LeftButton
)) {
291 } else if (event
->buttons() & Qt::RightButton
) {
299 void ProxWidget::keyPressEvent(QKeyEvent
*event
)
301 switch(event
->key()) {
303 if(GraphPixelsPerPoint
<= 50) {
304 GraphPixelsPerPoint
*= 2;
309 if(GraphPixelsPerPoint
>= 0.02) {
310 GraphPixelsPerPoint
/= 2;
315 if(GraphPixelsPerPoint
< 20) {
316 GraphStart
+= (int)(20 / GraphPixelsPerPoint
);
323 if(GraphPixelsPerPoint
< 20) {
324 GraphStart
-= (int)(20 / GraphPixelsPerPoint
);
331 QWidget::keyPressEvent(event
);