From dc2b050e311d8b2f4e3f65200904bb4d271cc98d Mon Sep 17 00:00:00 2001 From: Maximilian Rehkopf Date: Wed, 15 Jan 2025 13:11:32 +0100 Subject: [PATCH 1/3] fix: adjust form region dimensions to include borders Prevent window from shrinking by one pixel when resizing one dimension. --- DSView/pv/mainframe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSView/pv/mainframe.cpp b/DSView/pv/mainframe.cpp index f9e91588..baa9324a 100644 --- a/DSView/pv/mainframe.cpp +++ b/DSView/pv/mainframe.cpp @@ -557,7 +557,7 @@ bool MainFrame::eventFilter(QObject *object, QEvent *event) } if (r != l){ - SetFormRegion(l, t, r-l, b-t); + SetFormRegion(l, t, r-l+1, b-t+1); #ifndef _WIN32 saveNormalRegion(); #endif From 61ad1b8829740063b9d87ecb5a1ff6f485ea5f9a Mon Sep 17 00:00:00 2001 From: Maximilian Rehkopf Date: Wed, 15 Jan 2025 13:12:30 +0100 Subject: [PATCH 2/3] Update signal height handling and enable vertical scrolling in view --- DSView/pv/view/view.cpp | 62 ++++++++++++++++++++++++++++++----------- DSView/pv/view/view.h | 2 +- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index c35f8f86..8e701e9f 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -61,9 +61,8 @@ const int View::LabelMarginWidth = 70; const int View::RulerHeight = 50; const int View::MaxScrollValue = INT_MAX / 2; -const int View::MaxHeightUnit = 20; +const int View::HeightUnit = 20; // also serves as minimum signal height -//const int View::SignalHeight = 30;s const int View::SignalMargin = 7; const int View::SignalSnapGridSize = 10; @@ -107,6 +106,9 @@ View::View(SigSession *session, pv::toolbars::SamplingBar *sampling_bar, QWidget _device_agent = session->get_device(); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); +// setWidgetResizable(true); +// setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // trace viewport map _trace_view_map[SR_CHANNEL_LOGIC] = TIME_VIEW; @@ -607,7 +609,7 @@ void View::update_scroll() assert(_viewcenter); int width = get_view_width(); - if (width == 0){ + if (width == 0) { return; } @@ -632,11 +634,28 @@ void View::update_scroll() _offset * 1.0 / length * MaxScrollValue); } - _updating_scroll = false; + // Set up vertical scrollbar + std::vector traces; + get_traces(ALL_VIEW, traces); + + // Calculate total required height for all traces + int total_height = 0; + for (auto t : traces) { + if (t->enabled()) + total_height += t->get_totalHeight() + SignalMargin; + } - // Set the vertical scrollbar - verticalScrollBar()->setPageStep(areaSize.height()); - verticalScrollBar()->setRange(0,0); + // Make sure we can scroll the last signal past the status bar + total_height += StatusHeight; + + // Enable vertical scrolling if total height exceeds viewport + if (total_height > areaSize.height()) { + verticalScrollBar()->setRange(0, total_height - areaSize.height()); + verticalScrollBar()->setPageStep(areaSize.height()); + } else { + verticalScrollBar()->setRange(0, 0); + } + _updating_scroll = false; } void View::update_scale_offset() @@ -678,7 +697,7 @@ void View::signals_changed(const Trace* eventTrace) double actualMargin = SignalMargin; int total_rows = 0; int label_size = 0; - uint8_t max_height = MaxHeightUnit; + uint8_t max_height = HeightUnit; std::vector time_traces; std::vector fft_traces; std::vector traces; @@ -759,22 +778,21 @@ void View::signals_changed(const Trace* eventTrace) ret = _device_agent->get_config_byte(SR_CONF_MAX_HEIGHT_VALUE, v); if (ret) { - max_height = (v + 1) * MaxHeightUnit; + max_height = (v + 1) * HeightUnit; } - if (height < 2*actualMargin) { actualMargin /= 2; - _signalHeight = max(1.0, (_time_viewport->height() + _signalHeight = max((double)HeightUnit, (_time_viewport->height() - 2 * actualMargin * label_size) * 1.0 / total_rows); } else { - _signalHeight = (height >= max_height) ? max_height : height; + _signalHeight = max((double)HeightUnit, (height >= max_height) ? max_height : height); } } else if (_device_agent->get_work_mode() == DSO) { - _signalHeight = (_header->height() + _signalHeight = max((double)HeightUnit, (_header->height() - horizontalScrollBar()->height() - - 2 * actualMargin * label_size) * 1.0 / total_rows; + - 2 * actualMargin * label_size) * 1.0 / total_rows); } else { _signalHeight = (int)((height <= 0) ? 1 : height); @@ -967,8 +985,20 @@ void View::h_scroll_value_changed(int value) void View::v_scroll_value_changed(int value) { - (void)value; - _header->update(); + // Update vertical positions of all traces based on scroll value + std::vector traces; + get_traces(ALL_VIEW, traces); + + int y_offset = -value + (traces[0]->get_totalHeight() / 2) + (SignalMargin / 2); // Start from negative scroll value to move traces up + + for (auto t : traces) { + if (t->enabled()) { + t->set_v_offset(y_offset); + y_offset += t->get_totalHeight() + SignalMargin; + } + } + + _header->update(); viewport_update(); } diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index aa738ecd..518986aa 100644 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -79,7 +79,7 @@ class View : public QScrollArea, public IUiWindow static const int RulerHeight; static const int MaxScrollValue; - static const int MaxHeightUnit; + static const int HeightUnit; public: //static const int SignalHeight; From c3fd77b1e1ad9e90feddb217595fea707e435120 Mon Sep 17 00:00:00 2001 From: Maximilian Rehkopf Date: Sun, 19 Jan 2025 02:43:13 +0100 Subject: [PATCH 3/3] fix bad scroll offset calculation, refactor scroll handling --- DSView/pv/view/trace.cpp | 3 +++ DSView/pv/view/trace.h | 11 ++++++++++- DSView/pv/view/view.cpp | 11 ++++------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/DSView/pv/view/trace.cpp b/DSView/pv/view/trace.cpp index 55408995..f54796f4 100644 --- a/DSView/pv/view/trace.cpp +++ b/DSView/pv/view/trace.cpp @@ -53,6 +53,7 @@ Trace::Trace(QString name, uint16_t index, int type) : _view(NULL), _name(name), _v_offset(INT_MAX), + _v_offset_orig(INT_MAX), _type(type), _sec_index(0), _totalHeight(30), @@ -66,6 +67,7 @@ Trace::Trace(QString name, std::list index_list, int type, int sec_index) : _view(NULL), _name(name), _v_offset(INT_MAX), + _v_offset_orig(INT_MAX), _type(type), _index_list(index_list), _sec_index(sec_index), @@ -80,6 +82,7 @@ Trace::Trace(const Trace &t) : _name(t._name), _colour(t._colour), _v_offset(t._v_offset), + _v_offset_orig(INT_MAX), _type(t._type), _index_list(t._index_list), _sec_index(t._sec_index), diff --git a/DSView/pv/view/trace.h b/DSView/pv/view/trace.h index d05c8fb9..0e07b4f7 100644 --- a/DSView/pv/view/trace.h +++ b/DSView/pv/view/trace.h @@ -107,7 +107,15 @@ class Trace : public SelectableItem * Sets the vertical layout offset of this signal. */ inline void set_v_offset(int v_offset){ - _v_offset = v_offset; + _v_offset_orig = _v_offset = v_offset; + } + + /** + * Sets the vertical scroll offset of this signal. + * (additional v_offset displacement) + */ + inline void update_v_scroll(int v_scroll) { + _v_offset = _v_offset_orig + v_scroll; } /** @@ -336,6 +344,7 @@ private slots: QString _name; QColor _colour; int _v_offset; + int _v_offset_orig; int _type; std::list _index_list; int _sec_index; diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index 8e701e9f..c3202a0f 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -63,7 +63,7 @@ const int View::RulerHeight = 50; const int View::MaxScrollValue = INT_MAX / 2; const int View::HeightUnit = 20; // also serves as minimum signal height -const int View::SignalMargin = 7; +const int View::SignalMargin = 3; const int View::SignalSnapGridSize = 10; const QColor View::CursorAreaColour(220, 231, 243); @@ -642,7 +642,7 @@ void View::update_scroll() int total_height = 0; for (auto t : traces) { if (t->enabled()) - total_height += t->get_totalHeight() + SignalMargin; + total_height += t->get_totalHeight() + 2 * SignalMargin; } // Make sure we can scroll the last signal past the status bar @@ -781,7 +781,7 @@ void View::signals_changed(const Trace* eventTrace) max_height = (v + 1) * HeightUnit; } if (height < 2*actualMargin) { - actualMargin /= 2; + //actualMargin /= 2; _signalHeight = max((double)HeightUnit, (_time_viewport->height() - 2 * actualMargin * label_size) * 1.0 / total_rows); } @@ -989,12 +989,9 @@ void View::v_scroll_value_changed(int value) std::vector traces; get_traces(ALL_VIEW, traces); - int y_offset = -value + (traces[0]->get_totalHeight() / 2) + (SignalMargin / 2); // Start from negative scroll value to move traces up - for (auto t : traces) { if (t->enabled()) { - t->set_v_offset(y_offset); - y_offset += t->get_totalHeight() + SignalMargin; + t->update_v_scroll(-value); } }