]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/proxguiqt.cpp
Fix: ControlWidget placement (#690)
[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 controlWidget = new QWidget();
186 opsController = new Ui::Form();
187 opsController->setupUi(controlWidget);
188 //Due to quirks in QT Designer, we need to fiddle a bit
189 opsController->horizontalSlider_dirthr_down->setMinimum(-128);
190 opsController->horizontalSlider_dirthr_down->setMaximum(0);
191 opsController->horizontalSlider_dirthr_down->setValue(-20);
192 opsController->horizontalSlider_dirthr_up->setMinimum(-40);
193 opsController->horizontalSlider_dirthr_up->setMaximum(128);
194 opsController->horizontalSlider_dirthr_up->setValue(20);
195 opsController->horizontalSlider_askedge->setValue(25);
196 opsController->horizontalSlider_window->setValue(4000);
197
198
199 QObject::connect(opsController->pushButton_apply, SIGNAL(clicked()), this, SLOT(applyOperation()));
200 QObject::connect(opsController->pushButton_sticky, SIGNAL(clicked()), this, SLOT(stickOperation()));
201 QObject::connect(opsController->horizontalSlider_window, SIGNAL(valueChanged(int)), this, SLOT(vchange_autocorr(int)));
202 QObject::connect(opsController->horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_up(int)));
203 QObject::connect(opsController->horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_down(int)));
204 QObject::connect(opsController->horizontalSlider_askedge, SIGNAL(valueChanged(int)), this, SLOT(vchange_askedge(int)));
205
206 // Set up the plot widget, which does the actual plotting
207 plot = new Plot(this);
208 QVBoxLayout *layout = new QVBoxLayout;
209 layout->addWidget(plot);
210 setLayout(layout);
211 show(); // places the window on the screen.
212
213 // Move controller widget below plot
214 controlWidget->move(x(),y()+frameSize().height());
215 controlWidget->resize(size().width(), controlWidget->size().height());
216 controlWidget->show();
217 }
218
219 // not 100% sure what i need in this block
220 // feel free to fix - marshmellow...
221 ProxWidget::~ProxWidget(void)
222 {
223 if (controlWidget) {
224 controlWidget->close();
225 delete controlWidget;
226 controlWidget = NULL;
227 }
228
229 if (opsController) {
230 delete opsController;
231 opsController = NULL;
232 }
233
234 if (plot) {
235 plot->close();
236 delete plot;
237 plot = NULL;
238 }
239 }
240 void ProxWidget::closeEvent(QCloseEvent *event)
241 {
242 event->ignore();
243 this->hide();
244 g_useOverlays = false;
245 }
246 void ProxWidget::hideEvent(QHideEvent *event) {
247 controlWidget->hide();
248 plot->hide();
249 }
250 void ProxWidget::showEvent(QShowEvent *event) {
251 controlWidget->show();
252 plot->show();
253 }
254
255 //----------- Plotting
256
257 int Plot::xCoordOf(int i, QRect r )
258 {
259 return r.left() + (int)((i - GraphStart)*GraphPixelsPerPoint);
260 }
261
262 int Plot::yCoordOf(int v, QRect r, int maxVal)
263 {
264 int z = (r.bottom() - r.top())/2;
265 if ( maxVal == 0 ) maxVal++;
266 return -(z * v) / maxVal + z;
267 }
268
269 int Plot::valueOf_yCoord(int y, QRect r, int maxVal)
270 {
271 int z = (r.bottom() - r.top())/2;
272 return (y-z) * maxVal / z;
273 }
274 static const QColor GREEN = QColor(100,255,100);
275 static const QColor RED = QColor(255,100,100);
276 static const QColor BLUE = QColor(100,100,255);
277 static const QColor GRAY = QColor(240,240,240);
278
279 QColor Plot::getColor(int graphNum)
280 {
281 switch (graphNum) {
282 case 0: return GREEN; //Green
283 case 1: return RED; //Red
284 case 2: return BLUE; //Blue
285 default: return GRAY; //Gray
286 }
287 }
288
289 void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect)
290 {
291 if (len == 0) return;
292 startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint));
293 if(startMax < 0) {
294 startMax = 0;
295 }
296 if(GraphStart > startMax) {
297 GraphStart = startMax;
298 }
299 if (GraphStart > len) return;
300 int vMin = INT_MAX, vMax = INT_MIN, v = 0;
301 int sample_index = GraphStart ;
302 for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) {
303
304 v = buffer[sample_index];
305 if(v < vMin) vMin = v;
306 if(v > vMax) vMax = v;
307 }
308
309 g_absVMax = 0;
310 if(fabs( (double) vMin) > g_absVMax) g_absVMax = (int)fabs( (double) vMin);
311 if(fabs( (double) vMax) > g_absVMax) g_absVMax = (int)fabs( (double) vMax);
312 g_absVMax = (int)(g_absVMax*1.25 + 1);
313 }
314
315 void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset)
316 {
317 if (len == 0 || PlotGridX <= 0) return;
318 //clock_t begin = clock();
319 QPainterPath penPath;
320
321 int grid_delta_x = PlotGridX;
322 int first_delta_x = grid_delta_x; //(plotOffset > 0) ? PlotGridX : (PlotGridX +);
323 if (GraphStart > plotOffset) first_delta_x -= (GraphStart-plotOffset);
324 int DemodStart = GraphStart;
325 if (plotOffset > GraphStart) DemodStart = plotOffset;
326
327 int BitStart = 0;
328 // round down
329 if (DemodStart-plotOffset > 0) BitStart = (int)(((DemodStart-plotOffset)+(PlotGridX-1))/PlotGridX)-1;
330 first_delta_x += BitStart * PlotGridX;
331 if (BitStart > (int)len) return;
332 int delta_x = 0;
333 int v = 0;
334 //printf("first_delta_x %i, grid_delta_x %i, DemodStart %i, BitStart %i\n",first_delta_x,grid_delta_x,DemodStart, BitStart);
335
336 painter->setPen(getColor(graphNum));
337 char str[5];
338 int absVMax = (int)(100*1.05+1);
339 int x = xCoordOf(DemodStart, plotRect);
340 int y = yCoordOf((buffer[BitStart]*200-100)*-1,plotRect,absVMax);
341 penPath.moveTo(x, y);
342 delta_x = 0;
343 int clk = first_delta_x;
344 for(int i = BitStart; i < (int)len && xCoordOf(delta_x+DemodStart, plotRect) < plotRect.right(); i++) {
345 for (int ii = 0; ii < (clk) && i < (int)len && xCoordOf(DemodStart+delta_x+ii, plotRect) < plotRect.right() ; ii++ ) {
346 x = xCoordOf(DemodStart+delta_x+ii, plotRect);
347 v = buffer[i]*200-100;
348
349 y = yCoordOf( v, plotRect, absVMax);
350
351 penPath.lineTo(x, y);
352
353 if(GraphPixelsPerPoint > 10) {
354 QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
355 painter->fillRect(f, QColor(100, 255, 100));
356 }
357 if (ii == (int)clk/2) {
358 //print label
359 sprintf(str, "%u",buffer[i]);
360 painter->drawText(x-8, y + ((buffer[i] > 0) ? 18 : -6), str);
361 }
362 }
363 delta_x += clk;
364 clk = grid_delta_x;
365 }
366
367 //Graph annotations
368 painter->drawPath(penPath);
369 }
370
371 void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum)
372 {
373 if (len == 0) return;
374 //clock_t begin = clock();
375 QPainterPath penPath;
376 int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, i = 0;
377 int x = xCoordOf(GraphStart, plotRect);
378 int y = yCoordOf(buffer[GraphStart],plotRect,g_absVMax);
379 penPath.moveTo(x, y);
380 for(i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) {
381
382 x = xCoordOf(i, plotRect);
383 v = buffer[i];
384
385 y = yCoordOf( v, plotRect, g_absVMax);
386
387 penPath.lineTo(x, y);
388
389 if(GraphPixelsPerPoint > 10) {
390 QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
391 painter->fillRect(f, QColor(100, 255, 100));
392 }
393 //catch stats
394 if(v < vMin) vMin = v;
395 if(v > vMax) vMax = v;
396 vMean += v;
397 }
398 vMean /= (i - GraphStart);
399
400 painter->setPen(getColor(graphNum));
401
402 //Draw y-axis
403 int xo = 5+(graphNum*40);
404 painter->drawLine(xo, plotRect.top(),xo, plotRect.bottom());
405
406 int vMarkers = (g_absVMax - (g_absVMax % 10)) / 5;
407 int minYDist = 40; //Minimum pixel-distance between markers
408
409 char yLbl[20];
410
411 int n = 0;
412 int lasty0 = 65535;
413
414 for(v = vMarkers; yCoordOf(v,plotRect,g_absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++)
415 {
416 int y0 = yCoordOf(v,plotRect,g_absVMax);
417 int y1 = yCoordOf(-v,plotRect,g_absVMax);
418
419 if(lasty0 - y0 < minYDist) continue;
420
421 painter->drawLine(xo-5,y0, xo+5, y0);
422
423 sprintf(yLbl, "%d", v);
424 painter->drawText(xo+8,y0+7,yLbl);
425
426 painter->drawLine(xo-5, y1, xo+5, y1);
427 sprintf(yLbl, "%d",-v);
428 painter->drawText(xo+8, y1+5 , yLbl);
429 lasty0 = y0;
430 }
431
432 //Graph annotations
433 painter->drawPath(penPath);
434 char str[200];
435 sprintf(str, "max=%d min=%d mean=%d n=%d/%d CursorAVal=[%d] CursorBVal=[%d]",
436 vMax, vMin, vMean, i, len, buffer[CursorAPos], buffer[CursorBPos]);
437 painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str);
438
439 //clock_t end = clock();
440 //double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
441 //printf("Plot time %f\n", elapsed_secs);
442 }
443
444 void Plot::plotGridLines(QPainter* painter,QRect r)
445 {
446 // set GridOffset
447 if (PlotGridX <= 0) return;
448 int offset = GridOffset;
449 if (GridLocked && PlotGridX) {
450 offset = GridOffset + PlotGridX - (GraphStart % PlotGridX);
451 } else if (!GridLocked && GraphStart > 0 && PlotGridX) {
452 offset = PlotGridX-((GraphStart - offset) % PlotGridX) + GraphStart - unlockStart;
453 }
454 offset %= PlotGridX;
455 if (offset < 0) offset += PlotGridX;
456
457 int i;
458 int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint);
459 int grid_delta_y = PlotGridY;
460 if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
461 for(i = (offset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) {
462 painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom());
463 }
464 }
465 if (PlotGridY > 0) {
466 for(i = 0; yCoordOf(i,r,g_absVMax) > r.top(); i += grid_delta_y) {
467 painter->drawLine( r.left(), yCoordOf(i,r,g_absVMax), r.right(), yCoordOf(i,r,g_absVMax) );
468 painter->drawLine( r.left(), yCoordOf(i*-1,r,g_absVMax), r.right(), yCoordOf(i*-1,r,g_absVMax) );
469 }
470 }
471 }
472
473 #define HEIGHT_INFO 60
474 #define WIDTH_AXES 80
475
476 void Plot::paintEvent(QPaintEvent *event)
477 {
478
479 QPainter painter(this);
480 QBrush brush(QColor(100, 255, 100));
481 QPen pen(QColor(100, 255, 100));
482
483 painter.setFont(QFont("Courier New", 10));
484
485 if(GraphStart < 0) {
486 GraphStart = 0;
487 }
488
489 if (CursorAPos > GraphTraceLen)
490 CursorAPos= 0;
491 if(CursorBPos > GraphTraceLen)
492 CursorBPos= 0;
493 if(CursorCPos > GraphTraceLen)
494 CursorCPos= 0;
495 if(CursorDPos > GraphTraceLen)
496 CursorDPos= 0;
497
498 QRect plotRect(WIDTH_AXES, 0, width()-WIDTH_AXES, height()-HEIGHT_INFO);
499 QRect infoRect(0, height()-HEIGHT_INFO, width(), HEIGHT_INFO);
500
501 //Grey background
502 painter.fillRect(rect(), QColor(60, 60, 60));
503 //Black foreground
504 painter.fillRect(plotRect, QColor(0, 0, 0));
505
506 //init graph variables
507 setMaxAndStart(GraphBuffer,GraphTraceLen,plotRect);
508
509 // center line
510 int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2;
511 painter.setPen(QColor(100, 100, 100));
512 painter.drawLine(plotRect.left(), zeroHeight, plotRect.right(), zeroHeight);
513 // plot X and Y grid lines
514 plotGridLines(&painter, plotRect);
515
516 //Start painting graph
517 PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0);
518 if (showDemod && DemodBufferLen > 8) {
519 PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx);
520 }
521 if (g_useOverlays) {
522 //init graph variables
523 setMaxAndStart(s_Buff,GraphTraceLen,plotRect);
524 PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1);
525 }
526 // End graph drawing
527
528 //Draw the cursors
529 if(CursorAPos > GraphStart && xCoordOf(CursorAPos, plotRect) < plotRect.right())
530 {
531 painter.setPen(QColor(255, 255, 0));
532 painter.drawLine(xCoordOf(CursorAPos, plotRect),plotRect.top(),xCoordOf(CursorAPos, plotRect),plotRect.bottom());
533 }
534 if(CursorBPos > GraphStart && xCoordOf(CursorBPos, plotRect) < plotRect.right())
535 {
536 painter.setPen(QColor(255, 0, 255));
537 painter.drawLine(xCoordOf(CursorBPos, plotRect),plotRect.top(),xCoordOf(CursorBPos, plotRect),plotRect.bottom());
538 }
539 if(CursorCPos > GraphStart && xCoordOf(CursorCPos, plotRect) < plotRect.right())
540 {
541 painter.setPen(QColor(255, 153, 0)); //orange
542 painter.drawLine(xCoordOf(CursorCPos, plotRect),plotRect.top(),xCoordOf(CursorCPos, plotRect),plotRect.bottom());
543 }
544 if(CursorDPos > GraphStart && xCoordOf(CursorDPos, plotRect) < plotRect.right())
545 {
546 painter.setPen(QColor(0, 0, 205)); //light blue
547 painter.drawLine(xCoordOf(CursorDPos, plotRect),plotRect.top(),xCoordOf(CursorDPos, plotRect),plotRect.bottom());
548 }
549
550 //Draw annotations
551 char str[200];
552 sprintf(str, "@%d dt=%d [%2.2f] zoom=%2.2f CursorAPos=%d CursorBPos=%d GridX=%d GridY=%d (%s) GridXoffset=%d",
553 GraphStart, CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor,
554 GraphPixelsPerPoint,CursorAPos,CursorBPos,PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked",GridOffset);
555 painter.setPen(QColor(255, 255, 255));
556 painter.drawText(20, infoRect.bottom() - 3, str);
557
558 }
559
560 Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1)
561 {
562 //Need to set this, otherwise we don't receive keypress events
563 setFocusPolicy( Qt::StrongFocus);
564 resize(600, 300);
565
566 QPalette palette(QColor(0,0,0,0));
567 palette.setColor(QPalette::WindowText, QColor(255,255,255));
568 palette.setColor(QPalette::Text, QColor(255,255,255));
569 palette.setColor(QPalette::Button, QColor(100, 100, 100));
570 setPalette(palette);
571 setAutoFillBackground(true);
572 CursorAPos = 0;
573 CursorBPos = 0;
574
575 setWindowTitle(tr("Sliders"));
576
577 master = parent;
578 }
579
580 void Plot::closeEvent(QCloseEvent *event)
581 {
582 event->ignore();
583 this->hide();
584 g_useOverlays = false;
585 }
586
587 void Plot::mouseMoveEvent(QMouseEvent *event)
588 {
589 int x = event->x();
590 x -= WIDTH_AXES;
591 x = (int)(x / GraphPixelsPerPoint);
592 x += GraphStart;
593 if((event->buttons() & Qt::LeftButton)) {
594 CursorAPos = x;
595 } else if (event->buttons() & Qt::RightButton) {
596 CursorBPos = x;
597 }
598
599
600 this->update();
601 }
602
603 void Plot::keyPressEvent(QKeyEvent *event)
604 {
605 int offset;
606
607 if(event->modifiers() & Qt::ShiftModifier) {
608 if (PlotGridX)
609 offset= PageWidth - (PageWidth % PlotGridX);
610 else
611 offset= PageWidth;
612 } else
613 if(event->modifiers() & Qt::ControlModifier)
614 offset= 1;
615 else
616 offset= (int)(20 / GraphPixelsPerPoint);
617
618 switch(event->key()) {
619 case Qt::Key_Down:
620 if(GraphPixelsPerPoint <= 50) {
621 GraphPixelsPerPoint *= 2;
622 }
623 break;
624
625 case Qt::Key_Up:
626 if(GraphPixelsPerPoint >= 0.02) {
627 GraphPixelsPerPoint /= 2;
628 }
629 break;
630
631 case Qt::Key_Right:
632 if(GraphPixelsPerPoint < 20) {
633 GraphStart += offset;
634 } else {
635 GraphStart++;
636 }
637 break;
638
639 case Qt::Key_Left:
640 if(GraphPixelsPerPoint < 20) {
641 GraphStart -= offset;
642 } else {
643 GraphStart--;
644 }
645 break;
646
647 case Qt::Key_G:
648 if(PlotGridX || PlotGridY) {
649 PlotGridX= 0;
650 PlotGridY= 0;
651 } else {
652 PlotGridX= PlotGridXdefault;
653 PlotGridY= PlotGridYdefault;
654 }
655 break;
656
657 case Qt::Key_H:
658 puts("Plot Window Keystrokes:\n");
659 puts(" Key Action\n");
660 puts(" DOWN Zoom in");
661 puts(" G Toggle grid display");
662 puts(" H Show help");
663 puts(" L Toggle lock grid relative to samples");
664 puts(" LEFT Move left");
665 puts(" <CTL>LEFT Move left 1 sample");
666 puts(" <SHIFT>LEFT Page left");
667 puts(" LEFT-MOUSE-CLICK Set yellow cursor");
668 puts(" Q Hide window");
669 puts(" RIGHT Move right");
670 puts(" <CTL>RIGHT Move right 1 sample");
671 puts(" <SHIFT>RIGHT Page right");
672 puts(" RIGHT-MOUSE-CLICK Set purple cursor");
673 puts(" UP Zoom out");
674 puts("");
675 puts("Use client window 'data help' for more plot commands\n");
676 break;
677
678 case Qt::Key_L:
679 GridLocked = !GridLocked;
680 if (GridLocked)
681 GridOffset += (GraphStart - unlockStart);
682 else
683 unlockStart = GraphStart;
684 break;
685
686 case Qt::Key_Q:
687 master->hide();
688 break;
689
690 default:
691 QWidget::keyPressEvent(event);
692 return;
693 break;
694 }
695
696 this->update();
697 }
Impressum, Datenschutz