# HG changeset patch # User Torsten Lilge # Date 1573419378 -3600 # Node ID a1271c5b621aec27df733bcf2c166322a3eceeb3 # Parent bd7decacf32eab83f8c34f6b0faa7f0eb80d55d1 replace preference literals by symbolic constants for dock widgets * gui-preferences-all.h: added new include file for dock widgets * gui-preferences-dw.h: new include file with symbolic constants for dock widgets * main-window.cc: include new pref include file; (notice_settings): replace literals for preferences by symbolic constants; (set_window_layout): dito * module.mk: new include file * octave-dock-widget.cc: include new include file; (handle_settings): replace literals for preferences by symbolic constants (save_settings): dito * settings-dialog.cc (settings_dialog): replace literals for preferences by symbolic constants; (write_changed_settings): dito diff -r bd7decacf32e -r a1271c5b621a libgui/src/gui-preferences-all.h --- a/libgui/src/gui-preferences-all.h Sun Nov 10 14:05:23 2019 +0100 +++ b/libgui/src/gui-preferences-all.h Sun Nov 10 21:56:18 2019 +0100 @@ -24,6 +24,7 @@ #define octave_gui_preferences_all_h 1 #include "gui-preferences-cs.h" +#include "gui-preferences-dw.h" #include "gui-preferences-ed.h" #include "gui-preferences-fb.h" #include "gui-preferences-global.h" diff -r bd7decacf32e -r a1271c5b621a libgui/src/gui-preferences-dw.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-dw.h Sun Nov 10 21:56:18 2019 +0100 @@ -0,0 +1,69 @@ +/* + +Copyright (C) 2017-2019 Torsten Lilge + +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 +. + +*/ + +#if ! defined (octave_gui_preferences_dw_h) +#define octave_gui_preferences_dw_h 1 + +#include "gui-preferences.h" + +const gui_pref +dw_title_custom_style ("DockWidgets/widget_title_custom_style", QVariant (false)); + +const gui_pref dw_title_3d ("DockWidgets/widget_title_3d", QVariant (50)); + +const gui_pref +dw_title_fg_color ("DockWidgets/title_fg_color", QVariant (QColor (0,0,0))); + +const gui_pref dw_title_fg_color_active ("DockWidgets/title_fg_color_active", + QVariant (QColor (0,0,0))); + +const gui_pref dw_title_bg_color ("DockWidgets/title_bg_color", + QVariant (QColor (255,255,255))); + +const gui_pref dw_title_bg_color_active ("DockWidgets/title_bg_color_active", + QVariant (QColor (192,192,192))); + +const gui_pref dw_icon_set ("DockWidgets/widget_icon_set", QVariant ("NONE")); + +const struct { QString name; QString path; } dw_icon_set_names[] + = { + // array of possible icon sets (name, path (complete for NONE)) + // the first entry here is the default! + {"NONE", ":/actions/icons/logo.png"}, + {"GRAPHIC", ":/actions/icons/graphic_logo_"}, + {"LETTER", ":/actions/icons/letter_logo_"}, + {"", ""} // end marker has empty name + }; + +// The following keys have to be used with .arg (objectName ()) +const gui_pref dw_float_geometry ("DockWidgets/%1_floating_geometry", + QVariant (QRect (50, 50, 480, 640))); + +const gui_pref dw_dock_geometry ("DockWidgets/%1", QVariant (QByteArray ())); + +const gui_pref dw_is_visible ("DockWidgets/%1Visible", QVariant (true)); + +const gui_pref dw_is_floating ("DockWidgets/%1Floating", QVariant (false)); + +const gui_pref dw_is_minimized ("DockWidgets/%1_minimized", QVariant (false)); + +#endif \ No newline at end of file diff -r bd7decacf32e -r a1271c5b621a libgui/src/main-window.cc --- a/libgui/src/main-window.cc Sun Nov 10 14:05:23 2019 +0100 +++ b/libgui/src/main-window.cc Sun Nov 10 21:56:18 2019 +0100 @@ -57,6 +57,7 @@ #endif #include "gui-preferences.h" #include "gui-preferences-cs.h" +#include "gui-preferences-dw.h" #include "gui-preferences-ed.h" #include "gui-preferences-mw.h" #include "gui-preferences-nr.h" @@ -839,31 +840,15 @@ // the widget's icons (when floating) QString icon_set - = settings->value ("DockWidgets/widget_icon_set", "NONE").toString (); - - static struct - { - QString name; - QString path; - } - - widget_icon_data[] = - { - // array of possible icon sets (name, path (complete for NONE)) - // the first entry here is the default! - {"NONE", ":/actions/icons/logo.png"}, - {"GRAPHIC", ":/actions/icons/graphic_logo_"}, - {"LETTER", ":/actions/icons/letter_logo_"}, - {"", ""} // end marker has empty name - }; + = settings->value (dw_icon_set.key, dw_icon_set.def).toString (); int count = 0; int icon_set_found = 0; // default - while (! widget_icon_data[count].name.isEmpty ()) + while (! dw_icon_set_names[count].name.isEmpty ()) { // while not end of data - if (widget_icon_data[count].name == icon_set) + if (dw_icon_set_names[count].name == icon_set) { // data of desired icon set found icon_set_found = count; @@ -879,14 +864,14 @@ if (! name.isEmpty ()) { // if children has a name - icon = widget_icon_data[icon_set_found].path; // prefix | octave-logo - if (widget_icon_data[icon_set_found].name != "NONE") + icon = dw_icon_set_names[icon_set_found].path; // prefix | octave-logo + if (dw_icon_set_names[icon_set_found].name != "NONE") icon += name + ".png"; // add widget name and ext. widget->setWindowIcon (QIcon (icon)); } } - if (widget_icon_data[icon_set_found].name != "NONE") - m_release_notes_icon = widget_icon_data[icon_set_found].path + if (dw_icon_set_names[icon_set_found].name != "NONE") + m_release_notes_icon = dw_icon_set_names[icon_set_found].path + "ReleaseWidget.png"; else m_release_notes_icon = ":/actions/icons/logo.png"; @@ -1498,9 +1483,9 @@ if (settings) { floating = settings->value - ("DockWidgets/" + name + "Floating", false).toBool (); + (dw_is_floating.key.arg (name), dw_is_floating.def).toBool (); visible = settings->value - ("DockWidgets/" + name + "Visible", true).toBool (); + (dw_is_visible.key.arg (name), dw_is_visible.def).toBool (); } // If floating, make window from widget. @@ -1510,8 +1495,9 @@ if (visible) { - if (settings && settings->value ("DockWidgets/" + name - + "_minimized").toBool ()) + if (settings + && settings->value (dw_is_minimized.key.arg (name), + dw_is_minimized.def).toBool ()) widget->showMinimized (); else widget->setVisible (true); diff -r bd7decacf32e -r a1271c5b621a libgui/src/module.mk --- a/libgui/src/module.mk Sun Nov 10 14:05:23 2019 +0100 +++ b/libgui/src/module.mk Sun Nov 10 21:56:18 2019 +0100 @@ -189,6 +189,7 @@ %reldir%/dw-main-window.h \ %reldir%/gui-preferences-all.h \ %reldir%/gui-preferences-cs.h \ + %reldir%/gui-preferences-dw.h \ %reldir%/gui-preferences-ed.h \ %reldir%/gui-preferences-fb.h \ %reldir%/gui-preferences-global.h \ diff -r bd7decacf32e -r a1271c5b621a libgui/src/octave-dock-widget.cc --- a/libgui/src/octave-dock-widget.cc Sun Nov 10 14:05:23 2019 +0100 +++ b/libgui/src/octave-dock-widget.cc Sun Nov 10 21:56:18 2019 +0100 @@ -34,7 +34,8 @@ #include #include -#include "gui-preferences-global.h" +#include "gui-preferences.h" +#include "gui-preferences-dw.h" #include "gui-preferences-mw.h" #include "gui-settings.h" #include "octave-dock-widget.h" @@ -423,24 +424,25 @@ octave_dock_widget::handle_settings (const gui_settings *settings) { m_custom_style - = settings->value ("DockWidgets/widget_title_custom_style",false).toBool (); + = settings->value (dw_title_custom_style.key, + dw_title_custom_style.def).toBool (); - m_title_3d - = settings->value ("DockWidgets/widget_title_3d",50).toInt (); + m_title_3d = settings->value (dw_title_3d.key, dw_title_3d.def).toInt (); + + m_fg_color + = settings->value (dw_title_fg_color.key, + dw_title_fg_color.def).value (); - QColor default_var = QColor (0,0,0); - m_fg_color = settings->value ("DockWidgets/title_fg_color", - default_var).value (); - default_var = QColor (0,0,0); - m_fg_color_active = settings->value ("DockWidgets/title_fg_color_active", - default_var).value (); + m_fg_color_active + = settings->value (dw_title_fg_color_active.key, + dw_title_fg_color_active.def).value (); - default_var = QColor (255,255,255); - m_bg_color = settings->value ("DockWidgets/title_bg_color", - default_var).value (); - default_var = QColor (192,192,192); - m_bg_color_active = settings->value ("DockWidgets/title_bg_color_active", - default_var).value (); + m_bg_color = settings->value (dw_title_bg_color.key, + dw_title_bg_color.def).value (); + + m_bg_color_active + = settings->value (dw_title_bg_color_active.key, + dw_title_bg_color_active.def).value (); QColor bcol (m_bg_color); QColor bcola (m_bg_color_active); @@ -469,9 +471,9 @@ available_size.getCoords (&x1, &y1, &x2, &y2); QRect default_size = QRect (x1+16, y1+32, x2/3, 2*y2/3); - m_recent_float_geom = settings->value ("DockWidgets/" + objectName () - + "_floating_geometry", - default_size).toRect (); + m_recent_float_geom + = settings->value (dw_float_geometry.key.arg (objectName ()), + default_size).toRect (); QWidget dummy; dummy.setGeometry (m_recent_float_geom); @@ -479,8 +481,9 @@ if (QApplication::desktop ()->screenNumber (&dummy) == -1) m_recent_float_geom = default_size; - m_recent_dock_geom = settings->value ("DockWidgets/" + objectName (), - QByteArray ()).toByteArray (); + m_recent_dock_geom + = settings->value (dw_dock_geometry.key.arg (objectName ()), + dw_dock_geometry.def).toByteArray (); notice_settings (settings); // call individual handler @@ -527,19 +530,16 @@ store_geometry (); - settings->beginGroup ("DockWidgets"); - // conditional needed? if (! m_recent_float_geom.isNull ()) - settings->setValue (name + "_floating_geometry", m_recent_float_geom); + settings->setValue (dw_float_geometry.key.arg (name), m_recent_float_geom); if (! m_recent_dock_geom.isEmpty ()) - settings->setValue (name, m_recent_dock_geom); - settings->setValue (name+"Visible", isVisible ()); // store visibility - settings->setValue (name+"Floating", isFloating ()); // store floating - settings->setValue (name+"_minimized", isMinimized ()); // store minimized + settings->setValue (dw_dock_geometry.key.arg (name), m_recent_dock_geom); + settings->setValue (dw_is_visible.key.arg (name), isVisible ()); // store visibility + settings->setValue (dw_is_floating.key.arg (name), isFloating ()); // store floating + settings->setValue (dw_is_minimized.key.arg (name), isMinimized ()); // store minimized - settings->endGroup (); settings->sync (); } @@ -766,15 +766,15 @@ resource_manager& rmgr = m_octave_qobj.get_resource_manager (); rmgr.update_settings_key ("Dockwidgets/title_bg_color", - "DockWidgets/title_bg_color"); + dw_title_bg_color.key); rmgr.update_settings_key ("Dockwidgets/title_bg_color_active", - "DockWidgets/title_bg_color_active"); + dw_title_bg_color_active.key); rmgr.update_settings_key ("Dockwidgets/title_fg_color", - "DockWidgets/title_fg_color"); + dw_title_fg_color.key); rmgr.update_settings_key ("Dockwidgets/title_fg_color_active", - "DockWidgets/title_fg_color_active"); + dw_title_fg_color_active.key); } } diff -r bd7decacf32e -r a1271c5b621a libgui/src/settings-dialog.cc --- a/libgui/src/settings-dialog.cc Sun Nov 10 14:05:23 2019 +0100 +++ b/libgui/src/settings-dialog.cc Sun Nov 10 21:56:18 2019 +0100 @@ -157,16 +157,15 @@ icon_group->addButton (general_icon_graphic); icon_group->addButton (general_icon_letter); QString widget_icon_set = - settings->value ("DockWidgets/widget_icon_set", "NONE").toString (); + settings->value (dw_icon_set.key, dw_icon_set.def).toString (); general_icon_octave->setChecked (true); // the default (if invalid set) general_icon_octave->setChecked (widget_icon_set == "NONE"); general_icon_graphic->setChecked (widget_icon_set == "GRAPHIC"); general_icon_letter->setChecked (widget_icon_set == "LETTER"); // custom title bar of dock widget - QVariant default_var = QColor (255, 255, 255); - QColor bg_color = settings->value ("DockWidgets/title_bg_color", - default_var).value (); + QColor bg_color = settings->value (dw_title_bg_color.key, + dw_title_bg_color.def).value (); m_widget_title_bg_color = new color_picker (bg_color); m_widget_title_bg_color->setEnabled (false); layout_widget_bgtitle->addWidget (m_widget_title_bg_color, 0); @@ -174,9 +173,8 @@ connect (cb_widget_custom_style, SIGNAL (toggled (bool)), m_widget_title_bg_color, SLOT (setEnabled (bool))); - default_var = QColor (192, 192, 192); - QColor bg_color_active = settings->value ("DockWidgets/title_bg_color_active", - default_var).value (); + QColor bg_color_active = settings->value (dw_title_bg_color_active.key, + dw_title_bg_color_active.def).value (); m_widget_title_bg_color_active = new color_picker (bg_color_active); m_widget_title_bg_color_active->setEnabled (false); layout_widget_bgtitle_active->addWidget (m_widget_title_bg_color_active, 0); @@ -184,9 +182,8 @@ connect (cb_widget_custom_style, SIGNAL (toggled (bool)), m_widget_title_bg_color_active, SLOT (setEnabled (bool))); - default_var = QColor (0, 0, 0); - QColor fg_color = settings->value ("DockWidgets/title_fg_color", - default_var).value (); + QColor fg_color = settings->value (dw_title_fg_color.key, + dw_title_fg_color.def).value (); m_widget_title_fg_color = new color_picker (fg_color); m_widget_title_fg_color->setEnabled (false); layout_widget_fgtitle->addWidget (m_widget_title_fg_color, 0); @@ -194,9 +191,8 @@ connect (cb_widget_custom_style, SIGNAL (toggled (bool)), m_widget_title_fg_color, SLOT (setEnabled (bool))); - default_var = QColor (0, 0, 0); - QColor fg_color_active = settings->value ("DockWidgets/title_fg_color_active", - default_var).value (); + QColor fg_color_active = settings->value (dw_title_fg_color_active.key, + dw_title_fg_color_active.def).value (); m_widget_title_fg_color_active = new color_picker (fg_color_active); m_widget_title_fg_color_active->setEnabled (false); layout_widget_fgtitle_active->addWidget (m_widget_title_fg_color_active, 0); @@ -204,8 +200,10 @@ connect (cb_widget_custom_style, SIGNAL (toggled (bool)), m_widget_title_fg_color_active, SLOT (setEnabled (bool))); - sb_3d_title->setValue (settings->value ("DockWidgets/widget_title_3d", 50).toInt ()); - cb_widget_custom_style->setChecked (settings->value ("DockWidgets/widget_title_custom_style", false).toBool ()); + sb_3d_title->setValue (settings->value (dw_title_3d.key, + dw_title_3d.def).toInt ()); + cb_widget_custom_style->setChecked (settings->value (dw_title_custom_style.key, + dw_title_custom_style.def).toBool ()); // Native file dialogs. // FIXME: This preference can be deprecated / removed if all display @@ -254,7 +252,7 @@ rmgr.combo_encoding (editor_combo_encoding); - default_var = QColor (240, 240, 240); + QColor default_var = QColor (240, 240, 240); QColor setting_color = settings->value ("editor/highlight_current_line_color", default_var).value (); m_editor_current_line_color = new color_picker (setting_color); editor_grid_current_line->addWidget (m_editor_current_line_color, 0, 3); @@ -833,7 +831,7 @@ widget_icon_set = "LETTER"; else if (general_icon_graphic->isChecked ()) widget_icon_set = "GRAPHIC"; - settings->setValue ("DockWidgets/widget_icon_set", widget_icon_set); + settings->setValue (dw_icon_set.key, widget_icon_set); // language QString language = comboBox_language->currentText (); @@ -848,12 +846,12 @@ settings->setValue (global_style.key, selected_style); // dock widget title bar - settings->setValue ("DockWidgets/widget_title_custom_style", cb_widget_custom_style->isChecked ()); - settings->setValue ("DockWidgets/widget_title_3d", sb_3d_title->value ()); - settings->setValue ("DockWidgets/title_bg_color", m_widget_title_bg_color->color ()); - settings->setValue ("DockWidgets/title_bg_color_active", m_widget_title_bg_color_active->color ()); - settings->setValue ("DockWidgets/title_fg_color", m_widget_title_fg_color->color ()); - settings->setValue ("DockWidgets/title_fg_color_active", m_widget_title_fg_color_active->color ()); + settings->setValue (dw_title_custom_style.key, cb_widget_custom_style->isChecked ()); + settings->setValue (dw_title_3d.key, sb_3d_title->value ()); + settings->setValue (dw_title_bg_color.key, m_widget_title_bg_color->color ()); + settings->setValue (dw_title_bg_color_active.key, m_widget_title_bg_color_active->color ()); + settings->setValue (dw_title_fg_color.key, m_widget_title_fg_color->color ()); + settings->setValue (dw_title_fg_color_active.key, m_widget_title_fg_color_active->color ()); // icon size and theme int icon_size = icon_size_large->isChecked () - icon_size_small->isChecked ();