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