changeset 18217:7952fb0435db gui-release

improve title bar of dock widgets * libgui/src/module.mk: new icon files for darker dock widget's title bars * libgui/src/resource.qrc: new icon files for darker dock widget's title bars * octave-dock-widget.cc (constructor): class vars for close action and icons; (set_title): transparent background of title text; (make_window, make_widget): new dock icon depends on chosen color; (handle_settings): title bar with gradient, chose icons depending on color * octave-dock-widget.h: new class variables
author Torsten <ttl@justmail.de>
date Sat, 04 Jan 2014 22:16:10 +0100
parents 55b8dc2ea022
children 7adbc822065a
files libgui/src/module.mk libgui/src/octave-dock-widget.cc libgui/src/octave-dock-widget.h libgui/src/resource.qrc
diffstat 4 files changed, 47 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/module.mk	Sat Jan 04 17:03:33 2014 +0100
+++ b/libgui/src/module.mk	Sat Jan 04 22:16:10 2014 +0100
@@ -71,6 +71,9 @@
   src/icons/widget-close.png \
   src/icons/widget-dock.png \
   src/icons/widget-undock.png \
+  src/icons/widget-close-light.png \
+  src/icons/widget-dock-light.png \
+  src/icons/widget-undock-light.png \
   src/icons/zoom-in.png \
   src/icons/zoom-out.png
 
--- a/libgui/src/octave-dock-widget.cc	Sat Jan 04 17:03:33 2014 +0100
+++ b/libgui/src/octave-dock-widget.cc	Sat Jan 04 22:16:10 2014 +0100
@@ -65,16 +65,18 @@
   _dock_button->setFocusPolicy (Qt::NoFocus);
   _dock_button->setIconSize (QSize (12,12));
 
-  QAction *close_action = new QAction
+  _close_action = new QAction
                    (QIcon (":/actions/icons/widget-close.png"), "", this );
-  close_action-> setToolTip (tr ("Hide widget"));
-  connect (close_action, SIGNAL (triggered (bool)),
+  _close_action-> setToolTip (tr ("Hide widget"));
+  connect (_close_action, SIGNAL (triggered (bool)),
            this, SLOT (change_visibility (bool)));
   _close_button = new QToolButton (this);
-  _close_button->setDefaultAction (close_action);
+  _close_button->setDefaultAction (_close_action);
   _close_button->setFocusPolicy (Qt::NoFocus);
   _close_button->setIconSize (QSize (12,12));
 
+  _icon_color = "";
+
   QHBoxLayout *h_layout = new QHBoxLayout ();
   h_layout->addStretch (100);
   h_layout->addWidget (_dock_button);
@@ -146,6 +148,7 @@
   QHBoxLayout* h_layout =
     static_cast<QHBoxLayout *> (titleBarWidget ()->layout ());
   QLabel *label = new QLabel (title);
+  label->setStyleSheet ("background: transparent;");
   h_layout->insertWidget (0,label);
 #endif
   setWindowTitle (title);
@@ -170,7 +173,7 @@
 
   // remove parent and adjust the (un)dock icon
   setParent (0, Qt::Window);
-  _dock_action->setIcon (QIcon (":/actions/icons/widget-dock.png"));
+  _dock_action->setIcon (QIcon (":/actions/icons/widget-dock"+_icon_color+".png"));
   _dock_action->setToolTip (tr ("Dock widget"));
 
   // restore the last geometry( when floating
@@ -183,7 +186,7 @@
   setWindowFlags (Qt::Window);
 
   QString css = styleSheet ();
-  css.replace ("widget-undock.png","widget-dock.png");
+  css.replace ("widget-undock","widget-dock");
   setStyleSheet (css);
 
 #endif
@@ -223,7 +226,7 @@
     setParent (_parent);
 
   // adjust the (un)dock icon
-  _dock_action->setIcon (QIcon (":/actions/icons/widget-undock.png"));
+  _dock_action->setIcon (QIcon (":/actions/icons/widget-undock"+_icon_color+".png"));
   _dock_action->setToolTip (tr ("Undock widget"));
 
 #else
@@ -232,7 +235,7 @@
   setWindowFlags (Qt::Widget);
 
   QString css = styleSheet ();
-  css.replace ("widget-dock.png","widget-undock.png");
+  css.replace ("widget-dock","widget-undock");
   setStyleSheet (css);
 
 #endif
@@ -276,10 +279,11 @@
   QString css;
   QString css_button;
   QString dock_icon;
+
   if (_floating)
-    dock_icon = "widget-dock.png";
+    dock_icon = "widget-dock";
   else
-    dock_icon = "widget-undock.png";
+    dock_icon = "widget-undock";
 
   if (settings->value ("DockWidgets/widget_title_custom_style",false).toBool ())
     {
@@ -292,35 +296,41 @@
       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 ();
+      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";
+      else
+        _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 ());
 
 #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);
+      css = background + QString (" color: %1 ;").arg (fg_color.name ());
 #else
-      css = QString ("QDockWidget::title { background: %1;"
+      css = QString ("QDockWidget::title { " + background +
                      "                     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 { color: %1 ; "
+                     "  titlebar-close-icon: url(:/actions/icons/widget-close%2.png);"
+                     "  titlebar-normal-icon: url(:/actions/icons/"+dock_icon+"%2); }"
                      "QDockWidget::close-button,"
-                     "QDockWidget::float-button { background: %3; border: 0px;}"
+                     "QDockWidget::float-button { border: 0px;}"
                      ).
-                     arg (bg_color.name ()).
                      arg (fg_color.name ()).
-                     arg (bg_icon);
+                     arg (_icon_color);
 #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;}"
@@ -335,8 +345,11 @@
 
 #if defined (Q_OS_WIN32)
   _title_widget->setStyleSheet (css);
+  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"));
 #else
   setStyleSheet (css);
 #endif
--- a/libgui/src/octave-dock-widget.h	Sat Jan 04 17:03:33 2014 +0100
+++ b/libgui/src/octave-dock-widget.h	Sat Jan 04 22:16:10 2014 +0100
@@ -110,13 +110,15 @@
 private:
 
   QMainWindow *_parent;  // store the parent since we are reparenting to 0
-  QAction *_dock_action;
   bool _floating;
+  QString _icon_color;
 
 #if defined (Q_OS_WIN32)
   QWidget *_title_widget;
   QToolButton *_dock_button;
   QToolButton *_close_button;
+  QAction *_dock_action;
+  QAction *_close_action;
 #endif
 
 };
--- a/libgui/src/resource.qrc	Sat Jan 04 17:03:33 2014 +0100
+++ b/libgui/src/resource.qrc	Sat Jan 04 22:16:10 2014 +0100
@@ -67,5 +67,8 @@
         <file>icons/widget-close.png</file>
         <file>icons/widget-dock.png</file>
         <file>icons/widget-undock.png</file>
+        <file>icons/widget-close-light.png</file>
+        <file>icons/widget-dock-light.png</file>
+        <file>icons/widget-undock-light.png</file>
     </qresource>
 </RCC>