# HG changeset patch # User Torsten # Date 1388493105 -3600 # Node ID b3838cedfe046496bec81c91377324ff3ce89a77 # Parent 256e280850f1c8bee8c83e57f188f16815e5ef62 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 diff --git a/libgui/src/octave-dock-widget.cc b/libgui/src/octave-dock-widget.cc --- a/libgui/src/octave-dock-widget.cc +++ b/libgui/src/octave-dock-widget.cc @@ -27,7 +27,6 @@ #include #include -#include #include #include #include @@ -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 (); + + default_var = QColor (255,255,255); + QColor bg_color = settings->value ("Dockwidgets/title_bg_color", + default_var).value (); + + 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 +} diff --git a/libgui/src/octave-dock-widget.h b/libgui/src/octave-dock-widget.h --- a/libgui/src/octave-dock-widget.h +++ b/libgui/src/octave-dock-widget.h @@ -27,6 +27,7 @@ #include #include #include +#include #include 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 diff --git a/libgui/src/settings-dialog.cc b/libgui/src/settings-dialog.cc --- 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 (); + _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 (); + _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 (); _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", diff --git a/libgui/src/settings-dialog.h b/libgui/src/settings-dialog.h --- 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; }; diff --git a/libgui/src/settings-dialog.ui b/libgui/src/settings-dialog.ui --- a/libgui/src/settings-dialog.ui +++ b/libgui/src/settings-dialog.ui @@ -32,7 +32,7 @@ - 3 + 0 @@ -74,7 +74,7 @@ - + @@ -107,7 +107,7 @@ - + @@ -131,7 +131,7 @@ - + @@ -172,6 +172,95 @@ + + + + Dock widget title bar + + + + + + + + + Custom style + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + false + + + Background color + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 12 + 20 + + + + + + + + false + + + Text color + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -1655,5 +1744,37 @@ + + cb_widget_custom_style + toggled(bool) + label_bgtitle + setEnabled(bool) + + + 228 + 156 + + + 380 + 156 + + + + + cb_widget_custom_style + toggled(bool) + label_fgtitle + setEnabled(bool) + + + 228 + 156 + + + 496 + 156 + + +