src/gui/styles/qgtkstyle.cpp
changeset 30 5dc02b23752f
parent 19 fcece45ef507
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   220     Q_D(const QGtkStyle);
   220     Q_D(const QGtkStyle);
   221 
   221 
   222     QPalette palette = QCleanlooksStyle::standardPalette();
   222     QPalette palette = QCleanlooksStyle::standardPalette();
   223     if (d->isThemeAvailable()) {
   223     if (d->isThemeAvailable()) {
   224         GtkStyle *style = d->gtkStyle();
   224         GtkStyle *style = d->gtkStyle();
   225         GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
   225         GtkWidget *gtkButton = d->gtkWidget("GtkButton");
   226         GtkWidget *gtkEntry = d->getTextColorWidget();
   226         GtkWidget *gtkEntry = d->getTextColorWidget();
   227 
   227 
   228         GdkColor gdkBg, gdkBase, gdkText, gdkForeground, gdkSbg, gdkSfg;
   228         GdkColor gdkBg, gdkBase, gdkText, gdkForeground, gdkSbg, gdkSfg;
   229         QColor bg, base, text, fg, highlight, highlightText;
   229         QColor bg, base, text, fg, highlight, highlightText;
   230         gdkBg = style->bg[GTK_STATE_NORMAL];
   230         gdkBg = style->bg[GTK_STATE_NORMAL];
   251         palette.setColor(QPalette::WindowText, fg);
   251         palette.setColor(QPalette::WindowText, fg);
   252         palette.setColor(QPalette::ButtonText, fg);
   252         palette.setColor(QPalette::ButtonText, fg);
   253         palette.setColor(QPalette::Base, base);
   253         palette.setColor(QPalette::Base, base);
   254 
   254 
   255         QColor alternateRowColor = palette.base().color().lighter(93); // ref gtkstyle.c draw_flat_box
   255         QColor alternateRowColor = palette.base().color().lighter(93); // ref gtkstyle.c draw_flat_box
   256         GtkWidget *gtkTreeView = d->gtkWidget(QLS("GtkTreeView"));
   256         GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
   257         GdkColor *gtkAltBase = NULL;
   257         GdkColor *gtkAltBase = NULL;
   258         d->gtk_widget_style_get(gtkTreeView, "odd-row-color", &gtkAltBase, NULL);
   258         d->gtk_widget_style_get(gtkTreeView, "odd-row-color", &gtkAltBase, NULL);
   259         if (gtkAltBase) {
   259         if (gtkAltBase) {
   260             alternateRowColor = QColor(gtkAltBase->red>>8, gtkAltBase->green>>8, gtkAltBase->blue>>8);
   260             alternateRowColor = QColor(gtkAltBase->red>>8, gtkAltBase->green>>8, gtkAltBase->blue>>8);
   261             d->gdk_color_free(gtkAltBase);
   261             d->gdk_color_free(gtkAltBase);
   419 
   419 
   420     case PM_ToolBarItemSpacing:
   420     case PM_ToolBarItemSpacing:
   421         return 0;
   421         return 0;
   422 
   422 
   423     case PM_ButtonShiftHorizontal: {
   423     case PM_ButtonShiftHorizontal: {
   424         GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
   424         GtkWidget *gtkButton = d->gtkWidget("GtkButton");
   425         guint horizontal_shift;
   425         guint horizontal_shift;
   426         d->gtk_widget_style_get(gtkButton, "child-displacement-x", &horizontal_shift, NULL);
   426         d->gtk_widget_style_get(gtkButton, "child-displacement-x", &horizontal_shift, NULL);
   427         return horizontal_shift;
   427         return horizontal_shift;
   428     }
   428     }
   429 
   429 
   430     case PM_ButtonShiftVertical: {
   430     case PM_ButtonShiftVertical: {
   431         GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
   431         GtkWidget *gtkButton = d->gtkWidget("GtkButton");
   432         guint vertical_shift;
   432         guint vertical_shift;
   433         d->gtk_widget_style_get(gtkButton, "child-displacement-y", &vertical_shift, NULL);
   433         d->gtk_widget_style_get(gtkButton, "child-displacement-y", &vertical_shift, NULL);
   434         return vertical_shift;
   434         return vertical_shift;
   435     }
   435     }
   436 
   436 
   437     case PM_MenuBarPanelWidth:
   437     case PM_MenuBarPanelWidth:
   438         return 0;
   438         return 0;
   439 
   439 
   440     case PM_MenuPanelWidth: {
   440     case PM_MenuPanelWidth: {
   441         GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu"));
   441         GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
   442         guint horizontal_padding = 0;
   442         guint horizontal_padding = 0;
   443         // horizontal-padding is used by Maemo to get thicker borders
   443         // horizontal-padding is used by Maemo to get thicker borders
   444         if (!d->gtk_check_version(2, 10, 0))
   444         if (!d->gtk_check_version(2, 10, 0))
   445             d->gtk_widget_style_get(gtkMenu, "horizontal-padding", &horizontal_padding, NULL);
   445             d->gtk_widget_style_get(gtkMenu, "horizontal-padding", &horizontal_padding, NULL);
   446         int padding = qMax<int>(gtkMenu->style->xthickness, horizontal_padding);
   446         int padding = qMax<int>(gtkMenu->style->xthickness, horizontal_padding);
   493     case PM_SplitterWidth:
   493     case PM_SplitterWidth:
   494         return 6;
   494         return 6;
   495 
   495 
   496     case PM_SliderThickness:
   496     case PM_SliderThickness:
   497     case PM_SliderControlThickness: {
   497     case PM_SliderControlThickness: {
   498         GtkWidget *gtkScale = d->gtkWidget(QLS("GtkHScale"));
   498         GtkWidget *gtkScale = d->gtkWidget("GtkHScale");
   499         gint val;
   499         gint val;
   500         d->gtk_widget_style_get(gtkScale, "slider-width", &val, NULL);
   500         d->gtk_widget_style_get(gtkScale, "slider-width", &val, NULL);
   501         if (metric == PM_SliderControlThickness)
   501         if (metric == PM_SliderControlThickness)
   502             return val + 2*gtkScale->style->ythickness;
   502             return val + 2*gtkScale->style->ythickness;
   503         return val;
   503         return val;
   504     }
   504     }
   505 
   505 
   506     case PM_ScrollBarExtent: {
   506     case PM_ScrollBarExtent: {
   507         gint sliderLength;
   507         gint sliderLength;
   508         gint trough_border;
   508         gint trough_border;
   509         GtkWidget *hScrollbar = d->gtkWidget(QLS("GtkHScrollbar"));
   509         GtkWidget *hScrollbar = d->gtkWidget("GtkHScrollbar");
   510         d->gtk_widget_style_get(hScrollbar,
   510         d->gtk_widget_style_get(hScrollbar,
   511                                "trough-border",   &trough_border,
   511                                "trough-border",   &trough_border,
   512                                "slider-width",    &sliderLength,
   512                                "slider-width",    &sliderLength,
   513                                NULL);
   513                                NULL);
   514         return sliderLength + trough_border*2;
   514         return sliderLength + trough_border*2;
   517     case PM_ScrollBarSliderMin:
   517     case PM_ScrollBarSliderMin:
   518         return 34;
   518         return 34;
   519 
   519 
   520     case PM_SliderLength:
   520     case PM_SliderLength:
   521         gint val;
   521         gint val;
   522         d->gtk_widget_style_get(d->gtkWidget(QLS("GtkHScale")), "slider-length", &val, NULL);
   522         d->gtk_widget_style_get(d->gtkWidget("GtkHScale"), "slider-length", &val, NULL);
   523         return val;
   523         return val;
   524 
   524 
   525     case PM_ExclusiveIndicatorWidth:
   525     case PM_ExclusiveIndicatorWidth:
   526     case PM_ExclusiveIndicatorHeight:
   526     case PM_ExclusiveIndicatorHeight:
   527     case PM_IndicatorWidth:
   527     case PM_IndicatorWidth:
   528     case PM_IndicatorHeight: {
   528     case PM_IndicatorHeight: {
   529         GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
   529         GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
   530         gint size, spacing;
   530         gint size, spacing;
   531         d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, "indicator-size", &size, NULL);
   531         d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, "indicator-size", &size, NULL);
   532         return size + 2 * spacing;
   532         return size + 2 * spacing;
   533     }
   533     }
   534 
   534 
   535     case PM_MenuBarVMargin: {
   535     case PM_MenuBarVMargin: {
   536         GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar"));
   536         GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
   537         return  qMax(0, gtkMenubar->style->ythickness);
   537         return  qMax(0, gtkMenubar->style->ythickness);
   538     }
   538     }
   539     case PM_ScrollView_ScrollBarSpacing:
   539     case PM_ScrollView_ScrollBarSpacing:
   540     {
   540     {
   541         gint spacing = 3;
   541         gint spacing = 3;
   542         GtkWidget *gtkScrollWindow = d->gtkWidget(QLS("GtkScrolledWindow"));
   542         GtkWidget *gtkScrollWindow = d->gtkWidget("GtkScrolledWindow");
   543         Q_ASSERT(gtkScrollWindow);
   543         Q_ASSERT(gtkScrollWindow);
   544         d->gtk_widget_style_get(gtkScrollWindow, "scrollbar-spacing", &spacing, NULL);
   544         d->gtk_widget_style_get(gtkScrollWindow, "scrollbar-spacing", &spacing, NULL);
   545         return spacing;
   545         return spacing;
   546     }
   546     }
   547     case PM_SubMenuOverlap: {
   547     case PM_SubMenuOverlap: {
   548         gint offset = 0;
   548         gint offset = 0;
   549         GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu"));
   549         GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
   550         d->gtk_widget_style_get(gtkMenu, "horizontal-offset", &offset, NULL);
   550         d->gtk_widget_style_get(gtkMenu, "horizontal-offset", &offset, NULL);
   551         return offset;
   551         return offset;
   552     }
   552     }
   553     default:
   553     default:
   554         return QCleanlooksStyle::pixelMetric(metric, option, widget);
   554         return QCleanlooksStyle::pixelMetric(metric, option, widget);
   585 
   585 
   586     case SH_ToolButtonStyle:
   586     case SH_ToolButtonStyle:
   587     {
   587     {
   588         if (d->isKDE4Session())
   588         if (d->isKDE4Session())
   589             return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
   589             return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
   590         GtkWidget *gtkToolbar = d->gtkWidget(QLS("GtkToolbar"));
   590         GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
   591         GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS;
   591         GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS;
   592         g_object_get(gtkToolbar, "toolbar-style", &toolbar_style, NULL);
   592         g_object_get(gtkToolbar, "toolbar-style", &toolbar_style, NULL);
   593         switch (toolbar_style) {
   593         switch (toolbar_style) {
   594         case GTK_TOOLBAR_TEXT:
   594         case GTK_TOOLBAR_TEXT:
   595             return Qt::ToolButtonTextOnly;
   595             return Qt::ToolButtonTextOnly;
   608 
   608 
   609     case SH_DitherDisabledText:
   609     case SH_DitherDisabledText:
   610         return int(false);
   610         return int(false);
   611 
   611 
   612     case SH_ComboBox_Popup: {
   612     case SH_ComboBox_Popup: {
   613         GtkWidget *gtkComboBox = d->gtkWidget(QLS("GtkComboBox"));
   613         GtkWidget *gtkComboBox = d->gtkWidget("GtkComboBox");
   614         gboolean appears_as_list;
   614         gboolean appears_as_list;
   615         d->gtk_widget_style_get((GtkWidget*)gtkComboBox, "appears-as-list", &appears_as_list, NULL);
   615         d->gtk_widget_style_get((GtkWidget*)gtkComboBox, "appears-as-list", &appears_as_list, NULL);
   616         return appears_as_list ? 0 : 1;
   616         return appears_as_list ? 0 : 1;
   617     }
   617     }
   618 
   618 
   632     case SH_ScrollView_FrameOnlyAroundContents: {
   632     case SH_ScrollView_FrameOnlyAroundContents: {
   633         gboolean scrollbars_within_bevel = false;
   633         gboolean scrollbars_within_bevel = false;
   634         if (widget && widget->isWindow())
   634         if (widget && widget->isWindow())
   635             scrollbars_within_bevel = true;
   635             scrollbars_within_bevel = true;
   636         else if (!d->gtk_check_version(2, 12, 0)) {
   636         else if (!d->gtk_check_version(2, 12, 0)) {
   637             GtkWidget *gtkScrollWindow = d->gtkWidget(QLS("GtkScrolledWindow"));
   637             GtkWidget *gtkScrollWindow = d->gtkWidget("GtkScrolledWindow");
   638             d->gtk_widget_style_get(gtkScrollWindow, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
   638             d->gtk_widget_style_get(gtkScrollWindow, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
   639         }
   639         }
   640         return !scrollbars_within_bevel;
   640         return !scrollbars_within_bevel;
   641     }
   641     }
   642 
   642 
   710                 shadow_type = GTK_SHADOW_OUT;
   710                 shadow_type = GTK_SHADOW_OUT;
   711 
   711 
   712             GtkStyle *style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(),
   712             GtkStyle *style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(),
   713                                      "*.GtkScrolledWindow", "*.GtkScrolledWindow", d->gtk_window_get_type());
   713                                      "*.GtkScrolledWindow", "*.GtkScrolledWindow", d->gtk_window_get_type());
   714             if (style)
   714             if (style)
   715                 gtkFramePainter.paintShadow(d->gtkWidget(QLS("GtkFrame")), "viewport", pmRect,
   715                 gtkFramePainter.paintShadow(d->gtkWidget("GtkFrame"), "viewport", pmRect,
   716                                          option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
   716                                          option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
   717                                          shadow_type, style);
   717                                          shadow_type, style);
   718             QPixmapCache::insert(pmKey, pixmap);
   718             QPixmapCache::insert(pmKey, pixmap);
   719         }
   719         }
   720 
   720 
   737         painter->drawPixmap(rect.adjusted(rw, rh, 0, 0), pixmap, pmRect.adjusted(pw, ph, 0,0));
   737         painter->drawPixmap(rect.adjusted(rw, rh, 0, 0), pixmap, pmRect.adjusted(pw, ph, 0,0));
   738     }
   738     }
   739     break;
   739     break;
   740 
   740 
   741     case PE_PanelTipLabel: {
   741     case PE_PanelTipLabel: {
   742         GtkWidget *gtkWindow = d->gtkWidget(QLS("GtkWindow")); // The Murrine Engine currently assumes a widget is passed
   742         GtkWidget *gtkWindow = d->gtkWidget("GtkWindow"); // The Murrine Engine currently assumes a widget is passed
   743         style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow",
   743         style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow",
   744                 d->gtk_window_get_type());
   744                 d->gtk_window_get_type());
   745         gtkPainter.paintFlatBox(gtkWindow, "tooltip", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, style);
   745         gtkPainter.paintFlatBox(gtkWindow, "tooltip", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, style);
   746     }
   746     }
   747     break;
   747     break;
   752             // Respect custom palette
   752             // Respect custom palette
   753             painter->fillRect(option->rect, option->palette.window());
   753             painter->fillRect(option->rect, option->palette.window());
   754             break;
   754             break;
   755         }
   755         }
   756         GtkShadowType shadow_type;
   756         GtkShadowType shadow_type;
   757         GtkWidget *gtkStatusbarFrame = d->gtkWidget(QLS("GtkStatusbar.GtkFrame"));
   757         GtkWidget *gtkStatusbarFrame = d->gtkWidget("GtkStatusbar.GtkFrame");
   758         d->gtk_widget_style_get(gtkStatusbarFrame->parent, "shadow-type", &shadow_type, NULL);
   758         d->gtk_widget_style_get(gtkStatusbarFrame->parent, "shadow-type", &shadow_type, NULL);
   759         gtkPainter.paintShadow(gtkStatusbarFrame, "frame", option->rect, GTK_STATE_NORMAL,
   759         gtkPainter.paintShadow(gtkStatusbarFrame, "frame", option->rect, GTK_STATE_NORMAL,
   760                                shadow_type, gtkStatusbarFrame->style);
   760                                shadow_type, gtkStatusbarFrame->style);
   761     }
   761     }
   762     break;
   762     break;
   763 
   763 
   764     case PE_IndicatorHeaderArrow:
   764     case PE_IndicatorHeaderArrow:
   765         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
   765         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
   766             GtkWidget *gtkTreeHeader = d->gtkWidget(QLS("GtkTreeView.GtkButton"));
   766             GtkWidget *gtkTreeHeader = d->gtkWidget("GtkTreeView.GtkButton");
   767             GtkStateType state = gtkPainter.gtkState(option);
   767             GtkStateType state = gtkPainter.gtkState(option);
   768             style = gtkTreeHeader->style;
   768             style = gtkTreeHeader->style;
   769             GtkArrowType type = GTK_ARROW_UP;
   769             GtkArrowType type = GTK_ARROW_UP;
   770             QRect r = header->rect;
   770             QRect r = header->rect;
   771             QImage arrow;
   771             QImage arrow;
       
   772             // This sorting indicator inversion is intentional, and follows the GNOME HIG.
       
   773             // See http://library.gnome.org/devel/hig-book/stable/controls-lists.html.en#controls-lists-sortable
   772             if (header->sortIndicator & QStyleOptionHeader::SortUp)
   774             if (header->sortIndicator & QStyleOptionHeader::SortUp)
   773                 type = GTK_ARROW_UP;
   775                 type = GTK_ARROW_UP;
   774             else if (header->sortIndicator & QStyleOptionHeader::SortDown)
   776             else if (header->sortIndicator & QStyleOptionHeader::SortDown)
   775                 type = GTK_ARROW_DOWN;
   777                 type = GTK_ARROW_DOWN;
   776 
   778 
   799             rect = QRect(0, 0, 12, 12);
   801             rect = QRect(0, 0, 12, 12);
   800             rect.moveCenter(option->rect.center());
   802             rect.moveCenter(option->rect.center());
   801             rect.translate(2, 0);
   803             rect.translate(2, 0);
   802             GtkExpanderStyle openState = GTK_EXPANDER_EXPANDED;
   804             GtkExpanderStyle openState = GTK_EXPANDER_EXPANDED;
   803             GtkExpanderStyle closedState = GTK_EXPANDER_COLLAPSED;
   805             GtkExpanderStyle closedState = GTK_EXPANDER_COLLAPSED;
   804             GtkWidget *gtkTreeView = d->gtkWidget(QLS("GtkTreeView"));
   806             GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
   805 
   807 
   806             GtkStateType state = GTK_STATE_NORMAL;
   808             GtkStateType state = GTK_STATE_NORMAL;
   807             if (!(option->state & State_Enabled))
   809             if (!(option->state & State_Enabled))
   808                 state = GTK_STATE_INSENSITIVE;
   810                 state = GTK_STATE_INSENSITIVE;
   809             else if (option->state & State_MouseOver)
   811             else if (option->state & State_MouseOver)
   835         }
   837         }
   836         break;
   838         break;
   837     case PE_IndicatorToolBarSeparator:
   839     case PE_IndicatorToolBarSeparator:
   838         {
   840         {
   839             const int margin = 6;
   841             const int margin = 6;
   840             GtkWidget *gtkSeparator = d->gtkWidget(QLS("GtkToolbar.GtkSeparatorToolItem"));
   842             GtkWidget *gtkSeparator = d->gtkWidget("GtkToolbar.GtkSeparatorToolItem");
   841             if (option->state & State_Horizontal) {
   843             if (option->state & State_Horizontal) {
   842                 const int offset = option->rect.width()/2;
   844                 const int offset = option->rect.width()/2;
   843                 QRect rect = option->rect.adjusted(offset, margin, 0, -margin);
   845                 QRect rect = option->rect.adjusted(offset, margin, 0, -margin);
   844                 painter->setPen(QPen(option->palette.background().color().darker(110)));
   846                 painter->setPen(QPen(option->palette.background().color().darker(110)));
   845                 gtkPainter.paintVline( gtkSeparator, "vseparator",
   847                 gtkPainter.paintVline( gtkSeparator, "vseparator",
   855             }
   857             }
   856        }
   858        }
   857        break;
   859        break;
   858 
   860 
   859     case PE_IndicatorToolBarHandle: {
   861     case PE_IndicatorToolBarHandle: {
   860         GtkWidget *gtkToolbar = d->gtkWidget(QLS("GtkToolbar"));
   862         GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
   861         GtkShadowType shadow_type;
   863         GtkShadowType shadow_type;
   862         d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
   864         d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
   863         //Note when the toolbar is horizontal, the handle is vertical
   865         //Note when the toolbar is horizontal, the handle is vertical
   864         painter->setClipRect(option->rect);
   866         painter->setClipRect(option->rect);
   865         gtkPainter.paintHandle(gtkToolbar, "toolbar", option->rect.adjusted(-1, -1 ,0 ,1),
   867         gtkPainter.paintHandle(gtkToolbar, "toolbar", option->rect.adjusted(-1, -1 ,0 ,1),
   903         QRect arrowRect = option->rect.adjusted(border + bsx, border + bsy, -border + bsx, -border + bsy);
   905         QRect arrowRect = option->rect.adjusted(border + bsx, border + bsy, -border + bsx, -border + bsy);
   904         GtkShadowType shadow = option->state & State_Sunken ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
   906         GtkShadowType shadow = option->state & State_Sunken ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
   905         GtkStateType state = gtkPainter.gtkState(option);
   907         GtkStateType state = gtkPainter.gtkState(option);
   906 
   908 
   907         QColor arrowColor = option->palette.buttonText().color();
   909         QColor arrowColor = option->palette.buttonText().color();
   908         GtkWidget *gtkArrow = d->gtkWidget(QLS("GtkArrow"));
   910         GtkWidget *gtkArrow = d->gtkWidget("GtkArrow");
   909         GdkColor color = fromQColor(arrowColor);
   911         GdkColor color = fromQColor(arrowColor);
   910         d->gtk_widget_modify_fg (gtkArrow, state, &color);
   912         d->gtk_widget_modify_fg (gtkArrow, state, &color);
   911         gtkPainter.paintArrow(gtkArrow, "button", arrowRect,
   913         gtkPainter.paintArrow(gtkArrow, "button", arrowRect,
   912                               type, state, shadow, FALSE, gtkArrow->style,
   914                               type, state, shadow, FALSE, gtkArrow->style,
   913                               QString::number(arrowColor.rgba(), 16));
   915                               QString::number(arrowColor.rgba(), 16));
   919     case PE_FrameGroupBox:
   921     case PE_FrameGroupBox:
   920         // Do nothing here, the GNOME groupboxes are flat
   922         // Do nothing here, the GNOME groupboxes are flat
   921         break;
   923         break;
   922 
   924 
   923     case PE_PanelMenu: {
   925     case PE_PanelMenu: {
   924             GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu"));
   926             GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
   925             gtkPainter.setAlphaSupport(false); // Note, alpha disabled for performance reasons
   927             gtkPainter.setAlphaSupport(false); // Note, alpha disabled for performance reasons
   926             gtkPainter.paintBox(gtkMenu, "menu", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, gtkMenu->style, QString());
   928             gtkPainter.paintBox(gtkMenu, "menu", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, gtkMenu->style, QString());
   927         }
   929         }
   928         break;
   930         break;
   929 
   931 
   931         //This is actually done by PE_Widget due to a clipping issue
   933         //This is actually done by PE_Widget due to a clipping issue
   932         //Otherwise Menu items will not be able to span the entire menu width
   934         //Otherwise Menu items will not be able to span the entire menu width
   933 
   935 
   934         // This is only used by floating tool bars
   936         // This is only used by floating tool bars
   935         if (qobject_cast<const QToolBar *>(widget)) {
   937         if (qobject_cast<const QToolBar *>(widget)) {
   936             GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar"));
   938             GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
   937             gtkPainter.paintBox( gtkMenubar, "toolbar",  option->rect,
   939             gtkPainter.paintBox( gtkMenubar, "toolbar",  option->rect,
   938                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
   940                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
   939             gtkPainter.paintBox( gtkMenubar, "menu",  option->rect,
   941             gtkPainter.paintBox( gtkMenubar, "menu",  option->rect,
   940                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
   942                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
   941         }
   943         }
   942         break;
   944         break;
   943 
   945 
   944     case PE_FrameLineEdit: {
   946     case PE_FrameLineEdit: {
   945         GtkWidget *gtkEntry = d->gtkWidget(QLS("GtkEntry"));
   947         GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
   946 
   948 
   947 
   949 
   948         gboolean interior_focus;
   950         gboolean interior_focus;
   949         gint focus_line_width;
   951         gint focus_line_width;
   950         QRect rect = option->rect;
   952         QRect rect = option->rect;
   974     }
   976     }
   975     break;
   977     break;
   976 
   978 
   977     case PE_PanelLineEdit:
   979     case PE_PanelLineEdit:
   978         if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
   980         if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
   979             GtkWidget *gtkEntry = d->gtkWidget(QLS("GtkEntry"));
   981             GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
   980             if (panel->lineWidth > 0)
   982             if (panel->lineWidth > 0)
   981                 proxy()->drawPrimitive(PE_FrameLineEdit, option, painter, widget);
   983                 proxy()->drawPrimitive(PE_FrameLineEdit, option, painter, widget);
   982             uint resolve_mask = option->palette.resolve();
   984             uint resolve_mask = option->palette.resolve();
   983             QRect textRect = option->rect.adjusted(gtkEntry->style->xthickness, gtkEntry->style->ythickness,
   985             QRect textRect = option->rect.adjusted(gtkEntry->style->xthickness, gtkEntry->style->ythickness,
   984                                                    -gtkEntry->style->xthickness, -gtkEntry->style->ythickness);
   986                                                    -gtkEntry->style->xthickness, -gtkEntry->style->ythickness);
   992         }
   994         }
   993         break;
   995         break;
   994 
   996 
   995     case PE_FrameTabWidget:
   997     case PE_FrameTabWidget:
   996         if (const QStyleOptionTabWidgetFrame *frame = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option)) {
   998         if (const QStyleOptionTabWidgetFrame *frame = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option)) {
   997             GtkWidget *gtkNotebook = d->gtkWidget(QLS("GtkNotebook"));
   999             GtkWidget *gtkNotebook = d->gtkWidget("GtkNotebook");
   998             style = gtkPainter.getStyle(gtkNotebook);
  1000             style = gtkPainter.getStyle(gtkNotebook);
   999             gtkPainter.setAlphaSupport(false);
  1001             gtkPainter.setAlphaSupport(false);
  1000             GtkShadowType shadow = GTK_SHADOW_OUT;
  1002             GtkShadowType shadow = GTK_SHADOW_OUT;
  1001             GtkStateType state = GTK_STATE_NORMAL; // Only state supported by gtknotebook
  1003             GtkStateType state = GTK_STATE_NORMAL; // Only state supported by gtknotebook
  1002             bool reverse = (option->direction == Qt::RightToLeft);
  1004             bool reverse = (option->direction == Qt::RightToLeft);
  1040             break;
  1042             break;
  1041 
  1043 
  1042         GtkStateType state = gtkPainter.gtkState(option);
  1044         GtkStateType state = gtkPainter.gtkState(option);
  1043         if (option->state & State_On || option->state & State_Sunken)
  1045         if (option->state & State_On || option->state & State_Sunken)
  1044             state = GTK_STATE_ACTIVE;
  1046             state = GTK_STATE_ACTIVE;
  1045         GtkWidget *gtkButton = d->gtkWidget(isTool ? QLS("GtkToolButton.GtkButton") : QLS("GtkButton"));
  1047         GtkWidget *gtkButton = isTool ? d->gtkWidget("GtkToolButton.GtkButton") : d->gtkWidget("GtkButton");
  1046         gint focusWidth, focusPad;
  1048         gint focusWidth, focusPad;
  1047         gboolean interiorFocus = false;
  1049         gboolean interiorFocus = false;
  1048         d->gtk_widget_style_get (gtkButton,
  1050         d->gtk_widget_style_get (gtkButton,
  1049                                 "focus-line-width", &focusWidth,
  1051                                 "focus-line-width", &focusWidth,
  1050                                 "focus-padding", &focusPad,
  1052                                 "focus-padding", &focusPad,
  1096         else if (option->state & State_On)
  1098         else if (option->state & State_On)
  1097             shadow = GTK_SHADOW_IN;
  1099             shadow = GTK_SHADOW_IN;
  1098         else
  1100         else
  1099             shadow = GTK_SHADOW_OUT;
  1101             shadow = GTK_SHADOW_OUT;
  1100 
  1102 
  1101         GtkWidget *gtkRadioButton = d->gtkWidget(QLS("GtkRadioButton"));
  1103         GtkWidget *gtkRadioButton = d->gtkWidget("GtkRadioButton");
  1102         gint spacing;
  1104         gint spacing;
  1103         d->gtk_widget_style_get(gtkRadioButton, "indicator-spacing", &spacing, NULL);
  1105         d->gtk_widget_style_get(gtkRadioButton, "indicator-spacing", &spacing, NULL);
  1104         QRect buttonRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
  1106         QRect buttonRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
  1105         gtkPainter.setClipRect(option->rect);
  1107         gtkPainter.setClipRect(option->rect);
  1106         // ### Note: Ubuntulooks breaks when the proper widget is passed
  1108         // ### Note: Ubuntulooks breaks when the proper widget is passed
  1107         //           Murrine engine requires a widget not to get RGBA check - warnings
  1109         //           Murrine engine requires a widget not to get RGBA check - warnings
  1108         GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
  1110         GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
  1109         QString key(QLS("radiobutton"));
  1111         QString key(QLS("radiobutton"));
  1110         if (option->state & State_HasFocus) { // Themes such as Nodoka check this flag
  1112         if (option->state & State_HasFocus) { // Themes such as Nodoka check this flag
  1111             key += QLatin1Char('f');
  1113             key += QLatin1Char('f');
  1112             GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
  1114             GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
  1113         }
  1115         }
  1131         else
  1133         else
  1132             shadow = GTK_SHADOW_OUT;
  1134             shadow = GTK_SHADOW_OUT;
  1133 
  1135 
  1134         int spacing;
  1136         int spacing;
  1135 
  1137 
  1136         GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
  1138         GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
  1137         QString key(QLS("checkbutton"));
  1139         QString key(QLS("checkbutton"));
  1138         if (option->state & State_HasFocus) { // Themes such as Nodoka checks this flag
  1140         if (option->state & State_HasFocus) { // Themes such as Nodoka checks this flag
  1139             key += QLatin1Char('f');
  1141             key += QLatin1Char('f');
  1140             GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
  1142             GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
  1141         }
  1143         }
  1159 
  1161 
  1160     case PE_FrameTabBarBase:
  1162     case PE_FrameTabBarBase:
  1161         if (const QStyleOptionTabBarBase *tbb
  1163         if (const QStyleOptionTabBarBase *tbb
  1162                 = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) {
  1164                 = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) {
  1163             QRect tabRect = tbb->rect;
  1165             QRect tabRect = tbb->rect;
  1164             QRegion region(tabRect);
       
  1165             painter->save();
  1166             painter->save();
  1166             painter->setPen(QPen(option->palette.dark().color().dark(110), 0));
  1167             painter->setPen(QPen(option->palette.dark().color().dark(110), 0));
  1167             switch (tbb->shape) {
  1168             switch (tbb->shape) {
  1168 
  1169 
  1169             case QTabBar::RoundedNorth:
  1170             case QTabBar::RoundedNorth:
  1241     if (widget)
  1242     if (widget)
  1242         alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), darkOutline);
  1243         alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), darkOutline);
  1243     else
  1244     else
  1244         alphaCornerColor = mergedColors(option->palette.background().color(), darkOutline);
  1245         alphaCornerColor = mergedColors(option->palette.background().color(), darkOutline);
  1245 
  1246 
  1246     QPalette palette = option->palette;
       
  1247 
       
  1248     switch (control) {
  1247     switch (control) {
  1249 
  1248 
  1250     case CC_TitleBar:
  1249     case CC_TitleBar:
  1251         if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
  1250         if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
  1252             // Since this is drawn by metacity and not Gtk we
  1251             // Since this is drawn by metacity and not Gtk we
  1273             QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxCheckBox, widget);
  1272             QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxCheckBox, widget);
  1274             // Draw title
  1273             // Draw title
  1275 
  1274 
  1276             if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
  1275             if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
  1277                 // Draw prelight background
  1276                 // Draw prelight background
  1278                 GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
  1277                 GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
  1279 
  1278 
  1280                 if (option->state & State_MouseOver) {
  1279                 if (option->state & State_MouseOver) {
  1281                     QRect bgRect = textRect | checkBoxRect;
  1280                     QRect bgRect = textRect | checkBoxRect;
  1282                     gtkPainter.paintFlatBox(gtkCheckButton, "checkbutton", bgRect.adjusted(0, 0, 0, -2),
  1281                     gtkPainter.paintFlatBox(gtkCheckButton, "checkbutton", bgRect.adjusted(0, 0, 0, -2),
  1283                                             GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkCheckButton->style);
  1282                                             GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkCheckButton->style);
  1329             QGtkPainter gtkCachedPainter(p);
  1328             QGtkPainter gtkCachedPainter(p);
  1330             gtkCachedPainter.setUsePixmapCache(false); // cached externally
  1329             gtkCachedPainter.setUsePixmapCache(false); // cached externally
  1331 
  1330 
  1332             bool isEnabled = (comboBox->state & State_Enabled);
  1331             bool isEnabled = (comboBox->state & State_Enabled);
  1333             bool focus = isEnabled && (comboBox->state & State_HasFocus);
  1332             bool focus = isEnabled && (comboBox->state & State_HasFocus);
  1334             QColor buttonShadow = option->palette.dark().color();
       
  1335             GtkStateType state = gtkPainter.gtkState(option);
  1333             GtkStateType state = gtkPainter.gtkState(option);
  1336             int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, comboBox, widget);
  1334             int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, comboBox, widget);
  1337             QPixmap cache;
       
  1338             QString pixmapName;
       
  1339             QStyleOptionComboBox comboBoxCopy = *comboBox;
  1335             QStyleOptionComboBox comboBoxCopy = *comboBox;
  1340             comboBoxCopy.rect = option->rect;
  1336             comboBoxCopy.rect = option->rect;
  1341 
  1337 
  1342             bool reverse = (option->direction == Qt::RightToLeft);
  1338             bool reverse = (option->direction == Qt::RightToLeft);
  1343             QRect rect = option->rect;
  1339             QRect rect = option->rect;
  1344             QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, &comboBoxCopy,
  1340             QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, &comboBoxCopy,
  1345                                                    SC_ComboBoxArrow, widget);
  1341                                                    SC_ComboBoxArrow, widget);
  1346             QRect editRect = proxy()->subControlRect(CC_ComboBox, &comboBoxCopy,
       
  1347                                             SC_ComboBoxEditField, widget);
       
  1348 
  1342 
  1349             GtkShadowType shadow = (option->state & State_Sunken || option->state & State_On ) ?
  1343             GtkShadowType shadow = (option->state & State_Sunken || option->state & State_On ) ?
  1350                                    GTK_SHADOW_IN : GTK_SHADOW_OUT;
  1344                                    GTK_SHADOW_IN : GTK_SHADOW_OUT;
  1351             QString comboBoxPath = QLS(comboBox->editable ? "GtkComboBoxEntry" : "GtkComboBox");
  1345             const QHashableLatin1Literal comboBoxPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry") : QHashableLatin1Literal("GtkComboBox");
  1352 
  1346 
  1353             // We use the gtk widget to position arrows and separators for us
  1347             // We use the gtk widget to position arrows and separators for us
  1354             GtkWidget *gtkCombo = d->gtkWidget(comboBoxPath);
  1348             GtkWidget *gtkCombo = d->gtkWidget(comboBoxPath);
  1355             GtkAllocation geometry = {0, 0, option->rect.width(), option->rect.height()};
  1349             GtkAllocation geometry = {0, 0, option->rect.width(), option->rect.height()};
  1356             d->gtk_widget_set_direction(gtkCombo, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1350             d->gtk_widget_set_direction(gtkCombo, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1357             d->gtk_widget_size_allocate(gtkCombo, &geometry);
  1351             d->gtk_widget_size_allocate(gtkCombo, &geometry);
  1358 
  1352 
  1359             QString buttonPath = comboBoxPath + QLS(".GtkToggleButton");
  1353             QHashableLatin1Literal buttonPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton")
       
  1354                                 : QHashableLatin1Literal("GtkComboBox.GtkToggleButton");
  1360             GtkWidget *gtkToggleButton = d->gtkWidget(buttonPath);
  1355             GtkWidget *gtkToggleButton = d->gtkWidget(buttonPath);
  1361             d->gtk_widget_set_direction(gtkToggleButton, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1356             d->gtk_widget_set_direction(gtkToggleButton, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1362             if (gtkToggleButton && (appears_as_list || comboBox->editable)) {
  1357             if (gtkToggleButton && (appears_as_list || comboBox->editable)) {
  1363                 if (focus)
  1358                 if (focus)
  1364                     GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1359                     GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1365                 // Draw the combo box as a line edit with a button next to it
  1360                 // Draw the combo box as a line edit with a button next to it
  1366                 if (comboBox->editable || appears_as_list) {
  1361                 if (comboBox->editable || appears_as_list) {
  1367                     GtkStateType frameState = (state == GTK_STATE_PRELIGHT) ? GTK_STATE_NORMAL : state;
  1362                     GtkStateType frameState = (state == GTK_STATE_PRELIGHT) ? GTK_STATE_NORMAL : state;
  1368                     QString entryPath = QLS(comboBox->editable ? "GtkComboBoxEntry.GtkEntry" : "GtkComboBox.GtkFrame");
  1363                     QHashableLatin1Literal entryPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry.GtkEntry") : QHashableLatin1Literal("GtkComboBox.GtkFrame");
  1369                     GtkWidget *gtkEntry = d->gtkWidget(entryPath);
  1364                     GtkWidget *gtkEntry = d->gtkWidget(entryPath);
  1370                     d->gtk_widget_set_direction(gtkEntry, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1365                     d->gtk_widget_set_direction(gtkEntry, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1371                     QRect frameRect = option->rect;
  1366                     QRect frameRect = option->rect;
  1372 
  1367 
  1373                     if (reverse)
  1368                     if (reverse)
  1389                         resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
  1384                         resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
  1390                         p->fillRect(contentRect, option->palette.base().color());
  1385                         p->fillRect(contentRect, option->palette.base().color());
  1391                     else {
  1386                     else {
  1392                         gtkCachedPainter.paintFlatBox(gtkEntry, "entry_bg", contentRect,
  1387                         gtkCachedPainter.paintFlatBox(gtkEntry, "entry_bg", contentRect,
  1393                                                 option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
  1388                                                 option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
  1394                                                 GTK_SHADOW_NONE, gtkEntry->style, entryPath + QString::number(focus));
  1389                                                 GTK_SHADOW_NONE, gtkEntry->style, entryPath.toString() + QString::number(focus));
  1395                     }
  1390                     }
  1396 
  1391 
  1397                     gtkCachedPainter.paintShadow(gtkEntry, comboBox->editable ? "entry" : "frame", frameRect, frameState,
  1392                     gtkCachedPainter.paintShadow(gtkEntry, comboBox->editable ? "entry" : "frame", frameRect, frameState,
  1398                                            GTK_SHADOW_IN, gtkEntry->style, entryPath +
  1393                                            GTK_SHADOW_IN, gtkEntry->style, entryPath.toString() +
  1399                                            QString::number(focus) + QString::number(comboBox->editable) +
  1394                                            QString::number(focus) + QString::number(comboBox->editable) +
  1400                                            QString::number(option->direction));
  1395                                            QString::number(option->direction));
  1401                     if (focus)
  1396                     if (focus)
  1402                         GTK_WIDGET_UNSET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
  1397                         GTK_WIDGET_UNSET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
  1403                 }
  1398                 }
  1409                 else if (option->state & State_Sunken || option->state & State_On)
  1404                 else if (option->state & State_Sunken || option->state & State_On)
  1410                     buttonState = GTK_STATE_ACTIVE;
  1405                     buttonState = GTK_STATE_ACTIVE;
  1411                 else if (option->state & State_MouseOver && comboBox->activeSubControls & SC_ComboBoxArrow)
  1406                 else if (option->state & State_MouseOver && comboBox->activeSubControls & SC_ComboBoxArrow)
  1412                     buttonState = GTK_STATE_PRELIGHT;
  1407                     buttonState = GTK_STATE_PRELIGHT;
  1413 
  1408 
  1414                 QRect buttonrect = QRect(gtkToggleButton->allocation.x, gtkToggleButton->allocation.y,
       
  1415                                          gtkToggleButton->allocation.width, gtkToggleButton->allocation.height);
       
  1416 
       
  1417                 Q_ASSERT(gtkToggleButton);
  1409                 Q_ASSERT(gtkToggleButton);
  1418                 gtkCachedPainter.paintBox( gtkToggleButton, "button", arrowButtonRect, buttonState,
  1410                 gtkCachedPainter.paintBox( gtkToggleButton, "button", arrowButtonRect, buttonState,
  1419                                      shadow, gtkToggleButton->style, buttonPath +
  1411                                      shadow, gtkToggleButton->style, buttonPath.toString() +
  1420                                      QString::number(focus) + QString::number(option->direction));
  1412                                      QString::number(focus) + QString::number(option->direction));
  1421                 if (focus)
  1413                 if (focus)
  1422                     GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1414                     GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1423             } else {
  1415             } else {
  1424                 // Draw combo box as a button
  1416                 // Draw combo box as a button
  1427                 if (focus) // Clearlooks actually check the widget for the default state
  1419                 if (focus) // Clearlooks actually check the widget for the default state
  1428                     GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1420                     GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1429                 gtkCachedPainter.paintBox(gtkToggleButton, "button",
  1421                 gtkCachedPainter.paintBox(gtkToggleButton, "button",
  1430                                     buttonRect, state,
  1422                                     buttonRect, state,
  1431                                     shadow, gtkToggleButton->style,
  1423                                     shadow, gtkToggleButton->style,
  1432                                     buttonPath + QString::number(focus));
  1424                                     buttonPath.toString() + QString::number(focus));
  1433                 if (focus)
  1425                 if (focus)
  1434                     GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1426                     GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1435 
  1427 
       
  1428 
  1436                 // Draw the separator between label and arrows
  1429                 // Draw the separator between label and arrows
  1437                 QString vSeparatorPath = buttonPath + QLS(".GtkHBox.GtkVSeparator");
  1430                 QHashableLatin1Literal vSeparatorPath = comboBox->editable
       
  1431                     ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkHBox.GtkVSeparator")
       
  1432                     : QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkHBox.GtkVSeparator");
  1438 
  1433 
  1439                 if (GtkWidget *gtkVSeparator = d->gtkWidget(vSeparatorPath)) {
  1434                 if (GtkWidget *gtkVSeparator = d->gtkWidget(vSeparatorPath)) {
  1440                     QRect vLineRect(gtkVSeparator->allocation.x,
  1435                     QRect vLineRect(gtkVSeparator->allocation.x,
  1441                                     gtkVSeparator->allocation.y,
  1436                                     gtkVSeparator->allocation.y,
  1442                                     gtkVSeparator->allocation.width,
  1437                                     gtkVSeparator->allocation.width,
  1443                                     gtkVSeparator->allocation.height);
  1438                                     gtkVSeparator->allocation.height);
  1444 
  1439 
  1445                     gtkCachedPainter.paintVline( gtkVSeparator, "vseparator",
  1440                     gtkCachedPainter.paintVline( gtkVSeparator, "vseparator",
  1446                                            vLineRect, state, gtkVSeparator->style,
  1441                                            vLineRect, state, gtkVSeparator->style,
  1447                                            0, vLineRect.height(), 0,  vSeparatorPath);
  1442                                            0, vLineRect.height(), 0,  vSeparatorPath.toString());
  1448 
  1443 
  1449 
  1444 
  1450                     gint interiorFocus = true;
  1445                     gint interiorFocus = true;
  1451                     d->gtk_widget_style_get(gtkToggleButton, "interior-focus", &interiorFocus, NULL);
  1446                     d->gtk_widget_style_get(gtkToggleButton, "interior-focus", &interiorFocus, NULL);
  1452                     int xt = interiorFocus ? gtkToggleButton->style->xthickness : 0;
  1447                     int xt = interiorFocus ? gtkToggleButton->style->xthickness : 0;
  1467                 else if (option->state & State_MouseOver)
  1462                 else if (option->state & State_MouseOver)
  1468                     state = GTK_STATE_PRELIGHT;
  1463                     state = GTK_STATE_PRELIGHT;
  1469                 else
  1464                 else
  1470                     state = GTK_STATE_NORMAL;
  1465                     state = GTK_STATE_NORMAL;
  1471 
  1466 
  1472                 QString arrowPath = comboBoxPath + QLS(appears_as_list ? ".GtkToggleButton.GtkArrow"
  1467                 QHashableLatin1Literal arrowPath("");
  1473                                                     : ".GtkToggleButton.GtkHBox.GtkArrow");
  1468                 if (comboBox->editable) {
       
  1469                     if (appears_as_list)
       
  1470                         arrowPath = QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkArrow");
       
  1471                     else
       
  1472                         arrowPath = QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkHBox.GtkArrow");
       
  1473                 } else {
       
  1474                     if (appears_as_list)
       
  1475                         arrowPath = QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkArrow");
       
  1476                     else
       
  1477                         arrowPath = QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkHBox.GtkArrow");
       
  1478                 }
  1474 
  1479 
  1475                 GtkWidget *gtkArrow = d->gtkWidget(arrowPath);
  1480                 GtkWidget *gtkArrow = d->gtkWidget(arrowPath);
  1476                 gfloat scale = 0.7;
  1481                 gfloat scale = 0.7;
  1477                 gint minSize = 15;
  1482                 gint minSize = 15;
  1478                 QRect arrowWidgetRect;
  1483                 QRect arrowWidgetRect;
  1495 
  1500 
  1496                 arrowRect.moveCenter(arrowWidgetRect.center());
  1501                 arrowRect.moveCenter(arrowWidgetRect.center());
  1497 
  1502 
  1498                 if (sunken) {
  1503                 if (sunken) {
  1499                     int xoff, yoff;
  1504                     int xoff, yoff;
  1500                     GtkWidget *gtkButton = d->gtkWidget(comboBoxPath + QLS(".GtkToggleButton"));
  1505                     const QHashableLatin1Literal toggleButtonPath = comboBox->editable
       
  1506                             ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton")
       
  1507                             : QHashableLatin1Literal("GtkComboBox.GtkToggleButton");
       
  1508 
       
  1509                     GtkWidget *gtkButton = d->gtkWidget(toggleButtonPath);
  1501                     d->gtk_widget_style_get(gtkButton, "child-displacement-x", &xoff, NULL);
  1510                     d->gtk_widget_style_get(gtkButton, "child-displacement-x", &xoff, NULL);
  1502                     d->gtk_widget_style_get(gtkButton, "child-displacement-y", &yoff, NULL);
  1511                     d->gtk_widget_style_get(gtkButton, "child-displacement-y", &yoff, NULL);
  1503                     arrowRect = arrowRect.adjusted(xoff, yoff, xoff, yoff);
  1512                     arrowRect = arrowRect.adjusted(xoff, yoff, xoff, yoff);
  1504                 }
  1513                 }
  1505 
  1514 
  1507                 // hence we have provide the whole widget as the cliprect
  1516                 // hence we have provide the whole widget as the cliprect
  1508                 if (gtkArrow) {
  1517                 if (gtkArrow) {
  1509                     gtkCachedPainter.setClipRect(option->rect);
  1518                     gtkCachedPainter.setClipRect(option->rect);
  1510                     gtkCachedPainter.paintArrow( gtkArrow, "arrow", arrowRect,
  1519                     gtkCachedPainter.paintArrow( gtkArrow, "arrow", arrowRect,
  1511                                            GTK_ARROW_DOWN, state, GTK_SHADOW_NONE, TRUE,
  1520                                            GTK_ARROW_DOWN, state, GTK_SHADOW_NONE, TRUE,
  1512                                            style, arrowPath + QString::number(option->direction));
  1521                                            style, arrowPath.toString() + QString::number(option->direction));
  1513                 }
  1522                 }
  1514             }
  1523             }
  1515             END_STYLE_PIXMAPCACHE;
  1524             END_STYLE_PIXMAPCACHE;
  1516         }
  1525         }
  1517         break;
  1526         break;
  1568                 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
  1577                 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
  1569             }
  1578             }
  1570 
  1579 
  1571             QStyleOptionToolButton label = *toolbutton;
  1580             QStyleOptionToolButton label = *toolbutton;
  1572             label.state = bflags;
  1581             label.state = bflags;
  1573             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkToolButton.GtkButton"));
  1582             GtkWidget *gtkButton = d->gtkWidget("GtkToolButton.GtkButton");
  1574             QPalette pal = toolbutton->palette;
  1583             QPalette pal = toolbutton->palette;
  1575             if (option->state & State_Enabled && 
  1584             if (option->state & State_Enabled && 
  1576                 option->state & State_MouseOver && !(widget && widget->testAttribute(Qt::WA_SetPalette))) {
  1585                 option->state & State_MouseOver && !(widget && widget->testAttribute(Qt::WA_SetPalette))) {
  1577                 GdkColor gdkText = gtkButton->style->fg[GTK_STATE_PRELIGHT];
  1586                 GdkColor gdkText = gtkButton->style->fg[GTK_STATE_PRELIGHT];
  1578                 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
  1587                 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
  1603 #endif // QT_NO_TOOLBUTTON
  1612 #endif // QT_NO_TOOLBUTTON
  1604 #ifndef QT_NO_SCROLLBAR
  1613 #ifndef QT_NO_SCROLLBAR
  1605 
  1614 
  1606     case CC_ScrollBar:
  1615     case CC_ScrollBar:
  1607         if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
  1616         if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
  1608             GtkWidget *gtkHScrollBar = d->gtkWidget(QLS("GtkHScrollbar"));
  1617             GtkWidget *gtkHScrollBar = d->gtkWidget("GtkHScrollbar");
  1609             GtkWidget *gtkVScrollBar = d->gtkWidget(QLS("GtkVScrollbar"));
  1618             GtkWidget *gtkVScrollBar = d->gtkWidget("GtkVScrollbar");
  1610 
  1619 
  1611             // Fill background in case the scrollbar is partially transparent
  1620             // Fill background in case the scrollbar is partially transparent
  1612             painter->fillRect(option->rect, option->palette.background());
  1621             painter->fillRect(option->rect, option->palette.background());
  1613 
  1622 
  1614             QRect rect = scrollBar->rect;
  1623             QRect rect = scrollBar->rect;
  1619             bool horizontal = scrollBar->orientation == Qt::Horizontal;
  1628             bool horizontal = scrollBar->orientation == Qt::Horizontal;
  1620             GtkWidget * scrollbarWidget = horizontal ? gtkHScrollBar : gtkVScrollBar;
  1629             GtkWidget * scrollbarWidget = horizontal ? gtkHScrollBar : gtkVScrollBar;
  1621             style = scrollbarWidget->style;
  1630             style = scrollbarWidget->style;
  1622             gboolean trough_under_steppers = true;
  1631             gboolean trough_under_steppers = true;
  1623             gboolean trough_side_details = false;
  1632             gboolean trough_side_details = false;
       
  1633             gboolean activate_slider = false;
  1624             gboolean stepper_size = 14;
  1634             gboolean stepper_size = 14;
  1625             gint trough_border = 1;
  1635             gint trough_border = 1;
  1626             if (!d->gtk_check_version(2, 10, 0)) {
  1636             if (!d->gtk_check_version(2, 10, 0)) {
  1627                 d->gtk_widget_style_get((GtkWidget*)(scrollbarWidget),
  1637                 d->gtk_widget_style_get((GtkWidget*)(scrollbarWidget),
  1628                                            "trough-border",   &trough_border,
  1638                                            "trough-border",   &trough_border,
  1629                                            "trough-side-details",   &trough_side_details,
  1639                                            "trough-side-details",   &trough_side_details,
  1630                                            "trough-under-steppers", &trough_under_steppers,
  1640                                            "trough-under-steppers", &trough_under_steppers,
       
  1641                                            "activate-slider",       &activate_slider,
  1631                                            "stepper-size",          &stepper_size, NULL);
  1642                                            "stepper-size",          &stepper_size, NULL);
  1632             }
  1643             }
  1633             if (trough_under_steppers) {
  1644             if (trough_under_steppers) {
  1634                 scrollBarAddLine.adjust(trough_border, trough_border, -trough_border, -trough_border);
  1645                 scrollBarAddLine.adjust(trough_border, trough_border, -trough_border, -trough_border);
  1635                 scrollBarSubLine.adjust(trough_border, trough_border, -trough_border, -trough_border);
  1646                 scrollBarSubLine.adjust(trough_border, trough_border, -trough_border, -trough_border);
  1671             if (scrollBar->subControls & SC_ScrollBarSlider) {
  1682             if (scrollBar->subControls & SC_ScrollBarSlider) {
  1672                 GtkStateType state = GTK_STATE_NORMAL;
  1683                 GtkStateType state = GTK_STATE_NORMAL;
  1673 
  1684 
  1674                 if (!(option->state & State_Enabled))
  1685                 if (!(option->state & State_Enabled))
  1675                     state = GTK_STATE_INSENSITIVE;
  1686                     state = GTK_STATE_INSENSITIVE;
       
  1687                 else if (activate_slider &&
       
  1688                          option->state & State_Sunken && (scrollBar->activeSubControls & SC_ScrollBarSlider))
       
  1689                     state = GTK_STATE_ACTIVE;
  1676                 else if (option->state & State_MouseOver && (scrollBar->activeSubControls & SC_ScrollBarSlider))
  1690                 else if (option->state & State_MouseOver && (scrollBar->activeSubControls & SC_ScrollBarSlider))
  1677                     state = GTK_STATE_PRELIGHT;
  1691                     state = GTK_STATE_PRELIGHT;
  1678 
  1692 
  1679                 GtkShadowType shadow = GTK_SHADOW_OUT;
  1693                 GtkShadowType shadow = GTK_SHADOW_OUT;
  1680 
  1694 
  1749 #ifndef QT_NO_SPINBOX
  1763 #ifndef QT_NO_SPINBOX
  1750 
  1764 
  1751     case CC_SpinBox:
  1765     case CC_SpinBox:
  1752         if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  1766         if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  1753 
  1767 
  1754             GtkWidget *gtkSpinButton = d->gtkWidget(
  1768             GtkWidget *gtkSpinButton = spinBox->buttonSymbols == QAbstractSpinBox::NoButtons
  1755                     spinBox->buttonSymbols == QAbstractSpinBox::NoButtons ?
  1769                         ? d->gtkWidget("GtkEntry")
  1756                     QLS("GtkEntry") :
  1770                         : d->gtkWidget("GtkSpinButton");
  1757                     QLS("GtkSpinButton"));
       
  1758             bool isEnabled = (spinBox->state & State_Enabled);
  1771             bool isEnabled = (spinBox->state & State_Enabled);
  1759             bool hover = isEnabled && (spinBox->state & State_MouseOver);
  1772             bool hover = isEnabled && (spinBox->state & State_MouseOver);
  1760             bool sunken = (spinBox->state & State_Sunken);
  1773             bool sunken = (spinBox->state & State_Sunken);
  1761             bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
  1774             bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
  1762             bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
  1775             bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
  1904 
  1917 
  1905 #ifndef QT_NO_SLIDER
  1918 #ifndef QT_NO_SLIDER
  1906 
  1919 
  1907     case CC_Slider:
  1920     case CC_Slider:
  1908         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
  1921         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
  1909             GtkWidget *hScaleWidget = d->gtkWidget(QLS("GtkHScale"));
  1922             GtkWidget *hScaleWidget = d->gtkWidget("GtkHScale");
  1910             GtkWidget *vScaleWidget = d->gtkWidget(QLS("GtkVScale"));
  1923             GtkWidget *vScaleWidget = d->gtkWidget("GtkVScale");
  1911 
  1924 
  1912             QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
  1925             QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
  1913             QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
  1926             QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
  1914             QRect ticks = proxy()->subControlRect(CC_Slider, option, SC_SliderTickmarks, widget);
       
  1915 
  1927 
  1916             bool horizontal = slider->orientation == Qt::Horizontal;
  1928             bool horizontal = slider->orientation == Qt::Horizontal;
  1917             bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
  1929             bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
  1918             bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
  1930             bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
  1919             QColor activeHighlight = option->palette.color(QPalette::Normal, QPalette::Highlight);
  1931 
  1920 
       
  1921             QPixmap cache;
       
  1922             QBrush oldBrush = painter->brush();
  1932             QBrush oldBrush = painter->brush();
  1923             QPen oldPen = painter->pen();
  1933             QPen oldPen = painter->pen();
  1924 
  1934 
  1925             QColor shadowAlpha(Qt::black);
  1935             QColor shadowAlpha(Qt::black);
  1926             shadowAlpha.setAlpha(10);
  1936             shadowAlpha.setAlpha(10);
  1927             QColor highlightAlpha(Qt::white);
  1937             QColor highlightAlpha(Qt::white);
  1928             highlightAlpha.setAlpha(80);
  1938             highlightAlpha.setAlpha(80);
  1929 
  1939 
       
  1940             QGtkStylePrivate::gtk_widget_set_direction(hScaleWidget, slider->upsideDown ?
       
  1941                                                        GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1930             GtkWidget *scaleWidget = horizontal ? hScaleWidget : vScaleWidget;
  1942             GtkWidget *scaleWidget = horizontal ? hScaleWidget : vScaleWidget;
  1931             style = scaleWidget->style;
  1943             style = scaleWidget->style;
  1932 
  1944 
  1933             if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
  1945             if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
  1934                 GtkObject *adjustment =  d->gtk_adjustment_new(slider->sliderPosition,
  1946                 GtkObject *adjustment =  d->gtk_adjustment_new(slider->sliderPosition,
  1958                 } else {
  1970                 } else {
  1959                     QRect upperGroove = grooveRect;
  1971                     QRect upperGroove = grooveRect;
  1960                     QRect lowerGroove = grooveRect;
  1972                     QRect lowerGroove = grooveRect;
  1961 
  1973 
  1962                     if (horizontal) {
  1974                     if (horizontal) {
  1963                         upperGroove.setLeft(handle.center().x());
  1975                         if (slider->upsideDown) {
  1964                         lowerGroove.setRight(handle.center().x());
  1976                             lowerGroove.setLeft(handle.center().x());
       
  1977                             upperGroove.setRight(handle.center().x());
       
  1978                         } else {
       
  1979                             upperGroove.setLeft(handle.center().x());
       
  1980                             lowerGroove.setRight(handle.center().x());
       
  1981                         }
  1965                     } else {
  1982                     } else {
  1966                         upperGroove.setBottom(handle.center().y());
  1983                         if (!slider->upsideDown) {
  1967                         lowerGroove.setTop(handle.center().y());
  1984                             lowerGroove.setBottom(handle.center().y());
       
  1985                             upperGroove.setTop(handle.center().y());
       
  1986                         } else {
       
  1987                             upperGroove.setBottom(handle.center().y());
       
  1988                             lowerGroove.setTop(handle.center().y());
       
  1989                         }
  1968                     }
  1990                     }
  1969 
  1991 
  1970                     gtkPainter.paintBox( scaleWidget, "trough-upper", upperGroove, state,
  1992                     gtkPainter.paintBox( scaleWidget, "trough-upper", upperGroove, state,
  1971                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
  1993                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
  1972                     gtkPainter.paintBox( scaleWidget, "trough-lower", lowerGroove, state,
  1994                     gtkPainter.paintBox( scaleWidget, "trough-lower", lowerGroove, state,
  2095     QGtkPainter gtkPainter(painter);
  2117     QGtkPainter gtkPainter(painter);
  2096 
  2118 
  2097     switch (element) {
  2119     switch (element) {
  2098     case CE_ProgressBarLabel:
  2120     case CE_ProgressBarLabel:
  2099         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2121         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2100             GtkWidget *gtkProgressBar = d->gtkWidget(QLS("GtkProgressBar"));
  2122             GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
  2101             if (!gtkProgressBar)
  2123             if (!gtkProgressBar)
  2102                 return;
  2124                 return;
  2103 
  2125 
  2104             QRect leftRect;
  2126             QRect leftRect;
  2105             QRect rect = bar->rect;
  2127             QRect rect = bar->rect;
  2198             ir.translate(buttonShift);
  2220             ir.translate(buttonShift);
  2199 
  2221 
  2200             if (button->features & QStyleOptionButton::HasMenu)
  2222             if (button->features & QStyleOptionButton::HasMenu)
  2201                 ir = ir.adjusted(0, 0, -pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
  2223                 ir = ir.adjusted(0, 0, -pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
  2202 
  2224 
  2203             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
  2225             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
  2204             QPalette pal = button->palette;
  2226             QPalette pal = button->palette;
  2205             int labelState = GTK_STATE_INSENSITIVE;
  2227             int labelState = GTK_STATE_INSENSITIVE;
  2206             if (option->state & State_Enabled)
  2228             if (option->state & State_Enabled)
  2207                 labelState = (option->state & State_MouseOver && !(option->state & State_Sunken)) ?
  2229                 labelState = (option->state & State_MouseOver && !(option->state & State_Sunken)) ?
  2208                              GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
  2230                              GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
  2219     case CE_CheckBox:
  2241     case CE_CheckBox:
  2220         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  2242         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  2221             bool isRadio = (element == CE_RadioButton);
  2243             bool isRadio = (element == CE_RadioButton);
  2222 
  2244 
  2223             // Draw prelight background
  2245             // Draw prelight background
  2224             GtkWidget *gtkRadioButton = d->gtkWidget(QLS("GtkRadioButton"));
  2246             GtkWidget *gtkRadioButton = d->gtkWidget("GtkRadioButton");
  2225 
  2247 
  2226             if (option->state & State_MouseOver) {
  2248             if (option->state & State_MouseOver) {
  2227                 gtkPainter.paintFlatBox(gtkRadioButton, "checkbutton", option->rect,
  2249                 gtkPainter.paintFlatBox(gtkRadioButton, "checkbutton", option->rect,
  2228                                         GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkRadioButton->style);
  2250                                         GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkRadioButton->style);
  2229             }
  2251             }
  2287                 else
  2309                 else
  2288                     editRect.translate(cb->iconSize.width() + 4, 0);
  2310                     editRect.translate(cb->iconSize.width() + 4, 0);
  2289             }
  2311             }
  2290 
  2312 
  2291             if (!cb->currentText.isEmpty() && !cb->editable) {
  2313             if (!cb->currentText.isEmpty() && !cb->editable) {
  2292                 GtkWidget *gtkCombo = d->gtkWidget(QLS("GtkComboBox"));
  2314                 GtkWidget *gtkCombo = d->gtkWidget("GtkComboBox");
  2293                 QPalette pal = cb->palette;
  2315                 QPalette pal = cb->palette;
  2294                 int labelState = GTK_STATE_INSENSITIVE;
  2316                 int labelState = GTK_STATE_INSENSITIVE;
  2295 
  2317 
  2296                 if (option->state & State_Enabled)
  2318                 if (option->state & State_Enabled)
  2297                     labelState = (option->state & State_MouseOver && !appearsAsList) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
  2319                     labelState = (option->state & State_MouseOver && !appearsAsList) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
  2364         painter->save();
  2386         painter->save();
  2365 
  2387 
  2366         // Draws the header in tables.
  2388         // Draws the header in tables.
  2367         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
  2389         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
  2368             Q_UNUSED(header);
  2390             Q_UNUSED(header);
  2369             GtkWidget *gtkTreeView = d->gtkWidget(QLS("GtkTreeView"));
  2391             GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
  2370             // Get the middle column
  2392             // Get the middle column
  2371             GtkTreeViewColumn *column = d->gtk_tree_view_get_column((GtkTreeView*)gtkTreeView, 1);
  2393             GtkTreeViewColumn *column = d->gtk_tree_view_get_column((GtkTreeView*)gtkTreeView, 1);
  2372             Q_ASSERT(column);
  2394             Q_ASSERT(column);
  2373 
  2395 
  2374             GtkWidget *gtkTreeHeader = column->button;
  2396             GtkWidget *gtkTreeHeader = column->button;
  2385         break;
  2407         break;
  2386 
  2408 
  2387 #ifndef QT_NO_SIZEGRIP
  2409 #ifndef QT_NO_SIZEGRIP
  2388 
  2410 
  2389     case CE_SizeGrip: {
  2411     case CE_SizeGrip: {
  2390         GtkWidget *gtkStatusbar = d->gtkWidget(QLS("GtkStatusbar.GtkFrame"));
  2412         GtkWidget *gtkStatusbar = d->gtkWidget("GtkStatusbar.GtkFrame");
  2391         QRect gripRect = option->rect.adjusted(0, 0, -gtkStatusbar->style->xthickness, -gtkStatusbar->style->ythickness);
  2413         QRect gripRect = option->rect.adjusted(0, 0, -gtkStatusbar->style->xthickness, -gtkStatusbar->style->ythickness);
  2392         gtkPainter.paintResizeGrip( gtkStatusbar, "statusbar", gripRect, GTK_STATE_NORMAL,
  2414         gtkPainter.paintResizeGrip( gtkStatusbar, "statusbar", gripRect, GTK_STATE_NORMAL,
  2393                                     GTK_SHADOW_OUT, QApplication::isRightToLeft() ?
  2415                                     GTK_SHADOW_OUT, QApplication::isRightToLeft() ?
  2394                                         GDK_WINDOW_EDGE_SOUTH_WEST : GDK_WINDOW_EDGE_SOUTH_EAST,
  2416                                         GDK_WINDOW_EDGE_SOUTH_WEST : GDK_WINDOW_EDGE_SOUTH_EAST,
  2395                                     gtkStatusbar->style);
  2417                                     gtkStatusbar->style);
  2397     break;
  2419     break;
  2398 
  2420 
  2399 #endif // QT_NO_SIZEGRIP
  2421 #endif // QT_NO_SIZEGRIP
  2400 
  2422 
  2401     case CE_MenuBarEmptyArea: {
  2423     case CE_MenuBarEmptyArea: {
  2402         GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar"));
  2424         GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
  2403         GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
  2425         GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
  2404         painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
  2426         painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
  2405         if (widget) { // See CE_MenuBarItem
  2427         if (widget) { // See CE_MenuBarItem
  2406             QRect menuBarRect = widget->rect();
  2428             QRect menuBarRect = widget->rect();
  2407             QPixmap pixmap(menuBarRect.size());
  2429             QPixmap pixmap(menuBarRect.size());
  2420 
  2442 
  2421     case CE_MenuBarItem:
  2443     case CE_MenuBarItem:
  2422         painter->save();
  2444         painter->save();
  2423 
  2445 
  2424         if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  2446         if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  2425             GtkWidget *gtkMenubarItem = d->gtkWidget(QLS("GtkMenuBar.GtkMenuItem"));
  2447             GtkWidget *gtkMenubarItem = d->gtkWidget("GtkMenuBar.GtkMenuItem");
  2426             GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar"));
  2448             GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
  2427 
  2449 
  2428             style = gtkMenubarItem->style;
  2450             style = gtkMenubarItem->style;
  2429 
  2451 
  2430             if (widget) {
  2452             if (widget) {
  2431                 // Since Qt does not currently allow filling the entire background
  2453                 // Since Qt does not currently allow filling the entire background
  2477         }
  2499         }
  2478         painter->restore();
  2500         painter->restore();
  2479         break;
  2501         break;
  2480 
  2502 
  2481     case CE_Splitter: {
  2503     case CE_Splitter: {
  2482         GtkWidget *gtkWindow = d->gtkWidget(QLS("GtkWindow")); // The Murrine Engine currently assumes a widget is passed
  2504         GtkWidget *gtkWindow = d->gtkWidget("GtkWindow"); // The Murrine Engine currently assumes a widget is passed
  2483         gtkPainter.paintHandle(gtkWindow, "splitter", option->rect, gtkPainter.gtkState(option), GTK_SHADOW_NONE,
  2505         gtkPainter.paintHandle(gtkWindow, "splitter", option->rect, gtkPainter.gtkState(option), GTK_SHADOW_NONE,
  2484                                 !(option->state & State_Horizontal) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL,
  2506                                 !(option->state & State_Horizontal) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL,
  2485                                 style);
  2507                                 style);
  2486     }
  2508     }
  2487     break;
  2509     break;
  2497             QRect rect = option->rect;
  2519             QRect rect = option->rect;
  2498             // There is a 1 pixel gap between toolbar lines in some styles (i.e Human)
  2520             // There is a 1 pixel gap between toolbar lines in some styles (i.e Human)
  2499             if (toolbar->positionWithinLine != QStyleOptionToolBar::End)
  2521             if (toolbar->positionWithinLine != QStyleOptionToolBar::End)
  2500                 rect.adjust(0, 0, 1, 0);
  2522                 rect.adjust(0, 0, 1, 0);
  2501 
  2523 
  2502             GtkWidget *gtkToolbar = d->gtkWidget(QLS("GtkToolbar"));
  2524             GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
  2503             GtkShadowType shadow_type = GTK_SHADOW_NONE;
  2525             GtkShadowType shadow_type = GTK_SHADOW_NONE;
  2504             d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
  2526             d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
  2505             gtkPainter.paintBox( gtkToolbar, "toolbar",  rect,
  2527             gtkPainter.paintBox( gtkToolbar, "toolbar",  rect,
  2506                                  GTK_STATE_NORMAL, shadow_type, gtkToolbar->style);
  2528                                  GTK_STATE_NORMAL, shadow_type, gtkToolbar->style);
  2507         }
  2529         }
  2516         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  2538         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  2517             const int windowsItemFrame        =  2; // menu item frame width
  2539             const int windowsItemFrame        =  2; // menu item frame width
  2518             const int windowsItemHMargin      =  3; // menu item hor text margin
  2540             const int windowsItemHMargin      =  3; // menu item hor text margin
  2519             const int windowsItemVMargin      = 26; // menu item ver text margin
  2541             const int windowsItemVMargin      = 26; // menu item ver text margin
  2520             const int windowsRightBorder      = 15; // right border on windows
  2542             const int windowsRightBorder      = 15; // right border on windows
  2521             GtkWidget *gtkMenuItem = menuItem->checked ? d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")) :
  2543             GtkWidget *gtkMenuItem = menuItem->checked ? d->gtkWidget("GtkMenu.GtkCheckMenuItem") :
  2522                                      d->gtkWidget(QLS("GtkMenu.GtkMenuItem"));
  2544                                      d->gtkWidget("GtkMenu.GtkMenuItem");
  2523 
  2545 
  2524             style = gtkPainter.getStyle(gtkMenuItem);
  2546             style = gtkPainter.getStyle(gtkMenuItem);
  2525             QColor borderColor = option->palette.background().color().darker(160);
       
  2526             QColor shadow = option->palette.dark().color();
  2547             QColor shadow = option->palette.dark().color();
  2527 
  2548 
  2528             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  2549             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  2529                 GtkWidget *gtkMenuSeparator = d->gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem"));
  2550                 GtkWidget *gtkMenuSeparator = d->gtkWidget("GtkMenu.GtkSeparatorMenuItem");
  2530                 painter->setPen(shadow.lighter(106));
  2551                 painter->setPen(shadow.lighter(106));
  2531                 gboolean wide_separators = 0;
  2552                 gboolean wide_separators = 0;
  2532                 gint     separator_height = 0;
  2553                 gint     separator_height = 0;
  2533                 guint    horizontal_padding = 3;
  2554                 guint    horizontal_padding = 3;
  2534                 QRect separatorRect = option->rect;
  2555                 QRect separatorRect = option->rect;
  2568             bool checked = menuItem->checked;
  2589             bool checked = menuItem->checked;
  2569             bool enabled = menuItem->state & State_Enabled;
  2590             bool enabled = menuItem->state & State_Enabled;
  2570             bool ignoreCheckMark = false;
  2591             bool ignoreCheckMark = false;
  2571 
  2592 
  2572             gint checkSize;
  2593             gint checkSize;
  2573             d->gtk_widget_style_get(d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")), "indicator-size", &checkSize, NULL);
  2594             d->gtk_widget_style_get(d->gtkWidget("GtkMenu.GtkCheckMenuItem"), "indicator-size", &checkSize, NULL);
  2574 
  2595 
  2575             int checkcol = qMax(menuItem->maxIconWidth, qMax(20, checkSize));
  2596             int checkcol = qMax(menuItem->maxIconWidth, qMax(20, checkSize));
  2576 
  2597 
  2577 #ifndef QT_NO_COMBOBOX
  2598 #ifndef QT_NO_COMBOBOX
  2578 
  2599 
  2745                 p->restore();
  2766                 p->restore();
  2746             }
  2767             }
  2747 
  2768 
  2748             // Arrow
  2769             // Arrow
  2749             if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
  2770             if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
  2750                 QPoint buttonShift(pixelMetric(PM_ButtonShiftHorizontal, option, widget),
       
  2751                                    proxy()->pixelMetric(PM_ButtonShiftVertical, option, widget));
       
  2752 
  2771 
  2753                 QFontMetrics fm(menuitem->font);
  2772                 QFontMetrics fm(menuitem->font);
  2754                 int arrow_size = fm.ascent() + fm.descent() - 2 * gtkMenuItem->style->ythickness;
  2773                 int arrow_size = fm.ascent() + fm.descent() - 2 * gtkMenuItem->style->ythickness;
  2755                 gfloat arrow_scaling = 0.8;
  2774                 gfloat arrow_scaling = 0.8;
  2756                 int extra = 0;
  2775                 int extra = 0;
  2779         painter->restore();
  2798         painter->restore();
  2780         break;
  2799         break;
  2781 
  2800 
  2782     case CE_PushButton:
  2801     case CE_PushButton:
  2783         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  2802         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  2784             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
  2803             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
  2785             proxy()->drawControl(CE_PushButtonBevel, btn, painter, widget);
  2804             proxy()->drawControl(CE_PushButtonBevel, btn, painter, widget);
  2786             QStyleOptionButton subopt = *btn;
  2805             QStyleOptionButton subopt = *btn;
  2787             subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
  2806             subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
  2788             gint interiorFocus = true;
  2807             gint interiorFocus = true;
  2789             d->gtk_widget_style_get(gtkButton, "interior-focus", &interiorFocus, NULL);
  2808             d->gtk_widget_style_get(gtkButton, "interior-focus", &interiorFocus, NULL);
  2805 
  2824 
  2806 #ifndef QT_NO_TABBAR
  2825 #ifndef QT_NO_TABBAR
  2807 
  2826 
  2808     case CE_TabBarTabShape:
  2827     case CE_TabBarTabShape:
  2809         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
  2828         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
  2810             GtkWidget *gtkNotebook = d->gtkWidget(QLS("GtkNotebook"));
  2829             GtkWidget *gtkNotebook = d->gtkWidget("GtkNotebook");
  2811             style = gtkPainter.getStyle(gtkNotebook);
  2830             style = gtkPainter.getStyle(gtkNotebook);
  2812 
  2831 
  2813             QRect rect = option->rect;
  2832             QRect rect = option->rect;
  2814             GtkShadowType shadow = GTK_SHADOW_OUT;
  2833             GtkShadowType shadow = GTK_SHADOW_OUT;
  2815             GtkStateType state = GTK_STATE_ACTIVE;
  2834             GtkStateType state = GTK_STATE_ACTIVE;
  2872 #endif //QT_NO_TABBAR
  2891 #endif //QT_NO_TABBAR
  2873 
  2892 
  2874     case CE_ProgressBarGroove:
  2893     case CE_ProgressBarGroove:
  2875         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2894         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2876             Q_UNUSED(bar);
  2895             Q_UNUSED(bar);
  2877             GtkWidget *gtkProgressBar = d->gtkWidget(QLS("GtkProgressBar"));
  2896             GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
  2878             GtkStateType state = gtkPainter.gtkState(option);
  2897             GtkStateType state = gtkPainter.gtkState(option);
  2879             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, gtkProgressBar->style);
  2898             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, gtkProgressBar->style);
  2880         }
  2899         }
  2881 
  2900 
  2882         break;
  2901         break;
  2883 
  2902 
  2884     case CE_ProgressBarContents:
  2903     case CE_ProgressBarContents:
  2885         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2904         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2886             GtkStateType state = option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE;
  2905             GtkStateType state = option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE;
  2887             GtkWidget *gtkProgressBar = d->gtkWidget(QLS("GtkProgressBar"));
  2906             GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
  2888             style = gtkProgressBar->style;
  2907             style = gtkProgressBar->style;
  2889             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, style);
  2908             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, style);
  2890             int xt = style->xthickness;
  2909             int xt = style->xthickness;
  2891             int yt = style->ythickness;
  2910             int yt = style->ythickness;
  2892             QRect rect = bar->rect.adjusted(xt, yt, -xt, -yt);
  2911             QRect rect = bar->rect.adjusted(xt, yt, -xt, -yt);
  3040 #endif
  3059 #endif
  3041 #ifndef QT_NO_SPINBOX
  3060 #ifndef QT_NO_SPINBOX
  3042 
  3061 
  3043     case CC_SpinBox:
  3062     case CC_SpinBox:
  3044         if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  3063         if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  3045             GtkWidget *gtkSpinButton = d->gtkWidget(QLS("GtkSpinButton"));
  3064             GtkWidget *gtkSpinButton = d->gtkWidget("GtkSpinButton");
  3046             int center = spinbox->rect.height() / 2;
  3065             int center = spinbox->rect.height() / 2;
  3047             int xt = spinbox->frame ? gtkSpinButton->style->xthickness : 0;
  3066             int xt = spinbox->frame ? gtkSpinButton->style->xthickness : 0;
  3048             int yt = spinbox->frame ? gtkSpinButton->style->ythickness : 0;
  3067             int yt = spinbox->frame ? gtkSpinButton->style->ythickness : 0;
  3049             int y = yt;
  3068             int y = yt;
  3050 
  3069 
  3093 #ifndef QT_NO_COMBOBOX
  3112 #ifndef QT_NO_COMBOBOX
  3094 
  3113 
  3095     case CC_ComboBox:
  3114     case CC_ComboBox:
  3096         if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  3115         if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  3097             // We employ the gtk widget to position arrows and separators for us
  3116             // We employ the gtk widget to position arrows and separators for us
  3098             QString comboBoxPath = box->editable ? QLS("GtkComboBoxEntry") : QLS("GtkComboBox");
  3117             GtkWidget *gtkCombo = box->editable ? d->gtkWidget("GtkComboBoxEntry")
  3099             GtkWidget *gtkCombo = d->gtkWidget(comboBoxPath);
  3118                                                 : d->gtkWidget("GtkComboBox");
  3100             d->gtk_widget_set_direction(gtkCombo, (option->direction == Qt::RightToLeft) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  3119             d->gtk_widget_set_direction(gtkCombo, (option->direction == Qt::RightToLeft) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  3101             GtkAllocation geometry = {0, 0, qMax(0, option->rect.width()), qMax(0, option->rect.height())};
  3120             GtkAllocation geometry = {0, 0, qMax(0, option->rect.width()), qMax(0, option->rect.height())};
  3102             d->gtk_widget_size_allocate(gtkCombo, &geometry);
  3121             d->gtk_widget_size_allocate(gtkCombo, &geometry);
  3103             int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, option, widget);
  3122             int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, option, widget);
  3104             QString arrowPath = comboBoxPath + QLS(".GtkToggleButton");
  3123             QHashableLatin1Literal arrowPath("GtkComboBoxEntry.GtkToggleButton");
  3105 
  3124             if (!box->editable) {
  3106             if (!box->editable && !appears_as_list)
  3125                 if (appears_as_list)
  3107                 arrowPath += QLS(".GtkHBox.GtkArrow");
  3126                     arrowPath = "GtkComboBox.GtkToggleButton";
       
  3127                 else
       
  3128                     arrowPath = "GtkComboBox.GtkToggleButton.GtkHBox.GtkArrow";
       
  3129             }
  3108 
  3130 
  3109             GtkWidget *arrowWidget = d->gtkWidget(arrowPath);
  3131             GtkWidget *arrowWidget = d->gtkWidget(arrowPath);
  3110             if (!arrowWidget)
  3132             if (!arrowWidget)
  3111                 return QCleanlooksStyle::subControlRect(control, option, subControl, widget);
  3133                 return QCleanlooksStyle::subControlRect(control, option, subControl, widget);
  3112 
  3134 
  3161 
  3183 
  3162     switch (type) {
  3184     switch (type) {
  3163 
  3185 
  3164     case CT_ToolButton:
  3186     case CT_ToolButton:
  3165         if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  3187         if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  3166             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkToolButton.GtkButton"));
  3188             GtkWidget *gtkButton = d->gtkWidget("GtkToolButton.GtkButton");
  3167             newSize = size + QSize(2 * gtkButton->style->xthickness, 2 + 2 * gtkButton->style->ythickness);
  3189             newSize = size + QSize(2 * gtkButton->style->xthickness, 2 + 2 * gtkButton->style->ythickness);
  3168             if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
  3190             if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
  3169                 QSize minSize(0, 25);
  3191                 QSize minSize(0, 25);
  3170                 if (toolbutton->toolButtonStyle != Qt::ToolButtonTextOnly)
  3192                 if (toolbutton->toolButtonStyle != Qt::ToolButtonTextOnly)
  3171                     minSize = toolbutton->iconSize + QSize(12, 12);
  3193                     minSize = toolbutton->iconSize + QSize(12, 12);
  3179     case CT_MenuItem:
  3201     case CT_MenuItem:
  3180         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  3202         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  3181             int textMargin = 8;
  3203             int textMargin = 8;
  3182 
  3204 
  3183             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  3205             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  3184                 GtkWidget *gtkMenuSeparator = d->gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem"));
  3206                 GtkWidget *gtkMenuSeparator = d->gtkWidget("GtkMenu.GtkSeparatorMenuItem");
  3185                 GtkRequisition sizeReq = {0, 0};
  3207                 GtkRequisition sizeReq = {0, 0};
  3186                 d->gtk_widget_size_request(gtkMenuSeparator, &sizeReq);
  3208                 d->gtk_widget_size_request(gtkMenuSeparator, &sizeReq);
  3187                 newSize = QSize(size.width(), sizeReq.height);
  3209                 newSize = QSize(size.width(), sizeReq.height);
  3188                 break;
  3210                 break;
  3189             }
  3211             }
  3190 
  3212 
  3191             GtkWidget *gtkMenuItem = d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem"));
  3213             GtkWidget *gtkMenuItem = d->gtkWidget("GtkMenu.GtkCheckMenuItem");
  3192             GtkStyle* style = gtkMenuItem->style;
  3214             GtkStyle* style = gtkMenuItem->style;
  3193 
  3215 
  3194             // Note we get the perfect height for the default font since we
  3216             // Note we get the perfect height for the default font since we
  3195             // set a fake text label on the gtkMenuItem
  3217             // set a fake text label on the gtkMenuItem
  3196             // But if custom fonts are used on the widget we need a minimum size
  3218             // But if custom fonts are used on the widget we need a minimum size
  3208 
  3230 
  3209         break;
  3231         break;
  3210 
  3232 
  3211     case CT_SpinBox:
  3233     case CT_SpinBox:
  3212         // QSpinBox does some nasty things that depends on CT_LineEdit
  3234         // QSpinBox does some nasty things that depends on CT_LineEdit
  3213         newSize = size + QSize(0, -d->gtkWidget(QLS("GtkSpinButton"))->style->ythickness * 2);
  3235         newSize = size + QSize(0, -d->gtkWidget("GtkSpinButton")->style->ythickness * 2);
  3214         break;
  3236         break;
  3215 
  3237 
  3216     case CT_PushButton:
  3238     case CT_PushButton:
  3217         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  3239         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  3218             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
  3240             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
  3219             gint focusPadding, focusWidth;
  3241             gint focusPadding, focusWidth;
  3220             d->gtk_widget_style_get(gtkButton, "focus-padding", &focusPadding, NULL);
  3242             d->gtk_widget_style_get(gtkButton, "focus-padding", &focusPadding, NULL);
  3221             d->gtk_widget_style_get(gtkButton, "focus-line-width", &focusWidth, NULL);
  3243             d->gtk_widget_style_get(gtkButton, "focus-line-width", &focusWidth, NULL);
  3222             newSize = size;
  3244             newSize = size;
  3223             newSize += QSize(2*gtkButton->style->xthickness + 4, 2*gtkButton->style->ythickness);
  3245             newSize += QSize(2*gtkButton->style->xthickness + 4, 2*gtkButton->style->ythickness);
  3224             newSize += QSize(2*(focusWidth + focusPadding + 2), 2*(focusWidth + focusPadding));
  3246             newSize += QSize(2*(focusWidth + focusPadding + 2), 2*(focusWidth + focusPadding));
  3225 
  3247 
  3226             GtkWidget *gtkButtonBox = d->gtkWidget(QLS("GtkHButtonBox"));
  3248             GtkWidget *gtkButtonBox = d->gtkWidget("GtkHButtonBox");
  3227             gint minWidth = 85, minHeight = 0;
  3249             gint minWidth = 85, minHeight = 0;
  3228             d->gtk_widget_style_get(gtkButtonBox, "child-min-width", &minWidth,
  3250             d->gtk_widget_style_get(gtkButtonBox, "child-min-width", &minWidth,
  3229                                    "child-min-height", &minHeight, NULL);
  3251                                    "child-min-height", &minHeight, NULL);
  3230             if (!btn->text.isEmpty() && newSize.width() < minWidth)
  3252             if (!btn->text.isEmpty() && newSize.width() < minWidth)
  3231                 newSize.setWidth(minWidth);
  3253                 newSize.setWidth(minWidth);
  3234         }
  3256         }
  3235 
  3257 
  3236         break;
  3258         break;
  3237 
  3259 
  3238     case CT_Slider: {
  3260     case CT_Slider: {
  3239         GtkWidget *gtkSlider = d->gtkWidget(QLS("GtkHScale"));
  3261         GtkWidget *gtkSlider = d->gtkWidget("GtkHScale");
  3240         newSize = size + QSize(2*gtkSlider->style->xthickness, 2*gtkSlider->style->ythickness);
  3262         newSize = size + QSize(2*gtkSlider->style->xthickness, 2*gtkSlider->style->ythickness);
  3241     }
  3263     }
  3242     break;
  3264     break;
  3243 
  3265 
  3244     case CT_LineEdit: {
  3266     case CT_LineEdit: {
  3245         GtkWidget *gtkEntry = d->gtkWidget(QLS("GtkEntry"));
  3267         GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
  3246         newSize = size + QSize(2*gtkEntry->style->xthickness, 2 + 2*gtkEntry->style->ythickness);
  3268         newSize = size + QSize(2*gtkEntry->style->xthickness, 2 + 2*gtkEntry->style->ythickness);
  3247     }
  3269     }
  3248     break;
  3270     break;
  3249 
  3271 
  3250     case CT_ItemViewItem:
  3272     case CT_ItemViewItem:
  3251         newSize += QSize(0, 2);
  3273         newSize += QSize(0, 2);
  3252         break;
  3274         break;
  3253 
  3275 
  3254     case CT_ComboBox:
  3276     case CT_ComboBox:
  3255         if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  3277         if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  3256             GtkWidget *gtkCombo = d->gtkWidget(QLS("GtkComboBox"));
  3278             GtkWidget *gtkCombo = d->gtkWidget("GtkComboBox");
  3257             QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, combo, SC_ComboBoxArrow, widget);
  3279             QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, combo, SC_ComboBoxArrow, widget);
  3258             newSize = size + QSize(12 + arrowButtonRect.width() + 2*gtkCombo->style->xthickness, 4 + 2*gtkCombo->style->ythickness);
  3280             newSize = size + QSize(12 + arrowButtonRect.width() + 2*gtkCombo->style->xthickness, 4 + 2*gtkCombo->style->ythickness);
  3259 
  3281 
  3260             if (!(widget && qobject_cast<QToolBar *>(widget->parentWidget())))
  3282             if (!(widget && qobject_cast<QToolBar *>(widget->parentWidget())))
  3261                 newSize += QSize(0, 2);
  3283                 newSize += QSize(0, 2);
  3406     case SE_ProgressBarContents:
  3428     case SE_ProgressBarContents:
  3407     case SE_ProgressBarGroove:
  3429     case SE_ProgressBarGroove:
  3408         return option->rect;
  3430         return option->rect;
  3409     case SE_PushButtonContents:
  3431     case SE_PushButtonContents:
  3410         if (!d->gtk_check_version(2, 10, 0)) {
  3432         if (!d->gtk_check_version(2, 10, 0)) {
  3411             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
  3433             GtkWidget *gtkButton = d->gtkWidget("GtkButton");
  3412             GtkBorder *border = 0;
  3434             GtkBorder *border = 0;
  3413             d->gtk_widget_style_get(gtkButton, "inner-border", &border, NULL);
  3435             d->gtk_widget_style_get(gtkButton, "inner-border", &border, NULL);
  3414             if (border) {
  3436             if (border) {
  3415                 r = option->rect.adjusted(border->left, border->top, -border->right, -border->bottom);
  3437                 r = option->rect.adjusted(border->left, border->top, -border->right, -border->bottom);
  3416                 d->gtk_border_free(border);
  3438                 d->gtk_border_free(border);