GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
gui-settings.cc
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 (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <QApplication>
31 #include <QSettings>
32 
33 #include "gui-settings.h"
34 
36 
37 QColor gui_settings::get_color_value (const QVariant& def, int mode) const
38 {
39  QColor default_color;
40 
41  // Determine whether the default value in pref is given as
42  // QPalette::ColorRole or as QColor
43  if (def.canConvert (QMetaType::QColor))
44  default_color = def.value<QColor> ();
45  else
46  {
47  // The default colors are given as color roles for
48  // the application's palette
49  default_color = QApplication::palette ().color
50  (static_cast<QPalette::ColorRole> (def.toInt ()));
51  // FIXME: use value<QPalette::ColorRole> instead of static cast after
52  // dropping support of Qt 5.4
53  }
54 
55  if ((mode == 1) && (default_color != settings_color_no_change))
56  {
57  // In second mode, determine the default color from the first mode
58  qreal h, s, l, a;
59  default_color.getHslF (&h, &s, &l, &a);
60  qreal l_new = 1.0-l*0.85;
61  if (l < 0.3)
62  l_new = 1.0-l*0.7; // convert darker into lighter colors
63  default_color.setHslF (h, s, l_new, a);
64  }
65 
66  return default_color;
67 }
68 
69 QColor gui_settings::color_value (const gui_pref& pref, int mode) const
70 {
71  QColor default_color = get_color_value (pref.def, mode);
72 
73  return value (pref.key + settings_color_modes_ext[mode],
74  QVariant (default_color)).value<QColor> ();
75 }
76 
78  const QColor& color, int mode)
79 {
80  int m = mode;
81  if (m > 1)
82  m = 1;
83 
84  setValue (pref.key + settings_color_modes_ext[m], QVariant (color));
85 }
86 
87 QString gui_settings::sc_value (const sc_pref& pref) const
88 {
89  QKeySequence key_seq = sc_def_value (pref);
90 
91  // Get the value from the settings where the key sequences are stored
92  // as strings
93  return value (sc_group + pref.key, key_seq.toString ()).toString ();
94 }
95 
96 QKeySequence gui_settings::sc_def_value (const sc_pref& pref) const
97 {
98  QKeySequence key_seq = QKeySequence ();
99 
100  // Check, which of the elements for the default value in the sc_pref
101  // structure has a valid value and take this as default. If both
102  // elements are not valid, leave the key sequence empty
103  if (pref.def)
104  key_seq = QKeySequence (pref.def);
105  else if (pref.def_std != QKeySequence::UnknownKey)
106  key_seq = QKeySequence (pref.def_std);
107 
108  return key_seq;
109 }
110 
OCTAVE_END_NAMESPACE(octave)
QKeySequence sc_def_value(const sc_pref &pref) const
Definition: gui-settings.cc:96
QColor color_value(const gui_pref &pref, int mode=0) const
Definition: gui-settings.cc:69
QColor get_color_value(const QVariant &def, int mode=0) const
Definition: gui-settings.cc:37
void set_color_value(const gui_pref &pref, const QColor &color, int mode=0)
Definition: gui-settings.cc:77
QVariant value(const gui_pref &pref) const
Definition: gui-settings.h:65
QString sc_value(const sc_pref &pref) const
Definition: gui-settings.cc:87
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
const QString sc_group("shortcuts/")
const QColor settings_color_no_change(255, 0, 255)
const QStringList settings_color_modes_ext(QStringList()<< ""<< "_2")
T octave_idx_type m
Definition: mx-inlines.cc:773
const QString key
const QVariant def
const QKeySequence::StandardKey def_std
const unsigned int def
const QString key