@@ -85,9 +85,9 @@ GlScope::GlScope( DsoSettingsScope *scope, DsoSettingsView *view, QWidget *paren
85
85
GlScope::~GlScope () { /* virtual destructor necessary */
86
86
}
87
87
88
- QPointF GlScope::eventToPosition ( QMouseEvent *event ) {
89
- QPointF position ( double ( event-> x () - width () / 2 ) * DIVS_TIME / double ( width () ),
90
- double ( height () / 2 - event-> y () ) * DIVS_VOLTAGE / double ( height () ) );
88
+ QPointF GlScope::posToPosition ( QPoint pos ) {
89
+ QPointF position ( double ( pos. x () - width () / 2 ) * DIVS_TIME / double ( width () ),
90
+ double ( height () / 2 - pos. y () ) * DIVS_VOLTAGE / double ( height () ) );
91
91
if ( zoomed ) {
92
92
double m1 = scope->getMarker ( 0 );
93
93
double m2 = scope->getMarker ( 1 );
@@ -100,7 +100,7 @@ QPointF GlScope::eventToPosition( QMouseEvent *event ) {
100
100
101
101
void GlScope::mousePressEvent ( QMouseEvent *event ) {
102
102
if ( !( zoomed && selectedCursor == 0 ) && event->button () == Qt::LeftButton ) {
103
- QPointF position = eventToPosition ( event );
103
+ QPointF position = posToPosition ( event-> pos () );
104
104
selectedMarker = NO_MARKER;
105
105
DsoSettingsScopeCursor *cursor = cursorInfo[ selectedCursor ];
106
106
// Capture nearest marker located within snap area (+/- 1% of full scale).
@@ -151,7 +151,7 @@ void GlScope::mousePressEvent( QMouseEvent *event ) {
151
151
152
152
void GlScope::mouseMoveEvent ( QMouseEvent *event ) {
153
153
if ( !( zoomed && selectedCursor == 0 ) && ( event->buttons () & Qt::LeftButton ) != 0 ) {
154
- QPointF position = eventToPosition ( event );
154
+ QPointF position = posToPosition ( event-> pos () );
155
155
if ( selectedMarker == NO_MARKER ) {
156
156
// qDebug() << "mouseMoveEvent";
157
157
// User started draging outside the snap area of any marker:
@@ -171,7 +171,7 @@ void GlScope::mouseMoveEvent( QMouseEvent *event ) {
171
171
172
172
void GlScope::mouseReleaseEvent ( QMouseEvent *event ) {
173
173
if ( !( zoomed && selectedCursor == 0 ) && event->button () == Qt::LeftButton ) {
174
- QPointF position = eventToPosition ( event );
174
+ QPointF position = posToPosition ( event-> pos () );
175
175
if ( selectedMarker < 2 ) {
176
176
// qDebug() << "mouseReleaseEvent";
177
177
cursorInfo[ selectedCursor ]->pos [ selectedMarker ] = position;
@@ -185,13 +185,13 @@ void GlScope::mouseReleaseEvent( QMouseEvent *event ) {
185
185
void GlScope::mouseDoubleClickEvent ( QMouseEvent *event ) {
186
186
if ( !( zoomed && selectedCursor == 0 ) && ( event->buttons () & Qt::LeftButton ) != 0 ) {
187
187
// left double click positions two markers left and right of clicked pos with zoom=100
188
- QPointF position = eventToPosition ( event );
188
+ QPointF position = posToPosition ( event-> pos () );
189
189
if ( selectedMarker == NO_MARKER ) {
190
190
// User double clicked outside the snap area of any marker
191
- QPointF p = QPointF ( 0.5 , 0 ); // 10x zoom
192
- if ( event->modifiers () & Qt::SHIFT ) // 100x zoom
191
+ QPointF p = QPointF ( 0.5 , 0 ); // 10x zoom
192
+ if ( event->modifiers () & Qt::CTRL ) // 100x zoom
193
193
p /= 10 ;
194
- if ( event->modifiers () & Qt::CTRL ) // center at trigger position
194
+ if ( event->modifiers () & Qt::SHIFT ) // center at trigger position
195
195
position = QPointF ( 10 * scope->trigger .offset - 5 , 0 );
196
196
// move 1st marker left of current position.
197
197
cursorInfo[ selectedCursor ]->pos [ 0 ] = position - p;
@@ -212,6 +212,43 @@ void GlScope::mouseDoubleClickEvent( QMouseEvent *event ) {
212
212
event->accept ();
213
213
}
214
214
215
+
216
+ void GlScope::wheelEvent ( QWheelEvent *event ) {
217
+ static std::vector< int > zoomList = {1 , 2 , 5 , 10 , 20 , 50 , 100 , 200 , 500 };
218
+ if ( !( zoomed && selectedCursor == 0 ) ) {
219
+ if ( selectedMarker == NO_MARKER ) {
220
+ double step = event->angleDelta ().y () / 1200.0 ; // one click = 0.1
221
+ // qDebug() << "wheeelEvent" << selectedCursor << event->globalPos() << step;
222
+ double &m1 = cursorInfo[ selectedCursor ]->pos [ 0 ].rx ();
223
+ double &m2 = cursorInfo[ selectedCursor ]->pos [ 1 ].rx ();
224
+ if ( m1 > m2 )
225
+ std::swap ( m1, m2 );
226
+ double dm = m2 - m1;
227
+ if ( event->modifiers () & Qt::CTRL ) { // zoom in/out
228
+ if ( ( step > 0 && dm <= 1 ) || ( step < 0 && dm < 1 ) )
229
+ step *= 0.1 ;
230
+ if ( dm >= 3 * step ) {
231
+ m1 += step;
232
+ m2 -= step;
233
+ }
234
+ } else {
235
+ if ( step < 0 ) { // shift zoom range left ..
236
+ step = qMax ( step, MARGIN_LEFT - m1 ); // .. until m1 == MARGIN_LEFT
237
+ } else { // shift zoom range right ..
238
+ step = qMin ( step, MARGIN_RIGHT - m2 ); // .. until m2 == MARGIN_RIGHT
239
+ }
240
+ m1 += step;
241
+ m2 += step;
242
+ }
243
+ }
244
+ emit markerMoved ( selectedCursor, 0 );
245
+ emit markerMoved ( selectedCursor, 1 );
246
+ selectedMarker = NO_MARKER;
247
+ }
248
+ event->accept ();
249
+ }
250
+
251
+
215
252
void GlScope::paintEvent ( QPaintEvent *event ) {
216
253
if ( shaderCompileSuccess ) {
217
254
QOpenGLWidget::paintEvent ( event );
0 commit comments