X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=inline;f=pv%2Fviews%2Ftrace%2Fviewport.cpp;h=192e8f096303aca51013254b70582e3dd4398d42;hb=ffad6cd6856a0e0de36cad164d9d09e06c0ec52a;hp=6c51d0a1f4a4c44f4964421000edd7cc16aad9a7;hpb=af33d4cbacc745f4473f5c0f4fa1f9ebb8d84d0a;p=pulseview.git diff --git a/pv/views/trace/viewport.cpp b/pv/views/trace/viewport.cpp index 6c51d0a1..192e8f09 100644 --- a/pv/views/trace/viewport.cpp +++ b/pv/views/trace/viewport.cpp @@ -54,6 +54,17 @@ Viewport::Viewport(View &parent) : { setAutoFillBackground(true); setBackgroundRole(QPalette::Base); + + // Set up settings and event handlers + GlobalSettings settings; + allow_vertical_dragging_ = settings.value(GlobalSettings::Key_View_AllowVerticalDragging).toBool(); + + GlobalSettings::add_change_handler(this); +} + +Viewport::~Viewport() +{ + GlobalSettings::remove_change_handler(this); } shared_ptr Viewport::get_mouse_over_item(const QPoint &pt) @@ -70,7 +81,7 @@ void Viewport::item_hover(const shared_ptr &item, QPoint pos) { if (item && item->is_draggable(pos)) setCursor(dynamic_pointer_cast(item) ? - Qt::SizeVerCursor : Qt::SizeHorCursor); + Qt::SizeHorCursor : Qt::SizeVerCursor); else unsetCursor(); } @@ -78,7 +89,9 @@ void Viewport::item_hover(const shared_ptr &item, QPoint pos) void Viewport::drag() { drag_offset_ = view_.offset(); - drag_v_offset_ = view_.owner_visual_v_offset(); + + if (allow_vertical_dragging_) + drag_v_offset_ = view_.owner_visual_v_offset(); } void Viewport::drag_by(const QPoint &delta) @@ -89,7 +102,8 @@ void Viewport::drag_by(const QPoint &delta) view_.set_scale_offset(view_.scale(), (*drag_offset_ - delta.x() * view_.scale())); - view_.set_v_offset(-drag_v_offset_ - delta.y()); + if (allow_vertical_dragging_) + view_.set_v_offset(-drag_v_offset_ - delta.y()); } void Viewport::drag_release() @@ -116,6 +130,9 @@ bool Viewport::touch_event(QTouchEvent *event) pinch_zoom_active_ = false; return false; } + if (event->device()->type() == QTouchDevice::TouchPad) { + return false; + } const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first(); const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last(); @@ -208,23 +225,43 @@ void Viewport::wheelEvent(QWheelEvent *event) { assert(event); +#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) + int delta = (event->angleDelta().x() != 0) ? event->angleDelta().x() : event->angleDelta().y(); +#else + int delta = event->delta(); +#endif + +#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) + if (event->angleDelta().y() != 0) { +#else if (event->orientation() == Qt::Vertical) { +#endif if (event->modifiers() & Qt::ControlModifier) { // Vertical scrolling with the control key pressed // is intrepretted as vertical scrolling view_.set_v_offset(-view_.owner_visual_v_offset() - - (event->delta() * height()) / (8 * 120)); + (delta * height()) / (8 * 120)); } else { // Vertical scrolling is interpreted as zooming in/out - view_.zoom(event->delta() / 120.0, event->x()); + view_.zoom(delta / 120.0, event->position().x()); } +#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) + } else if (event->angleDelta().x() != 0) { +#else } else if (event->orientation() == Qt::Horizontal) { +#endif // Horizontal scrolling is interpreted as moving left/right view_.set_scale_offset(view_.scale(), - event->delta() * view_.scale() + view_.offset()); + delta * view_.scale() + view_.offset()); } } +void Viewport::on_setting_changed(const QString &key, const QVariant &value) +{ + if (key == GlobalSettings::Key_View_AllowVerticalDragging) + allow_vertical_dragging_ = value.toBool(); +} + } // namespace trace } // namespace views } // namespace pv