From cbb50547a69f8a10dd05e8cf8d03fdd679e4442f Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Sun, 16 Jul 2017 22:10:16 +0200 Subject: [PATCH] AnalogSignal: Make div height adjustable --- pv/views/trace/analogsignal.cpp | 39 +++++++++++++++++++++++++++++++-- pv/views/trace/analogsignal.hpp | 3 ++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/pv/views/trace/analogsignal.cpp b/pv/views/trace/analogsignal.cpp index f94a70f8..e26b203a 100644 --- a/pv/views/trace/analogsignal.cpp +++ b/pv/views/trace/analogsignal.cpp @@ -89,7 +89,6 @@ AnalogSignal::AnalogSignal( Signal(session, base), scale_index_(4), // 20 per div scale_index_drag_offset_(0), - div_height_(3 * QFontMetrics(QApplication::font()).height()), pos_vdivs_(1), neg_vdivs_(1), resolution_(0), @@ -103,6 +102,9 @@ AnalogSignal::AnalogSignal( connect(analog_data, SIGNAL(samples_added(QObject*, uint64_t, uint64_t)), this, SLOT(on_samples_added())); + GlobalSettings gs; + div_height_ = gs.value(GlobalSettings::Key_View_DefaultDivHeight).toInt(); + base_->set_colour(SignalColours[base_->index() % countof(SignalColours)]); update_scale(); } @@ -120,6 +122,7 @@ void AnalogSignal::save_settings(QSettings &settings) const settings.setValue("conversion_type", conversion_type_); settings.setValue("display_type", display_type_); settings.setValue("autoranging", autoranging_); + settings.setValue("div_height", div_height_); } void AnalogSignal::restore_settings(QSettings &settings) @@ -145,6 +148,17 @@ void AnalogSignal::restore_settings(QSettings &settings) if (settings.contains("autoranging")) autoranging_ = settings.value("autoranging").toBool(); + + if (settings.contains("div_height")) { + const int old_height = div_height_; + div_height_ = settings.value("div_height").toInt(); + + if ((div_height_ != old_height) && owner_) { + // Call order is important, otherwise the lazy event handler won't work + owner_->extents_changed(false, true); + owner_->row_item_appearance_changed(false, true); + } + } } pair AnalogSignal::v_extents() const @@ -665,7 +679,7 @@ void AnalogSignal::populate_popup_form(QWidget *parent, QFormLayout *form) QFormLayout *const layout = new QFormLayout; - // Add the number of vdivs + // Add div-related settings pvdiv_sb_ = new QSpinBox(parent); pvdiv_sb_->setRange(0, MaximumVDivs); pvdiv_sb_->setValue(pos_vdivs_); @@ -680,6 +694,15 @@ void AnalogSignal::populate_popup_form(QWidget *parent, QFormLayout *form) this, SLOT(on_neg_vdivs_changed(int))); layout->addRow(tr("Number of neg vertical divs"), nvdiv_sb_); + div_height_sb_ = new QSpinBox(parent); + div_height_sb_->setRange(20, 1000); + div_height_sb_->setSingleStep(5); + div_height_sb_->setSuffix(tr(" pixels")); + div_height_sb_->setValue(div_height_); + connect(div_height_sb_, SIGNAL(valueChanged(int)), + this, SLOT(on_div_height_changed(int))); + layout->addRow(tr("Div height"), div_height_sb_); + // Add the vertical resolution resolution_cb_ = new QComboBox(parent); @@ -810,6 +833,18 @@ void AnalogSignal::on_neg_vdivs_changed(int vdivs) } } +void AnalogSignal::on_div_height_changed(int height) +{ + div_height_ = height; + update_scale(); + + if (owner_) { + // Call order is important, otherwise the lazy event handler won't work + owner_->extents_changed(false, true); + owner_->row_item_appearance_changed(false, true); + } +} + void AnalogSignal::on_resolution_changed(int index) { scale_index_ = resolution_cb_->itemData(index).toInt(); diff --git a/pv/views/trace/analogsignal.hpp b/pv/views/trace/analogsignal.hpp index a1b3eeef..a67c4ff3 100644 --- a/pv/views/trace/analogsignal.hpp +++ b/pv/views/trace/analogsignal.hpp @@ -156,6 +156,7 @@ private Q_SLOTS: void on_pos_vdivs_changed(int vdivs); void on_neg_vdivs_changed(int vdivs); + void on_div_height_changed(int height); void on_resolution_changed(int index); @@ -167,7 +168,7 @@ private Q_SLOTS: private: QComboBox *resolution_cb_, *conversion_cb_, *display_type_cb_; - QSpinBox *pvdiv_sb_, *nvdiv_sb_; + QSpinBox *pvdiv_sb_, *nvdiv_sb_, *div_height_sb_; float scale_; int scale_index_; -- 2.30.2