Mercurial > hg > octave-lyh
changeset 16461:094bd3627ead
move common functionality to octave_dock_widget base class
* octave-dock-widget.h (octave_dock_widget::handle_visibility,
octave_dock_widget::connect_visibility_changed,
octave_dock_widget::focus): New virtual functions.
* documentation-dock-widget.cc, documentation-dock-widget.h,
files-dock-widget.cc, files-dock-widget.h, history-dock-widget.cc,
history-dock-widget.h, terminal-dock-widget.cc,
terminal-dock-widget.h: Inherit handle_visibility,
connect_visibility_changed, and focus methods.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 07 Apr 2013 12:36:07 -0400 |
parents | 4d4e7c6f839d |
children | 8c666c7b0e5d |
files | libgui/src/documentation-dock-widget.cc libgui/src/documentation-dock-widget.h libgui/src/files-dock-widget.cc libgui/src/files-dock-widget.h libgui/src/history-dock-widget.cc libgui/src/history-dock-widget.h libgui/src/octave-dock-widget.h libgui/src/terminal-dock-widget.cc libgui/src/terminal-dock-widget.h |
diffstat | 9 files changed, 55 insertions(+), 153 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/documentation-dock-widget.cc +++ b/libgui/src/documentation-dock-widget.cc @@ -37,28 +37,3 @@ _webinfo = new webinfo (this); setWidget (_webinfo); } - -void -documentation_dock_widget::connect_visibility_changed (void) -{ - connect (this, SIGNAL (visibilityChanged (bool)), - this, SLOT (handle_visibility (bool))); -} - -void -documentation_dock_widget::focus (void) -{ - if (! isVisible ()) - setVisible (true); - - setFocus (); - activateWindow (); - raise (); -} - -void -documentation_dock_widget::handle_visibility (bool visible) -{ - if (visible && ! isFloating ()) - focus (); -}
--- a/libgui/src/documentation-dock-widget.h +++ b/libgui/src/documentation-dock-widget.h @@ -35,14 +35,6 @@ documentation_dock_widget (QWidget *parent = 0); - void connect_visibility_changed (void); - -public slots: - - void focus (void); - - void handle_visibility (bool); - private: webinfo *_webinfo;
--- a/libgui/src/files-dock-widget.cc +++ b/libgui/src/files-dock-widget.cc @@ -136,13 +136,6 @@ } void -files_dock_widget::connect_visibility_changed (void) -{ - connect (this, SIGNAL (visibilityChanged (bool)), - this, SLOT (handle_visibility (bool))); -} - -void files_dock_widget::item_double_clicked (const QModelIndex& index) { // Retrieve the file info associated with the model index. @@ -211,22 +204,3 @@ // TODO: React on option for hidden files. } } - -void -files_dock_widget::focus (void) -{ - if (! isVisible ()) - setVisible (true); - - setFocus (); - activateWindow (); - raise (); -} - -void -files_dock_widget::handle_visibility (bool visible) -{ - if (visible && ! isFloating ()) - focus (); -} -
--- a/libgui/src/files-dock-widget.h +++ b/libgui/src/files-dock-widget.h @@ -53,8 +53,6 @@ ~files_dock_widget (); - void connect_visibility_changed (void); - public slots: /** Slot for handling a change in directory via double click. */ @@ -74,20 +72,16 @@ /** Tells the widget to react on changed settings. */ void notice_settings (const QSettings *settings); - void focus (void); +signals: - void handle_visibility (bool visible); - -signals: /** Emitted, whenever the user requested to open a file. */ void open_file (const QString& fileName); /** Emitted, whenever the currently displayed directory changed. */ void displayed_directory_changed (const QString& dir); -protected: +private: -private: // TODO: Add toolbar with buttons for navigating the path, creating dirs, etc /** Toolbar for file and directory manipulation. */
--- a/libgui/src/history-dock-widget.cc +++ b/libgui/src/history-dock-widget.cc @@ -54,13 +54,6 @@ } void -history_dock_widget::connect_visibility_changed (void) -{ - connect (this, SIGNAL (visibilityChanged (bool)), - this, SLOT (handle_visibility (bool))); -} - -void history_dock_widget::construct () { _history_model = new QStringListModel (); @@ -176,22 +169,3 @@ { _history_model->setStringList (QStringList ()); } - -void -history_dock_widget::focus (void) -{ - if (! isVisible ()) - setVisible (true); - - setFocus (); - activateWindow (); - raise (); -} - -void -history_dock_widget::handle_visibility (bool visible) -{ - if (visible && ! isFloating ()) - focus (); -} -
--- a/libgui/src/history-dock-widget.h +++ b/libgui/src/history-dock-widget.h @@ -37,17 +37,12 @@ history_dock_widget (QWidget *parent = 0); - void connect_visibility_changed (void); - public slots: void set_history (const QStringList& hist); void append_history (const QString& hist_entry); void clear_history (void); - void focus (void); - void handle_visibility (bool); - signals: void information (const QString& message);
--- a/libgui/src/octave-dock-widget.h +++ b/libgui/src/octave-dock-widget.h @@ -20,43 +20,68 @@ */ -#ifndef OCTAVEDOCKWIDGET_H -#define OCTAVEDOCKWIDGET_H +#if !defined (octave_dock_widget_h) +#define octave_dock_widget_h 1 #include <QDockWidget> -//#include <QMenu> -//#include <QToolBar> class octave_dock_widget : public QDockWidget { Q_OBJECT - public: +public: + octave_dock_widget (QWidget *p) : QDockWidget (p) { connect (this, SIGNAL (visibilityChanged (bool)), this, SLOT (handle_visibility_changed (bool))); - connect (this, SIGNAL (topLevelChanged(bool)), - this, SLOT(top_level_changed(bool))); + connect (this, SIGNAL (topLevelChanged (bool)), + this, SLOT (top_level_changed (bool))); } virtual ~octave_dock_widget () { } + virtual void connect_visibility_changed (void) + { + connect (this, SIGNAL (visibilityChanged (bool)), + this, SLOT (handle_visibility (bool))); + } + signals: - /** Custom signal that tells if a user has clicked away + + /** Custom signal that tells whether a user has clicked away * that dock widget, i.e the active dock widget has * changed. */ void active_changed (bool active); protected: + virtual void closeEvent (QCloseEvent *e) { emit active_changed (false); QDockWidget::closeEvent (e); } +public slots: + + virtual void focus (void) + { + if (! isVisible ()) + setVisible (true); + + setFocus (); + activateWindow (); + raise (); + } + + virtual void handle_visibility (bool visible) + { + if (visible && ! isFloating ()) + focus (); + } + protected slots: /** Slot to steer changing visibility from outside. */ @@ -69,13 +94,14 @@ /** Slot when floating property changes */ virtual void top_level_changed (bool floating) { - if(floating) + if (floating) { - setWindowFlags(Qt::Window); // make a window from the widget when floating - show(); // make it visible again since setWindowFlags hides it + // Make a window from the widget when floating and make it + // visible again since setWindowFlags hides it. + setWindowFlags (Qt::Window); + show(); } } - }; -#endif // OCTAVEDOCKWIDGET_H +#endif
--- a/libgui/src/terminal-dock-widget.cc +++ b/libgui/src/terminal-dock-widget.cc @@ -47,11 +47,6 @@ connect (parent (), SIGNAL (relay_command_signal (const QString&)), this, SLOT (relay_command (const QString&))); - // topLevelChanged is emitted when floating property changes (floating - // = true) - connect (this, SIGNAL (topLevelChanged (bool)), - this, SLOT (top_level_changed (bool))); - // Forward signals to QTerminal widget. connect (this, SIGNAL (notice_settings_signal (const QSettings *)), @@ -68,37 +63,6 @@ } void -terminal_dock_widget::connect_visibility_changed (void) -{ - connect (this, SIGNAL (visibilityChanged (bool)), - this, SLOT (handle_visibility_changed (bool))); -} - -void -terminal_dock_widget::focus (void) -{ - if (! isVisible ()) - setVisible (true); - - setFocus (); - activateWindow (); - raise (); - - widget ()->setFocus (); - widget ()->activateWindow (); - widget ()->raise (); -} - -void -terminal_dock_widget::handle_visibility (bool visible) -{ - // if widget is changed to visible and is not floating - - if (visible && ! isFloating ()) - focus (); -} - -void terminal_dock_widget::notice_settings (const QSettings *settings) { emit notice_settings_signal (settings); @@ -121,3 +85,15 @@ { emit pasteClipboard_signal (); } + +void +terminal_dock_widget::focus (void) +{ + octave_dock_widget::focus (); + + QWidget *w = widget (); + + w->setFocus (); + w->activateWindow (); + w->raise (); +}
--- a/libgui/src/terminal-dock-widget.h +++ b/libgui/src/terminal-dock-widget.h @@ -37,16 +37,10 @@ terminal_dock_widget (QWidget *parent = 0); - void connect_visibility_changed (void); - signals: public slots: - void focus (void); - - void handle_visibility (bool visible); - void notice_settings (const QSettings *settings); void relay_command (const QString& command); @@ -55,6 +49,8 @@ void pasteClipboard (void); + void focus (void); + signals: void notice_settings_signal (const QSettings *settings);