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