1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #include "qgtkstyle.h"
42 
43 #if !defined(QT_NO_STYLE_GTK)
44 
45 #include <private/qapplication_p.h>
46 #include <QtCore/QLibrary>
47 #include <QtCore/QSettings>
48 #include <QtGui/QDialogButtonBox>
49 #include <QtGui/QStatusBar>
50 #include <QtGui/QLineEdit>
51 #include <QtGui/QWidget>
52 #include <QtGui/QListView>
53 #include <QtGui/QApplication>
54 #include <QtGui/QStyleOption>
55 #include <QtGui/QPushButton>
56 #include <QtGui/QPainter>
57 #include <QtGui/QMainWindow>
58 #include <QtGui/QToolBar>
59 #include <QtGui/QHeaderView>
60 #include <QtGui/QMenuBar>
61 #include <QtGui/QComboBox>
62 #include <QtGui/QSpinBox>
63 #include <QtGui/QScrollBar>
64 #include <QtGui/QAbstractButton>
65 #include <QtGui/QToolButton>
66 #include <QtGui/QGroupBox>
67 #include <QtGui/QRadioButton>
68 #include <QtGui/QCheckBox>
69 #include <QtGui/QTreeView>
70 #include <QtGui/QStyledItemDelegate>
71 #include <qpixmapcache.h>
72 #undef signals // Collides with GTK stymbols
73 #include <private/qgtkpainter_p.h>
74 #include <private/qstylehelper_p.h>
75 #include <private/qgtkstyle_p.h>
76 #include <private/qcleanlooksstyle_p.h>
77 
78 
79 QT_BEGIN_NAMESPACE
80 
81 static const char * const dock_widget_close_xpm[] =
82     {
83         "11 13 5 1",
84         "  c None",
85         ". c #D5CFCB",
86         "+ c #6C6A67",
87         "@ c #6C6A67",
88         "$ c #B5B0AC",
89         "           ",
90         " @@@@@@@@@ ",
91         "@+       +@",
92         "@ +@   @+ @",
93         "@ @@@ @@@ @",
94         "@  @@@@@  @",
95         "@   @@@   @",
96         "@  @@@@@  @",
97         "@ @@@ @@@ @",
98         "@ +@   @+ @",
99         "@+       +@",
100         " @@@@@@@@@ ",
101         "           "
102     };
103 
104 static const char * const dock_widget_restore_xpm[] =
105     {
106         "11 13 5 1",
107         "  c None",
108         ". c #D5CFCB",
109         "+ c #6C6A67",
110         "@ c #6C6A67",
111         "# c #6C6A67",
112         "           ",
113         " @@@@@@@@@ ",
114         "@+       +@",
115         "@   #@@@# @",
116         "@   @   @ @",
117         "@ #@@@# @ @",
118         "@ @   @ @ @",
119         "@ @   @@@ @",
120         "@ @   @   @",
121         "@ #@@@@   @",
122         "@+       +@",
123         " @@@@@@@@@ ",
124         "           "
125     };
126 
127 static const int groupBoxBottomMargin    =  2;  // space below the groupbox
128 static const int groupBoxTitleMargin     =  6;  // space between contents and title
129 static const int groupBoxTopMargin       =  2;
130 
131 /*!
132   Returns the configuration string for \a value.
133   Returns \a fallback if \a value is not found.
134  */
getGConfString(const QString & value,const QString & fallback)135 QString QGtkStyle::getGConfString(const QString &value, const QString &fallback)
136 {
137     return QGtkStylePrivate::getGConfString(value, fallback);
138 }
139 
140 /*!
141   Returns the configuration boolean for \a key.
142   Returns \a fallback if \a key is not found.
143  */
getGConfBool(const QString & key,bool fallback)144 bool QGtkStyle::getGConfBool(const QString &key, bool fallback)
145 {
146     return QGtkStylePrivate::getGConfBool(key, fallback);
147 }
148 
mergedColors(const QColor & colorA,const QColor & colorB,int factor=50)149 static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50)
150 {
151     const int maxFactor = 100;
152     QColor tmp = colorA;
153     tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
154     tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
155     tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
156     return tmp;
157 }
158 
fromQColor(const QColor & color)159 static GdkColor fromQColor(const QColor &color)
160 {
161     GdkColor retval;
162     retval.red = color.red() * 255;
163     retval.green = color.green() * 255;
164     retval.blue = color.blue() * 255;
165     return retval;
166 }
167 
168 /*!
169     \class QGtkStyle
170     \brief The QGtkStyle class provides a widget style rendered by GTK+
171     \since 4.5
172 
173     The QGtkStyle style provides a look and feel that integrates well
174     into GTK-based desktop environments such as the XFCe and GNOME.
175 
176     It does this by making use of the GTK+ theme engine, ensuring
177     that Qt applications look and feel native on these platforms.
178 
179     Note: The style requires GTK+ version 2.10 or later.
180           The Qt3-based "Qt" GTK+ theme engine will not work with QGtkStyle.
181 
182     \sa {Cleanlooks Style Widget Gallery}, QWindowsXPStyle, QMacStyle, QWindowsStyle,
183         QCDEStyle, QMotifStyle, QPlastiqueStyle, QCleanlooksStyle
184 */
185 
186 /*!
187     Constructs a QGtkStyle object.
188 */
QGtkStyle()189 QGtkStyle::QGtkStyle()
190     : QCleanlooksStyle(*new QGtkStylePrivate)
191 {
192     Q_D(QGtkStyle);
193     d->init();
194 }
195 
196 /*!
197     \internal
198 
199     Constructs a QGtkStyle object.
200 */
QGtkStyle(QGtkStylePrivate & dd)201 QGtkStyle::QGtkStyle(QGtkStylePrivate &dd)
202      : QCleanlooksStyle(dd)
203 {
204     Q_D(QGtkStyle);
205     d->init();
206 }
207 
208 
209 /*!
210     Destroys the QGtkStyle object.
211 */
~QGtkStyle()212 QGtkStyle::~QGtkStyle()
213 {
214 }
215 
216 /*!
217     \reimp
218 */
standardPalette() const219 QPalette QGtkStyle::standardPalette() const
220 {
221     Q_D(const QGtkStyle);
222 
223     QPalette palette = QCleanlooksStyle::standardPalette();
224     if (d->isThemeAvailable()) {
225         GtkStyle *style = d->gtkStyle();
226         GtkWidget *gtkButton = d->gtkWidget("GtkButton");
227         GtkWidget *gtkEntry = d->getTextColorWidget();
228         GdkColor gdkBg, gdkBase, gdkText, gdkForeground, gdkSbg, gdkSfg, gdkaSbg, gdkaSfg;
229         QColor bg, base, text, fg, highlight, highlightText, inactiveHighlight, inactiveHighlightedTExt;
230         gdkBg = style->bg[GTK_STATE_NORMAL];
231         gdkForeground = gtkButton->style->fg[GTK_STATE_NORMAL];
232 
233         // Our base and selected color is primarily used for text
234         // so we assume a gtkEntry will have the most correct value
235         gdkBase = gtkEntry->style->base[GTK_STATE_NORMAL];
236         gdkText = gtkEntry->style->text[GTK_STATE_NORMAL];
237         gdkSbg = gtkEntry->style->base[GTK_STATE_SELECTED];
238         gdkSfg = gtkEntry->style->text[GTK_STATE_SELECTED];
239 
240         // The ACTIVE base color is really used for inactive windows
241         gdkaSbg = gtkEntry->style->base[GTK_STATE_ACTIVE];
242         gdkaSfg = gtkEntry->style->text[GTK_STATE_ACTIVE];
243 
244         bg = QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8);
245         text = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
246         fg = QColor(gdkForeground.red>>8, gdkForeground.green>>8, gdkForeground.blue>>8);
247         base = QColor(gdkBase.red>>8, gdkBase.green>>8, gdkBase.blue>>8);
248         highlight = QColor(gdkSbg.red>>8, gdkSbg.green>>8, gdkSbg.blue>>8);
249         highlightText = QColor(gdkSfg.red>>8, gdkSfg.green>>8, gdkSfg.blue>>8);
250         inactiveHighlight = QColor(gdkaSbg.red>>8, gdkaSbg.green>>8, gdkaSbg.blue>>8);
251         inactiveHighlightedTExt = QColor(gdkaSfg.red>>8, gdkaSfg.green>>8, gdkaSfg.blue>>8);
252 
253         palette.setColor(QPalette::HighlightedText, highlightText);
254 
255 
256         palette.setColor(QPalette::Light, bg.lighter(125));
257         palette.setColor(QPalette::Shadow, bg.darker(130));
258         palette.setColor(QPalette::Dark, bg.darker(120));
259         palette.setColor(QPalette::Text, text);
260         palette.setColor(QPalette::WindowText, fg);
261         palette.setColor(QPalette::ButtonText, fg);
262         palette.setColor(QPalette::Base, base);
263 
264         QColor alternateRowColor = palette.base().color().lighter(93); // ref gtkstyle.c draw_flat_box
265         GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
266         GdkColor *gtkAltBase = NULL;
267         d->gtk_widget_style_get(gtkTreeView, "odd-row-color", &gtkAltBase, NULL);
268         if (gtkAltBase) {
269             alternateRowColor = QColor(gtkAltBase->red>>8, gtkAltBase->green>>8, gtkAltBase->blue>>8);
270             d->gdk_color_free(gtkAltBase);
271         }
272         palette.setColor(QPalette::AlternateBase, alternateRowColor);
273 
274         palette.setColor(QPalette::Window, bg);
275         palette.setColor(QPalette::Button, bg);
276         palette.setColor(QPalette::Background, bg);
277         QColor disabled((fg.red()   + bg.red())  / 2,
278                         (fg.green() + bg.green())/ 2,
279                         (fg.blue()  + bg.blue()) / 2);
280         palette.setColor(QPalette::Disabled, QPalette::Text, disabled);
281         palette.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
282         palette.setColor(QPalette::Disabled, QPalette::Foreground, disabled);
283         palette.setColor(QPalette::Disabled, QPalette::ButtonText, disabled);
284         palette.setColor(QPalette::Highlight, highlight);
285         // calculate disabled colors by removing saturation
286         highlight.setHsv(highlight.hue(), 0, highlight.value(), highlight.alpha());
287         highlightText.setHsv(highlightText.hue(), 0, highlightText.value(), highlightText.alpha());
288         palette.setColor(QPalette::Disabled, QPalette::Highlight, highlight);
289         palette.setColor(QPalette::Disabled, QPalette::HighlightedText, highlightText);
290 
291         palette.setColor(QPalette::Inactive, QPalette::HighlightedText, inactiveHighlightedTExt);
292         palette.setColor(QPalette::Inactive, QPalette::Highlight, inactiveHighlight);
293 
294         style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow",
295                 d->gtk_window_get_type());
296         if (style) {
297             gdkText = style->fg[GTK_STATE_NORMAL];
298             text = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
299             palette.setColor(QPalette::ToolTipText, text);
300         }
301     }
302     return palette;
303 }
304 
305 /*!
306     \reimp
307 */
polish(QPalette & palette)308 void QGtkStyle::polish(QPalette &palette)
309 {
310     Q_D(QGtkStyle);
311 
312     // QCleanlooksStyle will alter the palette, hence we do
313     // not want to polish the palette unless we are using it as
314     // the fallback
315     if (!d->isThemeAvailable())
316         QCleanlooksStyle::polish(palette);
317     else
318         palette = palette.resolve(standardPalette());
319 }
320 
321 /*!
322     \reimp
323 */
polish(QApplication * app)324 void QGtkStyle::polish(QApplication *app)
325 {
326     Q_D(QGtkStyle);
327 
328     QCleanlooksStyle::polish(app);
329     // Custom fonts and palettes with QtConfig are intentionally
330     // not supported as these should be entirely determined by
331     // current Gtk settings
332     if (app->desktopSettingsAware() && d->isThemeAvailable()) {
333         QApplicationPrivate::setSystemPalette(standardPalette());
334         QApplicationPrivate::setSystemFont(d->getThemeFont());
335         d->applyCustomPaletteHash();
336         if (!d->isKDE4Session()) {
337             qt_filedialog_open_filename_hook = &QGtkStylePrivate::openFilename;
338             qt_filedialog_save_filename_hook = &QGtkStylePrivate::saveFilename;
339             qt_filedialog_open_filenames_hook = &QGtkStylePrivate::openFilenames;
340             qt_filedialog_existing_directory_hook = &QGtkStylePrivate::openDirectory;
341             qApp->installEventFilter(&d->filter);
342         }
343     }
344 }
345 
346 /*!
347     \reimp
348 */
unpolish(QApplication * app)349 void QGtkStyle::unpolish(QApplication *app)
350 {
351     Q_D(QGtkStyle);
352 
353     QCleanlooksStyle::unpolish(app);
354     QPixmapCache::clear();
355 
356     if (app->desktopSettingsAware() && d->isThemeAvailable()
357         && !d->isKDE4Session()) {
358         qt_filedialog_open_filename_hook = 0;
359         qt_filedialog_save_filename_hook = 0;
360         qt_filedialog_open_filenames_hook = 0;
361         qt_filedialog_existing_directory_hook = 0;
362         qApp->removeEventFilter(&d->filter);
363     }
364 }
365 
366 /*!
367     \reimp
368 */
369 
polish(QWidget * widget)370 void QGtkStyle::polish(QWidget *widget)
371 {
372     Q_D(QGtkStyle);
373 
374     QCleanlooksStyle::polish(widget);
375     if (!d->isThemeAvailable())
376         return;
377     if (qobject_cast<QAbstractButton*>(widget)
378             || qobject_cast<QToolButton*>(widget)
379             || qobject_cast<QComboBox*>(widget)
380             || qobject_cast<QGroupBox*>(widget)
381             || qobject_cast<QScrollBar*>(widget)
382             || qobject_cast<QSlider*>(widget)
383             || qobject_cast<QAbstractSpinBox*>(widget)
384             || qobject_cast<QSpinBox*>(widget)
385             || qobject_cast<QHeaderView*>(widget))
386         widget->setAttribute(Qt::WA_Hover);
387     else if (QTreeView *tree = qobject_cast<QTreeView *> (widget))
388         tree->viewport()->setAttribute(Qt::WA_Hover);
389 }
390 
391 /*!
392     \reimp
393 */
unpolish(QWidget * widget)394 void QGtkStyle::unpolish(QWidget *widget)
395 {
396     QCleanlooksStyle::unpolish(widget);
397 }
398 
399 /*!
400     \reimp
401 */
pixelMetric(PixelMetric metric,const QStyleOption * option,const QWidget * widget) const402 int QGtkStyle::pixelMetric(PixelMetric metric,
403                            const QStyleOption *option,
404                            const QWidget *widget) const
405 {
406     Q_D(const QGtkStyle);
407 
408     if (!d->isThemeAvailable())
409         return QCleanlooksStyle::pixelMetric(metric, option, widget);
410 
411     switch (metric) {
412     case PM_DefaultFrameWidth:
413         if (qobject_cast<const QFrame*>(widget)) {
414             if (GtkStyle *style =
415                 d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(),
416                                                 "*.GtkScrolledWindow",
417                                                 "*.GtkScrolledWindow",
418                                                 d->gtk_window_get_type()))
419                 return qMax(style->xthickness, style->ythickness);
420         }
421         return 2;
422 
423     case PM_MenuButtonIndicator:
424         return 20;
425 
426     case PM_TabBarBaseOverlap:
427         return 1;
428 
429     case PM_ToolBarSeparatorExtent:
430         return 11;
431 
432     case PM_ToolBarFrameWidth:
433         return 1;
434 
435     case PM_ToolBarItemSpacing:
436         return 0;
437 
438     case PM_ButtonShiftHorizontal: {
439         GtkWidget *gtkButton = d->gtkWidget("GtkButton");
440         guint horizontal_shift;
441         d->gtk_widget_style_get(gtkButton, "child-displacement-x", &horizontal_shift, NULL);
442         return horizontal_shift;
443     }
444 
445     case PM_ButtonShiftVertical: {
446         GtkWidget *gtkButton = d->gtkWidget("GtkButton");
447         guint vertical_shift;
448         d->gtk_widget_style_get(gtkButton, "child-displacement-y", &vertical_shift, NULL);
449         return vertical_shift;
450     }
451 
452     case PM_MenuBarPanelWidth:
453         return 0;
454 
455     case PM_MenuPanelWidth: {
456         GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
457         guint horizontal_padding = 0;
458         // horizontal-padding is used by Maemo to get thicker borders
459         if (!d->gtk_check_version(2, 10, 0))
460             d->gtk_widget_style_get(gtkMenu, "horizontal-padding", &horizontal_padding, NULL);
461         int padding = qMax<int>(gtkMenu->style->xthickness, horizontal_padding);
462         return padding;
463     }
464 
465     case PM_ButtonIconSize: {
466         int retVal = 24;
467         GtkSettings *settings = d->gtk_settings_get_default();
468         gchararray icon_sizes;
469         g_object_get(settings, "gtk-icon-sizes", &icon_sizes, NULL);
470         QStringList values = QString(QLS(icon_sizes)).split(QLatin1Char(':'));
471         g_free(icon_sizes);
472         QChar splitChar(QLatin1Char(','));
473         foreach (const QString &value, values) {
474             if (value.startsWith(QLS("gtk-button="))) {
475                 QString iconSize = value.right(value.size() - 11);
476 
477                 if (iconSize.contains(splitChar))
478                     retVal = iconSize.split(splitChar)[0].toInt();
479                 break;
480             }
481         }
482         return retVal;
483     }
484 
485     case PM_MenuVMargin:
486 
487     case PM_MenuHMargin:
488         return 0;
489 
490     case PM_DockWidgetTitleMargin:
491         return 0;
492 
493     case PM_DockWidgetTitleBarButtonMargin:
494         return 5;
495 
496     case PM_TabBarTabVSpace:
497         return 12;
498 
499     case PM_TabBarTabHSpace:
500         return 14;
501 
502     case PM_TabBarTabShiftVertical:
503         return 2;
504 
505     case PM_ToolBarHandleExtent:
506         return 9;
507 
508     case PM_SplitterWidth:
509         return 6;
510 
511     case PM_SliderThickness:
512     case PM_SliderControlThickness: {
513         GtkWidget *gtkScale = d->gtkWidget("GtkHScale");
514         gint val;
515         d->gtk_widget_style_get(gtkScale, "slider-width", &val, NULL);
516         if (metric == PM_SliderControlThickness)
517             return val + 2*gtkScale->style->ythickness;
518         return val;
519     }
520 
521     case PM_ScrollBarExtent: {
522         gint sliderLength;
523         gint trough_border;
524         GtkWidget *hScrollbar = d->gtkWidget("GtkHScrollbar");
525         d->gtk_widget_style_get(hScrollbar,
526                                "trough-border",   &trough_border,
527                                "slider-width",    &sliderLength,
528                                NULL);
529         return sliderLength + trough_border*2;
530     }
531 
532     case PM_ScrollBarSliderMin:
533         return 34;
534 
535     case PM_SliderLength:
536         gint val;
537         d->gtk_widget_style_get(d->gtkWidget("GtkHScale"), "slider-length", &val, NULL);
538         return val;
539 
540     case PM_ExclusiveIndicatorWidth:
541     case PM_ExclusiveIndicatorHeight:
542     case PM_IndicatorWidth:
543     case PM_IndicatorHeight: {
544         GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
545         gint size, spacing;
546         d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, "indicator-size", &size, NULL);
547         return size + 2 * spacing;
548     }
549 
550     case PM_MenuBarVMargin: {
551         GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
552         return  qMax(0, gtkMenubar->style->ythickness);
553     }
554     case PM_ScrollView_ScrollBarSpacing:
555     {
556         gint spacing = 3;
557         GtkWidget *gtkScrollWindow = d->gtkWidget("GtkScrolledWindow");
558         Q_ASSERT(gtkScrollWindow);
559         d->gtk_widget_style_get(gtkScrollWindow, "scrollbar-spacing", &spacing, NULL);
560         return spacing;
561     }
562     case PM_SubMenuOverlap: {
563         gint offset = 0;
564         GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
565         d->gtk_widget_style_get(gtkMenu, "horizontal-offset", &offset, NULL);
566         return offset;
567     }
568     default:
569         return QCleanlooksStyle::pixelMetric(metric, option, widget);
570     }
571 }
572 
573 /*!
574     \reimp
575 */
styleHint(StyleHint hint,const QStyleOption * option,const QWidget * widget,QStyleHintReturn * returnData=0) const576 int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
577 
578                          QStyleHintReturn *returnData = 0) const
579 {
580     Q_D(const QGtkStyle);
581 
582     if (!d->isThemeAvailable())
583         return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
584 
585     switch (hint) {
586 
587     case SH_DialogButtonLayout: {
588         int ret = QDialogButtonBox::GnomeLayout;
589         gboolean alternateOrder = 0;
590         GtkSettings *settings = d->gtk_settings_get_default();
591         g_object_get(settings, "gtk-alternative-button-order", &alternateOrder, NULL);
592 
593         if (alternateOrder)
594             ret = QDialogButtonBox::WinLayout;
595 
596         return ret;
597     }
598 
599     break;
600 
601     case SH_ToolButtonStyle:
602     {
603         if (d->isKDE4Session())
604             return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
605         GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
606         GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS;
607         g_object_get(gtkToolbar, "toolbar-style", &toolbar_style, NULL);
608         switch (toolbar_style) {
609         case GTK_TOOLBAR_TEXT:
610             return Qt::ToolButtonTextOnly;
611         case GTK_TOOLBAR_BOTH:
612             return Qt::ToolButtonTextUnderIcon;
613         case GTK_TOOLBAR_BOTH_HORIZ:
614             return Qt::ToolButtonTextBesideIcon;
615         case GTK_TOOLBAR_ICONS:
616         default:
617             return Qt::ToolButtonIconOnly;
618         }
619     }
620     break;
621     case SH_SpinControls_DisableOnBounds:
622         return int(true);
623 
624     case SH_DitherDisabledText:
625         return int(false);
626 
627     case SH_ComboBox_Popup: {
628         GtkWidget *gtkComboBox = d->gtkWidget("GtkComboBox");
629         gboolean appears_as_list;
630         d->gtk_widget_style_get((GtkWidget*)gtkComboBox, "appears-as-list", &appears_as_list, NULL);
631         return appears_as_list ? 0 : 1;
632     }
633 
634     case SH_MenuBar_AltKeyNavigation:
635         return int(false);
636 
637     case SH_EtchDisabledText:
638         return int(false);
639 
640     case SH_Menu_SubMenuPopupDelay: {
641         gint delay = 225;
642         GtkSettings *settings = d->gtk_settings_get_default();
643         g_object_get(settings, "gtk-menu-popup-delay", &delay, NULL);
644         return delay;
645     }
646 
647     case SH_ScrollView_FrameOnlyAroundContents: {
648         gboolean scrollbars_within_bevel = false;
649         if (widget && widget->isWindow())
650             scrollbars_within_bevel = true;
651         else if (!d->gtk_check_version(2, 12, 0)) {
652             GtkWidget *gtkScrollWindow = d->gtkWidget("GtkScrolledWindow");
653             d->gtk_widget_style_get(gtkScrollWindow, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
654         }
655         return !scrollbars_within_bevel;
656     }
657 
658     case SH_DialogButtonBox_ButtonsHaveIcons: {
659         static bool buttonsHaveIcons = d->getGConfBool(QLS("/desktop/gnome/interface/buttons_have_icons"));
660         return buttonsHaveIcons;
661     }
662 
663     case SH_UnderlineShortcut: {
664         gboolean underlineShortcut = true;
665         if (!d->gtk_check_version(2, 12, 0)) {
666             GtkSettings *settings = d->gtk_settings_get_default();
667             g_object_get(settings, "gtk-enable-mnemonics", &underlineShortcut, NULL);
668         }
669         return underlineShortcut;
670     }
671 
672     default:
673         return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
674     }
675 }
676 
677 /*!
678     \reimp
679 */
drawPrimitive(PrimitiveElement element,const QStyleOption * option,QPainter * painter,const QWidget * widget) const680 void QGtkStyle::drawPrimitive(PrimitiveElement element,
681                               const QStyleOption *option,
682                               QPainter *painter,
683                               const QWidget *widget) const
684 {
685     Q_D(const QGtkStyle);
686 
687     if (!d->isThemeAvailable()) {
688         QCleanlooksStyle::drawPrimitive(element, option, painter, widget);
689         return;
690     }
691 
692     GtkStyle* style = d->gtkStyle();
693     QGtkPainter gtkPainter(painter);
694 
695     switch (element) {
696       case PE_Frame: {
697         if (widget && widget->inherits("QComboBoxPrivateContainer")){
698             QStyleOption copy = *option;
699             copy.state |= State_Raised;
700             proxy()->drawPrimitive(PE_PanelMenu, &copy, painter, widget);
701             break;
702         }
703         // Drawing the entire itemview frame is very expensive, especially on the native X11 engine
704         // Instead we cheat a bit and draw a border image without the center part, hence only scaling
705         // thin rectangular images
706         const int pmSize = 64;
707         const int border = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
708         const QString pmKey = QLatin1Literal("windowframe") % HexString<uint>(option->state);
709 
710         QPixmap pixmap;
711         QRect pmRect(QPoint(0,0), QSize(pmSize, pmSize));
712 
713         // Only draw through style once
714         if (!QPixmapCache::find(pmKey, pixmap)) {
715             pixmap = QPixmap(pmSize, pmSize);
716             pixmap.fill(Qt::transparent);
717             QPainter pmPainter(&pixmap);
718             QGtkPainter gtkFramePainter(&pmPainter);
719             gtkFramePainter.setUsePixmapCache(false); // Don't cache twice
720 
721             GtkShadowType shadow_type = GTK_SHADOW_NONE;
722             if (option->state & State_Sunken)
723                 shadow_type = GTK_SHADOW_IN;
724             else if (option->state & State_Raised)
725                 shadow_type = GTK_SHADOW_OUT;
726 
727             GtkStyle *style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(),
728                                      "*.GtkScrolledWindow", "*.GtkScrolledWindow", d->gtk_window_get_type());
729             if (style)
730                 gtkFramePainter.paintShadow(d->gtkWidget("GtkFrame"), "viewport", pmRect,
731                                          option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
732                                          shadow_type, style);
733             QPixmapCache::insert(pmKey, pixmap);
734         }
735 
736         QRect rect = option->rect;
737         const int rw = rect.width() - border;
738         const int rh = rect.height() - border;
739         const int pw = pmRect.width() - border;
740         const int ph = pmRect.height() - border;
741 
742         // Sidelines
743         painter->drawPixmap(rect.adjusted(border, 0, -border, -rh), pixmap, pmRect.adjusted(border, 0, -border,-ph));
744         painter->drawPixmap(rect.adjusted(border, rh, -border, 0), pixmap, pmRect.adjusted(border, ph,-border,0));
745         painter->drawPixmap(rect.adjusted(0, border, -rw, -border), pixmap, pmRect.adjusted(0, border, -pw, -border));
746         painter->drawPixmap(rect.adjusted(rw, border, 0, -border), pixmap, pmRect.adjusted(pw, border, 0, -border));
747 
748         // Corners
749         painter->drawPixmap(rect.adjusted(0, 0, -rw, -rh), pixmap, pmRect.adjusted(0, 0, -pw,-ph));
750         painter->drawPixmap(rect.adjusted(rw, 0, 0, -rh), pixmap, pmRect.adjusted(pw, 0, 0,-ph));
751         painter->drawPixmap(rect.adjusted(0, rh, -rw, 0), pixmap, pmRect.adjusted(0, ph, -pw,0));
752         painter->drawPixmap(rect.adjusted(rw, rh, 0, 0), pixmap, pmRect.adjusted(pw, ph, 0,0));
753     }
754     break;
755 
756     case PE_PanelTipLabel: {
757         GtkWidget *gtkWindow = d->gtkWidget("GtkWindow"); // The Murrine Engine currently assumes a widget is passed
758         style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow",
759                 d->gtk_window_get_type());
760         gtkPainter.paintFlatBox(gtkWindow, "tooltip", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, style);
761     }
762     break;
763 
764     case PE_PanelStatusBar: {
765         if (widget && widget->testAttribute(Qt::WA_SetPalette) &&
766             option->palette.resolve() & (1 << QPalette::Window)) {
767             // Respect custom palette
768             painter->fillRect(option->rect, option->palette.window());
769             break;
770         }
771         GtkShadowType shadow_type;
772         GtkWidget *gtkStatusbarFrame = d->gtkWidget("GtkStatusbar.GtkFrame");
773         d->gtk_widget_style_get(gtkStatusbarFrame->parent, "shadow-type", &shadow_type, NULL);
774         gtkPainter.paintShadow(gtkStatusbarFrame, "frame", option->rect, GTK_STATE_NORMAL,
775                                shadow_type, gtkStatusbarFrame->style);
776     }
777     break;
778 
779     case PE_IndicatorHeaderArrow:
780         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
781             GtkWidget *gtkTreeHeader = d->gtkWidget("GtkTreeView.GtkButton");
782             GtkStateType state = gtkPainter.gtkState(option);
783             style = gtkTreeHeader->style;
784             GtkArrowType type = GTK_ARROW_UP;
785             QImage arrow;
786             // This sorting indicator inversion is intentional, and follows the GNOME HIG.
787             // See http://library.gnome.org/devel/hig-book/stable/controls-lists.html.en#controls-lists-sortable
788             if (header->sortIndicator & QStyleOptionHeader::SortUp)
789                 type = GTK_ARROW_UP;
790             else if (header->sortIndicator & QStyleOptionHeader::SortDown)
791                 type = GTK_ARROW_DOWN;
792 
793             gtkPainter.paintArrow(gtkTreeHeader, "button", option->rect.adjusted(1, 1, -1, -1), type, state,
794                                   GTK_SHADOW_NONE, FALSE, style);
795         }
796         break;
797 
798     case PE_FrameFocusRect:
799         if (!widget || qobject_cast<const QAbstractItemView*>(widget))
800             QCleanlooksStyle::drawPrimitive(element, option, painter, widget);
801         else {
802             // ### this mess should move to subcontrolrect
803             QRect frameRect = option->rect.adjusted(1, 1, -1, -2);
804 
805             if (qobject_cast<const QTabBar*>(widget)) {
806                 GtkWidget *gtkNotebook = d->gtkWidget("GtkNotebook");
807                 style = gtkPainter.getStyle(gtkNotebook);
808                 gtkPainter.paintFocus(gtkNotebook, "tab", frameRect.adjusted(-1, 1, 1, 1), GTK_STATE_ACTIVE, style);
809             } else {
810                 gtkPainter.paintFocus(NULL, "tab", frameRect, GTK_STATE_ACTIVE, style);
811             }
812         }
813         break;
814 
815     case PE_IndicatorBranch:
816         if (option->state & State_Children) {
817             QRect rect = option->rect;
818             rect = QRect(0, 0, 12, 12);
819             rect.moveCenter(option->rect.center());
820             rect.translate(2, 0);
821             GtkExpanderStyle openState = GTK_EXPANDER_EXPANDED;
822             GtkExpanderStyle closedState = GTK_EXPANDER_COLLAPSED;
823             GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
824 
825             GtkStateType state = GTK_STATE_NORMAL;
826             if (!(option->state & State_Enabled))
827                 state = GTK_STATE_INSENSITIVE;
828             else if (option->state & State_MouseOver)
829                 state = GTK_STATE_PRELIGHT;
830 
831             gtkPainter.paintExpander(gtkTreeView, "treeview", rect, state,
832                                      option->state & State_Open ? openState : closedState , gtkTreeView->style);
833         }
834         break;
835 
836     case PE_PanelItemViewRow:
837         // This primitive is only used to draw selection behind selected expander arrows.
838         // We try not to decorate the tree branch background unless you inherit from StyledItemDelegate
839         // The reason for this is that a lot of code that relies on custom item delegates will look odd having
840         // a gradient on the branch but a flat shaded color on the item itself.
841         QCommonStyle::drawPrimitive(element, option, painter, widget);
842         if (!option->state & State_Selected) {
843             break;
844         } else {
845             if (const QAbstractItemView *view = qobject_cast<const QAbstractItemView*>(widget)) {
846                 if (!qobject_cast<QStyledItemDelegate*>(view->itemDelegate()))
847                     break;
848             }
849         } // fall through
850 
851     case PE_PanelItemViewItem:
852         if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(option)) {
853             uint resolve_mask = vopt->palette.resolve();
854             if (vopt->backgroundBrush.style() != Qt::NoBrush
855                     || (resolve_mask & (1 << QPalette::Base)))
856             {
857                 QPointF oldBO = painter->brushOrigin();
858                 painter->setBrushOrigin(vopt->rect.topLeft());
859                 painter->fillRect(vopt->rect, vopt->backgroundBrush);
860                 painter->setBrushOrigin(oldBO);
861                 if (!(option->state & State_Selected))
862                     break;
863             }
864             if (GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView")) {
865                 const char *detail = "cell_even_ruled";
866                 if (vopt && vopt->features & QStyleOptionViewItemV2::Alternate)
867                     detail = "cell_odd_ruled";
868                 bool isActive = option->state & State_Active;
869                 QString key;
870                 if (isActive ) {
871                     // Required for active/non-active window appearance
872                     key = QLS("a");
873                     GTK_WIDGET_SET_FLAGS(gtkTreeView, GTK_HAS_FOCUS);
874                 }
875                 bool isEnabled = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled));
876                 gtkPainter.paintFlatBox(gtkTreeView, detail, option->rect,
877                                         option->state & State_Selected ? GTK_STATE_SELECTED :
878                                         isEnabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
879                                         GTK_SHADOW_OUT, gtkTreeView->style, key);
880                 if (isActive )
881                     GTK_WIDGET_UNSET_FLAGS(gtkTreeView, GTK_HAS_FOCUS);
882             }
883         }
884         break;
885     case PE_IndicatorToolBarSeparator:
886         {
887             const int margin = 6;
888             GtkWidget *gtkSeparator = d->gtkWidget("GtkToolbar.GtkSeparatorToolItem");
889             if (option->state & State_Horizontal) {
890                 const int offset = option->rect.width()/2;
891                 QRect rect = option->rect.adjusted(offset, margin, 0, -margin);
892                 painter->setPen(QPen(option->palette.background().color().darker(110)));
893                 gtkPainter.paintVline( gtkSeparator, "vseparator",
894                                        rect, GTK_STATE_NORMAL, gtkSeparator->style,
895                                        0, rect.height(), 0);
896             } else { //Draw vertical separator
897                 const int offset = option->rect.height()/2;
898                 QRect rect = option->rect.adjusted(margin, offset, -margin, 0);
899                 painter->setPen(QPen(option->palette.background().color().darker(110)));
900                 gtkPainter.paintHline( gtkSeparator, "hseparator",
901                                        rect, GTK_STATE_NORMAL, gtkSeparator->style,
902                                        0, rect.width(), 0);
903             }
904        }
905        break;
906 
907     case PE_IndicatorToolBarHandle: {
908         GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
909         GtkShadowType shadow_type;
910         d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
911         //Note when the toolbar is horizontal, the handle is vertical
912         painter->setClipRect(option->rect);
913         gtkPainter.paintHandle(gtkToolbar, "toolbar", option->rect.adjusted(-1, -1 ,0 ,1),
914                                GTK_STATE_NORMAL, shadow_type, !(option->state & State_Horizontal) ?
915                                GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, gtkToolbar->style);
916     }
917     break;
918 
919     case PE_IndicatorArrowUp:
920     case PE_IndicatorArrowDown:
921     case PE_IndicatorArrowLeft:
922     case PE_IndicatorArrowRight: {
923 
924 
925         GtkArrowType type = GTK_ARROW_UP;
926 
927         switch (element) {
928 
929         case PE_IndicatorArrowDown:
930             type = GTK_ARROW_DOWN;
931             break;
932 
933         case PE_IndicatorArrowLeft:
934             type = GTK_ARROW_LEFT;
935             break;
936 
937         case PE_IndicatorArrowRight:
938             type = GTK_ARROW_RIGHT;
939             break;
940 
941         default:
942             break;
943         }
944         int size = qMin(option->rect.height(), option->rect.width());
945         int border = (size > 9) ? (size/4) : 0; //Allow small arrows to have exact dimensions
946         int bsx = 0, bsy = 0;
947         if (option->state & State_Sunken) {
948             bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal);
949             bsy = proxy()->pixelMetric(PM_ButtonShiftVertical);
950         }
951         QRect arrowRect = option->rect.adjusted(border + bsx, border + bsy, -border + bsx, -border + bsy);
952         GtkShadowType shadow = option->state & State_Sunken ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
953         GtkStateType state = gtkPainter.gtkState(option);
954 
955         QColor arrowColor = option->palette.buttonText().color();
956         GtkWidget *gtkArrow = d->gtkWidget("GtkArrow");
957         GdkColor color = fromQColor(arrowColor);
958         d->gtk_widget_modify_fg (gtkArrow, state, &color);
959         gtkPainter.paintArrow(gtkArrow, "button", arrowRect,
960                               type, state, shadow, FALSE, gtkArrow->style,
961                               QString::number(arrowColor.rgba(), 16));
962         // Passing NULL will revert the color change
963         d->gtk_widget_modify_fg (gtkArrow, state, NULL);
964     }
965     break;
966 
967     case PE_FrameGroupBox:
968         // Do nothing here, the GNOME groupboxes are flat
969         break;
970 
971     case PE_PanelMenu: {
972             GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
973             gtkPainter.setAlphaSupport(false); // Note, alpha disabled for performance reasons
974             gtkPainter.paintBox(gtkMenu, "menu", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, gtkMenu->style, QString());
975         }
976         break;
977 
978     case PE_FrameMenu:
979         //This is actually done by PE_Widget due to a clipping issue
980         //Otherwise Menu items will not be able to span the entire menu width
981 
982         // This is only used by floating tool bars
983         if (qobject_cast<const QToolBar *>(widget)) {
984             GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
985             gtkPainter.paintBox( gtkMenubar, "toolbar",  option->rect,
986                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
987             gtkPainter.paintBox( gtkMenubar, "menu",  option->rect,
988                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
989         }
990         break;
991 
992     case PE_FrameLineEdit: {
993         GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
994 
995 
996         gboolean interior_focus;
997         gint focus_line_width;
998         QRect rect = option->rect;
999         d->gtk_widget_style_get(gtkEntry,
1000                                "interior-focus", &interior_focus,
1001                                "focus-line-width", &focus_line_width, NULL);
1002 
1003         // See https://bugzilla.mozilla.org/show_bug.cgi?id=405421 for info about this hack
1004         g_object_set_data(G_OBJECT(gtkEntry), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
1005 
1006         if (!interior_focus && option->state & State_HasFocus)
1007             rect.adjust(focus_line_width, focus_line_width, -focus_line_width, -focus_line_width);
1008 
1009         if (option->state & State_HasFocus)
1010             GTK_WIDGET_SET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1011         gtkPainter.paintShadow(gtkEntry, "entry", rect, option->state & State_Enabled ?
1012                                GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
1013                                GTK_SHADOW_IN, gtkEntry->style,
1014                                option->state & State_HasFocus ? QLS("focus") : QString());
1015         if (!interior_focus && option->state & State_HasFocus)
1016             gtkPainter.paintShadow(gtkEntry, "entry", option->rect, option->state & State_Enabled ?
1017                                    GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1018                                    GTK_SHADOW_IN, gtkEntry->style, QLS("GtkEntryShadowIn"));
1019 
1020         if (option->state & State_HasFocus)
1021             GTK_WIDGET_UNSET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1022     }
1023     break;
1024 
1025     case PE_PanelLineEdit:
1026         if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
1027             GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
1028             if (panel->lineWidth > 0)
1029                 proxy()->drawPrimitive(PE_FrameLineEdit, option, painter, widget);
1030             uint resolve_mask = option->palette.resolve();
1031             QRect textRect = option->rect.adjusted(gtkEntry->style->xthickness, gtkEntry->style->ythickness,
1032                                                    -gtkEntry->style->xthickness, -gtkEntry->style->ythickness);
1033 
1034             if (widget && widget->testAttribute(Qt::WA_SetPalette) &&
1035                 resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
1036                 painter->fillRect(textRect, option->palette.base());
1037             else
1038                 gtkPainter.paintFlatBox( gtkEntry, "entry_bg", textRect,
1039                                          option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_NONE, gtkEntry->style);
1040         }
1041         break;
1042 
1043     case PE_FrameTabWidget:
1044         if (const QStyleOptionTabWidgetFrame *frame = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option)) {
1045             GtkWidget *gtkNotebook = d->gtkWidget("GtkNotebook");
1046             style = gtkPainter.getStyle(gtkNotebook);
1047             gtkPainter.setAlphaSupport(false);
1048             GtkShadowType shadow = GTK_SHADOW_OUT;
1049             GtkStateType state = GTK_STATE_NORMAL; // Only state supported by gtknotebook
1050             bool reverse = (option->direction == Qt::RightToLeft);
1051             QGtkStylePrivate::gtk_widget_set_direction(gtkNotebook, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1052             if (const QStyleOptionTabWidgetFrameV2 *tabframe = qstyleoption_cast<const QStyleOptionTabWidgetFrameV2*>(option)) {
1053                 GtkPositionType frameType = GTK_POS_TOP;
1054                 QTabBar::Shape shape = frame->shape;
1055                 int gapStart = 0;
1056                 int gapSize = 0;
1057                 if (shape == QTabBar::RoundedNorth || shape == QTabBar::RoundedSouth) {
1058                     frameType = (shape == QTabBar::RoundedNorth) ? GTK_POS_TOP : GTK_POS_BOTTOM;
1059                     gapStart = tabframe->selectedTabRect.left();
1060                     gapSize = tabframe->selectedTabRect.width();
1061                 } else {
1062                     frameType = (shape == QTabBar::RoundedWest) ? GTK_POS_LEFT : GTK_POS_RIGHT;
1063                     gapStart = tabframe->selectedTabRect.y();
1064                     gapSize = tabframe->selectedTabRect.height();
1065                 }
1066                 gtkPainter.paintBoxGap(gtkNotebook, "notebook",  option->rect, state, shadow, frameType,
1067                                         gapStart, gapSize, style);
1068                 break; // done
1069             }
1070 
1071             // Note this is only the fallback option
1072             gtkPainter.paintBox(gtkNotebook, "notebook",  option->rect, state, shadow, style);
1073         }
1074         break;
1075 
1076     case PE_PanelButtonCommand:
1077     case PE_PanelButtonTool: {
1078         bool isDefault = false;
1079         bool isTool = (element == PE_PanelButtonTool);
1080         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton*>(option))
1081             isDefault = btn->features & QStyleOptionButton::DefaultButton;
1082 
1083         // don't draw a frame for tool buttons that have the autoRaise flag and are not enabled or on
1084         if (isTool && !(option->state & State_Enabled || option->state & State_On) && (option->state & State_AutoRaise))
1085             break;
1086         // don't draw a frame for dock widget buttons, unless we are hovering
1087         if (widget && widget->inherits("QDockWidgetTitleButton") && !(option->state & State_MouseOver))
1088             break;
1089 
1090         GtkStateType state = gtkPainter.gtkState(option);
1091         if (option->state & State_On || option->state & State_Sunken)
1092             state = GTK_STATE_ACTIVE;
1093         GtkWidget *gtkButton = isTool ? d->gtkWidget("GtkToolButton.GtkButton") : d->gtkWidget("GtkButton");
1094         gint focusWidth, focusPad;
1095         gboolean interiorFocus = false;
1096         d->gtk_widget_style_get (gtkButton,
1097                                 "focus-line-width", &focusWidth,
1098                                 "focus-padding", &focusPad,
1099                                 "interior-focus", &interiorFocus, NULL);
1100 
1101         style = gtkButton->style;
1102 
1103         QRect buttonRect = option->rect;
1104 
1105         QString key;
1106         if (isDefault) {
1107             key += QLS("def");
1108             GTK_WIDGET_SET_FLAGS(gtkButton, GTK_HAS_DEFAULT);
1109             gtkPainter.paintBox(gtkButton, "buttondefault", buttonRect, state, GTK_SHADOW_IN,
1110                                 style, isDefault ? QLS("d") : QString());
1111         }
1112 
1113         bool hasFocus = option->state & State_HasFocus;
1114 
1115         if (hasFocus) {
1116             key += QLS("def");
1117             GTK_WIDGET_SET_FLAGS(gtkButton, GTK_HAS_FOCUS);
1118         }
1119 
1120         if (!interiorFocus)
1121             buttonRect = buttonRect.adjusted(focusWidth, focusWidth, -focusWidth, -focusWidth);
1122 
1123         GtkShadowType shadow = (option->state & State_Sunken || option->state & State_On ) ?
1124                                GTK_SHADOW_IN : GTK_SHADOW_OUT;
1125 
1126         gtkPainter.paintBox(gtkButton, "button", buttonRect, state, shadow,
1127                             style, key);
1128         if (isDefault)
1129             GTK_WIDGET_UNSET_FLAGS(gtkButton, GTK_HAS_DEFAULT);
1130         if (hasFocus)
1131             GTK_WIDGET_UNSET_FLAGS(gtkButton, GTK_HAS_FOCUS);
1132     }
1133     break;
1134 
1135     case PE_IndicatorRadioButton: {
1136         GtkShadowType shadow = GTK_SHADOW_OUT;
1137         GtkStateType state = gtkPainter.gtkState(option);
1138 
1139         if (option->state & State_Sunken)
1140             state = GTK_STATE_ACTIVE;
1141 
1142         if (option->state & State_NoChange)
1143             shadow = GTK_SHADOW_ETCHED_IN;
1144         else if (option->state & State_On)
1145             shadow = GTK_SHADOW_IN;
1146         else
1147             shadow = GTK_SHADOW_OUT;
1148 
1149         GtkWidget *gtkRadioButton = d->gtkWidget("GtkRadioButton");
1150         gint spacing;
1151         d->gtk_widget_style_get(gtkRadioButton, "indicator-spacing", &spacing, NULL);
1152         QRect buttonRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
1153         gtkPainter.setClipRect(option->rect);
1154         // ### Note: Ubuntulooks breaks when the proper widget is passed
1155         //           Murrine engine requires a widget not to get RGBA check - warnings
1156         GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
1157         QString key(QLS("radiobutton"));
1158         if (option->state & State_HasFocus) { // Themes such as Nodoka check this flag
1159             key += QLatin1Char('f');
1160             GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1161         }
1162         gtkPainter.paintOption(gtkCheckButton , buttonRect, state, shadow, gtkRadioButton->style, key);
1163         if (option->state & State_HasFocus)
1164             GTK_WIDGET_UNSET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1165     }
1166     break;
1167 
1168     case PE_IndicatorCheckBox: {
1169         GtkShadowType shadow = GTK_SHADOW_OUT;
1170         GtkStateType state = gtkPainter.gtkState(option);
1171 
1172         if (option->state & State_Sunken)
1173             state = GTK_STATE_ACTIVE;
1174 
1175         if (option->state & State_NoChange)
1176             shadow = GTK_SHADOW_ETCHED_IN;
1177         else if (option->state & State_On)
1178             shadow = GTK_SHADOW_IN;
1179         else
1180             shadow = GTK_SHADOW_OUT;
1181 
1182         int spacing;
1183 
1184         GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
1185         QString key(QLS("checkbutton"));
1186         if (option->state & State_HasFocus) { // Themes such as Nodoka checks this flag
1187             key += QLatin1Char('f');
1188             GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1189         }
1190 
1191         // Some styles such as aero-clone assume they can paint in the spacing area
1192         gtkPainter.setClipRect(option->rect);
1193 
1194         d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, NULL);
1195 
1196         QRect checkRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
1197 
1198         gtkPainter.paintCheckbox(gtkCheckButton, checkRect, state, shadow, gtkCheckButton->style,
1199                                  key);
1200         if (option->state & State_HasFocus)
1201             GTK_WIDGET_UNSET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1202 
1203     }
1204     break;
1205 
1206 #ifndef QT_NO_TABBAR
1207 
1208     case PE_FrameTabBarBase:
1209         if (const QStyleOptionTabBarBase *tbb
1210                 = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) {
1211             QRect tabRect = tbb->rect;
1212             painter->save();
1213             painter->setPen(QPen(option->palette.dark().color().dark(110), 0));
1214             switch (tbb->shape) {
1215 
1216             case QTabBar::RoundedNorth:
1217                 painter->drawLine(tabRect.topLeft(), tabRect.topRight());
1218                 break;
1219 
1220             case QTabBar::RoundedWest:
1221                 painter->drawLine(tabRect.left(), tabRect.top(), tabRect.left(), tabRect.bottom());
1222                 break;
1223 
1224             case QTabBar::RoundedSouth:
1225                 painter->drawLine(tbb->rect.left(), tbb->rect.bottom(),
1226                                   tabRect.right(), tabRect.bottom());
1227                 break;
1228 
1229             case QTabBar::RoundedEast:
1230                 painter->drawLine(tabRect.topRight(), tabRect.bottomRight());
1231                 break;
1232 
1233             case QTabBar::TriangularNorth:
1234             case QTabBar::TriangularEast:
1235             case QTabBar::TriangularWest:
1236             case QTabBar::TriangularSouth:
1237                 painter->restore();
1238                 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1239                 return;
1240             }
1241 
1242             painter->restore();
1243         }
1244         return;
1245 
1246 #endif // QT_NO_TABBAR
1247 
1248     case PE_Widget:
1249         break;
1250 
1251     default:
1252         QCleanlooksStyle::drawPrimitive(element, option, painter, widget);
1253     }
1254 }
1255 
1256 /*!
1257     \reimp
1258 */
drawComplexControl(ComplexControl control,const QStyleOptionComplex * option,QPainter * painter,const QWidget * widget) const1259 void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
1260 
1261                                    QPainter *painter, const QWidget *widget) const
1262 {
1263     Q_D(const QGtkStyle);
1264 
1265     if (!d->isThemeAvailable()) {
1266         QCleanlooksStyle::drawComplexControl(control, option, painter, widget);
1267         return;
1268     }
1269 
1270     GtkStyle* style = d->gtkStyle();
1271     QGtkPainter gtkPainter(painter);
1272     QColor button = option->palette.button().color();
1273     QColor dark;
1274     QColor grooveColor;
1275     QColor darkOutline;
1276     dark.setHsv(button.hue(),
1277                 qMin(255, (int)(button.saturation()*1.9)),
1278                 qMin(255, (int)(button.value()*0.7)));
1279     grooveColor.setHsv(button.hue(),
1280                        qMin(255, (int)(button.saturation()*2.6)),
1281                        qMin(255, (int)(button.value()*0.9)));
1282     darkOutline.setHsv(button.hue(),
1283                        qMin(255, (int)(button.saturation()*3.0)),
1284                        qMin(255, (int)(button.value()*0.6)));
1285 
1286     QColor alphaCornerColor;
1287 
1288     if (widget)
1289         alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), darkOutline);
1290     else
1291         alphaCornerColor = mergedColors(option->palette.background().color(), darkOutline);
1292 
1293     switch (control) {
1294 
1295     case CC_TitleBar:
1296         if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
1297             // Since this is drawn by metacity and not Gtk we
1298             // have to rely on Cleanlooks for a fallback
1299             QStyleOptionTitleBar copyOpt = *tb;
1300             QPalette pal = copyOpt.palette;
1301             // Bg color is closer to the window selection than
1302             // the base selection color
1303             GdkColor gdkBg = style->bg[GTK_STATE_SELECTED];
1304             QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8);
1305             pal.setBrush(QPalette::Active, QPalette::Highlight, bgColor);
1306             copyOpt.palette = pal;
1307             QCleanlooksStyle::drawComplexControl(control, &copyOpt, painter, widget);
1308         }
1309         break;
1310 
1311 #ifndef QT_NO_GROUPBOX
1312 
1313     case CC_GroupBox:
1314         painter->save();
1315 
1316         if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
1317             QRect textRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxLabel, widget);
1318             QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxCheckBox, widget);
1319             // Draw title
1320 
1321             if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
1322                 // Draw prelight background
1323                 GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
1324 
1325                 if (option->state & State_MouseOver) {
1326                     QRect bgRect = textRect | checkBoxRect;
1327                     gtkPainter.paintFlatBox(gtkCheckButton, "checkbutton", bgRect.adjusted(0, 0, 0, -2),
1328                                             GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkCheckButton->style);
1329                 }
1330 
1331                 if (!groupBox->text.isEmpty()) {
1332                     int alignment = int(groupBox->textAlignment);
1333                     if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, option, widget))
1334                         alignment |= Qt::TextHideMnemonic;
1335                     QColor textColor = groupBox->textColor; // Note: custom textColor is currently ignored
1336                     int labelState = GTK_STATE_INSENSITIVE;
1337 
1338                     if (option->state & State_Enabled)
1339                         labelState = (option->state & State_MouseOver) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
1340 
1341                     GdkColor gdkText = gtkCheckButton->style->fg[labelState];
1342                     textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
1343                     painter->setPen(textColor);
1344                     QFont font = painter->font();
1345                     font.setBold(true);
1346                     painter->setFont(font);
1347                     painter->drawText(textRect, Qt::TextShowMnemonic | Qt::AlignLeft| alignment, groupBox->text);
1348 
1349                     if (option->state & State_HasFocus)
1350                         gtkPainter.paintFocus( NULL, "tab", textRect.adjusted(-4, -1, 0, -3), GTK_STATE_ACTIVE, style);
1351                 }
1352             }
1353 
1354             if (groupBox->subControls & SC_GroupBoxCheckBox) {
1355                 QStyleOptionButton box;
1356                 box.QStyleOption::operator=(*groupBox);
1357                 box.rect = checkBoxRect;
1358                 proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
1359             }
1360         }
1361 
1362         painter->restore();
1363         break;
1364 #endif // QT_NO_GROUPBOX
1365 
1366 #ifndef QT_NO_COMBOBOX
1367 
1368     case CC_ComboBox:
1369         // See: http://live.gnome.org/GnomeArt/Tutorials/GtkThemes/GtkComboBox
1370         // and http://live.gnome.org/GnomeArt/Tutorials/GtkThemes/GtkComboBoxEntry
1371         if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1372             bool sunken = comboBox->state & State_On; // play dead, if combobox has no items
1373             BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("cb-%0-%1").arg(sunken).arg(comboBox->editable));
1374             QGtkPainter gtkCachedPainter(p);
1375             gtkCachedPainter.setUsePixmapCache(false); // cached externally
1376 
1377             bool isEnabled = (comboBox->state & State_Enabled);
1378             bool focus = isEnabled && (comboBox->state & State_HasFocus);
1379             GtkStateType state = gtkPainter.gtkState(option);
1380             int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, comboBox, widget);
1381             QStyleOptionComboBox comboBoxCopy = *comboBox;
1382             comboBoxCopy.rect = option->rect;
1383 
1384             bool reverse = (option->direction == Qt::RightToLeft);
1385             QRect rect = option->rect;
1386             QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, &comboBoxCopy,
1387                                                    SC_ComboBoxArrow, widget);
1388 
1389             GtkShadowType shadow = (option->state & State_Sunken || option->state & State_On ) ?
1390                                    GTK_SHADOW_IN : GTK_SHADOW_OUT;
1391             const QHashableLatin1Literal comboBoxPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry") : QHashableLatin1Literal("GtkComboBox");
1392 
1393             // We use the gtk widget to position arrows and separators for us
1394             GtkWidget *gtkCombo = d->gtkWidget(comboBoxPath);
1395             GtkAllocation geometry = {0, 0, option->rect.width(), option->rect.height()};
1396             d->gtk_widget_set_direction(gtkCombo, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1397             d->gtk_widget_size_allocate(gtkCombo, &geometry);
1398 
1399             QHashableLatin1Literal buttonPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton")
1400                                 : QHashableLatin1Literal("GtkComboBox.GtkToggleButton");
1401             GtkWidget *gtkToggleButton = d->gtkWidget(buttonPath);
1402             d->gtk_widget_set_direction(gtkToggleButton, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1403             if (gtkToggleButton && (appears_as_list || comboBox->editable)) {
1404                 if (focus)
1405                     GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1406                 // Draw the combo box as a line edit with a button next to it
1407                 if (comboBox->editable || appears_as_list) {
1408                     GtkStateType frameState = (state == GTK_STATE_PRELIGHT) ? GTK_STATE_NORMAL : state;
1409                     QHashableLatin1Literal entryPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry.GtkEntry") : QHashableLatin1Literal("GtkComboBox.GtkFrame");
1410                     GtkWidget *gtkEntry = d->gtkWidget(entryPath);
1411                     d->gtk_widget_set_direction(gtkEntry, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1412                     QRect frameRect = option->rect;
1413 
1414                     if (reverse)
1415                         frameRect.setLeft(arrowButtonRect.right());
1416                     else
1417                         frameRect.setRight(arrowButtonRect.left());
1418 
1419                     // Fill the line edit background
1420                     // We could have used flat_box with "entry_bg" but that is probably not worth the overhead
1421                     uint resolve_mask = option->palette.resolve();
1422                     int xt = gtkEntry->style->xthickness;
1423                     int yt = gtkEntry->style->ythickness;
1424                     QRect contentRect = frameRect.adjusted(xt, yt, -xt, -yt);
1425                     // Required for inner blue highlight with clearlooks
1426                     if (focus)
1427                         GTK_WIDGET_SET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1428 
1429                     if (widget && widget->testAttribute(Qt::WA_SetPalette) &&
1430                         resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
1431                         p->fillRect(contentRect, option->palette.base().color());
1432                     else {
1433                         gtkCachedPainter.paintFlatBox(gtkEntry, "entry_bg", contentRect,
1434                                                 option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
1435                                                 GTK_SHADOW_NONE, gtkEntry->style, entryPath.toString() + QString::number(focus));
1436                     }
1437 
1438                     gtkCachedPainter.paintShadow(gtkEntry, comboBox->editable ? "entry" : "frame", frameRect, frameState,
1439                                            GTK_SHADOW_IN, gtkEntry->style, entryPath.toString() +
1440                                            QString::number(focus) + QString::number(comboBox->editable) +
1441                                            QString::number(option->direction));
1442                     if (focus)
1443                         GTK_WIDGET_UNSET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1444                 }
1445 
1446                 GtkStateType buttonState = GTK_STATE_NORMAL;
1447 
1448                 if (!(option->state & State_Enabled))
1449                     buttonState = GTK_STATE_INSENSITIVE;
1450                 else if (option->state & State_Sunken || option->state & State_On)
1451                     buttonState = GTK_STATE_ACTIVE;
1452                 else if (option->state & State_MouseOver && comboBox->activeSubControls & SC_ComboBoxArrow)
1453                     buttonState = GTK_STATE_PRELIGHT;
1454 
1455                 Q_ASSERT(gtkToggleButton);
1456                 gtkCachedPainter.paintBox( gtkToggleButton, "button", arrowButtonRect, buttonState,
1457                                      shadow, gtkToggleButton->style, buttonPath.toString() +
1458                                      QString::number(focus) + QString::number(option->direction));
1459                 if (focus)
1460                     GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1461             } else {
1462                 // Draw combo box as a button
1463                 QRect buttonRect = option->rect;
1464 
1465                 if (focus) // Clearlooks actually check the widget for the default state
1466                     GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1467                 gtkCachedPainter.paintBox(gtkToggleButton, "button",
1468                                     buttonRect, state,
1469                                     shadow, gtkToggleButton->style,
1470                                     buttonPath.toString() + QString::number(focus));
1471                 if (focus)
1472                     GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1473 
1474 
1475                 // Draw the separator between label and arrows
1476                 QHashableLatin1Literal vSeparatorPath = comboBox->editable
1477                     ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkHBox.GtkVSeparator")
1478                     : QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkHBox.GtkVSeparator");
1479 
1480                 if (GtkWidget *gtkVSeparator = d->gtkWidget(vSeparatorPath)) {
1481                     QRect vLineRect(gtkVSeparator->allocation.x,
1482                                     gtkVSeparator->allocation.y,
1483                                     gtkVSeparator->allocation.width,
1484                                     gtkVSeparator->allocation.height);
1485 
1486                     gtkCachedPainter.paintVline( gtkVSeparator, "vseparator",
1487                                            vLineRect, state, gtkVSeparator->style,
1488                                            0, vLineRect.height(), 0,  vSeparatorPath.toString());
1489 
1490 
1491                     gint interiorFocus = true;
1492                     d->gtk_widget_style_get(gtkToggleButton, "interior-focus", &interiorFocus, NULL);
1493                     int xt = interiorFocus ? gtkToggleButton->style->xthickness : 0;
1494                     int yt = interiorFocus ? gtkToggleButton->style->ythickness : 0;
1495                     if (focus && ((option->state & State_KeyboardFocusChange) || styleHint(SH_UnderlineShortcut, option, widget)))
1496                         gtkCachedPainter.paintFocus(gtkToggleButton, "button",
1497                                               option->rect.adjusted(xt, yt, -xt, -yt),
1498                                               option->state & State_Sunken ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL,
1499                                               gtkToggleButton->style);
1500                 }
1501             }
1502 
1503             if (comboBox->subControls & SC_ComboBoxArrow) {
1504                 if (!isEnabled)
1505                     state = GTK_STATE_INSENSITIVE;
1506                 else if (sunken)
1507                     state = GTK_STATE_ACTIVE;
1508                 else if (option->state & State_MouseOver)
1509                     state = GTK_STATE_PRELIGHT;
1510                 else
1511                     state = GTK_STATE_NORMAL;
1512 
1513                 QHashableLatin1Literal arrowPath("");
1514                 if (comboBox->editable) {
1515                     if (appears_as_list)
1516                         arrowPath = QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkArrow");
1517                     else
1518                         arrowPath = QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkHBox.GtkArrow");
1519                 } else {
1520                     if (appears_as_list)
1521                         arrowPath = QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkArrow");
1522                     else
1523                         arrowPath = QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkHBox.GtkArrow");
1524                 }
1525 
1526                 GtkWidget *gtkArrow = d->gtkWidget(arrowPath);
1527                 gfloat scale = 0.7;
1528                 gint minSize = 15;
1529                 QRect arrowWidgetRect;
1530 
1531                 if (gtkArrow && !d->gtk_check_version(2, 12, 0)) {
1532                     d->gtk_widget_style_get(gtkArrow, "arrow-scaling", &scale, NULL);
1533                     d->gtk_widget_style_get(gtkCombo, "arrow-size", &minSize, NULL);
1534                 }
1535                 if (gtkArrow) {
1536                     arrowWidgetRect = QRect(gtkArrow->allocation.x, gtkArrow->allocation.y,
1537                                             gtkArrow->allocation.width, gtkArrow->allocation.height);
1538                     style = gtkArrow->style;
1539                 }
1540 
1541                 // Note that for some reason the arrow-size is not properly respected with Hildon
1542                 // Hence we enforce the minimum "arrow-size" ourselves
1543                 int arrowSize = qMax(qMin(rect.height() - gtkCombo->style->ythickness * 2, minSize),
1544                                      qMin(arrowWidgetRect.width(), arrowWidgetRect.height()));
1545                 QRect arrowRect(0, 0, static_cast<int>(arrowSize * scale), static_cast<int>(arrowSize * scale));
1546 
1547                 arrowRect.moveCenter(arrowWidgetRect.center());
1548 
1549                 if (sunken) {
1550                     int xoff, yoff;
1551                     const QHashableLatin1Literal toggleButtonPath = comboBox->editable
1552                             ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton")
1553                             : QHashableLatin1Literal("GtkComboBox.GtkToggleButton");
1554 
1555                     GtkWidget *gtkButton = d->gtkWidget(toggleButtonPath);
1556                     d->gtk_widget_style_get(gtkButton, "child-displacement-x", &xoff, NULL);
1557                     d->gtk_widget_style_get(gtkButton, "child-displacement-y", &yoff, NULL);
1558                     arrowRect = arrowRect.adjusted(xoff, yoff, xoff, yoff);
1559                 }
1560 
1561                 // Some styles such as Nimbus paint outside the arrowRect
1562                 // hence we have provide the whole widget as the cliprect
1563                 if (gtkArrow) {
1564                     gtkCachedPainter.setClipRect(option->rect);
1565                     gtkCachedPainter.paintArrow( gtkArrow, "arrow", arrowRect,
1566                                            GTK_ARROW_DOWN, state, GTK_SHADOW_NONE, TRUE,
1567                                            style, arrowPath.toString() + QString::number(option->direction));
1568                 }
1569             }
1570             END_STYLE_PIXMAPCACHE;
1571         }
1572         break;
1573 #endif // QT_NO_COMBOBOX
1574 #ifndef QT_NO_TOOLBUTTON
1575 
1576     case CC_ToolButton:
1577         if (const QStyleOptionToolButton *toolbutton
1578                 = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
1579             QRect button, menuarea;
1580             button = proxy()->subControlRect(control, toolbutton, SC_ToolButton, widget);
1581             menuarea = proxy()->subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
1582             State bflags = toolbutton->state & ~(State_Sunken | State_MouseOver);
1583 
1584             if (bflags & State_AutoRaise)
1585                 if (!(bflags & State_MouseOver))
1586                     bflags &= ~State_Raised;
1587 
1588             State mflags = bflags;
1589 
1590             if (toolbutton->state & State_Sunken) {
1591                 if (toolbutton->activeSubControls & SC_ToolButton)
1592                     bflags |= State_Sunken;
1593                 if (toolbutton->activeSubControls & SC_ToolButtonMenu)
1594                     mflags |= State_Sunken;
1595             } else if (toolbutton->state & State_MouseOver) {
1596                 if (toolbutton->activeSubControls & SC_ToolButton)
1597                     bflags |= State_MouseOver;
1598                 if (toolbutton->activeSubControls & SC_ToolButtonMenu)
1599                     mflags |= State_MouseOver;
1600             }
1601 
1602             QStyleOption tool(0);
1603 
1604             tool.palette = toolbutton->palette;
1605 
1606             if (toolbutton->subControls & SC_ToolButton) {
1607                 if (bflags & (State_Sunken | State_On | State_Raised | State_MouseOver)) {
1608                     tool.rect = button;
1609                     tool.state = bflags;
1610                     proxy()->drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
1611                 }
1612             }
1613 
1614             bool drawMenuArrow = toolbutton->features & QStyleOptionToolButton::HasMenu &&
1615                                  !(toolbutton->features & QStyleOptionToolButton::MenuButtonPopup);
1616             int popupArrowSize = drawMenuArrow ? 7 : 0;
1617 
1618             if (toolbutton->state & State_HasFocus) {
1619                 QStyleOptionFocusRect fr;
1620                 fr.QStyleOption::operator=(*toolbutton);
1621                 fr.rect = proxy()->subControlRect(CC_ToolButton, toolbutton, SC_ToolButton, widget);
1622                 fr.rect.adjust(1, 1, -1, -1);
1623                 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
1624             }
1625 
1626             QStyleOptionToolButton label = *toolbutton;
1627             label.state = bflags;
1628             GtkWidget *gtkButton = d->gtkWidget("GtkToolButton.GtkButton");
1629             QPalette pal = toolbutton->palette;
1630             if (option->state & State_Enabled &&
1631                 option->state & State_MouseOver && !(widget && widget->testAttribute(Qt::WA_SetPalette))) {
1632                 GdkColor gdkText = gtkButton->style->fg[GTK_STATE_PRELIGHT];
1633                 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
1634                 pal.setBrush(QPalette::All, QPalette::ButtonText, textColor);
1635                 label.palette = pal;
1636             }
1637             label.rect = button.adjusted(style->xthickness, style->ythickness,
1638                                         -style->xthickness - popupArrowSize, -style->ythickness);
1639             proxy()->drawControl(CE_ToolButtonLabel, &label, painter, widget);
1640 
1641             if (toolbutton->subControls & SC_ToolButtonMenu) {
1642                 tool.rect = menuarea;
1643                 tool.state = mflags;
1644                 if ((mflags & State_Enabled && (mflags & (State_Sunken | State_Raised | State_MouseOver))) || !(mflags & State_AutoRaise))
1645                     proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, painter, widget);
1646 
1647                 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
1648 
1649             } else if (drawMenuArrow) {
1650                 QRect ir = toolbutton->rect;
1651                 QStyleOptionToolButton newBtn = *toolbutton;
1652                 newBtn.rect = QRect(ir.right() - popupArrowSize - style->xthickness - 3, ir.height()/2 - 1, popupArrowSize, popupArrowSize);
1653                 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
1654             }
1655         }
1656         break;
1657 
1658 #endif // QT_NO_TOOLBUTTON
1659 #ifndef QT_NO_SCROLLBAR
1660 
1661     case CC_ScrollBar:
1662         if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
1663             GtkWidget *gtkHScrollBar = d->gtkWidget("GtkHScrollbar");
1664             GtkWidget *gtkVScrollBar = d->gtkWidget("GtkVScrollbar");
1665 
1666             // Fill background in case the scrollbar is partially transparent
1667             painter->fillRect(option->rect, option->palette.background());
1668 
1669             QRect rect = scrollBar->rect;
1670             QRect scrollBarSubLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubLine, widget);
1671             QRect scrollBarAddLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddLine, widget);
1672             QRect scrollBarSlider = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSlider, widget);
1673             QRect grooveRect = proxy()->subControlRect(control, scrollBar, SC_ScrollBarGroove, widget);
1674             bool horizontal = scrollBar->orientation == Qt::Horizontal;
1675             GtkWidget * scrollbarWidget = horizontal ? gtkHScrollBar : gtkVScrollBar;
1676             style = scrollbarWidget->style;
1677             gboolean trough_under_steppers = true;
1678             gboolean trough_side_details = false;
1679             gboolean activate_slider = false;
1680             gboolean stepper_size = 14;
1681             gint trough_border = 1;
1682             if (!d->gtk_check_version(2, 10, 0)) {
1683                 d->gtk_widget_style_get((GtkWidget*)(scrollbarWidget),
1684                                            "trough-border",   &trough_border,
1685                                            "trough-side-details",   &trough_side_details,
1686                                            "trough-under-steppers", &trough_under_steppers,
1687                                            "activate-slider",       &activate_slider,
1688                                            "stepper-size",          &stepper_size, NULL);
1689             }
1690             if (trough_under_steppers) {
1691                 scrollBarAddLine.adjust(trough_border, trough_border, -trough_border, -trough_border);
1692                 scrollBarSubLine.adjust(trough_border, trough_border, -trough_border, -trough_border);
1693                 scrollBarSlider.adjust(horizontal ? -trough_border : 0, horizontal ? 0 : -trough_border,
1694                                        horizontal ? trough_border : 0, horizontal ? 0 : trough_border);
1695             }
1696 
1697             // Some styles check the position of scrollbars in order to determine
1698             // if lines should be painted when the scrollbar is in max or min positions.
1699             int maximum = 2;
1700             int fakePos = 0;
1701             bool reverse = (option->direction == Qt::RightToLeft);
1702             if (scrollBar->minimum == scrollBar->maximum)
1703                 maximum = 0;
1704             if (scrollBar->sliderPosition == scrollBar->maximum)
1705                 fakePos = maximum;
1706             else if (scrollBar->sliderPosition > scrollBar->minimum)
1707                 fakePos = maximum - 1;
1708 
1709 
1710             GtkRange *range = (GtkRange*)(horizontal ? gtkHScrollBar : gtkVScrollBar);
1711             GtkAdjustment *adjustment = 0;
1712 
1713             if (d->gtk_adjustment_configure)
1714                 adjustment = d->gtk_range_get_adjustment(range);
1715             if (adjustment) {
1716                 d->gtk_adjustment_configure(adjustment, fakePos, 0, maximum, 0, 0, 0);
1717             } else {
1718                 adjustment = (GtkAdjustment*)d->gtk_adjustment_new(fakePos, 0, maximum, 0, 0, 0);
1719                 d->gtk_range_set_adjustment(range, adjustment);
1720             }
1721 
1722             if (scrollBar->subControls & SC_ScrollBarGroove) {
1723                 GtkStateType state = GTK_STATE_ACTIVE;
1724 
1725                 if (!(option->state & State_Enabled))
1726                     state = GTK_STATE_INSENSITIVE;
1727 
1728                 if (trough_under_steppers)
1729                     grooveRect = option->rect;
1730 
1731                 gtkPainter.paintBox( scrollbarWidget, "trough", grooveRect, state, GTK_SHADOW_IN, style);
1732             }
1733 
1734             //paint slider
1735             if (scrollBar->subControls & SC_ScrollBarSlider) {
1736                 GtkStateType state = GTK_STATE_NORMAL;
1737 
1738                 if (!(option->state & State_Enabled))
1739                     state = GTK_STATE_INSENSITIVE;
1740                 else if (activate_slider &&
1741                          option->state & State_Sunken && (scrollBar->activeSubControls & SC_ScrollBarSlider))
1742                     state = GTK_STATE_ACTIVE;
1743                 else if (option->state & State_MouseOver && (scrollBar->activeSubControls & SC_ScrollBarSlider))
1744                     state = GTK_STATE_PRELIGHT;
1745 
1746                 GtkShadowType shadow = GTK_SHADOW_OUT;
1747 
1748                 if (trough_under_steppers) {
1749                     if (!horizontal)
1750                         scrollBarSlider.adjust(trough_border, 0, -trough_border, 0);
1751                     else
1752                         scrollBarSlider.adjust(0, trough_border, 0, -trough_border);
1753                 }
1754 
1755                 gtkPainter.paintSlider( scrollbarWidget, "slider", scrollBarSlider, state, shadow, style,
1756 
1757                                         horizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, QString(QLS("%0%1")).arg(fakePos).arg(maximum));
1758             }
1759 
1760             if (scrollBar->subControls & SC_ScrollBarAddLine) {
1761                 gtkVScrollBar->allocation.y = scrollBarAddLine.top();
1762                 gtkVScrollBar->allocation.height = scrollBarAddLine.height() - rect.height() + 6;
1763                 gtkHScrollBar->allocation.x = scrollBarAddLine.right();
1764                 gtkHScrollBar->allocation.width = scrollBarAddLine.width() - rect.width();
1765 
1766                 GtkShadowType shadow = GTK_SHADOW_OUT;
1767                 GtkStateType state = GTK_STATE_NORMAL;
1768 
1769                 if (!(option->state & State_Enabled) || (fakePos == maximum))
1770                     state = GTK_STATE_INSENSITIVE;
1771                 else if (option->state & State_Sunken && (scrollBar->activeSubControls & SC_ScrollBarAddLine)) {
1772                     state = GTK_STATE_ACTIVE;
1773                     shadow = GTK_SHADOW_IN;
1774 
1775                 } else if (option->state & State_MouseOver && (scrollBar->activeSubControls & SC_ScrollBarAddLine))
1776                     state = GTK_STATE_PRELIGHT;
1777 
1778                 gtkPainter.paintBox( scrollbarWidget,
1779                                      horizontal ? "hscrollbar" : "vscrollbar", scrollBarAddLine,
1780                                      state, shadow, style, QLS("add"));
1781 
1782                 gtkPainter.paintArrow( scrollbarWidget, horizontal ? "hscrollbar" : "vscrollbar", scrollBarAddLine.adjusted(4, 4, -4, -4),
1783                                        horizontal ? (reverse ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT) :
1784                                        GTK_ARROW_DOWN, state, GTK_SHADOW_NONE, FALSE, style);
1785             }
1786 
1787             if (scrollBar->subControls & SC_ScrollBarSubLine) {
1788                 gtkVScrollBar->allocation.y = 0;
1789                 gtkVScrollBar->allocation.height = scrollBarSubLine.height();
1790                 gtkHScrollBar->allocation.x = 0;
1791                 gtkHScrollBar->allocation.width = scrollBarSubLine.width();
1792 
1793                 GtkShadowType shadow = GTK_SHADOW_OUT;
1794                 GtkStateType state = GTK_STATE_NORMAL;
1795 
1796                 if (!(option->state & State_Enabled) || (fakePos == 0))
1797                     state = GTK_STATE_INSENSITIVE;
1798                 else if (option->state & State_Sunken && (scrollBar->activeSubControls & SC_ScrollBarSubLine)) {
1799                     shadow = GTK_SHADOW_IN;
1800                     state = GTK_STATE_ACTIVE;
1801 
1802                 } else if (option->state & State_MouseOver && (scrollBar->activeSubControls & SC_ScrollBarSubLine))
1803                     state = GTK_STATE_PRELIGHT;
1804 
1805                 gtkPainter.paintBox(scrollbarWidget, horizontal ? "hscrollbar" : "vscrollbar", scrollBarSubLine,
1806                                     state, shadow, style, QLS("sub"));
1807 
1808                 gtkPainter.paintArrow(scrollbarWidget, horizontal ? "hscrollbar" : "vscrollbar", scrollBarSubLine.adjusted(4, 4, -4, -4),
1809                                       horizontal ? (reverse ? GTK_ARROW_RIGHT : GTK_ARROW_LEFT) :
1810                                       GTK_ARROW_UP, state, GTK_SHADOW_NONE, FALSE, style);
1811             }
1812         }
1813         break;
1814 
1815 #endif //QT_NO_SCROLLBAR
1816 #ifndef QT_NO_SPINBOX
1817 
1818     case CC_SpinBox:
1819         if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
1820 
1821             GtkWidget *gtkSpinButton = spinBox->buttonSymbols == QAbstractSpinBox::NoButtons
1822                         ? d->gtkWidget("GtkEntry")
1823                         : d->gtkWidget("GtkSpinButton");
1824             bool isEnabled = (spinBox->state & State_Enabled);
1825             bool hover = isEnabled && (spinBox->state & State_MouseOver);
1826             bool sunken = (spinBox->state & State_Sunken);
1827             bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
1828             bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
1829             bool reverse = (spinBox->direction == Qt::RightToLeft);
1830 
1831             QRect editArea = option->rect;
1832             QRect editRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxEditField, widget);
1833             QRect upRect, downRect, buttonRect;
1834             if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
1835                 upRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
1836                 downRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
1837 
1838                 //### Move this to subControlRect
1839                 upRect.setTop(option->rect.top());
1840 
1841                 if (reverse)
1842                     upRect.setLeft(option->rect.left());
1843                 else
1844                     upRect.setRight(option->rect.right());
1845 
1846                 downRect.setBottom(option->rect.bottom());
1847 
1848                 if (reverse)
1849                     downRect.setLeft(option->rect.left());
1850                 else
1851                     downRect.setRight(option->rect.right());
1852 
1853                 buttonRect = upRect | downRect;
1854 
1855                 if (reverse)
1856                     editArea.setLeft(upRect.right());
1857                 else
1858                     editArea.setRight(upRect.left());
1859             }
1860             if (spinBox->frame) {
1861                 GtkStateType state = gtkPainter.gtkState(option);
1862 
1863                 if (!(option->state & State_Enabled))
1864                     state = GTK_STATE_INSENSITIVE;
1865                 else if (option->state & State_HasFocus)
1866                     state = GTK_STATE_NORMAL;
1867                 else if (state == GTK_STATE_PRELIGHT)
1868                     state = GTK_STATE_NORMAL;
1869 
1870                 style = gtkPainter.getStyle(gtkSpinButton);
1871 
1872 
1873                 QString key;
1874 
1875                 if (option->state & State_HasFocus) {
1876                     key += QLatin1Char('f');
1877                     GTK_WIDGET_SET_FLAGS(gtkSpinButton, GTK_HAS_FOCUS);
1878                 }
1879 
1880                 uint resolve_mask = option->palette.resolve();
1881 
1882                 if (resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
1883                     painter->fillRect(editRect, option->palette.base().color());
1884                 else
1885                     gtkPainter.paintFlatBox(gtkSpinButton, "entry_bg", editArea.adjusted(style->xthickness, style->ythickness,
1886                                             -style->xthickness, -style->ythickness),
1887                                             option->state & State_Enabled ?
1888                                             GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_NONE, style, key);
1889 
1890                 gtkPainter.paintShadow(gtkSpinButton, "entry", editArea, state, GTK_SHADOW_IN, gtkSpinButton->style, key);
1891                 if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
1892                     gtkPainter.paintBox(gtkSpinButton, "spinbutton", buttonRect, state, GTK_SHADOW_IN, style, key);
1893 
1894                     upRect.setSize(downRect.size());
1895                     if (!(option->state & State_Enabled))
1896                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_INSENSITIVE, GTK_SHADOW_IN, style, key);
1897                     else if (upIsActive && sunken)
1898                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_ACTIVE, GTK_SHADOW_IN, style, key);
1899                     else if (upIsActive && hover)
1900                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style, key);
1901                     else
1902                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, style, key);
1903 
1904                     if (!(option->state & State_Enabled))
1905                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_INSENSITIVE, GTK_SHADOW_IN, style, key);
1906                     else if (downIsActive && sunken)
1907                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_ACTIVE, GTK_SHADOW_IN, style, key);
1908                     else if (downIsActive && hover)
1909                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style, key);
1910                     else
1911                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, style, key);
1912 
1913                     if (option->state & State_HasFocus)
1914                         GTK_WIDGET_UNSET_FLAGS(gtkSpinButton, GTK_HAS_FOCUS);
1915                 }
1916             }
1917 
1918             if (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) {
1919                 int centerX = upRect.center().x();
1920                 int centerY = upRect.center().y();
1921                 // plus/minus
1922 
1923                 if (spinBox->activeSubControls == SC_SpinBoxUp && sunken) {
1924                     painter->drawLine(1 + centerX - 2, 1 + centerY, 1 + centerX + 2, 1 + centerY);
1925                     painter->drawLine(1 + centerX, 1 + centerY - 2, 1 + centerX, 1 + centerY + 2);
1926 
1927                 } else {
1928                     painter->drawLine(centerX - 2, centerY, centerX + 2, centerY);
1929                     painter->drawLine(centerX, centerY - 2, centerX, centerY + 2);
1930                 }
1931                 centerX = downRect.center().x();
1932                 centerY = downRect.center().y();
1933 
1934                 if (spinBox->activeSubControls == SC_SpinBoxDown && sunken) {
1935                     painter->drawLine(1 + centerX - 2, 1 + centerY, 1 + centerX + 2, 1 + centerY);
1936                 } else {
1937                     painter->drawLine(centerX - 2, centerY, centerX + 2, centerY);
1938                 }
1939 
1940             } else if (spinBox->buttonSymbols == QAbstractSpinBox::UpDownArrows) {
1941                 int size = d->getSpinboxArrowSize();
1942                 int w = size / 2 - 1;
1943                 w -= w % 2 - 1; // force odd
1944                 int h = (w + 1)/2;
1945                 QRect arrowRect(0, 0, w, h);
1946                 arrowRect.moveCenter(upRect.center());
1947                 // arrows
1948                 GtkStateType state = GTK_STATE_NORMAL;
1949 
1950                 if (!(option->state & State_Enabled) || !(spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled))
1951                     state = GTK_STATE_INSENSITIVE;
1952 
1953                 gtkPainter.paintArrow( gtkSpinButton, "spinbutton", arrowRect, GTK_ARROW_UP, state,
1954                                        GTK_SHADOW_NONE, FALSE, style);
1955 
1956                 arrowRect.moveCenter(downRect.center());
1957 
1958                 if (!(option->state & State_Enabled) || !(spinBox->stepEnabled & QAbstractSpinBox::StepDownEnabled))
1959                     state = GTK_STATE_INSENSITIVE;
1960 
1961                 gtkPainter.paintArrow( gtkSpinButton, "spinbutton", arrowRect, GTK_ARROW_DOWN, state,
1962                                        GTK_SHADOW_NONE, FALSE, style);
1963             }
1964         }
1965         break;
1966 
1967 #endif // QT_NO_SPINBOX
1968 
1969 #ifndef QT_NO_SLIDER
1970 
1971     case CC_Slider:
1972         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
1973             GtkWidget *hScaleWidget = d->gtkWidget("GtkHScale");
1974             GtkWidget *vScaleWidget = d->gtkWidget("GtkVScale");
1975 
1976             QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
1977             QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
1978 
1979             bool horizontal = slider->orientation == Qt::Horizontal;
1980             bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
1981             bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
1982 
1983             QBrush oldBrush = painter->brush();
1984             QPen oldPen = painter->pen();
1985 
1986             QColor shadowAlpha(Qt::black);
1987             shadowAlpha.setAlpha(10);
1988             QColor highlightAlpha(Qt::white);
1989             highlightAlpha.setAlpha(80);
1990 
1991             QGtkStylePrivate::gtk_widget_set_direction(hScaleWidget, slider->upsideDown ?
1992                                                        GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1993             GtkWidget *scaleWidget = horizontal ? hScaleWidget : vScaleWidget;
1994             style = scaleWidget->style;
1995 
1996             if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
1997 
1998                 GtkRange *range = (GtkRange*)scaleWidget;
1999                 GtkAdjustment *adjustment = 0;
2000                 if (d->gtk_adjustment_configure)
2001                     adjustment = d->gtk_range_get_adjustment(range);
2002                 if (adjustment) {
2003                     d->gtk_adjustment_configure(adjustment,
2004                                                 slider->sliderPosition,
2005                                                 slider->minimum,
2006                                                 slider->maximum,
2007                                                 slider->singleStep,
2008                                                 slider->singleStep,
2009                                                 slider->pageStep);
2010                 } else {
2011                     adjustment = (GtkAdjustment*)d->gtk_adjustment_new(slider->sliderPosition,
2012                                                                        slider->minimum,
2013                                                                        slider->maximum,
2014                                                                        slider->singleStep,
2015                                                                        slider->singleStep,
2016                                                                        slider->pageStep);
2017                     d->gtk_range_set_adjustment(range, adjustment);
2018                 }
2019 
2020                 int outerSize;
2021                 d->gtk_range_set_inverted(range, !horizontal);
2022                 d->gtk_widget_style_get(scaleWidget, "trough-border", &outerSize, NULL);
2023                 outerSize++;
2024 
2025                 GtkStateType state = gtkPainter.gtkState(option);
2026                 int focusFrameMargin = 2;
2027                 QRect grooveRect = option->rect.adjusted(focusFrameMargin, outerSize + focusFrameMargin,
2028                                    -focusFrameMargin, -outerSize - focusFrameMargin);
2029 
2030                 gboolean trough_side_details = false; // Indicates if the upper or lower scale background differs
2031                 if (!d->gtk_check_version(2, 10, 0))
2032                     d->gtk_widget_style_get((GtkWidget*)(scaleWidget), "trough-side-details",   &trough_side_details, NULL);
2033 
2034                 if (!trough_side_details) {
2035                     gtkPainter.paintBox( scaleWidget, "trough", grooveRect, state,
2036                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
2037                 } else {
2038                     QRect upperGroove = grooveRect;
2039                     QRect lowerGroove = grooveRect;
2040 
2041                     if (horizontal) {
2042                         if (slider->upsideDown) {
2043                             lowerGroove.setLeft(handle.center().x());
2044                             upperGroove.setRight(handle.center().x());
2045                         } else {
2046                             upperGroove.setLeft(handle.center().x());
2047                             lowerGroove.setRight(handle.center().x());
2048                         }
2049                     } else {
2050                         if (!slider->upsideDown) {
2051                             lowerGroove.setBottom(handle.center().y());
2052                             upperGroove.setTop(handle.center().y());
2053                         } else {
2054                             upperGroove.setBottom(handle.center().y());
2055                             lowerGroove.setTop(handle.center().y());
2056                         }
2057                     }
2058 
2059                     gtkPainter.paintBox( scaleWidget, "trough-upper", upperGroove, state,
2060                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
2061                     gtkPainter.paintBox( scaleWidget, "trough-lower", lowerGroove, state,
2062                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
2063                 }
2064             }
2065 
2066             if (option->subControls & SC_SliderTickmarks) {
2067                 painter->setPen(darkOutline);
2068                 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
2069                 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
2070                 int interval = slider->tickInterval;
2071 
2072                 if (interval <= 0) {
2073                     interval = slider->singleStep;
2074 
2075                     if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
2076                                                         available)
2077                             - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
2078                                                               0, available) < 3)
2079                         interval = slider->pageStep;
2080                 }
2081 
2082                 if (interval <= 0)
2083                     interval = 1;
2084 
2085                 int v = slider->minimum;
2086                 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
2087                 while (v <= slider->maximum + 1) {
2088                     if (v == slider->maximum + 1 && interval == 1)
2089                         break;
2090                     const int v_ = qMin(v, slider->maximum);
2091                     int pos = sliderPositionFromValue(slider->minimum, slider->maximum,
2092                                                       v_, (horizontal
2093                                                            ? slider->rect.width()
2094                                                            : slider->rect.height()) - len,
2095                                                       slider->upsideDown) + len / 2;
2096                     int extra = 2 - ((v_ == slider->minimum || v_ == slider->maximum) ? 1 : 0);
2097                     if (horizontal) {
2098                         if (ticksAbove)
2099                             painter->drawLine(pos, slider->rect.top() + extra,
2100                                               pos, slider->rect.top() + tickSize);
2101                         if (ticksBelow)
2102                             painter->drawLine(pos, slider->rect.bottom() - extra,
2103                                               pos, slider->rect.bottom() - tickSize);
2104 
2105                     } else {
2106                         if (ticksAbove)
2107                             painter->drawLine(slider->rect.left() + extra, pos,
2108                                               slider->rect.left() + tickSize, pos);
2109                         if (ticksBelow)
2110                             painter->drawLine(slider->rect.right() - extra, pos,
2111                                               slider->rect.right() - tickSize, pos);
2112                     }
2113 
2114                     // In the case where maximum is max int
2115                     int nextInterval = v + interval;
2116                     if (nextInterval < v)
2117                         break;
2118                     v = nextInterval;
2119                 }
2120             }
2121 
2122             // Draw slider handle
2123             if (option->subControls & SC_SliderHandle) {
2124                 GtkShadowType shadow =  GTK_SHADOW_OUT;
2125                 GtkStateType state = GTK_STATE_NORMAL;
2126 
2127                 if (!(option->state & State_Enabled))
2128                     state = GTK_STATE_INSENSITIVE;
2129                 else if (option->state & State_MouseOver && option->activeSubControls & SC_SliderHandle)
2130                     state = GTK_STATE_PRELIGHT;
2131 
2132                 bool horizontal = option->state & State_Horizontal;
2133 
2134                 if (slider->state & State_HasFocus) {
2135                     QStyleOptionFocusRect fropt;
2136                     fropt.QStyleOption::operator=(*slider);
2137                     fropt.rect = slider->rect.adjusted(-1, -1 ,1, 1);
2138 
2139                     if (horizontal) {
2140                         fropt.rect.setTop(handle.top() - 3);
2141                         fropt.rect.setBottom(handle.bottom() + 4);
2142 
2143                     } else {
2144                         fropt.rect.setLeft(handle.left() - 3);
2145                         fropt.rect.setRight(handle.right() + 3);
2146                     }
2147                     proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
2148                 }
2149                 gtkPainter.paintSlider( scaleWidget, horizontal ? "hscale" : "vscale", handle, state, shadow, style,
2150 
2151                                         horizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL);
2152             }
2153             painter->setBrush(oldBrush);
2154             painter->setPen(oldPen);
2155         }
2156         break;
2157 
2158 #endif // QT_NO_SLIDER
2159 
2160     default:
2161         QCleanlooksStyle::drawComplexControl(control, option, painter, widget);
2162 
2163         break;
2164     }
2165 }
2166 
2167 
2168 /*!
2169     \reimp
2170 */
drawControl(ControlElement element,const QStyleOption * option,QPainter * painter,const QWidget * widget) const2171 void QGtkStyle::drawControl(ControlElement element,
2172                             const QStyleOption *option,
2173                             QPainter *painter,
2174                             const QWidget *widget) const
2175 {
2176     Q_D(const QGtkStyle);
2177 
2178     if (!d->isThemeAvailable()) {
2179         QCleanlooksStyle::drawControl(element, option, painter, widget);
2180         return;
2181     }
2182 
2183     GtkStyle* style = d->gtkStyle();
2184     QGtkPainter gtkPainter(painter);
2185 
2186     switch (element) {
2187     case CE_ProgressBarLabel:
2188         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2189             GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
2190             if (!gtkProgressBar)
2191                 return;
2192 
2193             QRect leftRect;
2194             QRect rect = bar->rect;
2195             GdkColor gdkText = gtkProgressBar->style->fg[GTK_STATE_NORMAL];
2196             QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2197             gdkText = gtkProgressBar->style->fg[GTK_STATE_PRELIGHT];
2198             QColor alternateTextColor= QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2199 
2200             painter->save();
2201             bool vertical = false, inverted = false;
2202             if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
2203                 vertical = (bar2->orientation == Qt::Vertical);
2204                 inverted = bar2->invertedAppearance;
2205             }
2206             if (vertical)
2207                 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
2208             const int progressIndicatorPos = (bar->progress - qreal(bar->minimum)) * rect.width() /
2209                                               qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum);
2210             if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width())
2211                 leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
2212             if (vertical)
2213                 leftRect.translate(rect.width() - progressIndicatorPos, 0);
2214 
2215             bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted) ||
2216                                        ((bar->direction == Qt::LeftToRight) && inverted)));
2217 
2218             QRegion rightRect = rect;
2219             rightRect = rightRect.subtracted(leftRect);
2220             painter->setClipRegion(rightRect);
2221             painter->setPen(flip ? alternateTextColor : textColor);
2222             painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
2223             if (!leftRect.isNull()) {
2224                 painter->setPen(flip ? textColor : alternateTextColor);
2225                 painter->setClipRect(leftRect);
2226                 painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
2227             }
2228             painter->restore();
2229         }
2230         break;
2231     case CE_PushButtonLabel:
2232         if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2233             QRect ir = button->rect;
2234             uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
2235             QPoint buttonShift;
2236 
2237             if (option->state & State_Sunken)
2238                 buttonShift = QPoint(pixelMetric(PM_ButtonShiftHorizontal, option, widget),
2239                                      proxy()->pixelMetric(PM_ButtonShiftVertical, option, widget));
2240 
2241             if (proxy()->styleHint(SH_UnderlineShortcut, button, widget))
2242                 tf |= Qt::TextShowMnemonic;
2243             else
2244                 tf |= Qt::TextHideMnemonic;
2245 
2246             if (!button->icon.isNull()) {
2247                 //Center both icon and text
2248                 QPoint point;
2249 
2250                 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
2251                 if (mode == QIcon::Normal && button->state & State_HasFocus)
2252                     mode = QIcon::Active;
2253 
2254                 QIcon::State state = QIcon::Off;
2255 
2256                 if (button->state & State_On)
2257                     state = QIcon::On;
2258 
2259                 QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state);
2260                 int w = pixmap.width();
2261                 int h = pixmap.height();
2262 
2263                 if (!button->text.isEmpty())
2264                     w += button->fontMetrics.boundingRect(option->rect, tf, button->text).width() + 4;
2265 
2266                 point = QPoint(ir.x() + ir.width() / 2 - w / 2,
2267                                ir.y() + ir.height() / 2 - h / 2);
2268 
2269                 if (button->direction == Qt::RightToLeft)
2270                     point.rx() += pixmap.width();
2271 
2272                 painter->drawPixmap(visualPos(button->direction, button->rect, point + buttonShift), pixmap);
2273 
2274                 if (button->direction == Qt::RightToLeft)
2275                     ir.translate(-point.x() - 2, 0);
2276                 else
2277                     ir.translate(point.x() + pixmap.width() + 2, 0);
2278 
2279                 // left-align text if there is
2280                 if (!button->text.isEmpty())
2281                     tf |= Qt::AlignLeft;
2282 
2283             } else {
2284                 tf |= Qt::AlignHCenter;
2285             }
2286 
2287             ir.translate(buttonShift);
2288 
2289             if (button->features & QStyleOptionButton::HasMenu)
2290                 ir = ir.adjusted(0, 0, -pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
2291 
2292             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
2293             QPalette pal = button->palette;
2294             int labelState = GTK_STATE_INSENSITIVE;
2295             if (option->state & State_Enabled)
2296                 labelState = (option->state & State_MouseOver && !(option->state & State_Sunken)) ?
2297                              GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
2298 
2299             GdkColor gdkText = gtkButton->style->fg[labelState];
2300             QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2301             pal.setBrush(QPalette::ButtonText, textColor);
2302             proxy()->drawItemText(painter, ir, tf, pal, (button->state & State_Enabled),
2303                          button->text, QPalette::ButtonText);
2304         }
2305         break;
2306 
2307     case CE_RadioButton: // Fall through
2308     case CE_CheckBox:
2309         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2310             bool isRadio = (element == CE_RadioButton);
2311 
2312             // Draw prelight background
2313             GtkWidget *gtkRadioButton = d->gtkWidget("GtkRadioButton");
2314 
2315             if (option->state & State_MouseOver) {
2316                 gtkPainter.paintFlatBox(gtkRadioButton, "checkbutton", option->rect,
2317                                         GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkRadioButton->style);
2318             }
2319 
2320             QStyleOptionButton subopt = *btn;
2321             subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator
2322                                          : SE_CheckBoxIndicator, btn, widget);
2323             proxy()->drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox,
2324                           &subopt, painter, widget);
2325             subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents
2326                                          : SE_CheckBoxContents, btn, widget);
2327             // Get label text color
2328             QPalette pal = subopt.palette;
2329             int labelState = GTK_STATE_INSENSITIVE;
2330             if (option->state & State_Enabled)
2331                 labelState = (option->state & State_MouseOver) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
2332 
2333             GdkColor gdkText = gtkRadioButton->style->fg[labelState];
2334             QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2335             pal.setBrush(QPalette::WindowText, textColor);
2336             subopt.palette = pal;
2337             proxy()->drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, painter, widget);
2338 
2339             if (btn->state & State_HasFocus) {
2340                 QStyleOptionFocusRect fropt;
2341                 fropt.QStyleOption::operator=(*btn);
2342                 fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect
2343                                             : SE_CheckBoxFocusRect, btn, widget);
2344                 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
2345             }
2346         }
2347         break;
2348 
2349 #ifndef QT_NO_COMBOBOX
2350 
2351     case CE_ComboBoxLabel:
2352         if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
2353             QRect editRect = proxy()->subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
2354             bool appearsAsList = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, cb, widget);
2355             painter->save();
2356             painter->setClipRect(editRect);
2357 
2358             if (!cb->currentIcon.isNull()) {
2359                 QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
2360                                    : QIcon::Disabled;
2361                 QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
2362                 QRect iconRect(editRect);
2363                 iconRect.setWidth(cb->iconSize.width() + 4);
2364 
2365                 iconRect = alignedRect(cb->direction,
2366                                        Qt::AlignLeft | Qt::AlignVCenter,
2367                                        iconRect.size(), editRect);
2368 
2369                 if (cb->editable)
2370                     painter->fillRect(iconRect, option->palette.brush(QPalette::Base));
2371 
2372                 proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
2373 
2374                 if (cb->direction == Qt::RightToLeft)
2375                     editRect.translate(-4 - cb->iconSize.width(), 0);
2376                 else
2377                     editRect.translate(cb->iconSize.width() + 4, 0);
2378             }
2379 
2380             if (!cb->currentText.isEmpty() && !cb->editable) {
2381                 GtkWidget *gtkCombo = d->gtkWidget("GtkComboBox");
2382                 QPalette pal = cb->palette;
2383                 int labelState = GTK_STATE_INSENSITIVE;
2384 
2385                 if (option->state & State_Enabled)
2386                     labelState = (option->state & State_MouseOver && !appearsAsList) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
2387 
2388                 GdkColor gdkText = gtkCombo->style->fg[labelState];
2389 
2390                 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2391 
2392                 pal.setBrush(QPalette::ButtonText, textColor);
2393 
2394                 proxy()->drawItemText(painter, editRect.adjusted(1, 0, -1, 0),
2395                              visualAlignment(cb->direction, Qt::AlignLeft | Qt::AlignVCenter),
2396                              pal, cb->state & State_Enabled, cb->currentText, QPalette::ButtonText);
2397             }
2398 
2399             painter->restore();
2400         }
2401         break;
2402 
2403 #endif // QT_NO_COMBOBOX
2404 
2405     case CE_DockWidgetTitle:
2406         painter->save();
2407         if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) {
2408             const QStyleOptionDockWidgetV2 *v2
2409                 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(dwOpt);
2410             bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
2411 
2412             QRect rect = dwOpt->rect;
2413             QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget).adjusted(-2, 0, -2, 0);
2414             QRect r = rect.adjusted(0, 0, -1, -1);
2415             if (verticalTitleBar)
2416                 r.adjust(0, 0, 0, -1);
2417 
2418             if (verticalTitleBar) {
2419                 QRect r = rect;
2420                 QSize s = r.size();
2421                 s.transpose();
2422                 r.setSize(s);
2423 
2424                 titleRect = QRect(r.left() + rect.bottom()
2425                                     - titleRect.bottom(),
2426                                 r.top() + titleRect.left() - rect.left(),
2427                                 titleRect.height(), titleRect.width());
2428 
2429                 painter->translate(r.left(), r.top() + r.width());
2430                 painter->rotate(-90);
2431                 painter->translate(-r.left(), -r.top());
2432 
2433                 rect = r;
2434             }
2435 
2436             if (!dwOpt->title.isEmpty()) {
2437                 QString titleText
2438                     = painter->fontMetrics().elidedText(dwOpt->title,
2439                                             Qt::ElideRight, titleRect.width());
2440                 proxy()->drawItemText(painter,
2441                              titleRect,
2442                              Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette,
2443                              dwOpt->state & State_Enabled, titleText,
2444                              QPalette::WindowText);
2445                 }
2446         }
2447         painter->restore();
2448         break;
2449 
2450 
2451 
2452     case CE_HeaderSection:
2453         painter->save();
2454 
2455         // Draws the header in tables.
2456         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
2457             Q_UNUSED(header);
2458             GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
2459             // Get the middle column
2460             GtkTreeViewColumn *column = d->gtk_tree_view_get_column((GtkTreeView*)gtkTreeView, 1);
2461             Q_ASSERT(column);
2462 
2463             GtkWidget *gtkTreeHeader = column->button;
2464             GtkStateType state = gtkPainter.gtkState(option);
2465             GtkShadowType shadow = GTK_SHADOW_OUT;
2466 
2467             if (option->state & State_Sunken)
2468                 shadow = GTK_SHADOW_IN;
2469 
2470             gtkPainter.paintBox(gtkTreeHeader, "button",  option->rect.adjusted(-1, 0, 0, 0), state, shadow, gtkTreeHeader->style);
2471         }
2472 
2473         painter->restore();
2474         break;
2475 
2476 #ifndef QT_NO_SIZEGRIP
2477 
2478     case CE_SizeGrip: {
2479         GtkWidget *gtkStatusbar = d->gtkWidget("GtkStatusbar.GtkFrame");
2480         QRect gripRect = option->rect.adjusted(0, 0, -gtkStatusbar->style->xthickness, -gtkStatusbar->style->ythickness);
2481         gtkPainter.paintResizeGrip( gtkStatusbar, "statusbar", gripRect, GTK_STATE_NORMAL,
2482                                     GTK_SHADOW_OUT, QApplication::isRightToLeft() ?
2483                                         GDK_WINDOW_EDGE_SOUTH_WEST : GDK_WINDOW_EDGE_SOUTH_EAST,
2484                                     gtkStatusbar->style);
2485     }
2486     break;
2487 
2488 #endif // QT_NO_SIZEGRIP
2489 
2490     case CE_MenuBarEmptyArea: {
2491         GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
2492         GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
2493         painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
2494         if (widget) { // See CE_MenuBarItem
2495             QRect menuBarRect = widget->rect();
2496             QPixmap pixmap(menuBarRect.size());
2497             pixmap.fill(Qt::transparent);
2498             QPainter pmPainter(&pixmap);
2499             QGtkPainter gtkMenuBarPainter(&pmPainter);
2500             GtkShadowType shadow_type;
2501             d->gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL);
2502             gtkMenuBarPainter.paintBox( gtkMenubar, "menubar",  menuBarRect,
2503                                         GTK_STATE_NORMAL, shadow_type, gtkMenubar->style);
2504             pmPainter.end();
2505             painter->drawPixmap(option->rect, pixmap, option->rect);
2506         }
2507     }
2508     break;
2509 
2510     case CE_MenuBarItem:
2511         painter->save();
2512 
2513         if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
2514             GtkWidget *gtkMenubarItem = d->gtkWidget("GtkMenuBar.GtkMenuItem");
2515             GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
2516 
2517             style = gtkMenubarItem->style;
2518 
2519             if (widget) {
2520                 // Since Qt does not currently allow filling the entire background
2521                 // we use a hack for this by making a complete menubar each time and
2522                 // paint with the correct offset inside it. Pixmap caching should resolve
2523                 // most of the performance penalty.
2524                 QRect menuBarRect = widget->rect();
2525                 QPixmap pixmap(menuBarRect.size());
2526                 pixmap.fill(Qt::transparent);
2527                 QPainter pmPainter(&pixmap);
2528                 QGtkPainter menubarPainter(&pmPainter);
2529                 GtkShadowType shadow_type;
2530                 d->gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL);
2531                 GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
2532                 painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
2533                 menubarPainter.paintBox(gtkMenubar, "menubar",  menuBarRect,
2534                                         GTK_STATE_NORMAL, shadow_type, gtkMenubar->style);
2535                 pmPainter.end();
2536                 painter->drawPixmap(option->rect, pixmap, option->rect);
2537             }
2538 
2539             QStyleOptionMenuItem item = *mbi;
2540             bool act = mbi->state & State_Selected && mbi->state & State_Sunken;
2541             bool dis = !(mbi->state & State_Enabled);
2542             item.rect = mbi->rect;
2543             GdkColor gdkText = gtkMenubarItem->style->fg[dis ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL];
2544             GdkColor gdkHText = gtkMenubarItem->style->fg[GTK_STATE_PRELIGHT];
2545             QColor normalTextColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2546             QColor highlightedTextColor = QColor(gdkHText.red>>8, gdkHText.green>>8, gdkHText.blue>>8);
2547             item.palette.setBrush(QPalette::HighlightedText, highlightedTextColor);
2548             item.palette.setBrush(QPalette::Text, normalTextColor);
2549             item.palette.setBrush(QPalette::ButtonText, normalTextColor);
2550             QCommonStyle::drawControl(element, &item, painter, widget);
2551 
2552             if (act) {
2553                 GtkShadowType shadowType = GTK_SHADOW_NONE;
2554                 d->gtk_widget_style_get (gtkMenubarItem, "selected-shadow-type", &shadowType, NULL);
2555                 gtkPainter.paintBox(gtkMenubarItem, "menuitem",  option->rect.adjusted(0, 0, 0, 3),
2556                                     GTK_STATE_PRELIGHT, shadowType, gtkMenubarItem->style);
2557                 //draw text
2558                 QPalette::ColorRole textRole = dis ? QPalette::Text : QPalette::HighlightedText;
2559                 uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2560 
2561                 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
2562                     alignment |= Qt::TextHideMnemonic;
2563 
2564                 proxy()->drawItemText(painter, item.rect, alignment, item.palette, mbi->state & State_Enabled, mbi->text, textRole);
2565             }
2566         }
2567         painter->restore();
2568         break;
2569 
2570     case CE_Splitter: {
2571         GtkWidget *gtkWindow = d->gtkWidget("GtkWindow"); // The Murrine Engine currently assumes a widget is passed
2572         gtkPainter.paintHandle(gtkWindow, "splitter", option->rect, gtkPainter.gtkState(option), GTK_SHADOW_NONE,
2573                                 !(option->state & State_Horizontal) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL,
2574                                 style);
2575     }
2576     break;
2577 
2578 #ifndef QT_NO_TOOLBAR
2579 
2580     case CE_ToolBar:
2581         if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) {
2582             // Reserve the beveled appearance only for mainwindow toolbars
2583             if (!(widget && qobject_cast<const QMainWindow*> (widget->parentWidget())))
2584                 break;
2585 
2586             QRect rect = option->rect;
2587             // There is a 1 pixel gap between toolbar lines in some styles (i.e Human)
2588             if (toolbar->positionWithinLine != QStyleOptionToolBar::End)
2589                 rect.adjust(0, 0, 1, 0);
2590 
2591             GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
2592             GtkShadowType shadow_type = GTK_SHADOW_NONE;
2593             d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
2594             gtkPainter.paintBox( gtkToolbar, "toolbar",  rect,
2595                                  GTK_STATE_NORMAL, shadow_type, gtkToolbar->style);
2596         }
2597         break;
2598 
2599 #endif // QT_NO_TOOLBAR
2600 
2601     case CE_MenuItem:
2602         painter->save();
2603 
2604         // Draws one item in a popup menu.
2605         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
2606             const int windowsItemFrame        =  2; // menu item frame width
2607             const int windowsItemHMargin      =  3; // menu item hor text margin
2608             const int windowsItemVMargin      = 26; // menu item ver text margin
2609             const int windowsRightBorder      = 15; // right border on windows
2610             GtkWidget *gtkMenuItem = menuItem->checked ? d->gtkWidget("GtkMenu.GtkCheckMenuItem") :
2611                                      d->gtkWidget("GtkMenu.GtkMenuItem");
2612 
2613             style = gtkPainter.getStyle(gtkMenuItem);
2614             QColor shadow = option->palette.dark().color();
2615 
2616             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
2617                 GtkWidget *gtkMenuSeparator = d->gtkWidget("GtkMenu.GtkSeparatorMenuItem");
2618                 painter->setPen(shadow.lighter(106));
2619                 gboolean wide_separators = 0;
2620                 gint     separator_height = 0;
2621                 guint    horizontal_padding = 3;
2622                 QRect separatorRect = option->rect;
2623                 if (!d->gtk_check_version(2, 10, 0)) {
2624                     d->gtk_widget_style_get(gtkMenuSeparator,
2625                                            "wide-separators",    &wide_separators,
2626                                            "separator-height",   &separator_height,
2627                                            "horizontal-padding", &horizontal_padding,
2628                                            NULL);
2629                 }
2630                 separatorRect.setHeight(option->rect.height() - 2 * gtkMenuSeparator->style->ythickness);
2631                 separatorRect.setWidth(option->rect.width() - 2 * (horizontal_padding + gtkMenuSeparator->style->xthickness));
2632                 separatorRect.moveCenter(option->rect.center());
2633                 if (wide_separators)
2634                    gtkPainter.paintBox( gtkMenuSeparator, "hseparator",
2635                                         separatorRect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, gtkMenuSeparator->style);
2636                 else
2637                     gtkPainter.paintHline( gtkMenuSeparator, "hseparator",
2638                                            separatorRect, GTK_STATE_NORMAL, gtkMenuSeparator->style,
2639                                            0, option->rect.right() - 1, 1);
2640                 painter->restore();
2641                 break;
2642             }
2643 
2644             bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
2645 
2646             if (selected) {
2647                 QRect rect = option->rect;
2648 #ifndef QT_NO_COMBOBOX
2649                 if (qobject_cast<const QComboBox*>(widget))
2650                     rect = option->rect;
2651 #endif
2652                 gtkPainter.paintBox( gtkMenuItem, "menuitem", rect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style);
2653             }
2654 
2655             bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
2656             bool checked = menuItem->checked;
2657             bool enabled = menuItem->state & State_Enabled;
2658             bool ignoreCheckMark = false;
2659 
2660             gint checkSize;
2661             d->gtk_widget_style_get(d->gtkWidget("GtkMenu.GtkCheckMenuItem"), "indicator-size", &checkSize, NULL);
2662 
2663             int checkcol = qMax(menuItem->maxIconWidth, qMax(20, checkSize));
2664 
2665 #ifndef QT_NO_COMBOBOX
2666 
2667             if (qobject_cast<const QComboBox*>(widget))
2668                 ignoreCheckMark = true; // Ignore the checkmarks provided by the QComboMenuDelegate
2669 
2670 #endif
2671             if (!ignoreCheckMark) {
2672                 // Check
2673                 QRect checkRect(option->rect.left() + 7, option->rect.center().y() - checkSize/2 + 1, checkSize, checkSize);
2674                 checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
2675 
2676                 if (checkable && menuItem->icon.isNull()) {
2677                     // Some themes such as aero-clone draw slightly outside the paint rect
2678                     int spacing = 1; // ### Consider using gtkCheckBox : "indicator-spacing" instead
2679 
2680                     if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) {
2681                         // Radio button
2682                         GtkShadowType shadow = GTK_SHADOW_OUT;
2683                         GtkStateType state = gtkPainter.gtkState(option);
2684 
2685                         if (selected)
2686                             state = GTK_STATE_PRELIGHT;
2687                         if (checked)
2688                             shadow = GTK_SHADOW_IN;
2689 
2690                         gtkPainter.setClipRect(checkRect.adjusted(-spacing, -spacing, spacing, spacing));
2691                         gtkPainter.paintOption(gtkMenuItem, checkRect.translated(-spacing, -spacing), state, shadow,
2692                                                gtkMenuItem->style, QLS("option"));
2693                         gtkPainter.setClipRect(QRect());
2694 
2695                     } else {
2696                         // Check box
2697                         if (menuItem->icon.isNull()) {
2698                             GtkShadowType shadow = GTK_SHADOW_OUT;
2699                             GtkStateType state = gtkPainter.gtkState(option);
2700 
2701                             if (selected)
2702                                 state = GTK_STATE_PRELIGHT;
2703                             if (checked)
2704                                 shadow = GTK_SHADOW_IN;
2705 
2706                             gtkPainter.setClipRect(checkRect.adjusted(-spacing, -spacing, -spacing, -spacing));
2707                             gtkPainter.paintCheckbox(gtkMenuItem, checkRect.translated(-spacing, -spacing), state, shadow,
2708                                                      gtkMenuItem->style, QLS("check"));
2709                            gtkPainter.setClipRect(QRect());
2710                         }
2711                     }
2712                 }
2713 
2714             } else {
2715                 // Ignore checkmark
2716                 if (menuItem->icon.isNull())
2717                     checkcol = 0;
2718                 else
2719                     checkcol = menuItem->maxIconWidth;
2720             }
2721 
2722             bool dis = !(menuItem->state & State_Enabled);
2723             bool act = menuItem->state & State_Selected;
2724             const QStyleOption *opt = option;
2725             const QStyleOptionMenuItem *menuitem = menuItem;
2726             QPainter *p = painter;
2727             QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
2728                                           QRect(menuitem->rect.x() + 3, menuitem->rect.y(),
2729                                                 checkcol, menuitem->rect.height()));
2730 
2731             if (!menuItem->icon.isNull()) {
2732                 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
2733 
2734                 if (act && !dis)
2735                     mode = QIcon::Active;
2736 
2737                 QPixmap pixmap;
2738                 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2739                 QSize iconSize(smallIconSize, smallIconSize);
2740 
2741 #ifndef QT_NO_COMBOBOX
2742                 if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget))
2743                     iconSize = combo->iconSize();
2744 
2745 #endif // QT_NO_COMBOBOX
2746                 if (checked)
2747                     pixmap = menuItem->icon.pixmap(iconSize, mode, QIcon::On);
2748                 else
2749                     pixmap = menuItem->icon.pixmap(iconSize, mode);
2750 
2751                 int pixw = pixmap.width();
2752                 int pixh = pixmap.height();
2753                 QRect pmr(0, 0, pixw, pixh);
2754                 pmr.moveCenter(vCheckRect.center() - QPoint(0, 1));
2755                 painter->setPen(menuItem->palette.text().color());
2756                 if (!ignoreCheckMark && checkable && checked) {
2757                     QStyleOption opt = *option;
2758 
2759                     if (act) {
2760                         QColor activeColor = mergedColors(option->palette.background().color(),
2761                                                           option->palette.highlight().color());
2762                         opt.palette.setBrush(QPalette::Button, activeColor);
2763                     }
2764                     opt.state |= State_Sunken;
2765                     opt.rect = vCheckRect;
2766                     proxy()->drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget);
2767                 }
2768                 painter->drawPixmap(pmr.topLeft(), pixmap);
2769             }
2770 
2771             GdkColor gdkText = gtkMenuItem->style->fg[GTK_STATE_NORMAL];
2772             GdkColor gdkDText = gtkMenuItem->style->fg[GTK_STATE_INSENSITIVE];
2773             GdkColor gdkHText = gtkMenuItem->style->fg[GTK_STATE_PRELIGHT];
2774             uint resolve_mask = option->palette.resolve();
2775             QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2776             QColor disabledTextColor = QColor(gdkDText.red>>8, gdkDText.green>>8, gdkDText.blue>>8);
2777             if (resolve_mask & (1 << QPalette::ButtonText)) {
2778                 textColor = option->palette.buttonText().color();
2779                 disabledTextColor = option->palette.brush(QPalette::Disabled, QPalette::ButtonText).color();
2780             }
2781 
2782             QColor highlightedTextColor = QColor(gdkHText.red>>8, gdkHText.green>>8, gdkHText.blue>>8);
2783             if (resolve_mask & (1 << QPalette::HighlightedText)) {
2784                 highlightedTextColor = option->palette.highlightedText().color();
2785             }
2786 
2787             if (selected)
2788                 painter->setPen(highlightedTextColor);
2789             else
2790                 painter->setPen(textColor);
2791 
2792             int x, y, w, h;
2793             menuitem->rect.getRect(&x, &y, &w, &h);
2794             int tab = menuitem->tabWidth;
2795             int xm = windowsItemFrame + checkcol + windowsItemHMargin;
2796             int xpos = menuitem->rect.x() + xm + 1;
2797             QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
2798             QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
2799             QString s = menuitem->text;
2800 
2801             if (!s.isEmpty()) { // Draw text
2802                 p->save();
2803                 int t = s.indexOf(QLatin1Char('\t'));
2804                 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2805 
2806                 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
2807                     text_flags |= Qt::TextHideMnemonic;
2808 
2809                 // Draw shortcut right aligned
2810                 text_flags |= Qt::AlignRight;
2811 
2812                 if (t >= 0) {
2813                     int rightMargin = 12; // Hardcode for now
2814                     QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
2815                                                      QRect(textRect.topRight(), QPoint(menuitem->rect.right() - rightMargin, textRect.bottom())));
2816 
2817                     if (dis)
2818                         p->setPen(disabledTextColor);
2819                     p->drawText(vShortcutRect, text_flags , s.mid(t + 1));
2820                     s = s.left(t);
2821                 }
2822 
2823                 text_flags &= ~Qt::AlignRight;
2824                 text_flags |= Qt::AlignLeft;
2825                 QFont font = menuitem->font;
2826                 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
2827                     font.setBold(true);
2828                 p->setFont(font);
2829 
2830                 if (dis)
2831                     p->setPen(disabledTextColor);
2832                 p->drawText(vTextRect, text_flags, s.left(t));
2833                 p->restore();
2834             }
2835 
2836             // Arrow
2837             if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
2838 
2839                 QFontMetrics fm(menuitem->font);
2840                 int arrow_size = fm.ascent() + fm.descent() - 2 * gtkMenuItem->style->ythickness;
2841                 gfloat arrow_scaling = 0.8;
2842                 int extra = 0;
2843                 if (!d->gtk_check_version(2, 16, 0)) {
2844                     // "arrow-scaling" is actually hardcoded and fails on hardy (see gtk+-2.12/gtkmenuitem.c)
2845                     // though the current documentation states otherwise
2846                     d->gtk_widget_style_get(gtkMenuItem, "arrow-scaling", &arrow_scaling, NULL);
2847                     // in versions < 2.16 ythickness was previously subtracted from the arrow_size
2848                     extra = 2 * gtkMenuItem->style->ythickness;
2849                 }
2850 
2851                 int horizontal_padding;
2852                 d->gtk_widget_style_get(gtkMenuItem, "horizontal-padding", &horizontal_padding, NULL);
2853 
2854                 const int dim = static_cast<int>(arrow_size * arrow_scaling) + extra;
2855                 int xpos = menuItem->rect.left() + menuItem->rect.width() - horizontal_padding - dim;
2856                 QRect  vSubMenuRect = visualRect(option->direction, menuItem->rect,
2857                                                  QRect(xpos, menuItem->rect.top() +
2858                                                        menuItem->rect.height() / 2 - dim / 2, dim, dim));
2859                 GtkStateType state = enabled ? (act ? GTK_STATE_PRELIGHT: GTK_STATE_NORMAL) : GTK_STATE_INSENSITIVE;
2860                 GtkShadowType shadowType = (state == GTK_STATE_PRELIGHT) ? GTK_SHADOW_OUT : GTK_SHADOW_IN;
2861                 gtkPainter.paintArrow(gtkMenuItem, "menuitem", vSubMenuRect, QApplication::isRightToLeft() ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT, state,
2862                                       shadowType, FALSE, style);
2863             }
2864         }
2865         painter->restore();
2866         break;
2867 
2868     case CE_PushButton:
2869         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2870             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
2871             proxy()->drawControl(CE_PushButtonBevel, btn, painter, widget);
2872             QStyleOptionButton subopt = *btn;
2873             subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
2874             gint interiorFocus = true;
2875             d->gtk_widget_style_get(gtkButton, "interior-focus", &interiorFocus, NULL);
2876             int xt = interiorFocus ? gtkButton->style->xthickness : 0;
2877             int yt = interiorFocus ? gtkButton->style->ythickness : 0;
2878 
2879             if (btn->features & QStyleOptionButton::Flat && btn->state & State_HasFocus)
2880                 // The normal button focus rect does not work well for flat buttons in Clearlooks
2881                 proxy()->drawPrimitive(PE_FrameFocusRect, option, painter, widget);
2882             else if (btn->state & State_HasFocus)
2883                 gtkPainter.paintFocus(gtkButton, "button",
2884                                       option->rect.adjusted(xt, yt, -xt, -yt),
2885                                       btn->state & State_Sunken ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL,
2886                                       gtkButton->style);
2887 
2888             proxy()->drawControl(CE_PushButtonLabel, &subopt, painter, widget);
2889         }
2890         break;
2891 
2892 #ifndef QT_NO_TABBAR
2893 
2894     case CE_TabBarTabShape:
2895         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
2896             GtkWidget *gtkNotebook = d->gtkWidget("GtkNotebook");
2897             style = gtkPainter.getStyle(gtkNotebook);
2898 
2899             QRect rect = option->rect;
2900             GtkShadowType shadow = GTK_SHADOW_OUT;
2901             GtkStateType state = GTK_STATE_ACTIVE;
2902             if (tab->state & State_Selected)
2903                 state = GTK_STATE_NORMAL;
2904 
2905             bool selected = (tab->state & State_Selected);
2906             bool first = false, last = false;
2907             if (widget) {
2908                 // This is most accurate and avoids resizing tabs while moving
2909                 first = tab->rect.left() == widget->rect().left();
2910                 last = tab->rect.right() == widget->rect().right();
2911             } else if (option->direction == Qt::RightToLeft) {
2912                 bool tmp = first;
2913                 first = last;
2914                 last = tmp;
2915             }
2916             int topIndent = 3;
2917             int bottomIndent = 1;
2918             int tabOverlap = 1;
2919             painter->save();
2920 
2921             switch (tab->shape) {
2922             case QTabBar::RoundedNorth:
2923                 if (!selected)
2924                     rect.adjust(first ? 0 : -tabOverlap, topIndent, last ? 0 : tabOverlap, -bottomIndent);
2925                 gtkPainter.paintExtention( gtkNotebook, "tab", rect,
2926                                            state, shadow, GTK_POS_BOTTOM, style);
2927                 break;
2928 
2929             case QTabBar::RoundedSouth:
2930                 if (!selected)
2931                     rect.adjust(first ? 0 : -tabOverlap, 0, last ? 0 : tabOverlap, -topIndent);
2932                 gtkPainter.paintExtention( gtkNotebook, "tab", rect.adjusted(0, 1, 0, 0),
2933                                            state, shadow, GTK_POS_TOP, style);
2934                 break;
2935 
2936             case QTabBar::RoundedWest:
2937                 if (!selected)
2938                     rect.adjust(topIndent, 0, -bottomIndent, 0);
2939                 gtkPainter.paintExtention( gtkNotebook, "tab", rect, state, shadow, GTK_POS_RIGHT, style);
2940                 break;
2941 
2942             case QTabBar::RoundedEast:
2943                 if (!selected)
2944                     rect.adjust(bottomIndent, 0, -topIndent, 0);
2945                 gtkPainter.paintExtention( gtkNotebook, "tab", rect, state, shadow, GTK_POS_LEFT, style);
2946                 break;
2947 
2948             default:
2949                 QCleanlooksStyle::drawControl(element, option, painter, widget);
2950                 break;
2951             }
2952 
2953             painter->restore();
2954         }
2955 
2956         break;
2957 
2958 #endif //QT_NO_TABBAR
2959 
2960     case CE_ProgressBarGroove:
2961         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2962             Q_UNUSED(bar);
2963             GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
2964             GtkStateType state = gtkPainter.gtkState(option);
2965             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, gtkProgressBar->style);
2966         }
2967 
2968         break;
2969 
2970     case CE_ProgressBarContents:
2971         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2972             GtkStateType state = option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE;
2973             GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
2974             style = gtkProgressBar->style;
2975             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, style);
2976             int xt = style->xthickness;
2977             int yt = style->ythickness;
2978             QRect rect = bar->rect.adjusted(xt, yt, -xt, -yt);
2979             bool vertical = false;
2980             bool inverted = false;
2981             bool indeterminate = (bar->minimum == 0 && bar->maximum == 0);
2982             // Get extra style options if version 2
2983 
2984             if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
2985                 vertical = (bar2->orientation == Qt::Vertical);
2986                 inverted = bar2->invertedAppearance;
2987             }
2988 
2989             // If the orientation is vertical, we use a transform to rotate
2990             // the progress bar 90 degrees clockwise.  This way we can use the
2991             // same rendering code for both orientations.
2992             if (vertical) {
2993                 rect.translate(xt, -yt * 2);
2994                 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // Flip width and height
2995                 QTransform m = QTransform::fromTranslate(rect.height(), 0);
2996                 m.rotate(90.0);
2997                 painter->setTransform(m);
2998             }
2999 
3000             int maxWidth = rect.width();
3001             int minWidth = 4;
3002 
3003             qint64 progress = (qint64)qMax(bar->progress, bar->minimum); // Workaround for bug in QProgressBar
3004             double vc6_workaround = ((progress - qint64(bar->minimum)) / double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth;
3005             int progressBarWidth = (int(vc6_workaround) > minWidth ) ? int(vc6_workaround) : minWidth;
3006             int width = indeterminate ? maxWidth : progressBarWidth;
3007             bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical;
3008 
3009             if (inverted)
3010                 reverse = !reverse;
3011 
3012             int maximum = 2;
3013             int fakePos = 0;
3014             if (bar->minimum == bar->maximum)
3015                 maximum = 0;
3016             if (bar->progress == bar->maximum)
3017                 fakePos = maximum;
3018             else if (bar->progress > bar->minimum)
3019                 fakePos = maximum - 1;
3020 
3021             d->gtk_progress_configure((GtkProgress*)gtkProgressBar, fakePos, 0, maximum);
3022 
3023             QRect progressBar;
3024 
3025             if (!indeterminate) {
3026                 if (!reverse)
3027                     progressBar.setRect(rect.left(), rect.top(), width, rect.height());
3028                 else
3029                     progressBar.setRect(rect.right() - width, rect.top(), width, rect.height());
3030 
3031             } else {
3032                 Q_D(const QGtkStyle);
3033                 int slideWidth = ((rect.width() - 4) * 2) / 3;
3034                 int step = ((d->animateStep * slideWidth) / d->animationFps) % slideWidth;
3035                 if ((((d->animateStep * slideWidth) / d->animationFps) % (2 * slideWidth)) >= slideWidth)
3036                     step = slideWidth - step;
3037                 progressBar.setRect(rect.left() + step, rect.top(), slideWidth / 2, rect.height());
3038             }
3039 
3040             QString key = QString(QLS("%0")).arg(fakePos);
3041             if (inverted) {
3042                 key += QLatin1String("inv");
3043                 gtkPainter.setFlipHorizontal(true);
3044             }
3045             gtkPainter.paintBox( gtkProgressBar, "bar",  progressBar, GTK_STATE_SELECTED, GTK_SHADOW_OUT, style, key);
3046         }
3047 
3048         break;
3049 
3050     default:
3051         QCleanlooksStyle::drawControl(element, option, painter, widget);
3052     }
3053 }
3054 
3055 /*!
3056   \reimp
3057 */
subControlRect(ComplexControl control,const QStyleOptionComplex * option,SubControl subControl,const QWidget * widget) const3058 QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
3059                                 SubControl subControl, const QWidget *widget) const
3060 {
3061     Q_D(const QGtkStyle);
3062 
3063     QRect rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
3064     if (!d->isThemeAvailable())
3065         return QCleanlooksStyle::subControlRect(control, option, subControl, widget);
3066 
3067     switch (control) {
3068     case CC_TitleBar:
3069         return QCleanlooksStyle::subControlRect(control, option, subControl, widget);
3070 
3071     case CC_Slider:
3072         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3073             // Reserve space for outside focus rect
3074             QStyleOptionSlider sliderCopy = *slider;
3075             sliderCopy.rect = option->rect.adjusted(2, 2, -2, -2);
3076             return QCleanlooksStyle::subControlRect(control, &sliderCopy, subControl, widget);
3077         }
3078 
3079         break;
3080 
3081 #ifndef QT_NO_GROUPBOX
3082 
3083     case CC_GroupBox:
3084         if (qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
3085             rect = option->rect.adjusted(0, groupBoxTopMargin, 0, -groupBoxBottomMargin);
3086             int topMargin = 0;
3087             int topHeight = 0;
3088             topHeight = 10;
3089             QRect frameRect = rect;
3090             frameRect.setTop(topMargin);
3091 
3092             if (subControl == SC_GroupBoxFrame)
3093                 return rect;
3094             else if (subControl == SC_GroupBoxContents) {
3095                 int margin = 0;
3096                 int leftMarginExtension = 8;
3097                 return frameRect.adjusted(leftMarginExtension + margin, margin + topHeight + groupBoxTitleMargin, -margin, -margin);
3098             }
3099 
3100             if (const QGroupBox *groupBoxWidget = qobject_cast<const QGroupBox *>(widget)) {
3101                 //Prepare metrics for a bold font
3102                 QFont font = widget->font();
3103                 font.setBold(true);
3104                 QFontMetrics fontMetrics(font);
3105                 QSize textRect = fontMetrics.boundingRect(groupBoxWidget->title()).size() + QSize(4, 4);
3106                 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, option, widget);
3107                 int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, option, widget);
3108 
3109                 if (subControl == SC_GroupBoxCheckBox) {
3110                     rect.setWidth(indicatorWidth);
3111                     rect.setHeight(indicatorHeight);
3112                     rect.moveTop((textRect.height() - indicatorHeight) / 2);
3113 
3114                 } else if (subControl == SC_GroupBoxLabel) {
3115                     if (groupBoxWidget->isCheckable())
3116                         rect.adjust(indicatorWidth + 4, 0, 0, 0);
3117                     rect.setSize(textRect);
3118                 }
3119                 rect = visualRect(option->direction, option->rect, rect);
3120             }
3121         }
3122 
3123         return rect;
3124 
3125 #endif
3126 #ifndef QT_NO_SPINBOX
3127 
3128     case CC_SpinBox:
3129         if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
3130             GtkWidget *gtkSpinButton = d->gtkWidget("GtkSpinButton");
3131             int center = spinbox->rect.height() / 2;
3132             int xt = spinbox->frame ? gtkSpinButton->style->xthickness : 0;
3133             int yt = spinbox->frame ? gtkSpinButton->style->ythickness : 0;
3134             int y = yt;
3135 
3136             QSize bs;
3137             bs.setHeight(qMax(8, spinbox->rect.height()/2 - y));
3138             bs.setWidth(d->getSpinboxArrowSize());
3139             int x, lx, rx;
3140             x = spinbox->rect.width() - y - bs.width() + 2;
3141             lx = xt;
3142             rx = x - xt;
3143 
3144             switch (subControl) {
3145 
3146             case SC_SpinBoxUp:
3147                 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
3148                     return QRect();
3149                 rect = QRect(x, xt, bs.width(), center - yt);
3150                 break;
3151 
3152             case SC_SpinBoxDown:
3153                 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
3154                     return QRect();
3155                 rect = QRect(x, center, bs.width(), spinbox->rect.bottom() - center - yt + 1);
3156                 break;
3157 
3158             case SC_SpinBoxEditField:
3159                 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
3160                     rect = QRect(lx, yt, spinbox->rect.width() - 2*xt, spinbox->rect.height() - 2*yt);
3161                 else
3162                     rect = QRect(lx, yt, rx - qMax(xt - 1, 0), spinbox->rect.height() - 2*yt);
3163                 break;
3164 
3165             case SC_SpinBoxFrame:
3166                 rect = spinbox->rect;
3167 
3168             default:
3169                 break;
3170             }
3171 
3172             rect = visualRect(spinbox->direction, spinbox->rect, rect);
3173         }
3174 
3175         break;
3176 
3177 #endif // Qt_NO_SPINBOX
3178 #ifndef QT_NO_COMBOBOX
3179 
3180     case CC_ComboBox:
3181         if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3182             // We employ the gtk widget to position arrows and separators for us
3183             GtkWidget *gtkCombo = box->editable ? d->gtkWidget("GtkComboBoxEntry")
3184                                                 : d->gtkWidget("GtkComboBox");
3185             d->gtk_widget_set_direction(gtkCombo, (option->direction == Qt::RightToLeft) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
3186             GtkAllocation geometry = {0, 0, qMax(0, option->rect.width()), qMax(0, option->rect.height())};
3187             d->gtk_widget_size_allocate(gtkCombo, &geometry);
3188             int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, option, widget);
3189             QHashableLatin1Literal arrowPath("GtkComboBoxEntry.GtkToggleButton");
3190             if (!box->editable) {
3191                 if (appears_as_list)
3192                     arrowPath = "GtkComboBox.GtkToggleButton";
3193                 else
3194                     arrowPath = "GtkComboBox.GtkToggleButton.GtkHBox.GtkArrow";
3195             }
3196 
3197             GtkWidget *arrowWidget = d->gtkWidget(arrowPath);
3198             if (!arrowWidget)
3199                 return QCleanlooksStyle::subControlRect(control, option, subControl, widget);
3200 
3201             QRect buttonRect(option->rect.left() + arrowWidget->allocation.x,
3202                              option->rect.top() + arrowWidget->allocation.y,
3203                              arrowWidget->allocation.width, arrowWidget->allocation.height);
3204 
3205             switch (subControl) {
3206 
3207             case SC_ComboBoxArrow: // Note: this indicates the arrowbutton for editable combos
3208                 rect = buttonRect;
3209                 break;
3210 
3211             case SC_ComboBoxEditField: {
3212                 rect = visualRect(option->direction, option->rect, rect);
3213                 int xMargin = box->editable ? 1 : 4, yMargin = 2;
3214                 rect.setRect(option->rect.left() + gtkCombo->style->xthickness + xMargin,
3215                              option->rect.top()  + gtkCombo->style->ythickness + yMargin,
3216                              option->rect.width() - buttonRect.width() - 2*(gtkCombo->style->xthickness + xMargin),
3217                              option->rect.height() - 2*(gtkCombo->style->ythickness + yMargin));
3218                 rect = visualRect(option->direction, option->rect, rect);
3219                 break;
3220             }
3221 
3222             default:
3223                 break;
3224             }
3225         }
3226 
3227         break;
3228 
3229 #endif // QT_NO_COMBOBOX
3230 
3231     default:
3232         break;
3233     }
3234 
3235     return rect;
3236 }
3237 
3238 /*!
3239   \reimp
3240 */
sizeFromContents(ContentsType type,const QStyleOption * option,const QSize & size,const QWidget * widget) const3241 QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
3242                                   const QSize &size, const QWidget *widget) const
3243 {
3244     Q_D(const QGtkStyle);
3245 
3246     QSize newSize = QCleanlooksStyle::sizeFromContents(type, option, size, widget);
3247     if (!d->isThemeAvailable())
3248         return newSize;
3249 
3250     switch (type) {
3251 
3252     case CT_ToolButton:
3253         if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
3254             GtkWidget *gtkButton = d->gtkWidget("GtkToolButton.GtkButton");
3255             newSize = size + QSize(2 * gtkButton->style->xthickness, 2 + 2 * gtkButton->style->ythickness);
3256             if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
3257                 QSize minSize(0, 25);
3258                 if (toolbutton->toolButtonStyle != Qt::ToolButtonTextOnly)
3259                     minSize = toolbutton->iconSize + QSize(12, 12);
3260                 newSize = newSize.expandedTo(minSize);
3261             }
3262 
3263             if (toolbutton->features & QStyleOptionToolButton::HasMenu)
3264                 newSize += QSize(6, 0);
3265         }
3266         break;
3267     case CT_MenuItem:
3268         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
3269             int textMargin = 8;
3270 
3271             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
3272                 GtkWidget *gtkMenuSeparator = d->gtkWidget("GtkMenu.GtkSeparatorMenuItem");
3273                 GtkRequisition sizeReq = {0, 0};
3274                 d->gtk_widget_size_request(gtkMenuSeparator, &sizeReq);
3275                 newSize = QSize(size.width(), sizeReq.height);
3276                 break;
3277             }
3278 
3279             GtkWidget *gtkMenuItem = d->gtkWidget("GtkMenu.GtkCheckMenuItem");
3280             GtkStyle* style = gtkMenuItem->style;
3281 
3282             // Note we get the perfect height for the default font since we
3283             // set a fake text label on the gtkMenuItem
3284             // But if custom fonts are used on the widget we need a minimum size
3285             GtkRequisition sizeReq = {0, 0};
3286             d->gtk_widget_size_request(gtkMenuItem, &sizeReq);
3287             newSize.setHeight(qMax(newSize.height() - 4, sizeReq.height));
3288             newSize += QSize(textMargin + style->xthickness - 1, 0);
3289 
3290             // Cleanlooks assumes a check column of 20 pixels so we need to
3291             // expand it a bit
3292             gint checkSize;
3293             d->gtk_widget_style_get(gtkMenuItem, "indicator-size", &checkSize, NULL);
3294             newSize.setWidth(newSize.width() + qMax(0, checkSize - 20));
3295         }
3296 
3297         break;
3298 
3299     case CT_SpinBox:
3300         // QSpinBox does some nasty things that depends on CT_LineEdit
3301         newSize = size + QSize(0, -d->gtkWidget("GtkSpinButton")->style->ythickness * 2);
3302         break;
3303 
3304     case CT_PushButton:
3305         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
3306             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
3307             gint focusPadding, focusWidth;
3308             d->gtk_widget_style_get(gtkButton, "focus-padding", &focusPadding, NULL);
3309             d->gtk_widget_style_get(gtkButton, "focus-line-width", &focusWidth, NULL);
3310             newSize = size;
3311             newSize += QSize(2*gtkButton->style->xthickness + 4, 2*gtkButton->style->ythickness);
3312             newSize += QSize(2*(focusWidth + focusPadding + 2), 2*(focusWidth + focusPadding));
3313 
3314             GtkWidget *gtkButtonBox = d->gtkWidget("GtkHButtonBox");
3315             gint minWidth = 85, minHeight = 0;
3316             d->gtk_widget_style_get(gtkButtonBox, "child-min-width", &minWidth,
3317                                    "child-min-height", &minHeight, NULL);
3318             if (!btn->text.isEmpty() && newSize.width() < minWidth)
3319                 newSize.setWidth(minWidth);
3320             if (newSize.height() < minHeight)
3321                 newSize.setHeight(minHeight);
3322         }
3323 
3324         break;
3325 
3326     case CT_Slider: {
3327         GtkWidget *gtkSlider = d->gtkWidget("GtkHScale");
3328         newSize = size + QSize(2*gtkSlider->style->xthickness, 2*gtkSlider->style->ythickness);
3329     }
3330     break;
3331 
3332     case CT_LineEdit: {
3333         GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
3334         newSize = size + QSize(2*gtkEntry->style->xthickness, 2 + 2*gtkEntry->style->ythickness);
3335     }
3336     break;
3337 
3338     case CT_ItemViewItem:
3339         newSize += QSize(0, 2);
3340         break;
3341 
3342     case CT_ComboBox:
3343         if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3344             GtkWidget *gtkCombo = d->gtkWidget("GtkComboBox");
3345             QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, combo, SC_ComboBoxArrow, widget);
3346             newSize = size + QSize(12 + arrowButtonRect.width() + 2*gtkCombo->style->xthickness, 4 + 2*gtkCombo->style->ythickness);
3347 
3348             if (!(widget && qobject_cast<QToolBar *>(widget->parentWidget())))
3349                 newSize += QSize(0, 2);
3350         }
3351         break;
3352 
3353     case CT_GroupBox:
3354         newSize += QSize(4, groupBoxBottomMargin + groupBoxTopMargin + groupBoxTitleMargin); // Add some space below the groupbox
3355         break;
3356 
3357     case CT_TabBarTab:
3358         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
3359             if (!tab->icon.isNull())
3360                 newSize += QSize(6, 0);
3361         }
3362         newSize += QSize(1, 1);
3363         break;
3364 
3365     default:
3366         break;
3367     }
3368 
3369     return newSize;
3370 }
3371 
3372 
3373 /*! \reimp */
standardPixmap(StandardPixmap sp,const QStyleOption * option,const QWidget * widget) const3374 QPixmap QGtkStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option,
3375                                   const QWidget *widget) const
3376 {
3377     Q_D(const QGtkStyle);
3378 
3379     if (!d->isThemeAvailable())
3380         return QCleanlooksStyle::standardPixmap(sp, option, widget);
3381 
3382     QPixmap pixmap;
3383     switch (sp) {
3384 
3385     case SP_TitleBarNormalButton: {
3386         QImage restoreButton((const char **)dock_widget_restore_xpm);
3387         QColor alphaCorner = restoreButton.color(2);
3388         alphaCorner.setAlpha(80);
3389         restoreButton.setColor(2, alphaCorner.rgba());
3390         alphaCorner.setAlpha(180);
3391         restoreButton.setColor(4, alphaCorner.rgba());
3392         return QPixmap::fromImage(restoreButton);
3393     }
3394     break;
3395 
3396     case SP_TitleBarCloseButton: // Fall through
3397     case SP_DockWidgetCloseButton: {
3398 
3399         QImage closeButton((const char **)dock_widget_close_xpm);
3400         QColor alphaCorner = closeButton.color(2);
3401         alphaCorner.setAlpha(80);
3402         closeButton.setColor(2, alphaCorner.rgba());
3403         return QPixmap::fromImage(closeButton);
3404     }
3405     break;
3406 
3407     case SP_DialogDiscardButton:
3408         return QGtkPainter::getIcon(GTK_STOCK_DELETE);
3409     case SP_DialogOkButton:
3410         return QGtkPainter::getIcon(GTK_STOCK_OK);
3411     case SP_DialogCancelButton:
3412         return QGtkPainter::getIcon(GTK_STOCK_CANCEL);
3413     case SP_DialogYesButton:
3414         return QGtkPainter::getIcon(GTK_STOCK_YES);
3415     case SP_DialogNoButton:
3416         return QGtkPainter::getIcon(GTK_STOCK_NO);
3417     case SP_DialogOpenButton:
3418         return QGtkPainter::getIcon(GTK_STOCK_OPEN);
3419     case SP_DialogCloseButton:
3420         return QGtkPainter::getIcon(GTK_STOCK_CLOSE);
3421     case SP_DialogApplyButton:
3422         return QGtkPainter::getIcon(GTK_STOCK_APPLY);
3423     case SP_DialogSaveButton:
3424         return QGtkPainter::getIcon(GTK_STOCK_SAVE);
3425     case SP_MessageBoxWarning:
3426         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
3427     case SP_MessageBoxQuestion:
3428         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
3429     case SP_MessageBoxInformation:
3430         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
3431     case SP_MessageBoxCritical:
3432         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
3433     default:
3434         return QCleanlooksStyle::standardPixmap(sp, option, widget);
3435     }
3436     return pixmap;
3437 }
3438 
3439 /*!
3440     \internal
3441 */
standardIconImplementation(StandardPixmap standardIcon,const QStyleOption * option,const QWidget * widget) const3442 QIcon QGtkStyle::standardIconImplementation(StandardPixmap standardIcon,
3443                                                   const QStyleOption *option,
3444                                                   const QWidget *widget) const
3445 {
3446     Q_D(const QGtkStyle);
3447 
3448     if (!d->isThemeAvailable())
3449         return QCleanlooksStyle::standardIconImplementation(standardIcon, option, widget);
3450     switch (standardIcon) {
3451     case SP_DialogDiscardButton:
3452         return QGtkPainter::getIcon(GTK_STOCK_DELETE);
3453     case SP_DialogOkButton:
3454         return QGtkPainter::getIcon(GTK_STOCK_OK);
3455     case SP_DialogCancelButton:
3456         return QGtkPainter::getIcon(GTK_STOCK_CANCEL);
3457     case SP_DialogYesButton:
3458         return QGtkPainter::getIcon(GTK_STOCK_YES);
3459     case SP_DialogNoButton:
3460         return QGtkPainter::getIcon(GTK_STOCK_NO);
3461     case SP_DialogOpenButton:
3462         return QGtkPainter::getIcon(GTK_STOCK_OPEN);
3463     case SP_DialogCloseButton:
3464         return QGtkPainter::getIcon(GTK_STOCK_CLOSE);
3465     case SP_DialogApplyButton:
3466         return QGtkPainter::getIcon(GTK_STOCK_APPLY);
3467     case SP_DialogSaveButton:
3468         return QGtkPainter::getIcon(GTK_STOCK_SAVE);
3469     case SP_MessageBoxWarning:
3470         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
3471     case SP_MessageBoxQuestion:
3472         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
3473     case SP_MessageBoxInformation:
3474         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
3475     case SP_MessageBoxCritical:
3476         return QGtkPainter::getIcon(GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
3477     default:
3478         return QCleanlooksStyle::standardIconImplementation(standardIcon, option, widget);
3479     }
3480 }
3481 
3482 
3483 /*! \reimp */
subElementRect(SubElement element,const QStyleOption * option,const QWidget * widget) const3484 QRect QGtkStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
3485 {
3486     Q_D(const QGtkStyle);
3487 
3488     QRect r = QCleanlooksStyle::subElementRect(element, option, widget);
3489     if (!d->isThemeAvailable())
3490         return r;
3491 
3492     switch (element) {
3493     case SE_ProgressBarLabel:
3494     case SE_ProgressBarContents:
3495     case SE_ProgressBarGroove:
3496         return option->rect;
3497     case SE_PushButtonContents:
3498         if (!d->gtk_check_version(2, 10, 0)) {
3499             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
3500             GtkBorder *border = 0;
3501             d->gtk_widget_style_get(gtkButton, "inner-border", &border, NULL);
3502             if (border) {
3503                 r = option->rect.adjusted(border->left, border->top, -border->right, -border->bottom);
3504                 d->gtk_border_free(border);
3505             } else {
3506                 r = option->rect.adjusted(1, 1, -1, -1);
3507             }
3508             r = visualRect(option->direction, option->rect, r);
3509         }
3510         break;
3511     default:
3512         break;
3513     }
3514 
3515     return r;
3516 }
3517 
3518 /*!
3519   \reimp
3520 */
itemPixmapRect(const QRect & r,int flags,const QPixmap & pixmap) const3521 QRect QGtkStyle::itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
3522 {
3523     return QCleanlooksStyle::itemPixmapRect(r, flags, pixmap);
3524 }
3525 
3526 /*!
3527   \reimp
3528 */
drawItemPixmap(QPainter * painter,const QRect & rect,int alignment,const QPixmap & pixmap) const3529 void QGtkStyle::drawItemPixmap(QPainter *painter, const QRect &rect,
3530                             int alignment, const QPixmap &pixmap) const
3531 {
3532     QCleanlooksStyle::drawItemPixmap(painter, rect, alignment, pixmap);
3533 }
3534 
3535 /*!
3536   \reimp
3537 */
hitTestComplexControl(ComplexControl cc,const QStyleOptionComplex * opt,const QPoint & pt,const QWidget * w) const3538 QStyle::SubControl QGtkStyle::hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
3539                               const QPoint &pt, const QWidget *w) const
3540 {
3541     return QCleanlooksStyle::hitTestComplexControl(cc, opt, pt, w);
3542 }
3543 
3544 /*!
3545   \reimp
3546 */
generatedIconPixmap(QIcon::Mode iconMode,const QPixmap & pixmap,const QStyleOption * opt) const3547 QPixmap QGtkStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
3548                                         const QStyleOption *opt) const
3549 {
3550     return QCleanlooksStyle::generatedIconPixmap(iconMode, pixmap, opt);
3551 }
3552 
3553 /*!
3554   \reimp
3555 */
drawItemText(QPainter * painter,const QRect & rect,int alignment,const QPalette & pal,bool enabled,const QString & text,QPalette::ColorRole textRole) const3556 void QGtkStyle::drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal,
3557                                     bool enabled, const QString& text, QPalette::ColorRole textRole) const
3558 {
3559     return QCleanlooksStyle::drawItemText(painter, rect, alignment, pal, enabled, text, textRole);
3560 }
3561 
3562 QT_END_NAMESPACE
3563 
3564 #endif //!defined(QT_NO_STYLE_QGTK)
3565