comparison widgets/LevelPanWidget.cpp @ 1303:13f5f84fbfad

Collect the bits of bookkeeping for mouse wheel events, and use in all widgets
author Chris Cannam
date Fri, 22 Jun 2018 17:19:48 +0100
parents f3d3fab250ac
children a575dae05fbf
comparison
equal deleted inserted replaced
1302:f3d3fab250ac 1303:13f5f84fbfad
72 m_monitorLeft(-1), 72 m_monitorLeft(-1),
73 m_monitorRight(-1), 73 m_monitorRight(-1),
74 m_editable(true), 74 m_editable(true),
75 m_editing(false), 75 m_editing(false),
76 m_includeMute(true), 76 m_includeMute(true),
77 m_includeHalfSteps(true), 77 m_includeHalfSteps(true)
78 m_pendingWheelAngle(0)
79 { 78 {
80 setToolTip(tr("Drag vertically to adjust level, horizontally to adjust pan")); 79 setToolTip(tr("Drag vertically to adjust level, horizontally to adjust pan"));
81 setLevel(1.0); 80 setLevel(1.0);
82 setPan(0.0); 81 setPan(0.0);
83 } 82 }
282 } 281 }
283 282
284 void 283 void
285 LevelPanWidget::wheelEvent(QWheelEvent *e) 284 LevelPanWidget::wheelEvent(QWheelEvent *e)
286 { 285 {
287 e->accept(); 286 int delta = m_wheelCounter.count(e);
288 287
289 int dy = e->angleDelta().y(); 288 if (delta == 0) {
290 if (dy == 0) {
291 return; 289 return;
292 } 290 }
293 291
294 if (e->phase() == Qt::ScrollBegin || 292 if (e->modifiers() & Qt::ControlModifier) {
295 std::abs(dy) >= 120 || 293 m_pan = clampPan(m_pan + delta);
296 (dy > 0 && m_pendingWheelAngle < 0) || 294 emitPanChanged();
297 (dy < 0 && m_pendingWheelAngle > 0)) { 295 update();
298 m_pendingWheelAngle = dy;
299 } else { 296 } else {
300 m_pendingWheelAngle += dy; 297 m_notch = clampNotch(m_notch + delta);
301 } 298 emitLevelChanged();
302 299 update();
303 if (abs(m_pendingWheelAngle) >= 600) {
304 // discard absurd results
305 m_pendingWheelAngle = 0;
306 return;
307 }
308
309 while (abs(m_pendingWheelAngle) >= 120) {
310
311 int sign = (m_pendingWheelAngle < 0 ? -1 : 1);
312
313 if (e->modifiers() & Qt::ControlModifier) {
314 m_pan += sign;
315 m_pan = clampPan(m_pan);
316 emitPanChanged();
317 update();
318 } else {
319 m_notch += sign;
320 m_notch = clampNotch(m_notch);
321 emitLevelChanged();
322 update();
323 }
324
325 m_pendingWheelAngle -= sign * 120;
326 } 300 }
327 } 301 }
328 302
329 int 303 int
330 LevelPanWidget::coordsToNotch(QRectF rect, QPointF loc) const 304 LevelPanWidget::coordsToNotch(QRectF rect, QPointF loc) const