Commit 65f1202bf20910e9ba83fdf219e9b5aec715ec11

Authored by Denis Dovzhenko
Committed by David Gräff
1 parent 4f3d56bf

drag markers by mouse press in the scope area

openhantek/src/dsowidget.cpp
... ... @@ -80,6 +80,12 @@ DsoWidget::DsoWidget(DsoSettingsScope *scope, DsoSettingsView *view, const Dso::
80 80 markerSlider->setIndexVisible(marker, true);
81 81 }
82 82  
  83 + connect(mainScope, &GlScope::markerMoved, [this] (int marker, double position) {
  84 + double step = this->markerSlider->step(marker);
  85 + this->scope->horizontal.marker[marker] =
  86 + this->markerSlider->setValue(marker, std::round(position / step) * step);
  87 + });
  88 +
83 89 // The table for the settings
84 90 settingsTriggerLabel = new QLabel();
85 91 settingsTriggerLabel->setMinimumWidth(160);
... ... @@ -265,12 +271,17 @@ void DsoWidget::updateMarkerDetails() {
265 271 double divs = fabs(scope->horizontal.marker[1] - scope->horizontal.marker[0]);
266 272 double time = divs * scope->horizontal.timebase;
267 273  
  274 + QString infoLabelPrefix(tr("Markers"));
268 275 if (view->zoom) {
269   - markerInfoLabel->setText(tr("Zoom x%L1").arg(DIVS_TIME / divs, -1, 'g', 3));
  276 + infoLabelPrefix = tr("Zoom x%L1").arg(DIVS_TIME / divs, -1, 'g', 3);
270 277 markerTimebaseLabel->setText(valueToString(time / DIVS_TIME, UNIT_SECONDS, 3) + tr("/div"));
271 278 markerFrequencybaseLabel->setText(
272 279 valueToString(divs * scope->horizontal.frequencybase / DIVS_TIME, UNIT_HERTZ, 4) + tr("/div"));
273 280 }
  281 + markerInfoLabel->setText(infoLabelPrefix.append(": %1 %2")
  282 + .arg(valueToString(0.5 + scope->horizontal.marker[0] / DIVS_TIME - scope->trigger.position, UNIT_SECONDS, 4))
  283 + .arg(valueToString(0.5 + scope->horizontal.marker[1] / DIVS_TIME - scope->trigger.position, UNIT_SECONDS, 4)));
  284 +
274 285 markerTimeLabel->setText(valueToString(time, UNIT_SECONDS, 4));
275 286 markerFrequencyLabel->setText(valueToString(1.0 / time, UNIT_HERTZ, 4));
276 287 }
... ... @@ -426,10 +437,7 @@ void DsoWidget::updateZoom(bool enabled) {
426 437 markerTimebaseLabel->setVisible(enabled);
427 438 markerLayout->setStretch(4, enabled ? 1 : 0);
428 439 markerFrequencybaseLabel->setVisible(enabled);
429   - if (enabled)
430   - updateMarkerDetails();
431   - else
432   - markerInfoLabel->setText(tr("Marker 1/2"));
  440 + updateMarkerDetails();
433 441  
434 442 repaint();
435 443 }
... ...
openhantek/src/exporter.cpp
... ... @@ -64,7 +64,7 @@ std::unique_ptr<QPrinter> Exporter::printPaintDevice(DsoSettings *settings) {
64 64 }
65 65  
66 66 bool Exporter::exportSamples(const DataAnalyzerResult *result) {
67   - if (this->format == EXPORT_FORMAT_CSV) { return exportCVS(result); }
  67 + if (this->format == EXPORT_FORMAT_CSV) { return exportCSV(result); }
68 68  
69 69 // Choose the color values we need
70 70 DsoSettingsColorValues *colorValues;
... ... @@ -136,7 +136,7 @@ bool Exporter::exportSamples(const DataAnalyzerResult *result) {
136 136 // Draw the measurement table
137 137 stretchBase = (double)(paintDevice->width() - lineHeight * 6) / 10;
138 138 int channelCount = 0;
139   - for (ChannelID channel = settings->scope.voltage.size() - 1; channel >= 0; channel--) {
  139 + for (int channel = settings->scope.voltage.size() - 1; channel >= 0; channel--) {
140 140 if ((settings->scope.voltage[channel].used || settings->scope.spectrum[channel].used) &&
141 141 result->data(channel)) {
142 142 ++channelCount;
... ... @@ -329,7 +329,7 @@ bool Exporter::exportSamples(const DataAnalyzerResult *result) {
329 329 return true;
330 330 }
331 331  
332   -bool Exporter::exportCVS(const DataAnalyzerResult *result) {
  332 +bool Exporter::exportCSV(const DataAnalyzerResult *result) {
333 333 QFile csvFile(this->filename);
334 334 if (!csvFile.open(QIODevice::WriteOnly | QIODevice::Text)) return false;
335 335  
... ...
openhantek/src/exporter.h
... ... @@ -30,7 +30,7 @@ class Exporter {
30 30 private:
31 31 Exporter(DsoSettings *settings, const QString &filename, ExportFormat format);
32 32 void setFormat(ExportFormat format);
33   - bool exportCVS(const DataAnalyzerResult *result);
  33 + bool exportCSV(const DataAnalyzerResult *result);
34 34 static std::unique_ptr<QPrinter> printPaintDevice(DsoSettings *settings);
35 35 void drawGrids(QPainter &painter, DsoSettingsColorValues *colorValues, double lineHeight, double scopeHeight,
36 36 int scopeWidth);
... ...
openhantek/src/glscope.cpp
... ... @@ -3,6 +3,7 @@
3 3 #include <cmath>
4 4  
5 5 #include <QColor>
  6 +#include <QMouseEvent>
6 7  
7 8 #include "glscope.h"
8 9  
... ... @@ -70,6 +71,7 @@ void GlScope::paintGL() {
70 71 vaMarker[marker][0] = (GLfloat)scope->horizontal.marker[marker];
71 72 vaMarker[marker][2] = (GLfloat)scope->horizontal.marker[marker];
72 73  
  74 + glLineWidth((marker == selectedMarker) ? 3 : 1);
73 75 glVertexPointer(2, GL_FLOAT, 0, &vaMarker[marker].front());
74 76 glDrawArrays(GL_LINES, 0, (GLsizei)vaMarker[marker].size() / 2);
75 77 }
... ... @@ -97,6 +99,55 @@ void GlScope::resizeGL(int width, int height) {
97 99 glMatrixMode(GL_MODELVIEW);
98 100 }
99 101  
  102 +void GlScope::mousePressEvent(QMouseEvent *event) {
  103 + if (!zoomed && event->button() == Qt::LeftButton) {
  104 + double position = (double)(event->x() - width() / 2) * DIVS_TIME / (double)width();
  105 + double distance = DIVS_TIME;
  106 + selectedMarker = NO_MARKER;
  107 + // Capture nearest marker located within snap area (+/- 1% of full scale).
  108 + for (int marker = 0; marker < MARKER_COUNT; ++marker) {
  109 + if (!scope->horizontal.marker_visible[marker]) continue;
  110 + if (fabs(scope->horizontal.marker[marker] - position) < std::min(distance, DIVS_TIME / 100.0)) {
  111 + distance = fabs(scope->horizontal.marker[marker] - position);
  112 + selectedMarker = marker;
  113 + }
  114 + }
  115 + if (selectedMarker != NO_MARKER) {
  116 + emit markerMoved(selectedMarker, position);
  117 + }
  118 + }
  119 + event->accept();
  120 +}
  121 +
  122 +void GlScope::mouseMoveEvent(QMouseEvent *event) {
  123 + if (!zoomed && (event->buttons() & Qt::LeftButton) != 0) {
  124 + double position = (double)(event->x() - width() / 2) * DIVS_TIME / (double)width();
  125 + if (selectedMarker == NO_MARKER) {
  126 + // User started draging outside the snap area of any marker:
  127 + // move all markers to current position and select last marker in the array.
  128 + for (int marker = 0; marker < MARKER_COUNT; ++marker) {
  129 + emit markerMoved(marker, position);
  130 + selectedMarker = marker;
  131 + }
  132 + }
  133 + else if (selectedMarker < MARKER_COUNT) {
  134 + emit markerMoved(selectedMarker, position);
  135 + }
  136 + }
  137 + event->accept();
  138 +}
  139 +
  140 +void GlScope::mouseReleaseEvent(QMouseEvent *event) {
  141 + if (!zoomed && event->button() == Qt::LeftButton) {
  142 + double position = (double)(event->x() - width() / 2) * DIVS_TIME / (double)width();
  143 + if (selectedMarker != NO_MARKER && selectedMarker < MARKER_COUNT) {
  144 + emit markerMoved(selectedMarker, position);
  145 + }
  146 + selectedMarker = NO_MARKER;
  147 + }
  148 + event->accept();
  149 +}
  150 +
100 151 void GlScope::drawGrid() {
101 152 glDisable(GL_POINT_SMOOTH);
102 153 glDisable(GL_LINE_SMOOTH);
... ...
openhantek/src/glscope.h
... ... @@ -46,6 +46,10 @@ class GlScope : public GL_WIDGET_CLASS {
46 46 /// \param height The new height of the widget.
47 47 void resizeGL(int width, int height) override;
48 48  
  49 + void mousePressEvent(QMouseEvent *event) override;
  50 + void mouseMoveEvent(QMouseEvent *event) override;
  51 + void mouseReleaseEvent(QMouseEvent *event) override;
  52 +
49 53 /// \brief Draw the grid.
50 54 void drawGrid();
51 55  
... ... @@ -59,7 +63,11 @@ class GlScope : public GL_WIDGET_CLASS {
59 63 */
60 64 bool channelUsed(Dso::ChannelMode mode, ChannelID channel);
61 65  
  66 + signals:
  67 + void markerMoved(int marker, double position);
  68 +
62 69 private:
  70 + const int NO_MARKER = -1;
63 71 DsoSettingsScope *scope;
64 72 DsoSettingsView *view;
65 73 const GlGenerator *generator;
... ... @@ -67,4 +75,5 @@ class GlScope : public GL_WIDGET_CLASS {
67 75  
68 76 std::vector<GLfloat> vaMarker[2];
69 77 bool zoomed = false;
  78 + int selectedMarker = NO_MARKER;
70 79 };
... ...