Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/styles/qstylesheetstyle.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    8282#include <QAbstractSpinBox>
    8383#include <QLabel>
     84#include "qdrawutil.h"
    8485
    8586#include <limits.h>
     87#include <QtGui/qtoolbar.h>
    8688
    8789QT_BEGIN_NAMESPACE
     
    214216    PseudoElement_ViewItemIndicator,
    215217    PseudoElement_ScrollAreaCorner,
     218    PseudoElement_TabBarTabCloseButton,
    216219    NumPseudoElements
    217220};
     
    223226
    224227static const PseudoElementInfo knownPseudoElements[NumPseudoElements] = {
    225     { QStyle::SC_None, "", },
     228    { QStyle::SC_None, "" },
    226229    { QStyle::SC_None, "down-arrow" },
    227230    { QStyle::SC_None, "up-arrow" },
     
    300303    { QStyle::SC_None, "icon" },
    301304    { QStyle::SC_None, "text" },
    302     { QStyle::SC_None, "indicator" } ,
    303     { QStyle::SC_None, "corner" }
     305    { QStyle::SC_None, "indicator" },
     306    { QStyle::SC_None, "corner" },
     307    { QStyle::SC_None, "close-button" },
    304308};
    305309
     
    313317            cuts[i] = -1;
    314318    }
    315     QPixmap topEdge, bottomEdge, leftEdge, rightEdge, middle;
    316     QRect topEdgeRect, bottomEdgeRect, leftEdgeRect, rightEdgeRect, middleRect;
    317     QRect topLeftCorner, topRightCorner, bottomRightCorner, bottomLeftCorner;
    318319    int cuts[4];
    319320    QPixmap pixmap;
    320321    QImage image;
    321322    QCss::TileMode horizStretch, vertStretch;
    322 
    323     void cutBorderImage();
    324323};
    325324
     
    872871: features(0), hasFont(false), pal(0), b(0), bg(0), bd(0), ou(0), geo(0), p(0), img(0), clipset(0)
    873872{
    874     QPalette palette = qApp->palette(); // ###: ideally widget's palette
     873    QPalette palette = QApplication::palette(); // ###: ideally widget's palette
    875874    ValueExtractor v(declarations, palette);
    876875    features = v.extractStyleFeatures();
     
    11231122            bi->cuts[i] = int(border()->borders[i]);
    11241123    }
    1125     bi->cutBorderImage();
    1126 }
    1127 
    1128 void QStyleSheetBorderImageData::cutBorderImage()
    1129 {
    1130     const int w = pixmap.width();
    1131     const int h = pixmap.height();
    1132     const int &l = cuts[LeftEdge], &r = cuts[RightEdge],
    1133               &t = cuts[TopEdge], &b = cuts[BottomEdge];
    1134 
    1135     topEdgeRect = QRect(l, 0, w - r - l, t);
    1136     bottomEdgeRect = QRect(l, h - b, w - l - r, b);
    1137     if (horizStretch != TileMode_Stretch) {
    1138         if (topEdgeRect.isValid())
    1139             topEdge = pixmap.copy(topEdgeRect).scaledToHeight(t);
    1140         if (bottomEdgeRect.isValid())
    1141             bottomEdge = pixmap.copy(bottomEdgeRect).scaledToHeight(b);
    1142     }
    1143 
    1144     leftEdgeRect = QRect(0, t, l, h - b - t);
    1145     rightEdgeRect = QRect(w - r, t, r, h - t- b);
    1146     if (vertStretch != TileMode_Stretch) {
    1147         if (leftEdgeRect.isValid())
    1148             leftEdge = pixmap.copy(leftEdgeRect).scaledToWidth(l);
    1149         if (rightEdgeRect.isValid())
    1150             rightEdge = pixmap.copy(rightEdgeRect).scaledToWidth(r);
    1151     }
    1152 
    1153     middleRect = QRect(l, t, w - r -l, h - t - b);
    1154     if (middleRect.isValid()
    1155         && !(horizStretch == TileMode_Stretch && vertStretch == TileMode_Stretch)) {
    1156         middle = pixmap.copy(middleRect);
    1157     }
    1158 }
    1159 
    1160 static void qDrawCenterTiledPixmap(QPainter *p, const QRectF& r, const QPixmap& pix)
    1161 {
    1162     p->drawTiledPixmap(r, pix, QPoint(pix.width() - int(r.width())%pix.width(),
    1163                                       pix.height() - int(r.height())%pix.height()));
    1164 }
    1165 
    1166 // Note: Round is not supported
     1124}
     1125
    11671126void QRenderRule::drawBorderImage(QPainter *p, const QRect& rect)
    11681127{
    1169     setClip(p, rect);
    1170     const QRectF br(rect);
    1171     const int *borders = border()->borders;
    1172     const int &l = borders[LeftEdge], &r = borders[RightEdge],
    1173               &t = borders[TopEdge],  &b = borders[BottomEdge];
    1174     QRectF pr = br.adjusted(l, t, -r, -b);
     1128    static const Qt::TileRule tileMode2TileRule[] = {
     1129        Qt::StretchTile, Qt::RoundTile, Qt::StretchTile, Qt::RepeatTile, Qt::StretchTile };
     1130
     1131    const QStyleSheetBorderImageData *borderImageData = border()->borderImage();
     1132    const int *targetBorders = border()->borders;
     1133    const int *sourceBorders = borderImageData->cuts;
     1134    QMargins sourceMargins(sourceBorders[LeftEdge], sourceBorders[TopEdge],
     1135                           sourceBorders[RightEdge], sourceBorders[BottomEdge]);
     1136    QMargins targetMargins(targetBorders[LeftEdge], targetBorders[TopEdge],
     1137                           targetBorders[RightEdge], targetBorders[BottomEdge]);
    11751138
    11761139    bool wasSmoothPixmapTransform = p->renderHints() & QPainter::SmoothPixmapTransform;
    11771140    p->setRenderHint(QPainter::SmoothPixmapTransform);
    1178 
    1179     const QStyleSheetBorderImageData *bi = border()->borderImage();
    1180     const QPixmap& pix = bi->pixmap;
    1181     const int *c = bi->cuts;
    1182     QRectF tlc(0, 0, c[LeftEdge], c[TopEdge]);
    1183     if (tlc.isValid())
    1184         p->drawPixmap(QRectF(br.topLeft(), QSizeF(l, t)), pix, tlc);
    1185     QRectF trc(pix.width() - c[RightEdge], 0, c[RightEdge], c[TopEdge]);
    1186     if (trc.isValid())
    1187         p->drawPixmap(QRectF(br.left() + br.width() - r, br.y(), r, t), pix, trc);
    1188     QRectF blc(0, pix.height() - c[BottomEdge], c[LeftEdge], c[BottomEdge]);
    1189     if (blc.isValid())
    1190         p->drawPixmap(QRectF(br.x(), br.y() + br.height() - b, l, b), pix, blc);
    1191     QRectF brc(pix.width() - c[RightEdge], pix.height() - c[BottomEdge],
    1192                c[RightEdge], c[BottomEdge]);
    1193     if (brc.isValid())
    1194         p->drawPixmap(QRectF(br.x() + br.width() - r, br.y() + br.height() - b, r, b),
    1195                       pix, brc);
    1196 
    1197     QRectF topEdgeRect(br.x() + l, br.y(), pr.width(), t);
    1198     QRectF bottomEdgeRect(br.x() + l, br.y() + br.height() - b, pr.width(), b);
    1199 
    1200     switch (bi->horizStretch) {
    1201     case TileMode_Stretch:
    1202         if (bi->topEdgeRect.isValid())
    1203             p->drawPixmap(topEdgeRect, pix, bi->topEdgeRect);
    1204         if (bi->bottomEdgeRect.isValid())
    1205             p->drawPixmap(bottomEdgeRect, pix, bi->bottomEdgeRect);
    1206         if (bi->middleRect.isValid()) {
    1207             if (bi->vertStretch == TileMode_Stretch)
    1208                 p->drawPixmap(pr, pix, bi->middleRect);
    1209             else if (bi->vertStretch == TileMode_Repeat) {
    1210                 QPixmap scaled = bi->middle.scaled(int(pr.width()), bi->middle.height());
    1211                 qDrawCenterTiledPixmap(p, pr, scaled);
    1212             }
    1213         }
    1214         break;
    1215     case TileMode_Repeat:
    1216         if (!bi->topEdge.isNull() && !topEdgeRect.isEmpty()) {
    1217             QPixmap scaled = bi->topEdge.scaled(bi->topEdge.width(), t);
    1218             qDrawCenterTiledPixmap(p, topEdgeRect, scaled);
    1219         }
    1220         if (!bi->bottomEdge.isNull() && !bottomEdgeRect.isEmpty()) {
    1221             QPixmap scaled = bi->bottomEdge.scaled(bi->bottomEdge.width(), b);
    1222             qDrawCenterTiledPixmap(p, bottomEdgeRect, scaled);
    1223         }
    1224         if (bi->middleRect.isValid()) {
    1225             if (bi->vertStretch == TileMode_Repeat) {
    1226                 qDrawCenterTiledPixmap(p, pr, bi->middle);
    1227             } else if (bi->vertStretch == TileMode_Stretch) {
    1228                 QPixmap scaled = bi->middle.scaled(bi->middle.width(), int(pr.height()));
    1229                 qDrawCenterTiledPixmap(p, pr, scaled);
    1230             }
    1231         }
    1232         break;
    1233     case TileMode_Round:
    1234         if (!bi->topEdge.isNull()) {
    1235             int rwh = (int)pr.width()/ceil(pr.width()/bi->topEdge.width());
    1236             QPixmap scaled = bi->topEdge.scaled(rwh, bi->topEdge.height());
    1237             int blank = int(pr.width()) % rwh;
    1238             p->drawTiledPixmap(QRectF(br.x() + l + blank/2, br.y(), pr.width() - blank, t),
    1239                                scaled);
    1240         }
    1241         if (!bi->bottomEdge.isNull()) {
    1242             int rwh = (int) pr.width()/ceil(pr.width()/bi->bottomEdge.width());
    1243             QPixmap scaled = bi->bottomEdge.scaled(rwh, bi->bottomEdge.height());
    1244             int blank = int(pr.width()) % rwh;
    1245             p->drawTiledPixmap(QRectF(br.x() + l+ blank/2, br.y()+br.height()-b,
    1246                                       pr.width() - blank, b), scaled);
    1247         }
    1248         break;
    1249     default:
    1250         break;
    1251     }
    1252 
    1253     QRectF leftEdgeRect(br.x(), br.y() + t, l, pr.height());
    1254     QRectF rightEdgeRect(br.x() + br.width()- r, br.y() + t, r, pr.height());
    1255 
    1256     switch (bi->vertStretch) {
    1257     case TileMode_Stretch:
    1258          if (bi->leftEdgeRect.isValid())
    1259               p->drawPixmap(leftEdgeRect, pix, bi->leftEdgeRect);
    1260         if (bi->rightEdgeRect.isValid())
    1261             p->drawPixmap(rightEdgeRect, pix, bi->rightEdgeRect);
    1262         break;
    1263     case TileMode_Repeat:
    1264         if (!bi->leftEdge.isNull() && !leftEdgeRect.isEmpty()) {
    1265             QPixmap scaled = bi->leftEdge.scaled(l, bi->leftEdge.height());
    1266             qDrawCenterTiledPixmap(p, leftEdgeRect, scaled);
    1267         }
    1268         if (!bi->rightEdge.isNull() && !rightEdgeRect.isEmpty()) {
    1269             QPixmap scaled = bi->rightEdge.scaled(r, bi->rightEdge.height());
    1270             qDrawCenterTiledPixmap(p, rightEdgeRect, scaled);
    1271         }
    1272         break;
    1273     case TileMode_Round:
    1274         if (!bi->leftEdge.isNull()) {
    1275             int rwh = (int) pr.height()/ceil(pr.height()/bi->leftEdge.height());
    1276             QPixmap scaled = bi->leftEdge.scaled(bi->leftEdge.width(), rwh);
    1277             int blank = int(pr.height()) % rwh;
    1278             p->drawTiledPixmap(QRectF(br.x(), br.y() + t + blank/2, l, pr.height() - blank),
    1279                                scaled);
    1280         }
    1281         if (!bi->rightEdge.isNull()) {
    1282             int rwh = (int) pr.height()/ceil(pr.height()/bi->rightEdge.height());
    1283             QPixmap scaled = bi->rightEdge.scaled(bi->rightEdge.width(), rwh);
    1284             int blank = int(pr.height()) % rwh;
    1285             p->drawTiledPixmap(QRectF(br.x() + br.width() - r, br.y()+t+blank/2, r,
    1286                                       pr.height() - blank), scaled);
    1287         }
    1288         break;
    1289     default:
    1290         break;
    1291     }
    1292 
     1141    qDrawBorderPixmap(p, rect, targetMargins, borderImageData->pixmap,
     1142                      QRect(QPoint(), borderImageData->pixmap.size()), sourceMargins,
     1143                      QTileRules(tileMode2TileRule[borderImageData->horizStretch], tileMode2TileRule[borderImageData->vertStretch]));
    12931144    p->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothPixmapTransform);
    1294     unsetClip(p);
    12951145}
    12961146
     
    13311181    QRect r = originRect(rect, background()->origin);
    13321182    QRect aligned = QStyle::alignedRect(Qt::LeftToRight, background()->position, bgp.size(), r);
    1333     QRect inter = aligned.intersected(r);
     1183    QRect inter = aligned.translated(-off).intersected(r);
    13341184
    13351185    switch (background()->repeat) {
     
    14521302void QRenderRule::drawBackground(QPainter *p, const QRect& rect, const QPoint& off)
    14531303{
    1454     setClip(p, borderRect(rect));
    14551304    QBrush brush = hasBackground() ? background()->brush : QBrush();
    14561305    if (brush.style() == Qt::NoBrush)
     
    14601309        Origin origin = hasBackground() ? background()->clip : Origin_Border;
    14611310        // ### fix for  gradients
    1462         p->fillRect(originRect(rect, origin), brush);
     1311        const QPainterPath &borderPath = borderClip(originRect(rect, origin));
     1312        if (!borderPath.isEmpty()) {
     1313            // Drawn intead of being used as clipping path for better visual quality
     1314            bool wasAntialiased = p->renderHints() & QPainter::Antialiasing;
     1315            p->setRenderHint(QPainter::Antialiasing);
     1316            p->fillPath(borderPath, brush);
     1317            p->setRenderHint(QPainter::Antialiasing, wasAntialiased);
     1318        } else {
     1319            p->fillRect(originRect(rect, origin), brush);
     1320        }
    14631321    }
    14641322
    14651323    drawBackgroundImage(p, rect, off);
    1466     unsetClip(p);
    14671324}
    14681325
     
    15261383         * to be transparent when we have a transparent background or border image */
    15271384        if ((hasBackground() && background()->isTransparent())
    1528             || (hasBorder() && border()->hasBorderImage() && border()->borderImage()->middleRect.isValid()))
     1385            || (hasBorder() && border()->hasBorderImage() && !border()->borderImage()->pixmap.isNull()))
    15291386            p->setBrush(cg, w->backgroundRole(), Qt::NoBrush);
    15301387    }
     
    17091566            parser.init(wid->styleSheet());
    17101567            if (!parser.parse(&ss)) {
    1711                 parser.init(QLatin1String("* {") + wid->styleSheet() + QLatin1String("}"));
     1568                parser.init(QLatin1String("* {") + wid->styleSheet() + QLatin1Char('}'));
    17121569                if (!parser.parse(&ss))
    17131570                   qWarning("Could not parse stylesheet of widget %p", wid);
     
    19031760
    19041761            if (!(complex->activeSubControls & subControl))
    1905                 state = QStyle::State(state & (QStyle::State_Enabled | QStyle::State_Horizontal));
     1762                state &= (QStyle::State_Enabled | QStyle::State_Horizontal | QStyle::State_HasFocus);
    19061763        }
    19071764
     
    21582015        } else
    21592016#endif
    2160         { } // required for the above ifdef'ery
     2017        if (const QFrame *frm = qobject_cast<const QFrame *>(w)) {
     2018            if (frm->lineWidth() == 0)
     2019                extraClass |= PseudoClass_Frameless;
     2020        }
    21612021    }
    21622022
     
    27382598        widget->style()->polish(widget);
    27392599        QEvent event(QEvent::StyleChange);
    2740         qApp->sendEvent(widget, &event);
     2600        QApplication::sendEvent(widget, &event);
    27412601        widget->update();
    27422602        widget->updateGeometry();
     
    27842644    if (base)
    27852645        return base;
    2786     if (QStyleSheetStyle *me = qobject_cast<QStyleSheetStyle *>(qApp->style()))
     2646    if (QStyleSheetStyle *me = qobject_cast<QStyleSheetStyle *>(QApplication::style()))
    27872647        return me->base;
    2788     return qApp->style();
     2648    return QApplication::style();
    27892649}
    27902650
     
    28562716        if ((rule.hasBorder() && rule.border()->hasBorderImage())
    28572717            || (rule.hasBackground() && !rule.background()->pixmap.isNull())) {
    2858             QObject::disconnect(sa->horizontalScrollBar(), SIGNAL(valueChanged(int)),
    2859                              sa, SLOT(update()));
    2860             QObject::disconnect(sa->verticalScrollBar(), SIGNAL(valueChanged(int)),
    2861                              sa, SLOT(update()));
    28622718            QObject::connect(sa->horizontalScrollBar(), SIGNAL(valueChanged(int)),
    2863                              sa, SLOT(update()));
     2719                             sa, SLOT(update()), Qt::UniqueConnection);
    28642720            QObject::connect(sa->verticalScrollBar(), SIGNAL(valueChanged(int)),
    2865                              sa, SLOT(update()));
     2721                             sa, SLOT(update()), Qt::UniqueConnection);
    28662722        }
    28672723    }
     
    28772733    if (rule.hasDrawable() || rule.hasBox()) {
    28782734        if (w->metaObject() == &QWidget::staticMetaObject
    2879 #ifndef QT_NO_MENUBAR
    2880               || qobject_cast<QMenuBar *>(w)
    2881 #endif
    2882 #ifndef QT_NO_MENU
    2883               || qobject_cast<QMenu *>(w)
    2884 #endif
    28852735#ifndef QT_NO_ITEMVIEWS
    28862736              || qobject_cast<QHeaderView *>(w)
     
    28972747#ifndef QT_NO_MDIAREA
    28982748              || qobject_cast<QMdiSubWindow *>(w)
     2749#endif
     2750#ifndef QT_NO_MENUBAR
     2751              || qobject_cast<QMenuBar *>(w)
    28992752#endif
    29002753              || qobject_cast<QDialog *>(w)) {
     
    30142867                rule.configurePalette(&cmbOpt.palette, QPalette::ButtonText, QPalette::Button);
    30152868                bool customDropDown = (opt->subControls & QStyle::SC_ComboBoxArrow)
    3016                                       && hasStyleRule(w, PseudoElement_ComboBoxDropDown);
     2869                                && (hasStyleRule(w, PseudoElement_ComboBoxDropDown) || hasStyleRule(w, PseudoElement_ComboBoxArrow));
    30172870                if (customDropDown)
    30182871                    cmbOpt.subControls &= ~QStyle::SC_ComboBoxArrow;
     
    30512904            QStyleOptionSpinBox spinOpt(*spin);
    30522905            rule.configurePalette(&spinOpt.palette, QPalette::ButtonText, QPalette::Button);
     2906            rule.configurePalette(&spinOpt.palette, QPalette::Text, QPalette::Base);
    30532907            spinOpt.rect = rule.borderRect(opt->rect);
    30542908            bool customUp = true, customDown = true;
    30552909            QRenderRule upRule = renderRule(w, opt, PseudoElement_SpinBoxUpButton);
    30562910            QRenderRule downRule = renderRule(w, opt, PseudoElement_SpinBoxDownButton);
    3057             bool upRuleMatch = upRule.hasGeometry();
    3058             bool downRuleMatch = downRule.hasGeometry();
     2911            bool upRuleMatch = upRule.hasGeometry() || upRule.hasPosition();
     2912            bool downRuleMatch = downRule.hasGeometry() || downRule.hasPosition();
    30592913            if (rule.hasNativeBorder() && !upRuleMatch && !downRuleMatch) {
    30602914                rule.drawBackgroundImage(p, spinOpt.rect);
    30612915                customUp = (opt->subControls & QStyle::SC_SpinBoxUp)
    3062                            && hasStyleRule(w, PseudoElement_SpinBoxUpButton);
     2916                        && (hasStyleRule(w, PseudoElement_SpinBoxUpButton) || hasStyleRule(w, PseudoElement_UpArrow));
    30632917                if (customUp)
    30642918                    spinOpt.subControls &= ~QStyle::SC_SpinBoxUp;
    30652919                customDown = (opt->subControls & QStyle::SC_SpinBoxDown)
    3066                              && hasStyleRule(w, PseudoElement_SpinBoxDownButton);
     2920                        && (hasStyleRule(w, PseudoElement_SpinBoxDownButton) || hasStyleRule(w, PseudoElement_DownArrow));
    30672921                if (customDown)
    30682922                    spinOpt.subControls &= ~QStyle::SC_SpinBoxDown;
     
    31903044            QStyleOptionToolButton toolOpt(*tool);
    31913045            rule.configurePalette(&toolOpt.palette, QPalette::ButtonText, QPalette::Button);
     3046            toolOpt.font = rule.font.resolve(toolOpt.font);
    31923047            toolOpt.rect = rule.borderRect(opt->rect);
    31933048            bool customArrow = (tool->features & (QStyleOptionToolButton::HasMenu | QStyleOptionToolButton::MenuButtonPopup));
     
    32823137            rule.drawRule(p, opt->rect);
    32833138
    3284             QRenderRule subRule = renderRule(w, opt, PseudoElement_SliderGroove);
    3285             if (!subRule.hasDrawable()) {
    3286                 baseStyle()->drawComplexControl(cc, slider, p, w);
    3287                 return;
     3139            QRenderRule grooveSubRule = renderRule(w, opt, PseudoElement_SliderGroove);
     3140            QRenderRule handleSubRule = renderRule(w, opt, PseudoElement_SliderHandle);
     3141            if (!grooveSubRule.hasDrawable()) {
     3142                QStyleOptionSlider slOpt(*slider);
     3143                bool handleHasRule = handleSubRule.hasDrawable();
     3144                // If the style specifies a different handler rule, draw the groove without the handler.
     3145                if (handleHasRule)
     3146                    slOpt.subControls &= ~SC_SliderHandle;
     3147                baseStyle()->drawComplexControl(cc, &slOpt, p, w);
     3148                if (!handleHasRule)
     3149                    return;
    32883150            }
    32893151
    32903152            QRect gr = subControlRect(cc, opt, SC_SliderGroove, w);
    32913153            if (slider->subControls & SC_SliderGroove) {
    3292                 subRule.drawRule(p, gr);
     3154                grooveSubRule.drawRule(p, gr);
    32933155            }
    32943156
    32953157            if (slider->subControls & SC_SliderHandle) {
    3296                 QRenderRule subRule = renderRule(w, opt, PseudoElement_SliderHandle);
    32973158                QRect hr = subControlRect(cc, opt, SC_SliderHandle, w);
    32983159
     
    33153176                }
    33163177
    3317                 subRule.drawRule(p, subRule.boxRect(hr, Margin));
     3178                handleSubRule.drawRule(p, grooveSubRule.boxRect(hr, Margin));
    33183179            }
    33193180
     
    33493210                    QRect rect = subRule.boxRect(subControlRect(CC_MdiControls, opt, control, w), Margin);
    33503211                    subRule.drawRule(p, rect);
    3351                     QIcon icon = standardIcon(subControlIcon(layoutButton));
     3212                    QIcon icon = standardIcon(subControlIcon(layoutButton), opt);
    33523213                    icon.paint(p, subRule.contentsRect(rect), Qt::AlignCenter);
    33533214                } else {
     
    34653326
    34663327    case CE_PushButton:
    3467         ParentStyle::drawControl(ce, opt, p, w);
    3468         return;
    3469 
     3328        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
     3329            if (rule.hasDrawable() || rule.hasBox() || rule.hasPosition() || rule.hasPalette() ||
     3330                    ((btn->features & QStyleOptionButton::HasMenu) && hasStyleRule(w, PseudoElement_PushButtonMenuIndicator))) {
     3331                ParentStyle::drawControl(ce, opt, p, w);
     3332                return;
     3333            }
     3334        }
     3335        break;
    34703336    case CE_PushButtonBevel:
    34713337        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
     
    35103376                Qt::Alignment textAlignment = rule.position()->textAlignment;
    35113377                QRect textRect = button->rect;
    3512                 uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
     3378                uint tf = Qt::TextShowMnemonic;
     3379                const uint verticalAlignMask = Qt::AlignVCenter | Qt::AlignTop | Qt::AlignLeft;
     3380                tf |= (textAlignment & verticalAlignMask) ? (textAlignment & verticalAlignMask) : Qt::AlignVCenter;
    35133381                if (!styleHint(SH_UnderlineShortcut, button, w))
    35143382                    tf |= Qt::TextHideMnemonic;
     
    36193487    case CE_MenuBarEmptyArea:
    36203488        if (rule.hasDrawable()) {
     3489            // Drawn by PE_Widget
    36213490            return;
    36223491        }
     
    37363605                    drawPrimitive(arrow, &mi, p, w);
    37373606                }
    3738             } else if (hasStyleRule(w, PseudoElement_MenuCheckMark)) {
     3607            } else if (hasStyleRule(w, PseudoElement_MenuCheckMark) || hasStyleRule(w, PseudoElement_MenuRightArrow)) {
    37393608                QWindowsStyle::drawControl(ce, &mi, p, w);
     3609                if (mi.checkType != QStyleOptionMenuItem::NotCheckable && !mi.checked) {
     3610                    // We have a style defined, but QWindowsStyle won't draw anything if not checked.
     3611                    // So we mimick what QWindowsStyle would do.
     3612                    int checkcol = qMax<int>(mi.maxIconWidth, QWindowsStylePrivate::windowsCheckMarkWidth);
     3613                    QRect vCheckRect = visualRect(opt->direction, mi.rect, QRect(mi.rect.x(), mi.rect.y(), checkcol, mi.rect.height()));
     3614                    if (mi.state.testFlag(State_Enabled) && mi.state.testFlag(State_Selected)) {
     3615                        qDrawShadePanel(p, vCheckRect, mi.palette, true, 1, &mi.palette.brush(QPalette::Button));
     3616                    } else {
     3617                        QBrush fill(mi.palette.light().color(), Qt::Dense4Pattern);
     3618                        qDrawShadePanel(p, vCheckRect, mi.palette, true, 1, &fill);
     3619                    }
     3620                    QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark);
     3621                    if (subSubRule.hasDrawable()) {
     3622                        QStyleOptionMenuItem newMi(mi);
     3623                        newMi.rect = visualRect(opt->direction, mi.rect, QRect(mi.rect.x() + QWindowsStylePrivate::windowsItemFrame,
     3624                                                                               mi.rect.y() + QWindowsStylePrivate::windowsItemFrame,
     3625                                                                               checkcol - 2 * QWindowsStylePrivate::windowsItemFrame,
     3626                                                                               mi.rect.height() - 2 * QWindowsStylePrivate::windowsItemFrame));
     3627                        drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w);
     3628                    }
     3629                }
    37403630            } else {
    37413631                if (rule.hasDrawable() && !subRule.hasDrawable() && !(opt->state & QStyle::State_Selected)) {
     
    37693659                QCommonStyle::drawControl(ce, &mi, p, w);
    37703660            } else {
     3661                if (rule.hasDrawable() && !(opt->state & QStyle::State_Selected)) {
     3662                    // So that the menu bar background is not hidden by the items
     3663                    mi.palette.setColor(QPalette::Window, Qt::transparent);
     3664                    mi.palette.setColor(QPalette::Button, Qt::transparent);
     3665                }
    37713666                baseStyle()->drawControl(ce, &mi, p, w);
    37723667            }
     
    37903685                QRect iconRect(editRect);
    37913686                iconRect.setWidth(cb->iconSize.width());
    3792                 iconRect = alignedRect(QApplication::layoutDirection(),
    3793                                                            Qt::AlignLeft | Qt::AlignVCenter,
    3794                                                            iconRect.size(), editRect);
     3687                iconRect = alignedRect(cb->direction,
     3688                                       Qt::AlignLeft | Qt::AlignVCenter,
     3689                                       iconRect.size(), editRect);
    37953690                drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap);
    37963691
     
    38023697            if (!cb->currentText.isEmpty() && !cb->editable) {
    38033698                drawItemText(p, editRect.adjusted(0, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, cb->palette,
    3804                              cb->state & State_Enabled, cb->currentText);
     3699                             cb->state & State_Enabled, cb->currentText, QPalette::Text);
    38053700            }
    38063701            p->restore();
     
    40933988            if (subRule.hasFont)
    40943989                p->setFont(subRule.font);
    4095             if (subRule.hasBox()) {
     3990            if (subRule.hasBox() || !subRule.hasNativeBorder()) {
    40963991                tabCopy.rect = ce == CE_TabBarTabShape ? subRule.borderRect(r)
    40973992                                                       : subRule.contentsRect(r);
     
    41654060                frmOpt.rect = rule.borderRect(frmOpt.rect);
    41664061                baseStyle()->drawControl(ce, &frmOpt, p, w);
    4167             } else {
    4168                 rule.drawBorder(p, rule.borderRect(opt->rect));
    4169             }
     4062            }
     4063            // else, borders are already drawn in PE_Widget
    41704064        }
    41714065        return;
     
    42214115
    42224116    switch (pe) {
    4223     case PE_PanelStatusBar:
    4224         if (rule.hasDrawable()) {
    4225             rule.drawRule(p, opt->rect);
    4226             return;
    4227         }
    4228         break;
    42294117
    42304118    case PE_FrameStatusBar: {
     
    43174205                if (!spinboxRule.hasNativeBorder() || !spinboxRule.baseStyleCanDraw())
    43184206                    return;
     4207                rule = spinboxRule;
    43194208            }
    43204209#endif
     
    43384227
    43394228    case PE_Widget:
    4340         if (!rule.hasBackground()) {
     4229        if (!rule.hasDrawable()) {
    43414230            QWidget *container = containerWidget(w);
    43424231            if (autoFillDisabledWidgets->contains(container)
     
    43484237            break;
    43494238        }
    4350 
    43514239#ifndef QT_NO_SCROLLAREA
    43524240        if (const QAbstractScrollArea *sa = qobject_cast<const QAbstractScrollArea *>(w)) {
    43534241            const QAbstractScrollAreaPrivate *sap = sa->d_func();
    43544242            rule.drawBackground(p, opt->rect, sap->contentsOffset());
    4355         } else
     4243            if (rule.hasBorder())
     4244                rule.drawBorder(p, rule.borderRect(opt->rect));
     4245            break;
     4246        }
    43564247#endif
    4357         {
    4358             rule.drawBackground(p, opt->rect);
    4359         }
    4360 
     4248    //fall tghought
     4249    case PE_PanelMenu:
     4250    case PE_PanelStatusBar:
     4251        if(rule.hasDrawable()) {
     4252            rule.drawRule(p, opt->rect);
     4253            return;
     4254        }
     4255    break;
     4256
     4257    case PE_PanelMenuBar:
     4258    if (rule.hasDrawable()) {
     4259        // Drawn by PE_Widget
    43614260        return;
    4362 
    4363     case PE_FrameMenu:
    4364     case PE_PanelMenuBar:
    4365         if (!rule.hasNativeBorder()) {
    4366             rule.drawBorder(p, rule.borderRect(opt->rect));
    4367             return;
    4368         }
    4369         break;
     4261    }
     4262    break;
    43704263
    43714264    case PE_IndicatorToolBarSeparator:
     
    44114304                subRule.drawRule(p, opt->rect);
    44124305            } else {
    4413                 QStyleOptionViewItemV2 v2Copy(*v2);
    4414                 if (v2->showDecorationSelected) {
    4415                     QRenderRule subRule2 = renderRule(w, opt, PseudoElement_ViewItem);
    4416                     if (v2->state & QStyle::State_Selected) {
    4417                         subRule2.configurePalette(&v2Copy.palette, QPalette::NoRole, QPalette::Highlight);
    4418                     } else if (v2->features & QStyleOptionViewItemV2::Alternate) {
    4419                         subRule2.configurePalette(&v2Copy.palette, QPalette::NoRole, QPalette::AlternateBase);
    4420                     } else if (subRule2.hasBackground()) {
    4421                         p->fillRect(v2->rect, subRule2.background()->brush);
    4422                     }
    4423                 } else if (v2->features & QStyleOptionViewItemV2::Alternate) {
    4424                     quint64 pc = v2->state & QStyle::State_Enabled ? PseudoClass_Enabled : PseudoClass_Disabled;
    4425                     pc |= PseudoClass_Alternate;
    4426                     QRenderRule subRule2 = renderRule(w, PseudoElement_ViewItem, pc);
    4427                     subRule2.configurePalette(&v2Copy.palette, QPalette::NoRole, QPalette::AlternateBase);
    4428                 }
    4429                 baseStyle()->drawPrimitive(pe, &v2Copy, p, w);
     4306                baseStyle()->drawPrimitive(pe, v2, p, w);
    44304307            }
    44314308        }
     
    44614338            if (subRule.hasNativeBorder()) {
    44624339                subRule.drawBackground(p, opt->rect);
    4463                 QStyleOptionTabWidgetFrame frmCopy(*frm);
     4340                QStyleOptionTabWidgetFrameV2 frmCopy(*frm);
    44644341                subRule.configurePalette(&frmCopy.palette, QPalette::WindowText, QPalette::Window);
    44654342                baseStyle()->drawPrimitive(pe, &frmCopy, p, w);
     
    44924369
    44934370    case PE_PanelItemViewItem:
    4494         if (!styleHint(SH_ItemView_ShowDecorationSelected, opt, w)) {
    4495             rect = subElementRect(QStyle::SE_ItemViewItemText,  opt, w)
    4496                    | subElementRect(QStyle::SE_ItemViewItemDecoration, opt, w)
    4497                    | subElementRect(QStyle::SE_ItemViewItemCheckIndicator, opt, w);
    4498         }
    4499         pseudoElement = PseudoElement_ViewItem;
    4500         break;
    4501 
    4502     case PE_PanelItemViewRow:
    4503         ParentStyle::drawPrimitive(pe, opt, p, w);
    4504         if (!styleHint(SH_ItemView_ShowDecorationSelected, opt, w))
    4505             return;
    45064371        pseudoElement = PseudoElement_ViewItem;
    45074372        break;
     
    45104375        pseudoElement = PseudoElement_ScrollAreaCorner;
    45114376        break;
     4377
     4378    case PE_IndicatorSpinDown:
     4379    case PE_IndicatorSpinMinus:
     4380        pseudoElement = PseudoElement_SpinBoxDownArrow;
     4381        break;
     4382
     4383    case PE_IndicatorSpinUp:
     4384    case PE_IndicatorSpinPlus:
     4385        pseudoElement = PseudoElement_SpinBoxUpArrow;
     4386        break;
     4387#ifndef QT_NO_TABBAR
     4388    case PE_IndicatorTabClose:
     4389        if (w)
     4390            w = w->parentWidget(); //match on the QTabBar instead of the CloseButton
     4391        pseudoElement = PseudoElement_TabBarTabCloseButton;
     4392#endif
    45124393
    45134394    default:
     
    47574638        break;
    47584639
     4640#ifndef QT_NO_TABWIDGET
    47594641    case PM_TabBarTabHSpace:
    47604642    case PM_TabBarTabVSpace:
     
    47804662        break;
    47814663
    4782     case PM_TabBarBaseOverlap:
    4783         if (hasStyleRule(w->parentWidget(), PseudoElement_TabWidgetPane)) {
     4664    case PM_TabBarBaseOverlap: {
     4665        const QWidget *tabWidget = qobject_cast<const QTabWidget *>(w) ? w : w->parentWidget();
     4666        if (hasStyleRule(tabWidget, PseudoElement_TabWidgetPane)) {
    47844667            return 0;
    47854668        }
    47864669        break;
     4670    }
     4671#endif // QT_NO_TABWIDGET
    47874672
    47884673    case PM_SliderThickness: // horizontal slider's height (sizeHint)
     
    48424727        else if (subRule.hasBox() || subRule.hasBorder()) {
    48434728            QFontMetrics fm = opt ?  opt->fontMetrics : w->fontMetrics();
    4844             return subRule.size(QSize(0, fm.lineSpacing())).height();
     4729            return subRule.size(QSize(0, fm.height())).height();
    48454730        }
    48464731        break;
     
    49274812#ifndef QT_NO_SPINBOX
    49284813        // ### hopelessly broken QAbstractSpinBox (part 2)
    4929         if (QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(w->parentWidget())) {
     4814        if (QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(w ? w->parentWidget() : 0)) {
    49304815            QRenderRule rule = renderRule(spinBox, opt);
    49314816            if (rule.hasBox() || !rule.hasNativeBorder())
     
    49744859                return QSize(sz.width(), subRule.size().height());
    49754860            } else if ((pe == PseudoElement_Item) && (subRule.hasBox() || subRule.hasBorder())) {
    4976                 int width = csz.width(), height = qMax(csz.height(), mi->fontMetrics.height());
    4977                 if (!mi->icon.isNull()) {
    4978                     int iconExtent = pixelMetric(PM_SmallIconSize);
    4979                     height = qMax(height, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height());
    4980                 }
    4981                 width += mi->tabWidth;
    4982                return subRule.boxSize(csz.expandedTo(subRule.minimumContentsSize()));
     4861                int width = csz.width();
     4862                if (mi->text.contains(QLatin1Char('\t')))
     4863                    width += 12; //as in QCommonStyle
     4864                return subRule.boxSize(subRule.adjustSize(QSize(width, csz.height())));
    49834865            }
    49844866        }
     
    52475129            s = QLatin1String("alignment");
    52485130            break;
     5131#ifndef QT_NO_TABBAR
     5132        case SH_TabBar_CloseButtonPosition:
     5133            rule = renderRule(w, opt, PseudoElement_TabBarTabCloseButton);
     5134            if (rule.hasPosition()) {
     5135                Qt::Alignment align = rule.position()->position;
     5136                if (align & Qt::AlignLeft || align & Qt::AlignTop)
     5137                    return QTabBar::LeftSide;
     5138                if (align & Qt::AlignRight || align & Qt::AlignBottom)
     5139                    return QTabBar::RightSide;
     5140            }
     5141            break;
     5142#endif
    52495143        case SH_TabBar_ElideMode: s = QLatin1String("tabbar-elide-mode"); break;
    52505144        case SH_TabBar_PreferNoArrows: s = QLatin1String("tabbar-prefer-no-arrows"); break;
     
    52535147            if (qobject_cast<const QComboBox *>(w)) {
    52545148                QAbstractItemView *view = qFindChild<QAbstractItemView *>(w);
    5255                 QRenderRule subRule = renderRule(view, PseudoElement_None);
    5256                 if (subRule.hasBox() || !subRule.hasNativeBorder())
    5257                     return QFrame::NoFrame;
     5149                if (view) {
     5150                    view->ensurePolished();
     5151                    QRenderRule subRule = renderRule(view, PseudoElement_None);
     5152                    if (subRule.hasBox() || !subRule.hasNativeBorder())
     5153                        return QFrame::NoFrame;
     5154                }
    52585155            }
    52595156#endif // QT_NO_COMBOBOX
     
    53295226            QRenderRule downRule = renderRule(w, opt, PseudoElement_SpinBoxDownButton);
    53305227            bool ruleMatch = rule.hasBox() || !rule.hasNativeBorder();
    5331             bool upRuleMatch = upRule.hasGeometry();
    5332             bool downRuleMatch = downRule.hasGeometry();
     5228            bool upRuleMatch = upRule.hasGeometry() || upRule.hasPosition();
     5229            bool downRuleMatch = downRule.hasGeometry() || upRule.hasPosition();
    53335230            if (ruleMatch || upRuleMatch || downRuleMatch) {
    53345231                switch (sc) {
     
    58225719        break;
    58235720    }
     5721    case SE_TabBarTabText:
     5722    case SE_TabBarTabLeftButton:
     5723    case SE_TabBarTabRightButton: {
     5724        QRenderRule subRule = renderRule(w, opt, PseudoElement_TabBarTab);
     5725        if (subRule.hasBox() || !subRule.hasNativeBorder()) {
     5726            return ParentStyle::subElementRect(se, opt, w);
     5727        }
     5728        break;
     5729    }
    58245730#endif // QT_NO_TABBAR
    58255731
     
    58435749bool QStyleSheetStyle::event(QEvent *e)
    58445750{
    5845     return baseStyle()->event(e) || ParentStyle::event(e);
     5751    return (baseStyle()->event(e) && e->isAccepted()) || ParentStyle::event(e);
    58465752}
    58475753
     
    58885794}
    58895795
    5890 // Returns the palette that should be used when the particular widget is focused.
    5891 // This needs to be called by some widgets that do drawing themselves instead
    5892 // of through the style.
    5893 // ### This should be removed ideally by Qt 4.5, and at least by Qt 5, and fixed
    5894 // for good by letting the style draw everything.
     5796// Polish palette that should be used for a particular widget, with particular states
     5797// (eg. :focus, :hover, ...)
     5798// this is called by widgets that paint themself in their paint event
    58955799// Returns true if there is a new palette in pal.
    5896 bool QStyleSheetStyle::focusPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal)
     5800bool QStyleSheetStyle::styleSheetPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal)
    58975801{
    58985802    if (!w || !opt || !pal)
Note: See TracChangeset for help on using the changeset viewer.