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