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