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