comparison libgui/src/octave-dock-widget.cc @ 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 b3838cedfe04
children 2d5d0d86432e
comparison
equal deleted inserted replaced
18216:55b8dc2ea022 18217:7952fb0435db
63 _dock_button = new QToolButton (this); 63 _dock_button = new QToolButton (this);
64 _dock_button->setDefaultAction (_dock_action); 64 _dock_button->setDefaultAction (_dock_action);
65 _dock_button->setFocusPolicy (Qt::NoFocus); 65 _dock_button->setFocusPolicy (Qt::NoFocus);
66 _dock_button->setIconSize (QSize (12,12)); 66 _dock_button->setIconSize (QSize (12,12));
67 67
68 QAction *close_action = new QAction 68 _close_action = new QAction
69 (QIcon (":/actions/icons/widget-close.png"), "", this ); 69 (QIcon (":/actions/icons/widget-close.png"), "", this );
70 close_action-> setToolTip (tr ("Hide widget")); 70 _close_action-> setToolTip (tr ("Hide widget"));
71 connect (close_action, SIGNAL (triggered (bool)), 71 connect (_close_action, SIGNAL (triggered (bool)),
72 this, SLOT (change_visibility (bool))); 72 this, SLOT (change_visibility (bool)));
73 _close_button = new QToolButton (this); 73 _close_button = new QToolButton (this);
74 _close_button->setDefaultAction (close_action); 74 _close_button->setDefaultAction (_close_action);
75 _close_button->setFocusPolicy (Qt::NoFocus); 75 _close_button->setFocusPolicy (Qt::NoFocus);
76 _close_button->setIconSize (QSize (12,12)); 76 _close_button->setIconSize (QSize (12,12));
77
78 _icon_color = "";
77 79
78 QHBoxLayout *h_layout = new QHBoxLayout (); 80 QHBoxLayout *h_layout = new QHBoxLayout ();
79 h_layout->addStretch (100); 81 h_layout->addStretch (100);
80 h_layout->addWidget (_dock_button); 82 h_layout->addWidget (_dock_button);
81 h_layout->addWidget (_close_button); 83 h_layout->addWidget (_close_button);
144 { 146 {
145 #if defined (Q_OS_WIN32) 147 #if defined (Q_OS_WIN32)
146 QHBoxLayout* h_layout = 148 QHBoxLayout* h_layout =
147 static_cast<QHBoxLayout *> (titleBarWidget ()->layout ()); 149 static_cast<QHBoxLayout *> (titleBarWidget ()->layout ());
148 QLabel *label = new QLabel (title); 150 QLabel *label = new QLabel (title);
151 label->setStyleSheet ("background: transparent;");
149 h_layout->insertWidget (0,label); 152 h_layout->insertWidget (0,label);
150 #endif 153 #endif
151 setWindowTitle (title); 154 setWindowTitle (title);
152 } 155 }
153 156
168 settings->setValue ("DockWidgets/" + objectName (), saveGeometry ()); 171 settings->setValue ("DockWidgets/" + objectName (), saveGeometry ());
169 settings->sync (); 172 settings->sync ();
170 173
171 // remove parent and adjust the (un)dock icon 174 // remove parent and adjust the (un)dock icon
172 setParent (0, Qt::Window); 175 setParent (0, Qt::Window);
173 _dock_action->setIcon (QIcon (":/actions/icons/widget-dock.png")); 176 _dock_action->setIcon (QIcon (":/actions/icons/widget-dock"+_icon_color+".png"));
174 _dock_action->setToolTip (tr ("Dock widget")); 177 _dock_action->setToolTip (tr ("Dock widget"));
175 178
176 // restore the last geometry( when floating 179 // restore the last geometry( when floating
177 setGeometry (settings->value ("DockWidgets/" + objectName () 180 setGeometry (settings->value ("DockWidgets/" + objectName ()
178 + "_floating_geometry",QRect(50,100,480,480)).toRect ()); 181 + "_floating_geometry",QRect(50,100,480,480)).toRect ());
181 184
182 // non windows: Just set the appripriate window flag 185 // non windows: Just set the appripriate window flag
183 setWindowFlags (Qt::Window); 186 setWindowFlags (Qt::Window);
184 187
185 QString css = styleSheet (); 188 QString css = styleSheet ();
186 css.replace ("widget-undock.png","widget-dock.png"); 189 css.replace ("widget-undock","widget-dock");
187 setStyleSheet (css); 190 setStyleSheet (css);
188 191
189 #endif 192 #endif
190 193
191 _floating = true; 194 _floating = true;
221 } 224 }
222 else // only reparent, no docking 225 else // only reparent, no docking
223 setParent (_parent); 226 setParent (_parent);
224 227
225 // adjust the (un)dock icon 228 // adjust the (un)dock icon
226 _dock_action->setIcon (QIcon (":/actions/icons/widget-undock.png")); 229 _dock_action->setIcon (QIcon (":/actions/icons/widget-undock"+_icon_color+".png"));
227 _dock_action->setToolTip (tr ("Undock widget")); 230 _dock_action->setToolTip (tr ("Undock widget"));
228 231
229 #else 232 #else
230 233
231 // non windows: just say we are a docked widget again 234 // non windows: just say we are a docked widget again
232 setWindowFlags (Qt::Widget); 235 setWindowFlags (Qt::Widget);
233 236
234 QString css = styleSheet (); 237 QString css = styleSheet ();
235 css.replace ("widget-dock.png","widget-undock.png"); 238 css.replace ("widget-dock","widget-undock");
236 setStyleSheet (css); 239 setStyleSheet (css);
237 240
238 #endif 241 #endif
239 242
240 _floating = false; 243 _floating = false;
274 octave_dock_widget::handle_settings (const QSettings *settings) 277 octave_dock_widget::handle_settings (const QSettings *settings)
275 { 278 {
276 QString css; 279 QString css;
277 QString css_button; 280 QString css_button;
278 QString dock_icon; 281 QString dock_icon;
282
279 if (_floating) 283 if (_floating)
280 dock_icon = "widget-dock.png"; 284 dock_icon = "widget-dock";
281 else 285 else
282 dock_icon = "widget-undock.png"; 286 dock_icon = "widget-undock";
283 287
284 if (settings->value ("DockWidgets/widget_title_custom_style",false).toBool ()) 288 if (settings->value ("DockWidgets/widget_title_custom_style",false).toBool ())
285 { 289 {
286 290
287 QColor default_var = QColor (0,0,0); 291 QColor default_var = QColor (0,0,0);
290 294
291 default_var = QColor (255,255,255); 295 default_var = QColor (255,255,255);
292 QColor bg_color = settings->value ("Dockwidgets/title_bg_color", 296 QColor bg_color = settings->value ("Dockwidgets/title_bg_color",
293 default_var).value<QColor> (); 297 default_var).value<QColor> ();
294 298
295 QString bg_icon = QString ("transparent"); 299 int r, g, b;
296 if (bg_color.lightness () < 128) 300 QColor bg_color_light = bg_color.lighter ();
297 bg_icon = fg_color.name (); 301
298 302 bg_color.getRgb (&r, &g, &b);
299 #if defined (Q_OS_WIN32) 303 if (r+g+b < 400)
300 css = QString ("background: %1; color: %2 ;"). 304 _icon_color = "-light";
301 arg (bg_color.name ()). 305 else
302 arg (fg_color.name ()); 306 _icon_color = "";
303 css_button = QString ("background: %3; border: 0px;").arg (bg_icon); 307
304 #else 308 QString background =
305 css = QString ("QDockWidget::title { background: %1;" 309 QString ("background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
310 " stop: 0 %1, stop: 0.75 %2, stop: 0.9 %2, stop: 1.0 %1);").
311 arg (bg_color_light.name ()).
312 arg (bg_color.name ());
313
314 #if defined (Q_OS_WIN32)
315 css = background + QString (" color: %1 ;").arg (fg_color.name ());
316 #else
317 css = QString ("QDockWidget::title { " + background +
306 " text-align: center left;" 318 " text-align: center left;"
307 " padding: 0px 0px 0px 4px;}\n" 319 " padding: 0px 0px 0px 4px;}\n"
308 "QDockWidget { color: %2 ; " 320 "QDockWidget { color: %1 ; "
309 " titlebar-close-icon: url(:/actions/icons/widget-close.png);" 321 " titlebar-close-icon: url(:/actions/icons/widget-close%2.png);"
310 " titlebar-normal-icon: url(:/actions/icons/"+dock_icon+"); }" 322 " titlebar-normal-icon: url(:/actions/icons/"+dock_icon+"%2); }"
311 "QDockWidget::close-button," 323 "QDockWidget::close-button,"
312 "QDockWidget::float-button { background: %3; border: 0px;}" 324 "QDockWidget::float-button { border: 0px;}"
313 ). 325 ).
314 arg (bg_color.name ()).
315 arg (fg_color.name ()). 326 arg (fg_color.name ()).
316 arg (bg_icon); 327 arg (_icon_color);
317 #endif 328 #endif
318 } 329 }
319 else 330 else
320 { 331 {
321 #if defined (Q_OS_WIN32) 332 #if defined (Q_OS_WIN32)
322 css = QString (""); 333 css = QString ("");
323 css_button = QString ("background: transparent; border: 0px;");
324 #else 334 #else
325 css = QString ("QDockWidget::title { text-align: center left;" 335 css = QString ("QDockWidget::title { text-align: center left;"
326 " padding: 0px 0px 0px 4px;}" 336 " padding: 0px 0px 0px 4px;}"
327 "QDockWidget {" 337 "QDockWidget {"
328 " titlebar-close-icon: url(:/actions/icons/widget-close.png);" 338 " titlebar-close-icon: url(:/actions/icons/widget-close.png);"
333 #endif 343 #endif
334 } 344 }
335 345
336 #if defined (Q_OS_WIN32) 346 #if defined (Q_OS_WIN32)
337 _title_widget->setStyleSheet (css); 347 _title_widget->setStyleSheet (css);
348 css_button = QString ("background: transparent; border: 0px;");
338 _dock_button->setStyleSheet (css_button); 349 _dock_button->setStyleSheet (css_button);
339 _close_button->setStyleSheet (css_button); 350 _close_button->setStyleSheet (css_button);
351 _dock_action->setIcon (QIcon (":/actions/icons/"+dock_icon+_icon_color+".png"));
352 _close_action->setIcon (QIcon (":/actions/icons/widget-close"+_icon_color+".png"));
340 #else 353 #else
341 setStyleSheet (css); 354 setStyleSheet (css);
342 #endif 355 #endif
343 356
344 notice_settings (settings); // call individual handler 357 notice_settings (settings); // call individual handler