diff libgui/src/main-window.cc @ 16453:2e3c652c89d1

improve encapsulation of documentation browser window object * documentation-dockwidget.h, documentation-dockwidget.cc (documentation_dock_widget): Derive from octave_dock_widget, not QDockWidget. (documentation_dock_widget::documentation_dock_widget): Don't connect documentation_dock_widget::visibilityChanged signal to documentation_dock_widget::handle_visibility_changed. Don't connect documentation_dock_widget::topLevelChanged signal to documentation_dock_widget::top_level_changed. Set status tip. (documentation_dock_widget::connect_visibility_changed): New function. (documentation_dock_widget::closeEvent): Delete. (documentation_dock_widget::focus, (documentation_dock_widget::handle_visibility): New functions. (documentation_dock_widget::active_changed): Delete signal. * main-window.h, main-window.cc (main_window::file_browser_window): Rename from documentation_dock_widget. Change all uses. (main_window::main_window): Initialize it. (main_window::focus_documentation, main_window::handle_documentation_visible): Delete. (main_window::connect_visibility_changed): Call doc_browser_window->connect_visibility_changed. (main_window::construct): Don't create _documentation_dock_widget.
author John W. Eaton <jwe@octave.org>
date Sun, 07 Apr 2013 00:43:36 -0400
parents 744ff2fe11ce
children 246d25c8761b
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Sat Apr 06 23:58:58 2013 -0400
+++ b/libgui/src/main-window.cc	Sun Apr 07 00:43:36 2013 -0400
@@ -61,7 +61,8 @@
     status_bar (new QStatusBar ()),
     command_window (new terminal_dock_widget (this)),
     history_window (new history_dock_widget (this)),
-    file_browser_window (new files_dock_widget (this))
+    file_browser_window (new files_dock_widget (this)),
+    doc_browser_window (new documentation_dock_widget (this))
 {
   // We have to set up all our windows, before we finally launch octave.
   construct ();
@@ -74,6 +75,7 @@
   delete command_window;
   delete history_window;
   delete file_browser_window;
+  delete doc_browser_window;
 
   // Clean up all dynamically created objects to ensure they are
   // deleted before this main_window is.  Otherwise, some will be
@@ -90,9 +92,6 @@
     delete _file_editor;
 #endif
 
-  if (_documentation_dock_widget)
-    delete _documentation_dock_widget;
-
   delete _workspace_view;
 }
 
@@ -377,19 +376,6 @@
 }
 
 void
-main_window::focus_documentation ()
-{
-  if (!_documentation_dock_widget->isVisible ())
-    {
-      _documentation_dock_widget->setVisible (true);
-    }
-
-  _documentation_dock_widget->setFocus ();
-  _documentation_dock_widget->activateWindow ();
-  _documentation_dock_widget->raise ();
-}
-
-void
 main_window::handle_workspace_visible (bool visible)
 {
   // if changed to visible and widget is not floating
@@ -408,14 +394,6 @@
 }
 
 void
-main_window::handle_documentation_visible (bool visible)
-{
-  // if changed to visible and widget is not floating
-  if (visible && !_documentation_dock_widget->isFloating ())
-    focus_documentation ();
-}
-
-void
 main_window::handle_enter_debugger (void)
 {
   setWindowTitle ("Octave (Debugging)");
@@ -580,6 +558,7 @@
   command_window->connect_visibility_changed ();
   history_window->connect_visibility_changed ();
   file_browser_window->connect_visibility_changed ();
+  doc_browser_window->connect_visibility_changed ();
 
   connect (_workspace_view,       SIGNAL (visibilityChanged (bool)),
            this,                  SLOT (handle_workspace_visible (bool)));
@@ -589,8 +568,6 @@
            this,                  SLOT (handle_editor_visible (bool)));
 #endif
 
-  connect (_documentation_dock_widget,  SIGNAL (visibilityChanged (bool)),
-           this,                  SLOT (handle_documentation_visible (bool)));
 }
 
 
@@ -610,9 +587,6 @@
   connect (_workspace_model, SIGNAL (model_changed ()),
            _workspace_view, SLOT (model_changed ()));
 
-  _documentation_dock_widget= new documentation_dock_widget (this);
-  _documentation_dock_widget->setStatusTip (tr ("See the documentation for help."));
-
   _current_directory_line_edit = new QLineEdit (this);
   _current_directory_combo_box = new QComboBox (this);
   _current_directory_combo_box->setFixedWidth (current_directory_width);
@@ -984,8 +958,8 @@
            show_editor_action,          SLOT   (setChecked (bool)));
 #endif
   connect (show_documentation_action,   SIGNAL (toggled (bool)),
-           _documentation_dock_widget,  SLOT   (setVisible (bool)));
-  connect (_documentation_dock_widget,  SIGNAL (active_changed (bool)),
+           doc_browser_window,          SLOT   (setVisible (bool)));
+  connect (doc_browser_window,          SIGNAL (active_changed (bool)),
            show_documentation_action,   SLOT   (setChecked (bool)));
 
   connect (command_window_action,       SIGNAL (triggered ()),
@@ -1000,9 +974,9 @@
   connect (editor_action,               SIGNAL (triggered ()),
            this,                        SLOT (focus_editor ()));
   connect (documentation_action,        SIGNAL (triggered ()),
-           this,                        SLOT (focus_documentation ()));
+           doc_browser_window,          SLOT (focus ()));
   connect (ondisk_documentation_action, SIGNAL (triggered ()),
-           this,                        SLOT (focus_documentation ()));
+           doc_browser_window,          SLOT (focus ()));
 
   connect (reset_windows_action,        SIGNAL (triggered ()),
            this,                        SLOT   (reset_windows ()));
@@ -1059,8 +1033,8 @@
   setWindowTitle ("Octave");
   setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks);
   addDockWidget (Qt::RightDockWidgetArea, command_window);
-  addDockWidget (Qt::RightDockWidgetArea, _documentation_dock_widget);
-  tabifyDockWidget (command_window, _documentation_dock_widget);
+  addDockWidget (Qt::RightDockWidgetArea, doc_browser_window);
+  tabifyDockWidget (command_window, doc_browser_window);
 #ifdef HAVE_QSCINTILLA
   addDockWidget (Qt::RightDockWidgetArea, _file_editor);
   tabifyDockWidget (command_window, _file_editor);