changeset 16529:faccc20d5f39

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.
author John W. Eaton <jwe@octave.org>
date Wed, 17 Apr 2013 00:57:07 -0400
parents 9bc1f8278966
children 7ca7e7d5eb91
files libgui/src/qtinfo/webinfo.cc libgui/src/qtinfo/webinfo.h
diffstat 2 files changed, 13 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/qtinfo/webinfo.cc	Wed Apr 17 00:17:21 2013 -0400
+++ b/libgui/src/qtinfo/webinfo.cc	Wed Apr 17 00:57:07 2013 -0400
@@ -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<QWidget*> (tab_data.value<void*> ());
+      _stacked_widget->removeWidget (w);
+      delete w;
 
-void
-webinfo::closeTab (int index)
-{
-  QVariant tab_data = _tab_bar->tabData (index);
-  QWidget *w = static_cast<QWidget*> (tab_data.value<void*> ());
-  _stacked_widget->removeWidget (w);
-  delete w;
-
-  _tab_bar->removeTab (index);
+      _tab_bar->removeTab (index);
+    }
 }
 
 void
--- a/libgui/src/qtinfo/webinfo.h	Wed Apr 17 00:17:21 2013 -0400
+++ b/libgui/src/qtinfo/webinfo.h	Wed Apr 17 00:57:07 2013 -0400
@@ -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);
 };