Mercurial > octave
diff libgui/src/octave-dock-widget.h @ 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 | 045ce3896e3f |
children | 999400bebe5e |
line wrap: on
line diff
--- a/libgui/src/octave-dock-widget.h Sun Apr 07 12:07:10 2013 -0400 +++ b/libgui/src/octave-dock-widget.h Sun Apr 07 12:36:07 2013 -0400 @@ -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