File indexing completed on 2024-04-21 16:31:16

0001 /*****************************************************************************
0002  *   Copyright 2007 - 2010 Craig Drummond <craig.p.drummond@gmail.com>       *
0003  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
0004  *                                                                           *
0005  *   This program is free software; you can redistribute it and/or modify    *
0006  *   it under the terms of the GNU Lesser General Public License as          *
0007  *   published by the Free Software Foundation; either version 2.1 of the    *
0008  *   License, or (at your option) version 3, or any later version accepted   *
0009  *   by the membership of KDE e.V. (or its successor approved by the         *
0010  *   membership of KDE e.V.), which shall act as a proxy defined in          *
0011  *   Section 6 of version 3 of the license.                                  *
0012  *                                                                           *
0013  *   This program is distributed in the hope that it will be useful,         *
0014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0016  *   Lesser General Public License for more details.                         *
0017  *                                                                           *
0018  *   You should have received a copy of the GNU Lesser General Public        *
0019  *   License along with this library. If not,                                *
0020  *   see <http://www.gnu.org/licenses/>.                                     *
0021  *****************************************************************************/
0022 
0023 #include "config.h"
0024 #include <qtcurve-utils/log.h>
0025 #include <qtcurve-utils/qtprops.h>
0026 
0027 #include "qtcurve_p.h"
0028 #include "windowmanager.h"
0029 #include "blurhelper.h"
0030 #include "shortcuthandler.h"
0031 
0032 #include <QProgressBar>
0033 #include <QFileDialog>
0034 #include <QToolButton>
0035 #include <QAbstractItemView>
0036 #include <QSplitter>
0037 #include <QSettings>
0038 #include <QTreeView>
0039 #include <QPixmapCache>
0040 #include <QMdiSubWindow>
0041 #include <QStatusBar>
0042 #include <QComboBox>
0043 #include <QWidget>
0044 #include <QListView>
0045 #include <QCheckBox>
0046 #include <QGroupBox>
0047 #include <QRadioButton>
0048 #include <QTextEdit>
0049 #include <QDial>
0050 #include <QStackedLayout>
0051 #include <QSpinBox>
0052 #include <QLabel>
0053 #include <QPrintDialog>
0054 #include <QMouseEvent>
0055 #include <QMenuBar>
0056 #include <QWheelEvent>
0057 #include <QScrollBar>
0058 #include <QResizeEvent>
0059 #include <QWizard>
0060 #include <QDialogButtonBox>
0061 #include <QPushButton>
0062 #include <QHeaderView>
0063 #include <QLineEdit>
0064 #include <QFormLayout>
0065 #include <QPainter>
0066 #include <QMainWindow>
0067 #include <QTextStream>
0068 #include <QToolBox>
0069 #include <QDBusConnection>
0070 #include <QDBusInterface>
0071 
0072 #include "macmenu.h"
0073 #include "shadowhelper.h"
0074 #include <sys/time.h>
0075 #include <qtcurve-utils/x11qtc.h>
0076 
0077 #include <QDebug>
0078 
0079 #include <common/config_file.h>
0080 #include "check_on-png.h"
0081 #include "check_x_on-png.h"
0082 
0083 #ifndef QTC_QT4_ENABLE_KDE
0084 #  include "dialog_error-png.h"
0085 #  include "dialog_warning-png.h"
0086 #  include "dialog_information-png.h"
0087 #endif
0088 
0089 #include <algorithm>
0090 
0091 // WebKit seems to just use the values from ::pixelMetric to get button sizes. So, in pixelMetric we add some extra padding to PM_ButtonMargin
0092 // if we're max rounding - this gives a nicer border. However, dont want this on real buttons - so in sizeFromContents we remove this padding
0093 // in CT_PushButton and CT_ComboBox
0094 #define MAX_ROUND_BTN_PAD (ROUND_MAX==opts.round ? 3 : 0)
0095 
0096 #ifdef QTC_QT4_ENABLE_KDE
0097 #include <KDE/KApplication>
0098 #include <KDE/KAboutData>
0099 #include <KDE/KGlobalSettings>
0100 #include <KDE/KConfig>
0101 #include <KDE/KConfigGroup>
0102 #include <KDE/KIconLoader>
0103 #include <KDE/KIcon>
0104 #include <KDE/KColorScheme>
0105 #include <KDE/KStandardDirs>
0106 #include <KDE/KComponentData>
0107 #include <KDE/KTitleWidget>
0108 #include <KDE/KTabBar>
0109 #include <KDE/KFileDialog>
0110 #include <KDE/KPassivePopup>
0111 #include <KDE/KXmlGuiWindow>
0112 #include <KDE/KStandardAction>
0113 #include <KDE/KActionCollection>
0114 #include <KDE/KIconEffect>
0115 #include <KDE/KMenu>
0116 #include <KDE/KAboutApplicationDialog>
0117 #endif // QTC_QT4_ENABLE_KDE
0118 
0119 #include <qtcurve-utils/color.h>
0120 
0121 // TODO! REMOVE THIS WHEN KDE'S ICON SETTINGS ACTUALLY WORK!!!
0122 #define FIX_DISABLED_ICONS
0123 
0124 extern QString (*qt_filedialog_existing_directory_hook)(
0125     QWidget *parent, const QString &caption, const QString &dir,
0126     QFileDialog::Options options);
0127 
0128 extern QString (*qt_filedialog_open_filename_hook)(
0129     QWidget *parent, const QString &caption, const QString &dir,
0130     const QString &filter, QString *selectedFilter,
0131     QFileDialog::Options options);
0132 
0133 extern QStringList (*qt_filedialog_open_filenames_hook)(
0134     QWidget * parent, const QString &caption, const QString &dir,
0135     const QString &filter, QString *selectedFilter,
0136     QFileDialog::Options options);
0137 
0138 extern QString (*qt_filedialog_save_filename_hook)(
0139     QWidget *parent, const QString &caption, const QString &dir,
0140     const QString &filter, QString *selectedFilter,
0141     QFileDialog::Options options);
0142 
0143 #ifndef Q_OS_MAC
0144 #define POPUP_MENUS_SQUARE(opts)    ((opts).square & SQUARE_POPUP_MENUS)
0145 #else
0146 // prevent a rendering glitch in popup menus:
0147 #define POPUP_MENUS_SQUARE(opts)    true
0148 #endif
0149 
0150 namespace QtCurve {
0151 
0152 #if defined FIX_DISABLED_ICONS && defined QTC_QT4_ENABLE_KDE
0153 static inline QPixmap
0154 getIconPixmap(const QIcon &icon, const QSize &size,
0155               QIcon::Mode mode, QIcon::State)
0156 {
0157     QPixmap pix = icon.pixmap(size, QIcon::Normal);
0158 
0159     if (QIcon::Disabled == mode) {
0160         QImage img = pix.toImage();
0161         KIconEffect::toGray(img, 1.0);
0162         KIconEffect::semiTransparent(img);
0163         pix = QPixmap::fromImage(img);
0164     }
0165 
0166     return pix;
0167 }
0168 #else
0169 QTC_ALWAYS_INLINE static inline QPixmap
0170 getIconPixmap(const QIcon &icon, const QSize &size,
0171               QIcon::Mode mode, QIcon::State state=QIcon::Off)
0172 {
0173     return icon.pixmap(size, mode, state);
0174 }
0175 #endif
0176 
0177 QTC_ALWAYS_INLINE static inline QPixmap
0178 getIconPixmap(const QIcon &icon, int size, QIcon::Mode mode,
0179               QIcon::State state=QIcon::Off)
0180 {
0181     return getIconPixmap(icon, QSize(size, size), mode, state);
0182 }
0183 
0184 QTC_ALWAYS_INLINE static inline QPixmap
0185 getIconPixmap(const QIcon &icon, const QSize &size, int flags,
0186               QIcon::State state=QIcon::Off)
0187 {
0188     return getIconPixmap(icon, size, (flags & QStyle::State_Enabled ?
0189                                       QIcon::Normal : QIcon::Disabled), state);
0190 }
0191 
0192 QTC_ALWAYS_INLINE static inline QPixmap
0193 getIconPixmap(const QIcon &icon, int size, int flags,
0194               QIcon::State state=QIcon::Off)
0195 {
0196     return getIconPixmap(icon, QSize(size, size), flags, state);
0197 }
0198 
0199 QTC_ALWAYS_INLINE static inline Style::Icon
0200 pix2Icon(QStyle::StandardPixmap pix)
0201 {
0202     switch (pix) {
0203     case QStyle::SP_TitleBarNormalButton:
0204         return Style::ICN_RESTORE;
0205     case QStyle::SP_TitleBarShadeButton:
0206         return Style::ICN_SHADE;
0207     case QStyle::SP_ToolBarHorizontalExtensionButton:
0208         return Style::ICN_RIGHT;
0209     case QStyle::SP_ToolBarVerticalExtensionButton:
0210         return Style::ICN_DOWN;
0211     case QStyle::SP_TitleBarUnshadeButton:
0212         return Style::ICN_UNSHADE;
0213     default:
0214     case QStyle::SP_DockWidgetCloseButton:
0215     case QStyle::SP_TitleBarCloseButton:
0216         return Style::ICN_CLOSE;
0217     }
0218 }
0219 
0220 QTC_ALWAYS_INLINE static inline Style::Icon
0221 subControlToIcon(QStyle::SubControl sc)
0222 {
0223     switch (sc) {
0224     case QStyle::SC_TitleBarMinButton:
0225         return Style::ICN_MIN;
0226     case QStyle::SC_TitleBarMaxButton:
0227         return Style::ICN_MAX;
0228     case QStyle::SC_TitleBarCloseButton:
0229     default:
0230         return Style::ICN_CLOSE;
0231     case QStyle::SC_TitleBarNormalButton:
0232         return Style::ICN_RESTORE;
0233     case QStyle::SC_TitleBarShadeButton:
0234         return Style::ICN_SHADE;
0235     case QStyle::SC_TitleBarUnshadeButton:
0236         return Style::ICN_UNSHADE;
0237     case QStyle::SC_TitleBarSysMenu:
0238         return Style::ICN_MENU;
0239     }
0240 }
0241 
0242 QTC_ALWAYS_INLINE static inline void
0243 drawTbArrow(const QStyle *style, const QStyleOptionToolButton *toolbutton,
0244             const QRect &rect, QPainter *painter, const QWidget *widget=0)
0245 {
0246     QStyle::PrimitiveElement pe;
0247     switch (toolbutton->arrowType) {
0248     case Qt::LeftArrow:
0249         pe = QStyle::PE_IndicatorArrowLeft;
0250         break;
0251     case Qt::RightArrow:
0252         pe = QStyle::PE_IndicatorArrowRight;
0253         break;
0254     case Qt::UpArrow:
0255         pe = QStyle::PE_IndicatorArrowUp;
0256         break;
0257     case Qt::DownArrow:
0258         pe = QStyle::PE_IndicatorArrowDown;
0259         break;
0260     default:
0261         return;
0262     }
0263 
0264     QStyleOption arrowOpt;
0265     arrowOpt.rect = rect;
0266     arrowOpt.palette = toolbutton->palette;
0267     arrowOpt.state = toolbutton->state;
0268     style->drawPrimitive(pe, &arrowOpt, painter, widget);
0269 }
0270 
0271 #define WINDOWTITLE_SPACER    0x10000000
0272 #define STATE_REVERSE       (QStyle::StateFlag)0x10000000
0273 #define STATE_MENU          (QStyle::StateFlag)0x20000000
0274 #define STATE_VIEW          (QStyle::StateFlag)0x40000000
0275 #define STATE_KWIN_BUTTON   (QStyle::StateFlag)0x40000000
0276 #define STATE_TBAR_BUTTON   (QStyle::StateFlag)0x80000000
0277 #define STATE_DWT_BUTTON    (QStyle::StateFlag)0x20000000
0278 #define STATE_TOGGLE_BUTTON (QStyle::StateFlag)0x10000000
0279 
0280 static const int constMenuPixmapWidth = 22;
0281 
0282 QtcThemedApp theThemedApp = APP_OTHER;
0283 
0284 static QString appName;
0285 
0286 static inline bool
0287 isOOWidget(const QWidget *widget)
0288 {
0289     return APP_OPENOFFICE == theThemedApp && !widget;
0290 }
0291 
0292 static inline bool
0293 blendOOMenuHighlight(const QPalette &pal, const QColor &highlight)
0294 {
0295     QColor text(pal.text().color());
0296     QColor hl(pal.highlightedText().color());
0297 
0298     return (text.red() < 50 && text.green() < 50 &&
0299             text.blue() < 50 && hl.red() > 127 && hl.green() > 127 &&
0300             hl.blue() > 127 && TOO_DARK(highlight));
0301 }
0302 
0303 QTC_ALWAYS_INLINE static inline int
0304 toHint(int sc)
0305 {
0306     switch (sc) {
0307     case QStyle::SC_TitleBarSysMenu:
0308         return Qt::WindowSystemMenuHint;
0309     case QStyle::SC_TitleBarMinButton:
0310         return Qt::WindowMinimizeButtonHint;
0311     case QStyle::SC_TitleBarMaxButton:
0312         return Qt::WindowMaximizeButtonHint;
0313     case QStyle::SC_TitleBarCloseButton:
0314         return 0;
0315     case QStyle::SC_TitleBarNormalButton:
0316         return 0;
0317     case QStyle::SC_TitleBarShadeButton:
0318     case QStyle::SC_TitleBarUnshadeButton:
0319         return Qt::WindowShadeButtonHint;
0320     case QStyle::SC_TitleBarContextHelpButton:
0321         return Qt::WindowContextHelpButtonHint;
0322     default:
0323         return 0;
0324     }
0325 }
0326 
0327 static const char *constBoldProperty = "qtc-set-bold";
0328 
0329 static void
0330 setBold(QWidget *widget)
0331 {
0332     QVariant prop(widget->property(constBoldProperty));
0333     if(!prop.isValid() || !prop.toBool())
0334     {
0335         QFont font(widget->font());
0336 
0337         if(!font.bold())
0338         {
0339             font.setBold(true);
0340             widget->setFont(font);
0341             widget->setProperty(constBoldProperty, true);
0342         }
0343     }
0344 }
0345 
0346 static void unSetBold(QWidget *widget)
0347 {
0348     QVariant prop(widget->property(constBoldProperty));
0349 
0350     if(prop.isValid() && prop.toBool())
0351     {
0352         QFont font(widget->font());
0353 
0354         font.setBold(false);
0355         widget->setFont(font);
0356         widget->setProperty(constBoldProperty, false);
0357     }
0358 }
0359 
0360 static void adjustToolbarButtons(const QWidget *widget, const QToolBar *toolbar, int &leftAdjust, int &topAdjust,
0361                                  int &rightAdjust, int &bottomAdjust, int &round)
0362 {
0363     const int constAdjust=6;
0364     const int d = 1;
0365     QRect geo(widget->geometry());
0366 
0367     if (Qt::Horizontal==toolbar->orientation())
0368     {
0369         bool haveLeft=qobject_cast<QToolButton*>(toolbar->childAt(geo.x()-d, geo.y())),
0370              haveRight=qobject_cast<QToolButton*>(toolbar->childAt(geo.right()+d, geo.y()));
0371 
0372         if(haveLeft && haveRight)
0373             leftAdjust=-constAdjust, rightAdjust=constAdjust, round=ROUNDED_NONE;
0374         else if(haveLeft)
0375             leftAdjust=-constAdjust, round=ROUNDED_RIGHT;
0376         else if(haveRight)
0377             rightAdjust=constAdjust, round=ROUNDED_LEFT;
0378     }
0379     else
0380     {
0381         bool haveTop=qobject_cast<QToolButton*>(toolbar->childAt(geo.x(), geo.y()-d)),
0382              haveBot=qobject_cast<QToolButton*>(toolbar->childAt(geo.x(), geo.bottom()+d));
0383 
0384         if(haveTop && haveBot)
0385             topAdjust=-constAdjust, bottomAdjust=constAdjust, round=ROUNDED_NONE;
0386         else if(haveTop)
0387             topAdjust=-constAdjust, round=ROUNDED_BOTTOM;
0388         else if(haveBot)
0389             bottomAdjust=constAdjust, round=ROUNDED_TOP;
0390     }
0391 }
0392 
0393 static const QToolBar * getToolBar(const QWidget *w/*, bool checkQ3*/)
0394 {
0395     return w
0396             ? qobject_cast<const QToolBar*>(w) // || (checkQ3 && w->inherits("Q3ToolBar"))
0397                 ? static_cast<const QToolBar*>(w)
0398                 : getToolBar(w->parentWidget()/*, checkQ3*/)
0399             : 0L;
0400 }
0401 
0402 static inline QList<QStatusBar*> getStatusBars(QWidget *w)
0403 {
0404     return w ? w->findChildren<QStatusBar*>() : QList<QStatusBar*>();
0405 }
0406 
0407 static QToolBar*
0408 getToolBarChild(QWidget *w)
0409 {
0410     foreach (QObject *child, w->children()) {
0411         if (child->isWidgetType()) {
0412             if (qobject_cast<QToolBar*>(child))
0413                 return static_cast<QToolBar*>(child);
0414             QToolBar *tb = getToolBarChild((QWidget*)child);
0415             if (tb) {
0416                 return tb;
0417             }
0418         }
0419     }
0420     return 0L;
0421 }
0422 
0423 static void
0424 setStyleRecursive(QWidget *w, QStyle *s, int minSize)
0425 {
0426     w->setStyle(s);
0427     if (qobject_cast<QToolButton*>(w))
0428         w->setMinimumSize(1, minSize);
0429     foreach (QObject *child, w->children()) {
0430         if (child->isWidgetType()) {
0431             setStyleRecursive((QWidget*)child, s, minSize);
0432         }
0433     }
0434 }
0435 
0436 static bool
0437 isA(const QObject *w, const char *type)
0438 {
0439     return w && (oneOf(w->metaObject()->className(), type) ||
0440                  (w->parent() &&
0441                   oneOf(w->parent()->metaObject()->className(), type)));
0442 }
0443 
0444 static bool
0445 isInQAbstractItemView(const QObject *w)
0446 {
0447     int level = 8;
0448 
0449     while (w && --level > 0) {
0450         if (qobject_cast<const QAbstractItemView*>(w))
0451             return true;
0452         if (qobject_cast<const QDialog*>(w)/* || qobject_cast<const QMainWindow*>(w)*/)
0453             return false;
0454         w = w->parent();
0455     }
0456 
0457     return false;
0458 }
0459 
0460 static bool
0461 isKontactPreviewPane(const QWidget *widget)
0462 {
0463     return (theThemedApp == APP_KONTACT &&
0464             qtcCheckType(widget, "KHBox") &&
0465             qtcCheckType<QSplitter>(widget->parentWidget()) &&
0466             qtcCheckType(getParent<2>(widget), "KMReaderWin"));
0467 }
0468 
0469 static bool isKateView(const QWidget *widget)
0470 {
0471     return (qtcCheckType<QFrame>(widget) &&
0472             qtcCheckType(widget->parentWidget(), "KateView"));
0473 }
0474 
0475 static bool isNoEtchWidget(const QWidget *widget)
0476 {
0477     if (APP_KRUNNER == theThemedApp)
0478         return true;
0479 
0480     if (theThemedApp == APP_PLASMA) {
0481         const QWidget *top = widget->window();
0482         return !top || (!qobject_cast<const QDialog*>(top) &&
0483                         !qobject_cast<const QMainWindow*>(top));
0484     }
0485 
0486     if(widget && widget->inherits("QWebView"))
0487         return true;
0488 
0489     // KHTML:  widget -> QWidget       -> QWidget    -> KHTMLView
0490     const QObject *w=widget && widget->parent() && widget->parent()->parent() ? widget->parent()->parent()->parent() : 0L;
0491 
0492     return (w && isA(w, "KHTMLView")) || (widget && isInQAbstractItemView(widget->parentWidget()));
0493 }
0494 
0495 static QWidget * scrollViewFrame(QWidget *widget)
0496 {
0497     QWidget *w=widget;
0498 
0499     for(int i=0; i<10 && w; ++i, w=w->parentWidget())
0500     {
0501         if((qobject_cast<QFrame*>(w) && ((QFrame*)w)->frameWidth()>0) || qobject_cast<QTabWidget*>(w))
0502             return w;
0503     }
0504     return 0L;
0505 }
0506 
0507 static QColor checkColour(const QStyleOption *option, QPalette::ColorRole role)
0508 {
0509     QColor col(option->palette.brush(role).color());
0510 
0511     if (col.alpha() == 255 && isBlack(col))
0512         return QApplication::palette().brush(role).color();
0513     return col;
0514 }
0515 
0516 static QColor blendColors(const QColor &foreground, const QColor &background, double alpha)
0517 {
0518 #ifdef QTC_QT4_ENABLE_KDE
0519     return KColorUtils::mix(background, foreground, alpha);
0520 #else
0521     return qtcColorMix(&background, &foreground, alpha);
0522 #endif
0523 }
0524 
0525 static void addStripes(QPainter *p, const QPainterPath &path, const QRect &rect, bool horizontal)
0526 {
0527     QColor          col(Qt::white);
0528     QLinearGradient patternGradient(rect.topLeft(), rect.topLeft()+(horizontal ? QPoint(STRIPE_WIDTH, 0) : QPoint(0, STRIPE_WIDTH)));
0529 
0530     col.setAlphaF(0.0);
0531     patternGradient.setColorAt(0.0, col);
0532     col.setAlphaF(0.15);
0533     patternGradient.setColorAt(1.0, col);
0534     patternGradient.setSpread(QGradient::ReflectSpread);
0535     if(path.isEmpty())
0536         p->fillRect(rect, patternGradient);
0537     else
0538     {
0539         p->save();
0540         p->setRenderHint(QPainter::Antialiasing, true);
0541         p->fillPath(path, patternGradient);
0542         p->restore();
0543     }
0544 }
0545 
0546 static QRegion windowMask(const QRect &r, bool full)
0547 {
0548     int x, y, w, h;
0549     r.getRect(&x, &y, &w, &h);
0550 
0551     if(full)
0552     {
0553         QRegion region(x + 4, y + 0, w-4*2, h-0*2);
0554         region += QRegion(x + 0, y + 4, w-0*2, h-4*2);
0555         region += QRegion(x + 2, y + 1, w-2*2, h-1*2);
0556         region += QRegion(x + 1, y + 2, w-1*2, h-2*2);
0557         return region;
0558     }
0559     else
0560     {
0561         QRegion region(x+1, y+1, w-2, h-2);
0562         region += QRegion(x, y+2, w, h-4);
0563         region += QRegion(x+2, y, w-4, h);
0564         return region;
0565     }
0566 }
0567 
0568 enum WindowsStyleConsts
0569 {
0570     windowsItemFrame      =  2, // menu item frame width
0571     windowsSepHeight      =  9, // separator item height
0572     windowsItemHMargin    =  3, // menu item hor text margin
0573     windowsItemVMargin    =  2, // menu item ver text margin
0574     windowsRightBorder    = 15, // right border on windows
0575     windowsCheckMarkWidth = 12, // checkmarks width on windows
0576     windowsArrowHMargin   =  6  // arrow horizontal margin
0577 };
0578 
0579 static const int constWindowMargin   =  2;
0580 static const int constProgressBarFps = 20;
0581 static const int constTabPad         =  6;
0582 
0583 static const QLatin1String constDwtClose("qt_dockwidget_closebutton");
0584 static const QLatin1String constDwtFloat("qt_dockwidget_floatbutton");
0585 
0586 #define SB_SUB2 ((QStyle::SubControl)(QStyle::SC_ScrollBarGroove << 1))
0587 
0588 void
0589 setOpacityProp(QWidget *w, unsigned short opacity)
0590 {
0591     // DO NOT condition compile on QTC_ENABLE_X11.
0592     // There's no direct linkage on X11 and the following code will just do
0593     // nothing if X11 is not enabled (either at compile time or at run time).
0594     QTC_RET_IF_FAIL(qtcX11Enabled());
0595 
0596     if (WId wid = qtcGetWid(w->window())) {
0597         qtcX11SetOpacity(wid, opacity);
0598     }
0599 }
0600 
0601 void
0602 setBgndProp(QWidget *w, EAppearance app, bool haveBgndImage)
0603 {
0604     // DO NOT condition compile on QTC_ENABLE_X11.
0605     // There's no direct linkage on X11 and the following code will just do
0606     // nothing if X11 is not enabled (either at compile time or at run time).
0607     QTC_RET_IF_FAIL(qtcX11Enabled());
0608 
0609     if (WId wid = qtcGetWid(w->window())) {
0610         uint32_t prop =
0611             (((qtcIsFlatBgnd(app) ? (haveBgndImage ? APPEARANCE_RAISED :
0612                                      APPEARANCE_FLAT) : app) & 0xFF) |
0613              (w->palette().background().color().rgb() & 0x00FFFFFF) << 8);
0614         qtcX11SetBgnd(wid, prop);
0615     }
0616 }
0617 
0618 void
0619 setSbProp(QWidget *w)
0620 {
0621     // DO NOT condition compile on QTC_ENABLE_X11.
0622     // There's no direct linkage on X11 and the following code will just do
0623     // nothing if X11 is not enabled (either at compile time or at run time).
0624     QTC_RET_IF_FAIL(qtcX11Enabled());
0625 
0626     if (WId wid = qtcGetWid(w->window())) {
0627         static const char *constStatusBarProperty = "qtcStatusBar";
0628         QVariant prop(w->property(constStatusBarProperty));
0629 
0630         if (!prop.isValid() || !prop.toBool()) {
0631             w->setProperty(constStatusBarProperty, true);
0632             qtcX11SetStatusBar(wid);
0633         }
0634     }
0635 }
0636 
0637 #ifndef QTC_QT4_ENABLE_KDE
0638 static void setRgb(QColor *col, const QStringList &rgb)
0639 {
0640     if(3==rgb.size())
0641         *col=QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt());
0642 }
0643 #endif
0644 
0645 #ifdef QTC_QT4_STYLE_SUPPORT
0646 
0647 static QString themeFile(const QString &dir, const QString &n, const char *sub)
0648 {
0649     QString name(dir+sub+n+THEME_SUFFIX);
0650 
0651     return QFile(name).exists() ? name : QString();
0652 }
0653 
0654 static QString themeFile(const QString &dir, const QString &n, bool kde3=false)
0655 {
0656     QString name(themeFile(dir, n, kde3 ? THEME_DIR : THEME_DIR4));
0657 
0658     if(name.isEmpty())
0659         name=themeFile(dir, n, kde3 ? THEME_DIR4 : THEME_DIR);
0660     return name;
0661 }
0662 #endif
0663 
0664 static inline void drawRect(QPainter *p, const QRect &r)
0665 {
0666     p->drawRect(r.x(), r.y(), r.width()-1, r.height()-1);
0667 }
0668 
0669 static inline void
0670 drawAaLine(QPainter *p, int x1, int y1, int x2, int y2)
0671 {
0672     p->drawLine(QLineF(x1 + 0.5, y1 + 0.5, x2 + 0.5, y2 + 0.5));
0673 }
0674 
0675 static inline void drawAaPoint(QPainter *p, int x, int y)
0676 {
0677     p->drawPoint(QPointF(x+0.5, y+0.5));
0678 }
0679 
0680 static inline void drawAaRect(QPainter *p, const QRect &r)
0681 {
0682     p->drawRect(QRectF(r.x()+0.5, r.y()+0.5, r.width()-1, r.height()-1));
0683 }
0684 
0685 static void drawDots(QPainter *p, const QRect &r, bool horiz, int nLines, int offset,
0686                      const QColor *cols, int startOffset, int dark)
0687 {
0688     int space((nLines*2)+(nLines-1)),
0689         x(horiz ? r.x() : r.x()+((r.width()-space)>>1)),
0690         y(horiz ? r.y()+((r.height()-space)>>1) : r.y()),
0691         i, j,
0692         numDots((horiz ? (r.width()-(2*offset))/3 : (r.height()-(2*offset))/3)+1);
0693 
0694     p->setRenderHint(QPainter::Antialiasing, true);
0695     if(horiz)
0696     {
0697         if(startOffset && y+startOffset>0)
0698             y+=startOffset;
0699 
0700         p->setPen(cols[dark]);
0701         for(i=0; i<space; i+=3)
0702             for(j=0; j<numDots; j++)
0703                 drawAaPoint(p, x+offset+(3*j), y+i);
0704 
0705         p->setPen(cols[0]);
0706         for(i=1; i<space; i+=3)
0707             for(j=0; j<numDots; j++)
0708                 drawAaPoint(p, x+offset+1+(3*j), y+i);
0709     }
0710     else
0711     {
0712         if(startOffset && x+startOffset>0)
0713             x+=startOffset;
0714 
0715         p->setPen(cols[dark]);
0716         for(i=0; i<space; i+=3)
0717             for(j=0; j<numDots; j++)
0718                 drawAaPoint(p, x+i, y+offset+(3*j));
0719 
0720         p->setPen(cols[0]);
0721         for(i=1; i<space; i+=3)
0722             for(j=0; j<numDots; j++)
0723                 drawAaPoint(p, x+i, y+offset+1+(3*j));
0724     }
0725     p->setRenderHint(QPainter::Antialiasing, false);
0726 }
0727 
0728 static bool isHoriz(const QStyleOption *option, EWidget w, bool joinedTBar)
0729 {
0730     return option->state&QStyle::State_Horizontal ||
0731            (WIDGET_BUTTON(w) && (!joinedTBar || (WIDGET_TOOLBAR_BUTTON!=w && WIDGET_NO_ETCH_BTN!=w && WIDGET_MENU_BUTTON!=w)));
0732 }
0733 
0734 static bool isOnToolbar(const QWidget *widget)
0735 {
0736     const QWidget *wid=widget ? widget->parentWidget() : 0L;
0737 
0738     while(wid)
0739     {
0740         if(qobject_cast<const QToolBar*>(wid) || wid->inherits("Q3ToolBar"))
0741             return true;
0742         wid=wid->parentWidget();
0743     }
0744 
0745     return false;
0746 }
0747 
0748 #define PIXMAP_DIMENSION 10
0749 
0750 /*
0751 Cache key:
0752     widgettype 2
0753     app        5
0754     size      15
0755     horiz      1
0756     alpha      8
0757     blue       8
0758     green      8
0759     red        8
0760     type       1  (0 for widget, 1 for pixmap)
0761     ------------
0762               56
0763 */
0764 enum ECacheType
0765 {
0766     CACHE_STD,
0767     CACHE_PBAR,
0768     CACHE_TAB_TOP,
0769     CACHE_TAB_BOT
0770 };
0771 
0772 static QtcKey createKey(qulonglong size, const QColor &color, bool horiz, int app, EWidget w)
0773 {
0774     ECacheType type=WIDGET_TAB_TOP==w
0775                         ? CACHE_TAB_TOP
0776                         : WIDGET_TAB_BOT==w
0777                             ? CACHE_TAB_BOT
0778                             : WIDGET_PROGRESSBAR==w
0779                                 ? CACHE_PBAR
0780                                 : CACHE_STD;
0781 
0782     return (color.rgba()<<1)+
0783            (((qulonglong)(horiz ? 1 : 0))<<33)+
0784            (((qulonglong)(size&0xFFFF))<<34)+
0785            (((qulonglong)(app&0x1F))<<50)+
0786            (((qulonglong)(type&0x03))<<55);
0787 }
0788 
0789 static QtcKey createKey(const QColor &color, EPixmap p)
0790 {
0791     return 1+
0792            ((color.rgb()&RGB_MASK)<<1)+
0793            (((qulonglong)(p&0x1F))<<33)+
0794            (((qulonglong)1)<<38);
0795 }
0796 
0797 #ifdef QTC_QT4_ENABLE_KDE
0798 static void parseWindowLine(const QString &line, QList<int> &data)
0799 {
0800     int len(line.length());
0801 
0802     for(int i=0; i<len; ++i)
0803         switch(line[i].toLatin1())
0804         {
0805             case 'M':
0806                 data.append(QStyle::SC_TitleBarSysMenu);
0807                 break;
0808             case '_':
0809                 data.append(WINDOWTITLE_SPACER);
0810                 break;
0811             case 'H':
0812                 data.append(QStyle::SC_TitleBarContextHelpButton);
0813                 break;
0814             case 'L':
0815                 data.append(QStyle::SC_TitleBarShadeButton);
0816                 break;
0817             case 'I':
0818                 data.append(QStyle::SC_TitleBarMinButton);
0819                 break;
0820             case 'A':
0821                 data.append(QStyle::SC_TitleBarMaxButton);
0822                 break;
0823             case 'X':
0824                 data.append(QStyle::SC_TitleBarCloseButton);
0825             default:
0826                 break;
0827         }
0828 }
0829 #endif
0830 
0831 static const QWidget*
0832 getWidget(const QPainter *p)
0833 {
0834     if (p) {
0835         if (p->device()->devType() == QInternal::Widget) {
0836             return static_cast<const QWidget*>(p->device());
0837         } else {
0838             QPaintDevice *dev = QPainter::redirected(p->device());
0839             if (dev && dev->devType() == QInternal::Widget) {
0840                 return static_cast<const QWidget*>(dev);
0841             }
0842         }
0843     }
0844     return 0L;
0845 }
0846 
0847 static const QImage * getImage(const QPainter *p)
0848 {
0849     return p && p->device() && QInternal::Image==p->device()->devType() ? static_cast<const QImage*>(p->device()) : 0L;
0850 }
0851 
0852 static const QAbstractButton * getButton(const QWidget *w, const QPainter *p)
0853 {
0854     const QWidget *widget=w ? w : getWidget(p);
0855     return widget ? qobject_cast<const QAbstractButton*>(widget) : 0L;
0856 }
0857 
0858 inline bool isMultiTabBarTab(const QAbstractButton *button)
0859 {
0860     // Check for isFlat fails in KDE SC4.5
0861     return button && ((qobject_cast<const QPushButton*>(button) &&
0862                        // ((QPushButton*)button)->isFlat() &&
0863                        button->inherits("KMultiTabBarTab")) ||
0864                       (theThemedApp == APP_KDEVELOP &&
0865                        qobject_cast<const QToolButton*>(button) &&
0866                        button->inherits("Sublime::IdealToolButton")));
0867 }
0868 
0869 #ifdef QTC_QT4_STYLE_SUPPORT
0870 Style::Style(const QString &name)
0871 #else
0872 Style::Style()
0873 #endif
0874       : m_popupMenuCols(0L),
0875         m_sliderCols(0L),
0876         m_defBtnCols(0L),
0877         m_comboBtnCols(0L),
0878         m_checkRadioSelCols(0L),
0879         m_sortedLvColors(0L),
0880         m_ooMenuCols(0L),
0881         m_progressCols(0L),
0882         m_saveMenuBarStatus(false),
0883         m_usePixmapCache(true),
0884         m_inactiveChangeSelectionColor(false),
0885         m_isPreview(PREVIEW_FALSE),
0886         m_sidebarButtonsCols(0L),
0887         m_activeMdiColors(0L),
0888         m_mdiColors(0L),
0889         m_pixmapCache(150000),
0890         m_active(true),
0891         m_sbWidget(0L),
0892         m_clickedLabel(0L),
0893         m_progressBarAnimateTimer(0),
0894         m_animateStep(0),
0895         m_titlebarHeight(0),
0896         m_pos(-1, -1),
0897         m_hoverWidget(0L),
0898         m_dBus(0),
0899         m_shadowHelper(new ShadowHelper(this)),
0900         m_sViewSBar(0L),
0901         m_windowManager(new WindowManager(this)),
0902         m_blurHelper(new BlurHelper(this)),
0903         m_shortcutHandler(new ShortcutHandler(this))
0904 #ifdef QTC_QT4_STYLE_SUPPORT
0905         , m_name(name)
0906 #endif
0907 {
0908     const char *env = getenv(QTCURVE_PREVIEW_CONFIG);
0909     if (oneOf(env, QTCURVE_PREVIEW_CONFIG)) {
0910         // To enable preview of QtCurve settings, the style config module will set QTCURVE_PREVIEW_CONFIG
0911         // and use CE_QtC_SetOptions to set options. If this is set, we do not use the QPixmapCache as it
0912         // will interfere with that of the kcm's widgets!
0913         m_isPreview = PREVIEW_MDI;
0914         m_usePixmapCache = false;
0915     } else if (oneOf(env, QTCURVE_PREVIEW_CONFIG_FULL)) {
0916         // As above, but preview is in window - so can use opacity settings!
0917         m_isPreview = PREVIEW_WINDOW;
0918         m_usePixmapCache = false;
0919     } else {
0920         init(true);
0921     }
0922 }
0923 
0924 void Style::init(bool initial)
0925 {
0926     if (!initial)
0927         freeColors();
0928 
0929 #ifdef QTC_QT4_ENABLE_KDE
0930     if (initial) {
0931         if (KGlobal::hasMainComponent()) {
0932             m_componentData = KGlobal::mainComponent();
0933         } else {
0934             QString name(QApplication::applicationName());
0935 
0936             if (name.isEmpty()) {
0937                 name = qAppName();
0938             }
0939             if (name.isEmpty()) {
0940                 name = "QtApp";
0941             }
0942             m_componentData = KComponentData(
0943                 name.toLatin1(), name.toLatin1(),
0944                 KComponentData::SkipMainComponentRegistration);
0945         }
0946     }
0947 #endif
0948 
0949     if (m_isPreview) {
0950         if (PREVIEW_WINDOW != m_isPreview) {
0951             opts.bgndOpacity = opts.dlgOpacity = opts.menuBgndOpacity = 100;
0952         }
0953     } else {
0954 #ifdef QTC_QT4_STYLE_SUPPORT
0955         QString rcFile;
0956         if (!m_name.isEmpty()) {
0957             rcFile = themeFile(Utils::kdeHome(), m_name);
0958             if (rcFile.isEmpty()) {
0959                 rcFile = themeFile(KDE_PREFIX(4), m_name, false);
0960             }
0961         }
0962         qtcReadConfig(rcFile, &opts);
0963 #else
0964         qtcReadConfig(QString(), &opts);
0965 #endif
0966 
0967         if (initial) {
0968 #ifdef Q_OS_MAC
0969             if (opts.nonnativeMenubarApps.contains("kde") || opts.nonnativeMenubarApps.contains(appName)) {
0970                 QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);
0971             }
0972 #endif
0973             QDBusConnection::sessionBus().connect(
0974                 QString(), "/KGlobalSettings", "org.kde.KGlobalSettings",
0975                 "notifyChange", this, SLOT(kdeGlobalSettingsChange(int, int)));
0976             QDBusConnection::sessionBus().connect(
0977                 "org.kde.kwin", "/KWin", "org.kde.KWin",
0978                 "compositingToggled", this, SLOT(compositingToggled()));
0979 
0980             if (!qApp || QString(qApp->argv()[0]) != "kwin") {
0981                 QDBusConnection::sessionBus().connect(
0982                     "org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
0983                     "borderSizesChanged", this, SLOT(borderSizesChanged()));
0984                 if (opts.menubarHiding & HIDE_KWIN) {
0985                     QDBusConnection::sessionBus().connect(
0986                         "org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
0987                         "toggleMenuBar", this,
0988                         SLOT(toggleMenuBar(unsigned int)));
0989                 }
0990 
0991                 if (opts.statusbarHiding & HIDE_KWIN) {
0992                     QDBusConnection::sessionBus().connect(
0993                         "org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
0994                         "toggleStatusBar", this,
0995                         SLOT(toggleStatusBar(unsigned int)));
0996                 }
0997             }
0998         }
0999     }
1000 
1001     opts.contrast=QSettings(QLatin1String("Trolltech")).value("/Qt/KDE/contrast", DEFAULT_CONTRAST).toInt();
1002     if(opts.contrast<0 || opts.contrast>10)
1003         opts.contrast=DEFAULT_CONTRAST;
1004 
1005     shadeColors(QApplication::palette().color(QPalette::Active, QPalette::Highlight), m_highlightCols);
1006     shadeColors(QApplication::palette().color(QPalette::Active, QPalette::Background), m_backgroundCols);
1007     shadeColors(QApplication::palette().color(QPalette::Active, QPalette::Button), m_buttonCols);
1008 
1009     // Set defaults for Hover and Focus, these will be changed when KDE4 palette is applied...
1010     shadeColors(QApplication::palette().color(QPalette::Active, QPalette::Highlight), m_focusCols);
1011     shadeColors(QApplication::palette().color(QPalette::Active, QPalette::Highlight), m_mouseOverCols);
1012 // Dont setup KDE4 fonts/colours here - seems to mess things up when using proxy styles.
1013 // See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=638629
1014 //#ifdef QTC_QT4_ENABLE_KDE
1015 //    setupKde4();
1016 //#endif
1017 
1018     m_windowManager->initialize(opts.windowDrag, opts.windowDragWhiteList.toList(), opts.windowDragBlackList.toList());
1019 
1020     switch(opts.shadeSliders)
1021     {
1022         default:
1023         case SHADE_DARKEN:
1024         case SHADE_NONE:
1025             break;
1026         case SHADE_SELECTED:
1027             m_sliderCols=m_highlightCols;
1028             break;
1029         case SHADE_BLEND_SELECTED:
1030         case SHADE_CUSTOM:
1031             if(!m_sliderCols)
1032                 m_sliderCols=new QColor [TOTAL_SHADES+1];
1033             shadeColors(SHADE_BLEND_SELECTED==opts.shadeSliders
1034                             ? midColor(m_highlightCols[ORIGINAL_SHADE],
1035                                        m_buttonCols[ORIGINAL_SHADE])
1036                             : opts.customSlidersColor,
1037                         m_sliderCols);
1038     }
1039 
1040     switch(opts.defBtnIndicator)
1041     {
1042         case IND_GLOW:
1043         case IND_SELECTED:
1044             m_defBtnCols=m_highlightCols;
1045             break;
1046         case IND_TINT:
1047             m_defBtnCols=new QColor [TOTAL_SHADES+1];
1048             shadeColors(tint(m_buttonCols[ORIGINAL_SHADE],
1049                             m_highlightCols[ORIGINAL_SHADE], DEF_BNT_TINT), m_defBtnCols);
1050             break;
1051         default:
1052             break;
1053         case IND_COLORED:
1054             if(SHADE_BLEND_SELECTED==opts.shadeSliders)
1055                 m_defBtnCols=m_sliderCols;
1056             else
1057             {
1058                 m_defBtnCols=new QColor [TOTAL_SHADES+1];
1059                 shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE],
1060                                     m_buttonCols[ORIGINAL_SHADE]), m_defBtnCols);
1061             }
1062     }
1063 
1064     switch(opts.comboBtn)
1065     {
1066         default:
1067         case SHADE_DARKEN:
1068         case SHADE_NONE:
1069             break;
1070         case SHADE_SELECTED:
1071             m_comboBtnCols=m_highlightCols;
1072             break;
1073         case SHADE_BLEND_SELECTED:
1074             if (opts.shadeSliders==SHADE_BLEND_SELECTED) {
1075                 m_comboBtnCols=m_sliderCols;
1076                 break;
1077             }
1078             QTC_FALLTHROUGH();
1079         case SHADE_CUSTOM:
1080             if(opts.shadeSliders==SHADE_CUSTOM && opts.customSlidersColor==opts.customComboBtnColor)
1081             {
1082                 m_comboBtnCols=m_sliderCols;
1083                 break;
1084             }
1085             if(!m_comboBtnCols)
1086                 m_comboBtnCols=new QColor [TOTAL_SHADES+1];
1087             shadeColors(SHADE_BLEND_SELECTED==opts.comboBtn
1088                             ? midColor(m_highlightCols[ORIGINAL_SHADE],
1089                                        m_buttonCols[ORIGINAL_SHADE])
1090                             : opts.customComboBtnColor,
1091                         m_comboBtnCols);
1092     }
1093 
1094     switch(opts.sortedLv)
1095     {
1096         case SHADE_DARKEN:
1097             if(!m_sortedLvColors)
1098                 m_sortedLvColors=new QColor [TOTAL_SHADES+1];
1099             shadeColors(shade(opts.lvButton ? m_buttonCols[ORIGINAL_SHADE] : m_backgroundCols[ORIGINAL_SHADE], LV_HEADER_DARK_FACTOR), m_sortedLvColors);
1100             break;
1101         default:
1102         case SHADE_NONE:
1103             break;
1104         case SHADE_SELECTED:
1105             m_sortedLvColors=m_highlightCols;
1106             break;
1107         case SHADE_BLEND_SELECTED:
1108             if(SHADE_BLEND_SELECTED==opts.shadeSliders)
1109             {
1110                 m_sortedLvColors=m_sliderCols;
1111                 break;
1112             }
1113             else if(SHADE_BLEND_SELECTED==opts.comboBtn)
1114             {
1115                 m_sortedLvColors=m_comboBtnCols;
1116                 break;
1117             }
1118             QTC_FALLTHROUGH();
1119         case SHADE_CUSTOM:
1120             if(opts.shadeSliders==SHADE_CUSTOM && opts.customSlidersColor==opts.customSortedLvColor)
1121             {
1122                 m_sortedLvColors=m_sliderCols;
1123                 break;
1124             }
1125             if(opts.comboBtn==SHADE_CUSTOM && opts.customComboBtnColor==opts.customSortedLvColor)
1126             {
1127                 m_sortedLvColors=m_comboBtnCols;
1128                 break;
1129             }
1130             if(!m_sortedLvColors)
1131                 m_sortedLvColors=new QColor [TOTAL_SHADES+1];
1132             shadeColors(SHADE_BLEND_SELECTED==opts.sortedLv
1133                             ? midColor(m_highlightCols[ORIGINAL_SHADE],
1134                                        (opts.lvButton ? m_buttonCols[ORIGINAL_SHADE] : m_backgroundCols[ORIGINAL_SHADE]))
1135                             : opts.customSortedLvColor,
1136                         m_sortedLvColors);
1137     }
1138 
1139     switch(opts.crColor)
1140     {
1141         default:
1142         case SHADE_NONE:
1143             m_checkRadioSelCols=m_buttonCols;
1144             break;
1145         case SHADE_DARKEN:
1146             if(!m_checkRadioSelCols)
1147                 m_checkRadioSelCols=new QColor [TOTAL_SHADES+1];
1148             shadeColors(shade(m_buttonCols[ORIGINAL_SHADE], LV_HEADER_DARK_FACTOR), m_checkRadioSelCols);
1149             break;
1150         case SHADE_SELECTED:
1151             m_checkRadioSelCols=m_highlightCols;
1152             break;
1153         case SHADE_CUSTOM:
1154             if(SHADE_CUSTOM==opts.shadeSliders && opts.customSlidersColor==opts.customCrBgndColor)
1155                 m_checkRadioSelCols=m_sliderCols;
1156             else if(SHADE_CUSTOM==opts.comboBtn && opts.customComboBtnColor==opts.customCrBgndColor)
1157                 m_checkRadioSelCols=m_comboBtnCols;
1158             else if(SHADE_CUSTOM==opts.sortedLv && opts.customSortedLvColor==opts.customCrBgndColor)
1159                 m_checkRadioSelCols=m_sortedLvColors;
1160             else
1161             {
1162                 if(!m_checkRadioSelCols)
1163                     m_checkRadioSelCols=new QColor [TOTAL_SHADES+1];
1164                 shadeColors(opts.customCrBgndColor, m_checkRadioSelCols);
1165             }
1166             break;
1167         case SHADE_BLEND_SELECTED:
1168             if(SHADE_BLEND_SELECTED==opts.shadeSliders)
1169                 m_checkRadioSelCols=m_sliderCols;
1170             else if(SHADE_BLEND_SELECTED==opts.comboBtn)
1171                 m_checkRadioSelCols=m_comboBtnCols;
1172             else if(SHADE_BLEND_SELECTED==opts.sortedLv)
1173                 m_checkRadioSelCols=m_sortedLvColors;
1174             else
1175             {
1176                 if(!m_checkRadioSelCols)
1177                     m_checkRadioSelCols=new QColor [TOTAL_SHADES+1];
1178                 shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE], m_buttonCols[ORIGINAL_SHADE]), m_checkRadioSelCols);
1179             }
1180     }
1181 
1182     switch(opts.progressColor)
1183     {
1184         case SHADE_NONE:
1185             m_progressCols=m_backgroundCols;
1186             break;
1187         default:
1188             // Not set!
1189             break;
1190         case SHADE_CUSTOM:
1191             if(SHADE_CUSTOM==opts.shadeSliders && opts.customSlidersColor==opts.customProgressColor)
1192                 m_progressCols=m_sliderCols;
1193             else if(SHADE_CUSTOM==opts.comboBtn && opts.customComboBtnColor==opts.customProgressColor)
1194                 m_progressCols=m_comboBtnCols;
1195             else if(SHADE_CUSTOM==opts.sortedLv && opts.customSortedLvColor==opts.customProgressColor)
1196                 m_progressCols=m_sortedLvColors;
1197             else if(SHADE_CUSTOM==opts.crColor && opts.customCrBgndColor==opts.customProgressColor)
1198                 m_progressCols=m_checkRadioSelCols;
1199             else
1200             {
1201                 if(!m_progressCols)
1202                     m_progressCols=new QColor [TOTAL_SHADES+1];
1203                 shadeColors(opts.customProgressColor, m_progressCols);
1204             }
1205             break;
1206         case SHADE_BLEND_SELECTED:
1207             if(SHADE_BLEND_SELECTED==opts.shadeSliders)
1208                 m_progressCols=m_sliderCols;
1209             else if(SHADE_BLEND_SELECTED==opts.comboBtn)
1210                 m_progressCols=m_comboBtnCols;
1211             else if(SHADE_BLEND_SELECTED==opts.sortedLv)
1212                 m_progressCols=m_sortedLvColors;
1213             else
1214             {
1215                 if(!m_progressCols)
1216                     m_progressCols=new QColor [TOTAL_SHADES+1];
1217                 shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE], m_backgroundCols[ORIGINAL_SHADE]), m_progressCols);
1218             }
1219     }
1220 
1221     setMenuColors(QApplication::palette().color(QPalette::Active, QPalette::Background));
1222 
1223     switch(opts.shadeCheckRadio)
1224     {
1225         default:
1226             m_checkRadioCol=QApplication::palette().color(QPalette::Active, opts.crButton ? QPalette::ButtonText : QPalette::Text);
1227             break;
1228         case SHADE_BLEND_SELECTED:
1229         case SHADE_SELECTED:
1230             m_checkRadioCol=QApplication::palette().color(QPalette::Active, QPalette::Highlight);
1231             break;
1232         case SHADE_CUSTOM:
1233             m_checkRadioCol=opts.customCheckRadioColor;
1234     }
1235 
1236     if(opts.titlebarButtons&TITLEBAR_BUTTON_COLOR && opts.titlebarButtonColors.size()>=NUM_TITLEBAR_BUTTONS)
1237         for(int i=0; i<NUM_TITLEBAR_BUTTONS; ++i)
1238         {
1239             QColor *cols=new QColor [TOTAL_SHADES+1];
1240             shadeColors(opts.titlebarButtonColors[(ETitleBarButtons)i], cols);
1241             m_titleBarButtonsCols[i]=cols;
1242         }
1243     else
1244         opts.titlebarButtons&=~TITLEBAR_BUTTON_COLOR;
1245 
1246     if(IMG_PLAIN_RINGS==opts.bgndImage.type || IMG_BORDERED_RINGS==opts.bgndImage.type ||
1247        IMG_SQUARE_RINGS==opts.bgndImage.type ||
1248        IMG_PLAIN_RINGS==opts.menuBgndImage.type || IMG_BORDERED_RINGS==opts.menuBgndImage.type ||
1249        IMG_SQUARE_RINGS==opts.menuBgndImage.type)
1250         qtcCalcRingAlphas(&m_backgroundCols[ORIGINAL_SHADE]);
1251 
1252     m_blurHelper->setEnabled(100!=opts.bgndOpacity || 100!=opts.dlgOpacity || 100!=opts.menuBgndOpacity);
1253 
1254 #ifdef QTC_QT4_ENABLE_KDE
1255     // We need to set the decoration colours for the preview now...
1256     if (m_isPreview) {
1257         setDecorationColors();
1258     }
1259 #endif
1260 }
1261 
1262 Style::~Style()
1263 {
1264     freeColors();
1265     if (m_dBus) {
1266         delete m_dBus;
1267     }
1268 }
1269 
1270 void Style::freeColor(QSet<QColor*> &freedColors, QColor **cols)
1271 {
1272     if(!freedColors.contains(*cols) &&
1273         *cols!=m_highlightCols &&
1274         *cols!=m_backgroundCols &&
1275         *cols!=m_menubarCols &&
1276         *cols!=m_focusCols &&
1277         *cols!=m_mouseOverCols &&
1278         *cols!=m_buttonCols &&
1279         *cols!=m_coloredButtonCols &&
1280         *cols!=m_coloredBackgroundCols &&
1281         *cols!=m_coloredHighlightCols)
1282     {
1283         freedColors.insert(*cols);
1284         delete [] *cols;
1285     }
1286     *cols=0L;
1287 }
1288 
1289 void Style::freeColors()
1290 {
1291     if(0!=m_progressBarAnimateTimer) {
1292         killTimer(m_progressBarAnimateTimer);
1293         m_progressBarAnimateTimer = 0;
1294     }
1295 
1296     QSet<QColor*> freedColors;
1297 
1298     freeColor(freedColors, &m_sidebarButtonsCols);
1299     freeColor(freedColors, &m_popupMenuCols);
1300     freeColor(freedColors, &m_activeMdiColors);
1301     freeColor(freedColors, &m_mdiColors);
1302     freeColor(freedColors, &m_progressCols);
1303     freeColor(freedColors, &m_checkRadioSelCols);
1304     freeColor(freedColors, &m_sortedLvColors);
1305     freeColor(freedColors, &m_comboBtnCols);
1306     freeColor(freedColors, &m_defBtnCols);
1307     freeColor(freedColors, &m_sliderCols);
1308 
1309     if (opts.titlebarButtons & TITLEBAR_BUTTON_COLOR) {
1310         for (int i = 0;i < NUM_TITLEBAR_BUTTONS;i++) {
1311             delete []m_titleBarButtonsCols[i];
1312             m_titleBarButtonsCols[i] = 0L;
1313         }
1314     }
1315     if (m_ooMenuCols) {
1316         delete []m_ooMenuCols;
1317         m_ooMenuCols = 0L;
1318     }
1319 }
1320 
1321 static QString getFile(const QString &f)
1322 {
1323     QString d(f);
1324 
1325     int slashPos(d.lastIndexOf('/'));
1326 
1327     if(slashPos!=-1)
1328         d.remove(0, slashPos+1);
1329 
1330     return d;
1331 }
1332 
1333 void Style::polish(QApplication *app)
1334 {
1335     appName=getFile(app->argv()[0]);
1336 
1337     if("kwin"==appName)
1338         theThemedApp=APP_KWIN;
1339     else if("systemsettings"==appName)
1340         theThemedApp = APP_SYSTEMSETTINGS;
1341     else if("plasma"==appName || appName.startsWith("plasma-"))
1342         theThemedApp = APP_PLASMA;
1343     else if("krunner"==appName || "krunner_lock"==appName || "kscreenlocker"==appName)
1344         theThemedApp=APP_KRUNNER;
1345     else if("kontact"==appName)
1346         theThemedApp=APP_KONTACT;
1347     else if("k3b"==appName)
1348         theThemedApp=APP_K3B;
1349     else if("arora"==appName)
1350         theThemedApp=APP_ARORA;
1351     else if("rekonq"==appName)
1352         theThemedApp=APP_REKONQ;
1353     else if("Designer"==QCoreApplication::applicationName())
1354         theThemedApp=APP_QTDESIGNER;
1355     else if("QtCreator"==QCoreApplication::applicationName())
1356         theThemedApp=APP_QTCREATOR;
1357     else if("kdevelop"==appName || "kdevelop.bin"==appName)
1358         theThemedApp=APP_KDEVELOP;
1359     else if("soffice.bin"==appName)
1360         theThemedApp=APP_OPENOFFICE;
1361     else if("kdmgreet"==appName)
1362         opts.forceAlternateLvCols=false;
1363 
1364     qtcInfo("QtCurve: Application name: \"%s\"\n",
1365             appName.toLatin1().constData());
1366 
1367     if(APP_REKONQ==theThemedApp)
1368         opts.statusbarHiding=0;
1369     if(opts.menubarHiding)
1370         m_saveMenuBarStatus=opts.menubarApps.contains("kde") || opts.menubarApps.contains(appName);
1371     if(opts.statusbarHiding)
1372         m_saveStatusBarStatus=opts.statusbarApps.contains("kde") || opts.statusbarApps.contains(appName);
1373 
1374     if(!qtcIsFlatBgnd(opts.bgndAppearance) && opts.noBgndGradientApps.contains(appName))
1375         opts.bgndAppearance=APPEARANCE_FLAT;
1376     if(IMG_NONE!=opts.bgndImage.type && opts.noBgndImageApps.contains(appName))
1377         opts.bgndImage.type=IMG_NONE;
1378     if(SHADE_NONE!=opts.menuStripe && opts.noMenuStripeApps.contains(appName))
1379         opts.menuStripe=SHADE_NONE;
1380 
1381     if((100!=opts.bgndOpacity || 100!=opts.dlgOpacity) && (opts.noBgndOpacityApps.contains(appName) || appName.endsWith(".kss")))
1382         opts.bgndOpacity=opts.dlgOpacity=100;
1383     if(100!=opts.menuBgndOpacity && opts.noMenuBgndOpacityApps.contains(appName))
1384         opts.menuBgndOpacity=100;
1385 
1386     if (theThemedApp == APP_KWIN) {
1387         opts.bgndAppearance = APPEARANCE_FLAT;
1388     } else if (theThemedApp == APP_OPENOFFICE) {
1389         opts.scrollbarType = SCROLLBAR_WINDOWS;
1390         if (opts.menuitemAppearance == APPEARANCE_FADE)
1391             opts.menuitemAppearance = APPEARANCE_FLAT;
1392         opts.borderMenuitems = opts.etchEntry = false;
1393 
1394         if(opts.useHighlightForMenu && blendOOMenuHighlight(QApplication::palette(), m_highlightCols[ORIGINAL_SHADE]))
1395         {
1396             m_ooMenuCols=new QColor [TOTAL_SHADES+1];
1397             shadeColors(tint(popupMenuCols()[ORIGINAL_SHADE], m_highlightCols[ORIGINAL_SHADE], 0.5), m_ooMenuCols);
1398         }
1399         opts.menubarHiding=opts.statusbarHiding=HIDE_NONE;
1400         opts.square|=SQUARE_POPUP_MENUS|SQUARE_TOOLTIPS;
1401         if(!qtcIsFlatBgnd(opts.menuBgndAppearance) && 0==opts.lighterPopupMenuBgnd)
1402             opts.lighterPopupMenuBgnd=1; // shade so that we dont have 3d-ish borders...
1403         opts.menuBgndAppearance=APPEARANCE_FLAT;
1404     }
1405 
1406     if (opts.useQtFileDialogApps.contains(appName)) {
1407         qt_filedialog_existing_directory_hook = 0L;
1408         qt_filedialog_open_filename_hook = 0L;
1409         qt_filedialog_open_filenames_hook = 0L;
1410         qt_filedialog_save_filename_hook = 0L;
1411     }
1412 
1413     BaseStyle::polish(app);
1414     if (opts.hideShortcutUnderline) {
1415         app->installEventFilter(m_shortcutHandler);
1416     }
1417 }
1418 
1419 void Style::polish(QPalette &palette)
1420 {
1421     int  contrast(QSettings(QLatin1String("Trolltech")).value("/Qt/KDE/contrast", DEFAULT_CONTRAST).toInt());
1422     bool newContrast(false);
1423 
1424     if(contrast<0 || contrast>10)
1425         contrast=DEFAULT_CONTRAST;
1426 
1427     if(contrast!=opts.contrast)
1428     {
1429         opts.contrast=contrast;
1430         newContrast=true;
1431     }
1432 
1433     bool newHighlight(newContrast ||
1434                  m_highlightCols[ORIGINAL_SHADE]!=palette.color(QPalette::Active, QPalette::Highlight)),
1435          newGray(newContrast ||
1436                  m_backgroundCols[ORIGINAL_SHADE]!=palette.color(QPalette::Active, QPalette::Background)),
1437          newButton(newContrast ||
1438                    m_buttonCols[ORIGINAL_SHADE]!=palette.color(QPalette::Active, QPalette::Button)),
1439          newSlider(m_sliderCols && m_highlightCols!=m_sliderCols && SHADE_BLEND_SELECTED==opts.shadeSliders &&
1440                    (newButton || newHighlight)),
1441          newDefBtn(m_defBtnCols && (IND_COLORED!=opts.defBtnIndicator || SHADE_BLEND_SELECTED!=opts.shadeSliders) &&
1442                    IND_SELECTED!=opts.defBtnIndicator && IND_GLOW!=opts.defBtnIndicator &&
1443                    (newContrast || newButton || newHighlight)),
1444          newComboBtn(m_comboBtnCols && m_highlightCols!=m_comboBtnCols && m_sliderCols!=m_comboBtnCols &&
1445                      SHADE_BLEND_SELECTED==opts.comboBtn &&
1446                      (newButton || newHighlight)),
1447          newSortedLv(m_sortedLvColors && ((SHADE_BLEND_SELECTED==opts.sortedLv && m_defBtnCols!=m_sortedLvColors &&
1448                                             m_sliderCols!=m_sortedLvColors && m_comboBtnCols!=m_sortedLvColors) ||
1449                                              SHADE_DARKEN==opts.sortedLv) &&
1450                      (newContrast || (opts.lvButton ? newButton : newGray))),
1451          newCheckRadioSelCols(m_checkRadioSelCols && ((SHADE_BLEND_SELECTED==opts.crColor && m_defBtnCols!=m_checkRadioSelCols &&
1452                                                          m_sliderCols!=m_checkRadioSelCols && m_comboBtnCols!=m_checkRadioSelCols &&
1453                                                          m_sortedLvColors!=m_checkRadioSelCols) ||
1454                                              SHADE_DARKEN==opts.crColor) &&
1455                      (newContrast || newButton)),
1456          newProgressCols(m_progressCols && SHADE_BLEND_SELECTED==opts.progressColor &&
1457                          m_sliderCols!=m_progressCols && m_comboBtnCols!=m_progressCols &&
1458                          m_sortedLvColors!=m_progressCols && m_checkRadioSelCols!=m_progressCols && (newContrast || newButton));
1459 
1460     if(newGray)
1461     {
1462         shadeColors(palette.color(QPalette::Active, QPalette::Background), m_backgroundCols);
1463         if(IMG_PLAIN_RINGS==opts.bgndImage.type || IMG_BORDERED_RINGS==opts.bgndImage.type ||
1464            IMG_SQUARE_RINGS==opts.bgndImage.type ||
1465            IMG_PLAIN_RINGS==opts.menuBgndImage.type || IMG_BORDERED_RINGS==opts.menuBgndImage.type ||
1466            IMG_SQUARE_RINGS==opts.menuBgndImage.type)
1467         {
1468             qtcCalcRingAlphas(&m_backgroundCols[ORIGINAL_SHADE]);
1469             if(m_usePixmapCache)
1470                 QPixmapCache::clear();
1471         }
1472     }
1473 
1474     if(newButton)
1475         shadeColors(palette.color(QPalette::Active, QPalette::Button), m_buttonCols);
1476 
1477     if(newHighlight)
1478         shadeColors(palette.color(QPalette::Active, QPalette::Highlight), m_highlightCols);
1479 
1480 // Dont set these here, they will be updated in setDecorationColors()...
1481 //     shadeColors(QApplication::palette().color(QPalette::Active, QPalette::Highlight), m_focusCols);
1482 //     if(opts.coloredMouseOver)
1483 //         shadeColors(QApplication::palette().color(QPalette::Active, QPalette::Highlight), m_mouseOverCols);
1484 
1485     setMenuColors(palette.color(QPalette::Active, QPalette::Background));
1486 
1487     if(newSlider)
1488         shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE], m_buttonCols[ORIGINAL_SHADE]), m_sliderCols);
1489 
1490     if(newDefBtn)
1491     {
1492         if(IND_TINT==opts.defBtnIndicator)
1493             shadeColors(tint(m_buttonCols[ORIGINAL_SHADE],
1494                         m_highlightCols[ORIGINAL_SHADE], DEF_BNT_TINT), m_defBtnCols);
1495         else if(IND_GLOW!=opts.defBtnIndicator)
1496             shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE],
1497                         m_buttonCols[ORIGINAL_SHADE]), m_defBtnCols);
1498     }
1499 
1500     if(newComboBtn)
1501         shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE], m_buttonCols[ORIGINAL_SHADE]), m_comboBtnCols);
1502 
1503     if(newSortedLv)
1504     {
1505         if(SHADE_BLEND_SELECTED==opts.sortedLv)
1506             shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE],
1507                         opts.lvButton ? m_buttonCols[ORIGINAL_SHADE] : m_backgroundCols[ORIGINAL_SHADE]), m_sortedLvColors);
1508         else
1509             shadeColors(shade(opts.lvButton ? m_buttonCols[ORIGINAL_SHADE] : m_backgroundCols[ORIGINAL_SHADE], LV_HEADER_DARK_FACTOR),
1510                         m_sortedLvColors);
1511     }
1512 
1513     if(m_sidebarButtonsCols && SHADE_BLEND_SELECTED!=opts.shadeSliders &&
1514        IND_COLORED!=opts.defBtnIndicator)
1515         shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE],
1516                    m_buttonCols[ORIGINAL_SHADE]), m_sidebarButtonsCols);
1517 
1518     switch(opts.shadeCheckRadio)
1519     {
1520         default:
1521             m_checkRadioCol=palette.color(QPalette::Active, opts.crButton ? QPalette::ButtonText : QPalette::Text);
1522             break;
1523         case SHADE_BLEND_SELECTED:
1524         case SHADE_SELECTED:
1525             m_checkRadioCol=palette.color(QPalette::Active, QPalette::Highlight);
1526             break;
1527         case SHADE_CUSTOM:
1528              m_checkRadioCol=opts.customCheckRadioColor;
1529     }
1530 
1531     if(newCheckRadioSelCols)
1532     {
1533         if(SHADE_BLEND_SELECTED==opts.crColor)
1534             shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE], m_buttonCols[ORIGINAL_SHADE]), m_checkRadioSelCols);
1535         else
1536             shadeColors(shade(m_buttonCols[ORIGINAL_SHADE], LV_HEADER_DARK_FACTOR), m_checkRadioSelCols);
1537     }
1538 
1539     if(newProgressCols)
1540         shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE], m_backgroundCols[ORIGINAL_SHADE]), m_progressCols);
1541 
1542     if(APP_OPENOFFICE==theThemedApp && opts.useHighlightForMenu && (newGray || newHighlight))
1543     {
1544         if(blendOOMenuHighlight(palette, m_highlightCols[ORIGINAL_SHADE]))
1545         {
1546             if(!m_ooMenuCols)
1547                 m_ooMenuCols=new QColor [TOTAL_SHADES+1];
1548             shadeColors(tint(popupMenuCols()[ORIGINAL_SHADE], m_highlightCols[ORIGINAL_SHADE], 0.5), m_ooMenuCols);
1549         }
1550         else if(m_ooMenuCols)
1551         {
1552             delete [] m_ooMenuCols;
1553             m_ooMenuCols=0L;
1554         }
1555     }
1556 
1557     palette.setColor(QPalette::Active, QPalette::Light, m_backgroundCols[0]);
1558     palette.setColor(QPalette::Active, QPalette::Dark, m_backgroundCols[QTC_STD_BORDER]);
1559     palette.setColor(QPalette::Inactive, QPalette::Light, m_backgroundCols[0]);
1560     palette.setColor(QPalette::Inactive, QPalette::Dark, m_backgroundCols[QTC_STD_BORDER]);
1561     palette.setColor(QPalette::Inactive, QPalette::WindowText, palette.color(QPalette::Active, QPalette::WindowText));
1562     palette.setColor(QPalette::Disabled, QPalette::Light, m_backgroundCols[0]);
1563     palette.setColor(QPalette::Disabled, QPalette::Dark, m_backgroundCols[QTC_STD_BORDER]);
1564 
1565     palette.setColor(QPalette::Disabled, QPalette::Base, palette.color(QPalette::Active, QPalette::Background));
1566     palette.setColor(QPalette::Disabled, QPalette::Background, palette.color(QPalette::Active, QPalette::Background));
1567 
1568     // Fix KDE4's palette...
1569     if(palette.color(QPalette::Active, QPalette::Highlight)!=palette.color(QPalette::Inactive, QPalette::Highlight))
1570         m_inactiveChangeSelectionColor=true;
1571 
1572     for(int i=QPalette::WindowText; i<QPalette::NColorRoles; ++i)
1573         //if(i!=QPalette::Highlight && i!=QPalette::HighlightedText)
1574             palette.setColor(QPalette::Inactive, (QPalette::ColorRole)i, palette.color(QPalette::Active, (QPalette::ColorRole)i));
1575 
1576     // Force this to be re-generated!
1577     if(SHADE_BLEND_SELECTED==opts.menuStripe)
1578         opts.customMenuStripeColor=Qt::black;
1579 #ifdef QTC_QT4_ENABLE_KDE
1580     // Only set palette here...
1581     if(kapp)
1582         setDecorationColors();
1583 #endif
1584 }
1585 
1586 void
1587 Style::polish(QWidget *widget)
1588 {
1589     // TODO Reorganize this polish function
1590     if (!widget)
1591         return;
1592 
1593     QtcQWidgetProps qtcProps(widget);
1594     bool enableMouseOver(opts.highlightFactor || opts.coloredMouseOver);
1595     if (Log::checkLevel(LogLevel::Info) && qtcGetWid(widget) &&
1596         widget->windowType() != Qt::Desktop && !qtcProps->prePolished) {
1597         qDebug() << "Window Created before polishing:" << widget;
1598     }
1599     qtcProps->prePolished = true;
1600 
1601     if (opts.buttonEffect != EFFECT_NONE && !USE_CUSTOM_ALPHAS(opts) &&
1602         isNoEtchWidget(widget)) {
1603         qtcProps->noEtch = true;
1604     }
1605 
1606     m_windowManager->registerWidget(widget);
1607     m_shadowHelper->registerWidget(widget);
1608 
1609     // Need to register all widgets to blur helper, in order to have proper
1610     // blur_behind region set have proper regions removed for opaque widgets.
1611     // Note: that the helper does nothing as long as compositing and ARGB
1612     // are not enabled
1613     const bool isDialog = qtcIsDialog(widget->window());
1614     if ((opts.menuBgndOpacity != 100 &&
1615          (qobject_cast<QMenu*>(widget) ||
1616           // TODO temporary solution only
1617           widget->inherits("QComboBoxPrivateContainer"))) ||
1618         (opts.bgndOpacity != 100 && (!widget->window() || !isDialog)) ||
1619         (opts.dlgOpacity != 100 && (!widget->window() || isDialog))) {
1620         m_blurHelper->registerWidget(widget);
1621     }
1622     // Sometimes get background errors with QToolBox (e.g. in Bespin config),
1623     // and setting WA_StyledBackground seems to fix this,..
1624     if (qtcIsCustomBgnd(opts) ||
1625         oneOf(opts.groupBox, FRAME_SHADED, FRAME_FADED)) {
1626         switch (widget->windowType()) {
1627         case Qt::Window:
1628         case Qt::Sheet:
1629         case Qt::Dialog: {
1630             // For non-transparent widgets, only need to set
1631             // WA_StyledBackground - and PE_Widget will be called to
1632             // render background...
1633             widget->setAttribute(Qt::WA_StyledBackground);
1634             break;
1635         }
1636         case Qt::Popup:
1637             // we currently don't want that kind of gradient on menus etc
1638         case Qt::Drawer:
1639         case Qt::Tool:
1640             // this we exclude as it is used for dragging of icons etc
1641         default:
1642             break;
1643         }
1644         if (qobject_cast<QSlider*>(widget)) {
1645             widget->setBackgroundRole(QPalette::NoRole);
1646         }
1647         if (widget->autoFillBackground() && widget->parentWidget() &&
1648             widget->parentWidget()->objectName() == "qt_scrollarea_viewport" &&
1649             qtcCheckType<QAbstractScrollArea>(getParent<2>(widget)) &&
1650             qtcCheckType<QToolBox>(getParent<3>(widget))) {
1651             widget->parentWidget()->setAutoFillBackground(false);
1652             widget->setAutoFillBackground(false);
1653         }
1654     }
1655 
1656     // Translucent main window seems to cause QMdiSubWindow to not draw its
1657     // background. Not sure what exactly the problem is but drawing the
1658     // background ourselves by setting Qt::WA_StyledBackground
1659     // as well as handling it in drawPrimitive seems to fix/workaround
1660     // the problem.
1661     // TODO:
1662     // Figuring out what's wrong.
1663     // Check what oxygen does to QMdiSubWindow
1664     // Check Qt5 version
1665     if (qobject_cast<QMdiSubWindow*>(widget)) {
1666         widget->setAttribute(Qt::WA_StyledBackground);
1667     }
1668 
1669     if (opts.menubarHiding && qobject_cast<QMainWindow*>(widget) &&
1670         static_cast<QMainWindow*>(widget)->menuWidget()) {
1671         widget->installEventFilter(this);
1672         if (m_saveMenuBarStatus) {
1673             static_cast<QMainWindow*>(widget)->menuWidget()
1674                 ->installEventFilter(this);
1675         }
1676         if (m_saveMenuBarStatus && qtcMenuBarHidden(appName)) {
1677             static_cast<QMainWindow*>(widget)->menuWidget()->setHidden(true);
1678             if (BLEND_TITLEBAR || opts.menubarHiding & HIDE_KWIN ||
1679                 opts.windowBorder &
1680                 WINDOW_BORDER_USE_MENUBAR_COLOR_FOR_TITLEBAR) {
1681                 emitMenuSize(static_cast<QMainWindow*>(widget)->menuWidget(), 0);
1682             }
1683         }
1684     }
1685 
1686     if (opts.statusbarHiding && qobject_cast<QMainWindow*>(widget)) {
1687         QList<QStatusBar*> sb = getStatusBars(widget);
1688         if (sb.count()) {
1689             widget->installEventFilter(this);
1690             foreach (QStatusBar *statusBar, sb) {
1691                 if (m_saveStatusBarStatus) {
1692                     statusBar->installEventFilter(this);
1693                 }
1694                 if (m_saveStatusBarStatus && qtcStatusBarHidden(appName)) {
1695                     statusBar->setHidden(true);
1696                 }
1697             }
1698             setSbProp(widget);
1699             emitStatusBarState(sb.first());
1700         }
1701     }
1702 
1703     // Enable hover effects in all itemviews
1704     if (QAbstractItemView *itemView =
1705         qobject_cast<QAbstractItemView*>(widget)) {
1706         QWidget *viewport=itemView->viewport();
1707         viewport->setAttribute(Qt::WA_Hover);
1708 
1709         if(opts.forceAlternateLvCols &&
1710            viewport->autoFillBackground() && // Dolphins Folders panel
1711            //255==viewport->palette().color(itemView->viewport()->backgroundRole()).alpha() && // KFilePlacesView
1712            !widget->inherits("KFilePlacesView") &&
1713            // Exclude non-editable combo popup...
1714            !(opts.gtkComboMenus && widget->inherits("QComboBoxListView") &&
1715              qtcCheckType<QComboBox>(getParent<2>(widget)) &&
1716              !static_cast<QComboBox*>(getParent<2>(widget))->isEditable()) &&
1717            // Exclude KAboutDialog...
1718            !qtcCheckKDEType(getParent<5>(widget), KAboutApplicationDialog) &&
1719            (qobject_cast<QTreeView*>(widget) ||
1720             (qobject_cast<QListView*>(widget) &&
1721              ((QListView*)widget)->viewMode() != QListView::IconMode))) {
1722             itemView->setAlternatingRowColors(true);
1723         }
1724     }
1725 
1726     if (APP_KONTACT == theThemedApp && qobject_cast<QToolButton*>(widget))
1727         ((QToolButton*)widget)->setAutoRaise(true);
1728 
1729     if(enableMouseOver &&
1730        (qobject_cast<QPushButton*>(widget) ||
1731         qobject_cast<QAbstractButton*>(widget) ||
1732         qobject_cast<QComboBox*>(widget) ||
1733         qobject_cast<QAbstractSpinBox*>(widget) ||
1734         qobject_cast<QCheckBox*>(widget) ||
1735         qobject_cast<QGroupBox*>(widget) ||
1736         qobject_cast<QRadioButton*>(widget) ||
1737         qobject_cast<QSplitterHandle*>(widget) ||
1738         qobject_cast<QSlider*>(widget) ||
1739         qobject_cast<QHeaderView*>(widget) ||
1740         qobject_cast<QTabBar*>(widget) ||
1741         qobject_cast<QAbstractScrollArea*>(widget) ||
1742         qobject_cast<QTextEdit*>(widget) ||
1743         qobject_cast<QLineEdit*>(widget) ||
1744         qobject_cast<QDial*>(widget) ||
1745         // qobject_cast<QDockWidget*>(widget) ||
1746         widget->inherits("QWorkspaceTitleBar") ||
1747         widget->inherits("QDockSeparator") ||
1748         widget->inherits("QDockWidgetSeparator") ||
1749         widget->inherits("Q3DockWindowResizeHandle")))
1750         widget->setAttribute(Qt::WA_Hover, true);
1751 
1752     if (qobject_cast<QSplitterHandle*>(widget)) {
1753         widget->setAttribute(Qt::WA_OpaquePaintEvent, false);
1754     } else if (qobject_cast<QScrollBar*>(widget)) {
1755         if (enableMouseOver) {
1756             widget->setAttribute(Qt::WA_Hover, true);
1757         }
1758         widget->setAttribute(Qt::WA_OpaquePaintEvent, false);
1759         if (!opts.gtkScrollViews) {
1760             widget->installEventFilter(this);
1761         }
1762     } else if (qobject_cast<QAbstractScrollArea*>(widget) &&
1763                widget->inherits("KFilePlacesView")) {
1764         if (qtcIsCustomBgnd(opts)) {
1765             polishScrollArea(static_cast<QAbstractScrollArea*>(widget), true);
1766         }
1767         widget->installEventFilter(this);
1768     } else if (qobject_cast<QProgressBar*>(widget)) {
1769         if (widget->palette().color(QPalette::Inactive,
1770                                     QPalette::HighlightedText) !=
1771             widget->palette().color(QPalette::Active,
1772                                     QPalette::HighlightedText)) {
1773             QPalette pal(widget->palette());
1774             pal.setColor(QPalette::Inactive, QPalette::HighlightedText,
1775                          pal.color(QPalette::Active,
1776                                    QPalette::HighlightedText));
1777             widget->setPalette(pal);
1778         }
1779         if (opts.boldProgress) {
1780             setBold(widget);
1781         }
1782         widget->installEventFilter(this);
1783     } else if (widget->inherits("Q3Header")) {
1784         widget->setMouseTracking(true);
1785         widget->installEventFilter(this);
1786     } else if (opts.highlightScrollViews && widget->inherits("Q3ScrollView")) {
1787         widget->installEventFilter(this);
1788         widget->setAttribute(Qt::WA_Hover, true);
1789     } else if (qobject_cast<QMenuBar*>(widget)) {
1790         if (opts.xbar &&
1791             (!(oneOf(theThemedApp, APP_QTDESIGNER, APP_KDEVELOP) &&
1792                widget->inherits("QDesignerMenuBar")))) {
1793             Bespin::MacMenu::manage((QMenuBar*)widget);
1794         }
1795         if (BLEND_TITLEBAR || opts.menubarHiding & HIDE_KWIN ||
1796             opts.windowBorder & WINDOW_BORDER_USE_MENUBAR_COLOR_FOR_TITLEBAR) {
1797             emitMenuSize(widget, PREVIEW_MDI == m_isPreview ||
1798                          !widget->isVisible() ? 0 : widget->rect().height());
1799         }
1800         if (qtcIsCustomBgnd(opts)) {
1801             widget->setBackgroundRole(QPalette::NoRole);
1802         }
1803         widget->setAttribute(Qt::WA_Hover, true);
1804 
1805         // if(opts.shadeMenubarOnlyWhenActive && SHADE_NONE!=opts.shadeMenubars)
1806         widget->installEventFilter(this);
1807 
1808         setMenuTextColors(widget, true);
1809     } else if (qobject_cast<QLabel*>(widget)) {
1810         widget->installEventFilter(this);
1811         if (WM_DRAG_ALL == opts.windowDrag &&
1812             (((QLabel*)widget)->textInteractionFlags()
1813              .testFlag(Qt::TextSelectableByMouse)) &&
1814             qtcCheckType<QFrame>(widget->parentWidget()) &&
1815             qtcCheckKDEType(getParent<2>(widget), KTitleWidget))
1816             ((QLabel*)widget)->setTextInteractionFlags(((QLabel*)widget)->textInteractionFlags()&~Qt::TextSelectableByMouse);
1817 
1818     } else if (/*!opts.gtkScrollViews && */qobject_cast<QAbstractScrollArea*>(widget)) {
1819         if(qtcIsCustomBgnd(opts))
1820             polishScrollArea(static_cast<QAbstractScrollArea*>(widget));
1821         if (!opts.gtkScrollViews && (((QFrame*)widget)->frameWidth() > 0)) {
1822             widget->installEventFilter(this);
1823         }
1824         if (theThemedApp == APP_KONTACT && widget->parentWidget()) {
1825             QWidget *frame = scrollViewFrame(widget->parentWidget());
1826 
1827             if (frame) {
1828                 frame->installEventFilter(this);
1829                 m_sViewContainers[frame].insert(widget);
1830                 connect(widget, SIGNAL(destroyed(QObject*)),
1831                         this, SLOT(widgetDestroyed(QObject*)));
1832                 connect(frame, SIGNAL(destroyed(QObject*)),
1833                         this, SLOT(widgetDestroyed(QObject*)));
1834             }
1835         }
1836     } else if(qobject_cast<QDialog*>(widget) &&
1837               widget->inherits("QPrintPropertiesDialog") &&
1838               widget->parentWidget() && widget->window() &&
1839               widget->parentWidget()->window() &&
1840               widget->window()->windowTitle().isEmpty() &&
1841               !widget->parentWidget()->window()->windowTitle().isEmpty()) {
1842         widget->window()->setWindowTitle(widget->parentWidget()->window()
1843                                          ->windowTitle());
1844     } else if (widget->inherits("QWhatsThat")) {
1845         QPalette pal(widget->palette());
1846         QColor shadow(pal.shadow().color());
1847 
1848         shadow.setAlpha(32);
1849         pal.setColor(QPalette::Shadow, shadow);
1850         widget->setPalette(pal);
1851         widget->setMask(QRegion(widget->rect().adjusted(0, 0, -6, -6))+QRegion(widget->rect().adjusted(6, 6, 0, 0)));
1852     } else if (qobject_cast<QDockWidget*>(widget) &&
1853                qtcCheckType<QSplitter>(widget->parentWidget()) &&
1854                qtcCheckType(getParent<2>(widget), "KFileWidget")) {
1855         ((QDockWidget*)widget)
1856             ->setTitleBarWidget(new QtCurveDockWidgetTitleBar(widget));
1857     }
1858 
1859     if (widget->inherits("QTipLabel") &&
1860         !qtcIsFlat(opts.tooltipAppearance)) {
1861         widget->setBackgroundRole(QPalette::NoRole);
1862         // TODO: turn this into addAlphaChannel
1863         widget->setAttribute(Qt::WA_TranslucentBackground);
1864     }
1865 
1866     if (!widget->isWindow())
1867         if (QFrame *frame = qobject_cast<QFrame*>(widget)) {
1868             // kill ugly frames...
1869             if (QFrame::Box == frame->frameShape() ||
1870                 QFrame::Panel == frame->frameShape() ||
1871                 QFrame::WinPanel == frame->frameShape())
1872                 frame->setFrameShape(QFrame::StyledPanel);
1873             // else if (QFrame::HLine==frame->frameShape() || QFrame::VLine==frame->frameShape())
1874             widget->installEventFilter(this);
1875             if (qtcCheckKDEType(widget->parent(), KTitleWidget)) {
1876                 if(qtcIsCustomBgnd(opts))
1877                     frame->setAutoFillBackground(false);
1878                 else
1879                     frame->setBackgroundRole(QPalette::Window);
1880 
1881                 QLayout *layout(frame->layout());
1882 
1883                 if (layout) {
1884                     layout->setMargin(0);
1885                 }
1886             }
1887 
1888             QComboBox *p = nullptr;
1889             if (opts.gtkComboMenus &&
1890                 (p = qtcObjCast<QComboBox>(getParent<2>(widget))) &&
1891                 !p->isEditable()) {
1892                 QPalette pal(widget->palette());
1893                 QColor col(popupMenuCols()[ORIGINAL_SHADE]);
1894 
1895                 if(!qtcIsFlatBgnd(opts.menuBgndAppearance) || 100!=opts.menuBgndOpacity || !POPUP_MENUS_SQUARE(opts))
1896                     col.setAlphaF(0);
1897 
1898                 pal.setBrush(QPalette::Active, QPalette::Base, col);
1899                 pal.setBrush(QPalette::Active, QPalette::Window, col);
1900                 widget->setPalette(pal);
1901                 if(opts.shadePopupMenu)
1902                     setMenuTextColors(widget, false);
1903             }
1904         }
1905 
1906     if (qobject_cast<QMenu*>(widget)) {
1907         if (!qtcIsFlatBgnd(opts.menuBgndAppearance) ||
1908             opts.menuBgndOpacity != 100 ||
1909             !POPUP_MENUS_SQUARE(opts)) {
1910             widget->installEventFilter(this);
1911             // Set WA_NoSystemBackground or a square background will be drawn.
1912             widget->setAttribute(Qt::WA_NoSystemBackground);
1913         }
1914         if (opts.lighterPopupMenuBgnd || opts.shadePopupMenu) {
1915             QPalette pal = widget->palette();
1916 
1917             pal.setBrush(QPalette::Active, QPalette::Window,
1918                          popupMenuCols()[ORIGINAL_SHADE]);
1919             widget->setPalette(pal);
1920             if (opts.shadePopupMenu)
1921                 setMenuTextColors(widget, false);
1922             if (IMG_NONE != opts.menuBgndImage.type) {
1923                 widget->installEventFilter(this);
1924             }
1925         }
1926     }
1927 
1928     if ((!qtcIsFlatBgnd(opts.menuBgndAppearance) ||
1929          opts.menuBgndOpacity != 100 || !POPUP_MENUS_SQUARE(opts)) &&
1930         widget->inherits("QComboBoxPrivateContainer")) {
1931         widget->installEventFilter(this);
1932         // Set WA_NoSystemBackground or a square background will be drawn.
1933         widget->setAttribute(Qt::WA_NoSystemBackground);
1934     }
1935 
1936     bool parentIsToolbar(false);
1937 
1938     // Using dark menubars - konqueror's combo box texts get messed up. Seems to be when a plain QWidget has widget->setBackgroundRole(QPalette::Window);
1939     // and widget->setAutoFillBackground(false); set (below). These onyl happen if 'parentIsToolbar' - so dont bather detecting this if the widget
1940     // is a plain QWidget
1941     //
1942     // QWidget QComboBoxListView QComboBoxPrivateContainer SearchBarCombo KToolBar KonqMainWindow
1943     // QWidget KCompletionBox KLineEdit SearchBarCombo KToolBar KonqMainWindow
1944     if (noneOf(widget->metaObject()->className(), "QWidget")) {
1945         QWidget *wid = widget ? widget->parentWidget() : nullptr;
1946         while (wid && !parentIsToolbar) {
1947             parentIsToolbar = (qobject_cast<QToolBar*>(wid) ||
1948                                wid->inherits("Q3ToolBar"));
1949             wid = wid->parentWidget();
1950         }
1951     }
1952 
1953     if (theThemedApp == APP_QTCREATOR &&
1954         qobject_cast<QMainWindow*>(widget) &&
1955         static_cast<QMainWindow*>(widget)->menuWidget()) {
1956         static_cast<QMainWindow*>(widget)->menuWidget()->setStyle(this);
1957     }
1958 
1959     if (theThemedApp == APP_QTCREATOR && qobject_cast<QDialog*>(widget) &&
1960         qtcCheckKDEType(widget, KFileDialog)) {
1961         if (QToolBar *tb = getToolBarChild(widget)) {
1962             int size = pixelMetric(PM_ToolBarIconSize);
1963             tb->setIconSize(QSize(size, size));
1964             tb->setMinimumSize(QSize(size+14, size+14));
1965             setStyleRecursive(tb, this, size+4);
1966         }
1967     }
1968 
1969     if(parentIsToolbar && (qobject_cast<QComboBox*>(widget) ||
1970                            qobject_cast<QLineEdit*>(widget)))
1971         widget->setFont(QApplication::font());
1972 
1973     if (qobject_cast<QMenuBar*>(widget) || widget->inherits("Q3ToolBar") || qobject_cast<QToolBar*>(widget) || parentIsToolbar)
1974         widget->setBackgroundRole(QPalette::Window);
1975 
1976     if(!qtcIsFlat(opts.toolbarAppearance) && parentIsToolbar)
1977         widget->setAutoFillBackground(false);
1978 
1979     if (APP_SYSTEMSETTINGS == theThemedApp &&
1980         qtcCheckType<QFrame>(widget) &&
1981         QFrame::NoFrame != ((QFrame*)widget)->frameShape() &&
1982         qtcCheckType<QFrame>(widget->parentWidget()) &&
1983         qtcCheckType<QTabWidget>(getParent<2>(widget)))
1984         ((QFrame*)widget)->setFrameShape(QFrame::NoFrame);
1985 
1986     if (QLayout *layout = widget->layout()) {
1987         // explicitly check public layout classes,
1988         // QMainWindowLayout doesn't work here
1989         if (qobject_cast<QBoxLayout*>(layout) ||
1990             qobject_cast<QFormLayout*>(layout) ||
1991             qobject_cast<QGridLayout*>(layout) ||
1992             qobject_cast<QStackedLayout*>(layout)) {
1993             polishLayout(layout);
1994         }
1995     }
1996 
1997     if((APP_K3B==theThemedApp && widget->inherits("K3b::ThemedHeader") && qobject_cast<QFrame*>(widget)) ||
1998         widget->inherits("KColorPatch"))
1999     {
2000         ((QFrame*)widget)->setLineWidth(0);
2001         ((QFrame*)widget)->setFrameShape(QFrame::NoFrame);
2002     }
2003 
2004     if(APP_KDEVELOP==theThemedApp && !opts.stdSidebarButtons && widget->inherits("Sublime::IdealButtonBarWidget") && widget->layout())
2005     {
2006         widget->layout()->setSpacing(0);
2007         widget->layout()->setMargin(0);
2008     }
2009 
2010     QWidget *window = widget->window();
2011 
2012     if ((opts.bgndOpacity != 100 && qtcIsWindow(window)) ||
2013         (opts.dlgOpacity != 100 && qtcIsDialog(window))) {
2014         widget->installEventFilter(this);
2015 
2016         if (widget->inherits("KFilePlacesView")) {
2017             widget->setAutoFillBackground(false);
2018             widget->setAttribute(Qt::WA_OpaquePaintEvent, false);
2019         }
2020     }
2021 
2022 #ifdef QTC_QT4_ENABLE_KDE
2023     // Make file selection button in QPrintDialog appear more KUrlRequester like.
2024     if (qobject_cast<QToolButton*>(widget) &&
2025         qtcCheckType<QGroupBox>(widget->parentWidget()) &&
2026         qtcCheckType<QPrintDialog>(getParent<3>(widget)) &&
2027         static_cast<QToolButton*>(widget)->text() == QLatin1String("...")) {
2028         static_cast<QToolButton*>(widget)->setIcon(KIcon("document-open"));
2029         static_cast<QToolButton*>(widget)->setAutoRaise(false);
2030     }
2031 #endif
2032 }
2033 
2034 static QFontMetrics styledFontMetrics(const QStyleOption *option, const QWidget *widget)
2035 {
2036     return (option ? option->fontMetrics :
2037             widget ? widget->fontMetrics() : qApp->fontMetrics());
2038 }
2039 
2040 static int fontHeight(const QStyleOption *option, const QWidget *widget)
2041 {
2042     return styledFontMetrics(option, widget).height();
2043 }
2044 
2045 // Taken from skulpture 0.2.3
2046 void Style::polishFormLayout(QFormLayout *layout)
2047 {
2048     int widgetSize=-1;
2049 
2050     if (layout->labelAlignment() & Qt::AlignVCenter)
2051         return;
2052 
2053     int addedHeight = -1;
2054     for (int row = 0; row < layout->rowCount(); ++row)
2055     {
2056         QLayoutItem *labelItem = layout->itemAt(row, QFormLayout::LabelRole);
2057         if (!labelItem)
2058             continue;
2059 
2060         QLayoutItem *fieldItem = layout->itemAt(row, QFormLayout::FieldRole);
2061         if (!fieldItem)
2062             continue;
2063 
2064         QWidget *label = labelItem->widget();
2065         if (!label)
2066             continue;
2067 
2068         int labelHeight;
2069         if (addedHeight < 0)
2070             addedHeight = 4 + 2 * widgetSize;
2071         if (qobject_cast<QLabel*>(label))
2072             labelHeight = label->sizeHint().height() + addedHeight;
2073         else if (qobject_cast<QCheckBox*>(label))
2074             labelHeight = label->sizeHint().height();
2075         else
2076             continue;
2077 
2078         int fieldHeight = fieldItem->sizeHint().height();
2079         /* for large fields, we don't center */
2080         if (fieldHeight <= 2 * fontHeight(0, label) + addedHeight)
2081         {
2082             if (fieldHeight > labelHeight)
2083                 labelHeight = fieldHeight;
2084         }
2085 //         else if (verticalTextShift(label->fontMetrics()) & 1)
2086 //                 labelHeight += 1;
2087         if (qobject_cast<QCheckBox*>(label))
2088             label->setMinimumHeight(labelHeight);
2089         else
2090         {
2091 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 2)
2092             label->setMinimumHeight((labelHeight * 4 + 6) / 7);
2093 #else
2094             // QFormLayout determines label size as height * 5 / 4, so revert that
2095             label->setMinimumHeight((labelHeight * 4 + 4) / 5);
2096 #endif
2097         }
2098     }
2099 }
2100 
2101 void Style::polishLayout(QLayout *layout)
2102 {
2103     if (QFormLayout *formLayout = qobject_cast<QFormLayout*>(layout))
2104         polishFormLayout(formLayout);
2105     // recurse into layouts
2106     for (int i = 0; i < layout->count(); ++i)
2107         if (QLayout *l = layout->itemAt(i)->layout())
2108             polishLayout(l);
2109 }
2110 
2111 // Taken from oxygen!
2112 void Style::polishScrollArea(QAbstractScrollArea *scrollArea, bool isKFilePlacesView) const
2113 {
2114     if(!scrollArea)
2115         return;
2116 
2117     // HACK: add exception for KPIM transactionItemView, which is an overlay widget and must have filled background. This is a temporary workaround
2118     // until a more robust solution is found.
2119     if (scrollArea->inherits("KPIM::TransactionItemView")) {
2120         // also need to make the scrollarea background plain (using autofill background) so that optional vertical scrollbar background is not
2121         // transparent either.
2122         // TODO: possibly add an event filter to use the "normal" window background instead of something flat.
2123         scrollArea->setAutoFillBackground(true);
2124         return;
2125     }
2126 
2127     // check frame style and background role
2128     if(QFrame::NoFrame!=scrollArea->frameShape() || QPalette::Window!=scrollArea->backgroundRole())
2129         return;
2130 
2131     // get viewport and check background role
2132     QWidget *viewport(scrollArea->viewport());
2133     if(!(viewport && QPalette::Window==viewport->backgroundRole()) && !isKFilePlacesView)
2134         return;
2135 
2136     // change viewport autoFill background.
2137     // do the same for children if the background role is QPalette::Window
2138     viewport->setAutoFillBackground(false);
2139     foreach (QWidget *child, viewport->findChildren<QWidget*>()) {
2140         if (child->parent() == viewport &&
2141             QPalette::Window == child->backgroundRole()) {
2142             child->setAutoFillBackground(false);
2143         }
2144     }
2145 }
2146 
2147 void Style::unpolish(QApplication *app)
2148 {
2149     if (opts.hideShortcutUnderline)
2150         app->removeEventFilter(m_shortcutHandler);
2151     BaseStyle::unpolish(app);
2152 }
2153 
2154 void Style::unpolish(QWidget *widget)
2155 {
2156     if (!widget)
2157         return;
2158     widget->removeEventFilter(this);
2159     m_windowManager->unregisterWidget(widget);
2160     m_shadowHelper->unregisterWidget(widget);
2161     m_blurHelper->unregisterWidget(widget);
2162 
2163     // Sometimes get background errors with QToolBox (e.g. in Bespin config),
2164     // and setting WA_StyledBackground seems to fix this,..
2165     if (qtcIsCustomBgnd(opts) || FRAME_SHADED == opts.groupBox ||
2166         FRAME_FADED == opts.groupBox) {
2167         switch (widget->windowType()) {
2168         case Qt::Window:
2169         case Qt::Sheet:
2170         case Qt::Dialog:
2171             widget->setAttribute(Qt::WA_StyledBackground, false);
2172             break;
2173         case Qt::Popup:
2174             // we currently don't want that kind of gradient on menus etc
2175         case Qt::Drawer:
2176         case Qt::Tool:
2177             // this we exclude as it is used for dragging of icons etc
2178         default:
2179             break;
2180         }
2181         if (qobject_cast<QSlider*>(widget)) {
2182             widget->setBackgroundRole(QPalette::Window);
2183         }
2184     }
2185 
2186     if (// m_isPreview &&
2187         qobject_cast<QMdiSubWindow*>(widget))
2188         widget->setAttribute(Qt::WA_StyledBackground, false);
2189 
2190     if (opts.menubarHiding && qobject_cast<QMainWindow*>(widget) &&
2191         static_cast<QMainWindow*>(widget)->menuWidget()) {
2192         if (m_saveMenuBarStatus) {
2193             static_cast<QMainWindow*>(widget)->menuWidget()
2194                 ->removeEventFilter(this);
2195         }
2196     }
2197 
2198     if (opts.statusbarHiding && qobject_cast<QMainWindow*>(widget)) {
2199         if (m_saveStatusBarStatus) {
2200             foreach (QStatusBar *statusBar, getStatusBars(widget)) {
2201                 statusBar->removeEventFilter(this);
2202             }
2203         }
2204     }
2205 
2206     if(qobject_cast<QPushButton*>(widget) ||
2207        qobject_cast<QComboBox*>(widget) ||
2208        qobject_cast<QAbstractSpinBox*>(widget) ||
2209        qobject_cast<QCheckBox*>(widget) ||
2210        qobject_cast<QGroupBox*>(widget) ||
2211        qobject_cast<QRadioButton*>(widget) ||
2212        qobject_cast<QSplitterHandle*>(widget) ||
2213        qobject_cast<QSlider*>(widget) ||
2214        qobject_cast<QHeaderView*>(widget) ||
2215        qobject_cast<QTabBar*>(widget) ||
2216        qobject_cast<QAbstractScrollArea*>(widget) ||
2217        qobject_cast<QTextEdit*>(widget) ||
2218        qobject_cast<QLineEdit*>(widget) ||
2219        qobject_cast<QDial*>(widget) ||
2220        // qobject_cast<QDockWidget*>(widget) ||
2221        widget->inherits("QWorkspaceTitleBar") ||
2222        widget->inherits("QDockSeparator") ||
2223        widget->inherits("QDockWidgetSeparator") ||
2224        widget->inherits("Q3DockWindowResizeHandle"))
2225         widget->setAttribute(Qt::WA_Hover, false);
2226     if (qobject_cast<QScrollBar*>(widget)) {
2227         widget->setAttribute(Qt::WA_Hover, false);
2228         if (opts.round != ROUND_NONE && !opts.flatSbarButtons) {
2229             widget->setAttribute(Qt::WA_OpaquePaintEvent, false);
2230         }
2231     } else if (qobject_cast<QProgressBar*>(widget)) {
2232         if(opts.boldProgress)
2233             unSetBold(widget);
2234         m_progressBars.remove((QProgressBar*)widget);
2235     } else if (widget->inherits("Q3Header")) {
2236         widget->setMouseTracking(false);
2237     } else if (qobject_cast<QMenuBar*>(widget)) {
2238         if (opts.xbar) {
2239             Bespin::MacMenu::release((QMenuBar*)widget);
2240         }
2241         widget->setAttribute(Qt::WA_Hover, false);
2242 
2243         if(qtcIsCustomBgnd(opts))
2244             widget->setBackgroundRole(QPalette::Background);
2245 
2246         if (SHADE_WINDOW_BORDER==opts.shadeMenubars || opts.customMenuTextColor || SHADE_BLEND_SELECTED==opts.shadeMenubars ||
2247            SHADE_SELECTED==opts.shadeMenubars || (SHADE_CUSTOM==opts.shadeMenubars &&TOO_DARK(m_menubarCols[ORIGINAL_SHADE])))
2248             widget->setPalette(QApplication::palette());
2249     } else if(/*!opts.gtkScrollViews && */qobject_cast<QAbstractScrollArea*>(widget))
2250     {
2251         if(APP_KONTACT==theThemedApp && widget->parentWidget())
2252         {
2253             QWidget *frame=scrollViewFrame(widget->parentWidget());
2254 
2255             if (frame) {
2256                 if (m_sViewContainers.contains(frame)) {
2257                     m_sViewContainers[frame].remove(widget);
2258                     if (m_sViewContainers[frame].count() == 0) {
2259                         frame->removeEventFilter(this);
2260                         m_sViewContainers.remove(frame);
2261                         disconnect(frame, SIGNAL(destroyed(QObject*)),
2262                                    this, SLOT(widgetDestroyed(QObject*)));
2263                     }
2264                 }
2265             }
2266         }
2267     } else if(qobject_cast<QDockWidget*>(widget) &&
2268               ((QDockWidget*)widget)->titleBarWidget() &&
2269               qobject_cast<QtCurveDockWidgetTitleBar*>(((QDockWidget*)widget)
2270                                                        ->titleBarWidget()) &&
2271               qtcCheckType<QSplitter>(widget->parentWidget()) &&
2272               qtcCheckType(getParent<2>(widget), "KFileWidget")) {
2273         delete ((QDockWidget*)widget)->titleBarWidget();
2274         ((QDockWidget*)widget)->setTitleBarWidget(0L);
2275     }
2276     else if(opts.boldProgress && "CE_CapacityBar"==widget->objectName())
2277         unSetBold(widget);
2278 
2279     if (widget->inherits("QTipLabel") && !qtcIsFlat(opts.tooltipAppearance)) {
2280         widget->setAttribute(Qt::WA_NoSystemBackground, false);
2281         widget->clearMask();
2282     }
2283 
2284     if (!widget->isWindow())
2285         if (QFrame *frame = qobject_cast<QFrame*>(widget)) {
2286             if (qtcCheckKDEType(widget->parent(), KTitleWidget)) {
2287                 if(qtcIsCustomBgnd(opts))
2288                     frame->setAutoFillBackground(true);
2289                 else
2290                     frame->setBackgroundRole(QPalette::Base);
2291 
2292                 QLayout *layout(frame->layout());
2293 
2294                 if(layout)
2295                     layout->setMargin(6);
2296             }
2297 
2298             QWidget *p=0L;
2299 
2300             if (opts.gtkComboMenus && widget->parentWidget() &&
2301                 (p = getParent<2>(widget)) && qobject_cast<QComboBox*>(p) &&
2302                 !((QComboBox*)(p))->isEditable()) {
2303                 widget->setPalette(QApplication::palette());
2304             }
2305         }
2306 
2307     if (qobject_cast<QMenu*>(widget)) {
2308         widget->setAttribute(Qt::WA_NoSystemBackground, false);
2309         widget->clearMask();
2310         if (opts.lighterPopupMenuBgnd || opts.shadePopupMenu) {
2311             widget->setPalette(QApplication::palette());
2312         }
2313     }
2314 
2315     if ((!qtcIsFlatBgnd(opts.menuBgndAppearance) ||
2316          100 != opts.menuBgndOpacity || !POPUP_MENUS_SQUARE(opts)) &&
2317         widget->inherits("QComboBoxPrivateContainer")) {
2318         widget->setAttribute(Qt::WA_NoSystemBackground, false);
2319         widget->clearMask();
2320     }
2321 
2322     if (qobject_cast<QMenuBar*>(widget) ||
2323         widget->inherits("Q3ToolBar") ||
2324         qobject_cast<QToolBar*>(widget) ||
2325         (widget && qobject_cast<QToolBar*>(widget->parent())))
2326         widget->setBackgroundRole(QPalette::Button);
2327 }
2328 
2329 //
2330 // QtCurve's menu's have a 2 pixel border all around - but want the top, and left edges to
2331 // active the nearest menu item. Therefore, when we get a mouse event in that region then
2332 // adjsut its position...
2333 static bool updateMenuBarEvent(QMouseEvent *event, QMenuBar *menu)
2334 {
2335     struct HackEvent : public QMouseEvent {
2336         bool
2337         adjust()
2338         {
2339             bool res = false;
2340             if (p.x() < 2) {
2341                 p.rx() += 2;
2342                 g.rx() += 2;
2343                 res = true;
2344             }
2345             if (p.y() < 2) {
2346                 p.ry() += 2;
2347                 g.ry() += 2;
2348                 res = true;
2349             }
2350             return res;
2351         }
2352     };
2353 
2354     if (((HackEvent*)event)->adjust()) {
2355         static_cast<QObject*>(menu)->event(event);
2356         return true;
2357     }
2358     return false;
2359 }
2360 
2361 bool Style::eventFilter(QObject *object, QEvent *event)
2362 {
2363     if (qobject_cast<QMenuBar*>(object) && dynamic_cast<QMouseEvent*>(event)) {
2364         if (updateMenuBarEvent((QMouseEvent*)event, (QMenuBar*)object)) {
2365             return true;
2366         }
2367     }
2368 
2369     if (event->type() == QEvent::Show &&
2370         qobject_cast<QAbstractScrollArea*>(object) &&
2371         object->inherits("KFilePlacesView")) {
2372         QWidget *view = ((QAbstractScrollArea*)object)->viewport();
2373         QPalette palette = view->palette();
2374         QColor color = ((QWidget*)object)->palette().background().color();
2375 
2376         if (qtcIsCustomBgnd(opts))
2377             color.setAlphaF(0.0);
2378 
2379         palette.setColor(view->backgroundRole(), color);
2380         view->setPalette(palette);
2381         object->removeEventFilter(this);
2382     }
2383 
2384     bool isSViewCont = (theThemedApp == APP_KONTACT &&
2385                         m_sViewContainers.contains((QWidget*)object));
2386     if ((!opts.gtkScrollViews &&
2387          qobject_cast<QAbstractScrollArea*>(object)) || isSViewCont) {
2388         QPoint pos;
2389         switch (event->type()) {
2390         case QEvent::MouseMove:
2391         case QEvent::MouseButtonPress:
2392         case QEvent::MouseButtonRelease:
2393             pos = ((QMouseEvent*)event)->pos();
2394             break;
2395         case QEvent::Wheel:
2396             pos = ((QWheelEvent*)event)->pos();
2397         default:
2398             break;
2399         }
2400 
2401         if (!pos.isNull()) {
2402             QAbstractScrollArea *area=0L;
2403             QPoint mapped(pos);
2404 
2405             if (isSViewCont) {
2406                 QSet<QWidget*>::ConstIterator it(m_sViewContainers[(QWidget*)object].begin()),
2407                                                end(m_sViewContainers[(QWidget*)object].end());
2408 
2409                 for(; it!=end && !area; ++it)
2410                     if((*it)->isVisible())
2411                     {
2412                         mapped=(*it)->mapFrom((QWidget*)object, pos);
2413                         if((*it)->rect().adjusted(0, 0, 4, 4).contains(mapped))
2414                             area=(QAbstractScrollArea*)(*it);
2415                     }
2416             } else {
2417                 area = (QAbstractScrollArea*)object;
2418             }
2419 
2420             if (area) {
2421                 QScrollBar *sbars[2]={area->verticalScrollBar(), area->horizontalScrollBar() };
2422 
2423                 for(int i=0; i<2; ++i)
2424                     if(sbars[i])
2425                     {
2426                         QRect r(i ? 0 : area->rect().right()-3,   i ? area->rect().bottom()-3 : 0,
2427                                 sbars[i]->rect().width(), sbars[i]->rect().height());
2428 
2429                         if(r.contains(pos) ||
2430                             (sbars[i]==m_sViewSBar &&
2431                              (QEvent::MouseMove==event->type() ||
2432                               QEvent::MouseButtonRelease==event->type())))
2433                         {
2434                             if(QEvent::Wheel!=event->type())
2435                             {
2436                                 struct HackEvent : public QMouseEvent
2437                                 {
2438                                     void set(const QPoint &mapped, bool vert)
2439                                     {
2440                                         p=QPoint(vert ? 0 : mapped.x(), vert ? mapped.y() : 0);
2441                                         g=QPoint(g.x()+(vert ? 0 : -3), g.y()+(vert ? -3 : 0));
2442                                     }
2443                                 };
2444 
2445                                 ((HackEvent*)event)->set(mapped, 0==i);
2446                             }
2447                             sbars[i]->event(event);
2448                             if(QEvent::MouseButtonPress==event->type())
2449                                 m_sViewSBar=sbars[i];
2450                             else if(QEvent::MouseButtonRelease==event->type())
2451                                 m_sViewSBar=0L;
2452                             return true;
2453                         }
2454                     }
2455             }
2456         }
2457     }
2458 
2459     switch((int)(event->type()))
2460     {
2461         case QEvent::Timer:
2462         case QEvent::Move:
2463             return false; // just for performance - they can occur really often
2464         case QEvent::Resize:
2465             if (!POPUP_MENUS_SQUARE(opts) &&
2466                 object->inherits("QComboBoxPrivateContainer")) {
2467                 QWidget *widget = static_cast<QWidget*>(object);
2468                 if (Utils::hasAlphaChannel(widget)) {
2469                     widget->clearMask();
2470                 } else {
2471                     widget->setMask(windowMask(widget->rect(),
2472                                                opts.round > ROUND_SLIGHT));
2473                 }
2474                 return false;
2475             } else if ((BLEND_TITLEBAR ||
2476                         opts.windowBorder &
2477                         WINDOW_BORDER_USE_MENUBAR_COLOR_FOR_TITLEBAR ||
2478                         opts.menubarHiding & HIDE_KWIN) &&
2479                        qobject_cast<QMenuBar*>(object)) {
2480                 QResizeEvent *re = static_cast<QResizeEvent*>(event);
2481 
2482                 if (re->size().height() != re->oldSize().height())
2483                     emitMenuSize((QMenuBar*)object, PREVIEW_MDI==m_isPreview || !((QMenuBar*)object)->isVisible()
2484                                     ? 0 : re->size().height());
2485             }
2486             break;
2487         case QEvent::ShortcutOverride:
2488             if((opts.menubarHiding || opts.statusbarHiding) && qobject_cast<QMainWindow*>(object))
2489             {
2490                 QMainWindow *window=static_cast<QMainWindow*>(object);
2491 
2492                 if(window->isVisible())
2493                 {
2494                     if(opts.menubarHiding&HIDE_KEYBOARD && window->menuWidget())
2495                     {
2496                         QKeyEvent *k=static_cast<QKeyEvent*>(event);
2497 
2498                         if(k->modifiers()&Qt::ControlModifier && k->modifiers()&Qt::AltModifier && Qt::Key_M==k->key())
2499                             toggleMenuBar(window);
2500                     }
2501                     if(opts.statusbarHiding&HIDE_KEYBOARD)
2502                     {
2503                         QKeyEvent *k=static_cast<QKeyEvent*>(event);
2504 
2505                         if(k->modifiers()&Qt::ControlModifier && k->modifiers()&Qt::AltModifier && Qt::Key_S==k->key())
2506                             toggleStatusBar(window);
2507                     }
2508                 }
2509             }
2510             break;
2511         case QEvent::ShowToParent:
2512             if(qobject_cast<QMenuBar*>(object)) {
2513                 if(opts.menubarHiding && m_saveMenuBarStatus && qtcMenuBarHidden(appName))
2514                     static_cast<QMenuBar*>(object)->setHidden(true);
2515 #ifdef Q_OS_MAC
2516                 if (opts.nonnativeMenubarApps.contains(appName)) {
2517                     QMenuBar *mnb = static_cast<QMenuBar*>(object);
2518                     if (mnb->isNativeMenuBar()) {
2519                         mnb->setNativeMenuBar(false);
2520                         mnb->setHidden(false);
2521                         mnb->setVisible(true);
2522                     }
2523                 } else {
2524                     static_cast<QMenuBar*>(object)->setNativeMenuBar(true);
2525                 }
2526 #endif
2527             }
2528             if(opts.statusbarHiding && m_saveStatusBarStatus && qobject_cast<QStatusBar*>(object) &&
2529                qtcStatusBarHidden(appName))
2530                 static_cast<QStatusBar*>(object)->setHidden(true);
2531             break;
2532         case QEvent::PaletteChange: {
2533             QWidget *widget = qtcToWidget(object);
2534 
2535             if (widget && widget->isWindow() &&
2536                 (qtcIsDialog(widget) || qtcIsWindow(widget))) {
2537                 setBgndProp(widget, opts.bgndAppearance,
2538                             IMG_NONE != opts.bgndImage.type);
2539             }
2540             break;
2541         }
2542         case QEvent::Paint: {
2543             if ((!qtcIsFlatBgnd(opts.menuBgndAppearance) ||
2544                  opts.menuBgndImage.type != IMG_NONE ||
2545                  opts.menuBgndOpacity != 100 ||
2546                  !POPUP_MENUS_SQUARE(opts)) &&
2547                 (qobject_cast<QMenu*>(object) ||
2548                  (object->inherits("QComboBoxPrivateContainer")))) {
2549                 QWidget *widget = qtcToWidget(object);
2550                 QPainter p(widget);
2551                 QRect r(widget->rect());
2552                 double radius = opts.round >= ROUND_FULL ? 5.0 : 2.5;
2553                 QStyleOption opt;
2554                 opt.init(widget);
2555                 const QColor *use = popupMenuCols(&opt);
2556 
2557                 // Qt4 does not clear the background if the attribute
2558                 // Qt::WA_NoSystemBackground is not set on the widget.
2559                 p.setCompositionMode(QPainter::CompositionMode_Source);
2560                 p.setClipRegion(static_cast<QPaintEvent*>(event)->region());
2561                 if (!opts.popupBorder) {
2562                     p.setRenderHint(QPainter::Antialiasing, true);
2563                     p.setPen(use[ORIGINAL_SHADE]);
2564                     p.drawPath(buildPath(r, WIDGET_OTHER, ROUNDED_ALL, radius));
2565                     p.setRenderHint(QPainter::Antialiasing, false);
2566                 }
2567                 if (!POPUP_MENUS_SQUARE(opts)) // && !isCombo)
2568                     p.setClipRegion(windowMask(r, opts.round > ROUND_SLIGHT),
2569                                     Qt::IntersectClip);
2570 
2571                 // In case the gradient uses alpha, we need to fill with
2572                 // the background colour - this makes it consistent with Gtk.
2573                 if (opts.menuBgndOpacity == 100) {
2574                     p.fillRect(r, opt.palette.brush(QPalette::Background));
2575                 }
2576                 drawBackground(&p, widget, BGND_MENU);
2577                 if (opts.popupBorder) {
2578                     EGradientBorder border =
2579                         qtcGetGradient(opts.menuBgndAppearance, &opts)->border;
2580 
2581                     p.setClipping(false);
2582                     p.setPen(use[QTC_STD_BORDER]);
2583                     // For now dont round combos - getting weird effects with
2584                     // shadow/clipping in Gtk2 style :-(
2585                     if (POPUP_MENUS_SQUARE(opts)) {
2586                         drawRect(&p, r);
2587                     } else {
2588                         p.setRenderHint(QPainter::Antialiasing, true);
2589                         p.drawPath(buildPath(r, WIDGET_OTHER,
2590                                              ROUNDED_ALL, radius));
2591                     }
2592 
2593                     if (qtcUseBorder(border) &&
2594                         APPEARANCE_FLAT != opts.menuBgndAppearance) {
2595                         QRect ri(r.adjusted(1, 1, -1, -1));
2596 
2597                         p.setPen(use[0]);
2598                         if (border == GB_LIGHT) {
2599                             if(POPUP_MENUS_SQUARE(opts)) // || isCombo)
2600                                 drawRect(&p, ri);
2601                             else
2602                                 p.drawPath(buildPath(ri, WIDGET_OTHER, ROUNDED_ALL, radius-1.0));
2603                         } else if (POPUP_MENUS_SQUARE(opts)) {
2604                             if (GB_3D != border) {
2605                                 p.drawLine(ri.x(), ri.y(),
2606                                            ri.x() + ri.width() - 1,  ri.y());
2607                                 p.drawLine(ri.x(), ri.y(), ri.x(),
2608                                            ri.y() + ri.height() - 1);
2609                             }
2610                             p.setPen(use[FRAME_DARK_SHADOW]);
2611                             p.drawLine(ri.x(), ri.y()+ri.height()-1, ri.x()+ri.width()-1,  ri.y()+ri.height()-1);
2612                             p.drawLine(ri.x()+ri.width()-1, ri.y(), ri.x()+ri.width()-1,  ri.y()+ri.height()-1);
2613                         }
2614                         else
2615                         {
2616                             QPainterPath tl,
2617                                          br;
2618 
2619                             buildSplitPath(ri, ROUNDED_ALL, radius-1.0, tl, br);
2620                             if(GB_3D!=border)
2621                                 p.drawPath(tl);
2622                             p.setPen(use[FRAME_DARK_SHADOW]);
2623                             p.drawPath(br);
2624                         }
2625                     }
2626                 }
2627             }
2628             else if(m_clickedLabel==object && qobject_cast<QLabel*>(object) && ((QLabel*)object)->buddy() && ((QLabel*)object)->buddy()->isEnabled())
2629             {
2630                 // paint focus rect
2631                 QLabel                *lbl = (QLabel*)object;
2632                 QPainter              painter(lbl);
2633                 QStyleOptionFocusRect opts;
2634 
2635                 opts.palette = lbl->palette();
2636                 opts.rect    = QRect(0, 0, lbl->width(), lbl->height());
2637                 drawPrimitive(PE_FrameFocusRect, &opts, &painter, lbl);
2638             }
2639             else
2640             {
2641                 QFrame *frame = qobject_cast<QFrame*>(object);
2642 
2643                 if (frame)
2644                 {
2645                     if(QFrame::HLine==frame->frameShape() || QFrame::VLine==frame->frameShape())
2646                     {
2647                         QPainter painter(frame);
2648                         QRect    r(QFrame::HLine==frame->frameShape()
2649                                     ? QRect(frame->rect().x(), frame->rect().y()+ (frame->rect().height()/2), frame->rect().width(), 1)
2650                                     : QRect(frame->rect().x()+(frame->rect().width()/2),  frame->rect().y(), 1, frame->rect().height()));
2651 
2652                         drawFadedLine(&painter, r, backgroundColors(frame->palette().window().color())[QTC_STD_BORDER], true, true,
2653                                       QFrame::HLine==frame->frameShape());
2654                         return true;
2655                     }
2656                     else
2657                         return false;
2658                 }
2659             }
2660             break;
2661         }
2662         case QEvent::MouseButtonPress:
2663             if(dynamic_cast<QMouseEvent*>(event) && qobject_cast<QLabel*>(object) && ((QLabel*)object)->buddy())
2664             {
2665                 QLabel      *lbl = (QLabel*)object;
2666                 QMouseEvent *mev = (QMouseEvent*)event;
2667 
2668                 if (lbl->rect().contains(mev->pos()))
2669                 {
2670                     m_clickedLabel=lbl;
2671                     lbl->repaint();
2672                 }
2673             }
2674             break;
2675         case QEvent::MouseButtonRelease:
2676             if (dynamic_cast<QMouseEvent*>(event) && qobject_cast<QLabel*>(object) && ((QLabel*)object)->buddy())
2677             {
2678                 QLabel      *lbl = (QLabel*)object;
2679                 QMouseEvent *mev = (QMouseEvent*)event;
2680 
2681                 if(m_clickedLabel)
2682                 {
2683                     m_clickedLabel=0;
2684                     lbl->update();
2685                 }
2686 
2687                 // set focus to the buddy...
2688                 if (lbl->rect().contains(mev->pos()))
2689                     ((QLabel*)object)->buddy()->setFocus(Qt::ShortcutFocusReason);
2690             }
2691             break;
2692         case QEvent::StyleChange:
2693         case QEvent::Show:
2694         {
2695             QProgressBar *bar = qobject_cast<QProgressBar*>(object);
2696 
2697             if(bar)
2698             {
2699                 m_progressBars.insert(bar);
2700                 if (!m_progressBarAnimateTimer) {
2701                     if (opts.animatedProgress || (0 == bar->minimum() && 0 == bar->maximum())) {
2702                         // we know we'll need a timer, start it at once
2703                         if (m_timer.isNull()) {
2704                             m_timer.start();
2705                         }
2706                         m_progressBarAnimateFps = constProgressBarFps;
2707                         m_progressBarAnimateTimer = startTimer(1000/m_progressBarAnimateFps);
2708                     }
2709                 }
2710             } else if(!POPUP_MENUS_SQUARE(opts) &&
2711                       object->inherits("QComboBoxPrivateContainer")) {
2712                 QWidget *widget = static_cast<QWidget*>(object);
2713                 if (Utils::hasAlphaChannel(widget)) {
2714                     widget->clearMask();
2715                 } else {
2716                     widget->setMask(windowMask(widget->rect(),
2717                                                opts.round > ROUND_SLIGHT));
2718                 }
2719                 return false;
2720             } else if ((BLEND_TITLEBAR || opts.windowBorder&WINDOW_BORDER_USE_MENUBAR_COLOR_FOR_TITLEBAR || opts.menubarHiding&HIDE_KWIN) &&
2721                     qobject_cast<QMenuBar*>(object))
2722             {
2723                 QMenuBar *mb=(QMenuBar*)object;
2724                 emitMenuSize((QMenuBar*)mb, PREVIEW_MDI==m_isPreview || !((QMenuBar*)mb)->isVisible() ? 0 : mb->size().height(), true);
2725             } else if (QEvent::Show == event->type()) {
2726                 QWidget *widget = qtcToWidget(object);
2727 
2728                 if (widget && widget->isWindow() &&
2729                     (qtcIsWindow(widget) || qtcIsDialog(widget))) {
2730                     setBgndProp(widget, opts.bgndAppearance,
2731                                 IMG_NONE != opts.bgndImage.type);
2732 
2733                     int opacity = (qtcIsDialog(widget) ? opts.dlgOpacity :
2734                                    opts.bgndOpacity);
2735                     setOpacityProp(widget, (unsigned short)opacity);
2736                 }
2737             }
2738             break;
2739         }
2740         case QEvent::Close:
2741         case QEvent::Destroy:
2742         case QEvent::Hide: {
2743             if((BLEND_TITLEBAR || opts.windowBorder&WINDOW_BORDER_USE_MENUBAR_COLOR_FOR_TITLEBAR || opts.menubarHiding&HIDE_KWIN) &&
2744                 qobject_cast<QMenuBar*>(object))
2745             {
2746                 QMenuBar *mb=(QMenuBar*)object;
2747                 emitMenuSize((QMenuBar*)mb, 0);
2748             }
2749             if(m_hoverWidget && object==m_hoverWidget)
2750             {
2751                 m_pos.setX(-1);
2752                 m_pos.setY(-1);
2753                 m_hoverWidget=0L;
2754             }
2755 
2756             // The Destroy event is sent from ~QWidget, which happens after ~QProgressBar - therefore, we can't cast to a QProgressBar.
2757             // So we have to check on object.
2758             if(object && !m_progressBars.isEmpty())
2759             {
2760                 m_progressBars.remove(reinterpret_cast<QProgressBar*>(object));
2761                 if (m_progressBars.isEmpty() && m_progressBarAnimateTimer)
2762                 {
2763                     killTimer(m_progressBarAnimateTimer);
2764                     m_progressBarAnimateTimer = 0;
2765                 }
2766             }
2767             break;
2768         }
2769         case QEvent::Enter:
2770             if(object->isWidgetType() && object->inherits("Q3Header"))
2771             {
2772                 m_hoverWidget=(QWidget*)object;
2773 
2774                 if(m_hoverWidget && !m_hoverWidget->isEnabled())
2775                     m_hoverWidget=0L;
2776             }
2777             break;
2778         case QEvent::Leave:
2779             if(m_hoverWidget && object==m_hoverWidget)
2780             {
2781                 m_pos.setX(-1);
2782                 m_pos.setY(-1);
2783                 m_hoverWidget=0L;
2784                 ((QWidget*)object)->repaint();
2785             }
2786             break;
2787         case QEvent::MouseMove:  // Only occurs for widgets with mouse tracking enabled
2788         {
2789             QMouseEvent *me = dynamic_cast<QMouseEvent*>(event);
2790 
2791             if(me && m_hoverWidget && object->isWidgetType() && object->inherits("Q3Header"))
2792             {
2793                 if(!me->pos().isNull() && me->pos()!=m_pos)
2794                     m_hoverWidget->repaint();
2795                 m_pos=me->pos();
2796             }
2797             break;
2798         }
2799         case QEvent::FocusIn:
2800         case QEvent::FocusOut:
2801             if(opts.highlightScrollViews && object->isWidgetType() && object->inherits("Q3ScrollView"))
2802             {
2803                 ((QWidget*)object)->update();
2804                 return false;
2805             }
2806             break;
2807         case QEvent::WindowActivate:
2808             if(opts.shadeMenubarOnlyWhenActive && SHADE_NONE!=opts.shadeMenubars && qobject_cast<QMenuBar*>(object))
2809             {
2810                 m_active=true;
2811                 ((QWidget*)object)->repaint();
2812                 return false;
2813             }
2814             break;
2815         case QEvent::WindowDeactivate:
2816             if(opts.shadeMenubarOnlyWhenActive && SHADE_NONE!=opts.shadeMenubars && qobject_cast<QMenuBar*>(object))
2817             {
2818                 m_active=false;
2819                 ((QWidget*)object)->repaint();
2820                 return false;
2821             }
2822             break;
2823         default:
2824             break;
2825     }
2826 
2827     return BaseStyle::eventFilter(object, event);
2828 }
2829 
2830 void Style::timerEvent(QTimerEvent *event)
2831 {
2832     if (event->timerId() == m_progressBarAnimateTimer) {
2833         bool hasAnimation = false;
2834         m_animateStep = m_timer.elapsed() / (1000 / constProgressBarFps);
2835         foreach (QProgressBar *bar, const_(m_progressBars)) {
2836             if ((opts.animatedProgress && 0 == m_animateStep % 2 &&
2837                  bar->value() != bar->minimum() &&
2838                  bar->value() != bar->maximum()) ||
2839                 (0 == bar->minimum() && 0 == bar->maximum())) {
2840                 bar->update();
2841                 hasAnimation = true;
2842             }
2843         }
2844         if (Q_UNLIKELY(!hasAnimation && m_progressBarAnimateFps == constProgressBarFps)) {
2845             // go back to "idling frequency" mode.
2846             killTimer(m_progressBarAnimateTimer);
2847             m_progressBarAnimateTimer = 0;
2848         }
2849     }
2850 
2851     event->ignore();
2852 }
2853 
2854 int Style::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
2855 {
2856     prePolish(widget);
2857     switch((unsigned)metric)
2858     {
2859         case PM_ToolTipLabelFrameWidth:
2860             return !(opts.round != ROUND_NONE) || opts.square&SQUARE_TOOLTIPS ? BaseStyle::pixelMetric(metric, option, widget) : 3;
2861         case PM_MdiSubWindowFrameWidth:
2862             return 3;
2863         case PM_DockWidgetTitleMargin:
2864             return !(opts.dwtSettings&DWT_TEXT_ALIGN_AS_PER_TITLEBAR) || ALIGN_LEFT==opts.titlebarAlignment ? 4 : 0;
2865         case PM_DockWidgetTitleBarButtonMargin:
2866             return 4;
2867         case PM_DockWidgetFrameWidth:
2868             return 2;
2869         case PM_ToolBarExtensionExtent:
2870             return 15;
2871 #ifndef QTC_QT4_ENABLE_KDE
2872         case PM_SmallIconSize:
2873             return 16;
2874         case PM_ToolBarIconSize:
2875             return 22;
2876         case PM_IconViewIconSize:
2877         case PM_LargeIconSize:
2878             return 32;
2879 #else
2880         case PM_TabCloseIndicatorWidth:
2881         case PM_TabCloseIndicatorHeight:
2882         case PM_SmallIconSize:
2883         case PM_ButtonIconSize:
2884             return KIconLoader::global()->currentSize(KIconLoader::Small);
2885         case PM_ToolBarIconSize:
2886             return KIconLoader::global()->currentSize(KIconLoader::Toolbar);
2887         case PM_IconViewIconSize:
2888         case PM_LargeIconSize:
2889             return KIconLoader::global()->currentSize(KIconLoader::Dialog);
2890         case PM_MessageBoxIconSize:
2891             // TODO return KIconLoader::global()->currentSize(KIconLoader::MessageBox);
2892             return KIconLoader::SizeHuge;
2893 #endif
2894         case PM_SubMenuOverlap:
2895             return -2;
2896         case PM_ScrollView_ScrollBarSpacing:
2897             return opts.etchEntry ? 2 : 3;
2898         case PM_MenuPanelWidth:
2899             return opts.popupBorder ? pixelMetric(PM_DefaultFrameWidth, option, widget) : 0;
2900         case PM_SizeGripSize:
2901             return SIZE_GRIP_SIZE;
2902         case PM_TabBarScrollButtonWidth:
2903             return 18;
2904         case PM_HeaderMargin:
2905             return 3;
2906         case PM_DefaultChildMargin:
2907             return isOOWidget(widget)
2908                     ? /*opts.round>=ROUND_FULL && !(opts.square&SQUARE_SCROLLVIEW)
2909                         ?*/ 2
2910                         /*: 1*/
2911                     : 6;
2912         case PM_DefaultTopLevelMargin:
2913             return 9;
2914         case PM_LayoutHorizontalSpacing:
2915         case PM_LayoutVerticalSpacing:
2916             return -1; // use layoutSpacingImplementation
2917         case PM_DefaultLayoutSpacing:
2918             return 6;
2919         case PM_LayoutLeftMargin:
2920         case PM_LayoutTopMargin:
2921         case PM_LayoutRightMargin:
2922         case PM_LayoutBottomMargin:
2923             return pixelMetric((option && (option->state&QStyle::State_Window)) || (widget && widget->isWindow())
2924                                 ? PM_DefaultTopLevelMargin
2925                                 : PM_DefaultChildMargin, option, widget);
2926         case PM_MenuBarItemSpacing:
2927             return 0;
2928         case PM_ToolBarItemMargin:
2929             // with two locked toolbars together the last/first items are too close when there is no frame,
2930             // so add a margin instead.
2931             return TB_NONE==opts.toolbarBorders ? 1 : 0;
2932         case PM_ToolBarItemSpacing:
2933             return TBTN_JOINED==opts.tbarBtns ? 0 : 1;
2934         case PM_ToolBarFrameWidth:
2935             return TB_NONE==opts.toolbarBorders ? 0 : 1;
2936         case PM_FocusFrameVMargin:
2937         case PM_FocusFrameHMargin:
2938             return 2;
2939         case PM_MenuBarVMargin:
2940         case PM_MenuBarHMargin:
2941             // Bangarang (media player) has a 4 pixel high menubar at the top - when it doesn't actually have a menubar!
2942             // Seems to be because of the return 2 below (which was previously always returned unless XBar support and
2943             // size was 0). So, if we are askes for these metrics for a widet whose size<6, then return 0.
2944             return widget && widget->size().height() < 6 ? 0 : 2;
2945         case PM_MenuHMargin:
2946         case PM_MenuVMargin:
2947             return 0;
2948         case PM_MenuButtonIndicator:
2949             return (opts.buttonEffect != EFFECT_NONE ? 10 : 9)+
2950                     (!widget || qobject_cast<const QToolButton*>(widget) ? 6 : 0);
2951         case PM_ButtonMargin:
2952             return (opts.buttonEffect != EFFECT_NONE ?
2953                     (opts.thin & THIN_BUTTONS) ? 4 : 6 :
2954                     (opts.thin & THIN_BUTTONS) ? 2 : 4) + MAX_ROUND_BTN_PAD;
2955         case PM_TabBarTabShiftVertical:
2956             return 2;
2957         case PM_TabBarTabShiftHorizontal:
2958             return 0;
2959         case PM_ButtonShiftHorizontal:
2960             // return Qt::RightToLeft==QApplication::layoutDirection() ? -1 : 1;
2961         case PM_ButtonShiftVertical:
2962             return APP_KDEVELOP==theThemedApp && !opts.stdSidebarButtons && widget && isMultiTabBarTab(getButton(widget, 0L)) ? 0 : 1;
2963         case PM_ButtonDefaultIndicator:
2964             return 0;
2965         case PM_DefaultFrameWidth:
2966             if ((/*!opts.popupBorder || */opts.gtkComboMenus) && widget && widget->inherits("QComboBoxPrivateContainer"))
2967                 return opts.gtkComboMenus ? (opts.borderMenuitems || !POPUP_MENUS_SQUARE(opts) ? 2 : 1) : 0;
2968 
2969             if ((!opts.gtkScrollViews || (opts.square&SQUARE_SCROLLVIEW)) && isKateView(widget))
2970                 return (opts.square&SQUARE_SCROLLVIEW) ? 1 : 0;
2971 
2972             if ((opts.square&SQUARE_SCROLLVIEW) && widget && !opts.etchEntry &&
2973                 (qobject_cast<const QAbstractScrollArea*>(widget) ||
2974                  isKontactPreviewPane(widget) ||
2975                  widget->inherits("Q3ScrollView")))
2976                 return (opts.gtkScrollViews || opts.thinSbarGroove ||
2977                         !opts.borderSbarGroove) &&
2978                     (!opts.highlightScrollViews) ? 1 : 2;
2979 
2980             if (!qtcDrawMenuBorder(opts) && !opts.borderMenuitems &&
2981                 POPUP_MENUS_SQUARE(opts) &&
2982                 qobject_cast<const QMenu*>(widget)) {
2983                 return 1;
2984             }
2985 
2986             if (opts.buttonEffect != EFFECT_NONE && opts.etchEntry &&
2987                 (!widget || // !isFormWidget(widget) &&
2988                 qobject_cast<const QLineEdit*>(widget) || qobject_cast<const QAbstractScrollArea*>(widget) ||
2989                 widget->inherits("Q3ScrollView") /*|| isKontactPreviewPane(widget)*/))
2990                 return 3;
2991             else
2992                 return 2;
2993         case PM_SpinBoxFrameWidth:
2994             return opts.buttonEffect != EFFECT_NONE && opts.etchEntry ? 3 : 2;
2995         case PM_IndicatorWidth:
2996         case PM_IndicatorHeight:
2997         case PM_ExclusiveIndicatorWidth:
2998         case PM_ExclusiveIndicatorHeight:
2999         case PM_CheckListControllerSize:
3000         case PM_CheckListButtonSize:
3001             return (opts.buttonEffect != EFFECT_NONE ?
3002                     opts.crSize + 2 : opts.crSize);
3003         case PM_TabBarTabOverlap:
3004             return TAB_MO_GLOW==opts.tabMouseOver ? 0 : 1;
3005         case PM_ProgressBarChunkWidth:
3006             return 4;
3007         // case PM_DockWindowHandleExtent:
3008         //     return 10;
3009         case PM_DockWidgetSeparatorExtent:
3010         case PM_SplitterWidth:
3011             return LINE_1DOT==opts.splitters ? 7 : 6;
3012         case PM_ToolBarHandleExtent:
3013             return LINE_1DOT==opts.handles ? 7 : 8;
3014         case PM_ScrollBarSliderMin:
3015             // Leave a minimum of 21 pixels (which is the size used by Oxygen)
3016             // See https://github.com/QtCurve/qtcurve-qt4/issues/7
3017             // and https://bugs.kde.org/show_bug.cgi?id=317690
3018             return qtcMax(opts.sliderWidth, 20) + 1;
3019         case PM_SliderThickness: {
3020             int glowSize = (opts.buttonEffect != EFFECT_NONE &&
3021                             opts.coloredMouseOver == MO_GLOW ? 2 : 0);
3022             if (opts.sliderStyle == SLIDER_CIRCULAR) {
3023                 return CIRCULAR_SLIDER_SIZE + 6 + glowSize;
3024             } else if (opts.sliderStyle == SLIDER_TRIANGULAR) {
3025                 return 19 + glowSize;
3026             } else {
3027                 return (SLIDER_SIZE + glowSize +
3028                         (oneOf(opts.sliderStyle, SLIDER_PLAIN_ROTATED,
3029                                SLIDER_ROUND_ROTATED) ? 11 : 6));
3030             }
3031         }
3032         case PM_SliderControlThickness: {
3033             int glowSize = (opts.buttonEffect != EFFECT_NONE &&
3034                             opts.coloredMouseOver == MO_GLOW ? 2 : 0);
3035             if (opts.sliderStyle == SLIDER_CIRCULAR) {
3036                 return CIRCULAR_SLIDER_SIZE + glowSize;
3037             } else if (opts.sliderStyle == SLIDER_TRIANGULAR) {
3038                 return 11 + glowSize;
3039             } else {
3040                 return (SLIDER_SIZE + glowSize +
3041                         (oneOf(opts.sliderStyle, SLIDER_PLAIN_ROTATED,
3042                                SLIDER_ROUND_ROTATED) ? 6 : -2));
3043             }
3044         }
3045         case PM_SliderTickmarkOffset:
3046             return SLIDER_TRIANGULAR==opts.sliderStyle ? 5 : 4;
3047         case PM_SliderSpaceAvailable:
3048             if (auto slider = styleOptCast<QStyleOptionSlider>(option)) {
3049                 int size(pixelMetric(PM_SliderControlThickness, slider, widget));
3050 
3051                 if (slider->tickPosition & QSlider::TicksBelow)
3052                     ++size;
3053                 if (slider->tickPosition & QSlider::TicksAbove)
3054                     ++size;
3055                 return size;
3056             }
3057             return BaseStyle::pixelMetric(metric, option, widget);
3058         case PM_SliderLength: {
3059             int glowSize = (opts.buttonEffect != EFFECT_NONE &&
3060                             opts.coloredMouseOver == MO_GLOW ? 2 : 0);
3061             if (opts.sliderStyle == SLIDER_CIRCULAR) {
3062                 return CIRCULAR_SLIDER_SIZE + glowSize;
3063             } else if (opts.sliderStyle == SLIDER_TRIANGULAR) {
3064                 return 11 + glowSize;
3065             } else {
3066                 return (SLIDER_SIZE + glowSize +
3067                         (oneOf(opts.sliderStyle, SLIDER_PLAIN_ROTATED,
3068                                SLIDER_ROUND_ROTATED) ? -2 : 6));
3069             }
3070         }
3071         case PM_ScrollBarExtent:
3072             return opts.sliderWidth;
3073         case PM_MaximumDragDistance:
3074             return -1;
3075         case PM_TabBarTabHSpace:
3076             return 14;
3077         case PM_TabBarTabVSpace:
3078             return opts.highlightTab ? 10 : 8;
3079         case PM_TitleBarHeight:
3080             return qMax(widget ? widget->fontMetrics().lineSpacing()
3081                                : option ? option->fontMetrics.lineSpacing()
3082                                         : 0, 24);
3083         case PM_MenuBarPanelWidth:
3084             return 0;
3085         case QtC_Round:
3086             return (int)((opts.square&SQUARE_WINDOWS && opts.round>ROUND_SLIGHT) ? ROUND_SLIGHT : opts.round);
3087         case QtC_WindowBorder:
3088             return opts.windowBorder;
3089         case QtC_CustomBgnd:
3090             return qtcIsCustomBgnd(opts);
3091         case QtC_TitleAlignment:
3092             switch(opts.titlebarAlignment)
3093             {
3094                 default:
3095                 case ALIGN_LEFT:
3096                     return Qt::AlignLeft;
3097                 case ALIGN_CENTER:
3098                     return Qt::AlignHCenter|Qt::AlignVCenter;
3099                 case ALIGN_FULL_CENTER:
3100                     return Qt::AlignHCenter;
3101                 case ALIGN_RIGHT:
3102                     return Qt::AlignRight;
3103             }
3104         case QtC_TitleBarButtons:
3105             return opts.titlebarButtons;
3106         case QtC_TitleBarIcon:
3107             return opts.titlebarIcon;
3108         case QtC_TitleBarIconColor:
3109             return titlebarIconColor(option).rgb();
3110         case QtC_TitleBarEffect:
3111             return opts.titlebarEffect;
3112         case QtC_BlendMenuAndTitleBar:
3113             return BLEND_TITLEBAR;
3114         case QtC_ShadeMenubarOnlyWhenActive:
3115             return opts.shadeMenubarOnlyWhenActive;
3116         case QtC_ToggleButtons:
3117             return (opts.menubarHiding&HIDE_KWIN   ? 0x1 : 0)+
3118                    (opts.statusbarHiding&HIDE_KWIN ? 0x2 : 0);
3119         case QtC_MenubarColor:
3120             return m_menubarCols[ORIGINAL_SHADE].rgb();
3121         case QtC_TitleBarApp:
3122             return !option || option->state&State_Active ? opts.titlebarAppearance : opts.inactiveTitlebarAppearance;
3123 // The following is a somewhat hackyish fix for konqueror's show close button on tab setting...
3124 // ...its hackish in the way that I'm assuming when KTabBar is positioning the close button and it
3125 // asks for these options, it only passes in a QStyleOption  not a QStyleOptionTab
3126 //.........
3127         case PM_TabBarBaseHeight:
3128             if (qtcCheckKDEType(widget, KTabBar) &&
3129                 !styleOptCast<QStyleOptionTab>(option)) {
3130                 return 10;
3131             }
3132             return BaseStyle::pixelMetric(metric, option, widget);
3133         case PM_TabBarBaseOverlap:
3134             if (qtcCheckKDEType(widget, KTabBar) &&
3135                 !styleOptCast<QStyleOptionTab>(option)) {
3136                 return 0;
3137             }
3138 // Fall through!
3139 //.........
3140         default:
3141             return BaseStyle::pixelMetric(metric, option, widget);
3142     }
3143 }
3144 
3145 int Style::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const
3146 {
3147     prePolish(widget);
3148     switch (hint)
3149     {
3150         case SH_ToolTip_Mask:
3151         case SH_Menu_Mask:
3152             if ((SH_ToolTip_Mask == hint && (opts.square & SQUARE_TOOLTIPS)) ||
3153                 (SH_Menu_Mask == hint && POPUP_MENUS_SQUARE(opts))) {
3154                 return BaseStyle::styleHint(hint, option, widget, returnData);
3155             } else {
3156                 if (!Utils::hasAlphaChannel(widget) &&
3157                     (!widget || widget->isWindow())) {
3158                     if (auto mask =
3159                         styleOptCast<QStyleHintReturnMask>(returnData)) {
3160                         mask->region = windowMask(option->rect,
3161                                                   opts.round > ROUND_SLIGHT);
3162                     }
3163                 }
3164                 return true;
3165             }
3166         case SH_ComboBox_ListMouseTracking:
3167         case SH_PrintDialog_RightAlignButtons:
3168         case SH_ItemView_ArrowKeysNavigateIntoChildren:
3169         case SH_ToolBox_SelectedPageTitleBold:
3170         case SH_ScrollBar_MiddleClickAbsolutePosition:
3171         case SH_SpinControls_DisableOnBounds:
3172         case SH_Slider_SnapToValue:
3173         case SH_FontDialog_SelectAssociatedText:
3174         case SH_Menu_MouseTracking:
3175             return true;
3176         case SH_UnderlineShortcut:
3177             return widget && opts.hideShortcutUnderline ? m_shortcutHandler->showShortcut(widget) : true;
3178         case SH_GroupBox_TextLabelVerticalAlignment:
3179             if (auto frame = styleOptCast<QStyleOptionGroupBox>(option)) {
3180                 if (frame->features & QStyleOptionFrameV2::Flat) {
3181                     return Qt::AlignVCenter;
3182                 }
3183             }
3184             return opts.gbLabel&GB_LBL_INSIDE
3185                     ? Qt::AlignBottom
3186                     : opts.gbLabel&GB_LBL_OUTSIDE
3187                         ? Qt::AlignTop
3188                         : Qt::AlignVCenter;
3189         case SH_MessageBox_CenterButtons:
3190         case SH_ProgressDialog_CenterCancelButton:
3191         case SH_DitherDisabledText:
3192         case SH_EtchDisabledText:
3193         case SH_Menu_AllowActiveAndDisabled:
3194         case SH_ItemView_ShowDecorationSelected: // Controls whether the highlighting of listview/treeview items highlights whole line.
3195         case SH_MenuBar_AltKeyNavigation:
3196             return false;
3197         case SH_ItemView_ChangeHighlightOnFocus: // gray out selected items when losing focus.
3198             return false;
3199         case SH_WizardStyle:
3200             return QWizard::ClassicStyle;
3201         case SH_RubberBand_Mask: {
3202             auto opt = styleOptCast<QStyleOptionRubberBand>(option);
3203             if (!opt)
3204                 return true;
3205             if (auto mask = styleOptCast<QStyleHintReturnMask>(returnData)) {
3206                 mask->region = option->rect;
3207                 mask->region -= option->rect.adjusted(1,1,-1,-1);
3208             }
3209             return true;
3210         }
3211         case SH_Menu_SubMenuPopupDelay:
3212             return opts.menuDelay;
3213         case SH_ToolButton_PopupDelay:
3214             return 250;
3215         case SH_ComboBox_PopupFrameStyle:
3216             return opts.popupBorder || !POPUP_MENUS_SQUARE(opts) ? QFrame::StyledPanel|QFrame::Plain : QFrame::NoFrame;
3217         case SH_TabBar_Alignment:
3218             return Qt::AlignLeft;
3219         case SH_Header_ArrowAlignment:
3220             return Qt::AlignLeft;
3221         case SH_WindowFrame_Mask:
3222             if (auto mask = styleOptCast<QStyleHintReturnMask>(returnData)) {
3223                 QRect r(option->rect);
3224 
3225                 switch((opts.square&SQUARE_WINDOWS && opts.round>ROUND_SLIGHT) ? ROUND_SLIGHT : opts.round)
3226                 {
3227                     case ROUND_NONE:
3228                         mask->region=r;
3229                         break;
3230                     case ROUND_SLIGHT:
3231                         mask->region=QRegion(r.x()+1, r.y(), r.width()-2, r.height());
3232                         mask->region += QRegion(r.x()+0, r.y()+1, 1, r.height()-2);
3233                         mask->region += QRegion(r.x()+r.width()-1, r.y()+1, 1, r.height()-2);
3234                         break;
3235                     default: // ROUND_FULL
3236                         mask->region=QRegion(r.x()+5, r.y(), r.width()-10, r.height());
3237                         mask->region += QRegion(r.x()+0, r.y()+5, 1, r.height()-5);
3238                         mask->region += QRegion(r.x()+1, r.y()+3, 1, r.height()-2);
3239                         mask->region += QRegion(r.x()+2, r.y()+2, 1, r.height()-1);
3240                         mask->region += QRegion(r.x()+3, r.y()+1, 2, r.height());
3241                         mask->region += QRegion(r.x()+r.width()-1, r.y()+5, 1, r.height()-5);
3242                         mask->region += QRegion(r.x()+r.width()-2, r.y()+3, 1, r.height()-2);
3243                         mask->region += QRegion(r.x()+r.width()-3, r.y()+2, 1, r.height()-1);
3244                         mask->region += QRegion(r.x()+r.width()-5, r.y()+1, 2, r.height()-0);
3245                 }
3246             }
3247             return 1;
3248         case SH_TitleBar_NoBorder:
3249         case SH_TitleBar_AutoRaise:
3250             return 1;
3251         case SH_MainWindow_SpaceBelowMenuBar:
3252             if(opts.xbar)
3253                 if (const QMenuBar *menubar = qobject_cast<const QMenuBar*>(widget))
3254                     if (0==menubar->height() && !menubar->actions().isEmpty())
3255                     {   // we trick menubars if we use macmenus - hehehe...
3256                         // NOTICE the final result NEEDS to be > "0" (i.e. "1") to avoid side effects...
3257                         return -menubar->actionGeometry(menubar->actions().first()).height() + 1;
3258                     }
3259             return 0;
3260         case SH_DialogButtonLayout:
3261             return opts.gtkButtonOrder ? QDialogButtonBox::GnomeLayout : QDialogButtonBox::KdeLayout;
3262         case SH_MessageBox_TextInteractionFlags:
3263             return Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse;
3264         case SH_LineEdit_PasswordCharacter:
3265             if(opts.passwordChar)
3266             {
3267                 int                chars[4]={opts.passwordChar, 0x25CF, 0x2022, 0};
3268                 const QFontMetrics &fm(option ? option->fontMetrics
3269                                         : (widget ? widget->fontMetrics() : QFontMetrics(QFont())));
3270                 for(int i=0; chars[i]; ++i)
3271                     if (fm.inFont(QChar(chars[i])))
3272                         return chars[i];
3273                 return '*';
3274             }
3275             else
3276                 return '\0';
3277         case SH_MenuBar_MouseTracking:
3278             // Always return 1, as setting to 0 dissables the effect when a menu is shown.
3279             return 1; // opts.menubarMouseOver ? 1 : 0;
3280         case SH_ScrollView_FrameOnlyAroundContents:
3281             return widget && widget->isWindow()
3282                     ? false
3283                     : opts.gtkScrollViews && (!widget || !widget->inherits("QComboBoxListView"));
3284         case SH_ComboBox_Popup:
3285             if (opts.gtkComboMenus) {
3286                 if (widget && widget->inherits("Q3ComboBox"))
3287                     return 0;
3288                 if (auto cmb = styleOptCast<QStyleOptionComboBox>(option)) {
3289                     return !cmb->editable;
3290                 }
3291             }
3292             return 0;
3293         case SH_FormLayoutFormAlignment:
3294             // KDE4 HIG, align the contents in a form layout to the left
3295             return Qt::AlignLeft | Qt::AlignTop;
3296         case SH_FormLayoutLabelAlignment:
3297             // KDE4  HIG, align the labels in a form layout to the right
3298             return Qt::AlignRight;
3299         case SH_FormLayoutFieldGrowthPolicy:
3300             return QFormLayout::ExpandingFieldsGrow;
3301         case SH_FormLayoutWrapPolicy:
3302             return QFormLayout::DontWrapRows;
3303 #ifdef QTC_QT4_ENABLE_KDE
3304         case SH_DialogButtonBox_ButtonsHaveIcons:
3305             return KGlobalSettings::showIconsOnPushButtons();
3306         case SH_ItemView_ActivateItemOnSingleClick:
3307             return KGlobalSettings::singleClick();
3308 #endif
3309         default:
3310 #ifdef QTC_QT4_ENABLE_KDE
3311             // Tell the calling app that we can handle certain custom widgets...
3312             if(hint>=SH_CustomBase && widget)
3313                 if("CE_CapacityBar"==widget->objectName())
3314                 {
3315                     if (opts.boldProgress)
3316                         setBold((QWidget*)widget);
3317                     return CE_QtC_KCapacityBar;
3318                 }
3319 #endif
3320             return BaseStyle::styleHint(hint, option, widget, returnData);
3321    }
3322 }
3323 
3324 QPalette Style::standardPalette() const
3325 {
3326 #ifdef QTC_QT4_ENABLE_KDE
3327     return KGlobalSettings::createApplicationPalette(KSharedConfig::openConfig(m_componentData));
3328 #else
3329     return BaseStyle::standardPalette();
3330 #endif
3331 }
3332 
3333 QIcon Style::standardIconImplementation(StandardPixmap pix, const QStyleOption *option, const QWidget *widget) const
3334 {
3335     switch(pix)
3336     {
3337 //         case SP_TitleBarMenuButton:
3338 //         case SP_TitleBarMinButton:
3339 //         case SP_TitleBarMaxButton:
3340 //         case SP_TitleBarContextHelpButton:
3341         case SP_TitleBarNormalButton:
3342         case SP_TitleBarShadeButton:
3343         case SP_TitleBarUnshadeButton:
3344         case SP_DockWidgetCloseButton:
3345         case SP_TitleBarCloseButton:
3346         {
3347             QPixmap pm(13, 13);
3348 
3349             pm.fill(Qt::transparent);
3350 
3351             QPainter painter(&pm);
3352 
3353             drawIcon(&painter, Qt::color1, QRect(0, 0, pm.width(), pm.height()), false, pix2Icon(pix),
3354                      SP_TitleBarShadeButton==pix || SP_TitleBarUnshadeButton==pix);
3355             return QIcon(pm);
3356         }
3357         case SP_ToolBarHorizontalExtensionButton:
3358         case SP_ToolBarVerticalExtensionButton:
3359         {
3360             QPixmap pm(9, 9);
3361 
3362             pm.fill(Qt::transparent);
3363 
3364             QPainter painter(&pm);
3365 
3366             drawIcon(&painter, Qt::color1, QRect(0, 0, pm.width(), pm.height()), false, pix2Icon(pix), true);
3367             return QIcon(pm);
3368         }
3369 #ifndef QTC_QT4_ENABLE_KDE
3370         case SP_MessageBoxQuestion:
3371         case SP_MessageBoxInformation: {
3372             static QIcon icn(QPixmap::fromImage(qtc_dialog_information));
3373             return icn;
3374         }
3375         case SP_MessageBoxWarning: {
3376             static QIcon icn(QPixmap::fromImage(qtc_dialog_warning));
3377             return icn;
3378         }
3379         case SP_MessageBoxCritical: {
3380             static QIcon icn(QPixmap::fromImage(qtc_dialog_error));
3381             return icn;
3382         }
3383 /*
3384         case SP_DialogYesButton:
3385         case SP_DialogOkButton:
3386         {
3387             static QIcon icn(load(dialog_ok_png_len, dialog_ok_png_data));
3388             return icn;
3389         }
3390         case SP_DialogNoButton:
3391         case SP_DialogCancelButton:
3392         {
3393             static QIcon icn(load(dialog_cancel_png_len, dialog_cancel_png_data));
3394             return icn;
3395         }
3396         case SP_DialogHelpButton:
3397         {
3398             static QIcon icn(load(help_contents_png_len, help_contents_png_data));
3399             return icn;
3400         }
3401         case SP_DialogCloseButton:
3402         {
3403             static QIcon icn(load(dialog_close_png_len, dialog_close_png_data));
3404             return icn;
3405         }
3406         case SP_DialogApplyButton:
3407         {
3408             static QIcon icn(load(dialog_ok_apply_png_len, dialog_ok_apply_png_data));
3409             return icn;
3410         }
3411         case SP_DialogResetButton:
3412         {
3413             static QIcon icn(load(document_revert_png_len, document_revert_png_data));
3414             return icn;
3415         }
3416 */
3417 #else
3418         case SP_MessageBoxInformation:
3419             return KIcon("dialog-information");
3420         case SP_MessageBoxWarning:
3421             return KIcon("dialog-warning");
3422         case SP_MessageBoxCritical:
3423             return KIcon("dialog-error");
3424         case SP_MessageBoxQuestion:
3425             return KIcon("dialog-information");
3426         case SP_DesktopIcon:
3427             return KIcon("user-desktop");
3428         case SP_TrashIcon:
3429             return KIcon("user-trash");
3430         case SP_ComputerIcon:
3431             return KIcon("computer");
3432         case SP_DriveFDIcon:
3433             return KIcon("media-floppy");
3434         case SP_DriveHDIcon:
3435             return KIcon("drive-harddisk");
3436         case SP_DriveCDIcon:
3437         case SP_DriveDVDIcon:
3438             return KIcon("media-optical");
3439         case SP_DriveNetIcon:
3440             return KIcon("network-server");
3441         case SP_DirOpenIcon:
3442             return KIcon("document-open");
3443         case SP_DirIcon:
3444         case SP_DirClosedIcon:
3445             return KIcon("folder");
3446 //         case SP_DirLinkIcon:
3447         case SP_FileIcon:
3448             return KIcon("application-x-zerosize");
3449 //         case SP_FileLinkIcon:
3450         case SP_FileDialogStart:
3451             return KIcon(Qt::RightToLeft==QApplication::layoutDirection() ? "go-edn" : "go-first");
3452         case SP_FileDialogEnd:
3453             return KIcon(Qt::RightToLeft==QApplication::layoutDirection() ? "go-first" : "go-end");
3454         case SP_FileDialogToParent:
3455             return KIcon("go-up");
3456         case SP_FileDialogNewFolder:
3457             return KIcon("folder-new");
3458         case SP_FileDialogDetailedView:
3459             return KIcon("view-list-details");
3460 //         case SP_FileDialogInfoView:
3461 //             return KIcon("dialog-ok");
3462 //         case SP_FileDialogContentsView:
3463 //             return KIcon("dialog-ok");
3464         case SP_FileDialogListView:
3465             return KIcon("view-list-icons");
3466         case SP_FileDialogBack:
3467             return KIcon(Qt::RightToLeft==QApplication::layoutDirection() ? "go-next" : "go-previous");
3468         case SP_DialogOkButton:
3469             return KIcon("dialog-ok");
3470         case SP_DialogCancelButton:
3471             return KIcon("dialog-cancel");
3472         case SP_DialogHelpButton:
3473             return KIcon("help-contents");
3474         case SP_DialogOpenButton:
3475             return KIcon("document-open");
3476         case SP_DialogSaveButton:
3477             return KIcon("document-save");
3478         case SP_DialogCloseButton:
3479             return KIcon("dialog-close");
3480         case SP_DialogApplyButton:
3481             return KIcon("dialog-ok-apply");
3482         case SP_DialogResetButton:
3483             return KIcon("document-revert");
3484 //         case SP_DialogDiscardButton:
3485 //              return KIcon("dialog-cancel");
3486         case SP_DialogYesButton:
3487             return KIcon("dialog-ok");
3488         case SP_DialogNoButton:
3489             return KIcon("dialog-cancel");
3490         case SP_ArrowUp:
3491             return KIcon("arrow-up");
3492         case SP_ArrowDown:
3493             return KIcon("arrow-down");
3494         case SP_ArrowLeft:
3495             return KIcon("arrow-left");
3496         case SP_ArrowRight:
3497             return KIcon("arrow-right");
3498         case SP_ArrowBack:
3499             return KIcon(Qt::RightToLeft==QApplication::layoutDirection() ? "go-next" : "go-previous");
3500         case SP_ArrowForward:
3501             return KIcon(Qt::RightToLeft==QApplication::layoutDirection() ? "go-previous" : "go-next");
3502         case SP_DirHomeIcon:
3503             return KIcon("user-home");
3504 //         case SP_CommandLink:
3505 //         case SP_VistaShield:
3506         case SP_BrowserReload:
3507             return KIcon("view-refresh");
3508         case SP_BrowserStop:
3509             return KIcon("process-stop");
3510         case SP_MediaPlay:
3511             return KIcon("media-playback-start");
3512         case SP_MediaStop:
3513             return KIcon("media-playback-stop");
3514         case SP_MediaPause:
3515             return KIcon("media-playback-pause");
3516         case SP_MediaSkipForward:
3517             return KIcon("media-skip-forward");
3518         case SP_MediaSkipBackward:
3519             return KIcon("media-skip-backward");
3520         case SP_MediaSeekForward:
3521             return KIcon("media-seek-forward");
3522         case SP_MediaSeekBackward:
3523             return KIcon("media-seek-backward");
3524         case SP_MediaVolume:
3525             return KIcon("player-volume");
3526         case SP_MediaVolumeMuted:
3527             return KIcon("player-volume-muted");
3528 #endif
3529         default:
3530             break;
3531     }
3532     return BaseStyle::standardIconImplementation(pix, option, widget);
3533 }
3534 
3535 int Style::layoutSpacingImplementation(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation,
3536                                        const QStyleOption *option, const QWidget *widget) const
3537 {
3538     Q_UNUSED(control1); Q_UNUSED(control2); Q_UNUSED(orientation);
3539 
3540     return pixelMetric(PM_DefaultLayoutSpacing, option, widget);
3541 }
3542 
3543 void Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
3544 {
3545     prePolish(widget);
3546     QRect r(option->rect);
3547     QFlags<State> state(option->state);
3548     const QPalette &palette(option->palette);
3549     bool reverse(Qt::RightToLeft==option->direction);
3550 
3551     switch ((unsigned)element) {
3552 #if defined QTC_QT4_ENABLE_KDE
3553     case PE_IndicatorTabClose: {
3554         int size(pixelMetric(QStyle::PM_SmallIconSize));
3555         QIcon::Mode mode(state&State_Enabled ? state& State_Raised ?
3556                          QIcon::Active : QIcon::Normal : QIcon::Disabled);
3557 
3558         if (!(state & State_Raised) && !(state & State_Sunken) &&
3559             !(state & QStyle::State_Selected))
3560             mode = QIcon::Disabled;
3561 
3562         drawItemPixmap(painter, r, Qt::AlignCenter,
3563                        KIcon("dialog-close").pixmap(size, mode,
3564                                                     state & State_Sunken ?
3565                                                     QIcon::On : QIcon::Off));
3566         break;
3567     }
3568 #endif
3569     case PE_Widget:
3570         // TODO: handle widget == nullptr
3571         if (widget && widget->testAttribute(Qt::WA_StyledBackground) &&
3572             ((!widget->testAttribute(Qt::WA_NoSystemBackground) &&
3573               (qtcIsDialog(widget) || qtcIsWindow(widget)) &&
3574               widget->isWindow()) ||
3575              qobject_cast<const QMdiSubWindow*>(widget))) {
3576             bool isDialog = qobject_cast<const QDialog*>(widget);
3577 
3578             if (qtcIsCustomBgnd(opts) || m_isPreview ||
3579                 (isDialog && opts.dlgOpacity != 100) ||
3580                 (!isDialog && opts.bgndOpacity != 100)) {
3581                 painter->save();
3582                 // Blur and shadow here?
3583                 if (!(widget && qobject_cast<const QMdiSubWindow*>(widget))) {
3584                     painter->setCompositionMode(
3585                         QPainter::CompositionMode_Source);
3586                 }
3587                 drawBackground(painter, widget,
3588                                isDialog ? BGND_DIALOG : BGND_WINDOW);
3589                 painter->restore();
3590             }
3591         }
3592         break;
3593     case PE_PanelScrollAreaCorner:
3594         // disable painting of PE_PanelScrollAreaCorner
3595         // the default implementation fills the rect with the window background color which does not work for windows that have gradients.
3596         // ...but need to for WebView!!!
3597         if (!opts.gtkScrollViews || !qtcIsCustomBgnd(opts) ||
3598             (widget && widget->inherits("WebView")))
3599             painter->fillRect(r, palette.brush(QPalette::Window));
3600         break;
3601     case PE_IndicatorBranch: {
3602         int middleH((r.x() + r.width() / 2) - 1);
3603         int middleV(r.y() + r.height() / 2);
3604 #if 0
3605         int beforeH(middleH);
3606 #endif
3607         int beforeV(middleV);
3608         int afterH(middleH);
3609         int afterV(middleV);
3610 
3611         painter->save();
3612 
3613         if (state & State_Children) {
3614             QRect ar(r.x() + ((r.width() - (LV_SIZE + 4)) >> 1),
3615                      r.y() + ((r.height() - (LV_SIZE + 4)) >> 1),
3616                      LV_SIZE + 4, LV_SIZE + 4);
3617             if (/*LV_OLD == */opts.lvLines) {
3618                 beforeV = ar.y()-1;
3619                 afterH = ar.x() + LV_SIZE + 4;
3620                 afterV = ar.y() + LV_SIZE + 4;
3621 #if 0
3622                 beforeH = ar.x();
3623                 int lo = opts.round != ROUND_NONE ? 2 : 0;
3624 
3625                 painter->setPen(palette.mid().color());
3626                 painter->drawLine(ar.x() + lo, ar.y(),
3627                                   (ar.x() + ar.width() - 1) - lo, ar.y());
3628                 painter->drawLine(ar.x() + lo, ar.y() + ar.height() - 1,
3629                                   (ar.x() + ar.width() - 1) - lo,
3630                                   ar.y() + ar.height() - 1);
3631                 painter->drawLine(ar.x(), ar.y() + lo, ar.x(),
3632                                   (ar.y() + ar.height() - 1) - lo);
3633                 painter->drawLine(ar.x() + ar.width() - 1,
3634                                   ar.y() + lo, ar.x() + ar.width() - 1,
3635                                   (ar.y() + ar.height() - 1) - lo);
3636 
3637                 if (opts.round != ROUND_NONE) {
3638                     painter->drawPoint(ar.x() + 1, ar.y() + 1);
3639                     painter->drawPoint(ar.x() + 1, ar.y() + ar.height() - 2);
3640                     painter->drawPoint(ar.x() + ar.width() - 2, ar.y() + 1);
3641                     painter->drawPoint(ar.x() + ar.width() - 2,
3642                                        ar.y() + ar.height() - 2);
3643 
3644                     QColor col(palette.mid().color());
3645 
3646                     col.setAlphaF(0.5);
3647                     painter->setPen(col);
3648                     painter->drawLine(ar.x() + 1, ar.y() + 1,
3649                                       ar.x() + 2, ar.y());
3650                     painter->drawLine(ar.x() + ar.width() - 2,
3651                                       ar.y(), ar.x() + ar.width() - 1,
3652                                       ar.y() + 1);
3653                     painter->drawLine(ar.x() + 1, ar.y() + ar.height() - 2,
3654                                       ar.x() + 2, ar.y() + ar.height() - 1);
3655                     painter->drawLine(ar.x() + ar.width() - 2,
3656                                       ar.y() + ar.height() - 1,
3657                                       ar.x() + ar.width() - 1,
3658                                       ar.y() + ar.height() - 2);
3659                 }
3660 #endif
3661             }
3662             drawArrow(painter, ar, state&State_Open ?
3663                       PE_IndicatorArrowDown : reverse ?
3664                       PE_IndicatorArrowLeft : PE_IndicatorArrowRight,
3665                       MOArrow(state, palette, QPalette::ButtonText));
3666         }
3667 
3668         const int constStep = /*LV_OLD == */opts.lvLines ? 0
3669             : widget && qobject_cast<const QTreeView*>(widget) ?
3670             ((QTreeView*)widget)->indentation() : 20;
3671 
3672         if (opts.lvLines /*&& (LV_OLD == opts.lvLines ||
3673                            (r.x() >= constStep && constStep > 0))*/) {
3674             painter->setPen(palette.mid().color());
3675             if (state & State_Item) {
3676                 if (reverse) {
3677                         painter->drawLine(r.left(), middleV, afterH, middleV);
3678                 } else {
3679 #if 0
3680                     if (LV_NEW == opts.lvLines) {
3681                         if(state & State_Children) {
3682                             painter->drawLine(middleH - constStep, middleV,
3683                                               r.right() - constStep, middleV);
3684                         } else {
3685                             drawFadedLine(painter,
3686                                           QRect(middleH - constStep, middleV,
3687                                                 r.right() - (middleH - constStep),
3688                                                 middleV), palette.mid().color(),
3689                                           false, true, true);
3690                         }
3691                     } else
3692 #endif
3693                         painter->drawLine(afterH, middleV, r.right(), middleV);
3694                 }
3695             }
3696             if (state & State_Sibling && afterV < r.bottom())
3697                 painter->drawLine(middleH - constStep, afterV,
3698                                   middleH - constStep, r.bottom());
3699             if (state & (State_Open | State_Children | State_Item | State_Sibling) && (/*LV_NEW==opts.lvLines || */beforeV>r.y()))
3700                 painter->drawLine(middleH-constStep, r.y(), middleH-constStep, beforeV);
3701         }
3702         painter->restore();
3703         break;
3704     }
3705     case PE_IndicatorViewItemCheck: {
3706         QStyleOption opt(*option);
3707 
3708         opt.state &= ~State_MouseOver;
3709         opt.state |= STATE_VIEW;
3710         drawPrimitive(PE_IndicatorCheckBox, &opt, painter, widget);
3711         break;
3712     }
3713     case PE_IndicatorHeaderArrow:
3714         if (auto header = styleOptCast<QStyleOptionHeader>(option)) {
3715             drawArrow(painter, r,
3716                       header->sortIndicator & QStyleOptionHeader::SortUp ?
3717                       PE_IndicatorArrowUp : PE_IndicatorArrowDown,
3718                       MOArrow(state, palette, QPalette::ButtonText));
3719         }
3720         break;
3721     case PE_IndicatorArrowUp:
3722     case PE_IndicatorArrowDown:
3723     case PE_IndicatorArrowLeft:
3724     case PE_IndicatorArrowRight:
3725         if (State_None==state)
3726             state|=State_Enabled;
3727         if((QStyle::State_Enabled|QtC_StateKWin)==state) {
3728             drawArrow(painter, r, element, Qt::color1, false, true);
3729         } else {
3730             QColor col = MOArrow(state, palette, QPalette::Text);
3731             if (state & (State_Sunken | State_On) &&
3732                !(widget &&
3733                  ((opts.unifySpin && qobject_cast<const QSpinBox*>(widget)) ||
3734                   (opts.unifyCombo && qobject_cast<const QComboBox*>(widget) &&
3735                    ((const QComboBox*)widget)->isEditable())))) {
3736                 r.adjust(1, 1, 1, 1);
3737             }
3738             if (col.alpha() < 255 &&
3739                 PE_IndicatorArrowRight == element &&
3740                 widget && widget->inherits("KUrlButton"))
3741                 col = blendColors(col, palette.background().color(),
3742                                   col.alphaF());
3743 
3744             drawArrow(painter, r, element, col, false, false);
3745         }
3746         break;
3747     case PE_IndicatorSpinMinus:
3748     case PE_IndicatorSpinPlus:
3749     case PE_IndicatorSpinUp:
3750     case PE_IndicatorSpinDown: {
3751             QRect sr(r);
3752             const QColor *use(buttonColors(option));
3753             const QColor &col = MOArrow(state, palette, QPalette::ButtonText);
3754             bool down(PE_IndicatorSpinDown==element || PE_IndicatorSpinMinus==element);
3755 
3756             if((!opts.unifySpinBtns || state&State_Sunken) && !opts.unifySpin)
3757                 drawLightBevel(painter, sr, option, widget, down
3758                                                     ? reverse
3759                                                             ? ROUNDED_BOTTOMLEFT
3760                                                             : ROUNDED_BOTTOMRIGHT
3761                                                         : reverse
3762                                                             ? ROUNDED_TOPLEFT
3763                                                             : ROUNDED_TOPRIGHT,
3764                                getFill(option, use), use, true, WIDGET_SPIN);
3765 
3766             if(PE_IndicatorSpinUp==element || PE_IndicatorSpinDown==element)
3767             {
3768                 sr.setY(sr.y()+(down ? -2 : 1));
3769 
3770                 if (opts.unifySpin) {
3771                     sr.adjust(reverse ? 1 : -1, 0, reverse ? 1 : -1, 0);
3772                     if (!opts.vArrows) {
3773                         sr.setY(sr.y()+(down ? -2 : 2));
3774                     }
3775                 } else if(state&State_Sunken) {
3776                     sr.adjust(1, 1, 1, 1);
3777                 }
3778 
3779                 drawArrow(painter, sr, PE_IndicatorSpinUp==element ? PE_IndicatorArrowUp : PE_IndicatorArrowDown,
3780                           col, !opts.unifySpin);
3781             }
3782             else
3783             {
3784                 int    l(qMin(r.width()-6, r.height()-6));
3785                 QPoint c(r.x()+(r.width()/2), r.y()+(r.height()/2));
3786 
3787                 l/=2;
3788                 if(l%2 != 0)
3789                     --l;
3790 
3791                 if(state&State_Sunken && !opts.unifySpin)
3792                     c+=QPoint(1, 1);
3793 
3794                 painter->setPen(col);
3795                 painter->drawLine(c.x()-l, c.y(), c.x()+l, c.y());
3796                 if (!down) {
3797                     painter->drawLine(c.x(), c.y() - l, c.x(), c.y() + l);
3798                 }
3799             }
3800             break;
3801         }
3802         case PE_IndicatorToolBarSeparator:
3803         {
3804             painter->save();
3805             switch(opts.toolbarSeparators)
3806             {
3807                 case LINE_NONE:
3808                     break;
3809                 case LINE_FLAT:
3810                 case LINE_SUNKEN:
3811                     if(r.width()<r.height())
3812                     {
3813                         int x(r.x()+((r.width()-2) / 2));
3814                         drawFadedLine(painter, QRect(x, r.y()+TOOLBAR_SEP_GAP, 1, r.height()-(TOOLBAR_SEP_GAP*2)),
3815                                       m_backgroundCols[LINE_SUNKEN==opts.toolbarSeparators ? 3 : 4], true, true, false);
3816 
3817                         if(LINE_SUNKEN==opts.toolbarSeparators)
3818                             drawFadedLine(painter, QRect(x+1, r.y()+6, 1, r.height()-12), m_backgroundCols[0], true, true, false);
3819                     }
3820                     else
3821                     {
3822                         int y(r.y()+((r.height()-2) / 2));
3823 
3824                         drawFadedLine(painter, QRect(r.x()+TOOLBAR_SEP_GAP, y, r.width()-(TOOLBAR_SEP_GAP*2), 1),
3825                                       m_backgroundCols[LINE_SUNKEN==opts.toolbarSeparators ? 3 : 4], true, true, true);
3826                         if(LINE_SUNKEN==opts.toolbarSeparators)
3827                             drawFadedLine(painter, QRect(r.x()+TOOLBAR_SEP_GAP, y+1, r.width()-(TOOLBAR_SEP_GAP*2), 1),
3828                                           m_backgroundCols[0], true, true, true);
3829                     }
3830                     break;
3831                 default:
3832                 case LINE_DOTS:
3833                     drawDots(painter, r, !(state&State_Horizontal), 1, 5, m_backgroundCols, 0, 5);
3834             }
3835             painter->restore();
3836             break;
3837         }
3838         case PE_FrameGroupBox:
3839             if(FRAME_NONE==opts.groupBox)
3840                 break;
3841             if (auto frame = styleOptCast<QStyleOptionFrame>(option)) {
3842                 QStyleOptionFrameV2 frameV2(*frame);
3843                 if (frameV2.features & QStyleOptionFrameV2::Flat || FRAME_LINE==opts.groupBox)
3844                     drawFadedLine(painter, QRect(r.x(), r.y(), r.width(), 1), backgroundColors(option)[QTC_STD_BORDER],
3845                                   opts.gbLabel&GB_LBL_CENTRED || reverse, opts.gbLabel&GB_LBL_CENTRED || !reverse, true);
3846                 else
3847                 {
3848                     if(opts.gbLabel&GB_LBL_OUTSIDE)
3849                         r.adjust(0, 2, 0, 0);
3850 
3851                     if(FRAME_SHADED==opts.groupBox || FRAME_FADED==opts.groupBox)
3852                     {
3853                         int          round=opts.square&SQUARE_FRAME ? ROUNDED_NONE : ROUNDED_ALL;
3854                         QPainterPath path(buildPath(r, WIDGET_FRAME, round,
3855                                                     ROUNDED_ALL==round
3856                                                         ? qtcGetRadius(&opts, r.width(), r.height(), WIDGET_FRAME, RADIUS_EXTERNAL)
3857                                                         : 0.0));
3858 
3859                         painter->save();
3860                         painter->setClipping(false);
3861                         if(0!=opts.gbFactor)
3862                         {
3863                             QColor col(opts.gbFactor<0 ? Qt::black : Qt::white);
3864 
3865                             col.setAlphaF(TO_ALPHA(opts.gbFactor));
3866                             if(FRAME_SHADED==opts.groupBox)
3867                                 painter->fillPath(path, col);
3868                             else
3869                             {
3870                                 QLinearGradient grad(r.topLeft(), r.bottomLeft());
3871 
3872                                 grad.setColorAt(0, col);
3873                                 col.setAlphaF(0.0);
3874                                 grad.setColorAt(1, col);
3875                                 painter->fillPath(path, grad);
3876                             }
3877                         }
3878 
3879                         if(!(opts.gbLabel&(GB_LBL_INSIDE|GB_LBL_OUTSIDE)))
3880                             painter->restore();
3881 
3882                         if(FRAME_SHADED==opts.groupBox)
3883                             drawBorder(painter, r, option, round, backgroundColors(option), WIDGET_FRAME,
3884                                         /*state&State_Raised && opts.gbFactor<0 ? BORDER_RAISED : */BORDER_SUNKEN);
3885                         else
3886                         {
3887                             QColor          col(backgroundColors(option)[QTC_STD_BORDER]);
3888                             QLinearGradient grad(r.topLeft(), r.bottomLeft());
3889 
3890                             col.setAlphaF(1.0);
3891                             grad.setColorAt(0, col);
3892                             col.setAlphaF(0.0);
3893                             grad.setColorAt(1, col);
3894                             painter->setRenderHint(QPainter::Antialiasing, true);
3895                             painter->setPen(QPen(QBrush(grad), 1));
3896                             painter->drawPath(path);
3897                         }
3898                         if(opts.gbLabel&(GB_LBL_INSIDE|GB_LBL_OUTSIDE))
3899                             painter->restore();
3900                     }
3901                     else
3902                     {
3903                         frameV2.state &= ~(State_Sunken | State_HasFocus);
3904                         frameV2.rect=r;
3905                         drawPrimitive(PE_Frame, &frameV2, painter, widget);
3906                     }
3907                 }
3908             }
3909             break;
3910         case PE_Frame:
3911         {
3912             // Dont draw OO.o status bar frames...
3913             if(isOOWidget(widget) && r.height()<22)
3914                 break;
3915 
3916             if (widget && qtcCheckKDEType(widget->parent(), KTitleWidget)) {
3917                 break;
3918             } else if (widget && widget->parent() &&
3919                        qobject_cast<const QComboBox*>(widget->parent())) {
3920                 if(opts.gtkComboMenus && !((QComboBox*)(widget->parent()))->isEditable())
3921                     drawPrimitive(PE_FrameMenu, option, painter, widget);
3922                 else if(POPUP_MENUS_SQUARE(opts))
3923                 {
3924                     const QColor *use(APP_KRUNNER==theThemedApp ? m_backgroundCols : backgroundColors(option));
3925 
3926                     painter->save();
3927                     painter->setPen(use[QTC_STD_BORDER]);
3928                     drawRect(painter, r);
3929                     painter->setPen(palette.base().color());
3930                     drawRect(painter, r.adjusted(1, 1, -1, -1));
3931                     painter->restore();
3932                 }
3933             } else {
3934                 auto fo = styleOptCast<QStyleOptionFrame>(option);
3935 
3936                 if(APP_K3B==theThemedApp && !(state&(State_Sunken|State_Raised)) && fo && 1==fo->lineWidth)
3937                 {
3938                     painter->save();
3939                     painter->setPen(backgroundColors(option)[QTC_STD_BORDER]);
3940                     drawRect(painter, r);
3941                     painter->restore();
3942                 }
3943                 else if((QtC_StateKWin==state || (QtC_StateKWin|State_Active)==state) && fo && 1==fo->lineWidth && 1==fo->midLineWidth)
3944                 {
3945                     QColor border;
3946                     if(fo->version==(TBAR_BORDER_VERSION_HACK+2))
3947                         border=palette.color(QPalette::Active, QPalette::Shadow);
3948                     else
3949                     {
3950                         const QColor *borderCols(opts.windowBorder&WINDOW_BORDER_COLOR_TITLEBAR_ONLY
3951                                                     ? backgroundColors(palette.color(QPalette::Active, QPalette::Window))
3952                                                     : theThemedApp==APP_KWIN
3953                                                         ? buttonColors(option)
3954                                                         : getMdiColors(option, state&State_Active));
3955                         border=borderCols[fo->version==TBAR_BORDER_VERSION_HACK ? 0 : QTC_STD_BORDER];
3956                     }
3957 
3958                     border.setAlphaF(1.0);
3959                     painter->save();
3960                     painter->setRenderHint(QPainter::Antialiasing, false);
3961                     painter->setPen(border);
3962                     drawRect(painter, r);
3963                     painter->restore();
3964                 }
3965                 else
3966                 {
3967                     bool kateView(isKateView(widget)),
3968                          kontactPreview(!kateView && isKontactPreviewPane(widget)),
3969                          sv(isOOWidget(widget) ||
3970                             qobject_cast<const QAbstractScrollArea*>(widget) ||
3971                             (widget && widget->inherits("Q3ScrollView")) ||
3972                             ((opts.square&SQUARE_SCROLLVIEW) && (kateView || kontactPreview))),
3973                         squareSv(sv && ((opts.square&SQUARE_SCROLLVIEW) || (widget && widget->isWindow()))),
3974                         inQAbstractItemView(widget && widget->parentWidget() && isInQAbstractItemView(widget->parentWidget()));
3975                     QtcQWidgetProps props(widget);
3976 
3977                     if (sv && (opts.etchEntry || squareSv ||
3978                                isOOWidget(widget))) {
3979                         // For some reason, in KPackageKit, the KTextBrower when polished is not in the scrollview,
3980                         // but is when painted. So check here if it should not be etched.
3981                         // Also, see not in getLowerEtchCol()
3982                         if (opts.buttonEffect != EFFECT_NONE &&
3983                             !USE_CUSTOM_ALPHAS(opts) && widget &&
3984                             widget->parentWidget() &&
3985                             !props->noEtch && inQAbstractItemView) {
3986                             props->noEtch = true;
3987                         }
3988 
3989                         // If we are set to have sunken scrollviews, then the frame width is set to 3.
3990                         // ...but it we are a scrollview within a scrollview, then we dont draw sunken, therefore
3991                         // need to draw inner border...
3992                         bool doEtch = (opts.buttonEffect != EFFECT_NONE &&
3993                                        opts.etchEntry);
3994                         bool noEtchW = (doEtch &&
3995                                         !USE_CUSTOM_ALPHAS(opts) &&
3996                                         props->noEtch);
3997 
3998                         if(doEtch && noEtchW)
3999                         {
4000                             painter->setPen(palette.brush(QPalette::Base).color());
4001                             drawRect(painter, r.adjusted(2, 2, -2, -2));
4002                         }
4003 
4004                         if(!opts.highlightScrollViews && fo)
4005                         {
4006                             QStyleOptionFrame opt(*fo);
4007                             opt.state&=~State_HasFocus;
4008                             drawEntryField(painter, r, widget, &opt, squareSv ? ROUNDED_NONE : ROUNDED_ALL, false, doEtch && !noEtchW, WIDGET_SCROLLVIEW);
4009                         }
4010                         else
4011                             drawEntryField(painter, r, widget, option, squareSv ? ROUNDED_NONE : ROUNDED_ALL, false,
4012                                            doEtch && !noEtchW, WIDGET_SCROLLVIEW);
4013                     }
4014                     // K3b's Disk usage status bar, etc...
4015 //                     else if(APP_K3B==theThemedApp && widget && widget->inherits("K3b::FillStatusDisplay"))
4016                     else if (fo && fo->lineWidth > 0) {
4017                         bool kwinTab(theThemedApp == APP_KWIN && widget &&
4018                                      !widget->parentWidget() &&
4019                                      oneOf(widget->metaObject()->className(), "KWin::TabBox"));
4020                         QStyleOption opt(*option);
4021 
4022                         painter->save();
4023 
4024                         if(kwinTab)
4025                             r.adjust(-1, -1, 1, 1);
4026 
4027                         if(!opts.highlightScrollViews)
4028                             opt.state&=~State_HasFocus;
4029 
4030                         if(opts.round && qtcIsFlatBgnd(opts.bgndAppearance) && 100==opts.bgndOpacity &&
4031                            widget && widget->parentWidget() && !inQAbstractItemView/* &&
4032                            widget->palette().background().color()!=widget->parentWidget()->palette().background().color()*/)
4033                         {
4034                             painter->setPen(widget->parentWidget()->palette().background().color());
4035                             painter->drawRect(r);
4036                             painter->drawRect(r.adjusted(1, 1, -1, -1));
4037                         }
4038 
4039                         if(sv || kateView || kontactPreview)
4040                         {
4041                             painter->setRenderHint(QPainter::Antialiasing, true);
4042                             painter->setPen(option->palette.brush(opts.thin&THIN_FRAMES && !(opts.square&SQUARE_SCROLLVIEW)
4043                                                                     ? QPalette::Window
4044                                                                     : QPalette::Base).color());
4045                             painter->drawPath(buildPath(r.adjusted(1, 1, -1, -1), WIDGET_SCROLLVIEW, ROUNDED_ALL,
4046                                                         qtcGetRadius(&opts, r.width()-2, r.height()-2, WIDGET_SCROLLVIEW, RADIUS_INTERNAL)));
4047                             painter->setRenderHint(QPainter::Antialiasing, false);
4048                         }
4049 
4050                         drawBorder(painter, r, &opt,
4051                                    opts.round ?  getFrameRound(widget) : ROUND_NONE, backgroundColors(option),
4052                                    sv || kateView || kontactPreview ? WIDGET_SCROLLVIEW : WIDGET_FRAME,
4053                                    state&State_Sunken || state&State_HasFocus
4054                                         ? BORDER_SUNKEN
4055                                         : state&State_Raised
4056                                             ? BORDER_RAISED
4057                                             : BORDER_FLAT);
4058                         painter->restore();
4059                     }
4060                 }
4061             }
4062             break;
4063         }
4064         case PE_PanelMenuBar:
4065             if (widget && widget->parentWidget() && (qobject_cast<const QMainWindow*>(widget->parentWidget()) ||
4066                                                      widget->parentWidget()->inherits("Q3MainWindow")))
4067             {
4068                 painter->save();
4069                 if (!opts.xbar ||
4070                     (!widget || noneOf(widget->metaObject()->className(),
4071                                        "QWidget")))
4072                     drawMenuOrToolBarBackground(widget, painter, r, option);
4073                 if (opts.toolbarBorders != TB_NONE) {
4074                     const QColor *use = (m_active ? m_menubarCols :
4075                                          backgroundColors(option));
4076                     bool dark(oneOf(opts.toolbarBorders, TB_DARK, TB_DARK_ALL));
4077 
4078                     if (oneOf(opts.toolbarBorders, TB_DARK_ALL, TB_LIGHT_ALL)) {
4079                         painter->setPen(use[0]);
4080                         painter->drawLine(r.x(), r.y(),
4081                                           r.x() + r.width() - 1, r.y());
4082                         painter->drawLine(r.x(), r.y(), r.x(),
4083                                           r.y() + r.height() - 1);
4084                         painter->setPen(use[dark ? 3 : 4]);
4085                         painter->drawLine(r.x(), r.y() + r.height() - 1,
4086                                           r.x() + r.width() - 1,
4087                                           r.y() + r.height() - 1);
4088                         painter->drawLine(r.x() + r.width() - 1, r.y(),
4089                                           r.x() + r.width() - 1,
4090                                           r.y() + r.height() - 1);
4091                     } else {
4092                         painter->setPen(use[dark ? 3 : 4]);
4093                         painter->drawLine(r.x(), r.y() + r.height() - 1,
4094                                           r.x() + r.width() - 1,
4095                                           r.y() + r.height() - 1);
4096                     }
4097                 }
4098                 painter->restore();
4099             }
4100             break;
4101         case PE_FrameTabBarBase:
4102             if (auto tbb = styleOptCast<QStyleOptionTabBarBase>(option)) {
4103                 if(tbb->shape != QTabBar::RoundedNorth && tbb->shape != QTabBar::RoundedWest &&
4104                    tbb->shape != QTabBar::RoundedSouth && tbb->shape != QTabBar::RoundedEast)
4105                     BaseStyle::drawPrimitive(element, option, painter, widget);
4106                 else
4107                 {
4108                     static const int constSidePad=16*2;
4109                     const QColor *use(backgroundColors(option));
4110                     QRegion      region(tbb->rect);
4111                     QLine        topLine(tbb->rect.bottomLeft() - QPoint(0, 1), tbb->rect.bottomRight() - QPoint(0, 1)),
4112                                  bottomLine(tbb->rect.bottomLeft(), tbb->rect.bottomRight());
4113                     bool         horiz(QTabBar::RoundedNorth==tbb->shape || QTabBar::RoundedSouth==tbb->shape);
4114                     double       size=horiz ? tbb->rect.width() : tbb->rect.height(),
4115                                  tabRectSize=horiz ? tbb->tabBarRect.width() : tbb->tabBarRect.height(),
4116                                  tabFadeSize=tabRectSize+constSidePad > size ? 0.0 : 1.0-((tabRectSize+constSidePad)/size),
4117                                  minFadeSize=1.0-((size-constSidePad)/size),
4118                                  fadeSizeStart=minFadeSize,
4119                                  fadeSizeEnd=tabFadeSize<minFadeSize ? minFadeSize : (tabFadeSize>FADE_SIZE ? FADE_SIZE : tabFadeSize);
4120 
4121                     if(reverse && horiz)
4122                         fadeSizeStart=fadeSizeEnd, fadeSizeEnd=minFadeSize;
4123 
4124                     region -= tbb->tabBarRect;
4125 
4126                     painter->save();
4127                     painter->setClipRegion(region);
4128                     bool fadeState=true, fadeEnd=true;
4129 
4130                     // Dont fade start/end of tabbar in KDevelop's menubar
4131                     if (theThemedApp == APP_KDEVELOP &&
4132                         qtcCheckType<QMenuBar>(getParent<2>(widget)) &&
4133                         qobject_cast<const QTabBar*>(widget))
4134                         fadeState=fadeEnd=false;
4135 
4136                     drawFadedLine(painter, QRect(topLine.p1(), topLine.p2()),
4137                                   QTabBar::RoundedSouth==tbb->shape && APPEARANCE_FLAT==opts.appearance
4138                                     ? palette.background().color()
4139                                     : use[QTabBar::RoundedNorth==tbb->shape ? QTC_STD_BORDER
4140                                                                             : (opts.borderTab ? 0 : FRAME_DARK_SHADOW)],
4141                                   fadeState, fadeEnd, horiz, fadeSizeStart, fadeSizeEnd);
4142                     if(!(opts.thin&THIN_FRAMES))
4143                         drawFadedLine(painter, QRect(bottomLine.p1(), bottomLine.p2()),
4144                                       use[QTabBar::RoundedNorth==tbb->shape ? 0 : QTC_STD_BORDER],
4145                                       fadeState, fadeEnd, horiz, fadeSizeStart, fadeSizeEnd);
4146                     painter->restore();
4147                 }
4148             }
4149             break;
4150         case PE_FrameStatusBar:
4151             if(!opts.drawStatusBarFrames)
4152                 break;
4153             QTC_FALLTHROUGH();
4154         case PE_FrameMenu:
4155             if(POPUP_MENUS_SQUARE(opts) &&
4156                 (qtcIsFlatBgnd(opts.menuBgndAppearance) ||
4157                 (opts.gtkComboMenus && widget && widget->parent() && qobject_cast<const QComboBox*>(widget->parent()))))
4158             {
4159                 const QColor    *use(popupMenuCols(option));
4160                 EGradientBorder border=qtcGetGradient(opts.menuBgndAppearance, &opts)->border;
4161                 painter->save();
4162                 painter->setPen(use[QTC_STD_BORDER]);
4163                 drawRect(painter, r);
4164 
4165                 if(qtcUseBorder(border) && APPEARANCE_FLAT!=opts.menuBgndAppearance)
4166                 {
4167                     painter->setPen(use[0]);
4168                     if(GB_LIGHT==border)
4169                          drawRect(painter, r.adjusted(1, 1, -1, -1));
4170                     else
4171                     {
4172                         if(GB_3D!=border)
4173                         {
4174                             painter->drawLine(r.x()+1, r.y()+1, r.x()+r.width()-2,  r.y()+1);
4175                             painter->drawLine(r.x()+1, r.y()+1, r.x()+1,  r.y()+r.height()-2);
4176                         }
4177                         painter->setPen(use[FRAME_DARK_SHADOW]);
4178                         painter->drawLine(r.x()+1, r.y()+r.height()-2, r.x()+r.width()-2,  r.y()+r.height()-2);
4179                         painter->drawLine(r.x()+r.width()-2, r.y()+1, r.x()+r.width()-2,  r.y()+r.height()-2);
4180                     }
4181                 }
4182                 painter->restore();
4183             }
4184             break;
4185         case PE_FrameDockWidget:
4186         {
4187             const QColor *use(backgroundColors(option));
4188 
4189             painter->save();
4190             painter->setPen(use[0]);
4191             painter->drawLine(r.x(), r.y(), r.x()+r.width()-1, r.y());
4192             painter->drawLine(r.x(), r.y(), r.x(), r.y()+r.height()-1);
4193             painter->setPen(use[APPEARANCE_FLAT==opts.appearance ? ORIGINAL_SHADE : QTC_STD_BORDER]);
4194             painter->drawLine(r.x(), r.y()+r.height()-1, r.x()+r.width()-1, r.y()+r.height()-1);
4195             painter->drawLine(r.x()+r.width()-1, r.y(), r.x()+r.width()-1, r.y()+r.height()-1);
4196             painter->restore();
4197             break;
4198         }
4199         case PE_FrameButtonTool:
4200         case PE_PanelButtonTool:
4201             if(isMultiTabBarTab(getButton(widget, painter)))
4202             {
4203                 if(!opts.stdSidebarButtons)
4204                     drawSideBarButton(painter, r, option, widget);
4205                 else if((state&State_Enabled) || !(state&State_AutoRaise) )
4206                 {
4207                     QStyleOption opt(*option);
4208                     opt.state|=STATE_TBAR_BUTTON;
4209                     drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget);
4210                 }
4211                 break;
4212             }
4213             QTC_FALLTHROUGH();
4214         case PE_IndicatorButtonDropDown: // This should never be called, but just in case - draw as a normal toolbutton...
4215         {
4216             bool dwt(widget && widget->inherits("QDockWidgetTitleButton")),
4217                  koDwt(!dwt && widget && widget->parentWidget() && widget->parentWidget()->inherits("KoDockWidgetTitleBar"));
4218 
4219             if(((state&State_Enabled) || !(state&State_AutoRaise)) &&
4220                (!widget || !(dwt || koDwt)|| (state&State_MouseOver)) )
4221             {
4222                 QStyleOption opt(*option);
4223 
4224                 if(dwt || koDwt)
4225                     opt.state|=STATE_DWT_BUTTON;
4226                 drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget);
4227             }
4228             break;
4229         }
4230         case PE_IndicatorDockWidgetResizeHandle:
4231         {
4232             QStyleOption dockWidgetHandle = *option;
4233             bool horizontal = state&State_Horizontal;
4234             if (horizontal)
4235                 dockWidgetHandle.state &= ~State_Horizontal;
4236             else
4237                 dockWidgetHandle.state |= State_Horizontal;
4238             drawControl(CE_Splitter, &dockWidgetHandle, painter, widget);
4239             break;
4240         }
4241         case PE_PanelLineEdit:
4242             if (auto panel = styleOptCast<QStyleOptionFrame>(option)) {
4243                 if(panel->lineWidth > 0)
4244                 {
4245                     QRect r2(r.adjusted(1, 1, -1, opts.buttonEffect !=
4246                                         EFFECT_NONE ? -2 : -1));
4247                     painter->fillPath(buildPath(r2, WIDGET_ENTRY, ROUNDED_ALL, qtcGetRadius(&opts, r2.width(), r2.height(), WIDGET_ENTRY, RADIUS_INTERNAL)),
4248                                       palette.brush(QPalette::Base));
4249                     drawPrimitive(PE_FrameLineEdit, option, painter, widget);
4250                 }
4251                 else
4252                     painter->fillRect(r.adjusted(2, 2, -2, -2), palette.brush(QPalette::Base));
4253             }
4254             break;
4255         case PE_FrameLineEdit:
4256             if (auto lineEdit = styleOptCast<QStyleOptionFrame>(option)) {
4257                 if ((lineEdit->lineWidth>0 || isOOWidget(widget)) &&
4258                     !(widget &&
4259                      (qobject_cast<const QComboBox*>(widget->parentWidget()) ||
4260                       qobject_cast<const QAbstractSpinBox*>(widget->parentWidget()))))
4261                 {
4262                     QStyleOptionFrame opt(*lineEdit);
4263 
4264                     if(opt.state&State_Enabled && state&State_ReadOnly)
4265                         opt.state^=State_Enabled;
4266 
4267                     if (opts.buttonEffect != EFFECT_NONE && opts.etchEntry &&
4268                         theThemedApp == APP_ARORA && widget &&
4269                         widget->parentWidget() &&
4270                         oneOf(widget->metaObject()->className(), "LocationBar")) {
4271                         if (const QToolBar *tb =
4272                             getToolBar(widget->parentWidget()/*, false*/)) {
4273                             QRect r2(r);
4274                             struct TB: public QToolBar {
4275                                 void
4276                                 initOpt(QStyleOptionToolBar *opt)
4277                                 {
4278                                     initStyleOption(opt);
4279                                 }
4280                             };
4281 
4282                             QStyleOptionToolBar opt;
4283 
4284                             ((TB*)tb)->initOpt(&opt);
4285 
4286                             painter->save();
4287 
4288                             // Only need to adjust coords if toolbar has a gradient...
4289                             if (!qtcIsFlat(opts.toolbarAppearance)) {
4290                                 r2.setY(-widget->mapTo((QWidget*)tb, QPoint(r.x(), r.y())).y());
4291                                 r2.setHeight(tb->rect().height());
4292                             }
4293                             painter->setClipRegion(QRegion(r2).subtract(QRegion(r2.adjusted(2, 2, -2, -2))));
4294                             drawMenuOrToolBarBackground(widget, painter, r2, &opt, false, true);
4295                             painter->restore();
4296                         }
4297                     }
4298                     painter->save();
4299                     bool  isOO(isOOWidget(widget));
4300                     QRect rect(r);
4301                     int   round(ROUNDED_ALL);
4302 
4303                     if(isOO)
4304                     {
4305                         // This (hopefull) checks is we're OO.o 3.2 - in which case no adjustment is required...
4306                         const QImage *img=getImage(painter);
4307 
4308                         if(!img || img->rect()!=r) // OO.o 3.1?
4309                             rect.adjust(1, 2, -1, -2);
4310                         else
4311                         {
4312                             round=ROUNDED_NONE;
4313                             painter->fillRect(r, palette.brush(QPalette::Window));
4314                             rect.adjust(1, 1, -1, -1);
4315                         }
4316                     }
4317 
4318                     drawEntryField(painter, rect, widget, &opt, round, isOO,
4319                                    !isOO && opts.buttonEffect != EFFECT_NONE);
4320                     painter->restore();
4321                 }
4322             }
4323             break;
4324         case PE_Q3CheckListIndicator:
4325             if (auto lv = styleOptCast<QStyleOptionQ3ListView>(option)) {
4326                 if(lv->items.isEmpty())
4327                     break;
4328 
4329                 QStyleOptionQ3ListViewItem item(lv->items.at(0));
4330                 int                        x(lv->rect.x()),
4331                                            w(lv->rect.width()),
4332                                            marg(lv->itemMargin);
4333 
4334                 if (state & State_Selected && !lv->rootIsDecorated && !(item.features & QStyleOptionQ3ListViewItem::ParentControl))
4335                     painter->fillRect(0, 0, x + marg + w + 4, item.height, palette.brush(QPalette::Highlight));
4336             }
4337 
4338             r.setX(r.x()+((r.width()-opts.crSize)/2)-1);
4339             r.setY(r.y()+((r.height()-opts.crSize)/2)-1);
4340             r.setWidth(opts.crSize);
4341             r.setHeight(opts.crSize);
4342             QTC_FALLTHROUGH();
4343         case PE_IndicatorMenuCheckMark:
4344         case PE_IndicatorCheckBox:
4345         {
4346             bool  menu(state&STATE_MENU),
4347                   view(state&STATE_VIEW),
4348                   doEtch(opts.buttonEffect != EFFECT_NONE &&
4349                          (opts.crButton || (PE_IndicatorMenuCheckMark!=element && !menu &&
4350                                             r.width()>=opts.crSize+2 && r.height()>=opts.crSize+2))),
4351                   isOO(isOOWidget(widget)),
4352                   selectedOOMenu(isOO && (r==QRect(0, 0, 15, 15) || r==QRect(0, 0, 14, 15)) &&  // OO.o 3.2 =14x15?
4353                                 ((State_Sunken|State_Enabled)==state || (State_Sunken|State_Enabled|State_Selected)==state));
4354             int   crSize(opts.crSize+(doEtch ? 2 : 0));
4355             QRect rect(r.x(), r.y()+(view ? -1 : 0), crSize, crSize);
4356             // render checkable menu items with only a tick; should become an option
4357             bool onlyTicksInMenu = menu && opts.onlyTicksInMenu;
4358 
4359             painter->save();
4360 
4361             // For OO.o 3.2 need to fill widget background!
4362             if(isOO)
4363                 painter->fillRect(r, palette.brush(QPalette::Window));
4364 
4365             if(selectedOOMenu)
4366             {
4367                 if(r==QRect(0, 0, 14, 15)) // OO.o 3.2 =14x15?
4368                     rect.adjust(-1, -1, -1, -1);
4369                 painter->setPen(option ? option->palette.text().color() : QApplication::palette().text().color());
4370                 drawRect(painter, r);
4371                 // LibreOffice its 15x15 - and arrow is not centred, so adjust this...
4372                 if(r==QRect(0, 0, 15, 15))
4373                     rect.adjust(-1, -1, -1, -1);
4374             }
4375             else if (!onlyTicksInMenu)
4376             {
4377                 if(isOO && r==QRect(0, 0, opts.crSize, opts.crSize))
4378                     rect.adjust(0, -1, 0, -1);
4379 
4380                 if(CR_SMALL_SIZE!=opts.crSize)
4381                 {
4382                     if(menu)
4383                         rect.adjust(0, -1, 0, -1);
4384                     else if(r.height()>crSize)   // Can only adjust position if there is space!
4385                         rect.adjust(0, 1, 0, 1); // ...when used in a listview, usually there is no space.
4386                 }
4387 
4388                 if(opts.crButton)
4389                 {
4390                     const QColor *use(checkRadioColors(option));
4391                     QStyleOption opt(*option);
4392 
4393                     if(menu || selectedOOMenu)
4394                         opt.state&=~(State_MouseOver|State_Sunken);
4395                     opt.state&=~State_On;
4396                     opt.state|=State_Raised;
4397                     opt.rect=rect;
4398                     drawLightBevel(painter, rect, &opt, widget, ROUNDED_ALL, getFill(&opt, use, true, false),
4399                                    use, true, WIDGET_CHECKBOX);
4400                 }
4401                 else
4402                 {
4403                     bool         sunken(!menu && !selectedOOMenu && (state&State_Sunken)),
4404                                  mo(!sunken && state&State_MouseOver && state&State_Enabled),
4405                                  glow(doEtch && MO_GLOW==opts.coloredMouseOver && mo);
4406                     const QColor *bc(sunken ? 0L : borderColors(option, 0L)),
4407                                  *btn(checkRadioColors(option)),
4408                                  *use(bc ? bc : btn);
4409                     const QColor &bgnd(state&State_Enabled && !sunken
4410                                             ? MO_NONE==opts.coloredMouseOver && !opts.crHighlight && mo
4411                                                 ? use[CR_MO_FILL]
4412                                                 : palette.base().color()
4413                                             : palette.background().color());
4414                     bool         lightBorder=DRAW_LIGHT_BORDER(false, WIDGET_TROUGH, APPEARANCE_INVERTED);
4415 
4416                     rect=QRect(doEtch ? rect.adjusted(1, 1, -1, -1) : rect);
4417 
4418                     if(qtcIsFlat(opts.appearance))
4419                         painter->fillRect(rect.adjusted(1, 1, -1, -1), bgnd);
4420                     else
4421                         drawBevelGradient(bgnd, painter, rect.adjusted(1, 1, -1, -1), true, false, APPEARANCE_INVERTED, WIDGET_TROUGH);
4422 
4423                     if(MO_NONE!=opts.coloredMouseOver && !glow && mo)
4424                     {
4425                         painter->setRenderHint(QPainter::Antialiasing, true);
4426                         painter->setPen(use[CR_MO_FILL]);
4427                         drawAaRect(painter, rect.adjusted(1, 1, -1, -1));
4428                         painter->setRenderHint(QPainter::Antialiasing, false);
4429                     }
4430                     else
4431                     {
4432                         painter->setPen(midColor(state&State_Enabled ? palette.base().color()
4433                                                                     : palette.background().color(), use[3]));
4434                         if(lightBorder)
4435                             drawRect(painter, rect.adjusted(1, 1, -1, -1));
4436                         else
4437                         {
4438                             painter->drawLine(rect.x()+1, rect.y()+1, rect.x()+1, rect.y()+rect.height()-2);
4439                             painter->drawLine(rect.x()+1, rect.y()+1, rect.x()+rect.width()-2, rect.y()+1);
4440                         }
4441                     }
4442 
4443                     if(doEtch && !view)
4444                     {
4445                         if(glow && !(opts.thin&THIN_FRAMES))
4446                             drawGlow(painter, r, WIDGET_CHECKBOX);
4447                         else
4448                             drawEtch(painter, r, widget, WIDGET_CHECKBOX, opts.crButton && EFFECT_SHADOW==opts.buttonEffect ? !sunken : false);
4449                     }
4450 
4451                     drawBorder(painter, rect, option, ROUNDED_ALL, use, WIDGET_CHECKBOX);
4452                 }
4453             }
4454 
4455             if(state&State_On || selectedOOMenu)
4456             {
4457                 // widget can be NULL in LibreOffice: see http://crashreport.libreoffice.org/stats/signature/qtcurve.so
4458                 // In a pure Qt build we don't really have a way of knowing what font to use without a widget,
4459                 // but in a KDE build we can use KGlobalSettings::menuFont()
4460                 if (onlyTicksInMenu
4461 #ifndef QTC_QT4_ENABLE_KDE
4462                     && widget
4463 #endif
4464                 ) {
4465                     // only tickmarks (= without the box) in menu; adjust its horizontal position
4466                     rect.adjust(6, 0, 0, 0);
4467                     // get the font for adjusting; widget will be the menu holding the menuitem
4468                     // but that uses the same font as the menuitem.
4469 #ifdef QTC_QT4_ENABLE_KDE
4470                     QFont font(widget ? widget->font() : KGlobalSettings::menuFont());
4471 #else
4472                     QFont font(widget->font());
4473 #endif
4474 #ifndef Q_OS_MAC
4475                     font.setBold(true);
4476 #else
4477                     // not that there is much variation in the CheckMark symbol on OS X, but
4478                     // we pick one from a font that's always supposed to be there and that's
4479                     // a good choice functionally speaking.
4480                     font.setFamily("Apple Symbols");
4481 #endif
4482                     // adjust the size so the tickmark looks just about right
4483                     font.setPointSizeF(font.pointSizeF() * 1.3);
4484                     painter->save();
4485                     painter->setFont(font);
4486                     // render the tickmark using the Unicode "Check Mark" symbol (✓)
4487                     drawItemTextWithRole(painter, rect, Qt::AlignHCenter|Qt::AlignVCenter, palette, true,
4488                                      QString(QChar(0x2713)), QPalette::Text);
4489                     painter->restore();
4490                 }
4491                 else
4492                 {
4493                         QPixmap *pix(getPixmap(checkRadioCol(option), PIX_CHECK, 1.0));
4494                         painter->drawPixmap(rect.center().x()-(pix->width()/2), rect.center().y()-(pix->height()/2), *pix);
4495                 }
4496             }
4497             else if (state&State_NoChange)    // tri-state
4498             {
4499                 int x(rect.center().x()), y(rect.center().y());
4500 
4501                 painter->setPen(checkRadioCol(option));
4502                 painter->drawLine(x-3, y, x+3, y);
4503                 painter->drawLine(x-3, y+1, x+3, y+1);
4504             }
4505 
4506             painter->restore();
4507             break;
4508         }
4509         case PE_Q3CheckListExclusiveIndicator:
4510             if (auto lv = styleOptCast<QStyleOptionQ3ListView>(option)) {
4511                 if(lv->items.isEmpty())
4512                     break;
4513 
4514                 QStyleOptionQ3ListViewItem item(lv->items.at(0));
4515                 int                        x(lv->rect.x()),
4516                                            w(lv->rect.width()),
4517                                            marg(lv->itemMargin);
4518 
4519                 if (state & State_Selected && !lv->rootIsDecorated && !(item.features & QStyleOptionQ3ListViewItem::ParentControl))
4520                     painter->fillRect(0, 0, x + marg + w + 4, item.height, palette.brush(QPalette::Highlight));
4521             }
4522 
4523             r.setX(r.x()+((r.width()-opts.crSize)/2)-1);
4524             r.setY(r.y()+((r.height()-opts.crSize)/2)-1);
4525             r.setWidth(opts.crSize);
4526             r.setHeight(opts.crSize);
4527             QTC_FALLTHROUGH();
4528         case PE_IndicatorRadioButton:
4529         {
4530             bool isOO(isOOWidget(widget)),
4531                  selectedOOMenu(isOO && (r==QRect(0, 0, 15, 15) || r==QRect(0, 0, 14, 15)) &&  // OO.o 3.2 =14x15?
4532                                 ((State_Sunken|State_Enabled)==state || (State_Sunken|State_Enabled|State_Selected)==state));
4533 
4534             if(isOO)
4535                 painter->fillRect(r, palette.brush(QPalette::Background));
4536 
4537             if(selectedOOMenu)
4538                 drawPrimitive(PE_IndicatorCheckBox, option, painter, widget);
4539             else
4540             {
4541                 bool menu(state&STATE_MENU);
4542                 int  x(r.x()), y(r.y());
4543 
4544                 painter->save();
4545 
4546                 if(opts.crButton)
4547                 {
4548                     const QColor *use(checkRadioColors(option));
4549                     QStyleOption opt(*option);
4550                     bool         doEtch(opts.buttonEffect != EFFECT_NONE);
4551                     QRect        rect(r.x(), r.y(), opts.crSize+(doEtch ? 2 : 0), opts.crSize+(doEtch ? 2 : 0));
4552 
4553                     if(CR_SMALL_SIZE!=opts.crSize && menu)
4554                         rect.adjust(0, -1, 0, -1), y++;
4555 
4556                     if(isOO && r==QRect(0, 0, opts.crSize, opts.crSize))
4557                         rect.adjust(-1, -1, -1, -1), --x, --y;
4558 
4559                     if(menu || selectedOOMenu)
4560                         opt.state&=~(State_MouseOver|State_Sunken);
4561                     opt.state&=~State_On;
4562                     opt.state|=State_Raised;
4563                     opt.rect=rect;
4564 
4565                     if(doEtch)
4566                         x++, y++;
4567                     if(CR_SMALL_SIZE!=opts.crSize && menu)
4568                         y-=2;
4569 
4570                     drawLightBevel(painter, rect, &opt, widget, ROUNDED_ALL, getFill(&opt, use, true, false), use, true, WIDGET_RADIO_BUTTON);
4571                 }
4572                 else
4573                 {
4574                     bool         sunken(!menu && !selectedOOMenu && (state&State_Sunken)),
4575                                  doEtch(!menu
4576                                         && r.width()>=opts.crSize+2 && r.height()>=opts.crSize+2
4577                                         && opts.buttonEffect != EFFECT_NONE),
4578                                  mo(!sunken && state&State_MouseOver && state&State_Enabled),
4579                                  glow(doEtch && MO_GLOW==opts.coloredMouseOver && mo),
4580                                  coloredMo(MO_NONE!=opts.coloredMouseOver && !glow && mo && !sunken);
4581                     bool         lightBorder=DRAW_LIGHT_BORDER(false, WIDGET_TROUGH, APPEARANCE_INVERTED),
4582                                  doneShadow=false;
4583                     QRect        rect(doEtch ? r.adjusted(1, 1, -1, -1) : r);
4584                     const QColor *bc(sunken ? 0L : borderColors(option, 0L)),
4585                                  *btn(checkRadioColors(option)),
4586                                  *use(bc ? bc : btn);
4587 
4588                     if(doEtch)
4589                         x++, y++;
4590 
4591                     const QColor &bgnd(state&State_Enabled && !sunken
4592                                             ? MO_NONE==opts.coloredMouseOver && !opts.crHighlight && mo
4593                                                 ? use[CR_MO_FILL]
4594                                                 : palette.base().color()
4595                                             : palette.background().color());
4596                     QPainterPath path;
4597 
4598                     path.addEllipse(QRectF(rect).adjusted(0.5, 0.5, -1.0, -1.0));
4599                     drawBevelGradient(bgnd, painter, rect.adjusted(1, 1, -1, -1), path, true, false, APPEARANCE_INVERTED, WIDGET_TROUGH);
4600                     painter->setRenderHint(QPainter::Antialiasing, true);
4601                     if(coloredMo)
4602                     {
4603                         painter->setBrush(Qt::NoBrush);
4604                         painter->setPen(use[CR_MO_FILL]);
4605                         painter->drawArc(QRectF(x+1, y+1, opts.crSize-2, opts.crSize-2), 0, 360*16);
4606                         painter->drawArc(QRectF(x+2, y+2, opts.crSize-4, opts.crSize-4), 0, 360*16);
4607                     }
4608 
4609                     painter->setBrush(Qt::NoBrush);
4610                     if(!doneShadow && doEtch && (glow || EFFECT_NONE!=opts.buttonEffect || sunken))
4611                     {
4612                         QColor topCol(glow ? m_mouseOverCols[GLOW_MO] : Qt::black);
4613 
4614                         if(!glow)
4615                             topCol.setAlphaF(ETCH_RADIO_TOP_ALPHA);
4616 
4617                         painter->setPen(topCol);
4618                         painter->drawArc(QRectF(x-0.5, y-0.5, opts.crSize+1, opts.crSize+1), 45*16, 180*16);
4619                         if(!glow)
4620                             painter->setPen(getLowerEtchCol(widget));
4621                         painter->drawArc(QRectF(x-0.5, y-0.5, opts.crSize+1, opts.crSize+1), 225*16, 180*16);
4622                     }
4623 
4624                     painter->setPen(use[BORDER_VAL(state&State_Enabled)]);
4625                     painter->drawArc(QRectF(x+0.25, y+0.25, opts.crSize-0.5, opts.crSize-0.5), 0, 360*16);
4626                     if(!coloredMo)
4627                     {
4628                         painter->setPen(btn[state&State_MouseOver ? 3 : 4]);
4629                         painter->drawArc(QRectF(x+0.75, y+0.75, opts.crSize-1.5, opts.crSize-1.5), lightBorder ? 0 : 45*16, lightBorder ? 360*16 : 180*16);
4630                     }
4631                 }
4632                 if(state&State_On || selectedOOMenu)
4633                 {
4634                     QPainterPath path;
4635                     double       radius=opts.smallRadio ? 2.75 : 3.75,
4636                                 offset=(opts.crSize/2.0)-radius;
4637 
4638                     path.addEllipse(QRectF(x+offset, y+offset, radius*2.0, radius*2.0));
4639                     painter->setRenderHint(QPainter::Antialiasing, true);
4640                     painter->fillPath(path, checkRadioCol(option));
4641                 }
4642 
4643                 painter->restore();
4644             }
4645             break;
4646         }
4647         case PE_IndicatorToolBarHandle:
4648             painter->save();
4649             drawHandleMarkers(painter, r, option, true, opts.handles);
4650             painter->restore();
4651             break;
4652         case PE_FrameFocusRect:
4653             if (FOCUS_NONE==opts.focus)
4654                 return;
4655             if (auto focusFrame = styleOptCast<QStyleOptionFocusRect>(option)) {
4656                 if (!(focusFrame->state&State_KeyboardFocusChange) ||
4657                     (widget && widget->inherits("QComboBoxListView")))
4658                     return;
4659 
4660                 if(widget && FOCUS_GLOW==opts.focus)
4661                 {
4662                     if(qobject_cast<const QAbstractButton*>(widget))
4663                     {
4664                         if(!qobject_cast<const QToolButton*>(widget) || !static_cast<const QToolButton*>(widget)->autoRaise())
4665                             return;
4666                     }
4667                     else if(qobject_cast<const QComboBox*>(widget) || qobject_cast<const QGroupBox*>(widget) ||
4668                             qobject_cast<const QDial*>(widget))
4669                         return;
4670                 }
4671 
4672                 QRect r2(r);
4673 
4674                 if(widget && (qobject_cast<const QCheckBox*>(widget) || qobject_cast<const QRadioButton*>(widget)) &&
4675                    ((QAbstractButton*)widget)->text().isEmpty() && r.height()<=widget->rect().height()-2 && r.width()<=widget->rect().width()-2 &&
4676                    r.x()>=1 && r.y()>=1)
4677                 {
4678                     int adjust=qMin(qMin(abs(widget->rect().x()-r.x()), 2), abs(widget->rect().y()-r.y()));
4679                     r2.adjust(-adjust, -adjust, adjust, adjust);
4680                 }
4681 
4682                 if(widget && qobject_cast<const QGroupBox*>(widget))
4683                    r2.adjust(0, 2, 0, 0);
4684 
4685                 if(FOCUS_STANDARD==opts.focus)
4686                 {
4687                     // Taken from QWindowsStyle...
4688                     painter->save();
4689                     painter->setBackgroundMode(Qt::TransparentMode);
4690                     QColor bgCol(focusFrame->backgroundColor);
4691                     if (!bgCol.isValid())
4692                         bgCol = painter->background().color();
4693                     // Create an "XOR" color.
4694                     QColor patternCol((bgCol.red() ^ 0xff) & 0xff,
4695                                       (bgCol.green() ^ 0xff) & 0xff,
4696                                       (bgCol.blue() ^ 0xff) & 0xff);
4697                     painter->setBrush(QBrush(patternCol, Qt::Dense4Pattern));
4698                     painter->setBrushOrigin(r.topLeft());
4699                     painter->setPen(Qt::NoPen);
4700                     painter->drawRect(r.left(), r.top(), r.width(), 1);    // Top
4701                     painter->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom
4702                     painter->drawRect(r.left(), r.top(), 1, r.height());   // Left
4703                     painter->drawRect(r.right(), r.top(), 1, r.height());  // Right
4704                     painter->restore();
4705                 }
4706                 else
4707                 {
4708                     //Figuring out in what beast we are painting...
4709                     bool view(state&State_Item ||
4710                               ((widget && ((qobject_cast<const QAbstractScrollArea*>(widget)) ||
4711                                         widget->inherits("Q3ScrollView"))) ||
4712                                          (widget && widget->parent() &&
4713                                             ((qobject_cast<const QAbstractScrollArea*>(widget->parent())) ||
4714                                               widget->parent()->inherits("Q3ScrollView")))) );
4715 
4716                     if(!view && !widget)
4717                     {
4718                         // Try to determine if we are in a KPageView...
4719                         const QWidget *wid=getWidget(painter);
4720 
4721                         if(wid && wid->parentWidget())
4722                         {
4723                             if(wid->parentWidget()->inherits("KDEPrivate::KPageListView"))
4724                             {
4725                                 r2.adjust(2, 2, -2, -2);
4726                                 view=true;
4727                             }
4728                             else if(APP_KONTACT==theThemedApp && (wid->parentWidget()->inherits("KMail::MainFolderView") ||
4729                                                                   wid->parentWidget()->inherits("MessageList::Core::View")))
4730                             {
4731                                 view=true;
4732                             }
4733                         }
4734                     }
4735                     painter->save();
4736                     QColor c(view && state&State_Selected
4737                                   ? palette.highlightedText().color()
4738                                   : m_focusCols[FOCUS_SHADE(state&State_Selected)]);
4739 
4740                     if(FOCUS_LINE==opts.focus || FOCUS_GLOW==opts.focus)
4741                     {
4742                         if(!(state&State_Horizontal) && widget && qobject_cast<const QTabBar*>(widget))
4743                             drawFadedLine(painter, QRect(r2.x()+r2.width()-1, r2.y(), 1, r2.height()), c, true, true, false);
4744                         else
4745                             drawFadedLine(painter, QRect(r2.x(), r2.y()+r2.height()-(view ? 3 : 1), r2.width(), 1), c, true, true, true);
4746                     }
4747                     else
4748                     {
4749                         //if(FOCUS_GLOW==opts.focus)
4750                         //    c.setAlphaF(FOCUS_GLOW_LINE_ALPHA);
4751                         painter->setPen(c);
4752                         if(FOCUS_FILLED==opts.focus)
4753                         {
4754                             c.setAlphaF(FOCUS_ALPHA);
4755                             painter->setBrush(c);
4756                         }
4757 
4758                         if (opts.round != ROUND_NONE) {
4759                             bool square((opts.square&SQUARE_LISTVIEW_SELECTION) &&
4760                                         ((/*(!widget && r.height()<=40 && r.width()>=48) || */
4761                                           (widget && !widget->inherits("KFilePlacesView") &&
4762                                           (qobject_cast<const QTreeView*>(widget) ||
4763                                             (qobject_cast<const QListView*>(widget) &&
4764                                              QListView::IconMode!=((const QListView*)widget)->viewMode())))) ||
4765                                           (!widget && view) ) );
4766 
4767                             painter->setRenderHint(QPainter::Antialiasing, true);
4768                             painter->drawPath(buildPath(r2, WIDGET_SELECTION, ROUNDED_ALL,
4769                                                         square ? SLIGHT_INNER_RADIUS : qtcGetRadius(&opts, r2.width(), r2.height(), WIDGET_OTHER,
4770                                                                                                     oneOf(opts.focus, FOCUS_FULL, FOCUS_FILLED) ? RADIUS_EXTERNAL : RADIUS_SELECTION)));
4771                         }
4772                         else
4773                             drawRect(painter, r2);
4774                     }
4775                     painter->restore();
4776                 }
4777             }
4778             break;
4779         case PE_FrameButtonBevel:
4780         case PE_PanelButtonBevel:
4781         case PE_PanelButtonCommand:
4782         {
4783             if(state&STATE_DWT_BUTTON && (opts.dwtSettings&DWT_BUTTONS_AS_PER_TITLEBAR))
4784                 break;
4785 
4786             bool doEtch = opts.buttonEffect != EFFECT_NONE;
4787 
4788             // This fixes the "Sign in" button at mail.lycos.co.uk
4789             // ...basically if KHTML gices us a fully transparent background colour, then
4790             // dont paint the button.
4791             if(0==option->palette.button().color().alpha())
4792             {
4793                 if(state&State_MouseOver && state&State_Enabled && MO_GLOW==opts.coloredMouseOver && doEtch && !(opts.thin&THIN_FRAMES))
4794                     drawGlow(painter, r, WIDGET_STD_BUTTON);
4795                 return;
4796             }
4797 
4798             if(!widget)
4799                 widget=getWidget(painter);
4800 
4801             const QColor *use(buttonColors(option));
4802             bool         isDefault(false),
4803                          isFlat(false),
4804                          isKWin(state&QtC_StateKWin),
4805                          isDown(state&State_Sunken || state&State_On),
4806                          isOnListView(!isKWin && widget && qobject_cast<const QAbstractItemView*>(widget));
4807             QStyleOption opt(*option);
4808 
4809             if(PE_PanelButtonBevel==element)
4810                 opt.state|=State_Enabled;
4811 
4812             if (auto button = styleOptCast<QStyleOptionButton>(option)) {
4813                 isDefault = (button->features & QStyleOptionButton::DefaultButton) && (button->state&State_Enabled);
4814                 isFlat = (button->features & QStyleOptionButton::Flat);
4815             }
4816 
4817             if(!(opt.state&State_Enabled))
4818                 opt.state&=~State_MouseOver;
4819 
4820             // For some reason with OO.o not all buttons are set as raised!
4821             if(!(opt.state&State_AutoRaise))
4822                 opt.state|=State_Raised;
4823 
4824             isDefault = (isDefault ||
4825                          (doEtch && opts.coloredMouseOver == MO_GLOW &&
4826                           oneOf(opts.focus, FOCUS_FULL, FOCUS_FILLED) &&
4827                           opt.state & State_HasFocus &&
4828                           opt.state & State_Enabled));
4829             if(isFlat && !isDown && !(opt.state&State_MouseOver))
4830                 return;
4831 
4832             painter->save();
4833 
4834             if(isOnListView)
4835                 opt.state|=State_Horizontal|State_Raised;
4836 
4837             if(isDefault && state&State_Enabled && (IND_TINT==opts.defBtnIndicator || IND_SELECTED==opts.defBtnIndicator))
4838                 use=m_defBtnCols;
4839             else if(state&STATE_DWT_BUTTON && widget && opts.titlebarButtons&TITLEBAR_BUTTON_COLOR &&
4840                     coloredMdiButtons(state&State_Active, state&State_MouseOver) &&
4841                     !(opts.titlebarButtons&TITLEBAR_BUTTON_COLOR_SYMBOL))
4842             {
4843                 if(constDwtClose==widget->objectName())
4844                     use=m_titleBarButtonsCols[TITLEBAR_CLOSE];
4845                 else if (constDwtFloat==widget->objectName()) {
4846                     use=m_titleBarButtonsCols[TITLEBAR_MAX];
4847                 } else if (qtcCheckType<QDockWidget>(getParent<2>(widget)) &&
4848                            getParent(widget)
4849                            ->inherits("KoDockWidgetTitleBar")) {
4850                     QDockWidget *dw = (QDockWidget*)getParent<2>(widget);;
4851                     QWidget *koDw = widget->parentWidget();
4852                     int fw = (dw->isFloating() ?
4853                               pixelMetric(QStyle::PM_DockWidgetFrameWidth,
4854                                           0, dw) : 0);
4855                     QRect geom(widget->geometry());
4856                     QStyleOptionDockWidgetV2 dwOpt;
4857                     dwOpt.initFrom(dw);
4858                     dwOpt.rect = QRect(QPoint(fw, fw), QSize(koDw->geometry().width() - (fw * 2),
4859                                                              koDw->geometry().height() - (fw * 2)));
4860                     dwOpt.title = dw->windowTitle();
4861                     dwOpt.closable = (dw->features()&QDockWidget::DockWidgetClosable)==QDockWidget::DockWidgetClosable;
4862                     dwOpt.floatable = (dw->features()&QDockWidget::DockWidgetFloatable)==QDockWidget::DockWidgetFloatable;
4863 
4864                     if(dwOpt.closable &&
4865                        subElementRect(QStyle::SE_DockWidgetCloseButton, &dwOpt,
4866                                       getParent(widget)) == geom)
4867                         use=m_titleBarButtonsCols[TITLEBAR_CLOSE];
4868                     else if(dwOpt.floatable &&
4869                        subElementRect(QStyle::SE_DockWidgetFloatButton, &dwOpt,
4870                                       getParent(widget)) == geom)
4871                         use=m_titleBarButtonsCols[TITLEBAR_MAX];
4872                     else
4873                         use=m_titleBarButtonsCols[TITLEBAR_SHADE];
4874                 }
4875             }
4876 
4877             if(isKWin)
4878                 opt.state|=STATE_KWIN_BUTTON;
4879 
4880             bool coloredDef=isDefault && state&State_Enabled && IND_COLORED==opts.defBtnIndicator;
4881 
4882             if(widget && qobject_cast<const QAbstractButton*>(widget) && (static_cast<const QAbstractButton*>(widget))->isCheckable())
4883                 opt.state|=STATE_TOGGLE_BUTTON;
4884 
4885             drawLightBevel(painter, r, &opt, widget, ROUNDED_ALL,
4886                            coloredDef ? m_defBtnCols[MO_DEF_BTN]
4887                                       : getFill(&opt, use, false,
4888                                                 isDefault && state&State_Enabled && IND_DARKEN==opts.defBtnIndicator),
4889                            coloredDef ? m_defBtnCols : use,
4890                            true, isKWin || state&STATE_DWT_BUTTON
4891                                     ? WIDGET_MDI_WINDOW_BUTTON
4892                                     : isOnListView
4893                                         ? WIDGET_NO_ETCH_BTN
4894                                         : isDefault && state&State_Enabled
4895                                             ? WIDGET_DEF_BUTTON
4896                                             : state&STATE_TBAR_BUTTON
4897                                                 ? WIDGET_TOOLBAR_BUTTON
4898                                                 : WIDGET_STD_BUTTON);
4899 
4900             if (isDefault && state&State_Enabled)
4901                 switch(opts.defBtnIndicator)
4902                 {
4903                     case IND_CORNER:
4904                     {
4905                         QPainterPath path;
4906                         int          offset(isDown ? 5 : 4),
4907                                      etchOffset(doEtch ? 1 : 0);
4908                         double       xd(r.x()+0.5),
4909                                      yd(r.y()+0.5);
4910                         const QColor *cols = m_focusCols;
4911                         // Was:
4912                         // const QColor *cols = (m_focusCols ? m_focusCols :
4913                         //                       m_highlightCols);
4914                         // which is always m_focusCols
4915 
4916                         path.moveTo(xd+offset+etchOffset, yd+offset+etchOffset);
4917                         path.lineTo(xd+offset+6+etchOffset, yd+offset+etchOffset);
4918                         path.lineTo(xd+offset+etchOffset, yd+offset+6+etchOffset);
4919                         path.lineTo(xd+offset+etchOffset, yd+offset+etchOffset);
4920                         painter->setBrush(cols[isDown ? 0 : 4]);
4921                         painter->setPen(cols[isDown ? 0 : 4]);
4922                         painter->setRenderHint(QPainter::Antialiasing, true);
4923                         painter->drawPath(path);
4924                         painter->setRenderHint(QPainter::Antialiasing, false);
4925                         break;
4926                     }
4927                     case IND_COLORED:
4928                     {
4929                         int   offset=COLORED_BORDER_SIZE+(doEtch ? 1 : 0);
4930                         QRect r2(r.adjusted(offset, offset, -offset, -offset));
4931 
4932                         drawBevelGradient(getFill(&opt, use), painter, r2, true, state &(State_On | State_Sunken), opts.appearance, WIDGET_STD_BUTTON);
4933                     }
4934                     default:
4935                         break;
4936                 }
4937             painter->restore();
4938             break;
4939         }
4940         case PE_FrameDefaultButton:
4941             break;
4942         case PE_FrameWindow:
4943         {
4944             bool         colTbarOnly=opts.windowBorder&WINDOW_BORDER_COLOR_TITLEBAR_ONLY,
4945                          fillBgnd=!(state&QtC_StateKWin) && !m_isPreview && !qtcIsFlatBgnd(opts.bgndAppearance);
4946             const QColor *bgndCols(colTbarOnly || fillBgnd ? backgroundColors(palette.color(QPalette::Active, QPalette::Window)) : 0L),
4947                          *borderCols(colTbarOnly
4948                                         ? bgndCols
4949                                         : theThemedApp==APP_KWIN
4950                                             ? buttonColors(option)
4951                                             : getMdiColors(option, state&State_Active));
4952             QColor       light(borderCols[0]),
4953                          dark(option->version==(TBAR_BORDER_VERSION_HACK+2)
4954                                 ? palette.color(QPalette::Active, QPalette::Shadow)
4955                                 : borderCols[option && option->version==TBAR_BORDER_VERSION_HACK ? 0 : QTC_STD_BORDER]);
4956             bool         isKWin=state&QtC_StateKWin,
4957                          addLight=opts.windowBorder&WINDOW_BORDER_ADD_LIGHT_BORDER && (!isKWin || qtcGetWindowBorderSize(false).sides>1);
4958 
4959             light.setAlphaF(1.0);
4960             dark.setAlphaF(1.0);
4961 
4962             painter->save();
4963 
4964             if(fillBgnd)
4965                 painter->fillRect(r, bgndCols[ORIGINAL_SHADE]);
4966             if(opts.round<ROUND_SLIGHT || !isKWin || (state&QtC_StateKWinNotFull && state&QtC_StateKWin))
4967             {
4968                 painter->setRenderHint(QPainter::Antialiasing, false);
4969 
4970                 if(addLight)
4971                 {
4972                     painter->setPen(light);
4973                     painter->drawLine(r.x()+1, r.y(), r.x()+1, r.y()+r.height()-1);
4974                 }
4975                 painter->setPen(dark);
4976                 drawRect(painter, r);
4977             }
4978             else
4979             {
4980                 if(addLight)
4981                 {
4982                     painter->setRenderHint(QPainter::Antialiasing, false);
4983                     painter->setPen(light);
4984                     painter->drawLine(r.x()+1, r.y(), r.x()+1, r.y()+r.height()-(1+(opts.round>ROUND_SLIGHT && state&QtC_StateKWin ? 3 : 1)));
4985                 }
4986                 painter->setRenderHint(QPainter::Antialiasing, true);
4987                 painter->setPen(dark);
4988                 painter->drawPath(buildPath(r, WIDGET_OTHER, ROUNDED_ALL,
4989                                             opts.round>ROUND_SLIGHT && state&QtC_StateKWin
4990                                                 ? 6.0
4991                                                 : 2.0));
4992 
4993                 if (opts.round >= ROUND_FULL &&
4994                     !(state & QtC_StateKWinCompositing)) {
4995                     QColor col(opts.windowBorder&WINDOW_BORDER_COLOR_TITLEBAR_ONLY
4996                                 ? backgroundColors(option)[QTC_STD_BORDER]
4997                                 : buttonColors(option)[QTC_STD_BORDER]);
4998 
4999                     painter->setRenderHint(QPainter::Antialiasing, false);
5000                     painter->setPen(col);
5001                     painter->drawPoint(r.x()+2, r.y()+r.height()-3);
5002                     painter->drawPoint(r.x()+r.width()-3, r.y()+r.height()-3);
5003                     painter->drawLine(r.x()+1, r.y()+r.height()-5, r.x()+1, r.y()+r.height()-4);
5004                     painter->drawLine(r.x()+3, r.y()+r.height()-2, r.x()+4, r.y()+r.height()-2);
5005                     painter->drawLine(r.x()+r.width()-2, r.y()+r.height()-5, r.x()+r.width()-2, r.y()+r.height()-4);
5006                     painter->drawLine(r.x()+r.width()-4, r.y()+r.height()-2, r.x()+r.width()-5, r.y()+r.height()-2);
5007                 }
5008             }
5009             painter->restore();
5010             break;
5011         }
5012         case PE_FrameTabWidget:
5013         {
5014             int round(opts.square&SQUARE_TAB_FRAME ? ROUNDED_NONE : ROUNDED_ALL);
5015 
5016             painter->save();
5017 
5018             if (auto twf = styleOptCast<QStyleOptionTabWidgetFrame>(option))
5019                 if((opts.round || (/*qtcIsCustomBgnd(opts) && */0==opts.tabBgnd)) &&
5020                     widget && qobject_cast<const QTabWidget*>(widget))
5021                 {
5022                     struct QtcTabWidget : public QTabWidget
5023                     {
5024                         bool  tabsVisible()    const { return tabBar() && tabBar()->isVisible(); }
5025                         QRect currentTabRect() const { return tabBar()->tabRect(tabBar()->currentIndex()); }
5026                     };
5027 
5028                     const QTabWidget *tw((const QTabWidget*)widget);
5029 
5030                     if(tw->count()>0 && ((const QtcTabWidget*)widget)->tabsVisible())
5031                     {
5032                         if(!reverse && /*qtcIsCustomBgnd(opts) && */0==opts.tabBgnd) // Does not work for reverse :-(
5033                         {
5034                             QRect tabRect(((const QtcTabWidget*)widget)->currentTabRect());
5035                             int   adjust(TAB_MO_GLOW==opts.tabMouseOver && !(opts.thin&THIN_FRAMES) ? 2 : 1);
5036 
5037                             switch(tw->tabPosition())
5038                             {
5039                                 case QTabWidget::South:
5040                                     tabRect=QRect(tabRect.x()+adjust, r.y()+r.height()-2, tabRect.width()-(2*adjust), 4);
5041                                     break;
5042                                 case QTabWidget::North:
5043                                 {
5044                                     int leftAdjust=twf->leftCornerWidgetSize.width()>0 ? twf->leftCornerWidgetSize.width() : 0;
5045                                     tabRect.adjust(leftAdjust+adjust, 0, leftAdjust-adjust, 2);
5046                                     break;
5047                                 }
5048                                 case QTabWidget::West:
5049                                     tabRect.adjust(0, adjust, 2, -adjust);
5050                                     break;
5051                                 case QTabWidget::East:
5052                                     tabRect=QRect(r.x()+r.width()-2, tabRect.y()+adjust, 4, tabRect.height()-(2*adjust));
5053                                     break;
5054                             }
5055 
5056                             painter->setClipRegion(QRegion(r).subtract(tabRect), Qt::IntersectClip);
5057                         }
5058 
5059                         if(!(opts.square&SQUARE_TAB_FRAME) && 0==tw->currentIndex())
5060                         {
5061                             bool reverse(Qt::RightToLeft==twf->direction);
5062 
5063                             switch(tw->tabPosition())
5064                             {
5065                                 case QTabWidget::North:
5066                                     if(reverse && twf->rightCornerWidgetSize.isEmpty())
5067                                         round-=CORNER_TR;
5068                                     else if(!reverse && twf->leftCornerWidgetSize.isEmpty())
5069                                         round-=CORNER_TL;
5070                                     break;
5071                                 case QTabWidget::South:
5072                                     if(reverse && twf->rightCornerWidgetSize.isEmpty())
5073                                         round-=CORNER_BR;
5074                                     else if(!reverse && twf->leftCornerWidgetSize.isEmpty())
5075                                         round-=CORNER_BL;
5076                                     break;
5077                                 case QTabWidget::West:
5078                                     round-=CORNER_TL;
5079                                     break;
5080                                 case QTabWidget::East:
5081                                     round-=CORNER_TR;
5082                                     break;
5083                             }
5084                         }
5085                     }
5086                 }
5087 
5088             QStyleOption opt(*option);
5089             const QColor *use=backgroundColors(option);
5090 
5091             opt.state|=State_Enabled;
5092             if(0!=opts.tabBgnd)
5093             {
5094                 QColor bgnd(shade(use[ORIGINAL_SHADE], TO_FACTOR(opts.tabBgnd)));
5095 
5096                 painter->fillRect(r.adjusted(0, 1, 0, -1), bgnd);
5097                 painter->fillRect(r.adjusted(1, 0, -1, 0), bgnd);
5098             }
5099             drawBorder(painter, r, &opt, round, use, WIDGET_TAB_FRAME, opts.borderTab ? BORDER_LIGHT : BORDER_RAISED, false);
5100             painter->restore();
5101             break;
5102         }
5103         case PE_PanelItemViewItem: {
5104             auto v4Opt = styleOptCast<QStyleOptionViewItemV4>(option);
5105             const QAbstractItemView *view = qobject_cast<const QAbstractItemView*>(widget);
5106             bool                         hover = state&State_MouseOver && state&State_Enabled && (!view ||
5107                                                  QAbstractItemView::NoSelection!=view->selectionMode()),
5108                                          hasCustomBackground = v4Opt->backgroundBrush.style() != Qt::NoBrush &&
5109                                                                !(option->state & State_Selected),
5110                                          hasSolidBackground = !hasCustomBackground || Qt::SolidPattern==v4Opt->backgroundBrush.style();
5111 
5112             if (!hover && !(state & State_Selected) && !hasCustomBackground &&
5113                 !(v4Opt->features & QStyleOptionViewItemV2::Alternate))
5114                 break;
5115 
5116             QPalette::ColorGroup cg(state&State_Enabled
5117                                         ? state&State_Active
5118                                             ? QPalette::Normal
5119                                             : QPalette::Inactive
5120                                         : QPalette::Disabled);
5121 
5122             if (v4Opt && (v4Opt->features & QStyleOptionViewItemV2::Alternate))
5123                 painter->fillRect(r, option->palette.brush(cg, QPalette::AlternateBase));
5124 
5125             if (!hover && !(state&State_Selected) && !hasCustomBackground)
5126                 break;
5127 
5128             if (hasCustomBackground) {
5129                 painter->save();
5130                 painter->setBrushOrigin(r.topLeft());
5131                 painter->fillRect(r, v4Opt->backgroundBrush);
5132                 painter->restore();
5133             }
5134 
5135             if(state&State_Selected || hover)
5136             {
5137                 if(!widget)
5138                 {
5139                     widget=getWidget(painter);
5140                     if(widget)
5141                         widget=widget->parentWidget();
5142                 }
5143 
5144                 QColor color(hasCustomBackground && hasSolidBackground
5145                                 ? v4Opt->backgroundBrush.color()
5146                                 : palette.color(cg, QPalette::Highlight));
5147                 bool   square((opts.square&SQUARE_LISTVIEW_SELECTION) &&
5148                               (/*(!widget && r.height()<=40 && r.width()>=48) || */
5149                                (widget && !widget->inherits("KFilePlacesView") &&
5150                                 (qobject_cast<const QTreeView*>(widget) ||
5151                                   (qobject_cast<const QListView*>(widget) &&
5152                                   QListView::IconMode!=((const QListView*)widget)->viewMode()))))),
5153                        modAlpha(!(state&State_Active) && m_inactiveChangeSelectionColor);
5154 
5155                 if (hover && !hasCustomBackground) {
5156                     if (!(state & State_Selected)) {
5157                         color.setAlphaF(theThemedApp == APP_PLASMA && !widget ?
5158                                         0.5 * (modAlpha ? 0.75 : 1.0) : 0.20);
5159                     } else {
5160                         color = color.lighter(110);
5161                         if (modAlpha) {
5162                             color.setAlphaF(INACTIVE_SEL_ALPHA);
5163                         }
5164                     }
5165                 } else if (modAlpha) {
5166                     color.setAlphaF(color.alphaF() * INACTIVE_SEL_ALPHA);
5167                 }
5168 
5169                 if(square)
5170                     drawBevelGradient(color, painter, r, true, false, opts.selectionAppearance, WIDGET_SELECTION);
5171                 else
5172                 {
5173                     QPixmap pix;
5174                     QString key;
5175 
5176                     key.sprintf("qtc-sel-%x-%x", r.height(), color.rgba());
5177                     if(!m_usePixmapCache || !QPixmapCache::find(key, pix))
5178                     {
5179                         pix=QPixmap(QSize(24, r.height()));
5180                         pix.fill(Qt::transparent);
5181 
5182                         QPainter pixPainter(&pix);
5183                         QRect    border(0, 0, pix.width(), pix.height());
5184                         double   radius(qtcGetRadius(&opts, r.width(), r.height(), WIDGET_OTHER, RADIUS_SELECTION));
5185 
5186                         pixPainter.setRenderHint(QPainter::Antialiasing, true);
5187                         drawBevelGradient(color, &pixPainter, border, buildPath(QRectF(border), WIDGET_OTHER, ROUNDED_ALL, radius), true,
5188                                           false, opts.selectionAppearance, WIDGET_SELECTION, false);
5189                         if(opts.borderSelection)
5190                         {
5191                             pixPainter.setBrush(Qt::NoBrush);
5192                             pixPainter.setPen(color);
5193                             pixPainter.drawPath(buildPath(border, WIDGET_SELECTION, ROUNDED_ALL, radius));
5194                         }
5195                         pixPainter.end();
5196                         if(m_usePixmapCache)
5197                             QPixmapCache::insert(key, pix);
5198                     }
5199 
5200                     bool roundedLeft  = false,
5201                          roundedRight = false;
5202 
5203                     if (v4Opt)
5204                     {
5205                         roundedLeft  = (QStyleOptionViewItemV4::Beginning==v4Opt->viewItemPosition);
5206                         roundedRight = (QStyleOptionViewItemV4::End==v4Opt->viewItemPosition);
5207                         if (QStyleOptionViewItemV4::OnlyOne==v4Opt->viewItemPosition ||
5208                             QStyleOptionViewItemV4::Invalid==v4Opt->viewItemPosition ||
5209                             (view && view->selectionBehavior() != QAbstractItemView::SelectRows))
5210                         {
5211                             roundedLeft=roundedRight=true;
5212                         }
5213                     }
5214 
5215                     int size(roundedLeft && roundedRight ? qMin(8, r.width()/2) : 8);
5216 
5217                     if (!reverse ? roundedLeft : roundedRight)
5218                     {
5219                         painter->drawPixmap(r.topLeft(), pix.copy(0, 0, size, r.height()));
5220                         r.adjust(size, 0, 0, 0);
5221                     }
5222                     if (!reverse ? roundedRight : roundedLeft)
5223                     {
5224                         painter->drawPixmap(r.right() - size + 1, r.top(), pix.copy(24-size, 0, size, r.height()));
5225                         r.adjust(0, 0, -size, 0);
5226                     }
5227                     if (r.isValid())
5228                         painter->drawTiledPixmap(r, pix.copy(7, 0, 8, r.height()));
5229                 }
5230             }
5231             break;
5232         }
5233         case QtC_PE_DrawBackground:
5234             if (auto bgnd = styleOptCast<BgndOption>(option))
5235                 if(state&QtC_StateKWin)
5236                 {
5237                     QColor col(palette.brush(QPalette::Window).color());
5238                     int    opacity(col.alphaF()*100);
5239 
5240                     col.setAlphaF(1.0);
5241                     drawBackground(painter, col, r, opacity, BGND_WINDOW, bgnd->app, bgnd->path);
5242                      // APPEARANCE_RAISED is used to signal flat background, but have background image!
5243                     if(APPEARANCE_FLAT!=bgnd->app)
5244                     {
5245                         painter->save();
5246                         painter->setClipRect(bgnd->rect, Qt::IntersectClip);
5247                         drawBackgroundImage(painter, true,
5248                                             (opts.bgndImage.type == IMG_FILE &&
5249                                              opts.bgndImage.onBorder) ?
5250                                             bgnd->rect : bgnd->widgetRect);
5251                         painter->restore();
5252                     }
5253                 }
5254             break;
5255         // TODO: This is the only part left from QWindowsStyle - but I dont think its actually used!
5256         // case PE_IndicatorProgressChunk:
5257         case PE_PanelTipLabel: {
5258             bool haveAlpha = Utils::hasAlphaChannel(widget);
5259             bool rounded = !(opts.square & SQUARE_TOOLTIPS);
5260             QPainterPath path = rounded ? buildPath(QRectF(r), WIDGET_OTHER, ROUNDED_ALL, opts.round >= ROUND_FULL ? 5.0 : 2.5) : QPainterPath();
5261             QColor       col=palette.toolTipBase().color();
5262 
5263             if(widget && widget->window())
5264                 m_shadowHelper->registerWidget(widget->window());
5265             painter->save();
5266             if(rounded)
5267                 painter->setRenderHint(QPainter::Antialiasing, true);
5268             if(haveAlpha)
5269                 col.setAlphaF(0.875);
5270             drawBevelGradient(col, painter, r, path, true, false, opts.tooltipAppearance, WIDGET_TOOLTIP, !haveAlpha);
5271             if(qtcIsFlat(opts.tooltipAppearance))
5272             {
5273                 painter->setPen(QPen(palette.toolTipText(), 0));
5274                 drawRect(painter, r);
5275             }
5276             painter->restore();
5277             break;
5278         }
5279             // Fall through!
5280         default:
5281             BaseStyle::drawPrimitive(element, option, painter, widget);
5282             break;
5283     }
5284 }
5285 
5286 void Style::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
5287 {
5288     prePolish(widget);
5289     QRect               r(option->rect);
5290     const QFlags<State> &state(option->state);
5291     const QPalette      &palette(option->palette);
5292     bool                reverse(Qt::RightToLeft==option->direction);
5293 
5294     switch((unsigned)element)
5295     {
5296         case CE_QtC_SetOptions:
5297             if (auto preview = styleOptCast<PreviewOption>(option)) {
5298                 if(!painter && widget && QLatin1String("QtCurveConfigDialog")==widget->objectName())
5299                 {
5300                     Style *that=(Style*)this;
5301                     opts=preview->opts;
5302                     qtcCheckConfig(&opts);
5303                     that->init(true);
5304                 }
5305             }
5306             break;
5307         case CE_QtC_Preview:
5308             if (auto preview = styleOptCast<PreviewOption>(option)) {
5309                 if(widget && widget && QLatin1String("QtCurveConfigDialog-GradientPreview")==widget->objectName())
5310                 {
5311                     Options      old=opts;
5312                     const QColor *use(buttonColors(option));
5313                     opts=preview->opts;
5314 
5315                     drawLightBevelReal(painter, r, option, widget, ROUNDED_ALL, getFill(option, use, false, false), use,
5316                                        true, WIDGET_STD_BUTTON, false, opts.round, false);
5317                     opts=old;
5318                 }
5319             }
5320             break;
5321         case CE_QtC_KCapacityBar:
5322             if (auto bar = styleOptCast<QStyleOptionProgressBar>(option)) {
5323                 QStyleOptionProgressBar mod(*bar);
5324 
5325                 if(mod.rect.height()>16 && widget->parentWidget() &&
5326                    (qobject_cast<const QStatusBar*>(widget->parentWidget()) ||
5327                     widget->parentWidget()->inherits("DolphinStatusBar")))
5328                 {
5329                     int m=(mod.rect.height()-16)/2;
5330                     mod.rect.adjust(0, m, 0, -m);
5331                 }
5332                 drawControl(CE_ProgressBarGroove, &mod, painter, widget);
5333                 if (opts.buttonEffect != EFFECT_NONE && opts.borderProgress)
5334                     mod.rect.adjust(1, 1, -1, -1);
5335                 drawControl(CE_ProgressBarContents, &mod, painter, widget);
5336                 drawControl(CE_ProgressBarLabel, &mod, painter, widget);
5337             }
5338             break;
5339         case CE_ToolBoxTabShape:
5340         {
5341             auto tb = styleOptCast<QStyleOptionToolBox>(option);
5342             if(!(tb && widget))
5343                 break;
5344 
5345             const QColor *use = backgroundColors(widget->palette().color(QPalette::Window));
5346             QPainterPath path;
5347             int          y = r.height()*15/100;
5348 
5349             painter->save();
5350             if (reverse)
5351             {
5352                 path.moveTo(r.left()+52, r.top());
5353                 path.cubicTo(QPointF(r.left()+50-8, r.top()), QPointF(r.left()+50-10, r.top()+y), QPointF(r.left()+50-10, r.top()+y));
5354                 path.lineTo(r.left()+18+9, r.bottom()-y);
5355                 path.cubicTo(QPointF(r.left()+18+9, r.bottom()-y), QPointF(r.left()+19+6, r.bottom()-1-0.3), QPointF(r.left()+19, r.bottom()-1-0.3));
5356             }
5357             else
5358             {
5359                 path.moveTo(r.right()-52, r.top());
5360                 path.cubicTo(QPointF(r.right()-50+8, r.top()), QPointF(r.right()-50+10, r.top()+y), QPointF(r.right()-50+10, r.top()+y));
5361                 path.lineTo(r.right()-18-9, r.bottom()-y);
5362                 path.cubicTo(QPointF(r.right()-18-9, r.bottom()-y), QPointF(r.right()-19-6, r.bottom()-1-0.3), QPointF(r.right()-19, r.bottom()-1-0.3));
5363             }
5364 
5365             painter->setRenderHint(QPainter::Antialiasing, true);
5366             painter->translate(0, 1);
5367             painter->setPen(use[0]);
5368             painter->drawPath(path);
5369             painter->translate(0, -1);
5370             painter->setPen(use[4]);
5371             painter->drawPath(path);
5372             painter->setRenderHint(QPainter::Antialiasing, false);
5373             if (reverse)
5374             {
5375                 painter->drawLine(r.left()+50-1, r.top(), r.right(), r.top());
5376                 painter->drawLine(r.left()+20, r.bottom()-2, r.left(), r.bottom()-2);
5377                 painter->setPen(use[0]);
5378                 painter->drawLine(r.left()+50, r.top()+1, r.right(), r.top()+1);
5379                 painter->drawLine(r.left()+20, r.bottom()-1, r.left(), r.bottom()-1);
5380             }
5381             else
5382             {
5383                 painter->drawLine(r.left(), r.top(), r.right()-50+1, r.top());
5384                 painter->drawLine(r.right()-20, r.bottom()-2, r.right(), r.bottom()-2);
5385                 painter->setPen(use[0]);
5386                 painter->drawLine(r.left(), r.top()+1, r.right()-50, r.top()+1);
5387                 painter->drawLine(r.right()-20, r.bottom()-1, r.right(), r.bottom()-1);
5388             }
5389             painter->restore();
5390             break;
5391         }
5392         case CE_MenuScroller:
5393         {
5394             const QColor *use(popupMenuCols());
5395             painter->fillRect(r, use[ORIGINAL_SHADE]);
5396             painter->setPen(use[QTC_STD_BORDER]);
5397             drawRect(painter, r);
5398             drawPrimitive(((state&State_DownArrow) ? PE_IndicatorArrowDown : PE_IndicatorArrowUp), option, painter, widget);
5399             break;
5400         }
5401         case CE_RubberBand: // Rubber band used in such things as iconview.
5402         {
5403             if(r.width()>0 && r.height()>0)
5404             {
5405                 painter->save();
5406                 QColor c(m_highlightCols[ORIGINAL_SHADE]);
5407 
5408                 painter->setClipRegion(r);
5409                 painter->setPen(c);
5410                 c.setAlpha(50);
5411                 painter->setBrush(c);
5412                 drawRect(painter, r);
5413                 painter->restore();
5414             }
5415             break;
5416         }
5417         case CE_Splitter:
5418         {
5419             const QColor *use(buttonColors(option));
5420             const QColor *border(borderColors(option, use));
5421             // In Amarok nightly (2.2) State_Horizontal doesn't seem to
5422             // always be set...
5423             bool horiz(state & State_Horizontal ||
5424                        (r.height() > 6 && r.height() > r.width()));
5425 
5426             painter->save();
5427             if(/*qtcIsFlatBgnd(opts.bgndAppearance) || */state&State_MouseOver && state&State_Enabled)
5428             {
5429                 QColor color(palette.color(QPalette::Active, QPalette::Window));
5430 
5431                 if(state&State_MouseOver && state&State_Enabled && opts.splitterHighlight)
5432                     if(ROUND_NONE!=opts.round)
5433                     {
5434                         painter->save();
5435                         painter->setRenderHint(QPainter::Antialiasing, true);
5436                         double   radius(qtcGetRadius(&opts, r.width(), r.height(), WIDGET_OTHER, RADIUS_SELECTION));
5437 
5438                         drawBevelGradient(shade(palette.background().color(), TO_FACTOR(opts.splitterHighlight)),
5439                                           painter, r, buildPath(QRectF(r), WIDGET_OTHER, ROUNDED_ALL, radius),
5440                                           !(state&State_Horizontal), false, opts.selectionAppearance, WIDGET_SELECTION, false);
5441                         painter->restore();
5442                     }
5443                     else
5444                         drawBevelGradient(shade(palette.background().color(), TO_FACTOR(opts.splitterHighlight)), painter,
5445                                           r, !(state&State_Horizontal), false, opts.selectionAppearance, WIDGET_SELECTION);
5446                 else
5447                     painter->fillRect(r, color);
5448             }
5449 
5450             switch(opts.splitters)
5451             {
5452                 case LINE_NONE:
5453                     break;
5454                 case LINE_1DOT:
5455                     painter->drawPixmap(r.x()+((r.width()-5)/2), r.y()+((r.height()-5)/2), *getPixmap(border[QTC_STD_BORDER], PIX_DOT, 1.0));
5456                     break;
5457                 default:
5458                 case LINE_DOTS:
5459                     drawDots(painter, r, horiz, NUM_SPLITTER_DASHES, 1, border, 0, 5);
5460                     break;
5461                 case LINE_FLAT:
5462                 case LINE_SUNKEN:
5463                 case LINE_DASHES:
5464                     drawLines(painter, r, horiz, NUM_SPLITTER_DASHES, 3, border, 0, 3, opts.splitters);
5465             }
5466             painter->restore();
5467             break;
5468         }
5469         case CE_SizeGrip:
5470         {
5471             QPolygon   triangle(3);
5472             Qt::Corner corner;
5473             int        size=SIZE_GRIP_SIZE-2;
5474 
5475             if (auto sgrp = styleOptCast<QStyleOptionSizeGrip>(option))
5476                 corner = sgrp->corner;
5477             else if (Qt::RightToLeft==option->direction)
5478                 corner = Qt::BottomLeftCorner;
5479             else
5480                 corner = Qt::BottomRightCorner;
5481 
5482             switch(corner)
5483             {
5484                 case Qt::BottomLeftCorner:
5485                     triangle.putPoints(0, 3, 0,0, size,size, 0,size);
5486                     triangle.translate(r.x(), r.y()+(r.height()-(SIZE_GRIP_SIZE-1)));
5487                     break;
5488                 case Qt::BottomRightCorner:
5489                     triangle.putPoints(0, 3, size,0, size,size, 0,size);
5490                     triangle.translate(r.x()+(r.width()-(SIZE_GRIP_SIZE-1)), r.y()+(r.height()-(SIZE_GRIP_SIZE-1)));
5491                     break;
5492                 case Qt::TopRightCorner:
5493                     triangle.putPoints(0, 3, 0,0, size,0, size,size);
5494                     triangle.translate(r.x()+(r.width()-(SIZE_GRIP_SIZE-1)), r.y());
5495                     break;
5496                 case Qt::TopLeftCorner:
5497                     triangle.putPoints(0, 3, 0,0, size,0, 0,size);
5498                     triangle.translate(r.x(), r.y());
5499             }
5500             painter->save();
5501             painter->setPen(m_backgroundCols[2]);
5502             painter->setBrush(m_backgroundCols[2]);
5503             painter->drawPolygon(triangle);
5504             painter->restore();
5505             break;
5506         }
5507         case CE_ToolBar:
5508             if (auto toolbar = styleOptCast<QStyleOptionToolBar>(option)) {
5509                 if(!widget || !widget->parent() || qobject_cast<QMainWindow*>(widget->parent()))
5510                 {
5511                     painter->save();
5512                     drawMenuOrToolBarBackground(widget, painter, r, option, false, Qt::NoToolBarArea==toolbar->toolBarArea ||
5513                                                                                    Qt::BottomToolBarArea==toolbar->toolBarArea ||
5514                                                                                    Qt::TopToolBarArea==toolbar->toolBarArea);
5515                     if(TB_NONE!=opts.toolbarBorders)
5516                     {
5517                         const QColor *use=/*PE_PanelMenuBar==pe && m_active
5518                                             ? m_menubarCols
5519                                             : */ backgroundColors(option);
5520                         bool         dark(TB_DARK==opts.toolbarBorders || TB_DARK_ALL==opts.toolbarBorders);
5521 
5522                         if(TB_DARK_ALL==opts.toolbarBorders || TB_LIGHT_ALL==opts.toolbarBorders)
5523                         {
5524                             painter->setPen(use[0]);
5525                             painter->drawLine(r.x(), r.y(), r.x()+r.width()-1, r.y());
5526                             painter->drawLine(r.x(), r.y(), r.x(), r.y()+r.height()-1);
5527                             painter->setPen(use[dark ? 3 : 4]);
5528                             painter->drawLine(r.x(), r.y()+r.height()-1, r.x()+r.width()-1, r.y()+r.height()-1);
5529                             painter->drawLine(r.x()+r.width()-1, r.y(), r.x()+r.width()-1, r.y()+r.height()-1);
5530                         }
5531                         else
5532                         {
5533                             bool paintH(true),
5534                                  paintV(true);
5535 
5536                             switch (toolbar->toolBarArea)
5537                             {
5538                                 case Qt::BottomToolBarArea:
5539                                 case Qt::TopToolBarArea:
5540                                     paintV=false;
5541                                     break;
5542                                 case Qt::RightToolBarArea:
5543                                 case Qt::LeftToolBarArea:
5544                                     paintH=false;
5545                                 default:
5546                                     break;
5547                             }
5548 
5549                             painter->setPen(use[0]);
5550                             if(paintH)
5551                                 painter->drawLine(r.x(), r.y(), r.x()+r.width()-1, r.y());
5552                             if(paintV)
5553                                 painter->drawLine(r.x(), r.y(), r.x(), r.y()+r.height()-1);
5554                             painter->setPen(use[dark ? 3 : 4]);
5555                             if(paintH)
5556                                 painter->drawLine(r.x(), r.y()+r.height()-1, r.x()+r.width()-1, r.y()+r.height()-1);
5557                             if(paintV)
5558                                 painter->drawLine(r.x()+r.width()-1, r.y(), r.x()+r.width()-1, r.y()+r.height()-1);
5559                         }
5560                     }
5561                     painter->restore();
5562                 }
5563             }
5564             break;
5565         case CE_DockWidgetTitle:
5566             if (auto dwOpt = styleOptCast<QStyleOptionDockWidget>(option)) {
5567                 auto v2 = styleOptCast<QStyleOptionDockWidgetV2>(dwOpt);
5568                 bool verticalTitleBar(v2 == 0 ? false : v2->verticalTitleBar);
5569                 bool isKOffice(widget && widget->inherits("KoDockWidgetTitleBar"));
5570                 QRect fillRect(r);
5571 
5572                 // This fixes the look of KOffice's dock widget titlebars...
5573                 if(isKOffice)
5574                     fillRect.adjust(-r.x(), -r.y(), 0, 0);
5575 
5576                 if(!qtcIsFlat(opts.dwtAppearance))
5577                 {
5578                     painter->save();
5579 
5580                     QColor col((opts.dwtSettings&DWT_COLOR_AS_PER_TITLEBAR)
5581                                 ? getMdiColors(option, state&State_Active)[ORIGINAL_SHADE]
5582                                 : palette.background().color());
5583                     if(opts.round<ROUND_FULL)
5584                         drawBevelGradient(col, painter, fillRect, !verticalTitleBar,
5585                                           false, opts.dwtAppearance, WIDGET_DOCK_WIDGET_TITLE);
5586                     else
5587                     {
5588                         double radius(qtcGetRadius(&opts, fillRect.width(), fillRect.height(), WIDGET_OTHER, RADIUS_EXTERNAL));
5589                         int    round=ROUNDED_ALL;
5590 
5591                         if(opts.dwtSettings&DWT_ROUND_TOP_ONLY)
5592                             round=verticalTitleBar ? ROUNDED_LEFT : ROUNDED_TOP;
5593                         painter->setRenderHint(QPainter::Antialiasing, true);
5594                         drawBevelGradient(col, painter, fillRect, buildPath(QRectF(fillRect), WIDGET_OTHER, round, radius), !verticalTitleBar,
5595                                           false, opts.dwtAppearance, WIDGET_DOCK_WIDGET_TITLE, false);
5596                     }
5597 
5598                     painter->restore();
5599                 }
5600 
5601                 if (!dwOpt->title.isEmpty())
5602                 {
5603                     QRect titleRect(subElementRect(SE_DockWidgetTitleBarText, option, widget));
5604 
5605                     if (verticalTitleBar)
5606                     {
5607                         QRect rVert(r);
5608                         QSize s(rVert.size());
5609 
5610                         s.transpose();
5611                         rVert.setSize(s);
5612 
5613                         titleRect = QRect(rVert.left() + r.bottom() - titleRect.bottom(),
5614                                         rVert.top() + titleRect.left() - r.left(),
5615                                         titleRect.height(), titleRect.width());
5616 
5617                         painter->translate(rVert.left(), rVert.top() + rVert.width());
5618                         painter->rotate(-90);
5619                         painter->translate(-rVert.left(), -rVert.top());
5620                     }
5621 #ifdef QTC_QT4_ENABLE_KDE
5622                     if(opts.dwtSettings&DWT_FONT_AS_PER_TITLEBAR)
5623                         painter->setFont(KGlobalSettings::windowTitleFont());
5624 #endif
5625                     QFontMetrics fm(painter->fontMetrics());
5626                     QString      title(fm.elidedText(dwOpt->title, Qt::ElideRight, titleRect.width(), QPalette::WindowText));
5627                     painter->save();
5628                     getMdiColors(option, state&State_Active);
5629 
5630                     QColor textColor((opts.dwtSettings&DWT_COLOR_AS_PER_TITLEBAR)
5631                                         ? state&State_Active
5632                                             ? m_activeMdiTextColor
5633                                             : m_mdiTextColor
5634                                         : palette.color(QPalette::WindowText)),
5635                            shadow(WINDOW_SHADOW_COLOR(opts.titlebarEffect));
5636                     int textOpt(Qt::AlignVCenter); // TODO: dwtPosAsPerTitleBar ?
5637 
5638                     if(opts.dwtSettings&DWT_TEXT_ALIGN_AS_PER_TITLEBAR)
5639                         switch(opts.titlebarAlignment)
5640                         {
5641                             case ALIGN_FULL_CENTER:
5642                                 if (!verticalTitleBar && !reverse) {
5643                                     QFontMetrics fm(painter->fontMetrics());
5644                                     int          width=fm.boundingRect(title).width();
5645 
5646                                     if(((fillRect.width()+width)/2)<=titleRect.width()+(isKOffice ? r.x() : 0))
5647                                     {
5648                                         titleRect=fillRect;
5649                                         textOpt|=Qt::AlignHCenter;
5650                                     }
5651                                     else
5652                                         textOpt|=Qt::AlignRight;
5653                                     break;
5654                                 }
5655                                 QTC_FALLTHROUGH();
5656                             case ALIGN_CENTER:
5657                                 textOpt|=Qt::AlignHCenter;
5658                                 break;
5659                             case ALIGN_RIGHT:
5660                                 textOpt|=Qt::AlignRight;
5661                                 break;
5662                             default:
5663                             case ALIGN_LEFT:
5664                                 textOpt|=Qt::AlignLeft;
5665                         }
5666                     else
5667                         textOpt|=Qt::AlignLeft;
5668 
5669                     if (!styleHint(SH_UnderlineShortcut, dwOpt, widget))
5670                         textOpt|=Qt::TextHideMnemonic;
5671                     else
5672                         textOpt|=Qt::TextShowMnemonic;
5673 
5674                     if((opts.dwtSettings&DWT_EFFECT_AS_PER_TITLEBAR) &&
5675                        EFFECT_NONE!=opts.titlebarEffect)
5676                     {
5677                         shadow.setAlphaF(WINDOW_TEXT_SHADOW_ALPHA(opts.titlebarEffect));
5678                         painter->setPen(shadow);
5679                         painter->drawText(titleRect.adjusted(1, 1, 1, 1), textOpt, title);
5680 
5681                         if (!(state&State_Active) && DARK_WINDOW_TEXT(textColor))
5682                             textColor.setAlpha((textColor.alpha() * 180) >> 8);
5683                     }
5684                     painter->setPen(textColor);
5685                     painter->drawText(titleRect, textOpt, title);
5686                     painter->restore();
5687                 }
5688             }
5689             break;
5690         case CE_HeaderEmptyArea:
5691         {
5692             auto ho = styleOptCast<QStyleOptionHeader>(option);
5693             bool horiz(ho ? Qt::Horizontal==ho->orientation : state&State_Horizontal);
5694             QStyleOption opt(*option);
5695             const QColor             *use(opts.lvButton ? buttonColors(option) : backgroundColors(option));
5696 
5697             opt.state&=~State_MouseOver;
5698             painter->save();
5699 
5700             drawBevelGradient(getFill(&opt, use), painter, r, horiz, false, opts.lvAppearance, WIDGET_LISTVIEW_HEADER);
5701 
5702             painter->setRenderHint(QPainter::Antialiasing, true);
5703             if(APPEARANCE_RAISED==opts.lvAppearance)
5704             {
5705                 painter->setPen(use[4]);
5706                 if(horiz)
5707                     drawAaLine(painter, r.x(), r.y()+r.height()-2, r.x()+r.width()-1, r.y()+r.height()-2);
5708                 else
5709                     drawAaLine(painter, r.x()+r.width()-2, r.y(), r.x()+r.width()-2, r.y()+r.height()-1);
5710             }
5711 
5712             painter->setPen(use[QTC_STD_BORDER]);
5713             if(horiz)
5714                 drawAaLine(painter, r.x(), r.y()+r.height()-1, r.x()+r.width()-1, r.y()+r.height()-1);
5715             else if(reverse)
5716                 drawAaLine(painter, r.x(), r.y(), r.x(), r.y()+r.height()-1);
5717             else
5718                 drawAaLine(painter, r.x()+r.width()-1, r.y(), r.x()+r.width()-1, r.y()+r.height()-1);
5719             painter->setRenderHint(QPainter::Antialiasing, false);
5720             painter->restore();
5721             break;
5722         }
5723         case CE_HeaderSection:
5724             if (auto ho = styleOptCast<QStyleOptionHeader>(option)) {
5725                 const QColor *use(state&State_Enabled && m_sortedLvColors &&
5726                                   ho->sortIndicator != QStyleOptionHeader::None ?
5727                                   m_sortedLvColors : opts.lvButton ?
5728                                   buttonColors(option) :
5729                                   backgroundColors(option));
5730 
5731                 painter->save();
5732 
5733                 if (state & (State_Raised | State_Sunken)) {
5734                     /* State_Down | State_On */
5735                     bool sunken = (state & State_Sunken);
5736                     bool q3Header = widget && widget->inherits("Q3Header");
5737                     QStyleOption opt(*option);
5738 
5739                     opt.state &= ~State_On;
5740                     if (q3Header && widget && widget->underMouse() &&
5741                         m_hoverWidget && r.contains(m_pos)) {
5742                         opt.state |= State_MouseOver;
5743                     }
5744 
5745                     if (ho->section == -1 && !(state & State_Enabled) &&
5746                         widget && widget->isEnabled()) {
5747                         opt.state |= State_Enabled;
5748                     }
5749 
5750                     drawBevelGradient(getFill(&opt, use), painter, r,
5751                                       ho->orientation == Qt::Horizontal,
5752                                       sunken, opts.lvAppearance,
5753                                       WIDGET_LISTVIEW_HEADER);
5754 
5755                     painter->setRenderHint(QPainter::Antialiasing, true);
5756                     if (opts.lvAppearance == APPEARANCE_RAISED) {
5757                         painter->setPen(use[4]);
5758                         if (ho->orientation == Qt::Horizontal) {
5759                             drawAaLine(painter, r.x(), r.y() + r.height() - 2,
5760                                        r.x() + r.width() - 1,
5761                                        r.y() + r.height() - 2);
5762                         } else {
5763                             drawAaLine(painter, r.x() + r.width() - 2, r.y(),
5764                                        r.x() + r.width() - 2,
5765                                        r.y() + r.height() - 1);
5766                         }
5767                     }
5768 
5769                     if (ho->orientation == Qt::Horizontal) {
5770                         painter->setPen(use[QTC_STD_BORDER]);
5771                         drawAaLine(painter, r.x(), r.y() + r.height() - 1,
5772                                    r.x() + r.width() - 1,
5773                                    r.y() + r.height() - 1);
5774                         if (opts.coloredMouseOver && state & State_MouseOver &&
5775                             state & State_Enabled)
5776                             drawHighlight(painter,
5777                                           QRect(r.x(), r.y() + r.height() - 2,
5778                                                 r.width(), 2), true, true);
5779 
5780                         if (q3Header ||
5781                             noneOf(ho->position, QStyleOptionHeader::End,
5782                                    QStyleOptionHeader::OnlyOneSection)) {
5783                             // Draw header separator
5784                             int sep_x = reverse ? r.x() : r.x() + r.width() - 2;
5785                             drawFadedLine(painter,
5786                                           QRect(sep_x, r.y() + 5, 1,
5787                                                 r.height() - 10),
5788                                           use[QTC_STD_BORDER],
5789                                           true, true, false);
5790                             drawFadedLine(painter,
5791                                           QRect(sep_x + 1, r.y() + 5, 1,
5792                                                 r.height() - 10),
5793                                           use[0], true, true, false);
5794                         }
5795                     } else {
5796                         painter->setPen(use[QTC_STD_BORDER]);
5797                         if (reverse) {
5798                             drawAaLine(painter, r.x(), r.y(), r.x(),
5799                                        r.y()+r.height()-1);
5800                         } else {
5801                             drawAaLine(painter, r.x() + r.width() - 1, r.y(),
5802                                        r.x() + r.width() - 1,
5803                                        r.y() + r.height() - 1);
5804                         }
5805 
5806                         if (q3Header ||
5807                             noneOf(ho->position, QStyleOptionHeader::End,
5808                                    QStyleOptionHeader::OnlyOneSection)) {
5809                             // Draw header separator
5810                             drawFadedLine(painter,
5811                                           QRect(r.x() + 5,
5812                                                 r.y() + r.height() - 2,
5813                                                 r.width() - 10, 1),
5814                                           use[QTC_STD_BORDER], true, true, true);
5815                             drawFadedLine(painter,
5816                                           QRect(r.x() + 5,
5817                                                 r.y() + r.height() - 1,
5818                                                 r.width() - 10, 1),
5819                                           use[0], true, true, true);
5820                         }
5821                         if (opts.coloredMouseOver && state & State_MouseOver &&
5822                             state & State_Enabled) {
5823                             drawHighlight(painter,
5824                                           QRect(r.x(), r.y() + r.height() - 3,
5825                                                 r.width(), 2), true, true);
5826                         }
5827                     }
5828                     painter->setRenderHint(QPainter::Antialiasing, false);
5829                 } else if (!qtcIsFlat(opts.lvAppearance) && !reverse &&
5830                            (state == (State_Enabled | State_Active) ||
5831                             state == State_Enabled)) {
5832                     QPolygon top;
5833                     const QColor &col(getFill(option, use));
5834 
5835                     top.setPoints(3, r.x(), r.y(), r.x() + r.width(), r.y(),
5836                                   r.x() + r.width(), r.y() + r.height());
5837                     painter->setClipRegion(QRegion(top));
5838                     drawBevelGradient(col, painter, r, true, false,
5839                                       opts.lvAppearance, WIDGET_LISTVIEW_HEADER);
5840                     painter->setClipRegion(QRegion(r).eor(QRegion(top)));
5841                     drawBevelGradient(col, painter, r, false, false,
5842                                       opts.lvAppearance, WIDGET_LISTVIEW_HEADER);
5843                 } else {
5844                     painter->fillRect(r, getFill(option, use));
5845                 }
5846                 painter->restore();
5847             }
5848             break;
5849         case CE_HeaderLabel:
5850             if (auto header = styleOptCast<QStyleOptionHeader>(option)) {
5851                 if (!header->icon.isNull())
5852                 {
5853                     QPixmap pixmap(getIconPixmap(header->icon, pixelMetric(PM_SmallIconSize), header->state));
5854                     int     pixw(pixmap.width());
5855                     QRect   aligned(alignedRect(header->direction, QFlag(header->iconAlignment), pixmap.size(), r)),
5856                             inter(aligned.intersected(r));
5857 
5858                     painter->drawPixmap(inter.x(), inter.y(), pixmap, inter.x() - aligned.x(), inter.y() - aligned.y(), inter.width(), inter.height());
5859 
5860                     if (header->direction == Qt::LeftToRight)
5861                         r.setLeft(r.left() + pixw + 2);
5862                     else
5863                         r.setRight(r.right() - pixw - 2);
5864                 }
5865                 drawItemTextWithRole(painter, r, header->textAlignment, palette,
5866                                      state&State_Enabled, header->text,
5867                                      QPalette::ButtonText);
5868             }
5869             break;
5870         case CE_ProgressBarGroove: {
5871             bool doEtch = (opts.buttonEffect != EFFECT_NONE &&
5872                            opts.borderProgress);
5873             bool horiz = true;
5874             QColor col;
5875 
5876             if (auto bar = styleOptCast<QStyleOptionProgressBarV2>(option)) {
5877                 horiz = bar->orientation == Qt::Horizontal;
5878             }
5879             painter->save();
5880 
5881             if(doEtch)
5882                 r.adjust(1, 1, -1, -1);
5883 
5884             switch(opts.progressGrooveColor)
5885             {
5886                 default:
5887                 case ECOLOR_BASE:
5888                     col=palette.base().color();
5889                     break;
5890                 case ECOLOR_BACKGROUND:
5891                     col=palette.background().color();
5892                     break;
5893                 case ECOLOR_DARK:
5894                     col=m_backgroundCols[2];
5895             }
5896 
5897             drawBevelGradient(col, painter, r, opts.borderProgress
5898                                 ? buildPath(r, WIDGET_PBAR_TROUGH, ROUNDED_ALL,
5899                                             qtcGetRadius(&opts, r.width(), r.height(), WIDGET_PBAR_TROUGH, RADIUS_EXTERNAL))
5900                                 : QPainterPath(),
5901                               horiz, false, opts.progressGrooveAppearance, WIDGET_PBAR_TROUGH);
5902 
5903             if(doEtch)
5904                 drawEtch(painter, r.adjusted(-1, -1, 1, 1), widget, WIDGET_PBAR_TROUGH);
5905             else if(!opts.borderProgress)
5906             {
5907                 painter->setPen(m_backgroundCols[QTC_STD_BORDER]);
5908                 if(horiz)
5909                 {
5910                     painter->drawLine(r.topLeft(), r.topRight());
5911                     painter->drawLine(r.bottomLeft(), r.bottomRight());
5912                 }
5913                 else
5914                 {
5915                     painter->drawLine(r.topLeft(), r.bottomLeft());
5916                     painter->drawLine(r.topRight(), r.bottomRight());
5917                 }
5918             }
5919 
5920             if(opts.borderProgress)
5921                 drawBorder(painter, r, option, ROUNDED_ALL, backgroundColors(option), WIDGET_PBAR_TROUGH,
5922                            qtcIsFlat(opts.progressGrooveAppearance) && ECOLOR_DARK!=opts.progressGrooveColor ? BORDER_SUNKEN : BORDER_FLAT);
5923             painter->restore();
5924             break;
5925         }
5926         case CE_ProgressBarContents:
5927             if (auto bar = styleOptCast<QStyleOptionProgressBar>(option)) {
5928                 bool vertical(false),
5929                      inverted(false),
5930                      indeterminate(0==bar->minimum && 0==bar->maximum);
5931 
5932                 // Get extra style options if version 2
5933                 if (auto bar2 =
5934                     styleOptCast<QStyleOptionProgressBarV2>(option)) {
5935                     vertical = Qt::Vertical==bar2->orientation;
5936                     inverted = bar2->invertedAppearance;
5937                 }
5938 
5939                 if (!indeterminate && -1==bar->progress)
5940                     break;
5941 
5942                 bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical;
5943 
5944                 if (inverted)
5945                     reverse = !reverse;
5946 
5947                 painter->save();
5948 
5949                 if (!m_progressBarAnimateTimer && (opts.animatedProgress || indeterminate)) {
5950                     if (m_timer.isNull()) {
5951                         m_timer.start();
5952                     }
5953                     // now we'll need a timer, start it at the regular frequency
5954                     m_progressBarAnimateFps = constProgressBarFps;
5955                     m_progressBarAnimateTimer = const_cast<Style*>(this)->startTimer(1000/m_progressBarAnimateFps);
5956                 }
5957 
5958                 if(indeterminate) //Busy indicator
5959                 {
5960                     int chunkSize(PROGRESS_CHUNK_WIDTH*3.4),
5961                         measure(vertical ? r.height() : r.width());
5962 
5963                     if(chunkSize>(measure/2))
5964                         chunkSize=measure/2;
5965 
5966                     int          step(m_animateStep % ((measure-chunkSize) * 2));
5967                     QStyleOption opt(*option);
5968 
5969                     if (step > (measure-chunkSize))
5970                         step = 2 * (measure-chunkSize) - step;
5971 
5972                     opt.state|=State_Raised|State_Horizontal;
5973                     drawProgress(painter, vertical ? QRect(r.x(), r.y()+step, r.width(), chunkSize) : QRect(r.x()+step, r.y(), chunkSize, r.height()),
5974                                  option, vertical);
5975                 }
5976                 else if(r.isValid() && bar->progress>0)
5977                 {
5978                     qint64 progress = qMax<qint64>(bar->progress, bar->minimum); // workaround for bug in QProgressBar
5979                     double pg = ((progress - qint64(bar->minimum)) /
5980                                 qMax(double(1.0), double(qint64(bar->maximum) - qint64(bar->minimum))));
5981 
5982                     if(vertical)
5983                     {
5984                         int height(qMin(r.height(), (int)(pg * r.height())));
5985 
5986                         if(inverted)
5987                             drawProgress(painter, QRect(r.x(), r.y(), r.width(), height), option, true);
5988                         else
5989                             drawProgress(painter, QRect(r.x(), r.y()+(r.height()-height), r.width(), height), option, true);
5990                     }
5991                     else
5992                     {
5993                         int width(qMin(r.width(), (int)(pg * r.width())));
5994 
5995                         if(reverse || inverted)
5996                             drawProgress(painter, QRect(r.x()+(r.width()-width), r.y(), width, r.height()), option, false, true);
5997                         else
5998                             drawProgress(painter, QRect(r.x(), r.y(), width, r.height()), option);
5999                     }
6000                 }
6001 
6002                 painter->restore();
6003             }
6004             break;
6005         case CE_ProgressBarLabel:
6006             if (auto bar = styleOptCast<QStyleOptionProgressBar>(option)) {
6007                 // The busy indicator doesn't draw a label
6008                 if (0==bar->minimum && 0==bar->maximum)
6009                     return;
6010 
6011                 bool vertical(false),
6012                      inverted(false),
6013                      bottomToTop(false);
6014 
6015                 // Get extra style options if version 2
6016                 if (auto bar2 =
6017                     styleOptCast<QStyleOptionProgressBarV2>(option)) {
6018                     vertical = bar2->orientation == Qt::Vertical;
6019                     inverted = bar2->invertedAppearance;
6020                     bottomToTop = bar2->bottomToTop;
6021                 }
6022 
6023                 painter->save();
6024                 painter->setRenderHint(QPainter::Antialiasing, true);
6025 
6026                 if (vertical)
6027                 {
6028                     r = QRect(r.left(), r.top(), r.height(), r.width()); // flip width and height
6029 
6030                     QTransform m;
6031                     if (bottomToTop)
6032                     {
6033                         m.translate(0.0, r.width());
6034                         m.rotate(-90);
6035                     }
6036                     else
6037                     {
6038                         m.translate(r.height(), 0.0);
6039                         m.rotate(90);
6040                     }
6041                     painter->setTransform(m);
6042                 }
6043 
6044                 int                  progressIndicatorPos = (bar->progress - qreal(bar->minimum)) /
6045                                                              qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum) * r.width();
6046                 bool                 flip((!vertical && (((Qt::RightToLeft==bar->direction) && !inverted) ||
6047                                                         ((Qt::LeftToRight==bar->direction) && inverted))) ||
6048                                           (vertical && ((!inverted && !bottomToTop) || (inverted && bottomToTop))));
6049                 QRect                leftRect;
6050                 QRegion              rightRect(r);
6051                 QPalette::ColorGroup cg=state&State_Enabled || State_None==state ? QPalette::Active : QPalette::Current;
6052 
6053                 if (flip)
6054                 {
6055                     int indicatorPos(r.width() - progressIndicatorPos);
6056 
6057                     if (indicatorPos >= 0 && indicatorPos <= r.width())
6058                     {
6059                         painter->setPen(palette.brush(cg, QPalette::Base).color());
6060                         leftRect = QRect(r.left(), r.top(), indicatorPos, r.height());
6061                         //rightRect = QRect(r.left()+indicatorPos, r.top(), r.width()-indicatorPos, r.height());
6062                     }
6063                     else if (indicatorPos > r.width())
6064                         painter->setPen(palette.brush(cg, QPalette::Text).color());
6065                     else
6066                         painter->setPen(palette.brush(cg, QPalette::HighlightedText).color());
6067                 }
6068                 else
6069                 {
6070                     if (progressIndicatorPos >= 0 && progressIndicatorPos <= r.width())
6071                     {
6072                         leftRect = QRect(r.left(), r.top(), progressIndicatorPos, r.height());
6073                         //rightRect = QRect(r.left()+progressIndicatorPos, r.top(), r.width()-progressIndicatorPos, r.height());
6074                     }
6075                     else if (progressIndicatorPos > r.width())
6076                         painter->setPen(palette.brush(cg, QPalette::HighlightedText).color());
6077                     else
6078                         painter->setPen(palette.brush(cg, QPalette::Text).color());
6079                 }
6080 
6081                 QString text = bar->fontMetrics.elidedText(bar->text, Qt::ElideRight, r.width());
6082 
6083                 rightRect = rightRect.subtracted(leftRect);
6084                 painter->setClipRegion(rightRect);
6085                 painter->drawText(r, text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
6086                 if (!leftRect.isNull())
6087                 {
6088                     painter->setPen(palette.brush(cg, flip ? QPalette::Text : QPalette::HighlightedText).color());
6089                     painter->setClipRect(leftRect);
6090                     painter->drawText(r, text, QTextOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter));
6091                 }
6092 
6093                 painter->restore();
6094             }
6095             break;
6096         case CE_MenuBarItem:
6097             if (auto mbi = styleOptCast<QStyleOptionMenuItem>(option)) {
6098                 bool    down(state&(State_On|State_Sunken)),
6099                         active(state&State_Enabled && (down || (state&State_Selected && opts.menubarMouseOver)));
6100                 uint    alignment(Qt::AlignCenter|Qt::TextShowMnemonic|Qt::TextDontClip|Qt::TextSingleLine);
6101                 QPixmap pix(getIconPixmap(mbi->icon, pixelMetric(PM_SmallIconSize), mbi->state));
6102 
6103                 if (!styleHint(SH_UnderlineShortcut, mbi, widget))
6104                     alignment|=Qt::TextHideMnemonic;
6105 
6106                 painter->save();
6107 
6108                 if (!opts.xbar ||
6109                     (!widget || oneOf(widget->metaObject()->className(), "QWidget"))) {
6110                     drawMenuOrToolBarBackground(widget, painter,
6111                                                 mbi->menuRect, option);
6112                 }
6113 
6114                 if(active)
6115                     drawMenuItem(painter, !opts.roundMbTopOnly && !POPUP_MENUS_SQUARE(opts) ? r.adjusted(1, 1, -1, -1) : r,
6116                                  option, MENU_BAR,
6117                                  (down || APP_OPENOFFICE==theThemedApp) && opts.roundMbTopOnly ? ROUNDED_TOP : ROUNDED_ALL,
6118                                  opts.useHighlightForMenu && (opts.colorMenubarMouseOver || down || APP_OPENOFFICE==theThemedApp)
6119                                             ? (m_ooMenuCols ? m_ooMenuCols : m_highlightCols) : m_backgroundCols);
6120 
6121                 if (!pix.isNull())
6122                     drawItemPixmap(painter, mbi->rect, alignment, pix);
6123                 else
6124                 {
6125                     const QColor &col=state&State_Enabled
6126                                         ? ((opts.colorMenubarMouseOver && active) || (!opts.colorMenubarMouseOver && down))
6127                                             ? opts.customMenuTextColor
6128                                                 ? opts.customMenuSelTextColor
6129                                                 : opts.useHighlightForMenu
6130                                                     ? palette.highlightedText().color()
6131                                                     : palette.foreground().color()
6132                                             : palette.foreground().color()
6133                                          : palette.foreground().color();
6134 
6135                     painter->setPen(col);
6136                     painter->drawText(r, alignment, mbi->text);
6137                 }
6138                 painter->restore();
6139             }
6140             break;
6141         case CE_MenuItem:
6142             if (auto menuItem = styleOptCast<QStyleOptionMenuItem>(option)) {
6143                 bool           comboMenu(qobject_cast<const QComboBox*>(widget)),
6144                                reverse(Qt::RightToLeft==menuItem->direction),
6145                                isOO(isOOWidget(widget));
6146                 int            checkcol(qMax(menuItem->maxIconWidth, 20)),
6147                                stripeWidth(qMax(checkcol, constMenuPixmapWidth)-2);
6148                 const QColor * use(popupMenuCols(option));
6149 
6150                 QRect rx(r);
6151 
6152                 if(isOO)
6153                 {
6154                     if(opts.borderMenuitems)
6155                         r.adjust(2, 0, -2, 0);
6156                     else if(APPEARANCE_FADE==opts.menuitemAppearance)
6157                         r.adjust(1, 0, -1, 0);
6158                 }
6159 
6160                 painter->save();
6161 
6162                 if (QStyleOptionMenuItem::Separator==menuItem->menuItemType)
6163                 {
6164                     bool isMenu(!widget || qobject_cast<const QMenu*>(widget)),
6165                          doStripe(isMenu && opts.menuStripe && !comboMenu);
6166 
6167                     if(doStripe)
6168                         drawBevelGradient(menuStripeCol(), painter, QRect(reverse ? r.right()-stripeWidth : r.x(), r.y(),
6169                                                                           stripeWidth, r.height()),
6170                                           false, false, opts.menuStripeAppearance, WIDGET_OTHER);
6171 
6172                     if(!menuItem->text.isEmpty())
6173                     {
6174                         int textAlignment;
6175                         QFont font(menuItem->font);
6176                         QRect textRect;
6177                         if (opts.buttonStyleMenuSections) {
6178                             QStyleOption opt;
6179                             opt.rect = r.adjusted(2, 2, -3, -2);
6180                             opt.state = State_Raised | State_Enabled | State_Horizontal;
6181                             drawLightBevel(painter, opt.rect, &opt, widget, ROUNDED_ALL,
6182                                            getFill(&opt, use), use, true,
6183                                            WIDGET_NO_ETCH_BTN);
6184 
6185                             font.setBold(true);
6186                             painter->setFont(font);
6187                             textAlignment = Qt::AlignHCenter | Qt::AlignVCenter;
6188                             textRect = r;
6189                         } else {
6190                             font.setBold(true);
6191                             font.setUnderline(true);
6192 #ifdef Q_OS_MACOS
6193                             if (QGuiApplication::platformName() == QLatin1String("cocoa")) {
6194                                 font.setLetterSpacing(QFont::PercentageSpacing, 95);
6195                             }
6196 #endif
6197                             painter->setFont(font);
6198                             QRect miRect(menuItem->rect.left() + 5 +
6199                                          (!reverse && doStripe ? stripeWidth : 0),
6200                                          menuItem->rect.center().y() - painter->fontMetrics().ascent() / 2 - 5,
6201                                          menuItem->rect.width() -
6202                                          (9 + (doStripe ? stripeWidth : 0)), 1);
6203                             QColor lineCol = use[MENU_SEP_SHADE];
6204                             if (miRect.y() >= rx.height() / 2) {
6205                                 drawFadedLine(painter, miRect, lineCol, reverse,
6206                                           !reverse, true);
6207                             }
6208                             textAlignment = Qt::AlignLeft | Qt::AlignBottom;
6209                             textRect = r.adjusted(5, 5, -5, -5);
6210                         }
6211                         drawItemTextWithRole(painter, textRect,
6212                                              textAlignment,
6213                                              palette, state & State_Enabled,
6214                                              menuItem->text, QPalette::Text);
6215                     }
6216                     else
6217                     {
6218                         QRect miRect(menuItem->rect.left() + 3 +
6219                                         (!reverse && doStripe ? stripeWidth : 0),
6220                                         menuItem->rect.center().y(),
6221                                         menuItem->rect.width() - (7 + (doStripe ? stripeWidth : 0)),
6222                                         1);
6223                         drawFadedLine(painter, miRect, use[MENU_SEP_SHADE], true, true, true);
6224                     }
6225 
6226                     if(isOO)
6227                     {
6228                         painter->setPen(use[QTC_STD_BORDER]);
6229                         painter->drawLine(rx.topLeft(), rx.bottomLeft());
6230                         painter->drawLine(rx.topRight(), rx.bottomRight());
6231                     }
6232                     painter->restore();
6233                     break;
6234                 }
6235 
6236                 bool selected(state&State_Selected),
6237                      checkable(QStyleOptionMenuItem::NotCheckable!=menuItem->checkType),
6238                      checked(menuItem->checked),
6239                      enabled(state&State_Enabled);
6240 
6241                 if(opts.menuStripe && !comboMenu)
6242                     drawBevelGradient(menuStripeCol(), painter,
6243                                       QRect(reverse ? r.right()-stripeWidth : r.x(), r.y(), stripeWidth, r.height()),
6244                                       false, false, opts.menuStripeAppearance, WIDGET_OTHER);
6245 
6246                 if (selected && enabled)
6247                     drawMenuItem(painter, r, option, /*comboMenu ? MENU_COMBO : */MENU_POPUP, ROUNDED_ALL,
6248                                  opts.useHighlightForMenu ? (m_ooMenuCols ? m_ooMenuCols : m_highlightCols) : use);
6249 
6250                 if(comboMenu)
6251                 {
6252                     if (menuItem->icon.isNull())
6253                         checkcol = 0;
6254                     else
6255                         checkcol = menuItem->maxIconWidth;
6256                 }
6257                 else
6258                 {
6259                     // Check
6260                     QRect checkRect(r.left() + 3, r.center().y() - 6, opts.crSize, opts.crSize);
6261                     checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
6262                     if (checkable)
6263                     {
6264                         if (!opts.onlyTicksInMenu && (menuItem->checkType & QStyleOptionMenuItem::Exclusive) && menuItem->icon.isNull())
6265                         {
6266                             QStyleOptionButton button;
6267                             button.rect = checkRect;
6268                             button.state = menuItem->state|STATE_MENU;
6269                             if (checked)
6270                                 button.state |= State_On;
6271                             button.palette = palette;
6272                             drawPrimitive(PE_IndicatorRadioButton, &button, painter, widget);
6273                         }
6274                         else
6275                         {
6276                             if (menuItem->icon.isNull() || !opts.menuIcons)
6277                             {
6278                                 QStyleOptionButton button;
6279                                 button.rect = checkRect;
6280                                 button.state = menuItem->state|STATE_MENU;
6281                                 if (checked)
6282                                     button.state |= State_On;
6283                                 button.palette = palette;
6284                                 drawPrimitive(PE_IndicatorMenuCheckMark, &button, painter, widget);
6285                             }
6286                             else if (checked)
6287                             {
6288                                 int          iconSize(qMax(menuItem->maxIconWidth, 20));
6289                                 QRect        sunkenRect(r.left() + 1, r.top() + (r.height() - iconSize) / 2,
6290                                                         iconSize, iconSize);
6291                                 QStyleOption opt(*option);
6292 
6293                                 sunkenRect = visualRect(menuItem->direction, menuItem->rect, sunkenRect);
6294                                 opt.state = menuItem->state;
6295                                 opt.state|=State_Raised|State_Horizontal|State_On;
6296                                 drawLightBevel(painter, sunkenRect, &opt, widget, ROUNDED_ALL, getFill(&opt, m_buttonCols), m_buttonCols);
6297                             }
6298                         }
6299                     }
6300                 }
6301 
6302                 // Text and icon, ripped from windows style
6303                 bool  dis(!(state&State_Enabled)),
6304                       act(state&State_Selected);
6305                 QRect vCheckRect(visualRect(option->direction, menuItem->rect,
6306                                             QRect(menuItem->rect.x(), menuItem->rect.y(), checkcol, menuItem->rect.height())));
6307 
6308                 if (opts.menuIcons && !menuItem->icon.isNull())
6309                 {
6310                     QIcon::Mode mode(dis ? QIcon::Disabled : QIcon::Normal);
6311 
6312                     if (act && !dis)
6313                         mode = QIcon::Active;
6314 
6315                     QPixmap pixmap(getIconPixmap(menuItem->icon, pixelMetric(PM_SmallIconSize), mode,
6316                                    checked ? QIcon::On : QIcon::Off));
6317 
6318                     int     pixw(pixmap.width()),
6319                             pixh(pixmap.height());
6320                     QRect   pmr(0, 0, pixw, pixh);
6321 
6322                     pmr.moveCenter(vCheckRect.center());
6323                     painter->setPen(palette.text().color());
6324                     if (checkable && checked)
6325                         painter->drawPixmap(QPoint(pmr.left() + 1, pmr.top() + 1), pixmap);
6326                     else
6327                         painter->drawPixmap(pmr.topLeft(), pixmap);
6328                 }
6329 
6330                 painter->setPen(dis
6331                                     ? palette.text().color()
6332                                     : selected && opts.useHighlightForMenu && !m_ooMenuCols
6333                                         ? palette.highlightedText().color()
6334                                         : palette.foreground().color());
6335 
6336                 int x, y, w, h,
6337                     tab(menuItem->tabWidth);
6338 
6339                 menuItem->rect.getRect(&x, &y, &w, &h);
6340 
6341                 int     xm(windowsItemFrame + checkcol + windowsItemHMargin -2),
6342                         xpos(menuItem->rect.x() + xm);
6343                 QRect   textRect(xpos, y + windowsItemVMargin,
6344                                  opts.menuIcons ? (w - xm - windowsRightBorder - tab + 1)
6345                                                 : (w - ((xm*2) + tab)),
6346                                  h - 2 * windowsItemVMargin),
6347                         vTextRect = visualRect(option->direction, menuItem->rect, textRect);
6348                 QString s(menuItem->text);
6349 
6350                 if (!s.isEmpty())                      // draw text
6351                 {
6352                     int t(s.indexOf(QLatin1Char('\t'))),
6353                         textFlags(Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine);
6354 
6355                     if (!styleHint(SH_UnderlineShortcut, menuItem, widget))
6356                         textFlags |= Qt::TextHideMnemonic;
6357                     textFlags |= Qt::AlignLeft;
6358 
6359                     if (t >= 0)
6360                     {
6361                         QRect vShortcutRect(visualRect(option->direction, menuItem->rect,
6362                                                     QRect(textRect.topRight(), QPoint(menuItem->rect.right(), textRect.bottom()))));
6363 
6364                         painter->drawText(vShortcutRect, textFlags, s.mid(t + 1));
6365                         s = s.left(t);
6366                     }
6367 
6368                     QFont font(menuItem->font);
6369 
6370                     if (menuItem->menuItemType == QStyleOptionMenuItem::DefaultItem)
6371                         font.setBold(true);
6372 
6373                     painter->setFont(font);
6374                     painter->drawText(vTextRect, textFlags, s.left(t));
6375                 }
6376 
6377                 // Arrow
6378                 if (QStyleOptionMenuItem::SubMenu==menuItem->menuItemType) // draw sub menu arrow
6379                 {
6380                     int              dim((menuItem->rect.height() - 4) / 2),
6381                                      xpos(menuItem->rect.left() + menuItem->rect.width() - 3 - dim);
6382                     PrimitiveElement arrow(Qt::RightToLeft==option->direction ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight);
6383                     QRect            vSubMenuRect(visualRect(option->direction, menuItem->rect,
6384                                                              QRect(xpos, menuItem->rect.top() + menuItem->rect.height() / 2 - dim / 2, dim, dim)));
6385 
6386                     drawArrow(painter, vSubMenuRect, arrow,
6387                               opts.useHighlightForMenu && state&State_Enabled && state&State_Selected && !m_ooMenuCols
6388                                 ? palette.highlightedText().color()
6389                                 : palette.text().color());
6390                 }
6391 
6392                 if(isOO)
6393                 {
6394                     painter->setPen(use[QTC_STD_BORDER]);
6395                     painter->drawLine(rx.topLeft(), rx.bottomLeft());
6396                     painter->drawLine(rx.topRight(), rx.bottomRight());
6397                 }
6398                 painter->restore();
6399             }
6400             break;
6401         case CE_MenuHMargin:
6402         case CE_MenuVMargin:
6403         case CE_MenuEmptyArea:
6404             break;
6405         case CE_PushButton:
6406             if (auto btn = styleOptCast<QStyleOptionButton>(option)) {
6407                 // For OO.o 3.2 need to fill widget background!
6408                 if(isOOWidget(widget))
6409                     painter->fillRect(r, palette.brush(QPalette::Window));
6410                 drawControl(CE_PushButtonBevel, btn, painter, widget);
6411 
6412                 QStyleOptionButton subopt(*btn);
6413 
6414                 subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
6415                 drawControl(CE_PushButtonLabel, &subopt, painter, widget);
6416 
6417                 if (state & State_HasFocus &&
6418                     !(state & State_MouseOver &&
6419                       oneOf(opts.focus, FOCUS_FULL, FOCUS_FILLED) &&
6420                       opts.coloredMouseOver != MO_NONE)) {
6421                     QStyleOptionFocusRect fropt;
6422                     fropt.QStyleOption::operator=(*btn);
6423                     fropt.rect = subElementRect(SE_PushButtonFocusRect, btn,
6424                                                 widget);
6425                     drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
6426                 }
6427             }
6428             break;
6429         case CE_PushButtonBevel:
6430             if (auto btn = styleOptCast<QStyleOptionButton>(option)) {
6431                 int dbi(pixelMetric(PM_ButtonDefaultIndicator, btn, widget));
6432 
6433                 if (btn->features & QStyleOptionButton::DefaultButton)
6434                     drawPrimitive(PE_FrameDefaultButton, option, painter, widget);
6435                 if (btn->features & QStyleOptionButton::AutoDefaultButton)
6436                     r.setCoords(r.left() + dbi, r.top() + dbi, r.right() - dbi, r.bottom() - dbi);
6437                 if (!(btn->features &
6438                       (QStyleOptionButton::Flat |
6439                        QStyleOptionButton::CommandLinkButton)) ||
6440                     state & (State_Sunken | State_On | State_MouseOver)) {
6441                     QStyleOptionButton tmpBtn(*btn);
6442 
6443                     tmpBtn.rect = r;
6444                     drawPrimitive(PE_PanelButtonCommand, &tmpBtn, painter, widget);
6445                 }
6446                 if (btn->features & QStyleOptionButton::HasMenu)
6447                 {
6448                     int   mbi(pixelMetric(PM_MenuButtonIndicator, btn, widget));
6449                     QRect ar(Qt::LeftToRight==btn->direction
6450                                 ? btn->rect.right() - (mbi+6)
6451                                 : btn->rect.x() + 6,
6452                              ((btn->rect.height() - mbi)/2),
6453                              mbi, mbi);
6454 
6455                     if(option->state &(State_On | State_Sunken))
6456                         ar.adjust(1, 1, 1, 1);
6457 
6458                     drawArrow(painter, ar, PE_IndicatorArrowDown,
6459                               MOArrow(state, palette, QPalette::ButtonText));
6460                 }
6461             }
6462             break;
6463         case CE_PushButtonLabel:
6464             if (auto button = styleOptCast<QStyleOptionButton>(option)) {
6465                 uint tf(Qt::AlignVCenter | Qt::TextShowMnemonic);
6466 
6467                 if (!styleHint(SH_UnderlineShortcut, button, widget))
6468                     tf |= Qt::TextHideMnemonic;
6469 
6470                 if (!button->icon.isNull())
6471                 {
6472                     //Center both icon and text
6473                     QIcon::Mode mode(button->state&State_Enabled ? QIcon::Normal : QIcon::Disabled);
6474 
6475                     if (QIcon::Normal==mode && button->state&State_HasFocus)
6476                         mode = QIcon::Active;
6477 
6478                     QIcon::State state((button->state&State_On) || (button->state&State_Sunken) ? QIcon::On : QIcon::Off);
6479                     QPixmap      pixmap(getIconPixmap(button->icon, button->iconSize, mode, state));
6480                     int          labelWidth(pixmap.width()),
6481                                  labelHeight(pixmap.height()),
6482                                  iconSpacing (4);//### 4 is currently hardcoded in QPushButton::sizeHint()
6483 
6484                     if (!button->text.isEmpty())
6485                         labelWidth += (button->fontMetrics.boundingRect(r, tf, button->text).width() + iconSpacing);
6486 
6487                     QRect iconRect(r.x() + (r.width() - labelWidth) / 2,
6488                                    r.y() + (r.height() - labelHeight) / 2,
6489                                    pixmap.width(), pixmap.height());
6490 
6491                     iconRect = visualRect(button->direction, r, iconRect);
6492 
6493                     tf |= Qt::AlignLeft; //left align, we adjust the text-rect instead
6494 
6495                     if (Qt::RightToLeft==button->direction)
6496                         r.setRight(iconRect.left() - iconSpacing);
6497                     else
6498                         r.setLeft(iconRect.left() + iconRect.width() + iconSpacing);
6499 
6500                     if (button->state & (State_On|State_Sunken))
6501                         iconRect.translate(pixelMetric(PM_ButtonShiftHorizontal, option, widget),
6502                                            pixelMetric(PM_ButtonShiftVertical, option, widget));
6503                     painter->drawPixmap(iconRect, pixmap);
6504                 }
6505                 else
6506                     tf |= Qt::AlignHCenter;
6507 
6508                 if (button->state & (State_On|State_Sunken))
6509                     r.translate(pixelMetric(PM_ButtonShiftHorizontal, option, widget),
6510                                 pixelMetric(PM_ButtonShiftVertical, option, widget));
6511 
6512                 // The following is mainly for DejaVu Sans 11...
6513                 if(button->fontMetrics.height()==19 && r.height()==(23+((opts.thin&THIN_BUTTONS) ? 0 : 2)))
6514                     r.translate(0, 1);
6515 
6516                 if (button->features & QStyleOptionButton::HasMenu) {
6517                     int mbi(pixelMetric(PM_MenuButtonIndicator, button, widget));
6518 
6519                     if (Qt::LeftToRight == button->direction) {
6520                         r = r.adjusted(0, 0, -mbi, 0);
6521                     } else {
6522                         r = r.adjusted(mbi, 0, 0, 0);
6523                     }
6524                 }
6525 
6526                 int num(opts.embolden && button->features&QStyleOptionButton::DefaultButton ? 2 : 1);
6527 
6528                 for(int i=0; i<num; ++i)
6529                     drawItemTextWithRole(painter, r.adjusted(i, 0, i, 0), tf, palette, (button->state&State_Enabled),
6530                                          button->text, QPalette::ButtonText);
6531             }
6532             break;
6533         case CE_ComboBoxLabel:
6534             if (auto comboBox = styleOptCast<QStyleOptionComboBox>(option)) {
6535                 QRect editRect = subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget);
6536                 bool  sunken=!comboBox->editable && (state&(State_On|State_Sunken));
6537                 int   shiftH=sunken ? pixelMetric(PM_ButtonShiftHorizontal, option, widget) : 0,
6538                       shiftV=sunken ? pixelMetric(PM_ButtonShiftVertical, option, widget) : 0;
6539 
6540                 painter->save();
6541 
6542                 if (!comboBox->currentIcon.isNull())
6543                 {
6544                     QPixmap pixmap = getIconPixmap(comboBox->currentIcon, comboBox->iconSize, state);
6545                     QRect   iconRect(editRect);
6546 
6547                     iconRect.setWidth(comboBox->iconSize.width() + 5);
6548                     if(!comboBox->editable)
6549                         iconRect = alignedRect(QApplication::layoutDirection(), Qt::AlignLeft|Qt::AlignVCenter,
6550                                                iconRect.size(), editRect);
6551                     if (comboBox->editable)
6552                     {
6553                         int adjust=opts.etchEntry ? 2 : 1;
6554 
6555                         if(opts.square&SQUARE_ENTRY || opts.round<ROUND_FULL)
6556                             painter->fillRect(iconRect.adjusted(adjust-1, adjust, -(adjust-1), -adjust), palette.brush(QPalette::Base));
6557                         else
6558                         {
6559                             painter->fillRect(iconRect.adjusted(1, adjust, -1, -adjust), palette.brush(QPalette::Base));
6560                             painter->fillRect(iconRect.adjusted(0, adjust+1, 0, -(adjust+1)), palette.brush(QPalette::Base));
6561                         }
6562                     }
6563 
6564                     if (sunken)
6565                         iconRect.translate(shiftH, shiftV);
6566 
6567                     drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
6568 
6569                     if (reverse)
6570                         editRect.translate(-4 - comboBox->iconSize.width(), 0);
6571                     else
6572                         editRect.translate(comboBox->iconSize.width() + 4, 0);
6573                 }
6574 
6575                 if (!comboBox->currentText.isEmpty() && !comboBox->editable)
6576                 {
6577                     if (sunken)
6578                         editRect.translate(shiftH, shiftV);
6579 
6580                     int margin=comboBox->frame && widget && widget->rect().height()<(opts.buttonEffect != EFFECT_NONE ? 22 : 20)  ? 4 : 0;
6581                     editRect.adjust(1, -margin, -1, margin);
6582                     painter->setClipRect(editRect);
6583                     drawItemTextWithRole(painter, editRect, Qt::AlignLeft|Qt::AlignVCenter, palette,
6584                                          state&State_Enabled, comboBox->currentText, QPalette::ButtonText);
6585                 }
6586                 painter->restore();
6587             }
6588             break;
6589         case CE_MenuBarEmptyArea: {
6590             painter->save();
6591             if (!opts.xbar ||
6592                 (!widget || noneOf(widget->metaObject()->className(), "QWidget"))) {
6593                 drawMenuOrToolBarBackground(widget, painter, r, option);
6594             }
6595             if (TB_NONE != opts.toolbarBorders && widget &&
6596                 widget->parentWidget() &&
6597                 (qobject_cast<const QMainWindow*>(widget->parentWidget()) ||
6598                  widget->parentWidget()->inherits("Q3MainWindow"))) {
6599                 const QColor *use = menuColors(option, m_active);
6600                 bool dark = (TB_DARK == opts.toolbarBorders ||
6601                              TB_DARK_ALL == opts.toolbarBorders);
6602 
6603                 if (TB_DARK_ALL == opts.toolbarBorders ||
6604                     TB_LIGHT_ALL == opts.toolbarBorders) {
6605                     painter->setPen(use[0]);
6606                     painter->drawLine(r.x(), r.y(),
6607                                       r.x() + r.width() - 1, r.y());
6608                     painter->drawLine(r.x(), r.y(), r.x(),
6609                                       r.y() + r.width() - 1);
6610                     painter->setPen(use[dark ? 3 : 4]);
6611                     painter->drawLine(r.x(), r.y() + r.height() - 1,
6612                                       r.x() + r.width() - 1,
6613                                       r.y() + r.height() - 1);
6614                     painter->drawLine(r.x() + r.width() - 1, r.y(),
6615                                       r.x() + r.width() - 1,
6616                                       r.y() + r.height() - 1);
6617                 } else {
6618                     painter->setPen(use[dark ? 3 : 4]);
6619                     painter->drawLine(r.x(), r.y() + r.height() - 1,
6620                                       r.x() + r.width() - 1,
6621                                       r.y() + r.height() - 1);
6622                 }
6623             }
6624             painter->restore();
6625             break;
6626         }
6627         case CE_TabBarTabLabel:
6628             if (auto tab = styleOptCast<QStyleOptionTab>(option)) {
6629                 QStyleOptionTabV3 tabV2(*tab);
6630                 bool verticalTabs(QTabBar::RoundedEast==tabV2.shape || QTabBar::RoundedWest==tabV2.shape ||
6631                                   QTabBar::TriangularEast==tabV2.shape || QTabBar::TriangularWest==tabV2.shape),
6632                      toolbarTab=!opts.toolbarTabs && widget && widget->parentWidget() &&
6633                                 qobject_cast<QToolBar*>(widget->parentWidget());
6634 
6635                 if (verticalTabs)
6636                 {
6637                     painter->save();
6638                     int newX, newY, newRot;
6639                     if (QTabBar::RoundedEast==tabV2.shape || QTabBar::TriangularEast==tabV2.shape)
6640                     {
6641                         newX = r.width();
6642                         newY = r.y();
6643                         newRot = 90;
6644                     }
6645                     else
6646                     {
6647                         newX = 0;
6648                         newY = r.y() + r.height();
6649                         newRot = -90;
6650                     }
6651                     r.setRect(0, 0, r.height(), r.width());
6652 
6653                     QTransform m;
6654                     m.translate(newX, newY);
6655                     m.rotate(newRot);
6656                     painter->setTransform(m, true);
6657                 }
6658 
6659                 int alignment(Qt::AlignVCenter | Qt::TextShowMnemonic | (opts.centerTabText ? Qt::AlignHCenter : Qt::AlignLeft));
6660 
6661                 if (!styleHint(SH_UnderlineShortcut, option, widget))
6662                     alignment |= Qt::TextHideMnemonic;
6663 
6664                 if(toolbarTab)
6665                     tabV2.state&=~State_Selected;
6666                 r = subElementRect(SE_TabBarTabText, &tabV2, widget);
6667                 if (!tabV2.icon.isNull())
6668                 {
6669                     QSize iconSize(tabV2.iconSize);
6670                     if (!iconSize.isValid())
6671                     {
6672                         int iconExtent(pixelMetric(PM_SmallIconSize));
6673                         iconSize = QSize(iconExtent, iconExtent);
6674                     }
6675 
6676                     QPixmap tabIcon(getIconPixmap(tabV2.icon, iconSize, state&State_Enabled));
6677                     QSize   tabIconSize = tabV2.icon.actualSize(iconSize, tabV2.state&State_Enabled
6678                                                                   ? QIcon::Normal
6679                                                                   : QIcon::Disabled);
6680 
6681                     int offset = 4,
6682                         left = option->rect.left();
6683                     if (tabV2.leftButtonSize.isNull() || tabV2.leftButtonSize.width()<=0)
6684                         offset += 2;
6685                     else
6686                         left += tabV2.leftButtonSize.width() + 2;
6687                     QRect iconRect = QRect(left + offset, r.center().y() - tabIcon.height() / 2,
6688                                            tabIconSize.width(), tabIconSize.height());
6689                     if (!verticalTabs)
6690                         iconRect = visualRect(option->direction, option->rect, iconRect);
6691                     painter->drawPixmap(iconRect.x(), iconRect.y(), tabIcon);
6692                 }
6693 
6694                 if(!tab->text.isEmpty())
6695                 {
6696                     drawItemTextWithRole(painter, r, alignment, tab->palette, tab->state&State_Enabled, tab->text,
6697                                          !opts.stdSidebarButtons && toolbarTab && state&State_Selected
6698                                             ? QPalette::HighlightedText : QPalette::WindowText);
6699                 }
6700 
6701                 if (verticalTabs)
6702                     painter->restore();
6703 
6704                 if (tabV2.state & State_HasFocus)
6705                 {
6706                     const int constOffset = 1 + pixelMetric(PM_DefaultFrameWidth);
6707 
6708                     int                   x1=tabV2.rect.left(),
6709                                           x2=tabV2.rect.right() - 1;
6710                     QStyleOptionFocusRect fropt;
6711                     fropt.QStyleOption::operator=(*tab);
6712                     fropt.rect.setRect(x1 + 1 + constOffset, tabV2.rect.y() + constOffset,
6713                                        x2 - x1 - 2*constOffset, tabV2.rect.height() - 2*constOffset);
6714 
6715                     fropt.state|=State_Horizontal;
6716                     if(FOCUS_LINE!=opts.focus)
6717                     {
6718                         if(QTabBar::RoundedNorth==tabV2.shape || QTabBar::TriangularNorth==tabV2.shape)
6719                             fropt.rect.adjust(0, 1, 0, 0);
6720                     }
6721                     else if(TAB_MO_BOTTOM==opts.tabMouseOver && FOCUS_LINE==opts.focus)
6722                         switch(tabV2.shape)
6723                         {
6724                             case QTabBar::RoundedNorth:
6725                             case QTabBar::TriangularNorth:
6726                                 fropt.rect.adjust(0, 0, 0, 1);
6727                                 break;
6728                             case QTabBar::RoundedEast:
6729                             case QTabBar::TriangularEast:
6730                                 fropt.rect.adjust(-2, 0, -(fropt.rect.width()+1), 0);
6731                                 fropt.state&=~State_Horizontal;
6732                                 break;
6733                             case QTabBar::RoundedSouth:
6734                             case QTabBar::TriangularSouth:
6735                                 fropt.rect.adjust(0, 0, 0, 1);
6736                                 break;
6737                             case QTabBar::RoundedWest:
6738                             case QTabBar::TriangularWest:
6739                                 fropt.rect.adjust(0, 0, 2, 0);
6740                                 fropt.state&=~State_Horizontal;
6741                             default:
6742                                 break;
6743                         }
6744 
6745                     drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
6746                 }
6747             }
6748             break;
6749         case CE_TabBarTabShape:
6750             if(!opts.toolbarTabs && widget && widget->parentWidget() && qobject_cast<QToolBar*>(widget->parentWidget()))
6751             {
6752                 QStyleOption opt(*option);
6753                 if(state&State_Selected)
6754                     opt.state|=State_On;
6755                 if(opts.stdSidebarButtons)
6756                 {
6757                     if(state&(State_Selected|State_MouseOver))
6758                     {
6759                         opt.state|=STATE_TBAR_BUTTON;
6760                         drawPrimitive(PE_PanelButtonTool, &opt, painter, widget);
6761                     }
6762                 }
6763                 else
6764                     drawSideBarButton(painter, r, &opt, widget);
6765             } else if (auto tab = styleOptCast<QStyleOptionTab>(option)) {
6766                 bool onlyTab(widget && widget->parentWidget()
6767                                 ? qobject_cast<const QTabWidget*>(widget->parentWidget()) ? false : true
6768                                 : false),
6769                      selected(state&State_Selected),
6770                      horiz(QTabBar::RoundedNorth==tab->shape || QTabBar::RoundedSouth==tab->shape);
6771 
6772                 QStyleOptionTabV3 tabV3(*tab);
6773                 QRect        r2(r);
6774                 bool         rtlHorTabs(Qt::RightToLeft==tab->direction && horiz),
6775                              oneTab(QStyleOptionTab::OnlyOneTab==tab->position),
6776                              leftCornerWidget(tab->cornerWidgets&QStyleOptionTab::LeftCornerWidget),
6777                              rightCornerWidget(tab->cornerWidgets&QStyleOptionTab::RightCornerWidget),
6778                              firstTab((tab->position == (Qt::LeftToRight==tab->direction || !horiz ?
6779                                        QStyleOptionTab::Beginning : QStyleOptionTab::End)) || oneTab),
6780                              lastTab((tab->position == (Qt::LeftToRight==tab->direction  || !horiz ?
6781                                      QStyleOptionTab::End : QStyleOptionTab::Beginning)) || oneTab);
6782                 int          tabBarAlignment(styleHint(SH_TabBar_Alignment, tab, widget)),
6783                              tabOverlap(oneTab ? 0 : pixelMetric(PM_TabBarTabOverlap, option, widget)),
6784                              moOffset(ROUND_NONE==opts.round || TAB_MO_TOP!=opts.tabMouseOver ? 1 : opts.round),
6785                              highlightOffset(opts.highlightTab && opts.round>ROUND_SLIGHT ? 2 : 1),
6786                              highlightBorder(opts.round>ROUND_FULL ? 4 : 3),
6787                              sizeAdjust(!selected && TAB_MO_GLOW==opts.tabMouseOver ? 1 : 0);
6788                 bool         leftAligned((!rtlHorTabs && Qt::AlignLeft==tabBarAlignment) ||
6789                                  (rtlHorTabs && Qt::AlignRight==tabBarAlignment)),
6790                              rightAligned((!rtlHorTabs && Qt::AlignRight==tabBarAlignment) ||
6791                                           (rtlHorTabs && Qt::AlignLeft==tabBarAlignment)),
6792                              docMode(tabV3.documentMode),
6793                              docFixLeft(!leftCornerWidget && leftAligned && firstTab && (docMode || onlyTab)),
6794                              fixLeft(!onlyTab && !leftCornerWidget && leftAligned && firstTab && !docMode),
6795                              fixRight(!onlyTab && !rightCornerWidget && rightAligned && lastTab && !docMode),
6796                              mouseOver(state&State_Enabled && state&State_MouseOver),
6797                              glowMo(!selected && mouseOver && opts.coloredMouseOver && TAB_MO_GLOW==opts.tabMouseOver),
6798                              thin(opts.thin&THIN_FRAMES),
6799                              drawOuterGlow(glowMo && !thin);
6800                 const QColor *use(backgroundColors(option));
6801                 QColor       fill(getTabFill(selected, mouseOver, use));
6802                 double       radius=qtcGetRadius(&opts, r.width(), r.height(), WIDGET_TAB_TOP, RADIUS_EXTERNAL);
6803                 EBorder      borderProfile(selected || opts.borderInactiveTab
6804                                             ? opts.borderTab
6805                                                 ? BORDER_LIGHT
6806                                                 : BORDER_RAISED
6807                                             : BORDER_FLAT);
6808 
6809                 painter->save();
6810 
6811                 if(!selected && (100!=opts.bgndOpacity || 100!=opts.dlgOpacity))
6812                 {
6813                     QWidget *top = widget ? widget->window() : 0L;
6814                     bool isDialog = top && qtcIsDialog(top);
6815 
6816                     // Note: opacity is divided by 150 to make dark inactive tabs more translucent
6817                     if(isDialog && 100!=opts.dlgOpacity)
6818                         fill.setAlphaF(opts.dlgOpacity/150.0);
6819                     else if(!isDialog && 100!=opts.bgndOpacity)
6820                         fill.setAlphaF(opts.bgndOpacity/150.0);
6821                 }
6822 
6823                 switch(tab->shape)
6824                 {
6825                     case QTabBar::RoundedNorth:
6826                     case QTabBar::TriangularNorth:
6827                     {
6828                         int round=selected || oneTab || TAB_MO_GLOW==opts.tabMouseOver || opts.roundAllTabs
6829                                         ? ROUNDED_TOP
6830                                         : firstTab
6831                                             ? ROUNDED_TOPLEFT
6832                                             : lastTab
6833                                                 ? ROUNDED_TOPRIGHT
6834                                                 : ROUNDED_NONE;
6835                         if(!selected)
6836                             r.adjust(0, 2, 0, -2);
6837 
6838                         if(!firstTab)
6839                             r.adjust(-tabOverlap, 0, 0, 0);
6840                         painter->setClipPath(buildPath(r.adjusted(0, 0, 0, 4), WIDGET_TAB_TOP, round, radius));
6841                         fillTab(painter, r.adjusted(1+sizeAdjust, 1, -(1+sizeAdjust), 0), option, fill, true, WIDGET_TAB_TOP, (docMode || onlyTab));
6842                         // This clipping (for selected) helps with plasma's tabs and nvidia
6843                         if(selected || thin)
6844                             painter->setClipRect(r2.adjusted(-1, 0, 1, -1));
6845                         else
6846                             painter->setClipping(false);
6847                         drawBorder(painter, r.adjusted(sizeAdjust, 0, -sizeAdjust, 4), option, round, glowMo ? m_mouseOverCols : 0L,
6848                                    WIDGET_TAB_TOP, borderProfile, false);
6849                         if(drawOuterGlow)
6850                             drawGlow(painter, r.adjusted(0, -1, 0, 5), WIDGET_TAB_TOP);
6851 
6852                         if(selected || thin)
6853                             painter->setClipping(false);
6854 
6855                         if(selected)
6856                         {
6857                             if(!thin)
6858                             {
6859                                 painter->setPen(use[0]);
6860 
6861                                 // The point drawn below is because of the clipping above...
6862                                 if(fixLeft)
6863                                     painter->drawPoint(r2.x()+1, r2.y()+r2.height()-1);
6864                                 else
6865                                     painter->drawLine(r2.left()-1, r2.bottom(), r2.left(), r2.bottom());
6866                                 if(!fixRight)
6867                                     painter->drawLine(r2.right()-1, r2.bottom(), r2.right(), r2.bottom());
6868                             }
6869 
6870                             if(docFixLeft)
6871                             {
6872                                 QColor col(use[QTC_STD_BORDER]);
6873                                 col.setAlphaF(0.5);
6874                                 painter->setPen(col);
6875                                 painter->drawPoint(r2.x(), r2.y()+r2.height()-1);
6876                             }
6877                         }
6878                         else
6879                         {
6880                             int l(fixLeft ? r2.left()+(opts.round>ROUND_SLIGHT && !(opts.square&SQUARE_TAB_FRAME) ? 2 : 1) : r2.left()-1),
6881                                 r(fixRight ? r2.right()-2 : r2.right()+1);
6882                             painter->setPen(use[QTC_STD_BORDER]);
6883                             painter->drawLine(l, r2.bottom()-1, r, r2.bottom()-1);
6884                             if(!thin)
6885                             {
6886                                 painter->setPen(use[0]);
6887                                 painter->drawLine(l, r2.bottom(), r, r2.bottom());
6888                             }
6889                         }
6890 
6891                         if(selected)
6892                         {
6893                             if(opts.highlightTab)
6894                             {
6895                                 QColor col(m_highlightCols[0]);
6896                                 painter->setRenderHint(QPainter::Antialiasing, true);
6897                                 painter->setPen(col);
6898                                 drawAaLine(painter, r.left()+highlightOffset, r.top()+1, r.right()-highlightOffset, r.top()+1);
6899                                 col.setAlphaF(0.5);
6900                                 painter->setPen(col);
6901                                 drawAaLine(painter, r.left()+1, r.top()+2, r.right()-1, r.top()+2);
6902                                 painter->setRenderHint(QPainter::Antialiasing, false);
6903                                 painter->setClipRect(QRect(r.x(), r.y(), r.width(), highlightBorder));
6904                                 drawBorder(painter, r, option, ROUNDED_ALL, m_highlightCols, WIDGET_TAB_TOP, BORDER_FLAT, false, 3);
6905                             }
6906 
6907                             if(opts.colorSelTab)
6908                                 colorTab(painter, r.adjusted(1+sizeAdjust, 1, -(1+sizeAdjust), 0), true, WIDGET_TAB_TOP, round);
6909                         }
6910                         else if(mouseOver && opts.coloredMouseOver && TAB_MO_GLOW!=opts.tabMouseOver)
6911                             drawHighlight(painter, QRect(r.x()+(firstTab ? moOffset : 1),
6912                                                          r.y()+(TAB_MO_TOP==opts.tabMouseOver ? 0 : r.height()-1),
6913                                                          r.width()-(firstTab || lastTab ? moOffset : 1), 2),
6914                                           true, TAB_MO_TOP==opts.tabMouseOver);
6915                         break;
6916                     }
6917                     case QTabBar::RoundedSouth:
6918                     case QTabBar::TriangularSouth:
6919                     {
6920                         int round=selected || oneTab || TAB_MO_GLOW==opts.tabMouseOver || opts.roundAllTabs
6921                                         ? ROUNDED_BOTTOM
6922                                         : firstTab
6923                                             ? ROUNDED_BOTTOMLEFT
6924                                             : lastTab
6925                                                 ? ROUNDED_BOTTOMRIGHT
6926                                                 : ROUNDED_NONE;
6927                         if(!selected)
6928                             r.adjust(0, 2, 0, -2);
6929                         if(!firstTab)
6930                             r.adjust(-tabOverlap, 0, 0, 0);
6931 
6932                         painter->setClipPath(buildPath(r.adjusted(0, -4, 0, 0), WIDGET_TAB_BOT, round, radius));
6933                         fillTab(painter, r.adjusted(1+sizeAdjust, 0, -(1+sizeAdjust), -1), option, fill, true, WIDGET_TAB_BOT, (docMode || onlyTab));
6934                         if(thin)
6935                             painter->setClipRect(r2.adjusted(0, 1, 0, 0));
6936                         else
6937                             painter->setClipping(false);
6938                         drawBorder(painter, r.adjusted(sizeAdjust, -4, -sizeAdjust, 0), option, round, glowMo ? m_mouseOverCols : 0L,
6939                                    WIDGET_TAB_BOT, borderProfile, false);
6940                         if(thin)
6941                             painter->setClipping(false);
6942                         if(drawOuterGlow)
6943                             drawGlow(painter, r.adjusted(0, -5, 0, 1), WIDGET_TAB_BOT);
6944 
6945                         if(selected)
6946                         {
6947                             if(!thin)
6948                             {
6949                                 painter->setPen(use[opts.borderTab ? 0 : FRAME_DARK_SHADOW]);
6950                                 if(!fixLeft)
6951                                     painter->drawPoint(r2.left()-(TAB_MO_GLOW==opts.tabMouseOver ? 0 : 1), r2.top());
6952                                 if(!fixRight)
6953                                     painter->drawLine(r2.right()-(TAB_MO_GLOW==opts.tabMouseOver ? 0 : 1), r2.top(), r2.right(), r2.top());
6954                             }
6955                             if(docFixLeft)
6956                             {
6957                                 QColor col(use[QTC_STD_BORDER]);
6958                                 col.setAlphaF(0.5);
6959                                 painter->setPen(col);
6960                                 painter->drawPoint(r2.x(), r2.y());
6961                             }
6962                         }
6963                         else
6964                         {
6965                             int l(fixLeft ? r2.left()+(opts.round>ROUND_SLIGHT && !(opts.square&SQUARE_TAB_FRAME)? 2 : 1) : r2.left()-1),
6966                                 r(fixRight ? r2.right()-2 : r2.right());
6967                             painter->setPen(use[QTC_STD_BORDER]);
6968                             painter->drawLine(l, r2.top()+1, r, r2.top()+1);
6969                             if(!thin)
6970                             {
6971                                 painter->setPen(use[opts.borderTab ? 0 : FRAME_DARK_SHADOW]);
6972                                 painter->drawLine(l, r2.top(), r, r2.top());
6973                             }
6974                         }
6975 
6976                         if(selected)
6977                         {
6978                             if(opts.highlightTab)
6979                             {
6980                                 QColor col(m_highlightCols[0]);
6981                                 painter->setRenderHint(QPainter::Antialiasing, true);
6982                                 painter->setPen(col);
6983                                 drawAaLine(painter, r.left()+highlightOffset, r.bottom()-1, r.right()-highlightOffset, r.bottom()-1);
6984                                 col.setAlphaF(0.5);
6985                                 painter->setPen(col);
6986                                 drawAaLine(painter, r.left()+1, r.bottom()-2, r.right()-1, r.bottom()-2);
6987                                 painter->setRenderHint(QPainter::Antialiasing, false);
6988                                 painter->setClipRect(QRect(r.x(), r.y()+r.height()-highlightBorder, r.width(), r.y()+r.height()-1));
6989                                 drawBorder(painter, r, option, ROUNDED_ALL, m_highlightCols, WIDGET_TAB_BOT, BORDER_FLAT, false, 3);
6990                             }
6991 
6992                             if(opts.colorSelTab)
6993                                 colorTab(painter, r.adjusted(1+sizeAdjust, 0, -(1+sizeAdjust), -1), true, WIDGET_TAB_BOT, round);
6994                         }
6995                         else if(mouseOver && opts.coloredMouseOver && TAB_MO_GLOW!=opts.tabMouseOver)
6996                             drawHighlight(painter, QRect(r.x()+(firstTab ? moOffset : 1),
6997                                                          r.y()+(TAB_MO_TOP==opts.tabMouseOver ? r.height()-2 : -1),
6998                                                          r.width()-(firstTab || lastTab ? moOffset : 1), 2),
6999                                           true, TAB_MO_TOP!=opts.tabMouseOver);
7000                         break;
7001                     }
7002                     case QTabBar::RoundedWest:
7003                     case QTabBar::TriangularWest:
7004                     {
7005                         int round=selected || oneTab || TAB_MO_GLOW==opts.tabMouseOver || opts.roundAllTabs
7006                                         ? ROUNDED_LEFT
7007                                         : firstTab
7008                                             ? ROUNDED_TOPLEFT
7009                                             : lastTab
7010                                                 ? ROUNDED_BOTTOMLEFT
7011                                                 : ROUNDED_NONE;
7012                         if(!selected)
7013                             r.adjust(2, 0, -2, 0);
7014 
7015                         if(!firstTab)
7016                             r.adjust(0, -tabOverlap, 0, 0);
7017                         painter->setClipPath(buildPath(r.adjusted(0, 0, 4, 0), WIDGET_TAB_TOP, round, radius));
7018                         fillTab(painter, r.adjusted(1, sizeAdjust, 0, -(1+sizeAdjust)), option, fill, false, WIDGET_TAB_TOP, (docMode || onlyTab));
7019                         if(thin)
7020                             painter->setClipRect(r2.adjusted(0, 0, -1, 0));
7021                         else
7022                             painter->setClipping(false);
7023                         drawBorder(painter, r.adjusted(0, sizeAdjust, 4, -sizeAdjust), option, round, glowMo ? m_mouseOverCols : 0L,
7024                                    WIDGET_TAB_TOP, borderProfile, false);
7025                         if(thin)
7026                             painter->setClipping(false);
7027                         if(drawOuterGlow)
7028                             drawGlow(painter, r.adjusted(-1, 0, 5, 0), WIDGET_TAB_TOP);
7029 
7030                         if(selected)
7031                         {
7032                             if(!thin)
7033                             {
7034                                 painter->setPen(use[0]);
7035                                 if(!firstTab)
7036                                     painter->drawPoint(r2.right(), r2.top()-(TAB_MO_GLOW==opts.tabMouseOver ? 0 : 1));
7037                                 painter->drawLine(r2.right(), r2.bottom()-1, r2.right(), r2.bottom());
7038                             }
7039                         }
7040                         else
7041                         {
7042                             int t(firstTab ? r2.top()+(opts.round>ROUND_SLIGHT && !(opts.square&SQUARE_TAB_FRAME)? 2 : 1) : r2.top()-1),
7043                                 b(/*lastTab ? r2.bottom()-2 : */ r2.bottom()+1);
7044 
7045                             painter->setPen(use[QTC_STD_BORDER]);
7046                             painter->drawLine(r2.right()-1, t, r2.right()-1, b);
7047                             if(!thin)
7048                             {
7049                                 painter->setPen(use[0]);
7050                                 painter->drawLine(r2.right(), t, r2.right(), b);
7051                             }
7052                         }
7053 
7054                         if(selected)
7055                         {
7056                             if(opts.highlightTab)
7057                             {
7058                                 QColor col(m_highlightCols[0]);
7059                                 painter->setRenderHint(QPainter::Antialiasing, true);
7060                                 painter->setPen(col);
7061                                 drawAaLine(painter, r.left()+1, r.top()+highlightOffset, r.left()+1, r.bottom()-highlightOffset);
7062                                 col.setAlphaF(0.5);
7063                                 painter->setPen(col);
7064                                 drawAaLine(painter, r.left()+2, r.top()+1, r.left()+2, r.bottom()-1);
7065                                 painter->setRenderHint(QPainter::Antialiasing, false);
7066                                 painter->setClipRect(QRect(r.x(), r.y(), highlightBorder, r.height()));
7067                                 drawBorder(painter, r, option, ROUNDED_ALL, m_highlightCols, WIDGET_TAB_TOP, BORDER_FLAT, false, 3);
7068                             }
7069 
7070                             if(opts.colorSelTab)
7071                                 colorTab(painter, r.adjusted(1, sizeAdjust, 0, -(1+sizeAdjust)), false, WIDGET_TAB_TOP, round);
7072                         }
7073                         else if(mouseOver && opts.coloredMouseOver && TAB_MO_GLOW!=opts.tabMouseOver)
7074                             drawHighlight(painter, QRect(r.x()+(TAB_MO_TOP==opts.tabMouseOver ? 0 : r.width()-1),
7075                                                          r.y()+(firstTab ? moOffset : 1),
7076                                                          2, r.height()-(firstTab || lastTab ? moOffset : 1)),
7077                                           false, TAB_MO_TOP==opts.tabMouseOver);
7078                         break;
7079                     }
7080                     case QTabBar::RoundedEast:
7081                     case QTabBar::TriangularEast:
7082                     {
7083                         int round=selected || oneTab || TAB_MO_GLOW==opts.tabMouseOver || opts.roundAllTabs
7084                                         ? ROUNDED_RIGHT
7085                                         : firstTab
7086                                             ? ROUNDED_TOPRIGHT
7087                                             : lastTab
7088                                                 ? ROUNDED_BOTTOMRIGHT
7089                                                 : ROUNDED_NONE;
7090                         if(!selected)
7091                             r.adjust(2, 0, -2, 0);
7092 
7093                         if(!firstTab)
7094                             r.adjust(0, -tabOverlap, 0, 0);
7095                         painter->setClipPath(buildPath(r.adjusted(-4, 0, 0, 0), WIDGET_TAB_BOT, round, radius));
7096                         fillTab(painter, r.adjusted(0, sizeAdjust, -1, -(1+sizeAdjust)), option, fill, false, WIDGET_TAB_BOT, (docMode || onlyTab));
7097                         if(thin)
7098                             painter->setClipRect(r2.adjusted(1, 0, 0, 0));
7099                         else
7100                             painter->setClipping(false);
7101                         drawBorder(painter, r.adjusted(-4, sizeAdjust, 0, -sizeAdjust), option, round, glowMo ? m_mouseOverCols : 0L,
7102                                    WIDGET_TAB_BOT, borderProfile, false);
7103                         if(thin)
7104                             painter->setClipping(false);
7105                         if(drawOuterGlow)
7106                             drawGlow(painter, r.adjusted(-5, 0, 1, 0), WIDGET_TAB_BOT);
7107 
7108                         if(selected)
7109                         {
7110                             if(!thin)
7111                             {
7112                                 painter->setPen(use[opts.borderTab ? 0 : FRAME_DARK_SHADOW]);
7113                                 if(!firstTab)
7114                                     painter->drawPoint(r2.left(), r2.top()-(TAB_MO_GLOW==opts.tabMouseOver ? 0 : 1));
7115                                 painter->drawLine(r2.left(), r2.bottom()-(TAB_MO_GLOW==opts.tabMouseOver ? 0 : 1), r2.left(), r2.bottom());
7116                             }
7117                         }
7118                         else
7119                         {
7120                             int t(firstTab ? r2.top()+(opts.round>ROUND_SLIGHT && !(opts.square&SQUARE_TAB_FRAME)? 2 : 1) : r2.top()-1),
7121                                 b(/*lastTab ? r2.bottom()-2 : */ r2.bottom()+1);
7122 
7123                             painter->setPen(use[QTC_STD_BORDER]);
7124                             painter->drawLine(r2.left()+1, t, r2.left()+1, b);
7125                             if(!thin)
7126                             {
7127                                 painter->setPen(use[opts.borderTab ? 0 : FRAME_DARK_SHADOW]);
7128                                 painter->drawLine(r2.left(), t, r2.left(), b);
7129                             }
7130                         }
7131 
7132                         if(selected)
7133                         {
7134                             if(opts.highlightTab)
7135                             {
7136                                 QColor col(m_highlightCols[0]);
7137                                 painter->setRenderHint(QPainter::Antialiasing, true);
7138                                 painter->setPen(col);
7139                                 drawAaLine(painter, r.right()-1, r.top()+highlightOffset, r.right()-1, r.bottom()-highlightOffset);
7140                                 col.setAlphaF(0.5);
7141                                 painter->setPen(col);
7142                                 drawAaLine(painter, r.right()-2, r.top()+1, r.right()-2, r.bottom()-1);
7143                                 painter->setRenderHint(QPainter::Antialiasing, false);
7144                                 painter->setClipRect(QRect(r.x()+r.width()-highlightBorder, r.y(), r.x()+r.width()-1, r.height()));
7145                                 drawBorder(painter, r, option, ROUNDED_ALL, m_highlightCols, WIDGET_TAB_TOP, BORDER_FLAT, false, 3);
7146                             }
7147 
7148                             if(opts.colorSelTab)
7149                                 colorTab(painter, r.adjusted(0, sizeAdjust, -1, -(1+sizeAdjust)), false, WIDGET_TAB_BOT, round);
7150                         }
7151                         else if(mouseOver && opts.coloredMouseOver && TAB_MO_GLOW!=opts.tabMouseOver)
7152                             drawHighlight(painter, QRect(r.x()+(TAB_MO_TOP==opts.tabMouseOver ? r.width()-2 : -1),
7153                                                          r.y()+(firstTab ? moOffset : 1),
7154                                                          2, r.height()-(firstTab || lastTab ? moOffset : 1)),
7155                                           false, TAB_MO_TOP!=opts.tabMouseOver);
7156                         break;
7157                     }
7158                 }
7159                 painter->restore();
7160             }
7161             break;
7162         case CE_ScrollBarAddLine:
7163         case CE_ScrollBarSubLine:
7164         {
7165             QRect            br(r),
7166                              ar(r);
7167             const QColor     *use(state&State_Enabled ? m_buttonCols : m_backgroundCols); // buttonColors(option));
7168             bool             reverse(option && Qt::RightToLeft==option->direction);
7169             PrimitiveElement pe=state&State_Horizontal
7170                                  ? CE_ScrollBarAddLine==element ? (reverse ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight)
7171                                                                 : (reverse ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft)
7172                                  : CE_ScrollBarAddLine==element ? PE_IndicatorArrowDown : PE_IndicatorArrowUp;
7173             int              round=PE_IndicatorArrowRight==pe ? ROUNDED_RIGHT :
7174                                    PE_IndicatorArrowLeft==pe ? ROUNDED_LEFT :
7175                                    PE_IndicatorArrowDown==pe ? ROUNDED_BOTTOM :
7176                                    PE_IndicatorArrowUp==pe ? ROUNDED_TOP : ROUNDED_NONE;
7177 
7178             switch(opts.scrollbarType)
7179             {
7180             default:
7181             case SCROLLBAR_WINDOWS:
7182                 break;
7183             case SCROLLBAR_KDE:
7184             case SCROLLBAR_PLATINUM:
7185                 if (!reverse && PE_IndicatorArrowLeft == pe && r.x() > 3) {
7186                     round = ROUNDED_NONE;
7187                     br.adjust(0, 0, 1, 0);
7188                     if (opts.flatSbarButtons || !opts.vArrows) {
7189                         ar.adjust(1, 0, 1, 0);
7190                     }
7191                 } else if(reverse && PE_IndicatorArrowRight == pe && r.x() > 3) {
7192                     if (SCROLLBAR_PLATINUM == opts.scrollbarType) {
7193                         round = ROUNDED_NONE;
7194                         br.adjust(-1, 0, 0, 0);
7195                         if (opts.flatSbarButtons || !opts.vArrows) {
7196                             ar.adjust(-1, 0, -1, 0);
7197                         }
7198                     } else {
7199                         if(r.x() < pixelMetric(PM_ScrollBarExtent, option, widget)+2)
7200                             round = ROUNDED_NONE;
7201                         br.adjust(0, 0, 1, 0);
7202                         if (opts.flatSbarButtons || !opts.vArrows) {
7203                             ar.adjust(1, 0, 1, 0);
7204                         }
7205                     }
7206                 } else if (PE_IndicatorArrowUp == pe && r.y() > 3) {
7207                     round = ROUNDED_NONE;
7208                     br.adjust(0, 0, 0, 1);
7209                     if (opts.flatSbarButtons || !opts.vArrows) {
7210                             ar.adjust(0, 1, 0, 1);
7211                     }
7212                 }
7213                 break;
7214             case SCROLLBAR_NEXT:
7215                 if (!reverse && PE_IndicatorArrowRight == pe) {
7216                     round = ROUNDED_NONE;
7217                     br.adjust(-1, 0, 0, 0);
7218                     if (opts.flatSbarButtons || !opts.vArrows) {
7219                         ar.adjust(-1, 0, 0, -1);
7220                     }
7221                 } else if (reverse && PE_IndicatorArrowLeft == pe) {
7222                     round = ROUNDED_NONE;
7223                     br.adjust(0, 0, 1, 0);
7224                     if (opts.flatSbarButtons || !opts.vArrows) {
7225                         ar.adjust(-1, 0, 0, 1);
7226                     }
7227                 } else if (PE_IndicatorArrowDown == pe) {
7228                     round = ROUNDED_NONE;
7229                     br.adjust(0, -1, 0, 0);
7230                     if (opts.flatSbarButtons || !opts.vArrows) {
7231                         ar.adjust(0, -1, 0, -1);
7232                     }
7233                 }
7234                 break;
7235             }
7236 
7237             painter->save();
7238             if(opts.flatSbarButtons && !qtcIsFlat(opts.sbarBgndAppearance) /*&& SCROLLBAR_NONE!=opts.scrollbarType*/)
7239                 drawBevelGradientReal(palette.brush(QPalette::Background).color(), painter, r, state&State_Horizontal, false,
7240                                       opts.sbarBgndAppearance, WIDGET_SB_BGND);
7241 
7242             QStyleOption opt(*option);
7243 
7244             opt.state|=State_Raised;
7245 
7246             if (auto slider = styleOptCast<QStyleOptionSlider>(option)) {
7247                 if((CE_ScrollBarSubLine==element && slider->sliderValue==slider->minimum) ||
7248                    (CE_ScrollBarAddLine==element && slider->sliderValue==slider->maximum))
7249                     opt.state&=~(State_MouseOver|State_Sunken|State_On);
7250 
7251                 if(slider->minimum==slider->maximum && opt.state&State_Enabled)
7252                     opt.state^=State_Enabled;
7253             }
7254 
7255             if(opts.flatSbarButtons)
7256                 opt.state&=~(State_Sunken|State_On);
7257             else
7258                 drawLightBevel(painter, br, &opt, widget, round, getFill(&opt, use), use, true, WIDGET_SB_BUTTON);
7259 
7260             opt.rect = ar;
7261 
7262             if(!(opt.state&State_Enabled))
7263                 opt.palette.setCurrentColorGroup(QPalette::Disabled);
7264 
7265             if(opt.palette.text().color()!=opt.palette.buttonText().color()) // The following fixes gwenviews scrollbars...
7266                 opt.palette.setColor(QPalette::Text, opt.palette.buttonText().color());
7267 
7268             drawPrimitive(pe, &opt, painter, widget);
7269             painter->restore();
7270             break;
7271         }
7272         case CE_ScrollBarSubPage:
7273         case CE_ScrollBarAddPage:
7274         {
7275             const QColor *use(m_backgroundCols); // backgroundColors(option));
7276             int          borderAdjust(0);
7277 
7278             painter->save();
7279 #ifndef SIMPLE_SCROLLBARS
7280             if (opts.round != ROUND_NONE && (SCROLLBAR_NONE==opts.scrollbarType || opts.flatSbarButtons))
7281                 painter->fillRect(r, palette.background().color());
7282 #endif
7283 
7284             switch(opts.scrollbarType)
7285             {
7286                 case SCROLLBAR_KDE:
7287                 case SCROLLBAR_WINDOWS:
7288                     borderAdjust=1;
7289                     break;
7290                 case SCROLLBAR_PLATINUM:
7291                     if(CE_ScrollBarAddPage==element)
7292                         borderAdjust=1;
7293                     break;
7294                 case SCROLLBAR_NEXT:
7295                     if(CE_ScrollBarSubPage==element)
7296                         borderAdjust=1;
7297                 default:
7298                     break;
7299             }
7300 
7301             if(state&State_Horizontal)
7302             {
7303                 if(qtcIsFlat(opts.appearance))
7304                     painter->fillRect(r.x(), r.y()+1, r.width(), r.height()-2, use[2]);
7305                 else
7306                     drawBevelGradient(use[2], painter, QRect(r.x(), r.y()+1, r.width(), r.height()-2),
7307                                       true, false, opts.grooveAppearance, WIDGET_TROUGH);
7308 
7309 #ifndef SIMPLE_SCROLLBARS
7310                 if (opts.round != ROUND_NONE && (SCROLLBAR_NONE==opts.scrollbarType || opts.flatSbarButtons))
7311                 {
7312                     if(CE_ScrollBarAddPage==element)
7313                         drawBorder(painter, r.adjusted(-5, 0, 0, 0), option, ROUNDED_RIGHT, use, WIDGET_TROUGH);
7314                     else
7315                         drawBorder(painter, r.adjusted(0, 0, 5, 0), option, ROUNDED_LEFT, use, WIDGET_TROUGH);
7316                 }
7317                 else
7318 #endif
7319                     if(CE_ScrollBarAddPage==element)
7320                         drawBorder(painter, r.adjusted(-5, 0, borderAdjust, 0), option, ROUNDED_NONE, use, WIDGET_TROUGH);
7321                     else
7322                         drawBorder(painter, r.adjusted(-borderAdjust, 0, 5, 0), option, ROUNDED_NONE, use, WIDGET_TROUGH);
7323             }
7324             else
7325             {
7326                 if(qtcIsFlat(opts.appearance))
7327                     painter->fillRect(r.x()+1, r.y(), r.width()-2, r.height(), use[2]);
7328                 else
7329                     drawBevelGradient(use[2], painter, QRect(r.x()+1, r.y(), r.width()-2, r.height()),
7330                                       false, false, opts.grooveAppearance, WIDGET_TROUGH);
7331 
7332 #ifndef SIMPLE_SCROLLBARS
7333                 if (opts.round != ROUND_NONE && (SCROLLBAR_NONE==opts.scrollbarType || opts.flatSbarButtons))
7334                 {
7335                     if(CE_ScrollBarAddPage==element)
7336                         drawBorder(painter, r.adjusted(0, -5, 0, 0), option, ROUNDED_BOTTOM, use, WIDGET_TROUGH);
7337                     else
7338                         drawBorder(painter, r.adjusted(0, 0, 0, 5), option, ROUNDED_TOP, use, WIDGET_TROUGH);
7339                 }
7340                 else
7341 #endif
7342                     if(CE_ScrollBarAddPage==element)
7343                         drawBorder(painter, r.adjusted(0, -5, 0, borderAdjust), option, ROUNDED_NONE, use, WIDGET_TROUGH);
7344                     else
7345                         drawBorder(painter, r.adjusted(0, -borderAdjust, 0, 5), option, ROUNDED_NONE, use, WIDGET_TROUGH);
7346             }
7347             painter->restore();
7348             break;
7349         }
7350         case CE_ScrollBarSlider:
7351             painter->save();
7352             drawSbSliderHandle(painter, r, option);
7353             painter->restore();
7354             break;
7355 #ifdef FIX_DISABLED_ICONS
7356         // Taken from QStyle - only required so that we can corectly set the disabled icon!!!
7357         case CE_ToolButtonLabel:
7358             if (auto tb = styleOptCast<QStyleOptionToolButton>(option)) {
7359                 int shiftX = 0,
7360                     shiftY = 0;
7361                 if (state & (State_Sunken|State_On))
7362                 {
7363                     shiftX = pixelMetric(PM_ButtonShiftHorizontal, tb, widget);
7364                     shiftY = pixelMetric(PM_ButtonShiftVertical, tb, widget);
7365                 }
7366 
7367                 // Arrow type always overrules and is always shown
7368                 bool hasArrow = tb->features & QStyleOptionToolButton::Arrow;
7369 
7370                 if (((!hasArrow && tb->icon.isNull()) && !tb->text.isEmpty()) || Qt::ToolButtonTextOnly==tb->toolButtonStyle)
7371                 {
7372                     int alignment = Qt::AlignCenter|Qt::TextShowMnemonic;
7373 
7374                     if (!styleHint(SH_UnderlineShortcut, option, widget))
7375                         alignment |= Qt::TextHideMnemonic;
7376 
7377                     r.translate(shiftX, shiftY);
7378 
7379                     drawItemTextWithRole(painter, r, alignment, palette, state&State_Enabled, tb->text, QPalette::ButtonText);
7380                 }
7381                 else
7382                 {
7383                     QPixmap pm;
7384                     QSize   pmSize = tb->iconSize;
7385                     QRect   pr = r;
7386 
7387                     if (!tb->icon.isNull())
7388                     {
7389                         QIcon::State state = tb->state & State_On ? QIcon::On : QIcon::Off;
7390                         QIcon::Mode  mode=!(tb->state & State_Enabled)
7391                                             ? QIcon::Disabled
7392                                             : (state&State_MouseOver) && (state&State_AutoRaise)
7393                                                 ? QIcon::Active
7394                                                 : QIcon::Normal;
7395                         QSize        iconSize = tb->iconSize;
7396 
7397                         if (!iconSize.isValid())
7398                         {
7399                             int iconExtent = pixelMetric(PM_ToolBarIconSize);
7400                             iconSize = QSize(iconExtent, iconExtent);
7401                         }
7402                         /* Not required?
7403                         else if(iconSize.width()>iconSize.height())
7404                             iconSize.setWidth(iconSize.height());
7405                         else if(iconSize.width()<iconSize.height())
7406                             iconSize.setHeight(iconSize.width());
7407                         */
7408 
7409                         if(iconSize.width()>tb->rect.size().width())
7410                             iconSize=QSize(tb->rect.size().width(), tb->rect.size().width());
7411                         if(iconSize.height()>tb->rect.size().height())
7412                             iconSize=QSize(tb->rect.size().height(), tb->rect.size().height());
7413 
7414                         pm=getIconPixmap(tb->icon, iconSize, mode, state);
7415                         pmSize = pm.size(); // tb->icon.actualSize(iconSize, mode);
7416                         /*if(pmSize.width()<pm.width())
7417                             pr.setX(pr.x()+((pm.width()-pmSize.width())));
7418                         if(pmSize.height()<pm.height())
7419                             pr.setY(pr.y()+((pm.height()-pmSize.height())));
7420                         */
7421                     }
7422 
7423                     if (Qt::ToolButtonIconOnly!=tb->toolButtonStyle)
7424                     {
7425                         QRect tr = r;
7426                         int   alignment = Qt::TextShowMnemonic;
7427 
7428                         painter->setFont(tb->font);
7429                         if (!styleHint(SH_UnderlineShortcut, option, widget))
7430                             alignment |= Qt::TextHideMnemonic;
7431 
7432                         if (Qt::ToolButtonTextUnderIcon==tb->toolButtonStyle)
7433                         {
7434                             pr.setHeight(pmSize.height() + 6);
7435 
7436                             tr.adjust(0, pr.bottom()-3, 0, 0); // -3);
7437                             pr.translate(shiftX, shiftY);
7438                             if (hasArrow)
7439                                 drawTbArrow(this, tb, pr, painter, widget);
7440                             else
7441                                 drawItemPixmap(painter, pr, Qt::AlignCenter, pm);
7442                             alignment |= Qt::AlignCenter;
7443                         }
7444                         else
7445                         {
7446                             pr.setWidth(pmSize.width() + 8);
7447                             tr.adjust(pr.right(), 0, 0, 0);
7448                             pr.translate(shiftX, shiftY);
7449                             if (hasArrow)
7450                                 drawTbArrow(this, tb, pr, painter, widget);
7451                             else
7452                                 drawItemPixmap(painter, QStyle::visualRect(option->direction, r, pr), Qt::AlignCenter, pm);
7453                             alignment |= Qt::AlignLeft | Qt::AlignVCenter;
7454                         }
7455                         tr.translate(shiftX, shiftY);
7456                         drawItemTextWithRole(painter, QStyle::visualRect(option->direction, r, tr), alignment, palette,
7457                                              state & State_Enabled, tb->text, QPalette::ButtonText);
7458                     }
7459                     else
7460                     {
7461                         pr.translate(shiftX, shiftY);
7462 
7463                         if (hasArrow)
7464                             drawTbArrow(this, tb, pr, painter, widget);
7465                         else
7466                         {
7467                             if (!(tb->subControls&SC_ToolButtonMenu) && tb->features&QStyleOptionToolButton::HasMenu &&
7468                                 pr.width()>pm.width() && ((pr.width()-pm.width())>LARGE_ARR_WIDTH))
7469                                 pr.adjust(-LARGE_ARR_WIDTH, 0, 0, 0);
7470                             drawItemPixmap(painter, pr, Qt::AlignCenter, pm);
7471                         }
7472                     }
7473                 }
7474             }
7475             break;
7476         case CE_RadioButtonLabel:
7477         case CE_CheckBoxLabel:
7478             if (auto btn = styleOptCast<QStyleOptionButton>(option)) {
7479                 uint    alignment = visualAlignment(btn->direction, Qt::AlignLeft | Qt::AlignVCenter);
7480                 QPixmap pix;
7481                 QRect   textRect = r;
7482 
7483                 if (!styleHint(SH_UnderlineShortcut, btn, widget))
7484                     alignment |= Qt::TextHideMnemonic;
7485 
7486                 if (!btn->icon.isNull())
7487                 {
7488                     pix = getIconPixmap(btn->icon, btn->iconSize, btn->state);
7489                     drawItemPixmap(painter, r, alignment, pix);
7490                     if (reverse)
7491                         textRect.setRight(textRect.right() - btn->iconSize.width() - 4);
7492                     else
7493                         textRect.setLeft(textRect.left() + btn->iconSize.width() + 4);
7494                 }
7495                 if (!btn->text.isEmpty())
7496                     drawItemTextWithRole(painter, textRect, alignment | Qt::TextShowMnemonic,
7497                                          palette, state&State_Enabled, btn->text, QPalette::WindowText);
7498             }
7499             break;
7500         case CE_ToolBoxTabLabel:
7501             if (auto tb = styleOptCast<QStyleOptionToolBox>(option)) {
7502                 bool    enabled = state & State_Enabled,
7503                         selected = state & State_Selected;
7504                 QPixmap pm = getIconPixmap(tb->icon, pixelMetric(QStyle::PM_SmallIconSize, tb, widget) ,state);
7505                 QRect   cr = subElementRect(QStyle::SE_ToolBoxTabContents, tb, widget);
7506                 QRect   tr, ir;
7507                 int     ih = 0;
7508 
7509                 if (pm.isNull())
7510                 {
7511                     tr = cr;
7512                     tr.adjust(4, 0, -8, 0);
7513                 }
7514                 else
7515                 {
7516                     int iw = pm.width() + 4;
7517                     ih = pm.height();
7518                     ir = QRect(cr.left() + 4, cr.top(), iw + 2, ih);
7519                     tr = QRect(ir.right(), cr.top(), cr.width() - ir.right() - 4, cr.height());
7520                 }
7521 
7522                 if (selected && styleHint(QStyle::SH_ToolBox_SelectedPageTitleBold, tb, widget))
7523                 {
7524                     QFont f(painter->font());
7525                     f.setBold(true);
7526                     painter->setFont(f);
7527                 }
7528 
7529                 QString txt = tb->fontMetrics.elidedText(tb->text, Qt::ElideRight, tr.width());
7530 
7531                 if (ih)
7532                     painter->drawPixmap(ir.left(), (tb->rect.height() - ih) / 2, pm);
7533 
7534                 int alignment = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic;
7535                 if (!styleHint(QStyle::SH_UnderlineShortcut, tb, widget))
7536                     alignment |= Qt::TextHideMnemonic;
7537                 drawItemTextWithRole(painter, tr, alignment, tb->palette, enabled, txt, QPalette::ButtonText);
7538 
7539                 if (!txt.isEmpty() && state&State_HasFocus)
7540                 {
7541                     QStyleOptionFocusRect opt;
7542                     opt.rect = tr;
7543                     opt.palette = palette;
7544                     opt.state = QStyle::State_None;
7545                     drawPrimitive(PE_FrameFocusRect, &opt, painter, widget);
7546                 }
7547             }
7548             break;
7549 #endif
7550         case CE_RadioButton:
7551         case CE_CheckBox:
7552             if (opts.crHighlight && (r.width()>opts.crSize*2))
7553                 if (auto button = styleOptCast<QStyleOptionButton>(option)) {
7554                     QStyleOptionButton copy(*button);
7555 
7556                     copy.rect.adjust(2, 0, -2, 0);
7557 
7558                     if(button->state&State_MouseOver && button->state&State_Enabled)
7559                     {
7560                         QRect highlightRect(subElementRect(CE_RadioButton==element ? SE_RadioButtonFocusRect : SE_CheckBoxFocusRect,
7561                                                            option, widget));
7562 
7563                         if(Qt::RightToLeft==button->direction)
7564                             highlightRect.setRight(r.right());
7565                         else
7566                             highlightRect.setX(r.x());
7567                         highlightRect.setWidth(highlightRect.width()+1);
7568 
7569                         if(ROUND_NONE!=opts.round)
7570                         {
7571                             painter->save();
7572                             painter->setRenderHint(QPainter::Antialiasing, true);
7573                             double   radius(qtcGetRadius(&opts, highlightRect.width(), highlightRect.height(),
7574                                                       WIDGET_OTHER, RADIUS_SELECTION));
7575 
7576                             drawBevelGradient(shade(palette.background().color(), TO_FACTOR(opts.crHighlight)),
7577                                               painter, highlightRect,
7578                                               buildPath(QRectF(highlightRect), WIDGET_OTHER, ROUNDED_ALL, radius), true,
7579                                               false, opts.selectionAppearance, WIDGET_SELECTION, false);
7580                             painter->restore();
7581                         }
7582                         else
7583                             drawBevelGradient(shade(palette.background().color(), TO_FACTOR(opts.crHighlight)), painter,
7584                                               highlightRect, true, false, opts.selectionAppearance, WIDGET_SELECTION);
7585                     }
7586                     BaseStyle::drawControl(element, &copy, painter, widget);
7587                     break;
7588                 }
7589             // Fall through!
7590         default:
7591             BaseStyle::drawControl(element, option, painter, widget);
7592     }
7593 }
7594 
7595 void
7596 Style::drawComplexControl(ComplexControl control,
7597                           const QStyleOptionComplex *option,
7598                           QPainter *painter, const QWidget *widget) const
7599 {
7600     prePolish(widget);
7601     QRect r(option->rect);
7602     const QFlags<State> &state(option->state);
7603     const QPalette &palette(option->palette);
7604     bool reverse = option->direction == Qt::RightToLeft;
7605 
7606     switch (control) {
7607         case CC_Dial:
7608             if (auto slider = styleOptCast<QStyleOptionSlider>(option)) {
7609                 r.adjust(1, 1, -1, -1);
7610 
7611                 QStyleOptionComplex opt(*option);
7612                 bool mo(state&State_Enabled && state&State_MouseOver);
7613                 QRect outer(r);
7614                 int sliderWidth = /*qMin(2*r.width()/5, */CIRCULAR_SLIDER_SIZE/*)*/;
7615 #ifdef DIAL_DOT_ON_RING
7616                 int halfWidth = sliderWidth / 2;
7617 #endif
7618 
7619                 opt.state|=State_Horizontal;
7620 
7621                 // Outer circle...
7622                 if (outer.width() > outer.height())
7623                 {
7624                     outer.setLeft(outer.x()+(outer.width()-outer.height())/2);
7625                     outer.setWidth(outer.height());
7626                 }
7627                 else
7628                 {
7629                     outer.setTop(outer.y()+(outer.height()-outer.width())/2);
7630                     outer.setHeight(outer.width());
7631                 }
7632 
7633                 opt.state&=~State_MouseOver;
7634 #ifdef DIAL_DOT_ON_RING
7635                 opt.rect=outer.adjusted(halfWidth, halfWidth, -halfWidth, -halfWidth);
7636 #else
7637                 opt.rect=outer;
7638 #endif
7639                 drawLightBevel(painter, opt.rect, &opt, widget, ROUNDED_ALL,
7640                                getFill(&opt, m_backgroundCols), m_backgroundCols,
7641                                true, WIDGET_DIAL);
7642 
7643                 // Inner 'dot'
7644                 if(mo)
7645                     opt.state|=State_MouseOver;
7646 
7647                 // angle calculation from qcommonstyle.cpp (c)
7648                 // Trolltech 1992-2007, ASA.
7649                 qreal angle(0);
7650                 if (slider->maximum == slider->minimum) {
7651                     angle = M_PI / 2;
7652                 } else {
7653                     const qreal fraction(qreal(slider->sliderValue - slider->minimum)/
7654                                          qreal(slider->maximum - slider->minimum));
7655                     if(slider->dialWrapping)
7656                         angle = 1.5*M_PI - fraction*2*M_PI;
7657                     else
7658                         angle = (M_PI*8 - fraction*10*M_PI)/6;
7659                 }
7660 
7661                 QPoint center = outer.center();
7662 #ifdef DIAL_DOT_ON_RING
7663                 const qreal radius=0.5*(outer.width() - sliderWidth);
7664 #else
7665                 const qreal radius=0.5*(outer.width() - 2*sliderWidth);
7666 #endif
7667                 center += QPoint(radius*cos(angle), -radius*sin(angle));
7668 
7669                 opt.rect=QRect(outer.x(), outer.y(), sliderWidth, sliderWidth);
7670                 opt.rect.moveCenter(center);
7671 
7672                 const QColor *use(buttonColors(option));
7673 
7674                 drawLightBevel(painter, opt.rect, &opt, widget, ROUNDED_ALL,
7675                                getFill(&opt, use), use, true, WIDGET_RADIO_BUTTON);
7676 
7677                 // Draw value...
7678 #ifdef DIAL_DOT_ON_RING
7679                 drawItemTextWithRole(painter, outer.adjusted(sliderWidth, sliderWidth, -sliderWidth, -sliderWidth),
7680                                      Qt::AlignCenter, palette, state&State_Enabled,
7681                                      QString::number(slider->sliderValue), QPalette::ButtonText);
7682 #else
7683                 int adjust=2*sliderWidth;
7684                 drawItemTextWithRole(painter, outer.adjusted(adjust, adjust, -adjust, -adjust),
7685                                      Qt::AlignCenter, palette, state&State_Enabled,
7686                                      QString::number(slider->sliderValue), QPalette::ButtonText);
7687 #endif
7688 
7689                 if(state&State_HasFocus)
7690                 {
7691                     QStyleOptionFocusRect fr;
7692                     fr.rect = outer.adjusted(-1, -1, 1, 1);
7693                     drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
7694                 }
7695             }
7696             break;
7697         case CC_ToolButton:
7698             // For OO.o 3.2 need to fill widget background!
7699             if (isOOWidget(widget))
7700                 painter->fillRect(r, palette.brush(QPalette::Window));
7701             if (auto toolbutton =
7702                 styleOptCast<QStyleOptionToolButton>(option)) {
7703                 int widthAdjust = 0;
7704                 int heightAdjust = 0;
7705 
7706                 if (widget) {
7707                     if ((opts.dwtSettings & DWT_BUTTONS_AS_PER_TITLEBAR) &&
7708                         (widget->inherits("QDockWidgetTitleButton") ||
7709                          qtcCheckType(getParent(widget),
7710                                       "KoDockWidgetTitleBar"))) {
7711                         ETitleBarButtons btn = TITLEBAR_CLOSE;
7712                         Icon icon = ICN_CLOSE;
7713 
7714                         if(constDwtFloat == widget->objectName())
7715                             btn=TITLEBAR_MAX, icon=ICN_RESTORE;
7716                         else if (constDwtClose != widget->objectName() &&
7717                                  qtcCheckType<QDockWidget>(
7718                                      getParent<2>(widget)) &&
7719                                  qtcCheckType(widget->parentWidget(),
7720                                               "KoDockWidgetTitleBar")) {
7721                             QDockWidget *dw =
7722                                 (QDockWidget*)getParent<2>(widget);
7723                             QWidget *koDw = widget->parentWidget();
7724                             int fw =
7725                                 (dw->isFloating() ?
7726                                  pixelMetric(QStyle::PM_DockWidgetFrameWidth,
7727                                              0, dw) : 0);
7728                             QRect geom(widget->geometry());
7729                             QStyleOptionDockWidgetV2 dwOpt;
7730                             dwOpt.initFrom(dw);
7731                             dwOpt.rect = QRect(QPoint(fw, fw), QSize(koDw->geometry().width() - (fw * 2),
7732                                                                     koDw->geometry().height() - (fw * 2)));
7733                             dwOpt.title = dw->windowTitle();
7734                             dwOpt.closable = (dw->features()&QDockWidget::DockWidgetClosable)==QDockWidget::DockWidgetClosable;
7735                             dwOpt.floatable =
7736                                 (dw->features() &
7737                                  QDockWidget::DockWidgetFloatable) ==
7738                                 QDockWidget::DockWidgetFloatable;
7739                             if (dwOpt.closable &&
7740                                 subElementRect(QStyle::SE_DockWidgetCloseButton,
7741                                                &dwOpt, getParent<2>(widget)) == geom) {
7742                                 btn = TITLEBAR_CLOSE;
7743                                 icon = ICN_CLOSE;
7744                             } else if (dwOpt.floatable &&
7745                                        subElementRect(QStyle::SE_DockWidgetFloatButton, &dwOpt,
7746                                                       getParent<2>(widget)) == geom)
7747                                 btn=TITLEBAR_MAX, icon=ICN_RESTORE;
7748                             else
7749                                 btn=TITLEBAR_SHADE, icon=dw && dw->widget() && dw->widget()->isVisible()
7750                                         ? ICN_SHADE
7751                                         : ICN_UNSHADE;
7752                         }
7753 
7754                         QColor        shadow(WINDOW_SHADOW_COLOR(opts.titlebarEffect));
7755                         const QColor *bgndCols((opts.dwtSettings&DWT_COLOR_AS_PER_TITLEBAR)
7756                                                 ? getMdiColors(option, state&State_Active)
7757                                                 : buttonColors(option)),
7758                                      *btnCols((opts.dwtSettings&DWT_COLOR_AS_PER_TITLEBAR)
7759                                                 ? opts.titlebarButtons&TITLEBAR_BUTTON_STD_COLOR
7760                                                     ? buttonColors(option)
7761                                                     : getMdiColors(option, state&State_Active)
7762                                                 : bgndCols);
7763 
7764                         drawDwtControl(painter, state, r.adjusted(-1, -1, 1, 1), btn, icon, option->palette.color(QPalette::WindowText), btnCols,
7765                                        bgndCols);
7766                         break;
7767                     }
7768                     if (qobject_cast<QTabBar*>(widget->parentWidget())) {
7769                         QStyleOptionToolButton btn(*toolbutton);
7770 
7771                         if (oneOf(toolbutton->arrowType, Qt::LeftArrow,
7772                                   Qt::RightArrow)) {
7773                             btn.rect.adjust(0, 4, 0, -4);
7774                         } else {
7775                             btn.rect.adjust(4, 0, -4, 0);
7776                         }
7777                         if(!(btn.state&State_Enabled))
7778                             btn.state&=~State_MouseOver;
7779                         drawPrimitive(PE_PanelButtonTool, &btn, painter, widget);
7780                         if (opts.vArrows) {
7781                             switch (toolbutton->arrowType) {
7782                             case Qt::LeftArrow:
7783                                 btn.rect.adjust(-1, 0, -1, 0);
7784                                 break;
7785                             case Qt::RightArrow:
7786                                 btn.rect.adjust(1, 0, 1, 0);
7787                                 break;
7788                             case Qt::UpArrow:
7789                                 btn.rect.adjust(0, -1, 0, -1);
7790                                 break;
7791                             case Qt::DownArrow:
7792                                 btn.rect.adjust(0, 1, 0, 1);
7793                             default:
7794                                 break;
7795                             }
7796                         }
7797                         drawTbArrow(this, &btn, btn.rect, painter, widget);
7798                         break;
7799                     }
7800 
7801                     const QToolButton *btn = qobject_cast<const QToolButton*>(widget);
7802 
7803                     if(btn && btn->isDown() && Qt::ToolButtonTextBesideIcon==btn->toolButtonStyle() &&
7804                        widget->parentWidget() && qobject_cast<QMenu*>(widget->parentWidget()))
7805                     {
7806                         painter->save();
7807                         if(opts.menuStripe)
7808                         {
7809                             int stripeWidth(qMax(20, constMenuPixmapWidth));
7810 
7811                             drawBevelGradient(menuStripeCol(),
7812                                               painter, QRect(reverse ? r.right()-stripeWidth : r.x(), r.y(),
7813                                                              stripeWidth, r.height()), false,
7814                                               false, opts.menuStripeAppearance, WIDGET_OTHER);
7815                         }
7816 
7817 #if 0
7818                         // For some reason the MenuTitle has a larger border on the left, so adjust the width by 1 pixel to make this look nicer.
7819                         //drawBorder(painter, r.adjusted(2, 2, -3, -2), option, ROUNDED_ALL, 0L, WIDGET_OTHER, BORDER_SUNKEN);
7820                         QStyleOptionToolButton opt(*toolbutton);
7821                         opt.rect = r.adjusted(2, 2, -3, -2);
7822                         opt.state=State_Raised|State_Enabled|State_Horizontal;
7823                         drawLightBevel(painter, opt.rect, &opt, widget, ROUNDED_ALL,
7824                                        getFill(&opt, m_backgroundCols), m_backgroundCols, true, WIDGET_NO_ETCH_BTN);
7825 #else
7826                         if(!opts.menuStripe)
7827                             drawFadedLine(painter, QRect(r.x()+3, r.y()+r.height()-1, r.width()-7, 1),
7828                                           popupMenuCols(option)[MENU_SEP_SHADE], true, true, true);
7829 #endif
7830                         QFont font(toolbutton->font);
7831 
7832                         font.setBold(true);
7833                         painter->setFont(font);
7834                         drawItemTextWithRole(painter, r, Qt::AlignHCenter | Qt::AlignVCenter,
7835                                              palette, state&State_Enabled, toolbutton->text, QPalette::Text);
7836                         painter->restore();
7837                         break;
7838                     }
7839 
7840                     // Amarok's toolbars (the one just above the collection list) are much thinner then normal,
7841                     // and QToolBarExtension does not seem to take this into account - so adjust the size here...
7842                     if(widget->inherits("QToolBarExtension") && widget->parentWidget())
7843                     {
7844                         if(r.height()>widget->parentWidget()->rect().height())
7845                             heightAdjust=(r.height()-widget->parentWidget()->rect().height())+2;
7846                         if(r.width()>widget->parentWidget()->rect().width())
7847                             widthAdjust=(r.width()-widget->parentWidget()->rect().width())+2;
7848                     }
7849                 }
7850                 QRect button(subControlRect(control, toolbutton, SC_ToolButton, widget)),
7851                       menuarea(subControlRect(control, toolbutton, SC_ToolButtonMenu, widget));
7852                 State bflags(toolbutton->state);
7853                 bool  etched = opts.buttonEffect != EFFECT_NONE,
7854                       raised=widget && (TBTN_RAISED==opts.tbarBtns || TBTN_JOINED==opts.tbarBtns),
7855                       horizTBar(true);
7856                 int   round=ROUNDED_ALL,
7857                       leftAdjust(0), topAdjust(0), rightAdjust(0), bottomAdjust(0);
7858 
7859                 if(raised)
7860                 {
7861                     const QToolBar *toolbar=getToolBar(widget);
7862 
7863                     if(toolbar)
7864                     {
7865                         if(TBTN_JOINED==opts.tbarBtns)
7866                         {
7867                             horizTBar=Qt::Horizontal==toolbar->orientation();
7868                             adjustToolbarButtons(widget, toolbar, leftAdjust, topAdjust, rightAdjust, bottomAdjust, round);
7869                         }
7870                     }
7871                     else
7872                         raised=false;
7873                 }
7874 
7875                 if (!(bflags&State_Enabled))
7876                     bflags &= ~(State_MouseOver/* | State_Raised*/);
7877 
7878                 if(bflags&State_MouseOver)
7879                     bflags |= State_Raised;
7880                 else if(!raised && (bflags&State_AutoRaise))
7881                     bflags &= ~State_Raised;
7882 
7883                 if(state&State_AutoRaise || toolbutton->subControls&SC_ToolButtonMenu)
7884                     bflags|=STATE_TBAR_BUTTON;
7885 
7886                 State mflags(bflags);
7887 
7888                 if (!isOOWidget(widget)) {
7889                     if (state & State_Sunken &&
7890                         !(toolbutton->activeSubControls & SC_ToolButton)) {
7891                         bflags &= ~State_Sunken;
7892                     }
7893                 }
7894 
7895                 bool         drawMenu=TBTN_JOINED==opts.tbarBtns
7896                                         ? mflags & (State_Sunken | State_On)
7897                                         : raised || (mflags & (State_Sunken | State_On | State_Raised)),
7898                              drawnBevel=false;
7899                 QStyleOption tool(0);
7900                 tool.palette = toolbutton->palette;
7901 
7902                 if (raised ||
7903                      (toolbutton->subControls&SC_ToolButton && (bflags & (State_Sunken | State_On | State_Raised))) ||
7904                      (toolbutton->subControls&SC_ToolButtonMenu && drawMenu))
7905                 {
7906                     const QColor *use(buttonColors(toolbutton));
7907 
7908                     tool.rect = (toolbutton->subControls&SC_ToolButtonMenu ? button.united(menuarea) : button)
7909                                 .adjusted(leftAdjust, topAdjust, rightAdjust, bottomAdjust);
7910                     tool.state = bflags|State_Horizontal;
7911 
7912                     if(raised && TBTN_JOINED==opts.tbarBtns && !horizTBar)
7913                         tool.state &= ~State_Horizontal;
7914 
7915                     tool.rect.adjust(0, 0, -widthAdjust, -heightAdjust);
7916                     if(!(bflags&State_Sunken) && (mflags&State_Sunken))
7917                         tool.state &= ~State_MouseOver;
7918                     drawnBevel=true;
7919                     drawLightBevel(painter, tool.rect, &tool, widget, round, getFill(&tool, use), use, true, WIDGET_TOOLBAR_BUTTON);
7920 
7921                     if(raised && TBTN_JOINED==opts.tbarBtns)
7922                     {
7923                         const int constSpace=4;
7924 
7925                         QRect br(tool.rect.adjusted(-leftAdjust, -topAdjust, -rightAdjust, -bottomAdjust));
7926 
7927                         if(leftAdjust)
7928                             drawFadedLine(painter, QRect(br.x(), br.y()+constSpace, 1, br.height()-(constSpace*2)), use[0], true, true, false);
7929                         if(topAdjust)
7930                             drawFadedLine(painter, QRect(br.x()+constSpace, br.y(), br.width()-(constSpace*2), 1), use[0], true, true, true);
7931                         if(rightAdjust)
7932                             drawFadedLine(painter, QRect(br.x()+br.width()-1, br.y()+constSpace, 1, br.height()-(constSpace*2)),
7933                                           use[QTC_STD_BORDER], true, true, false);
7934                         if(bottomAdjust)
7935                             drawFadedLine(painter, QRect(br.x()+constSpace, br.y()+br.height()-1, br.width()-(constSpace*2), 1),
7936                                           use[QTC_STD_BORDER], true, true, true);
7937                     }
7938                 }
7939 
7940                 if (toolbutton->subControls&SC_ToolButtonMenu)
7941                 {
7942                     if(etched)
7943                     {
7944                         if(reverse)
7945                             menuarea.adjust(1, 1, 0, -1);
7946                         else
7947                             menuarea.adjust(0, 1, -1, -1);
7948                     }
7949 
7950                     tool.state = mflags|State_Horizontal;
7951 
7952                     if(drawMenu)
7953                     {
7954                         const QColor *use(buttonColors(option));
7955                         int          mRound=reverse ? ROUNDED_LEFT : ROUNDED_RIGHT;
7956 
7957                         if(mflags&State_Sunken)
7958                             tool.state&=~State_MouseOver;
7959 
7960                         if(raised && TBTN_JOINED==opts.tbarBtns)
7961                         {
7962                             if(!horizTBar)
7963                                 tool.state &= ~State_Horizontal;
7964                             painter->save();
7965                             painter->setClipRect(menuarea, Qt::IntersectClip);
7966                             if((reverse && leftAdjust) || (!reverse && rightAdjust))
7967                                 mRound=ROUNDED_NONE;
7968                             if(reverse)
7969                                 tool.rect.adjust(1, 0, 0, 0);
7970                             else
7971                                 tool.rect.adjust(0, 0, -1, 0);
7972                         }
7973                         else
7974                             tool.rect = menuarea;
7975 
7976                         drawLightBevel(painter, tool.rect, &tool, widget, mRound, getFill(&tool, use), use, true,
7977                                        MO_GLOW==opts.coloredMouseOver ? WIDGET_MENU_BUTTON : WIDGET_NO_ETCH_BTN);
7978                         if(raised && TBTN_JOINED==opts.tbarBtns)
7979                             painter->restore();
7980                     }
7981 
7982                     tool.rect = menuarea;
7983 
7984                     if(mflags&State_Sunken)
7985                         tool.rect.adjust(1, 1, 1, 1);
7986                     drawArrow(painter, tool.rect, PE_IndicatorArrowDown,
7987                               MOArrow(state, palette,
7988                                       toolbutton->activeSubControls &
7989                                       SC_ToolButtonMenu,
7990                                       QPalette::ButtonText));
7991                 }
7992 
7993                 if ((FOCUS_GLOW!=opts.focus || !drawnBevel) && toolbutton->state&State_HasFocus)
7994                 {
7995                     QStyleOptionFocusRect fr;
7996 
7997                     fr.QStyleOption::operator=(*toolbutton);
7998                     if (oneOf(opts.focus, FOCUS_FULL, FOCUS_FILLED)) {
7999                         if (etched) {
8000                             fr.rect.adjust(1, 1, -1, -1);
8001                         }
8002                     } else {
8003                         if (opts.focus == FOCUS_GLOW) {
8004                             fr.rect.adjust(1, 1, -1, -1);
8005                         } else if (etched) {
8006                             fr.rect.adjust(4, 4, -4, -4);
8007                         } else {
8008                             fr.rect.adjust(3, 3, -3, -3);
8009                         }
8010                         if (toolbutton->features &
8011                             QStyleOptionToolButton::MenuButtonPopup) {
8012                             fr.rect.adjust(
8013                                 0, 0, -(pixelMetric(
8014                                             QStyle::PM_MenuButtonIndicator,
8015                                             toolbutton, widget) - 1), 0);
8016                         }
8017                     }
8018                     if (!(state & State_MouseOver &&
8019                           oneOf(opts.focus, FOCUS_FULL, FOCUS_FILLED) &&
8020                           opts.coloredMouseOver != MO_NONE)) {
8021                         drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
8022                     }
8023                 }
8024                 QStyleOptionToolButton label = *toolbutton;
8025                 int fw = pixelMetric(PM_DefaultFrameWidth, option, widget);
8026                 label.rect = button.adjusted(fw, fw, -(fw+widthAdjust), -(fw+heightAdjust));
8027                 label.state = bflags;
8028                 drawControl(CE_ToolButtonLabel, &label, painter, widget);
8029 
8030                 if (!(toolbutton->subControls&SC_ToolButtonMenu) &&
8031                      (toolbutton->features&QStyleOptionToolButton::HasMenu))
8032                 {
8033                     QRect arrow(r.right()-(LARGE_ARR_WIDTH+(etched ? 3 : 2)),
8034                                 r.bottom()-(LARGE_ARR_HEIGHT+(etched ? 4 : 3)),
8035                                 LARGE_ARR_WIDTH, LARGE_ARR_HEIGHT);
8036 
8037                     if(bflags&State_Sunken)
8038                         arrow.adjust(1, 1, 1, 1);
8039 
8040                     drawArrow(painter, arrow, PE_IndicatorArrowDown,
8041                               MOArrow(state, palette, QPalette::ButtonText));
8042                 }
8043             }
8044             break;
8045         case CC_GroupBox:
8046             if (auto groupBox = styleOptCast<QStyleOptionGroupBox>(option)) {
8047                 // Draw frame
8048                 QRect textRect = subControlRect(CC_GroupBox, option,
8049                                                 SC_GroupBoxLabel, widget);
8050                 QRect checkBoxRect = subControlRect(CC_GroupBox, option,
8051                                                     SC_GroupBoxCheckBox, widget);
8052                 if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
8053                     QStyleOptionFrameV2 frame;
8054                     frame.QStyleOption::operator=(*groupBox);
8055                     frame.features = groupBox->features;
8056                     frame.lineWidth = groupBox->lineWidth;
8057                     frame.midLineWidth = groupBox->midLineWidth;
8058                     frame.rect = subControlRect(CC_GroupBox, option,
8059                                                 SC_GroupBoxFrame, widget);
8060 
8061                     if ((groupBox->features & QStyleOptionFrameV2::Flat) ||
8062                         !(opts.gbLabel & (GB_LBL_INSIDE | GB_LBL_OUTSIDE))) {
8063                         painter->save();
8064                         QRegion region(r);
8065                         if (!groupBox->text.isEmpty())
8066                             region -= QRect(groupBox->subControls &
8067                                             QStyle::SC_GroupBoxCheckBox ?
8068                                             checkBoxRect.united(textRect)
8069                                             .adjusted(reverse ? 0 : -2, 0,
8070                                                       reverse ? 2 : 0, 0) :
8071                                             textRect);
8072                         painter->setClipRegion(region);
8073                     }
8074                     drawPrimitive(PE_FrameGroupBox, &frame, painter, widget);
8075                     if ((groupBox->features & QStyleOptionFrameV2::Flat) ||
8076                         !(opts.gbLabel & (GB_LBL_INSIDE | GB_LBL_OUTSIDE))) {
8077                         painter->restore();
8078                     }
8079                 }
8080 
8081                 // Draw title
8082                 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) &&
8083                     !groupBox->text.isEmpty()) {
8084                     QColor textColor = groupBox->textColor;
8085                     if (textColor.isValid())
8086                         painter->setPen(textColor);
8087                     int alignment = int(groupBox->textAlignment);
8088                     if (!styleHint(QStyle::SH_UnderlineShortcut, option, widget))
8089                         alignment |= Qt::TextHideMnemonic;
8090 
8091                     if (opts.gbLabel & GB_LBL_BOLD) {
8092                         QFont font(painter->font());
8093 
8094                         font.setBold(true);
8095                         painter->save();
8096                         painter->setFont(font);
8097                     }
8098                     drawItemText(painter, textRect,
8099                                  Qt::TextShowMnemonic | Qt::AlignHCenter |
8100                                  alignment, palette, state & State_Enabled,
8101                                  groupBox->text, textColor.isValid() ?
8102                                  QPalette::NoRole : QPalette::WindowText);
8103 
8104                     if (opts.gbLabel & GB_LBL_BOLD)
8105                         painter->restore();
8106 
8107                     if (state & State_HasFocus) {
8108                         QStyleOptionFocusRect fropt;
8109                         fropt.QStyleOption::operator=(*groupBox);
8110                         fropt.rect = textRect;
8111                         drawPrimitive(PE_FrameFocusRect, &fropt,
8112                                       painter, widget);
8113                     }
8114                 }
8115 
8116                 // Draw checkbox
8117                 if (groupBox->subControls & SC_GroupBoxCheckBox) {
8118                     QStyleOptionButton box;
8119                     box.QStyleOption::operator=(*groupBox);
8120                     box.rect = checkBoxRect;
8121                     drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
8122                 }
8123             }
8124             break;
8125         case CC_Q3ListView:
8126             if (auto lv = styleOptCast<QStyleOptionQ3ListView>(option)) {
8127                 int i;
8128                 if (lv->subControls&SC_Q3ListView)
8129                     BaseStyle::drawComplexControl(control, lv, painter, widget);
8130                 if (lv->subControls & (SC_Q3ListViewBranch | SC_Q3ListViewExpand))
8131                 {
8132                     if (lv->items.isEmpty())
8133                         break;
8134 
8135                     QStyleOptionQ3ListViewItem item(lv->items.at(0));
8136                     int                        y(r.y()),
8137                                                c;
8138                     QPolygon                   lines;
8139 
8140                     painter->save();
8141                     painter->setRenderHint(QPainter::Antialiasing, false);
8142                     if ((lv->activeSubControls&SC_All) && (lv->subControls&SC_Q3ListViewExpand))
8143                     {
8144                         c = 2;
8145                         if(opts.lvLines)
8146                         {
8147                             lines.resize(2);
8148                             lines[0] = QPoint(r.right(), r.top());
8149                             lines[1] = QPoint(r.right(), r.bottom());
8150                         }
8151                     }
8152                     else
8153                     {
8154                         int linetop(0),
8155                             linebot(0);
8156                         // each branch needs at most two lines, ie. four end points
8157                         lines.resize(item.childCount * 4);
8158                         c = 0;
8159 
8160                         // skip the stuff above the exposed rectangle
8161                         for (i = 1;i < lv->items.size();++i) {
8162                             QStyleOptionQ3ListViewItem child = lv->items.at(i);
8163                             if (child.height + y > 0)
8164                                 break;
8165                             y += child.totalHeight;
8166                         }
8167                         int bx(r.width() / 2);
8168 
8169                         // paint stuff in the magical area
8170                         while (i < lv->items.size() && y < r.height())
8171                         {
8172                             QStyleOptionQ3ListViewItem child = lv->items.at(i);
8173                             if (child.features & QStyleOptionQ3ListViewItem::Visible)
8174                             {
8175                                 int lh(!(item.features & QStyleOptionQ3ListViewItem::MultiLine)
8176                                         ? child.height
8177                                         : painter->fontMetrics().height() + 2 * lv->itemMargin);
8178 
8179                                 lh = qMax(lh, QApplication::globalStrut().height());
8180                                 if (lh % 2 > 0)
8181                                     ++lh;
8182                                 linebot = y + lh / 2;
8183                                 if (child.features & QStyleOptionQ3ListViewItem::Expandable
8184                                     || (child.childCount > 0 && child.height > 0))
8185                                 {
8186 
8187                                     QRect ar(bx-4, linebot-4, 11, 11);
8188 
8189 #if 0
8190                                     if(LV_OLD==opts.lvLines)
8191                                     {
8192                                         int lo(opts.round != ROUND_NONE ? 2 : 0);
8193 
8194                                         painter->setPen(palette.mid().color());
8195                                         painter->drawLine(ar.x()+lo, ar.y(), (ar.x()+ar.width()-1)-lo, ar.y());
8196                                         painter->drawLine(ar.x()+lo, ar.y()+ar.height()-1, (ar.x()+ar.width()-1)-lo, ar.y()+ar.height()-1);
8197                                         painter->drawLine(ar.x(), ar.y()+lo, ar.x(), (ar.y()+ar.height()-1)-lo);
8198                                         painter->drawLine(ar.x()+ar.width()-1, ar.y()+lo, ar.x()+ar.width()-1, (ar.y()+ar.height()-1)-lo);
8199 
8200                                         if (opts.round != ROUND_NONE) {
8201                                             painter->drawPoint(ar.x()+1, ar.y()+1);
8202                                             painter->drawPoint(ar.x()+1, ar.y()+ar.height()-2);
8203                                             painter->drawPoint(ar.x()+ar.width()-2, ar.y()+1);
8204                                             painter->drawPoint(ar.x()+ar.width()-2, ar.y()+ar.height()-2);
8205 
8206                                             QColor col(palette.mid().color());
8207 
8208                                             col.setAlphaF(0.5);
8209                                             painter->setPen(col);
8210                                             painter->drawLine(ar.x()+1, ar.y()+1, ar.x()+2, ar.y());
8211                                             painter->drawLine(ar.x()+ar.width()-2, ar.y(), ar.x()+ar.width()-1, ar.y()+1);
8212                                             painter->drawLine(ar.x()+1, ar.y()+ar.height()-2, ar.x()+2, ar.y()+ar.height()-1);
8213                                             painter->drawLine(ar.x()+ar.width()-2, ar.y()+ar.height()-1, ar.x()+ar.width()-1, ar.y()+ar.height()-2);
8214                                         }
8215                                     }
8216 #endif
8217 
8218                                     drawArrow(painter, ar,
8219                                               child.state&State_Open
8220                                                 ? PE_IndicatorArrowDown
8221                                                 : reverse
8222                                                     ? PE_IndicatorArrowLeft
8223                                                     : PE_IndicatorArrowRight,
8224                                               palette.text().color());
8225 
8226                                     if(opts.lvLines)
8227                                     {
8228                                         lines[c++] = QPoint(bx+1, linetop);
8229                                         lines[c++] = QPoint(bx+1, linebot - 4);
8230                                         lines[c++] = QPoint(bx + 6, linebot);
8231                                         lines[c++] = QPoint(r.width(), linebot);
8232                                         linetop = linebot + 6;
8233                                     }
8234                                 }
8235                                 else if(opts.lvLines)
8236                                 {
8237                                     // just dotlinery
8238                                     lines[c++] = QPoint(bx+1, linebot -1);
8239                                     lines[c++] = QPoint(r.width(), linebot -1);
8240                                 }
8241                                 y += child.totalHeight;
8242                             }
8243                             ++i;
8244                         }
8245 
8246                         if(opts.lvLines)
8247                         {
8248                             // Expand line height to edge of rectangle if there's any
8249                             // visible child below
8250                             while (i < lv->items.size() && lv->items.at(i).height <= 0)
8251                                 ++i;
8252 
8253                             if (i < lv->items.size())
8254                                 linebot = r.height();
8255 
8256                             if (linetop < linebot)
8257                             {
8258                                 lines[c++] = QPoint(bx+1, linetop);
8259                                 lines[c++] = QPoint(bx+1, linebot-1);
8260                             }
8261                         }
8262                     }
8263 
8264                     if (opts.lvLines && (lv->subControls&SC_Q3ListViewBranch))
8265                     {
8266                         painter->setPen(palette.mid().color());
8267 
8268                         for(int line = 0; line < c; line += 2)
8269                             if (lines[line].y() == lines[line+1].y())
8270                                 painter->drawLine(lines[line].x(), lines[line].y(), lines[line + 1].x(), lines[line].y());
8271                             else
8272                                 painter->drawLine(lines[line].x(), lines[line].y(), lines[line].x(), lines[line + 1].y());
8273                     }
8274                     painter->restore();
8275                 }
8276             }
8277             break;
8278         case CC_SpinBox:
8279             if (auto spinBox = styleOptCast<QStyleOptionSpinBox>(option)) {
8280                 QRect frame(subControlRect(CC_SpinBox, option, SC_SpinBoxFrame, widget)),
8281                       up(subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget)),
8282                       down(subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget)),
8283                       all(frame.united(up).united(down));
8284                 bool  doFrame(spinBox->frame && frame.isValid()),
8285                       sunken(state&State_Sunken),
8286                       enabled(state&State_Enabled),
8287                       mouseOver(state&State_MouseOver),
8288                       upIsActive(SC_SpinBoxUp==spinBox->activeSubControls),
8289                       downIsActive(SC_SpinBoxDown==spinBox->activeSubControls),
8290                       doEtch(opts.buttonEffect != EFFECT_NONE &&
8291                              opts.etchEntry),
8292                       isOO(isOOWidget(widget)),
8293                       oldUnify=opts.unifySpin; // See Krita note below...
8294 
8295                 if(!doFrame && isOO && !opts.unifySpin)
8296                 {
8297                     doFrame=true;
8298                     frame=all;
8299                 }
8300 
8301                 if(isOO)
8302                     painter->fillRect(r, palette.brush(QPalette::Window));
8303 
8304                 if(up.isValid())
8305                 {
8306                     if(reverse)
8307                         frame.adjust(up.width(), 0, 0, 0);
8308                     else
8309                         frame.adjust(0, 0, -up.width(), 0);
8310                 }
8311 
8312                 if(doEtch)
8313                 {
8314                     drawEtch(painter, all, widget, WIDGET_SPIN, false,
8315                              opts.square&SQUARE_ENTRY
8316                                 ? opts.unifySpin
8317                                     ? ROUNDED_NONE
8318                                     : reverse
8319                                         ? ROUNDED_LEFT
8320                                         : ROUNDED_RIGHT
8321                                 : ROUNDED_ALL);
8322                     down.adjust(reverse ? 1 : 0, 0, reverse ? 0 : -1, -1);
8323                     up.adjust(reverse ? 1 : 0, 1, reverse ? 0 : -1, 0);
8324                     frame.adjust(reverse ? 0 : 1, 1, reverse ? -1 : 0, -1);
8325                     all.adjust(1, 1, -1, -1);
8326                 }
8327 
8328                 // Krita/KOffice uses a progressbar with spin buttons at the end
8329                 // ...when drawn, the frame part is not set - so in this case dont draw the background behind the buttons!
8330                 if(!isOO && !doFrame)
8331                     opts.unifySpin=true; // So, set this to true to fake the above scenario!
8332                 else
8333                     if(opts.unifySpin)
8334                         drawEntryField(painter, all, widget, option, ROUNDED_ALL, true, false);
8335                     else
8336                     {
8337                         if(opts.unifySpinBtns)
8338                         {
8339                             QRect btns=up.united(down);
8340                             const QColor *use(buttonColors(option));
8341                             QStyleOption opt(*option);
8342 
8343                             opt.state&=~(State_Sunken|State_MouseOver);
8344                             opt.state|=State_Horizontal;
8345 
8346                             drawLightBevel(painter, btns, &opt, widget, reverse ?  ROUNDED_LEFT : ROUNDED_RIGHT,
8347                                         getFill(&opt, use), use, true, WIDGET_SPIN);
8348 
8349                             if(state&State_MouseOver && state&State_Enabled && !(state&State_Sunken))
8350                             {
8351                                 opt.state|=State_MouseOver;
8352                                 painter->save();
8353                                 painter->setClipRect(upIsActive ? up : down);
8354                                 drawLightBevel(painter, btns, &opt, widget, reverse ?  ROUNDED_LEFT : ROUNDED_RIGHT,
8355                                             getFill(&opt, use), use, true, WIDGET_SPIN);
8356                                 painter->restore();
8357                             }
8358                             drawFadedLine(painter, down.adjusted(2, 0, -2, 0), use[BORDER_VAL(state&State_Enabled)], true, true, true);
8359                         }
8360                     }
8361 
8362                 if(up.isValid())
8363                 {
8364                     QStyleOption opt(*option);
8365 
8366                     up.setHeight(up.height()+1);
8367                     opt.rect=up;
8368                     opt.direction=option->direction;
8369                     opt.state=(enabled && (spinBox->stepEnabled&QAbstractSpinBox::StepUpEnabled ||
8370                                            (QAbstractSpinBox::StepNone==spinBox->stepEnabled && isOO))
8371                                     ? State_Enabled : State_None)|
8372                               (upIsActive && sunken ? State_Sunken : State_Raised)|
8373                               (upIsActive && !sunken && mouseOver ? State_MouseOver : State_None)|State_Horizontal;
8374 
8375                     drawPrimitive(QAbstractSpinBox::PlusMinus==spinBox->buttonSymbols ? PE_IndicatorSpinPlus : PE_IndicatorSpinUp,
8376                                   &opt, painter, widget);
8377                 }
8378 
8379                 if(down.isValid())
8380                 {
8381                     QStyleOption opt(*option);
8382 
8383                     opt.rect=down;
8384                     opt.state=(enabled && (spinBox->stepEnabled&QAbstractSpinBox::StepDownEnabled ||
8385                                            (QAbstractSpinBox::StepNone==spinBox->stepEnabled && isOO))
8386                                     ? State_Enabled : State_None)|
8387                               (downIsActive && sunken ? State_Sunken : State_Raised)|
8388                               (downIsActive && !sunken && mouseOver ? State_MouseOver : State_None)|State_Horizontal;
8389                     opt.direction=option->direction;
8390 
8391                     drawPrimitive(QAbstractSpinBox::PlusMinus==spinBox->buttonSymbols ? PE_IndicatorSpinMinus : PE_IndicatorSpinDown,
8392                                   &opt, painter, widget);
8393                 }
8394                 if(doFrame && !opts.unifySpin)
8395                 {
8396                     if(reverse)
8397                         frame.setX(frame.x()-1);
8398                     else
8399                         frame.setWidth(frame.width()+1);
8400                     drawEntryField(painter, frame, widget, option, reverse ? ROUNDED_RIGHT : ROUNDED_LEFT, true, false);
8401                 }
8402                 opts.unifySpin=oldUnify;
8403             }
8404             break;
8405         case CC_Slider:
8406             if (auto slider = styleOptCast<QStyleOptionSlider>(option)) {
8407                 QRect groove(subControlRect(CC_Slider, option,
8408                                             SC_SliderGroove, widget));
8409                 QRect handle(subControlRect(CC_Slider, option,
8410                                             SC_SliderHandle, widget));
8411                 // QRect ticks(subControlRect(CC_Slider, option,
8412                 //                            SC_SliderTickmarks, widget));
8413                 bool  horizontal(slider->orientation == Qt::Horizontal),
8414                       ticksAbove(slider->tickPosition & QSlider::TicksAbove),
8415                       ticksBelow(slider->tickPosition & QSlider::TicksBelow);
8416 
8417                 //The clickable region is 5 px wider than the visible groove for improved usability
8418 //                 if (groove.isValid())
8419 //                     groove = horizontal ? groove.adjusted(0, 5, 0, -5) : groove.adjusted(5, 0, -5, 0);
8420 
8421                 if ((option->subControls&SC_SliderGroove) && groove.isValid())
8422                     drawSliderGroove(painter, groove, handle, slider, widget);
8423 
8424                 if ((option->subControls&SC_SliderHandle) && handle.isValid())
8425                 {
8426                     QStyleOptionSlider s(*slider);
8427                     if(!(s.activeSubControls & QStyle::SC_SliderHandle))
8428                     {
8429                         s.state &= ~QStyle::State_MouseOver;
8430                         s.state &= ~QStyle::State_Sunken;
8431                     }
8432 
8433                     drawSliderHandle(painter, handle, &s);
8434 
8435                     if (state&State_HasFocus && FOCUS_GLOW!=opts.focus)
8436                     {
8437                         QStyleOptionFocusRect fropt;
8438                         fropt.QStyleOption::operator=(*slider);
8439                         fropt.rect = slider->rect;
8440 
8441                         if(horizontal)
8442                             fropt.rect.adjust(0, 0, 0, -1);
8443                         else
8444                             fropt.rect.adjust(0, 0, -1, 0);
8445 
8446                         drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
8447                     }
8448                 }
8449 
8450                 if (option->subControls&SC_SliderTickmarks)
8451                 {
8452                     QPen oldPen = painter->pen();
8453                     painter->setPen(backgroundColors(option)[QTC_STD_BORDER]);
8454                     int tickSize(pixelMetric(PM_SliderTickmarkOffset, option, widget)),
8455                         available(pixelMetric(PM_SliderSpaceAvailable, slider, widget)),
8456                         interval(slider->tickInterval);
8457                     if (interval <= 0)
8458                     {
8459                         interval = slider->singleStep;
8460                         if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
8461                                                             available)
8462                             - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
8463                                                             0, available) < 3)
8464                             interval = slider->pageStep;
8465                     }
8466                     if (interval <= 0)
8467                         interval = 1;
8468 
8469                     int sliderLength(slider->maximum - slider->minimum + 1),
8470                         nticks(sliderLength / interval); // add one to get the end tickmark
8471                     if (sliderLength % interval > 0)
8472                         nticks++; // round up the number of tick marks
8473 
8474                     int v(slider->minimum),
8475                         len(pixelMetric(PM_SliderLength, slider, widget));
8476 
8477                     while (v <= slider->maximum + 1)
8478                     {
8479                         if (v == slider->maximum + 1 && interval == 1)
8480                             break;
8481 
8482                         int pos(sliderPositionFromValue(slider->minimum, slider->maximum,
8483                                                         qMin(v, slider->maximum), (horizontal
8484                                                             ? slider->rect.width()
8485                                                             : slider->rect.height()) - len,
8486                                                         slider->upsideDown) + len / 2);
8487 
8488                         int extra(2); // - ((v == slider->minimum || v == slider->maximum) ? 1 : 0);
8489 
8490                         if (horizontal)
8491                         {
8492                             if (ticksAbove)
8493                                 painter->drawLine(QLine(pos, slider->rect.top() + extra,
8494                                                 pos, slider->rect.top() + tickSize));
8495                             if (ticksBelow)
8496                                 painter->drawLine(QLine(pos, slider->rect.bottom() - extra,
8497                                                 pos, slider->rect.bottom() - tickSize));
8498                         }
8499                         else
8500                         {
8501                             if (ticksAbove)
8502                                 painter->drawLine(QLine(slider->rect.left() + extra, pos,
8503                                                 slider->rect.left() + tickSize, pos));
8504                             if (ticksBelow)
8505                                 painter->drawLine(QLine(slider->rect.right() - extra, pos,
8506                                                 slider->rect.right() - tickSize, pos));
8507                         }
8508 
8509                         // in the case where maximum is max int
8510                         int nextInterval = v + interval;
8511                         if (nextInterval < v)
8512                             break;
8513                         v = nextInterval;
8514                     }
8515                     painter->setPen(oldPen);
8516                 }
8517             }
8518             break;
8519         case CC_TitleBar:
8520             if (auto titleBar = styleOptCast<QStyleOptionTitleBar>(option)) {
8521                 painter->save();
8522 
8523                 EAppearance  app=qtcWidgetApp(WIDGET_MDI_WINDOW_TITLE, &opts, option->state&State_Active);
8524                 bool         active(state&State_Active),
8525                              kwin(theThemedApp==APP_KWIN || titleBar->titleBarState&QtC_StateKWin);
8526                 const QColor *bgndCols(APPEARANCE_NONE==app
8527                                         ? kwin ? backgroundColors(option) : backgroundColors(palette.color(QPalette::Active, QPalette::Window))
8528                                         : kwin ? buttonColors(option) : getMdiColors(titleBar, active)),
8529                              *btnCols(kwin || opts.titlebarButtons&TITLEBAR_BUTTON_STD_COLOR
8530                                         ? buttonColors(option)
8531                                         : getMdiColors(titleBar, active)),
8532                              *titleCols(APPEARANCE_NONE==app
8533                                         ? bgndCols
8534                                         : kwin || !(opts.titlebarButtons&TITLEBAR_BUTTON_STD_COLOR)
8535                                             ? btnCols : getMdiColors(titleBar, active));
8536                 QColor       textColor(theThemedApp==APP_KWIN
8537                                         ? option->palette.color(QPalette::WindowText)
8538                                         : active
8539                                             ? m_activeMdiTextColor
8540                                             : m_mdiTextColor),
8541                              iconColor(textColor),
8542                              shadow(WINDOW_SHADOW_COLOR(opts.titlebarEffect));
8543                 QStyleOption opt(*option);
8544                 QRect        tr(r),
8545                              menuRect(subControlRect(CC_TitleBar, titleBar, SC_TitleBarSysMenu, widget));
8546                 ERound       round=(opts.square&SQUARE_WINDOWS && opts.round>ROUND_SLIGHT) ? ROUND_SLIGHT : opts.round;
8547                 QColor       borderCol(kwin && option->version==(TBAR_BORDER_VERSION_HACK+2)
8548                                         ? palette.color(QPalette::Active, QPalette::Shadow)
8549                                         : titleCols[kwin && option->version==TBAR_BORDER_VERSION_HACK ? 0 : QTC_STD_BORDER]);
8550 
8551                 if (!kwin && widget && BLEND_TITLEBAR &&
8552                     qobject_cast<const QMdiSubWindow*>(widget)) {
8553                     const QWidget *w = nullptr;
8554                     if (qobject_cast<const QMainWindow*>(widget)) {
8555                         w = widget;
8556                     } else if (static_cast<const QMdiSubWindow*>(
8557                                    widget)->widget()) {
8558                         w = qobject_cast<const QMainWindow*>(
8559                             static_cast<const QMdiSubWindow*>(
8560                                 widget)->widget());
8561                     }
8562                     if(w)
8563                     {
8564                         const QMenuBar *menuBar=static_cast<const QMainWindow*>(w)->menuBar();
8565 
8566                         if(menuBar)
8567                             tr.adjust(0, 0, 0, menuBar->rect().height());
8568                     }
8569                 }
8570 
8571                 opt.state=State_Horizontal|State_Enabled|State_Raised|(active ? State_Active : State_None);
8572 
8573 #ifndef QTC_QT4_ENABLE_KDE
8574                 QPainterPath path;
8575 #else
8576                 QPainterPath path(round < ROUND_SLIGHT ? QPainterPath() :
8577                                   buildPath(QRectF(state&QtC_StateKWinNoBorder ?
8578                                                    tr : tr.adjusted(1, 1, -1, 0)),
8579                                             WIDGET_MDI_WINDOW_TITLE,
8580                                             state & QtC_StateKWin &&
8581                                             state & QtC_StateKWinTabDrag ?
8582                                             ROUNDED_ALL : ROUNDED_TOP,
8583                                             (round > ROUND_SLIGHT /*&& kwin*/ ?
8584                                              6.0 : 2.0)));
8585 #endif
8586                 if (!kwin && !qtcIsCustomBgnd(opts))
8587                     painter->fillRect(tr, borderCol);
8588 
8589                 painter->setRenderHint(QPainter::Antialiasing, true);
8590 
8591                 if (kwin && (state & QtC_StateKWinFillBgnd))
8592                     drawBevelGradient(titleCols[ORIGINAL_SHADE], painter, tr,
8593                                       path, true, false, APPEARANCE_FLAT,
8594                                       WIDGET_MDI_WINDOW, false);
8595                 if ((!kwin && !m_isPreview) ||
8596                     (APPEARANCE_NONE != app &&
8597                      (!qtcIsFlat(app) || (titleCols[ORIGINAL_SHADE] != QApplication::palette().background().color()))))
8598                     drawBevelGradient(titleCols[ORIGINAL_SHADE], painter, tr, path, true, false, app, WIDGET_MDI_WINDOW, false);
8599 
8600                 if (!(state & QtC_StateKWinNoBorder)) {
8601                     QColor light(titleCols[0]),
8602                            dark(borderCol);
8603                     bool   addLight=opts.windowBorder&WINDOW_BORDER_ADD_LIGHT_BORDER && (!kwin || qtcGetWindowBorderSize(false).sides>1);
8604 
8605                     if(kwin)
8606                     {
8607                         light.setAlphaF(1.0);
8608                         dark.setAlphaF(1.0);
8609                     }
8610 
8611                     if(addLight)
8612                     {
8613                         painter->setPen(light);
8614                         painter->save();
8615                         painter->setClipRect(r.adjusted(0, 0, -1, -1));
8616                         painter->drawPath(buildPath(r.adjusted(1, 1, 0, 1), WIDGET_MDI_WINDOW_TITLE, ROUNDED_TOP,
8617                                                     round<ROUND_SLIGHT
8618                                                         ? 0
8619                                                         : round>ROUND_SLIGHT /*&& kwin*/
8620                                                             ? 5.0
8621                                                             : 1.0));
8622                         painter->restore();
8623                     }
8624 
8625                     painter->setPen(dark);
8626                     painter->drawPath(buildPath(r, WIDGET_MDI_WINDOW_TITLE, ROUNDED_TOP,
8627                                                 round<ROUND_SLIGHT
8628                                                     ? 0
8629                                                     : round>ROUND_SLIGHT /*&& kwin*/
8630                                                         ? 6.0
8631                                                         : 2.0));
8632 
8633                     painter->setRenderHint(QPainter::Antialiasing, false);
8634 
8635                     if(addLight)
8636                     {
8637                         painter->setPen(light);
8638                         painter->drawPoint(r.x()+1, r.y()+r.height()-1);
8639                     }
8640 
8641                     if (round > ROUND_SLIGHT && opts.round >= ROUND_FULL) {
8642                         if (!(state & QtC_StateKWinCompositing)) {
8643                             painter->setPen(dark);
8644 
8645                             painter->drawLine(r.x()+1, r.y()+4, r.x()+1, r.y()+3);
8646                             painter->drawPoint(r.x()+2, r.y()+2);
8647                             painter->drawLine(r.x()+3, r.y()+1, r.x()+4, r.y()+1);
8648                             painter->drawLine(r.x()+r.width()-2, r.y()+4, r.x()+r.width()-2, r.y()+3);
8649                             painter->drawPoint(r.x()+r.width()-3, r.y()+2);
8650                             painter->drawLine(r.x()+r.width()-4, r.y()+1, r.x()+r.width()-5, r.y()+1);
8651                         }
8652 
8653                         if(addLight &&
8654                             (APPEARANCE_SHINY_GLASS!=(active ? opts.titlebarAppearance : opts.inactiveTitlebarAppearance)))
8655                         {
8656                             painter->setPen(light);
8657                             painter->drawLine(r.x()+2, r.y()+4, r.x()+2, r.y()+3);
8658                             painter->drawLine(r.x()+3, r.y()+2, r.x()+4, r.y()+2);
8659                             painter->drawLine(r.x()+r.width()-4, r.y()+2, r.x()+r.width()-5, r.y()+2);
8660                         }
8661                     }
8662 
8663                     if(opts.windowBorder&WINDOW_BORDER_BLEND_TITLEBAR && (!kwin || !(state&QtC_StateKWinNoBorder)))
8664                     {
8665                         static const int constFadeLen=8;
8666                         QPoint          start(0, r.y()+r.height()-(1+constFadeLen)),
8667                                         end(start.x(), start.y()+constFadeLen);
8668                         QLinearGradient grad(start, end);
8669 
8670                         grad.setColorAt(0, dark);
8671                         grad.setColorAt(1, m_backgroundCols[QTC_STD_BORDER]);
8672                         painter->setPen(QPen(QBrush(grad), 1));
8673                         painter->drawLine(r.x(), start.y(), r.x(), end.y());
8674                         painter->drawLine(r.x()+r.width()-1, start.y(), r.x()+r.width()-1, end.y());
8675 
8676                         if(addLight)
8677                         {
8678                             grad.setColorAt(0, light);
8679                             grad.setColorAt(1, m_backgroundCols[0]);
8680                             painter->setPen(QPen(QBrush(grad), 1));
8681                             painter->drawLine(r.x()+1, start.y(), r.x()+1, end.y());
8682                         }
8683                     }
8684                 }
8685                 else
8686                     painter->setRenderHint(QPainter::Antialiasing, false);
8687 
8688                 if(kwin)
8689                 {
8690                     painter->restore();
8691                     break;
8692                 }
8693 
8694                 int   adjust(0);
8695                 QRect captionRect(subControlRect(CC_TitleBar, titleBar, SC_TitleBarLabel, widget));
8696 
8697                 if(opts.titlebarButtons&TITLEBAR_BUTTON_SUNKEN_BACKGROUND && captionRect!=r)
8698                 {
8699                     bool menuIcon=TITLEBAR_ICON_MENU_BUTTON==opts.titlebarIcon,
8700                          menuLeft=menuRect.isValid() && !titleBar->icon.isNull() && menuRect.left()<(r.left()+constWindowMargin+4);
8701                     int  height=r.height()-(1+(2*constWindowMargin));
8702 
8703                     adjust=1;
8704                     if(captionRect.left()>(r.left()+constWindowMargin))
8705                     {
8706                         int width=captionRect.left()-(r.left()+(2*constWindowMargin));
8707 
8708                         if(!(menuIcon && menuLeft) || width>(height+4))
8709                             drawSunkenBevel(painter, QRect(r.left()+constWindowMargin+1, r.top()+constWindowMargin+1, width, height), titleCols[ORIGINAL_SHADE]);
8710                     }
8711                     if(captionRect.right()<(r.right()-constWindowMargin))
8712                     {
8713                         int width=r.right()-(captionRect.right()+(2*constWindowMargin));
8714 
8715                         if(!(menuIcon && !menuLeft) || width>(height+4))
8716                             drawSunkenBevel(painter, QRect(captionRect.right()+constWindowMargin, r.top()+constWindowMargin+1, width, height), titleCols[ORIGINAL_SHADE]);
8717                     }
8718                 }
8719 
8720                 bool    showIcon=TITLEBAR_ICON_NEXT_TO_TITLE==opts.titlebarIcon && !titleBar->icon.isNull();
8721                 int     iconSize=showIcon ? pixelMetric(QStyle::PM_SmallIconSize) : 0,
8722                         iconX=r.x();
8723                 QPixmap pixmap;
8724 
8725                 if(showIcon)
8726                     pixmap=getIconPixmap(titleBar->icon, iconSize, titleBar->state);
8727 
8728                 if(!titleBar->text.isEmpty())
8729                 {
8730                     static const int constPad=4;
8731 
8732                     Qt::Alignment alignment((Qt::Alignment)pixelMetric((QStyle::PixelMetric)QtC_TitleAlignment, 0L, 0L));
8733                     bool          alignFull(Qt::AlignHCenter==alignment),
8734                                   iconRight((!reverse && alignment&Qt::AlignRight) || (reverse && alignment&Qt::AlignLeft));
8735                     QRect         textRect(alignFull
8736                                             ? QRect(r.x(), captionRect.y(), r.width(), captionRect.height())
8737                                             : captionRect);
8738 
8739 #ifndef QTC_QT4_ENABLE_KDE
8740                     QFont         font(painter->font());
8741                     font.setBold(true);
8742                     painter->setFont(font);
8743 #else
8744                     painter->setFont(KGlobalSettings::windowTitleFont());
8745 #endif
8746 
8747                     QFontMetrics fm(painter->fontMetrics());
8748                     QString str(fm.elidedText(titleBar->text, Qt::ElideRight, textRect.width(), QPalette::WindowText));
8749 
8750                     int           textWidth=alignFull || (showIcon && alignment&Qt::AlignHCenter)
8751                                                 ? fm.boundingRect(str).width()+(showIcon ? iconSize+constPad : 0) : 0;
8752 
8753                     if(alignFull &&
8754                         ((captionRect.left()>((textRect.width()-textWidth)>>1)) ||
8755                           (captionRect.right()<((textRect.width()+textWidth)>>1)) ) )
8756                     {
8757                         alignment=Qt::AlignVCenter|Qt::AlignRight;
8758                         textRect=captionRect;
8759                     }
8760 
8761                     if(alignment&Qt::AlignLeft && constWindowMargin==textRect.x())
8762                         textRect.adjust(showIcon ? 4 : 6, 0, 0, 0);
8763 
8764                     if(showIcon)
8765                     {
8766                         if(alignment&Qt::AlignHCenter)
8767                         {
8768                             if(reverse)
8769                             {
8770                                 iconX=((textRect.width()-textWidth)/2.0)+0.5+textWidth+iconSize;
8771                                 textRect.setX(textRect.x()-(iconSize+constPad));
8772                             }
8773                             else
8774                             {
8775                                 iconX=((textRect.width()-textWidth)/2.0)+0.5;
8776                                 textRect.setX(iconX+iconSize+constPad);
8777                                 alignment=Qt::AlignVCenter|Qt::AlignLeft;
8778                             }
8779                         }
8780                         else if((!reverse && alignment&Qt::AlignLeft) || (reverse && alignment&Qt::AlignRight))
8781                         {
8782                             iconX=textRect.x();
8783                             textRect.setX(textRect.x()+(iconSize+constPad));
8784                         }
8785                         else if((!reverse && alignment&Qt::AlignRight) || (reverse && alignment&Qt::AlignLeft))
8786                         {
8787                             if(iconRight)
8788                             {
8789                                 iconX=textRect.x()+textRect.width()-iconSize;
8790                                 textRect.setWidth(textRect.width()-(iconSize+constPad));
8791                             }
8792                             else
8793                             {
8794                                 iconX=textRect.x()+textRect.width()-textWidth;
8795                                 if(iconX<textRect.x())
8796                                     iconX=textRect.x();
8797                             }
8798                         }
8799                     }
8800 
8801                     QTextOption textOpt(alignment|Qt::AlignVCenter);
8802                     textOpt.setWrapMode(QTextOption::NoWrap);
8803 
8804                     if(EFFECT_NONE!=opts.titlebarEffect)
8805                     {
8806                         shadow.setAlphaF(WINDOW_TEXT_SHADOW_ALPHA(opts.titlebarEffect));
8807                         //painter->setPen(shadow);
8808                         painter->setPen(blendColors(WINDOW_SHADOW_COLOR(opts.titlebarEffect), titleCols[ORIGINAL_SHADE],
8809                                                     WINDOW_TEXT_SHADOW_ALPHA(opts.titlebarEffect)));
8810                         painter->drawText(EFFECT_SHADOW==opts.titlebarEffect
8811                                             ? textRect.adjusted(1, 1, 1, 1)
8812                                             : textRect.adjusted(0, 1, 0, 1),
8813                                           str, textOpt);
8814 
8815                         if (!active && DARK_WINDOW_TEXT(textColor))
8816                         {
8817                             //textColor.setAlpha((textColor.alpha() * 180) >> 8);
8818                             textColor=blendColors(textColor, titleCols[ORIGINAL_SHADE], ((255 * 180) >> 8)/256.0);
8819                         }
8820                     }
8821                     painter->setPen(textColor);
8822                     painter->drawText(textRect, str, textOpt);
8823                 }
8824 
8825                 if(showIcon && iconX>=0)
8826                     painter->drawPixmap(iconX, r.y()+((r.height()-iconSize)/2)+1, pixmap);
8827 
8828                 if ((titleBar->subControls&SC_TitleBarMinButton) && (titleBar->titleBarFlags&Qt::WindowMinimizeButtonHint) &&
8829                     !(titleBar->titleBarState&Qt::WindowMinimized))
8830                     drawMdiControl(painter, titleBar, SC_TitleBarMinButton, widget, TITLEBAR_MIN, iconColor, btnCols, bgndCols,
8831                                    adjust, active);
8832 
8833                 if ((titleBar->subControls&SC_TitleBarMaxButton) && (titleBar->titleBarFlags&Qt::WindowMaximizeButtonHint) &&
8834                     !(titleBar->titleBarState&Qt::WindowMaximized))
8835                     drawMdiControl(painter, titleBar, SC_TitleBarMaxButton, widget, TITLEBAR_MAX, iconColor, btnCols, bgndCols,
8836                                    adjust, active);
8837 
8838                 if ((titleBar->subControls&SC_TitleBarCloseButton) && (titleBar->titleBarFlags&Qt::WindowSystemMenuHint))
8839                     drawMdiControl(painter, titleBar, SC_TitleBarCloseButton, widget, TITLEBAR_CLOSE, iconColor, btnCols, bgndCols,
8840                                    adjust, active);
8841 
8842                 if ((titleBar->subControls&SC_TitleBarNormalButton) &&
8843                     (((titleBar->titleBarFlags&Qt::WindowMinimizeButtonHint) &&
8844                     (titleBar->titleBarState&Qt::WindowMinimized)) ||
8845                     ((titleBar->titleBarFlags&Qt::WindowMaximizeButtonHint) &&
8846                     (titleBar->titleBarState&Qt::WindowMaximized))))
8847                     drawMdiControl(painter, titleBar, SC_TitleBarNormalButton, widget, TITLEBAR_MAX, iconColor, btnCols, bgndCols,
8848                                    adjust, active);
8849 
8850                 if (titleBar->subControls&SC_TitleBarContextHelpButton && (titleBar->titleBarFlags&Qt::WindowContextHelpButtonHint))
8851                     drawMdiControl(painter, titleBar, SC_TitleBarContextHelpButton, widget, TITLEBAR_HELP, iconColor, btnCols, bgndCols,
8852                                    adjust, active);
8853 
8854                 if (titleBar->subControls&SC_TitleBarShadeButton && (titleBar->titleBarFlags&Qt::WindowShadeButtonHint))
8855                     drawMdiControl(painter, titleBar, SC_TitleBarShadeButton, widget, TITLEBAR_SHADE, iconColor, btnCols, bgndCols,
8856                                    adjust, active);
8857 
8858                 if (titleBar->subControls&SC_TitleBarUnshadeButton && (titleBar->titleBarFlags&Qt::WindowShadeButtonHint))
8859                     drawMdiControl(painter, titleBar, SC_TitleBarUnshadeButton, widget, TITLEBAR_SHADE, iconColor, btnCols, bgndCols,
8860                                    adjust, active);
8861 
8862                 if ((titleBar->subControls&SC_TitleBarSysMenu) && (titleBar->titleBarFlags&Qt::WindowSystemMenuHint))
8863                 {
8864                     if(TITLEBAR_ICON_MENU_BUTTON==opts.titlebarIcon)
8865                     {
8866                         bool hover((titleBar->activeSubControls&SC_TitleBarSysMenu) && (titleBar->state&State_MouseOver));
8867 
8868                         if(active || hover || !(opts.titlebarButtons&TITLEBAR_BUTTOM_HIDE_ON_INACTIVE_WINDOW))
8869                         {
8870                             if (menuRect.isValid())
8871                             {
8872                                 bool sunken((titleBar->activeSubControls&SC_TitleBarSysMenu) && (titleBar->state&State_Sunken));
8873                                 int  offset(sunken ? 1 : 0);
8874 
8875 //                                 if(!(opts.titlebarButtons&TITLEBAR_BUTTON_ROUND))
8876 //                                     drawMdiButton(painter, menuRect, hover, sunken,
8877 //                                                   coloredMdiButtons(state&State_Active, hover)
8878 //                                                     ? m_titleBarButtonsCols[TITLEBAR_MENU] : btnCols);
8879 
8880                                 if (!titleBar->icon.isNull())
8881                                     titleBar->icon.paint(painter, menuRect.adjusted(offset, offset, offset, offset));
8882                                 else
8883                                 {
8884                                     QStyleOption tool(0);
8885 
8886                                     tool.palette = palette;
8887                                     tool.rect = menuRect;
8888                                     painter->save();
8889                                     drawItemPixmap(painter, menuRect.adjusted(offset, offset, offset, offset), Qt::AlignCenter,
8890                                                    standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(16, 16));
8891                                     painter->restore();
8892                                 }
8893                             }
8894                         }
8895                     }
8896                     else
8897                         drawMdiControl(painter, titleBar, SC_TitleBarSysMenu, widget, TITLEBAR_MENU, iconColor, btnCols, bgndCols,
8898                                        adjust, active);
8899 
8900                     if(active && opts.windowBorder&WINDOW_BORDER_SEPARATOR)
8901                     {
8902                         QColor        color(active ? m_activeMdiTextColor : m_mdiTextColor);
8903                         Qt::Alignment align(pixelMetric((QStyle::PixelMetric)QtC_TitleAlignment, 0L, 0L));
8904                         QRect         lr(r.x(), captionRect.y(), r.width(), captionRect.height());
8905 
8906                         lr.adjust(16, lr.height()-2, -16, 0);
8907                         color.setAlphaF(0.5);
8908                         drawFadedLine(painter, lr, color, align&(Qt::AlignHCenter|Qt::AlignRight),
8909                                       align&(Qt::AlignHCenter|Qt::AlignLeft), true);
8910                     }
8911                 }
8912 
8913                 painter->restore();
8914             }
8915             break;
8916         case CC_ScrollBar:
8917             if (auto scrollbar = styleOptCast<QStyleOptionSlider>(option)) {
8918                 bool useThreeButtonScrollBar(SCROLLBAR_KDE==opts.scrollbarType),
8919                                    horiz(Qt::Horizontal==scrollbar->orientation),
8920                                    maxed(scrollbar->minimum == scrollbar->maximum),
8921                                    atMin(maxed || scrollbar->sliderValue==scrollbar->minimum),
8922                                    atMax(maxed || scrollbar->sliderValue==scrollbar->maximum)/*,
8923                                    inStack(0!=opts.tabBgnd && inStackWidget(widget))*/;
8924                 QRect subline(subControlRect(control, option,
8925                                              SC_ScrollBarSubLine, widget));
8926                 QRect addline(subControlRect(control, option,
8927                                              SC_ScrollBarAddLine, widget));
8928                 QRect subpage(subControlRect(control, option,
8929                                              SC_ScrollBarSubPage, widget));
8930                 QRect addpage(subControlRect(control, option,
8931                                              SC_ScrollBarAddPage, widget));
8932                 QRect slider(subControlRect(control, option,
8933                                             SC_ScrollBarSlider, widget));
8934                 QRect first(subControlRect(control, option,
8935                                            SC_ScrollBarFirst, widget));
8936                 QRect last(subControlRect(control, option,
8937                                           SC_ScrollBarLast, widget));
8938                 QRect subline2(addline);
8939                 // QRect sbRect(scrollbar->rect);
8940                 QStyleOptionSlider opt(*scrollbar);
8941 
8942                 // For OO.o 3.2 need to fill widget background!
8943                 if(isOOWidget(widget))
8944                     painter->fillRect(r, palette.brush(QPalette::Window));
8945 
8946                 if(reverse && horiz)
8947                 {
8948                     bool tmp(atMin);
8949 
8950                     atMin=atMax;
8951                     atMax=tmp;
8952                 }
8953 
8954                 if (useThreeButtonScrollBar)
8955                 {
8956                     int sbextent(pixelMetric(PM_ScrollBarExtent, scrollbar, widget));
8957 
8958                     if(horiz && reverse)
8959                         subline2=QRect((r.x()+r.width()-1)-sbextent, r.y(), sbextent, sbextent);
8960                     else if (horiz)
8961                         subline2.translate(-addline.width(), 0);
8962                     else
8963                         subline2.translate(0, -addline.height());
8964 
8965                     if (horiz)
8966                         subline.setWidth(sbextent);
8967                     else
8968                         subline.setHeight(sbextent);
8969                 }
8970 
8971                 // Draw trough...
8972                 bool  noButtons(opts.round != ROUND_NONE &&
8973                                 (SCROLLBAR_NONE==opts.scrollbarType || opts.flatSbarButtons));
8974                 QRect s2(subpage), a2(addpage);
8975 
8976 #ifndef SIMPLE_SCROLLBARS
8977                 if(noButtons)
8978                 {
8979                     // Increase clipping to allow trough to "bleed" into slider corners...
8980                     a2.adjust(-3, -3, 3, 3);
8981                     s2.adjust(-3, -3, 3, 3);
8982                 }
8983 #endif
8984 
8985                 painter->save();
8986 
8987                 if ((opts.thinSbarGroove || opts.flatSbarButtons) &&
8988                     qtcCheckType(getParent<2>(widget),
8989                                  "QComboBoxListView")) {
8990                     painter->fillRect(r, palette.brush(QPalette::Base));
8991                 } else if (opts.thinSbarGroove && theThemedApp == APP_ARORA &&
8992                            qtcCheckType(widget, "WebView")) {
8993                     painter->fillRect(r, m_backgroundCols[ORIGINAL_SHADE]);
8994                 }
8995 
8996                 if(!opts.gtkScrollViews ||
8997                    (opts.flatSbarButtons && !qtcIsFlat(opts.sbarBgndAppearance)/* && SCROLLBAR_NONE!=opts.scrollbarType*/))
8998                     drawBevelGradientReal(palette.brush(QPalette::Background).color(), painter, r, horiz, false,
8999                                           opts.sbarBgndAppearance, WIDGET_SB_BGND);
9000 
9001                 if(noButtons || opts.flatSbarButtons)
9002                 {
9003                     int mod=THIN_SBAR_MOD;
9004                     // Draw complete groove here, as we want to round both ends...
9005                     opt.rect=subpage.united(addpage);
9006                     opt.state=scrollbar->state;
9007                     opt.state&=~(State_MouseOver|State_Sunken|State_On);
9008 
9009                     if(opts.thinSbarGroove && slider.isValid())
9010                     {
9011                         painter->save();
9012                         painter->setClipRegion(QRegion(opt.rect).subtract(slider.adjusted(1, 1, -1, -1)));
9013                     }
9014                     drawLightBevel(painter, opts.thinSbarGroove
9015                                                 ? horiz
9016                                                     ? opt.rect.adjusted(0, mod, 0, -mod)
9017                                                     : opt.rect.adjusted(mod, 0, -mod, 0)
9018                                                 : opt.rect, &opt, widget,
9019 #ifndef SIMPLE_SCROLLBARS
9020                                    !(opts.square&SQUARE_SB_SLIDER) && (SCROLLBAR_NONE==opts.scrollbarType || opts.flatSbarButtons)
9021                                         ? ROUNDED_ALL :
9022 #endif
9023                                    ROUNDED_NONE,
9024                                    m_backgroundCols[2], m_backgroundCols, true,
9025                                    opts.thinSbarGroove ? WIDGET_SLIDER_TROUGH : WIDGET_TROUGH);
9026                     if(opts.thinSbarGroove && slider.isValid())
9027                         painter->restore();
9028                 }
9029                 else
9030                 {
9031                     if((option->subControls&SC_ScrollBarSubPage) && subpage.isValid())
9032                     {
9033                         opt.state=scrollbar->state;
9034                         opt.rect = subpage;
9035 //                         if (!(scrollbar->activeSubControls&SC_ScrollBarSubPage))
9036                             opt.state &= ~(State_Sunken|State_MouseOver|State_On);
9037                         drawControl(CE_ScrollBarSubPage, &opt, painter, widget);
9038                     }
9039 
9040                     if((option->subControls&SC_ScrollBarAddPage) && addpage.isValid())
9041                     {
9042                         opt.state=scrollbar->state;
9043                         opt.rect = addpage;
9044 //                         if (!(scrollbar->activeSubControls&SC_ScrollBarAddPage))
9045                             opt.state &= ~(State_Sunken|State_MouseOver|State_On);
9046                         drawControl(CE_ScrollBarAddPage, &opt, painter, widget);
9047                     }
9048                 }
9049 
9050                 if((option->subControls&SC_ScrollBarSubLine) && subline.isValid())
9051                 {
9052                     opt.rect=subline;
9053                     opt.state=scrollbar->state/*|(inStack ? NO_BGND_BUTTON : State_None)*/;
9054                     if(maxed || atMin)
9055                         opt.state&=~State_Enabled;
9056                     if (!(scrollbar->activeSubControls&SC_ScrollBarSubLine) ||
9057                         (useThreeButtonScrollBar && m_sbWidget && m_sbWidget==widget))
9058                         opt.state &= ~(State_Sunken | State_MouseOver);
9059 
9060                     drawControl(CE_ScrollBarSubLine, &opt, painter, widget);
9061 
9062                     if (useThreeButtonScrollBar && subline2.isValid())
9063                     {
9064                         opt.rect=subline2;
9065                         opt.state=scrollbar->state/*|(inStack ? NO_BGND_BUTTON : State_None)*/;
9066                         if(maxed || atMin)
9067                             opt.state&=~State_Enabled;
9068                         if ((!(scrollbar->activeSubControls&SC_ScrollBarSubLine)) || (m_sbWidget && m_sbWidget!=widget))
9069                             opt.state &= ~(State_Sunken | State_MouseOver);
9070 
9071                         drawControl(CE_ScrollBarSubLine, &opt, painter, widget);
9072                     }
9073                 }
9074 
9075                 if((option->subControls&SC_ScrollBarAddLine) && addline.isValid())
9076                 {
9077                     opt.rect=addline;
9078                     opt.state=scrollbar->state/*|(inStack ? NO_BGND_BUTTON : State_None)*/;
9079                     if(maxed || atMax)
9080                         opt.state&=~State_Enabled;
9081                     if (!(scrollbar->activeSubControls&SC_ScrollBarAddLine))
9082                         opt.state &= ~(State_Sunken | State_MouseOver);
9083                     drawControl(CE_ScrollBarAddLine, &opt, painter, widget);
9084                 }
9085 
9086                 if((option->subControls&SC_ScrollBarFirst) && first.isValid())
9087                 {
9088                     opt.rect=first;
9089                     opt.state=scrollbar->state;
9090                     if (!(scrollbar->activeSubControls&SC_ScrollBarFirst))
9091                         opt.state &= ~(State_Sunken | State_MouseOver);
9092                     drawControl(CE_ScrollBarFirst, &opt, painter, widget);
9093                 }
9094 
9095                 if((option->subControls&SC_ScrollBarLast) && last.isValid())
9096                 {
9097                     opt.rect=last;
9098                     opt.state=scrollbar->state;
9099                     if (!(scrollbar->activeSubControls&SC_ScrollBarLast))
9100                         opt.state &= ~(State_Sunken | State_MouseOver);
9101                     drawControl(CE_ScrollBarLast, &opt, painter, widget);
9102                 }
9103 
9104                 if(((option->subControls&SC_ScrollBarSlider) || noButtons) && slider.isValid())
9105                 {
9106                     // If "SC_ScrollBarSlider" wasn't specified, then we only want to draw the portion
9107                     // of the slider that overlaps with the trough. So, once again set the clipping
9108                     // region...
9109 
9110                     // NO! Seeems to mess things up with Arora, su just dsiable all clipping when drawing
9111                     // the slider...
9112                     painter->setClipping(false);
9113 #ifdef INCREASE_SB_SLIDER
9114                     if (!opts.flatSbarButtons) {
9115                         if(atMax)
9116                             switch(opts.scrollbarType)
9117                             {
9118                                 case SCROLLBAR_KDE:
9119                                 case SCROLLBAR_WINDOWS:
9120                                 case SCROLLBAR_PLATINUM:
9121                                     if(horiz)
9122                                         slider.adjust(0, 0, 1, 0);
9123                                     else
9124                                         slider.adjust(0, 0, 0, 1);
9125                                 default:
9126                                     break;
9127                             }
9128                         if(atMin)
9129                             switch(opts.scrollbarType)
9130                             {
9131                                 case SCROLLBAR_KDE:
9132                                 case SCROLLBAR_WINDOWS:
9133                                 case SCROLLBAR_NEXT:
9134                                     if(horiz)
9135                                         slider.adjust(-1, 0, 0, 0);
9136                                     else
9137                                         slider.adjust(0, -1, 0, 0);
9138                                 default:
9139                                     break;
9140                             }
9141                     }
9142 #endif
9143                     opt.rect=slider;
9144                     opt.state=scrollbar->state;
9145                     if (!(scrollbar->activeSubControls&SC_ScrollBarSlider))
9146                         opt.state &= ~(State_Sunken | State_MouseOver);
9147                     drawControl(CE_ScrollBarSlider, &opt, painter, widget);
9148 
9149                     // ### perhaps this should not be able to accept focus if maxedOut?
9150                     if(state&State_HasFocus)
9151                     {
9152                         opt.state=scrollbar->state;
9153                         opt.rect=QRect(slider.x()+2, slider.y()+2, slider.width()-5, slider.height()-5);
9154                         drawPrimitive(PE_FrameFocusRect, &opt, painter, widget);
9155                     }
9156                 }
9157                 painter->restore();
9158             }
9159             break;
9160         case CC_ComboBox:
9161             if (auto comboBox = styleOptCast<QStyleOptionComboBox>(option)) {
9162                 painter->save();
9163 
9164                 QRect        frame(subControlRect(CC_ComboBox, option, SC_ComboBoxFrame, widget)),
9165                              arrow(subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget)),
9166                              field(subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget));
9167                 const QColor *use(buttonColors(option));
9168                 bool         sunken(state&State_On), // comboBox->listBox() ? comboBox->listBox()->isShown() : false),
9169                              glowOverFocus(state & State_MouseOver &&
9170                                            oneOf(opts.focus, FOCUS_FULL,
9171                                                  FOCUS_FILLED) &&
9172                                            MO_GLOW == opts.coloredMouseOver &&
9173                                            opts.buttonEffect != EFFECT_NONE &&
9174                                            !sunken && !comboBox->editable &&
9175                                            state & State_Enabled &&
9176                                            state & State_HasFocus),
9177                              doEffect(opts.buttonEffect != EFFECT_NONE &&
9178                                       (!comboBox->editable || opts.etchEntry)),
9179                              isOO(isOOWidget(widget)),
9180                              isOO31(isOO);
9181 
9182                 if(isOO)
9183                 {
9184                     // This (hopefull) checks is we're OO.o 3.2 - in which case no adjustment is required...
9185                     const QImage *img=getImage(painter);
9186 
9187                     isOO31=!img || img->rect()!=r;
9188 
9189                     if(isOO31)
9190                         frame.adjust(0, 0, 0, -2), arrow.adjust(0, 0, 0, -2), field.adjust(0, 0, 0, -2);
9191                     else
9192                         arrow.adjust(1, 0, 0, 0);
9193                 }
9194 
9195 //                 painter->fillRect(r, Qt::transparent);
9196                 if(doEffect)
9197                 {
9198                     bool glowFocus(state&State_HasFocus && state&State_Enabled && USE_GLOW_FOCUS(state&State_MouseOver));
9199 
9200                     if (!glowOverFocus && !(opts.thin & THIN_FRAMES) &&
9201                         !sunken && opts.coloredMouseOver == MO_GLOW &&
9202                         (((oneOf(opts.focus, FOCUS_FULL, FOCUS_FILLED) ||
9203                            glowFocus) && state & State_HasFocus) ||
9204                          state & State_MouseOver) &&
9205                         state & State_Enabled && !comboBox->editable) {
9206                         drawGlow(painter, r,
9207                                  oneOf(opts.focus, FOCUS_FULL, FOCUS_FILLED) &&
9208                                  state & State_HasFocus ? WIDGET_DEF_BUTTON :
9209                                  WIDGET_COMBO, glowFocus ? m_focusCols : 0L);
9210                     } else {
9211                         drawEtch(painter, r, widget, WIDGET_COMBO,
9212                                  !comboBox->editable &&
9213                                  opts.buttonEffect == EFFECT_SHADOW && !sunken,
9214                                  comboBox->editable && opts.square &
9215                                  SQUARE_ENTRY ? opts.unifyCombo ? ROUNDED_NONE :
9216                                  reverse ? ROUNDED_LEFT :
9217                                  ROUNDED_RIGHT : ROUNDED_ALL);
9218                     }
9219                     frame.adjust(1, 1, -1, -1);
9220                 }
9221 
9222                 if(/*comboBox->frame &&*/ frame.isValid() && (!comboBox->editable || !opts.unifyCombo))
9223                 {
9224                     const QColor *cols=m_comboBtnCols && comboBox->editable && state&State_Enabled ? m_comboBtnCols : use;
9225 
9226                     QStyleOption frameOpt(*option);
9227 
9228                     if (comboBox->editable && !(comboBox->activeSubControls&SC_ComboBoxArrow))
9229                         frameOpt.state &= ~(State_Sunken | State_MouseOver);
9230 
9231                     if(!sunken)
9232                         frameOpt.state|=State_Raised;
9233 
9234                     //if(opts.coloredMouseOver && frameOpt.state&State_MouseOver && comboBox->editable && !sunken)
9235                     //    frame.adjust(reverse ? 0 : 1, 0, reverse ? 1 : 0, 0);
9236 
9237                     drawLightBevel(painter, frame, &frameOpt, widget,
9238                                    comboBox->editable ? (reverse ? ROUNDED_LEFT : ROUNDED_RIGHT) : ROUNDED_ALL,
9239                                    getFill(&frameOpt, cols, false,
9240                                            (SHADE_DARKEN==opts.comboBtn || (SHADE_NONE!=opts.comboBtn &&
9241                                                                             !(state&State_Enabled))) &&
9242                                            comboBox->editable),
9243                                    cols, true, comboBox->editable ? WIDGET_COMBO_BUTTON : WIDGET_COMBO);
9244                 }
9245 
9246                 if(/*controls&SC_ComboBoxEditField &&*/ field.isValid())
9247                 {
9248                     if(comboBox->editable)
9249                     {
9250                         if(opts.unifyCombo)
9251                         {
9252                             field=r;
9253                             if(doEffect)
9254                                 field.adjust(1, 1, -1, -1);
9255                             if(isOO31)
9256                                 field.adjust(0, 0, 0, -2);
9257                         }
9258                         else if(doEffect)
9259                             field.adjust(reverse ? -4 : -3, -1, reverse ? 3 : 4, 1);
9260                         else
9261                             field.adjust(reverse ? -4 : -2, -1, reverse ? 2 : 4, 1);
9262                         drawEntryField(painter, field, widget, option, opts.unifyCombo ? ROUNDED_ALL : reverse ? ROUNDED_RIGHT : ROUNDED_LEFT,
9263                                        true, false);
9264                     }
9265                     else if(opts.comboSplitter && !(SHADE_DARKEN==opts.comboBtn || m_comboBtnCols))
9266                     {
9267                         drawFadedLine(painter, QRect(reverse ? arrow.right()+1 : arrow.x()-1, arrow.top()+2,
9268                                                      1, arrow.height()-4),
9269                                       use[BORDER_VAL(state&State_Enabled)], true, true, false);
9270                         if(!sunken)
9271                             drawFadedLine(painter, QRect(reverse ? arrow.right()+2 : arrow.x(), arrow.top()+2,
9272                                                          1, arrow.height()-4),
9273                                           use[0], true, true, false);
9274                     }
9275                 }
9276 
9277                 if(/*controls&SC_ComboBoxArrow && */arrow.isValid())
9278                 {
9279                     bool mouseOver=comboBox->editable && !(comboBox->activeSubControls&SC_ComboBoxArrow)
9280                                     ? false : (state&State_MouseOver ? true : false);
9281 
9282                     if(!comboBox->editable && (SHADE_DARKEN==opts.comboBtn || m_comboBtnCols))
9283                     {
9284                         if(!comboBox->editable && isOO && !isOO31)
9285                             arrow.adjust(reverse ? 0 : 1, 0, reverse ? -1 : 0, 0);
9286 
9287                         QStyleOption frameOpt(*option);
9288                         QRect        btn(arrow.x(), frame.y(), arrow.width()+1, frame.height());
9289                         const QColor *cols=SHADE_DARKEN==opts.comboBtn || !(state&State_Enabled) ? use : m_comboBtnCols;
9290                         if(!sunken)
9291                             frameOpt.state|=State_Raised;
9292                         painter->save();
9293                         painter->setClipRect(btn, Qt::IntersectClip);
9294                         drawLightBevel(painter, opts.comboSplitter
9295                                                     ? btn.adjusted(reverse ? -2 : 0, 0, reverse ? 2 : 1, 0)
9296                                                     : btn.adjusted(reverse ? -3 : -2, 0, reverse ? 2 : 1, 0),
9297                                        &frameOpt, widget, reverse ? ROUNDED_LEFT : ROUNDED_RIGHT,
9298                                        getFill(&frameOpt, cols, false,
9299                                                SHADE_DARKEN==opts.comboBtn || (SHADE_NONE!=opts.comboBtn &&
9300                                                                                !(state&State_Enabled))),
9301                                        cols, true, WIDGET_COMBO);
9302                         painter->restore();
9303                     }
9304 
9305                     if(sunken && (!comboBox->editable || !opts.unifyCombo))
9306                         arrow.adjust(1, 1, 1, 1);
9307 
9308                     const QColor &arrowColor = MOArrow(state, palette, mouseOver,
9309                                                        QPalette::ButtonText);
9310                     if(comboBox->editable || !(opts.gtkComboMenus && opts.doubleGtkComboArrow)) {
9311                         drawArrow(painter, arrow, PE_IndicatorArrowDown, arrowColor, false);
9312                     } else {
9313                         int middle = arrow.y() + (arrow.height() >> 1);
9314                         int gap = (opts.vArrows ? 2 : 1);
9315 
9316                         QRect ar = QRect(arrow.x(), middle - (LARGE_ARR_HEIGHT + gap),
9317                                          arrow.width(), LARGE_ARR_HEIGHT);
9318                         drawArrow(painter, ar, PE_IndicatorArrowUp, arrowColor, false);
9319                         ar = QRect(arrow.x(), middle + gap, arrow.width(), LARGE_ARR_HEIGHT);
9320                         drawArrow(painter, ar, PE_IndicatorArrowDown, arrowColor, false);
9321                     }
9322                 }
9323 
9324                 if(state&State_Enabled && state&State_HasFocus &&
9325                     /*state&State_KeyboardFocusChange &&*/ !comboBox->editable && FOCUS_GLOW!=opts.focus)
9326                 {
9327                     QStyleOptionFocusRect focus;
9328                     bool listViewCombo =
9329                         (comboBox->frame && widget &&
9330                          widget->rect().height() <
9331                          (opts.buttonEffect != EFFECT_NONE ? 22 : 20));
9332 
9333                     if (oneOf(opts.focus, FOCUS_FULL, FOCUS_FILLED)) {
9334                         focus.rect = frame;
9335                     } else if (opts.comboSplitter) {
9336                         focus.rect = (reverse ? field.adjusted(0, -1, 1, 1) :
9337                                       field.adjusted(-1, -1, 0, 1));
9338                         if (listViewCombo) {
9339                             focus.rect.adjust(0, -2, 0, 2);
9340                         }
9341                     } else if (listViewCombo) {
9342                         focus.rect = frame.adjusted(1, 1, -1, -1);
9343                     } else {
9344                         focus.rect = frame.adjusted(3, 3, -3, -3);
9345                     }
9346                     // Draw glow over top of filled focus
9347                     if(glowOverFocus && !(opts.thin&THIN_FRAMES))
9348                         drawGlow(painter, frame.adjusted(-1, -1, 1, 1), WIDGET_COMBO);
9349                     else
9350                         drawPrimitive(PE_FrameFocusRect, &focus, painter, widget);
9351                 }
9352                 painter->restore();
9353             }
9354             break;
9355         default:
9356             BaseStyle::drawComplexControl(control, option, painter, widget);
9357             break;
9358     }
9359 }
9360 
9361 // Use 'drawItemTextWithRole' when already know which role to use.
9362 void
9363 Style::drawItemTextWithRole(QPainter *painter, const QRect &rect, int flags,
9364                             const QPalette &pal, bool enabled,
9365                             const QString &text,
9366                             QPalette::ColorRole textRole) const
9367 {
9368     BaseStyle::drawItemText(painter, rect, flags, pal, enabled,
9369                                text, textRole);
9370 }
9371 
9372 void
9373 Style::drawItemText(QPainter *painter, const QRect &rect, int flags,
9374                     const QPalette &pal, bool enabled, const QString &text,
9375                     QPalette::ColorRole textRole) const
9376 {
9377     if (textRole == QPalette::ButtonText && !opts.stdSidebarButtons) {
9378         const QAbstractButton *button = getButton(nullptr, painter);
9379 
9380         if (button && isMultiTabBarTab(button) && button->isChecked()) {
9381             QPalette p(pal);
9382 
9383             if (m_inactiveChangeSelectionColor &&
9384                 p.currentColorGroup() == QPalette::Inactive) {
9385                 p.setCurrentColorGroup(QPalette::Active);
9386             }
9387             BaseStyle::drawItemText(painter, rect, flags, p, enabled,
9388                                        text, QPalette::HighlightedText);
9389             return;
9390         }
9391     }
9392 
9393     BaseStyle::drawItemText(painter, rect, flags, pal, enabled,
9394                                text, textRole);
9395 }
9396 
9397 QSize Style::sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const
9398 {
9399     prePolish(widget);
9400     QSize newSize(BaseStyle::sizeFromContents(type, option, size, widget));
9401 
9402     switch (type)
9403     {
9404         case CT_TabBarTab:
9405             newSize+=QSize(1, 1);
9406             break;
9407         case CT_Splitter:
9408         {
9409             int sw=pixelMetric(PM_SplitterWidth, 0L, 0L);
9410             return QSize(sw, sw);
9411         }
9412         case CT_PushButton:
9413         {
9414             newSize=size;
9415             newSize.setWidth(newSize.width()+(ROUND_MAX==opts.round ? 12 : 8));
9416 
9417             if (auto btn = styleOptCast<QStyleOptionButton>(option)) {
9418                 if (!opts.stdBtnSizes) {
9419                     // Cant rely on AutoDefaultButton
9420                     //   - as VirtualBox does not set this!!!
9421                     if (qtcCheckType<QDialogButtonBox>(getParent(widget)) ||
9422                         qtcCheckType(getParent(widget), "KFileWidget")) {
9423                         int iconHeight = (btn->icon.isNull() ?
9424                                           btn->iconSize.height() : 16);
9425                         if (size.height() < iconHeight + 2) {
9426                             newSize.setHeight(iconHeight + 2);
9427                         }
9428                     }
9429                 }
9430 
9431                 int margin = (pixelMetric(PM_ButtonMargin, btn, widget)+
9432                               (pixelMetric(PM_DefaultFrameWidth, btn, widget) * 2))-MAX_ROUND_BTN_PAD;
9433 
9434                 newSize+=QSize(margin, margin);
9435 
9436                 if (btn->features&QStyleOptionButton::HasMenu)
9437                     newSize+=QSize(4, 0);
9438 
9439                 if (!btn->text.isEmpty() && "..."!=btn->text && newSize.width() < 80)
9440                     newSize.setWidth(80);
9441 
9442                 newSize.rheight() += ((1 - newSize.rheight()) & 1);
9443             }
9444             break;
9445         }
9446 //         case CT_RadioButton:
9447 //             ++newSize.rheight();
9448 //             ++newSize.rwidth();
9449 //             break;
9450         case CT_RadioButton:
9451         case CT_CheckBox:
9452             if (auto btn = styleOptCast<QStyleOptionButton>(option)) {
9453                 bool isRadio = CT_RadioButton==type;
9454                 int  w = /*proxy()->*/pixelMetric(isRadio ? PM_ExclusiveIndicatorWidth : PM_IndicatorWidth, btn, widget),
9455                      h = /*proxy()->*/pixelMetric(isRadio ? PM_ExclusiveIndicatorHeight : PM_IndicatorHeight, btn, widget),
9456                      margins = 0;
9457 
9458                 newSize=size;
9459                 // we add 4 pixels for label margins
9460                 if (btn->icon.isNull() || !btn->text.isEmpty())
9461                     margins = 0+/*proxy()->*/pixelMetric(isRadio ? PM_RadioButtonLabelSpacing : PM_CheckBoxLabelSpacing, option, widget)+
9462                               (opts.crHighlight ? 4 : 0);
9463 
9464                 newSize += QSize(w + margins, 4);
9465                 newSize.setHeight(qMax(newSize.height(), h));
9466             }
9467             break;
9468         case CT_ScrollBar:
9469             if (auto scrollBar = styleOptCast<QStyleOptionSlider>(option)) {
9470                 int scrollBarExtent =
9471                     pixelMetric(PM_ScrollBarExtent, option, widget);
9472                 // See https://github.com/QtCurve/qtcurve-qt4/issues/7
9473                 // and https://bugs.kde.org/show_bug.cgi?id=317690.
9474                 int scrollBarLen =
9475                     (qtcMax(scrollBarExtent, 13) *
9476                      qtcScrollbarButtonNumSize(opts.scrollbarType) +
9477                      pixelMetric(PM_ScrollBarSliderMin, option, widget));
9478 
9479                 if (scrollBar->orientation == Qt::Horizontal) {
9480                     newSize = QSize(scrollBarLen, scrollBarExtent);
9481                 } else {
9482                     newSize = QSize(scrollBarExtent, scrollBarLen);
9483                 }
9484             }
9485             break;
9486         case CT_LineEdit:
9487             if (auto f = styleOptCast<QStyleOptionFrame>(option)) {
9488                 newSize = size + QSize(2 * f->lineWidth, 2 * f->lineWidth);
9489             }
9490             break;
9491         case CT_SpinBox:
9492             if(!opts.unifySpin)
9493                 newSize.rheight() -= ((1 - newSize.rheight()) & 1);
9494             break;
9495         case CT_ToolButton:
9496         {
9497             newSize = QSize(size.width()+8, size.height()+8);
9498             // -- from kstyle & oxygen --
9499             // We want to avoid super-skiny buttons, for things like "up" when icons + text
9500             // For this, we would like to make width >= height.
9501             // However, once we get here, QToolButton may have already put in the menu area
9502             // (PM_MenuButtonIndicator) into the width. So we may have to take it out, fix things
9503             // up, and add it back in. So much for class-independent rendering...
9504             int menuAreaWidth(0);
9505 
9506             if (auto tbOpt = styleOptCast<QStyleOptionToolButton>(option)) {
9507                 // Make Kate/KWrite's option toolbuton have the same size as the next/prev buttons...
9508                 if (widget && !getToolBar(widget) && !tbOpt->text.isEmpty() &&
9509                    tbOpt->features & QStyleOptionToolButton::MenuButtonPopup) {
9510                     QStyleOptionButton btn;
9511 
9512                     btn.init(widget);
9513                     btn.text=tbOpt->text;
9514                     btn.icon=tbOpt->icon;
9515                     btn.iconSize=tbOpt->iconSize;
9516                     btn.features=tbOpt->features&QStyleOptionToolButton::MenuButtonPopup
9517                                     ? QStyleOptionButton::HasMenu : QStyleOptionButton::None;
9518                     return sizeFromContents(CT_PushButton, &btn, size, widget);
9519                 }
9520 
9521                 if (!tbOpt->icon.isNull() && !tbOpt->text.isEmpty() && Qt::ToolButtonTextUnderIcon==tbOpt->toolButtonStyle)
9522                     newSize.setHeight(newSize.height()-4);
9523 
9524                 if (tbOpt->features & QStyleOptionToolButton::MenuButtonPopup)
9525                     menuAreaWidth = pixelMetric(QStyle::PM_MenuButtonIndicator,
9526                                                 option, widget);
9527                 else if (tbOpt->features & QStyleOptionToolButton::HasMenu)
9528                     switch(tbOpt->toolButtonStyle)
9529                     {
9530                         case Qt::ToolButtonIconOnly:
9531                             newSize.setWidth(newSize.width()+LARGE_ARR_WIDTH+2);
9532                             break;
9533                         case Qt::ToolButtonTextBesideIcon:
9534                             newSize.setWidth(newSize.width()+3);
9535                             break;
9536                         case Qt::ToolButtonTextOnly:
9537                             newSize.setWidth(newSize.width()+8);
9538                             break;
9539                         case Qt::ToolButtonTextUnderIcon:
9540                             newSize.setWidth(newSize.width()+8);
9541                             break;
9542                         default:
9543                             break;
9544                     }
9545             }
9546 
9547             newSize.setWidth(newSize.width() - menuAreaWidth);
9548             if (newSize.width() < newSize.height())
9549                 newSize.setWidth(newSize.height());
9550             newSize.setWidth(newSize.width() + menuAreaWidth);
9551 
9552             break;
9553         }
9554         case CT_ComboBox:
9555         {
9556             newSize=size;
9557             newSize.setWidth(newSize.width()+4);
9558 
9559             auto combo = styleOptCast<QStyleOptionComboBox>(option);
9560 
9561             int  margin = (pixelMetric(PM_ButtonMargin, option, widget)+
9562                               (pixelMetric(PM_DefaultFrameWidth, option, widget) * 2))-MAX_ROUND_BTN_PAD,
9563                  textMargins = 2*(pixelMetric(PM_FocusFrameHMargin) + 1),
9564                  // QItemDelegate::sizeHint expands the textMargins two times, thus the 2*textMargins...
9565                  other = qMax(opts.buttonEffect != EFFECT_NONE ? 20 : 18, 2*textMargins + pixelMetric(QStyle::PM_ScrollBarExtent, option, widget));
9566             bool editable=combo ? combo->editable : false;
9567             newSize+=QSize(margin+other, margin-2);
9568             newSize.rheight() += ((1 - newSize.rheight()) & 1);
9569 
9570             if (!opts.etchEntry && opts.buttonEffect != EFFECT_NONE && editable)
9571                 newSize.rheight()-=2;
9572             // KWord's zoom combo clips 'Fit Page Width' without the following...
9573             if(editable)
9574                 newSize.rwidth()+=6;
9575             break;
9576         }
9577         case CT_MenuItem:
9578             if (auto mi = styleOptCast<QStyleOptionMenuItem>(option)) {
9579                 // Taken from QWindowStyle...
9580                 int w = size.width();
9581 
9582                 if (QStyleOptionMenuItem::Separator==mi->menuItemType)
9583                     newSize = QSize(10, windowsSepHeight);
9584                 else if (mi->icon.isNull())
9585                 {
9586                     newSize.setHeight(newSize.height() - 2);
9587                     w -= 6;
9588                 }
9589 
9590                 if (QStyleOptionMenuItem::Separator!=mi->menuItemType && !mi->icon.isNull())
9591                 {
9592                     int iconExtent = pixelMetric(PM_SmallIconSize, option, widget);
9593                     newSize.setHeight(qMax(newSize.height(),
9594                                   mi->icon.actualSize(QSize(iconExtent, iconExtent)).height()
9595                                   + 2 * windowsItemFrame));
9596                 }
9597                 int maxpmw = mi->maxIconWidth,
9598                     tabSpacing = 20;
9599 
9600                 if (!opts.buttonStyleMenuSections && QStyleOptionMenuItem::Separator == mi->menuItemType && !mi->text.isEmpty())
9601                 {
9602                     QFont fontBold = mi->font;
9603                     fontBold.setBold(true);
9604                     QFontMetrics fmBold(fontBold);
9605                     // _set_ w, it will have been initialised to something inappropriately small
9606                     w = fmBold.width(mi->text);
9607                 }
9608                 else if (mi->text.contains(QLatin1Char('\t')))
9609                     w += tabSpacing;
9610                 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
9611                     w += 2 * windowsArrowHMargin;
9612                 else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem)
9613                 {
9614                     // adjust the font and add the difference in size.
9615                     // it would be better if the font could be adjusted in the initStyleOption qmenu func!!
9616                     QFontMetrics fm(mi->font);
9617                     QFont fontBold = mi->font;
9618                     fontBold.setBold(true);
9619                     QFontMetrics fmBold(fontBold);
9620                     w += fmBold.width(mi->text) - fm.width(mi->text);
9621                 }
9622 
9623                 if (QStyleOptionMenuItem::Separator != mi->menuItemType || opts.buttonStyleMenuSections)
9624                 {
9625                     int checkcol = qMax<int>(maxpmw, windowsCheckMarkWidth); // Windows always shows a check column
9626                     w += checkcol + windowsRightBorder;
9627                 }
9628                 else
9629                 {
9630                     w += 5;
9631                 }
9632                 w += 10;
9633                 newSize.setWidth(w);
9634                 // ....
9635 
9636                 int h(newSize.height()-8); // Fix mainly for Qt4.4
9637 
9638                 if (QStyleOptionMenuItem::Separator==mi->menuItemType && mi->text.isEmpty())
9639                     h = 7;
9640                 else
9641                 {
9642                     h = qMax(h, mi->fontMetrics.height());
9643                     if (!mi->icon.isNull())
9644                         h = qMax(h, mi->icon.pixmap(pixelMetric(PM_SmallIconSize), QIcon::Normal).height());
9645 
9646                     if (h < 18)
9647                         h = 18;
9648                     h+=((opts.thin&THIN_MENU_ITEMS) ? 2 : 4);
9649 
9650                     if(QStyleOptionMenuItem::Separator==mi->menuItemType)
9651                         h+=4;
9652                 }
9653 
9654                 newSize.setHeight(h);
9655                 // Gtk2's icon->text spacing is 2 pixels smaller - so adjust here...
9656                 newSize.setWidth(newSize.width()-2);
9657             }
9658             break;
9659         case CT_MenuBarItem:
9660             if (!size.isEmpty())
9661                 newSize = size + QSize(windowsItemHMargin * 4 + 2,
9662                                        windowsItemVMargin + 1);
9663             break;
9664         default:
9665             break;
9666     }
9667 
9668     return newSize;
9669 }
9670 
9671 QRect Style::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
9672 {
9673     prePolish(widget);
9674     QRect rect;
9675     switch (element)
9676     {
9677         case SE_SliderFocusRect:
9678         case SE_ToolBoxTabContents:
9679             return visualRect(option->direction, option->rect, option->rect);
9680         case SE_DockWidgetTitleBarText: {
9681             auto v2= styleOptCast<QStyleOptionDockWidgetV2>(option);
9682             bool verticalTitleBar = v2 ? v2->verticalTitleBar : false;
9683             int m = pixelMetric(PM_DockWidgetTitleMargin, option, widget);
9684 
9685             rect = BaseStyle::subElementRect(element, option, widget);
9686 
9687             if (verticalTitleBar)
9688                 rect.adjust(0, 0, 0, -m);
9689             else if (Qt::LeftToRight==option->direction )
9690                 rect.adjust(m, 0, 0, 0);
9691             else
9692                 rect.adjust(0, 0, -m, 0);
9693             return rect;
9694         }
9695         case SE_TabBarTabLeftButton:
9696             return BaseStyle::subElementRect(element, option, widget).translated(-2, -1);
9697         case SE_TabBarTabRightButton:
9698             return BaseStyle::subElementRect(element, option, widget).translated(2, -1);
9699         case SE_TabBarTabText:
9700             if (auto tab = styleOptCast<QStyleOptionTab>(option)) {
9701                 QStyleOptionTabV3 tabV2(*tab);
9702                 bool              verticalTabs=QTabBar::RoundedEast==tabV2.shape || QTabBar::RoundedWest==tabV2.shape ||
9703                                                QTabBar::TriangularEast==tabV2.shape || QTabBar::TriangularWest==tabV2.shape;
9704 
9705                 rect=tabV2.rect;
9706                 if (verticalTabs)
9707                     rect.setRect(0, 0, rect.height(), rect.width());
9708                 int verticalShift = pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget),
9709                     horizontalShift = pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget);
9710                 if (tabV2.shape == QTabBar::RoundedSouth || tabV2.shape == QTabBar::TriangularSouth)
9711                     verticalShift = -verticalShift;
9712                 rect.adjust(0, 0, horizontalShift, verticalShift);
9713                 bool selected = tabV2.state & State_Selected;
9714                 if (selected)
9715                 {
9716                     rect.setBottom(rect.bottom() - verticalShift);
9717                     rect.setRight(rect.right() - horizontalShift);
9718                 }
9719 
9720                 // left widget
9721                 if(opts.centerTabText)
9722                 {
9723                     if (!tabV2.leftButtonSize.isEmpty())  // left widget
9724                         rect.setLeft(rect.left() + constTabPad +
9725                                      (verticalTabs ? tabV2.leftButtonSize.height() : tabV2.leftButtonSize.width()));
9726                     if (!tabV2.rightButtonSize.isEmpty()) // right widget
9727                         rect.setRight(rect.right() - constTabPad -
9728                                      (verticalTabs ? tabV2.rightButtonSize.height() : tabV2.rightButtonSize.width()));
9729                 }
9730                 else
9731                 {
9732                     if (tabV2.leftButtonSize.isNull())
9733                         rect.setLeft(rect.left()+constTabPad);
9734                     else if(tabV2.leftButtonSize.width()>0)
9735                         rect.setLeft(rect.left() + constTabPad + 2 +
9736                                     (verticalTabs ? tabV2.leftButtonSize.height() : tabV2.leftButtonSize.width()));
9737                     else if(tabV2.icon.isNull())
9738                         rect.setLeft(rect.left()+constTabPad);
9739                     else
9740                         rect.setLeft(rect.left() + 2);
9741                 }
9742 
9743                 // icon
9744                 if (!tabV2.icon.isNull())
9745                 {
9746                     QSize iconSize = tabV2.iconSize;
9747                     if (!iconSize.isValid())
9748                     {
9749                         int iconExtent = pixelMetric(PM_SmallIconSize);
9750                         iconSize = QSize(iconExtent, iconExtent);
9751                     }
9752                     QSize tabIconSize = tabV2.icon.actualSize(iconSize,
9753                                                             (tabV2.state & State_Enabled) ? QIcon::Normal
9754                                                             : QIcon::Disabled);
9755                     int offset = 4;
9756 
9757                     if (!opts.centerTabText && tabV2.leftButtonSize.isNull())
9758                         offset += 2;
9759 
9760                     QRect iconRect = QRect(rect.left() + offset, rect.center().y() - tabIconSize.height() / 2,
9761                                            tabIconSize.width(), tabIconSize .height());
9762                     if (!verticalTabs)
9763                         iconRect = visualRect(option->direction, option->rect, iconRect);
9764                     rect.setLeft(rect.left() + tabIconSize.width() + offset + 2);
9765                 }
9766 
9767                 // right widget
9768                 if (!opts.centerTabText && !tabV2.rightButtonSize.isNull() && tabV2.rightButtonSize.width()>0)
9769                     rect.setRight(rect.right() - constTabPad - 2 -
9770                                   (verticalTabs ? tabV2.rightButtonSize.height() : tabV2.rightButtonSize.width()));
9771                 else
9772                     rect.setRight(rect.right() - constTabPad);
9773 
9774 
9775                 if (!verticalTabs)
9776                     rect = visualRect(option->direction, option->rect, rect);
9777                 return rect;
9778             }
9779             break;
9780         case SE_RadioButtonIndicator:
9781             rect = visualRect(option->direction, option->rect,
9782                               BaseStyle::subElementRect(element, option, widget)).adjusted(0, 0, 1, 1);
9783             break;
9784         case SE_ProgressBarContents:
9785             return (opts.fillProgress ? opts.buttonEffect != EFFECT_NONE &&
9786                     opts.borderProgress ? option->rect.adjusted(1, 1, -1, -1) :
9787                     option->rect : opts.buttonEffect != EFFECT_NONE &&
9788                     opts.borderProgress ? option->rect.adjusted(3, 3, -3, -3) :
9789                     option->rect.adjusted(2, 2, -2, -2));
9790         case SE_ProgressBarGroove:
9791         case SE_ProgressBarLabel:
9792             return option->rect;
9793         case SE_GroupBoxLayoutItem:
9794             rect = option->rect;
9795 //             if (auto groupBoxOpt = styleOptCast<QStyleOptionGroupBox>(option))
9796 //                 if (groupBoxOpt->subControls & (SC_GroupBoxCheckBox | SC_GroupBoxLabel))
9797 //                     rect.setTop(rect.top() + 2);    // eat the top margin a little bit
9798             break;
9799         case SE_PushButtonFocusRect:
9800             if (oneOf(opts.focus, FOCUS_FULL, FOCUS_FILLED)) {
9801                 rect = subElementRect(SE_PushButtonContents, option, widget);
9802                 if (opts.buttonEffect != EFFECT_NONE) {
9803                     rect.adjust(-1, -1, 1, 1);
9804                 } else {
9805                     rect.adjust(-2, -2, 2, 2);
9806                 }
9807             } else {
9808                 rect = BaseStyle::subElementRect(element, option, widget);
9809                 if (opts.buttonEffect != EFFECT_NONE) {
9810                     rect.adjust(1, 1, -1, -1);
9811                 }
9812             }
9813             return rect;
9814         default:
9815             return BaseStyle::subElementRect(element, option, widget);
9816     }
9817 
9818     return visualRect(option->direction, option->rect, rect);
9819 }
9820 
9821 QRect Style::subControlRect(ComplexControl control, const QStyleOptionComplex *option, SubControl subControl, const QWidget *widget) const
9822 {
9823     prePolish(widget);
9824     QRect r(option->rect);
9825     bool  reverse(Qt::RightToLeft==option->direction);
9826 
9827     switch (control)
9828     {
9829         case CC_ComboBox:
9830             if (auto comboBox = styleOptCast<QStyleOptionComboBox>(option))
9831             {
9832                 bool ed(comboBox->editable),
9833                      doEtch((!ed || opts.etchEntry) &&
9834                             opts.buttonEffect != EFFECT_NONE);
9835                 int  x(r.x()),
9836                      y(r.y()),
9837                      w(r.width()),
9838                      h(r.height());
9839 
9840                 switch (subControl)
9841                 {
9842                     case SC_ComboBoxFrame:
9843                         if(ed)
9844                         {
9845                             int btnWidth(doEtch ? 22 : 20);
9846 
9847                             r=QRect(x+w-btnWidth, y, btnWidth, h);
9848                         }
9849                         break;
9850                     case SC_ComboBoxArrow:
9851                     {
9852                         int bmarg(comboBox->frame ? 2 : 0);
9853 
9854                         r.setRect(x + w - bmarg - (doEtch ? 17 : 16), y + bmarg, 16, h - 2*bmarg);
9855                         if(ed && opts.unifyCombo)
9856                             r.adjust(-1, 0, 0, 0);
9857                         break;
9858                     }
9859                     case SC_ComboBoxEditField:
9860                     {
9861                         int margin(comboBox->frame ? 3 : 0);
9862 
9863                         r.setRect(x + margin+(opts.unifyCombo ? 0 : 2), y + margin,
9864                                   w - 2 * margin - (opts.unifyCombo ? 15 : 23), h - 2 * margin);
9865                         if(doEtch)
9866                             r.adjust(ed ? 0 : 1, 1, ed ? 0 : -1, -1);
9867                         if(ed)
9868                             r.adjust(-1, -2, 1, 2);
9869                         break;
9870                     }
9871                     case SC_ComboBoxListBoxPopup:
9872                     default:
9873                         break;
9874                 }
9875                 return visualRect(comboBox->direction, comboBox->rect, r);
9876             }
9877             break;
9878         case CC_SpinBox:
9879             if (auto spinbox = styleOptCast<QStyleOptionSpinBox>(option)) {
9880                 int   fw(spinbox->frame ? pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0);
9881                 QSize bs;
9882 
9883                 bs.setHeight(r.height()>>1);
9884                 if(bs.height()< 8)
9885                     bs.setHeight(8);
9886                 bs.setWidth(opts.buttonEffect != EFFECT_NONE && opts.etchEntry ?
9887                             16 : 15);
9888                 bs=bs.expandedTo(QApplication::globalStrut());
9889 
9890                 int y(0), x(reverse ? 0 : r.width()-bs.width());
9891 
9892                 switch(subControl)
9893                 {
9894                     case SC_SpinBoxUp:
9895                         return QAbstractSpinBox::NoButtons==spinbox->buttonSymbols
9896                                     ? QRect()
9897                                     : QRect(x, y, bs.width(), bs.height());
9898                     case SC_SpinBoxDown:
9899                         if(QAbstractSpinBox::NoButtons==spinbox->buttonSymbols)
9900                             return QRect();
9901                         else
9902                             return QRect(x, y+bs.height(), bs.width(), bs.height()+(bs.height()*2==r.height() ? 0 : 1));
9903                     case SC_SpinBoxEditField:
9904                     {
9905                         int pad=opts.round>ROUND_FULL ? 2 : 0;
9906 
9907                         if (QAbstractSpinBox::NoButtons==spinbox->buttonSymbols)
9908                             return QRect(fw, fw, (x-fw*2)-pad, r.height()-2*fw);
9909                         else
9910                             return QRect(fw+(reverse ? bs.width() : 0), fw, (x-fw*2)-pad, r.height()-2*fw);
9911                     }
9912                     case SC_SpinBoxFrame:
9913                     default:
9914                         return visualRect(spinbox->direction, spinbox->rect, spinbox->rect);
9915                 }
9916             }
9917             break;
9918         case CC_ScrollBar:
9919             if (auto scrollBar = styleOptCast<QStyleOptionSlider>(option)) {
9920                 // Taken from kstyle.cpp (KDE 3) , and modified so as to allow for no scrollbar butttons...
9921                 bool  threeButtonScrollBar(SCROLLBAR_KDE==opts.scrollbarType),
9922                       platinumScrollBar(SCROLLBAR_PLATINUM==opts.scrollbarType),
9923                       nextScrollBar(SCROLLBAR_NEXT==opts.scrollbarType),
9924                       noButtons(SCROLLBAR_NONE==opts.scrollbarType);
9925                 QRect ret;
9926                 bool  horizontal(Qt::Horizontal==scrollBar->orientation);
9927                 int   sbextent(pixelMetric(PM_ScrollBarExtent, scrollBar, widget)),
9928                       sliderMaxLength(((scrollBar->orientation == Qt::Horizontal) ?
9929                                       scrollBar->rect.width() : scrollBar->rect.height()) - (sbextent * qtcScrollbarButtonNum(opts.scrollbarType))),
9930                       sliderMinLength(pixelMetric(PM_ScrollBarSliderMin, scrollBar, widget)),
9931                       sliderLength;
9932 
9933                 if (scrollBar->maximum != scrollBar->minimum)
9934                 {
9935                     uint valueRange = scrollBar->maximum - scrollBar->minimum;
9936                     sliderLength = (scrollBar->pageStep * sliderMaxLength) / (valueRange + scrollBar->pageStep);
9937 
9938                     if (sliderLength < sliderMinLength || (!isOOWidget(widget) && valueRange > INT_MAX / 2))
9939                         sliderLength = sliderMinLength;
9940                     if (sliderLength > sliderMaxLength)
9941                         sliderLength = sliderMaxLength;
9942                 }
9943                 else
9944                     sliderLength = sliderMaxLength;
9945 
9946                 int sliderstart(sliderPositionFromValue(scrollBar->minimum,
9947                                                         scrollBar->maximum,
9948                                                         scrollBar->sliderPosition,
9949                                                         sliderMaxLength - sliderLength,
9950                                                         scrollBar->upsideDown));
9951 
9952                 switch(opts.scrollbarType)
9953                 {
9954                     case SCROLLBAR_KDE:
9955                     case SCROLLBAR_WINDOWS:
9956                         sliderstart+=sbextent;
9957                         break;
9958                     case SCROLLBAR_NEXT:
9959                         sliderstart+=sbextent*2;
9960                     default:
9961                         break;
9962                 }
9963 
9964                 // Subcontrols
9965                 switch(subControl)
9966                 {
9967                     case SC_ScrollBarSubLine:
9968                         if(noButtons)
9969                             return QRect();
9970 
9971                         // top/left button
9972                         if (platinumScrollBar)
9973                             if (horizontal)
9974                                 ret.setRect(scrollBar->rect.width() - 2 * sbextent, 0, sbextent, sbextent);
9975                             else
9976                                 ret.setRect(0, scrollBar->rect.height() - 2 * sbextent, sbextent, sbextent);
9977                         else if(threeButtonScrollBar)
9978                             if (horizontal)
9979                                 ret.setRect(0, 0, scrollBar->rect.width() - sbextent +1, sbextent);
9980                             else
9981                                 ret.setRect(0, 0, sbextent, scrollBar->rect.height() - sbextent +1);
9982                         else
9983                             ret.setRect(0, 0, sbextent, sbextent);
9984                         break;
9985                     case SB_SUB2:
9986                         if(threeButtonScrollBar)
9987                             if (horizontal)
9988                                 if(reverse)
9989                                     ret.setRect(sbextent, 0, sbextent, sbextent);
9990                                 else
9991                                     ret.setRect(scrollBar->rect.width() - 2 * sbextent, 0, sbextent, sbextent);
9992                             else
9993                                 ret.setRect(0, scrollBar->rect.height() - 2 * sbextent, sbextent, sbextent);
9994                         else
9995                             return QRect();
9996                         break;
9997                     case SC_ScrollBarAddLine:
9998                         if(noButtons)
9999                             return QRect();
10000 
10001                         // bottom/right button
10002                         if (nextScrollBar)
10003                             if (horizontal)
10004                                 ret.setRect(sbextent, 0, sbextent, sbextent);
10005                             else
10006                                 ret.setRect(0, sbextent, sbextent, sbextent);
10007                         else
10008                             if (horizontal)
10009                                 ret.setRect(scrollBar->rect.width() - sbextent, 0, sbextent, sbextent);
10010                             else
10011                                 ret.setRect(0, scrollBar->rect.height() - sbextent, sbextent, sbextent);
10012                         break;
10013                     case SC_ScrollBarSubPage:
10014                         // between top/left button and slider
10015                         if (platinumScrollBar)
10016                             if (horizontal)
10017                                 ret.setRect(0, 0, sliderstart, sbextent);
10018                             else
10019                                 ret.setRect(0, 0, sbextent, sliderstart);
10020                         else if (nextScrollBar)
10021                             if (horizontal)
10022                                 ret.setRect(sbextent*2, 0, sliderstart-2*sbextent, sbextent);
10023                             else
10024                                 ret.setRect(0, sbextent*2, sbextent, sliderstart-2*sbextent);
10025                         else
10026                             if (horizontal)
10027                                 ret.setRect(noButtons ? 0 : sbextent, 0,
10028                                             noButtons ? sliderstart
10029                                                     : (sliderstart - sbextent), sbextent);
10030                             else
10031                                 ret.setRect(0, noButtons ? 0 : sbextent, sbextent,
10032                                             noButtons ? sliderstart : (sliderstart - sbextent));
10033                         break;
10034                     case SC_ScrollBarAddPage:
10035                     {
10036                         // between bottom/right button and slider
10037                         int fudge;
10038 
10039                         if (platinumScrollBar)
10040                             fudge = 0;
10041                         else if (nextScrollBar)
10042                             fudge = 2*sbextent;
10043                         else if(noButtons)
10044                             fudge = 0;
10045                         else
10046                             fudge = sbextent;
10047 
10048                         if (horizontal)
10049                             ret.setRect(sliderstart + sliderLength, 0,
10050                                         sliderMaxLength - sliderstart - sliderLength + fudge, sbextent);
10051                         else
10052                             ret.setRect(0, sliderstart + sliderLength, sbextent,
10053                                         sliderMaxLength - sliderstart - sliderLength + fudge);
10054                         break;
10055                     }
10056                     case SC_ScrollBarGroove:
10057                         if(noButtons)
10058                         {
10059                             if (horizontal)
10060                                 ret=QRect(0, 0, scrollBar->rect.width(), scrollBar->rect.height());
10061                             else
10062                                 ret=QRect(0, 0, scrollBar->rect.width(), scrollBar->rect.height());
10063                         }
10064                         else
10065                         {
10066                             int multi = threeButtonScrollBar ? 3 : 2,
10067                                 fudge;
10068 
10069                             if (platinumScrollBar)
10070                                 fudge = 0;
10071                             else if (nextScrollBar)
10072                                 fudge = 2*sbextent;
10073                             else
10074                                 fudge = sbextent;
10075 
10076                             if (horizontal)
10077                                 ret=QRect(fudge, 0, scrollBar->rect.width() - sbextent * multi, scrollBar->rect.height());
10078                             else
10079                                 ret=QRect(0, fudge, scrollBar->rect.width(), scrollBar->rect.height() - sbextent * multi);
10080                         }
10081                         break;
10082                     case SC_ScrollBarSlider:
10083                         if (horizontal)
10084                             ret=QRect(sliderstart, 0, sliderLength, sbextent);
10085                         else
10086                             ret=QRect(0, sliderstart, sbextent, sliderLength);
10087                         break;
10088                     default:
10089                         ret = BaseStyle::subControlRect(control, option, subControl, widget);
10090                         break;
10091                 }
10092                 return visualRect(scrollBar->direction/*Qt::LeftToRight*/, scrollBar->rect, ret);
10093             }
10094             break;
10095         case CC_Slider:
10096             if (auto slider = styleOptCast<QStyleOptionSlider>(option)) {
10097                 if(SLIDER_TRIANGULAR==opts.sliderStyle)
10098                 {
10099                     int   tickSize(pixelMetric(PM_SliderTickmarkOffset, option, widget)),
10100                           mod=MO_GLOW==opts.coloredMouseOver && opts.buttonEffect != EFFECT_NONE ? 2 : 0;
10101                     QRect rect(BaseStyle::subControlRect(control, option, subControl, widget));
10102 
10103                     switch (subControl)
10104                     {
10105                         case SC_SliderHandle:
10106                             if (slider->orientation == Qt::Horizontal)
10107                             {
10108                                 rect.setWidth(11+mod);
10109                                 rect.setHeight(15+mod);
10110                                 int centerY(r.center().y() - rect.height() / 2);
10111                                 if (slider->tickPosition & QSlider::TicksAbove)
10112                                     centerY += tickSize;
10113                                 if (slider->tickPosition & QSlider::TicksBelow)
10114                                     centerY -= (tickSize-1);
10115                                 rect.moveTop(centerY);
10116                             }
10117                             else
10118                             {
10119                                 rect.setWidth(15+mod);
10120                                 rect.setHeight(11+mod);
10121                                 int centerX(r.center().x() - rect.width() / 2);
10122                                 if (slider->tickPosition & QSlider::TicksAbove)
10123                                     centerX += tickSize;
10124                                 if (slider->tickPosition & QSlider::TicksBelow)
10125                                     centerX -= (tickSize-1);
10126                                 rect.moveLeft(centerX);
10127                             }
10128                             break;
10129                         case SC_SliderGroove:
10130                         {
10131                             QPoint grooveCenter(r.center());
10132 
10133                             if (Qt::Horizontal==slider->orientation)
10134                             {
10135                                 rect.setHeight(13);
10136                                 --grooveCenter.ry();
10137                                 if (slider->tickPosition & QSlider::TicksAbove)
10138                                     grooveCenter.ry() += (tickSize+2);
10139                                 if (slider->tickPosition & QSlider::TicksBelow)
10140                                     grooveCenter.ry() -= (tickSize-1);
10141                             }
10142                             else
10143                             {
10144                                 rect.setWidth(13);
10145                                 --grooveCenter.rx();
10146                                 if (slider->tickPosition & QSlider::TicksAbove)
10147                                     grooveCenter.rx() += (tickSize+2);
10148                                 if (slider->tickPosition & QSlider::TicksBelow)
10149                                     grooveCenter.rx() -= (tickSize-1);
10150                             }
10151                             rect.moveCenter(grooveCenter);
10152                             break;
10153                         }
10154                         default:
10155                             break;
10156                     }
10157                     return rect;
10158                 }
10159                 else
10160                 {
10161                     bool horizontal(Qt::Horizontal==slider->orientation);
10162                     int  thickness(pixelMetric(PM_SliderControlThickness, slider, widget)),
10163                          tickOffset(slider->tickPosition&QSlider::TicksAbove ||
10164                                     slider->tickPosition&QSlider::TicksBelow
10165                                         ? pixelMetric(PM_SliderTickmarkOffset, slider, widget)
10166                                         : ((horizontal ? r.height() : r.width()) - thickness)/2);
10167 
10168                     switch (subControl)
10169                     {
10170                         case SC_SliderHandle:
10171                         {
10172                             int len(pixelMetric(PM_SliderLength, slider, widget)),
10173                                 sliderPos(sliderPositionFromValue(slider->minimum, slider->maximum,
10174                                                                 slider->sliderPosition,
10175                                                                 (horizontal ? r.width()
10176                                                                             : r.height()) - len,
10177                                                                 slider->upsideDown));
10178 
10179                             if (horizontal)
10180                                 r.setRect(r.x() + sliderPos, r.y() + tickOffset, len, thickness);
10181                             else
10182                                 r.setRect(r.x() + tickOffset, r.y() + sliderPos, thickness, len);
10183                             break;
10184                         }
10185                         case SC_SliderGroove:
10186                             if (horizontal)
10187                                 r.setRect(r.x(), r.y() + tickOffset, r.width(), thickness);
10188                             else
10189                                 r.setRect(r.x() + tickOffset, r.y(), thickness, r.height());
10190                             break;
10191                         default:
10192                             break;
10193                     }
10194                     return visualRect(slider->direction, r, r);
10195                 }
10196             }
10197             break;
10198         case CC_GroupBox:
10199             if (oneOf(subControl, SC_GroupBoxCheckBox, SC_GroupBoxLabel))
10200                 if (auto groupBox = styleOptCast<QStyleOptionGroupBox>(option)) {
10201                     QFont font(widget ? widget->font() : QApplication::font());
10202 
10203                     font.setBold(opts.gbLabel&GB_LBL_BOLD);
10204 
10205                     QFontMetrics fontMetrics(font);
10206                     int          h(fontMetrics.height()),
10207                                  tw(fontMetrics.size(Qt::TextShowMnemonic, groupBox->text + QLatin1Char(' ')).width()),
10208                                  marg((groupBox->features & QStyleOptionFrameV2::Flat) ||
10209                                        qtcNoFrame(opts.groupBox) || opts.gbLabel&GB_LBL_OUTSIDE
10210                                             ? 0
10211                                             : opts.gbLabel&GB_LBL_INSIDE
10212                                                 ? 2
10213                                                 : 6),
10214                                  indicatorWidth(pixelMetric(PM_IndicatorWidth, option, widget)),
10215                                  indicatorSpace(pixelMetric(PM_CheckBoxLabelSpacing, option, widget) - 1);
10216                     bool         hasCheckBox(groupBox->subControls & QStyle::SC_GroupBoxCheckBox);
10217                     int          checkBoxSize(hasCheckBox ? (indicatorWidth + indicatorSpace) : 0),
10218                                  checkAdjust(qtcNoFrame(opts.groupBox) || opts.gbLabel&GB_LBL_OUTSIDE ? 0 : 2);
10219 
10220                     if(0==checkAdjust)
10221                         checkBoxSize-=2;
10222 
10223                     r.adjust(marg, 0, -marg, 0);
10224                     if(!qtcNoFrame(opts.groupBox) &&
10225                        opts.gbLabel & GB_LBL_INSIDE) {
10226                         r.adjust(0, 2, 0, 2);
10227                     }
10228                     r.setHeight(h);
10229 
10230                     // Adjusted rect for label + indicatorWidth + indicatorSpace
10231                     Qt::Alignment align(groupBox->textAlignment);
10232                     if(opts.gbLabel&GB_LBL_CENTRED)
10233                     {
10234                         align&=~(Qt::AlignLeft|Qt::AlignRight);
10235                         align|=Qt::AlignHCenter;
10236                     }
10237                     r=alignedRect(groupBox->direction, align, QSize(tw + checkBoxSize, h), r);
10238 
10239                     // Adjust totalRect if checkbox is set
10240                     if (hasCheckBox)
10241                     {
10242                         if (SC_GroupBoxCheckBox==subControl) // Adjust for check box
10243                         {
10244                             int indicatorHeight(pixelMetric(PM_IndicatorHeight, option, widget)),
10245                                 top(r.top() + (fontMetrics.height() - indicatorHeight) / 2);
10246 
10247                             r.setRect(reverse ? (r.right() - indicatorWidth) : r.left()+checkAdjust, top, indicatorWidth, indicatorHeight);
10248                         }
10249                         else // Adjust for label
10250                             r.setRect(reverse ? r.left() : (r.left() + checkBoxSize), r.top(), r.width() - checkBoxSize, r.height());
10251                     }
10252                     return r;
10253                 }
10254         break;
10255     case CC_TitleBar:
10256         if (auto tb = styleOptCast<QStyleOptionTitleBar>(option)) {
10257             bool isMinimized(tb->titleBarState&Qt::WindowMinimized),
10258                  isMaximized(tb->titleBarState&Qt::WindowMaximized);
10259 
10260             if((isMaximized && SC_TitleBarMaxButton==subControl) ||
10261                 (isMinimized && SC_TitleBarMinButton==subControl) ||
10262                 (isMinimized && SC_TitleBarShadeButton==subControl) ||
10263                 (!isMinimized && SC_TitleBarUnshadeButton==subControl))
10264                 return QRect();
10265 
10266             readMdiPositions();
10267 
10268             const int controlSize(tb->rect.height() - constWindowMargin *2);
10269             int sc = (SC_TitleBarUnshadeButton == subControl ?
10270                       SC_TitleBarShadeButton :
10271                       SC_TitleBarNormalButton == subControl ? isMaximized ?
10272                       SC_TitleBarMaxButton : SC_TitleBarMinButton :
10273                       subControl);
10274             int pos = 0;
10275             int totalLeft = 0;
10276             int totalRight = 0;
10277             bool rhs = false;
10278             bool found = false;
10279 
10280             foreach (int hint, m_mdiButtons[0]) {
10281                 if (hint == SC_TitleBarCloseButton ||
10282                     hint == WINDOWTITLE_SPACER ||
10283                     tb->titleBarFlags & toHint(hint)) {
10284                     totalLeft += (WINDOWTITLE_SPACER == hint ?
10285                                   controlSize / 2 : controlSize);
10286                     if (hint == sc) {
10287                         found = true;
10288                     } else if (!found) {
10289                         pos += (WINDOWTITLE_SPACER == hint ? controlSize / 2 :
10290                                 controlSize);
10291                     }
10292                 }
10293             }
10294             if (!found) {
10295                 pos = 0;
10296                 rhs = true;
10297             }
10298 
10299             foreach (int hint, m_mdiButtons[1]) {
10300                 if (hint == SC_TitleBarCloseButton ||
10301                     hint == WINDOWTITLE_SPACER ||
10302                     tb->titleBarFlags & toHint(hint)) {
10303                     if (hint != WINDOWTITLE_SPACER || totalRight)
10304                         totalRight += (hint == WINDOWTITLE_SPACER ?
10305                                        controlSize / 2 : controlSize);
10306                     if (rhs) {
10307                         if (hint == sc) {
10308                             pos += controlSize;
10309                             found = true;
10310                         } else if (found) {
10311                             pos += (hint == WINDOWTITLE_SPACER ?
10312                                     controlSize / 2 : controlSize);
10313                         }
10314                     }
10315                 }
10316             }
10317 
10318             totalLeft += constWindowMargin * (totalLeft ? 2 : 1);
10319             totalRight += constWindowMargin * (totalRight ? 2 : 1);
10320 
10321             if (subControl == SC_TitleBarLabel) {
10322                 r.adjust(totalLeft, 0, -totalRight, 0);
10323             } else if (!found) {
10324                 return QRect();
10325             } else if (rhs) {
10326                 r.setRect(r.right() - (pos + constWindowMargin),
10327                           r.top() + constWindowMargin,
10328                           controlSize, controlSize);
10329             } else {
10330                 r.setRect(r.left() + constWindowMargin + pos,
10331                           r.top() + constWindowMargin,
10332                           controlSize, controlSize);
10333             }
10334             if (r.height() % 2 == 0)
10335                 r.adjust(0, 0, 1, 1);
10336             return visualRect(tb->direction, tb->rect, r);
10337         }
10338     default:
10339         break;
10340     }
10341     return BaseStyle::subControlRect(control, option, subControl, widget);
10342 }
10343 
10344 QStyle::SubControl
10345 Style::hitTestComplexControl(ComplexControl control,
10346                              const QStyleOptionComplex *option,
10347                              const QPoint &pos, const QWidget *widget) const
10348 {
10349     prePolish(widget);
10350     m_sbWidget = 0L;
10351     switch (control) {
10352         case CC_ScrollBar:
10353             if (auto scrollBar = styleOptCast<QStyleOptionSlider>(option)) {
10354                 if (subControlRect(control, scrollBar, SC_ScrollBarSlider, widget).contains(pos))
10355                     return SC_ScrollBarSlider;
10356 
10357                 if (subControlRect(control, scrollBar, SC_ScrollBarAddLine, widget).contains(pos))
10358                     return SC_ScrollBarAddLine;
10359 
10360                 if (subControlRect(control, scrollBar, SC_ScrollBarSubPage, widget).contains(pos))
10361                     return SC_ScrollBarSubPage;
10362 
10363                 if (subControlRect(control, scrollBar, SC_ScrollBarAddPage, widget).contains(pos))
10364                     return SC_ScrollBarAddPage;
10365 
10366                 if (subControlRect(control, scrollBar, SC_ScrollBarSubLine, widget).contains(pos))
10367                 {
10368                     if (SCROLLBAR_KDE==opts.scrollbarType && subControlRect(control, scrollBar, SB_SUB2, widget).contains(pos))
10369                         m_sbWidget=widget;
10370                     return SC_ScrollBarSubLine;
10371                 }
10372             }
10373         default:
10374             break;
10375     }
10376 
10377     return BaseStyle::hitTestComplexControl(control, option,  pos, widget);
10378 }
10379 
10380 void Style::drawSideBarButton(QPainter *painter, const QRect &r, const QStyleOption *option, const QWidget *widget) const
10381 {
10382     const QPalette &palette(option->palette);
10383     QRect          r2(r);
10384     QStyleOption   opt(*option);
10385 
10386     if(r2.height()>r2.width() || (r2.height()<r2.width() && r2.width()<=32))
10387         opt.state&=~State_Horizontal;
10388     else
10389         opt.state|=State_Horizontal;
10390 
10391     const QColor *use(opt.state&State_On ? getSidebarButtons() : buttonColors(option));
10392     bool         horiz(opt.state&State_Horizontal);
10393 
10394     painter->save();
10395     if(opt.state&State_On || opt.state&State_MouseOver)
10396     {
10397         r2.adjust(-1, -1, 1, 1);
10398         drawLightBevel(painter, r2, &opt, widget, ROUNDED_NONE, getFill(&opt, use), use, false, WIDGET_MENU_ITEM);
10399     }
10400     else
10401         painter->fillRect(r2, palette.background().color());
10402 
10403     if(opt.state&State_MouseOver && opts.coloredMouseOver)
10404     {
10405         r2=r;
10406         if(MO_PLASTIK==opts.coloredMouseOver)
10407             if(horiz)
10408                 r2.adjust(0, 1, 0, -1);
10409             else
10410                 r2.adjust(1, 0, -1, 0);
10411         else
10412             r2.adjust(1, 1, -1, -1);
10413 
10414         if(MO_GLOW==opts.coloredMouseOver)
10415         {
10416             QColor col(m_mouseOverCols[opt.state&State_On ? 0 : 1]);
10417 
10418             col.setAlphaF(GLOW_ALPHA(false));
10419             painter->setPen(col);
10420             drawRect(painter, r);
10421             col=m_mouseOverCols[opt.state&State_On ? 4 : 3];
10422             col.setAlphaF(0.8);
10423             painter->setPen(col);
10424             drawRect(painter, r2);
10425         }
10426         else
10427         {
10428             painter->setPen(m_mouseOverCols[opt.state&State_On ? 0 : 1]);
10429 
10430             if(horiz || MO_PLASTIK!=opts.coloredMouseOver)
10431             {
10432                 painter->drawLine(r.x(), r.y(), r.x()+r.width()-1, r.y());
10433                 painter->drawLine(r2.x(), r2.y(), r2.x()+r2.width()-1, r2.y());
10434             }
10435 
10436             if(!horiz || MO_PLASTIK!=opts.coloredMouseOver)
10437             {
10438                 painter->drawLine(r.x(), r.y(), r.x(), r.y()+r.height()-1);
10439                 painter->drawLine(r2.x(), r2.y(), r2.x(), r2.y()+r2.height()-1);
10440                 if(MO_PLASTIK!=opts.coloredMouseOver)
10441                     painter->setPen(m_mouseOverCols[opt.state&State_On ? 1 : 2]);
10442             }
10443 
10444             if(horiz || MO_PLASTIK!=opts.coloredMouseOver)
10445             {
10446                 painter->drawLine(r.x(), r.y()+r.height()-1, r.x()+r.width()-1, r.y()+r.height()-1);
10447                 painter->drawLine(r2.x(), r2.y()+r2.height()-1, r2.x()+r2.width()-1, r2.y()+r2.height()-1);
10448             }
10449 
10450             if(!horiz || MO_PLASTIK!=opts.coloredMouseOver)
10451             {
10452                 painter->drawLine(r.x()+r.width()-1, r.y(), r.x()+r.width()-1, r.y()+r.height()-1);
10453                 painter->drawLine(r2.x()+r2.width()-1, r2.y(), r2.x()+r2.width()-1, r2.y()+r2.height()-1);
10454             }
10455         }
10456     }
10457 
10458     painter->restore();
10459 }
10460 
10461 void Style::drawHighlight(QPainter *p, const QRect &r, bool horiz, bool inc) const
10462 {
10463     QColor col1(m_mouseOverCols[ORIGINAL_SHADE]);
10464 
10465     col1.setAlphaF(0.5);
10466     drawFadedLine(p, r, inc ? col1 : m_mouseOverCols[ORIGINAL_SHADE], true, true, horiz);
10467     drawFadedLine(p, r.adjusted(horiz ? 0 : 1, horiz ? 1 : 0, 0, 0), inc ? m_mouseOverCols[ORIGINAL_SHADE] : col1, true, true, horiz);
10468 }
10469 
10470 void
10471 Style::drawFadedLine(QPainter *p, const QRect &r, const QColor &col,
10472                      bool fadeStart, bool fadeEnd, bool horiz,
10473                      double fadeSizeStart, double fadeSizeEnd) const
10474 {
10475     bool aa = p->testRenderHint(QPainter::Antialiasing);
10476     QPointF start(r.x() + (aa ? 0.5 : 0.0), r.y() + (aa ? 0.5 : 0.0));
10477     QPointF end(r.x() + (horiz ? r.width() - 1 : 0) + (aa ? 0.5 : 0.0),
10478                 r.y() + (horiz ? 0 : r.height() - 1) + (aa ? 0.5 : 0.0));
10479 
10480     if (opts.fadeLines && (fadeStart || fadeEnd)) {
10481         QLinearGradient grad(start, end);
10482         QColor fade(col);
10483 
10484         fade.setAlphaF(0.0);
10485         grad.setColorAt(0, fadeStart && opts.fadeLines ? fade : col);
10486         if (fadeSizeStart >= 0 && fadeSizeStart <= 1.0)
10487             grad.setColorAt(fadeSizeStart, col);
10488         if (fadeSizeEnd >= 0 && fadeSizeEnd <= 1.0)
10489             grad.setColorAt(1.0 - fadeSizeEnd, col);
10490         grad.setColorAt(1, fadeEnd && opts.fadeLines ? fade : col);
10491         p->setPen(QPen(QBrush(grad), 1));
10492     } else {
10493         p->setPen(col);
10494     }
10495     p->drawLine(start, end);
10496 }
10497 
10498 void Style::drawLines(QPainter *p, const QRect &r, bool horiz, int nLines, int offset, const QColor *cols, int startOffset,
10499                       int dark, ELine type) const
10500 {
10501     int  space((nLines*2)+(LINE_DASHES!=type ? (nLines-1) : 0)),
10502          step(LINE_DASHES!=type ? 3 : 2),
10503          etchedDisp(LINE_SUNKEN==type ? 1 : 0),
10504          x(horiz ? r.x() : r.x()+((r.width()-space)>>1)),
10505          y(horiz ? r.y()+((r.height()-space)>>1) : r.y()),
10506          x2(r.x()+r.width()-1),
10507          y2(r.y()+r.height()-1),
10508          i;
10509     QPen dp(cols[dark], 1),
10510          lp(cols[0], 1);
10511 
10512     if(opts.fadeLines && (horiz ? r.width() : r.height())>16)
10513     {
10514         QLinearGradient grad(r.topLeft(), horiz ? r.topRight() : r.bottomLeft());
10515         QColor          fade(cols[dark]);
10516 
10517         fade.setAlphaF(0.0);
10518         grad.setColorAt(0, fade);
10519         grad.setColorAt(0.4, cols[dark]);
10520         grad.setColorAt(0.6, cols[dark]);
10521         grad.setColorAt(1, fade);
10522 
10523         dp=QPen(QBrush(grad), 1);
10524 
10525         if(LINE_FLAT!=type)
10526         {
10527             fade=QColor(cols[0]);
10528 
10529             fade.setAlphaF(0.0);
10530             grad.setColorAt(0, fade);
10531             grad.setColorAt(0.4, cols[0]);
10532             grad.setColorAt(0.6, cols[0]);
10533             grad.setColorAt(1, fade);
10534             lp=QPen(QBrush(grad), 1);
10535         }
10536     }
10537 
10538     p->setRenderHint(QPainter::Antialiasing, true);
10539     if(horiz)
10540     {
10541         if(startOffset && y+startOffset>0)
10542             y+=startOffset;
10543 
10544         p->setPen(dp);
10545         for(i=0; i<space; i+=step)
10546             drawAaLine(p, x+offset, y+i, x2-offset, y+i);
10547 
10548         if(LINE_FLAT!=type)
10549         {
10550             p->setPen(lp);
10551             x+=etchedDisp;
10552             x2+=etchedDisp;
10553             for(i=1; i<space; i+=step)
10554                 drawAaLine(p, x+offset, y+i, x2-offset, y+i);
10555         }
10556     }
10557     else
10558     {
10559         if(startOffset && x+startOffset>0)
10560             x+=startOffset;
10561 
10562         p->setPen(dp);
10563         for(i=0; i<space; i+=step)
10564             drawAaLine(p, x+i, y+offset, x+i, y2-offset);
10565 
10566         if(LINE_FLAT!=type)
10567         {
10568             p->setPen(lp);
10569             y+=etchedDisp;
10570             y2+=etchedDisp;
10571             for(i=1; i<space; i+=step)
10572                 drawAaLine(p, x+i, y+offset, x+i, y2-offset);
10573         }
10574     }
10575     p->setRenderHint(QPainter::Antialiasing, false);
10576 }
10577 
10578 void Style::drawProgressBevelGradient(QPainter *p, const QRect &origRect, const QStyleOption *option, bool horiz, EAppearance bevApp,
10579                                       const QColor *cols) const
10580 {
10581     bool    vertical(!horiz),
10582             inCache(true);
10583     QRect   r(0, 0, horiz ? PROGRESS_CHUNK_WIDTH*2 : origRect.width(),
10584                     horiz ? origRect.height() : PROGRESS_CHUNK_WIDTH*2);
10585     QtcKey  key(createKey(horiz ? r.height() : r.width(), cols[ORIGINAL_SHADE], horiz, bevApp, WIDGET_PROGRESSBAR));
10586     QPixmap *pix(m_pixmapCache.object(key));
10587 
10588     if(!pix)
10589     {
10590         pix=new QPixmap(r.width(), r.height());
10591 
10592         QPainter pixPainter(pix);
10593 
10594         if(qtcIsFlat(bevApp))
10595             pixPainter.fillRect(r, cols[ORIGINAL_SHADE]);
10596         else
10597             drawBevelGradientReal(cols[ORIGINAL_SHADE], &pixPainter, r, horiz, false, bevApp, WIDGET_PROGRESSBAR);
10598 
10599         switch(opts.stripedProgress)
10600         {
10601             default:
10602             case STRIPE_NONE:
10603                 break;
10604             case STRIPE_PLAIN:
10605             {
10606                 QRect r2(horiz
10607                             ? QRect(r.x(), r.y(), PROGRESS_CHUNK_WIDTH, r.height())
10608                             : QRect(r.x(), r.y(), r.width(), PROGRESS_CHUNK_WIDTH));
10609 
10610                 if(qtcIsFlat(bevApp))
10611                     pixPainter.fillRect(r2, cols[1]);
10612                 else
10613                     drawBevelGradientReal(cols[1], &pixPainter, r2, horiz, false, bevApp, WIDGET_PROGRESSBAR);
10614                 break;
10615             }
10616             case STRIPE_DIAGONAL:
10617             {
10618                 QRegion reg;
10619                 int     size(vertical ? origRect.width() : origRect.height());
10620 
10621                 for(int offset=0; offset<(size*2); offset+=(PROGRESS_CHUNK_WIDTH*2))
10622                 {
10623                     QPolygon a;
10624 
10625                     if(vertical)
10626                         a.setPoints(4, r.x(),           r.y()+offset,
10627                                        r.x()+r.width(), (r.y()+offset)-size,
10628                                        r.x()+r.width(), (r.y()+offset+PROGRESS_CHUNK_WIDTH)-size,
10629                                        r.x(),           r.y()+offset+PROGRESS_CHUNK_WIDTH);
10630                     else
10631                         a.setPoints(4, r.x()+offset,                             r.y(),
10632                                        r.x()+offset+PROGRESS_CHUNK_WIDTH,        r.y(),
10633                                        (r.x()+offset+PROGRESS_CHUNK_WIDTH)-size, r.y()+r.height(),
10634                                        (r.x()+offset)-size,                      r.y()+r.height());
10635 
10636                     reg+=QRegion(a);
10637                 }
10638 
10639                 pixPainter.setClipRegion(reg);
10640                 if(qtcIsFlat(bevApp))
10641                     pixPainter.fillRect(r, cols[1]);
10642                 else
10643                     drawBevelGradientReal(cols[1], &pixPainter, r, horiz, false, bevApp, WIDGET_PROGRESSBAR);
10644             }
10645         }
10646 
10647         pixPainter.end();
10648         int cost(pix->width()*pix->height()*(pix->depth()/8));
10649 
10650         if(cost<m_pixmapCache.maxCost())
10651             m_pixmapCache.insert(key, pix, cost);
10652         else
10653             inCache=false;
10654     }
10655     QRect fillRect(origRect);
10656 
10657     if(opts.animatedProgress)
10658     {
10659         int animShift=vertical || option->state&STATE_REVERSE ? PROGRESS_CHUNK_WIDTH : -PROGRESS_CHUNK_WIDTH;
10660 
10661         if(vertical || option->state&STATE_REVERSE)
10662             animShift -= (m_animateStep/2) % (PROGRESS_CHUNK_WIDTH*2);
10663         else
10664             animShift += (m_animateStep/2) % (PROGRESS_CHUNK_WIDTH*2);
10665 
10666         if(horiz)
10667             fillRect.adjust(animShift-PROGRESS_CHUNK_WIDTH, 0, PROGRESS_CHUNK_WIDTH, 0);
10668         else
10669             fillRect.adjust(0, animShift-PROGRESS_CHUNK_WIDTH, 0, PROGRESS_CHUNK_WIDTH);
10670     }
10671 
10672     p->save();
10673     p->setClipRect(origRect, Qt::IntersectClip);
10674     p->drawTiledPixmap(fillRect, *pix);
10675     if(STRIPE_FADE==opts.stripedProgress && fillRect.width()>4 && fillRect.height()>4)
10676         addStripes(p, QPainterPath(), fillRect, !vertical);
10677     p->restore();
10678 
10679     if(!inCache)
10680         delete pix;
10681 }
10682 
10683 void
10684 Style::drawBevelGradient(const QColor &base, QPainter *p, const QRect &origRect,
10685                          const QPainterPath &path, bool horiz, bool sel,
10686                          EAppearance bevApp, EWidget w, bool useCache) const
10687 {
10688     if (origRect.width() < 1 || origRect.height() < 1)
10689         return;
10690 
10691     if (qtcIsFlat(bevApp)) {
10692         if (noneOf(w, WIDGET_TAB_TOP, WIDGET_TAB_BOT) ||
10693             !qtcIsCustomBgnd(opts) || opts.tabBgnd || !sel) {
10694             if (path.isEmpty())
10695                 p->fillRect(origRect, base);
10696             else
10697                 p->fillPath(path, base);
10698         }
10699     } else {
10700         bool        tab(WIDGET_TAB_TOP==w || WIDGET_TAB_BOT==w),
10701                     selected(tab ? false : sel);
10702         EAppearance app(selected
10703                             ? opts.sunkenAppearance
10704                             : WIDGET_LISTVIEW_HEADER==w && APPEARANCE_BEVELLED==bevApp
10705                                 ? APPEARANCE_LV_BEVELLED
10706                                 : APPEARANCE_BEVELLED!=bevApp || WIDGET_BUTTON(w) || WIDGET_LISTVIEW_HEADER==w ||
10707                                   WIDGET_TROUGH==w || WIDGET_NO_ETCH_BTN==w || WIDGET_MENU_BUTTON==w
10708                                     ? bevApp
10709                                     : APPEARANCE_GRADIENT);
10710 
10711         if(WIDGET_PROGRESSBAR==w || !useCache)
10712             drawBevelGradientReal(base, p, origRect, path, horiz, sel, app, w);
10713         else
10714         {
10715             QRect   r(0, 0, horiz ? PIXMAP_DIMENSION : origRect.width(),
10716                             horiz ? origRect.height() : PIXMAP_DIMENSION);
10717             QtcKey  key(createKey(horiz ? r.height() : r.width(), base, horiz, app, w));
10718             QPixmap *pix(m_pixmapCache.object(key));
10719             bool    inCache(true);
10720 
10721             if(!pix)
10722             {
10723                 pix=new QPixmap(r.width(), r.height());
10724                 pix->fill(Qt::transparent);
10725 
10726                 QPainter pixPainter(pix);
10727 
10728                 drawBevelGradientReal(base, &pixPainter, r, horiz, sel, app, w);
10729                 pixPainter.end();
10730 
10731                 int cost(pix->width()*pix->height()*(pix->depth()/8));
10732 
10733                 if(cost<m_pixmapCache.maxCost())
10734                     m_pixmapCache.insert(key, pix, cost);
10735                 else
10736                     inCache=false;
10737             }
10738 
10739             if(!path.isEmpty())
10740             {
10741                 p->save();
10742                 p->setClipPath(path, Qt::IntersectClip);
10743             }
10744 
10745             p->drawTiledPixmap(origRect, *pix);
10746             if(!path.isEmpty())
10747                 p->restore();
10748             if(!inCache)
10749                 delete pix;
10750         }
10751     }
10752 }
10753 
10754 void Style::drawBevelGradientReal(const QColor &base, QPainter *p, const QRect &r, const QPainterPath &path,
10755                                   bool horiz, bool sel, EAppearance app, EWidget w) const
10756 {
10757     bool                             topTab(WIDGET_TAB_TOP==w),
10758                                      botTab(WIDGET_TAB_BOT==w),
10759                                      dwt(qtcIsCustomBgnd(opts) && WIDGET_DOCK_WIDGET_TITLE==w),
10760                                      titleBar(opts.windowBorder&WINDOW_BORDER_BLEND_TITLEBAR &&
10761                                                     (WIDGET_MDI_WINDOW==w || WIDGET_MDI_WINDOW_TITLE==w ||
10762                                                      (opts.dwtSettings&DWT_COLOR_AS_PER_TITLEBAR &&
10763                                                                      WIDGET_DOCK_WIDGET_TITLE==w && !dwt))),
10764                                      reverse(Qt::RightToLeft==QApplication::layoutDirection());
10765     const Gradient                   *grad=qtcGetGradient(app, &opts);
10766     QLinearGradient                  g(r.topLeft(), horiz ? r.bottomLeft() : r.topRight());
10767     GradientStopCont::const_iterator it(grad->stops.begin()),
10768                                      end(grad->stops.end());
10769     int                              numStops(grad->stops.size());
10770 
10771     for(int i=0; it!=end; ++it, ++i)
10772     {
10773         QColor col;
10774 
10775         if(/*sel && */(topTab || botTab || dwt || titleBar) && i==numStops-1)
10776         {
10777             if(titleBar)
10778             {
10779                 col=m_backgroundCols[ORIGINAL_SHADE];
10780                 //if(APPEARANCE_STRIPED==opts.bgndAppearance)
10781                     col.setAlphaF(0.0);
10782             }
10783             else
10784             {
10785                 col=base;
10786                 if((sel /*&& qtcIsCustomBgnd(opts)*/ && 0==opts.tabBgnd && !reverse) || dwt)
10787                     col.setAlphaF(0.0);
10788             }
10789         }
10790         else
10791             shade(base, &col, botTab && opts.invertBotTab ? qMax(INVERT_SHADE((*it).val), 0.9) : (*it).val);
10792         if(WIDGET_TOOLTIP!=w && (*it).alpha<1.0)
10793             col.setAlphaF(col.alphaF()*(*it).alpha);
10794         g.setColorAt(botTab ? 1.0-(*it).pos : (*it).pos, col);
10795     }
10796 
10797     if(APPEARANCE_AGUA==app && !(topTab || botTab || dwt) && (horiz ? r.height() : r.width())>AGUA_MAX)
10798     {
10799         QColor col;
10800         double pos=AGUA_MAX/((horiz ? r.height() : r.width())*2.0);
10801         shade(base, &col, AGUA_MID_SHADE);
10802         g.setColorAt(pos, col);
10803         g.setColorAt(1.0-pos, col);
10804     }
10805 
10806     //p->fillRect(r, base);
10807     if(path.isEmpty())
10808         p->fillRect(r, QBrush(g));
10809     else
10810         p->fillPath(path, QBrush(g));
10811 }
10812 
10813 void Style::drawSunkenBevel(QPainter *p, const QRect &r, const QColor &col) const
10814 {
10815     double          radius=opts.titlebarButtons&TITLEBAR_BUTTON_ROUND
10816                             ? r.height()/2.0
10817                             : opts.round>ROUND_FULL
10818                                 ? 5.0
10819                                 : opts.round>ROUND_SLIGHT
10820                                     ? 3.0
10821                                     : 2.0;
10822     QPainterPath    path(buildPath(QRectF(r), WIDGET_OTHER, ROUNDED_ALL, radius));
10823     QLinearGradient g(r.topLeft(), r.bottomLeft());
10824     QColor          black(Qt::black),
10825                     white(Qt::white);
10826 
10827     black.setAlphaF(SUNKEN_BEVEL_DARK_ALPHA(col));
10828     white.setAlphaF(SUNKEN_BEVEL_LIGHT_ALPHA(col));
10829     g.setColorAt(0, black);
10830     g.setColorAt(1, white);
10831     p->save();
10832     p->setRenderHint(QPainter::Antialiasing, true);
10833     p->fillPath(path, QBrush(g));
10834     p->restore();
10835 }
10836 
10837 void Style::drawLightBevel(QPainter *p, const QRect &r, const QStyleOption *option, const QWidget *widget, int round, const QColor &fill,
10838                            const QColor *custom, bool doBorder, EWidget w) const
10839 {
10840     bool onToolbar=APPEARANCE_NONE!=opts.tbarBtnAppearance && (WIDGET_TOOLBAR_BUTTON==w || (WIDGET_BUTTON(w) && isOnToolbar(widget)));
10841 
10842     if(WIDGET_PROGRESSBAR==w || WIDGET_SB_BUTTON==w || (WIDGET_SPIN==w && !opts.unifySpin)/* || !m_usePixmapCache*/)
10843         drawLightBevelReal(p, r, option, widget, round, fill, custom, doBorder, w, true, opts.round, onToolbar);
10844     else
10845     {
10846         static const int constMaxCachePixmap = 128;
10847 
10848         int    endSize=0,
10849                middleSize=8;
10850         bool   horiz(CIRCULAR_SLIDER(w) || isHoriz(option, w, TBTN_JOINED==opts.tbarBtns)),
10851                circular((WIDGET_MDI_WINDOW_BUTTON==w && (opts.titlebarButtons&TITLEBAR_BUTTON_ROUND)) ||
10852                          WIDGET_RADIO_BUTTON==w || WIDGET_DIAL==w || CIRCULAR_SLIDER(w));
10853         double radius=0;
10854         ERound realRound=qtcGetWidgetRound(&opts, r.width(), r.height(), w);
10855 
10856         if(!circular)
10857         {
10858             switch(realRound)
10859             {
10860                 case ROUND_SLIGHT:
10861                 case ROUND_NONE:
10862                 case ROUND_FULL:
10863                     endSize=SLIDER(w) && MO_PLASTIK==opts.coloredMouseOver && option->state&State_MouseOver ? 9 : 5;
10864                     break;
10865                 case ROUND_EXTRA:
10866                     endSize=7;
10867                     break;
10868                 case ROUND_MAX:
10869                 {
10870                     radius=qtcGetRadius(&opts, r.width(), r.height(), w, RADIUS_ETCH);
10871                     endSize=SLIDER(w)
10872                                 ? qMax((opts.sliderWidth/2)+1, (int)(radius+1.5))
10873                                 : (int)(radius+2.5);
10874                     middleSize=(MIN_ROUND_MAX_WIDTH-(endSize*2))+4;
10875                     if(middleSize<4)
10876                         middleSize=4;
10877                     break;
10878                 }
10879             }
10880         }
10881 
10882         int size((2*endSize)+middleSize);
10883 
10884         if(size>constMaxCachePixmap)
10885             drawLightBevelReal(p, r, option, widget, round, fill, custom, doBorder, w, true, realRound, onToolbar);
10886         else
10887         {
10888             QString key;
10889             bool    small(circular || (horiz ? r.width() : r.height())<(2*endSize));
10890             QPixmap pix;
10891             QSize   pixSize(small ? QSize(r.width(), r.height()) : QSize(horiz ? size : r.width(), horiz ? r.height() : size));
10892             uint    state(option->state&(State_Raised|State_Sunken|State_On|State_Horizontal|State_HasFocus|State_MouseOver|
10893                           (WIDGET_MDI_WINDOW_BUTTON==w ? State_Active : State_None)));
10894 
10895             key.sprintf("qtc-%x-%x-%x-%x-%x-%x-%x-%x-%x", w, onToolbar ? 1 : 0, round, (int)realRound, pixSize.width(), pixSize.height(),
10896                         state, fill.rgba(), (int)(radius*100));
10897             if(!m_usePixmapCache || !QPixmapCache::find(key, pix))
10898             {
10899                 pix=QPixmap(pixSize);
10900                 pix.fill(Qt::transparent);
10901 
10902                 QPainter pixPainter(&pix);
10903                 ERound   oldRound=opts.round;
10904                 opts.round=realRound;
10905                 drawLightBevelReal(&pixPainter, QRect(0, 0, pix.width(), pix.height()), option, widget, round, fill, custom,
10906                                    doBorder, w, false, realRound, onToolbar);
10907                 opts.round=oldRound;
10908                 pixPainter.end();
10909 
10910                 if(m_usePixmapCache)
10911                     QPixmapCache::insert(key, pix);
10912             }
10913 
10914             if(small)
10915                 p->drawPixmap(r.topLeft(), pix);
10916             else if(horiz)
10917             {
10918                 int middle(qMin(r.width()-(2*endSize), middleSize));
10919                 if(middle>0)
10920                     p->drawTiledPixmap(r.x()+endSize, r.y(), r.width()-(2*endSize), pix.height(), pix.copy(endSize, 0, middle, pix.height()));
10921                 p->drawPixmap(r.x(), r.y(), pix.copy(0, 0, endSize, pix.height()));
10922                 p->drawPixmap(r.x()+r.width()-endSize, r.y(), pix.copy(pix.width()-endSize, 0, endSize, pix.height()));
10923             }
10924             else
10925             {
10926                 int middle(qMin(r.height()-(2*endSize), middleSize));
10927                 if(middle>0)
10928                     p->drawTiledPixmap(r.x(), r.y()+endSize, pix.width(), r.height()-(2*endSize),
10929                                        pix.copy(0, endSize, pix.width(), middle));
10930                 p->drawPixmap(r.x(), r.y(), pix.copy(0, 0, pix.width(), endSize));
10931                 p->drawPixmap(r.x(), r.y()+r.height()-endSize, pix.copy(0, pix.height()-endSize, pix.width(), endSize));
10932             }
10933 
10934             if(WIDGET_SB_SLIDER==w && opts.stripedSbar)
10935             {
10936                 QRect rx(r.adjusted(1, 1, -1, -1));
10937                 addStripes(p, buildPath(rx, WIDGET_SB_SLIDER, realRound, qtcGetRadius(&opts, rx.width()-1, rx.height()-1, WIDGET_SB_SLIDER,
10938                                                                                    RADIUS_INTERNAL)),
10939                            rx, horiz);
10940             }
10941         }
10942     }
10943 }
10944 
10945 void
10946 Style::drawLightBevelReal(QPainter *p, const QRect &rOrig,
10947                           const QStyleOption *option, const QWidget *widget,
10948                           int round, const QColor &fill, const QColor *custom,
10949                           bool doBorder, EWidget w, bool useCache,
10950                           ERound realRound, bool onToolbar) const
10951 {
10952     EAppearance app = qtcWidgetApp(onToolbar ? WIDGET_TOOLBAR_BUTTON : w,
10953                                    &opts, option->state & State_Active);
10954     QRect r(rOrig);
10955     bool bevelledButton = ((WIDGET_BUTTON(w) || WIDGET_NO_ETCH_BTN==w || WIDGET_MENU_BUTTON==w) && APPEARANCE_BEVELLED==app),
10956                  sunken(option->state &(/*State_Down | */State_On | State_Sunken)),
10957                  flatWidget((WIDGET_MDI_WINDOW_BUTTON==w &&
10958                               (opts.round==ROUND_MAX || opts.titlebarButtons&TITLEBAR_BUTTON_ROUND)) ||
10959                               (WIDGET_PROGRESSBAR==w && !opts.borderProgress)),
10960                  lightBorder(!flatWidget && DRAW_LIGHT_BORDER(sunken, w, app)),
10961                  draw3dfull(!flatWidget && !lightBorder && DRAW_3D_FULL_BORDER(sunken, app)),
10962                  draw3d(!flatWidget && (draw3dfull || (
10963                             !lightBorder && DRAW_3D_BORDER(sunken, app)))),
10964                  drawShine(DRAW_SHINE(sunken, app)),
10965                  doColouredMouseOver(doBorder && option->state&State_Enabled &&
10966                                      WIDGET_MDI_WINDOW_BUTTON!=w &&
10967                                      WIDGET_SPIN!=w && WIDGET_COMBO_BUTTON!=w && WIDGET_SB_BUTTON!=w &&
10968                                      (!SLIDER(w) || !opts.colorSliderMouseOver) &&
10969                                      !(option->state&STATE_KWIN_BUTTON) &&
10970                                      (opts.coloredTbarMo || !(option->state&STATE_TBAR_BUTTON)) &&
10971                                      opts.coloredMouseOver && option->state&State_MouseOver &&
10972                                      WIDGET_PROGRESSBAR!=w &&
10973                                      (option->state&STATE_TOGGLE_BUTTON || !sunken)),
10974                  plastikMouseOver(doColouredMouseOver && MO_PLASTIK==opts.coloredMouseOver),
10975                  colouredMouseOver(doColouredMouseOver && WIDGET_MENU_BUTTON!=w &&
10976                                        (MO_COLORED==opts.coloredMouseOver ||
10977                                         MO_COLORED_THICK==opts.coloredMouseOver ||
10978                                         (MO_GLOW==opts.coloredMouseOver &&
10979                                          !(opts.buttonEffect != EFFECT_NONE)))),
10980                  doEtch(doBorder && ETCH_WIDGET(w) &&
10981                         opts.buttonEffect != EFFECT_NONE),
10982                  glowFocus(doEtch && USE_GLOW_FOCUS(option->state&State_MouseOver) && option->state&State_HasFocus &&
10983                            option->state&State_Enabled),
10984                  horiz(CIRCULAR_SLIDER(w) || isHoriz(option, w, TBTN_JOINED==opts.tbarBtns)),
10985                  sunkenToggleMo(sunken && !(option->state&State_Sunken) && option->state&(State_MouseOver|STATE_TOGGLE_BUTTON));
10986     const QColor *cols(custom ? custom : m_backgroundCols),
10987                  *border(colouredMouseOver ? borderColors(option, cols) : cols);
10988 
10989     p->save();
10990 
10991     if (doEtch)
10992         r.adjust(1, 1, -1, -1);
10993 
10994     if (w == WIDGET_TROUGH && !opts.borderSbarGroove)
10995         doBorder=false;
10996 
10997     p->setRenderHint(QPainter::Antialiasing, true);
10998 
10999     if (r.width() > 0 && r.height() > 0) {
11000         if (w == WIDGET_PROGRESSBAR && opts.stripedProgress != STRIPE_NONE) {
11001             drawProgressBevelGradient(p, opts.borderProgress ?
11002                                       r.adjusted(1, 1, -1, -1) : r,
11003                                       option, horiz, app, custom);
11004         } else {
11005             drawBevelGradient(fill, p, WIDGET_PROGRESSBAR==w && opts.borderProgress ? r.adjusted(1, 1, -1, -1) : r,
11006                               doBorder
11007                                 ? buildPath(r, w, round, qtcGetRadius(&opts, r.width()-2, r.height()-2, w, RADIUS_INTERNAL))
11008                                 : buildPath(QRectF(r), w, round, qtcGetRadius(&opts, r.width(), r.height(), w, RADIUS_EXTERNAL)),
11009                               horiz, sunken, app, w, useCache);
11010 
11011             if(!sunken || sunkenToggleMo)
11012                 if(plastikMouseOver) // && !sunken)
11013                 {
11014                     p->save();
11015                     p->setClipPath(buildPath(r.adjusted(0, 0, 0, -1), w, round,
11016                                              qtcGetRadius(&opts, r.width()-2, r.height()-2, w, RADIUS_INTERNAL)));
11017                     if (SLIDER(w)) {
11018                         int len = sbSliderMOLen(opts, horiz ? r.width() :
11019                                                 r.height()) + 1;
11020                         int so = lightBorder ? SLIDER_MO_PLASTIK_BORDER : 1;
11021                         int eo = len + so;
11022                         int col = SLIDER_MO_SHADE;
11023 
11024                         if (horiz) {
11025                             drawBevelGradient(m_mouseOverCols[col], p, QRect(r.x()+so-1, r.y(), len, r.height()-1), horiz, sunken, app, w, useCache);
11026                             drawBevelGradient(m_mouseOverCols[col], p, QRect(r.x()+r.width()-eo+1, r.y(), len, r.height()-1), horiz, sunken, app, w, useCache);
11027                         }
11028                         else
11029                         {
11030                             drawBevelGradient(m_mouseOverCols[col], p, QRect(r.x(), r.y()+so-1, r.width()-1, len), horiz, sunken, app, w, useCache);
11031                             drawBevelGradient(m_mouseOverCols[col], p, QRect(r.x(), r.y()+r.height()-eo+1, r.width()-1, len), horiz, sunken, app, w, useCache);
11032                         }
11033                     }
11034                     else
11035                     {
11036                         bool horizontal((horiz && WIDGET_SB_BUTTON!=w)|| (!horiz && WIDGET_SB_BUTTON==w)),
11037                              thin(WIDGET_SB_BUTTON==w || WIDGET_SPIN==w || ((horiz ? r.height() : r.width())<16));
11038 
11039                         p->setPen(m_mouseOverCols[MO_PLASTIK_DARK(w)]);
11040                         if(horizontal)
11041                         {
11042                             drawAaLine(p, r.x()+1, r.y()+1, r.x()+r.width()-2, r.y()+1);
11043                             drawAaLine(p, r.x()+1, r.y()+r.height()-2, r.x()+r.width()-2, r.y()+r.height()-2);
11044                         }
11045                         else
11046                         {
11047                             drawAaLine(p, r.x()+1, r.y()+1, r.x()+1, r.y()+r.height()-2);
11048                             drawAaLine(p, r.x()+r.width()-2, r.y()+1, r.x()+r.width()-2, r.y()+r.height()-2);
11049                         }
11050                         if(!thin)
11051                         {
11052                             p->setPen(m_mouseOverCols[MO_PLASTIK_LIGHT(w)]);
11053                             if(horizontal)
11054                             {
11055                                 drawAaLine(p, r.x()+1, r.y()+2, r.x()+r.width()-2, r.y()+2);
11056                                 drawAaLine(p, r.x()+1, r.y()+r.height()-3, r.x()+r.width()-2, r.y()+r.height()-3);
11057                             }
11058                             else
11059                             {
11060                                 drawAaLine(p, r.x()+2, r.y()+1, r.x()+2, r.y()+r.height()-2);
11061                                 drawAaLine(p, r.x()+r.width()-3, r.y()+1, r.x()+r.width()-3, r.y()+r.height()-2);
11062                             }
11063                         }
11064                     }
11065                     p->restore();
11066                 }
11067         }
11068 
11069         if(drawShine)
11070         {
11071             bool   mo(option->state&State_Enabled && option->state&State_MouseOver && opts.highlightFactor);
11072             QColor white(Qt::white);
11073 
11074             if(WIDGET_MDI_WINDOW_BUTTON==w || WIDGET_RADIO_BUTTON==w || CIRCULAR_SLIDER(w))
11075             {
11076                 QRectF          ra(r.x()+0.5, r.y()+0.5, r.width(), r.height());
11077                 double          topSize=(ra.height()*0.4),
11078                                 topWidthAdjust=WIDGET_RADIO_BUTTON==w || WIDGET_SLIDER==w ? 4 : 4.75;
11079                 QRectF          topGradRect(ra.x()+topWidthAdjust, ra.y(),
11080                                             ra.width()-(topWidthAdjust*2)-1, topSize-1);
11081                 QLinearGradient topGrad(topGradRect.topLeft(), topGradRect.bottomLeft());
11082 
11083                 white.setAlphaF(mo ? (opts.highlightFactor>0 ? 0.8 : 0.7) : 0.75);
11084                 topGrad.setColorAt(0.0, white);
11085                 white.setAlphaF(/*mo ? (opts.highlightFactor>0 ? 0.3 : 0.1) : */0.2);
11086                 topGrad.setColorAt(1.0, white);
11087                 p->fillPath(buildPath(topGradRect, w, round, topSize), QBrush(topGrad));
11088             }
11089             else
11090             {
11091                 QRectF ra(r.x()+0.5, r.y()+0.5, r.width(), r.height());
11092                 double size = qtcMin((horiz ? ra.height() : ra.width()) / 2.0,
11093                                      16),
11094                        rad=size/2.0;
11095                 int    mod=4;
11096 
11097                 if(horiz)
11098                 {
11099                     if(!(ROUNDED_LEFT&round))
11100                         ra.adjust(-8, 0, 0, 0);
11101                     if(!(ROUNDED_RIGHT&round))
11102                         ra.adjust(0, 0, 8, 0);
11103                 }
11104                 else
11105                 {
11106                     if(!(ROUNDED_TOP&round))
11107                         ra.adjust(0, -8, 0, 0);
11108                     if(!(ROUNDED_BOTTOM&round))
11109                         ra.adjust(0, 0, 0, 8);
11110                 }
11111 
11112                 if (realRound < ROUND_MAX ||
11113                     (!isMaxRoundWidget(w) && !IS_SLIDER(w))) {
11114                     rad /= 2.0;
11115                     mod = mod >> 1;
11116                 }
11117 
11118                 QRectF          gr(horiz ? QRectF(ra.x()+mod, ra.y(), ra.width()-(mod*2)-1, size-1)
11119                                          : QRectF(ra.x(), ra.y()+mod, size-1, ra.height()-(mod*2)-1));
11120                 QLinearGradient g(gr.topLeft(), horiz ? gr.bottomLeft() : gr.topRight());
11121 
11122                 white.setAlphaF(mo ? (opts.highlightFactor>0 ? 0.95 : 0.85) : 0.9);
11123                 g.setColorAt(0.0, white);
11124                 white.setAlphaF(mo ? (opts.highlightFactor>0 ? 0.3 : 0.1) : 0.2);
11125                 g.setColorAt(1.0, white);
11126                 if(WIDGET_SB_BUTTON==w)
11127                 {
11128                     p->save();
11129                     p->setClipRect(r);
11130                 }
11131                 p->fillPath(buildPath(gr, w, round, rad), QBrush(g));
11132                 if(WIDGET_SB_BUTTON==w)
11133                     p->restore();
11134             }
11135         }
11136     }
11137 
11138     r.adjust(1, 1, -1, -1);
11139 
11140     if(plastikMouseOver && (!sunken  || sunkenToggleMo))
11141     {
11142         bool thin(WIDGET_SB_BUTTON==w || WIDGET_SPIN==w || ((horiz ? r.height() : r.width())<16)),
11143              horizontal(SLIDER(w) ? !horiz : (horiz && WIDGET_SB_BUTTON!=w)|| (!horiz && WIDGET_SB_BUTTON==w));
11144         int len = (SLIDER(w) ? sbSliderMOLen(opts, horiz ? r.width() :
11145                                              r.height()) : (thin ? 1 : 2));
11146 
11147         p->save();
11148         if(horizontal)
11149             p->setClipRect(r.x(), r.y()+len, r.width(), r.height()-(len*2));
11150         else
11151             p->setClipRect(r.x()+len, r.y(), r.width()-(len*2), r.height());
11152     }
11153 
11154     if(!colouredMouseOver && lightBorder)
11155     {
11156         p->setPen(cols[LIGHT_BORDER(app)]);
11157         p->drawPath(buildPath(r, w, round, qtcGetRadius(&opts, r.width(), r.height(), w, RADIUS_INTERNAL)));
11158     }
11159     else if(colouredMouseOver || (draw3d && option->state&State_Raised))
11160     {
11161         QPainterPath innerTlPath,
11162                      innerBrPath;
11163         int          dark(/*bevelledButton ? */2/* : 4*/);
11164 
11165         buildSplitPath(r, round, qtcGetRadius(&opts, r.width(), r.height(), w, RADIUS_INTERNAL),
11166                        innerTlPath, innerBrPath);
11167 
11168         p->setPen(border[colouredMouseOver ? MO_STD_LIGHT(w, sunken) : (sunken ? dark : 0)]);
11169         p->drawPath(innerTlPath);
11170         if(colouredMouseOver || bevelledButton || draw3dfull)
11171         {
11172             p->setPen(border[colouredMouseOver ? MO_STD_DARK(w) : (sunken ? 0 : dark)]);
11173             p->drawPath(innerBrPath);
11174         }
11175     }
11176     if(plastikMouseOver && (!sunken  || sunkenToggleMo))
11177         p->restore();
11178     p->setRenderHint(QPainter::Antialiasing, false);
11179 
11180     if(doEtch || glowFocus)
11181     {
11182         if(!(opts.thin&THIN_FRAMES) && (!sunken || sunkenToggleMo ||
11183                (sunken && glowFocus && widget && qobject_cast<const QAbstractButton*>(widget) &&
11184                 static_cast<const QAbstractButton*>(widget)->isCheckable())) &&
11185             ((WIDGET_OTHER!=w && WIDGET_SLIDER_TROUGH!=w && MO_GLOW==opts.coloredMouseOver && option->state&State_MouseOver) ||
11186             (WIDGET_DEF_BUTTON==w && IND_GLOW==opts.defBtnIndicator) ||
11187             glowFocus) )
11188             drawGlow(p, rOrig, WIDGET_DEF_BUTTON==w && option->state&State_MouseOver ? WIDGET_STD_BUTTON : w,
11189                      glowFocus ? m_focusCols : 0L);
11190         else
11191             drawEtch(p, rOrig, widget, w, EFFECT_SHADOW==opts.buttonEffect && WIDGET_BUTTON(w) && !sunken);
11192     }
11193 
11194     if(doBorder)
11195     {
11196         const QColor *borderCols=glowFocus || ((WIDGET_COMBO==w || WIDGET_MENU_BUTTON==w || (WIDGET_NO_ETCH_BTN==w && ROUNDED_ALL!=round)) &&
11197                                                 USE_GLOW_FOCUS(option->state&State_MouseOver) &&
11198                                                 option->state&State_HasFocus && option->state&State_Enabled)
11199                             ? m_focusCols
11200                             : (WIDGET_COMBO==w || WIDGET_COMBO_BUTTON==w) && border==m_comboBtnCols
11201                                 ? option->state&State_MouseOver && MO_GLOW==opts.coloredMouseOver && !sunken
11202                                     ? m_mouseOverCols
11203                                     : m_buttonCols
11204                                 : cols;
11205 
11206         r.adjust(-1, -1, 1, 1);
11207         if(!sunken && option->state&State_Enabled && !glowFocus &&
11208             ((((doEtch && WIDGET_OTHER!=w && WIDGET_SLIDER_TROUGH!=w) || SLIDER(w) || WIDGET_COMBO==w || WIDGET_MENU_BUTTON==w ) &&
11209                  (MO_GLOW==opts.coloredMouseOver/* || MO_COLORED==opts.colorMenubarMouseOver*/) && option->state&State_MouseOver) ||
11210                glowFocus || (doEtch && WIDGET_DEF_BUTTON==w && IND_GLOW==opts.defBtnIndicator)))
11211             drawBorder(p, r, option, round,
11212                        WIDGET_DEF_BUTTON==w && IND_GLOW==opts.defBtnIndicator && !(option->state&State_MouseOver)
11213                             ? m_defBtnCols : m_mouseOverCols, w);
11214         else
11215             drawBorder(p, r, option, round,
11216                        colouredMouseOver && MO_COLORED_THICK==opts.coloredMouseOver ? m_mouseOverCols : borderCols, w);
11217     }
11218 
11219     p->restore();
11220 }
11221 
11222 void Style::drawGlow(QPainter *p, const QRect &r, EWidget w, const QColor *cols) const
11223 {
11224     bool   def(WIDGET_DEF_BUTTON==w && IND_GLOW==opts.defBtnIndicator),
11225            defShade=def && (!m_defBtnCols ||
11226                             (m_defBtnCols[ORIGINAL_SHADE]==m_mouseOverCols[ORIGINAL_SHADE]));
11227     QColor col(cols ? cols[GLOW_MO]
11228                     : def && m_defBtnCols
11229                     ? m_defBtnCols[GLOW_DEFBTN] : m_mouseOverCols[GLOW_MO]);
11230 
11231     col.setAlphaF(GLOW_ALPHA(defShade));
11232     p->setBrush(Qt::NoBrush);
11233     p->setRenderHint(QPainter::Antialiasing, true);
11234     p->setPen(col);
11235     p->drawPath(buildPath(r, w, ROUNDED_ALL, qtcGetRadius(&opts, r.width(), r.height(), w, RADIUS_ETCH)));
11236     p->setRenderHint(QPainter::Antialiasing, false);
11237 }
11238 
11239 void Style::drawEtch(QPainter *p, const QRect &r, const QWidget *widget,  EWidget w, bool raised, int round) const
11240 {
11241     QPainterPath tl,
11242                  br;
11243     QColor       col(Qt::black);
11244 
11245     if(WIDGET_TOOLBAR_BUTTON==w && EFFECT_ETCH==opts.tbarBtnEffect)
11246         raised=false;
11247 
11248     buildSplitPath(r, round, qtcGetRadius(&opts, r.width(), r.height(), w, RADIUS_ETCH), tl, br);
11249 
11250     col.setAlphaF(USE_CUSTOM_ALPHAS(opts) ? opts.customAlphas[ALPHA_ETCH_DARK] : ETCH_TOP_ALPHA);
11251     p->setBrush(Qt::NoBrush);
11252     p->setRenderHint(QPainter::Antialiasing, true);
11253     p->setPen(col);
11254 
11255     if(!raised && WIDGET_SLIDER!=w)
11256     {
11257         p->drawPath(tl);
11258         if(WIDGET_SLIDER_TROUGH==w && opts.thinSbarGroove && widget && qobject_cast<const QScrollBar*>(widget))
11259         {
11260             QColor col(Qt::white);
11261             col.setAlphaF(USE_CUSTOM_ALPHAS(opts) ? opts.customAlphas[ALPHA_ETCH_LIGHT] : ETCH_BOTTOM_ALPHA); // 0.25);
11262             p->setPen(col);
11263         }
11264         else
11265             p->setPen(getLowerEtchCol(widget));
11266     }
11267 
11268     p->drawPath(br);
11269     p->setRenderHint(QPainter::Antialiasing, false);
11270 }
11271 
11272 void Style::drawBgndRing(QPainter &painter, int x, int y, int size, int size2, bool isWindow) const
11273 {
11274     double width=(size-size2)/2.0,
11275            width2=width/2.0;
11276     QColor col(Qt::white);
11277 
11278     col.setAlphaF(RINGS_INNER_ALPHA(isWindow ? opts.bgndImage.type : opts.menuBgndImage.type));
11279     painter.setPen(QPen(col, width));
11280     painter.drawEllipse(QRectF(x+width2, y+width2, size-width, size-width));
11281 
11282     if(IMG_BORDERED_RINGS==(isWindow ? opts.bgndImage.type : opts.menuBgndImage.type))
11283     {
11284         col.setAlphaF(RINGS_OUTER_ALPHA);
11285         painter.setPen(QPen(col, 1));
11286         painter.drawEllipse(QRectF(x, y, size, size));
11287         if(size2)
11288             painter.drawEllipse(QRectF(x+width, y+width, size2, size2));
11289     }
11290 }
11291 
11292 QPixmap Style::drawStripes(const QColor &color, int opacity) const
11293 {
11294     QPixmap pix;
11295     QString key;
11296     QColor  col(color);
11297 
11298     if(100!=opacity)
11299         col.setAlphaF(opacity/100.0);
11300 
11301     key.sprintf("qtc-stripes-%x", col.rgba());
11302     if(!m_usePixmapCache || !QPixmapCache::find(key, pix))
11303     {
11304         pix=QPixmap(QSize(64, 64));
11305 
11306         if(100!=opacity)
11307             pix.fill(Qt::transparent);
11308 
11309         QPainter pixPainter(&pix);
11310         QColor   col2(shade(col, BGND_STRIPE_SHADE));
11311 
11312         if(100!=opacity)
11313         {
11314             col2.setAlphaF(opacity/100.0);
11315             pixPainter.setPen(col);
11316             for(int i=0; i<pix.height(); i+=4)
11317                 pixPainter.drawLine(0, i, pix.width()-1, i);
11318         }
11319         else
11320             pixPainter.fillRect(pix.rect(), col);
11321         pixPainter.setPen(QColor((3*col.red()+col2.red())/4,
11322                                  (3*col.green()+col2.green())/4,
11323                                  (3*col.blue()+col2.blue())/4,
11324                                  100!=opacity ? col2.alpha() : 255));
11325 
11326         for(int i=1; i<pix.height(); i+=4)
11327         {
11328             pixPainter.drawLine(0, i, pix.width()-1, i);
11329             pixPainter.drawLine(0, i+2, pix.width()-1, i+2);
11330         }
11331         pixPainter.setPen(col2);
11332         for(int i=2; i<pix.height()-1; i+=4)
11333             pixPainter.drawLine(0, i, pix.width()-1, i);
11334 
11335         if(m_usePixmapCache)
11336             QPixmapCache::insert(key, pix);
11337     }
11338 
11339     return pix;
11340 }
11341 
11342 void
11343 Style::drawBackground(QPainter *p, const QColor &bgnd, const QRect &r,
11344                       int opacity, BackgroundType type, EAppearance app,
11345                       const QPainterPath &path) const
11346 {
11347     bool isWindow(BGND_MENU!=type);
11348 
11349     if(!qtcIsFlatBgnd(app))
11350     {
11351         static const int constPixmapWidth  = 16;
11352         static const int constPixmapHeight = 512;
11353 
11354         QColor    col(bgnd);
11355         QPixmap   pix;
11356         QSize     scaledSize;
11357         EGradType grad=isWindow ? opts.bgndGrad : opts.menuBgndGrad;
11358 
11359         if(APPEARANCE_STRIPED==app)
11360             pix=drawStripes(col, opacity);
11361         else if(APPEARANCE_FILE==app)
11362             pix=isWindow ? opts.bgndPixmap.img : opts.menuBgndPixmap.img;
11363         else
11364         {
11365             QString key;
11366 
11367             scaledSize=QSize(GT_HORIZ==grad ? constPixmapWidth : r.width(), GT_HORIZ==grad ? r.height() : constPixmapWidth);
11368 
11369             if(100!=opacity)
11370                 col.setAlphaF(opacity/100.0);
11371 
11372             key.sprintf("qtc-bgnd-%x-%d-%d", col.rgba(), grad, app);
11373             if(!m_usePixmapCache || !QPixmapCache::find(key, pix))
11374             {
11375                 pix=QPixmap(QSize(GT_HORIZ==grad ? constPixmapWidth : constPixmapHeight, GT_HORIZ==grad ? constPixmapHeight : constPixmapWidth));
11376                 pix.fill(Qt::transparent);
11377 
11378                 QPainter pixPainter(&pix);
11379 
11380                 drawBevelGradientReal(col, &pixPainter, QRect(0, 0, pix.width(), pix.height()), GT_HORIZ==grad, false, app, WIDGET_OTHER);
11381                 pixPainter.end();
11382                 if(m_usePixmapCache)
11383                     QPixmapCache::insert(key, pix);
11384             }
11385         }
11386 
11387         if (path.isEmpty()) {
11388             p->drawTiledPixmap(r, oneOf(app, APPEARANCE_STRIPED,
11389                                         APPEARANCE_FILE) ||
11390                                scaledSize == pix.size() ? pix :
11391                                pix.scaled(scaledSize, Qt::IgnoreAspectRatio));
11392         } else {
11393             p->save();
11394             p->setBrushOrigin(r.x(), r.y());
11395             p->fillPath(path, QBrush(oneOf(app, APPEARANCE_STRIPED,
11396                                            APPEARANCE_FILE) ||
11397                                      scaledSize == pix.size() ? pix :
11398                                      pix.scaled(scaledSize,
11399                                                 Qt::IgnoreAspectRatio)));
11400             p->save();
11401         }
11402 
11403         if (isWindow && noneOf(app, APPEARANCE_STRIPED, APPEARANCE_FILE) &&
11404             grad == GT_HORIZ &&
11405             qtcGetGradient(app, &opts)->border == GB_SHINE) {
11406             int size = qMin(BGND_SHINE_SIZE, qMin(r.height() * 2, r.width()));
11407             QString key;
11408             key.sprintf("qtc-radial-%x", size/BGND_SHINE_STEPS);
11409             if (!m_usePixmapCache || !QPixmapCache::find(key, pix)) {
11410                 size /= BGND_SHINE_STEPS;
11411                 size *= BGND_SHINE_STEPS;
11412                 pix = QPixmap(size, size / 2);
11413                 pix.fill(Qt::transparent);
11414                 QRadialGradient gradient(QPointF(pix.width() / 2.0, 0),
11415                                          pix.width() / 2.0,
11416                                          QPointF(pix.width() / 2.0, 0));
11417                 QColor c(Qt::white);
11418                 double alpha = qtcShineAlpha(&col);
11419 
11420                 c.setAlphaF(alpha);
11421                 gradient.setColorAt(0, c);
11422                 c.setAlphaF(alpha * 0.625);
11423                 gradient.setColorAt(0.5, c);
11424                 c.setAlphaF(alpha * 0.175);
11425                 gradient.setColorAt(0.75, c);
11426                 c.setAlphaF(0);
11427                 gradient.setColorAt(1, c);
11428                 QPainter pixPainter(&pix);
11429                 pixPainter.fillRect(QRect(0, 0, pix.width(), pix.height()),
11430                                     gradient);
11431                 pixPainter.end();
11432                 if (m_usePixmapCache) {
11433                     QPixmapCache::insert(key, pix);
11434                 }
11435             }
11436             p->drawPixmap(r.x() + (r.width() - pix.width()) / 2, r.y(), pix);
11437         }
11438     } else {
11439         QColor col(bgnd);
11440         if (opacity != 100) {
11441             col.setAlphaF(opacity / 100.0);
11442         }
11443         if (path.isEmpty()) {
11444             p->fillRect(r, col);
11445         } else {
11446             p->save();
11447             p->setBrushOrigin(r.x(), r.y());
11448             p->fillPath(path, col);
11449             p->restore();
11450         }
11451     }
11452 }
11453 
11454 void
11455 Style::drawBackgroundImage(QPainter *p, bool isWindow, const QRect &r) const
11456 {
11457     QtCImage &img = isWindow ? opts.bgndImage : opts.menuBgndImage;
11458     int imgWidth = img.type == IMG_FILE ? img.width : RINGS_WIDTH(img.type);
11459     int imgHeight = img.type == IMG_FILE ? img.height : RINGS_HEIGHT(img.type);
11460 
11461     switch (img.type) {
11462         case IMG_NONE:
11463             break;
11464         case IMG_FILE:
11465             qtcLoadBgndImage(&img);
11466             if(!img.pixmap.img.isNull())
11467             {
11468                 switch(img.pos)
11469                 {
11470                     case PP_TL:
11471                         p->drawPixmap(r.x(), r.y(), img.pixmap.img);
11472                         break;
11473                     case PP_TM:
11474                         p->drawPixmap(r.x()+((r.width()-img.pixmap.img.width())/2), r.y(), img.pixmap.img);
11475                         break;
11476                     default:
11477                     case PP_TR:
11478                         p->drawPixmap(r.right()-img.pixmap.img.width(), r.y(), img.pixmap.img);
11479                         break;
11480                     case PP_BL:
11481                         p->drawPixmap(r.x(), r.bottom()-img.pixmap.img.height(), img.pixmap.img);
11482                         break;
11483                     case PP_BM:
11484                         p->drawPixmap(r.x()+((r.width()-img.pixmap.img.width())/2), r.bottom()-img.pixmap.img.height(), img.pixmap.img);
11485                         break;
11486                     case PP_BR:
11487                         p->drawPixmap(r.right()-img.pixmap.img.width(), r.bottom()-img.pixmap.img.height(), img.pixmap.img);
11488                         break;
11489                     case PP_LM:
11490                         p->drawPixmap(r.left(), r.y()+((r.height()-img.pixmap.img.height())/2), img.pixmap.img);
11491                         break;
11492                     case PP_RM:
11493                         p->drawPixmap(r.right()-img.pixmap.img.width(), r.y()+((r.height()-img.pixmap.img.height())/2), img.pixmap.img);
11494                         break;
11495                     case PP_CENTRED:
11496                         p->drawPixmap(r.x()+((r.width()-img.pixmap.img.width())/2),
11497                                       r.y()+((r.height()-img.pixmap.img.height())/2),
11498                                       img.pixmap.img);
11499                 }
11500             }
11501             break;
11502         case IMG_PLAIN_RINGS:
11503         case IMG_BORDERED_RINGS:
11504             if(img.pixmap.img.isNull())
11505             {
11506                 img.pixmap.img=QPixmap(imgWidth, imgHeight);
11507                 img.pixmap.img.fill(Qt::transparent);
11508                 QPainter pixPainter(&img.pixmap.img);
11509 
11510                 pixPainter.setRenderHint(QPainter::Antialiasing);
11511                 drawBgndRing(pixPainter, 0, 0, 200, 140, isWindow);
11512 
11513                 drawBgndRing(pixPainter, 210, 10, 230, 214, isWindow);
11514                 drawBgndRing(pixPainter, 226, 26, 198, 182, isWindow);
11515                 drawBgndRing(pixPainter, 300, 100, 50, 0, isWindow);
11516 
11517                 drawBgndRing(pixPainter, 100, 96, 160, 144, isWindow);
11518                 drawBgndRing(pixPainter, 116, 112, 128, 112, isWindow);
11519 
11520                 drawBgndRing(pixPainter, 250, 160, 200, 140, isWindow);
11521                 drawBgndRing(pixPainter, 310, 220, 80, 0, isWindow);
11522                 pixPainter.end();
11523             }
11524             p->drawPixmap(r.right()-img.pixmap.img.width(), r.y()+1, img.pixmap.img);
11525             break;
11526         case IMG_SQUARE_RINGS:
11527             if(img.pixmap.img.isNull())
11528             {
11529                 img.pixmap.img=QPixmap(imgWidth, imgHeight);
11530                 img.pixmap.img.fill(Qt::transparent);
11531                 QPainter pixPainter(&img.pixmap.img);
11532                 QColor   col(Qt::white);
11533                 double   halfWidth=RINGS_SQUARE_LINE_WIDTH/2.0;
11534 
11535                 col.setAlphaF(RINGS_SQUARE_SMALL_ALPHA);
11536                 pixPainter.setRenderHint(QPainter::Antialiasing);
11537                 pixPainter.setPen(QPen(col, RINGS_SQUARE_LINE_WIDTH, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
11538                 pixPainter.drawPath(buildPath(QRectF(halfWidth+0.5, halfWidth+0.5,
11539                                                      RINGS_SQUARE_SMALL_SIZE, RINGS_SQUARE_SMALL_SIZE),
11540                                               WIDGET_OTHER, ROUNDED_ALL, RINGS_SQUARE_RADIUS));
11541                 pixPainter.drawPath(buildPath(QRectF(halfWidth+0.5+(imgWidth-(RINGS_SQUARE_SMALL_SIZE+RINGS_SQUARE_LINE_WIDTH)),
11542                                                      halfWidth+0.5+(imgHeight-(RINGS_SQUARE_SMALL_SIZE+RINGS_SQUARE_LINE_WIDTH)),
11543                                                      RINGS_SQUARE_SMALL_SIZE, RINGS_SQUARE_SMALL_SIZE),
11544                                               WIDGET_OTHER, ROUNDED_ALL, RINGS_SQUARE_RADIUS));
11545                 col.setAlphaF(RINGS_SQUARE_LARGE_ALPHA);
11546                 pixPainter.setPen(QPen(col, RINGS_SQUARE_LINE_WIDTH, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
11547                 pixPainter.drawPath(buildPath(QRectF(halfWidth+0.5+((imgWidth-RINGS_SQUARE_LARGE_SIZE-RINGS_SQUARE_LINE_WIDTH)/2.0),
11548                                                      halfWidth+0.5+((imgHeight-RINGS_SQUARE_LARGE_SIZE-RINGS_SQUARE_LINE_WIDTH)/2.0),
11549                                                      RINGS_SQUARE_LARGE_SIZE, RINGS_SQUARE_LARGE_SIZE),
11550                                               WIDGET_OTHER, ROUNDED_ALL, RINGS_SQUARE_RADIUS));
11551                 pixPainter.end();
11552             }
11553             p->drawPixmap(r.right()-img.pixmap.img.width(), r.y()+1, img.pixmap.img);
11554             break;
11555     }
11556 }
11557 
11558 void
11559 Style::drawBackground(QPainter *p, const QWidget *widget,
11560                       BackgroundType type) const
11561 {
11562     bool isWindow(BGND_MENU != type);
11563     bool previewMdi(isWindow && m_isPreview &&
11564                     qobject_cast<const QMdiSubWindow*>(widget));
11565     const QWidget *window = m_isPreview ? widget : widget->window();
11566     int opacity = (BGND_MENU == type ? opts.menuBgndOpacity :
11567                    BGND_DIALOG == type ? opts.dlgOpacity : opts.bgndOpacity);
11568     QRect bgndRect = widget->rect();
11569     QRect imgRect = bgndRect;
11570     QtcQWidgetProps props(widget);
11571 
11572     if (opacity != 100 && !(qobject_cast<const QMdiSubWindow*>(widget) ||
11573                             Utils::hasAlphaChannel(window))) {
11574         opacity = 100;
11575     }
11576     if (widget) {
11577         props->opacity = opacity;
11578     }
11579 
11580     p->setClipRegion(widget->rect(), Qt::IntersectClip);
11581 
11582     if (isWindow) {
11583         if (!previewMdi) {
11584             WindowBorders borders = qtcGetWindowBorderSize(false);
11585             bgndRect.adjust(-borders.sides, -borders.titleHeight,
11586                             borders.sides, borders.bottom);
11587         } else {
11588             bgndRect.adjust(0, -pixelMetric(PM_TitleBarHeight,
11589                                             0L, widget), 0, 0);
11590         }
11591         if (opts.bgndImage.type == IMG_FILE && opts.bgndImage.onBorder) {
11592             imgRect = bgndRect;
11593         }
11594     }
11595 
11596     drawBackground(p, isWindow ? window->palette().window().color() :
11597                    popupMenuCols()[ORIGINAL_SHADE], bgndRect, opacity, type,
11598                    type != BGND_MENU ? opts.bgndAppearance :
11599                    opts.menuBgndAppearance);
11600     // FIXME, workaround only, the non transparent part of the image will have
11601     // a different overall opacity.
11602     p->save();
11603     p->setCompositionMode(QPainter::CompositionMode_SourceOver);
11604     drawBackgroundImage(p, isWindow, imgRect);
11605     p->restore();
11606 }
11607 
11608 QPainterPath Style::buildPath(const QRectF &r, EWidget w, int round, double radius) const
11609 {
11610     QPainterPath path;
11611 
11612     if(WIDGET_RADIO_BUTTON==w || WIDGET_DIAL==w ||
11613        (WIDGET_MDI_WINDOW_BUTTON==w && opts.titlebarButtons&TITLEBAR_BUTTON_ROUND) ||
11614        CIRCULAR_SLIDER(w))
11615     {
11616         path.addEllipse(r);
11617         return path;
11618     }
11619 
11620     if(ROUND_NONE==opts.round || (radius<0.01))
11621         round=ROUNDED_NONE;
11622 
11623     double       diameter(radius*2);
11624 
11625     if (WIDGET_MDI_WINDOW_TITLE!=w && round&CORNER_BR)
11626         path.moveTo(r.x()+r.width(), r.y()+r.height()-radius);
11627     else
11628         path.moveTo(r.x()+r.width(), r.y()+r.height());
11629 
11630     if (round&CORNER_TR)
11631         path.arcTo(r.x()+r.width()-diameter, r.y(), diameter, diameter, 0, 90);
11632     else
11633         path.lineTo(r.x()+r.width(), r.y());
11634 
11635     if (round&CORNER_TL)
11636         path.arcTo(r.x(), r.y(), diameter, diameter, 90, 90);
11637     else
11638         path.lineTo(r.x(), r.y());
11639 
11640     if (WIDGET_MDI_WINDOW_TITLE!=w && round&CORNER_BL)
11641         path.arcTo(r.x(), r.y()+r.height()-diameter, diameter, diameter, 180, 90);
11642     else
11643         path.lineTo(r.x(), r.y()+r.height());
11644 
11645     if(WIDGET_MDI_WINDOW_TITLE!=w)
11646     {
11647         if (round&CORNER_BR)
11648             path.arcTo(r.x()+r.width()-diameter, r.y()+r.height()-diameter, diameter, diameter, 270, 90);
11649         else
11650             path.lineTo(r.x()+r.width(), r.y()+r.height());
11651     }
11652 
11653     return path;
11654 }
11655 
11656 QPainterPath Style::buildPath(const QRect &r, EWidget w, int round, double radius) const
11657 {
11658     return buildPath(QRectF(r.x()+0.5, r.y()+0.5, r.width()-1, r.height()-1), w, round, radius);
11659 }
11660 
11661 void Style::buildSplitPath(const QRect &r, int round, double radius, QPainterPath &tl, QPainterPath &br) const
11662 {
11663     double xd(r.x()+0.5),
11664            yd(r.y()+0.5),
11665            diameter(radius*2);
11666     bool   rounded=diameter>0.0;
11667     int    width(r.width()-1),
11668            height(r.height()-1);
11669 
11670     if (rounded && round&CORNER_TR)
11671     {
11672         tl.arcMoveTo(xd+width-diameter, yd, diameter, diameter, 45);
11673         tl.arcTo(xd+width-diameter, yd, diameter, diameter, 45, 45);
11674         if(width>diameter)
11675             tl.lineTo(xd+width-diameter, yd);
11676     }
11677     else
11678         tl.moveTo(xd+width, yd);
11679 
11680     if (rounded && round&CORNER_TL)
11681         tl.arcTo(xd, yd, diameter, diameter, 90, 90);
11682     else
11683         tl.lineTo(xd, yd);
11684 
11685     if (rounded && round&CORNER_BL)
11686     {
11687         tl.arcTo(xd, yd+height-diameter, diameter, diameter, 180, 45);
11688         br.arcMoveTo(xd, yd+height-diameter, diameter, diameter, 180+45);
11689         br.arcTo(xd, yd+height-diameter, diameter, diameter, 180+45, 45);
11690     }
11691     else
11692     {
11693         tl.lineTo(xd, yd+height);
11694         br.moveTo(xd, yd+height);
11695     }
11696 
11697     if (rounded && round&CORNER_BR)
11698         br.arcTo(xd+width-diameter, yd+height-diameter, diameter, diameter, 270, 90);
11699     else
11700         br.lineTo(xd+width, yd+height);
11701 
11702     if (rounded && round&CORNER_TR)
11703         br.arcTo(xd+width-diameter, yd, diameter, diameter, 0, 45);
11704     else
11705         br.lineTo(xd+width, yd);
11706 }
11707 
11708 void Style::drawBorder(QPainter *p, const QRect &r, const QStyleOption *option, int round, const QColor *custom, EWidget w,
11709                        EBorder borderProfile, bool doBlend, int borderVal) const
11710 {
11711     if(ROUND_NONE==opts.round)
11712         round=ROUNDED_NONE;
11713 
11714     State        state(option->state);
11715     bool         enabled(state&State_Enabled),
11716                  entry(WIDGET_ENTRY==w || (WIDGET_SCROLLVIEW==w && opts.highlightScrollViews)),
11717                  hasFocus(enabled && entry && state&State_HasFocus),
11718                  hasMouseOver(enabled && entry && state & State_MouseOver &&
11719                               opts.unifyCombo && opts.unifySpin);
11720     const QColor *cols(enabled && hasMouseOver && opts.coloredMouseOver &&
11721                        entry ? m_mouseOverCols : enabled &&
11722                        // && m_focusCols // (always true)
11723                        hasFocus && entry ?
11724                        m_focusCols : custom ? custom :
11725                        APP_KRUNNER==theThemedApp ? m_backgroundCols : backgroundColors(option));
11726     QColor       border(WIDGET_DEF_BUTTON==w && IND_FONT_COLOR==opts.defBtnIndicator && enabled
11727                           ? option->palette.buttonText().color()
11728                           : cols[WIDGET_PROGRESSBAR==w
11729                                     ? PBAR_BORDER
11730                                     : !enabled && (WIDGET_BUTTON(w) || WIDGET_SLIDER_TROUGH==w)
11731                                         ? QTC_STD_BORDER
11732                                             : m_mouseOverCols==cols && IS_SLIDER(w)
11733                                                 ? SLIDER_MO_BORDER_VAL
11734                                                 : borderVal]);
11735 
11736     p->setRenderHint(QPainter::Antialiasing, true);
11737     p->setBrush(Qt::NoBrush);
11738 
11739     if(WIDGET_TAB_BOT==w || WIDGET_TAB_TOP==w)
11740         cols=m_backgroundCols;
11741 
11742     if(!(opts.thin&THIN_FRAMES) && (WIDGET_SCROLLVIEW!=w || !(opts.square&SQUARE_SCROLLVIEW) || opts.highlightScrollViews))
11743         switch(borderProfile)
11744         {
11745             case BORDER_FLAT:
11746                 break;
11747             case BORDER_RAISED:
11748             case BORDER_SUNKEN:
11749             case BORDER_LIGHT:
11750             {
11751                 int          dark=FRAME_DARK_SHADOW;
11752                 QColor       tl(cols[BORDER_RAISED==borderProfile || BORDER_LIGHT==borderProfile ? 0 : dark]),
11753                              br(cols[BORDER_RAISED==borderProfile ? dark : 0]);
11754                 QPainterPath topPath,
11755                              botPath;
11756 
11757                 if(((hasMouseOver || hasFocus) && WIDGET_ENTRY==w) ||
11758                     (hasFocus && WIDGET_SCROLLVIEW==w))
11759                 {
11760                     tl.setAlphaF(ENTRY_INNER_ALPHA);
11761                     br.setAlphaF(ENTRY_INNER_ALPHA);
11762                 }
11763                 else if(doBlend)
11764                 {
11765                     tl.setAlphaF(BORDER_BLEND_ALPHA(w));
11766                     br.setAlphaF(BORDER_SUNKEN==borderProfile ? 0.0 : BORDER_BLEND_ALPHA(w));
11767                 }
11768 
11769                 QRect inner(r.adjusted(1, 1, -1, -1));
11770 
11771                 buildSplitPath(inner, round, qtcGetRadius(&opts, inner.width(), inner.height(), w, RADIUS_INTERNAL), topPath, botPath);
11772 
11773                 p->setPen((enabled || BORDER_SUNKEN==borderProfile) /*&&
11774                             (BORDER_RAISED==borderProfile || BORDER_LIGHT==borderProfile || hasFocus || APPEARANCE_FLAT!=app)*/
11775                                 ? tl
11776                                 : option->palette.background().color());
11777                 p->drawPath(topPath);
11778                 if(WIDGET_SCROLLVIEW==w || // Because of list view headers, need to draw dark line on right!
11779                     (! ((WIDGET_ENTRY==w && !hasFocus && !hasMouseOver) ||
11780                         (WIDGET_ENTRY!=w && doBlend && BORDER_SUNKEN==borderProfile) ) ) )
11781                 {
11782                     if(!hasFocus && !hasMouseOver && BORDER_LIGHT!=borderProfile && WIDGET_SCROLLVIEW!=w)
11783                         p->setPen(/*WIDGET_SCROLLVIEW==w && !hasFocus
11784                                     ? checkColour(option, QPalette::Window)
11785                                     : WIDGET_ENTRY==w && !hasFocus
11786                                         ? checkColour(option, QPalette::Base)
11787                                         : */enabled && (BORDER_SUNKEN==borderProfile || hasFocus || /*APPEARANCE_FLAT!=app ||*/
11788                                             WIDGET_TAB_TOP==w || WIDGET_TAB_BOT==w)
11789                                             ? br
11790                                             : checkColour(option, QPalette::Window));
11791                     p->drawPath(botPath);
11792                 }
11793             }
11794         }
11795 
11796     if(BORDER_SUNKEN==borderProfile &&
11797        (WIDGET_FRAME==w || ((WIDGET_ENTRY==w || WIDGET_SCROLLVIEW==w) && !opts.etchEntry && !hasFocus && !hasMouseOver)))
11798     {
11799         QPainterPath topPath,
11800                      botPath;
11801         QColor       col(border);
11802 
11803         col.setAlphaF(LOWER_BORDER_ALPHA);
11804         buildSplitPath(r, round, qtcGetRadius(&opts, r.width(), r.height(), w, RADIUS_EXTERNAL), topPath, botPath);
11805         p->setPen(/*enabled ? */border/* : col*/);
11806         p->drawPath(topPath);
11807 //         if(enabled)
11808             p->setPen(col);
11809         p->drawPath(botPath);
11810     }
11811     else
11812     {
11813         p->setPen(border);
11814         p->drawPath(buildPath(r, w, round, qtcGetRadius(&opts, r.width(), r.height(), w, RADIUS_EXTERNAL)));
11815     }
11816 
11817     p->setRenderHint(QPainter::Antialiasing, false);
11818 }
11819 
11820 void Style::drawMdiControl(QPainter *p, const QStyleOptionTitleBar *titleBar, SubControl sc, const QWidget *widget,
11821                            ETitleBarButtons btn, const QColor &iconColor, const QColor *btnCols, const QColor *bgndCols,
11822                            int adjust, bool activeWindow) const
11823 {
11824     bool hover((titleBar->activeSubControls&sc) && (titleBar->state&State_MouseOver));
11825 
11826     if(!activeWindow && !hover && opts.titlebarButtons&TITLEBAR_BUTTOM_HIDE_ON_INACTIVE_WINDOW)
11827         return;
11828 
11829     QRect rect(subControlRect(CC_TitleBar, titleBar, sc, widget));
11830 
11831     if (rect.isValid())
11832     {
11833         rect.adjust(adjust, adjust, -adjust, -adjust);
11834 
11835         bool sunken((titleBar->activeSubControls&sc) && (titleBar->state&State_Sunken)),
11836              colored(coloredMdiButtons(titleBar->state&State_Active, hover)),
11837              useBtnCols(opts.titlebarButtons&TITLEBAR_BUTTON_STD_COLOR &&
11838                          (hover ||
11839                           !(opts.titlebarButtons&TITLEBAR_BUTTON_COLOR_MOUSE_OVER) ||
11840                           opts.titlebarButtons&TITLEBAR_BUTTON_COLOR));
11841         const QColor *buttonColors=colored && !(opts.titlebarButtons&TITLEBAR_BUTTON_COLOR_SYMBOL)
11842                                     ? m_titleBarButtonsCols[btn] : (useBtnCols ? btnCols : bgndCols);
11843         const QColor &icnColor=opts.titlebarButtons&TITLEBAR_BUTTON_ICON_COLOR
11844                                 ? opts.titlebarButtonColors[btn+(NUM_TITLEBAR_BUTTONS*(titleBar->state&State_Active ? 1 : 2))]
11845                                 : colored && opts.titlebarButtons&TITLEBAR_BUTTON_COLOR_SYMBOL
11846                                     ? m_titleBarButtonsCols[btn][ORIGINAL_SHADE]
11847                                     : SC_TitleBarCloseButton==sc && hover && !sunken && !(opts.titlebarButtons&TITLEBAR_BUTTON_COLOR)
11848                                         ? CLOSE_COLOR
11849                                         : SC_TitleBarCloseButton!=sc && hover && !sunken &&
11850                                           !(opts.titlebarButtons&TITLEBAR_BUTTON_COLOR) &&
11851                                           opts.titlebarButtons&TITLEBAR_BUTTON_USE_HOVER_COLOR
11852                                             ? m_mouseOverCols[ORIGINAL_SHADE]
11853                                             : iconColor;
11854 
11855         bool drewFrame=drawMdiButton(p, rect, hover, sunken, buttonColors);
11856         drawMdiIcon(p, icnColor, (drewFrame ? buttonColors : bgndCols)[ORIGINAL_SHADE],
11857                     rect, hover, sunken, subControlToIcon(sc), true, drewFrame);
11858     }
11859 }
11860 
11861 void Style::drawDwtControl(QPainter *p, const QFlags<State> &state, const QRect &rect, ETitleBarButtons btn, Icon icon,
11862                            const QColor &iconColor, const QColor *btnCols, const QColor *bgndCols) const
11863 {
11864     bool    sunken(state&State_Sunken),
11865             hover(state&State_MouseOver),
11866             colored(coloredMdiButtons(state&State_Active, hover)),
11867             useBtnCols(opts.titlebarButtons&TITLEBAR_BUTTON_STD_COLOR &&
11868                         (hover ||
11869                         !(opts.titlebarButtons&TITLEBAR_BUTTON_COLOR_MOUSE_OVER) ||
11870                         opts.titlebarButtons&TITLEBAR_BUTTON_COLOR));
11871     const QColor *buttonColors=colored && !(opts.titlebarButtons&TITLEBAR_BUTTON_COLOR_SYMBOL)
11872                                 ? m_titleBarButtonsCols[btn] : (useBtnCols ? btnCols : bgndCols);
11873     const QColor &icnColor=opts.dwtSettings&DWT_ICON_COLOR_AS_PER_TITLEBAR && opts.titlebarButtons&TITLEBAR_BUTTON_ICON_COLOR
11874                             ? opts.titlebarButtonColors[btn+(NUM_TITLEBAR_BUTTONS/**(titleBar->state&State_Active ? 1 : 2)*/)]
11875                             : colored && opts.titlebarButtons&TITLEBAR_BUTTON_COLOR_SYMBOL
11876                                 ? m_titleBarButtonsCols[btn][ORIGINAL_SHADE]
11877                                 : (TITLEBAR_CLOSE==btn && !(opts.titlebarButtons&TITLEBAR_BUTTON_COLOR) && (hover || sunken)
11878                                     ? CLOSE_COLOR
11879                                     : iconColor);
11880 
11881     bool drewFrame=drawMdiButton(p, rect, hover, sunken, buttonColors);
11882     drawMdiIcon(p, icnColor, (drewFrame ? buttonColors : bgndCols)[ORIGINAL_SHADE], rect, hover, sunken, icon, false, drewFrame);
11883 }
11884 
11885 bool Style::drawMdiButton(QPainter *painter, const QRect &r, bool hover, bool sunken, const QColor *cols) const
11886 {
11887     if(!(opts.titlebarButtons&TITLEBAR_BUTTON_NO_FRAME) &&
11888        (hover || sunken || !(opts.titlebarButtons&TITLEBAR_BUTTON_HOVER_FRAME)))
11889     {
11890         QStyleOption opt;
11891 
11892         opt.rect=r; // .adjusted(1, 1, -1, -1);
11893         if(opts.titlebarButtons&TITLEBAR_BUTTON_ROUND)
11894             opt.rect.adjust(1, 1, -1, -1);
11895         opt.state=State_Enabled|State_Horizontal|State_Raised;
11896         if(hover)
11897             opt.state|=State_MouseOver;
11898         if(sunken)
11899             opt.state|=State_Sunken;
11900 
11901         drawLightBevel(painter, opt.rect, &opt, 0L, ROUNDED_ALL, getFill(&opt, cols), cols, true, WIDGET_MDI_WINDOW_BUTTON);
11902         return true;
11903     }
11904 
11905     return false;
11906 }
11907 
11908 void Style::drawMdiIcon(QPainter *painter, const QColor &color, const QColor &bgnd,  const QRect &r, bool hover, bool sunken, Icon icon,
11909                         bool stdSize, bool drewFrame) const
11910 {
11911     if(!(opts.titlebarButtons&TITLEBAR_BUTTON_HOVER_SYMBOL_FULL) || hover || sunken)
11912     {
11913         bool faded=!sunken && !hover && opts.titlebarButtons&TITLEBAR_BUTTON_HOVER_SYMBOL;
11914 
11915         if(!sunken && !faded && EFFECT_NONE!=opts.titlebarEffect)
11916     //         // && hover && !(opts.titlebarButtons&TITLEBAR_BUTTON_HOVER_SYMBOL) && !customCol)
11917         {
11918             EEffect effect=opts.titlebarEffect;
11919 
11920             if(EFFECT_ETCH==opts.titlebarEffect && drewFrame)
11921                 effect=EFFECT_SHADOW;
11922 
11923             drawIcon(painter, blendColors(WINDOW_SHADOW_COLOR(effect), bgnd, WINDOW_TEXT_SHADOW_ALPHA(effect)),
11924                      EFFECT_SHADOW==effect
11925                         ? r.adjusted(1, 1, 1, 1)
11926                         : r.adjusted(0, 1, 0, 1),
11927                      sunken, icon, stdSize);
11928         }
11929 
11930         QColor col(color);
11931 
11932         if(faded)
11933             col=blendColors(col, bgnd, HOVER_BUTTON_ALPHA(col));
11934 
11935         drawIcon(painter, col, r, sunken, icon, stdSize);
11936     }
11937 }
11938 
11939 void Style::drawIcon(QPainter *painter, const QColor &color, const QRect &r, bool sunken, Icon icon, bool stdSize) const
11940 {
11941     static const int constIconSize=9;
11942     static const int constSmallIconSize=7;
11943 
11944     painter->setPen(color);
11945 
11946     QSize    iconSize(stdSize
11947                         ? constIconSize
11948                         : constSmallIconSize,
11949                       stdSize
11950                         ? constIconSize
11951                         : (ICN_RESTORE==icon && !(opts.titlebarButtons&TITLEBAR_BUTTOM_ARROW_MIN_MAX)
11952                             ? constSmallIconSize+1
11953                             : constSmallIconSize));
11954     QRect    br(r.x()+((r.width()-iconSize.width())>>1),
11955                 r.y()+((r.height()-iconSize.height())>>1),
11956                 iconSize.width(), iconSize.height());
11957     if(sunken)
11958         br.adjust(1, 1, 1, 1);
11959 
11960     switch(icon)
11961     {
11962         case ICN_MIN:
11963             if(opts.titlebarButtons&TITLEBAR_BUTTOM_ARROW_MIN_MAX)
11964                 drawArrow(painter, opts.vArrows ? br.adjusted(0, 1, 0, 1) : br, PE_IndicatorArrowDown, color, false);
11965             else
11966                 drawRect(painter, QRect(br.left(), br.bottom()-1, br.width(), 2));
11967             break;
11968         case ICN_MAX:
11969             if(opts.titlebarButtons&TITLEBAR_BUTTOM_ARROW_MIN_MAX)
11970                 drawArrow(painter, opts.vArrows ? br.adjusted(0, -1, 0, -1) : br, PE_IndicatorArrowUp, color, false);
11971             else
11972             {
11973                 drawRect(painter, br);
11974                 painter->drawLine(br.left() + 1, br.top() + 1,  br.right() - 1, br.top() + 1);
11975             }
11976             break;
11977         case ICN_CLOSE:
11978             if(stdSize && opts.titlebarButtons&TITLEBAR_BUTTON_SUNKEN_BACKGROUND)
11979                 br.adjust(1, 1, -1, -1);
11980             painter->save();
11981             painter->setClipRect(br);
11982             painter->setPen(QPen(color, 2));
11983             painter->drawLine(br.left(), br.top(), br.right(), br.bottom());
11984             painter->drawLine(br.right(), br.top(), br.left(), br.bottom());
11985             painter->restore();
11986             break;
11987         case ICN_RESTORE:
11988             if(opts.titlebarButtons&TITLEBAR_BUTTOM_ARROW_MIN_MAX)
11989             {
11990                 painter->drawLine(br.x()+1, br.y(), br.x()+br.width()-2, br.y());
11991                 painter->drawLine(br.x()+1, br.y()+br.height()-1, br.x()+br.width()-2, br.y()+br.height()-1);
11992                 painter->drawLine(br.x(), br.y()+1, br.x(), br.y()+br.height()-2);
11993                 painter->drawLine(br.x()+br.width()-1, br.y()+1, br.x()+br.width()-1, br.y()+br.height()-2);
11994                 drawRect(painter, br.adjusted(1, 1, -1, -1));
11995             }
11996             else
11997             {
11998                 drawRect(painter, QRect(br.x(), br.y()+3, br.width()-2, br.height()-3));
11999                 painter->drawLine(br.x()+1, br.y()+4, br.x()+br.width()-4, br.y()+4);
12000                 painter->drawLine(br.x()+2, br.y(), br.x()+br.width()-1, br.y());
12001                 painter->drawLine(br.x()+2, br.y()+1, br.x()+br.width()-1, br.y()+1);
12002                 painter->drawLine(br.x()+br.width()-1, br.y()+2, br.x()+br.width()-1, br.y()+(stdSize ? 5 : 4));
12003                 painter->drawPoint(br.x()+br.width()-2, br.y()+(stdSize ? 5 : 4));
12004                 painter->drawPoint(br.x()+2, br.y()+2);
12005             }
12006             break;
12007         case ICN_UP:
12008             drawArrow(painter, br, PE_IndicatorArrowUp, color, false);
12009             break;
12010         case ICN_DOWN:
12011             drawArrow(painter, opts.vArrows ? br.adjusted(0, 1, 0, 1) : br, PE_IndicatorArrowDown, color, false);
12012             break;
12013         case ICN_RIGHT:
12014             drawArrow(painter, br, PE_IndicatorArrowRight, color, false);
12015             break;
12016         case ICN_MENU:
12017             for(int i=1; i<=constIconSize; i+=3)
12018                 painter->drawLine(br.left() + 1, br.top() + i,  br.right() - 1, br.top() + i);
12019             break;
12020         case ICN_SHADE:
12021         case ICN_UNSHADE:
12022         {
12023             bool isDwt=opts.dwtSettings&DWT_BUTTONS_AS_PER_TITLEBAR;
12024             br.adjust(0, -2, 0, 0);
12025             drawRect(painter, isDwt ? QRect(br.left(), br.bottom(), br.width(), 2) : QRect(br.left()+1, br.bottom()-1, br.width()-2, 2));
12026             br.adjust(0, ICN_SHADE==icon ? -3 : -5, 0, 0);
12027             drawArrow(painter, opts.vArrows ? br.adjusted(0, 1, 0, 1) : br,
12028                       ICN_SHADE==icon ? PE_IndicatorArrowDown : PE_IndicatorArrowUp, color, false);
12029             break;
12030         }
12031         default:
12032             break;
12033     }
12034 }
12035 
12036 void Style::drawEntryField(QPainter *p, const QRect &rx,  const QWidget *widget, const QStyleOption *option,
12037                            int round, bool fill, bool doEtch, EWidget w) const
12038 {
12039     QRect r(rx);
12040 
12041     if(doEtch && opts.etchEntry)
12042         r.adjust(1, 1, -1, -1);
12043 
12044     p->setRenderHint(QPainter::Antialiasing, true);
12045     if(fill)
12046         p->fillPath(buildPath(QRectF(r).adjusted(1, 1, -1, -1), WIDGET_SCROLLVIEW==w ? w : WIDGET_ENTRY, round,
12047                               qtcGetRadius(&opts, r.width()-2, r.height()-2, WIDGET_SCROLLVIEW==w ? w : WIDGET_ENTRY, RADIUS_INTERNAL)),
12048                     option->palette.brush(QPalette::Base));
12049     else
12050     {
12051         p->setPen(WIDGET_SCROLLVIEW!=w || !(opts.square&SQUARE_SCROLLVIEW) || opts.highlightScrollViews ? checkColour(option, QPalette::Base)
12052                                                                                                         : backgroundColors(option)[ORIGINAL_SHADE]);
12053         p->drawPath(buildPath(r.adjusted(1, 1, -1, -1), WIDGET_SCROLLVIEW==w ? w : WIDGET_ENTRY, round,
12054                               qtcGetRadius(&opts, r.width()-2, r.height()-2, WIDGET_SCROLLVIEW==w ? w : WIDGET_ENTRY, RADIUS_INTERNAL)));
12055     }
12056     p->setRenderHint(QPainter::Antialiasing, false);
12057 
12058     if(doEtch && opts.etchEntry)
12059         drawEtch(p, rx, widget, WIDGET_SCROLLVIEW==w ? w : WIDGET_ENTRY, false);
12060 
12061     drawBorder(p, r, option, round, 0L, w, BORDER_SUNKEN);
12062 }
12063 
12064 void Style::drawMenuItem(QPainter *p, const QRect &r, const QStyleOption *option, MenuItemType type, int round, const QColor *cols) const
12065 {
12066     int fill=opts.useHighlightForMenu && ((MENU_BAR!=type) || m_highlightCols==cols || APP_OPENOFFICE==theThemedApp) ? ORIGINAL_SHADE : 4,
12067         border=opts.borderMenuitems ? 0 : fill;
12068 
12069     if(m_highlightCols!=cols && MENU_BAR==type && !(option->state&(State_On|State_Sunken)) &&
12070        !opts.colorMenubarMouseOver && (opts.borderMenuitems || !qtcIsFlat(opts.menuitemAppearance)))
12071         fill=ORIGINAL_SHADE;
12072 
12073     if(MENU_BAR!=type && APPEARANCE_FADE==opts.menuitemAppearance)
12074     {
12075         bool reverse = Qt::RightToLeft==option->direction;
12076         QColor trans(Qt::white);
12077         QRect r2(opts.round != ROUND_NONE ? r.adjusted(1, 1, -1, -1) : r);
12078         QRectF rf(r2);
12079         double fadePercent=((double)MENUITEM_FADE_SIZE)/rf.width();
12080         QLinearGradient grad(r2.topLeft(), r2.topRight());
12081 
12082         trans.setAlphaF(0.0);
12083         grad.setColorAt(0, reverse ? trans : cols[fill]);
12084         grad.setColorAt(reverse ? fadePercent : 1.0-fadePercent, cols[fill]);
12085         grad.setColorAt(1, reverse ? cols[fill] : trans);
12086         if (opts.round != ROUND_NONE) {
12087             p->save();
12088             p->setRenderHint(QPainter::Antialiasing, true);
12089             p->fillPath(buildPath(rf, WIDGET_OTHER,
12090                                   reverse ? ROUNDED_RIGHT : ROUNDED_LEFT, 4),
12091                         QBrush(grad));
12092             p->restore();
12093         }
12094         else
12095             p->fillRect(r2, QBrush(grad));
12096     }
12097     else if(MENU_BAR==type || opts.borderMenuitems)
12098     {
12099         bool stdColor(MENU_BAR!=type || (SHADE_BLEND_SELECTED!=opts.shadeMenubars && SHADE_SELECTED!=opts.shadeMenubars));
12100 
12101         QStyleOption opt(*option);
12102 
12103         opt.state|=State_Horizontal|State_Raised;
12104         opt.state&=~(State_Sunken|State_On);
12105 
12106         if(stdColor && opts.borderMenuitems)
12107             drawLightBevel(p, r, &opt, 0L, round, cols[fill], cols, stdColor, WIDGET_MENU_ITEM);
12108         else
12109         {
12110             QRect fr(r);
12111 
12112             fr.adjust(1, 1, -1, -1);
12113 
12114             if(fr.width()>0 && fr.height()>0)
12115                 drawBevelGradient(cols[fill], p, fr, true, false, opts.menuitemAppearance, WIDGET_MENU_ITEM);
12116             drawBorder(p, r, &opt, round, cols, WIDGET_MENU_ITEM, BORDER_FLAT, false, border);
12117         }
12118     }
12119     else
12120     {
12121         // For now dont round combos - getting weird effects with shadow/clipping in Gtk2 style :-(
12122         if(/*MENU_COMBO==type || */POPUP_MENUS_SQUARE(opts))
12123             drawBevelGradient(cols[fill], p, r, true, false, opts.menuitemAppearance, WIDGET_MENU_ITEM);
12124         else
12125         {
12126             p->save();
12127             p->setRenderHint(QPainter::Antialiasing, true);
12128             drawBevelGradient(
12129                 cols[fill], p, r,
12130                 buildPath(QRectF(r), WIDGET_OTHER, ROUNDED_ALL,
12131                           (opts.round >= ROUND_FULL ? 5.0 : 2.5) -
12132                           (opts.round > ROUND_SLIGHT ? 1.0 : 0.5)), true, false,
12133                 opts.menuitemAppearance, WIDGET_MENU_ITEM, false);
12134             p->restore();
12135         }
12136     }
12137 }
12138 
12139 void Style::drawProgress(QPainter *p, const QRect &r, const QStyleOption *option, bool vertical, bool reverse) const
12140 {
12141     QStyleOption opt(*option);
12142     QRect        rx(r);
12143 
12144     opt.state|=State_Raised;
12145 
12146     if(vertical)
12147         opt.state&=~State_Horizontal;
12148     else
12149         opt.state|=State_Horizontal;
12150 
12151     if(reverse)
12152         opt.state|=STATE_REVERSE;
12153     else
12154         opt.state&=~STATE_REVERSE;
12155 
12156     if((vertical ? r.height() : r.width())<1)
12157         return;
12158 
12159     if(vertical && r.height()<3)
12160         rx.setHeight(3);
12161 
12162     if(!vertical && rx.width()<3)
12163         rx.setWidth(3);
12164 
12165     // KTorrent's progressbars seem to have state==State_None
12166     const QColor *use=option->state&State_Enabled || State_None==option->state || ECOLOR_BACKGROUND==opts.progressGrooveColor
12167                     ? m_progressCols
12168                         ? m_progressCols
12169                         : highlightColors(option, true)
12170                     : m_backgroundCols;
12171 
12172     drawLightBevel(p, rx, &opt, 0L, ROUNDED_ALL, use[ORIGINAL_SHADE], use, opts.borderProgress, WIDGET_PROGRESSBAR);
12173 
12174     if(opts.glowProgress && (vertical ? rx.height() : rx.width())>3)
12175     {
12176         QRect           ri(opts.borderProgress ? rx.adjusted(1, 1, -1, -1) : rx);
12177         QLinearGradient grad(0, 0, vertical ? 0 : 1, vertical ? 1 : 0);
12178         QColor          glow(Qt::white),
12179                         blank(Qt::white);
12180 
12181         blank.setAlphaF(0);
12182         glow.setAlphaF(GLOW_PROG_ALPHA);
12183         grad.setCoordinateMode(QGradient::ObjectBoundingMode);
12184         grad.setColorAt(0, (reverse ? GLOW_END : GLOW_START)==opts.glowProgress ? glow : blank);
12185         if(GLOW_MIDDLE==opts.glowProgress)
12186             grad.setColorAt(0.5, glow);
12187         grad.setColorAt(1, (reverse ? GLOW_START : GLOW_END)==opts.glowProgress ? glow : blank);
12188         p->fillRect(ri, grad);
12189     }
12190 
12191     if(!opts.borderProgress)
12192     {
12193         p->setPen(use[PBAR_BORDER]);
12194         if(!vertical)
12195         {
12196             p->drawLine(rx.topLeft(), rx.topRight());
12197             p->drawLine(rx.bottomLeft(), rx.bottomRight());
12198         }
12199         else
12200         {
12201             p->drawLine(rx.topLeft(), rx.bottomLeft());
12202             p->drawLine(rx.topRight(), rx.bottomRight());
12203         }
12204     }
12205 }
12206 
12207 static QPolygon rotate(const QPolygon &p, double angle)
12208 {
12209     QMatrix matrix;
12210     matrix.rotate(angle);
12211     return matrix.map(p);
12212 }
12213 
12214 void Style::drawArrow(QPainter *p, const QRect &rx, PrimitiveElement pe,
12215                       QColor col, bool small, bool kwin) const
12216 {
12217     QPolygon a;
12218     QRect r(rx);
12219     int m = !small && kwin ? ((r.height() - 7) / 2) : 0;
12220 
12221     if (small) {
12222         a.setPoints(opts.vArrows ? 6 : 3,
12223                     2, 0, 0, -2,
12224                     -2, 0, -2, 1,
12225                     0, -1, 2, 1);
12226     } else {
12227         a.setPoints(opts.vArrows ? 8 : 3,
12228                     3 + m, 1 + m, 0, -2,
12229                     -(3 + m), 1 + m, -(3 + m), 2 + m,
12230                     -(2 + m), 2 + m, 0, 0,
12231                     2 + m, 2 + m, 3 + m, 2 + m);
12232     }
12233 
12234     switch (pe) {
12235     case PE_IndicatorArrowUp:
12236         if (m)
12237             r.adjust(0, -m, 0, -m);
12238         break;
12239     case PE_IndicatorArrowDown:
12240         if (m)
12241             r.adjust(0, m, 0, m);
12242         a = rotate(a, 180);
12243         break;
12244     case PE_IndicatorArrowRight:
12245         a = rotate(a, 90);
12246         break;
12247     case PE_IndicatorArrowLeft:
12248         a = rotate(a, 270);
12249         break;
12250     default:
12251         return;
12252     }
12253     a.translate(r.x() + r.width() / 2, r.y() + r.height() / 2);
12254     col.setAlpha(255);
12255     p->save();
12256     p->setPen(col);
12257     p->setBrush(col);
12258 #if (QT_VERSION >= QT_VERSION_CHECK(4, 8, 5))
12259     // Qt >= 4.8.5 has problem drawing polygons correctly. Enabling
12260     // antialiasing can work around the problem although it will also make
12261     // the arrow blurry.
12262     // QtCurve issue:
12263     // https://github.com/QtCurve/qtcurve-qt4/issues/3.
12264     // Upstream bug report:
12265     // https://bugreports.qt-project.org/browse/QTBUG-33512
12266     p->setRenderHint(QPainter::Antialiasing, opts.vArrows);
12267 #else
12268     p->setRenderHint(QPainter::Antialiasing, false);
12269 #endif
12270     p->drawPolygon(a);
12271     p->restore();
12272 }
12273 
12274 void
12275 Style::drawSbSliderHandle(QPainter *p, const QRect &rOrig,
12276                           const QStyleOption *option, bool slider) const
12277 {
12278     QStyleOption opt(*option);
12279     QRect r = rOrig;
12280 
12281     if(opt.state&(State_Sunken|State_On))
12282         opt.state|=State_MouseOver;
12283 
12284     if(r.width()>r.height())
12285         opt.state|=State_Horizontal;
12286 
12287     opt.state&=~(State_Sunken|State_On);
12288     opt.state|=State_Raised;
12289 
12290     if (auto slider = styleOptCast<QStyleOptionSlider>(option))
12291         if(slider->minimum==slider->maximum)
12292             opt.state&=~(State_MouseOver|State_Enabled);
12293 
12294     int min = MIN_SLIDER_SIZE(opts.sliderThumbs);
12295     const QColor *use(sliderColors(&opt));
12296 
12297     drawLightBevel(p, r, &opt, 0L, (slider && (!(opts.square&SQUARE_SLIDER) ||
12298                                                 (SLIDER_ROUND==opts.sliderStyle || SLIDER_ROUND_ROTATED==opts.sliderStyle)))
12299 #ifndef SIMPLE_SCROLLBARS
12300                    || (!slider && !(opts.square&SQUARE_SB_SLIDER) && (SCROLLBAR_NONE==opts.scrollbarType || opts.flatSbarButtons))
12301 #endif
12302                     ? ROUNDED_ALL : ROUNDED_NONE,
12303                    getFill(&opt, use, false, SHADE_DARKEN==opts.shadeSliders), use, true,
12304                    slider ? WIDGET_SLIDER : WIDGET_SB_SLIDER);
12305 
12306     if(LINE_NONE!=opts.sliderThumbs && (slider || ((opt.state&State_Horizontal && r.width()>=min)|| r.height()>=min)) &&
12307         (!slider || SLIDER_CIRCULAR!=opts.sliderStyle))
12308     {
12309         const QColor *markers(use);
12310         bool         horiz(opt.state&State_Horizontal);
12311 
12312         if(LINE_SUNKEN==opts.sliderThumbs)
12313             if(horiz)
12314                 r.adjust(0, -1, 0, 0);
12315             else
12316                 r.adjust(-1, 0, 0, 0);
12317         else
12318             r.adjust(horiz ? 1 : 0, horiz ? 0 : 1, 0, 0);
12319 
12320         switch(opts.sliderThumbs)
12321         {
12322             case LINE_1DOT:
12323                 p->drawPixmap(r.x()+((r.width()-5)/2), r.y()+((r.height()-5)/2), *getPixmap(markers[QTC_STD_BORDER], PIX_DOT, 1.0));
12324                 break;
12325             case LINE_FLAT:
12326                 drawLines(p, r, !horiz, 3, 5, markers, 0, 5, opts.sliderThumbs);
12327                 break;
12328             case LINE_SUNKEN:
12329                 drawLines(p, r, !horiz, 4, 3, markers, 0, 3, opts.sliderThumbs);
12330                 break;
12331             case LINE_DOTS:
12332             default:
12333                 drawDots(p, r, !horiz, slider ? 3 : 5, slider ? 4 : 2, markers, 0, 5);
12334         }
12335     }
12336 }
12337 
12338 void Style::drawSliderHandle(QPainter *p, const QRect &r, const QStyleOptionSlider *option) const
12339 {
12340     bool         horiz(SLIDER_TRIANGULAR==opts.sliderStyle ? r.height()>r.width() : r.width()>r.height());
12341     QStyleOption opt(*option);
12342 
12343     if(!(option->activeSubControls&SC_SliderHandle) || !(opt.state&State_Enabled))
12344         opt.state&=~State_MouseOver;
12345 
12346     if(SLIDER_TRIANGULAR==opts.sliderStyle)
12347     {
12348         if(r.width()>r.height())
12349             opt.state|=State_Horizontal;
12350         opt.state&=~(State_Sunken|State_On);
12351 
12352         opt.state|=State_Raised;
12353 
12354         const QColor     *use(sliderColors(&opt)),
12355                          *border(opt.state&State_MouseOver && (MO_GLOW==opts.coloredMouseOver ||
12356                                                                MO_COLORED==opts.coloredMouseOver)
12357                                     ? m_mouseOverCols : use);
12358         const QColor     &fill(getFill(&opt, use, false, SHADE_DARKEN==opts.shadeSliders));
12359         int              x(r.x()),
12360                          y(r.y());
12361         PrimitiveElement direction(horiz ? PE_IndicatorArrowDown : PE_IndicatorArrowRight);
12362         QPolygon         clipRegion;
12363         bool             drawLight(MO_PLASTIK!=opts.coloredMouseOver || !(opt.state&State_MouseOver));
12364         int              size(SLIDER_TRIANGULAR==opts.sliderStyle ? 15 : 13),
12365                          borderVal(m_mouseOverCols==border ? SLIDER_MO_BORDER_VAL : BORDER_VAL(opt.state&State_Enabled));
12366 
12367         if(option->tickPosition & QSlider::TicksBelow)
12368             direction=horiz ? PE_IndicatorArrowDown : PE_IndicatorArrowRight;
12369         else if(option->tickPosition & QSlider::TicksAbove)
12370             direction=horiz ? PE_IndicatorArrowUp : PE_IndicatorArrowLeft;
12371 
12372         if(MO_GLOW==opts.coloredMouseOver && opts.buttonEffect != EFFECT_NONE)
12373             x++, y++;
12374 
12375         switch(direction)
12376         {
12377             default:
12378             case PE_IndicatorArrowDown:
12379                 clipRegion.setPoints(7,   x, y+2,    x+2, y,   x+8, y,    x+10, y+2,   x+10, y+9,   x+5, y+14,    x, y+9);
12380                 break;
12381             case PE_IndicatorArrowUp:
12382                 clipRegion.setPoints(7,   x, y+12,   x+2, y+14,   x+8, y+14,   x+10, y+12,   x+10, y+5,   x+5, y,    x, y+5);
12383                 break;
12384             case PE_IndicatorArrowLeft:
12385                 clipRegion.setPoints(7,   x+12, y,   x+14, y+2,   x+14, y+8,   x+12, y+10,   x+5, y+10,    x, y+5,    x+5, y );
12386                 break;
12387             case PE_IndicatorArrowRight:
12388                 clipRegion.setPoints(7,   x+2, y,    x, y+2,   x, y+8,    x+2, y+10,   x+9, y+10,   x+14, y+5,    x+9, y);
12389         }
12390 
12391         p->save();
12392         p->setClipRegion(QRegion(clipRegion)); // , QPainter::CoordPainter);
12393         if(qtcIsFlat(opts.sliderAppearance))
12394         {
12395             p->fillRect(r, fill);
12396 
12397             if(MO_PLASTIK==opts.coloredMouseOver && opt.state&State_MouseOver && !opts.colorSliderMouseOver)
12398             {
12399                 int col(SLIDER_MO_SHADE),
12400                     len(SLIDER_MO_LEN);
12401 
12402                 if(horiz)
12403                 {
12404                     p->fillRect(QRect(x+1, y+1, len, size-2), m_mouseOverCols[col]);
12405                     p->fillRect(QRect(x+r.width()-(1+len), y+1, len, r.height()-2), m_mouseOverCols[col]);
12406                 }
12407                 else
12408                 {
12409                     p->fillRect(QRect(x+1, y+1, size-2, len), m_mouseOverCols[col]);
12410                     p->fillRect(QRect(x+1, y+r.height()-(1+len), r.width()-2, len), m_mouseOverCols[col]);
12411                 }
12412             }
12413         }
12414         else
12415         {
12416             drawBevelGradient(fill, p, QRect(x, y, horiz ? r.width()-1 : size, horiz ? size : r.height()-1),
12417                               horiz, false, MODIFY_AGUA(opts.sliderAppearance));
12418 
12419             if(MO_PLASTIK==opts.coloredMouseOver && opt.state&State_MouseOver && !opts.colorSliderMouseOver)
12420             {
12421                 int col(SLIDER_MO_SHADE),
12422                     len(SLIDER_MO_LEN);
12423 
12424                 if(horiz)
12425                 {
12426                     drawBevelGradient(m_mouseOverCols[col], p, QRect(x+1, y+1, len, size-2),
12427                                       horiz, false, MODIFY_AGUA(opts.sliderAppearance));
12428                     drawBevelGradient(m_mouseOverCols[col], p,  QRect(x+r.width()-(1+len), y+1, len, size-2),
12429                                       horiz, false, MODIFY_AGUA(opts.sliderAppearance));
12430                 }
12431                 else
12432                 {
12433                     drawBevelGradient(m_mouseOverCols[col], p, QRect(x+1, y+1, size-2, len),
12434                                       horiz, false, MODIFY_AGUA(opts.sliderAppearance));
12435                     drawBevelGradient(m_mouseOverCols[col], p,QRect(x+1, y+r.height()-(1+len), size-2, len),
12436                                       horiz, false, MODIFY_AGUA(opts.sliderAppearance));
12437                 }
12438             }
12439         }
12440 
12441         p->restore();
12442         p->save();
12443 
12444         QPainterPath path;
12445         double       xd(x+0.5),
12446                      yd(y+0.5),
12447                      radius(2.5),
12448                      diameter(radius*2),
12449                      xdg(x-0.5),
12450                      ydg(y-0.5),
12451                      radiusg(radius+1),
12452                      diameterg(radiusg*2);
12453         bool         glowMo(MO_GLOW==opts.coloredMouseOver && opt.state&State_MouseOver);
12454         QColor       glowCol(border[GLOW_MO]);
12455 
12456         glowCol.setAlphaF(GLOW_ALPHA(false));
12457 
12458         p->setPen(glowMo ? glowCol : border[borderVal]);
12459 
12460         switch(direction)
12461         {
12462             default:
12463             case PE_IndicatorArrowDown:
12464                 p->setRenderHint(QPainter::Antialiasing, true);
12465                 if(glowMo)
12466                 {
12467                     path.moveTo(xdg+12-radiusg, ydg);
12468                     path.arcTo(xdg, ydg, diameterg, diameterg, 90, 90);
12469                     path.lineTo(xdg, ydg+10.5);
12470                     path.lineTo(xdg+6, ydg+16.5);
12471                     path.lineTo(xdg+12, ydg+10.5);
12472                     path.arcTo(xdg+12-diameterg, ydg, diameterg, diameterg, 0, 90);
12473                     p->drawPath(path);
12474                     path=QPainterPath();
12475                     p->setPen(border[borderVal]);
12476                 }
12477                 path.moveTo(xd+10-radius, yd);
12478                 path.arcTo(xd, yd, diameter, diameter, 90, 90);
12479                 path.lineTo(xd, yd+9);
12480                 path.lineTo(xd+5, yd+14);
12481                 path.lineTo(xd+10, yd+9);
12482                 path.arcTo(xd+10-diameter, yd, diameter, diameter, 0, 90);
12483                 p->drawPath(path);
12484                 p->setRenderHint(QPainter::Antialiasing, false);
12485                 if(drawLight)
12486                 {
12487                     p->setPen(use[APPEARANCE_DULL_GLASS==opts.sliderAppearance ? 1 : 0]);
12488                     p->drawLine(x+1, y+2, x+1, y+8);
12489                     p->drawLine(x+2, y+1, x+7, y+1);
12490                 }
12491                 break;
12492             case PE_IndicatorArrowUp:
12493                 p->setRenderHint(QPainter::Antialiasing, true);
12494                 if(glowMo)
12495                 {
12496                     path.moveTo(xdg, ydg+6);
12497                     path.arcTo(xdg, ydg+16-diameterg, diameterg, diameterg, 180, 90);
12498                     path.arcTo(xdg+12-diameterg, ydg+16-diameterg, diameterg, diameterg, 270, 90);
12499                     path.lineTo(xdg+12, ydg+5.5);
12500                     path.lineTo(xdg+6, ydg-0.5);
12501                     path.lineTo(xdg, ydg+5.5);
12502                     p->drawPath(path);
12503                     path=QPainterPath();
12504                     p->setPen(border[borderVal]);
12505                 }
12506                 path.moveTo(xd, yd+5);
12507                 path.arcTo(xd, yd+14-diameter, diameter, diameter, 180, 90);
12508                 path.arcTo(xd+10-diameter, yd+14-diameter, diameter, diameter, 270, 90);
12509                 path.lineTo(xd+10, yd+5);
12510                 path.lineTo(xd+5, yd);
12511                 path.lineTo(xd, yd+5);
12512                 p->drawPath(path);
12513                 p->setRenderHint(QPainter::Antialiasing, false);
12514                 if(drawLight)
12515                 {
12516                     p->setPen(use[APPEARANCE_DULL_GLASS==opts.sliderAppearance ? 1 : 0]);
12517                     p->drawLine(x+5, y+1, x+1, y+5);
12518                     p->drawLine(x+1, y+5, x+1, y+11);
12519                 }
12520                 break;
12521             case PE_IndicatorArrowLeft:
12522                 p->setRenderHint(QPainter::Antialiasing, true);
12523                 if(glowMo)
12524                 {
12525                     path.moveTo(xdg+6, ydg+12);
12526                     path.arcTo(xdg+16-diameterg, ydg+12-diameterg, diameterg, diameterg, 270, 90);
12527                     path.arcTo(xdg+16-diameterg, ydg, diameterg, diameterg, 0, 90);
12528                     path.lineTo(xdg+5.5, ydg);
12529                     path.lineTo(xdg-0.5, ydg+6);
12530                     path.lineTo(xdg+5.5, ydg+12);
12531                     p->drawPath(path);
12532                     path=QPainterPath();
12533                     p->setPen(border[borderVal]);
12534                 }
12535                 path.moveTo(xd+5, yd+10);
12536                 path.arcTo(xd+14-diameter, yd+10-diameter, diameter, diameter, 270, 90);
12537                 path.arcTo(xd+14-diameter, yd, diameter, diameter, 0, 90);
12538                 path.lineTo(xd+5, yd);
12539                 path.lineTo(xd, yd+5);
12540                 path.lineTo(xd+5, yd+10);
12541                 p->drawPath(path);
12542                 p->setRenderHint(QPainter::Antialiasing, false);
12543                 if(drawLight)
12544                 {
12545                     p->setPen(use[APPEARANCE_DULL_GLASS==opts.sliderAppearance ? 1 : 0]);
12546                     p->drawLine(x+1, y+5, x+5, y+1);
12547                     p->drawLine(x+5, y+1, x+11, y+1);
12548                 }
12549                 break;
12550             case PE_IndicatorArrowRight:
12551                 p->setRenderHint(QPainter::Antialiasing, true);
12552                 if(glowMo)
12553                 {
12554                     path.moveTo(xdg+11, ydg);
12555                     path.arcTo(xdg, ydg, diameterg, diameterg, 90, 90);
12556                     path.arcTo(xdg, ydg+12-diameterg, diameterg, diameterg, 180, 90);
12557                     path.lineTo(xdg+10.5, ydg+12);
12558                     path.lineTo(xdg+16.5, ydg+6);
12559                     path.lineTo(xdg+10.5, ydg);
12560                     p->drawPath(path);
12561                     path=QPainterPath();
12562                     p->setPen(border[borderVal]);
12563                 }
12564                 path.moveTo(xd+9, yd);
12565                 path.arcTo(xd, yd, diameter, diameter, 90, 90);
12566                 path.arcTo(xd, yd+10-diameter, diameter, diameter, 180, 90);
12567                 path.lineTo(xd+9, yd+10);
12568                 path.lineTo(xd+14, yd+5);
12569                 path.lineTo(xd+9, yd);
12570                 p->drawPath(path);
12571                 p->setRenderHint(QPainter::Antialiasing, false);
12572                 if(drawLight)
12573                 {
12574                     p->setPen(use[APPEARANCE_DULL_GLASS==opts.sliderAppearance ? 1 : 0]);
12575                     p->drawLine(x+2, y+1, x+7, y+1);
12576                     p->drawLine(x+1, y+2, x+1, y+8);
12577                 }
12578                 break;
12579         }
12580         p->restore();
12581     } else {
12582         if (oneOf(opts.sliderStyle, SLIDER_PLAIN_ROTATED,
12583                   SLIDER_ROUND_ROTATED)) {
12584             opt.state ^= State_Horizontal;
12585         }
12586         drawSbSliderHandle(p, r, &opt, true);
12587    }
12588 }
12589 
12590 void Style::drawSliderGroove(QPainter *p, const QRect &groove, const QRect &handle,  const QStyleOptionSlider *slider,
12591                              const QWidget *widget) const
12592 {
12593     bool               horiz(Qt::Horizontal==slider->orientation);
12594     QRect              grv(groove);
12595     QStyleOptionSlider opt(*slider);
12596 
12597     opt.state&=~(State_HasFocus|State_On|State_Sunken|State_MouseOver);
12598 
12599     if (horiz) {
12600         int dh = (grv.height() - 5) / 2;
12601         grv.adjust(0, dh, 0, -dh);
12602         opt.state |= State_Horizontal;
12603 
12604         if (opts.buttonEffect != EFFECT_NONE) {
12605             grv.adjust(0, -1, 0, 1);
12606         }
12607     } else {
12608         int dw = (grv.width() - 5) / 2;
12609         grv.adjust(dw, 0, -dw, 0);
12610         opt.state &= ~State_Horizontal;
12611 
12612         if (opts.buttonEffect != EFFECT_NONE) {
12613             grv.adjust(-1, 0, 1, 0);
12614         }
12615     }
12616 
12617     if(grv.height()>0 && grv.width()>0)
12618     {
12619         drawLightBevel(p, grv, &opt, widget,
12620                        opts.square&SQUARE_SLIDER ? ROUNDED_NONE : ROUNDED_ALL,
12621                        m_backgroundCols[slider->state&State_Enabled ? 2 : ORIGINAL_SHADE],
12622                        m_backgroundCols, true, WIDGET_SLIDER_TROUGH);
12623 
12624         if(opts.fillSlider && slider->maximum!=slider->minimum && slider->state&State_Enabled)
12625         {
12626             const QColor *usedCols=m_sliderCols ? m_sliderCols : m_highlightCols;
12627 
12628             if (horiz)
12629                 if (slider->upsideDown)
12630                     grv=QRect(handle.right()-4, grv.top(), (grv.right()-handle.right())+4, grv.height());
12631                 else
12632                     grv=QRect(grv.left(), grv.top(), handle.left()+4, grv.height());
12633             else
12634                 if (slider->upsideDown)
12635                     grv=QRect(grv.left(), handle.bottom()-4, grv.width(), (grv.height() - handle.bottom())+4);
12636                 else
12637                     grv=QRect(grv.left(), grv.top(), grv.width(), (handle.top() - grv.top())+4);
12638 
12639             if(grv.height()>0 && grv.width()>0)
12640                 drawLightBevel(p, grv, &opt, widget, opts.square&SQUARE_SLIDER ? ROUNDED_NONE : ROUNDED_ALL,
12641                                usedCols[ORIGINAL_SHADE], usedCols, true, WIDGET_FILLED_SLIDER_TROUGH);
12642         }
12643     }
12644 }
12645 
12646 void
12647 Style::drawMenuOrToolBarBackground(const QWidget *widget, QPainter *p,
12648                                    const QRect &r, const QStyleOption *option,
12649                                    bool menu, bool horiz) const
12650 {
12651     // LibreOffice - when drawMenuOrToolBarBackground is
12652     // called with menuRect, this is empty!
12653     if (r.width() < 1 || r.height() < 1)
12654         return;
12655 
12656     EAppearance app = menu ? opts.menubarAppearance : opts.toolbarAppearance;
12657     if (!qtcIsCustomBgnd(opts) || !qtcIsFlat(app) ||
12658         (menu && opts.shadeMenubars != SHADE_NONE)) {
12659         p->save();
12660 #if 0
12661         // Revert for now
12662         // This is necessary for correct opacity on the menubar but may
12663         // break transparent gradient.
12664         p->setCompositionMode(QPainter::CompositionMode_Source);
12665 #endif
12666         QRect rx(r);
12667         QColor col(menu && (option->state & State_Enabled ||
12668                             opts.shadeMenubars != SHADE_NONE) ?
12669                    menuColors(option, m_active)[ORIGINAL_SHADE] :
12670                    option->palette.background().color());
12671         int opacity = qtcGetOpacity(widget ? widget : getWidget(p));
12672 
12673         if (menu && BLEND_TITLEBAR) {
12674             rx.adjust(0, -qtcGetWindowBorderSize(false).titleHeight, 0, 0);
12675         }
12676         if (opacity < 100) {
12677             col.setAlphaF(opacity / 100.0);
12678         }
12679         drawBevelGradient(col, p, rx, horiz, false, MODIFY_AGUA(app));
12680         p->restore();
12681     }
12682 }
12683 
12684 void
12685 Style::drawHandleMarkers(QPainter *p, const QRect &rx,
12686                          const QStyleOption *option,
12687                          bool tb, ELine handles) const
12688 {
12689     if (rx.width() < 2 || rx.height() < 2)
12690         return;
12691 
12692     QRect r(rx);
12693 
12694     if (theThemedApp == APP_OPENOFFICE) {
12695         r.setX(r.x() + 2);
12696         r.setWidth(10);
12697     }
12698 
12699     // CPD: Mouse over of toolbar handles not working -
12700     // the whole toolbar seems to be active :-(
12701     QStyleOption opt(*option);
12702 
12703     opt.state &= ~State_MouseOver;
12704 
12705     const QColor *border(borderColors(&opt, m_backgroundCols));
12706 
12707     switch (handles) {
12708         case LINE_NONE:
12709             break;
12710         case LINE_1DOT:
12711              p->drawPixmap(r.x()+((r.width()-5)/2), r.y()+((r.height()-5)/2), *getPixmap(border[QTC_STD_BORDER], PIX_DOT, 1.0));
12712             break;
12713         case LINE_DOTS:
12714             drawDots(p, r, !(option->state&State_Horizontal), 2, tb ? 5 : 3, border, tb ? -2 : 0, 5);
12715             break;
12716         case LINE_DASHES:
12717             if(option->state&State_Horizontal)
12718                 drawLines(p, QRect(r.x()+(tb ? 2 : (r.width()-6)/2), r.y(), 3, r.height()), true, (r.height()-8)/2,
12719                           tb ? 0 : (r.width()-5)/2, border, 0, 5, handles);
12720             else
12721                 drawLines(p, QRect(r.x(), r.y()+(tb ? 2 : (r.height()-6)/2), r.width(), 3), false, (r.width()-8)/2,
12722                           tb ? 0 : (r.height()-5)/2, border, 0, 5, handles);
12723             break;
12724         case LINE_FLAT:
12725             drawLines(p, r, !(option->state&State_Horizontal), 2, tb ? 4 : 2, border, tb ? -2 : 0, 4, handles);
12726             break;
12727         default:
12728             drawLines(p, r, !(option->state&State_Horizontal), 2, tb ? 4 : 2, border, tb ? -2 : 0, 3, handles);
12729     }
12730 }
12731 
12732 void Style::fillTab(QPainter *p, const QRect &r, const QStyleOption *option, const QColor &fill, bool horiz, EWidget tab,
12733                     bool tabOnly) const
12734 {
12735     bool   invertedSel=option->state&State_Selected && APPEARANCE_INVERTED==opts.appearance;
12736     QColor col(invertedSel ? option->palette.background().color() : fill);
12737 
12738     if(opts.tabBgnd && !tabOnly)
12739         col=shade(col, TO_FACTOR(opts.tabBgnd));
12740 
12741     if(invertedSel)
12742         p->fillRect(r, col);
12743     else
12744     {
12745         bool        selected(option->state&State_Selected);
12746         EAppearance app(selected ? SEL_TAB_APP : NORM_TAB_APP);
12747 
12748         drawBevelGradient(col, p, r, horiz, selected, app, tab);
12749     }
12750 }
12751 
12752 void Style::colorTab(QPainter *p, const QRect &r, bool horiz, EWidget tab, int round) const
12753 {
12754     p->save();
12755     p->setRenderHint(QPainter::Antialiasing, true);
12756     QLinearGradient grad(r.topLeft(), horiz ? r.bottomLeft() : r.topRight());
12757     QColor          start(m_highlightCols[ORIGINAL_SHADE]),
12758                     end(m_highlightCols[ORIGINAL_SHADE]);
12759 
12760     start.setAlphaF(TO_ALPHA(opts.colorSelTab));
12761     end.setAlphaF(0.0);
12762     grad.setColorAt(0, WIDGET_TAB_TOP==tab ? start : end);
12763     grad.setColorAt(1, WIDGET_TAB_TOP==tab ? end : start);
12764     p->fillPath(buildPath(r, tab, round, qtcGetRadius(&opts, r.width(), r.height(), tab, RADIUS_EXTERNAL)), grad);
12765     p->restore();
12766 }
12767 
12768 void Style::shadeColors(const QColor &base, QColor *vals) const
12769 {
12770     bool useCustom(USE_CUSTOM_SHADES(opts));
12771     double hl = TO_FACTOR(opts.highlightFactor);
12772 
12773     for(int i=0; i<QTC_NUM_STD_SHADES; ++i)
12774         shade(base, &vals[i], useCustom ? opts.customShades[i] :
12775               qtcShadeGetIntern(opts.contrast, i,
12776                                 opts.darkerBorders, opts.shading));
12777     shade(base, &vals[SHADE_ORIG_HIGHLIGHT], hl);
12778     shade(vals[4], &vals[SHADE_4_HIGHLIGHT], hl);
12779     shade(vals[2], &vals[SHADE_2_HIGHLIGHT], hl);
12780     vals[ORIGINAL_SHADE]=base;
12781 }
12782 
12783 const QColor * Style::buttonColors(const QStyleOption *option) const
12784 {
12785    if(option && option->version>=TBAR_VERSION_HACK &&
12786        option->version<TBAR_VERSION_HACK+NUM_TITLEBAR_BUTTONS &&
12787        coloredMdiButtons(option->state&State_Active, option->state&(State_MouseOver|State_Sunken)))
12788         return m_titleBarButtonsCols[option->version-TBAR_VERSION_HACK];
12789 
12790     if(option && option->palette.button()!=m_buttonCols[ORIGINAL_SHADE])
12791     {
12792         shadeColors(option->palette.button().color(), m_coloredButtonCols);
12793         return m_coloredButtonCols;
12794     }
12795 
12796     return m_buttonCols;
12797 }
12798 
12799 QColor Style::titlebarIconColor(const QStyleOption *option) const
12800 {
12801     if(option && option->version>=TBAR_VERSION_HACK)
12802     {
12803         if(opts.titlebarButtons&TITLEBAR_BUTTON_ICON_COLOR && option->version<TBAR_VERSION_HACK+(NUM_TITLEBAR_BUTTONS*3))
12804             return opts.titlebarButtonColors[option->version-TBAR_VERSION_HACK];
12805         if(option->version<TBAR_VERSION_HACK+NUM_TITLEBAR_BUTTONS &&
12806            coloredMdiButtons(option->state&State_Active, option->state&(State_MouseOver|State_Sunken)))
12807             return m_titleBarButtonsCols[option->version-TBAR_VERSION_HACK][ORIGINAL_SHADE];
12808     }
12809 
12810     return buttonColors(option)[ORIGINAL_SHADE];
12811 }
12812 
12813 const QColor*
12814 Style::popupMenuCols(const QStyleOption *option) const
12815 {
12816     return (opts.lighterPopupMenuBgnd || opts.shadePopupMenu || !option ?
12817             m_popupMenuCols : backgroundColors(option));
12818 }
12819 
12820 const QColor * Style::checkRadioColors(const QStyleOption *option) const
12821 {
12822     return opts.crColor && option && option->state&State_Enabled && (option->state&State_On || option->state&State_NoChange)
12823         ? m_checkRadioSelCols
12824         : buttonColors(option);
12825 }
12826 
12827 const QColor * Style::sliderColors(const QStyleOption *option) const
12828 {
12829     return (option && option->state&State_Enabled)
12830                 ? SHADE_NONE!=opts.shadeSliders && m_sliderCols &&
12831                   (!opts.colorSliderMouseOver || option->state&State_MouseOver)
12832                         ? m_sliderCols
12833                         : m_buttonCols //buttonColors(option)
12834                 : m_backgroundCols;
12835 }
12836 
12837 const QColor * Style::backgroundColors(const QColor &col) const
12838 {
12839     if(col.alpha()!=0 && col!=m_backgroundCols[ORIGINAL_SHADE])
12840     {
12841         shadeColors(col, m_coloredBackgroundCols);
12842         return m_coloredBackgroundCols;
12843     }
12844 
12845     return m_backgroundCols;
12846 }
12847 
12848 const QColor * Style::highlightColors(const QColor &col) const
12849 {
12850     if(col.alpha()!=0 && col!=m_highlightCols[ORIGINAL_SHADE])
12851     {
12852         shadeColors(col, m_coloredHighlightCols);
12853         return m_coloredHighlightCols;
12854     }
12855 
12856     return m_highlightCols;
12857 }
12858 
12859 const QColor * Style::borderColors(const QStyleOption *option, const QColor *use) const
12860 {
12861     return opts.coloredMouseOver && option && option->state&State_MouseOver && option->state&State_Enabled ? m_mouseOverCols : use;
12862 }
12863 
12864 const QColor * Style::getSidebarButtons() const
12865 {
12866     if(!m_sidebarButtonsCols)
12867     {
12868         if(SHADE_BLEND_SELECTED==opts.shadeSliders)
12869             m_sidebarButtonsCols=m_sliderCols;
12870         else if(IND_COLORED==opts.defBtnIndicator)
12871             m_sidebarButtonsCols=m_defBtnCols;
12872         else
12873         {
12874             m_sidebarButtonsCols=new QColor [TOTAL_SHADES+1];
12875             shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE], m_buttonCols[ORIGINAL_SHADE]),
12876                         m_sidebarButtonsCols);
12877         }
12878     }
12879 
12880     return m_sidebarButtonsCols;
12881 }
12882 
12883 void Style::setMenuColors(const QColor &bgnd)
12884 {
12885     switch(opts.shadeMenubars)
12886     {
12887         case SHADE_NONE:
12888             std::copy(m_backgroundCols, m_backgroundCols + TOTAL_SHADES + 1, m_menubarCols);
12889             break;
12890         case SHADE_BLEND_SELECTED:
12891             shadeColors(midColor(m_highlightCols[ORIGINAL_SHADE], m_backgroundCols[ORIGINAL_SHADE]), m_menubarCols);
12892             break;
12893         case SHADE_SELECTED:
12894             shadeColors(IS_GLASS(opts.appearance)
12895                             ? shade(m_highlightCols[ORIGINAL_SHADE], MENUBAR_GLASS_SELECTED_DARK_FACTOR)
12896                             : m_highlightCols[ORIGINAL_SHADE],
12897                         m_menubarCols);
12898             break;
12899         case SHADE_CUSTOM:
12900             shadeColors(opts.customMenubarsColor, m_menubarCols);
12901             break;
12902         case SHADE_DARKEN:
12903             shadeColors(shade(bgnd, MENUBAR_DARK_FACTOR), m_menubarCols);
12904             break;
12905         case SHADE_WINDOW_BORDER:
12906             break;
12907     }
12908 
12909     QColor *base=opts.shadePopupMenu
12910                     ? SHADE_WINDOW_BORDER==opts.shadeMenubars
12911                         ? (QColor*)getMdiColors(0L, true) // TODO: option!!!
12912                         : m_menubarCols
12913                     : m_backgroundCols;
12914 
12915     if (opts.lighterPopupMenuBgnd) {
12916         if (!m_popupMenuCols) {
12917             m_popupMenuCols = new QColor[TOTAL_SHADES + 1];
12918         }
12919         shadeColors(shade(base[ORIGINAL_SHADE],
12920                           TO_FACTOR(opts.lighterPopupMenuBgnd)),
12921                     m_popupMenuCols);
12922     } else {
12923         m_popupMenuCols = base;
12924     }
12925 }
12926 
12927 void Style::setMenuTextColors(QWidget *widget, bool isMenuBar) const
12928 {
12929     if(SHADE_WINDOW_BORDER==opts.shadeMenubars)
12930     {
12931         QPalette pal(widget->palette());
12932         QStyleOption opt;
12933 
12934         opt.init(widget);
12935         getMdiColors(&opt, false);
12936 
12937         pal.setBrush(QPalette::Active, QPalette::Foreground, m_activeMdiTextColor);
12938         pal.setBrush(QPalette::Active, QPalette::Text, pal.brush(QPalette::Active, QPalette::Foreground));
12939         if(isMenuBar)
12940         {
12941             pal.setBrush(QPalette::Inactive, QPalette::Foreground,
12942                             opts.shadeMenubarOnlyWhenActive ? m_mdiTextColor : m_activeMdiTextColor);
12943             pal.setBrush(QPalette::Inactive, QPalette::Text, pal.brush(QPalette::Inactive, QPalette::Foreground));
12944         }
12945         else if(opts.shadePopupMenu)
12946         {
12947             pal.setBrush(QPalette::Disabled, QPalette::Foreground, midColor(m_activeMdiTextColor, popupMenuCols()[ORIGINAL_SHADE]));
12948             pal.setBrush(QPalette::Disabled, QPalette::Text, pal.brush(QPalette::Disabled, QPalette::Foreground));
12949         }
12950 
12951         widget->setPalette(pal);
12952     }
12953     else if(opts.customMenuTextColor || SHADE_BLEND_SELECTED==opts.shadeMenubars ||
12954             SHADE_SELECTED==opts.shadeMenubars ||
12955             (SHADE_CUSTOM==opts.shadeMenubars && TOO_DARK(m_menubarCols[ORIGINAL_SHADE])))
12956     {
12957         QPalette pal(widget->palette());
12958 
12959         pal.setBrush(QPalette::Active, QPalette::Foreground, opts.customMenuTextColor
12960                                                 ? opts.customMenuNormTextColor
12961                                                 : pal.highlightedText().color());
12962         pal.setBrush(QPalette::Active, QPalette::Text, pal.brush(QPalette::Active, QPalette::Foreground));
12963 
12964         if(isMenuBar && !opts.shadeMenubarOnlyWhenActive)
12965         {
12966             pal.setBrush(QPalette::Inactive, QPalette::Foreground, opts.customMenuTextColor
12967                                                 ? opts.customMenuNormTextColor
12968                                                 : pal.highlightedText().color());
12969             pal.setBrush(QPalette::Inactive, QPalette::Text, pal.brush(QPalette::Inactive, QPalette::Foreground));
12970         }
12971         else if(!isMenuBar && opts.shadePopupMenu)
12972         {
12973             pal.setBrush(QPalette::Disabled, QPalette::Foreground,
12974                          midColor(pal.brush(QPalette::Active, QPalette::Foreground).color(), popupMenuCols()[ORIGINAL_SHADE]));
12975             pal.setBrush(QPalette::Disabled, QPalette::Text, pal.brush(QPalette::Disabled, QPalette::Foreground));
12976         }
12977         widget->setPalette(pal);
12978     }
12979 }
12980 
12981 const QColor * Style::menuColors(const QStyleOption *option, bool active) const
12982 {
12983     return SHADE_WINDOW_BORDER==opts.shadeMenubars
12984             ? getMdiColors(option, active)
12985             : SHADE_NONE==opts.shadeMenubars || (opts.shadeMenubarOnlyWhenActive && !active)
12986                 ? backgroundColors(option)
12987                 : m_menubarCols;
12988 }
12989 
12990 bool Style::coloredMdiButtons(bool active, bool mouseOver) const
12991 {
12992     return opts.titlebarButtons&TITLEBAR_BUTTON_COLOR &&
12993             (active
12994                 ? (mouseOver || !(opts.titlebarButtons&TITLEBAR_BUTTON_COLOR_MOUSE_OVER))
12995                 : ((opts.titlebarButtons&TITLEBAR_BUTTON_COLOR_MOUSE_OVER && mouseOver) ||
12996                     (!(opts.titlebarButtons&TITLEBAR_BUTTON_COLOR_MOUSE_OVER) &&
12997                        opts.titlebarButtons&TITLEBAR_BUTTON_COLOR_INACTIVE)) );
12998 }
12999 
13000 const QColor * Style::getMdiColors(const QStyleOption *option, bool active) const
13001 {
13002     if(!m_activeMdiColors)
13003     {
13004 #ifndef QTC_QT4_ENABLE_KDE
13005         m_activeMdiTextColor=option ? option->palette.text().color() : QApplication::palette().text().color();
13006         m_mdiTextColor=option ? option->palette.text().color() : QApplication::palette().text().color();
13007 
13008         QFile f(Utils::kdeHome()+"/share/config/kdeglobals");
13009 
13010         if(f.open(QIODevice::ReadOnly))
13011         {
13012             QTextStream in(&f);
13013             bool        inPal(false);
13014 
13015             while (!in.atEnd())
13016             {
13017                 QString line(in.readLine());
13018 
13019                 if(inPal)
13020                 {
13021                     if(!m_activeMdiColors && 0==line.indexOf("activeBackground="))
13022                     {
13023                         QColor col;
13024 
13025                         setRgb(&col, line.mid(17).split(","));
13026 
13027                         if(col!=m_highlightCols[ORIGINAL_SHADE])
13028                         {
13029                             m_activeMdiColors=new QColor [TOTAL_SHADES+1];
13030                             shadeColors(col, m_activeMdiColors);
13031                         }
13032                     }
13033                     else if(!m_mdiColors && 0==line.indexOf("inactiveBackground="))
13034                     {
13035                         QColor col;
13036 
13037                         setRgb(&col, line.mid(19).split(","));
13038                         if(col!=m_buttonCols[ORIGINAL_SHADE])
13039                         {
13040                             m_mdiColors=new QColor [TOTAL_SHADES+1];
13041                             shadeColors(col, m_mdiColors);
13042                         }
13043                     }
13044                     else if(0==line.indexOf("activeForeground="))
13045                         setRgb(&m_activeMdiTextColor, line.mid(17).split(","));
13046                     else if(0==line.indexOf("inactiveForeground="))
13047                         setRgb(&m_mdiTextColor, line.mid(19).split(","));
13048                     else if (-1!=line.indexOf('['))
13049                         break;
13050                 }
13051                 else if(0==line.indexOf("[WM]"))
13052                     inPal=true;
13053             }
13054             f.close();
13055         }
13056 #else
13057         Q_UNUSED(option)
13058 
13059         QColor col=KGlobalSettings::activeTitleColor();
13060 
13061         if(col!=m_backgroundCols[ORIGINAL_SHADE])
13062         {
13063             m_activeMdiColors=new QColor [TOTAL_SHADES+1];
13064             shadeColors(col, m_activeMdiColors);
13065         }
13066 
13067         col=KGlobalSettings::inactiveTitleColor();
13068         if(col!=m_backgroundCols[ORIGINAL_SHADE])
13069         {
13070             m_mdiColors=new QColor [TOTAL_SHADES+1];
13071             shadeColors(col, m_mdiColors);
13072         }
13073 
13074         m_activeMdiTextColor=KGlobalSettings::activeTextColor();
13075         m_mdiTextColor=KGlobalSettings::inactiveTextColor();
13076 #endif
13077 
13078         if(!m_activeMdiColors)
13079             m_activeMdiColors=(QColor*)m_backgroundCols;
13080         if(!m_mdiColors)
13081             m_mdiColors=(QColor*)m_backgroundCols;
13082 
13083         if(opts.shadeMenubarOnlyWhenActive && SHADE_WINDOW_BORDER==opts.shadeMenubars &&
13084            m_activeMdiColors[ORIGINAL_SHADE]==m_mdiColors[ORIGINAL_SHADE])
13085             opts.shadeMenubarOnlyWhenActive=false;
13086     }
13087 
13088     return active ? m_activeMdiColors : m_mdiColors;
13089 }
13090 
13091 void Style::readMdiPositions() const
13092 {
13093     if(0==m_mdiButtons[0].size() && 0==m_mdiButtons[1].size())
13094     {
13095 #ifdef Q_OS_MAC
13096         // no control over where the system menu appears, so we have little choice
13097         // but to keep it at its default position. The user can still override this.
13098         m_mdiButtons[0].append(SC_TitleBarSysMenu);
13099         m_mdiButtons[0].append(SC_TitleBarCloseButton);
13100         m_mdiButtons[0].append(SC_TitleBarMinButton);
13101         m_mdiButtons[0].append(SC_TitleBarMaxButton);
13102 
13103         m_mdiButtons[1].append(SC_TitleBarShadeButton);
13104         m_mdiButtons[1].append(SC_TitleBarContextHelpButton);
13105 #else
13106         // Set defaults...
13107         m_mdiButtons[0].append(SC_TitleBarSysMenu);
13108         m_mdiButtons[0].append(SC_TitleBarShadeButton);
13109 
13110         m_mdiButtons[1].append(SC_TitleBarContextHelpButton);
13111         m_mdiButtons[1].append(SC_TitleBarMinButton);
13112         m_mdiButtons[1].append(SC_TitleBarMaxButton);
13113         m_mdiButtons[1].append(WINDOWTITLE_SPACER);
13114         m_mdiButtons[1].append(SC_TitleBarCloseButton);
13115 #endif
13116 
13117 #ifdef QTC_QT4_ENABLE_KDE
13118         KSharedConfigPtr cfg = KSharedConfig::openConfig("kwinrc");
13119         KConfigGroup grp = cfg->group("Style");
13120 
13121         if(grp.readEntry("CustomButtonPositions", false))
13122         {
13123             QString left=grp.readEntry("ButtonsOnLeft"),
13124                     right=grp.readEntry("ButtonsOnRight");
13125 
13126             if(!left.isEmpty() || !right.isEmpty())
13127                 m_mdiButtons[0].clear(), m_mdiButtons[1].clear();
13128 
13129             if(!left.isEmpty())
13130                 parseWindowLine(left, m_mdiButtons[0]);
13131 
13132             if(!right.isEmpty())
13133                 parseWindowLine(right, m_mdiButtons[1]);
13134 
13135             // Designer uses shade buttons, not min/max - so if we don't have shade in our kwin config.
13136             // then add this button near the max button...
13137             if(-1==m_mdiButtons[0].indexOf(SC_TitleBarShadeButton) && -1==m_mdiButtons[1].indexOf(SC_TitleBarShadeButton))
13138             {
13139                 int maxPos=m_mdiButtons[0].indexOf(SC_TitleBarMaxButton);
13140 
13141                 if(-1==maxPos) // Left doesnt have max button, assume right does and add shade there
13142                 {
13143                     int minPos=m_mdiButtons[1].indexOf(SC_TitleBarMinButton);
13144                     maxPos=m_mdiButtons[1].indexOf(SC_TitleBarMaxButton);
13145 
13146                     m_mdiButtons[1].insert(minPos<maxPos ? (minPos==-1 ? 0 : minPos)
13147                                                             : (maxPos==-1 ? 0 : maxPos), SC_TitleBarShadeButton);
13148                 }
13149                 else // Add to left button
13150                 {
13151                     int minPos=m_mdiButtons[0].indexOf(SC_TitleBarMinButton);
13152 
13153                     m_mdiButtons[1].insert(minPos>maxPos ? (minPos==-1 ? 0 : minPos)
13154                                                         : (maxPos==-1 ? 0 : maxPos), SC_TitleBarShadeButton);
13155                 }
13156             }
13157         }
13158 #endif
13159     }
13160 }
13161 
13162 const QColor & Style::getFill(const QStyleOption *option, const QColor *use, bool cr, bool darker) const
13163 {
13164     return !option || !(option->state&State_Enabled)
13165                ? use[darker ? 2 : ORIGINAL_SHADE]
13166                : option->state&State_Sunken  // State_Down ????
13167                    ? use[darker ? 5 : 4]
13168                    : option->state&State_MouseOver
13169                          ? !cr && option->state&State_On
13170                                ? use[darker ? 3 : SHADE_4_HIGHLIGHT]
13171                                : use[darker ? SHADE_2_HIGHLIGHT : SHADE_ORIG_HIGHLIGHT]
13172                          : !cr && option->state&State_On
13173                                ? use[darker ? 5 : 4]
13174                                : use[darker ? 2 : ORIGINAL_SHADE];
13175 }
13176 
13177 QPixmap * Style::getPixmap(const QColor col, EPixmap p, double shade) const
13178 {
13179     QtcKey key(createKey(col, p));
13180     QPixmap *pix = m_pixmapCache.object(key);
13181 
13182     if (!pix) {
13183         if(PIX_DOT==p)
13184         {
13185             pix=new QPixmap(5, 5);
13186             pix->fill(Qt::transparent);
13187 
13188             QColor          c(col);
13189             QPainter        p(pix);
13190             QLinearGradient g1(0, 0, 5, 5),
13191                             g2(0, 0, 3, 3);
13192 
13193             g1.setColorAt(0.0, c);
13194             c.setAlphaF(0.4);
13195             g1.setColorAt(1.0, c);
13196             c=Qt::white;
13197             c.setAlphaF(0.9);
13198             g2.setColorAt(0.0, c);
13199             c.setAlphaF(0.7);
13200             g2.setColorAt(1.0, c);
13201             p.setRenderHint(QPainter::Antialiasing, true);
13202             p.setPen(Qt::NoPen);
13203             p.setBrush(g1);
13204             p.drawEllipse(0, 0, 5, 5);
13205             p.setBrush(g2);
13206             p.drawEllipse(1, 1, 4, 4);
13207             p.end();
13208         } else {
13209             pix = new QPixmap();
13210             QImage img;
13211             switch (p) {
13212             case PIX_CHECK:
13213                 if(opts.xCheck)
13214                     img = qtc_check_x_on;
13215                 else
13216                     img = qtc_check_on;
13217                 break;
13218             default:
13219                 break;
13220             }
13221 
13222             qtcAdjustPix(img.bits(), 4, img.width(), img.height(),
13223                          img.bytesPerLine(), col.red(), col.green(),
13224                          col.blue(), shade, QTC_PIXEL_QT);
13225             *pix = QPixmap::fromImage(img);
13226         }
13227         m_pixmapCache.insert(key, pix, pix->depth()/8);
13228     }
13229 
13230     return pix;
13231 }
13232 
13233 const QColor & Style::getTabFill(bool current, bool highlight, const QColor *use) const
13234 {
13235     return current
13236             ? use[ORIGINAL_SHADE]
13237             : highlight
13238                 ? use[SHADE_2_HIGHLIGHT]
13239                 : use[2];
13240 }
13241 
13242 QColor Style::menuStripeCol() const
13243 {
13244     switch(opts.menuStripe)
13245     {
13246         default:
13247         case SHADE_NONE:
13248             return m_backgroundCols[ORIGINAL_SHADE];
13249         case SHADE_CUSTOM:
13250             return opts.customMenuStripeColor;
13251         case SHADE_BLEND_SELECTED:
13252             // Hack! Use opts.customMenuStripeColor to store this setting!
13253             if (isBlack(opts.customMenuStripeColor)) {
13254                 opts.customMenuStripeColor =
13255                     midColor(m_highlightCols[ORIGINAL_SHADE],
13256                              popupMenuCols()[ORIGINAL_SHADE]);
13257             }
13258             return opts.customMenuStripeColor;
13259         case SHADE_SELECTED:
13260             return m_highlightCols[MENU_STRIPE_SHADE];
13261         case SHADE_DARKEN:
13262             return popupMenuCols()[MENU_STRIPE_SHADE];
13263     }
13264 }
13265 
13266 const QColor & Style::checkRadioCol(const QStyleOption *opt) const
13267 {
13268     return opt->state&State_Enabled
13269             ? m_checkRadioCol
13270             : opts.crButton
13271                 ? opt->palette.buttonText().color()
13272                 : opt->palette.text().color();
13273 }
13274 
13275 QColor Style::shade(const QColor &a, double k) const
13276 {
13277     QColor mod;
13278     qtcShade(&a, &mod, k, opts.shading);
13279     return mod;
13280 }
13281 
13282 void Style::shade(const QColor &ca, QColor *cb, double k) const
13283 {
13284     qtcShade(&ca, cb, k, opts.shading);
13285 }
13286 
13287 QColor Style::getLowerEtchCol(const QWidget *widget) const
13288 {
13289     if (USE_CUSTOM_ALPHAS(opts)) {
13290         QColor col(Qt::white);
13291         col.setAlphaF(opts.customAlphas[ALPHA_ETCH_LIGHT]);
13292         return col;
13293     }
13294 
13295     QtcQWidgetProps props(widget);
13296     if (qtcIsFlatBgnd(opts.bgndAppearance)) {
13297         bool doEtch = widget && widget->parentWidget() && !props->noEtch;
13298         // CPD: Don't really want to check here for every widget, when
13299         // (so far) on problem seems to be in KPackageKit, and thats with
13300         // its KTextBrowser - so just check when we draw scrollviews...
13301         // if (doEtch && isInQAbstractItemView(widget->parentWidget())) {
13302         //     doEtch = false;
13303         //     props->noEtch = true;
13304         // }
13305 
13306         if(doEtch)
13307         {
13308             QColor bgnd(widget->parentWidget()->palette().color(widget->parentWidget()->backgroundRole()));
13309 
13310             if(bgnd.alpha()>0)
13311                 return shade(bgnd, 1.06);
13312         }
13313     }
13314 
13315     QColor col(Qt::white);
13316     col.setAlphaF(0.1);
13317     // qtcIsFlatBgnd(opts.bgndAppearance) ? 0.25 : 0.4);
13318     return col;
13319 }
13320 
13321 int Style::getFrameRound(const QWidget *widget) const
13322 {
13323     if(opts.square&SQUARE_FRAME)
13324         return ROUNDED_NONE;
13325 
13326     const QWidget *window=widget ? widget->window() : 0L;
13327 
13328     if(window)
13329     {
13330         QRect widgetRect(widget->rect()),
13331               windowRect(window->rect());
13332 
13333         if(widgetRect==windowRect)
13334             return ROUNDED_NONE;
13335     }
13336 
13337     if((opts.square&SQUARE_ENTRY) && widget && qobject_cast<const QLabel*>(widget))
13338         return ROUNDED_NONE;
13339 
13340     return ROUNDED_ALL;
13341 }
13342 
13343 void Style::widgetDestroyed(QObject *o)
13344 {
13345     QWidget *w = static_cast<QWidget*>(o);
13346     if (APP_KONTACT == theThemedApp) {
13347         m_sViewContainers.remove(w);
13348         QMap<QWidget*, QSet<QWidget*> >::Iterator it(m_sViewContainers.begin());
13349         QMap<QWidget*, QSet<QWidget*> >::Iterator end(m_sViewContainers.end());
13350         QSet<QWidget*> rem;
13351 
13352         for (;it != end;++it) {
13353             (*it).remove(w);
13354             if ((*it).isEmpty()) {
13355                 rem.insert(it.key());
13356             }
13357         }
13358         foreach (QWidget *widget, rem) {
13359             m_sViewContainers.remove(widget);
13360         }
13361     }
13362 }
13363 
13364 #ifdef QTC_QT4_ENABLE_KDE
13365 void Style::setupKde4()
13366 {
13367     if(kapp)
13368         setDecorationColors();
13369     else
13370     {
13371         applyKdeSettings(true);
13372         applyKdeSettings(false);
13373     }
13374 }
13375 
13376 void Style::setDecorationColors()
13377 {
13378     KColorScheme kcs(QPalette::Active);
13379     if(opts.coloredMouseOver)
13380         shadeColors(kcs.decoration(KColorScheme::HoverColor).color(), m_mouseOverCols);
13381     shadeColors(kcs.decoration(KColorScheme::FocusColor).color(), m_focusCols);
13382 }
13383 
13384 void Style::applyKdeSettings(bool pal)
13385 {
13386     if(pal)
13387     {
13388         if(!kapp)
13389             QApplication::setPalette(standardPalette());
13390         setDecorationColors();
13391     }
13392     else
13393     {
13394         KConfigGroup g(KGlobal::config(), "General");
13395         QFont        mnu=g.readEntry("menuFont", QApplication::font());
13396 
13397         QApplication::setFont(g.readEntry("font", QApplication::font()));
13398         QApplication::setFont(mnu, "QMenuBar");
13399         QApplication::setFont(mnu, "QMenu");
13400         QApplication::setFont(mnu, "KPopupTitle");
13401         QApplication::setFont(KGlobalSettings::toolBarFont(), "QToolBar");
13402     }
13403 }
13404 #endif
13405 
13406 void Style::kdeGlobalSettingsChange(int type, int)
13407 {
13408 #ifndef QTC_QT4_ENABLE_KDE
13409     Q_UNUSED(type)
13410 #else
13411     switch(type) {
13412     case KGlobalSettings::StyleChanged: {
13413         KGlobal::config()->reparseConfiguration();
13414         if (m_usePixmapCache)
13415             QPixmapCache::clear();
13416         init(false);
13417         foreach (QWidget *widget, QApplication::topLevelWidgets()) {
13418             widget->update();
13419         }
13420         break;
13421     }
13422     case KGlobalSettings::PaletteChanged:
13423         KGlobal::config()->reparseConfiguration();
13424         applyKdeSettings(true);
13425         if (m_usePixmapCache)
13426             QPixmapCache::clear();
13427         break;
13428     case KGlobalSettings::FontChanged:
13429         KGlobal::config()->reparseConfiguration();
13430         applyKdeSettings(false);
13431         break;
13432     }
13433 #endif
13434 
13435     m_blurHelper->setEnabled(Utils::compositingActive());
13436     m_windowManager->initialize(opts.windowDrag);
13437 }
13438 
13439 void Style::borderSizesChanged()
13440 {
13441 #ifdef QTC_QT4_ENABLE_KDE
13442     int old = qtcGetWindowBorderSize(false).titleHeight;
13443 
13444     if (old != qtcGetWindowBorderSize(true).titleHeight) {
13445         foreach (QWidget *widget, QApplication::topLevelWidgets()) {
13446             if (qobject_cast<QMainWindow*>(widget) &&
13447                 static_cast<QMainWindow*>(widget)->menuBar()) {
13448                 static_cast<QMainWindow*>(widget)->menuBar()->update();
13449             }
13450         }
13451     }
13452 #endif
13453 }
13454 
13455 static QMainWindow*
13456 getWindow(unsigned int xid)
13457 {
13458     QTC_RET_IF_FAIL(xid, nullptr);
13459     foreach (QWidget *widget, QApplication::topLevelWidgets()) {
13460         if (qobject_cast<QMainWindow*>(widget) && qtcGetWid(widget) == xid) {
13461             return static_cast<QMainWindow*>(widget);
13462         }
13463     }
13464     return nullptr;
13465 }
13466 
13467 static bool
13468 diffTime(struct timeval *lastTime)
13469 {
13470     struct timeval now, diff;
13471 
13472     gettimeofday(&now, nullptr);
13473     timersub(&now, lastTime, &diff);
13474     *lastTime = now;
13475     return diff.tv_sec > 0 || diff.tv_usec > 500000;
13476 }
13477 
13478 void
13479 Style::toggleMenuBar(unsigned int xid)
13480 {
13481     static unsigned int lastXid = 0;
13482     static struct timeval lastTime = {0, 0};
13483 
13484     if (diffTime(&lastTime) || lastXid != xid) {
13485         QMainWindow *win = getWindow(xid);
13486         if (win) {
13487             toggleMenuBar(win);
13488         }
13489     }
13490     lastXid = xid;
13491 }
13492 
13493 void
13494 Style::toggleStatusBar(unsigned int xid)
13495 {
13496     static unsigned int lastXid  = 0;
13497     static struct timeval lastTime = {0, 0};
13498 
13499     if (diffTime(&lastTime) || lastXid != xid) {
13500         QMainWindow *win = getWindow(xid);
13501         if (win) {
13502             toggleStatusBar(win);
13503         }
13504     }
13505     lastXid = xid;
13506 }
13507 
13508 void
13509 Style::compositingToggled()
13510 {
13511     foreach (QWidget *widget, QApplication::topLevelWidgets()) {
13512         widget->update();
13513     }
13514 }
13515 
13516 void
13517 Style::toggleMenuBar(QMainWindow *window)
13518 {
13519     bool triggeredAction(false);
13520 
13521 #ifdef QTC_QT4_ENABLE_KDE
13522     if (qobject_cast<KXmlGuiWindow*>(window)) {
13523         KActionCollection *collection =
13524             static_cast<KXmlGuiWindow*>(window)->actionCollection();
13525         QAction *act = collection ? collection->action(KStandardAction::name(KStandardAction::ShowMenubar)) : 0L;
13526         if (act) {
13527             act->trigger();
13528             triggeredAction = true;
13529         }
13530     }
13531 #endif
13532     if (!triggeredAction) {
13533         QWidget *menubar = window->menuWidget();
13534         if (m_saveMenuBarStatus) {
13535             qtcSetMenuBarHidden(appName, menubar->isVisible());
13536         }
13537         window->menuWidget()->setHidden(menubar->isVisible());
13538     }
13539 }
13540 
13541 void Style::toggleStatusBar(QMainWindow *window)
13542 {
13543     bool triggeredAction(false);
13544 
13545 #ifdef QTC_QT4_ENABLE_KDE
13546     if (qobject_cast<KXmlGuiWindow*>(window)) {
13547         KActionCollection *collection = static_cast<KXmlGuiWindow*>(window)->actionCollection();
13548         QAction *act = collection ? collection->action(KStandardAction::name(KStandardAction::ShowStatusbar)) : 0L;
13549         if (act) {
13550             act->trigger();
13551             triggeredAction = true;
13552             // emitStatusBarState(true); // TODO: ???
13553         }
13554     }
13555 #endif
13556     if (!triggeredAction) {
13557         QList<QStatusBar*> sb = getStatusBars(window);
13558 
13559         if (sb.count()) {
13560             if (m_saveStatusBarStatus)
13561                 qtcSetStatusBarHidden(appName, sb.first()->isVisible());
13562             foreach (QStatusBar *statusBar, sb) {
13563                 statusBar->setHidden(statusBar->isVisible());
13564             }
13565             emitStatusBarState(sb.first());
13566         }
13567     }
13568 }
13569 
13570 void Style::emitMenuSize(QWidget *w, unsigned short size, bool force)
13571 {
13572     // DO NOT condition compile on QTC_ENABLE_X11.
13573     // There's no direct linkage on X11 and the following code will just do
13574     // nothing if X11 is not enabled (either at compile time or at run time).
13575     QTC_RET_IF_FAIL(qtcX11Enabled());
13576 
13577     if (WId wid = qtcGetWid(w->window())) {
13578         static const char *constMenuSizeProperty="qtcMenuSize";
13579         unsigned short oldSize = 2000;
13580         if (!force) {
13581             QVariant prop(w->property(constMenuSizeProperty));
13582 
13583             if (prop.isValid()) {
13584                 bool ok;
13585                 oldSize = prop.toUInt(&ok);
13586                 if (!ok) {
13587                     oldSize = 2000;
13588                 }
13589             }
13590         }
13591 
13592         if (oldSize != size) {
13593             w->setProperty(constMenuSizeProperty, size);
13594             qtcX11SetMenubarSize(wid, size);
13595             getKWinDBus()->call(QDBus::NoBlock, "menuBarSize",
13596                                 (unsigned int)wid, (int)size);
13597         }
13598     }
13599 }
13600 
13601 void Style::emitStatusBarState(QStatusBar *sb)
13602 {
13603     if (opts.statusbarHiding & HIDE_KWIN) {
13604         getKWinDBus()->call(QDBus::NoBlock, "statusBarState",
13605                             (unsigned int)qtcGetWid(sb->window()),
13606                             sb->isVisible());
13607     }
13608 }
13609 }