GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
gui-settings.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2019-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_gui_settings_h)
27#define octave_gui_settings_h 1
28
29#include <QSettings>
30
31#include "gui-preferences.h"
32
33namespace octave
34{
35 class gui_settings : public QSettings
36 {
37 Q_OBJECT
38
39 public:
40
41 gui_settings (const QString& file_name, QSettings::Format format,
42 QObject *parent = nullptr)
43 : QSettings (file_name, format, parent)
44 { }
45
46 gui_settings (QSettings::Format format, QSettings::Scope scope,
47 const QString& organization,
48 const QString& application = QString (),
49 QObject *parent = nullptr)
50 : QSettings (format, scope, organization, application, parent)
51 { }
52
53 // No copying!
54
55 gui_settings (const gui_settings&) = delete;
56
58
59 ~gui_settings (void) = default;
60
61 using QSettings::value;
62
63 QVariant value (const gui_pref& pref) const
64 {
65 if (pref.ignore)
66 return pref.def; // ignore the current pref and always use default
67
68 return value (pref.key, pref.def);
69 }
70
71 /*!
72 Reading a color from the given QVaraitn @p def taking different
73 color modes into account. The default value for a second color mode
74 @p mode=1 is deterimined from the standard default value @p mode=0
75 by inverting the lightness
76 \f{eqnarray*}{
77 H_1 &=& H_0\\
78 S_1 &=& S_0\\
79 L_1 &=& 1.0 - 0.85 L_0 L_0 > 0.3
80 L_1 &=& 1.0 - 0.70 L_0 L_0 < 0.3
81 \f}
82
83 @param def Color default value given by a QVariant of QColor
84 or QPalette::ColorRole
85 @param mode Color mode (currently 0 or 1, default is 0)
86
87 @return Color as QColor
88 */
89 QColor get_color_value (const QVariant& def, int mode = 0) const;
90
91 /*!
92 Reading a color from the gui_settings taking possible color modes
93 into account. The default value for a second color mode @p mode=1 is
94 deterimined from the standard default value @p mode=0 by inverting
95 the lightness (see get_color_value())
96
97 @param pref gui preference (key string, default value); the default
98 value can be given by QColor or QPalette::ColorRole
99 @param mode Color mode (currently 0 or 1, default is 0)
100
101 @return Color as QColor
102 */
103 QColor color_value (const gui_pref& pref, int mode = 0) const;
104
105 /*!
106 Writing a color to the gui_settings taking possible color modes
107 into account. When @p mode is not zero (standard mode), the
108 extension related to the mode is appended to the settings key string
109
110 @param pref gui preference where the color should be written
111 @param color QColor to write to the settings
112 @param mode Color mode (currently 0 or 1, default is 0)
113
114 */
115 void set_color_value (const gui_pref& pref, const QColor& color,
116 int mode = 0);
117
118 QString sc_value (const sc_pref& pref) const;
119
120 QKeySequence sc_def_value (const sc_pref& pref) const;
121
122 };
123
124}
125
126// Some constants used several times in the settings
127
128// Special color indicating no change compared to default color
129const QColor settings_color_no_change (255, 0, 255);
130
131// Other color schemes (currently one extra, but possibly more in the future)
132const QString settings_color_modes = QT_TRANSLATE_NOOP (
133 "octave::settings_dialog",
134 "Second color mode (light/dark)");
135const QString settings_color_modes_tooltip = QT_TRANSLATE_NOOP (
136 "octave::settings_dialog",
137 "Switches to another set of colors.\n"
138 "Useful for defining a dark/light mode.\n"
139 "Discards non-applied current changes!");
140const QStringList settings_color_modes_ext (QStringList () << "" << "_2");
141// Reset colors (reload default values)
142const QString settings_reload_colors = QT_TRANSLATE_NOOP (
143 "octave::settings_dialog",
144 "&Reload default colors");
145const QString settings_reload_colors_tooltip = QT_TRANSLATE_NOOP (
146 "octave::settings_dialog",
147 "Reloads the default colors,\n"
148 "depending on currently selected mode.");
149const QString settings_reload_styles = QT_TRANSLATE_NOOP (
150 "octave::settings_dialog",
151 "&Reload default styles");
152const QString settings_reload_styles_tooltip = QT_TRANSLATE_NOOP (
153 "octave::settings_dialog",
154 "Reloads the default values of the styles,\n"
155 "depending on currently selected mode.");
157#endif
158
QVariant value(const gui_pref &pref) const
Definition: gui-settings.h:63
QKeySequence sc_def_value(const sc_pref &pref) const
Definition: gui-settings.cc:97
void set_color_value(const gui_pref &pref, const QColor &color, int mode=0)
Definition: gui-settings.cc:78
QColor color_value(const gui_pref &pref, int mode=0) const
Definition: gui-settings.cc:70
QColor get_color_value(const QVariant &def, int mode=0) const
Definition: gui-settings.cc:38
QString sc_value(const sc_pref &pref) const
Definition: gui-settings.cc:88
gui_settings(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application=QString(), QObject *parent=nullptr)
Definition: gui-settings.h:46
gui_settings & operator=(const gui_settings &)=delete
gui_settings(const QString &file_name, QSettings::Format format, QObject *parent=nullptr)
Definition: gui-settings.h:41
~gui_settings(void)=default
gui_settings(const gui_settings &)=delete
const QString settings_reload_colors_tooltip
Definition: gui-settings.h:145
const QString settings_color_modes_tooltip
Definition: gui-settings.h:135
const QString settings_color_modes
Definition: gui-settings.h:132
const QString settings_reload_colors
Definition: gui-settings.h:142
const QColor settings_color_no_change(255, 0, 255)
const QString settings_reload_styles_tooltip
Definition: gui-settings.h:152
const QString settings_reload_styles
Definition: gui-settings.h:149
const QStringList settings_color_modes_ext(QStringList()<< ""<< "_2")
const int settings_reload_default_colors_flag
Definition: gui-settings.h:156
const QString key
const QVariant def
const bool ignore
std::size_t format(std::ostream &os, const char *fmt,...)
Definition: utils.cc:1471