src/gui/styles/qgtkstyle.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    67 #include <QtGui/QRadioButton>
    67 #include <QtGui/QRadioButton>
    68 #include <QtGui/QCheckBox>
    68 #include <QtGui/QCheckBox>
    69 #include <QtGui/QTreeView>
    69 #include <QtGui/QTreeView>
    70 #include <qpixmapcache.h>
    70 #include <qpixmapcache.h>
    71 #undef signals // Collides with GTK stymbols
    71 #undef signals // Collides with GTK stymbols
    72 #include "qgtkpainter_p.h"
    72 #include <private/qgtkpainter_p.h>
    73 #include "qstylehelper_p.h"
    73 #include <private/qstylehelper_p.h>
    74 
    74 #include <private/qgtkstyle_p.h>
    75 #include <private/qcleanlooksstyle_p.h>
    75 #include <private/qcleanlooksstyle_p.h>
    76 
    76 
    77 
    77 
    78 QT_BEGIN_NAMESPACE
    78 QT_BEGIN_NAMESPACE
    79 
       
    80 typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption, const QString &dir,
       
    81                                                           const QString &filter, QString *selectedFilter, QFileDialog::Options options);
       
    82 typedef QString (*_qt_filedialog_open_filename_hook)     (QWidget * parent, const QString &caption, const QString &dir,
       
    83                                                           const QString &filter, QString *selectedFilter, QFileDialog::Options options);
       
    84 typedef QString (*_qt_filedialog_save_filename_hook)     (QWidget * parent, const QString &caption, const QString &dir,
       
    85                                                           const QString &filter, QString *selectedFilter, QFileDialog::Options options);
       
    86 typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, const QString &dir,
       
    87                                                           QFileDialog::Options options);
       
    88 
       
    89 extern Q_GUI_EXPORT _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook;
       
    90 extern Q_GUI_EXPORT _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook;
       
    91 extern Q_GUI_EXPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook;
       
    92 extern Q_GUI_EXPORT _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook;
       
    93 
    79 
    94 static const char * const dock_widget_close_xpm[] =
    80 static const char * const dock_widget_close_xpm[] =
    95     {
    81     {
    96         "11 13 5 1",
    82         "11 13 5 1",
    97         "  c None",
    83         "  c None",
   135         "@+       +@",
   121         "@+       +@",
   136         " @@@@@@@@@ ",
   122         " @@@@@@@@@ ",
   137         "           "
   123         "           "
   138     };
   124     };
   139 
   125 
   140 
       
   141 class QGtkStyleFilter : public QObject
       
   142 {
       
   143 public:
       
   144     QGtkStyleFilter() {}
       
   145 private:
       
   146     bool eventFilter(QObject *obj, QEvent *e);
       
   147 };
       
   148 
       
   149 bool QGtkStyleFilter::eventFilter(QObject *obj, QEvent *e)
       
   150 {
       
   151     if (e->type() == QEvent::ApplicationPaletteChange) {
       
   152         // Only do this the first time since this will also
       
   153         // generate applicationPaletteChange events
       
   154         if (!qt_app_palettes_hash() ||  qt_app_palettes_hash()->isEmpty()) {
       
   155             QGtk::applyCustomPaletteHash();
       
   156         }
       
   157     }
       
   158     return QObject::eventFilter(obj, e);
       
   159 }
       
   160 
       
   161 class QGtkStylePrivate : public QCleanlooksStylePrivate
       
   162 {
       
   163     Q_DECLARE_PUBLIC(QGtkStyle)
       
   164 public:
       
   165     QGtkStylePrivate()
       
   166             : QCleanlooksStylePrivate()
       
   167     {
       
   168         QGtk::initGtkWidgets();
       
   169         if (QGtk::isThemeAvailable())
       
   170             qApp->installEventFilter(&filter);
       
   171 
       
   172     }
       
   173     QGtkStyleFilter filter;
       
   174 };
       
   175 
       
   176 static const int groupBoxBottomMargin    =  2;  // space below the groupbox
   126 static const int groupBoxBottomMargin    =  2;  // space below the groupbox
   177 static const int groupBoxTitleMargin     =  6;  // space between contents and title
   127 static const int groupBoxTitleMargin     =  6;  // space between contents and title
   178 static const int groupBoxTopMargin       =  2;
   128 static const int groupBoxTopMargin       =  2;
   179 
   129 
   180 // Get size of the arrow controls in a GtkSpinButton
   130 /*!
   181 static int spinboxArrowSize()
   131   Returns the configuration string for \a value.
       
   132   Returns \a fallback if \a value is not found.
       
   133  */
       
   134 QString QGtkStyle::getGConfString(const QString &value, const QString &fallback)
   182 {
   135 {
   183     const int MIN_ARROW_WIDTH = 6;
   136     return QGtkStylePrivate::getGConfString(value, fallback);
   184     GtkWidget *spinButton = QGtk::gtkWidget(QLS("GtkSpinButton"));
   137 }
   185     GtkStyle *style = spinButton->style;
   138 
   186     gint size = QGtk::pango_font_description_get_size (style->font_desc);
   139 /*!
   187     gint arrow_size;
   140   Returns the configuration boolean for \a key.
   188     arrow_size = qMax(PANGO_PIXELS (size), MIN_ARROW_WIDTH) + style->xthickness;
   141   Returns \a fallback if \a key is not found.
   189     arrow_size += arrow_size%2 + 1;
   142  */
   190     return arrow_size;
   143 bool QGtkStyle::getGConfBool(const QString &key, bool fallback)
       
   144 {
       
   145     return QGtkStylePrivate::getGConfBool(key, fallback);
   191 }
   146 }
   192 
   147 
   193 static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50)
   148 static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50)
   194 {
   149 {
   195     const int maxFactor = 100;
   150     const int maxFactor = 100;
   231     Constructs a QGtkStyle object.
   186     Constructs a QGtkStyle object.
   232 */
   187 */
   233 QGtkStyle::QGtkStyle()
   188 QGtkStyle::QGtkStyle()
   234     : QCleanlooksStyle(*new QGtkStylePrivate)
   189     : QCleanlooksStyle(*new QGtkStylePrivate)
   235 {
   190 {
       
   191     Q_D(QGtkStyle);
       
   192     d->init();
   236 }
   193 }
       
   194 
       
   195 /*!
       
   196     \internal
       
   197 
       
   198     Constructs a QGtkStyle object.
       
   199 */
       
   200 QGtkStyle::QGtkStyle(QGtkStylePrivate &dd)
       
   201      : QCleanlooksStyle(dd)
       
   202 {
       
   203     Q_D(QGtkStyle);
       
   204     d->init();
       
   205 }
       
   206 
   237 
   207 
   238 /*!
   208 /*!
   239     Destroys the QGtkStyle object.
   209     Destroys the QGtkStyle object.
   240 */
   210 */
   241 QGtkStyle::~QGtkStyle()
   211 QGtkStyle::~QGtkStyle()
   245 /*!
   215 /*!
   246     \reimp
   216     \reimp
   247 */
   217 */
   248 QPalette QGtkStyle::standardPalette() const
   218 QPalette QGtkStyle::standardPalette() const
   249 {
   219 {
       
   220     Q_D(const QGtkStyle);
       
   221 
   250     QPalette palette = QCleanlooksStyle::standardPalette();
   222     QPalette palette = QCleanlooksStyle::standardPalette();
   251     if (QGtk::isThemeAvailable()) {
   223     if (d->isThemeAvailable()) {
   252         GtkStyle *style = QGtk::gtkStyle();
   224         GtkStyle *style = d->gtkStyle();
   253         GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton"));
   225         GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
   254         GtkWidget *gtkEntry = QGtk::gtkWidget(QLS("GtkEntry"));
   226         GtkWidget *gtkEntry = d->getTextColorWidget();
   255 
   227 
   256         GdkColor gdkBg, gdkBase, gdkText, gdkForeground, gdkSbg, gdkSfg;
   228         GdkColor gdkBg, gdkBase, gdkText, gdkForeground, gdkSbg, gdkSfg;
   257         QColor bg, base, text, fg, highlight, highlightText;
   229         QColor bg, base, text, fg, highlight, highlightText;
   258         gdkBg = style->bg[GTK_STATE_NORMAL];
   230         gdkBg = style->bg[GTK_STATE_NORMAL];
   259         gdkForeground = gtkButton->style->fg[GTK_STATE_NORMAL];
   231         gdkForeground = gtkButton->style->fg[GTK_STATE_NORMAL];
   279         palette.setColor(QPalette::WindowText, fg);
   251         palette.setColor(QPalette::WindowText, fg);
   280         palette.setColor(QPalette::ButtonText, fg);
   252         palette.setColor(QPalette::ButtonText, fg);
   281         palette.setColor(QPalette::Base, base);
   253         palette.setColor(QPalette::Base, base);
   282 
   254 
   283         QColor alternateRowColor = palette.base().color().lighter(93); // ref gtkstyle.c draw_flat_box
   255         QColor alternateRowColor = palette.base().color().lighter(93); // ref gtkstyle.c draw_flat_box
   284         GtkWidget *gtkTreeView = QGtk::gtkWidget(QLS("GtkTreeView"));
   256         GtkWidget *gtkTreeView = d->gtkWidget(QLS("GtkTreeView"));
   285         GdkColor *gtkAltBase = NULL;
   257         GdkColor *gtkAltBase = NULL;
   286         QGtk::gtk_widget_style_get(gtkTreeView, "odd-row-color", &gtkAltBase, NULL);
   258         d->gtk_widget_style_get(gtkTreeView, "odd-row-color", &gtkAltBase, NULL);
   287         if (gtkAltBase) {
   259         if (gtkAltBase) {
   288             alternateRowColor = QColor(gtkAltBase->red>>8, gtkAltBase->green>>8, gtkAltBase->blue>>8);
   260             alternateRowColor = QColor(gtkAltBase->red>>8, gtkAltBase->green>>8, gtkAltBase->blue>>8);
   289             QGtk::gdk_color_free(gtkAltBase);
   261             d->gdk_color_free(gtkAltBase);
   290         }
   262         }
   291         palette.setColor(QPalette::AlternateBase, alternateRowColor);
   263         palette.setColor(QPalette::AlternateBase, alternateRowColor);
   292 
   264 
   293         palette.setColor(QPalette::Window, bg);
   265         palette.setColor(QPalette::Window, bg);
   294         palette.setColor(QPalette::Button, bg);
   266         palette.setColor(QPalette::Button, bg);
   304         // calculate disabled colors by removing saturation
   276         // calculate disabled colors by removing saturation
   305         highlight.setHsv(highlight.hue(), 0, highlight.value(), highlight.alpha());
   277         highlight.setHsv(highlight.hue(), 0, highlight.value(), highlight.alpha());
   306         highlightText.setHsv(highlightText.hue(), 0, highlightText.value(), highlightText.alpha());
   278         highlightText.setHsv(highlightText.hue(), 0, highlightText.value(), highlightText.alpha());
   307         palette.setColor(QPalette::Disabled, QPalette::Highlight, highlight);
   279         palette.setColor(QPalette::Disabled, QPalette::Highlight, highlight);
   308         palette.setColor(QPalette::Disabled, QPalette::HighlightedText, highlightText);
   280         palette.setColor(QPalette::Disabled, QPalette::HighlightedText, highlightText);
   309         style = QGtk::gtk_rc_get_style_by_paths(QGtk::gtk_settings_get_default(), "gtk-tooltips", "GtkWindow", Q_GTK_TYPE_WINDOW);
   281         style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow",
       
   282                 d->gtk_window_get_type());
   310         if (style) {
   283         if (style) {
   311             gdkText = style->fg[GTK_STATE_NORMAL];
   284             gdkText = style->fg[GTK_STATE_NORMAL];
   312             text = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
   285             text = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
   313             palette.setColor(QPalette::ToolTipText, text);
   286             palette.setColor(QPalette::ToolTipText, text);
   314         }
   287         }
   319 /*!
   292 /*!
   320     \reimp
   293     \reimp
   321 */
   294 */
   322 void QGtkStyle::polish(QPalette &palette)
   295 void QGtkStyle::polish(QPalette &palette)
   323 {
   296 {
       
   297     Q_D(QGtkStyle);
       
   298 
   324     // QCleanlooksStyle will alter the palette, hence we do
   299     // QCleanlooksStyle will alter the palette, hence we do
   325     // not want to polish the palette unless we are using it as
   300     // not want to polish the palette unless we are using it as
   326     // the fallback
   301     // the fallback
   327     if (!QGtk::isThemeAvailable())
   302     if (!d->isThemeAvailable())
   328         QCleanlooksStyle::polish(palette);
   303         QCleanlooksStyle::polish(palette);
   329     else
   304     else
   330         palette = palette.resolve(standardPalette());
   305         palette = palette.resolve(standardPalette());
   331 }
   306 }
   332 
   307 
   333 /*!
   308 /*!
   334     \reimp
   309     \reimp
   335 */
   310 */
   336 void QGtkStyle::polish(QApplication *app)
   311 void QGtkStyle::polish(QApplication *app)
   337 {
   312 {
       
   313     Q_D(QGtkStyle);
       
   314 
   338     QCleanlooksStyle::polish(app);
   315     QCleanlooksStyle::polish(app);
   339     // Custom fonts and palettes with QtConfig are intentionally 
   316     // Custom fonts and palettes with QtConfig are intentionally 
   340     // not supported as these should be entirely determined by
   317     // not supported as these should be entirely determined by
   341     // current Gtk settings
   318     // current Gtk settings
   342     if (app->desktopSettingsAware() && QGtk::isThemeAvailable()) {
   319     if (app->desktopSettingsAware() && d->isThemeAvailable()) {
   343         QApplicationPrivate::setSystemPalette(standardPalette());
   320         QApplicationPrivate::setSystemPalette(standardPalette());
   344         QApplicationPrivate::setSystemFont(QGtk::getThemeFont());
   321         QApplicationPrivate::setSystemFont(d->getThemeFont());
   345         QGtk::applyCustomPaletteHash();
   322         d->applyCustomPaletteHash();
   346         if (!QGtk::isKDE4Session()) {
   323         if (!d->isKDE4Session()) {
   347             qt_filedialog_open_filename_hook = &QGtk::openFilename;
   324             qt_filedialog_open_filename_hook = &QGtkStylePrivate::openFilename;
   348             qt_filedialog_save_filename_hook = &QGtk::saveFilename;
   325             qt_filedialog_save_filename_hook = &QGtkStylePrivate::saveFilename;
   349             qt_filedialog_open_filenames_hook = &QGtk::openFilenames;
   326             qt_filedialog_open_filenames_hook = &QGtkStylePrivate::openFilenames;
   350             qt_filedialog_existing_directory_hook = &QGtk::openDirectory;
   327             qt_filedialog_existing_directory_hook = &QGtkStylePrivate::openDirectory;
   351         }
   328         }
   352     }
   329     }
   353 }
   330 }
   354 
   331 
   355 /*!
   332 /*!
   356     \reimp
   333     \reimp
   357 */
   334 */
   358 void QGtkStyle::unpolish(QApplication *app)
   335 void QGtkStyle::unpolish(QApplication *app)
   359 {
   336 {
       
   337     Q_D(QGtkStyle);
       
   338 
   360     QCleanlooksStyle::unpolish(app);
   339     QCleanlooksStyle::unpolish(app);
   361     QPixmapCache::clear();
   340     QPixmapCache::clear();
   362 
   341 
   363     if (app->desktopSettingsAware() && QGtk::isThemeAvailable()
   342     if (app->desktopSettingsAware() && d->isThemeAvailable()
   364         && !QGtk::isKDE4Session()) {
   343         && !d->isKDE4Session()) {
   365         qt_filedialog_open_filename_hook = 0;
   344         qt_filedialog_open_filename_hook = 0;
   366         qt_filedialog_save_filename_hook = 0;
   345         qt_filedialog_save_filename_hook = 0;
   367         qt_filedialog_open_filenames_hook = 0;
   346         qt_filedialog_open_filenames_hook = 0;
   368         qt_filedialog_existing_directory_hook = 0;
   347         qt_filedialog_existing_directory_hook = 0;
   369     }
   348     }
   373     \reimp
   352     \reimp
   374 */
   353 */
   375 
   354 
   376 void QGtkStyle::polish(QWidget *widget)
   355 void QGtkStyle::polish(QWidget *widget)
   377 {
   356 {
       
   357     Q_D(QGtkStyle);
       
   358 
   378     QCleanlooksStyle::polish(widget);
   359     QCleanlooksStyle::polish(widget);
   379     if (!QGtk::isThemeAvailable())
   360     if (!d->isThemeAvailable())
   380         return;
   361         return;
   381     if (qobject_cast<QAbstractButton*>(widget)
   362     if (qobject_cast<QAbstractButton*>(widget)
   382             || qobject_cast<QToolButton*>(widget)
   363             || qobject_cast<QToolButton*>(widget)
   383             || qobject_cast<QComboBox*>(widget)
   364             || qobject_cast<QComboBox*>(widget)
   384             || qobject_cast<QGroupBox*>(widget)
   365             || qobject_cast<QGroupBox*>(widget)
   402 
   383 
   403 /*!
   384 /*!
   404     \reimp
   385     \reimp
   405 */
   386 */
   406 int QGtkStyle::pixelMetric(PixelMetric metric,
   387 int QGtkStyle::pixelMetric(PixelMetric metric,
   407 
       
   408                            const QStyleOption *option,
   388                            const QStyleOption *option,
   409                            const QWidget *widget) const
   389                            const QWidget *widget) const
   410 {
   390 {
   411     if (!QGtk::isThemeAvailable())
   391     Q_D(const QGtkStyle);
       
   392 
       
   393     if (!d->isThemeAvailable())
   412         return QCleanlooksStyle::pixelMetric(metric, option, widget);
   394         return QCleanlooksStyle::pixelMetric(metric, option, widget);
   413 
   395 
   414     switch (metric) {
   396     switch (metric) {
   415     case PM_DefaultFrameWidth:
   397     case PM_DefaultFrameWidth:
   416         if (qobject_cast<const QFrame*>(widget)) {
   398         if (qobject_cast<const QFrame*>(widget)) {
   417             if (GtkStyle *style =
   399             if (GtkStyle *style =
   418                 QGtk::gtk_rc_get_style_by_paths(QGtk::gtk_settings_get_default(),
   400                 d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(),
   419                                                 "*.GtkScrolledWindow",
   401                                                 "*.GtkScrolledWindow",
   420                                                 "*.GtkScrolledWindow",
   402                                                 "*.GtkScrolledWindow",
   421                                                 Q_GTK_TYPE_WINDOW))
   403                                                 d->gtk_window_get_type()))
   422                 return qMax(style->xthickness, style->ythickness);
   404                 return qMax(style->xthickness, style->ythickness);
   423         }
   405         }
   424         return 2;
   406         return 2;
   425 
   407 
   426     case PM_MenuButtonIndicator:
   408     case PM_MenuButtonIndicator:
   437 
   419 
   438     case PM_ToolBarItemSpacing:
   420     case PM_ToolBarItemSpacing:
   439         return 0;
   421         return 0;
   440 
   422 
   441     case PM_ButtonShiftHorizontal: {
   423     case PM_ButtonShiftHorizontal: {
   442         GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton"));
   424         GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
   443         guint horizontal_shift;
   425         guint horizontal_shift;
   444         QGtk::gtk_widget_style_get(gtkButton, "child-displacement-x", &horizontal_shift, NULL);
   426         d->gtk_widget_style_get(gtkButton, "child-displacement-x", &horizontal_shift, NULL);
   445         return horizontal_shift;
   427         return horizontal_shift;
   446     }
   428     }
   447 
   429 
   448     case PM_ButtonShiftVertical: {
   430     case PM_ButtonShiftVertical: {
   449         GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton"));
   431         GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
   450         guint vertical_shift;
   432         guint vertical_shift;
   451         QGtk::gtk_widget_style_get(gtkButton, "child-displacement-y", &vertical_shift, NULL);
   433         d->gtk_widget_style_get(gtkButton, "child-displacement-y", &vertical_shift, NULL);
   452         return vertical_shift;
   434         return vertical_shift;
   453     }
   435     }
   454 
   436 
   455     case PM_MenuBarPanelWidth:
   437     case PM_MenuBarPanelWidth:
   456         return 0;
   438         return 0;
   457 
   439 
   458     case PM_MenuPanelWidth: {
   440     case PM_MenuPanelWidth: {
   459         GtkWidget *gtkMenu = QGtk::gtkWidget(QLS("GtkMenu"));
   441         GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu"));
   460         guint horizontal_padding = 0;
   442         guint horizontal_padding = 0;
   461         // horizontal-padding is used by Maemo to get thicker borders
   443         // horizontal-padding is used by Maemo to get thicker borders
   462         if (!QGtk::gtk_check_version(2, 10, 0))
   444         if (!d->gtk_check_version(2, 10, 0))
   463             QGtk::gtk_widget_style_get(gtkMenu, "horizontal-padding", &horizontal_padding, NULL);
   445             d->gtk_widget_style_get(gtkMenu, "horizontal-padding", &horizontal_padding, NULL);
   464         int padding = qMax<int>(gtkMenu->style->xthickness, horizontal_padding);
   446         int padding = qMax<int>(gtkMenu->style->xthickness, horizontal_padding);
   465         return padding;
   447         return padding;
   466     }
   448     }
   467 
   449 
   468     case PM_ButtonIconSize: {
   450     case PM_ButtonIconSize: {
   469         int retVal = 24;
   451         int retVal = 24;
   470         GtkSettings *settings = QGtk::gtk_settings_get_default();
   452         GtkSettings *settings = d->gtk_settings_get_default();
   471         gchararray icon_sizes;
   453         gchararray icon_sizes;
   472         g_object_get(settings, "gtk-icon-sizes", &icon_sizes, NULL);
   454         g_object_get(settings, "gtk-icon-sizes", &icon_sizes, NULL);
   473         QStringList values = QString(QLS(icon_sizes)).split(QLatin1Char(':'));
   455         QStringList values = QString(QLS(icon_sizes)).split(QLatin1Char(':'));
   474         g_free(icon_sizes);
   456         g_free(icon_sizes);
   475         QChar splitChar(QLatin1Char(','));
   457         QChar splitChar(QLatin1Char(','));
   511     case PM_SplitterWidth:
   493     case PM_SplitterWidth:
   512         return 6;
   494         return 6;
   513 
   495 
   514     case PM_SliderThickness:
   496     case PM_SliderThickness:
   515     case PM_SliderControlThickness: {
   497     case PM_SliderControlThickness: {
   516         GtkWidget *gtkScale = QGtk::gtkWidget(QLS("GtkHScale"));
   498         GtkWidget *gtkScale = d->gtkWidget(QLS("GtkHScale"));
   517         gint val;
   499         gint val;
   518         QGtk::gtk_widget_style_get(gtkScale, "slider-width", &val, NULL);
   500         d->gtk_widget_style_get(gtkScale, "slider-width", &val, NULL);
   519         if (metric == PM_SliderControlThickness)
   501         if (metric == PM_SliderControlThickness)
   520             return val + 2*gtkScale->style->ythickness;
   502             return val + 2*gtkScale->style->ythickness;
   521         return val;
   503         return val;
   522     }
   504     }
   523 
   505 
   524     case PM_ScrollBarExtent: {
   506     case PM_ScrollBarExtent: {
   525         gint sliderLength;
   507         gint sliderLength;
   526         gint trough_border;
   508         gint trough_border;
   527         GtkWidget *hScrollbar = QGtk::gtkWidget(QLS("GtkHScrollbar"));
   509         GtkWidget *hScrollbar = d->gtkWidget(QLS("GtkHScrollbar"));
   528         QGtk::gtk_widget_style_get(hScrollbar,
   510         d->gtk_widget_style_get(hScrollbar,
   529                                "trough-border",   &trough_border,
   511                                "trough-border",   &trough_border,
   530                                "slider-width",    &sliderLength,
   512                                "slider-width",    &sliderLength,
   531                                NULL);
   513                                NULL);
   532         return sliderLength + trough_border*2;
   514         return sliderLength + trough_border*2;
   533     }
   515     }
   535     case PM_ScrollBarSliderMin:
   517     case PM_ScrollBarSliderMin:
   536         return 34;
   518         return 34;
   537 
   519 
   538     case PM_SliderLength:
   520     case PM_SliderLength:
   539         gint val;
   521         gint val;
   540         QGtk::gtk_widget_style_get(QGtk::gtkWidget(QLS("GtkHScale")), "slider-length", &val, NULL);
   522         d->gtk_widget_style_get(d->gtkWidget(QLS("GtkHScale")), "slider-length", &val, NULL);
   541         return val;
   523         return val;
   542 
   524 
   543     case PM_ExclusiveIndicatorWidth:
   525     case PM_ExclusiveIndicatorWidth:
   544     case PM_ExclusiveIndicatorHeight:
   526     case PM_ExclusiveIndicatorHeight:
   545     case PM_IndicatorWidth:
   527     case PM_IndicatorWidth:
   546     case PM_IndicatorHeight: {
   528     case PM_IndicatorHeight: {
   547         GtkWidget *gtkCheckButton = QGtk::gtkWidget(QLS("GtkCheckButton"));
   529         GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
   548         gint size, spacing;
   530         gint size, spacing;
   549         QGtk::gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, "indicator-size", &size, NULL);
   531         d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, "indicator-size", &size, NULL);
   550         return size + 2 * spacing;
   532         return size + 2 * spacing;
   551     }
   533     }
   552 
   534 
   553     case PM_MenuBarVMargin: {
   535     case PM_MenuBarVMargin: {
   554         GtkWidget *gtkMenubar = QGtk::gtkWidget(QLS("GtkMenuBar"));
   536         GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar"));
   555         return  qMax(0, gtkMenubar->style->ythickness);
   537         return  qMax(0, gtkMenubar->style->ythickness);
   556     }
   538     }
   557     case PM_ScrollView_ScrollBarSpacing:
   539     case PM_ScrollView_ScrollBarSpacing:
   558     {
   540     {
   559         gint spacing = 3;
   541         gint spacing = 3;
   560         GtkWidget *gtkScrollWindow = QGtk::gtkWidget(QLS("GtkScrolledWindow"));
   542         GtkWidget *gtkScrollWindow = d->gtkWidget(QLS("GtkScrolledWindow"));
   561         Q_ASSERT(gtkScrollWindow);
   543         Q_ASSERT(gtkScrollWindow);
   562         QGtk::gtk_widget_style_get(gtkScrollWindow, "scrollbar-spacing", &spacing, NULL);
   544         d->gtk_widget_style_get(gtkScrollWindow, "scrollbar-spacing", &spacing, NULL);
   563         return spacing;
   545         return spacing;
   564     }
   546     }
   565     case PM_SubMenuOverlap: {
   547     case PM_SubMenuOverlap: {
   566         gint offset = 0;
   548         gint offset = 0;
   567         GtkWidget *gtkMenu = QGtk::gtkWidget(QLS("GtkMenu"));
   549         GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu"));
   568         QGtk::gtk_widget_style_get(gtkMenu, "horizontal-offset", &offset, NULL);
   550         d->gtk_widget_style_get(gtkMenu, "horizontal-offset", &offset, NULL);
   569         return offset;
   551         return offset;
   570     }
   552     }
   571     default:
   553     default:
   572         return QCleanlooksStyle::pixelMetric(metric, option, widget);
   554         return QCleanlooksStyle::pixelMetric(metric, option, widget);
   573     }
   555     }
   578 */
   560 */
   579 int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
   561 int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
   580 
   562 
   581                          QStyleHintReturn *returnData = 0) const
   563                          QStyleHintReturn *returnData = 0) const
   582 {
   564 {
   583     if (!QGtk::isThemeAvailable())
   565     Q_D(const QGtkStyle);
       
   566 
       
   567     if (!d->isThemeAvailable())
   584         return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
   568         return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
   585 
   569 
   586     switch (hint) {
   570     switch (hint) {
   587 
   571 
   588     case SH_DialogButtonLayout: {
   572     case SH_DialogButtonLayout: {
   589         int ret = QDialogButtonBox::GnomeLayout;
   573         int ret = QDialogButtonBox::GnomeLayout;
   590         gboolean alternateOrder = 0;
   574         gboolean alternateOrder = 0;
   591         GtkSettings *settings = QGtk::gtk_settings_get_default();
   575         GtkSettings *settings = d->gtk_settings_get_default();
   592         g_object_get(settings, "gtk-alternative-button-order", &alternateOrder, NULL);
   576         g_object_get(settings, "gtk-alternative-button-order", &alternateOrder, NULL);
   593 
   577 
   594         if (alternateOrder)
   578         if (alternateOrder)
   595             ret = QDialogButtonBox::WinLayout;
   579             ret = QDialogButtonBox::WinLayout;
   596 
   580 
   599 
   583 
   600     break;
   584     break;
   601 
   585 
   602     case SH_ToolButtonStyle:
   586     case SH_ToolButtonStyle:
   603     {
   587     {
   604         if (QGtk::isKDE4Session())
   588         if (d->isKDE4Session())
   605             return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
   589             return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
   606         GtkWidget *gtkToolbar = QGtk::gtkWidget(QLS("GtkToolbar"));
   590         GtkWidget *gtkToolbar = d->gtkWidget(QLS("GtkToolbar"));
   607         GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS;
   591         GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS;
   608         g_object_get(gtkToolbar, "toolbar-style", &toolbar_style, NULL);
   592         g_object_get(gtkToolbar, "toolbar-style", &toolbar_style, NULL);
   609         switch (toolbar_style) {
   593         switch (toolbar_style) {
   610         case GTK_TOOLBAR_TEXT:
   594         case GTK_TOOLBAR_TEXT:
   611             return Qt::ToolButtonTextOnly;
   595             return Qt::ToolButtonTextOnly;
   624 
   608 
   625     case SH_DitherDisabledText:
   609     case SH_DitherDisabledText:
   626         return int(false);
   610         return int(false);
   627 
   611 
   628     case SH_ComboBox_Popup: {
   612     case SH_ComboBox_Popup: {
   629         GtkWidget *gtkComboBox = QGtk::gtkWidget(QLS("GtkComboBox"));
   613         GtkWidget *gtkComboBox = d->gtkWidget(QLS("GtkComboBox"));
   630         gboolean appears_as_list;
   614         gboolean appears_as_list;
   631         QGtk::gtk_widget_style_get((GtkWidget*)gtkComboBox, "appears-as-list", &appears_as_list, NULL);
   615         d->gtk_widget_style_get((GtkWidget*)gtkComboBox, "appears-as-list", &appears_as_list, NULL);
   632         return appears_as_list ? 0 : 1;
   616         return appears_as_list ? 0 : 1;
   633     }
   617     }
   634 
   618 
   635     case SH_MenuBar_AltKeyNavigation:
   619     case SH_MenuBar_AltKeyNavigation:
   636         return int(false);
   620         return int(false);
   638     case SH_EtchDisabledText:
   622     case SH_EtchDisabledText:
   639         return int(false);
   623         return int(false);
   640 
   624 
   641     case SH_Menu_SubMenuPopupDelay: {
   625     case SH_Menu_SubMenuPopupDelay: {
   642         gint delay = 225;
   626         gint delay = 225;
   643         GtkSettings *settings = QGtk::gtk_settings_get_default();
   627         GtkSettings *settings = d->gtk_settings_get_default();
   644         g_object_get(settings, "gtk-menu-popup-delay", &delay, NULL);
   628         g_object_get(settings, "gtk-menu-popup-delay", &delay, NULL);
   645         return delay;
   629         return delay;
   646     }
   630     }
   647 
   631 
   648     case SH_ScrollView_FrameOnlyAroundContents: {
   632     case SH_ScrollView_FrameOnlyAroundContents: {
   649         gboolean scrollbars_within_bevel = false;
   633         gboolean scrollbars_within_bevel = false;
   650         if (widget && widget->isWindow())
   634         if (widget && widget->isWindow())
   651             scrollbars_within_bevel = true;
   635             scrollbars_within_bevel = true;
   652         else if (!QGtk::gtk_check_version(2, 12, 0)) {
   636         else if (!d->gtk_check_version(2, 12, 0)) {
   653             GtkWidget *gtkScrollWindow = QGtk::gtkWidget(QLS("GtkScrolledWindow"));
   637             GtkWidget *gtkScrollWindow = d->gtkWidget(QLS("GtkScrolledWindow"));
   654             QGtk::gtk_widget_style_get(gtkScrollWindow, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
   638             d->gtk_widget_style_get(gtkScrollWindow, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
   655         }
   639         }
   656         return !scrollbars_within_bevel;
   640         return !scrollbars_within_bevel;
   657     }
   641     }
   658 
   642 
   659     case SH_DialogButtonBox_ButtonsHaveIcons: {
   643     case SH_DialogButtonBox_ButtonsHaveIcons: {
   660         static bool buttonsHaveIcons = QGtk::getGConfBool(QLS("/desktop/gnome/interface/buttons_have_icons"));
   644         static bool buttonsHaveIcons = d->getGConfBool(QLS("/desktop/gnome/interface/buttons_have_icons"));
   661         return buttonsHaveIcons;
   645         return buttonsHaveIcons;
       
   646     }
       
   647 
       
   648     case SH_UnderlineShortcut: {
       
   649         gboolean underlineShortcut = true;
       
   650         if (!d->gtk_check_version(2, 12, 0)) {
       
   651             GtkSettings *settings = d->gtk_settings_get_default();
       
   652             g_object_get(settings, "gtk-enable-mnemonics", &underlineShortcut, NULL);
       
   653         }
       
   654         return underlineShortcut;
   662     }
   655     }
   663 
   656 
   664     default:
   657     default:
   665         return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
   658         return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
   666     }
   659     }
   668 
   661 
   669 /*!
   662 /*!
   670     \reimp
   663     \reimp
   671 */
   664 */
   672 void QGtkStyle::drawPrimitive(PrimitiveElement element,
   665 void QGtkStyle::drawPrimitive(PrimitiveElement element,
   673 
       
   674                               const QStyleOption *option,
   666                               const QStyleOption *option,
   675                               QPainter *painter,
   667                               QPainter *painter,
   676                               const QWidget *widget) const
   668                               const QWidget *widget) const
   677 {
   669 {
   678     if (!QGtk::isThemeAvailable()) {
   670     Q_D(const QGtkStyle);
       
   671 
       
   672     if (!d->isThemeAvailable()) {
   679         QCleanlooksStyle::drawPrimitive(element, option, painter, widget);
   673         QCleanlooksStyle::drawPrimitive(element, option, painter, widget);
   680         return;
   674         return;
   681     }
   675     }
   682 
   676 
   683     GtkStyle* style = QGtk::gtkStyle();
   677     GtkStyle* style = d->gtkStyle();
   684     QGtkPainter gtkPainter(painter);
   678     QGtkPainter gtkPainter(painter);
   685 
   679 
   686     switch (element) {
   680     switch (element) {
   687       case PE_Frame: {
   681       case PE_Frame: {
   688         if (widget && widget->inherits("QComboBoxPrivateContainer")){
   682         if (widget && widget->inherits("QComboBoxPrivateContainer")){
   713             if (option->state & State_Sunken)
   707             if (option->state & State_Sunken)
   714                 shadow_type = GTK_SHADOW_IN;
   708                 shadow_type = GTK_SHADOW_IN;
   715             else if (option->state & State_Raised)
   709             else if (option->state & State_Raised)
   716                 shadow_type = GTK_SHADOW_OUT;
   710                 shadow_type = GTK_SHADOW_OUT;
   717 
   711 
   718             GtkStyle *style = QGtk::gtk_rc_get_style_by_paths(QGtk::gtk_settings_get_default(),
   712             GtkStyle *style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(),
   719                                      "*.GtkScrolledWindow", "*.GtkScrolledWindow", Q_GTK_TYPE_WINDOW);
   713                                      "*.GtkScrolledWindow", "*.GtkScrolledWindow", d->gtk_window_get_type());
   720             if (style)
   714             if (style)
   721                 gtkFramePainter.paintShadow(QGtk::gtkWidget(QLS("GtkFrame")), "viewport", pmRect,
   715                 gtkFramePainter.paintShadow(d->gtkWidget(QLS("GtkFrame")), "viewport", pmRect,
   722                                          option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
   716                                          option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
   723                                          shadow_type, style);
   717                                          shadow_type, style);
   724             QPixmapCache::insert(pmKey, pixmap);
   718             QPixmapCache::insert(pmKey, pixmap);
   725         }
   719         }
   726 
   720 
   743         painter->drawPixmap(rect.adjusted(rw, rh, 0, 0), pixmap, pmRect.adjusted(pw, ph, 0,0));
   737         painter->drawPixmap(rect.adjusted(rw, rh, 0, 0), pixmap, pmRect.adjusted(pw, ph, 0,0));
   744     }
   738     }
   745     break;
   739     break;
   746 
   740 
   747     case PE_PanelTipLabel: {
   741     case PE_PanelTipLabel: {
   748         GtkWidget *gtkWindow = QGtk::gtkWidget(QLS("GtkWindow")); // The Murrine Engine currently assumes a widget is passed
   742         GtkWidget *gtkWindow = d->gtkWidget(QLS("GtkWindow")); // The Murrine Engine currently assumes a widget is passed
   749         style = QGtk::gtk_rc_get_style_by_paths(QGtk::gtk_settings_get_default(), "gtk-tooltips", "GtkWindow", Q_GTK_TYPE_WINDOW);
   743         style = d->gtk_rc_get_style_by_paths(d->gtk_settings_get_default(), "gtk-tooltips", "GtkWindow",
       
   744                 d->gtk_window_get_type());
   750         gtkPainter.paintFlatBox(gtkWindow, "tooltip", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, style);
   745         gtkPainter.paintFlatBox(gtkWindow, "tooltip", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_NONE, style);
   751     }
   746     }
   752     break;
   747     break;
   753 
   748 
   754     case PE_PanelStatusBar: {
   749     case PE_PanelStatusBar: {
   757             // Respect custom palette
   752             // Respect custom palette
   758             painter->fillRect(option->rect, option->palette.window());
   753             painter->fillRect(option->rect, option->palette.window());
   759             break;
   754             break;
   760         }
   755         }
   761         GtkShadowType shadow_type;
   756         GtkShadowType shadow_type;
   762         GtkWidget *gtkStatusbarFrame = QGtk::gtkWidget(QLS("GtkStatusbar.GtkFrame"));
   757         GtkWidget *gtkStatusbarFrame = d->gtkWidget(QLS("GtkStatusbar.GtkFrame"));
   763         QGtk::gtk_widget_style_get(gtkStatusbarFrame->parent, "shadow-type", &shadow_type, NULL);
   758         d->gtk_widget_style_get(gtkStatusbarFrame->parent, "shadow-type", &shadow_type, NULL);
   764         gtkPainter.paintShadow(gtkStatusbarFrame, "frame", option->rect, GTK_STATE_NORMAL,
   759         gtkPainter.paintShadow(gtkStatusbarFrame, "frame", option->rect, GTK_STATE_NORMAL,
   765                                shadow_type, gtkStatusbarFrame->style);
   760                                shadow_type, gtkStatusbarFrame->style);
   766     }
   761     }
   767     break;
   762     break;
   768 
   763 
   769     case PE_IndicatorHeaderArrow:
   764     case PE_IndicatorHeaderArrow:
   770         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
   765         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
   771             GtkWidget *gtkTreeHeader = QGtk::gtkWidget(QLS("GtkTreeView.GtkButton"));
   766             GtkWidget *gtkTreeHeader = d->gtkWidget(QLS("GtkTreeView.GtkButton"));
   772             GtkStateType state = gtkPainter.gtkState(option);
   767             GtkStateType state = gtkPainter.gtkState(option);
   773             style = gtkTreeHeader->style;
   768             style = gtkTreeHeader->style;
   774             GtkArrowType type = GTK_ARROW_UP;
   769             GtkArrowType type = GTK_ARROW_UP;
   775             QRect r = header->rect;
   770             QRect r = header->rect;
   776             QImage arrow;
   771             QImage arrow;
   804             rect = QRect(0, 0, 12, 12);
   799             rect = QRect(0, 0, 12, 12);
   805             rect.moveCenter(option->rect.center());
   800             rect.moveCenter(option->rect.center());
   806             rect.translate(2, 0);
   801             rect.translate(2, 0);
   807             GtkExpanderStyle openState = GTK_EXPANDER_EXPANDED;
   802             GtkExpanderStyle openState = GTK_EXPANDER_EXPANDED;
   808             GtkExpanderStyle closedState = GTK_EXPANDER_COLLAPSED;
   803             GtkExpanderStyle closedState = GTK_EXPANDER_COLLAPSED;
   809             GtkWidget *gtkTreeView = QGtk::gtkWidget(QLS("GtkTreeView"));
   804             GtkWidget *gtkTreeView = d->gtkWidget(QLS("GtkTreeView"));
   810 
   805 
   811             GtkStateType state = GTK_STATE_NORMAL;
   806             GtkStateType state = GTK_STATE_NORMAL;
   812             if (!(option->state & State_Enabled))
   807             if (!(option->state & State_Enabled))
   813                 state = GTK_STATE_INSENSITIVE;
   808                 state = GTK_STATE_INSENSITIVE;
   814             else if (option->state & State_MouseOver)
   809             else if (option->state & State_MouseOver)
   840         }
   835         }
   841         break;
   836         break;
   842     case PE_IndicatorToolBarSeparator:
   837     case PE_IndicatorToolBarSeparator:
   843         {
   838         {
   844             const int margin = 6;
   839             const int margin = 6;
   845             GtkWidget *gtkSeparator = QGtk::gtkWidget(QLS("GtkToolbar.GtkSeparatorToolItem"));
   840             GtkWidget *gtkSeparator = d->gtkWidget(QLS("GtkToolbar.GtkSeparatorToolItem"));
   846             if (option->state & State_Horizontal) {
   841             if (option->state & State_Horizontal) {
   847                 const int offset = option->rect.width()/2;
   842                 const int offset = option->rect.width()/2;
   848                 QRect rect = option->rect.adjusted(offset, margin, 0, -margin);
   843                 QRect rect = option->rect.adjusted(offset, margin, 0, -margin);
   849                 painter->setPen(QPen(option->palette.background().color().darker(110)));
   844                 painter->setPen(QPen(option->palette.background().color().darker(110)));
   850                 gtkPainter.paintVline( gtkSeparator, "vseparator",
   845                 gtkPainter.paintVline( gtkSeparator, "vseparator",
   860             }
   855             }
   861        }
   856        }
   862        break;
   857        break;
   863 
   858 
   864     case PE_IndicatorToolBarHandle: {
   859     case PE_IndicatorToolBarHandle: {
   865         GtkWidget *gtkToolbar = QGtk::gtkWidget(QLS("GtkToolbar"));
   860         GtkWidget *gtkToolbar = d->gtkWidget(QLS("GtkToolbar"));
   866         GtkShadowType shadow_type;
   861         GtkShadowType shadow_type;
   867         QGtk::gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
   862         d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
   868         //Note when the toolbar is horizontal, the handle is vertical
   863         //Note when the toolbar is horizontal, the handle is vertical
   869         painter->setClipRect(option->rect);
   864         painter->setClipRect(option->rect);
   870         gtkPainter.paintHandle(gtkToolbar, "toolbar", option->rect.adjusted(-1, -1 ,0 ,1),
   865         gtkPainter.paintHandle(gtkToolbar, "toolbar", option->rect.adjusted(-1, -1 ,0 ,1),
   871                                GTK_STATE_NORMAL, shadow_type, !(option->state & State_Horizontal) ?
   866                                GTK_STATE_NORMAL, shadow_type, !(option->state & State_Horizontal) ?
   872                                GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, gtkToolbar->style);
   867                                GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, gtkToolbar->style);
   908         QRect arrowRect = option->rect.adjusted(border + bsx, border + bsy, -border + bsx, -border + bsy);
   903         QRect arrowRect = option->rect.adjusted(border + bsx, border + bsy, -border + bsx, -border + bsy);
   909         GtkShadowType shadow = option->state & State_Sunken ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
   904         GtkShadowType shadow = option->state & State_Sunken ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
   910         GtkStateType state = gtkPainter.gtkState(option);
   905         GtkStateType state = gtkPainter.gtkState(option);
   911 
   906 
   912         QColor arrowColor = option->palette.buttonText().color();
   907         QColor arrowColor = option->palette.buttonText().color();
   913         GtkWidget *gtkArrow = QGtk::gtkWidget(QLS("GtkArrow"));
   908         GtkWidget *gtkArrow = d->gtkWidget(QLS("GtkArrow"));
   914         GdkColor color = fromQColor(arrowColor);
   909         GdkColor color = fromQColor(arrowColor);
   915         QGtk::gtk_widget_modify_fg (gtkArrow, state, &color);
   910         d->gtk_widget_modify_fg (gtkArrow, state, &color);
   916         gtkPainter.paintArrow(gtkArrow, "button", arrowRect,
   911         gtkPainter.paintArrow(gtkArrow, "button", arrowRect,
   917                               type, state, shadow, FALSE, gtkArrow->style,
   912                               type, state, shadow, FALSE, gtkArrow->style,
   918                               QString::number(arrowColor.rgba(), 16));
   913                               QString::number(arrowColor.rgba(), 16));
   919         // Passing NULL will revert the color change
   914         // Passing NULL will revert the color change
   920         QGtk::gtk_widget_modify_fg (gtkArrow, state, NULL);
   915         d->gtk_widget_modify_fg (gtkArrow, state, NULL);
   921     }
   916     }
   922     break;
   917     break;
   923 
   918 
   924     case PE_FrameGroupBox:
   919     case PE_FrameGroupBox:
   925         // Do nothing here, the GNOME groupboxes are flat
   920         // Do nothing here, the GNOME groupboxes are flat
   926         break;
   921         break;
   927 
   922 
   928     case PE_PanelMenu: {
   923     case PE_PanelMenu: {
   929             GtkWidget *gtkMenu = QGtk::gtkWidget(QLS("GtkMenu"));
   924             GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu"));
   930             gtkPainter.setAlphaSupport(false); // Note, alpha disabled for performance reasons
   925             gtkPainter.setAlphaSupport(false); // Note, alpha disabled for performance reasons
   931             gtkPainter.paintBox(gtkMenu, "menu", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, gtkMenu->style, QString());
   926             gtkPainter.paintBox(gtkMenu, "menu", option->rect, GTK_STATE_NORMAL, GTK_SHADOW_OUT, gtkMenu->style, QString());
   932         }
   927         }
   933         break;
   928         break;
   934 
   929 
   936         //This is actually done by PE_Widget due to a clipping issue
   931         //This is actually done by PE_Widget due to a clipping issue
   937         //Otherwise Menu items will not be able to span the entire menu width
   932         //Otherwise Menu items will not be able to span the entire menu width
   938 
   933 
   939         // This is only used by floating tool bars
   934         // This is only used by floating tool bars
   940         if (qobject_cast<const QToolBar *>(widget)) {
   935         if (qobject_cast<const QToolBar *>(widget)) {
   941             GtkWidget *gtkMenubar = QGtk::gtkWidget(QLS("GtkMenuBar"));
   936             GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar"));
   942             gtkPainter.paintBox( gtkMenubar, "toolbar",  option->rect,
   937             gtkPainter.paintBox( gtkMenubar, "toolbar",  option->rect,
   943                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
   938                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
   944             gtkPainter.paintBox( gtkMenubar, "menu",  option->rect,
   939             gtkPainter.paintBox( gtkMenubar, "menu",  option->rect,
   945                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
   940                                  GTK_STATE_NORMAL, GTK_SHADOW_OUT, style);
   946         }
   941         }
   947         break;
   942         break;
   948 
   943 
   949     case PE_FrameLineEdit: {
   944     case PE_FrameLineEdit: {
   950         GtkWidget *gtkEntry = QGtk::gtkWidget(QLS("GtkEntry"));
   945         GtkWidget *gtkEntry = d->gtkWidget(QLS("GtkEntry"));
   951 
   946 
   952 
   947 
   953         gboolean interior_focus;
   948         gboolean interior_focus;
   954         gint focus_line_width;
   949         gint focus_line_width;
   955         QRect rect = option->rect;
   950         QRect rect = option->rect;
   956         QGtk::gtk_widget_style_get(gtkEntry,
   951         d->gtk_widget_style_get(gtkEntry,
   957                                "interior-focus", &interior_focus,
   952                                "interior-focus", &interior_focus,
   958                                "focus-line-width", &focus_line_width, NULL);
   953                                "focus-line-width", &focus_line_width, NULL);
   959 
   954 
   960         // See https://bugzilla.mozilla.org/show_bug.cgi?id=405421 for info about this hack
   955         // See https://bugzilla.mozilla.org/show_bug.cgi?id=405421 for info about this hack
   961         g_object_set_data(G_OBJECT(gtkEntry), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
   956         g_object_set_data(G_OBJECT(gtkEntry), "transparent-bg-hint", GINT_TO_POINTER(TRUE));
   979     }
   974     }
   980     break;
   975     break;
   981 
   976 
   982     case PE_PanelLineEdit:
   977     case PE_PanelLineEdit:
   983         if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
   978         if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
   984             GtkWidget *gtkEntry = QGtk::gtkWidget(QLS("GtkEntry"));
   979             GtkWidget *gtkEntry = d->gtkWidget(QLS("GtkEntry"));
   985             if (panel->lineWidth > 0)
   980             if (panel->lineWidth > 0)
   986                 proxy()->drawPrimitive(PE_FrameLineEdit, option, painter, widget);
   981                 proxy()->drawPrimitive(PE_FrameLineEdit, option, painter, widget);
   987             uint resolve_mask = option->palette.resolve();
   982             uint resolve_mask = option->palette.resolve();
   988             QRect textRect = option->rect.adjusted(gtkEntry->style->xthickness, gtkEntry->style->ythickness,
   983             QRect textRect = option->rect.adjusted(gtkEntry->style->xthickness, gtkEntry->style->ythickness,
   989                                                    -gtkEntry->style->xthickness, -gtkEntry->style->ythickness);
   984                                                    -gtkEntry->style->xthickness, -gtkEntry->style->ythickness);
   997         }
   992         }
   998         break;
   993         break;
   999 
   994 
  1000     case PE_FrameTabWidget:
   995     case PE_FrameTabWidget:
  1001         if (const QStyleOptionTabWidgetFrame *frame = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option)) {
   996         if (const QStyleOptionTabWidgetFrame *frame = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>(option)) {
  1002             GtkWidget *gtkNotebook = QGtk::gtkWidget(QLS("GtkNotebook"));
   997             GtkWidget *gtkNotebook = d->gtkWidget(QLS("GtkNotebook"));
  1003             style = gtkPainter.getStyle(gtkNotebook);
   998             style = gtkPainter.getStyle(gtkNotebook);
  1004             gtkPainter.setAlphaSupport(false);
   999             gtkPainter.setAlphaSupport(false);
  1005             GtkShadowType shadow = GTK_SHADOW_OUT;
  1000             GtkShadowType shadow = GTK_SHADOW_OUT;
  1006             GtkStateType state = GTK_STATE_NORMAL; // Only state supported by gtknotebook
  1001             GtkStateType state = GTK_STATE_NORMAL; // Only state supported by gtknotebook
  1007             if (const QTabWidget *tabwidget = qobject_cast<const QTabWidget*>(widget)) {
  1002             bool reverse = (option->direction == Qt::RightToLeft);
  1008                 // We should introduce QStyleOptionTabWidgetFrameV2 to obtain this information
  1003             QGtkStylePrivate::gtk_widget_set_direction(gtkNotebook, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1009                 // No gap if we do not show the actual tabs
  1004             if (const QStyleOptionTabWidgetFrameV2 *tabframe = qstyleoption_cast<const QStyleOptionTabWidgetFrameV2*>(option)) {
  1010                 QTabBar *tabBar = tabwidget->findChild<QTabBar*>();
  1005                 GtkPositionType frameType = GTK_POS_TOP;
  1011                 if (tabwidget->count() > 0 && tabBar->isVisible()) {
  1006                 QTabBar::Shape shape = frame->shape;
  1012                     QRect tabRect = tabBar->tabRect(tabBar->currentIndex());
  1007                 int gapStart = 0;
  1013                     int begin = 0, size = 0;
  1008                 int gapSize = 0;
  1014                     GtkPositionType frameType = GTK_POS_TOP;
  1009                 if (shape == QTabBar::RoundedNorth || shape == QTabBar::RoundedSouth) {
  1015                     QTabBar::Shape shape = frame->shape;
  1010                     frameType = (shape == QTabBar::RoundedNorth) ? GTK_POS_TOP : GTK_POS_BOTTOM;
  1016                     if (shape == QTabBar::RoundedNorth || shape == QTabBar::RoundedSouth) {
  1011                     gapStart = tabframe->selectedTabRect.left();
  1017                         begin = option->direction == Qt::LeftToRight ?
  1012                     gapSize = tabframe->selectedTabRect.width();
  1018                                 frame->leftCornerWidgetSize.width() + tabRect.left() :
  1013                 } else {
  1019                                 frame->rect.width() - frame->tabBarSize.width() + tabRect.left()
  1014                     frameType = (shape == QTabBar::RoundedWest) ? GTK_POS_LEFT : GTK_POS_RIGHT;
  1020                                 - frame->rightCornerWidgetSize.width();
  1015                     gapStart = tabframe->selectedTabRect.y();
  1021                         size = tabRect.width();
  1016                     gapSize = tabframe->selectedTabRect.height();
  1022                         frameType = (shape == QTabBar::RoundedNorth) ? GTK_POS_TOP : GTK_POS_BOTTOM;
       
  1023                     } else {
       
  1024                         begin = frame->leftCornerWidgetSize.height() + tabRect.top();
       
  1025                         size = tabRect.height();
       
  1026                         frameType = (shape == QTabBar::RoundedWest) ? GTK_POS_LEFT : GTK_POS_RIGHT;
       
  1027                     }
       
  1028                     gtkPainter.paintBoxGap(gtkNotebook, "notebook",  option->rect, state, shadow, frameType,
       
  1029                                             begin, size, style);
       
  1030                     break; // done
       
  1031                 }
  1017                 }
  1032             }
  1018                 gtkPainter.paintBoxGap(gtkNotebook, "notebook",  option->rect, state, shadow, frameType,
       
  1019                                         gapStart, gapSize, style);
       
  1020                 break; // done
       
  1021             }
       
  1022 
  1033             // Note this is only the fallback option
  1023             // Note this is only the fallback option
  1034             gtkPainter.paintBox(gtkNotebook, "notebook",  option->rect, state, shadow, style);
  1024             gtkPainter.paintBox(gtkNotebook, "notebook",  option->rect, state, shadow, style);
  1035         }
  1025         }
  1036         break;
  1026         break;
  1037 
  1027 
  1038     case PE_PanelButtonCommand: {
  1028     case PE_PanelButtonCommand:
       
  1029     case PE_PanelButtonTool: {
  1039         bool isDefault = false;
  1030         bool isDefault = false;
       
  1031         bool isTool = (element == PE_PanelButtonTool);
  1040         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton*>(option))
  1032         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton*>(option))
  1041             isDefault = btn->features & QStyleOptionButton::DefaultButton;
  1033             isDefault = btn->features & QStyleOptionButton::DefaultButton;
       
  1034 
       
  1035         // don't draw a frame for tool buttons that have the autoRaise flag and are not enabled or on
       
  1036         if (isTool && !(option->state & State_Enabled || option->state & State_On) && (option->state & State_AutoRaise))
       
  1037             break;
       
  1038         // don't draw a frame for dock widget buttons, unless we are hovering
       
  1039         if (widget && widget->inherits("QDockWidgetTitleButton") && !(option->state & State_MouseOver))
       
  1040             break;
  1042 
  1041 
  1043         GtkStateType state = gtkPainter.gtkState(option);
  1042         GtkStateType state = gtkPainter.gtkState(option);
  1044         if (option->state & State_On || option->state & State_Sunken)
  1043         if (option->state & State_On || option->state & State_Sunken)
  1045             state = GTK_STATE_ACTIVE;
  1044             state = GTK_STATE_ACTIVE;
  1046         GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton"));
  1045         GtkWidget *gtkButton = d->gtkWidget(isTool ? QLS("GtkToolButton.GtkButton") : QLS("GtkButton"));
  1047         gint focusWidth, focusPad;
  1046         gint focusWidth, focusPad;
  1048         gboolean interiorFocus = false;
  1047         gboolean interiorFocus = false;
  1049         QGtk::gtk_widget_style_get (gtkButton,
  1048         d->gtk_widget_style_get (gtkButton,
  1050                                 "focus-line-width", &focusWidth,
  1049                                 "focus-line-width", &focusWidth,
  1051                                 "focus-padding", &focusPad,
  1050                                 "focus-padding", &focusPad,
  1052                                 "interior-focus", &interiorFocus, NULL);
  1051                                 "interior-focus", &interiorFocus, NULL);
  1053 
  1052 
  1054         style = gtkButton->style;
  1053         style = gtkButton->style;
  1097         else if (option->state & State_On)
  1096         else if (option->state & State_On)
  1098             shadow = GTK_SHADOW_IN;
  1097             shadow = GTK_SHADOW_IN;
  1099         else
  1098         else
  1100             shadow = GTK_SHADOW_OUT;
  1099             shadow = GTK_SHADOW_OUT;
  1101 
  1100 
  1102         GtkWidget *gtkRadioButton = QGtk::gtkWidget(QLS("GtkRadioButton"));
  1101         GtkWidget *gtkRadioButton = d->gtkWidget(QLS("GtkRadioButton"));
  1103         gint spacing;
  1102         gint spacing;
  1104         QGtk::gtk_widget_style_get(gtkRadioButton, "indicator-spacing", &spacing, NULL);
  1103         d->gtk_widget_style_get(gtkRadioButton, "indicator-spacing", &spacing, NULL);
  1105         QRect buttonRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
  1104         QRect buttonRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
  1106         gtkPainter.setClipRect(option->rect);
  1105         gtkPainter.setClipRect(option->rect);
  1107         // ### Note: Ubuntulooks breaks when the proper widget is passed
  1106         // ### Note: Ubuntulooks breaks when the proper widget is passed
  1108         //           Murrine engine requires a widget not to get RGBA check - warnings
  1107         //           Murrine engine requires a widget not to get RGBA check - warnings
  1109         GtkWidget *gtkCheckButton = QGtk::gtkWidget(QLS("GtkCheckButton"));
  1108         GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
  1110         gtkPainter.paintOption(gtkCheckButton , buttonRect, state, shadow, gtkRadioButton->style, QLS("radiobutton"));
  1109         gtkPainter.paintOption(gtkCheckButton , buttonRect, state, shadow, gtkRadioButton->style, QLS("radiobutton"));
  1111 
  1110 
  1112     }
  1111     }
  1113     break;
  1112     break;
  1114 
  1113 
  1126         else
  1125         else
  1127             shadow = GTK_SHADOW_OUT;
  1126             shadow = GTK_SHADOW_OUT;
  1128 
  1127 
  1129         int spacing;
  1128         int spacing;
  1130 
  1129 
  1131         GtkWidget *gtkCheckButton = QGtk::gtkWidget(QLS("GtkCheckButton"));
  1130         GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
  1132 
  1131 
  1133         // Some styles such as aero-clone assume they can paint in the spacing area
  1132         // Some styles such as aero-clone assume they can paint in the spacing area
  1134         gtkPainter.setClipRect(option->rect);
  1133         gtkPainter.setClipRect(option->rect);
  1135 
  1134 
  1136         QGtk::gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, NULL);
  1135         d->gtk_widget_style_get(gtkCheckButton, "indicator-spacing", &spacing, NULL);
  1137 
  1136 
  1138         QRect checkRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
  1137         QRect checkRect = option->rect.adjusted(spacing, spacing, -spacing, -spacing);
  1139 
  1138 
  1140         gtkPainter.paintCheckbox(gtkCheckButton, checkRect, state, shadow, gtkCheckButton->style,
  1139         gtkPainter.paintCheckbox(gtkCheckButton, checkRect, state, shadow, gtkCheckButton->style,
  1141                                  QLS("checkbutton"));
  1140                                  QLS("checkbutton"));
  1198 */
  1197 */
  1199 void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
  1198 void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
  1200 
  1199 
  1201                                    QPainter *painter, const QWidget *widget) const
  1200                                    QPainter *painter, const QWidget *widget) const
  1202 {
  1201 {
  1203     if (!QGtk::isThemeAvailable()) {
  1202     Q_D(const QGtkStyle);
       
  1203 
       
  1204     if (!d->isThemeAvailable()) {
  1204         QCleanlooksStyle::drawComplexControl(control, option, painter, widget);
  1205         QCleanlooksStyle::drawComplexControl(control, option, painter, widget);
  1205         return;
  1206         return;
  1206     }
  1207     }
  1207 
  1208 
  1208     GtkStyle* style = QGtk::gtkStyle();
  1209     GtkStyle* style = d->gtkStyle();
  1209     QGtkPainter gtkPainter(painter);
  1210     QGtkPainter gtkPainter(painter);
  1210     QColor button = option->palette.button().color();
  1211     QColor button = option->palette.button().color();
  1211     QColor dark;
  1212     QColor dark;
  1212     QColor grooveColor;
  1213     QColor grooveColor;
  1213     QColor darkOutline;
  1214     QColor darkOutline;
  1258             QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxCheckBox, widget);
  1259             QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxCheckBox, widget);
  1259             // Draw title
  1260             // Draw title
  1260 
  1261 
  1261             if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
  1262             if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
  1262                 // Draw prelight background
  1263                 // Draw prelight background
  1263                 GtkWidget *gtkCheckButton = QGtk::gtkWidget(QLS("GtkCheckButton"));
  1264                 GtkWidget *gtkCheckButton = d->gtkWidget(QLS("GtkCheckButton"));
  1264 
  1265 
  1265                 if (option->state & State_MouseOver) {
  1266                 if (option->state & State_MouseOver) {
  1266                     QRect bgRect = textRect | checkBoxRect;
  1267                     QRect bgRect = textRect | checkBoxRect;
  1267                     gtkPainter.paintFlatBox(gtkCheckButton, "checkbutton", bgRect.adjusted(0, 0, 0, -2),
  1268                     gtkPainter.paintFlatBox(gtkCheckButton, "checkbutton", bgRect.adjusted(0, 0, 0, -2),
  1268                                             GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkCheckButton->style);
  1269                                             GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkCheckButton->style);
  1334             GtkShadowType shadow = (option->state & State_Sunken || option->state & State_On ) ?
  1335             GtkShadowType shadow = (option->state & State_Sunken || option->state & State_On ) ?
  1335                                    GTK_SHADOW_IN : GTK_SHADOW_OUT;
  1336                                    GTK_SHADOW_IN : GTK_SHADOW_OUT;
  1336             QString comboBoxPath = QLS(comboBox->editable ? "GtkComboBoxEntry" : "GtkComboBox");
  1337             QString comboBoxPath = QLS(comboBox->editable ? "GtkComboBoxEntry" : "GtkComboBox");
  1337 
  1338 
  1338             // We use the gtk widget to position arrows and separators for us
  1339             // We use the gtk widget to position arrows and separators for us
  1339             GtkWidget *gtkCombo = QGtk::gtkWidget(comboBoxPath);
  1340             GtkWidget *gtkCombo = d->gtkWidget(comboBoxPath);
  1340             GtkAllocation geometry = {0, 0, option->rect.width(), option->rect.height()};
  1341             GtkAllocation geometry = {0, 0, option->rect.width(), option->rect.height()};
  1341             QGtk::gtk_widget_set_direction(gtkCombo, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1342             d->gtk_widget_set_direction(gtkCombo, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1342             QGtk::gtk_widget_size_allocate(gtkCombo, &geometry);
  1343             d->gtk_widget_size_allocate(gtkCombo, &geometry);
  1343 
  1344 
  1344             QString buttonPath = comboBoxPath + QLS(".GtkToggleButton");
  1345             QString buttonPath = comboBoxPath + QLS(".GtkToggleButton");
  1345             GtkWidget *gtkToggleButton = QGtk::gtkWidget(buttonPath);
  1346             GtkWidget *gtkToggleButton = d->gtkWidget(buttonPath);
  1346             QGtk::gtk_widget_set_direction(gtkToggleButton, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1347             d->gtk_widget_set_direction(gtkToggleButton, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1347             if (gtkToggleButton && (appears_as_list || comboBox->editable)) {
  1348             if (gtkToggleButton && (appears_as_list || comboBox->editable)) {
  1348                 if (focus)
  1349                 if (focus)
  1349                     GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1350                     GTK_WIDGET_SET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1350                 // Draw the combo box as a line edit with a button next to it
  1351                 // Draw the combo box as a line edit with a button next to it
  1351                 if (comboBox->editable || appears_as_list) {
  1352                 if (comboBox->editable || appears_as_list) {
  1352                     GtkStateType frameState = (state == GTK_STATE_PRELIGHT) ? GTK_STATE_NORMAL : state;
  1353                     GtkStateType frameState = (state == GTK_STATE_PRELIGHT) ? GTK_STATE_NORMAL : state;
  1353                     QString entryPath = QLS(comboBox->editable ? "GtkComboBoxEntry.GtkEntry" : "GtkComboBox.GtkFrame");
  1354                     QString entryPath = QLS(comboBox->editable ? "GtkComboBoxEntry.GtkEntry" : "GtkComboBox.GtkFrame");
  1354                     GtkWidget *gtkEntry = QGtk::gtkWidget(entryPath);
  1355                     GtkWidget *gtkEntry = d->gtkWidget(entryPath);
  1355                     QGtk::gtk_widget_set_direction(gtkEntry, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1356                     d->gtk_widget_set_direction(gtkEntry, reverse ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  1356                     QRect frameRect = option->rect;
  1357                     QRect frameRect = option->rect;
  1357 
  1358 
  1358                     if (reverse)
  1359                     if (reverse)
  1359                         frameRect.setLeft(arrowButtonRect.right());
  1360                         frameRect.setLeft(arrowButtonRect.right());
  1360                     else
  1361                     else
  1374                         resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
  1375                         resolve_mask & (1 << QPalette::Base)) // Palette overridden by user
  1375                         p->fillRect(contentRect, option->palette.base().color());
  1376                         p->fillRect(contentRect, option->palette.base().color());
  1376                     else {
  1377                     else {
  1377                         gtkCachedPainter.paintFlatBox(gtkEntry, "entry_bg", contentRect,
  1378                         gtkCachedPainter.paintFlatBox(gtkEntry, "entry_bg", contentRect,
  1378                                                 option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
  1379                                                 option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE,
  1379                                                 GTK_SHADOW_NONE, style, entryPath + QString::number(focus));
  1380                                                 GTK_SHADOW_NONE, gtkCombo->style, entryPath + QString::number(focus));
  1380                     }
  1381                     }
  1381 
  1382 
  1382                     gtkCachedPainter.paintShadow(gtkEntry, comboBox->editable ? "entry" : "frame", frameRect, frameState,
  1383                     gtkCachedPainter.paintShadow(gtkEntry, comboBox->editable ? "entry" : "frame", frameRect, frameState,
  1383                                            GTK_SHADOW_IN, gtkEntry->style, entryPath +
  1384                                            GTK_SHADOW_IN, gtkEntry->style, entryPath +
  1384                                            QString::number(focus) + QString::number(comboBox->editable) +
  1385                                            QString::number(focus) + QString::number(comboBox->editable) +
  1419                     GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1420                     GTK_WIDGET_UNSET_FLAGS(gtkToggleButton, GTK_HAS_FOCUS);
  1420 
  1421 
  1421                 // Draw the separator between label and arrows
  1422                 // Draw the separator between label and arrows
  1422                 QString vSeparatorPath = buttonPath + QLS(".GtkHBox.GtkVSeparator");
  1423                 QString vSeparatorPath = buttonPath + QLS(".GtkHBox.GtkVSeparator");
  1423 
  1424 
  1424                 if (GtkWidget *gtkVSeparator = QGtk::gtkWidget(vSeparatorPath)) {
  1425                 if (GtkWidget *gtkVSeparator = d->gtkWidget(vSeparatorPath)) {
  1425                     QRect vLineRect(gtkVSeparator->allocation.x,
  1426                     QRect vLineRect(gtkVSeparator->allocation.x,
  1426                                     gtkVSeparator->allocation.y,
  1427                                     gtkVSeparator->allocation.y,
  1427                                     gtkVSeparator->allocation.width,
  1428                                     gtkVSeparator->allocation.width,
  1428                                     gtkVSeparator->allocation.height);
  1429                                     gtkVSeparator->allocation.height);
  1429 
  1430 
  1431                                            vLineRect, state, gtkVSeparator->style,
  1432                                            vLineRect, state, gtkVSeparator->style,
  1432                                            0, vLineRect.height(), 0,  vSeparatorPath);
  1433                                            0, vLineRect.height(), 0,  vSeparatorPath);
  1433 
  1434 
  1434 
  1435 
  1435                     gint interiorFocus = true;
  1436                     gint interiorFocus = true;
  1436                     QGtk::gtk_widget_style_get(gtkToggleButton, "interior-focus", &interiorFocus, NULL);
  1437                     d->gtk_widget_style_get(gtkToggleButton, "interior-focus", &interiorFocus, NULL);
  1437                     int xt = interiorFocus ? gtkToggleButton->style->xthickness : 0;
  1438                     int xt = interiorFocus ? gtkToggleButton->style->xthickness : 0;
  1438                     int yt = interiorFocus ? gtkToggleButton->style->ythickness : 0;
  1439                     int yt = interiorFocus ? gtkToggleButton->style->ythickness : 0;
  1439                     if (focus && ((option->state & State_KeyboardFocusChange) || styleHint(SH_UnderlineShortcut, option, widget)))
  1440                     if (focus && ((option->state & State_KeyboardFocusChange) || styleHint(SH_UnderlineShortcut, option, widget)))
  1440                         gtkCachedPainter.paintFocus(gtkToggleButton, "button",
  1441                         gtkCachedPainter.paintFocus(gtkToggleButton, "button",
  1441                                               option->rect.adjusted(xt, yt, -xt, -yt),
  1442                                               option->rect.adjusted(xt, yt, -xt, -yt),
  1455                     state = GTK_STATE_NORMAL;
  1456                     state = GTK_STATE_NORMAL;
  1456 
  1457 
  1457                 QString arrowPath = comboBoxPath + QLS(appears_as_list ? ".GtkToggleButton.GtkArrow"
  1458                 QString arrowPath = comboBoxPath + QLS(appears_as_list ? ".GtkToggleButton.GtkArrow"
  1458                                                     : ".GtkToggleButton.GtkHBox.GtkArrow");
  1459                                                     : ".GtkToggleButton.GtkHBox.GtkArrow");
  1459 
  1460 
  1460                 GtkWidget *gtkArrow = QGtk::gtkWidget(arrowPath);
  1461                 GtkWidget *gtkArrow = d->gtkWidget(arrowPath);
  1461                 gfloat scale = 0.7;
  1462                 gfloat scale = 0.7;
  1462                 gint minSize = 15;
  1463                 gint minSize = 15;
  1463                 QRect arrowWidgetRect;
  1464                 QRect arrowWidgetRect;
  1464 
  1465 
  1465                 if (gtkArrow && !QGtk::gtk_check_version(2, 12, 0)) {
  1466                 if (gtkArrow && !d->gtk_check_version(2, 12, 0)) {
  1466                     QGtk::gtk_widget_style_get(gtkArrow, "arrow-scaling", &scale, NULL);
  1467                     d->gtk_widget_style_get(gtkArrow, "arrow-scaling", &scale, NULL);
  1467                     QGtk::gtk_widget_style_get(gtkCombo, "arrow-size", &minSize, NULL);
  1468                     d->gtk_widget_style_get(gtkCombo, "arrow-size", &minSize, NULL);
  1468                 }
  1469                 }
  1469                 if (gtkArrow) {
  1470                 if (gtkArrow) {
  1470                     arrowWidgetRect = QRect(gtkArrow->allocation.x, gtkArrow->allocation.y,
  1471                     arrowWidgetRect = QRect(gtkArrow->allocation.x, gtkArrow->allocation.y,
  1471                                             gtkArrow->allocation.width, gtkArrow->allocation.height);
  1472                                             gtkArrow->allocation.width, gtkArrow->allocation.height);
  1472                     style = gtkArrow->style;
  1473                     style = gtkArrow->style;
  1480 
  1481 
  1481                 arrowRect.moveCenter(arrowWidgetRect.center());
  1482                 arrowRect.moveCenter(arrowWidgetRect.center());
  1482 
  1483 
  1483                 if (sunken) {
  1484                 if (sunken) {
  1484                     int xoff, yoff;
  1485                     int xoff, yoff;
  1485                     GtkWidget *gtkButton = QGtk::gtkWidget(comboBoxPath + QLS(".GtkToggleButton"));
  1486                     GtkWidget *gtkButton = d->gtkWidget(comboBoxPath + QLS(".GtkToggleButton"));
  1486                     QGtk::gtk_widget_style_get(gtkButton, "child-displacement-x", &xoff, NULL);
  1487                     d->gtk_widget_style_get(gtkButton, "child-displacement-x", &xoff, NULL);
  1487                     QGtk::gtk_widget_style_get(gtkButton, "child-displacement-y", &yoff, NULL);
  1488                     d->gtk_widget_style_get(gtkButton, "child-displacement-y", &yoff, NULL);
  1488                     arrowRect = arrowRect.adjusted(xoff, yoff, xoff, yoff);
  1489                     arrowRect = arrowRect.adjusted(xoff, yoff, xoff, yoff);
  1489                 }
  1490                 }
  1490 
  1491 
  1491                 // Some styles such as Nimbus paint outside the arrowRect
  1492                 // Some styles such as Nimbus paint outside the arrowRect
  1492                 // hence we have provide the whole widget as the cliprect
  1493                 // hence we have provide the whole widget as the cliprect
  1553                 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
  1554                 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
  1554             }
  1555             }
  1555 
  1556 
  1556             QStyleOptionToolButton label = *toolbutton;
  1557             QStyleOptionToolButton label = *toolbutton;
  1557             label.state = bflags;
  1558             label.state = bflags;
  1558             GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton"));
  1559             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkToolButton.GtkButton"));
  1559             QPalette pal = toolbutton->palette;
  1560             QPalette pal = toolbutton->palette;
  1560             if (option->state & State_Enabled && 
  1561             if (option->state & State_Enabled && 
  1561                 option->state & State_MouseOver && !(widget && widget->testAttribute(Qt::WA_SetPalette))) {
  1562                 option->state & State_MouseOver && !(widget && widget->testAttribute(Qt::WA_SetPalette))) {
  1562                 GdkColor gdkText = gtkButton->style->fg[GTK_STATE_PRELIGHT];
  1563                 GdkColor gdkText = gtkButton->style->fg[GTK_STATE_PRELIGHT];
  1563                 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
  1564                 QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
  1588 #endif // QT_NO_TOOLBUTTON
  1589 #endif // QT_NO_TOOLBUTTON
  1589 #ifndef QT_NO_SCROLLBAR
  1590 #ifndef QT_NO_SCROLLBAR
  1590 
  1591 
  1591     case CC_ScrollBar:
  1592     case CC_ScrollBar:
  1592         if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
  1593         if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
  1593             GtkWidget *gtkHScrollBar = QGtk::gtkWidget(QLS("GtkHScrollbar"));
  1594             GtkWidget *gtkHScrollBar = d->gtkWidget(QLS("GtkHScrollbar"));
  1594             GtkWidget *gtkVScrollBar = QGtk::gtkWidget(QLS("GtkVScrollbar"));
  1595             GtkWidget *gtkVScrollBar = d->gtkWidget(QLS("GtkVScrollbar"));
  1595 
  1596 
  1596             // Fill background in case the scrollbar is partially transparent
  1597             // Fill background in case the scrollbar is partially transparent
  1597             painter->fillRect(option->rect, option->palette.background());
  1598             painter->fillRect(option->rect, option->palette.background());
  1598 
  1599 
  1599             QRect rect = scrollBar->rect;
  1600             QRect rect = scrollBar->rect;
  1606             style = scrollbarWidget->style;
  1607             style = scrollbarWidget->style;
  1607             gboolean trough_under_steppers = true;
  1608             gboolean trough_under_steppers = true;
  1608             gboolean trough_side_details = false;
  1609             gboolean trough_side_details = false;
  1609             gboolean stepper_size = 14;
  1610             gboolean stepper_size = 14;
  1610             gint trough_border = 1;
  1611             gint trough_border = 1;
  1611             if (!QGtk::gtk_check_version(2, 10, 0)) {
  1612             if (!d->gtk_check_version(2, 10, 0)) {
  1612                 QGtk::gtk_widget_style_get((GtkWidget*)(scrollbarWidget),
  1613                 d->gtk_widget_style_get((GtkWidget*)(scrollbarWidget),
  1613                                            "trough-border",   &trough_border,
  1614                                            "trough-border",   &trough_border,
  1614                                            "trough-side-details",   &trough_side_details,
  1615                                            "trough-side-details",   &trough_side_details,
  1615                                            "trough-under-steppers", &trough_under_steppers,
  1616                                            "trough-under-steppers", &trough_under_steppers,
  1616                                            "stepper-size",          &stepper_size, NULL);
  1617                                            "stepper-size",          &stepper_size, NULL);
  1617             }
  1618             }
  1631                 maximum = 0;
  1632                 maximum = 0;
  1632             if (scrollBar->sliderPosition == scrollBar->maximum)
  1633             if (scrollBar->sliderPosition == scrollBar->maximum)
  1633                 fakePos = maximum;
  1634                 fakePos = maximum;
  1634             else if (scrollBar->sliderPosition > scrollBar->minimum)
  1635             else if (scrollBar->sliderPosition > scrollBar->minimum)
  1635                 fakePos = maximum - 1;
  1636                 fakePos = maximum - 1;
  1636             GtkObject *adjustment =  QGtk::gtk_adjustment_new(fakePos, 0, maximum, 0, 0, 0);
  1637             GtkObject *adjustment =  d->gtk_adjustment_new(fakePos, 0, maximum, 0, 0, 0);
  1637 
  1638 
  1638             if (horizontal)
  1639             if (horizontal)
  1639                 QGtk::gtk_range_set_adjustment((GtkRange*)(gtkHScrollBar), (GtkAdjustment*)(adjustment));
  1640                 d->gtk_range_set_adjustment((GtkRange*)(gtkHScrollBar), (GtkAdjustment*)(adjustment));
  1640             else
  1641             else
  1641                 QGtk::gtk_range_set_adjustment((GtkRange*)(gtkVScrollBar), (GtkAdjustment*)(adjustment));
  1642                 d->gtk_range_set_adjustment((GtkRange*)(gtkVScrollBar), (GtkAdjustment*)(adjustment));
  1642 
  1643 
  1643             if (scrollBar->subControls & SC_ScrollBarGroove) {
  1644             if (scrollBar->subControls & SC_ScrollBarGroove) {
  1644                 GtkStateType state = GTK_STATE_ACTIVE;
  1645                 GtkStateType state = GTK_STATE_ACTIVE;
  1645 
  1646 
  1646                 if (!(option->state & State_Enabled))
  1647                 if (!(option->state & State_Enabled))
  1733 #endif //QT_NO_SCROLLBAR
  1734 #endif //QT_NO_SCROLLBAR
  1734 #ifndef QT_NO_SPINBOX
  1735 #ifndef QT_NO_SPINBOX
  1735 
  1736 
  1736     case CC_SpinBox:
  1737     case CC_SpinBox:
  1737         if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  1738         if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  1738             GtkWidget *gtkSpinButton = QGtk::gtkWidget(QLS("GtkSpinButton"));
  1739             GtkWidget *gtkSpinButton = d->gtkWidget(QLS("GtkSpinButton"));
  1739             bool isEnabled = (spinBox->state & State_Enabled);
  1740             bool isEnabled = (spinBox->state & State_Enabled);
  1740             bool hover = isEnabled && (spinBox->state & State_MouseOver);
  1741             bool hover = isEnabled && (spinBox->state & State_MouseOver);
  1741             bool sunken = (spinBox->state & State_Sunken);
  1742             bool sunken = (spinBox->state & State_Sunken);
  1742             bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
  1743             bool upIsActive = (spinBox->activeSubControls == SC_SpinBoxUp);
  1743             bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
  1744             bool downIsActive = (spinBox->activeSubControls == SC_SpinBoxDown);
  1848                 } else {
  1849                 } else {
  1849                     painter->drawLine(centerX - 2, centerY, centerX + 2, centerY);
  1850                     painter->drawLine(centerX - 2, centerY, centerX + 2, centerY);
  1850                 }
  1851                 }
  1851 
  1852 
  1852             } else {
  1853             } else {
  1853                 int size = spinboxArrowSize();
  1854                 int size = d->getSpinboxArrowSize();
  1854                 int w = size / 2 - 1;
  1855                 int w = size / 2 - 1;
  1855                 w -= w % 2 - 1; // force odd
  1856                 w -= w % 2 - 1; // force odd
  1856                 int h = (w + 1)/2;
  1857                 int h = (w + 1)/2;
  1857                 QRect arrowRect(0, 0, w, h);
  1858                 QRect arrowRect(0, 0, w, h);
  1858                 arrowRect.moveCenter(upRect.center());
  1859                 arrowRect.moveCenter(upRect.center());
  1880 
  1881 
  1881 #ifndef QT_NO_SLIDER
  1882 #ifndef QT_NO_SLIDER
  1882 
  1883 
  1883     case CC_Slider:
  1884     case CC_Slider:
  1884         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
  1885         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
  1885             GtkWidget *hScaleWidget = QGtk::gtkWidget(QLS("GtkHScale"));
  1886             GtkWidget *hScaleWidget = d->gtkWidget(QLS("GtkHScale"));
  1886             GtkWidget *vScaleWidget = QGtk::gtkWidget(QLS("GtkVScale"));
  1887             GtkWidget *vScaleWidget = d->gtkWidget(QLS("GtkVScale"));
  1887 
  1888 
  1888             QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
  1889             QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
  1889             QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
  1890             QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
  1890             QRect ticks = proxy()->subControlRect(CC_Slider, option, SC_SliderTickmarks, widget);
  1891             QRect ticks = proxy()->subControlRect(CC_Slider, option, SC_SliderTickmarks, widget);
  1891 
  1892 
  1905 
  1906 
  1906             GtkWidget *scaleWidget = horizontal ? hScaleWidget : vScaleWidget;
  1907             GtkWidget *scaleWidget = horizontal ? hScaleWidget : vScaleWidget;
  1907             style = scaleWidget->style;
  1908             style = scaleWidget->style;
  1908 
  1909 
  1909             if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
  1910             if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
  1910                 GtkObject *adjustment =  QGtk::gtk_adjustment_new(slider->sliderPosition,
  1911                 GtkObject *adjustment =  d->gtk_adjustment_new(slider->sliderPosition,
  1911                                          slider->minimum,
  1912                                          slider->minimum,
  1912                                          slider->maximum,
  1913                                          slider->maximum,
  1913                                          slider->singleStep,
  1914                                          slider->singleStep,
  1914                                          slider->singleStep,
  1915                                          slider->singleStep,
  1915                                          slider->pageStep);
  1916                                          slider->pageStep);
  1916                 int outerSize;
  1917                 int outerSize;
  1917                 QGtk::gtk_range_set_adjustment ((GtkRange*)(scaleWidget), (GtkAdjustment*)(adjustment));
  1918                 d->gtk_range_set_adjustment ((GtkRange*)(scaleWidget), (GtkAdjustment*)(adjustment));
  1918                 QGtk::gtk_range_set_inverted((GtkRange*)(scaleWidget), !horizontal);
  1919                 d->gtk_range_set_inverted((GtkRange*)(scaleWidget), !horizontal);
  1919                 QGtk::gtk_widget_style_get(scaleWidget, "trough-border", &outerSize, NULL);
  1920                 d->gtk_widget_style_get(scaleWidget, "trough-border", &outerSize, NULL);
  1920                 outerSize++;
  1921                 outerSize++;
  1921 
  1922 
  1922                 GtkStateType state = gtkPainter.gtkState(option);
  1923                 GtkStateType state = gtkPainter.gtkState(option);
  1923                 int focusFrameMargin = 2;
  1924                 int focusFrameMargin = 2;
  1924                 QRect grooveRect = option->rect.adjusted(focusFrameMargin, outerSize + focusFrameMargin,
  1925                 QRect grooveRect = option->rect.adjusted(focusFrameMargin, outerSize + focusFrameMargin,
  1925                                    -focusFrameMargin, -outerSize - focusFrameMargin);
  1926                                    -focusFrameMargin, -outerSize - focusFrameMargin);
  1926 
  1927 
  1927                 gtkPainter.paintBox( scaleWidget, "trough", grooveRect, state,
       
  1928                                      GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
       
  1929 
       
  1930                 gboolean trough_side_details = false; // Indicates if the upper or lower scale background differs
  1928                 gboolean trough_side_details = false; // Indicates if the upper or lower scale background differs
  1931                 if (!QGtk::gtk_check_version(2, 10, 0))
  1929                 if (!d->gtk_check_version(2, 10, 0))
  1932                     QGtk::gtk_widget_style_get((GtkWidget*)(scaleWidget), "trough-side-details",   &trough_side_details, NULL);
  1930                     d->gtk_widget_style_get((GtkWidget*)(scaleWidget), "trough-side-details",   &trough_side_details, NULL);
  1933 
  1931 
  1934                 if (trough_side_details && horizontal) { //### Vertical sliders look broken with this for some reason
  1932                 if (!trough_side_details) {
       
  1933                     gtkPainter.paintBox( scaleWidget, "trough", grooveRect, state,
       
  1934                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
       
  1935                 } else {
       
  1936                     QRect upperGroove = grooveRect;
  1935                     QRect lowerGroove = grooveRect;
  1937                     QRect lowerGroove = grooveRect;
  1936                     lowerGroove.setRight(handle.center().x());
  1938 
       
  1939                     if (horizontal) {
       
  1940                         upperGroove.setLeft(handle.center().x());
       
  1941                         lowerGroove.setRight(handle.center().x());
       
  1942                     } else {
       
  1943                         upperGroove.setBottom(handle.center().y());
       
  1944                         lowerGroove.setTop(handle.center().y());
       
  1945                     }
       
  1946 
       
  1947                     gtkPainter.paintBox( scaleWidget, "trough-upper", upperGroove, state,
       
  1948                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
  1937                     gtkPainter.paintBox( scaleWidget, "trough-lower", lowerGroove, state,
  1949                     gtkPainter.paintBox( scaleWidget, "trough-lower", lowerGroove, state,
  1938                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
  1950                                          GTK_SHADOW_IN, style, QString(QLS("p%0")).arg(slider->sliderPosition));
  1939                 }
  1951                 }
  1940 
       
  1941             }
  1952             }
  1942 
  1953 
  1943             if (option->subControls & SC_SliderTickmarks) {
  1954             if (option->subControls & SC_SliderTickmarks) {
  1944                 painter->setPen(darkOutline);
  1955                 painter->setPen(darkOutline);
  1945                 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
  1956                 int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
  2048 void QGtkStyle::drawControl(ControlElement element,
  2059 void QGtkStyle::drawControl(ControlElement element,
  2049                             const QStyleOption *option,
  2060                             const QStyleOption *option,
  2050                             QPainter *painter,
  2061                             QPainter *painter,
  2051                             const QWidget *widget) const
  2062                             const QWidget *widget) const
  2052 {
  2063 {
  2053     if (!QGtk::isThemeAvailable()) {
  2064     Q_D(const QGtkStyle);
       
  2065 
       
  2066     if (!d->isThemeAvailable()) {
  2054         QCleanlooksStyle::drawControl(element, option, painter, widget);
  2067         QCleanlooksStyle::drawControl(element, option, painter, widget);
  2055         return;
  2068         return;
  2056     }
  2069     }
  2057 
  2070 
  2058     GtkStyle* style = QGtk::gtkStyle();
  2071     GtkStyle* style = d->gtkStyle();
  2059     QGtkPainter gtkPainter(painter);
  2072     QGtkPainter gtkPainter(painter);
  2060 
  2073 
  2061     switch (element) {
  2074     switch (element) {
  2062     case CE_ProgressBarLabel:
  2075     case CE_ProgressBarLabel:
  2063         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2076         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2064             GtkWidget *gtkProgressBar = QGtk::gtkWidget(QLS("GtkProgressBar"));
  2077             GtkWidget *gtkProgressBar = d->gtkWidget(QLS("GtkProgressBar"));
  2065             if (!gtkProgressBar)
  2078             if (!gtkProgressBar)
  2066                 return;
  2079                 return;
  2067 
  2080 
  2068             QRect leftRect;
  2081             QRect leftRect;
  2069             QRect rect = bar->rect;
  2082             QRect rect = bar->rect;
  2162             ir.translate(buttonShift);
  2175             ir.translate(buttonShift);
  2163 
  2176 
  2164             if (button->features & QStyleOptionButton::HasMenu)
  2177             if (button->features & QStyleOptionButton::HasMenu)
  2165                 ir = ir.adjusted(0, 0, -pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
  2178                 ir = ir.adjusted(0, 0, -pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
  2166 
  2179 
  2167             GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton"));
  2180             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
  2168             QPalette pal = button->palette;
  2181             QPalette pal = button->palette;
  2169             int labelState = GTK_STATE_INSENSITIVE;
  2182             int labelState = GTK_STATE_INSENSITIVE;
  2170             if (option->state & State_Enabled)
  2183             if (option->state & State_Enabled)
  2171                 labelState = (option->state & State_MouseOver && !(option->state & State_Sunken)) ?
  2184                 labelState = (option->state & State_MouseOver && !(option->state & State_Sunken)) ?
  2172                              GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
  2185                              GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
  2183     case CE_CheckBox:
  2196     case CE_CheckBox:
  2184         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  2197         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  2185             bool isRadio = (element == CE_RadioButton);
  2198             bool isRadio = (element == CE_RadioButton);
  2186 
  2199 
  2187             // Draw prelight background
  2200             // Draw prelight background
  2188             GtkWidget *gtkRadioButton = QGtk::gtkWidget(QLS("GtkRadioButton"));
  2201             GtkWidget *gtkRadioButton = d->gtkWidget(QLS("GtkRadioButton"));
  2189 
  2202 
  2190             if (option->state & State_MouseOver) {
  2203             if (option->state & State_MouseOver) {
  2191                 gtkPainter.paintFlatBox(gtkRadioButton, "checkbutton", option->rect,
  2204                 gtkPainter.paintFlatBox(gtkRadioButton, "checkbutton", option->rect,
  2192                                         GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkRadioButton->style);
  2205                                         GTK_STATE_PRELIGHT, GTK_SHADOW_ETCHED_OUT, gtkRadioButton->style);
  2193             }
  2206             }
  2251                 else
  2264                 else
  2252                     editRect.translate(cb->iconSize.width() + 4, 0);
  2265                     editRect.translate(cb->iconSize.width() + 4, 0);
  2253             }
  2266             }
  2254 
  2267 
  2255             if (!cb->currentText.isEmpty() && !cb->editable) {
  2268             if (!cb->currentText.isEmpty() && !cb->editable) {
  2256                 GtkWidget *gtkCombo = QGtk::gtkWidget(QLS("GtkComboBox"));
  2269                 GtkWidget *gtkCombo = d->gtkWidget(QLS("GtkComboBox"));
  2257                 QPalette pal = cb->palette;
  2270                 QPalette pal = cb->palette;
  2258                 int labelState = GTK_STATE_INSENSITIVE;
  2271                 int labelState = GTK_STATE_INSENSITIVE;
  2259 
  2272 
  2260                 if (option->state & State_Enabled)
  2273                 if (option->state & State_Enabled)
  2261                     labelState = (option->state & State_MouseOver && !appearsAsList) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
  2274                     labelState = (option->state & State_MouseOver && !appearsAsList) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
  2328         painter->save();
  2341         painter->save();
  2329 
  2342 
  2330         // Draws the header in tables.
  2343         // Draws the header in tables.
  2331         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
  2344         if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
  2332             Q_UNUSED(header);
  2345             Q_UNUSED(header);
  2333             GtkWidget *gtkTreeView = QGtk::gtkWidget(QLS("GtkTreeView"));
  2346             GtkWidget *gtkTreeView = d->gtkWidget(QLS("GtkTreeView"));
  2334             // Get the middle column
  2347             // Get the middle column
  2335             GtkTreeViewColumn *column = QGtk::gtk_tree_view_get_column((GtkTreeView*)gtkTreeView, 1);
  2348             GtkTreeViewColumn *column = d->gtk_tree_view_get_column((GtkTreeView*)gtkTreeView, 1);
  2336             Q_ASSERT(column);
  2349             Q_ASSERT(column);
  2337 
  2350 
  2338             GtkWidget *gtkTreeHeader = column->button;
  2351             GtkWidget *gtkTreeHeader = column->button;
  2339             GtkStateType state = gtkPainter.gtkState(option);
  2352             GtkStateType state = gtkPainter.gtkState(option);
  2340             GtkShadowType shadow = GTK_SHADOW_OUT;
  2353             GtkShadowType shadow = GTK_SHADOW_OUT;
  2349         break;
  2362         break;
  2350 
  2363 
  2351 #ifndef QT_NO_SIZEGRIP
  2364 #ifndef QT_NO_SIZEGRIP
  2352 
  2365 
  2353     case CE_SizeGrip: {
  2366     case CE_SizeGrip: {
  2354         GtkWidget *gtkStatusbar = QGtk::gtkWidget(QLS("GtkStatusbar.GtkFrame"));
  2367         GtkWidget *gtkStatusbar = d->gtkWidget(QLS("GtkStatusbar.GtkFrame"));
  2355         QRect gripRect = option->rect.adjusted(0, 0, -gtkStatusbar->style->xthickness, -gtkStatusbar->style->ythickness);
  2368         QRect gripRect = option->rect.adjusted(0, 0, -gtkStatusbar->style->xthickness, -gtkStatusbar->style->ythickness);
  2356         gtkPainter.paintResizeGrip( gtkStatusbar, "statusbar", gripRect, GTK_STATE_NORMAL,
  2369         gtkPainter.paintResizeGrip( gtkStatusbar, "statusbar", gripRect, GTK_STATE_NORMAL,
  2357                                     GTK_SHADOW_OUT, QApplication::isRightToLeft() ?
  2370                                     GTK_SHADOW_OUT, QApplication::isRightToLeft() ?
  2358                                         GDK_WINDOW_EDGE_SOUTH_WEST : GDK_WINDOW_EDGE_SOUTH_EAST,
  2371                                         GDK_WINDOW_EDGE_SOUTH_WEST : GDK_WINDOW_EDGE_SOUTH_EAST,
  2359                                     gtkStatusbar->style);
  2372                                     gtkStatusbar->style);
  2361     break;
  2374     break;
  2362 
  2375 
  2363 #endif // QT_NO_SIZEGRIP
  2376 #endif // QT_NO_SIZEGRIP
  2364 
  2377 
  2365     case CE_MenuBarEmptyArea: {
  2378     case CE_MenuBarEmptyArea: {
  2366         GtkWidget *gtkMenubar = QGtk::gtkWidget(QLS("GtkMenuBar"));
  2379         GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar"));
  2367         GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
  2380         GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
  2368         painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
  2381         painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
  2369         if (widget) { // See CE_MenuBarItem
  2382         if (widget) { // See CE_MenuBarItem
  2370             QRect menuBarRect = widget->rect();
  2383             QRect menuBarRect = widget->rect();
  2371             QPixmap pixmap(menuBarRect.size());
  2384             QPixmap pixmap(menuBarRect.size());
  2372             pixmap.fill(Qt::transparent);
  2385             pixmap.fill(Qt::transparent);
  2373             QPainter pmPainter(&pixmap);
  2386             QPainter pmPainter(&pixmap);
  2374             QGtkPainter gtkMenuBarPainter(&pmPainter);
  2387             QGtkPainter gtkMenuBarPainter(&pmPainter);
  2375             GtkShadowType shadow_type;
  2388             GtkShadowType shadow_type;
  2376             QGtk::gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL);
  2389             d->gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL);
  2377             gtkMenuBarPainter.paintBox( gtkMenubar, "menubar",  menuBarRect,
  2390             gtkMenuBarPainter.paintBox( gtkMenubar, "menubar",  menuBarRect,
  2378                                         GTK_STATE_NORMAL, shadow_type, gtkMenubar->style);
  2391                                         GTK_STATE_NORMAL, shadow_type, gtkMenubar->style);
  2379             pmPainter.end();
  2392             pmPainter.end();
  2380             painter->drawPixmap(option->rect, pixmap, option->rect);
  2393             painter->drawPixmap(option->rect, pixmap, option->rect);
  2381         }
  2394         }
  2384 
  2397 
  2385     case CE_MenuBarItem:
  2398     case CE_MenuBarItem:
  2386         painter->save();
  2399         painter->save();
  2387 
  2400 
  2388         if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  2401         if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  2389             GtkWidget *gtkMenubarItem = QGtk::gtkWidget(QLS("GtkMenuBar.GtkMenuItem"));
  2402             GtkWidget *gtkMenubarItem = d->gtkWidget(QLS("GtkMenuBar.GtkMenuItem"));
  2390             GtkWidget *gtkMenubar = QGtk::gtkWidget(QLS("GtkMenuBar"));
  2403             GtkWidget *gtkMenubar = d->gtkWidget(QLS("GtkMenuBar"));
  2391 
  2404 
  2392             style = gtkMenubarItem->style;
  2405             style = gtkMenubarItem->style;
  2393 
  2406 
  2394             if (widget) {
  2407             if (widget) {
  2395                 // Since Qt does not currently allow filling the entire background
  2408                 // Since Qt does not currently allow filling the entire background
  2400                 QPixmap pixmap(menuBarRect.size());
  2413                 QPixmap pixmap(menuBarRect.size());
  2401                 pixmap.fill(Qt::transparent);
  2414                 pixmap.fill(Qt::transparent);
  2402                 QPainter pmPainter(&pixmap);
  2415                 QPainter pmPainter(&pixmap);
  2403                 QGtkPainter menubarPainter(&pmPainter);
  2416                 QGtkPainter menubarPainter(&pmPainter);
  2404                 GtkShadowType shadow_type;
  2417                 GtkShadowType shadow_type;
  2405                 QGtk::gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL);
  2418                 d->gtk_widget_style_get(gtkMenubar, "shadow-type", &shadow_type, NULL);
  2406                 GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
  2419                 GdkColor gdkBg = gtkMenubar->style->bg[GTK_STATE_NORMAL]; // Theme can depend on transparency
  2407                 painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
  2420                 painter->fillRect(option->rect, QColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8));
  2408                 menubarPainter.paintBox(gtkMenubar, "menubar",  menuBarRect,
  2421                 menubarPainter.paintBox(gtkMenubar, "menubar",  menuBarRect,
  2409                                         GTK_STATE_NORMAL, shadow_type, gtkMenubar->style);
  2422                                         GTK_STATE_NORMAL, shadow_type, gtkMenubar->style);
  2410                 pmPainter.end();
  2423                 pmPainter.end();
  2424             item.palette.setBrush(QPalette::ButtonText, normalTextColor);
  2437             item.palette.setBrush(QPalette::ButtonText, normalTextColor);
  2425             QCommonStyle::drawControl(element, &item, painter, widget);
  2438             QCommonStyle::drawControl(element, &item, painter, widget);
  2426 
  2439 
  2427             if (act) {
  2440             if (act) {
  2428                 GtkShadowType shadowType = GTK_SHADOW_NONE;
  2441                 GtkShadowType shadowType = GTK_SHADOW_NONE;
  2429                 QGtk::gtk_widget_style_get (gtkMenubarItem, "selected-shadow-type", &shadowType, NULL);
  2442                 d->gtk_widget_style_get (gtkMenubarItem, "selected-shadow-type", &shadowType, NULL);
  2430                 gtkPainter.paintBox(gtkMenubarItem, "menuitem",  option->rect.adjusted(0, 0, 0, 3),
  2443                 gtkPainter.paintBox(gtkMenubarItem, "menuitem",  option->rect.adjusted(0, 0, 0, 3),
  2431                                     GTK_STATE_PRELIGHT, shadowType, gtkMenubarItem->style);
  2444                                     GTK_STATE_PRELIGHT, shadowType, gtkMenubarItem->style);
  2432                 //draw text
  2445                 //draw text
  2433                 QPalette::ColorRole textRole = dis ? QPalette::Text : QPalette::HighlightedText;
  2446                 QPalette::ColorRole textRole = dis ? QPalette::Text : QPalette::HighlightedText;
  2434                 uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
  2447                 uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
  2441         }
  2454         }
  2442         painter->restore();
  2455         painter->restore();
  2443         break;
  2456         break;
  2444 
  2457 
  2445     case CE_Splitter: {
  2458     case CE_Splitter: {
  2446         GtkWidget *gtkWindow = QGtk::gtkWidget(QLS("GtkWindow")); // The Murrine Engine currently assumes a widget is passed
  2459         GtkWidget *gtkWindow = d->gtkWidget(QLS("GtkWindow")); // The Murrine Engine currently assumes a widget is passed
  2447         gtkPainter.paintHandle(gtkWindow, "splitter", option->rect, gtkPainter.gtkState(option), GTK_SHADOW_NONE,
  2460         gtkPainter.paintHandle(gtkWindow, "splitter", option->rect, gtkPainter.gtkState(option), GTK_SHADOW_NONE,
  2448                                 !(option->state & State_Horizontal) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL,
  2461                                 !(option->state & State_Horizontal) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL,
  2449                                 style);
  2462                                 style);
  2450     }
  2463     }
  2451     break;
  2464     break;
  2461             QRect rect = option->rect;
  2474             QRect rect = option->rect;
  2462             // There is a 1 pixel gap between toolbar lines in some styles (i.e Human)
  2475             // There is a 1 pixel gap between toolbar lines in some styles (i.e Human)
  2463             if (toolbar->positionWithinLine != QStyleOptionToolBar::End)
  2476             if (toolbar->positionWithinLine != QStyleOptionToolBar::End)
  2464                 rect.adjust(0, 0, 1, 0);
  2477                 rect.adjust(0, 0, 1, 0);
  2465 
  2478 
  2466             GtkWidget *gtkToolbar = QGtk::gtkWidget(QLS("GtkToolbar"));
  2479             GtkWidget *gtkToolbar = d->gtkWidget(QLS("GtkToolbar"));
  2467             GtkShadowType shadow_type = GTK_SHADOW_NONE;
  2480             GtkShadowType shadow_type = GTK_SHADOW_NONE;
  2468             QGtk::gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
  2481             d->gtk_widget_style_get(gtkToolbar, "shadow-type", &shadow_type, NULL);
  2469             gtkPainter.paintBox( gtkToolbar, "toolbar",  rect,
  2482             gtkPainter.paintBox( gtkToolbar, "toolbar",  rect,
  2470                                  GTK_STATE_NORMAL, shadow_type, gtkToolbar->style);
  2483                                  GTK_STATE_NORMAL, shadow_type, gtkToolbar->style);
  2471         }
  2484         }
  2472         break;
  2485         break;
  2473 
  2486 
  2480         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  2493         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  2481             const int windowsItemFrame        =  2; // menu item frame width
  2494             const int windowsItemFrame        =  2; // menu item frame width
  2482             const int windowsItemHMargin      =  3; // menu item hor text margin
  2495             const int windowsItemHMargin      =  3; // menu item hor text margin
  2483             const int windowsItemVMargin      = 26; // menu item ver text margin
  2496             const int windowsItemVMargin      = 26; // menu item ver text margin
  2484             const int windowsRightBorder      = 15; // right border on windows
  2497             const int windowsRightBorder      = 15; // right border on windows
  2485             GtkWidget *gtkMenu = QGtk::gtkWidget(QLS("GtkMenu"));
  2498             GtkWidget *gtkMenu = d->gtkWidget(QLS("GtkMenu"));
  2486             GtkWidget *gtkMenuItem = menuItem->checked ? QGtk::gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")) :
  2499             GtkWidget *gtkMenuItem = menuItem->checked ? d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")) :
  2487                                      QGtk::gtkWidget(QLS("GtkMenu.GtkMenuItem"));
  2500                                      d->gtkWidget(QLS("GtkMenu.GtkMenuItem"));
  2488 
  2501 
  2489             style = gtkPainter.getStyle(gtkMenuItem);
  2502             style = gtkPainter.getStyle(gtkMenuItem);
  2490             QColor borderColor = option->palette.background().color().darker(160);
  2503             QColor borderColor = option->palette.background().color().darker(160);
  2491             QColor shadow = option->palette.dark().color();
  2504             QColor shadow = option->palette.dark().color();
  2492 
  2505 
  2493             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  2506             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  2494                 GtkWidget *gtkMenuSeparator = QGtk::gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem"));
  2507                 GtkWidget *gtkMenuSeparator = d->gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem"));
  2495                 painter->setPen(shadow.lighter(106));
  2508                 painter->setPen(shadow.lighter(106));
  2496                 gboolean wide_separators = 0;
  2509                 gboolean wide_separators = 0;
  2497                 gint     separator_height = 0;
  2510                 gint     separator_height = 0;
  2498                 guint    horizontal_padding = 3;
  2511                 guint    horizontal_padding = 3;
  2499                 if (!QGtk::gtk_check_version(2, 10, 0)) {
  2512                 if (!d->gtk_check_version(2, 10, 0)) {
  2500                     QGtk::gtk_widget_style_get(gtkMenuSeparator,
  2513                     d->gtk_widget_style_get(gtkMenuSeparator,
  2501                                            "wide-separators",    &wide_separators,
  2514                                            "wide-separators",    &wide_separators,
  2502                                            "separator-height",   &separator_height,
  2515                                            "separator-height",   &separator_height,
  2503                                            "horizontal-padding", &horizontal_padding,
  2516                                            "horizontal-padding", &horizontal_padding,
  2504                                            NULL);
  2517                                            NULL);
  2505                 }
  2518                 }
  2515             }
  2528             }
  2516 
  2529 
  2517             bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
  2530             bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
  2518 
  2531 
  2519             if (selected) {
  2532             if (selected) {
  2520                 QRect rect = option->rect.adjusted(0, 0, -1, -1);
  2533                 QRect rect = option->rect.adjusted(0, 0, 0, -1);
  2521 #ifndef QT_NO_COMBOBOX
  2534 #ifndef QT_NO_COMBOBOX
  2522                 if (qobject_cast<const QComboBox*>(widget))
  2535                 if (qobject_cast<const QComboBox*>(widget))
  2523                     rect = option->rect;
  2536                     rect = option->rect;
  2524 #endif
  2537 #endif
  2525                 gtkPainter.paintBox( gtkMenuItem, "menuitem", rect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style);
  2538                 gtkPainter.paintBox( gtkMenuItem, "menuitem", rect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style);
  2529             bool checked = menuItem->checked;
  2542             bool checked = menuItem->checked;
  2530             bool enabled = menuItem->state & State_Enabled;
  2543             bool enabled = menuItem->state & State_Enabled;
  2531             bool ignoreCheckMark = false;
  2544             bool ignoreCheckMark = false;
  2532 
  2545 
  2533             gint checkSize;
  2546             gint checkSize;
  2534             QGtk::gtk_widget_style_get(QGtk::gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")), "indicator-size", &checkSize, NULL);
  2547             d->gtk_widget_style_get(d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")), "indicator-size", &checkSize, NULL);
  2535 
  2548 
  2536             int checkcol = qMax(menuItem->maxIconWidth, qMax(20, checkSize));
  2549             int checkcol = qMax(menuItem->maxIconWidth, qMax(20, checkSize));
  2537 
  2550 
  2538 #ifndef QT_NO_COMBOBOX
  2551 #ifndef QT_NO_COMBOBOX
  2539 
  2552 
  2622                     pixmap = menuItem->icon.pixmap(iconSize, mode);
  2635                     pixmap = menuItem->icon.pixmap(iconSize, mode);
  2623 
  2636 
  2624                 int pixw = pixmap.width();
  2637                 int pixw = pixmap.width();
  2625                 int pixh = pixmap.height();
  2638                 int pixh = pixmap.height();
  2626                 QRect pmr(0, 0, pixw, pixh);
  2639                 QRect pmr(0, 0, pixw, pixh);
  2627                 pmr.moveCenter(vCheckRect.center());
  2640                 pmr.moveCenter(vCheckRect.center() - QPoint(0, 1));
  2628                 painter->setPen(menuItem->palette.text().color());
  2641                 painter->setPen(menuItem->palette.text().color());
  2629                 if (!ignoreCheckMark && checkable && checked) {
  2642                 if (!ignoreCheckMark && checkable && checked) {
  2630                     QStyleOption opt = *option;
  2643                     QStyleOption opt = *option;
  2631 
  2644 
  2632                     if (act) {
  2645                     if (act) {
  2664 
  2677 
  2665             int x, y, w, h;
  2678             int x, y, w, h;
  2666             menuitem->rect.getRect(&x, &y, &w, &h);
  2679             menuitem->rect.getRect(&x, &y, &w, &h);
  2667             int tab = menuitem->tabWidth;
  2680             int tab = menuitem->tabWidth;
  2668             int xm = windowsItemFrame + checkcol + windowsItemHMargin;
  2681             int xm = windowsItemFrame + checkcol + windowsItemHMargin;
  2669             int xpos = menuitem->rect.x() + xm;
  2682             int xpos = menuitem->rect.x() + xm + 1;
  2670             QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
  2683             QRect textRect(xpos, y + windowsItemVMargin - 1, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
  2671             QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
  2684             QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
  2672             QString s = menuitem->text;
  2685             QString s = menuitem->text;
  2673 
  2686 
  2674             if (!s.isEmpty()) { // Draw text
  2687             if (!s.isEmpty()) { // Draw text
  2675                 p->save();
  2688                 p->save();
  2712                                    proxy()->pixelMetric(PM_ButtonShiftVertical, option, widget));
  2725                                    proxy()->pixelMetric(PM_ButtonShiftVertical, option, widget));
  2713 
  2726 
  2714                 QFontMetrics fm(menuitem->font);
  2727                 QFontMetrics fm(menuitem->font);
  2715                 int arrow_size = fm.ascent() + fm.descent() - 2 * gtkMenuItem->style->ythickness;
  2728                 int arrow_size = fm.ascent() + fm.descent() - 2 * gtkMenuItem->style->ythickness;
  2716                 gfloat arrow_scaling = 0.8;
  2729                 gfloat arrow_scaling = 0.8;
  2717 
  2730                 int extra = 0;
  2718                 // "arrow-scaling" is actually hardcoded and fails on hardy (see gtk+-2.12/gtkmenuitem.c)
  2731                 if (!d->gtk_check_version(2, 16, 0)) {
  2719                 // though the current documentation states otherwise
  2732                     // "arrow-scaling" is actually hardcoded and fails on hardy (see gtk+-2.12/gtkmenuitem.c)
       
  2733                     // though the current documentation states otherwise
       
  2734                     d->gtk_widget_style_get(gtkMenuItem, "arrow-scaling", &arrow_scaling, NULL);
       
  2735                     // in versions < 2.16 ythickness was previously subtracted from the arrow_size
       
  2736                     extra = 2 * gtkMenuItem->style->ythickness;
       
  2737                 }
       
  2738 
  2720                 int horizontal_padding;
  2739                 int horizontal_padding;
  2721                 QGtk::gtk_widget_style_get(gtkMenuItem, "horizontal-padding", &horizontal_padding, NULL);
  2740                 d->gtk_widget_style_get(gtkMenuItem, "horizontal-padding", &horizontal_padding, NULL);
  2722 
  2741 
  2723                 const int dim = static_cast<int>(arrow_size * arrow_scaling);
  2742                 const int dim = static_cast<int>(arrow_size * arrow_scaling) + extra;
  2724                 int xpos = menuItem->rect.left() + menuItem->rect.width() - horizontal_padding - dim;
  2743                 int xpos = menuItem->rect.left() + menuItem->rect.width() - horizontal_padding - dim;
  2725                 QRect  vSubMenuRect = visualRect(option->direction, menuItem->rect,
  2744                 QRect  vSubMenuRect = visualRect(option->direction, menuItem->rect,
  2726                                                  QRect(xpos, menuItem->rect.top() +
  2745                                                  QRect(xpos, menuItem->rect.top() +
  2727                                                        menuItem->rect.height() / 2 - dim / 2, dim, dim));
  2746                                                        menuItem->rect.height() / 2 - dim / 2, dim, dim));
  2728                 GtkStateType state = enabled ? (act ? GTK_STATE_PRELIGHT: GTK_STATE_NORMAL) : GTK_STATE_INSENSITIVE;
  2747                 GtkStateType state = enabled ? (act ? GTK_STATE_PRELIGHT: GTK_STATE_NORMAL) : GTK_STATE_INSENSITIVE;
  2734         painter->restore();
  2753         painter->restore();
  2735         break;
  2754         break;
  2736 
  2755 
  2737     case CE_PushButton:
  2756     case CE_PushButton:
  2738         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  2757         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  2739             GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton"));
  2758             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
  2740             proxy()->drawControl(CE_PushButtonBevel, btn, painter, widget);
  2759             proxy()->drawControl(CE_PushButtonBevel, btn, painter, widget);
  2741             QStyleOptionButton subopt = *btn;
  2760             QStyleOptionButton subopt = *btn;
  2742             subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
  2761             subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
  2743             gint interiorFocus = true;
  2762             gint interiorFocus = true;
  2744             QGtk::gtk_widget_style_get(gtkButton, "interior-focus", &interiorFocus, NULL);
  2763             d->gtk_widget_style_get(gtkButton, "interior-focus", &interiorFocus, NULL);
  2745             int xt = interiorFocus ? gtkButton->style->xthickness : 0;
  2764             int xt = interiorFocus ? gtkButton->style->xthickness : 0;
  2746             int yt = interiorFocus ? gtkButton->style->ythickness : 0;
  2765             int yt = interiorFocus ? gtkButton->style->ythickness : 0;
  2747 
  2766 
  2748             if (btn->features & QStyleOptionButton::Flat && btn->state & State_HasFocus)
  2767             if (btn->features & QStyleOptionButton::Flat && btn->state & State_HasFocus)
  2749                 // The normal button focus rect does not work well for flat buttons in Clearlooks
  2768                 // The normal button focus rect does not work well for flat buttons in Clearlooks
  2760 
  2779 
  2761 #ifndef QT_NO_TABBAR
  2780 #ifndef QT_NO_TABBAR
  2762 
  2781 
  2763     case CE_TabBarTabShape:
  2782     case CE_TabBarTabShape:
  2764         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
  2783         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
  2765             GtkWidget *gtkNotebook = QGtk::gtkWidget(QLS("GtkNotebook"));
  2784             GtkWidget *gtkNotebook = d->gtkWidget(QLS("GtkNotebook"));
  2766             style = gtkPainter.getStyle(gtkNotebook);
  2785             style = gtkPainter.getStyle(gtkNotebook);
  2767 
  2786 
  2768             QRect rect = option->rect;
  2787             QRect rect = option->rect;
  2769             GtkShadowType shadow = GTK_SHADOW_OUT;
  2788             GtkShadowType shadow = GTK_SHADOW_OUT;
  2770             GtkStateType state = GTK_STATE_ACTIVE;
  2789             GtkStateType state = GTK_STATE_ACTIVE;
  2827 #endif //QT_NO_TABBAR
  2846 #endif //QT_NO_TABBAR
  2828 
  2847 
  2829     case CE_ProgressBarGroove:
  2848     case CE_ProgressBarGroove:
  2830         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2849         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2831             Q_UNUSED(bar);
  2850             Q_UNUSED(bar);
  2832             GtkWidget *gtkProgressBar = QGtk::gtkWidget(QLS("GtkProgressBar"));
  2851             GtkWidget *gtkProgressBar = d->gtkWidget(QLS("GtkProgressBar"));
  2833             GtkStateType state = gtkPainter.gtkState(option);
  2852             GtkStateType state = gtkPainter.gtkState(option);
  2834             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, gtkProgressBar->style);
  2853             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, gtkProgressBar->style);
  2835         }
  2854         }
  2836 
  2855 
  2837         break;
  2856         break;
  2838 
  2857 
  2839     case CE_ProgressBarContents:
  2858     case CE_ProgressBarContents:
  2840         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2859         if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
  2841             GtkStateType state = option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE;
  2860             GtkStateType state = option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE;
  2842             GtkWidget *gtkProgressBar = QGtk::gtkWidget(QLS("GtkProgressBar"));
  2861             GtkWidget *gtkProgressBar = d->gtkWidget(QLS("GtkProgressBar"));
  2843             style = gtkProgressBar->style;
  2862             style = gtkProgressBar->style;
  2844             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, style);
  2863             gtkPainter.paintBox( gtkProgressBar, "trough",  option->rect, state, GTK_SHADOW_IN, style);
  2845             int xt = style->xthickness;
  2864             int xt = style->xthickness;
  2846             int yt = style->ythickness;
  2865             int yt = style->ythickness;
  2847             QRect rect = bar->rect.adjusted(xt, yt, -xt, -yt);
  2866             QRect rect = bar->rect.adjusted(xt, yt, -xt, -yt);
  2885             if (bar->progress == bar->maximum)
  2904             if (bar->progress == bar->maximum)
  2886                 fakePos = maximum;
  2905                 fakePos = maximum;
  2887             else if (bar->progress > bar->minimum)
  2906             else if (bar->progress > bar->minimum)
  2888                 fakePos = maximum - 1;
  2907                 fakePos = maximum - 1;
  2889 
  2908 
  2890             GtkObject *adjustment =  QGtk::gtk_adjustment_new(fakePos, 0, maximum, 0, 0, 0);
  2909             GtkObject *adjustment =  d->gtk_adjustment_new(fakePos, 0, maximum, 0, 0, 0);
  2891             QGtk::gtk_progress_set_adjustment((GtkProgress*)(gtkProgressBar), (GtkAdjustment*)(adjustment));
  2910             d->gtk_progress_set_adjustment((GtkProgress*)(gtkProgressBar), (GtkAdjustment*)(adjustment));
  2892 
  2911 
  2893             QRect progressBar;
  2912             QRect progressBar;
  2894 
  2913 
  2895             if (!indeterminate) {
  2914             if (!indeterminate) {
  2896                 if (!reverse)
  2915                 if (!reverse)
  2926   \reimp
  2945   \reimp
  2927 */
  2946 */
  2928 QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
  2947 QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
  2929                                 SubControl subControl, const QWidget *widget) const
  2948                                 SubControl subControl, const QWidget *widget) const
  2930 {
  2949 {
       
  2950     Q_D(const QGtkStyle);
       
  2951 
  2931     QRect rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
  2952     QRect rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
  2932     if (!QGtk::isThemeAvailable())
  2953     if (!d->isThemeAvailable())
  2933         return QCleanlooksStyle::subControlRect(control, option, subControl, widget);
  2954         return QCleanlooksStyle::subControlRect(control, option, subControl, widget);
  2934 
  2955 
  2935     switch (control) {
  2956     switch (control) {
  2936     case CC_TitleBar:
  2957     case CC_TitleBar:
  2937         return QCleanlooksStyle::subControlRect(control, option, subControl, widget);
  2958         return QCleanlooksStyle::subControlRect(control, option, subControl, widget);
  2993 #endif
  3014 #endif
  2994 #ifndef QT_NO_SPINBOX
  3015 #ifndef QT_NO_SPINBOX
  2995 
  3016 
  2996     case CC_SpinBox:
  3017     case CC_SpinBox:
  2997         if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  3018         if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
  2998             GtkWidget *gtkSpinButton = QGtk::gtkWidget(QLS("GtkSpinButton"));
  3019             GtkWidget *gtkSpinButton = d->gtkWidget(QLS("GtkSpinButton"));
  2999             int center = spinbox->rect.height() / 2;
  3020             int center = spinbox->rect.height() / 2;
  3000             int xt = spinbox->frame ? gtkSpinButton->style->xthickness : 0;
  3021             int xt = spinbox->frame ? gtkSpinButton->style->xthickness : 0;
  3001             int yt = spinbox->frame ? gtkSpinButton->style->ythickness : 0;
  3022             int yt = spinbox->frame ? gtkSpinButton->style->ythickness : 0;
  3002             int y = yt;
  3023             int y = yt;
  3003 
  3024 
  3004             QSize bs;
  3025             QSize bs;
  3005             bs.setHeight(qMax(8, spinbox->rect.height()/2 - y));
  3026             bs.setHeight(qMax(8, spinbox->rect.height()/2 - y));
  3006             bs.setWidth(spinboxArrowSize());
  3027             bs.setWidth(d->getSpinboxArrowSize());
  3007             int x, lx, rx;
  3028             int x, lx, rx;
  3008             x = spinbox->rect.width() - y - bs.width() + 2;
  3029             x = spinbox->rect.width() - y - bs.width() + 2;
  3009             lx = xt;
  3030             lx = xt;
  3010             rx = x - xt;
  3031             rx = x - xt;
  3011 
  3032 
  3047 
  3068 
  3048     case CC_ComboBox:
  3069     case CC_ComboBox:
  3049         if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  3070         if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  3050             // We employ the gtk widget to position arrows and separators for us
  3071             // We employ the gtk widget to position arrows and separators for us
  3051             QString comboBoxPath = box->editable ? QLS("GtkComboBoxEntry") : QLS("GtkComboBox");
  3072             QString comboBoxPath = box->editable ? QLS("GtkComboBoxEntry") : QLS("GtkComboBox");
  3052             GtkWidget *gtkCombo = QGtk::gtkWidget(comboBoxPath);
  3073             GtkWidget *gtkCombo = d->gtkWidget(comboBoxPath);
  3053             QGtk::gtk_widget_set_direction(gtkCombo, (option->direction == Qt::RightToLeft) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  3074             d->gtk_widget_set_direction(gtkCombo, (option->direction == Qt::RightToLeft) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
  3054             GtkAllocation geometry = {0, 0, qMax(0, option->rect.width()), qMax(0, option->rect.height())};
  3075             GtkAllocation geometry = {0, 0, qMax(0, option->rect.width()), qMax(0, option->rect.height())};
  3055             QGtk::gtk_widget_size_allocate(gtkCombo, &geometry);
  3076             d->gtk_widget_size_allocate(gtkCombo, &geometry);
  3056             int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, option, widget);
  3077             int appears_as_list = !proxy()->styleHint(QStyle::SH_ComboBox_Popup, option, widget);
  3057             QString arrowPath = comboBoxPath + QLS(".GtkToggleButton");
  3078             QString arrowPath = comboBoxPath + QLS(".GtkToggleButton");
  3058 
  3079 
  3059             if (!box->editable && !appears_as_list)
  3080             if (!box->editable && !appears_as_list)
  3060                 arrowPath += QLS(".GtkHBox.GtkArrow");
  3081                 arrowPath += QLS(".GtkHBox.GtkArrow");
  3061 
  3082 
  3062             GtkWidget *arrowWidget = QGtk::gtkWidget(arrowPath);
  3083             GtkWidget *arrowWidget = d->gtkWidget(arrowPath);
  3063             if (!arrowWidget)
  3084             if (!arrowWidget)
  3064                 return QCleanlooksStyle::subControlRect(control, option, subControl, widget);
  3085                 return QCleanlooksStyle::subControlRect(control, option, subControl, widget);
  3065 
  3086 
  3066             QRect buttonRect(option->rect.left() + arrowWidget->allocation.x,
  3087             QRect buttonRect(option->rect.left() + arrowWidget->allocation.x,
  3067                              option->rect.top() + arrowWidget->allocation.y,
  3088                              option->rect.top() + arrowWidget->allocation.y,
  3102 
  3123 
  3103 /*!
  3124 /*!
  3104   \reimp
  3125   \reimp
  3105 */
  3126 */
  3106 QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
  3127 QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
  3107 
       
  3108                                   const QSize &size, const QWidget *widget) const
  3128                                   const QSize &size, const QWidget *widget) const
  3109 {
  3129 {
       
  3130     Q_D(const QGtkStyle);
  3110 
  3131 
  3111     QSize newSize = QCleanlooksStyle::sizeFromContents(type, option, size, widget);
  3132     QSize newSize = QCleanlooksStyle::sizeFromContents(type, option, size, widget);
  3112     if (!QGtk::isThemeAvailable())
  3133     if (!d->isThemeAvailable())
  3113         return newSize;
  3134         return newSize;
  3114 
  3135 
  3115     switch (type) {
  3136     switch (type) {
  3116 
  3137 
  3117     case CT_ToolButton:
  3138     case CT_ToolButton:
  3118         if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  3139         if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
  3119             GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton"));
  3140             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkToolButton.GtkButton"));
  3120             newSize = size + QSize(2 * gtkButton->style->xthickness, 1 + 2 * gtkButton->style->ythickness);
  3141             newSize = size + QSize(2 * gtkButton->style->xthickness, 2 + 2 * gtkButton->style->ythickness);
  3121             if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
  3142             if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
  3122                 QSize minSize(0, 25);
  3143                 QSize minSize(0, 25);
  3123                 if (toolbutton->toolButtonStyle != Qt::ToolButtonTextOnly)
  3144                 if (toolbutton->toolButtonStyle != Qt::ToolButtonTextOnly)
  3124                     minSize = toolbutton->iconSize + QSize(12, 12);
  3145                     minSize = toolbutton->iconSize + QSize(12, 12);
  3125                 newSize = newSize.expandedTo(minSize);
  3146                 newSize = newSize.expandedTo(minSize);
  3126             }
  3147             }
  3127             
  3148 
  3128             if (toolbutton->features & QStyleOptionToolButton::HasMenu)
  3149             if (toolbutton->features & QStyleOptionToolButton::HasMenu)
  3129                 newSize += QSize(6, 0);
  3150                 newSize += QSize(6, 0);
  3130         }
  3151         }
  3131         break;
  3152         break;
  3132 
  3153 
  3133     case CT_MenuItem:
  3154     case CT_MenuItem:
  3134         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  3155         if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
  3135             int textMargin = 8;
  3156             int textMargin = 8;
  3136 
  3157 
  3137             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  3158             if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
  3138                 GtkWidget *gtkMenuSeparator = QGtk::gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem"));
  3159                 GtkWidget *gtkMenuSeparator = d->gtkWidget(QLS("GtkMenu.GtkSeparatorMenuItem"));
  3139                 gboolean wide_separators;
  3160                 gboolean wide_separators;
  3140                 gint     separator_height;
  3161                 gint     separator_height;
  3141                 QGtk::gtk_widget_style_get(gtkMenuSeparator,
  3162                 d->gtk_widget_style_get(gtkMenuSeparator,
  3142                                        "wide-separators",    &wide_separators,
  3163                                        "wide-separators",    &wide_separators,
  3143                                        "separator-height",   &separator_height,
  3164                                        "separator-height",   &separator_height,
  3144                                        NULL);
  3165                                        NULL);
  3145                 newSize = QSize(size.width(), wide_separators ? separator_height - 1 : 7 );
  3166                 newSize = QSize(size.width(), wide_separators ? separator_height - 1 : 7 );
  3146 
  3167 
  3147                 break;
  3168                 break;
  3148             }
  3169             }
  3149 
  3170 
  3150             GtkWidget *gtkMenuItem = QGtk::gtkWidget(QLS("GtkMenu.GtkMenuItem"));
  3171             GtkWidget *gtkMenuItem = d->gtkWidget(QLS("GtkMenu.GtkMenuItem"));
  3151             GtkStyle* style = gtkMenuItem->style;
  3172             GtkStyle* style = gtkMenuItem->style;
  3152             newSize += QSize(textMargin + style->xthickness - 2, style->ythickness - 4);
  3173             newSize += QSize(textMargin + style->xthickness - 1, style->ythickness - 3);
  3153 
  3174 
  3154             // Cleanlooks assumes a check column of 20 pixels so we need to
  3175             // Cleanlooks assumes a check column of 20 pixels so we need to
  3155             // expand it a bit
  3176             // expand it a bit
  3156             gint checkSize;
  3177             gint checkSize;
  3157             QGtk::gtk_widget_style_get(QGtk::gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")), "indicator-size", &checkSize, NULL);
  3178             d->gtk_widget_style_get(d->gtkWidget(QLS("GtkMenu.GtkCheckMenuItem")), "indicator-size", &checkSize, NULL);
  3158             newSize.setHeight(qMax(newSize.height(), checkSize + 2));
  3179             newSize.setHeight(qMax(newSize.height(), checkSize + 2));
  3159             newSize.setWidth(newSize.width() + qMax(0, checkSize - 20));
  3180             newSize.setWidth(newSize.width() + qMax(0, checkSize - 20));
  3160         }
  3181         }
  3161 
  3182 
  3162         break;
  3183         break;
  3167 
  3188 
  3168         break;
  3189         break;
  3169 
  3190 
  3170     case CT_SpinBox:
  3191     case CT_SpinBox:
  3171         // QSpinBox does some nasty things that depends on CT_LineEdit
  3192         // QSpinBox does some nasty things that depends on CT_LineEdit
  3172         newSize = size + QSize(0, -QGtk::gtkWidget(QLS("GtkSpinButton"))->style->ythickness * 2 + 2);
  3193         newSize = size + QSize(0, -d->gtkWidget(QLS("GtkSpinButton"))->style->ythickness * 2);
  3173         break;
  3194         break;
  3174 
  3195 
  3175     case CT_PushButton:
  3196     case CT_PushButton:
  3176         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  3197         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
  3177             GtkWidget *gtkButton = QGtk::gtkWidget(QLS("GtkButton"));
  3198             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
  3178             gint focusPadding, focusWidth;
  3199             gint focusPadding, focusWidth;
  3179             QGtk::gtk_widget_style_get(gtkButton, "focus-padding", &focusPadding, NULL);
  3200             d->gtk_widget_style_get(gtkButton, "focus-padding", &focusPadding, NULL);
  3180             QGtk::gtk_widget_style_get(gtkButton, "focus-line-width", &focusWidth, NULL);
  3201             d->gtk_widget_style_get(gtkButton, "focus-line-width", &focusWidth, NULL);
  3181             newSize = size;
  3202             newSize = size;
  3182             newSize += QSize(2*gtkButton->style->xthickness + 4, 2*gtkButton->style->ythickness);
  3203             newSize += QSize(2*gtkButton->style->xthickness + 4, 2*gtkButton->style->ythickness);
  3183             newSize += QSize(2*(focusWidth + focusPadding + 2), 2*(focusWidth + focusPadding));
  3204             newSize += QSize(2*(focusWidth + focusPadding + 2), 2*(focusWidth + focusPadding));
  3184 
  3205 
  3185             GtkWidget *gtkButtonBox = QGtk::gtkWidget(QLS("GtkHButtonBox"));
  3206             GtkWidget *gtkButtonBox = d->gtkWidget(QLS("GtkHButtonBox"));
  3186             gint minWidth = 85, minHeight = 0;
  3207             gint minWidth = 85, minHeight = 0;
  3187             QGtk::gtk_widget_style_get(gtkButtonBox, "child-min-width", &minWidth,
  3208             d->gtk_widget_style_get(gtkButtonBox, "child-min-width", &minWidth,
  3188                                    "child-min-height", &minHeight, NULL);
  3209                                    "child-min-height", &minHeight, NULL);
  3189             if (!btn->text.isEmpty() && newSize.width() < minWidth)
  3210             if (!btn->text.isEmpty() && newSize.width() < minWidth)
  3190                 newSize.setWidth(minWidth);
  3211                 newSize.setWidth(minWidth);
  3191             if (newSize.height() < minHeight)
  3212             if (newSize.height() < minHeight)
  3192                 newSize.setHeight(minHeight);
  3213                 newSize.setHeight(minHeight);
  3193         }
  3214         }
  3194 
  3215 
  3195         break;
  3216         break;
  3196 
  3217 
  3197     case CT_Slider: {
  3218     case CT_Slider: {
  3198         GtkWidget *gtkSlider = QGtk::gtkWidget(QLS("GtkHScale"));
  3219         GtkWidget *gtkSlider = d->gtkWidget(QLS("GtkHScale"));
  3199         newSize = size + QSize(2*gtkSlider->style->xthickness, 2*gtkSlider->style->ythickness);
  3220         newSize = size + QSize(2*gtkSlider->style->xthickness, 2*gtkSlider->style->ythickness);
  3200     }
  3221     }
  3201     break;
  3222     break;
  3202 
  3223 
  3203     case CT_MenuBarItem://cleanlooks adds 2 pixels
       
  3204         newSize = QWindowsStyle::sizeFromContents(type, option, size, widget) + QSize(0, 1);
       
  3205         break;
       
  3206 
       
  3207     case CT_LineEdit: {
  3224     case CT_LineEdit: {
  3208         GtkWidget *gtkEntry = QGtk::gtkWidget(QLS("GtkEntry"));
  3225         GtkWidget *gtkEntry = d->gtkWidget(QLS("GtkEntry"));
  3209         newSize = size + QSize(2*gtkEntry->style->xthickness, 2*gtkEntry->style->ythickness);
  3226         newSize = size + QSize(2*gtkEntry->style->xthickness, 2 + 2*gtkEntry->style->ythickness);
  3210     }
  3227     }
  3211     break;
  3228     break;
  3212 
  3229 
  3213     case CT_ItemViewItem:
  3230     case CT_ItemViewItem:
  3214         newSize += QSize(0, 2);
  3231         newSize += QSize(0, 2);
  3215         break;
  3232         break;
  3216 
  3233 
  3217     case CT_ComboBox:
  3234     case CT_ComboBox:
  3218         if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  3235         if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
  3219             GtkWidget *gtkCombo = QGtk::gtkWidget(QLS("GtkComboBox"));
  3236             GtkWidget *gtkCombo = d->gtkWidget(QLS("GtkComboBox"));
  3220             QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, combo, SC_ComboBoxArrow, widget);
  3237             QRect arrowButtonRect = proxy()->subControlRect(CC_ComboBox, combo, SC_ComboBoxArrow, widget);
  3221             newSize = size + QSize(12 + arrowButtonRect.width() + 2*gtkCombo->style->xthickness, 4 + 2*gtkCombo->style->ythickness);
  3238             newSize = size + QSize(12 + arrowButtonRect.width() + 2*gtkCombo->style->xthickness, 4 + 2*gtkCombo->style->ythickness);
  3222 
  3239 
  3223             if (!(widget && qobject_cast<QToolBar *>(widget->parentWidget())))
  3240             if (!(widget && qobject_cast<QToolBar *>(widget->parentWidget())))
  3224                 newSize += QSize(0, 3);
  3241                 newSize += QSize(0, 2);
  3225         }
  3242         }
  3226         break;
  3243         break;
  3227 
  3244 
  3228     case CT_GroupBox:
  3245     case CT_GroupBox:
  3229         newSize += QSize(4, groupBoxBottomMargin + groupBoxTopMargin + groupBoxTitleMargin); // Add some space below the groupbox
  3246         newSize += QSize(4, groupBoxBottomMargin + groupBoxTopMargin + groupBoxTitleMargin); // Add some space below the groupbox
  3232     case CT_TabBarTab:
  3249     case CT_TabBarTab:
  3233         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
  3250         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
  3234             if (!tab->icon.isNull())
  3251             if (!tab->icon.isNull())
  3235                 newSize += QSize(6, 0);
  3252                 newSize += QSize(6, 0);
  3236         }
  3253         }
  3237         newSize += QSize(1, 0);
  3254         newSize += QSize(1, 1);
  3238         break;
  3255         break;
  3239 
  3256 
  3240     default:
  3257     default:
  3241         break;
  3258         break;
  3242     }
  3259     }
  3247 
  3264 
  3248 /*! \reimp */
  3265 /*! \reimp */
  3249 QPixmap QGtkStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option,
  3266 QPixmap QGtkStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option,
  3250                                   const QWidget *widget) const
  3267                                   const QWidget *widget) const
  3251 {
  3268 {
  3252     if (!QGtk::isThemeAvailable())
  3269     Q_D(const QGtkStyle);
       
  3270 
       
  3271     if (!d->isThemeAvailable())
  3253         return QCleanlooksStyle::standardPixmap(sp, option, widget);
  3272         return QCleanlooksStyle::standardPixmap(sp, option, widget);
  3254 
  3273 
  3255     QPixmap pixmap;
  3274     QPixmap pixmap;
  3256     switch (sp) {
  3275     switch (sp) {
  3257 
  3276 
  3314 */
  3333 */
  3315 QIcon QGtkStyle::standardIconImplementation(StandardPixmap standardIcon,
  3334 QIcon QGtkStyle::standardIconImplementation(StandardPixmap standardIcon,
  3316                                                   const QStyleOption *option,
  3335                                                   const QStyleOption *option,
  3317                                                   const QWidget *widget) const
  3336                                                   const QWidget *widget) const
  3318 {
  3337 {
  3319     if (!QGtk::isThemeAvailable())
  3338     Q_D(const QGtkStyle);
       
  3339 
       
  3340     if (!d->isThemeAvailable())
  3320         return QCleanlooksStyle::standardIconImplementation(standardIcon, option, widget);
  3341         return QCleanlooksStyle::standardIconImplementation(standardIcon, option, widget);
  3321     switch (standardIcon) {
  3342     switch (standardIcon) {
  3322     case SP_DialogDiscardButton:
  3343     case SP_DialogDiscardButton:
  3323         return QGtkPainter::getIcon(GTK_STOCK_DELETE);
  3344         return QGtkPainter::getIcon(GTK_STOCK_DELETE);
  3324     case SP_DialogOkButton:
  3345     case SP_DialogOkButton:
  3352 
  3373 
  3353 
  3374 
  3354 /*! \reimp */
  3375 /*! \reimp */
  3355 QRect QGtkStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
  3376 QRect QGtkStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
  3356 {
  3377 {
       
  3378     Q_D(const QGtkStyle);
       
  3379 
  3357     QRect r = QCleanlooksStyle::subElementRect(element, option, widget);
  3380     QRect r = QCleanlooksStyle::subElementRect(element, option, widget);
  3358     switch (element) {
  3381     switch (element) {
  3359     case SE_ProgressBarLabel:
  3382     case SE_ProgressBarLabel:
  3360     case SE_ProgressBarContents:
  3383     case SE_ProgressBarContents:
  3361     case SE_ProgressBarGroove:
  3384     case SE_ProgressBarGroove:
  3362         return option->rect;
  3385         return option->rect;
       
  3386     case SE_PushButtonContents:
       
  3387         if (!d->gtk_check_version(2, 10, 0)) {
       
  3388             GtkWidget *gtkButton = d->gtkWidget(QLS("GtkButton"));
       
  3389             GtkBorder *border = 0;
       
  3390             d->gtk_widget_style_get(gtkButton, "inner-border", &border, NULL);
       
  3391             if (border) {
       
  3392                 r = option->rect.adjusted(border->left, border->top, -border->right, -border->bottom);
       
  3393                 d->gtk_border_free(border);
       
  3394             } else {
       
  3395                 r = option->rect.adjusted(1, 1, -1, -1);
       
  3396             }
       
  3397             r = visualRect(option->direction, option->rect, r);
       
  3398         }
       
  3399         break;
  3363     default:
  3400     default:
  3364         break;
  3401         break;
  3365     }
  3402     }
  3366 
  3403 
  3367     return r;
  3404     return r;