Mercurial > octave
annotate libgui/src/gui-settings.cc @ 31657:61834788d3aa
get list of fonts from QFontDatabase, not QFontComboBox
* gui-settings.cc (gui_settings::get_default_font_family):
Get list of available fonts from the thread-safe QFontDatabase class,
not QFontComboBox.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 09 Dec 2022 01:09:04 -0500 |
parents | deb553ac2c54 |
children | 1a1f47f17ed4 |
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 <QFontDatabase> |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
36 #include <QMessageBox> |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
37 #include <QSettings> |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
38 #include <QString> |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
39 #include <QStringList> |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
40 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
41 #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
|
42 #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
|
43 #include "gui-settings.h" |
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
45 #include "oct-env.h" |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
46 |
31646
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
47 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
|
48 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
49 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
|
50 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
51 return fileName (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
52 } |
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 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
|
55 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
56 QFileInfo sfile (fileName ()); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
57 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
58 return sfile.absolutePath (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
59 } |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
60 |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
61 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
|
62 { |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
63 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
|
64 |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
65 // 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
|
66 // 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
|
67 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
|
68 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
|
69 else |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
70 { |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
71 // 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
|
72 // 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
|
73 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
|
74 (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
|
75 // 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
|
76 // 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
|
77 } |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
78 |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
79 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
|
80 { |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
81 // 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 } |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
89 |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
90 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
|
91 } |
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 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
|
94 { |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
95 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
|
96 |
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
97 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
|
98 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
|
99 } |
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 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
|
102 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
|
103 { |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
104 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
|
105 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
|
106 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 |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
108 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
|
109 } |
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
110 |
27818
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
111 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
|
112 { |
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
113 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
|
114 |
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
115 // 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
|
116 // as strings |
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
117 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
|
118 } |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
119 |
27818
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
120 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
|
121 { |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
122 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
|
123 |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
124 // 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
|
125 // 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
|
126 // 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
|
127 if (pref.def) |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 |
27818
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
132 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
|
133 } |
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
134 |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
135 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
|
136 { |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
137 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
|
138 |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
139 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
|
140 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
|
141 else |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
142 { |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
143 // 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
|
144 // remove deprecated key. |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
145 |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
146 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
|
147 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
|
148 else |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
149 theme_index = ICON_THEME_OCTAVE; |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
150 |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
151 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
|
152 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
|
153 } |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
154 |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
155 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
|
156 |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
157 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
|
158 |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
159 // Set the required fallback search paths. |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
160 |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
161 switch (theme_index) |
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
162 { |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 break; |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
167 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
|
168 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
|
169 break; |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
170 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
|
171 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
|
172 break; |
31641
ab33554f97d2
fix another error introduced in changeset ad014fc78bd6
John W. Eaton <jwe@octave.org>
parents:
31638
diff
changeset
|
173 } |
29498
5384bb4efc51
rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29487
diff
changeset
|
174 |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
175 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
|
176 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
177 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
|
178 } |
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 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
|
181 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
|
182 { |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
183 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
|
184 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
|
185 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 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
|
190 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
191 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
|
192 = 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
|
193 |
31621
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
194 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
|
195 { |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 } |
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 //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
|
202 return QIcon (); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
203 } |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
204 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
205 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
|
206 { |
31657
61834788d3aa
get list of fonts from QFontDatabase, not QFontComboBox
John W. Eaton <jwe@octave.org>
parents:
31649
diff
changeset
|
207 // Get all available fixed width fonts from the Qt font database. |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
208 |
31657
61834788d3aa
get list of fonts from QFontDatabase, not QFontComboBox
John W. Eaton <jwe@octave.org>
parents:
31649
diff
changeset
|
209 QFontDatabase font_database; |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
210 QStringList fonts; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
211 |
31657
61834788d3aa
get list of fonts from QFontDatabase, not QFontComboBox
John W. Eaton <jwe@octave.org>
parents:
31649
diff
changeset
|
212 for (QString font : font_database.families ()) |
61834788d3aa
get list of fonts from QFontDatabase, not QFontComboBox
John W. Eaton <jwe@octave.org>
parents:
31649
diff
changeset
|
213 { |
61834788d3aa
get list of fonts from QFontDatabase, not QFontComboBox
John W. Eaton <jwe@octave.org>
parents:
31649
diff
changeset
|
214 if (font_database.isFixedPitch (font)) |
61834788d3aa
get list of fonts from QFontDatabase, not QFontComboBox
John W. Eaton <jwe@octave.org>
parents:
31649
diff
changeset
|
215 fonts << font; |
61834788d3aa
get list of fonts from QFontDatabase, not QFontComboBox
John W. Eaton <jwe@octave.org>
parents:
31649
diff
changeset
|
216 } |
61834788d3aa
get list of fonts from QFontDatabase, not QFontComboBox
John W. Eaton <jwe@octave.org>
parents:
31649
diff
changeset
|
217 |
61834788d3aa
get list of fonts from QFontDatabase, not QFontComboBox
John W. Eaton <jwe@octave.org>
parents:
31649
diff
changeset
|
218 QString default_family; |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
219 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
220 #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
|
221 // 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
|
222 // 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
|
223 // 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
|
224 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
|
225 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
|
226 #endif |
29484
bed2fd5b8263
allow a second color theme for the console window (dark mode)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29358
diff
changeset
|
227 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
228 // 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
|
229 // 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
|
230 if (default_family.isEmpty ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
231 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
232 // 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
|
233 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
|
234 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
|
235 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
236 // 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
|
237 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
|
238 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
239 // 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
|
240 // 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
|
241 default_family = fonts[0]; |
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 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
244 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
245 // 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
|
246 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
|
247 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
|
248 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
|
249 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
250 return default_family; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
251 } |
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 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
|
254 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
255 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
|
256 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
257 // 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
|
258 // 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
|
259 // 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
|
260 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
|
261 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
262 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
|
263 if (font_size == -1) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
264 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
|
265 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
266 // 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
|
267 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
|
268 if (font_size > 0) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
269 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
|
270 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
271 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
|
272 = 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
|
273 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
274 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
|
275 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
|
276 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
277 QStringList result; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
278 result << default_family; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
279 result << default_font_size; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
280 return result; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
281 } |
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 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
|
284 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
285 // 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
|
286 // 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
|
287 QString custom_editor; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
288 QStringList def_font; |
27818
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
289 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
290 // 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
|
291 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
|
292 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
293 // 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
|
294 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
|
295 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
296 // 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
|
297 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
|
298 = 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
|
299 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
300 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
|
301 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
|
302 } |
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 check (); |
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 // 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
|
307 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
308 // Custom editor |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
309 if (! custom_editor.isEmpty ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
310 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
|
311 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
312 // 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
|
313 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
|
314 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
315 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
|
316 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
|
317 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
318 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
319 // 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
|
320 // 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
|
321 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
|
322 } |
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 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
|
325 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
326 if (status () == QSettings::NoError) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
327 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
328 // 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
|
329 setValue ("dummy", 0); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
330 sync (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
331 } |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
332 |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
333 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
|
334 && isWritable () |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
335 && status () == QSettings::NoError)) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
336 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
337 QString msg |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
338 = 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
|
339 "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
|
340 "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
|
341 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
342 QMessageBox::critical (nullptr, |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
343 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
|
344 msg.arg (status ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
345 .arg (file_name ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
346 .arg (directory_name ())); |
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 exit (1); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
349 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
350 else |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
351 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
|
352 } |
27724
19e80f22aa47
provide structure and settings value method for shortcut key sequences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27611
diff
changeset
|
353 |
31648
29d734430e5f
maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents:
31646
diff
changeset
|
354 OCTAVE_END_NAMESPACE(octave) |