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