]>
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
, 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
);
120 (GraphTraceLen
- (int)((r
.right() - r
.left() - 40) / GraphPixelsPerPoint
));
124 if(GraphStart
> startMax
) {
125 GraphStart
= startMax
;
131 for(i
= GraphStart
; ; i
++) {
132 if(i
>= GraphTraceLen
) {
135 if(fabs((double)GraphBuffer
[i
]) > absYMax
) {
136 absYMax
= (int)fabs((double)GraphBuffer
[i
]);
138 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
144 absYMax
= (int)(absYMax
*1.2 + 1);
146 // number of points that will be plotted
147 int span
= (int)((r
.right() - r
.left()) / GraphPixelsPerPoint
);
148 // one label every 100 pixels, let us say
149 int labels
= (r
.right() - r
.left() - 40) / 100;
150 if(labels
<= 0) labels
= 1;
151 int pointsPerLabel
= span
/ labels
;
152 if(pointsPerLabel
<= 0) pointsPerLabel
= 1;
159 for(i
= GraphStart
; ; i
++) {
160 if(i
>= GraphTraceLen
) {
163 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
164 if(x
> r
.right() + GraphPixelsPerPoint
) {
168 int y
= GraphBuffer
[i
];
178 y
= (y
* (r
.top() - r
.bottom()) / (2*absYMax
)) + zeroHeight
;
179 if(i
== GraphStart
) {
180 penPath
.moveTo(x
, y
);
182 penPath
.lineTo(x
, y
);
185 if(GraphPixelsPerPoint
> 10) {
186 QRect
f(QPoint(x
- 3, y
- 3),QPoint(x
+ 3, y
+ 3));
187 painter
.fillRect(f
, brush
);
190 if(((i
- GraphStart
) % pointsPerLabel
== 0) && i
!= GraphStart
) {
191 whitePath
.moveTo(x
, zeroHeight
- 3);
192 whitePath
.lineTo(x
, zeroHeight
+ 3);
195 sprintf(str
, "+%d", (i
- GraphStart
));
197 painter
.setPen(QColor(255, 255, 255));
199 QFontMetrics
metrics(painter
.font());
200 size
= metrics
.boundingRect(str
);
201 painter
.drawText(x
- (size
.right() - size
.left()), zeroHeight
+ 9, str
);
206 if(i
== CursorAPos
|| i
== CursorBPos
) {
207 QPainterPath
*cursorPath
;
209 if(i
== CursorAPos
) {
210 cursorPath
= &cursorAPath
;
212 cursorPath
= &cursorBPath
;
214 cursorPath
->moveTo(x
, r
.top());
215 cursorPath
->lineTo(x
, r
.bottom());
216 penPath
.moveTo(x
, y
);
224 painter
.setPen(QColor(255, 255, 255));
225 painter
.drawPath(whitePath
);
227 painter
.drawPath(penPath
);
228 painter
.setPen(QColor(255, 255, 0));
229 painter
.drawPath(cursorAPath
);
230 painter
.setPen(QColor(255, 0, 255));
231 painter
.drawPath(cursorBPath
);
234 sprintf(str
, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f] zoom=%.3f CursorA=%d CursorB=%d",
235 GraphStart
, yMax
, yMin
, yMean
, n
, GraphTraceLen
,
236 CursorBPos
- CursorAPos
, (CursorBPos
- CursorAPos
)/CursorScaleFactor
,GraphPixelsPerPoint
,CursorAPos
,CursorBPos
);
238 painter
.setPen(QColor(255, 255, 255));
239 painter
.drawText(50, r
.bottom() - 20, str
);
242 ProxWidget::ProxWidget(QWidget
*parent
) : QWidget(parent
), GraphStart(0), GraphPixelsPerPoint(1)
246 QPalette
palette(QColor(0,0,0,0));
247 palette
.setColor(QPalette::WindowText
, QColor(255,255,255));
248 palette
.setColor(QPalette::Text
, QColor(255,255,255));
249 palette
.setColor(QPalette::Button
, QColor(100, 100, 100));
251 setAutoFillBackground(true);
254 void ProxWidget::closeEvent(QCloseEvent
*event
)
260 void ProxWidget::mouseMoveEvent(QMouseEvent
*event
)
264 x
= (int)(x
/ GraphPixelsPerPoint
);
266 if((event
->buttons() & Qt::LeftButton
)) {
268 } else if (event
->buttons() & Qt::RightButton
) {
276 void ProxWidget::keyPressEvent(QKeyEvent
*event
)
278 switch(event
->key()) {
280 if(GraphPixelsPerPoint
<= 50) {
281 GraphPixelsPerPoint
*= 2;
286 if(GraphPixelsPerPoint
>= 0.02) {
287 GraphPixelsPerPoint
/= 2;
292 if(GraphPixelsPerPoint
< 20) {
293 GraphStart
+= (int)(20 / GraphPixelsPerPoint
);
300 if(GraphPixelsPerPoint
< 20) {
301 GraphStart
-= (int)(20 / GraphPixelsPerPoint
);
308 QWidget::keyPressEvent(event
);