]> sigrok.org Git - pulseview.git/commitdiff
View: Adjust top margin when needed
authorSoeren Apel <redacted>
Tue, 30 May 2017 06:07:50 +0000 (08:07 +0200)
committerUwe Hermann <redacted>
Tue, 30 May 2017 18:10:15 +0000 (20:10 +0200)
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.

pv/view/view.cpp
pv/view/view.hpp

index c7944179ad5a7185de2dc3c0bf2a30c69ef09860..2fc14d2b64c9e777827650f7565125d1fe351aae 100644 (file)
@@ -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<int, int> 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();
 }
 
index 1819ffddaba08873b30b10d23a900beed0001189..8ef8812cf5443aaaf1553343eeda27df6b77073b 100644 (file)
@@ -315,6 +315,8 @@ private:
         */
        void calculate_tick_spacing();
 
+       void adjust_top_margin();
+
        void update_scroll();
 
        void reset_scroll();