Mercurial > octave
diff libgui/src/gui-settings.cc @ 29484:bed2fd5b8263
allow a second color theme for the console window (dark mode)
* QTerminal.cc (notice_settings): use new method color_value for reading
the terminal colors from the gui_settings
* color-picker.cc/.h (set_color): new method for updating the current
color of a color picker
* gui-preferences-cs.h: using the extensions for color preference keys
of different color modes, define the keys for new mode, define preference
for the selected modes
* gui-settings.cc (color_value): new method for reading color values
from the settings taking the mode into consideration and computing
the default value from standard mode defaults, also allowing defaults
given as QColor or ColorRoles;
(set_color_value): new method for writing a color to the settings key,
where the key name is determined depending on the key
* gui-settings.h: new methods color_value, set_color_value, definition
of some constant strings related to color modes
* settings-dialog.cc (settings_dialog): reorder some action;
(write_changed_settings): reorder some action;
(read_terminal_colors): add checkbox for second color mode, connect
trigger signal of this checkbos to new slot update_terminal_colors,
use new method color_value for reading colors from the settings;
(update_terminal_colors): slot for updating the current color picker
colors depending on selected color mode;
(write_terminal_colors): use new method set_color_value for writing
colors to settings depending on color mode
* settings-dialog.h: new slot update_terminal_colors
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Fri, 02 Apr 2021 16:54:42 +0200 |
parents | 0a5b15007766 |
children | 00674bc1446d |
line wrap: on
line diff
--- a/libgui/src/gui-settings.cc Thu Apr 01 23:18:50 2021 +0200 +++ b/libgui/src/gui-settings.cc Fri Apr 02 16:54:42 2021 +0200 @@ -27,6 +27,7 @@ # include "config.h" #endif +#include <QApplication> #include <QSettings> #include "gui-settings.h" @@ -34,6 +35,46 @@ namespace octave { + QColor gui_settings::color_value (const gui_pref& pref, int mode) const + { + QColor default_color; + + // Determine whether the default value in pref is given as + // QPalette::ColorRole or as QColor + if (pref.def.canConvert (QMetaType::QColor)) + default_color = pref.def.value<QColor> (); + else + { + // The default colors are given as color roles for + // the application's palette + default_color = QApplication::palette ().color + (static_cast<QPalette::ColorRole> (pref.def.toInt ())); + // FIXME: use value<QPalette::ColorRole> instead of static cast after + // dropping support of Qt 5.4 + } + + if (mode == 1) + { + // In second mode, determine the default color from the first mode + qreal h, s, l, a; + default_color.getHslF (&h, &s, &l, &a); + default_color.setHslF (h, s, 1.0-l, a); + } + + return value (pref.key + settings_color_modes_ext.at (mode), + QVariant (default_color)).value<QColor> (); + } + + void gui_settings::set_color_value (const gui_pref& pref, + const QColor& color, int mode) + { + int m = mode; + if (m > 1) + m = 1; + + setValue (pref.key + settings_color_modes_ext.at (m), QVariant (color)); + } + QString gui_settings::sc_value (const sc_pref& pref) const { QKeySequence key_seq = sc_def_value (pref);