# HG changeset patch # User John W. Eaton # Date 1365309816 14400 # Node ID 2e3c652c89d111763f3d5bdaf81acc80102e0f7b # Parent 744ff2fe11ce1322672f01830afe2204ea34e8ce 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. diff -r 744ff2fe11ce -r 2e3c652c89d1 libgui/src/documentation-dockwidget.cc --- 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 (); } diff -r 744ff2fe11ce -r 2e3c652c89d1 libgui/src/documentation-dockwidget.h --- a/libgui/src/documentation-dockwidget.h Sat Apr 06 23:58:58 2013 -0400 +++ b/libgui/src/documentation-dockwidget.h Sun Apr 07 00:43:36 2013 -0400 @@ -23,30 +23,28 @@ #ifndef DOCUMENTATIONDOCKWIDGET_H #define DOCUMENTATIONDOCKWIDGET_H -#include -#include +#include "octave-dock-widget.h" + #include "webinfo.h" -class documentation_dock_widget : public QDockWidget +class documentation_dock_widget : public octave_dock_widget { Q_OBJECT - public: + +public: + documentation_dock_widget (QWidget *parent = 0); + void connect_visibility_changed (void); + public slots: - /** Slot to steer changing visibility from outside. */ - void handle_visibility_changed (bool visible); - /** Slot when floating property changes */ - void top_level_changed (bool floating); -signals: - /** Custom signal that tells if a user has clicked away that dock widget. */ - void active_changed (bool active); + void focus (void); -protected: - void closeEvent (QCloseEvent *event); + void handle_visibility (bool); private: + webinfo *_webinfo; }; diff -r 744ff2fe11ce -r 2e3c652c89d1 libgui/src/main-window.cc --- 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); diff -r 744ff2fe11ce -r 2e3c652c89d1 libgui/src/main-window.h --- a/libgui/src/main-window.h Sat Apr 06 23:58:58 2013 -0400 +++ b/libgui/src/main-window.h Sun Apr 07 00:43:36 2013 -0400 @@ -1,5 +1,6 @@ /* +Copyright (C) 2013 John W. Eaton Copyright (C) 2011-2012 Jacob Dawid This file is part of Octave. @@ -104,10 +105,8 @@ void focus_workspace (); void focus_editor (); - void focus_documentation (); void handle_workspace_visible (bool); void handle_editor_visible (bool); - void handle_documentation_visible (bool); void handle_enter_debugger (void); void handle_exit_debugger (void); @@ -160,6 +159,7 @@ terminal_dock_widget *command_window; history_dock_widget *history_window; files_dock_widget *file_browser_window; + documentation_dock_widget *doc_browser_window; #ifdef HAVE_QSCINTILLA file_editor_interface * _file_editor; @@ -174,7 +174,6 @@ // Dock widgets. workspace_view * _workspace_view; - documentation_dock_widget*_documentation_dock_widget; // Toolbars. QComboBox * _current_directory_combo_box;