1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
41 #include "qgtkstyle.h"
43 #if !defined(QT_NO_STYLE_GTK)
45 #include <private/qapplication_p.h>
46 #include <QtCore/QLibrary>
47 #include <QtCore/QSettings>
48 #include <QtWidgets/QDialogButtonBox>
49 #include <QtWidgets/QStatusBar>
50 #include <QtWidgets/QLineEdit>
51 #include <QtWidgets/QWidget>
52 #include <QtWidgets/QListView>
53 #include <QtWidgets/QApplication>
54 #include <QtWidgets/QStyleOption>
55 #include <QtWidgets/QPushButton>
56 #include <QtGui/QPainter>
57 #include <QtWidgets/QMainWindow>
58 #include <QtWidgets/QToolBar>
59 #include <QtWidgets/QHeaderView>
60 #include <QtWidgets/QMenuBar>
61 #include <QtWidgets/QComboBox>
62 #include <QtWidgets/QSpinBox>
63 #include <QtWidgets/QScrollBar>
64 #include <QtWidgets/QAbstractButton>
65 #include <QtWidgets/QToolButton>
66 #include <QtWidgets/QGroupBox>
67 #include <QtWidgets/QRadioButton>
68 #include <QtWidgets/QCheckBox>
69 #include <QtWidgets/QTreeView>
70 #include <QtWidgets/QStyledItemDelegate>
71 #include <QtWidgets/QWizard>
73 #include <qpixmapcache.h>
74 #undef signals // Collides with GTK stymbols
75 #include <private/qgtkpainter_p.h>
76 #include <private/qstylehelper_p.h>
77 #include <private/qgtkstyle_p.h>
81 static void qt_gtk_draw_mdibutton(QPainter *painter, const QStyleOptionTitleBar *option, const QRect &tmp, bool hover, bool sunken)
84 dark.setHsv(option->palette.button().color().hue(),
85 qMin(255, (int)(option->palette.button().color().saturation()*1.9)),
86 qMin(255, (int)(option->palette.button().color().value()*0.7)));
88 QColor highlight = option->palette.highlight().color();
90 bool active = (option->titleBarState & QStyle::State_Active);
91 QColor titleBarHighlight(255, 255, 255, 60);
94 painter->fillRect(tmp.adjusted(1, 1, -1, -1), option->palette.highlight().color().darker(120));
96 painter->fillRect(tmp.adjusted(1, 1, -1, -1), QColor(255, 255, 255, 20));
98 QColor mdiButtonGradientStartColor;
99 QColor mdiButtonGradientStopColor;
101 mdiButtonGradientStartColor = QColor(0, 0, 0, 40);
102 mdiButtonGradientStopColor = QColor(255, 255, 255, 60);
105 titleBarHighlight = highlight.darker(130);
107 QLinearGradient gradient(tmp.center().x(), tmp.top(), tmp.center().x(), tmp.bottom());
108 gradient.setColorAt(0, mdiButtonGradientStartColor);
109 gradient.setColorAt(1, mdiButtonGradientStopColor);
110 QColor mdiButtonBorderColor(active ? option->palette.highlight().color().darker(180): dark.darker(110));
112 painter->setPen(QPen(mdiButtonBorderColor, 1));
113 const QLine lines[4] = {
114 QLine(tmp.left() + 2, tmp.top(), tmp.right() - 2, tmp.top()),
115 QLine(tmp.left() + 2, tmp.bottom(), tmp.right() - 2, tmp.bottom()),
116 QLine(tmp.left(), tmp.top() + 2, tmp.left(), tmp.bottom() - 2),
117 QLine(tmp.right(), tmp.top() + 2, tmp.right(), tmp.bottom() - 2)
119 painter->drawLines(lines, 4);
120 const QPoint points[4] = {
121 QPoint(tmp.left() + 1, tmp.top() + 1),
122 QPoint(tmp.right() - 1, tmp.top() + 1),
123 QPoint(tmp.left() + 1, tmp.bottom() - 1),
124 QPoint(tmp.right() - 1, tmp.bottom() - 1)
126 painter->drawPoints(points, 4);
128 painter->setPen(titleBarHighlight);
129 painter->drawLine(tmp.left() + 2, tmp.top() + 1, tmp.right() - 2, tmp.top() + 1);
130 painter->drawLine(tmp.left() + 1, tmp.top() + 2, tmp.left() + 1, tmp.bottom() - 2);
132 painter->setPen(QPen(gradient, 1));
133 painter->drawLine(tmp.right() + 1, tmp.top() + 2, tmp.right() + 1, tmp.bottom() - 2);
134 painter->drawPoint(tmp.right() , tmp.top() + 1);
136 painter->drawLine(tmp.left() + 2, tmp.bottom() + 1, tmp.right() - 2, tmp.bottom() + 1);
137 painter->drawPoint(tmp.left() + 1, tmp.bottom());
138 painter->drawPoint(tmp.right() - 1, tmp.bottom());
139 painter->drawPoint(tmp.right() , tmp.bottom() - 1);
142 static const char * const dock_widget_close_xpm[] =
165 static const char * const dock_widget_restore_xpm[] =
188 static const char * const qt_titlebar_context_help[] = {
204 static const char * const qt_scrollbar_button_arrow_up[] = {
213 static const char * const qt_scrollbar_button_arrow_down[] = {
222 static const int groupBoxBottomMargin = 2; // space below the groupbox
223 static const int groupBoxTitleMargin = 6; // space between contents and title
224 static const int groupBoxTopMargin = 2;
227 Returns the configuration string for \a value.
228 Returns \a fallback if \a value is not found.
230 QString QGtkStyle::getGConfString(const QString &value, const QString &fallback)
232 return QGtkStylePrivate::getGConfString(value, fallback);
236 Returns the configuration boolean for \a key.
237 Returns \a fallback if \a key is not found.
239 bool QGtkStyle::getGConfBool(const QString &key, bool fallback)
241 return QGtkStylePrivate::getGConfBool(key, fallback);
244 static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50)
246 const int maxFactor = 100;
248 tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
249 tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
250 tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
254 static GdkColor fromQColor(const QColor &color)
257 retval.red = color.red() * 255;
258 retval.green = color.green() * 255;
259 retval.blue = color.blue() * 255;
265 \brief The QGtkStyle class provides a widget style rendered by GTK+
270 The QGtkStyle style provides a look and feel that integrates well
271 into GTK-based desktop environments such as the XFCe and GNOME.
273 It does this by making use of the GTK+ theme engine, ensuring
274 that Qt applications look and feel native on these platforms.
276 Note: The style requires GTK+ version 2.10 or later.
277 The Qt3-based "Qt" GTK+ theme engine will not work with QGtkStyle.
279 \sa {Cleanlooks Style Widget Gallery}, QWindowsXPStyle, QMacStyle, QWindowsStyle,
280 QPlastiqueStyle, QCleanlooksStyle
284 Constructs a QGtkStyle object.
286 QGtkStyle::QGtkStyle()
287 : QWindowsStyle(*new QGtkStylePrivate)
296 Constructs a QGtkStyle object.
298 QGtkStyle::QGtkStyle(QGtkStylePrivate &dd)
307 Destroys the QGtkStyle object.
309 QGtkStyle::~QGtkStyle()
316 QPalette QGtkStyle::standardPalette() const
318 Q_D(const QGtkStyle);
320 QPalette palette = QWindowsStyle::standardPalette();
321 if (d->isThemeAvailable()) {
322 GtkStyle *style = d->gtkStyle();
323 GtkWidget *gtkButton = d->gtkWidget("GtkButton");
324 GtkWidget *gtkEntry = d->getTextColorWidget();
325 GdkColor gdkBg, gdkBase, gdkText, gdkForeground, gdkSbg, gdkSfg, gdkaSbg, gdkaSfg;
326 QColor bg, base, text, fg, highlight, highlightText, inactiveHighlight, inactiveHighlightedTExt;
327 gdkBg = style->bg[GTK_STATE_NORMAL];
328 gdkForeground = gtkButton->style->fg[GTK_STATE_NORMAL];
330 // Our base and selected color is primarily used for text
331 // so we assume a gtkEntry will have the most correct value
332 gdkBase = gtkEntry->style->base[GTK_STATE_NORMAL];
333 gdkText = gtkEntry->style->text[GTK_STATE_NORMAL];
334 gdkSbg = gtkEntry->style->base[GTK_STATE_SELECTED];
335 gdkSfg = gtkEntry->style->text[GTK_STATE_SELECTED];
337 // The ACTIVE base color is really used for inactive windows
338 gdkaSbg = gtkEntry->style->base[GTK_STATE_ACTIVE];
339 gdkaSfg = gtkEntry->style->text[GTK_STATE_ACTIVE];
341 bg = QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8);
342 text = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
343 fg = QColor(gdkForeground.red>>8, gdkForeground.green>>8, gdkForeground.blue>>8);
344 base = QColor(gdkBase.red>>8, gdkBase.green>>8, gdkBase.blue>>8);
345 highlight = QColor(gdkSbg.red>>8, gdkSbg.green>>8, gdkSbg.blue>>8);
346 highlightText = QColor(gdkSfg.red>>8, gdkSfg.green>>8, gdkSfg.blue>>8);
347 inactiveHighlight = QColor(gdkaSbg.red>>8, gdkaSbg.green>>8, gdkaSbg.blue>>8);
348 inactiveHighlightedTExt = QColor(gdkaSfg.red>>8, gdkaSfg.green>>8, gdkaSfg.blue>>8);
350 palette.setColor(QPalette::HighlightedText, highlightText);
353 palette.setColor(QPalette::Light, bg.lighter(125));
354 palette.setColor(QPalette::Shadow, bg.darker(130));
355 palette.setColor(QPalette::Dark, bg.darker(120));
356 palette.setColor(QPalette::Text, text);
357 palette.setColor(QPalette::WindowText, fg);
358 palette.setColor(QPalette::ButtonText, fg);
359 palette.setColor(QPalette::Base, base);
361 QColor alternateRowColor = palette.base().color().lighter(93); // ref gtkstyle.c draw_flat_box
362 GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
363 GdkColor *gtkAltBase = NULL;
364 d->gtk_widget_style_get(gtkTreeView, "odd-row-color", >kAltBase, NULL);
366 alternateRowColor = QColor(gtkAltBase->red>>8, gtkAltBase->green>>8, gtkAltBase->blue>>8);
367 d->gdk_color_free(gtkAltBase);
369 palette.setColor(QPalette::AlternateBase, alternateRowColor);
371 palette.setColor(QPalette::Window, bg);
372 palette.setColor(QPalette::Button, bg);
373 palette.setColor(QPalette::Background, bg);
374 QColor disabled((fg.red() + bg.red()) / 2,
375 (fg.green() + bg.green())/ 2,
376 (fg.blue() + bg.blue()) / 2);
377 palette.setColor(QPalette::Disabled, QPalette::Text, disabled);
378 palette.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
379 palette.setColor(QPalette::Disabled, QPalette::Foreground, disabled);
380 palette.setColor(QPalette::Disabled, QPalette::ButtonText, disabled);
381 palette.setColor(QPalette::Highlight, highlight);
382 // calculate disabled colors by removing saturation
383 highlight.setHsv(highlight.hue(), 0, highlight.value(), highlight.alpha());
384 highlightText.setHsv(highlightText.hue(), 0, highlightText.value(), highlightText.alpha());
385 palette.setColor(QPalette::Disabled, QPalette::Highlight, highlight);
386 palette.setColor(QPalette::Disabled, QPalette::HighlightedText, highlightText);
388 palette.setColor(QPalette::Inactive, QPalette::HighlightedText, inactiveHighlightedTExt);
389 palette.setColor(QPalette::Inactive, QPalette::Highlight, inactiveHighlight);
391 style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow",
392 d->gtk_window_get_type());
394 gdkText = style->fg[GTK_STATE_NORMAL];
395 text = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
396 palette.setColor(QPalette::ToolTipText, text);
405 void QGtkStyle::polish(QPalette &palette)
409 if (!d->isThemeAvailable())
410 QWindowsStyle::polish(palette);
412 palette = palette.resolve(standardPalette());
418 void QGtkStyle::polish(QApplication *app)
422 QWindowsStyle::polish(app);
423 // Custom fonts and palettes with QtConfig are intentionally
424 // not supported as these should be entirely determined by
425 // current Gtk settings
426 if (app->desktopSettingsAware() && d->isThemeAvailable()) {
427 QApplicationPrivate::setSystemPalette(standardPalette());
428 QApplicationPrivate::setSystemFont(d->getThemeFont());
429 d->applyCustomPaletteHash();
430 if (!d->isKDE4Session()) {
431 #ifndef QT_NO_FILEDIALOG
432 qt_filedialog_open_filename_hook = &QGtkStylePrivate::openFilename;
433 qt_filedialog_save_filename_hook = &QGtkStylePrivate::saveFilename;
434 qt_filedialog_open_filenames_hook = &QGtkStylePrivate::openFilenames;
435 qt_filedialog_existing_directory_hook = &QGtkStylePrivate::openDirectory;
437 qApp->installEventFilter(&d->filter);
445 void QGtkStyle::unpolish(QApplication *app)
449 QWindowsStyle::unpolish(app);
450 QPixmapCache::clear();
452 if (app->desktopSettingsAware() && d->isThemeAvailable()
453 && !d->isKDE4Session()) {
454 #ifndef QT_NO_FILEDIALOG
455 qt_filedialog_open_filename_hook = 0;
456 qt_filedialog_save_filename_hook = 0;
457 qt_filedialog_open_filenames_hook = 0;
458 qt_filedialog_existing_directory_hook = 0;
460 qApp->removeEventFilter(&d->filter);
468 void QGtkStyle::polish(QWidget *widget)
472 QWindowsStyle::polish(widget);
473 if (!d->isThemeAvailable())
475 if (qobject_cast<QAbstractButton*>(widget)
476 || qobject_cast<QToolButton*>(widget)
477 || qobject_cast<QComboBox*>(widget)
478 || qobject_cast<QGroupBox*>(widget)
479 || qobject_cast<QScrollBar*>(widget)
480 || qobject_cast<QSlider*>(widget)
481 || qobject_cast<QAbstractSpinBox*>(widget)
482 || qobject_cast<QSpinBox*>(widget)
483 || qobject_cast<QHeaderView*>(widget))
484 widget->setAttribute(Qt::WA_Hover);
485 #ifndef QT_NO_TREEVIEW
486 else if (QTreeView *tree = qobject_cast<QTreeView *> (widget))
487 tree->viewport()->setAttribute(Qt::WA_Hover);
494 void QGtkStyle::unpolish(QWidget *widget)
496 QWindowsStyle::unpolish(widget);
502 int QGtkStyle::pixelMetric(PixelMetric metric,
503 const QStyleOption *option,
504 const QWidget *widget) const
506 Q_D(const QGtkStyle);
508 if (!d->isThemeAvailable())
509 return QWindowsStyle::pixelMetric(metric, option, widget);
512 case PM_DefaultFrameWidth:
513 if (qobject_cast<const QFrame*>(widget)) {
514 if (GtkStyle *style =
515 d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(),
516 "*.GtkScrolledWindow",
517 "*.GtkScrolledWindow",
518 d->gtk_window_get_type()))
519 return qMax(style->xthickness, style->ythickness);
523 case PM_MenuButtonIndicator:
526 case PM_TabBarBaseOverlap:
529 case PM_ToolBarSeparatorExtent:
532 case PM_ToolBarFrameWidth:
535 case PM_ToolBarItemSpacing:
538 case PM_ButtonShiftHorizontal: {
539 GtkWidget *gtkButton = d->gtkWidget("GtkButton");
540 guint horizontal_shift;
541 d->gtk_widget_style_get(gtkButton, "child-displacement-x", &horizontal_shift, NULL);
542 return horizontal_shift;
545 case PM_ButtonShiftVertical: {
546 GtkWidget *gtkButton = d->gtkWidget("GtkButton");
547 guint vertical_shift;
548 d->gtk_widget_style_get(gtkButton, "child-displacement-y", &vertical_shift, NULL);
549 return vertical_shift;
552 case PM_MenuBarPanelWidth:
555 case PM_MenuPanelWidth: {
556 GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
557 guint horizontal_padding = 0;
558 // horizontal-padding is used by Maemo to get thicker borders
559 if (!d->gtk_check_version(2, 10, 0))
560 d->gtk_widget_style_get(gtkMenu, "horizontal-padding", &horizontal_padding, NULL);
561 int padding = qMax<int>(gtkMenu->style->xthickness, horizontal_padding);
565 case PM_ButtonIconSize: {
567 GtkSettings *settings = d->gtk_settings_get_default();
568 gchararray icon_sizes;
569 g_object_get(settings, "gtk-icon-sizes", &icon_sizes, NULL);
570 QStringList values = QString(QLS(icon_sizes)).split(QLatin1Char(':'));
572 QChar splitChar(QLatin1Char(','));
573 foreach (const QString &value, values) {
574 if (value.startsWith(QLS("gtk-button="))) {
575 QString iconSize = value.right(value.size() - 11);
577 if (iconSize.contains(splitChar))
578 retVal = iconSize.split(splitChar)[0].toInt();
590 case PM_DockWidgetTitleMargin:
593 case PM_DockWidgetTitleBarButtonMargin:
596 case PM_TabBarTabVSpace:
599 case PM_TabBarTabHSpace:
602 case PM_TabBarTabShiftVertical:
605 case PM_ToolBarHandleExtent:
608 case PM_SplitterWidth:
611 case PM_SliderThickness:
612 case PM_SliderControlThickness: {
613 GtkWidget *gtkScale = d->gtkWidget("GtkHScale");
615 d->gtk_widget_style_get(gtkScale, "slider-width", &val, NULL);
616 if (metric == PM_SliderControlThickness)
617 return val + 2*gtkScale->style->ythickness;
621 case PM_ScrollBarExtent: {
624 GtkWidget *hScrollbar = d->gtkWidget("GtkHScrollbar");
625 d->gtk_widget_style_get(hScrollbar,
626 "trough-border", &trough_border,
627 "slider-width", &sliderLength,
629 return sliderLength + trough_border*2;
632 case PM_ScrollBarSliderMin:
635 case PM_SliderLength:
637 d->gtk_widget_style_get(d->gtkWidget("GtkHScale"), "slider-length", &val, NULL);
640 case PM_ExclusiveIndicatorWidth:
641 case PM_ExclusiveIndicatorHeight:
642 case PM_IndicatorWidth:
643 case PM_IndicatorHeight: {
644 GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
646 d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, "indicator-size", &size, NULL);
647 return size + 2 * spacing;
650 case PM_MenuBarVMargin: {
651 GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
652 return qMax(0, gtkMenubar->style->ythickness);
654 case PM_ScrollView_ScrollBarSpacing:
657 GtkWidget *gtkScrollWindow = d->gtkWidget("GtkScrolledWindow");
658 Q_ASSERT(gtkScrollWindow);
659 d->gtk_widget_style_get(gtkScrollWindow, "scrollbar-spacing", &spacing, NULL);
662 case PM_SubMenuOverlap: {
664 GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
665 d->gtk_widget_style_get(gtkMenu, "horizontal-offset", &offset, NULL);
668 case PM_ToolTipLabelFrameWidth:
670 case PM_ButtonDefaultIndicator:
672 case PM_ListViewIconSize:
674 case PM_DialogButtonsSeparator:
676 case PM_TitleBarHeight:
678 case PM_SpinBoxFrameWidth:
680 case PM_MenuBarItemSpacing:
682 case PM_MenuBarHMargin:
684 case PM_ToolBarItemMargin:
686 case PM_SmallIconSize:
688 case PM_MaximumDragDistance:
690 case PM_TabCloseIndicatorWidth:
691 case PM_TabCloseIndicatorHeight:
694 return QWindowsStyle::pixelMetric(metric, option, widget);
701 int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
703 QStyleHintReturn *returnData = 0) const
705 Q_D(const QGtkStyle);
707 if (!d->isThemeAvailable())
708 return QWindowsStyle::styleHint(hint, option, widget, returnData);
711 case SH_ScrollBar_MiddleClickAbsolutePosition:
713 case SH_Menu_AllowActiveAndDisabled:
715 case SH_MainWindow_SpaceBelowMenuBar:
717 case SH_MenuBar_MouseTracking:
719 case SH_TitleBar_AutoRaise:
721 case SH_TitleBar_NoBorder:
723 case SH_ItemView_ShowDecorationSelected:
725 case SH_Table_GridLineColor:
727 return option->palette.background().color().darker(120).rgb();
729 case SH_WindowFrame_Mask:
730 if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask *>(returnData)) {
731 //left rounded corner
732 mask->region = option->rect;
733 mask->region -= QRect(option->rect.left(), option->rect.top(), 5, 1);
734 mask->region -= QRect(option->rect.left(), option->rect.top() + 1, 3, 1);
735 mask->region -= QRect(option->rect.left(), option->rect.top() + 2, 2, 1);
736 mask->region -= QRect(option->rect.left(), option->rect.top() + 3, 1, 2);
738 //right rounded corner
739 mask->region -= QRect(option->rect.right() - 4, option->rect.top(), 5, 1);
740 mask->region -= QRect(option->rect.right() - 2, option->rect.top() + 1, 3, 1);
741 mask->region -= QRect(option->rect.right() - 1, option->rect.top() + 2, 2, 1);
742 mask->region -= QRect(option->rect.right() , option->rect.top() + 3, 1, 2);
744 return QWindowsStyle::styleHint(hint, option, widget, returnData);
745 case SH_MessageBox_TextInteractionFlags:
746 return Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse;
747 case SH_MessageBox_CenterButtons:
750 return QWizard::ClassicStyle;
751 case SH_ItemView_ArrowKeysNavigateIntoChildren:
753 case SH_DialogButtonLayout: {
754 int ret = QDialogButtonBox::GnomeLayout;
755 gboolean alternateOrder = 0;
756 GtkSettings *settings = d->gtk_settings_get_default();
757 g_object_get(settings, "gtk-alternative-button-order", &alternateOrder, NULL);
760 ret = QDialogButtonBox::WinLayout;
766 case SH_ToolButtonStyle:
768 if (d->isKDE4Session())
769 return QWindowsStyle::styleHint(hint, option, widget, returnData);
770 GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
771 GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS;
772 g_object_get(gtkToolbar, "toolbar-style", &toolbar_style, NULL);
773 switch (toolbar_style) {
774 case GTK_TOOLBAR_TEXT:
775 return Qt::ToolButtonTextOnly;
776 case GTK_TOOLBAR_BOTH:
777 return Qt::ToolButtonTextUnderIcon;
778 case GTK_TOOLBAR_BOTH_HORIZ:
779 return Qt::ToolButtonTextBesideIcon;
780 case GTK_TOOLBAR_ICONS:
782 return Qt::ToolButtonIconOnly;
786 case SH_SpinControls_DisableOnBounds:
789 case SH_DitherDisabledText:
792 case SH_ComboBox_Popup: {
793 GtkWidget *gtkComboBox = d->gtkWidget("GtkComboBox");
794 gboolean appears_as_list;
795 d->gtk_widget_style_get((GtkWidget*)gtkComboBox, "appears-as-list", &appears_as_list, NULL);
796 return appears_as_list ? 0 : 1;
799 case SH_MenuBar_AltKeyNavigation:
802 case SH_EtchDisabledText:
805 case SH_Menu_SubMenuPopupDelay: {
807 GtkSettings *settings = d->gtk_settings_get_default();
808 g_object_get(settings, "gtk-menu-popup-delay", &delay, NULL);
812 case SH_ScrollView_FrameOnlyAroundContents: {
813 gboolean scrollbars_within_bevel = false;
814 if (widget && widget->isWindow())
815 scrollbars_within_bevel = true;
816 else if (!d->gtk_check_version(2, 12, 0)) {
817 GtkWidget *gtkScrollWindow = d->gtkWidget("GtkScrolledWindow");
818 d->gtk_widget_style_get(gtkScrollWindow, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
820 return !scrollbars_within_bevel;
823 case SH_DialogButtonBox_ButtonsHaveIcons: {
824 static bool buttonsHaveIcons = d->getGConfBool(QLS("/desktop/gnome/interface/buttons_have_icons"));
825 return buttonsHaveIcons;
828 case SH_UnderlineShortcut: {
829 gboolean underlineShortcut = true;
830 if (!d->gtk_check_version(2, 12, 0)) {
831 GtkSettings *settings = d->gtk_settings_get_default();
832 g_object_get(settings, "gtk-enable-mnemonics", &underlineShortcut, NULL);
834 return underlineShortcut;
840 return QWindowsStyle::styleHint(hint, option, widget, returnData);
846 void QGtkStyle::drawPrimitive(PrimitiveElement element,
847 const QStyleOption *option,
849 const QWidget *widget) const
851 Q_D(const QGtkStyle);
853 if (!d->isThemeAvailable()) {
854 QWindowsStyle::drawPrimitive(element, option, painter, widget);
858 GtkStyle* style = d->gtkStyle();
859 QGtkPainter gtkPainter(painter);
863 if (widget && widget->inherits("QComboBoxPrivateContainer")){
864 QStyleOption copy = *option;
865 copy.state |= State_Raised;
866 proxy()->drawPrimitive(PE_PanelMenu, ©, painter, widget);
869 // Drawing the entire itemview frame is very expensive, especially on the native X11 engine
870 // Instead we cheat a bit and draw a border image without the center part, hence only scaling
871 // thin rectangular images
872 const int pmSize = 64;
873 const int border = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
874 const QString pmKey = QLatin1String("windowframe") % HexString<uint>(option->state);
877 QRect pmRect(QPoint(0,0), QSize(pmSize, pmSize));
879 // Only draw through style once
880 if (!QPixmapCache::find(pmKey, pixmap)) {
881 pixmap = QPixmap(pmSize, pmSize);
882 pixmap.fill(Qt::transparent);
883 QPainter pmPainter(&pixmap);
884 QGtkPainter gtkFramePainter(&pmPainter);
885 gtkFramePainter.setUsePixmapCache(false); // Don't cache twice
887 GtkShadowType shadow_type = GTK_SHADOW_NONE;
888 if (option->state & State_Sunken)
889 shadow_type = GTK_SHADOW_IN;
890 else if (option->state & State_Raised)
891 shadow_type = GTK_SHADOW_OUT;
893 GtkStyle *style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(),
894 "*.GtkScrolledWindow", "*.GtkScrolledWindow", d->gtk_window_get_type());
896 gtkFramePainter.paintShadow(d->gtkWidget("GtkFrame"), "viewport", pmRect,
897 option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
899 QPixmapCache::insert(pmKey, pixmap);
902 QRect rect = option->rect;
903 const int rw = rect.width() - border;
904 const int rh = rect.height() - border;
905 const int pw = pmRect.width() - border;
906 const int ph = pmRect.height() - border;
909 painter->drawPixmap(rect.adjusted(border, 0, -border, -rh), pixmap, pmRect.adjusted(border, 0, -border,-ph));
910 painter->drawPixmap(rect.adjusted(border, rh, -border, 0), pixmap, pmRect.adjusted(border, ph,-border,0));
911 painter->drawPixmap(rect.adjusted(0, border, -rw, -border), pixmap, pmRect.adjusted(0, border, -pw, -border));
912 painter->drawPixmap(rect.adjusted(rw, border, 0, -border), pixmap, pmRect.adjusted(pw, border, 0, -border));
915 painter->drawPixmap(rect.adjusted(0, 0, -rw, -rh), pixmap, pmRect.adjusted(0, 0, -pw,-ph));
916 painter->drawPixmap(rect.adjusted(rw, 0, 0, -rh), pixmap, pmRect.adjusted(pw, 0, 0,-ph));
917 painter->drawPixmap(rect.adjusted(0, rh, -rw, 0), pixmap, pmRect.adjusted(0, ph, -pw,0));
918 painter->drawPixmap(rect.adjusted(rw, rh, 0, 0), pixmap, pmRect.adjusted(pw, ph, 0,0));
924 QRect rect= option->rect;
925 painter->setPen(QPen(option->palette.dark().color().darker(150), 0));
926 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
927 painter->setPen(QPen(option->palette.light(), 0));
928 painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
929 QPoint(rect.left() + 1, rect.bottom() - 1));
930 painter->setPen(QPen(option->palette.background().color().darker(120), 0));
931 painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1),
932 QPoint(rect.right() - 2, rect.bottom() - 1));
933 painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1),
934 QPoint(rect.right() - 1, rect.bottom() - 1));
939 case PE_PanelTipLabel: {
940 GtkWidget *gtkWindow = d->gtkWidget("GtkWindow"); // The Murrine Engine currently assumes a widget is passed
941 style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow",
942 d->gtk_window_get_type());
943 gtkPainter.paintFlatBox(gtkWindow, "tooltip", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, style);
947 case PE_PanelStatusBar: {
948 if (widget && widget->testAttribute(Qt::WA_SetPalette) &&
949 option->palette.resolve() & (1 << QPalette::Window)) {
950 // Respect custom palette
951 painter->fillRect(option->rect, option->palette.window());
954 GtkShadowType shadow_type;
955 GtkWidget *gtkStatusbarFrame = d->gtkWidget("GtkStatusbar.GtkFrame");
956 d->gtk_widget_style_get(d->gtk_widget_get_parent(gtkStatusbarFrame), "shadow-type", &shadow_type, NULL);
957 gtkPainter.paintShadow(gtkStatusbarFrame, "frame", option->rect, GTK_STATE_NORMAL,
958 shadow_type, gtkStatusbarFrame->style);
962 case PE_IndicatorHeaderArrow:
963 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
964 GtkWidget *gtkTreeHeader = d->gtkWidget("GtkTreeView.GtkButton");
965 GtkStateType state = gtkPainter.gtkState(option);
966 style = gtkTreeHeader->style;
967 GtkArrowType type = GTK_ARROW_UP;
968 // This sorting indicator inversion is intentional, and follows the GNOME HIG.
969 // See http://library.gnome.org/devel/hig-book/stable/controls-lists.html.en#controls-lists-sortable
970 if (header->sortIndicator & QStyleOptionHeader::SortUp)
972 else if (header->sortIndicator & QStyleOptionHeader::SortDown)
973 type = GTK_ARROW_DOWN;
975 gtkPainter.paintArrow(gtkTreeHeader, "button", option->rect.adjusted(1, 1, -1, -1), type, state,
976 GTK_SHADOW_NONE, false, style);
980 case PE_FrameDefaultButton: // fall through
981 case PE_FrameFocusRect:
982 if ((widget && qobject_cast<const QAbstractItemView*>(widget))) {
983 if (option->state & State_KeyboardFocusChange)
984 QWindowsStyle::drawPrimitive(element, option, painter, widget);
986 // ### this mess should move to subcontrolrect
987 QRect frameRect = option->rect.adjusted(1, 1, -2, -2);
988 if ( qobject_cast<const QTabBar*>(widget)) {
989 GtkWidget *gtkNotebook = d->gtkWidget("GtkNotebook");
990 style = gtkPainter.getStyle(gtkNotebook);
991 gtkPainter.paintFocus(gtkNotebook, "tab", frameRect.adjusted(-1, 1, 1, 1), GTK_STATE_ACTIVE, style);
993 GtkWidget *gtkRadioButton = d->gtkWidget("GtkRadioButton");
994 gtkPainter.paintFocus(gtkRadioButton, "radiobutton", frameRect, GTK_STATE_ACTIVE, style);
999 case PE_IndicatorBranch:
1000 if (option->state & State_Children) {
1001 QRect rect = option->rect;
1002 rect = QRect(0, 0, 12, 12);
1003 rect.moveCenter(option->rect.center());
1004 rect.translate(2, 0);
1005 GtkExpanderStyle openState = GTK_EXPANDER_EXPANDED;
1006 GtkExpanderStyle closedState = GTK_EXPANDER_COLLAPSED;
1007 GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
1009 GtkStateType state = GTK_STATE_NORMAL;
1010 if (!(option->state & State_Enabled))
1011 state = GTK_STATE_INSENSITIVE;
1012 else if (option->state & State_MouseOver)
1013 state = GTK_STATE_PRELIGHT;
1015 gtkPainter.paintExpander(gtkTreeView, "treeview", rect, state,
1016 option->state & State_Open ? openState : closedState , gtkTreeView->style);
1020 case PE_PanelItemViewRow:
1021 // This primitive is only used to draw selection behind selected expander arrows.
1022 // We try not to decorate the tree branch background unless you inherit from StyledItemDelegate
1023 // The reason for this is that a lot of code that relies on custom item delegates will look odd having
1024 // a gradient on the branch but a flat shaded color on the item itself.
1025 QCommonStyle::drawPrimitive(element, option, painter, widget);
1026 if (!option->state & State_Selected) {
1029 if (const QAbstractItemView *view = qobject_cast<const QAbstractItemView*>(widget)) {
1030 if (!qobject_cast<QStyledItemDelegate*>(view->itemDelegate()))
1035 case PE_PanelItemViewItem:
1036 if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(option)) {
1037 uint resolve_mask = vopt->palette.resolve();
1038 if (vopt->backgroundBrush.style() != Qt::NoBrush
1039 || (resolve_mask & (1 << QPalette::Base)))
1041 QPointF oldBO = painter->brushOrigin();
1042 painter->setBrushOrigin(vopt->rect.topLeft());
1043 painter->fillRect(vopt->rect, vopt->backgroundBrush);
1044 painter->setBrushOrigin(oldBO);
1045 if (!(option->state & State_Selected))
1048 if (GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView")) {
1049 const char *detail = "cell_even_ruled";
1050 if (vopt && vopt->features & QStyleOptionViewItem::Alternate)
1051 detail = "cell_odd_ruled";
1052 bool isActive = option->state & State_Active;
1055 // Required for active/non-active window appearance
1057 GTK_WIDGET_SET_FLAGS(gtkTreeView, GTK_HAS_FOCUS);
1059 bool isEnabled = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled));
1060 gtkPainter.paintFlatBox(gtkTreeView, detail, option->rect,
1061 option->state & State_Selected ? GTK_STATE_SELECTED :
1062 isEnabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
1063 GTK_SHADOW_OUT, gtkTreeView->style, key);
1065 GTK_WIDGET_UNSET_FLAGS(gtkTreeView, GTK_HAS_FOCUS);
1069 case PE_IndicatorToolBarSeparator:
1071 const int margin = 6;
1072 GtkWidget *gtkSeparator = d->gtkWidget("GtkToolbar.GtkSeparatorToolItem");
1073 if (option->state & State_Horizontal) {
1074 const int offset = option->rect.width()/2;
1075 QRect rect = option->rect.adjusted(offset, margin, 0, -margin);
1076 painter->setPen(QPen(option->palette.background().color().darker(110)));
1077 gtkPainter.paintVline( gtkSeparator, "vseparator",
1078 rect, GTK_STATE_NORMAL, gtkSeparator->style,
1079 0, rect.height(), 0);
1080 } else { //Draw vertical separator
1081 const int offset = option->rect.height()/2;
1082 QRect rect = option->rect.adjusted(margin, offset, -margin, 0);
1083 painter->setPen(QPen(option->palette.background().color().darker(110)));
1084 gtkPainter.paintHline( gtkSeparator, "hseparator",
1085 rect, GTK_STATE_NORMAL, gtkSeparator->style,
1086 0, rect.width(), 0);
1091 case PE_IndicatorToolBarHandle: {
1092 GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
1093 GtkShadowType shadow_type;
1094 d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
1095 //Note when the toolbar is horizontal, the handle is vertical
1096 painter->setClipRect(option->rect);
1097 gtkPainter.paintHandle(gtkToolbar, "toolbar", option->rect.adjusted(-1, -1 ,0 ,1),
1098 GTK_STATE_NORMAL, shadow_type, !(option->state & State_Horizontal) ?
1099 GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, gtkToolbar->style);
1103 case PE_IndicatorArrowUp:
1104 case PE_IndicatorArrowDown:
1105 case PE_IndicatorArrowLeft:
1106 case PE_IndicatorArrowRight: {
1109 GtkArrowType type = GTK_ARROW_UP;
1113 case PE_IndicatorArrowDown:
1114 type = GTK_ARROW_DOWN;
1117 case PE_IndicatorArrowLeft:
1118 type = GTK_ARROW_LEFT;
1121 case PE_IndicatorArrowRight:
1122 type = GTK_ARROW_RIGHT;
1128 int size = qMin(option->rect.height(), option->rect.width());
1129 int border = (size > 9) ? (size/4) : 0; //Allow small arrows to have exact dimensions
1130 int bsx = 0, bsy = 0;
1131 if (option->state & State_Sunken) {
1132 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal);
1133 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical);
1135 QRect arrowRect = option->rect.adjusted(border + bsx, border + bsy, -border + bsx, -border + bsy);
1136 GtkShadowType shadow = option->state & State_Sunken ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
1137 GtkStateType state = gtkPainter.gtkState(option);
1139 QColor arrowColor = option->palette.buttonText().color();
1140 GtkWidget *gtkArrow = d->gtkWidget("GtkArrow");
1141 GdkColor color = fromQColor(arrowColor);
1142 d->gtk_widget_modify_fg (gtkArrow, state, &color);
1143 gtkPainter.paintArrow(gtkArrow, "button", arrowRect,
1144 type, state, shadow, false, gtkArrow->style,
1145 QString::number(arrowColor.rgba(), 16));
1146 // Passing NULL will revert the color change
1147 d->gtk_widget_modify_fg (gtkArrow, state, NULL);
1151 case PE_FrameGroupBox:
1152 // Do nothing here, the GNOME groupboxes are flat
1155 case PE_PanelMenu: {
1156 GtkWidget *gtkMenu = d->gtkWidget("GtkMenu");
1157 gtkPainter.setAlphaSupport(false); // Note, alpha disabled for performance reasons
1158 gtkPainter.paintBox(gtkMenu, "menu", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, gtkMenu->style, QString());
1163 //This is actually done by PE_Widget due to a clipping issue
1164 //Otherwise Menu items will not be able to span the entire menu width
1166 // This is only used by floating tool bars
1167 if (qobject_cast<const QToolBar *>(widget)) {
1168 GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
1169 gtkPainter.paintBox( gtkMenubar, "toolbar", option->rect,
1170 GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
1171 gtkPainter.paintBox( gtkMenubar, "menu", option->rect,
1172 GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
1176 case PE_FrameLineEdit: {
1177 GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
1180 gboolean interior_focus;
1181 gint focus_line_width;
1182 QRect rect = option->rect;
1183 d->gtk_widget_style_get(gtkEntry,
1184 "interior-focus", &interior_focus,
1185 "focus-line-width", &focus_line_width, NULL);
1187 // See https://bugzilla.mozilla.org/show_bug.cgi?id=405421 for info about this hack
1188 g_object_set_data(G_OBJECT(gtkEntry), "transparent-bg-hint", GINT_TO_POINTER(true));
1190 if (!interior_focus && option->state & State_HasFocus)
1191 rect.adjust(focus_line_width, focus_line_width, -focus_line_width, -focus_line_width);
1193 if (option->state & State_HasFocus)
1194 GTK_WIDGET_SET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1195 gtkPainter.paintShadow(gtkEntry, "entry", rect, option->state & State_Enabled ?
1196 GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
1197 GTK_SHADOW_IN, gtkEntry->style,
1198 option->state & State_HasFocus ? QLS("focus") : QString());
1199 if (!interior_focus && option->state & State_HasFocus)
1200 gtkPainter.paintShadow(gtkEntry, "entry", option->rect, option->state & State_Enabled ?
1201 GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
1202 GTK_SHADOW_IN, gtkEntry->style, QLS("GtkEntryShadowIn"));
1204 if (option->state & State_HasFocus)
1205 GTK_WIDGET_UNSET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1209 case PE_PanelLineEdit:
1210 if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
1211 GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
1212 if (panel->lineWidth > 0)
1213 proxy()->drawPrimitive(PE_FrameLineEdit, option, painter, widget);
1214 uint resolve_mask = option->palette.resolve();
1215 QRect textRect = option->rect.adjusted(gtkEntry->style->xthickness, gtkEntry->style->ythickness,
1216 -gtkEntry->style->xthickness, -gtkEntry->style->ythickness);
1218 if (widget && widget->testAttribute(Qt::WA_SetPalette) &&
1219 resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
1220 painter->fillRect(textRect, option->palette.base());
1222 gtkPainter.paintFlatBox( gtkEntry, "entry_bg", textRect,
1223 option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_NONE, gtkEntry->style);
1227 case PE_FrameTabWidget:
1228 if (const QStyleOptionTabWidgetFrame *frame = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option)) {
1229 GtkWidget *gtkNotebook = d->gtkWidget("GtkNotebook");
1230 style = gtkPainter.getStyle(gtkNotebook);
1231 gtkPainter.setAlphaSupport(false);
1232 GtkShadowType shadow = GTK_SHADOW_OUT;
1233 GtkStateType state = GTK_STATE_NORMAL; // Only state supported by gtknotebook
1234 bool reverse = (option->direction == Qt::RightToLeft);
1235 QGtkStylePrivate::gtk_widget_set_direction(gtkNotebook, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1236 if (const QStyleOptionTabWidgetFrameV2 *tabframe = qstyleoption_cast<const QStyleOptionTabWidgetFrameV2*>(option)) {
1237 GtkPositionType frameType = GTK_POS_TOP;
1238 QTabBar::Shape shape = frame->shape;
1241 if (shape == QTabBar::RoundedNorth || shape == QTabBar::RoundedSouth) {
1242 frameType = (shape == QTabBar::RoundedNorth) ? GTK_POS_TOP : GTK_POS_BOTTOM;
1243 gapStart = tabframe->selectedTabRect.left();
1244 gapSize = tabframe->selectedTabRect.width();
1246 frameType = (shape == QTabBar::RoundedWest) ? GTK_POS_LEFT : GTK_POS_RIGHT;
1247 gapStart = tabframe->selectedTabRect.y();
1248 gapSize = tabframe->selectedTabRect.height();
1250 gtkPainter.paintBoxGap(gtkNotebook, "notebook", option->rect, state, shadow, frameType,
1251 gapStart, gapSize, style);
1255 // Note this is only the fallback option
1256 gtkPainter.paintBox(gtkNotebook, "notebook", option->rect, state, shadow, style);
1260 case PE_PanelButtonCommand:
1261 case PE_PanelButtonTool: {
1262 bool isDefault = false;
1263 bool isTool = (element == PE_PanelButtonTool);
1264 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton*>(option))
1265 isDefault = btn->features & QStyleOptionButton::DefaultButton;
1267 // don't draw a frame for tool buttons that have the autoRaise flag and are not enabled or on
1268 if (isTool && !(option->state & State_Enabled || option->state & State_On) && (option->state & State_AutoRaise))
1270 // don't draw a frame for dock widget buttons, unless we are hovering
1271 if (widget && widget->inherits("QDockWidgetTitleButton") && !(option->state & State_MouseOver))
1274 GtkStateType state = gtkPainter.gtkState(option);
1275 if (option->state & State_On || option->state & State_Sunken)
1276 state = GTK_STATE_ACTIVE;
1277 GtkWidget *gtkButton = isTool ? d->gtkWidget("GtkToolButton.GtkButton") : d->gtkWidget("GtkButton");
1278 gint focusWidth, focusPad;
1279 gboolean interiorFocus = false;
1280 d->gtk_widget_style_get (gtkButton,
1281 "focus-line-width", &focusWidth,
1282 "focus-padding", &focusPad,
1283 "interior-focus", &interiorFocus, NULL);
1285 style = gtkButton->style;
1287 QRect buttonRect = option->rect;
1292 GTK_WIDGET_SET_FLAGS(gtkButton, GTK_HAS_DEFAULT);
1293 gtkPainter.paintBox(gtkButton, "buttondefault", buttonRect, state, GTK_SHADOW_IN,
1294 style, isDefault ? QLS("d") : QString());
1297 bool hasFocus = option->state & State_HasFocus;
1301 GTK_WIDGET_SET_FLAGS(gtkButton, GTK_HAS_FOCUS);
1305 buttonRect = buttonRect.adjusted(focusWidth, focusWidth, -focusWidth, -focusWidth);
1307 GtkShadowType shadow = (option->state & State_Sunken || option->state & State_On ) ?
1308 GTK_SHADOW_IN : GTK_SHADOW_OUT;
1310 gtkPainter.paintBox(gtkButton, "button", buttonRect, state, shadow,
1313 GTK_WIDGET_UNSET_FLAGS(gtkButton, GTK_HAS_DEFAULT);
1315 GTK_WIDGET_UNSET_FLAGS(gtkButton, GTK_HAS_FOCUS);
1319 case PE_IndicatorRadioButton: {
1320 GtkShadowType shadow = GTK_SHADOW_OUT;
1321 GtkStateType state = gtkPainter.gtkState(option);
1323 if (option->state & State_Sunken)
1324 state = GTK_STATE_ACTIVE;
1326 if (option->state & State_NoChange)
1327 shadow = GTK_SHADOW_ETCHED_IN;
1328 else if (option->state & State_On)
1329 shadow = GTK_SHADOW_IN;
1331 shadow = GTK_SHADOW_OUT;
1333 GtkWidget *gtkRadioButton = d->gtkWidget("GtkRadioButton");
1335 d->gtk_widget_style_get(gtkRadioButton, "indicator-spacing", &spacing, NULL);
1336 QRect buttonRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
1337 gtkPainter.setClipRect(option->rect);
1338 // ### Note: Ubuntulooks breaks when the proper widget is passed
1339 // Murrine engine requires a widget not to get RGBA check - warnings
1340 GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
1341 QString key(QLS("radiobutton"));
1342 if (option->state & State_HasFocus) { // Themes such as Nodoka check this flag
1343 key += QLatin1Char('f');
1344 GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1346 gtkPainter.paintOption(gtkCheckButton , buttonRect, state, shadow, gtkRadioButton->style, key);
1347 if (option->state & State_HasFocus)
1348 GTK_WIDGET_UNSET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1352 case PE_IndicatorCheckBox: {
1353 GtkShadowType shadow = GTK_SHADOW_OUT;
1354 GtkStateType state = gtkPainter.gtkState(option);
1356 if (option->state & State_Sunken)
1357 state = GTK_STATE_ACTIVE;
1359 if (option->state & State_NoChange)
1360 shadow = GTK_SHADOW_ETCHED_IN;
1361 else if (option->state & State_On)
1362 shadow = GTK_SHADOW_IN;
1364 shadow = GTK_SHADOW_OUT;
1368 GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
1369 QString key(QLS("checkbutton"));
1370 if (option->state & State_HasFocus) { // Themes such as Nodoka checks this flag
1371 key += QLatin1Char('f');
1372 GTK_WIDGET_SET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1375 // Some styles such as aero-clone assume they can paint in the spacing area
1376 gtkPainter.setClipRect(option->rect);
1378 d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, NULL);
1380 QRect checkRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
1382 gtkPainter.paintCheckbox(gtkCheckButton, checkRect, state, shadow, gtkCheckButton->style,
1384 if (option->state & State_HasFocus)
1385 GTK_WIDGET_UNSET_FLAGS(gtkCheckButton, GTK_HAS_FOCUS);
1390 #ifndef QT_NO_TABBAR
1392 case PE_FrameTabBarBase:
1393 if (const QStyleOptionTabBarBase *tbb
1394 = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) {
1395 QRect tabRect = tbb->rect;
1397 painter->setPen(QPen(option->palette.dark().color().dark(110), 0));
1398 switch (tbb->shape) {
1400 case QTabBar::RoundedNorth:
1401 painter->drawLine(tabRect.topLeft(), tabRect.topRight());
1404 case QTabBar::RoundedWest:
1405 painter->drawLine(tabRect.left(), tabRect.top(), tabRect.left(), tabRect.bottom());
1408 case QTabBar::RoundedSouth:
1409 painter->drawLine(tbb->rect.left(), tbb->rect.bottom(),
1410 tabRect.right(), tabRect.bottom());
1413 case QTabBar::RoundedEast:
1414 painter->drawLine(tabRect.topRight(), tabRect.bottomRight());
1417 case QTabBar::TriangularNorth:
1418 case QTabBar::TriangularEast:
1419 case QTabBar::TriangularWest:
1420 case QTabBar::TriangularSouth:
1422 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1430 #endif // QT_NO_TABBAR
1436 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1443 void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
1445 QPainter *painter, const QWidget *widget) const
1447 Q_D(const QGtkStyle);
1449 if (!d->isThemeAvailable()) {
1450 QWindowsStyle::drawComplexControl(control, option, painter, widget);
1454 GtkStyle* style = d->gtkStyle();
1455 QGtkPainter gtkPainter(painter);
1456 QColor button = option->palette.button().color();
1460 dark.setHsv(button.hue(),
1461 qMin(255, (int)(button.saturation()*1.9)),
1462 qMin(255, (int)(button.value()*0.7)));
1463 grooveColor.setHsv(button.hue(),
1464 qMin(255, (int)(button.saturation()*2.6)),
1465 qMin(255, (int)(button.value()*0.9)));
1466 darkOutline.setHsv(button.hue(),
1467 qMin(255, (int)(button.saturation()*3.0)),
1468 qMin(255, (int)(button.value()*0.6)));
1470 QColor alphaCornerColor;
1473 alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), darkOutline);
1475 alphaCornerColor = mergedColors(option->palette.background().color(), darkOutline);
1481 if (const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
1482 // Since this is drawn by metacity and not Gtk we
1483 // have to do custom drawing
1485 GdkColor gdkBg = style->bg[GTK_STATE_SELECTED];
1486 QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8);
1488 const int buttonMargin = 5;
1489 bool active = (titleBar->titleBarState & State_Active);
1490 QRect fullRect = titleBar->rect;
1491 QPalette palette = option->palette;
1492 QColor highlight = bgColor;
1494 QColor titleBarFrameBorder(active ? highlight.darker(180): dark.darker(110));
1495 QColor titleBarHighlight(active ? highlight.lighter(120): palette.background().color().lighter(120));
1496 QColor textColor(active ? 0xffffff : 0xff000000);
1497 QColor textAlphaColor(active ? 0xffffff : 0xff000000 );
1500 // Fill title bar gradient
1501 QColor titlebarColor = QColor(active ? highlight: palette.background().color());
1502 QLinearGradient gradient(option->rect.center().x(), option->rect.top(),
1503 option->rect.center().x(), option->rect.bottom());
1505 gradient.setColorAt(0, titlebarColor.lighter(114));
1506 gradient.setColorAt(0.5, titlebarColor.lighter(102));
1507 gradient.setColorAt(0.51, titlebarColor.darker(104));
1508 gradient.setColorAt(1, titlebarColor);
1509 painter->fillRect(option->rect.adjusted(1, 1, -1, 0), gradient);
1511 // Frame and rounded corners
1512 painter->setPen(titleBarFrameBorder);
1515 painter->drawLine(fullRect.left() + 5, fullRect.top(), fullRect.right() - 5, fullRect.top());
1516 painter->drawLine(fullRect.left(), fullRect.top() + 4, fullRect.left(), fullRect.bottom());
1517 const QPoint points[5] = {
1518 QPoint(fullRect.left() + 4, fullRect.top() + 1),
1519 QPoint(fullRect.left() + 3, fullRect.top() + 1),
1520 QPoint(fullRect.left() + 2, fullRect.top() + 2),
1521 QPoint(fullRect.left() + 1, fullRect.top() + 3),
1522 QPoint(fullRect.left() + 1, fullRect.top() + 4)
1524 painter->drawPoints(points, 5);
1526 painter->drawLine(fullRect.right(), fullRect.top() + 4, fullRect.right(), fullRect.bottom());
1527 const QPoint points2[5] = {
1528 QPoint(fullRect.right() - 3, fullRect.top() + 1),
1529 QPoint(fullRect.right() - 4, fullRect.top() + 1),
1530 QPoint(fullRect.right() - 2, fullRect.top() + 2),
1531 QPoint(fullRect.right() - 1, fullRect.top() + 3),
1532 QPoint(fullRect.right() - 1, fullRect.top() + 4)
1534 painter->drawPoints(points2, 5);
1537 painter->drawLine(fullRect.right(), fullRect.bottom(), fullRect.left(), fullRect.bottom());
1540 painter->setPen(titleBarHighlight);
1541 painter->drawLine(fullRect.left() + 6, fullRect.top() + 1, fullRect.right() - 6, fullRect.top() + 1);
1544 QRect textRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarLabel, widget);
1545 QFont font = painter->font();
1547 painter->setFont(font);
1548 painter->setPen(active? (titleBar->palette.text().color().lighter(120)) :
1549 titleBar->palette.text().color() );
1550 // Note workspace also does elliding but it does not use the correct font
1551 QString title = QFontMetrics(font).elidedText(titleBar->text, Qt::ElideRight, textRect.width() - 14);
1552 painter->drawText(textRect.adjusted(1, 1, 1, 1), title, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
1553 painter->setPen(Qt::white);
1555 painter->drawText(textRect, title, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
1557 if ((titleBar->subControls & SC_TitleBarMinButton) && (titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
1558 !(titleBar->titleBarState& Qt::WindowMinimized)) {
1559 QRect minButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMinButton, widget);
1560 if (minButtonRect.isValid()) {
1561 bool hover = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_MouseOver);
1562 bool sunken = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_Sunken);
1563 qt_gtk_draw_mdibutton(painter, titleBar, minButtonRect, hover, sunken);
1564 QRect minButtonIconRect = minButtonRect.adjusted(buttonMargin ,buttonMargin , -buttonMargin, -buttonMargin);
1565 painter->setPen(textColor);
1566 painter->drawLine(minButtonIconRect.center().x() - 2, minButtonIconRect.center().y() + 3,
1567 minButtonIconRect.center().x() + 3, minButtonIconRect.center().y() + 3);
1568 painter->drawLine(minButtonIconRect.center().x() - 2, minButtonIconRect.center().y() + 4,
1569 minButtonIconRect.center().x() + 3, minButtonIconRect.center().y() + 4);
1570 painter->setPen(textAlphaColor);
1571 painter->drawLine(minButtonIconRect.center().x() - 3, minButtonIconRect.center().y() + 3,
1572 minButtonIconRect.center().x() - 3, minButtonIconRect.center().y() + 4);
1573 painter->drawLine(minButtonIconRect.center().x() + 4, minButtonIconRect.center().y() + 3,
1574 minButtonIconRect.center().x() + 4, minButtonIconRect.center().y() + 4);
1578 if ((titleBar->subControls & SC_TitleBarMaxButton) && (titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
1579 !(titleBar->titleBarState & Qt::WindowMaximized)) {
1580 QRect maxButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMaxButton, widget);
1581 if (maxButtonRect.isValid()) {
1582 bool hover = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_MouseOver);
1583 bool sunken = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_Sunken);
1584 qt_gtk_draw_mdibutton(painter, titleBar, maxButtonRect, hover, sunken);
1586 QRect maxButtonIconRect = maxButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
1588 painter->setPen(textColor);
1589 painter->drawRect(maxButtonIconRect.adjusted(0, 0, -1, -1));
1590 painter->drawLine(maxButtonIconRect.left() + 1, maxButtonIconRect.top() + 1,
1591 maxButtonIconRect.right() - 1, maxButtonIconRect.top() + 1);
1592 painter->setPen(textAlphaColor);
1593 const QPoint points[4] = {
1594 maxButtonIconRect.topLeft(),
1595 maxButtonIconRect.topRight(),
1596 maxButtonIconRect.bottomLeft(),
1597 maxButtonIconRect.bottomRight()
1599 painter->drawPoints(points, 4);
1604 if ((titleBar->subControls & SC_TitleBarCloseButton) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
1605 QRect closeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarCloseButton, widget);
1606 if (closeButtonRect.isValid()) {
1607 bool hover = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_MouseOver);
1608 bool sunken = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_Sunken);
1609 qt_gtk_draw_mdibutton(painter, titleBar, closeButtonRect, hover, sunken);
1610 QRect closeIconRect = closeButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
1611 painter->setPen(textAlphaColor);
1612 const QLine lines[4] = {
1613 QLine(closeIconRect.left() + 1, closeIconRect.top(),
1614 closeIconRect.right(), closeIconRect.bottom() - 1),
1615 QLine(closeIconRect.left(), closeIconRect.top() + 1,
1616 closeIconRect.right() - 1, closeIconRect.bottom()),
1617 QLine(closeIconRect.right() - 1, closeIconRect.top(),
1618 closeIconRect.left(), closeIconRect.bottom() - 1),
1619 QLine(closeIconRect.right(), closeIconRect.top() + 1,
1620 closeIconRect.left() + 1, closeIconRect.bottom())
1622 painter->drawLines(lines, 4);
1623 const QPoint points[4] = {
1624 closeIconRect.topLeft(),
1625 closeIconRect.topRight(),
1626 closeIconRect.bottomLeft(),
1627 closeIconRect.bottomRight()
1629 painter->drawPoints(points, 4);
1631 painter->setPen(textColor);
1632 painter->drawLine(closeIconRect.left() + 1, closeIconRect.top() + 1,
1633 closeIconRect.right() - 1, closeIconRect.bottom() - 1);
1634 painter->drawLine(closeIconRect.left() + 1, closeIconRect.bottom() - 1,
1635 closeIconRect.right() - 1, closeIconRect.top() + 1);
1640 if ((titleBar->subControls & SC_TitleBarNormalButton) &&
1641 (((titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
1642 (titleBar->titleBarState & Qt::WindowMinimized)) ||
1643 ((titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
1644 (titleBar->titleBarState & Qt::WindowMaximized)))) {
1645 QRect normalButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarNormalButton, widget);
1646 if (normalButtonRect.isValid()) {
1648 bool hover = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_MouseOver);
1649 bool sunken = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_Sunken);
1650 QRect normalButtonIconRect = normalButtonRect.adjusted(buttonMargin, buttonMargin, -buttonMargin, -buttonMargin);
1651 qt_gtk_draw_mdibutton(painter, titleBar, normalButtonRect, hover, sunken);
1653 QRect frontWindowRect = normalButtonIconRect.adjusted(0, 3, -3, 0);
1654 painter->setPen(textColor);
1655 painter->drawRect(frontWindowRect.adjusted(0, 0, -1, -1));
1656 painter->drawLine(frontWindowRect.left() + 1, frontWindowRect.top() + 1,
1657 frontWindowRect.right() - 1, frontWindowRect.top() + 1);
1658 painter->setPen(textAlphaColor);
1659 const QPoint points[4] = {
1660 frontWindowRect.topLeft(),
1661 frontWindowRect.topRight(),
1662 frontWindowRect.bottomLeft(),
1663 frontWindowRect.bottomRight()
1665 painter->drawPoints(points, 4);
1667 QRect backWindowRect = normalButtonIconRect.adjusted(3, 0, 0, -3);
1668 QRegion clipRegion = backWindowRect;
1669 clipRegion -= frontWindowRect;
1671 painter->setClipRegion(clipRegion);
1672 painter->setPen(textColor);
1673 painter->drawRect(backWindowRect.adjusted(0, 0, -1, -1));
1674 painter->drawLine(backWindowRect.left() + 1, backWindowRect.top() + 1,
1675 backWindowRect.right() - 1, backWindowRect.top() + 1);
1676 painter->setPen(textAlphaColor);
1677 const QPoint points2[4] = {
1678 backWindowRect.topLeft(),
1679 backWindowRect.topRight(),
1680 backWindowRect.bottomLeft(),
1681 backWindowRect.bottomRight()
1683 painter->drawPoints(points2, 4);
1688 // context help button
1689 if (titleBar->subControls & SC_TitleBarContextHelpButton
1690 && (titleBar->titleBarFlags & Qt::WindowContextHelpButtonHint)) {
1691 QRect contextHelpButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarContextHelpButton, widget);
1692 if (contextHelpButtonRect.isValid()) {
1693 bool hover = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_MouseOver);
1694 bool sunken = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_Sunken);
1695 qt_gtk_draw_mdibutton(painter, titleBar, contextHelpButtonRect, hover, sunken);
1698 QImage image(qt_titlebar_context_help);
1699 QColor alpha = textColor;
1700 alpha.setAlpha(128);
1701 image.setColor(1, textColor.rgba());
1702 image.setColor(2, alpha.rgba());
1703 painter->setRenderHint(QPainter::SmoothPixmapTransform);
1704 painter->drawImage(contextHelpButtonRect.adjusted(4, 4, -4, -4), image);
1709 if (titleBar->subControls & SC_TitleBarShadeButton && (titleBar->titleBarFlags & Qt::WindowShadeButtonHint)) {
1710 QRect shadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarShadeButton, widget);
1711 if (shadeButtonRect.isValid()) {
1712 bool hover = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_MouseOver);
1713 bool sunken = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_Sunken);
1714 qt_gtk_draw_mdibutton(painter, titleBar, shadeButtonRect, hover, sunken);
1715 QImage image(qt_scrollbar_button_arrow_up);
1716 image.setColor(1, textColor.rgba());
1717 painter->drawImage(shadeButtonRect.adjusted(5, 7, -5, -7), image);
1722 if (titleBar->subControls & SC_TitleBarUnshadeButton && (titleBar->titleBarFlags & Qt::WindowShadeButtonHint)) {
1723 QRect unshadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarUnshadeButton, widget);
1724 if (unshadeButtonRect.isValid()) {
1725 bool hover = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_MouseOver);
1726 bool sunken = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_Sunken);
1727 qt_gtk_draw_mdibutton(painter, titleBar, unshadeButtonRect, hover, sunken);
1728 QImage image(qt_scrollbar_button_arrow_down);
1729 image.setColor(1, textColor.rgba());
1730 painter->drawImage(unshadeButtonRect.adjusted(5, 7, -5, -7), image);
1734 if ((titleBar->subControls & SC_TitleBarSysMenu) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
1735 QRect iconRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarSysMenu, widget);
1736 if (iconRect.isValid()) {
1737 if (!titleBar->icon.isNull()) {
1738 titleBar->icon.paint(painter, iconRect);
1740 QStyleOption tool(0);
1741 tool.palette = titleBar->palette;
1742 QPixmap pm = standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(16, 16);
1743 tool.rect = iconRect;
1745 proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pm);
1754 #ifndef QT_NO_GROUPBOX
1759 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
1760 QRect textRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxLabel, widget);
1761 QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxCheckBox, widget);
1764 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
1765 // Draw prelight background
1766 GtkWidget *gtkCheckButton = d->gtkWidget("GtkCheckButton");
1768 if (option->state & State_MouseOver) {
1769 QRect bgRect = textRect | checkBoxRect;
1770 gtkPainter.paintFlatBox(gtkCheckButton, "checkbutton", bgRect.adjusted(0, 0, 0, -2),
1771 GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkCheckButton->style);
1774 if (!groupBox->text.isEmpty()) {
1775 int alignment = int(groupBox->textAlignment);
1776 if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, option, widget))
1777 alignment |= Qt::TextHideMnemonic;
1778 QColor textColor = groupBox->textColor; // Note: custom textColor is currently ignored
1779 int labelState = GTK_STATE_INSENSITIVE;
1781 if (option->state & State_Enabled)
1782 labelState = (option->state & State_MouseOver) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
1784 GdkColor gdkText = gtkCheckButton->style->fg[labelState];
1785 textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
1786 painter->setPen(textColor);
1787 QFont font = painter->font();
1789 painter->setFont(font);
1790 painter->drawText(textRect, Qt::TextShowMnemonic | Qt::AlignLeft| alignment, groupBox->text);
1792 if (option->state & State_HasFocus)
1793 gtkPainter.paintFocus(gtkCheckButton, "checkbutton", textRect.adjusted(-4, -1, 0, -3), GTK_STATE_ACTIVE, style);
1797 if (groupBox->subControls & SC_GroupBoxCheckBox) {
1798 QStyleOptionButton box;
1799 box.QStyleOption::operator=(*groupBox);
1800 box.rect = checkBoxRect;
1801 proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
1807 #endif // QT_NO_GROUPBOX
1809 #ifndef QT_NO_COMBOBOX
1812 // See: http://live.gnome.org/GnomeArt/Tutorials/GtkThemes/GtkComboBox
1813 // and http://live.gnome.org/GnomeArt/Tutorials/GtkThemes/GtkComboBoxEntry
1814 if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1815 bool sunken = comboBox->state & State_On; // play dead, if combobox has no items
1816 BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("cb-%0-%1").arg(sunken).arg(comboBox->editable));
1817 QGtkPainter gtkCachedPainter(p);
1818 gtkCachedPainter.setUsePixmapCache(false); // cached externally
1820 bool isEnabled = (comboBox->state & State_Enabled);
1821 bool focus = isEnabled && (comboBox->state & State_HasFocus);
1822 GtkStateType state = gtkPainter.gtkState(option);
1823 int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, comboBox, widget);
1824 QStyleOptionComboBox comboBoxCopy = *comboBox;
1825 comboBoxCopy.rect = option->rect;
1827 bool reverse = (option->direction == Qt::RightToLeft);
1828 QRect rect = option->rect;
1829 QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, &comboBoxCopy,
1830 SC_ComboBoxArrow, widget);
1832 GtkShadowType shadow = (option->state & State_Sunken || option->state & State_On ) ?
1833 GTK_SHADOW_IN : GTK_SHADOW_OUT;
1834 const QHashableLatin1Literal comboBoxPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry") : QHashableLatin1Literal("GtkComboBox");
1836 // We use the gtk widget to position arrows and separators for us
1837 GtkWidget *gtkCombo = d->gtkWidget(comboBoxPath);
1838 GtkAllocation geometry = {0, 0, option->rect.width(), option->rect.height()};
1839 d->gtk_widget_set_direction(gtkCombo, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1840 d->gtk_widget_size_allocate(gtkCombo, &geometry);
1842 QHashableLatin1Literal buttonPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton")
1843 : QHashableLatin1Literal("GtkComboBox.GtkToggleButton");
1844 GtkWidget *gtkToggleButton = d->gtkWidget(buttonPath);
1845 d->gtk_widget_set_direction(gtkToggleButton, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1846 if (gtkToggleButton && (appears_as_list || comboBox->editable)) {
1848 GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1849 // Draw the combo box as a line edit with a button next to it
1850 if (comboBox->editable || appears_as_list) {
1851 GtkStateType frameState = (state == GTK_STATE_PRELIGHT) ? GTK_STATE_NORMAL : state;
1852 QHashableLatin1Literal entryPath = comboBox->editable ? QHashableLatin1Literal("GtkComboBoxEntry.GtkEntry") : QHashableLatin1Literal("GtkComboBox.GtkFrame");
1853 GtkWidget *gtkEntry = d->gtkWidget(entryPath);
1854 d->gtk_widget_set_direction(gtkEntry, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
1855 QRect frameRect = option->rect;
1858 frameRect.setLeft(arrowButtonRect.right());
1860 frameRect.setRight(arrowButtonRect.left());
1862 // Fill the line edit background
1863 // We could have used flat_box with "entry_bg" but that is probably not worth the overhead
1864 uint resolve_mask = option->palette.resolve();
1865 int xt = gtkEntry->style->xthickness;
1866 int yt = gtkEntry->style->ythickness;
1867 QRect contentRect = frameRect.adjusted(xt, yt, -xt, -yt);
1868 // Required for inner blue highlight with clearlooks
1870 GTK_WIDGET_SET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1872 if (widget && widget->testAttribute(Qt::WA_SetPalette) &&
1873 resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
1874 p->fillRect(contentRect, option->palette.base().color());
1876 gtkCachedPainter.paintFlatBox(gtkEntry, "entry_bg", contentRect,
1877 option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
1878 GTK_SHADOW_NONE, gtkEntry->style, entryPath.toString() + QString::number(focus));
1881 gtkCachedPainter.paintShadow(gtkEntry, comboBox->editable ? "entry" : "frame", frameRect, frameState,
1882 GTK_SHADOW_IN, gtkEntry->style, entryPath.toString() +
1883 QString::number(focus) + QString::number(comboBox->editable) +
1884 QString::number(option->direction));
1886 GTK_WIDGET_UNSET_FLAGS(gtkEntry, GTK_HAS_FOCUS);
1889 GtkStateType buttonState = GTK_STATE_NORMAL;
1891 if (!(option->state & State_Enabled))
1892 buttonState = GTK_STATE_INSENSITIVE;
1893 else if (option->state & State_Sunken || option->state & State_On)
1894 buttonState = GTK_STATE_ACTIVE;
1895 else if (option->state & State_MouseOver && comboBox->activeSubControls & SC_ComboBoxArrow)
1896 buttonState = GTK_STATE_PRELIGHT;
1898 Q_ASSERT(gtkToggleButton);
1899 gtkCachedPainter.paintBox( gtkToggleButton, "button", arrowButtonRect, buttonState,
1900 shadow, gtkToggleButton->style, buttonPath.toString() +
1901 QString::number(focus) + QString::number(option->direction));
1903 GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1905 // Draw combo box as a button
1906 QRect buttonRect = option->rect;
1908 if (focus) // Clearlooks actually check the widget for the default state
1909 GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1910 gtkCachedPainter.paintBox(gtkToggleButton, "button",
1912 shadow, gtkToggleButton->style,
1913 buttonPath.toString() + QString::number(focus));
1915 GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
1918 // Draw the separator between label and arrows
1919 QHashableLatin1Literal vSeparatorPath = comboBox->editable
1920 ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkHBox.GtkVSeparator")
1921 : QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkHBox.GtkVSeparator");
1923 if (GtkWidget *gtkVSeparator = d->gtkWidget(vSeparatorPath)) {
1924 GtkAllocation allocation;
1925 d->gtk_widget_get_allocation(gtkVSeparator, &allocation);
1926 QRect vLineRect(allocation.x, allocation.y, allocation.width, allocation.height);
1928 gtkCachedPainter.paintVline( gtkVSeparator, "vseparator",
1929 vLineRect, state, gtkVSeparator->style,
1930 0, vLineRect.height(), 0, vSeparatorPath.toString());
1933 gint interiorFocus = true;
1934 d->gtk_widget_style_get(gtkToggleButton, "interior-focus", &interiorFocus, NULL);
1935 int xt = interiorFocus ? gtkToggleButton->style->xthickness : 0;
1936 int yt = interiorFocus ? gtkToggleButton->style->ythickness : 0;
1937 if (focus && ((option->state & State_KeyboardFocusChange) || styleHint(SH_UnderlineShortcut, option, widget)))
1938 gtkCachedPainter.paintFocus(gtkToggleButton, "button",
1939 option->rect.adjusted(xt, yt, -xt, -yt),
1940 option->state & State_Sunken ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL,
1941 gtkToggleButton->style);
1945 if (comboBox->subControls & SC_ComboBoxArrow) {
1947 state = GTK_STATE_INSENSITIVE;
1949 state = GTK_STATE_ACTIVE;
1950 else if (option->state & State_MouseOver)
1951 state = GTK_STATE_PRELIGHT;
1953 state = GTK_STATE_NORMAL;
1955 QHashableLatin1Literal arrowPath("");
1956 if (comboBox->editable) {
1957 if (appears_as_list)
1958 arrowPath = QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkArrow");
1960 arrowPath = QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton.GtkHBox.GtkArrow");
1962 if (appears_as_list)
1963 arrowPath = QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkArrow");
1965 arrowPath = QHashableLatin1Literal("GtkComboBox.GtkToggleButton.GtkHBox.GtkArrow");
1968 GtkWidget *gtkArrow = d->gtkWidget(arrowPath);
1971 QRect arrowWidgetRect;
1973 if (gtkArrow && !d->gtk_check_version(2, 12, 0)) {
1974 d->gtk_widget_style_get(gtkArrow, "arrow-scaling", &scale, NULL);
1975 d->gtk_widget_style_get(gtkCombo, "arrow-size", &minSize, NULL);
1978 GtkAllocation allocation;
1979 d->gtk_widget_get_allocation(gtkArrow, &allocation);
1980 arrowWidgetRect = QRect(allocation.x, allocation.y, allocation.width, allocation.height);
1981 style = gtkArrow->style;
1984 // Note that for some reason the arrow-size is not properly respected with Hildon
1985 // Hence we enforce the minimum "arrow-size" ourselves
1986 int arrowSize = qMax(qMin(rect.height() - gtkCombo->style->ythickness * 2, minSize),
1987 qMin(arrowWidgetRect.width(), arrowWidgetRect.height()));
1988 QRect arrowRect(0, 0, static_cast<int>(arrowSize * scale), static_cast<int>(arrowSize * scale));
1990 arrowRect.moveCenter(arrowWidgetRect.center());
1994 const QHashableLatin1Literal toggleButtonPath = comboBox->editable
1995 ? QHashableLatin1Literal("GtkComboBoxEntry.GtkToggleButton")
1996 : QHashableLatin1Literal("GtkComboBox.GtkToggleButton");
1998 GtkWidget *gtkButton = d->gtkWidget(toggleButtonPath);
1999 d->gtk_widget_style_get(gtkButton, "child-displacement-x", &xoff, NULL);
2000 d->gtk_widget_style_get(gtkButton, "child-displacement-y", &yoff, NULL);
2001 arrowRect = arrowRect.adjusted(xoff, yoff, xoff, yoff);
2004 // Some styles such as Nimbus paint outside the arrowRect
2005 // hence we have provide the whole widget as the cliprect
2007 gtkCachedPainter.setClipRect(option->rect);
2008 gtkCachedPainter.paintArrow( gtkArrow, "arrow", arrowRect,
2009 GTK_ARROW_DOWN, state, GTK_SHADOW_NONE, true,
2010 style, arrowPath.toString() + QString::number(option->direction));
2013 END_STYLE_PIXMAPCACHE;
2016 #endif // QT_NO_COMBOBOX
2017 #ifndef QT_NO_TOOLBUTTON
2020 if (const QStyleOptionToolButton *toolbutton
2021 = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
2022 QRect button, menuarea;
2023 button = proxy()->subControlRect(control, toolbutton, SC_ToolButton, widget);
2024 menuarea = proxy()->subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
2025 State bflags = toolbutton->state & ~(State_Sunken | State_MouseOver);
2027 if (bflags & State_AutoRaise)
2028 if (!(bflags & State_MouseOver))
2029 bflags &= ~State_Raised;
2031 State mflags = bflags;
2033 if (toolbutton->state & State_Sunken) {
2034 if (toolbutton->activeSubControls & SC_ToolButton)
2035 bflags |= State_Sunken;
2036 if (toolbutton->activeSubControls & SC_ToolButtonMenu)
2037 mflags |= State_Sunken;
2038 } else if (toolbutton->state & State_MouseOver) {
2039 if (toolbutton->activeSubControls & SC_ToolButton)
2040 bflags |= State_MouseOver;
2041 if (toolbutton->activeSubControls & SC_ToolButtonMenu)
2042 mflags |= State_MouseOver;
2045 QStyleOption tool(0);
2047 tool.palette = toolbutton->palette;
2049 if (toolbutton->subControls & SC_ToolButton) {
2050 if (bflags & (State_Sunken | State_On | State_Raised | State_MouseOver)) {
2052 tool.state = bflags;
2053 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
2057 bool drawMenuArrow = toolbutton->features & QStyleOptionToolButton::HasMenu &&
2058 !(toolbutton->features & QStyleOptionToolButton::MenuButtonPopup);
2059 int popupArrowSize = drawMenuArrow ? 7 : 0;
2061 if (toolbutton->state & State_HasFocus) {
2062 QStyleOptionFocusRect fr;
2063 fr.QStyleOption::operator=(*toolbutton);
2064 fr.rect = proxy()->subControlRect(CC_ToolButton, toolbutton, SC_ToolButton, widget);
2065 fr.rect.adjust(1, 1, -1, -1);
2066 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
2069 QStyleOptionToolButton label = *toolbutton;
2070 label.state = bflags;
2071 GtkWidget *gtkButton = d->gtkWidget("GtkToolButton.GtkButton");
2072 QPalette pal = toolbutton->palette;
2073 if (option->state & State_Enabled &&
2074 option->state & State_MouseOver && !(widget && widget->testAttribute(Qt::WA_SetPalette))) {
2075 GdkColor gdkText = gtkButton->style->fg[GTK_STATE_PRELIGHT];
2076 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2077 pal.setBrush(QPalette::All, QPalette::ButtonText, textColor);
2078 label.palette = pal;
2080 label.rect = button.adjusted(style->xthickness, style->ythickness,
2081 -style->xthickness - popupArrowSize, -style->ythickness);
2082 proxy()->drawControl(CE_ToolButtonLabel, &label, painter, widget);
2084 if (toolbutton->subControls & SC_ToolButtonMenu) {
2085 tool.rect = menuarea;
2086 tool.state = mflags;
2087 if ((mflags & State_Enabled && (mflags & (State_Sunken | State_Raised | State_MouseOver))) || !(mflags & State_AutoRaise))
2088 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, painter, widget);
2090 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
2092 } else if (drawMenuArrow) {
2093 QRect ir = toolbutton->rect;
2094 QStyleOptionToolButton newBtn = *toolbutton;
2095 newBtn.rect = QRect(ir.right() - popupArrowSize - style->xthickness - 3, ir.height()/2 - 1, popupArrowSize, popupArrowSize);
2096 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
2101 #endif // QT_NO_TOOLBUTTON
2102 #ifndef QT_NO_SCROLLBAR
2105 if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
2106 GtkWidget *gtkHScrollBar = d->gtkWidget("GtkHScrollbar");
2107 GtkWidget *gtkVScrollBar = d->gtkWidget("GtkVScrollbar");
2109 // Fill background in case the scrollbar is partially transparent
2110 painter->fillRect(option->rect, option->palette.background());
2112 QRect rect = scrollBar->rect;
2113 QRect scrollBarSubLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubLine, widget);
2114 QRect scrollBarAddLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddLine, widget);
2115 QRect scrollBarSlider = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSlider, widget);
2116 QRect grooveRect = proxy()->subControlRect(control, scrollBar, SC_ScrollBarGroove, widget);
2117 bool horizontal = scrollBar->orientation == Qt::Horizontal;
2118 GtkWidget * scrollbarWidget = horizontal ? gtkHScrollBar : gtkVScrollBar;
2119 style = scrollbarWidget->style;
2120 gboolean trough_under_steppers = true;
2121 gboolean trough_side_details = false;
2122 gboolean activate_slider = false;
2123 gboolean stepper_size = 14;
2124 gint trough_border = 1;
2125 if (!d->gtk_check_version(2, 10, 0)) {
2126 d->gtk_widget_style_get((GtkWidget*)(scrollbarWidget),
2127 "trough-border", &trough_border,
2128 "trough-side-details", &trough_side_details,
2129 "trough-under-steppers", &trough_under_steppers,
2130 "activate-slider", &activate_slider,
2131 "stepper-size", &stepper_size, NULL);
2133 if (trough_under_steppers) {
2134 scrollBarAddLine.adjust(trough_border, trough_border, -trough_border, -trough_border);
2135 scrollBarSubLine.adjust(trough_border, trough_border, -trough_border, -trough_border);
2136 scrollBarSlider.adjust(horizontal ? -trough_border : 0, horizontal ? 0 : -trough_border,
2137 horizontal ? trough_border : 0, horizontal ? 0 : trough_border);
2140 // Some styles check the position of scrollbars in order to determine
2141 // if lines should be painted when the scrollbar is in max or min positions.
2144 bool reverse = (option->direction == Qt::RightToLeft);
2145 if (scrollBar->minimum == scrollBar->maximum)
2147 if (scrollBar->sliderPosition == scrollBar->maximum)
2149 else if (scrollBar->sliderPosition > scrollBar->minimum)
2150 fakePos = maximum - 1;
2153 GtkRange *range = (GtkRange*)(horizontal ? gtkHScrollBar : gtkVScrollBar);
2154 GtkAdjustment *adjustment = d->gtk_range_get_adjustment(range);
2157 d->gtk_adjustment_configure(adjustment, fakePos, 0, maximum, 0, 0, 0);
2159 adjustment = (GtkAdjustment*)d->gtk_adjustment_new(fakePos, 0, maximum, 0, 0, 0);
2160 d->gtk_range_set_adjustment(range, adjustment);
2163 if (scrollBar->subControls & SC_ScrollBarGroove) {
2164 GtkStateType state = GTK_STATE_ACTIVE;
2166 if (!(option->state & State_Enabled))
2167 state = GTK_STATE_INSENSITIVE;
2169 if (trough_under_steppers)
2170 grooveRect = option->rect;
2172 gtkPainter.paintBox( scrollbarWidget, "trough", grooveRect, state, GTK_SHADOW_IN, style);
2176 if (scrollBar->subControls & SC_ScrollBarSlider) {
2177 GtkStateType state = GTK_STATE_NORMAL;
2179 if (!(option->state & State_Enabled))
2180 state = GTK_STATE_INSENSITIVE;
2181 else if (activate_slider &&
2182 option->state & State_Sunken && (scrollBar->activeSubControls & SC_ScrollBarSlider))
2183 state = GTK_STATE_ACTIVE;
2184 else if (option->state & State_MouseOver && (scrollBar->activeSubControls & SC_ScrollBarSlider))
2185 state = GTK_STATE_PRELIGHT;
2187 GtkShadowType shadow = GTK_SHADOW_OUT;
2189 if (trough_under_steppers) {
2191 scrollBarSlider.adjust(trough_border, 0, -trough_border, 0);
2193 scrollBarSlider.adjust(0, trough_border, 0, -trough_border);
2196 gtkPainter.paintSlider( scrollbarWidget, "slider", scrollBarSlider, state, shadow, style,
2198 horizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, QString(QLS("%0%1")).arg(fakePos).arg(maximum));
2201 if (scrollBar->subControls & SC_ScrollBarAddLine) {
2202 GtkAllocation vAllocation;
2203 vAllocation.y = scrollBarAddLine.top();
2204 vAllocation.height = scrollBarAddLine.height() - rect.height() + 6;
2205 d->gtk_widget_set_allocation(gtkVScrollBar, &vAllocation);
2207 GtkAllocation hAllocation;
2208 hAllocation.x = scrollBarAddLine.right();
2209 hAllocation.width = scrollBarAddLine.width() - rect.width();
2210 d->gtk_widget_set_allocation(gtkHScrollBar, &hAllocation);
2212 GtkShadowType shadow = GTK_SHADOW_OUT;
2213 GtkStateType state = GTK_STATE_NORMAL;
2215 if (!(option->state & State_Enabled) || (fakePos == maximum))
2216 state = GTK_STATE_INSENSITIVE;
2217 else if (option->state & State_Sunken && (scrollBar->activeSubControls & SC_ScrollBarAddLine)) {
2218 state = GTK_STATE_ACTIVE;
2219 shadow = GTK_SHADOW_IN;
2221 } else if (option->state & State_MouseOver && (scrollBar->activeSubControls & SC_ScrollBarAddLine))
2222 state = GTK_STATE_PRELIGHT;
2224 gtkPainter.paintBox( scrollbarWidget,
2225 horizontal ? "hscrollbar" : "vscrollbar", scrollBarAddLine,
2226 state, shadow, style, QLS("add"));
2228 gtkPainter.paintArrow( scrollbarWidget, horizontal ? "hscrollbar" : "vscrollbar", scrollBarAddLine.adjusted(4, 4, -4, -4),
2229 horizontal ? (reverse ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT) :
2230 GTK_ARROW_DOWN, state, GTK_SHADOW_NONE, false, style);
2233 if (scrollBar->subControls & SC_ScrollBarSubLine) {
2234 GtkAllocation vAllocation;
2236 vAllocation.height = scrollBarSubLine.height();
2237 d->gtk_widget_set_allocation(gtkVScrollBar, &vAllocation);
2239 GtkAllocation hAllocation;
2241 hAllocation.width = scrollBarSubLine.width();
2242 d->gtk_widget_set_allocation(gtkHScrollBar, &hAllocation);
2244 GtkShadowType shadow = GTK_SHADOW_OUT;
2245 GtkStateType state = GTK_STATE_NORMAL;
2247 if (!(option->state & State_Enabled) || (fakePos == 0))
2248 state = GTK_STATE_INSENSITIVE;
2249 else if (option->state & State_Sunken && (scrollBar->activeSubControls & SC_ScrollBarSubLine)) {
2250 shadow = GTK_SHADOW_IN;
2251 state = GTK_STATE_ACTIVE;
2253 } else if (option->state & State_MouseOver && (scrollBar->activeSubControls & SC_ScrollBarSubLine))
2254 state = GTK_STATE_PRELIGHT;
2256 gtkPainter.paintBox(scrollbarWidget, horizontal ? "hscrollbar" : "vscrollbar", scrollBarSubLine,
2257 state, shadow, style, QLS("sub"));
2259 gtkPainter.paintArrow(scrollbarWidget, horizontal ? "hscrollbar" : "vscrollbar", scrollBarSubLine.adjusted(4, 4, -4, -4),
2260 horizontal ? (reverse ? GTK_ARROW_RIGHT : GTK_ARROW_LEFT) :
2261 GTK_ARROW_UP, state, GTK_SHADOW_NONE, false, style);
2266 #endif //QT_NO_SCROLLBAR
2267 #ifndef QT_NO_SPINBOX
2270 if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
2272 GtkWidget *gtkSpinButton = spinBox->buttonSymbols == QAbstractSpinBox::NoButtons
2273 ? d->gtkWidget("GtkEntry")
2274 : d->gtkWidget("GtkSpinButton");
2275 bool isEnabled = (spinBox->state & State_Enabled);
2276 bool hover = isEnabled && (spinBox->state & State_MouseOver);
2277 bool sunken = (spinBox->state & State_Sunken);
2278 bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
2279 bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
2280 bool reverse = (spinBox->direction == Qt::RightToLeft);
2282 QRect editArea = option->rect;
2283 QRect editRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxEditField, widget);
2284 QRect upRect, downRect, buttonRect;
2285 if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
2286 upRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
2287 downRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
2289 //### Move this to subControlRect
2290 upRect.setTop(option->rect.top());
2293 upRect.setLeft(option->rect.left());
2295 upRect.setRight(option->rect.right());
2297 downRect.setBottom(option->rect.bottom());
2300 downRect.setLeft(option->rect.left());
2302 downRect.setRight(option->rect.right());
2304 buttonRect = upRect | downRect;
2307 editArea.setLeft(upRect.right());
2309 editArea.setRight(upRect.left());
2311 if (spinBox->frame) {
2312 GtkStateType state = gtkPainter.gtkState(option);
2314 if (!(option->state & State_Enabled))
2315 state = GTK_STATE_INSENSITIVE;
2316 else if (option->state & State_HasFocus)
2317 state = GTK_STATE_NORMAL;
2318 else if (state == GTK_STATE_PRELIGHT)
2319 state = GTK_STATE_NORMAL;
2321 style = gtkPainter.getStyle(gtkSpinButton);
2326 if (option->state & State_HasFocus) {
2327 key += QLatin1Char('f');
2328 GTK_WIDGET_SET_FLAGS(gtkSpinButton, GTK_HAS_FOCUS);
2331 uint resolve_mask = option->palette.resolve();
2333 if (resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
2334 painter->fillRect(editRect, option->palette.base().color());
2336 gtkPainter.paintFlatBox(gtkSpinButton, "entry_bg", editArea.adjusted(style->xthickness, style->ythickness,
2337 -style->xthickness, -style->ythickness),
2338 option->state & State_Enabled ?
2339 GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_NONE, style, key);
2341 gtkPainter.paintShadow(gtkSpinButton, "entry", editArea, state, GTK_SHADOW_IN, gtkSpinButton->style, key);
2342 if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
2343 gtkPainter.paintBox(gtkSpinButton, "spinbutton", buttonRect, state, GTK_SHADOW_IN, style, key);
2345 upRect.setSize(downRect.size());
2346 if (!(option->state & State_Enabled))
2347 gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_INSENSITIVE, GTK_SHADOW_IN, style, key);
2348 else if (upIsActive && sunken)
2349 gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_ACTIVE, GTK_SHADOW_IN, style, key);
2350 else if (upIsActive && hover)
2351 gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style, key);
2353 gtkPainter.paintBox( gtkSpinButton, "spinbutton_up", upRect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, style, key);
2355 if (!(option->state & State_Enabled))
2356 gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_INSENSITIVE, GTK_SHADOW_IN, style, key);
2357 else if (downIsActive && sunken)
2358 gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_ACTIVE, GTK_SHADOW_IN, style, key);
2359 else if (downIsActive && hover)
2360 gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style, key);
2362 gtkPainter.paintBox( gtkSpinButton, "spinbutton_down", downRect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, style, key);
2364 if (option->state & State_HasFocus)
2365 GTK_WIDGET_UNSET_FLAGS(gtkSpinButton, GTK_HAS_FOCUS);
2369 if (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) {
2370 int centerX = upRect.center().x();
2371 int centerY = upRect.center().y();
2374 if (spinBox->activeSubControls == SC_SpinBoxUp && sunken) {
2375 painter->drawLine(1 + centerX - 2, 1 + centerY, 1 + centerX + 2, 1 + centerY);
2376 painter->drawLine(1 + centerX, 1 + centerY - 2, 1 + centerX, 1 + centerY + 2);
2379 painter->drawLine(centerX - 2, centerY, centerX + 2, centerY);
2380 painter->drawLine(centerX, centerY - 2, centerX, centerY + 2);
2382 centerX = downRect.center().x();
2383 centerY = downRect.center().y();
2385 if (spinBox->activeSubControls == SC_SpinBoxDown && sunken) {
2386 painter->drawLine(1 + centerX - 2, 1 + centerY, 1 + centerX + 2, 1 + centerY);
2388 painter->drawLine(centerX - 2, centerY, centerX + 2, centerY);
2391 } else if (spinBox->buttonSymbols == QAbstractSpinBox::UpDownArrows) {
2392 int size = d->getSpinboxArrowSize();
2393 int w = size / 2 - 1;
2394 w -= w % 2 - 1; // force odd
2396 QRect arrowRect(0, 0, w, h);
2397 arrowRect.moveCenter(upRect.center());
2399 GtkStateType state = GTK_STATE_NORMAL;
2401 if (!(option->state & State_Enabled) || !(spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled))
2402 state = GTK_STATE_INSENSITIVE;
2404 gtkPainter.paintArrow( gtkSpinButton, "spinbutton", arrowRect, GTK_ARROW_UP, state,
2405 GTK_SHADOW_NONE, false, style);
2407 arrowRect.moveCenter(downRect.center());
2409 if (!(option->state & State_Enabled) || !(spinBox->stepEnabled & QAbstractSpinBox::StepDownEnabled))
2410 state = GTK_STATE_INSENSITIVE;
2412 gtkPainter.paintArrow( gtkSpinButton, "spinbutton", arrowRect, GTK_ARROW_DOWN, state,
2413 GTK_SHADOW_NONE, false, style);
2418 #endif // QT_NO_SPINBOX
2420 #ifndef QT_NO_SLIDER
2423 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
2424 GtkWidget *hScaleWidget = d->gtkWidget("GtkHScale");
2425 GtkWidget *vScaleWidget = d->gtkWidget("GtkVScale");
2427 QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
2428 QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
2430 bool horizontal = slider->orientation == Qt::Horizontal;
2431 bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
2432 bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
2434 QBrush oldBrush = painter->brush();
2435 QPen oldPen = painter->pen();
2437 QColor shadowAlpha(Qt::black);
2438 shadowAlpha.setAlpha(10);
2439 QColor highlightAlpha(Qt::white);
2440 highlightAlpha.setAlpha(80);
2442 QGtkStylePrivate::gtk_widget_set_direction(hScaleWidget, slider->upsideDown ?
2443 GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
2444 GtkWidget *scaleWidget = horizontal ? hScaleWidget : vScaleWidget;
2445 style = scaleWidget->style;
2447 if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
2449 GtkRange *range = (GtkRange*)scaleWidget;
2450 GtkAdjustment *adjustment = d->gtk_range_get_adjustment(range);
2452 d->gtk_adjustment_configure(adjustment,
2453 slider->sliderPosition,
2460 adjustment = (GtkAdjustment*)d->gtk_adjustment_new(slider->sliderPosition,
2466 d->gtk_range_set_adjustment(range, adjustment);
2470 d->gtk_range_set_inverted(range, !horizontal);
2471 d->gtk_widget_style_get(scaleWidget, "trough-border", &outerSize, NULL);
2474 GtkStateType state = gtkPainter.gtkState(option);
2475 int focusFrameMargin = 2;
2476 QRect grooveRect = option->rect.adjusted(focusFrameMargin, outerSize + focusFrameMargin,
2477 -focusFrameMargin, -outerSize - focusFrameMargin);
2479 gboolean trough_side_details = false; // Indicates if the upper or lower scale background differs
2480 if (!d->gtk_check_version(2, 10, 0))
2481 d->gtk_widget_style_get((GtkWidget*)(scaleWidget), "trough-side-details", &trough_side_details, NULL);
2483 if (!trough_side_details) {
2484 gtkPainter.paintBox( scaleWidget, "trough", grooveRect, state,
2485 GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
2487 QRect upperGroove = grooveRect;
2488 QRect lowerGroove = grooveRect;
2491 if (slider->upsideDown) {
2492 lowerGroove.setLeft(handle.center().x());
2493 upperGroove.setRight(handle.center().x());
2495 upperGroove.setLeft(handle.center().x());
2496 lowerGroove.setRight(handle.center().x());
2499 if (!slider->upsideDown) {
2500 lowerGroove.setBottom(handle.center().y());
2501 upperGroove.setTop(handle.center().y());
2503 upperGroove.setBottom(handle.center().y());
2504 lowerGroove.setTop(handle.center().y());
2508 gtkPainter.paintBox( scaleWidget, "trough-upper", upperGroove, state,
2509 GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
2510 gtkPainter.paintBox( scaleWidget, "trough-lower", lowerGroove, state,
2511 GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
2515 if (option->subControls & SC_SliderTickmarks) {
2516 painter->setPen(darkOutline);
2517 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
2518 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
2519 int interval = slider->tickInterval;
2521 if (interval <= 0) {
2522 interval = slider->singleStep;
2524 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
2526 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
2528 interval = slider->pageStep;
2534 int v = slider->minimum;
2535 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
2536 while (v <= slider->maximum + 1) {
2537 if (v == slider->maximum + 1 && interval == 1)
2539 const int v_ = qMin(v, slider->maximum);
2540 int pos = sliderPositionFromValue(slider->minimum, slider->maximum,
2542 ? slider->rect.width()
2543 : slider->rect.height()) - len,
2544 slider->upsideDown) + len / 2;
2545 int extra = 2 - ((v_ == slider->minimum || v_ == slider->maximum) ? 1 : 0);
2548 painter->drawLine(pos, slider->rect.top() + extra,
2549 pos, slider->rect.top() + tickSize);
2551 painter->drawLine(pos, slider->rect.bottom() - extra,
2552 pos, slider->rect.bottom() - tickSize);
2556 painter->drawLine(slider->rect.left() + extra, pos,
2557 slider->rect.left() + tickSize, pos);
2559 painter->drawLine(slider->rect.right() - extra, pos,
2560 slider->rect.right() - tickSize, pos);
2563 // In the case where maximum is max int
2564 int nextInterval = v + interval;
2565 if (nextInterval < v)
2571 // Draw slider handle
2572 if (option->subControls & SC_SliderHandle) {
2573 GtkShadowType shadow = GTK_SHADOW_OUT;
2574 GtkStateType state = GTK_STATE_NORMAL;
2576 if (!(option->state & State_Enabled))
2577 state = GTK_STATE_INSENSITIVE;
2578 else if (option->state & State_MouseOver && option->activeSubControls & SC_SliderHandle)
2579 state = GTK_STATE_PRELIGHT;
2581 bool horizontal = option->state & State_Horizontal;
2583 if (slider->state & State_HasFocus) {
2584 QStyleOptionFocusRect fropt;
2585 fropt.QStyleOption::operator=(*slider);
2586 fropt.rect = slider->rect.adjusted(-1, -1 ,1, 1);
2589 fropt.rect.setTop(handle.top() - 3);
2590 fropt.rect.setBottom(handle.bottom() + 4);
2593 fropt.rect.setLeft(handle.left() - 3);
2594 fropt.rect.setRight(handle.right() + 3);
2596 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
2598 gtkPainter.paintSlider( scaleWidget, horizontal ? "hscale" : "vscale", handle, state, shadow, style,
2600 horizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL);
2602 painter->setBrush(oldBrush);
2603 painter->setPen(oldPen);
2607 if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(option))
2608 QStyleHelper::drawDial(dial, painter);
2611 #endif // QT_NO_SLIDER
2614 QWindowsStyle::drawComplexControl(control, option, painter, widget);
2624 void QGtkStyle::drawControl(ControlElement element,
2625 const QStyleOption *option,
2627 const QWidget *widget) const
2629 Q_D(const QGtkStyle);
2631 if (!d->isThemeAvailable()) {
2632 QWindowsStyle::drawControl(element, option, painter, widget);
2636 GtkStyle* style = d->gtkStyle();
2637 QGtkPainter gtkPainter(painter);
2640 case CE_ProgressBarLabel:
2641 if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2642 GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
2643 if (!gtkProgressBar)
2647 QRect rect = bar->rect;
2648 GdkColor gdkText = gtkProgressBar->style->fg[GTK_STATE_NORMAL];
2649 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2650 gdkText = gtkProgressBar->style->fg[GTK_STATE_PRELIGHT];
2651 QColor alternateTextColor= QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2654 bool vertical = false, inverted = false;
2655 if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
2656 vertical = (bar2->orientation == Qt::Vertical);
2657 inverted = bar2->invertedAppearance;
2660 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
2661 const int progressIndicatorPos = (bar->progress - qreal(bar->minimum)) * rect.width() /
2662 qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum);
2663 if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width())
2664 leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
2666 leftRect.translate(rect.width() - progressIndicatorPos, 0);
2668 bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted) ||
2669 ((bar->direction == Qt::LeftToRight) && inverted)));
2671 QRegion rightRect = rect;
2672 rightRect = rightRect.subtracted(leftRect);
2673 painter->setClipRegion(rightRect);
2674 painter->setPen(flip ? alternateTextColor : textColor);
2675 painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
2676 if (!leftRect.isNull()) {
2677 painter->setPen(flip ? textColor : alternateTextColor);
2678 painter->setClipRect(leftRect);
2679 painter->drawText(rect, bar->text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
2684 case CE_PushButtonLabel:
2685 if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2686 QRect ir = button->rect;
2687 uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
2690 if (option->state & State_Sunken)
2691 buttonShift = QPoint(pixelMetric(PM_ButtonShiftHorizontal, option, widget),
2692 proxy()->pixelMetric(PM_ButtonShiftVertical, option, widget));
2694 if (proxy()->styleHint(SH_UnderlineShortcut, button, widget))
2695 tf |= Qt::TextShowMnemonic;
2697 tf |= Qt::TextHideMnemonic;
2699 if (!button->icon.isNull()) {
2700 //Center both icon and text
2703 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
2704 if (mode == QIcon::Normal && button->state & State_HasFocus)
2705 mode = QIcon::Active;
2707 QIcon::State state = QIcon::Off;
2709 if (button->state & State_On)
2712 QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state);
2713 int w = pixmap.width();
2714 int h = pixmap.height();
2716 if (!button->text.isEmpty())
2717 w += button->fontMetrics.boundingRect(option->rect, tf, button->text).width() + 4;
2719 point = QPoint(ir.x() + ir.width() / 2 - w / 2,
2720 ir.y() + ir.height() / 2 - h / 2);
2722 if (button->direction == Qt::RightToLeft)
2723 point.rx() += pixmap.width();
2725 painter->drawPixmap(visualPos(button->direction, button->rect, point + buttonShift), pixmap);
2727 if (button->direction == Qt::RightToLeft)
2728 ir.translate(-point.x() - 2, 0);
2730 ir.translate(point.x() + pixmap.width() + 2, 0);
2732 // left-align text if there is
2733 if (!button->text.isEmpty())
2734 tf |= Qt::AlignLeft;
2737 tf |= Qt::AlignHCenter;
2740 ir.translate(buttonShift);
2742 if (button->features & QStyleOptionButton::HasMenu)
2743 ir = ir.adjusted(0, 0, -pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
2745 GtkWidget *gtkButton = d->gtkWidget("GtkButton");
2746 QPalette pal = button->palette;
2747 int labelState = GTK_STATE_INSENSITIVE;
2748 if (option->state & State_Enabled)
2749 labelState = (option->state & State_MouseOver && !(option->state & State_Sunken)) ?
2750 GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
2752 GdkColor gdkText = gtkButton->style->fg[labelState];
2753 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2754 pal.setBrush(QPalette::ButtonText, textColor);
2755 proxy()->drawItemText(painter, ir, tf, pal, (button->state & State_Enabled),
2756 button->text, QPalette::ButtonText);
2760 case CE_RadioButton: // Fall through
2762 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2763 bool isRadio = (element == CE_RadioButton);
2765 // Draw prelight background
2766 GtkWidget *gtkRadioButton = d->gtkWidget("GtkRadioButton");
2768 if (option->state & State_MouseOver) {
2769 gtkPainter.paintFlatBox(gtkRadioButton, "checkbutton", option->rect,
2770 GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkRadioButton->style);
2773 QStyleOptionButton subopt = *btn;
2774 subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator
2775 : SE_CheckBoxIndicator, btn, widget);
2776 proxy()->drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox,
2777 &subopt, painter, widget);
2778 subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents
2779 : SE_CheckBoxContents, btn, widget);
2780 // Get label text color
2781 QPalette pal = subopt.palette;
2782 int labelState = GTK_STATE_INSENSITIVE;
2783 if (option->state & State_Enabled)
2784 labelState = (option->state & State_MouseOver) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
2786 GdkColor gdkText = gtkRadioButton->style->fg[labelState];
2787 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2788 pal.setBrush(QPalette::WindowText, textColor);
2789 subopt.palette = pal;
2790 proxy()->drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, painter, widget);
2792 if (btn->state & State_HasFocus) {
2793 QStyleOptionFocusRect fropt;
2794 fropt.QStyleOption::operator=(*btn);
2795 fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect
2796 : SE_CheckBoxFocusRect, btn, widget);
2797 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
2802 #ifndef QT_NO_COMBOBOX
2804 case CE_ComboBoxLabel:
2805 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
2806 QRect editRect = proxy()->subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
2807 bool appearsAsList = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, cb, widget);
2809 painter->setClipRect(editRect);
2811 if (!cb->currentIcon.isNull()) {
2812 QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
2814 QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
2815 QRect iconRect(editRect);
2816 iconRect.setWidth(cb->iconSize.width() + 4);
2818 iconRect = alignedRect(cb->direction,
2819 Qt::AlignLeft | Qt::AlignVCenter,
2820 iconRect.size(), editRect);
2823 painter->fillRect(iconRect, option->palette.brush(QPalette::Base));
2825 proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
2827 if (cb->direction == Qt::RightToLeft)
2828 editRect.translate(-4 - cb->iconSize.width(), 0);
2830 editRect.translate(cb->iconSize.width() + 4, 0);
2833 if (!cb->currentText.isEmpty() && !cb->editable) {
2834 GtkWidget *gtkCombo = d->gtkWidget("GtkComboBox");
2835 QPalette pal = cb->palette;
2836 int labelState = GTK_STATE_INSENSITIVE;
2838 if (option->state & State_Enabled)
2839 labelState = (option->state & State_MouseOver && !appearsAsList) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
2841 GdkColor gdkText = gtkCombo->style->fg[labelState];
2843 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2845 pal.setBrush(QPalette::ButtonText, textColor);
2847 proxy()->drawItemText(painter, editRect.adjusted(1, 0, -1, 0),
2848 visualAlignment(cb->direction, Qt::AlignLeft | Qt::AlignVCenter),
2849 pal, cb->state & State_Enabled, cb->currentText, QPalette::ButtonText);
2856 #endif // QT_NO_COMBOBOX
2858 case CE_DockWidgetTitle:
2860 if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) {
2861 const QStyleOptionDockWidgetV2 *v2
2862 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(dwOpt);
2863 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
2865 QRect rect = dwOpt->rect;
2866 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget).adjusted(-2, 0, -2, 0);
2867 QRect r = rect.adjusted(0, 0, -1, -1);
2868 if (verticalTitleBar)
2869 r.adjust(0, 0, 0, -1);
2871 if (verticalTitleBar) {
2877 titleRect = QRect(r.left() + rect.bottom()
2878 - titleRect.bottom(),
2879 r.top() + titleRect.left() - rect.left(),
2880 titleRect.height(), titleRect.width());
2882 painter->translate(r.left(), r.top() + r.width());
2883 painter->rotate(-90);
2884 painter->translate(-r.left(), -r.top());
2889 if (!dwOpt->title.isEmpty()) {
2891 = painter->fontMetrics().elidedText(dwOpt->title,
2892 Qt::ElideRight, titleRect.width());
2893 proxy()->drawItemText(painter,
2895 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette,
2896 dwOpt->state & State_Enabled, titleText,
2897 QPalette::WindowText);
2905 case CE_HeaderSection:
2908 // Draws the header in tables.
2909 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
2911 GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView");
2912 // Get the middle column
2913 GtkTreeViewColumn *column = d->gtk_tree_view_get_column((GtkTreeView*)gtkTreeView, 1);
2916 GtkWidget *gtkTreeHeader = column->button;
2917 GtkStateType state = gtkPainter.gtkState(option);
2918 GtkShadowType shadow = GTK_SHADOW_OUT;
2920 if (option->state & State_Sunken)
2921 shadow = GTK_SHADOW_IN;
2923 gtkPainter.paintBox(gtkTreeHeader, "button", option->rect.adjusted(-1, 0, 0, 0), state, shadow, gtkTreeHeader->style);
2929 #ifndef QT_NO_SIZEGRIP
2932 GtkWidget *gtkStatusbar = d->gtkWidget("GtkStatusbar.GtkFrame");
2933 QRect gripRect = option->rect.adjusted(0, 0, -gtkStatusbar->style->xthickness, -gtkStatusbar->style->ythickness);
2934 gtkPainter.paintResizeGrip( gtkStatusbar, "statusbar", gripRect, GTK_STATE_NORMAL,
2935 GTK_SHADOW_OUT, QApplication::isRightToLeft() ?
2936 GDK_WINDOW_EDGE_SOUTH_WEST : GDK_WINDOW_EDGE_SOUTH_EAST,
2937 gtkStatusbar->style);
2941 #endif // QT_NO_SIZEGRIP
2943 case CE_MenuBarEmptyArea: {
2944 GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
2945 GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
2946 painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
2947 if (widget) { // See CE_MenuBarItem
2948 QRect menuBarRect = widget->rect();
2949 QPixmap pixmap(menuBarRect.size());
2950 pixmap.fill(Qt::transparent);
2951 QPainter pmPainter(&pixmap);
2952 QGtkPainter gtkMenuBarPainter(&pmPainter);
2953 GtkShadowType shadow_type;
2954 d->gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL);
2955 gtkMenuBarPainter.paintBox( gtkMenubar, "menubar", menuBarRect,
2956 GTK_STATE_NORMAL, shadow_type, gtkMenubar->style);
2958 painter->drawPixmap(option->rect, pixmap, option->rect);
2963 case CE_MenuBarItem:
2966 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
2967 GtkWidget *gtkMenubarItem = d->gtkWidget("GtkMenuBar.GtkMenuItem");
2968 GtkWidget *gtkMenubar = d->gtkWidget("GtkMenuBar");
2970 style = gtkMenubarItem->style;
2973 // Since Qt does not currently allow filling the entire background
2974 // we use a hack for this by making a complete menubar each time and
2975 // paint with the correct offset inside it. Pixmap caching should resolve
2976 // most of the performance penalty.
2977 QRect menuBarRect = widget->rect();
2978 QPixmap pixmap(menuBarRect.size());
2979 pixmap.fill(Qt::transparent);
2980 QPainter pmPainter(&pixmap);
2981 QGtkPainter menubarPainter(&pmPainter);
2982 GtkShadowType shadow_type;
2983 d->gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL);
2984 GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
2985 painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
2986 menubarPainter.paintBox(gtkMenubar, "menubar", menuBarRect,
2987 GTK_STATE_NORMAL, shadow_type, gtkMenubar->style);
2989 painter->drawPixmap(option->rect, pixmap, option->rect);
2992 QStyleOptionMenuItem item = *mbi;
2993 bool act = mbi->state & State_Selected && mbi->state & State_Sunken;
2994 bool dis = !(mbi->state & State_Enabled);
2995 item.rect = mbi->rect;
2996 GdkColor gdkText = gtkMenubarItem->style->fg[dis ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL];
2997 GdkColor gdkHText = gtkMenubarItem->style->fg[GTK_STATE_PRELIGHT];
2998 QColor normalTextColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
2999 QColor highlightedTextColor = QColor(gdkHText.red>>8, gdkHText.green>>8, gdkHText.blue>>8);
3000 item.palette.setBrush(QPalette::HighlightedText, highlightedTextColor);
3001 item.palette.setBrush(QPalette::Text, normalTextColor);
3002 item.palette.setBrush(QPalette::ButtonText, normalTextColor);
3003 QCommonStyle::drawControl(element, &item, painter, widget);
3006 GtkShadowType shadowType = GTK_SHADOW_NONE;
3007 d->gtk_widget_style_get (gtkMenubarItem, "selected-shadow-type", &shadowType, NULL);
3008 gtkPainter.paintBox(gtkMenubarItem, "menuitem", option->rect.adjusted(0, 0, 0, 3),
3009 GTK_STATE_PRELIGHT, shadowType, gtkMenubarItem->style);
3011 QPalette::ColorRole textRole = dis ? QPalette::Text : QPalette::HighlightedText;
3012 uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
3014 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
3015 alignment |= Qt::TextHideMnemonic;
3017 proxy()->drawItemText(painter, item.rect, alignment, item.palette, mbi->state & State_Enabled, mbi->text, textRole);
3024 GtkWidget *gtkWindow = d->gtkWidget("GtkWindow"); // The Murrine Engine currently assumes a widget is passed
3025 gtkPainter.paintHandle(gtkWindow, "splitter", option->rect, gtkPainter.gtkState(option), GTK_SHADOW_NONE,
3026 !(option->state & State_Horizontal) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL,
3031 #ifndef QT_NO_TOOLBAR
3034 if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) {
3035 // Reserve the beveled appearance only for mainwindow toolbars
3036 if (!(widget && qobject_cast<const QMainWindow*> (widget->parentWidget())))
3039 QRect rect = option->rect;
3040 // There is a 1 pixel gap between toolbar lines in some styles (i.e Human)
3041 if (toolbar->positionWithinLine != QStyleOptionToolBar::End)
3042 rect.adjust(0, 0, 1, 0);
3044 GtkWidget *gtkToolbar = d->gtkWidget("GtkToolbar");
3045 GtkShadowType shadow_type = GTK_SHADOW_NONE;
3046 d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
3047 gtkPainter.paintBox( gtkToolbar, "toolbar", rect,
3048 GTK_STATE_NORMAL, shadow_type, gtkToolbar->style);
3052 #endif // QT_NO_TOOLBAR
3057 // Draws one item in a popup menu.
3058 if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
3059 const int windowsItemFrame = 2; // menu item frame width
3060 const int windowsItemHMargin = 3; // menu item hor text margin
3061 const int windowsItemVMargin = 26; // menu item ver text margin
3062 const int windowsRightBorder = 15; // right border on windows
3063 GtkWidget *gtkMenuItem = menuItem->checked ? d->gtkWidget("GtkMenu.GtkCheckMenuItem") :
3064 d->gtkWidget("GtkMenu.GtkMenuItem");
3066 style = gtkPainter.getStyle(gtkMenuItem);
3067 QColor shadow = option->palette.dark().color();
3069 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
3070 GtkWidget *gtkMenuSeparator = d->gtkWidget("GtkMenu.GtkSeparatorMenuItem");
3071 painter->setPen(shadow.lighter(106));
3072 gboolean wide_separators = 0;
3073 gint separator_height = 0;
3074 guint horizontal_padding = 3;
3075 QRect separatorRect = option->rect;
3076 if (!d->gtk_check_version(2, 10, 0)) {
3077 d->gtk_widget_style_get(gtkMenuSeparator,
3078 "wide-separators", &wide_separators,
3079 "separator-height", &separator_height,
3080 "horizontal-padding", &horizontal_padding,
3083 separatorRect.setHeight(option->rect.height() - 2 * gtkMenuSeparator->style->ythickness);
3084 separatorRect.setWidth(option->rect.width() - 2 * (horizontal_padding + gtkMenuSeparator->style->xthickness));
3085 separatorRect.moveCenter(option->rect.center());
3086 if (wide_separators)
3087 gtkPainter.paintBox( gtkMenuSeparator, "hseparator",
3088 separatorRect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, gtkMenuSeparator->style);
3090 gtkPainter.paintHline( gtkMenuSeparator, "hseparator",
3091 separatorRect, GTK_STATE_NORMAL, gtkMenuSeparator->style,
3092 0, option->rect.right() - 1, 1);
3097 bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
3100 QRect rect = option->rect;
3101 #ifndef QT_NO_COMBOBOX
3102 if (qobject_cast<const QComboBox*>(widget))
3103 rect = option->rect;
3105 gtkPainter.paintBox( gtkMenuItem, "menuitem", rect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style);
3108 bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
3109 bool checked = menuItem->checked;
3110 bool enabled = menuItem->state & State_Enabled;
3111 bool ignoreCheckMark = false;
3114 d->gtk_widget_style_get(d->gtkWidget("GtkMenu.GtkCheckMenuItem"), "indicator-size", &checkSize, NULL);
3116 int checkcol = qMax(menuItem->maxIconWidth, qMax(20, checkSize));
3118 #ifndef QT_NO_COMBOBOX
3120 if (qobject_cast<const QComboBox*>(widget))
3121 ignoreCheckMark = true; // Ignore the checkmarks provided by the QComboMenuDelegate
3124 if (!ignoreCheckMark) {
3126 QRect checkRect(option->rect.left() + 7, option->rect.center().y() - checkSize/2 + 1, checkSize, checkSize);
3127 checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
3129 if (checkable && menuItem->icon.isNull()) {
3130 // Some themes such as aero-clone draw slightly outside the paint rect
3131 int spacing = 1; // ### Consider using gtkCheckBox : "indicator-spacing" instead
3133 if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) {
3135 GtkShadowType shadow = GTK_SHADOW_OUT;
3136 GtkStateType state = gtkPainter.gtkState(option);
3139 state = GTK_STATE_PRELIGHT;
3141 shadow = GTK_SHADOW_IN;
3143 gtkPainter.setClipRect(checkRect.adjusted(-spacing, -spacing, spacing, spacing));
3144 gtkPainter.paintOption(gtkMenuItem, checkRect.translated(-spacing, -spacing), state, shadow,
3145 gtkMenuItem->style, QLS("option"));
3146 gtkPainter.setClipRect(QRect());
3150 if (menuItem->icon.isNull()) {
3151 GtkShadowType shadow = GTK_SHADOW_OUT;
3152 GtkStateType state = gtkPainter.gtkState(option);
3155 state = GTK_STATE_PRELIGHT;
3157 shadow = GTK_SHADOW_IN;
3159 gtkPainter.setClipRect(checkRect.adjusted(-spacing, -spacing, -spacing, -spacing));
3160 gtkPainter.paintCheckbox(gtkMenuItem, checkRect.translated(-spacing, -spacing), state, shadow,
3161 gtkMenuItem->style, QLS("check"));
3162 gtkPainter.setClipRect(QRect());
3169 if (menuItem->icon.isNull())
3172 checkcol = menuItem->maxIconWidth;
3175 bool dis = !(menuItem->state & State_Enabled);
3176 bool act = menuItem->state & State_Selected;
3177 const QStyleOption *opt = option;
3178 const QStyleOptionMenuItem *menuitem = menuItem;
3179 QPainter *p = painter;
3180 QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
3181 QRect(menuitem->rect.x() + 3, menuitem->rect.y(),
3182 checkcol, menuitem->rect.height()));
3184 if (!menuItem->icon.isNull()) {
3185 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
3188 mode = QIcon::Active;
3191 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
3192 QSize iconSize(smallIconSize, smallIconSize);
3194 #ifndef QT_NO_COMBOBOX
3195 if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget))
3196 iconSize = combo->iconSize();
3198 #endif // QT_NO_COMBOBOX
3200 pixmap = menuItem->icon.pixmap(iconSize, mode, QIcon::On);
3202 pixmap = menuItem->icon.pixmap(iconSize, mode);
3204 int pixw = pixmap.width();
3205 int pixh = pixmap.height();
3206 QRect pmr(0, 0, pixw, pixh);
3207 pmr.moveCenter(vCheckRect.center() - QPoint(0, 1));
3208 painter->setPen(menuItem->palette.text().color());
3209 if (!ignoreCheckMark && checkable && checked) {
3210 QStyleOption opt = *option;
3213 QColor activeColor = mergedColors(option->palette.background().color(),
3214 option->palette.highlight().color());
3215 opt.palette.setBrush(QPalette::Button, activeColor);
3217 opt.state |= State_Sunken;
3218 opt.rect = vCheckRect;
3219 proxy()->drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget);
3221 painter->drawPixmap(pmr.topLeft(), pixmap);
3224 GdkColor gdkText = gtkMenuItem->style->fg[GTK_STATE_NORMAL];
3225 GdkColor gdkDText = gtkMenuItem->style->fg[GTK_STATE_INSENSITIVE];
3226 GdkColor gdkHText = gtkMenuItem->style->fg[GTK_STATE_PRELIGHT];
3227 uint resolve_mask = option->palette.resolve();
3228 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
3229 QColor disabledTextColor = QColor(gdkDText.red>>8, gdkDText.green>>8, gdkDText.blue>>8);
3230 if (resolve_mask & (1 << QPalette::ButtonText)) {
3231 textColor = option->palette.buttonText().color();
3232 disabledTextColor = option->palette.brush(QPalette::Disabled, QPalette::ButtonText).color();
3235 QColor highlightedTextColor = QColor(gdkHText.red>>8, gdkHText.green>>8, gdkHText.blue>>8);
3236 if (resolve_mask & (1 << QPalette::HighlightedText)) {
3237 highlightedTextColor = option->palette.highlightedText().color();
3241 painter->setPen(highlightedTextColor);
3243 painter->setPen(textColor);
3246 menuitem->rect.getRect(&x, &y, &w, &h);
3247 int tab = menuitem->tabWidth;
3248 int xm = windowsItemFrame + checkcol + windowsItemHMargin;
3249 int xpos = menuitem->rect.x() + xm + 1;
3250 QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
3251 QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
3252 QString s = menuitem->text;
3254 if (!s.isEmpty()) { // Draw text
3256 int t = s.indexOf(QLatin1Char('\t'));
3257 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
3259 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
3260 text_flags |= Qt::TextHideMnemonic;
3262 // Draw shortcut right aligned
3263 text_flags |= Qt::AlignRight;
3266 int rightMargin = 12; // Hardcode for now
3267 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
3268 QRect(textRect.topRight(), QPoint(menuitem->rect.right() - rightMargin, textRect.bottom())));
3271 p->setPen(disabledTextColor);
3272 p->drawText(vShortcutRect, text_flags , s.mid(t + 1));
3276 text_flags &= ~Qt::AlignRight;
3277 text_flags |= Qt::AlignLeft;
3278 QFont font = menuitem->font;
3279 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
3284 p->setPen(disabledTextColor);
3285 p->drawText(vTextRect, text_flags, s.left(t));
3290 if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
3292 QFontMetrics fm(menuitem->font);
3293 int arrow_size = fm.ascent() + fm.descent() - 2 * gtkMenuItem->style->ythickness;
3294 gfloat arrow_scaling = 0.8;
3296 if (!d->gtk_check_version(2, 16, 0)) {
3297 // "arrow-scaling" is actually hardcoded and fails on hardy (see gtk+-2.12/gtkmenuitem.c)
3298 // though the current documentation states otherwise
3299 d->gtk_widget_style_get(gtkMenuItem, "arrow-scaling", &arrow_scaling, NULL);
3300 // in versions < 2.16 ythickness was previously subtracted from the arrow_size
3301 extra = 2 * gtkMenuItem->style->ythickness;
3304 int horizontal_padding;
3305 d->gtk_widget_style_get(gtkMenuItem, "horizontal-padding", &horizontal_padding, NULL);
3307 const int dim = static_cast<int>(arrow_size * arrow_scaling) + extra;
3308 int xpos = menuItem->rect.left() + menuItem->rect.width() - horizontal_padding - dim;
3309 QRect vSubMenuRect = visualRect(option->direction, menuItem->rect,
3310 QRect(xpos, menuItem->rect.top() +
3311 menuItem->rect.height() / 2 - dim / 2, dim, dim));
3312 GtkStateType state = enabled ? (act ? GTK_STATE_PRELIGHT: GTK_STATE_NORMAL) : GTK_STATE_INSENSITIVE;
3313 GtkShadowType shadowType = (state == GTK_STATE_PRELIGHT) ? GTK_SHADOW_OUT : GTK_SHADOW_IN;
3314 gtkPainter.paintArrow(gtkMenuItem, "menuitem", vSubMenuRect, QApplication::isRightToLeft() ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT, state,
3315 shadowType, false, style);
3322 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
3323 GtkWidget *gtkButton = d->gtkWidget("GtkButton");
3324 proxy()->drawControl(CE_PushButtonBevel, btn, painter, widget);
3325 QStyleOptionButton subopt = *btn;
3326 subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
3327 gint interiorFocus = true;
3328 d->gtk_widget_style_get(gtkButton, "interior-focus", &interiorFocus, NULL);
3329 int xt = interiorFocus ? gtkButton->style->xthickness : 0;
3330 int yt = interiorFocus ? gtkButton->style->ythickness : 0;
3332 if (btn->features & QStyleOptionButton::Flat && btn->state & State_HasFocus)
3333 // The normal button focus rect does not work well for flat buttons in Clearlooks
3334 proxy()->drawPrimitive(PE_FrameFocusRect, option, painter, widget);
3335 else if (btn->state & State_HasFocus)
3336 gtkPainter.paintFocus(gtkButton, "button",
3337 option->rect.adjusted(xt, yt, -xt, -yt),
3338 btn->state & State_Sunken ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL,
3341 proxy()->drawControl(CE_PushButtonLabel, &subopt, painter, widget);
3345 #ifndef QT_NO_TABBAR
3347 case CE_TabBarTabShape:
3348 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
3349 GtkWidget *gtkNotebook = d->gtkWidget("GtkNotebook");
3350 style = gtkPainter.getStyle(gtkNotebook);
3352 QRect rect = option->rect;
3353 GtkShadowType shadow = GTK_SHADOW_OUT;
3354 GtkStateType state = GTK_STATE_ACTIVE;
3355 if (tab->state & State_Selected)
3356 state = GTK_STATE_NORMAL;
3358 bool selected = (tab->state & State_Selected);
3359 bool first = false, last = false;
3361 // This is most accurate and avoids resizing tabs while moving
3362 first = tab->rect.left() == widget->rect().left();
3363 last = tab->rect.right() == widget->rect().right();
3364 } else if (option->direction == Qt::RightToLeft) {
3370 int bottomIndent = 1;
3374 switch (tab->shape) {
3375 case QTabBar::RoundedNorth:
3377 rect.adjust(first ? 0 : -tabOverlap, topIndent, last ? 0 : tabOverlap, -bottomIndent);
3378 gtkPainter.paintExtention( gtkNotebook, "tab", rect,
3379 state, shadow, GTK_POS_BOTTOM, style);
3382 case QTabBar::RoundedSouth:
3384 rect.adjust(first ? 0 : -tabOverlap, 0, last ? 0 : tabOverlap, -topIndent);
3385 gtkPainter.paintExtention( gtkNotebook, "tab", rect.adjusted(0, 1, 0, 0),
3386 state, shadow, GTK_POS_TOP, style);
3389 case QTabBar::RoundedWest:
3391 rect.adjust(topIndent, 0, -bottomIndent, 0);
3392 gtkPainter.paintExtention( gtkNotebook, "tab", rect, state, shadow, GTK_POS_RIGHT, style);
3395 case QTabBar::RoundedEast:
3397 rect.adjust(bottomIndent, 0, -topIndent, 0);
3398 gtkPainter.paintExtention( gtkNotebook, "tab", rect, state, shadow, GTK_POS_LEFT, style);
3402 QWindowsStyle::drawControl(element, option, painter, widget);
3411 #endif //QT_NO_TABBAR
3413 case CE_ProgressBarGroove:
3414 if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
3416 GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
3417 GtkStateType state = gtkPainter.gtkState(option);
3418 gtkPainter.paintBox( gtkProgressBar, "trough", option->rect, state, GTK_SHADOW_IN, gtkProgressBar->style);
3423 case CE_ProgressBarContents:
3424 if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
3425 GtkStateType state = option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE;
3426 GtkWidget *gtkProgressBar = d->gtkWidget("GtkProgressBar");
3427 style = gtkProgressBar->style;
3428 gtkPainter.paintBox( gtkProgressBar, "trough", option->rect, state, GTK_SHADOW_IN, style);
3429 int xt = style->xthickness;
3430 int yt = style->ythickness;
3431 QRect rect = bar->rect.adjusted(xt, yt, -xt, -yt);
3432 bool vertical = false;
3433 bool inverted = false;
3434 bool indeterminate = (bar->minimum == 0 && bar->maximum == 0);
3435 // Get extra style options if version 2
3437 if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
3438 vertical = (bar2->orientation == Qt::Vertical);
3439 inverted = bar2->invertedAppearance;
3442 // If the orientation is vertical, we use a transform to rotate
3443 // the progress bar 90 degrees clockwise. This way we can use the
3444 // same rendering code for both orientations.
3446 rect.translate(xt, -yt * 2);
3447 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // Flip width and height
3448 QTransform m = QTransform::fromTranslate(rect.height(), 0);
3450 painter->setTransform(m);
3453 int maxWidth = rect.width();
3456 qint64 progress = (qint64)qMax(bar->progress, bar->minimum); // Workaround for bug in QProgressBar
3457 double vc6_workaround = ((progress - qint64(bar->minimum)) / double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth;
3458 int progressBarWidth = (int(vc6_workaround) > minWidth ) ? int(vc6_workaround) : minWidth;
3459 int width = indeterminate ? maxWidth : progressBarWidth;
3460 bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical;
3467 if (bar->minimum == bar->maximum)
3469 if (bar->progress == bar->maximum)
3471 else if (bar->progress > bar->minimum)
3472 fakePos = maximum - 1;
3474 d->gtk_progress_configure((GtkProgress*)gtkProgressBar, fakePos, 0, maximum);
3478 if (!indeterminate) {
3480 progressBar.setRect(rect.left(), rect.top(), width, rect.height());
3482 progressBar.setRect(rect.right() - width, rect.top(), width, rect.height());
3485 Q_D(const QGtkStyle);
3486 int slideWidth = ((rect.width() - 4) * 2) / 3;
3487 int step = ((d->animateStep * slideWidth) / d->animationFps) % slideWidth;
3488 if ((((d->animateStep * slideWidth) / d->animationFps) % (2 * slideWidth)) >= slideWidth)
3489 step = slideWidth - step;
3490 progressBar.setRect(rect.left() + step, rect.top(), slideWidth / 2, rect.height());
3493 QString key = QString(QLS("%0")).arg(fakePos);
3495 key += QLatin1String("inv");
3496 gtkPainter.setFlipHorizontal(true);
3498 gtkPainter.paintBox( gtkProgressBar, "bar", progressBar, GTK_STATE_SELECTED, GTK_SHADOW_OUT, style, key);
3504 QWindowsStyle::drawControl(element, option, painter, widget);
3511 QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
3512 SubControl subControl, const QWidget *widget) const
3514 Q_D(const QGtkStyle);
3516 QRect rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
3517 if (!d->isThemeAvailable())
3518 return QWindowsStyle::subControlRect(control, option, subControl, widget);
3524 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3525 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
3526 switch (subControl) {
3527 case SC_SliderHandle: {
3528 if (slider->orientation == Qt::Horizontal) {
3529 rect.setHeight(proxy()->pixelMetric(PM_SliderThickness));
3530 rect.setWidth(proxy()->pixelMetric(PM_SliderLength));
3531 int centerY = slider->rect.center().y() - rect.height() / 2;
3532 if (slider->tickPosition & QSlider::TicksAbove)
3533 centerY += tickSize;
3534 if (slider->tickPosition & QSlider::TicksBelow)
3535 centerY -= tickSize;
3536 rect.moveTop(centerY);
3538 rect.setWidth(proxy()->pixelMetric(PM_SliderThickness));
3539 rect.setHeight(proxy()->pixelMetric(PM_SliderLength));
3540 int centerX = slider->rect.center().x() - rect.width() / 2;
3541 if (slider->tickPosition & QSlider::TicksAbove)
3542 centerX += tickSize;
3543 if (slider->tickPosition & QSlider::TicksBelow)
3544 centerX -= tickSize;
3545 rect.moveLeft(centerX);
3549 case SC_SliderGroove: {
3550 QPoint grooveCenter = slider->rect.center();
3551 if (slider->orientation == Qt::Horizontal) {
3553 if (slider->tickPosition & QSlider::TicksAbove)
3554 grooveCenter.ry() += tickSize;
3555 if (slider->tickPosition & QSlider::TicksBelow)
3556 grooveCenter.ry() -= tickSize;
3559 if (slider->tickPosition & QSlider::TicksAbove)
3560 grooveCenter.rx() += tickSize;
3561 if (slider->tickPosition & QSlider::TicksBelow)
3562 grooveCenter.rx() -= tickSize;
3564 rect.moveCenter(grooveCenter);
3573 #ifndef QT_NO_GROUPBOX
3576 if (qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
3577 rect = option->rect.adjusted(0, groupBoxTopMargin, 0, -groupBoxBottomMargin);
3581 QRect frameRect = rect;
3582 frameRect.setTop(topMargin);
3584 if (subControl == SC_GroupBoxFrame)
3586 else if (subControl == SC_GroupBoxContents) {
3588 int leftMarginExtension = 8;
3589 return frameRect.adjusted(leftMarginExtension + margin, margin + topHeight + groupBoxTitleMargin, -margin, -margin);
3592 if (const QGroupBox *groupBoxWidget = qobject_cast<const QGroupBox *>(widget)) {
3593 //Prepare metrics for a bold font
3594 QFont font = widget->font();
3596 QFontMetrics fontMetrics(font);
3597 QSize textRect = fontMetrics.boundingRect(groupBoxWidget->title()).size() + QSize(4, 4);
3598 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, option, widget);
3599 int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, option, widget);
3601 if (subControl == SC_GroupBoxCheckBox) {
3602 rect.setWidth(indicatorWidth);
3603 rect.setHeight(indicatorHeight);
3604 rect.moveTop((textRect.height() - indicatorHeight) / 2);
3606 } else if (subControl == SC_GroupBoxLabel) {
3607 if (groupBoxWidget->isCheckable())
3608 rect.adjust(indicatorWidth + 4, 0, 0, 0);
3609 rect.setSize(textRect);
3611 rect = visualRect(option->direction, option->rect, rect);
3618 #ifndef QT_NO_SPINBOX
3621 if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
3622 GtkWidget *gtkSpinButton = d->gtkWidget("GtkSpinButton");
3623 int center = spinbox->rect.height() / 2;
3624 int xt = spinbox->frame ? gtkSpinButton->style->xthickness : 0;
3625 int yt = spinbox->frame ? gtkSpinButton->style->ythickness : 0;
3629 bs.setHeight(qMax(8, spinbox->rect.height()/2 - y));
3630 bs.setWidth(d->getSpinboxArrowSize());
3632 x = spinbox->rect.width() - y - bs.width() + 2;
3636 switch (subControl) {
3639 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
3641 rect = QRect(x, xt, bs.width(), center - yt);
3644 case SC_SpinBoxDown:
3645 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
3647 rect = QRect(x, center, bs.width(), spinbox->rect.bottom() - center - yt + 1);
3650 case SC_SpinBoxEditField:
3651 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
3652 rect = QRect(lx, yt, spinbox->rect.width() - 2*xt, spinbox->rect.height() - 2*yt);
3654 rect = QRect(lx, yt, rx - qMax(xt - 1, 0), spinbox->rect.height() - 2*yt);
3657 case SC_SpinBoxFrame:
3658 rect = spinbox->rect;
3664 rect = visualRect(spinbox->direction, spinbox->rect, rect);
3669 #endif // Qt_NO_SPINBOX
3670 #ifndef QT_NO_COMBOBOX
3673 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
3674 SubControl sc = subControl;
3676 const int indent = 3;
3677 const int controlTopMargin = 3;
3678 const int controlBottomMargin = 3;
3679 const int controlWidthMargin = 2;
3680 const int controlHeight = tb->rect.height() - controlTopMargin - controlBottomMargin ;
3681 const int delta = controlHeight + controlWidthMargin;
3684 bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
3685 bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
3688 case SC_TitleBarLabel:
3689 if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
3691 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
3692 ret.adjust(delta, 0, -delta, 0);
3693 if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3694 ret.adjust(0, 0, -delta, 0);
3695 if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3696 ret.adjust(0, 0, -delta, 0);
3697 if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
3698 ret.adjust(0, 0, -delta, 0);
3699 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
3700 ret.adjust(0, 0, -delta, 0);
3703 case SC_TitleBarContextHelpButton:
3704 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
3706 case SC_TitleBarMinButton:
3707 if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
3709 else if (sc == SC_TitleBarMinButton)
3711 case SC_TitleBarNormalButton:
3712 if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
3714 else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
3716 else if (sc == SC_TitleBarNormalButton)
3718 case SC_TitleBarMaxButton:
3719 if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
3721 else if (sc == SC_TitleBarMaxButton)
3723 case SC_TitleBarShadeButton:
3724 if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
3726 else if (sc == SC_TitleBarShadeButton)
3728 case SC_TitleBarUnshadeButton:
3729 if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
3731 else if (sc == SC_TitleBarUnshadeButton)
3733 case SC_TitleBarCloseButton:
3734 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
3736 else if (sc == SC_TitleBarCloseButton)
3738 ret.setRect(tb->rect.right() - indent - offset, tb->rect.top() + controlTopMargin,
3739 controlHeight, controlHeight);
3741 case SC_TitleBarSysMenu:
3742 if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3743 ret.setRect(tb->rect.left() + controlWidthMargin + indent, tb->rect.top() + controlTopMargin,
3744 controlHeight, controlHeight);
3750 ret = visualRect(tb->direction, tb->rect, ret);
3754 if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3755 // We employ the gtk widget to position arrows and separators for us
3756 GtkWidget *gtkCombo = box->editable ? d->gtkWidget("GtkComboBoxEntry")
3757 : d->gtkWidget("GtkComboBox");
3758 d->gtk_widget_set_direction(gtkCombo, (option->direction == Qt::RightToLeft) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
3759 GtkAllocation geometry = {0, 0, qMax(0, option->rect.width()), qMax(0, option->rect.height())};
3760 d->gtk_widget_size_allocate(gtkCombo, &geometry);
3761 int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, option, widget);
3762 QHashableLatin1Literal arrowPath("GtkComboBoxEntry.GtkToggleButton");
3763 if (!box->editable) {
3764 if (appears_as_list)
3765 arrowPath = "GtkComboBox.GtkToggleButton";
3767 arrowPath = "GtkComboBox.GtkToggleButton.GtkHBox.GtkArrow";
3770 GtkWidget *arrowWidget = d->gtkWidget(arrowPath);
3772 return QWindowsStyle::subControlRect(control, option, subControl, widget);
3774 GtkAllocation allocation;
3775 d->gtk_widget_get_allocation(arrowWidget, &allocation);
3776 QRect buttonRect(option->rect.left() + allocation.x,
3777 option->rect.top() + allocation.y,
3778 allocation.width, allocation.height);
3780 switch (subControl) {
3782 case SC_ComboBoxArrow: // Note: this indicates the arrowbutton for editable combos
3786 case SC_ComboBoxEditField: {
3787 rect = visualRect(option->direction, option->rect, rect);
3788 int xMargin = box->editable ? 1 : 4, yMargin = 2;
3789 rect.setRect(option->rect.left() + gtkCombo->style->xthickness + xMargin,
3790 option->rect.top() + gtkCombo->style->ythickness + yMargin,
3791 option->rect.width() - buttonRect.width() - 2*(gtkCombo->style->xthickness + xMargin),
3792 option->rect.height() - 2*(gtkCombo->style->ythickness + yMargin));
3793 rect = visualRect(option->direction, option->rect, rect);
3803 #endif // QT_NO_COMBOBOX
3815 QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
3816 const QSize &size, const QWidget *widget) const
3818 Q_D(const QGtkStyle);
3820 QSize newSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
3821 if (!d->isThemeAvailable())
3826 // Since we use a bold font we have to recalculate base width
3827 if (const QGroupBox *gb = qobject_cast<const QGroupBox*>(widget)) {
3828 QFont font = gb->font();
3830 QFontMetrics metrics(font);
3831 int baseWidth = metrics.width(gb->title()) + metrics.width(QLatin1Char(' '));
3832 if (gb->isCheckable()) {
3833 baseWidth += proxy()->pixelMetric(QStyle::PM_IndicatorWidth, option, widget);
3834 baseWidth += proxy()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, option, widget);
3836 newSize.setWidth(qMax(baseWidth, newSize.width()));
3838 newSize += QSize(4, 1 + groupBoxBottomMargin + groupBoxTopMargin + groupBoxTitleMargin); // Add some space below the groupbox
3841 if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
3842 GtkWidget *gtkButton = d->gtkWidget("GtkToolButton.GtkButton");
3843 newSize = size + QSize(2 * gtkButton->style->xthickness, 2 + 2 * gtkButton->style->ythickness);
3844 if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
3845 QSize minSize(0, 25);
3846 if (toolbutton->toolButtonStyle != Qt::ToolButtonTextOnly)
3847 minSize = toolbutton->iconSize + QSize(12, 12);
3848 newSize = newSize.expandedTo(minSize);
3851 if (toolbutton->features & QStyleOptionToolButton::HasMenu)
3852 newSize += QSize(6, 0);
3856 if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
3859 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
3860 GtkWidget *gtkMenuSeparator = d->gtkWidget("GtkMenu.GtkSeparatorMenuItem");
3861 GtkRequisition sizeReq = {0, 0};
3862 d->gtk_widget_size_request(gtkMenuSeparator, &sizeReq);
3863 newSize = QSize(size.width(), sizeReq.height);
3867 GtkWidget *gtkMenuItem = d->gtkWidget("GtkMenu.GtkCheckMenuItem");
3868 GtkStyle* style = gtkMenuItem->style;
3870 // Note we get the perfect height for the default font since we
3871 // set a fake text label on the gtkMenuItem
3872 // But if custom fonts are used on the widget we need a minimum size
3873 GtkRequisition sizeReq = {0, 0};
3874 d->gtk_widget_size_request(gtkMenuItem, &sizeReq);
3875 newSize.setHeight(qMax(newSize.height() - 4, sizeReq.height));
3876 newSize += QSize(textMargin + style->xthickness - 1, 0);
3879 d->gtk_widget_style_get(gtkMenuItem, "indicator-size", &checkSize, NULL);
3880 newSize.setWidth(newSize.width() + qMax(0, checkSize - 20));
3884 // QSpinBox does some nasty things that depends on CT_LineEdit
3885 newSize = size + QSize(0, -d->gtkWidget("GtkSpinButton")->style->ythickness * 2);
3887 case CT_RadioButton:
3889 newSize += QSize(0, 1);
3892 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
3893 if (!btn->icon.isNull() && btn->iconSize.height() > 16)
3894 newSize -= QSize(0, 2); // From cleanlooksstyle
3895 newSize += QSize(0, 1);
3896 GtkWidget *gtkButton = d->gtkWidget("GtkButton");
3897 gint focusPadding, focusWidth;
3898 d->gtk_widget_style_get(gtkButton, "focus-padding", &focusPadding, NULL);
3899 d->gtk_widget_style_get(gtkButton, "focus-line-width", &focusWidth, NULL);
3901 newSize += QSize(2*gtkButton->style->xthickness + 4, 2*gtkButton->style->ythickness);
3902 newSize += QSize(2*(focusWidth + focusPadding + 2), 2*(focusWidth + focusPadding));
3904 GtkWidget *gtkButtonBox = d->gtkWidget("GtkHButtonBox");
3905 gint minWidth = 85, minHeight = 0;
3906 d->gtk_widget_style_get(gtkButtonBox, "child-min-width", &minWidth,
3907 "child-min-height", &minHeight, NULL);
3908 if (!btn->text.isEmpty() && newSize.width() < minWidth)
3909 newSize.setWidth(minWidth);
3910 if (newSize.height() < minHeight)
3911 newSize.setHeight(minHeight);
3915 GtkWidget *gtkSlider = d->gtkWidget("GtkHScale");
3916 newSize = size + QSize(2*gtkSlider->style->xthickness, 2*gtkSlider->style->ythickness); }
3919 GtkWidget *gtkEntry = d->gtkWidget("GtkEntry");
3920 newSize = size + QSize(2*gtkEntry->style->xthickness, 2 + 2*gtkEntry->style->ythickness); }
3922 case CT_ItemViewItem:
3923 newSize += QSize(0, 2);
3926 if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3927 GtkWidget *gtkCombo = d->gtkWidget("GtkComboBox");
3928 QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, combo, SC_ComboBoxArrow, widget);
3929 newSize = size + QSize(12 + arrowButtonRect.width() + 2*gtkCombo->style->xthickness, 4 + 2*gtkCombo->style->ythickness);
3931 if (!(widget && qobject_cast<QToolBar *>(widget->parentWidget())))
3932 newSize += QSize(0, 2);
3936 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
3937 if (!tab->icon.isNull())
3938 newSize += QSize(6, 0);
3940 newSize += QSize(1, 1);
3942 case CT_MenuBarItem:
3943 newSize += QSize(0, 2);
3946 newSize += QSize(4, 4);
3948 case CT_MdiControls:
3949 if (const QStyleOptionComplex *styleOpt = qstyleoption_cast<const QStyleOptionComplex *>(option)) {
3951 if (styleOpt->subControls & SC_MdiMinButton)
3953 if (styleOpt->subControls & SC_MdiNormalButton)
3955 if (styleOpt->subControls & SC_MdiCloseButton)
3957 newSize = QSize(width, 19);
3959 newSize = QSize(60, 19);
3971 QPixmap QGtkStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option,
3972 const QWidget *widget) const
3974 Q_D(const QGtkStyle);
3976 if (!d->isThemeAvailable())
3977 return QWindowsStyle::standardPixmap(sp, option, widget);
3982 case SP_TitleBarNormalButton: {
3983 QImage restoreButton((const char **)dock_widget_restore_xpm);
3984 QColor alphaCorner = restoreButton.color(2);
3985 alphaCorner.setAlpha(80);
3986 restoreButton.setColor(2, alphaCorner.rgba());
3987 alphaCorner.setAlpha(180);
3988 restoreButton.setColor(4, alphaCorner.rgba());
3989 return QPixmap::fromImage(restoreButton);
3993 case SP_TitleBarCloseButton: // Fall through
3994 case SP_DockWidgetCloseButton: {
3996 QImage closeButton((const char **)dock_widget_close_xpm);
3997 QColor alphaCorner = closeButton.color(2);
3998 alphaCorner.setAlpha(80);
3999 closeButton.setColor(2, alphaCorner.rgba());
4000 return QPixmap::fromImage(closeButton);
4004 case SP_DialogDiscardButton:
4005 return QGtkPainter::getIcon(GTK_STOCK_DELETE);
4006 case SP_DialogOkButton:
4007 return QGtkPainter::getIcon(GTK_STOCK_OK);
4008 case SP_DialogCancelButton:
4009 return QGtkPainter::getIcon(GTK_STOCK_CANCEL);
4010 case SP_DialogYesButton:
4011 return QGtkPainter::getIcon(GTK_STOCK_YES);
4012 case SP_DialogNoButton:
4013 return QGtkPainter::getIcon(GTK_STOCK_NO);
4014 case SP_DialogOpenButton:
4015 return QGtkPainter::getIcon(GTK_STOCK_OPEN);
4016 case SP_DialogCloseButton:
4017 return QGtkPainter::getIcon(GTK_STOCK_CLOSE);
4018 case SP_DialogApplyButton:
4019 return QGtkPainter::getIcon(GTK_STOCK_APPLY);
4020 case SP_DialogSaveButton:
4021 return QGtkPainter::getIcon(GTK_STOCK_SAVE);
4022 case SP_MessageBoxWarning:
4023 return QGtkPainter::getIcon(GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
4024 case SP_MessageBoxQuestion:
4025 return QGtkPainter::getIcon(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
4026 case SP_MessageBoxInformation:
4027 return QGtkPainter::getIcon(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
4028 case SP_MessageBoxCritical:
4029 return QGtkPainter::getIcon(GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
4031 return QWindowsStyle::standardPixmap(sp, option, widget);
4039 QIcon QGtkStyle::standardIcon(StandardPixmap standardIcon,
4040 const QStyleOption *option,
4041 const QWidget *widget) const
4043 Q_D(const QGtkStyle);
4045 if (!d->isThemeAvailable())
4046 return QWindowsStyle::standardIcon(standardIcon, option, widget);
4047 switch (standardIcon) {
4048 case SP_DialogDiscardButton:
4049 return QGtkPainter::getIcon(GTK_STOCK_DELETE);
4050 case SP_DialogOkButton:
4051 return QGtkPainter::getIcon(GTK_STOCK_OK);
4052 case SP_DialogCancelButton:
4053 return QGtkPainter::getIcon(GTK_STOCK_CANCEL);
4054 case SP_DialogYesButton:
4055 return QGtkPainter::getIcon(GTK_STOCK_YES);
4056 case SP_DialogNoButton:
4057 return QGtkPainter::getIcon(GTK_STOCK_NO);
4058 case SP_DialogOpenButton:
4059 return QGtkPainter::getIcon(GTK_STOCK_OPEN);
4060 case SP_DialogCloseButton:
4061 return QGtkPainter::getIcon(GTK_STOCK_CLOSE);
4062 case SP_DialogApplyButton:
4063 return QGtkPainter::getIcon(GTK_STOCK_APPLY);
4064 case SP_DialogSaveButton:
4065 return QGtkPainter::getIcon(GTK_STOCK_SAVE);
4066 case SP_MessageBoxWarning:
4067 return QGtkPainter::getIcon(GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
4068 case SP_MessageBoxQuestion:
4069 return QGtkPainter::getIcon(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
4070 case SP_MessageBoxInformation:
4071 return QGtkPainter::getIcon(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
4072 case SP_MessageBoxCritical:
4073 return QGtkPainter::getIcon(GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
4075 return QWindowsStyle::standardIcon(standardIcon, option, widget);
4081 QRect QGtkStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
4083 Q_D(const QGtkStyle);
4085 QRect r = QWindowsStyle::subElementRect(element, option, widget);
4086 if (!d->isThemeAvailable())
4090 case SE_PushButtonFocusRect:
4091 r.adjust(0, 1, 0, -1);
4093 case SE_DockWidgetTitleBarText: {
4094 const QStyleOptionDockWidgetV2 *v2
4095 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(option);
4096 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
4097 if (verticalTitleBar) {
4098 r.adjust(0, 0, 0, -4);
4100 if (option->direction == Qt::LeftToRight)
4101 r.adjust(4, 0, 0, 0);
4103 r.adjust(0, 0, -4, 0);
4108 case SE_ProgressBarLabel:
4109 case SE_ProgressBarContents:
4110 case SE_ProgressBarGroove:
4111 return option->rect;
4112 case SE_PushButtonContents:
4113 if (!d->gtk_check_version(2, 10, 0)) {
4114 GtkWidget *gtkButton = d->gtkWidget("GtkButton");
4115 GtkBorder *border = 0;
4116 d->gtk_widget_style_get(gtkButton, "inner-border", &border, NULL);
4118 r = option->rect.adjusted(border->left, border->top, -border->right, -border->bottom);
4119 d->gtk_border_free(border);
4121 r = option->rect.adjusted(1, 1, -1, -1);
4123 r = visualRect(option->direction, option->rect, r);
4136 QRect QGtkStyle::itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
4138 return QWindowsStyle::itemPixmapRect(r, flags, pixmap);
4144 void QGtkStyle::drawItemPixmap(QPainter *painter, const QRect &rect,
4145 int alignment, const QPixmap &pixmap) const
4147 QWindowsStyle::drawItemPixmap(painter, rect, alignment, pixmap);
4153 QStyle::SubControl QGtkStyle::hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
4154 const QPoint &pt, const QWidget *w) const
4156 return QWindowsStyle::hitTestComplexControl(cc, opt, pt, w);
4162 QPixmap QGtkStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
4163 const QStyleOption *opt) const
4165 return QWindowsStyle::generatedIconPixmap(iconMode, pixmap, opt);
4171 void QGtkStyle::drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal,
4172 bool enabled, const QString& text, QPalette::ColorRole textRole) const
4174 return QWindowsStyle::drawItemText(painter, rect, alignment, pal, enabled, text, textRole);
4179 #endif //!defined(QT_NO_STYLE_QGTK)