Mercurial > octave
changeset 27662:3b078b750181
replace preference literals by symbolic constants for variable editor
* gui-preferences-ve.h: added all remaining workspace view preferences
* resource-manager.cc (varedit_default_colors, varedit_color_names):
remove obsolete function from resource_manager
* resource-manager.h: removed obsolete function varedit_color_chars,
varedit_color_names, varedit_default_colors
* settings-dialog.cc (settings_dialog): replaced literals by symb. constants;
(write_changed_settings): dito;
(read_varedit_colors): dito, resource_manager not needed anymore
(write_varedit_colors): dito
* variable-editor.cc (variable_editor_stack::save): replace literals by
symbolic constants;
(variable_editor): dito, resource_manager not needed anymore;
(notice_settings): dito;
(default_colors, color_names): removed obsolete functions;
* variable-editor.h: removed obsolete functions default_colors and color_names
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sun, 10 Nov 2019 12:15:33 +0100 |
parents | 2213e82bb9d3 |
children | 33674123f33a |
files | libgui/src/gui-preferences-ve.h libgui/src/resource-manager.cc libgui/src/resource-manager.h libgui/src/settings-dialog.cc libgui/src/variable-editor.cc libgui/src/variable-editor.h |
diffstat | 6 files changed, 86 insertions(+), 108 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/gui-preferences-ve.h Sat Nov 09 11:33:55 2019 -0800 +++ b/libgui/src/gui-preferences-ve.h Sun Nov 10 12:15:33 2019 +0100 @@ -25,9 +25,46 @@ #include "gui-preferences.h" +#include <QApplication> + // Variable Editor preferences const gui_pref -ve_font_size ("variable_editor/font_size", QVariant ()); +ve_use_terminal_font ("variable_editor/use_terminal_font", QVariant (true)); + +const gui_pref +ve_font_name ("variable_editor/font_name", QVariant ()); + +const gui_pref +ve_font_size ("variable_editor/font_size", QVariant (10)); + +const gui_pref +ve_column_width ("variable_editor/column_width", QVariant (100)); + +const gui_pref +ve_row_height ("variable_editor/row_height", QVariant (10)); + +const gui_pref +ve_alternate_rows ("variable_editor/alternate_rows", QVariant (false)); + +const int ve_colors_count = 5; + +const QString ve_color_chars ("fbsha"); + +const gui_pref ve_colors[ve_colors_count] = +{ + {"variable_editor/color_f", QVariant (QPalette::WindowText)}, + {"variable_editor/color_b", QVariant (QPalette::Base)}, + {"variable_editor/color_s", QVariant (QPalette::HighlightedText)}, + {"variable_editor/color_h", QVariant (QPalette::Highlight)}, + {"variable_editor/color_a", QVariant (QPalette::AlternateBase)} +}; + +const QStringList ve_color_names (QStringList () + << QT_TRANSLATE_NOOP ("variable_editor::variable_editor", "Foreground") + << QT_TRANSLATE_NOOP ("workspace_model::workspace_model", "Background") + << QT_TRANSLATE_NOOP ("workspace_model::workspace_model", "Selected Foreground") + << QT_TRANSLATE_NOOP ("workspace_model::workspace_model", "Selected Background") + << QT_TRANSLATE_NOOP ("workspace_model::workspace_model", "Alternate Background")); #endif
--- a/libgui/src/resource-manager.cc Sat Nov 09 11:33:55 2019 -0800 +++ b/libgui/src/resource-manager.cc Sun Nov 10 12:15:33 2019 +0100 @@ -185,16 +185,6 @@ } - QList<QColor> resource_manager::varedit_default_colors(void) - { - return variable_editor::default_colors (); - } - - QStringList resource_manager::varedit_color_names(void) - { - return variable_editor::color_names (); - } - gui_settings * resource_manager::get_settings (void) const { return m_settings;
--- a/libgui/src/resource-manager.h Sat Nov 09 11:33:55 2019 -0800 +++ b/libgui/src/resource-manager.h Sun Nov 10 12:15:33 2019 +0100 @@ -56,12 +56,6 @@ void config_translators (QTranslator *qt_tr, QTranslator *qsci_tr, QTranslator *gui_tr); - QString varedit_color_chars (void) {return "fbsha"; } - - QStringList varedit_color_names (void); - - QList<QColor> varedit_default_colors (void); - gui_settings * get_settings (void) const; gui_settings * get_default_settings (void) const;
--- a/libgui/src/settings-dialog.cc Sat Nov 09 11:33:55 2019 -0800 +++ b/libgui/src/settings-dialog.cc Sun Nov 10 12:15:33 2019 +0100 @@ -427,23 +427,25 @@ read_terminal_colors (settings); // variable editor - varedit_columnWidth->setValue (settings->value ("variable_editor/column_width", 100).toInt ()); + varedit_columnWidth->setValue (settings->value (ve_column_width.key, ve_column_width.def).toInt ()); varedit_autoFitColumnWidth->setChecked (settings->value ("variable_editor/autofit_column_width", false).toBool ()); varedit_autofitType->setCurrentIndex (settings->value ("variable_editor/autofit_type", 0).toInt ()); - varedit_rowHeight->setValue (settings->value ("variable_editor/row_height", 10).toInt ()); + varedit_rowHeight->setValue (settings->value (ve_row_height.key, ve_row_height.def).toInt ()); + varedit_rowAutofit->setChecked (settings->value ("variable_editor/autofit_row_height", true).toBool ()); - varedit_font->setCurrentFont (QFont (settings->value ("variable_editor/font_name", settings->value (cs_font.key, default_font)).toString ())); + varedit_font->setCurrentFont (QFont (settings->value (ve_font_name.key, + settings->value (cs_font.key, default_font)).toString ())); varedit_fontSize->setValue (settings->value (ve_font_size.key, ve_font_size.def).toInt ()); connect (varedit_useTerminalFont, SIGNAL (toggled (bool)), varedit_font, SLOT (setDisabled (bool))); connect (varedit_useTerminalFont, SIGNAL (toggled (bool)), varedit_fontSize, SLOT (setDisabled (bool))); - varedit_useTerminalFont->setChecked (settings->value ("variable_editor/use_terminal_font", false).toBool ()); + varedit_useTerminalFont->setChecked (settings->value (ve_use_terminal_font.key, ve_use_terminal_font.def).toBool ()); varedit_font->setDisabled (varedit_useTerminalFont->isChecked ()); varedit_fontSize->setDisabled (varedit_useTerminalFont->isChecked ()); - varedit_alternate->setChecked (settings->value ("variable_editor/alternate_rows", QVariant (false)).toBool ()); + varedit_alternate->setChecked (settings->value (ve_alternate_rows.key, ve_alternate_rows.def).toBool ()); // variable editor colors read_varedit_colors (settings); @@ -1031,12 +1033,12 @@ // Variable editor settings->setValue ("variable_editor/autofit_column_width", varedit_autoFitColumnWidth->isChecked ()); settings->setValue ("variable_editor/autofit_type", varedit_autofitType->currentIndex ()); - settings->setValue ("variable_editor/column_width", varedit_columnWidth->value ()); - settings->setValue ("variable_editor/row_height", varedit_rowHeight->value ()); + settings->setValue (ve_column_width.key, varedit_columnWidth->value ()); + settings->setValue (ve_row_height.key, varedit_rowHeight->value ()); settings->setValue ("variable_editor/autofit_row_height", varedit_rowAutofit->isChecked ()); - settings->setValue ("variable_editor/use_terminal_font", varedit_useTerminalFont->isChecked ()); - settings->setValue ("variable_editor/alternate_rows", varedit_alternate->isChecked ()); - settings->setValue ("variable_editor/font_name", varedit_font->currentFont ().family ()); + settings->setValue (ve_use_terminal_font.key, varedit_useTerminalFont->isChecked ()); + settings->setValue (ve_alternate_rows.key, varedit_alternate->isChecked ()); + settings->setValue (ve_font_name.key, varedit_font->currentFont ().family ()); settings->setValue (ve_font_size.key, varedit_fontSize->value ()); write_varedit_colors (settings); @@ -1171,26 +1173,26 @@ void settings_dialog::read_varedit_colors (gui_settings *settings) { - QList<QColor> default_colors = variable_editor::default_colors (); - QStringList class_names = variable_editor::color_names (); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - QString class_chars = rmgr.varedit_color_chars (); - int nr_of_classes = class_chars.length (); - QGridLayout *style_grid = new QGridLayout (); - QVector<QLabel*> description (nr_of_classes); - QVector<color_picker*> color (nr_of_classes); + QVector<QLabel*> description (ve_colors_count); + QVector<color_picker*> color (ve_colors_count); int column = 0; int row = 0; - for (int i = 0; i < nr_of_classes; i++) + for (int i = 0; i < ve_colors_count; i++) { - description[i] = new QLabel (" " + class_names.at (i)); + description[i] = new QLabel (" " + ve_color_names.at (i)); description[i]->setAlignment (Qt::AlignRight); - QVariant default_var = default_colors.at (i); - QColor setting_color = settings->value ("variable_editor/color_" + class_chars.mid (i, 1), default_var).value<QColor> (); + + // The default colors are given as color roles for + // the application's palette + QColor default_color = qApp->palette ().color + (ve_colors[i].def.value<QPalette::ColorRole> ()); + QColor setting_color = + settings->value (ve_colors[i].key, default_color).value<QColor> (); + color[i] = new color_picker (setting_color); - color[i]->setObjectName ("varedit_color_" + class_chars.mid (i, 1)); + color[i]->setObjectName (ve_colors[i].key); color[i]->setMinimumSize (30, 10); style_grid->addWidget (description[i], row, 2*column); style_grid->addWidget (color[i], row, 2*column+1); @@ -1208,15 +1210,13 @@ void settings_dialog::write_varedit_colors (gui_settings *settings) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - QString class_chars = rmgr.varedit_color_chars (); color_picker *color; - for (int i = 0; i < class_chars.length (); i++) + for (int i = 0; i < ve_colors_count; i++) { - color = varedit_colors_box->findChild <color_picker *> ("varedit_color_" + class_chars.mid (i, 1)); + color = varedit_colors_box->findChild <color_picker *> (ve_colors[i].key); if (color) - settings->setValue ("variable_editor/color_" + class_chars.mid (i, 1), color->color ()); + settings->setValue (ve_colors[i].key, color->color ()); } settings->sync ();
--- a/libgui/src/variable-editor.cc Sat Nov 09 11:33:55 2019 -0800 +++ b/libgui/src/variable-editor.cc Sun Nov 10 12:15:33 2019 +0100 @@ -461,7 +461,8 @@ int opts = 0; // No options by default. resource_manager& rmgr = m_octave_qobj.get_resource_manager (); gui_settings *settings = rmgr.get_settings (); - if (! settings->value ("use_native_file_dialogs", true).toBool ()) + if (! settings->value (global_use_native_dialogs.key, + global_use_native_dialogs.def).toBool ()) opts = QFileDialog::DontUseNativeDialog; QString name = objectName (); @@ -1084,9 +1085,7 @@ // Colors. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - for (int i = 0; i < rmgr.varedit_color_chars ().length (); i++) + for (int i = 0; i < ve_colors_count; i++) m_table_colors.append (QColor (Qt::white)); // Use an MDI area that is shrunk to nothing as the central widget. @@ -1342,34 +1341,6 @@ emit refresh_signal (); } - QList<QColor> - variable_editor::default_colors (void) - { - QList<QColor> colorlist; - - colorlist << qApp->palette ().color (QPalette::WindowText); - colorlist << qApp->palette ().color (QPalette::Base); - colorlist << qApp->palette ().color (QPalette::HighlightedText); - colorlist << qApp->palette ().color (QPalette::Highlight); - colorlist << qApp->palette ().color (QPalette::AlternateBase); - - return colorlist; - } - - QStringList - variable_editor::color_names (void) - { - QStringList output; - - output << tr("Foreground"); - output << tr("Background"); - output << tr("Selected Foreground"); - output << tr("Selected Background"); - output << tr("Alternate Background"); - - return output; - } - void variable_editor::callUpdate (const QModelIndex&, const QModelIndex&) { @@ -1381,23 +1352,17 @@ { m_main->notice_settings (settings); // update settings in parent main win - m_default_width = settings->value ("variable_editor/column_width", - 100).toInt (); + m_default_width = settings->value (ve_column_width.key, + ve_column_width.def).toInt (); - m_default_height = settings->value ("variable_editor/row_height", - 10).toInt (); - - m_alternate_rows = settings->value ("variable_editor/alternate_rows", - false).toBool (); + m_default_height = settings->value (ve_row_height.key, + ve_row_height.def).toInt (); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - QList<QColor> default_colors = rmgr.varedit_default_colors (); + m_alternate_rows = settings->value (ve_alternate_rows.key, + ve_alternate_rows.def).toBool (); - QString class_chars = rmgr.varedit_color_chars (); - - m_use_terminal_font = settings->value ("variable_editor/use_terminal_font", - true).toBool (); + m_use_terminal_font = settings->value (ve_use_terminal_font.key, + ve_use_terminal_font.def).toBool (); QString font_name; int font_size; @@ -1411,7 +1376,7 @@ } else { - font_name = settings->value ("variable_editor/font_name", default_font).toString (); + font_name = settings->value (ve_font_name.key, default_font).toString (); font_size = settings->value (ve_font_size.key, ve_font_size.def).toInt (); } @@ -1421,20 +1386,16 @@ m_add_font_height = fm.height (); - for (int i = 0; i < class_chars.length (); i++) + for (int i = 0; i < ve_colors_count; i++) { - QVariant default_var; - if (i < default_colors.length ()) - default_var = default_colors.at (i); - else - default_var = QColor (); + // The default colors are given as color roles for + // the application's palette + QColor default_color = qApp->palette ().color + (ve_colors[i].def.value<QPalette::ColorRole> ()); + QColor setting_color = + settings->value (ve_colors[i].key, default_color).value<QColor> (); - QColor setting_color = settings->value ("variable_editor/color_" - + class_chars.mid (i, 1), - default_var).value<QColor> (); - - if (i < m_table_colors.length ()) - m_table_colors.replace (i, setting_color); + m_table_colors.replace (i, setting_color); } update_colors ();