# HG changeset patch
# User Torsten <mttl@mailbox.org>
# Date 1544303939 -3600
#      Sat Dec 08 22:18:59 2018 +0100
# Node ID 104d600a69fc5a8969459049670b7fb42a8a7021
# Parent  a7be718a9dd358dc945cd29aa72f7c4e22b7ffff
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

diff -r a7be718a9dd3 -r 104d600a69fc libgui/src/gui-preferences.h
--- a/libgui/src/gui-preferences.h	Wed Dec 05 21:15:40 2018 +0100
+++ b/libgui/src/gui-preferences.h	Sat Dec 08 22:18:59 2018 +0100
@@ -63,6 +63,9 @@ const QStyle::PixelMetric global_icon_si
 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 ());
diff -r a7be718a9dd3 -r 104d600a69fc libgui/src/main-window.cc
--- a/libgui/src/main-window.cc	Wed Dec 05 21:15:40 2018 +0100
+++ b/libgui/src/main-window.cc	Sat Dec 08 22:18:59 2018 +0100
@@ -27,6 +27,7 @@ along with Octave; see the file COPYING.
 
 #include <QKeySequence>
 #include <QApplication>
+#include <QStyleFactory>
 #include <QInputDialog>
 #include <QLabel>
 #include <QMenuBar>
@@ -160,7 +161,8 @@ namespace octave
   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 @@ namespace octave
     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 @@ namespace octave
   {
     // 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 @@ namespace octave
 
     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);
 
diff -r a7be718a9dd3 -r 104d600a69fc libgui/src/main-window.h
--- a/libgui/src/main-window.h	Wed Dec 05 21:15:40 2018 +0100
+++ b/libgui/src/main-window.h	Sat Dec 08 22:18:59 2018 +0100
@@ -332,6 +332,8 @@ namespace octave
 
     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 @@ namespace octave
 
     QString m_default_encoding;
 
+    QString m_default_style;
+
     //! Toolbar.
 
     QStatusBar *m_status_bar;
@@ -506,6 +510,8 @@ namespace octave
 
     int exec (void);
 
+    QApplication *qt_app (void) { return m_qt_app; };
+
   public slots:
 
     void handle_octave_finished (int);
diff -r a7be718a9dd3 -r 104d600a69fc libgui/src/settings-dialog.cc
--- a/libgui/src/settings-dialog.cc	Wed Dec 05 21:15:40 2018 +0100
+++ b/libgui/src/settings-dialog.cc	Sat Dec 08 22:18:59 2018 +0100
@@ -43,6 +43,7 @@ along with Octave; see the file COPYING.
 #include <QHash>
 #include <QMessageBox>
 #include <QScrollBar>
+#include <QStyleFactory>
 #include <QTextCodec>
 
 #if defined (HAVE_QSCINTILLA)
@@ -124,6 +125,20 @@ namespace octave
     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 @@ namespace octave
       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 ());
diff -r a7be718a9dd3 -r 104d600a69fc libgui/src/settings-dialog.ui
--- a/libgui/src/settings-dialog.ui	Wed Dec 05 21:15:40 2018 +0100
+++ b/libgui/src/settings-dialog.ui	Sat Dec 08 22:18:59 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>
