From: Soeren Apel Date: Tue, 30 May 2017 06:07:50 +0000 (+0200) Subject: View: Adjust top margin when needed X-Git-Tag: pulseview-0.4.0~62 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8a5fd81fea577663e8c0f17e53d5928599d0926d;p=pulseview.git View: Adjust top margin when needed When the view is big and the traces are vertically centered, there will be blank space above and below the block of traces. When the user then resizes the window and makes it smaller, the white space stays, pushing traces out of the view that could fit on-screen if the blank space was adjusted properly. This is what we do with this patch. If there is still enough space to make everything fit, we center the traces vertically. If there's not enough space to make everything fit, we make sure that the top traces are shown. --- diff --git a/pv/view/view.cpp b/pv/view/view.cpp index c7944179..2fc14d2b 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -746,6 +746,30 @@ void View::calculate_tick_spacing() set_tick_precision(tick_precision); } +void View::adjust_top_margin() +{ + assert(viewport_); + + const QSize areaSize = viewport_->size(); + + const pair extents = v_extents(); + const int top_margin = owner_visual_v_offset() + extents.first; + const int trace_bottom = owner_visual_v_offset() + extents.first + extents.second; + + // Do we have empty space at the top while the last trace goes out of screen? + if ((top_margin > 0) && (trace_bottom > areaSize.height())) { + const int trace_height = extents.second - extents.first; + + // Center everything vertically if there is enough space + if (areaSize.height() >= trace_height) + set_v_offset(extents.first - + ((areaSize.height() - trace_height) / 2)); + else + // Remove the top margin to make as many traces fit on screen as possible + set_v_offset(extents.first); + } +} + void View::update_scroll() { assert(viewport_); @@ -955,8 +979,12 @@ bool View::eventFilter(QObject *object, QEvent *event) return QObject::eventFilter(object, event); } -void View::resizeEvent(QResizeEvent*) +void View::resizeEvent(QResizeEvent* event) { + // Only adjust the top margin if we shrunk vertically + if (event->size().height() < event->oldSize().height()) + adjust_top_margin(); + update_layout(); } diff --git a/pv/view/view.hpp b/pv/view/view.hpp index 1819ffdd..8ef8812c 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -315,6 +315,8 @@ private: */ void calculate_tick_spacing(); + void adjust_top_margin(); + void update_scroll(); void reset_scroll();