GNU Octave  8.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-2023 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 "octave-config.h"
30 
31 #include <QSettings>
32 
33 #include "gui-preferences.h"
34 
36 
37 class gui_settings : public QSettings
38 {
39  Q_OBJECT
40 
41 public:
42 
43  gui_settings (const QString& file_name, QSettings::Format format,
44  QObject *parent = nullptr)
45  : QSettings (file_name, format, parent)
46  { }
47 
48  gui_settings (QSettings::Format format, QSettings::Scope scope,
49  const QString& organization,
50  const QString& application = QString (),
51  QObject *parent = nullptr)
52  : QSettings (format, scope, organization, application, parent)
53  { }
54 
55  // No copying!
56 
57  gui_settings (const gui_settings&) = delete;
58 
59  gui_settings& operator = (const gui_settings&) = delete;
60 
61  ~gui_settings (void) = default;
62 
63  using QSettings::value;
64 
65  QVariant value (const gui_pref& pref) const
66  {
67  if (pref.ignore)
68  return pref.def; // ignore the current pref and always use default
69 
70  return value (pref.key, pref.def);
71  }
72 
73  /*!
74  Reading a color from the given QVaraitn @p def taking different
75  color modes into account. The default value for a second color mode
76  @p mode=1 is deterimined from the standard default value @p mode=0
77  by inverting the lightness
78  \f{eqnarray*}{
79  H_1 &=& H_0\\
80  S_1 &=& S_0\\
81  L_1 &=& 1.0 - 0.85 L_0 L_0 > 0.3
82  L_1 &=& 1.0 - 0.70 L_0 L_0 < 0.3
83  \f}
84 
85  @param def Color default value given by a QVariant of QColor
86  or QPalette::ColorRole
87  @param mode Color mode (currently 0 or 1, default is 0)
88 
89  @return Color as QColor
90  */
91  QColor get_color_value (const QVariant& def, int mode = 0) const;
92 
93  /*!
94  Reading a color from the gui_settings taking possible color modes
95  into account. The default value for a second color mode @p mode=1 is
96  deterimined from the standard default value @p mode=0 by inverting
97  the lightness (see get_color_value())
98 
99  @param pref gui preference (key string, default value); the default
100  value can be given by QColor or QPalette::ColorRole
101  @param mode Color mode (currently 0 or 1, default is 0)
102 
103  @return Color as QColor
104  */
105  QColor color_value (const gui_pref& pref, int mode = 0) const;
106 
107  /*!
108  Writing a color to the gui_settings taking possible color modes
109  into account. When @p mode is not zero (standard mode), the
110  extension related to the mode is appended to the settings key string
111 
112  @param pref gui preference where the color should be written
113  @param color QColor to write to the settings
114  @param mode Color mode (currently 0 or 1, default is 0)
115 
116  */
117  void set_color_value (const gui_pref& pref, const QColor& color,
118  int mode = 0);
119 
120  QString sc_value (const sc_pref& pref) const;
121 
122  QKeySequence sc_def_value (const sc_pref& pref) const;
123 
124 };
125 
127 
128 // Some constants used in the preferences of several widgets and therefore
129 // defined globally here
130 
131 // Constants for handling different color schemes
132 const QColor settings_color_no_change (255, 0, 255);
133 const QStringList settings_color_modes_ext (QStringList () << "" << "_2");
135 
136 #endif
OCTAVE_END_NAMESPACE(octave)
gui_settings(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application=QString(), QObject *parent=nullptr)
Definition: gui-settings.h:48
gui_settings(const gui_settings &)=delete
~gui_settings(void)=default
gui_settings(const QString &file_name, QSettings::Format format, QObject *parent=nullptr)
Definition: gui-settings.h:43
QVariant value(const gui_pref &pref) const
Definition: gui-settings.h:65
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
const QColor settings_color_no_change(255, 0, 255)
const QStringList settings_color_modes_ext(QStringList()<< ""<< "_2")
const int settings_reload_default_colors_flag
Definition: gui-settings.h:134
const QString key
const QVariant def
const bool ignore
std::size_t format(std::ostream &os, const char *fmt,...)
Definition: utils.cc:1473