]> cvs.zerfleddert.de Git - proxmark3-svn/blame_incremental - client/proxguiqt.cpp
USB comm: prepare for @micolous change (PR#463) (#587)
[proxmark3-svn] / client / proxguiqt.cpp
... / ...
CommitLineData
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
31bool g_useOverlays = false;
32int g_absVMax = 0;
33int startMax;
34int PageWidth;
35int unlockStart = 0;
36
37void ProxGuiQT::ShowGraphWindow(void)
38{
39 emit ShowGraphWindowSignal();
40}
41
42void ProxGuiQT::RepaintGraphWindow(void)
43{
44 emit RepaintGraphWindowSignal();
45}
46
47void ProxGuiQT::HideGraphWindow(void)
48{
49 emit HideGraphWindowSignal();
50}
51
52void ProxGuiQT::Exit(void)
53{
54 emit ExitSignal();
55}
56
57void ProxGuiQT::_ShowGraphWindow(void)
58{
59 if(!plotapp)
60 return;
61
62 if (!plotwidget)
63 plotwidget = new ProxWidget();
64
65 plotwidget->show();
66}
67
68void ProxGuiQT::_RepaintGraphWindow(void)
69{
70 if (!plotapp || !plotwidget)
71 return;
72
73 plotwidget->update();
74}
75
76void ProxGuiQT::_HideGraphWindow(void)
77{
78 if (!plotapp || !plotwidget)
79 return;
80
81 plotwidget->hide();
82}
83
84void ProxGuiQT::_Exit(void) {
85 delete this;
86}
87
88void 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
99void 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
114ProxGuiQT::ProxGuiQT(int argc, char **argv, WorkerThread *wthread) : plotapp(NULL), plotwidget(NULL),
115 argc(argc), argv(argv), proxmarkThread(wthread)
116{
117}
118
119ProxGuiQT::~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//--------------------
134void ProxWidget::applyOperation()
135{
136 //printf("ApplyOperation()");
137 save_restoreGB(GRAPH_SAVE);
138 memcpy(GraphBuffer, s_Buff, sizeof(int) * GraphTraceLen);
139 RepaintGraphWindow();
140}
141void ProxWidget::stickOperation()
142{
143 save_restoreGB(GRAPH_RESTORE);
144 //printf("stickOperation()");
145}
146void 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}
154void 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}
163void 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}
171void 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}
179ProxWidget::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...
228ProxWidget::~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}
247void ProxWidget::closeEvent(QCloseEvent *event)
248{
249 event->ignore();
250 this->hide();
251 g_useOverlays = false;
252}
253void ProxWidget::hideEvent(QHideEvent *event) {
254 controlWidget->hide();
255 plot->hide();
256}
257void ProxWidget::showEvent(QShowEvent *event) {
258 controlWidget->show();
259 plot->show();
260}
261
262//----------- Plotting
263
264int Plot::xCoordOf(int i, QRect r )
265{
266 return r.left() + (int)((i - GraphStart)*GraphPixelsPerPoint);
267}
268
269int Plot::yCoordOf(int v, QRect r, int maxVal)
270{
271 int z = (r.bottom() - r.top())/2;
272 return -(z * v) / maxVal + z;
273}
274
275int Plot::valueOf_yCoord(int y, QRect r, int maxVal)
276{
277 int z = (r.bottom() - r.top())/2;
278 return (y-z) * maxVal / z;
279}
280static const QColor GREEN = QColor(100,255,100);
281static const QColor RED = QColor(255,100,100);
282static const QColor BLUE = QColor(100,100,255);
283static const QColor GRAY = QColor(240,240,240);
284
285QColor Plot::getColor(int graphNum)
286{
287 switch (graphNum) {
288 case 0: return GREEN; //Green
289 case 1: return RED; //Red
290 case 2: return BLUE; //Blue
291 default: return GRAY; //Gray
292 }
293}
294
295void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect)
296{
297 if (len == 0) return;
298 startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint));
299 if(startMax < 0) {
300 startMax = 0;
301 }
302 if(GraphStart > startMax) {
303 GraphStart = startMax;
304 }
305 if (GraphStart > len) return;
306 int vMin = INT_MAX, vMax = INT_MIN, v = 0;
307 int sample_index = GraphStart ;
308 for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) {
309
310 v = buffer[sample_index];
311 if(v < vMin) vMin = v;
312 if(v > vMax) vMax = v;
313 }
314
315 g_absVMax = 0;
316 if(fabs( (double) vMin) > g_absVMax) g_absVMax = (int)fabs( (double) vMin);
317 if(fabs( (double) vMax) > g_absVMax) g_absVMax = (int)fabs( (double) vMax);
318 g_absVMax = (int)(g_absVMax*1.25 + 1);
319}
320
321void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset)
322{
323 if (len == 0 || PlotGridX <= 0) return;
324 //clock_t begin = clock();
325 QPainterPath penPath;
326
327 int grid_delta_x = PlotGridX;
328 int first_delta_x = grid_delta_x; //(plotOffset > 0) ? PlotGridX : (PlotGridX +);
329 if (GraphStart > plotOffset) first_delta_x -= (GraphStart-plotOffset);
330 int DemodStart = GraphStart;
331 if (plotOffset > GraphStart) DemodStart = plotOffset;
332
333 int BitStart = 0;
334 // round down
335 if (DemodStart-plotOffset > 0) BitStart = (int)(((DemodStart-plotOffset)+(PlotGridX-1))/PlotGridX)-1;
336 first_delta_x += BitStart * PlotGridX;
337 if (BitStart > (int)len) return;
338 int delta_x = 0;
339 int v = 0;
340 //printf("first_delta_x %i, grid_delta_x %i, DemodStart %i, BitStart %i\n",first_delta_x,grid_delta_x,DemodStart, BitStart);
341
342 painter->setPen(getColor(graphNum));
343 char str[5];
344 int absVMax = (int)(100*1.05+1);
345 int x = xCoordOf(DemodStart, plotRect);
346 int y = yCoordOf((buffer[BitStart]*200-100)*-1,plotRect,absVMax);
347 penPath.moveTo(x, y);
348 delta_x = 0;
349 int clk = first_delta_x;
350 for(int i = BitStart; i < (int)len && xCoordOf(delta_x+DemodStart, plotRect) < plotRect.right(); i++) {
351 for (int ii = 0; ii < (clk) && i < (int)len && xCoordOf(DemodStart+delta_x+ii, plotRect) < plotRect.right() ; ii++ ) {
352 x = xCoordOf(DemodStart+delta_x+ii, plotRect);
353 v = buffer[i]*200-100;
354
355 y = yCoordOf( v, plotRect, absVMax);
356
357 penPath.lineTo(x, y);
358
359 if(GraphPixelsPerPoint > 10) {
360 QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
361 painter->fillRect(f, QColor(100, 255, 100));
362 }
363 if (ii == (int)clk/2) {
364 //print label
365 sprintf(str, "%u",buffer[i]);
366 painter->drawText(x-8, y + ((buffer[i] > 0) ? 18 : -6), str);
367 }
368 }
369 delta_x += clk;
370 clk = grid_delta_x;
371 }
372
373 //Graph annotations
374 painter->drawPath(penPath);
375}
376
377void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum)
378{
379 if (len == 0) return;
380 //clock_t begin = clock();
381 QPainterPath penPath;
382 int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, i = 0;
383 int x = xCoordOf(GraphStart, plotRect);
384 int y = yCoordOf(buffer[GraphStart],plotRect,g_absVMax);
385 penPath.moveTo(x, y);
386 for(i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) {
387
388 x = xCoordOf(i, plotRect);
389 v = buffer[i];
390
391 y = yCoordOf( v, plotRect, g_absVMax);
392
393 penPath.lineTo(x, y);
394
395 if(GraphPixelsPerPoint > 10) {
396 QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
397 painter->fillRect(f, QColor(100, 255, 100));
398 }
399 //catch stats
400 if(v < vMin) vMin = v;
401 if(v > vMax) vMax = v;
402 vMean += v;
403 }
404 vMean /= (i - GraphStart);
405
406 painter->setPen(getColor(graphNum));
407
408 //Draw y-axis
409 int xo = 5+(graphNum*40);
410 painter->drawLine(xo, plotRect.top(),xo, plotRect.bottom());
411
412 int vMarkers = (g_absVMax - (g_absVMax % 10)) / 5;
413 int minYDist = 40; //Minimum pixel-distance between markers
414
415 char yLbl[20];
416
417 int n = 0;
418 int lasty0 = 65535;
419
420 for(v = vMarkers; yCoordOf(v,plotRect,g_absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++)
421 {
422 int y0 = yCoordOf(v,plotRect,g_absVMax);
423 int y1 = yCoordOf(-v,plotRect,g_absVMax);
424
425 if(lasty0 - y0 < minYDist) continue;
426
427 painter->drawLine(xo-5,y0, xo+5, y0);
428
429 sprintf(yLbl, "%d", v);
430 painter->drawText(xo+8,y0+7,yLbl);
431
432 painter->drawLine(xo-5, y1, xo+5, y1);
433 sprintf(yLbl, "%d",-v);
434 painter->drawText(xo+8, y1+5 , yLbl);
435 lasty0 = y0;
436 }
437
438 //Graph annotations
439 painter->drawPath(penPath);
440 char str[200];
441 sprintf(str, "max=%d min=%d mean=%d n=%d/%d CursorAVal=[%d] CursorBVal=[%d]",
442 vMax, vMin, vMean, i, len, buffer[CursorAPos], buffer[CursorBPos]);
443 painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str);
444
445 //clock_t end = clock();
446 //double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
447 //printf("Plot time %f\n", elapsed_secs);
448}
449
450void Plot::plotGridLines(QPainter* painter,QRect r)
451{
452 // set GridOffset
453 if (PlotGridX <= 0) return;
454 int offset = GridOffset;
455 if (GridLocked && PlotGridX) {
456 offset = GridOffset + PlotGridX - (GraphStart % PlotGridX);
457 } else if (!GridLocked && GraphStart > 0 && PlotGridX) {
458 offset = PlotGridX-((GraphStart - offset) % PlotGridX) + GraphStart - unlockStart;
459 }
460 offset %= PlotGridX;
461 if (offset < 0) offset += PlotGridX;
462
463 int i;
464 int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint);
465 int grid_delta_y = PlotGridY;
466 if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
467 for(i = (offset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) {
468 painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom());
469 }
470 }
471 if (PlotGridY > 0) {
472 for(i = 0; yCoordOf(i,r,g_absVMax) > r.top(); i += grid_delta_y) {
473 painter->drawLine( r.left(), yCoordOf(i,r,g_absVMax), r.right(), yCoordOf(i,r,g_absVMax) );
474 painter->drawLine( r.left(), yCoordOf(i*-1,r,g_absVMax), r.right(), yCoordOf(i*-1,r,g_absVMax) );
475 }
476 }
477}
478
479#define HEIGHT_INFO 60
480#define WIDTH_AXES 80
481
482void Plot::paintEvent(QPaintEvent *event)
483{
484
485 QPainter painter(this);
486 QBrush brush(QColor(100, 255, 100));
487 QPen pen(QColor(100, 255, 100));
488
489 painter.setFont(QFont("Courier New", 10));
490
491 if(GraphStart < 0) {
492 GraphStart = 0;
493 }
494
495 if (CursorAPos > GraphTraceLen)
496 CursorAPos= 0;
497 if(CursorBPos > GraphTraceLen)
498 CursorBPos= 0;
499 if(CursorCPos > GraphTraceLen)
500 CursorCPos= 0;
501 if(CursorDPos > GraphTraceLen)
502 CursorDPos= 0;
503
504 QRect plotRect(WIDTH_AXES, 0, width()-WIDTH_AXES, height()-HEIGHT_INFO);
505 QRect infoRect(0, height()-HEIGHT_INFO, width(), HEIGHT_INFO);
506
507 //Grey background
508 painter.fillRect(rect(), QColor(60, 60, 60));
509 //Black foreground
510 painter.fillRect(plotRect, QColor(0, 0, 0));
511
512 //init graph variables
513 setMaxAndStart(GraphBuffer,GraphTraceLen,plotRect);
514
515 // center line
516 int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2;
517 painter.setPen(QColor(100, 100, 100));
518 painter.drawLine(plotRect.left(), zeroHeight, plotRect.right(), zeroHeight);
519 // plot X and Y grid lines
520 plotGridLines(&painter, plotRect);
521
522 //Start painting graph
523 PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0);
524 if (showDemod && DemodBufferLen > 8) {
525 PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx);
526 }
527 if (g_useOverlays) {
528 //init graph variables
529 setMaxAndStart(s_Buff,GraphTraceLen,plotRect);
530 PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1);
531 }
532 // End graph drawing
533
534 //Draw the cursors
535 if(CursorAPos > GraphStart && xCoordOf(CursorAPos, plotRect) < plotRect.right())
536 {
537 painter.setPen(QColor(255, 255, 0));
538 painter.drawLine(xCoordOf(CursorAPos, plotRect),plotRect.top(),xCoordOf(CursorAPos, plotRect),plotRect.bottom());
539 }
540 if(CursorBPos > GraphStart && xCoordOf(CursorBPos, plotRect) < plotRect.right())
541 {
542 painter.setPen(QColor(255, 0, 255));
543 painter.drawLine(xCoordOf(CursorBPos, plotRect),plotRect.top(),xCoordOf(CursorBPos, plotRect),plotRect.bottom());
544 }
545 if(CursorCPos > GraphStart && xCoordOf(CursorCPos, plotRect) < plotRect.right())
546 {
547 painter.setPen(QColor(255, 153, 0)); //orange
548 painter.drawLine(xCoordOf(CursorCPos, plotRect),plotRect.top(),xCoordOf(CursorCPos, plotRect),plotRect.bottom());
549 }
550 if(CursorDPos > GraphStart && xCoordOf(CursorDPos, plotRect) < plotRect.right())
551 {
552 painter.setPen(QColor(0, 0, 205)); //light blue
553 painter.drawLine(xCoordOf(CursorDPos, plotRect),plotRect.top(),xCoordOf(CursorDPos, plotRect),plotRect.bottom());
554 }
555
556 //Draw annotations
557 char str[200];
558 sprintf(str, "@%d dt=%d [%2.2f] zoom=%2.2f CursorAPos=%d CursorBPos=%d GridX=%d GridY=%d (%s) GridXoffset=%d",
559 GraphStart, CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor,
560 GraphPixelsPerPoint,CursorAPos,CursorBPos,PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked",GridOffset);
561 painter.setPen(QColor(255, 255, 255));
562 painter.drawText(20, infoRect.bottom() - 3, str);
563
564}
565
566Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1)
567{
568 //Need to set this, otherwise we don't receive keypress events
569 setFocusPolicy( Qt::StrongFocus);
570 resize(600, 300);
571
572 QPalette palette(QColor(0,0,0,0));
573 palette.setColor(QPalette::WindowText, QColor(255,255,255));
574 palette.setColor(QPalette::Text, QColor(255,255,255));
575 palette.setColor(QPalette::Button, QColor(100, 100, 100));
576 setPalette(palette);
577 setAutoFillBackground(true);
578 CursorAPos = 0;
579 CursorBPos = 0;
580
581 setWindowTitle(tr("Sliders"));
582}
583
584void Plot::closeEvent(QCloseEvent *event)
585{
586 event->ignore();
587 this->hide();
588 g_useOverlays = false;
589}
590
591void Plot::mouseMoveEvent(QMouseEvent *event)
592{
593 int x = event->x();
594 x -= WIDTH_AXES;
595 x = (int)(x / GraphPixelsPerPoint);
596 x += GraphStart;
597 if((event->buttons() & Qt::LeftButton)) {
598 CursorAPos = x;
599 } else if (event->buttons() & Qt::RightButton) {
600 CursorBPos = x;
601 }
602
603
604 this->update();
605}
606
607void Plot::keyPressEvent(QKeyEvent *event)
608{
609 int offset;
610
611 if(event->modifiers() & Qt::ShiftModifier) {
612 if (PlotGridX)
613 offset= PageWidth - (PageWidth % PlotGridX);
614 else
615 offset= PageWidth;
616 } else
617 if(event->modifiers() & Qt::ControlModifier)
618 offset= 1;
619 else
620 offset= (int)(20 / GraphPixelsPerPoint);
621
622 switch(event->key()) {
623 case Qt::Key_Down:
624 if(GraphPixelsPerPoint <= 50) {
625 GraphPixelsPerPoint *= 2;
626 }
627 break;
628
629 case Qt::Key_Up:
630 if(GraphPixelsPerPoint >= 0.02) {
631 GraphPixelsPerPoint /= 2;
632 }
633 break;
634
635 case Qt::Key_Right:
636 if(GraphPixelsPerPoint < 20) {
637 GraphStart += offset;
638 } else {
639 GraphStart++;
640 }
641 break;
642
643 case Qt::Key_Left:
644 if(GraphPixelsPerPoint < 20) {
645 GraphStart -= offset;
646 } else {
647 GraphStart--;
648 }
649 break;
650
651 case Qt::Key_G:
652 if(PlotGridX || PlotGridY) {
653 PlotGridX= 0;
654 PlotGridY= 0;
655 } else {
656 PlotGridX= PlotGridXdefault;
657 PlotGridY= PlotGridYdefault;
658 }
659 break;
660
661 case Qt::Key_H:
662 puts("Plot Window Keystrokes:\n");
663 puts(" Key Action\n");
664 puts(" DOWN Zoom in");
665 puts(" G Toggle grid display");
666 puts(" H Show help");
667 puts(" L Toggle lock grid relative to samples");
668 puts(" LEFT Move left");
669 puts(" <CTL>LEFT Move left 1 sample");
670 puts(" <SHIFT>LEFT Page left");
671 puts(" LEFT-MOUSE-CLICK Set yellow cursor");
672 puts(" Q Hide window");
673 puts(" RIGHT Move right");
674 puts(" <CTL>RIGHT Move right 1 sample");
675 puts(" <SHIFT>RIGHT Page right");
676 puts(" RIGHT-MOUSE-CLICK Set purple cursor");
677 puts(" UP Zoom out");
678 puts("");
679 puts("Use client window 'data help' for more plot commands\n");
680 break;
681
682 case Qt::Key_L:
683 GridLocked = !GridLocked;
684 if (GridLocked)
685 GridOffset += (GraphStart - unlockStart);
686 else
687 unlockStart = GraphStart;
688 break;
689
690 case Qt::Key_Q:
691 this->hide();
692 break;
693
694 default:
695 QWidget::keyPressEvent(event);
696 return;
697 break;
698 }
699
700 this->update();
701}
Impressum, Datenschutz