Mercurial > octave
changeset 26227:2355f66cf91d
allow to select the gui style in the preferences dialog
* gui-preferences.h: add new constants for key and default of new preference
* main-window.cc (main_window): initialize new class variable for the qt app,
get name of default style;
(notice_settings): get desired style from preferences or take the default
one if the desired one is not found;
(octave_qt_app::octave_qt_app): do not set windows style by default
* main-window.h: new class variables in main_window for qt app and the name
of the default style, new public method for getting the qt app in
octave_qt_app
* settings-dialog.cc (settings_dialog): fill new combo box for style selection
with available styles and select the one from the settings file or the
default one;
(write_changed_settings): store the style name from the new combo box
* settings-dialog.ui: add new combo box for selecting the gui style
author | Torsten <mttl@mailbox.org> |
---|---|
date | Thu, 13 Dec 2018 21:53:32 +0100 |
parents | 3a90eff58fb5 |
children | 4f044bc43f07 |
files | libgui/src/gui-preferences.h libgui/src/main-window.cc libgui/src/main-window.h libgui/src/settings-dialog.cc libgui/src/settings-dialog.ui |
diffstat | 5 files changed, 207 insertions(+), 139 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/gui-preferences.h Thu Dec 13 21:53:15 2018 +0100 +++ b/libgui/src/gui-preferences.h Thu Dec 13 21:53:32 2018 +0100 @@ -63,6 +63,9 @@ const gui_pref global_icon_size ("toolbar_icon_size", QVariant (0)); const gui_pref global_icon_theme ("use_system_icon_theme", QVariant (true)); +// Style +const gui_pref global_style ("style", QVariant ("default")); + // Console preferences const gui_pref cs_font ("terminal/fontName", QVariant ());
--- a/libgui/src/main-window.cc Thu Dec 13 21:53:15 2018 +0100 +++ b/libgui/src/main-window.cc Thu Dec 13 21:53:32 2018 +0100 @@ -27,6 +27,7 @@ #include <QKeySequence> #include <QApplication> +#include <QStyleFactory> #include <QInputDialog> #include <QLabel> #include <QMenuBar> @@ -160,7 +161,8 @@ main_window::main_window (octave_qt_app& oct_qt_app, octave_qt_link *oct_qt_lnk) : QMainWindow (), - m_octave_qt_link (oct_qt_lnk), m_workspace_model (nullptr), + m_qt_app (oct_qt_app.qt_app ()), m_octave_qt_link (oct_qt_lnk), + m_workspace_model (nullptr), m_status_bar (nullptr), m_command_window (nullptr), m_history_window (nullptr), m_file_browser_window (nullptr), m_doc_browser_window (nullptr), m_editor_window (nullptr), @@ -226,6 +228,8 @@ QGuiApplication::setDesktopFileName ("org.octave.Octave.desktop"); #endif + m_default_style = m_qt_app->style ()->objectName (); + QSettings *settings = resource_manager::get_settings (); bool connect_to_web = true; @@ -715,6 +719,18 @@ { // QSettings pointer is checked before emitting. + // Get desired style from preferences or take the default one if + // the desired one is not found + QString preferred_style + = settings->value (global_style.key, global_style.def).toString (); + + if (preferred_style == global_style.def.toString ()) + preferred_style = m_default_style; + + QStyle *new_style = QStyleFactory::create (preferred_style); + if (new_style) + m_qt_app->setStyle (new_style); + // the widget's icons (when floating) QString icon_set = settings->value ("DockWidgets/widget_icon_set", "NONE").toString (); @@ -2782,11 +2798,6 @@ m_qt_app = new QApplication (m_argc, m_argv); - // set windows style for windows -#if defined (Q_OS_WIN32) - m_qt_app->setStyle (QStyleFactory::create ("Windows")); -#endif - // Force left-to-right alignment (see bug #46204) m_qt_app->setLayoutDirection (Qt::LeftToRight);
--- a/libgui/src/main-window.h Thu Dec 13 21:53:15 2018 +0100 +++ b/libgui/src/main-window.h Thu Dec 13 21:53:32 2018 +0100 @@ -332,6 +332,8 @@ QList<octave_dock_widget *> dock_widget_list (void); + QApplication *m_qt_app; + octave_qt_link *m_octave_qt_link; workspace_model *m_workspace_model; @@ -340,6 +342,8 @@ QString m_default_encoding; + QString m_default_style; + //! Toolbar. QStatusBar *m_status_bar; @@ -506,6 +510,8 @@ int exec (void); + QApplication *qt_app (void) { return m_qt_app; }; + public slots: void handle_octave_finished (int);
--- a/libgui/src/settings-dialog.cc Thu Dec 13 21:53:15 2018 +0100 +++ b/libgui/src/settings-dialog.cc Thu Dec 13 21:53:32 2018 +0100 @@ -43,6 +43,7 @@ #include <QHash> #include <QMessageBox> #include <QScrollBar> +#include <QStyleFactory> #include <QTextCodec> #if defined (HAVE_QSCINTILLA) @@ -124,6 +125,20 @@ else comboBox_language->setCurrentIndex (0); // System is default + // Global style + QStringList styles = QStyleFactory::keys(); + combo_styles->addItems (styles); + combo_styles->insertItem (0, global_style.def.toString ()); + combo_styles->insertSeparator (1); + QString current_style = settings->value (global_style.key, global_style.def).toString (); + if (current_style == global_style.def.toString ()) + current_style = global_style.def.toString (); + selected = combo_styles->findText (current_style); + if (selected >= 0) + combo_styles->setCurrentIndex (selected); + else + combo_styles->setCurrentIndex (0); + // icon size and theme QButtonGroup *icon_size_group = new QButtonGroup (this); icon_size_group->addButton (icon_size_small); @@ -807,6 +822,12 @@ language = "SYSTEM"; settings->setValue ("language", language); + // style + QString selected_style = combo_styles->currentText (); + if (selected_style == global_style.def.toString ()) + selected_style = global_style.def.toString (); + settings->setValue (global_style.key, selected_style); + // dock widget title bar settings->setValue ("DockWidgets/widget_title_custom_style", cb_widget_custom_style->isChecked ()); settings->setValue ("DockWidgets/widget_title_3d", sb_3d_title->value ());
--- a/libgui/src/settings-dialog.ui Thu Dec 13 21:53:15 2018 +0100 +++ b/libgui/src/settings-dialog.ui Thu Dec 13 21:53:32 2018 +0100 @@ -96,21 +96,157 @@ </item> </layout> </item> - <item row="10" column="0"> - <widget class="QCheckBox" name="cb_prompt_to_exit"> + <item row="7" column="0"> + <widget class="QLabel" name="label_15"> <property name="text"> - <string>Confirm before exiting</string> + <string>Dock widget title bar</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + </property> + </widget> + </item> + <item row="8" column="0"> + <widget class="QCheckBox" name="cb_use_native_file_dialogs"> + <property name="text"> + <string>Use native file dialogs</string> + </property> + <property name="checked"> + <bool>true</bool> </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_2"> + <item row="3" column="1"> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_6"> + <item> + <widget class="QRadioButton" name="icon_size_small"> + <property name="text"> + <string>Small</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="icon_size_normal"> + <property name="text"> + <string>Normal</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="icon_size_large"> + <property name="text"> + <string>Large</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_4"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QCheckBox" name="cb_system_icon_theme"> + <property name="text"> + <string>Use system icon theme if available (requires restart)</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="9" column="0"> + <widget class="QCheckBox" name="cb_cursor_blinking"> <property name="text"> - <string>Language</string> + <string>Cursor blinking</string> + </property> + <property name="checked"> + <bool>true</bool> </property> </widget> </item> - <item row="6" column="1"> + <item row="10" column="0"> + <widget class="QCheckBox" name="cb_status_bar"> + <property name="text"> + <string>Show status bar</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="5" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_9"> + <item> + <widget class="QRadioButton" name="general_icon_octave"> + <property name="text"> + <string>Octave logo only</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="general_icon_letter"> + <property name="text"> + <string>Letter icons</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="general_icon_graphic"> + <property name="text"> + <string>Graphic icons</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_6"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_8"> + <property name="text"> + <string>Toolbar Icons</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + </property> + </widget> + </item> + <item row="5" column="0"> + <widget class="QLabel" name="label_9"> + <property name="text"> + <string>Icon set for dock widgets</string> + </property> + </widget> + </item> + <item row="7" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_4"> <item> <layout class="QGridLayout" name="gridLayout_13"> @@ -272,44 +408,27 @@ </item> </layout> </item> - <item row="6" column="0"> - <widget class="QLabel" name="label_15"> + <item row="11" column="0"> + <widget class="QCheckBox" name="cb_prompt_to_exit"> <property name="text"> - <string>Dock widget title bar</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + <string>Confirm before exiting</string> </property> </widget> </item> - <item row="4" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout_9"> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Language</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_17"> <item> - <widget class="QRadioButton" name="general_icon_octave"> - <property name="text"> - <string>Octave logo only</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> + <widget class="QComboBox" name="combo_styles"/> </item> <item> - <widget class="QRadioButton" name="general_icon_letter"> - <property name="text"> - <string>Letter icons</string> - </property> - </widget> - </item> - <item> - <widget class="QRadioButton" name="general_icon_graphic"> - <property name="text"> - <string>Graphic icons</string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_6"> + <spacer name="horizontalSpacer"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> @@ -323,105 +442,13 @@ </item> </layout> </item> - <item row="4" column="0"> - <widget class="QLabel" name="label_9"> - <property name="text"> - <string>Icon set for dock widgets</string> - </property> - </widget> - </item> - <item row="9" column="0"> - <widget class="QCheckBox" name="cb_status_bar"> - <property name="text"> - <string>Show status bar</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="8" column="0"> - <widget class="QCheckBox" name="cb_cursor_blinking"> + <item row="2" column="0"> + <widget class="QLabel" name="label_29"> <property name="text"> - <string>Cursor blinking</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="7" column="0"> - <widget class="QCheckBox" name="cb_use_native_file_dialogs"> - <property name="text"> - <string>Use native file dialogs</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_8"> - <property name="text"> - <string>Toolbar Icons</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + <string>Style</string> </property> </widget> </item> - <item row="2" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_5"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_6"> - <item> - <widget class="QRadioButton" name="icon_size_small"> - <property name="text"> - <string>Small</string> - </property> - </widget> - </item> - <item> - <widget class="QRadioButton" name="icon_size_normal"> - <property name="text"> - <string>Normal</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <widget class="QRadioButton" name="icon_size_large"> - <property name="text"> - <string>Large</string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_4"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <widget class="QCheckBox" name="cb_system_icon_theme"> - <property name="text"> - <string>Use system icon theme if available (requires restart)</string> - </property> - </widget> - </item> - </layout> - </item> </layout> </item> </layout>