]> sigrok.org Git - pulseview.git/commitdiff
Add setting for the snap-to-edge distance
authorSoeren Apel <redacted>
Wed, 26 Sep 2018 21:41:53 +0000 (23:41 +0200)
committerSoeren Apel <redacted>
Wed, 26 Sep 2018 21:41:53 +0000 (23:41 +0200)
pv/dialogs/settings.cpp
pv/dialogs/settings.hpp
pv/globalsettings.cpp
pv/globalsettings.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index 1ac8a4c35f8b4203761cd36e2d877d6f1a6deb08..f0752c0704ef63312ba9114f0649d8b7f954a6c3 100644 (file)
@@ -237,6 +237,15 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const
                SLOT(on_view_showHoverMarker_changed(int)));
        trace_view_layout->addRow(tr("Highlight mouse cursor using a vertical marker line"), cb);
 
+       QSpinBox *snap_distance_sb = new QSpinBox();
+       snap_distance_sb->setRange(0, 1000);
+       snap_distance_sb->setSuffix(tr(" pixels"));
+       snap_distance_sb->setValue(
+               settings.value(GlobalSettings::Key_View_SnapDistance).toInt());
+       connect(snap_distance_sb, SIGNAL(valueChanged(int)), this,
+               SLOT(on_view_snapDistance_changed(int)));
+       trace_view_layout->addRow(tr("Maximum distance from edges before cursors snap to them"), snap_distance_sb);
+
        QComboBox *thr_disp_mode_cb = new QComboBox();
        thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None);
        thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background);
@@ -626,6 +635,12 @@ void Settings::on_view_showHoverMarker_changed(int state)
        settings.setValue(GlobalSettings::Key_View_ShowHoverMarker, state ? true : false);
 }
 
+void Settings::on_view_snapDistance_changed(int value)
+{
+       GlobalSettings settings;
+       settings.setValue(GlobalSettings::Key_View_SnapDistance, value);
+}
+
 void Settings::on_view_conversionThresholdDispMode_changed(int state)
 {
        GlobalSettings settings;
index a51bc97a93de5f8ddc5d8248d6ecda6b03866d56..f68b31dd69cbff058079224dcae6e7de084fabdc 100644 (file)
@@ -64,6 +64,7 @@ private Q_SLOTS:
        void on_view_showSamplingPoints_changed(int state);
        void on_view_showAnalogMinorGrid_changed(int state);
        void on_view_showHoverMarker_changed(int state);
+       void on_view_snapDistance_changed(int value);
        void on_view_conversionThresholdDispMode_changed(int state);
        void on_view_defaultDivHeight_changed(int value);
        void on_view_defaultLogicHeight_changed(int value);
index 7c40cae5b5157087c99e27cb7fb99bf2d887ab1c..df44162fe3372de01f626e731b928c086eebaae3 100644 (file)
@@ -41,6 +41,7 @@ const QString GlobalSettings::Key_View_ConversionThresholdDispMode = "View_Conve
 const QString GlobalSettings::Key_View_DefaultDivHeight = "View_DefaultDivHeight";
 const QString GlobalSettings::Key_View_DefaultLogicHeight = "View_DefaultLogicHeight";
 const QString GlobalSettings::Key_View_ShowHoverMarker = "View_ShowHoverMarker";
+const QString GlobalSettings::Key_View_SnapDistance = "View_SnapDistance";
 const QString GlobalSettings::Key_Dec_InitialStateConfigurable = "Dec_InitialStateConfigurable";
 const QString GlobalSettings::Key_Dec_ExportFormat = "Dec_ExportFormat";
 const QString GlobalSettings::Key_Log_BufferSize = "Log_BufferSize";
@@ -78,6 +79,9 @@ void GlobalSettings::set_defaults_where_needed()
                setValue(Key_View_DefaultLogicHeight,
                2 * QFontMetrics(QApplication::font()).height());
 
+       if (!contains(Key_View_SnapDistance))
+               setValue(Key_View_SnapDistance, 15);
+
        if (!contains(Key_Dec_ExportFormat))
                setValue(Key_Dec_ExportFormat, "%s %d: %c: %1");
 
index b5cd24fd5ad809a3fcb769fa503523229864726b..4f07955adb35200d9130f654f71894744cfacd54 100644 (file)
@@ -57,6 +57,7 @@ public:
        static const QString Key_View_DefaultDivHeight;
        static const QString Key_View_DefaultLogicHeight;
        static const QString Key_View_ShowHoverMarker;
+       static const QString Key_View_SnapDistance;
        static const QString Key_Dec_InitialStateConfigurable;
        static const QString Key_Dec_ExportFormat;
        static const QString Key_Log_BufferSize;
index b9872130890f4e124c9cb052680f852e68124757..29c0675d63b5ca1f2db20da4008e88083c8ac110 100644 (file)
@@ -178,6 +178,7 @@ View::View(Session &session, bool is_main_view, QWidget *parent) :
        // Set up settings and event handlers
        GlobalSettings settings;
        colored_bg_ = settings.value(GlobalSettings::Key_View_ColoredBG).toBool();
+       snap_distance_ = settings.value(GlobalSettings::Key_View_SnapDistance).toInt();
 
        GlobalSettings::add_change_handler(this);
 
@@ -860,6 +861,9 @@ const QPoint& View::hover_point() const
 
 int64_t View::get_nearest_level_change(const QPoint &p) const
 {
+       if (snap_distance_ == 0)
+               return -1;
+
        shared_ptr<Signal> signal = signal_under_mouse_cursor_;
 
        if (!signal)
@@ -887,9 +891,9 @@ int64_t View::get_nearest_level_change(const QPoint &p) const
        int64_t nearest = -1;
 
        // Only use closest left or right edge if they're close to the cursor
-       if ((left_delta < right_delta) && (left_delta < 15))
+       if ((left_delta < right_delta) && (left_delta < snap_distance_))
                nearest = edges.front().first;
-       if ((left_delta >= right_delta) && (right_delta < 15))
+       if ((left_delta >= right_delta) && (right_delta < snap_distance_))
                nearest = edges.back().first;
 
        return nearest;
@@ -926,6 +930,11 @@ void View::on_setting_changed(const QString &key, const QVariant &value)
 {
        if (key == GlobalSettings::Key_View_TriggerIsZeroTime)
                on_settingViewTriggerIsZeroTime_changed(value);
+
+       if (key == GlobalSettings::Key_View_SnapDistance) {
+               GlobalSettings settings;
+               snap_distance_ = settings.value(GlobalSettings::Key_View_SnapDistance).toInt();
+       }
 }
 
 void View::trigger_event(int segment_id, util::Timestamp location)
index 94082189be41bc1b47b7abfff094045ed703138c..7df0f3de23bfdebf9439f7f7fc02248e603f50d4 100644 (file)
@@ -529,6 +529,7 @@ private:
 
        QPoint hover_point_;
        shared_ptr<Signal> signal_under_mouse_cursor_;
+       uint16_t snap_distance_;
 
        unsigned int sticky_events_;
        QTimer lazy_event_handler_;