Mercurial > octave
annotate libgui/src/gui-settings.cc @ 31638:474e184321d3
move some functions from resource_manager to gui_settings
* gui-settings.h, gui-settings.cc (gui_settings::get_default_font_family,
gui_settings::get_default_font, gui_settings::reload,
gui_settings::check): Rename and move here from resource-manager.h and
resource-manager.cc. Change all uses.
* resource-manager.h, resource-manager.cc
(resource_manager::is_first_run): Delete.
* gui-preferences-global.h (global_skip_welcome_wizard):
New gui_pref object.
* main-window.cc (main_window::main_window): Check this setting to
determine whether to display welcome wizard.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 04 Dec 2022 22:56:23 -0500 |
parents | 0645ea65ca6b |
children | ab33554f97d2 |
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 |
27611
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 namespace octave |
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
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 } |
fa0582694fda
replace literal strings by symbolic constants for shortcut preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27724
diff
changeset
|
120 |
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 { |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
138 int theme = global_icon_theme_index.def.toInt (); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
139 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
140 // check for new and old setting and use old if required |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
141 if (! contains (global_icon_theme_index.key)) |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
142 { |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
143 // new pref does not exist |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
144 if (value (global_icon_theme).toBool ()) |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
145 theme = 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
|
146 else |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
147 theme = 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
|
148 setValue (global_icon_theme_index.key, theme); // add new |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
149 remove (global_icon_theme.key); // remove deprecated key |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
150 } |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
151 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
152 QIcon::setThemeName (global_all_icon_themes.at (theme)); |
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 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
|
155 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
156 // set the required fallback search paths |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
157 switch (theme) |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
158 { |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 break; |
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_TANGO: |
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 break; |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
166 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
|
167 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
|
168 break; |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
169 } |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
170 |
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_CURSORS); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
172 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
173 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
|
174 } |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
175 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
176 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
|
177 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
|
178 { |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
179 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
|
180 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
|
181 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 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
|
186 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
187 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
|
188 = value (global_icon_fallbacks.key).toStringList (); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
189 |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
190 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
|
191 { |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 } |
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 //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
|
198 return QIcon (); |
0645ea65ca6b
handle icons and themes in gui_settings class, not resource_manager
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
199 } |
31638
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
200 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
201 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
|
202 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
203 QString default_family; |
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 // 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
|
206 QFontComboBox font_combo_box; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
207 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
|
208 QStringList fonts; |
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 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
|
211 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
|
212 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
213 #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
|
214 // 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
|
215 // 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
|
216 // 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
|
217 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
|
218 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
|
219 #endif |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
220 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
221 // 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
|
222 // 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
|
223 if (default_family.isEmpty ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
224 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
225 // 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
|
226 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
|
227 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
|
228 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
229 // 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
|
230 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
|
231 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
232 // 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
|
233 // 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
|
234 default_family = fonts[0]; |
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 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
237 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
238 // 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
|
239 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
|
240 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
|
241 default_family = QString::fromStdString (env_default_family); |
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 return default_family; |
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 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
246 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
|
247 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
248 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
|
249 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
250 // 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
|
251 // 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
|
252 // 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
|
253 QFont font = QApplication::font (); |
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 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
|
256 if (font_size == -1) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
257 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
|
258 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
259 // 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
|
260 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
|
261 if (font_size > 0) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
262 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
|
263 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
264 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
|
265 = sys::env::getenv ("OCTAVE_DEFAULT_FONT_SIZE"); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
266 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
267 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
|
268 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
|
269 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
270 QStringList result; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
271 result << default_family; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
272 result << default_font_size; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
273 return result; |
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 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
276 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
|
277 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
278 // 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
|
279 // 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
|
280 QString custom_editor; |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
281 QStringList def_font; |
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 // 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
|
284 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
|
285 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
286 // 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
|
287 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
|
288 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
289 // 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
|
290 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
|
291 = 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
|
292 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
293 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
|
294 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
|
295 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
296 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
297 check (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
298 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
299 // 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
|
300 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
301 // Custom editor |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
302 if (! custom_editor.isEmpty ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
303 setValue (global_custom_editor.key, custom_editor); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
304 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
305 // 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
|
306 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
|
307 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
308 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
|
309 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
|
310 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
311 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
312 // 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
|
313 // 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
|
314 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
|
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 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
|
318 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
319 if (status () == QSettings::NoError) |
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 // 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
|
322 setValue ("dummy", 0); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
323 sync (); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
324 } |
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 (! (QFile::exists (file_name ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
327 && isWritable () |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
328 && status () == QSettings::NoError)) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
329 { |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
330 QString msg |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
331 = 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
|
332 "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
|
333 "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
|
334 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
335 QMessageBox::critical (nullptr, |
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 ("Octave Critical Error")), |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
337 msg.arg (status ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
338 .arg (file_name ()) |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
339 .arg (directory_name ())); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
340 |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
341 exit (1); |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
342 } |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
343 else |
474e184321d3
move some functions from resource_manager to gui_settings
John W. Eaton <jwe@octave.org>
parents:
31621
diff
changeset
|
344 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
|
345 } |
27611
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
346 } |