Mercurial > hg > octave-nkf
changeset 16798:d749c9b588e5
make stand-alone windows from dock widgets when floating (bug #38785)
* octave-dock-widget.cc: new file,
(constructor): moved from octave-dock-widget.h, disable floating and closing
by qt, add custom title bar with buttons for closing and floating,
(destructor): saving state and geometry depending on state,
(set_title): new function for setting the title of the custom title bar,
(make_window): make dock widget a stand-alone window by reparenting to 0
and restore last geometry,
(make_widget): readd the widget to the main window, the last position and size
can not be restored due to previous reparenting
(change_floating): slot for dock button in title bar
(change_visibility): slot for hiding the widget
* octave-dock-widget.h: removed signal connection and slot for floating by qt,
moved constructor to *.cc, declaration of new functions and slots
(main_win): new function returning the main window
* main-window.cc(notice-settings): when updating icons, use a list of all dock
widgets instead of searching childrens that may have set their parent to 0
(set_window_layout): use make_window instead of setWindowsFlag for floating,
do not use grouping in settings because of possibly nested groups
(write_settings): saving the state and geometry of the dock-widgets is
moved into the dock widget's destructors
main-window.n(dock_widget_list): function returning a list of all dock widgets
* documentation-dock-widget.cc, files-dock-widget.cc, history-dock-widget.cc,
file-editor.cc, terminal-dock-widget.cc, workspace-view.cc:
use new function set_title instead of setWindowTitle
* files-dock-widget.cc, file-editor.cc, : replace parent () by main_win ()
* widget-dock.png, widget-undock.png, widget-close.png: new icons
* resource.qrc: new icons widget-dock.png, widget-undock.png, widget-close.png
* module-mk: new icons widget-dock.png, widget-undock.png, widget-close.png
and new file octave-dock-widget.cc
author | Torsten <ttl@justmail.de> |
---|---|
date | Fri, 21 Jun 2013 22:40:53 +0200 |
parents | aac60c9bfc77 |
children | 286904321282 |
files | libgui/src/documentation-dock-widget.cc libgui/src/files-dock-widget.cc libgui/src/history-dock-widget.cc libgui/src/icons/widget-close.png libgui/src/icons/widget-dock.png libgui/src/icons/widget-undock.png libgui/src/m-editor/file-editor.cc libgui/src/main-window.cc libgui/src/main-window.h libgui/src/module.mk libgui/src/octave-dock-widget.cc libgui/src/octave-dock-widget.h libgui/src/resource.qrc libgui/src/terminal-dock-widget.cc libgui/src/workspace-view.cc |
diffstat | 15 files changed, 251 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/documentation-dock-widget.cc +++ b/libgui/src/documentation-dock-widget.cc @@ -31,7 +31,7 @@ { setObjectName ("DocumentationDockWidget"); setWindowIcon (QIcon (":/actions/icons/logo.png")); - setWindowTitle (tr ("Documentation")); + set_title (tr ("Documentation")); setStatusTip (tr ("See the documentation for help.")); _webinfo = new webinfo (this);
--- a/libgui/src/files-dock-widget.cc +++ b/libgui/src/files-dock-widget.cc @@ -64,7 +64,7 @@ { setObjectName ("FilesDockWidget"); setWindowIcon (QIcon(":/actions/icons/logo.png")); - setWindowTitle (tr ("File Browser")); + set_title (tr ("File Browser")); setToolTip (tr ("Browse your files.")); QWidget *container = new QWidget (this); @@ -72,10 +72,10 @@ setWidget (container); connect (this, SIGNAL (open_file (const QString&)), - parent (), SLOT (open_file (const QString&))); + main_win (), SLOT (open_file (const QString&))); connect (this, SIGNAL (displayed_directory_changed (const QString&)), - parent (), SLOT (set_current_working_directory (const QString&))); + main_win (), SLOT (set_current_working_directory (const QString&))); // Create a toolbar _navigation_tool_bar = new QToolBar ("", container); @@ -201,7 +201,7 @@ this, SLOT (set_current_directory (const QString &))); connect (this, SIGNAL (run_file_signal (const QFileInfo&)), - parent (), SLOT (run_file_in_terminal (const QFileInfo&))); + main_win (), SLOT (run_file_in_terminal (const QFileInfo&))); QCompleter *completer = new QCompleter (_file_system_model, this); _current_directory->setCompleter (completer);
--- a/libgui/src/history-dock-widget.cc +++ b/libgui/src/history-dock-widget.cc @@ -72,7 +72,7 @@ QVBoxLayout *vbox_layout = new QVBoxLayout (); setWindowIcon (QIcon(":/actions/icons/logo.png")); - setWindowTitle (tr ("Command History")); + set_title (tr ("Command History")); setWidget (new QWidget ()); vbox_layout->addWidget (_history_list_view);
new file mode 100755 index 0000000000000000000000000000000000000000..2bc8d43e6508c29b4b28ea144834ee2dc231583a GIT binary patch literal 220 zc%17D@N?(olHy`uVBq!ia0vp^AT}ol8<6B)wpSQPF%}28J29*~C-V}>VN3FMcVYMs zf(!O8pA1r4;1O92R4fd_j105pNB{-dOFVsD+3&K63UlddFOKU13dMN3IEF}EPMvU& z_kaNhvu{|_U-b`u@7SZ-KXo3Ro78#2=gfo_|IocZO+*+hU+6F>bxtsGc<ZwN)ij2N z<gI!cZ|w@1&)Z*owZ5j4+2h!sXP<6fS|=w~e7yE>?P+#nOAF>oaZ!+S89ZJ6T-G@y GGywq3ibt~m
new file mode 100644 index 0000000000000000000000000000000000000000..64d296b71140fb05da3077395c01be5ce287c3bb GIT binary patch literal 199 zc%17D@N?(olHy`uVBq!ia0vp^AT}ol8<6B)wpSQPF%}28J29*~C-V}>VN3FMcVYMs zf(!O8pA1r4;1O92R4fd_j105pNB{-dOFVsD+3&K63bSeFm2TM#6ms`;aSV~ToNQud z_V2s{OG1)@&<2N0H<gY5Giun_*xLRV2%n#0dHBGA0}7p|UEE~yj$|q+3#B=1ZrzaX k<KuJUyXh`#!#lhT=8Jg`uReHa2hd0cPgg&ebxsLQ0Cs3Q`v3p{
new file mode 100755 index 0000000000000000000000000000000000000000..c594db71e2222fbd22f80832bf0797b34b4432b4 GIT binary patch literal 210 zc%17D@N?(olHy`uVBq!ia0vp^AT}ol8<6B)wpSQPF%}28J29*~C-V}>VN3FMcVYMs zf(!O8pA1r4;1O92R4fd_j105pNB{-dOFVsD+3&K63bP9wOU=0k6bkZmaSV~T+}nSU z_kaNpQ~!$f>n6XkXSCiqe@m~<QLgyp2Un{3zX>(uO11C0c7934Wd@Vgsk04_l^siu x310Q;1Vg3U=Czd}teb=GPYo2T&u0D1aK%Mp&87Ocu|U%qJYD@<);T3K0RUgJMGgP}
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -956,10 +956,10 @@ editor_widget->setLayout (vbox_layout); setWidget (editor_widget); - connect (parent (), SIGNAL (new_file_signal (const QString&)), + connect (main_win (), SIGNAL (new_file_signal (const QString&)), this, SLOT (request_new_file (const QString&))); - connect (parent (), SIGNAL (open_file_signal (const QString&)), + connect (main_win (), SIGNAL (open_file_signal (const QString&)), this, SLOT (request_open_file (const QString&))); connect (new_action, SIGNAL (triggered ()), @@ -1044,7 +1044,7 @@ resize (500, 400); setWindowIcon (QIcon (":/actions/icons/logo.png")); - setWindowTitle ("Editor"); + set_title ("Editor"); //restore previous session if (settings->value ("editor/restoreSession", true).toBool ()) @@ -1083,10 +1083,10 @@ this, SLOT (handle_mru_add_file (const QString&))); connect (f, SIGNAL (run_file_signal (const QFileInfo&)), - parent (), SLOT (run_file_in_terminal (const QFileInfo&))); + main_win (), SLOT (run_file_in_terminal (const QFileInfo&))); connect (f, SIGNAL (execute_command_in_terminal_signal (const QString&)), - parent (), SLOT (execute_command_in_terminal (const QString&))); + main_win (), SLOT (execute_command_in_terminal (const QString&))); // Signals from the file_editor non-trivial operations connect (this, SIGNAL (fetab_settings_changed (const QSettings *)),
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -293,12 +293,11 @@ } QString icon; - foreach (QObject *obj, children ()) + foreach (octave_dock_widget *widget, dock_widget_list ()) { - QString name = obj->objectName (); - if (obj->inherits ("QDockWidget") && ! name.isEmpty ()) - { // if children is a dock widget with a name - QDockWidget *widget = qobject_cast<QDockWidget *> (obj); + QString name = widget->objectName (); + if (! name.isEmpty ()) + { // if children has a name icon = widget_icon_data[icon_set_found].path; // prefix or octave-logo if (widget_icon_data[icon_set_found].name != "NONE") icon = icon + name + ".png"; // add widget name and ext. @@ -545,8 +544,6 @@ { restoreState (settings->value ("MainWindow/windowState").toByteArray ()); - settings->beginGroup ("DockWidgets"); - // Restore the geometry of all dock-widgets foreach (QObject *obj, children ()) { @@ -554,24 +551,24 @@ if (obj->inherits ("QDockWidget") && ! name.isEmpty ()) { - QDockWidget *widget = qobject_cast<QDockWidget *> (obj); + octave_dock_widget *widget = qobject_cast<octave_dock_widget *> (obj); QVariant val = settings->value (name); widget->restoreGeometry (val.toByteArray ()); // If floating, make window from widget. - bool floating = settings->value (name+"Floating", false).toBool (); + bool floating = settings->value + ("DockWidgets/" + name + "Floating", false).toBool (); + bool visible = settings->value + ("DockWidgets/" + name + "Visible", true).toBool (); if (floating) - widget->setWindowFlags (Qt::Window); + widget->make_window (visible); - // make widget visible if desired (setWindowFlags hides widget). - bool visible = settings->value (name+"Visible", true).toBool (); + // make widget visible if desired widget->setVisible (visible); } } - settings->endGroup (); - restoreGeometry (settings->value ("MainWindow/geometry").toByteArray ()); } @@ -586,24 +583,6 @@ } settings->setValue ("MainWindow/geometry", saveGeometry ()); - settings->beginGroup ("DockWidgets"); - // saving the geometry of all widgets - foreach (QObject *obj, children()) - { - QString name = obj->objectName (); - if (obj->inherits ("QDockWidget") && ! name.isEmpty ()) - { - 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;
--- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -53,6 +53,7 @@ #include "terminal-dock-widget.h" #include "documentation-dock-widget.h" #include "octave-qt-link.h" +#include "octave-dock-widget.h" #include "find-files-dialog.h" /** @@ -249,6 +250,17 @@ documentation_dock_widget *doc_browser_window; file_editor_interface *editor_window; workspace_view *workspace_window; + QList<octave_dock_widget *> dock_widget_list () + { + QList<octave_dock_widget *> list = QList<octave_dock_widget *> (); + list.append (static_cast<octave_dock_widget *> (command_window)); + list.append (static_cast<octave_dock_widget *> (history_window)); + list.append (static_cast<octave_dock_widget *> (file_browser_window)); + list.append (static_cast<octave_dock_widget *> (doc_browser_window)); + list.append (static_cast<octave_dock_widget *> (editor_window)); + list.append (static_cast<octave_dock_widget *> (workspace_window)); + return list; + } QToolBar *_main_tool_bar; QMenu *_debug_menu;
--- a/libgui/src/module.mk +++ b/libgui/src/module.mk @@ -60,6 +60,9 @@ src/icons/terminal.png \ src/icons/undo.png \ src/icons/up.png \ + src/icons/widget-close.png \ + src/icons/widget-dock.png \ + src/icons/widget-undock.png \ src/icons/zoom-in.png \ src/icons/zoom-out.png @@ -139,6 +142,7 @@ src/m-editor/find-dialog.cc \ src/m-editor/octave-qscintilla.cc \ src/main-window.cc \ + src/octave-dock-widget.cc \ src/octave-gui.cc \ src/octave-main-thread.cc \ src/octave-qt-link.cc \
new file mode 100644 --- /dev/null +++ b/libgui/src/octave-dock-widget.cc @@ -0,0 +1,187 @@ +/* + +Copyright (C) 2012-2013 Richard Crozier +Copyright (C) 2013 Torsten <ttl@justmail.de> + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + + +#include <QToolBar> +#include <QToolButton> +#include <QAction> +#include <QHBoxLayout> +#include <QLabel> +#include <QSettings> + +#include "resource-manager.h" +#include "octave-dock-widget.h" + + +octave_dock_widget::octave_dock_widget (QWidget *p) + : QDockWidget (p) +{ + + _parent = static_cast<QMainWindow *> (p); // store main window + setFeatures (QDockWidget::DockWidgetMovable); // not floatable or cloasable + + connect (this, SIGNAL (visibilityChanged (bool)), + this, SLOT (handle_visibility_changed (bool))); + + connect (p, SIGNAL (settings_changed (const QSettings*)), + this, SLOT (notice_settings (const QSettings*))); + + // the custom (extra) title bar of the widget + _dock_action = new QAction + (QIcon (":/actions/icons/widget-undock.png"), "", this); + _dock_action-> setToolTip (tr ("Undock widget")); + connect (_dock_action, SIGNAL (triggered (bool)), + this, SLOT (change_floating (bool))); + QToolButton *dock_button = new QToolButton (this); + dock_button->setDefaultAction (_dock_action); + dock_button->setFocusPolicy(Qt::NoFocus); + + QAction *close_action = new QAction + (QIcon (":/actions/icons/widget-close.png"), "", this ); + close_action-> setToolTip (tr ("Hide widget")); + connect (close_action, SIGNAL (triggered (bool)), + this, SLOT (change_visibility (bool))); + QToolButton *close_button = new QToolButton (this); + close_button->setDefaultAction (close_action); + close_button->setFocusPolicy(Qt::NoFocus); + + QHBoxLayout *h_layout = new QHBoxLayout (); + h_layout->addStretch (100); + h_layout->addWidget (dock_button); + h_layout->addWidget (close_button); + h_layout->setSpacing (0); + h_layout->setContentsMargins (6,0,0,0); + + QWidget *title_widget = new QWidget (); + title_widget->setLayout (h_layout); + setTitleBarWidget (title_widget); + +} + +octave_dock_widget::~octave_dock_widget () +{ + // save state of this dock-widget + bool floating = false; + bool visible; + QString name = objectName (); + QSettings *settings = resource_manager::get_settings (); + + settings->beginGroup ("DockWidgets"); + + if (!parent ()) + { // widget is floating, save actual floating geometry + floating = true; + settings->setValue (name+"_floating_geometry", saveGeometry ()); + } + else // not floating save docked (normal) geometry + settings->setValue (name, saveGeometry ()); + + visible = isVisible (); + settings->setValue (name+"Floating", floating); // store floating state + settings->setValue (name+"Visible", visible); // store visibility + + settings->endGroup (); +} + +// set the title in the dockwidgets title bar +void +octave_dock_widget::set_title (const QString& title) +{ + QHBoxLayout* h_layout = + static_cast<QHBoxLayout *> (titleBarWidget ()->layout ()); + QLabel *label = new QLabel (title); + h_layout->insertWidget (0,label); + setWindowTitle (title); +} + +// make the widget floating +void +octave_dock_widget::make_window (bool visible) +{ + QSettings *settings = resource_manager::get_settings (); + + // save the docking area for later redocking + // FIXME: dockWidgetArea always returns 2 + settings->setValue ("DockWidgets/" + objectName () + "_dock_area", + _parent->dockWidgetArea (this)); + + // remove parent and adjust the (un)dock icon + setParent (0, Qt::Window); + _dock_action->setIcon (QIcon (":/actions/icons/widget-dock.png")); + _dock_action->setToolTip (tr ("Dock widget")); + + // restore the last geometry when floating + restoreGeometry (settings->value + ("DockWidgets/" + objectName ()+"_floating_geometry").toByteArray ()); + + if (visible) + show (); // make visible if desired +} + +// dock the widget +void +octave_dock_widget::make_widget (bool visible) +{ + QSettings *settings = resource_manager::get_settings (); + + // save last floating geometry + settings->setValue ("DockWidgets/" + objectName () + "_floating_geometry", + saveGeometry ()); + + // add widget to last saved docking area + int area = settings->value ("DockWidgets/" + objectName () + "_dock_area", + Qt::TopDockWidgetArea).toInt (); + _parent->addDockWidget (static_cast<Qt::DockWidgetArea> (area), this); + + // FIXME: restoreGeometry is ignored for docked widgets and its child widget + // restoreGeometry (settings->value + // ("DockWidgets/" + objectName ()).toByteArray ()); + + // adjust the (un)dock icon + _dock_action->setIcon (QIcon (":/actions/icons/widget-undock.png")); + _dock_action->setToolTip (tr ("Unock widget")); + + setVisible (visible); +} + +// slot for (un)dock action +void +octave_dock_widget::change_floating (bool) +{ + if (parent()) + { + make_window (true); + focus (); + } + else + make_widget (true); +} + +// slot for hiding the widget +void +octave_dock_widget::change_visibility (bool) +{ + setVisible (false); + emit active_changed (false); +} +
--- a/libgui/src/octave-dock-widget.h +++ b/libgui/src/octave-dock-widget.h @@ -25,6 +25,9 @@ #include <QDockWidget> #include <QSettings> +#include <QIcon> +#include <QMainWindow> +#include <QMouseEvent> class octave_dock_widget : public QDockWidget { @@ -32,20 +35,8 @@ 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 (p, SIGNAL (settings_changed (const QSettings*)), - this, SLOT (notice_settings (const QSettings*))); - } - - virtual ~octave_dock_widget () { } + octave_dock_widget (QWidget *p = 0); + virtual ~octave_dock_widget (); virtual void connect_visibility_changed (void) { @@ -53,6 +44,9 @@ this, SLOT (handle_visibility (bool))); } + void make_window (bool visible); + void make_widget (bool visible); + void set_title (const QString&); signals: @@ -69,6 +63,7 @@ QDockWidget::closeEvent (e); } + public slots: virtual void focus (void) @@ -91,6 +86,8 @@ { } + QMainWindow *main_win () { return _parent; } + protected slots: /** Slot to steer changing visibility from outside. */ @@ -100,17 +97,16 @@ emit active_changed (true); } - /** Slot when floating property changes */ - virtual void top_level_changed (bool floating) - { - if (floating) - { - // Make a window from the widget when floating and make it - // visible again since setWindowFlags hides it. - setWindowFlags (Qt::Window); - show(); - } - } +private slots: + + void change_floating (bool); + void change_visibility (bool); + +private: + + QMainWindow *_parent; // store the parent since we are reparenting to 0 + QAction *_dock_action; + }; #endif
--- a/libgui/src/resource.qrc +++ b/libgui/src/resource.qrc @@ -56,5 +56,8 @@ <file>icons/graphic_logo_HistoryDockWidget.png</file> <file>icons/graphic_logo_WorkspaceView.png</file> <file>icons/graphic_logo_DocumentationDockWidget.png</file> + <file>icons/widget-close.png</file> + <file>icons/widget-dock.png</file> + <file>icons/widget-undock.png</file> </qresource> </RCC>
--- a/libgui/src/terminal-dock-widget.cc +++ b/libgui/src/terminal-dock-widget.cc @@ -35,7 +35,7 @@ setObjectName ("TerminalDockWidget"); setWindowIcon (QIcon(":/actions/icons/logo.png")); - setWindowTitle (tr ("Command Window")); + set_title (tr ("Command Window")); setWidget (terminal); }
--- a/libgui/src/workspace-view.cc +++ b/libgui/src/workspace-view.cc @@ -44,7 +44,7 @@ { setObjectName ("WorkspaceView"); setWindowIcon (QIcon (":/actions/icons/logo.png")); - setWindowTitle (tr ("Workspace")); + set_title (tr ("Workspace")); setStatusTip (tr ("View the variables in the active workspace.")); view->setWordWrap (false);