]> sigrok.org Git - pulseview.git/commitdiff
View: Optimize header pane sizing
authorSoeren Apel <redacted>
Sun, 4 Jun 2017 20:11:59 +0000 (22:11 +0200)
committerUwe Hermann <redacted>
Mon, 5 Jun 2017 15:17:40 +0000 (17:17 +0200)
Before, the header pane didn't resize to accomodate all signals
when a new session was created and a driver selected (e.g. demo).
To fix this, the header pane autosizing was put in a method of
its own and is now called when new signals are added.

Also, the name of header_fully_visible() needed adjustment
because it also returned true when it *wasn't* 100% visible
due to the margin of error that we permit. It's now called
header_was_shrunk() and its return value logic inverted.

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

index 4ac98114104a4eb603aea4c9000e825a8f99dc2c..61b03b2e16b8495b8d8c6e8f0093bb4b7830a978 100644 (file)
@@ -872,7 +872,7 @@ void View::set_scroll_default()
                set_v_offset(extents.first);
 }
 
-bool View::header_fully_visible() const
+bool View::header_was_shrunk() const
 {
        const int header_pane_width = splitter_->sizes().front();
        const int header_width = header_->extended_size_hint().width();
@@ -880,24 +880,24 @@ bool View::header_fully_visible() const
        // Allow for a slight margin of error so that we also accept
        // slight differences when e.g. a label name change increased
        // the overall width
-       return (header_pane_width >= (header_width - 10));
+       return (header_pane_width < (header_width - 10));
 }
 
-void View::update_layout()
+void View::expand_header_to_fit()
 {
-       // Only adjust pane sizes if the header hasn't been partially hidden by the user
-       if (header_fully_visible()) {
-               int splitter_area_width = 0;
-               for (int w : splitter_->sizes())
-                       splitter_area_width += w;
-
-               // Make sure the header has enough horizontal space to show all labels fully
-               QList<int> pane_sizes;
-               pane_sizes.push_back(header_->extended_size_hint().width());
-               pane_sizes.push_back(splitter_area_width - header_->extended_size_hint().width());
-               splitter_->setSizes(pane_sizes);
-       }
+       int splitter_area_width = 0;
+       for (int w : splitter_->sizes())
+               splitter_area_width += w;
 
+       // Make sure the header has enough horizontal space to show all labels fully
+       QList<int> pane_sizes;
+       pane_sizes.push_back(header_->extended_size_hint().width());
+       pane_sizes.push_back(splitter_area_width - header_->extended_size_hint().width());
+       splitter_->setSizes(pane_sizes);
+}
+
+void View::update_layout()
+{
        update_scroll();
 }
 
@@ -1071,8 +1071,12 @@ void View::on_splitter_moved()
        // Setting the maximum width of the header widget doesn't work as
        // expected because the splitter would allow the user to make the
        // pane wider than that, creating empty space as a result.
-       // To make this work, we stricly enforce the maximum width by calling
-       update_layout();
+       // To make this work, we stricly enforce the maximum width by
+       // expanding the header unless the user shrunk it on purpose.
+       // As we're then setting the width of the header pane, we set the
+       // splitter to the maximum allowed position.
+       if (!header_was_shrunk())
+               expand_header_to_fit();
 }
 
 void View::h_scroll_value_changed(int value)
@@ -1270,6 +1274,12 @@ void View::signals_changed()
                        offset += extents.second;
        }
 
+
+       if (!new_top_level_items.empty())
+               // Expand the header pane because the header should become fully
+               // visible when new signals are added
+               expand_header_to_fit();
+
        update_layout();
 
        header_->update();
index 1184213150d21449423f97156f9bafa9fbe01f81..76a38f16630b672cdd2a5ba1ebcc2378ca363277 100644 (file)
@@ -323,7 +323,9 @@ private:
 
        void set_scroll_default();
 
-       bool header_fully_visible() const;
+       bool header_was_shrunk() const;
+
+       void expand_header_to_fit();
 
        void update_layout();