diff libgui/src/documentation-dockwidget.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 bbbb89cc338f
children
line wrap: on
line diff
--- a/libgui/src/documentation-dockwidget.cc	Sat Apr 06 23:58:58 2013 -0400
+++ b/libgui/src/documentation-dockwidget.cc	Sun Apr 07 00:43:36 2013 -0400
@@ -27,42 +27,38 @@
 #include "documentation-dockwidget.h"
 
 documentation_dock_widget::documentation_dock_widget (QWidget *p)
-  : QDockWidget (p)
+  : octave_dock_widget (p)
 {
   setObjectName ("DocumentationDockWidget");
-  setWindowIcon (QIcon(":/actions/icons/logo.png"));
+  setWindowIcon (QIcon (":/actions/icons/logo.png"));
   setWindowTitle (tr ("Documentation"));
-
-  connect (this, SIGNAL (visibilityChanged (bool)),
-           this, SLOT (handle_visibility_changed (bool)));
-  // topLevelChanged is emitted when floating property changes (floating = true)
-  connect (this, SIGNAL (topLevelChanged(bool)), this, SLOT(top_level_changed(bool)));
+  setStatusTip (tr ("See the documentation for help."));
 
   _webinfo = new webinfo (this);
   setWidget (_webinfo);
 }
 
 void
-documentation_dock_widget::handle_visibility_changed (bool visible)
+documentation_dock_widget::connect_visibility_changed (void)
 {
-  if (visible)
-    emit active_changed (true);
+  connect (this, SIGNAL (visibilityChanged (bool)),
+           this, SLOT (handle_visibility (bool)));
 }
 
 void
-documentation_dock_widget::closeEvent (QCloseEvent *e)
+documentation_dock_widget::focus (void)
 {
-  emit active_changed (false);
-  QDockWidget::closeEvent (e);
+  if (! isVisible ())
+    setVisible (true);
+
+  setFocus ();
+  activateWindow ();
+  raise ();
 }
 
-// slot for signal that is emitted when floating property changes
 void
-documentation_dock_widget::top_level_changed (bool floating)
+documentation_dock_widget::handle_visibility (bool visible)
 {
-  if(floating)
-    {
-      setWindowFlags(Qt::Window);  // make a window from the widget when floating
-      show();                      // make it visible again since setWindowFlags hides it
-    }
+  if (visible && ! isFloating ())
+    focus ();
 }