From: Soeren Apel Date: Wed, 26 Sep 2018 21:41:53 +0000 (+0200) Subject: Add setting for the snap-to-edge distance X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fb64180193664005567570724d52b685913e15ed;p=pulseview.git Add setting for the snap-to-edge distance --- diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index 1ac8a4c3..f0752c07 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -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; diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp index a51bc97a..f68b31dd 100644 --- a/pv/dialogs/settings.hpp +++ b/pv/dialogs/settings.hpp @@ -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); diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index 7c40cae5..df44162f 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -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"); diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index b5cd24fd..4f07955a 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -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; diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index b9872130..29c0675d 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -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_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) diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index 94082189..7df0f3de 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -529,6 +529,7 @@ private: QPoint hover_point_; shared_ptr signal_under_mouse_cursor_; + uint16_t snap_distance_; unsigned int sticky_events_; QTimer lazy_event_handler_;