]> sigrok.org Git - pulseview.git/commitdiff
Add "allow vertical dragging in the view" setting
authorSoeren Apel <redacted>
Thu, 26 Nov 2020 21:17:34 +0000 (22:17 +0100)
committerSoeren Apel <redacted>
Thu, 26 Nov 2020 21:17:34 +0000 (22:17 +0100)
pv/dialogs/settings.cpp
pv/dialogs/settings.hpp
pv/globalsettings.cpp
pv/globalsettings.hpp
pv/views/trace/viewport.cpp
pv/views/trace/viewport.hpp

index b07a63696fb4b11d3c6c69cbf8b5beb79d7da60d..12c6f0cfede13f370f4d4ae8a880c81465e49f68 100644 (file)
@@ -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;
index d419350c6821c592251a9175878f666be57f0edf..c8ba8162e03a4c03313e72515e01ff08ccfe71cd 100644 (file)
@@ -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);
index 4fa9bc334d27e4e470ca30afe0ae0d52715da9e9..6821f342757d49008b250694278da507826dbb1e 100644 (file)
@@ -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);
index 2b8bf17f5fba3dca6fa47a4872626d3b22dfb055..67922d7a696c0c032450c634e9230772add3ba77 100644 (file)
@@ -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;
index 0c73ec494adfbc72257252c59ead85d609a6ad24..a2d0b99ae34769ff8cf37b86525dcbc532b2a1d3 100644 (file)
@@ -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<ViewItem> Viewport::get_mouse_over_item(const QPoint &pt)
@@ -78,7 +89,9 @@ void Viewport::item_hover(const shared_ptr<ViewItem> &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
index 48f2d09c9d0c4c178535c089bdc86a7a064d26fc..8c82354ea8dcfb6f2e75ddeb8a34b35932087ef5 100644 (file)
@@ -26,6 +26,8 @@
 #include <QTimer>
 #include <QTouchEvent>
 
+#include <pv/globalsettings.hpp>
+
 #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<pv::util::Timestamp> drag_offset_;
        int drag_v_offset_;
+       bool allow_vertical_dragging_;
 
        double pinch_offset0_;
        double pinch_offset1_;