# HG changeset patch # User Torsten # Date 1419348542 -3600 # Node ID d93293218966f45b8fbeb294621e9a6c61c985a8 # Parent 476032040df940a3e405e95b85c2a089b7883dca custom style of dock widget title bars depending on focus (bug #43837) * octave-dock-widget.cc (ctor): connect active-dock-changed signal with the related new slot; (make_widget): prevent warning message on unused variable; (set_style): new function styling the title bar depending on activity; (handle_settings): get colors for custom style from settings file; (handle_active_dock_changed): new slot for signal from main window settings the custom style depending on changed activity * octave-dock-widget.h: new slot handle_active_dock_changed, new function set_style, new class variables for custom colors * settings-dialog.cc (ctor): init color pickers for back- and foreground color of title bars of active dock widgets from settings file; (write_changesd_settings): write back- and foreground color of title bars into settings file * settings-dialog.h: new class variables for active back- and foreground colors * settings-dialog.ui: new color pickers for active back- and foreground 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 @@ -49,6 +49,9 @@ connect (p, SIGNAL (settings_changed (const QSettings*)), this, SLOT (handle_settings (const QSettings*))); + connect (p, SIGNAL (active_dock_changed (octave_dock_widget*, octave_dock_widget*)), + this, SLOT (handle_active_dock_changed (octave_dock_widget*, octave_dock_widget*))); + #if defined (Q_OS_WIN32) // windows: add an extra title bar that persists when floating @@ -201,7 +204,7 @@ // dock the widget void -octave_dock_widget::make_widget (bool dock) +octave_dock_widget::make_widget (bool) { #if defined (Q_OS_WIN32) @@ -279,7 +282,7 @@ } void -octave_dock_widget::handle_settings (const QSettings *settings) +octave_dock_widget::set_style (bool active) { QString css; QString css_button; @@ -290,34 +293,33 @@ else dock_icon = "widget-undock"; - if (settings->value ("DockWidgets/widget_title_custom_style",false).toBool ()) + if (_custom_style) { - 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 (); + QColor bg_col, fg_col; + QString icon_col; - int r, g, b; - QColor bg_color_light = bg_color.lighter (); - - bg_color.getRgb (&r, &g, &b); - if (r+g+b < 400) - _icon_color = "-light"; + if (active) + { + bg_col = _bg_color_active; + fg_col = _fg_color_active; + icon_col = _icon_color_active; + } else - _icon_color = ""; + { + bg_col = _bg_color; + fg_col = _fg_color; + icon_col = _icon_color; + } QString background = QString ("background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," " stop: 0 %1, stop: 0.75 %2, stop: 0.9 %2, stop: 1.0 %1);"). - arg (bg_color_light.name ()). - arg (bg_color.name ()); + arg (bg_col.lighter ().name ()). + arg (bg_col.name ()); #if defined (Q_OS_WIN32) - css = background + QString (" color: %1 ;").arg (fg_color.name ()); + css = background + QString (" color: %1 ;").arg (fg_col.name ()); #else css = QString ("QDockWidget::title { " + background + " text-align: center left;" @@ -328,8 +330,8 @@ "QDockWidget::close-button," "QDockWidget::float-button { border: 0px;}" ). - arg (fg_color.name ()). - arg (_icon_color); + arg (fg_col.name ()). + arg (icon_col); #endif } else @@ -353,13 +355,49 @@ css_button = QString ("background: transparent; border: 0px;"); _dock_button->setStyleSheet (css_button); _close_button->setStyleSheet (css_button); - _dock_action->setIcon (QIcon (":/actions/icons/"+dock_icon+_icon_color+".png")); - _close_action->setIcon (QIcon (":/actions/icons/widget-close"+_icon_color+".png")); + _dock_action->setIcon (QIcon (":/actions/icons/" + dock_icon + icon_col + ".png")); + _close_action->setIcon (QIcon (":/actions/icons/widget-close" + dock_icon + icon_col ".png")); #else setStyleSheet (css); #endif +} + +void +octave_dock_widget::handle_settings (const QSettings *settings) +{ + _custom_style = + settings->value ("DockWidgets/widget_title_custom_style",false).toBool (); + + QColor default_var = QColor (0,0,0); + _fg_color = settings->value ("Dockwidgets/title_fg_color", + default_var).value (); + default_var = QColor (0,0,0); + _fg_color_active = settings->value ("Dockwidgets/title_fg_color_active", + default_var).value (); + + default_var = QColor (255,255,255); + _bg_color = settings->value ("Dockwidgets/title_bg_color", + default_var).value (); + default_var = QColor (192,192,192); + _bg_color_active = settings->value ("Dockwidgets/title_bg_color_active", + default_var).value (); + + int r, g, b; + _bg_color.getRgb (&r, &g, &b); + if (r+g+b < 400) + _icon_color = "-light"; + else + _icon_color = ""; + + _bg_color_active.getRgb (&r, &g, &b); + if (r+g+b < 400) + _icon_color_active = "-light"; + else + _icon_color_active = ""; notice_settings (settings); // call individual handler + + set_style (false); } bool octave_dock_widget::eventFilter(QObject *obj, QEvent *e) @@ -372,3 +410,20 @@ return QDockWidget::eventFilter (obj,e); } + +void +octave_dock_widget::handle_active_dock_changed (octave_dock_widget *w_old, + octave_dock_widget *w_new) +{ + if (_custom_style && this == w_old) + { + set_style (false); + update (); + } + + if (_custom_style && this == w_new) + { + set_style (true); + update (); + } +} \ No newline at end of file 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 @@ -84,6 +84,8 @@ } void handle_settings (const QSettings*); + void handle_active_dock_changed (octave_dock_widget*, octave_dock_widget*); + QMainWindow *main_win () { return _parent; } protected slots: @@ -115,9 +117,17 @@ private: + void set_style (bool active); + QMainWindow *_parent; // store the parent since we are reparenting to 0 bool _floating; + bool _custom_style; + QColor _bg_color; + QColor _bg_color_active; + QColor _fg_color; + QColor _fg_color_active; QString _icon_color; + QString _icon_color_active; #if defined (Q_OS_WIN32) QWidget *_title_widget; 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 @@ -106,6 +106,15 @@ connect (ui->cb_widget_custom_style, SIGNAL (toggled (bool)), _widget_title_bg_color, SLOT (setEnabled (bool))); + default_var = QColor (192,192,192); + QColor bg_color_active = settings->value ("Dockwidgets/title_bg_color_active", + default_var).value (); + _widget_title_bg_color_active = new color_picker (bg_color_active); + _widget_title_bg_color_active->setEnabled (false); + ui->layout_widget_bgtitle_active->addWidget (_widget_title_bg_color_active,0); + connect (ui->cb_widget_custom_style, SIGNAL (toggled (bool)), + _widget_title_bg_color_active, SLOT (setEnabled (bool))); + default_var = QColor (0,0,0); QColor fg_color = settings->value ("Dockwidgets/title_fg_color", default_var).value (); @@ -115,6 +124,15 @@ connect (ui->cb_widget_custom_style, SIGNAL (toggled (bool)), _widget_title_fg_color, SLOT (setEnabled (bool))); + default_var = QColor (0,0,0); + QColor fg_color_active = settings->value ("Dockwidgets/title_fg_color_active", + default_var).value (); + _widget_title_fg_color_active = new color_picker (fg_color_active); + _widget_title_fg_color_active->setEnabled (false); + ui->layout_widget_fgtitle_active->addWidget (_widget_title_fg_color_active,0); + connect (ui->cb_widget_custom_style, SIGNAL (toggled (bool)), + _widget_title_fg_color_active, SLOT (setEnabled (bool))); + ui->cb_widget_custom_style->setChecked ( settings->value ("DockWidgets/widget_title_custom_style",false).toBool ()); @@ -600,8 +618,12 @@ ui->cb_widget_custom_style->isChecked ()); settings->setValue ("Dockwidgets/title_bg_color", _widget_title_bg_color->color ()); + settings->setValue ("Dockwidgets/title_bg_color_active", + _widget_title_bg_color_active->color ()); settings->setValue ("Dockwidgets/title_fg_color", _widget_title_fg_color->color ()); + settings->setValue ("Dockwidgets/title_fg_color_active", + _widget_title_fg_color_active->color ()); // icon size settings->setValue ("toolbar_icon_size", ui->toolbar_icon_size->value ()); 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 @@ -75,7 +75,9 @@ void write_terminal_colors (QSettings *settings); color_picker *_widget_title_bg_color; + color_picker *_widget_title_bg_color_active; color_picker *_widget_title_fg_color; + color_picker *_widget_title_fg_color_active; 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 @@ - 1 + 0 @@ -70,6 +70,9 @@ Dock widget title bar + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + @@ -101,6 +104,9 @@ Icon size + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + @@ -110,88 +116,6 @@ - - - - - - Custom style - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - false - - - Background color - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 12 - 20 - - - - - - - - false - - - Text color - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - @@ -290,6 +214,130 @@ + + + + + + + + false + + + Text inactive + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + false + + + Active + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Custom style + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 12 + 20 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + false + + + Active + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + false + + + Background inactive + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -404,7 +452,7 @@ 0 - -256 + 0 662 634 @@ -2723,5 +2771,37 @@ + + cb_widget_custom_style + toggled(bool) + label_bgtitle_active + setEnabled(bool) + + + 260 + 190 + + + 525 + 190 + + + + + cb_widget_custom_style + toggled(bool) + label_fgtitle_active + setEnabled(bool) + + + 260 + 190 + + + 533 + 214 + + +