ab0976cceb4442e3b157bbc1403ff1b18721329a
[proxmark3-svn] / client / proxguiqt.cpp
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // GUI (QT)
9 //-----------------------------------------------------------------------------
10 #include "proxguiqt.h"
11
12 #include <stdbool.h>
13 #include <iostream>
14 #include <QPainterPath>
15 #include <QBrush>
16 #include <QPen>
17 #include <QTimer>
18 #include <QCloseEvent>
19 #include <QMouseEvent>
20 #include <QKeyEvent>
21 #include <math.h>
22 #include <limits.h>
23 #include <stdio.h>
24 #include <QSlider>
25 #include <QHBoxLayout>
26 #include <string.h>
27 #include "proxgui.h"
28 #include <QtGui>
29 //#include <ctime>
30
31 bool g_useOverlays = false;
32 int g_absVMax = 0;
33 int startMax;
34 int PageWidth;
35 int unlockStart = 0;
36
37 void ProxGuiQT::ShowGraphWindow(void)
38 {
39 emit ShowGraphWindowSignal();
40 }
41
42 void ProxGuiQT::RepaintGraphWindow(void)
43 {
44 emit RepaintGraphWindowSignal();
45 }
46
47 void ProxGuiQT::HideGraphWindow(void)
48 {
49 emit HideGraphWindowSignal();
50 }
51
52 void ProxGuiQT::Exit(void)
53 {
54 emit ExitSignal();
55 }
56
57 void ProxGuiQT::_ShowGraphWindow(void)
58 {
59 if(!plotapp)
60 return;
61
62 if (!plotwidget)
63 plotwidget = new ProxWidget();
64
65 plotwidget->show();
66 }
67
68 void ProxGuiQT::_RepaintGraphWindow(void)
69 {
70 if (!plotapp || !plotwidget)
71 return;
72
73 plotwidget->update();
74 }
75
76 void ProxGuiQT::_HideGraphWindow(void)
77 {
78 if (!plotapp || !plotwidget)
79 return;
80
81 plotwidget->hide();
82 }
83
84 void ProxGuiQT::_Exit(void) {
85 delete this;
86 }
87
88 void ProxGuiQT::_StartProxmarkThread(void) {
89 if (!proxmarkThread)
90 return;
91
92 // if thread finished delete self and delete application
93 QObject::connect(proxmarkThread, SIGNAL(finished()), proxmarkThread, SLOT(deleteLater()));
94 QObject::connect(proxmarkThread, SIGNAL(finished()), this, SLOT(_Exit()));
95 // start proxmark thread
96 proxmarkThread->start();
97 }
98
99 void ProxGuiQT::MainLoop()
100 {
101 plotapp = new QApplication(argc, argv);
102
103 connect(this, SIGNAL(ShowGraphWindowSignal()), this, SLOT(_ShowGraphWindow()));
104 connect(this, SIGNAL(RepaintGraphWindowSignal()), this, SLOT(_RepaintGraphWindow()));
105 connect(this, SIGNAL(HideGraphWindowSignal()), this, SLOT(_HideGraphWindow()));
106 connect(this, SIGNAL(ExitSignal()), this, SLOT(_Exit()));
107
108 //start proxmark thread after starting event loop
109 QTimer::singleShot(200, this, SLOT(_StartProxmarkThread()));
110
111 plotapp->exec();
112 }
113
114 ProxGuiQT::ProxGuiQT(int argc, char **argv, WorkerThread *wthread) : plotapp(NULL), plotwidget(NULL),
115 argc(argc), argv(argv), proxmarkThread(wthread)
116 {
117 }
118
119 ProxGuiQT::~ProxGuiQT(void)
120 {
121 //if (plotwidget) {
122 //plotwidget->destroy(true,true);
123 // delete plotwidget;
124 // plotwidget = NULL;
125 //}
126 if (plotapp) {
127 plotapp->quit();
128 // delete plotapp;
129 plotapp = NULL;
130 }
131 }
132
133 //--------------------
134 void ProxWidget::applyOperation()
135 {
136 //printf("ApplyOperation()");
137 save_restoreGB(GRAPH_SAVE);
138 memcpy(GraphBuffer, s_Buff, sizeof(int) * GraphTraceLen);
139 RepaintGraphWindow();
140 }
141 void ProxWidget::stickOperation()
142 {
143 save_restoreGB(GRAPH_RESTORE);
144 //printf("stickOperation()");
145 }
146 void ProxWidget::vchange_autocorr(int v)
147 {
148 int ans;
149 ans = AutoCorrelate(GraphBuffer, s_Buff, GraphTraceLen, v, true, false);
150 if (g_debugMode) printf("vchange_autocorr(w:%d): %d\n", v, ans);
151 g_useOverlays = true;
152 RepaintGraphWindow();
153 }
154 void ProxWidget::vchange_askedge(int v)
155 {
156 int ans;
157 //extern int AskEdgeDetect(const int *in, int *out, int len, int threshold);
158 ans = AskEdgeDetect(GraphBuffer, s_Buff, GraphTraceLen, v);
159 if (g_debugMode) printf("vchange_askedge(w:%d)%d\n", v, ans);
160 g_useOverlays = true;
161 RepaintGraphWindow();
162 }
163 void ProxWidget::vchange_dthr_up(int v)
164 {
165 int down = opsController->horizontalSlider_dirthr_down->value();
166 directionalThreshold(GraphBuffer, s_Buff, GraphTraceLen, v, down);
167 //printf("vchange_dthr_up(%d)", v);
168 g_useOverlays = true;
169 RepaintGraphWindow();
170 }
171 void ProxWidget::vchange_dthr_down(int v)
172 {
173 //printf("vchange_dthr_down(%d)", v);
174 int up = opsController->horizontalSlider_dirthr_up->value();
175 directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, up);
176 g_useOverlays = true;
177 RepaintGraphWindow();
178 }
179 ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent)
180 {
181 this->master = master;
182 resize(800,500);
183
184 /** Setup the controller widget **/
185
186 controlWidget = new QWidget();
187 opsController = new Ui::Form();
188 opsController->setupUi(controlWidget);
189 //Due to quirks in QT Designer, we need to fiddle a bit
190 opsController->horizontalSlider_dirthr_down->setMinimum(-128);
191 opsController->horizontalSlider_dirthr_down->setMaximum(0);
192 opsController->horizontalSlider_dirthr_down->setValue(-20);
193 opsController->horizontalSlider_dirthr_up->setMinimum(-40);
194 opsController->horizontalSlider_dirthr_up->setMaximum(128);
195 opsController->horizontalSlider_dirthr_up->setValue(20);
196 opsController->horizontalSlider_askedge->setValue(25);
197 opsController->horizontalSlider_window->setValue(4000);
198
199
200 QObject::connect(opsController->pushButton_apply, SIGNAL(clicked()), this, SLOT(applyOperation()));
201 QObject::connect(opsController->pushButton_sticky, SIGNAL(clicked()), this, SLOT(stickOperation()));
202 QObject::connect(opsController->horizontalSlider_window, SIGNAL(valueChanged(int)), this, SLOT(vchange_autocorr(int)));
203 QObject::connect(opsController->horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_up(int)));
204 QObject::connect(opsController->horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_down(int)));
205 QObject::connect(opsController->horizontalSlider_askedge, SIGNAL(valueChanged(int)), this, SLOT(vchange_askedge(int)));
206
207 controlWidget->show();
208
209 // Set up the plot widget, which does the actual plotting
210
211 plot = new Plot(this);
212 /*
213 QSlider* slider = new QSlider(Qt::Horizontal);
214 slider->setFocusPolicy(Qt::StrongFocus);
215 slider->setTickPosition(QSlider::TicksBothSides);
216 slider->setTickInterval(10);
217 slider->setSingleStep(1);
218 */
219 QVBoxLayout *layout = new QVBoxLayout;
220 //layout->addWidget(slider);
221 layout->addWidget(plot);
222 setLayout(layout);
223 //printf("Proxwidget Constructor just set layout\r\n");
224 }
225
226 // not 100% sure what i need in this block
227 // feel free to fix - marshmellow...
228 ProxWidget::~ProxWidget(void)
229 {
230 if (controlWidget) {
231 controlWidget->close();
232 delete controlWidget;
233 controlWidget = NULL;
234 }
235
236 if (opsController) {
237 delete opsController;
238 opsController = NULL;
239 }
240
241 if (plot) {
242 plot->close();
243 delete plot;
244 plot = NULL;
245 }
246 }
247 void ProxWidget::closeEvent(QCloseEvent *event)
248 {
249 event->ignore();
250 this->hide();
251 g_useOverlays = false;
252 }
253 void ProxWidget::hideEvent(QHideEvent *event) {
254 controlWidget->hide();
255 plot->hide();
256 }
257 void ProxWidget::showEvent(QShowEvent *event) {
258 controlWidget->show();
259 plot->show();
260 }
261
262 //----------- Plotting
263
264 int Plot::xCoordOf(int i, QRect r )
265 {
266 return r.left() + (int)((i - GraphStart)*GraphPixelsPerPoint);
267 }
268
269 int Plot::yCoordOf(int v, QRect r, int maxVal)
270 {
271 int z = (r.bottom() - r.top())/2;
272 if ( maxVal == 0 ) maxVal++;
273 return -(z * v) / maxVal + z;
274 }
275
276 int Plot::valueOf_yCoord(int y, QRect r, int maxVal)
277 {
278 int z = (r.bottom() - r.top())/2;
279 return (y-z) * maxVal / z;
280 }
281 static const QColor GREEN = QColor(100,255,100);
282 static const QColor RED = QColor(255,100,100);
283 static const QColor BLUE = QColor(100,100,255);
284 static const QColor GRAY = QColor(240,240,240);
285
286 QColor Plot::getColor(int graphNum)
287 {
288 switch (graphNum) {
289 case 0: return GREEN; //Green
290 case 1: return RED; //Red
291 case 2: return BLUE; //Blue
292 default: return GRAY; //Gray
293 }
294 }
295
296 void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect)
297 {
298 if (len == 0) return;
299 startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint));
300 if(startMax < 0) {
301 startMax = 0;
302 }
303 if(GraphStart > startMax) {
304 GraphStart = startMax;
305 }
306 if (GraphStart > len) return;
307 int vMin = INT_MAX, vMax = INT_MIN, v = 0;
308 int sample_index = GraphStart ;
309 for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) {
310
311 v = buffer[sample_index];
312 if(v < vMin) vMin = v;
313 if(v > vMax) vMax = v;
314 }
315
316 g_absVMax = 0;
317 if(fabs( (double) vMin) > g_absVMax) g_absVMax = (int)fabs( (double) vMin);
318 if(fabs( (double) vMax) > g_absVMax) g_absVMax = (int)fabs( (double) vMax);
319 g_absVMax = (int)(g_absVMax*1.25 + 1);
320 }
321
322 void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset)
323 {
324 if (len == 0 || PlotGridX <= 0) return;
325 //clock_t begin = clock();
326 QPainterPath penPath;
327
328 int grid_delta_x = PlotGridX;
329 int first_delta_x = grid_delta_x; //(plotOffset > 0) ? PlotGridX : (PlotGridX +);
330 if (GraphStart > plotOffset) first_delta_x -= (GraphStart-plotOffset);
331 int DemodStart = GraphStart;
332 if (plotOffset > GraphStart) DemodStart = plotOffset;
333
334 int BitStart = 0;
335 // round down
336 if (DemodStart-plotOffset > 0) BitStart = (int)(((DemodStart-plotOffset)+(PlotGridX-1))/PlotGridX)-1;
337 first_delta_x += BitStart * PlotGridX;
338 if (BitStart > (int)len) return;
339 int delta_x = 0;
340 int v = 0;
341 //printf("first_delta_x %i, grid_delta_x %i, DemodStart %i, BitStart %i\n",first_delta_x,grid_delta_x,DemodStart, BitStart);
342
343 painter->setPen(getColor(graphNum));
344 char str[5];
345 int absVMax = (int)(100*1.05+1);
346 int x = xCoordOf(DemodStart, plotRect);
347 int y = yCoordOf((buffer[BitStart]*200-100)*-1,plotRect,absVMax);
348 penPath.moveTo(x, y);
349 delta_x = 0;
350 int clk = first_delta_x;
351 for(int i = BitStart; i < (int)len && xCoordOf(delta_x+DemodStart, plotRect) < plotRect.right(); i++) {
352 for (int ii = 0; ii < (clk) && i < (int)len && xCoordOf(DemodStart+delta_x+ii, plotRect) < plotRect.right() ; ii++ ) {
353 x = xCoordOf(DemodStart+delta_x+ii, plotRect);
354 v = buffer[i]*200-100;
355
356 y = yCoordOf( v, plotRect, absVMax);
357
358 penPath.lineTo(x, y);
359
360 if(GraphPixelsPerPoint > 10) {
361 QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
362 painter->fillRect(f, QColor(100, 255, 100));
363 }
364 if (ii == (int)clk/2) {
365 //print label
366 sprintf(str, "%u",buffer[i]);
367 painter->drawText(x-8, y + ((buffer[i] > 0) ? 18 : -6), str);
368 }
369 }
370 delta_x += clk;
371 clk = grid_delta_x;
372 }
373
374 //Graph annotations
375 painter->drawPath(penPath);
376 }
377
378 void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum)
379 {
380 if (len == 0) return;
381 //clock_t begin = clock();
382 QPainterPath penPath;
383 int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, i = 0;
384 int x = xCoordOf(GraphStart, plotRect);
385 int y = yCoordOf(buffer[GraphStart],plotRect,g_absVMax);
386 penPath.moveTo(x, y);
387 for(i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) {
388
389 x = xCoordOf(i, plotRect);
390 v = buffer[i];
391
392 y = yCoordOf( v, plotRect, g_absVMax);
393
394 penPath.lineTo(x, y);
395
396 if(GraphPixelsPerPoint > 10) {
397 QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
398 painter->fillRect(f, QColor(100, 255, 100));
399 }
400 //catch stats
401 if(v < vMin) vMin = v;
402 if(v > vMax) vMax = v;
403 vMean += v;
404 }
405 vMean /= (i - GraphStart);
406
407 painter->setPen(getColor(graphNum));
408
409 //Draw y-axis
410 int xo = 5+(graphNum*40);
411 painter->drawLine(xo, plotRect.top(),xo, plotRect.bottom());
412
413 int vMarkers = (g_absVMax - (g_absVMax % 10)) / 5;
414 int minYDist = 40; //Minimum pixel-distance between markers
415
416 char yLbl[20];
417
418 int n = 0;
419 int lasty0 = 65535;
420
421 for(v = vMarkers; yCoordOf(v,plotRect,g_absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++)
422 {
423 int y0 = yCoordOf(v,plotRect,g_absVMax);
424 int y1 = yCoordOf(-v,plotRect,g_absVMax);
425
426 if(lasty0 - y0 < minYDist) continue;
427
428 painter->drawLine(xo-5,y0, xo+5, y0);
429
430 sprintf(yLbl, "%d", v);
431 painter->drawText(xo+8,y0+7,yLbl);
432
433 painter->drawLine(xo-5, y1, xo+5, y1);
434 sprintf(yLbl, "%d",-v);
435 painter->drawText(xo+8, y1+5 , yLbl);
436 lasty0 = y0;
437 }
438
439 //Graph annotations
440 painter->drawPath(penPath);
441 char str[200];
442 sprintf(str, "max=%d min=%d mean=%d n=%d/%d CursorAVal=[%d] CursorBVal=[%d]",
443 vMax, vMin, vMean, i, len, buffer[CursorAPos], buffer[CursorBPos]);
444 painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str);
445
446 //clock_t end = clock();
447 //double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
448 //printf("Plot time %f\n", elapsed_secs);
449 }
450
451 void Plot::plotGridLines(QPainter* painter,QRect r)
452 {
453 // set GridOffset
454 if (PlotGridX <= 0) return;
455 int offset = GridOffset;
456 if (GridLocked && PlotGridX) {
457 offset = GridOffset + PlotGridX - (GraphStart % PlotGridX);
458 } else if (!GridLocked && GraphStart > 0 && PlotGridX) {
459 offset = PlotGridX-((GraphStart - offset) % PlotGridX) + GraphStart - unlockStart;
460 }
461 offset %= PlotGridX;
462 if (offset < 0) offset += PlotGridX;
463
464 int i;
465 int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint);
466 int grid_delta_y = PlotGridY;
467 if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
468 for(i = (offset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) {
469 painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom());
470 }
471 }
472 if (PlotGridY > 0) {
473 for(i = 0; yCoordOf(i,r,g_absVMax) > r.top(); i += grid_delta_y) {
474 painter->drawLine( r.left(), yCoordOf(i,r,g_absVMax), r.right(), yCoordOf(i,r,g_absVMax) );
475 painter->drawLine( r.left(), yCoordOf(i*-1,r,g_absVMax), r.right(), yCoordOf(i*-1,r,g_absVMax) );
476 }
477 }
478 }
479
480 #define HEIGHT_INFO 60
481 #define WIDTH_AXES 80
482
483 void Plot::paintEvent(QPaintEvent *event)
484 {
485
486 QPainter painter(this);
487 QBrush brush(QColor(100, 255, 100));
488 QPen pen(QColor(100, 255, 100));
489
490 painter.setFont(QFont("Courier New", 10));
491
492 if(GraphStart < 0) {
493 GraphStart = 0;
494 }
495
496 if (CursorAPos > GraphTraceLen)
497 CursorAPos= 0;
498 if(CursorBPos > GraphTraceLen)
499 CursorBPos= 0;
500 if(CursorCPos > GraphTraceLen)
501 CursorCPos= 0;
502 if(CursorDPos > GraphTraceLen)
503 CursorDPos= 0;
504
505 QRect plotRect(WIDTH_AXES, 0, width()-WIDTH_AXES, height()-HEIGHT_INFO);
506 QRect infoRect(0, height()-HEIGHT_INFO, width(), HEIGHT_INFO);
507
508 //Grey background
509 painter.fillRect(rect(), QColor(60, 60, 60));
510 //Black foreground
511 painter.fillRect(plotRect, QColor(0, 0, 0));
512
513 //init graph variables
514 setMaxAndStart(GraphBuffer,GraphTraceLen,plotRect);
515
516 // center line
517 int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2;
518 painter.setPen(QColor(100, 100, 100));
519 painter.drawLine(plotRect.left(), zeroHeight, plotRect.right(), zeroHeight);
520 // plot X and Y grid lines
521 plotGridLines(&painter, plotRect);
522
523 //Start painting graph
524 PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0);
525 if (showDemod && DemodBufferLen > 8) {
526 PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx);
527 }
528 if (g_useOverlays) {
529 //init graph variables
530 setMaxAndStart(s_Buff,GraphTraceLen,plotRect);
531 PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1);
532 }
533 // End graph drawing
534
535 //Draw the cursors
536 if(CursorAPos > GraphStart && xCoordOf(CursorAPos, plotRect) < plotRect.right())
537 {
538 painter.setPen(QColor(255, 255, 0));
539 painter.drawLine(xCoordOf(CursorAPos, plotRect),plotRect.top(),xCoordOf(CursorAPos, plotRect),plotRect.bottom());
540 }
541 if(CursorBPos > GraphStart && xCoordOf(CursorBPos, plotRect) < plotRect.right())
542 {
543 painter.setPen(QColor(255, 0, 255));
544 painter.drawLine(xCoordOf(CursorBPos, plotRect),plotRect.top(),xCoordOf(CursorBPos, plotRect),plotRect.bottom());
545 }
546 if(CursorCPos > GraphStart && xCoordOf(CursorCPos, plotRect) < plotRect.right())
547 {
548 painter.setPen(QColor(255, 153, 0)); //orange
549 painter.drawLine(xCoordOf(CursorCPos, plotRect),plotRect.top(),xCoordOf(CursorCPos, plotRect),plotRect.bottom());
550 }
551 if(CursorDPos > GraphStart && xCoordOf(CursorDPos, plotRect) < plotRect.right())
552 {
553 painter.setPen(QColor(0, 0, 205)); //light blue
554 painter.drawLine(xCoordOf(CursorDPos, plotRect),plotRect.top(),xCoordOf(CursorDPos, plotRect),plotRect.bottom());
555 }
556
557 //Draw annotations
558 char str[200];
559 sprintf(str, "@%d dt=%d [%2.2f] zoom=%2.2f CursorAPos=%d CursorBPos=%d GridX=%d GridY=%d (%s) GridXoffset=%d",
560 GraphStart, CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor,
561 GraphPixelsPerPoint,CursorAPos,CursorBPos,PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked",GridOffset);
562 painter.setPen(QColor(255, 255, 255));
563 painter.drawText(20, infoRect.bottom() - 3, str);
564
565 }
566
567 Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1)
568 {
569 //Need to set this, otherwise we don't receive keypress events
570 setFocusPolicy( Qt::StrongFocus);
571 resize(600, 300);
572
573 QPalette palette(QColor(0,0,0,0));
574 palette.setColor(QPalette::WindowText, QColor(255,255,255));
575 palette.setColor(QPalette::Text, QColor(255,255,255));
576 palette.setColor(QPalette::Button, QColor(100, 100, 100));
577 setPalette(palette);
578 setAutoFillBackground(true);
579 CursorAPos = 0;
580 CursorBPos = 0;
581
582 setWindowTitle(tr("Sliders"));
583
584 master = parent;
585 }
586
587 void Plot::closeEvent(QCloseEvent *event)
588 {
589 event->ignore();
590 this->hide();
591 g_useOverlays = false;
592 }
593
594 void Plot::mouseMoveEvent(QMouseEvent *event)
595 {
596 int x = event->x();
597 x -= WIDTH_AXES;
598 x = (int)(x / GraphPixelsPerPoint);
599 x += GraphStart;
600 if((event->buttons() & Qt::LeftButton)) {
601 CursorAPos = x;
602 } else if (event->buttons() & Qt::RightButton) {
603 CursorBPos = x;
604 }
605
606
607 this->update();
608 }
609
610 void Plot::keyPressEvent(QKeyEvent *event)
611 {
612 int offset;
613
614 if(event->modifiers() & Qt::ShiftModifier) {
615 if (PlotGridX)
616 offset= PageWidth - (PageWidth % PlotGridX);
617 else
618 offset= PageWidth;
619 } else
620 if(event->modifiers() & Qt::ControlModifier)
621 offset= 1;
622 else
623 offset= (int)(20 / GraphPixelsPerPoint);
624
625 switch(event->key()) {
626 case Qt::Key_Down:
627 if(GraphPixelsPerPoint <= 50) {
628 GraphPixelsPerPoint *= 2;
629 }
630 break;
631
632 case Qt::Key_Up:
633 if(GraphPixelsPerPoint >= 0.02) {
634 GraphPixelsPerPoint /= 2;
635 }
636 break;
637
638 case Qt::Key_Right:
639 if(GraphPixelsPerPoint < 20) {
640 GraphStart += offset;
641 } else {
642 GraphStart++;
643 }
644 break;
645
646 case Qt::Key_Left:
647 if(GraphPixelsPerPoint < 20) {
648 GraphStart -= offset;
649 } else {
650 GraphStart--;
651 }
652 break;
653
654 case Qt::Key_G:
655 if(PlotGridX || PlotGridY) {
656 PlotGridX= 0;
657 PlotGridY= 0;
658 } else {
659 PlotGridX= PlotGridXdefault;
660 PlotGridY= PlotGridYdefault;
661 }
662 break;
663
664 case Qt::Key_H:
665 puts("Plot Window Keystrokes:\n");
666 puts(" Key Action\n");
667 puts(" DOWN Zoom in");
668 puts(" G Toggle grid display");
669 puts(" H Show help");
670 puts(" L Toggle lock grid relative to samples");
671 puts(" LEFT Move left");
672 puts(" <CTL>LEFT Move left 1 sample");
673 puts(" <SHIFT>LEFT Page left");
674 puts(" LEFT-MOUSE-CLICK Set yellow cursor");
675 puts(" Q Hide window");
676 puts(" RIGHT Move right");
677 puts(" <CTL>RIGHT Move right 1 sample");
678 puts(" <SHIFT>RIGHT Page right");
679 puts(" RIGHT-MOUSE-CLICK Set purple cursor");
680 puts(" UP Zoom out");
681 puts("");
682 puts("Use client window 'data help' for more plot commands\n");
683 break;
684
685 case Qt::Key_L:
686 GridLocked = !GridLocked;
687 if (GridLocked)
688 GridOffset += (GraphStart - unlockStart);
689 else
690 unlockStart = GraphStart;
691 break;
692
693 case Qt::Key_Q:
694 master->hide();
695 break;
696
697 default:
698 QWidget::keyPressEvent(event);
699 return;
700 break;
701 }
702
703 this->update();
704 }
Impressum, Datenschutz