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