Mercurial > hg > octave-nkf
changeset 15552:bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
* main-window.cc: save and recover the floating- and visible-state of each dock-widget in
write_settings() and read_settings(); change window-flag to window if widget is floating
at start-up
* documentation-dockwidget.cc/.h, files-dockwidget.cc/.h, history-dockwodget.cc/.h,
file-editor.cc/.h, terminal-dockwidget.cc/.h, workspace-view.cc/.h:
implement slot for signal topLevelChanged where window-flag is changed from widget
into window when widget is floating; change icon of all widgets to octave logo
author | Torsten <ttl@justmail.de> |
---|---|
date | Sat, 20 Oct 2012 17:43:35 +0200 |
parents | 48b1312bb0fe |
children | 3c5553180dd1 |
files | libgui/src/documentation-dockwidget.cc libgui/src/documentation-dockwidget.h libgui/src/files-dockwidget.cc libgui/src/files-dockwidget.h libgui/src/history-dockwidget.cc libgui/src/history-dockwidget.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc libgui/src/terminal-dockwidget.cc libgui/src/terminal-dockwidget.h libgui/src/workspace-view.cc libgui/src/workspace-view.h |
diffstat | 13 files changed, 118 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/documentation-dockwidget.cc +++ b/libgui/src/documentation-dockwidget.cc @@ -30,10 +30,13 @@ : QDockWidget (p) { setObjectName ("DocumentationDockWidget"); + 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))); _webinfo = new webinfo (this); setWidget (_webinfo); @@ -52,3 +55,14 @@ emit active_changed (false); QDockWidget::closeEvent (e); } + +// slot for signal that is emitted when floating property changes +void +documentation_dock_widget::top_level_changed (bool floating) +{ + if(floating) + { + setWindowFlags(Qt::Window); // make a window from the widget when floating + show(); // make it visible again since setWindowFlags hides it + } +}
--- a/libgui/src/documentation-dockwidget.h +++ b/libgui/src/documentation-dockwidget.h @@ -36,6 +36,8 @@ 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. */
--- a/libgui/src/files-dockwidget.cc +++ b/libgui/src/files-dockwidget.cc @@ -39,6 +39,7 @@ : QDockWidget (p) { setObjectName ("FilesDockWidget"); + setWindowIcon (QIcon(":/actions/icons/logo.png")); setWindowTitle (tr ("Current Directory")); setWidget (new QWidget (this)); @@ -115,6 +116,8 @@ 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))); setFocusProxy (_current_directory); } @@ -214,3 +217,14 @@ emit active_changed (false); QDockWidget::closeEvent (e); } + +// slot for signal that is emitted when floating property changes +void +files_dock_widget::top_level_changed (bool floating) +{ + if(floating) + { + setWindowFlags(Qt::Window); // make a window from the widget when floating + show(); // make it visible again since setWindowFlags hides it + } +}
--- a/libgui/src/files-dockwidget.h +++ b/libgui/src/files-dockwidget.h @@ -71,6 +71,9 @@ /** 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: /** Emitted, whenever the user requested to open a file. */ void open_file (const QString& fileName);
--- a/libgui/src/history-dockwidget.cc +++ b/libgui/src/history-dockwidget.cc @@ -61,6 +61,7 @@ _filter_line_edit->setStatusTip (tr ("Enter text to filter the command history.")); QVBoxLayout *vbox_layout = new QVBoxLayout (); + setWindowIcon (QIcon(":/actions/icons/logo.png")); setWindowTitle (tr ("Command History")); setWidget (new QWidget ()); @@ -85,6 +86,9 @@ 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))); + _update_history_model_timer.setInterval (200); _update_history_model_timer.setSingleShot (true); @@ -163,6 +167,17 @@ QDockWidget::closeEvent (e); } +// slot for signal that is emitted when floating property changes +void +history_dock_widget::top_level_changed (bool floating) +{ + if(floating) + { + setWindowFlags(Qt::Window); // make a window from the widget when floating + show(); // make it visible again since setWindowFlags hides it + } +} + void history_dock_widget::update_history_callback (void) {
--- a/libgui/src/history-dockwidget.h +++ b/libgui/src/history-dockwidget.h @@ -40,6 +40,8 @@ void handle_visibility_changed (bool visible); void request_history_model_update (); void reset_model (); + /** Slot when floating property changes */ + void top_level_changed (bool floating); signals: void information (const QString& message);
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -352,6 +352,17 @@ } } +// slot for signal that is emitted when floating property changes +void +file_editor::top_level_changed (bool floating) +{ + if(floating) + { + setWindowFlags(Qt::Window); // make a window from the widget when floating + show(); // make it visible again since setWindowFlag hides it + } +} + void file_editor::active_tab_changed (int) { @@ -582,11 +593,12 @@ SIGNAL (tabCloseRequested (int)), this, SLOT (handle_tab_close_request (int))); connect (_tab_widget, SIGNAL (currentChanged(int)), this, SLOT (active_tab_changed (int))); + // topLevelChanged is emitted when floating property changes (floating = true) + connect (this, SIGNAL (topLevelChanged(bool)), this, SLOT(top_level_changed(bool))); resize (500, 400); - setWindowIcon (QIcon::fromTheme ("accessories-text-editor", - editor_style->standardIcon (QStyle::SP_FileIcon))); - setWindowTitle ("Octave Editor"); + setWindowIcon (QIcon(":/actions/icons/logo.png")); + setWindowTitle ("Editor"); //restore previous session QSettings *settings = resource_manager::get_settings ();
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -93,6 +93,8 @@ void handle_tab_close_request (); void active_tab_changed (int index); void handle_editor_state_changed (); + /** Slot when floating property changes */ + void top_level_changed (bool floating); /** Tells the editor to react on changed settings. */ void notice_settings ();
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -397,15 +397,20 @@ restoreState (settings->value ("MainWindow/windowState").toByteArray ()); settings->beginGroup ("DockWidgets"); - // restoring the geometry of all widgets + // restoring the geometry of all dock-widgets foreach (QObject *obj, children ()) { QString name = obj->objectName (); - if (obj->isWidgetType () && ! name.isEmpty ()) + if (obj->inherits("QDockWidget") && ! name.isEmpty ()) { - QWidget *widget = qobject_cast<QWidget *> (obj); + QDockWidget *widget = qobject_cast<QDockWidget *> (obj); QVariant val = settings->value (name); widget->restoreGeometry (val.toByteArray ()); + bool floating = settings->value (name+"Floating",false).toBool (); + bool visible = settings->value (name+"Visible",true).toBool (); + if (floating) + widget->setWindowFlags (Qt::Window); // if floating, make window from widget + widget->setVisible (visible); // make widget visible if desired (setWindowFlags hides widget) } } settings->endGroup(); @@ -427,20 +432,25 @@ // FIXME -- what should happen if settings is 0? settings->setValue ("MainWindow/geometry", saveGeometry ()); - settings->setValue ("MainWindow/windowState", saveState ()); settings->beginGroup ("DockWidgets"); // saving the geometry of all widgets foreach (QObject *obj, children()) { QString name = obj->objectName (); - if (obj->isWidgetType () && ! name.isEmpty ()) + if (obj->inherits ("QDockWidget") && ! name.isEmpty ()) { - QWidget *widget = qobject_cast<QWidget *>(obj); + QDockWidget *widget = qobject_cast<QDockWidget *> (obj); settings->setValue (name, widget->saveGeometry ()); - } + bool floating = widget->isFloating (); + bool visible = widget->isVisible (); + settings->setValue (name+"Floating",floating); // store floating state + settings->setValue (name+"Visible",visible); // store visibility + if (floating) + widget->setWindowFlags(Qt::Widget); // if floating, recover the widget state such that the widget's + } // state is correctly saved by the saveSate () below } - settings->endGroup(); + settings->setValue ("MainWindow/windowState", saveState ()); // write the list of recent used directories QStringList curr_dirs; for (int i=0; i<_current_directory_combo_box->count (); i++)
--- a/libgui/src/terminal-dockwidget.cc +++ b/libgui/src/terminal-dockwidget.cc @@ -30,8 +30,22 @@ : QDockWidget (p) { setObjectName ("TerminalDockWidget"); + setWindowIcon (QIcon(":/actions/icons/logo.png")); setWindowTitle (tr ("Command Window")); setWidget (terminal); 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))); } + +// slot for signal that is emitted when floating property changes +void +terminal_dock_widget::top_level_changed (bool floating) +{ + if(floating) + { + setWindowFlags(Qt::Window); // make a window from the widget when floating + show(); // make it visible again since setWindowFlags hides it + } +}
--- a/libgui/src/terminal-dockwidget.h +++ b/libgui/src/terminal-dockwidget.h @@ -41,6 +41,8 @@ if (visible) emit active_changed (true); } + /** Slot when floating property changes */ + void top_level_changed (bool floating); }; #endif // TERMINALDOCKWIDGET_H
--- a/libgui/src/workspace-view.cc +++ b/libgui/src/workspace-view.cc @@ -35,6 +35,7 @@ : QDockWidget (p) { setObjectName ("WorkspaceView"); + setWindowIcon (QIcon(":/actions/icons/logo.png")); setWindowTitle (tr ("Workspace")); // Create a new workspace model. @@ -88,6 +89,9 @@ connect (_workspace_tree_view, SIGNAL (doubleClicked (QModelIndex)), this, SLOT (item_double_clicked (QModelIndex))); + // topLevelChanged is emitted when floating property changes (floating = true) + connect (this, SIGNAL (topLevelChanged(bool)), this, SLOT(top_level_changed(bool))); + } workspace_view::~workspace_view () @@ -215,3 +219,14 @@ emit active_changed (false); QDockWidget::closeEvent (e); } + +// slot for signal that is emitted when floating property changes +void +workspace_view::top_level_changed (bool floating) +{ + if(floating) + { + setWindowFlags(Qt::Window); // make a window from the widget when floating + show(); // make it visible again since setWindowFlags hides it + } +}
--- a/libgui/src/workspace-view.h +++ b/libgui/src/workspace-view.h @@ -39,6 +39,8 @@ public slots: void handle_visibility_changed (bool visible); void model_changed (); + /** Slot when floating property changes */ + void top_level_changed (bool floating); signals: /** Custom signal that tells if a user has clicke away that dock widget. */