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