Mercurial > octave
annotate libgui/src/gui-settings.cc @ 31649:deb553ac2c54
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Dec 2022 15:45:27 -0500 |
parents | 431f80aba37a 29d734430e5f |
children | 61834788d3aa |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29498
diff
changeset
|
3 // Copyright (C) 2019-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
27611
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 # include "config.h" |
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #endif |
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
30 #include <cmath> |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
31 |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
32 #include <QApplication> |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
33 #include <QFile> |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
34 #include <QFileInfo> |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
35 #include <QFontComboBox> |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
36 #include <QFontDatabase> |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
37 #include <QMessageBox> |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
38 #include <QSettings> |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
39 #include <QString> |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
40 #include <QStringList> |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
41 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
42 #include "gui-preferences-cs.h" |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
43 #include "gui-preferences-global.h" |
27611
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 #include "gui-settings.h" |
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
46 #include "oct-env.h" |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
47 |
31646
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
48 OCTAVE_BEGIN_NAMESPACE(octave) |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
49 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
50 QString gui_settings::file_name (void) const |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
51 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
52 return fileName (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
53 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
54 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
55 QString gui_settings::directory_name (void) const |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
56 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
57 QFileInfo sfile (fileName ()); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
58 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
59 return sfile.absolutePath (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
60 } |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
61 |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
62 QColor gui_settings::get_color_value (const QVariant& def, int mode) const |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
63 { |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
64 QColor default_color; |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
65 |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
66 // Determine whether the default value in pref is given as |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
67 // QPalette::ColorRole or as QColor |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
68 if (def.canConvert (QMetaType::QColor)) |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
69 default_color = def.value<QColor> (); |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
70 else |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
71 { |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
72 // The default colors are given as color roles for |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
73 // the application's palette |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
74 default_color = QApplication::palette ().color |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
75 (static_cast<QPalette::ColorRole> (def.toInt ())); |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
76 // FIXME: use value<QPalette::ColorRole> instead of static cast after |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
77 // dropping support of Qt 5.4 |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
78 } |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
79 |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
80 if ((mode == 1) && (default_color != settings_color_no_change)) |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
81 { |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
82 // In second mode, determine the default color from the first mode |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
83 qreal h, s, l, a; |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
84 default_color.getHslF (&h, &s, &l, &a); |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
85 qreal l_new = 1.0-l*0.85; |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
86 if (l < 0.3) |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
87 l_new = 1.0-l*0.7; // convert darker into lighter colors |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
88 default_color.setHslF (h, s, l_new, a); |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
89 } |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
90 |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
91 return default_color; |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
92 } |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
93 |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
94 QColor gui_settings::color_value (const gui_pref& pref, int mode) const |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
95 { |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
96 QColor default_color = get_color_value (pref.def, mode); |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
97 |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
98 return value (pref.key + settings_color_modes_ext[mode], |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
99 QVariant (default_color)).value<QColor> (); |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
100 } |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
101 |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
102 void gui_settings::set_color_value (const gui_pref& pref, |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
103 const QColor& color, int mode) |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
104 { |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
105 int m = mode; |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
106 if (m > 1) |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
107 m = 1; |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
108 |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
109 setValue (pref.key + settings_color_modes_ext[m], QVariant (color)); |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
110 } |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
111 |
27818
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
112 QString gui_settings::sc_value (const sc_pref& pref) const |
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
113 { |
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
114 QKeySequence key_seq = sc_def_value (pref); |
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
115 |
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
116 // Get the value from the settings where the key sequences are stored |
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
117 // as strings |
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
118 return value (sc_group + pref.key, key_seq.toString ()).toString (); |
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
119 } |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
120 |
27818
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
121 QKeySequence gui_settings::sc_def_value (const sc_pref& pref) const |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
122 { |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
123 QKeySequence key_seq = QKeySequence (); |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
124 |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
125 // Check, which of the elements for the default value in the sc_pref |
27929
265b386f8b20
maint: Use two spaces between sentences in code comments.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
126 // structure has a valid value and take this as default. If both |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
127 // elements are not valid, leave the key sequence empty |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
128 if (pref.def) |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
129 key_seq = QKeySequence (pref.def); |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
130 else if (pref.def_std != QKeySequence::UnknownKey) |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
131 key_seq = QKeySequence (pref.def_std); |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
132 |
27818
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
133 return key_seq; |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
134 } |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
135 |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
136 void gui_settings::config_icon_theme (void) |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
137 { |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
138 int theme_index; |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
139 |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
140 if (contains (global_icon_theme_index.key)) |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
141 theme_index = value (global_icon_theme_index).toInt (); |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
142 else |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
143 { |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
144 // New pref does not exist. Use old if required. Add new and |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
145 // remove deprecated key. |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
146 |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
147 if (value (global_icon_theme).toBool ()) |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
148 theme_index = ICON_THEME_SYSTEM; |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
149 else |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
150 theme_index = ICON_THEME_OCTAVE; |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
151 |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
152 setValue (global_icon_theme_index.key, theme_index); |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
153 remove (global_icon_theme.key); |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
154 } |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
155 |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
156 QIcon::setThemeName (global_all_icon_themes.at (theme_index)); |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
157 |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
158 QStringList icon_fallbacks; |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
159 |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
160 // Set the required fallback search paths. |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
161 |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
162 switch (theme_index) |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
163 { |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
164 case ICON_THEME_SYSTEM: |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
165 icon_fallbacks << global_icon_paths.at (ICON_THEME_OCTAVE); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
166 icon_fallbacks << global_icon_paths.at (ICON_THEME_TANGO); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
167 break; |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
168 case ICON_THEME_TANGO: |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
169 icon_fallbacks << global_icon_paths.at (ICON_THEME_OCTAVE); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
170 break; |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
171 case ICON_THEME_OCTAVE: |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
172 icon_fallbacks << global_icon_paths.at (ICON_THEME_TANGO); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
173 break; |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
174 } |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
175 |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
176 icon_fallbacks << global_icon_paths.at (ICON_THEME_CURSORS); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
177 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
178 setValue (global_icon_fallbacks.key, icon_fallbacks); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
179 } |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
180 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
181 QIcon gui_settings::icon (const QString& icon_name, bool octave_only, |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
182 const QString& icon_alt_name) |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
183 { |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
184 if (octave_only) |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
185 return QIcon (global_icon_paths.at (ICON_THEME_OCTAVE) + icon_name + ".png"); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
186 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
187 if (QIcon::hasThemeIcon (icon_name)) |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
188 return QIcon (QIcon::fromTheme (icon_name)); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
189 else if ((! icon_alt_name.isEmpty ()) && QIcon::hasThemeIcon (icon_alt_name)) |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
190 return QIcon (QIcon::fromTheme (icon_alt_name)); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
191 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
192 QStringList icon_fallbacks |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
193 = value (global_icon_fallbacks.key).toStringList (); |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
194 |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
195 for (int i = 0; i < icon_fallbacks.length (); i++ ) |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
196 { |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
197 QString icon_file (icon_fallbacks.at (i) + icon_name + ".png"); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
198 if (QFile (icon_file).exists ()) |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
199 return QIcon (icon_file); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
200 } |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
201 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
202 //QIcon::setThemeName (current_theme); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
203 return QIcon (); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
204 } |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
205 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
206 QString gui_settings::get_default_font_family (void) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
207 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
208 QString default_family; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
209 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
210 // Get all available fixed width fonts via a font combobox |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
211 QFontComboBox font_combo_box; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
212 font_combo_box.setFontFilters (QFontComboBox::MonospacedFonts); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
213 QStringList fonts; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
214 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
215 for (int index = 0; index < font_combo_box.count(); index++) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
216 fonts << font_combo_box.itemText(index); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
217 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
218 #if defined (Q_OS_MAC) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
219 // Use hard coded default on macOS, since selection of fixed width |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
220 // default font is unreliable (see bug #59128). |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
221 // Test for macOS default fixed width font |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
222 if (fonts.contains (global_mono_font.def.toString ())) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
223 default_family = global_mono_font.def.toString (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
224 #endif |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
225 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
226 // If default font is still empty (on all other platforms or |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
227 // if macOS default font is not available): use QFontDatabase |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
228 if (default_family.isEmpty ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
229 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
230 // Get the system's default monospaced font |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
231 QFont fixed_font = QFontDatabase::systemFont (QFontDatabase::FixedFont); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
232 default_family = fixed_font.defaultFamily (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
233 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
234 // Since this might be unreliable, test all available fixed width fonts |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
235 if (! fonts.contains (default_family)) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
236 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
237 // Font returned by QFontDatabase is not in fixed fonts list. |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
238 // Fallback: take first from this list |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
239 default_family = fonts[0]; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
240 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
241 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
242 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
243 // Test env variable which has preference |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
244 std::string env_default_family = sys::env::getenv ("OCTAVE_DEFAULT_FONT"); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
245 if (! env_default_family.empty ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
246 default_family = QString::fromStdString (env_default_family); |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
247 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
248 return default_family; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
249 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
250 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
251 QStringList gui_settings::get_default_font (void) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
252 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
253 QString default_family = get_default_font_family (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
254 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
255 // determine the fefault font size of the system |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
256 // FIXME: QApplication::font () does not return the monospace font, |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
257 // but the size should be probably near to the monospace font |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
258 QFont font = QApplication::font (); |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
259 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
260 int font_size = font.pointSize (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
261 if (font_size == -1) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
262 font_size = static_cast <int> (std::floor(font.pointSizeF ())); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
263 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
264 // check for valid font size, otherwise take default 10 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
265 QString default_font_size = "10"; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
266 if (font_size > 0) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
267 default_font_size = QString::number (font_size); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
268 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
269 std::string env_default_font_size |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
270 = sys::env::getenv ("OCTAVE_DEFAULT_FONT_SIZE"); |
27818
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
271 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
272 if (! env_default_font_size.empty ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
273 default_font_size = QString::fromStdString (env_default_font_size); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
274 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
275 QStringList result; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
276 result << default_family; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
277 result << default_font_size; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
278 return result; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
279 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
280 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
281 void gui_settings::reload (void) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
282 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
283 // Declare some empty options, which may be set at first startup for |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
284 // writing them into the newly created settings file |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
285 QString custom_editor; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
286 QStringList def_font; |
27818
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
287 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
288 // Check whether the settings file does not yet exist |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
289 if (! QFile::exists (file_name ())) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
290 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
291 // Get the default font (for terminal) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
292 def_font = get_default_font (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
293 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
294 // Get a custom editor defined as env variable |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
295 std::string env_default_editor |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
296 = sys::env::getenv ("OCTAVE_DEFAULT_EDITOR"); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
297 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
298 if (! env_default_editor.empty ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
299 custom_editor = QString::fromStdString (env_default_editor); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
300 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
301 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
302 check (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
303 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
304 // Write some settings that were dynamically determined at first startup |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
305 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
306 // Custom editor |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
307 if (! custom_editor.isEmpty ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
308 setValue (global_custom_editor.key, custom_editor); |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
309 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
310 // Default monospace font for the terminal |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
311 if (def_font.count () > 1) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
312 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
313 setValue (cs_font.key, def_font[0]); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
314 setValue (cs_font_size.key, def_font[1].toInt ()); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
315 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
316 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
317 // Write the default monospace font into the settings for later use by |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
318 // console and editor as fallbacks of their font preferences. |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
319 setValue (global_mono_font.key, get_default_font_family ()); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
320 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
321 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
322 void gui_settings::check (void) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
323 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
324 if (status () == QSettings::NoError) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
325 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
326 // Test usability (force file to be really created) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
327 setValue ("dummy", 0); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
328 sync (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
329 } |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
330 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
331 if (! (QFile::exists (file_name ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
332 && isWritable () |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
333 && status () == QSettings::NoError)) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
334 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
335 QString msg |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
336 = QString (QT_TR_NOOP ("Error %1 creating the settings file\n%2\n" |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
337 "Make sure you have read and write permissions to\n%3\n\n" |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
338 "Octave GUI must be closed now.")); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
339 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
340 QMessageBox::critical (nullptr, |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
341 QString (QT_TR_NOOP ("Octave Critical Error")), |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
342 msg.arg (status ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
343 .arg (file_name ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
344 .arg (directory_name ())); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
345 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
346 exit (1); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
347 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
348 else |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
349 remove ("dummy"); // Remove test entry |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
350 } |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
351 |
31648
29d734430e5f
maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents:
31646
diff
changeset
|
352 OCTAVE_END_NAMESPACE(octave) |