/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

Large files are truncated click here to view the full 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