* @brief Wheel = zoom toward the cursor; touch-pad gestures zoom more gently. */
| 1442 | * @brief Wheel = zoom toward the cursor; touch-pad gestures zoom more gently. |
| 1443 | */ |
| 1444 | void Widgets::Waterfall::wheelEvent(QWheelEvent* event) |
| 1445 | { |
| 1446 | if (event->angleDelta().y() == 0) { |
| 1447 | event->ignore(); |
| 1448 | return; |
| 1449 | } |
| 1450 | |
| 1451 | const bool isTouchpad = |
| 1452 | !event->pixelDelta().isNull() || event->source() == Qt::MouseEventSynthesizedBySystem; |
| 1453 | const double zoomBase = isTouchpad ? 1.05 : 1.15; |
| 1454 | constexpr double kInv120 = 1.0 / 120.0; |
| 1455 | const double delta = event->angleDelta().y() * kInv120; |
| 1456 | const double factor = std::pow(zoomBase, delta); |
| 1457 | |
| 1458 | const QPointF p = event->position(); |
| 1459 | const double w = qMax(1.0, width()); |
| 1460 | const double h = qMax(1.0, height()); |
| 1461 | zoomBy(factor, p.x() / w, p.y() / h); |
| 1462 | event->accept(); |
| 1463 | } |
| 1464 | |
| 1465 | /** |
| 1466 | * @brief Mouse-press starts a drag-to-pan interaction. |