Mercurial > hg > octave-nkf
changeset 18179:b3838cedfe04 gui-release
redesign of dock widgets title bar with configurable colors
* octave-dock-widget.cc (constructor): connect settings_changed signal to new
slot handle_settings;
(handle_settings): common settings for all dock widgets: style sheet, this
functions calls notice_settings for individual settings;
(make_window,make_widget): change dock-/undock-icon
* octave-dock-widget.h: new slot handle_settings
* settings-dialog.cc (constructor): check box and color pickers for title bar;
(write_changed_settings): store colors to settings file
* settings-dialog.h: new color-pickers as class variables
* settings-dialog.ui: check box and color pickers for title bar colors
author | Torsten <ttl@justmail.de> |
---|---|
date | Tue, 31 Dec 2013 13:31:45 +0100 |
parents | 256e280850f1 |
children | 7eeaecac9b5b |
files | libgui/src/octave-dock-widget.cc libgui/src/octave-dock-widget.h libgui/src/settings-dialog.cc libgui/src/settings-dialog.h libgui/src/settings-dialog.ui |
diffstat | 5 files changed, 264 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/octave-dock-widget.cc +++ b/libgui/src/octave-dock-widget.cc @@ -27,7 +27,6 @@ #include <QApplication> #include <QToolBar> -#include <QToolButton> #include <QAction> #include <QHBoxLayout> #include <QLabel> @@ -48,7 +47,7 @@ this, SLOT (handle_visibility_changed (bool))); connect (p, SIGNAL (settings_changed (const QSettings*)), - this, SLOT (notice_settings (const QSettings*))); + this, SLOT (handle_settings (const QSettings*))); #if defined (Q_OS_WIN32) // windows: add an extra title bar that persists when floating @@ -61,31 +60,31 @@ _dock_action-> setToolTip (tr ("Undock widget")); connect (_dock_action, SIGNAL (triggered (bool)), this, SLOT (change_floating (bool))); - QToolButton *dock_button = new QToolButton (this); - dock_button->setDefaultAction (_dock_action); - dock_button->setFocusPolicy (Qt::NoFocus); - dock_button->setIconSize (QSize (12,12)); + _dock_button = new QToolButton (this); + _dock_button->setDefaultAction (_dock_action); + _dock_button->setFocusPolicy (Qt::NoFocus); + _dock_button->setIconSize (QSize (12,12)); QAction *close_action = new QAction (QIcon (":/actions/icons/widget-close.png"), "", this ); close_action-> setToolTip (tr ("Hide widget")); connect (close_action, SIGNAL (triggered (bool)), this, SLOT (change_visibility (bool))); - QToolButton *close_button = new QToolButton (this); - close_button->setDefaultAction (close_action); - close_button->setFocusPolicy (Qt::NoFocus); - close_button->setIconSize (QSize (12,12)); + _close_button = new QToolButton (this); + _close_button->setDefaultAction (close_action); + _close_button->setFocusPolicy (Qt::NoFocus); + _close_button->setIconSize (QSize (12,12)); QHBoxLayout *h_layout = new QHBoxLayout (); h_layout->addStretch (100); - h_layout->addWidget (dock_button); - h_layout->addWidget (close_button); + h_layout->addWidget (_dock_button); + h_layout->addWidget (_close_button); h_layout->setSpacing (0); - h_layout->setContentsMargins (6,0,0,0); + h_layout->setContentsMargins (5,2,2,2); - QWidget *title_widget = new QWidget (); - title_widget->setLayout (h_layout); - setTitleBarWidget (title_widget); + _title_widget = new QWidget (); + _title_widget->setLayout (h_layout); + setTitleBarWidget (_title_widget); #else @@ -183,6 +182,10 @@ // non windows: Just set the appripriate window flag setWindowFlags (Qt::Window); + QString css = styleSheet (); + css.replace ("widget-undock.png","widget-dock.png"); + setStyleSheet (css); + #endif _floating = true; @@ -228,6 +231,10 @@ // non windows: just say we are a docked widget again setWindowFlags (Qt::Widget); + QString css = styleSheet (); + css.replace ("widget-dock.png","widget-undock.png"); + setStyleSheet (css); + #endif _floating = false; @@ -262,3 +269,77 @@ if (w && w->focusProxy ()) w = w->focusProxy (); return w; } + +void +octave_dock_widget::handle_settings (const QSettings *settings) +{ + QString css; + QString css_button; + QString dock_icon; + if (_floating) + dock_icon = "widget-dock.png"; + else + dock_icon = "widget-undock.png"; + + if (settings->value ("DockWidgets/widget_title_custom_style",false).toBool ()) + { + + QColor default_var = QColor (0,0,0); + QColor fg_color = settings->value ("Dockwidgets/title_fg_color", + default_var).value<QColor> (); + + default_var = QColor (255,255,255); + QColor bg_color = settings->value ("Dockwidgets/title_bg_color", + default_var).value<QColor> (); + + QString bg_icon = QString ("transparent"); + if (bg_color.lightness () < 128) + bg_icon = fg_color.name (); + +#if defined (Q_OS_WIN32) + css = QString ("background: %1; color: %2 ;"). + arg (bg_color.name ()). + arg (fg_color.name ()); + css_button = QString ("background: %3; border: 0px;").arg (bg_icon); +#else + css = QString ("QDockWidget::title { background: %1;" + " text-align: center left;" + " padding: 0px 0px 0px 4px;}\n" + "QDockWidget { color: %2 ; " + " titlebar-close-icon: url(:/actions/icons/widget-close.png);" + " titlebar-normal-icon: url(:/actions/icons/"+dock_icon+"); }" + "QDockWidget::close-button," + "QDockWidget::float-button { background: %3; border: 0px;}" + ). + arg (bg_color.name ()). + arg (fg_color.name ()). + arg (bg_icon); +#endif + } + else + { +#if defined (Q_OS_WIN32) + css = QString (""); + css_button = QString ("background: transparent; border: 0px;"); +#else + css = QString ("QDockWidget::title { text-align: center left;" + " padding: 0px 0px 0px 4px;}" + "QDockWidget {" + " titlebar-close-icon: url(:/actions/icons/widget-close.png);" + " titlebar-normal-icon: url(:/actions/icons/"+dock_icon+"); }" + "QDockWidget::close-button," + "QDockWidget::float-button { border: 0px; }" + ); +#endif + } + +#if defined (Q_OS_WIN32) + _title_widget->setStyleSheet (css); + _dock_button->setStyleSheet (css_button); + _close_button->setStyleSheet (css_button); +#else + setStyleSheet (css); +#endif + + notice_settings (settings); // call individual handler +}
--- a/libgui/src/octave-dock-widget.h +++ b/libgui/src/octave-dock-widget.h @@ -27,6 +27,7 @@ #include <QSettings> #include <QIcon> #include <QMainWindow> +#include <QToolButton> #include <QMouseEvent> class octave_dock_widget : public QDockWidget @@ -81,6 +82,7 @@ virtual void notice_settings (const QSettings*) { } + void handle_settings (const QSettings*); QMainWindow *main_win () { return _parent; } @@ -111,6 +113,12 @@ QAction *_dock_action; bool _floating; +#if defined (Q_OS_WIN32) + QWidget *_title_widget; + QToolButton *_dock_button; + QToolButton *_close_button; +#endif + }; #endif
--- a/libgui/src/settings-dialog.cc +++ b/libgui/src/settings-dialog.cc @@ -90,6 +90,29 @@ ui->general_icon_graphic-> setChecked (widget_icon_set == "GRAPHIC"); ui->general_icon_letter-> setChecked (widget_icon_set == "LETTER"); + // custom title bar of dock widget + QVariant default_var = QColor (255,255,255); + QColor bg_color = settings->value ("Dockwidgets/title_bg_color", + default_var).value<QColor> (); + _widget_title_bg_color = new color_picker (bg_color); + _widget_title_bg_color->setEnabled (false); + ui->layout_widget_bgtitle->addWidget (_widget_title_bg_color,0); + connect (ui->cb_widget_custom_style, SIGNAL (toggled (bool)), + _widget_title_bg_color, SLOT (setEnabled (bool))); + + default_var = QColor (0,0,0); + QColor fg_color = settings->value ("Dockwidgets/title_fg_color", + default_var).value<QColor> (); + _widget_title_fg_color = new color_picker (fg_color); + _widget_title_fg_color->setEnabled (false); + ui->layout_widget_fgtitle->addWidget (_widget_title_fg_color,0); + connect (ui->cb_widget_custom_style, SIGNAL (toggled (bool)), + _widget_title_fg_color, SLOT (setEnabled (bool))); + + ui->cb_widget_custom_style->setChecked ( + settings->value ("DockWidgets/widget_title_custom_style",false).toBool ()); + + // editor ui->useCustomFileEditor->setChecked (settings->value ("useCustomFileEditor", false).toBool ()); ui->customFileEditor->setText ( @@ -97,7 +120,7 @@ ui->editor_showLineNumbers->setChecked ( settings->value ("editor/showLineNumbers",true).toBool () ); - QVariant default_var = QColor (240, 240, 240); + default_var = QColor (240, 240, 240); QColor setting_color = settings->value ("editor/highlight_current_line_color", default_var).value<QColor> (); _editor_current_line_color = new color_picker (setting_color); @@ -467,6 +490,14 @@ language = "SYSTEM"; settings->setValue ("language", language); + // dock widget title bar + settings->setValue ("DockWidgets/widget_title_custom_style", + ui->cb_widget_custom_style->isChecked ()); + settings->setValue ("Dockwidgets/title_bg_color", + _widget_title_bg_color->color ()); + settings->setValue ("Dockwidgets/title_fg_color", + _widget_title_fg_color->color ()); + // other settings settings->setValue ("toolbar_icon_size", ui->toolbar_icon_size->value ()); settings->setValue ("useCustomFileEditor",
--- a/libgui/src/settings-dialog.h +++ b/libgui/src/settings-dialog.h @@ -61,6 +61,8 @@ void read_terminal_colors (QSettings *settings); void write_terminal_colors (QSettings *settings); + color_picker *_widget_title_bg_color; + color_picker *_widget_title_fg_color; color_picker *_editor_current_line_color; };
--- a/libgui/src/settings-dialog.ui +++ b/libgui/src/settings-dialog.ui @@ -32,7 +32,7 @@ <item> <widget class="QTabWidget" name="tabWidget"> <property name="currentIndex"> - <number>3</number> + <number>0</number> </property> <widget class="QWidget" name="tab_general"> <property name="enabled"> @@ -74,7 +74,7 @@ </property> </widget> </item> - <item row="2" column="2"> + <item row="2" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_6"> <item> <widget class="QSpinBox" name="toolbar_icon_size"> @@ -107,7 +107,7 @@ </item> </layout> </item> - <item row="1" column="2"> + <item row="1" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_8"> <item> <widget class="QComboBox" name="comboBox_language"> @@ -131,7 +131,7 @@ </item> </layout> </item> - <item row="3" column="2"> + <item row="3" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_9"> <item> <widget class="QRadioButton" name="general_icon_octave"> @@ -172,6 +172,95 @@ </item> </layout> </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_15"> + <property name="text"> + <string>Dock widget title bar</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QCheckBox" name="cb_widget_custom_style"> + <property name="text"> + <string>Custom style</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_22"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_bgtitle"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Background color</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="layout_widget_bgtitle"/> + </item> + <item> + <spacer name="horizontalSpacer_23"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>12</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_fgtitle"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Text color</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="layout_widget_fgtitle"/> + </item> + <item> + <spacer name="horizontalSpacer_21"> + <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> </layout> </item> <item> @@ -1655,5 +1744,37 @@ </hint> </hints> </connection> + <connection> + <sender>cb_widget_custom_style</sender> + <signal>toggled(bool)</signal> + <receiver>label_bgtitle</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>228</x> + <y>156</y> + </hint> + <hint type="destinationlabel"> + <x>380</x> + <y>156</y> + </hint> + </hints> + </connection> + <connection> + <sender>cb_widget_custom_style</sender> + <signal>toggled(bool)</signal> + <receiver>label_fgtitle</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>228</x> + <y>156</y> + </hint> + <hint type="destinationlabel"> + <x>496</x> + <y>156</y> + </hint> + </hints> + </connection> </connections> </ui>