Mercurial > octave
view libgui/src/gui-settings.h @ 29498:5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
* default-qt-settings.in: remove all lexer related default settings
* gui-preferences-ed.h: add constants related to the number of lexer
styles, remove obsolete preference ed_highlight_current_line_color
* gui-settings.cc (get_color_value): move detecting the color from
the QVaraiant drom color_value into this separate function (required
for reading the default lexer settings);
(color_value); see get_color_value;
(set_color_value): shorter access to QStringList elements
* gui-settings.h: new method get_color_value, new constant for
the magenta color indicating same color as the default value in the
editor styles
* file-editor-tab.cc (file_edito_tab): read lexer settings depending on
the current color mode, determine color of current line depending on
background color (no more user pref)
* octave-qscintilla.cc (set_selection_marker_color): increase alpha
value for highlighted occurrences of double clicked word
* resource-manager.cc (get_valid_lexer_styles): moved this method from
settings_dialog (static) to normal method here;
(copy_font_attributes): private method for copying attributes from
one font to another font
(read_lexer_settings): take color mode into consideration, if lexer
settings not found in settings file, take defaults from the lexer, not
from octaves default settings file, and write them to the settings file
related to the selected color mode
* resource-manager.h: new methods get_valid_lexer_styles,
copy_font_attributes and new arguments for read_lexer_settings
* settings-dialog.cc (get_valid_lexer_styles) moved static method into
non-static in resource_manager;
(settings_dialog): remove settings for current editor line color;
move lexer definition and reading related settings into separate
new slot update_editor_lexers, add color mode checkbox and connect
state change to update_editor_lexers;
(update_editor_lexers): definition of lexers for each language and
call update_lexer for the specific actions;
(update_lexer): call rmgr.read_lexer_settings, i.e., read settings
or get default values from lexer check whether the language tabs in
the settings dialog have to be created or updated (due to color mode
change), call get_lexer_settings in the first and update the color
picker in the second case;
(get_lexer_settings, renamed from read_lexer_settings): create the
language tab and fill in the lexer values
(write_lexer_settings): new argument color mode, write settings into
the related section into the settings file;
(write_changed_settings): write the editor color mode into the settings,
remove editor current line color
* settings-dialog.h: new methods update_editor_lexers, update_lexer,
renamed read_lexer_settings into get_lexer_settings, new arguments
for write_lexer_settings, removed class variable for editor current
line color
* settings-dialog.ui: added checkbox for editor color mode, removed
color picker for editor current line color
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Tue, 06 Apr 2021 21:26:52 +0200 |
parents | 00674bc1446d |
children | 730cac3d6d5a |
line wrap: on
line source
//////////////////////////////////////////////////////////////////////// // // Copyright (C) 2019-2021 The Octave Project Developers // // See the file COPYRIGHT.md in the top-level directory of this // distribution or <https://octave.org/copyright/>. // // 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 // <https://www.gnu.org/licenses/>. // //////////////////////////////////////////////////////////////////////// #if ! defined (octave_gui_settings_h) #define octave_gui_settings_h 1 #include <QSettings> #include "gui-preferences.h" namespace octave { class gui_settings : public QSettings { Q_OBJECT public: gui_settings (const QString& file_name, QSettings::Format format, QObject *parent = nullptr) : QSettings (file_name, format, parent) { } gui_settings (QSettings::Format format, QSettings::Scope scope, const QString& organization, const QString& application = QString (), QObject *parent = nullptr) : QSettings (format, scope, organization, application, parent) { } // No copying! gui_settings (const gui_settings&) = delete; gui_settings& operator = (const gui_settings&) = delete; ~gui_settings (void) = default; using QSettings::value; QVariant value (const gui_pref& pref) const { if (pref.ignore) return pref.def; // ignore the current pref and always use default return value (pref.key, pref.def); } /*! Reading a color from the given QVaraitn @p def taking different color modes into account. The default value for a second color mode @p mode=1 is deterimined from the standard default value @p mode=0 by inverting the lightness \f{eqnarray*}{ H_1 &=& H_0\\ S_1 &=& S_0\\ L_1 &=& 1.0 - 0.85 L_0 L_0 > 0.3 L_1 &=& 1.0 - 0.70 L_0 L_0 < 0.3 \f} @param def Color default value given by a QVariant of QColor or QPalette::ColorRole @param mode Color mode (currently 0 or 1, default is 0) @return Color as QColor */ QColor get_color_value (const QVariant& def, int mode = 0) const; /*! Reading a color from the gui_settings taking possible color modes into account. The default value for a second color mode @p mode=1 is deterimined from the standard default value @p mode=0 by inverting the lightness (see get_color_value()) @param pref gui preference (key string, default value); the default value can be given by QColor or QPalette::ColorRole @param mode Color mode (currently 0 or 1, default is 0) @return Color as QColor */ QColor color_value (const gui_pref& pref, int mode = 0) const; /*! Writing a color to the gui_settings taking possible color modes into account. When @p mode is not zero (standard mode), the extension related to the mode is appended to the settings key string @param pref gui preference where the color should be written @param color QColor to write to the settings @param mode Color mode (currently 0 or 1, default is 0) */ void set_color_value (const gui_pref& pref, const QColor& color, int mode = 0); QString sc_value (const sc_pref& pref) const; QKeySequence sc_def_value (const sc_pref& pref) const; }; } // Some constants used several times in the settings // Special color indicating no change compared to default color const QColor settings_color_no_change (255,0,255); // Other color schemes (currently one extra, but possibly more in the future) const QString settings_color_modes = QT_TRANSLATE_NOOP ( "octave::settings_dialog", "Second color mode (light/dark)"); const QString settings_color_modes_tooltip = QT_TRANSLATE_NOOP ( "octave::settings_dialog", "Switches to another set of colors.\n" "Useful for defining a dark/light mode.\n" "Discards non-applied current changes!"); const QStringList settings_color_modes_ext (QStringList () << "" << "_2"); #endif