Mercurial > hg > octave-nkf
changeset 19620:d93293218966 gui-release
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
author | Torsten <ttl@justmail.de> |
---|---|
date | Tue, 23 Dec 2014 16:29:02 +0100 |
parents | 476032040df9 |
children | 5e93d228ff6b |
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, 277 insertions(+), 108 deletions(-) [+] |
line wrap: on
line diff
--- 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<QColor> (); - - default_var = QColor (255,255,255); - QColor bg_color = settings->value ("Dockwidgets/title_bg_color", - default_var).value<QColor> (); + 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<QColor> (); + default_var = QColor (0,0,0); + _fg_color_active = settings->value ("Dockwidgets/title_fg_color_active", + default_var).value<QColor> (); + + default_var = QColor (255,255,255); + _bg_color = settings->value ("Dockwidgets/title_bg_color", + default_var).value<QColor> (); + default_var = QColor (192,192,192); + _bg_color_active = settings->value ("Dockwidgets/title_bg_color_active", + default_var).value<QColor> (); + + 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
--- 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;
--- 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<QColor> (); + _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<QColor> (); @@ -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<QColor> (); + _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 ());
--- 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; };
--- a/libgui/src/settings-dialog.ui +++ b/libgui/src/settings-dialog.ui @@ -32,7 +32,7 @@ </size> </property> <property name="currentIndex"> - <number>1</number> + <number>0</number> </property> <widget class="QWidget" name="tab_general"> <property name="enabled"> @@ -70,6 +70,9 @@ <property name="text"> <string>Dock widget title bar</string> </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + </property> </widget> </item> <item row="1" column="1"> @@ -101,6 +104,9 @@ <property name="text"> <string>Icon size</string> </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + </property> </widget> </item> <item row="6" column="0"> @@ -110,88 +116,6 @@ </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> <item row="2" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_6"> <item> @@ -290,6 +214,130 @@ </property> </widget> </item> + <item row="4" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <layout class="QGridLayout" name="gridLayout_13"> + <item row="1" column="2"> + <widget class="QLabel" name="label_fgtitle"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Text inactive</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="1" column="9"> + <widget class="QLabel" name="label_fgtitle_active"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Active</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QCheckBox" name="cb_widget_custom_style"> + <property name="text"> + <string>Custom style</string> + </property> + </widget> + </item> + <item row="0" column="7"> + <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 row="0" column="1"> + <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 row="0" column="9"> + <widget class="QLabel" name="label_bgtitle_active"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Active</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="1" column="4"> + <layout class="QHBoxLayout" name="layout_widget_fgtitle"/> + </item> + <item row="0" column="4"> + <layout class="QHBoxLayout" name="layout_widget_bgtitle"/> + </item> + <item row="0" column="2"> + <widget class="QLabel" name="label_bgtitle"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Background inactive</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="10"> + <layout class="QHBoxLayout" name="layout_widget_bgtitle_active"/> + </item> + <item row="1" column="10"> + <layout class="QHBoxLayout" name="layout_widget_fgtitle_active"/> + </item> + </layout> + </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> </layout> @@ -404,7 +452,7 @@ <property name="geometry"> <rect> <x>0</x> - <y>-256</y> + <y>0</y> <width>662</width> <height>634</height> </rect> @@ -2723,5 +2771,37 @@ </hint> </hints> </connection> + <connection> + <sender>cb_widget_custom_style</sender> + <signal>toggled(bool)</signal> + <receiver>label_bgtitle_active</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>260</x> + <y>190</y> + </hint> + <hint type="destinationlabel"> + <x>525</x> + <y>190</y> + </hint> + </hints> + </connection> + <connection> + <sender>cb_widget_custom_style</sender> + <signal>toggled(bool)</signal> + <receiver>label_fgtitle_active</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>260</x> + <y>190</y> + </hint> + <hint type="destinationlabel"> + <x>533</x> + <y>214</y> + </hint> + </hints> + </connection> </connections> </ui>