src/gui/styles/qgtkstyle.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 19 fcece45ef507
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
  1104         QRect buttonRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
  1104         QRect buttonRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
  1105         gtkPainter.setClipRect(option->rect);
  1105         gtkPainter.setClipRect(option->rect);
  1106         // ### Note: Ubuntulooks breaks when the proper widget is passed
  1106         // ### Note: Ubuntulooks breaks when the proper widget is passed
  1107         //           Murrine engine requires a widget not to get RGBA check - warnings
  1107         //           Murrine engine requires a widget not to get RGBA check - warnings
  1108         GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
  1108         GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
  1109         gtkPainter.paintOption(gtkCheckButton , buttonRect, state, shadow, gtkRadioButton->style, QLS("radiobutton"));
  1109         QString key(QLS("radiobutton"));
  1110 
  1110         if (option->state & State_HasFocus) { // Themes such as Nodoka check this flag
       
  1111             key += QLatin1Char('f');
       
  1112             GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
       
  1113         }
       
  1114         gtkPainter.paintOption(gtkCheckButton , buttonRect, state, shadow, gtkRadioButton->style, key);
       
  1115         if (option->state & State_HasFocus)
       
  1116             GTK_WIDGET_UNSET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
  1111     }
  1117     }
  1112     break;
  1118     break;
  1113 
  1119 
  1114     case PE_IndicatorCheckBox: {
  1120     case PE_IndicatorCheckBox: {
  1115         GtkShadowType shadow = GTK_SHADOW_OUT;
  1121         GtkShadowType shadow = GTK_SHADOW_OUT;
  1126             shadow = GTK_SHADOW_OUT;
  1132             shadow = GTK_SHADOW_OUT;
  1127 
  1133 
  1128         int spacing;
  1134         int spacing;
  1129 
  1135 
  1130         GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
  1136         GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
       
  1137         QString key(QLS("checkbutton"));
       
  1138         if (option->state & State_HasFocus) { // Themes such as Nodoka checks this flag
       
  1139             key += QLatin1Char('f');
       
  1140             GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
       
  1141         }
  1131 
  1142 
  1132         // Some styles such as aero-clone assume they can paint in the spacing area
  1143         // Some styles such as aero-clone assume they can paint in the spacing area
  1133         gtkPainter.setClipRect(option->rect);
  1144         gtkPainter.setClipRect(option->rect);
  1134 
  1145 
  1135         d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, NULL);
  1146         d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, NULL);
  1136 
  1147 
  1137         QRect checkRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
  1148         QRect checkRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
  1138 
  1149 
  1139         gtkPainter.paintCheckbox(gtkCheckButton, checkRect, state, shadow, gtkCheckButton->style,
  1150         gtkPainter.paintCheckbox(gtkCheckButton, checkRect, state, shadow, gtkCheckButton->style,
  1140                                  QLS("checkbutton"));
  1151                                  key);
       
  1152         if (option->state & State_HasFocus)
       
  1153             GTK_WIDGET_UNSET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
       
  1154 
  1141     }
  1155     }
  1142     break;
  1156     break;
  1143 
  1157 
  1144 #ifndef QT_NO_TABBAR
  1158 #ifndef QT_NO_TABBAR
  1145 
  1159 
  1375                         resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
  1389                         resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
  1376                         p->fillRect(contentRect, option->palette.base().color());
  1390                         p->fillRect(contentRect, option->palette.base().color());
  1377                     else {
  1391                     else {
  1378                         gtkCachedPainter.paintFlatBox(gtkEntry, "entry_bg", contentRect,
  1392                         gtkCachedPainter.paintFlatBox(gtkEntry, "entry_bg", contentRect,
  1379                                                 option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
  1393                                                 option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
  1380                                                 GTK_SHADOW_NONE, gtkCombo->style, entryPath + QString::number(focus));
  1394                                                 GTK_SHADOW_NONE, gtkEntry->style, entryPath + QString::number(focus));
  1381                     }
  1395                     }
  1382 
  1396 
  1383                     gtkCachedPainter.paintShadow(gtkEntry, comboBox->editable ? "entry" : "frame", frameRect, frameState,
  1397                     gtkCachedPainter.paintShadow(gtkEntry, comboBox->editable ? "entry" : "frame", frameRect, frameState,
  1384                                            GTK_SHADOW_IN, gtkEntry->style, entryPath +
  1398                                            GTK_SHADOW_IN, gtkEntry->style, entryPath +
  1385                                            QString::number(focus) + QString::number(comboBox->editable) +
  1399                                            QString::number(focus) + QString::number(comboBox->editable) +
  1734 #endif //QT_NO_SCROLLBAR
  1748 #endif //QT_NO_SCROLLBAR
  1735 #ifndef QT_NO_SPINBOX
  1749 #ifndef QT_NO_SPINBOX
  1736 
  1750 
  1737     case CC_SpinBox:
  1751     case CC_SpinBox:
  1738         if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  1752         if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  1739             GtkWidget *gtkSpinButton = d->gtkWidget(QLS("GtkSpinButton"));
  1753 
       
  1754             GtkWidget *gtkSpinButton = d->gtkWidget(
       
  1755                     spinBox->buttonSymbols == QAbstractSpinBox::NoButtons ?
       
  1756                     QLS("GtkEntry") :
       
  1757                     QLS("GtkSpinButton"));
  1740             bool isEnabled = (spinBox->state & State_Enabled);
  1758             bool isEnabled = (spinBox->state & State_Enabled);
  1741             bool hover = isEnabled && (spinBox->state & State_MouseOver);
  1759             bool hover = isEnabled && (spinBox->state & State_MouseOver);
  1742             bool sunken = (spinBox->state & State_Sunken);
  1760             bool sunken = (spinBox->state & State_Sunken);
  1743             bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
  1761             bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
  1744             bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
  1762             bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
  1745             bool reverse = (spinBox->direction == Qt::RightToLeft);
  1763             bool reverse = (spinBox->direction == Qt::RightToLeft);
  1746 
  1764 
  1747             //### Move this to subControlRect
  1765             QRect editArea = option->rect;
  1748             QRect upRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
       
  1749             upRect.setTop(option->rect.top());
       
  1750 
       
  1751             if (reverse)
       
  1752                 upRect.setLeft(option->rect.left());
       
  1753             else
       
  1754                 upRect.setRight(option->rect.right());
       
  1755 
       
  1756             QRect editRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxEditField, widget);
  1766             QRect editRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxEditField, widget);
  1757             QRect downRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
  1767             QRect upRect, downRect, buttonRect;
  1758             downRect.setBottom(option->rect.bottom());
  1768             if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
  1759 
  1769                 upRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
  1760             if (reverse)
  1770                 downRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
  1761                 downRect.setLeft(option->rect.left());
  1771 
  1762             else
  1772                 //### Move this to subControlRect
  1763                 downRect.setRight(option->rect.right());
  1773                 upRect.setTop(option->rect.top());
  1764 
  1774 
  1765             QRect buttonRect = upRect | downRect;
  1775                 if (reverse)
  1766             QRect editArea = option->rect;
  1776                     upRect.setLeft(option->rect.left());
  1767 
  1777                 else
  1768             if (reverse)
  1778                     upRect.setRight(option->rect.right());
  1769                 editArea.setLeft(upRect.right());
  1779 
  1770             else
  1780                 downRect.setBottom(option->rect.bottom());
  1771                 editArea.setRight(upRect.left());
  1781 
  1772 
  1782                 if (reverse)
       
  1783                     downRect.setLeft(option->rect.left());
       
  1784                 else
       
  1785                     downRect.setRight(option->rect.right());
       
  1786 
       
  1787                 buttonRect = upRect | downRect;
       
  1788 
       
  1789                 if (reverse)
       
  1790                     editArea.setLeft(upRect.right());
       
  1791                 else
       
  1792                     editArea.setRight(upRect.left());
       
  1793             }
  1773             if (spinBox->frame) {
  1794             if (spinBox->frame) {
  1774                 GtkShadowType shadow = GTK_SHADOW_OUT;
  1795                 GtkShadowType shadow = GTK_SHADOW_OUT;
  1775                 GtkStateType state = gtkPainter.gtkState(option);
  1796                 GtkStateType state = gtkPainter.gtkState(option);
  1776 
  1797 
  1777                 if (!(option->state & State_Enabled))
  1798                 if (!(option->state & State_Enabled))
  1801                                             -style->xthickness, -style->ythickness),
  1822                                             -style->xthickness, -style->ythickness),
  1802                                             option->state & State_Enabled ?
  1823                                             option->state & State_Enabled ?
  1803                                             GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_NONE, style, key);
  1824                                             GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_NONE, style, key);
  1804 
  1825 
  1805                 gtkPainter.paintShadow(gtkSpinButton, "entry", editArea, state, GTK_SHADOW_IN, gtkSpinButton->style, key);
  1826                 gtkPainter.paintShadow(gtkSpinButton, "entry", editArea, state, GTK_SHADOW_IN, gtkSpinButton->style, key);
  1806                 gtkPainter.paintBox(gtkSpinButton, "spinbutton", buttonRect, state, GTK_SHADOW_IN, style, key);
  1827                 if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
  1807 
  1828                     gtkPainter.paintBox(gtkSpinButton, "spinbutton", buttonRect, state, GTK_SHADOW_IN, style, key);
  1808                 upRect.setSize(downRect.size());
  1829 
  1809                 if (!(option->state & State_Enabled))
  1830                     upRect.setSize(downRect.size());
  1810                     gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_INSENSITIVE, GTK_SHADOW_IN, style, key);
  1831                     if (!(option->state & State_Enabled))
  1811                 else if (upIsActive && sunken)
  1832                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_INSENSITIVE, GTK_SHADOW_IN, style, key);
  1812                     gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_ACTIVE, GTK_SHADOW_IN, style, key);
  1833                     else if (upIsActive && sunken)
  1813                 else if (upIsActive && hover)
  1834                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_ACTIVE, GTK_SHADOW_IN, style, key);
  1814                     gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style, key);
  1835                     else if (upIsActive && hover)
  1815                 else
  1836                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style, key);
  1816                     gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, style, key);
  1837                     else
  1817 
  1838                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, style, key);
  1818                 if (!(option->state & State_Enabled))
  1839 
  1819                     gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_INSENSITIVE, GTK_SHADOW_IN, style, key);
  1840                     if (!(option->state & State_Enabled))
  1820                 else if (downIsActive && sunken)
  1841                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_INSENSITIVE, GTK_SHADOW_IN, style, key);
  1821                     gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_ACTIVE, GTK_SHADOW_IN, style, key);
  1842                     else if (downIsActive && sunken)
  1822                 else if (downIsActive && hover)
  1843                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_ACTIVE, GTK_SHADOW_IN, style, key);
  1823                     gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style, key);
  1844                     else if (downIsActive && hover)
  1824                 else
  1845                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style, key);
  1825                     gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, style, key);
  1846                     else
  1826 
  1847                         gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, style, key);
  1827                 if (option->state & State_HasFocus)
  1848 
  1828                     GTK_WIDGET_UNSET_FLAGS(gtkSpinButton, GTK_HAS_FOCUS);
  1849                     if (option->state & State_HasFocus)
       
  1850                         GTK_WIDGET_UNSET_FLAGS(gtkSpinButton, GTK_HAS_FOCUS);
       
  1851                 }
  1829             }
  1852             }
  1830 
  1853 
  1831             if (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) {
  1854             if (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) {
  1832                 int centerX = upRect.center().x();
  1855                 int centerX = upRect.center().x();
  1833                 int centerY = upRect.center().y();
  1856                 int centerY = upRect.center().y();
  1848                     painter->drawLine(1 + centerX - 2, 1 + centerY, 1 + centerX + 2, 1 + centerY);
  1871                     painter->drawLine(1 + centerX - 2, 1 + centerY, 1 + centerX + 2, 1 + centerY);
  1849                 } else {
  1872                 } else {
  1850                     painter->drawLine(centerX - 2, centerY, centerX + 2, centerY);
  1873                     painter->drawLine(centerX - 2, centerY, centerX + 2, centerY);
  1851                 }
  1874                 }
  1852 
  1875 
  1853             } else {
  1876             } else if (spinBox->buttonSymbols == QAbstractSpinBox::UpDownArrows) {
  1854                 int size = d->getSpinboxArrowSize();
  1877                 int size = d->getSpinboxArrowSize();
  1855                 int w = size / 2 - 1;
  1878                 int w = size / 2 - 1;
  1856                 w -= w % 2 - 1; // force odd
  1879                 w -= w % 2 - 1; // force odd
  1857                 int h = (w + 1)/2;
  1880                 int h = (w + 1)/2;
  1858                 QRect arrowRect(0, 0, w, h);
  1881                 QRect arrowRect(0, 0, w, h);
  2493         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  2516         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  2494             const int windowsItemFrame        =  2; // menu item frame width
  2517             const int windowsItemFrame        =  2; // menu item frame width
  2495             const int windowsItemHMargin      =  3; // menu item hor text margin
  2518             const int windowsItemHMargin      =  3; // menu item hor text margin
  2496             const int windowsItemVMargin      = 26; // menu item ver text margin
  2519             const int windowsItemVMargin      = 26; // menu item ver text margin
  2497             const int windowsRightBorder      = 15; // right border on windows
  2520             const int windowsRightBorder      = 15; // right border on windows
  2498             GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu"));
       
  2499             GtkWidget *gtkMenuItem = menuItem->checked ? d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")) :
  2521             GtkWidget *gtkMenuItem = menuItem->checked ? d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")) :
  2500                                      d->gtkWidget(QLS("GtkMenu.GtkMenuItem"));
  2522                                      d->gtkWidget(QLS("GtkMenu.GtkMenuItem"));
  2501 
  2523 
  2502             style = gtkPainter.getStyle(gtkMenuItem);
  2524             style = gtkPainter.getStyle(gtkMenuItem);
  2503             QColor borderColor = option->palette.background().color().darker(160);
  2525             QColor borderColor = option->palette.background().color().darker(160);
  2507                 GtkWidget *gtkMenuSeparator = d->gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem"));
  2529                 GtkWidget *gtkMenuSeparator = d->gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem"));
  2508                 painter->setPen(shadow.lighter(106));
  2530                 painter->setPen(shadow.lighter(106));
  2509                 gboolean wide_separators = 0;
  2531                 gboolean wide_separators = 0;
  2510                 gint     separator_height = 0;
  2532                 gint     separator_height = 0;
  2511                 guint    horizontal_padding = 3;
  2533                 guint    horizontal_padding = 3;
       
  2534                 QRect separatorRect = option->rect;
  2512                 if (!d->gtk_check_version(2, 10, 0)) {
  2535                 if (!d->gtk_check_version(2, 10, 0)) {
  2513                     d->gtk_widget_style_get(gtkMenuSeparator,
  2536                     d->gtk_widget_style_get(gtkMenuSeparator,
  2514                                            "wide-separators",    &wide_separators,
  2537                                            "wide-separators",    &wide_separators,
  2515                                            "separator-height",   &separator_height,
  2538                                            "separator-height",   &separator_height,
  2516                                            "horizontal-padding", &horizontal_padding,
  2539                                            "horizontal-padding", &horizontal_padding,
  2517                                            NULL);
  2540                                            NULL);
  2518                 }
  2541                 }
       
  2542                 separatorRect.setHeight(option->rect.height() - 2 * gtkMenuSeparator->style->ythickness);
       
  2543                 separatorRect.setWidth(option->rect.width() - 2 * (horizontal_padding + gtkMenuSeparator->style->xthickness));
       
  2544                 separatorRect.moveCenter(option->rect.center());
  2519                 if (wide_separators)
  2545                 if (wide_separators)
  2520                     gtkPainter.paintBox( gtkMenuSeparator, "hseparator",
  2546                    gtkPainter.paintBox( gtkMenuSeparator, "hseparator",
  2521                                          option->rect.adjusted(0, 0, 0, -1), GTK_STATE_NORMAL, GTK_SHADOW_NONE, gtkMenu->style);
  2547                                         separatorRect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, gtkMenuSeparator->style);
  2522                 else
  2548                 else
  2523                     gtkPainter.paintHline( gtkMenuSeparator, "hseparator",
  2549                     gtkPainter.paintHline( gtkMenuSeparator, "hseparator",
  2524                                            menuItem->rect, GTK_STATE_NORMAL, gtkMenu->style,
  2550                                            separatorRect, GTK_STATE_NORMAL, gtkMenuSeparator->style,
  2525                                            option->rect.left() + horizontal_padding, option->rect.width() - 2*horizontal_padding, 2);
  2551                                            0, option->rect.right() - 1, 1);
  2526                 painter->restore();
  2552                 painter->restore();
  2527                 break;
  2553                 break;
  2528             }
  2554             }
  2529 
  2555 
  2530             bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
  2556             bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
  2531 
  2557 
  2532             if (selected) {
  2558             if (selected) {
  2533                 QRect rect = option->rect.adjusted(0, 0, 0, -1);
  2559                 QRect rect = option->rect;
  2534 #ifndef QT_NO_COMBOBOX
  2560 #ifndef QT_NO_COMBOBOX
  2535                 if (qobject_cast<const QComboBox*>(widget))
  2561                 if (qobject_cast<const QComboBox*>(widget))
  2536                     rect = option->rect;
  2562                     rect = option->rect;
  2537 #endif
  2563 #endif
  2538                 gtkPainter.paintBox( gtkMenuItem, "menuitem", rect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style);
  2564                 gtkPainter.paintBox( gtkMenuItem, "menuitem", rect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style);
  2554                 ignoreCheckMark = true; // Ignore the checkmarks provided by the QComboMenuDelegate
  2580                 ignoreCheckMark = true; // Ignore the checkmarks provided by the QComboMenuDelegate
  2555 
  2581 
  2556 #endif
  2582 #endif
  2557             if (!ignoreCheckMark) {
  2583             if (!ignoreCheckMark) {
  2558                 // Check
  2584                 // Check
  2559                 QRect checkRect(option->rect.left() + 7, option->rect.center().y() - checkSize/2, checkSize, checkSize);
  2585                 QRect checkRect(option->rect.left() + 7, option->rect.center().y() - checkSize/2 + 1, checkSize, checkSize);
  2560                 checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
  2586                 checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
  2561 
  2587 
  2562                 if (checkable && menuItem->icon.isNull()) {
  2588                 if (checkable && menuItem->icon.isNull()) {
  2563                     // Some themes such as aero-clone draw slightly outside the paint rect
  2589                     // Some themes such as aero-clone draw slightly outside the paint rect
  2564                     int spacing = 1; // ### Consider using gtkCheckBox : "indicator-spacing" instead
  2590                     int spacing = 1; // ### Consider using gtkCheckBox : "indicator-spacing" instead
  2678             int x, y, w, h;
  2704             int x, y, w, h;
  2679             menuitem->rect.getRect(&x, &y, &w, &h);
  2705             menuitem->rect.getRect(&x, &y, &w, &h);
  2680             int tab = menuitem->tabWidth;
  2706             int tab = menuitem->tabWidth;
  2681             int xm = windowsItemFrame + checkcol + windowsItemHMargin;
  2707             int xm = windowsItemFrame + checkcol + windowsItemHMargin;
  2682             int xpos = menuitem->rect.x() + xm + 1;
  2708             int xpos = menuitem->rect.x() + xm + 1;
  2683             QRect textRect(xpos, y + windowsItemVMargin - 1, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
  2709             QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
  2684             QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
  2710             QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
  2685             QString s = menuitem->text;
  2711             QString s = menuitem->text;
  2686 
  2712 
  2687             if (!s.isEmpty()) { // Draw text
  2713             if (!s.isEmpty()) { // Draw text
  2688                 p->save();
  2714                 p->save();
  3148 
  3174 
  3149             if (toolbutton->features & QStyleOptionToolButton::HasMenu)
  3175             if (toolbutton->features & QStyleOptionToolButton::HasMenu)
  3150                 newSize += QSize(6, 0);
  3176                 newSize += QSize(6, 0);
  3151         }
  3177         }
  3152         break;
  3178         break;
  3153 
       
  3154     case CT_MenuItem:
  3179     case CT_MenuItem:
  3155         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  3180         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  3156             int textMargin = 8;
  3181             int textMargin = 8;
  3157 
  3182 
  3158             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  3183             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  3159                 GtkWidget *gtkMenuSeparator = d->gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem"));
  3184                 GtkWidget *gtkMenuSeparator = d->gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem"));
  3160                 gboolean wide_separators;
  3185                 GtkRequisition sizeReq = {0, 0};
  3161                 gint     separator_height;
  3186                 d->gtk_widget_size_request(gtkMenuSeparator, &sizeReq);
  3162                 d->gtk_widget_style_get(gtkMenuSeparator,
  3187                 newSize = QSize(size.width(), sizeReq.height);
  3163                                        "wide-separators",    &wide_separators,
       
  3164                                        "separator-height",   &separator_height,
       
  3165                                        NULL);
       
  3166                 newSize = QSize(size.width(), wide_separators ? separator_height - 1 : 7 );
       
  3167 
       
  3168                 break;
  3188                 break;
  3169             }
  3189             }
  3170 
  3190 
  3171             GtkWidget *gtkMenuItem = d->gtkWidget(QLS("GtkMenu.GtkMenuItem"));
  3191             GtkWidget *gtkMenuItem = d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem"));
  3172             GtkStyle* style = gtkMenuItem->style;
  3192             GtkStyle* style = gtkMenuItem->style;
  3173             newSize += QSize(textMargin + style->xthickness - 1, style->ythickness - 3);
  3193 
       
  3194             // Note we get the perfect height for the default font since we
       
  3195             // set a fake text label on the gtkMenuItem
       
  3196             // But if custom fonts are used on the widget we need a minimum size
       
  3197             GtkRequisition sizeReq = {0, 0};
       
  3198             d->gtk_widget_size_request(gtkMenuItem, &sizeReq);
       
  3199             newSize.setHeight(qMax(newSize.height() - 4, sizeReq.height));
       
  3200             newSize += QSize(textMargin + style->xthickness - 1, 0);
  3174 
  3201 
  3175             // Cleanlooks assumes a check column of 20 pixels so we need to
  3202             // Cleanlooks assumes a check column of 20 pixels so we need to
  3176             // expand it a bit
  3203             // expand it a bit
  3177             gint checkSize;
  3204             gint checkSize;
  3178             d->gtk_widget_style_get(d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")), "indicator-size", &checkSize, NULL);
  3205             d->gtk_widget_style_get(gtkMenuItem, "indicator-size", &checkSize, NULL);
  3179             newSize.setHeight(qMax(newSize.height(), checkSize + 2));
       
  3180             newSize.setWidth(newSize.width() + qMax(0, checkSize - 20));
  3206             newSize.setWidth(newSize.width() + qMax(0, checkSize - 20));
  3181         }
  3207         }
  3182 
       
  3183         break;
       
  3184 
       
  3185     case CT_Menu:
       
  3186         // This is evil, but QMenu adds 1 pixel too much
       
  3187         newSize -= QSize(0, 1);
       
  3188 
  3208 
  3189         break;
  3209         break;
  3190 
  3210 
  3191     case CT_SpinBox:
  3211     case CT_SpinBox:
  3192         // QSpinBox does some nasty things that depends on CT_LineEdit
  3212         // QSpinBox does some nasty things that depends on CT_LineEdit