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