# HG changeset patch # User John W. Eaton # Date 1366174627 14400 # Node ID faccc20d5f3923028ceec3317db8530dd2507a85 # Parent 9bc1f8278966d72b70d255d69746301ca46892cd allow doc browser tabs to be moved and individually closed * webinfo.h, webinfo.cc (webinfo::_close_tab_button): Delete member variable and all uses. (webinfo::webinfo): Set tab bar properties to allow moving and deleting individual tabs. Connect _close_tab_button::clicked to webinfo::close_tab. (webinfo::close_tab): Replace with closeTab function. Allow "Top" tab to be close, but require that at least one tab is open. (webinfo::closeTab): Delete. diff --git a/libgui/src/qtinfo/webinfo.cc b/libgui/src/qtinfo/webinfo.cc --- a/libgui/src/qtinfo/webinfo.cc +++ b/libgui/src/qtinfo/webinfo.cc @@ -43,14 +43,11 @@ hbox_layout->setMargin (2); vbox_layout->addLayout (hbox_layout); - _close_tab_button = new QPushButton (this); - _close_tab_button->setSizePolicy (QSizePolicy::Fixed,QSizePolicy::Preferred); - _close_tab_button->setIcon (QIcon (":/actions/icons/stop.png")); - hbox_layout->addWidget (_close_tab_button); - _tab_bar = new QTabBar (this); _tab_bar->setSizePolicy (QSizePolicy::Preferred,QSizePolicy::Preferred); _tab_bar->setExpanding (false); + _tab_bar->setTabsClosable (true); + _tab_bar->setMovable (true); hbox_layout->addWidget (_tab_bar); _zoom_in_button = new QToolButton (this); @@ -78,7 +75,7 @@ _search_check_box = new QCheckBox (tr ("Global search")); hbox_layout->addWidget (_search_check_box); - connect (_close_tab_button, SIGNAL (clicked ()), this, SLOT (close_tab ())); + connect (_tab_bar, SIGNAL (tabCloseRequested (int)), this, SLOT (close_tab (int))); connect (_tab_bar, SIGNAL (currentChanged (int)), this, SLOT (current_tab_changed (int))); connect (_zoom_in_button, SIGNAL (clicked ()), this, SLOT (zoom_in ())); connect (_zoom_out_button, SIGNAL (clicked ()), this, SLOT (zoom_out ())); @@ -170,22 +167,17 @@ } void -webinfo::close_tab () +webinfo::close_tab (int index) { - int index = _tab_bar->currentIndex (); - if (_tab_bar->tabText (index) != "Top") - closeTab (index); -} + if (_tab_bar->count () > 1) + { + QVariant tab_data = _tab_bar->tabData (index); + QWidget *w = static_cast (tab_data.value ()); + _stacked_widget->removeWidget (w); + delete w; -void -webinfo::closeTab (int index) -{ - QVariant tab_data = _tab_bar->tabData (index); - QWidget *w = static_cast (tab_data.value ()); - _stacked_widget->removeWidget (w); - delete w; - - _tab_bar->removeTab (index); + _tab_bar->removeTab (index); + } } void diff --git a/libgui/src/qtinfo/webinfo.h b/libgui/src/qtinfo/webinfo.h --- a/libgui/src/qtinfo/webinfo.h +++ b/libgui/src/qtinfo/webinfo.h @@ -37,7 +37,7 @@ public slots: void link_clicked (const QUrl& link); void current_tab_changed (int index); - void close_tab (); + void close_tab (int index); void search (); void zoom_in (); void zoom_out (); @@ -46,7 +46,6 @@ QTextBrowser *_text_browser; QTabBar *_tab_bar; QStackedWidget *_stacked_widget; - QPushButton *_close_tab_button; QLineEdit *_search_line_edit; QCheckBox *_search_check_box; QToolButton *_zoom_in_button; @@ -56,5 +55,4 @@ QFont _font_web; QTextBrowser *addNewTab (const QString& name); - void closeTab(int index); };