From: Soeren Apel Date: Thu, 26 Nov 2020 21:17:34 +0000 (+0100) Subject: Add "allow vertical dragging in the view" setting X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e6c8d58bde2c32f0ee8b73c5577505736caf8e23;p=pulseview.git Add "allow vertical dragging in the view" setting --- diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index b07a6369..12c6f0cf 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -313,19 +313,23 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const cb = create_checkbox(GlobalSettings::Key_View_TriggerIsZeroTime, SLOT(on_view_triggerIsZero_changed(int))); - trace_view_layout->addRow(tr("Show time zero at the trigger"), cb); + trace_view_layout->addRow(tr("Show time zero at the &trigger"), cb); cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling, SLOT(on_view_stickyScrolling_changed(int))); trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb); + cb = create_checkbox(GlobalSettings::Key_View_AllowVerticalDragging, + SLOT(on_view_allowVerticalDragging_changed(int))); + trace_view_layout->addRow(tr("Allow &vertical dragging in the view area"), cb); + cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints, SLOT(on_view_showSamplingPoints_changed(int))); trace_view_layout->addRow(tr("Show data &sampling points"), cb); cb = create_checkbox(GlobalSettings::Key_View_FillSignalHighAreas, SLOT(on_view_fillSignalHighAreas_changed(int))); - trace_view_layout->addRow(tr("Fill high areas of logic signals"), cb); + trace_view_layout->addRow(tr("Fill &high areas of logic signals"), cb); ColorButton* high_fill_cb = new ColorButton(parent); high_fill_cb->set_color(QColor::fromRgba( @@ -720,6 +724,12 @@ void Settings::on_view_stickyScrolling_changed(int state) settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false); } +void Settings::on_view_allowVerticalDragging_changed(int state) +{ + GlobalSettings settings; + settings.setValue(GlobalSettings::Key_View_AllowVerticalDragging, state ? true : false); +} + void Settings::on_view_showSamplingPoints_changed(int state) { GlobalSettings settings; diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp index d419350c..c8ba8162 100644 --- a/pv/dialogs/settings.hpp +++ b/pv/dialogs/settings.hpp @@ -68,6 +68,7 @@ private Q_SLOTS: void on_view_triggerIsZero_changed(int state); void on_view_coloredBG_changed(int state); void on_view_stickyScrolling_changed(int state); + void on_view_allowVerticalDragging_changed(int state); void on_view_showSamplingPoints_changed(int state); void on_view_fillSignalHighAreas_changed(int state); void on_view_fillSignalHighAreaColor_changed(QColor color); diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index 4fa9bc33..6821f342 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -58,6 +58,7 @@ const QString GlobalSettings::Key_View_ZoomToFitAfterAcq = "View_ZoomToFitAfterA const QString GlobalSettings::Key_View_TriggerIsZeroTime = "View_TriggerIsZeroTime"; const QString GlobalSettings::Key_View_ColoredBG = "View_ColoredBG"; const QString GlobalSettings::Key_View_StickyScrolling = "View_StickyScrolling"; +const QString GlobalSettings::Key_View_AllowVerticalDragging = "View_AllowVerticalDragging"; const QString GlobalSettings::Key_View_ShowSamplingPoints = "View_ShowSamplingPoints"; const QString GlobalSettings::Key_View_FillSignalHighAreas = "View_FillSignalHighAreas"; const QString GlobalSettings::Key_View_FillSignalHighAreaColor = "View_FillSignalHighAreaColor"; @@ -124,6 +125,10 @@ void GlobalSettings::set_defaults_where_needed() if (!contains(Key_View_ZoomToFitAfterAcq)) setValue(Key_View_ZoomToFitAfterAcq, true); + // Allow vertical dragging by default + if (!contains(Key_View_AllowVerticalDragging)) + setValue(Key_View_AllowVerticalDragging, true); + // Enable colored trace backgrounds by default if (!contains(Key_View_ColoredBG)) setValue(Key_View_ColoredBG, true); diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index 2b8bf17f..67922d7a 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -63,6 +63,7 @@ public: static const QString Key_View_TriggerIsZeroTime; static const QString Key_View_ColoredBG; static const QString Key_View_StickyScrolling; + static const QString Key_View_AllowVerticalDragging; static const QString Key_View_ShowSamplingPoints; static const QString Key_View_FillSignalHighAreas; static const QString Key_View_FillSignalHighAreaColor; diff --git a/pv/views/trace/viewport.cpp b/pv/views/trace/viewport.cpp index 0c73ec49..a2d0b99a 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) @@ -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() @@ -228,6 +242,14 @@ void Viewport::wheelEvent(QWheelEvent *event) } } +void Viewport::on_setting_changed(const QString &key, const QVariant &value) +{ + if (key == GlobalSettings::Key_View_AllowVerticalDragging) { + GlobalSettings settings; + allow_vertical_dragging_ = settings.value(GlobalSettings::Key_View_AllowVerticalDragging).toBool(); + } +} + } // namespace trace } // namespace views } // namespace pv diff --git a/pv/views/trace/viewport.hpp b/pv/views/trace/viewport.hpp index 48f2d09c..8c82354e 100644 --- a/pv/views/trace/viewport.hpp +++ b/pv/views/trace/viewport.hpp @@ -26,6 +26,8 @@ #include #include +#include + #include "pv/util.hpp" #include "viewwidget.hpp" @@ -42,12 +44,13 @@ namespace trace { class View; -class Viewport : public ViewWidget +class Viewport : public ViewWidget, public GlobalSettingsInterface { Q_OBJECT public: explicit Viewport(View &parent); + ~Viewport(); /** * Gets the first view item which has a hit-box that contains @c pt . @@ -92,15 +95,18 @@ private: */ bool touch_event(QTouchEvent *event); -private: void paintEvent(QPaintEvent *event); void mouseDoubleClickEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); + void on_setting_changed(const QString &key, const QVariant &value); + private: boost::optional drag_offset_; int drag_v_offset_; + bool allow_vertical_dragging_; double pinch_offset0_; double pinch_offset1_;