]>
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));
102 painter
.fillRect(r
, QColor(0, 0, 0));
104 whitePath
.moveTo(r
.left() + 40, r
.top());
105 whitePath
.lineTo(r
.left() + 40, r
.bottom());
107 int zeroHeight
= r
.top() + (r
.bottom() - r
.top()) / 2;
109 greyPath
.moveTo(r
.left(), zeroHeight
);
110 greyPath
.lineTo(r
.right(), zeroHeight
);
111 painter
.setPen(QColor(100, 100, 100));
112 painter
.drawPath(greyPath
);
115 (GraphTraceLen
- (int)((r
.right() - r
.left() - 40) / GraphPixelsPerPoint
));
119 if(GraphStart
> startMax
) {
120 GraphStart
= startMax
;
126 for(i
= GraphStart
; ; i
++) {
127 if(i
>= GraphTraceLen
) {
130 if(fabs((double)GraphBuffer
[i
]) > absYMax
) {
131 absYMax
= (int)fabs((double)GraphBuffer
[i
]);
133 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
139 absYMax
= (int)(absYMax
*1.2 + 1);
141 // number of points that will be plotted
142 int span
= (int)((r
.right() - r
.left()) / GraphPixelsPerPoint
);
143 // one label every 100 pixels, let us say
144 int labels
= (r
.right() - r
.left() - 40) / 100;
145 if(labels
<= 0) labels
= 1;
146 int pointsPerLabel
= span
/ labels
;
147 if(pointsPerLabel
<= 0) pointsPerLabel
= 1;
154 for(i
= GraphStart
; ; i
++) {
155 if(i
>= GraphTraceLen
) {
158 int x
= 40 + (int)((i
- GraphStart
)*GraphPixelsPerPoint
);
159 if(x
> r
.right() + GraphPixelsPerPoint
) {
163 int y
= GraphBuffer
[i
];
173 y
= (y
* (r
.top() - r
.bottom()) / (2*absYMax
)) + zeroHeight
;
174 if(i
== GraphStart
) {
175 penPath
.moveTo(x
, y
);
177 penPath
.lineTo(x
, y
);
180 if(GraphPixelsPerPoint
> 10) {
181 QRect
f(QPoint(x
- 3, y
- 3),QPoint(x
+ 3, y
+ 3));
182 painter
.fillRect(f
, brush
);
185 if(((i
- GraphStart
) % pointsPerLabel
== 0) && i
!= GraphStart
) {
186 whitePath
.moveTo(x
, zeroHeight
- 3);
187 whitePath
.lineTo(x
, zeroHeight
+ 3);
190 sprintf(str
, "+%d", (i
- GraphStart
));
192 painter
.setPen(QColor(255, 255, 255));
194 QFontMetrics
metrics(painter
.font());
195 size
= metrics
.boundingRect(str
);
196 painter
.drawText(x
- (size
.right() - size
.left()), zeroHeight
+ 9, str
);
201 if(i
== CursorAPos
|| i
== CursorBPos
) {
202 QPainterPath
*cursorPath
;
204 if(i
== CursorAPos
) {
205 cursorPath
= &cursorAPath
;
207 cursorPath
= &cursorBPath
;
209 cursorPath
->moveTo(x
, r
.top());
210 cursorPath
->lineTo(x
, r
.bottom());
211 penPath
.moveTo(x
, y
);
219 painter
.setPen(QColor(255, 255, 255));
220 painter
.drawPath(whitePath
);
222 painter
.drawPath(penPath
);
223 painter
.setPen(QColor(255, 255, 0));
224 painter
.drawPath(cursorAPath
);
225 painter
.setPen(QColor(255, 0, 255));
226 painter
.drawPath(cursorBPath
);
229 sprintf(str
, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f]",
230 GraphStart
, yMax
, yMin
, yMean
, n
, GraphTraceLen
,
231 CursorBPos
- CursorAPos
, (CursorBPos
- CursorAPos
)/CursorScaleFactor
);
233 painter
.setPen(QColor(255, 255, 255));
234 painter
.drawText(50, r
.bottom() - 20, str
);
237 ProxWidget::ProxWidget(QWidget
*parent
) : QWidget(parent
), GraphStart(0), GraphPixelsPerPoint(1)
241 QPalette
palette(QColor(0,0,0,0));
242 palette
.setColor(QPalette::WindowText
, QColor(255,255,255));
243 palette
.setColor(QPalette::Text
, QColor(255,255,255));
244 palette
.setColor(QPalette::Button
, QColor(100, 100, 100));
246 setAutoFillBackground(true);
249 void ProxWidget::closeEvent(QCloseEvent
*event
)
255 void ProxWidget::mouseMoveEvent(QMouseEvent
*event
)
259 x
= (int)(x
/ GraphPixelsPerPoint
);
261 if((event
->buttons() & Qt::LeftButton
)) {
263 } else if (event
->buttons() & Qt::RightButton
) {
271 void ProxWidget::keyPressEvent(QKeyEvent
*event
)
273 switch(event
->key()) {
275 if(GraphPixelsPerPoint
<= 50) {
276 GraphPixelsPerPoint
*= 2;
281 if(GraphPixelsPerPoint
>= 0.02) {
282 GraphPixelsPerPoint
/= 2;
287 if(GraphPixelsPerPoint
< 20) {
288 GraphStart
+= (int)(20 / GraphPixelsPerPoint
);
295 if(GraphPixelsPerPoint
< 20) {
296 GraphStart
-= (int)(20 / GraphPixelsPerPoint
);
303 QWidget::keyPressEvent(event
);