/src/gui/styles/qgtkstyle.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 3560 lines · 2759 code · 560 blank · 241 comment · 571 complexity · db14bb3d907cf6d36646cbae1b4fcf36 MD5 · raw file

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