]> sigrok.org Git - pulseview.git/blobdiff - pv/view/view.cpp
View: Limit header pane width
[pulseview.git] / pv / view / view.cpp
index d9b02353adaf708f04ea47b2ad4b4cc1112d7bb0..17b9c1532cdea80da45e8fbce0e13ff7783a2a3d 100644 (file)
@@ -155,7 +155,7 @@ View::View(Session &session, bool is_main_view, QWidget *parent) :
        ruler_ = new Ruler(*this);
 
        header_ = new Header(*this);
-       header_->setMinimumWidth(15);  // So that the arrow tips show at least
+       header_->setMinimumWidth(10);  // So that the arrow tips show at least
 
        // We put the header into a simple layout so that we can add the top margin,
        // allowing us to make it line up with the bottom of the ruler
@@ -204,6 +204,9 @@ View::View(Session &session, bool is_main_view, QWidget *parent) :
        connect(ruler_, SIGNAL(selection_changed()),
                this, SIGNAL(selection_changed()));
 
+       connect(splitter_, SIGNAL(splitterMoved(int, int)),
+               this, SLOT(on_splitter_moved()));
+
        connect(this, SIGNAL(hover_point_changed()),
                this, SLOT(on_hover_point_changed()));
 
@@ -300,6 +303,8 @@ void View::save_settings(QSettings &settings) const
        settings.setValue("v_offset",
                scrollarea_->verticalScrollBar()->sliderPosition());
 
+       settings.setValue("splitter_state", splitter_->saveState());
+
        stringstream ss;
        boost::archive::text_oarchive oa(ss);
        oa << boost::serialization::make_nvp("offset", offset_);
@@ -331,6 +336,9 @@ void View::restore_settings(QSettings &settings)
                set_offset(offset);
        }
 
+       if (settings.contains("splitter_state"))
+               splitter_->restoreState(settings.value("splitter_state").toByteArray());
+
        for (shared_ptr<Signal> signal : signals_) {
                settings.beginGroup(signal->base()->internal_name());
                signal->restore_settings(settings);
@@ -869,7 +877,10 @@ bool View::header_fully_visible() const
        const int header_pane_width = splitter_->sizes().front();
        const int header_width = header_->extended_size_hint().width();
 
-       return (header_pane_width >= header_width);
+       // 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));
 }
 
 void View::update_layout()
@@ -1035,8 +1046,13 @@ void View::row_item_appearance_changed(bool label, bool content)
 
 void View::time_item_appearance_changed(bool label, bool content)
 {
-       if (label)
+       if (label) {
                ruler_->update();
+
+               // Make sure the header pane width is updated, too
+               update_layout();
+       }
+
        if (content)
                viewport_->update();
 }
@@ -1050,6 +1066,15 @@ void View::extents_changed(bool horz, bool vert)
        lazy_event_handler_.start();
 }
 
+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();
+}
+
 void View::h_scroll_value_changed(int value)
 {
        if (updating_scroll_)