]> sigrok.org Git - pulseview.git/commitdiff
MainWindow: Prevent the QTabWidget from collapsing when empty
authorSoeren Apel <redacted>
Mon, 10 Oct 2016 07:15:04 +0000 (09:15 +0200)
committerSoeren Apel <redacted>
Sun, 4 Dec 2016 13:37:37 +0000 (14:37 +0100)
pv/mainwindow.cpp
pv/mainwindow.hpp

index 39ce7ed6f4b0034ad3b0adfc7241cdcd76340779..36f9b1a086f9861358f3de8028a4e37ff6e654d5 100644 (file)
@@ -248,6 +248,8 @@ shared_ptr<Session> MainWindow::add_session()
 
 void MainWindow::remove_session(shared_ptr<Session> session)
 {
+       int h = new_session_button_->height();
+
        for (shared_ptr<views::ViewBase> view : session->views()) {
                // Find the dock the view is contained in and remove it
                for (auto entry : view_docks_)
@@ -274,10 +276,21 @@ void MainWindow::remove_session(shared_ptr<Session> session)
        sessions_.remove_if([&](shared_ptr<Session> s) {
                return s == session; });
 
-       // Update the window title if there is no view left to
-       // generate focus change events
-       if (sessions_.empty())
+       if (sessions_.empty()) {
+               // When there are no more tabs, the height of the QTabWidget
+               // drops to zero. We must prevent this to keep the static
+               // widgets visible
+               for (QWidget *w : static_tab_widget_->findChildren<QWidget*>())
+                       w->setMinimumHeight(h);
+
+               int margin = static_tab_widget_->layout()->contentsMargins().bottom();
+               static_tab_widget_->setMinimumHeight(h + 2 * margin);
+               session_selector_.setMinimumHeight(h + 2 * margin);
+
+               // Update the window title if there is no view left to
+               // generate focus change events
                setWindowTitle(WindowTitle);
+       }
 }
 
 void MainWindow::setup_ui()
@@ -318,11 +331,10 @@ void MainWindow::setup_ui()
        layout->setContentsMargins(2, 2, 2, 2);
        layout->addWidget(new_session_button_);
 
-       QWidget* static_tab_widget_ = new QWidget();
+       static_tab_widget_ = new QWidget();
        static_tab_widget_->setLayout(layout);
 
        session_selector_.setCornerWidget(static_tab_widget_, Qt::TopLeftCorner);
-
        session_selector_.setTabsClosable(true);
 
        connect(new_session_button_, SIGNAL(clicked(bool)),
index 9d5b04125416e17ea24da97e065b03e67f47c359..0904845f983e5362c8ad56ee76633dcac8ce5e6e 100644 (file)
@@ -129,6 +129,7 @@ private:
 
        std::map< std::shared_ptr<Session>, QMainWindow*> session_windows_;
 
+       QWidget *static_tab_widget_;
        QToolButton *new_session_button_;
        QTabWidget session_selector_;