Mercurial > hg > octave-jordi
changeset 16593:e13051d7a472
allow GUI window layout to be restored
* main-window.h, main-window.cc (main_window::set_window_layout):
New function.
(main_window::read_settings): Call set_window_layout for current
settings.
(main_window::reset_windows): Call set_window_layout for default
settings.
(main_window::construct_window_menu): Enable reset_windows_action.
* resource-manager.h, resource-manager.cc (default_qt_settings_file):
Return QString instead of std::string. Change all callers.
(resource_manager::default_settings): New member variable.
(resource_manager::resource_manager): Initialize default_settings.
(resource_manager::~resource_manager): Delete default_settings.
(resource_manager::get_default_settings,
resource_manager::do_get_default_settings): New functions.
(resource_manager::do_is_first_run, resource_manager::do_get_settings,
resource_manager::do_get_home_path): Now const.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 29 Apr 2013 17:40:41 -0400 |
parents | d70f61485e5f |
children | 3ce0c312a40b |
files | libgui/src/main-window.cc libgui/src/main-window.h libgui/src/resource-manager.cc libgui/src/resource-manager.h |
diffstat | 4 files changed, 80 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -326,9 +326,11 @@ } void -main_window::reset_windows () +main_window::reset_windows (void) { - // TODO: Implement. + QSettings *settings = resource_manager::get_default_settings (); + + set_window_layout (settings); } void @@ -520,32 +522,15 @@ main_window::read_settings (void) { QSettings *settings = resource_manager::get_settings (); + if (!settings) { qDebug("Error: QSettings pointer from resource manager is NULL."); return; } - restoreState (settings->value ("MainWindow/windowState").toByteArray ()); - settings->beginGroup ("DockWidgets"); - // restoring the geometry of all dock-widgets - foreach (QObject *obj, children ()) - { - QString name = obj->objectName (); - if (obj->inherits ("QDockWidget") && ! name.isEmpty ()) - { - 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(); - restoreGeometry (settings->value ("MainWindow/geometry").toByteArray ()); + set_window_layout (settings); + // restore the list of the last directories QStringList curr_dirs = settings->value ("MainWindow/current_directory_list").toStringList (); for (int i=0; i < curr_dirs.size (); i++) @@ -556,6 +541,41 @@ } void +main_window::set_window_layout (QSettings *settings) +{ + restoreState (settings->value ("MainWindow/windowState").toByteArray ()); + + settings->beginGroup ("DockWidgets"); + + // Restore the geometry of all dock-widgets + foreach (QObject *obj, children ()) + { + QString name = obj->objectName (); + + if (obj->inherits ("QDockWidget") && ! name.isEmpty ()) + { + QDockWidget *widget = qobject_cast<QDockWidget *> (obj); + QVariant val = settings->value (name); + + widget->restoreGeometry (val.toByteArray ()); + + // If floating, make window from widget. + bool floating = settings->value (name+"Floating", false).toBool (); + if (floating) + widget->setWindowFlags (Qt::Window); + + // make widget visible if desired (setWindowFlags hides widget). + bool visible = settings->value (name+"Visible", true).toBool (); + widget->setVisible (visible); + } + } + + settings->endGroup (); + + restoreGeometry (settings->value ("MainWindow/geometry").toByteArray ()); +} + +void main_window::write_settings (void) { QSettings *settings = resource_manager::get_settings (); @@ -1194,9 +1214,7 @@ window_menu->addSeparator (); QAction *reset_windows_action - = window_menu->addAction (tr ("Reset Windows")); - - reset_windows_action->setEnabled (false); // TODO: Make this work. + = window_menu->addAction (tr ("Reset Default Window Layout")); connect (show_command_window_action, SIGNAL (toggled (bool)), command_window, SLOT (setVisible (bool)));
--- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -135,6 +135,7 @@ const QString& file, int line); void read_settings (void); + void set_window_layout (QSettings *settings); void write_settings (void); void connect_visibility_changed (void);
--- a/libgui/src/resource-manager.cc +++ b/libgui/src/resource-manager.cc @@ -42,15 +42,30 @@ resource_manager *resource_manager::instance = 0; +static QString +default_qt_settings_file (void) +{ + std::string dsf = octave_env::getenv ("OCTAVE_DEFAULT_QT_SETTINGS"); + + if (dsf.empty ()) + dsf = Voct_etc_dir + file_ops::dir_sep_str () + "default-qt-settings"; + + return QString::fromStdString (dsf); +} + resource_manager::resource_manager (void) : settings (0), home_path (), first_run (false) { do_reload_settings (); + + default_settings = new QSettings (default_qt_settings_file (), + QSettings::IniFormat); } resource_manager::~resource_manager (void) { delete settings; + delete default_settings; } @@ -104,26 +119,21 @@ } QSettings * -resource_manager::do_get_settings (void) +resource_manager::do_get_settings (void) const { return settings; } -QString -resource_manager::do_get_home_path (void) +QSettings * +resource_manager::do_get_default_settings (void) const { - return home_path; + return default_settings; } -static std::string -default_qt_settings_file (void) +QString +resource_manager::do_get_home_path (void) const { - std::string dsf = octave_env::getenv ("OCTAVE_DEFAULT_QT_SETTINGS"); - - if (dsf.empty ()) - dsf = Voct_etc_dir + file_ops::dir_sep_str () + "default-qt-settings"; - - return dsf; + return home_path; } void @@ -137,8 +147,7 @@ if (!QFile::exists (settings_file)) { QDir("/").mkpath (settings_path); - QFile::copy (QString::fromStdString (default_qt_settings_file ()), - settings_file); + QFile::copy (default_qt_settings_file (), settings_file); first_run = true; } else @@ -155,7 +164,7 @@ } bool -resource_manager::do_is_first_run (void) +resource_manager::do_is_first_run (void) const { return first_run; }
--- a/libgui/src/resource-manager.h +++ b/libgui/src/resource-manager.h @@ -44,6 +44,11 @@ return instance_ok () ? instance->do_get_settings () : 0; } + static QSettings *get_default_settings (void) + { + return instance_ok () ? instance->do_get_default_settings () : 0; + } + static QString get_home_path (void) { return instance_ok () ? instance->do_get_home_path () : QString (); @@ -94,13 +99,17 @@ QSettings *settings; + QSettings *default_settings; + QString home_path; bool first_run; - QSettings *do_get_settings (void); + QSettings *do_get_settings (void) const; - QString do_get_home_path (void); + QSettings *do_get_default_settings (void) const; + + QString do_get_home_path (void) const; void do_reload_settings (void); @@ -108,7 +117,7 @@ void do_update_network_settings (void); - bool do_is_first_run (void); + bool do_is_first_run (void) const; };