Mercurial > octave
changeset 29488:2a251de6c1a5
provide second color mode for variable editor
* gui-preferences-ve.h: using the extensions for color preference keys
of different color modes, define the keys for new mode, define preference
for the selected modes
* settings-dialog.cc (read_varedit_colors): add checkbox for second
color mode, connect trigger signal of this checkbox to new slot
update_varedit_colors, use new method color_value for reading colors
from the settings;
(update_varedit_colors): slot for updating the current color picker
colors depending on selected color mode;
(write_varedit_colors_colors): use new method set_color_value for writing
colors to settings depending on color mode;
* settings-dialog.h: new slot update_varedit_colors
* variable-editor.cc (notice_settings): get colors with new method
color_value from gui_settings;
(update_colors): fix stylesheet for foreground color
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sat, 03 Apr 2021 13:19:04 +0200 |
parents | 00674bc1446d |
children | ee66869c30d6 |
files | libgui/src/gui-preferences-ve.h libgui/src/settings-dialog.cc libgui/src/settings-dialog.h libgui/src/variable-editor.cc |
diffstat | 4 files changed, 65 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/gui-preferences-ve.h Sat Apr 03 08:26:30 2021 +0200 +++ b/libgui/src/gui-preferences-ve.h Sat Apr 03 13:19:04 2021 +0200 @@ -50,17 +50,24 @@ const gui_pref ve_alternate_rows ("variable_editor/alternate_rows", QVariant (false)); -const int ve_colors_count = 5; +const gui_pref +ve_color_mode ("variable_editor/color_mode", QVariant (0)); const QString ve_color_chars ("fbsha"); -const gui_pref ve_colors[ve_colors_count] = +const int ve_colors_count = 5; +const gui_pref ve_colors[2*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)} + {"variable_editor/color_f" + settings_color_modes_ext[0], QVariant (QPalette::WindowText)}, + {"variable_editor/color_b" + settings_color_modes_ext[0], QVariant (QPalette::Base)}, + {"variable_editor/color_s" + settings_color_modes_ext[0], QVariant (QPalette::HighlightedText)}, + {"variable_editor/color_h" + settings_color_modes_ext[0], QVariant (QPalette::Highlight)}, + {"variable_editor/color_a" + settings_color_modes_ext[0], QVariant (QPalette::AlternateBase)}, + {"variable_editor/color_f" + settings_color_modes_ext[1], QVariant ()}, + {"variable_editor/color_b" + settings_color_modes_ext[1], QVariant ()}, + {"variable_editor/color_s" + settings_color_modes_ext[1], QVariant ()}, + {"variable_editor/color_h" + settings_color_modes_ext[1], QVariant ()}, + {"variable_editor/color_a" + settings_color_modes_ext[1], QVariant ()} }; const QStringList ve_color_names (QStringList ()
--- a/libgui/src/settings-dialog.cc Sat Apr 03 08:26:30 2021 +0200 +++ b/libgui/src/settings-dialog.cc Sat Apr 03 13:19:04 2021 +0200 @@ -1313,7 +1313,16 @@ QVector<QLabel*> description (ve_colors_count); QVector<color_picker*> color (ve_colors_count); - int column = 0; + int mode = settings->value (ve_color_mode).toInt (); + + QCheckBox *cb_color_mode = new QCheckBox (settings_color_modes); + cb_color_mode->setToolTip (settings_color_modes_tooltip); + cb_color_mode->setChecked (mode == 1); + cb_color_mode->setObjectName (ve_color_mode.key); + style_grid->addWidget (cb_color_mode, 0, 0); + + int column = 1; + int color_columns = 2; int row = 0; for (int i = 0; i < ve_colors_count; i++) { @@ -1321,44 +1330,67 @@ + tr (ve_color_names.at (i).toStdString ().data ())); description[i]->setAlignment (Qt::AlignRight); - // The default colors are given as color roles for - // the application's palette - QColor default_color = qApp->palette ().color - (static_cast<QPalette::ColorRole> (ve_colors[i].def.toInt ())); - // FIXME: use value<QPalette::ColorRole> instead of static cast after - // dropping support of Qt 5.4 - - QColor setting_color = - settings->value (ve_colors[i].key, default_color).value<QColor> (); - + QColor setting_color = settings->color_value (ve_colors[i], mode); color[i] = new color_picker (setting_color); 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); - if (++column == 2) + if (++column > color_columns) { style_grid->setColumnStretch (3*column, 10); row++; - column = 0; + column = 1; } } // place grid with elements into the tab varedit_colors_box->setLayout (style_grid); + + // update colors depending on second theme selection + connect (cb_color_mode, SIGNAL (stateChanged (int)), + this, SLOT (update_varedit_colors (int))); + } + + void settings_dialog::update_varedit_colors (int mode) + { + int m = mode; + if (m > 1) + m = 1; // Currently one more color mode + + resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings *settings = rmgr.get_settings (); + + color_picker *c_picker; + + for (unsigned int i = 0; i < ve_colors_count; i++) + { + c_picker = varedit_colors_box->findChild <color_picker *> (ve_colors[i].key); + if (c_picker) + c_picker->set_color (settings->color_value (ve_colors[i], m)); + } } void settings_dialog::write_varedit_colors (gui_settings *settings) { + QCheckBox *cb_color_mode + = varedit_colors_box->findChild <QCheckBox *> (ve_color_mode.key); + + int mode = 0; + if (cb_color_mode && cb_color_mode->isChecked ()) + mode = 1; + color_picker *color; for (int i = 0; i < ve_colors_count; i++) { color = varedit_colors_box->findChild <color_picker *> (ve_colors[i].key); if (color) - settings->setValue (ve_colors[i].key, color->color ()); + settings->set_color_value (ve_colors[i], color->color (), mode); } + settings->setValue (ve_color_mode.key, mode); + settings->sync (); } }
--- a/libgui/src/settings-dialog.h Sat Apr 03 08:26:30 2021 +0200 +++ b/libgui/src/settings-dialog.h Sat Apr 03 13:19:04 2021 +0200 @@ -70,6 +70,7 @@ // slots updating colors depending on theme void update_terminal_colors (int mode); void update_workspace_colors (int mode); + void update_varedit_colors (int mode); // slots for dialog's buttons void button_clicked (QAbstractButton *button);
--- a/libgui/src/variable-editor.cc Sat Apr 03 08:26:30 2021 +0200 +++ b/libgui/src/variable-editor.cc Sat Apr 03 13:19:04 2021 +0200 @@ -1415,18 +1415,11 @@ m_add_font_height = fm.height (); + int mode = settings->value (ve_color_mode).toInt (); + for (int i = 0; i < ve_colors_count; i++) { - // The default colors are given as color roles for - // the application's palette - QColor default_color = qApp->palette ().color - (static_cast<QPalette::ColorRole> (ve_colors[i].def.toInt ())); - // FIXME: use value<QPalette::ColorRole> instead of static cast after - // dropping support of Qt 5.4 - - QColor setting_color = - settings->value (ve_colors[i].key, default_color).value<QColor> (); - + QColor setting_color = settings->color_value (ve_colors[i], mode); m_table_colors.replace (i, setting_color); } @@ -1564,7 +1557,7 @@ m_stylesheet = ""; if (m_table_colors.length () > 0) - m_stylesheet += "QTableView::item{ foreground-color: " + m_stylesheet += "QTableView::item{ color: " + m_table_colors[0].name () +" }"; if (m_table_colors.length () > 1)