Changeset 561 for trunk/src/gui/styles/qstylesheetstyle.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/styles/qstylesheetstyle.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 82 82 #include <QAbstractSpinBox> 83 83 #include <QLabel> 84 #include "qdrawutil.h" 84 85 85 86 #include <limits.h> 87 #include <QtGui/qtoolbar.h> 86 88 87 89 QT_BEGIN_NAMESPACE … … 214 216 PseudoElement_ViewItemIndicator, 215 217 PseudoElement_ScrollAreaCorner, 218 PseudoElement_TabBarTabCloseButton, 216 219 NumPseudoElements 217 220 }; … … 223 226 224 227 static const PseudoElementInfo knownPseudoElements[NumPseudoElements] = { 225 { QStyle::SC_None, "" ,},228 { QStyle::SC_None, "" }, 226 229 { QStyle::SC_None, "down-arrow" }, 227 230 { QStyle::SC_None, "up-arrow" }, … … 300 303 { QStyle::SC_None, "icon" }, 301 304 { 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" }, 304 308 }; 305 309 … … 313 317 cuts[i] = -1; 314 318 } 315 QPixmap topEdge, bottomEdge, leftEdge, rightEdge, middle;316 QRect topEdgeRect, bottomEdgeRect, leftEdgeRect, rightEdgeRect, middleRect;317 QRect topLeftCorner, topRightCorner, bottomRightCorner, bottomLeftCorner;318 319 int cuts[4]; 319 320 QPixmap pixmap; 320 321 QImage image; 321 322 QCss::TileMode horizStretch, vertStretch; 322 323 void cutBorderImage();324 323 }; 325 324 … … 872 871 : features(0), hasFont(false), pal(0), b(0), bg(0), bd(0), ou(0), geo(0), p(0), img(0), clipset(0) 873 872 { 874 QPalette palette = qApp->palette(); // ###: ideally widget's palette873 QPalette palette = QApplication::palette(); // ###: ideally widget's palette 875 874 ValueExtractor v(declarations, palette); 876 875 features = v.extractStyleFeatures(); … … 1123 1122 bi->cuts[i] = int(border()->borders[i]); 1124 1123 } 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 1167 1126 void QRenderRule::drawBorderImage(QPainter *p, const QRect& rect) 1168 1127 { 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]); 1175 1138 1176 1139 bool wasSmoothPixmapTransform = p->renderHints() & QPainter::SmoothPixmapTransform; 1177 1140 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])); 1293 1144 p->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothPixmapTransform); 1294 unsetClip(p);1295 1145 } 1296 1146 … … 1331 1181 QRect r = originRect(rect, background()->origin); 1332 1182 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); 1334 1184 1335 1185 switch (background()->repeat) { … … 1452 1302 void QRenderRule::drawBackground(QPainter *p, const QRect& rect, const QPoint& off) 1453 1303 { 1454 setClip(p, borderRect(rect));1455 1304 QBrush brush = hasBackground() ? background()->brush : QBrush(); 1456 1305 if (brush.style() == Qt::NoBrush) … … 1460 1309 Origin origin = hasBackground() ? background()->clip : Origin_Border; 1461 1310 // ### 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 } 1463 1321 } 1464 1322 1465 1323 drawBackgroundImage(p, rect, off); 1466 unsetClip(p);1467 1324 } 1468 1325 … … 1526 1383 * to be transparent when we have a transparent background or border image */ 1527 1384 if ((hasBackground() && background()->isTransparent()) 1528 || (hasBorder() && border()->hasBorderImage() && border()->borderImage()->middleRect.isValid()))1385 || (hasBorder() && border()->hasBorderImage() && !border()->borderImage()->pixmap.isNull())) 1529 1386 p->setBrush(cg, w->backgroundRole(), Qt::NoBrush); 1530 1387 } … … 1709 1566 parser.init(wid->styleSheet()); 1710 1567 if (!parser.parse(&ss)) { 1711 parser.init(QLatin1String("* {") + wid->styleSheet() + QLatin1 String("}"));1568 parser.init(QLatin1String("* {") + wid->styleSheet() + QLatin1Char('}')); 1712 1569 if (!parser.parse(&ss)) 1713 1570 qWarning("Could not parse stylesheet of widget %p", wid); … … 1903 1760 1904 1761 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); 1906 1763 } 1907 1764 … … 2158 2015 } else 2159 2016 #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 } 2161 2021 } 2162 2022 … … 2738 2598 widget->style()->polish(widget); 2739 2599 QEvent event(QEvent::StyleChange); 2740 qApp->sendEvent(widget, &event);2600 QApplication::sendEvent(widget, &event); 2741 2601 widget->update(); 2742 2602 widget->updateGeometry(); … … 2784 2644 if (base) 2785 2645 return base; 2786 if (QStyleSheetStyle *me = qobject_cast<QStyleSheetStyle *>( qApp->style()))2646 if (QStyleSheetStyle *me = qobject_cast<QStyleSheetStyle *>(QApplication::style())) 2787 2647 return me->base; 2788 return qApp->style();2648 return QApplication::style(); 2789 2649 } 2790 2650 … … 2856 2716 if ((rule.hasBorder() && rule.border()->hasBorderImage()) 2857 2717 || (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()));2862 2718 QObject::connect(sa->horizontalScrollBar(), SIGNAL(valueChanged(int)), 2863 sa, SLOT(update()) );2719 sa, SLOT(update()), Qt::UniqueConnection); 2864 2720 QObject::connect(sa->verticalScrollBar(), SIGNAL(valueChanged(int)), 2865 sa, SLOT(update()) );2721 sa, SLOT(update()), Qt::UniqueConnection); 2866 2722 } 2867 2723 } … … 2877 2733 if (rule.hasDrawable() || rule.hasBox()) { 2878 2734 if (w->metaObject() == &QWidget::staticMetaObject 2879 #ifndef QT_NO_MENUBAR2880 || qobject_cast<QMenuBar *>(w)2881 #endif2882 #ifndef QT_NO_MENU2883 || qobject_cast<QMenu *>(w)2884 #endif2885 2735 #ifndef QT_NO_ITEMVIEWS 2886 2736 || qobject_cast<QHeaderView *>(w) … … 2897 2747 #ifndef QT_NO_MDIAREA 2898 2748 || qobject_cast<QMdiSubWindow *>(w) 2749 #endif 2750 #ifndef QT_NO_MENUBAR 2751 || qobject_cast<QMenuBar *>(w) 2899 2752 #endif 2900 2753 || qobject_cast<QDialog *>(w)) { … … 3014 2867 rule.configurePalette(&cmbOpt.palette, QPalette::ButtonText, QPalette::Button); 3015 2868 bool customDropDown = (opt->subControls & QStyle::SC_ComboBoxArrow) 3016 && hasStyleRule(w, PseudoElement_ComboBoxDropDown);2869 && (hasStyleRule(w, PseudoElement_ComboBoxDropDown) || hasStyleRule(w, PseudoElement_ComboBoxArrow)); 3017 2870 if (customDropDown) 3018 2871 cmbOpt.subControls &= ~QStyle::SC_ComboBoxArrow; … … 3051 2904 QStyleOptionSpinBox spinOpt(*spin); 3052 2905 rule.configurePalette(&spinOpt.palette, QPalette::ButtonText, QPalette::Button); 2906 rule.configurePalette(&spinOpt.palette, QPalette::Text, QPalette::Base); 3053 2907 spinOpt.rect = rule.borderRect(opt->rect); 3054 2908 bool customUp = true, customDown = true; 3055 2909 QRenderRule upRule = renderRule(w, opt, PseudoElement_SpinBoxUpButton); 3056 2910 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(); 3059 2913 if (rule.hasNativeBorder() && !upRuleMatch && !downRuleMatch) { 3060 2914 rule.drawBackgroundImage(p, spinOpt.rect); 3061 2915 customUp = (opt->subControls & QStyle::SC_SpinBoxUp) 3062 && hasStyleRule(w, PseudoElement_SpinBoxUpButton);2916 && (hasStyleRule(w, PseudoElement_SpinBoxUpButton) || hasStyleRule(w, PseudoElement_UpArrow)); 3063 2917 if (customUp) 3064 2918 spinOpt.subControls &= ~QStyle::SC_SpinBoxUp; 3065 2919 customDown = (opt->subControls & QStyle::SC_SpinBoxDown) 3066 && hasStyleRule(w, PseudoElement_SpinBoxDownButton);2920 && (hasStyleRule(w, PseudoElement_SpinBoxDownButton) || hasStyleRule(w, PseudoElement_DownArrow)); 3067 2921 if (customDown) 3068 2922 spinOpt.subControls &= ~QStyle::SC_SpinBoxDown; … … 3190 3044 QStyleOptionToolButton toolOpt(*tool); 3191 3045 rule.configurePalette(&toolOpt.palette, QPalette::ButtonText, QPalette::Button); 3046 toolOpt.font = rule.font.resolve(toolOpt.font); 3192 3047 toolOpt.rect = rule.borderRect(opt->rect); 3193 3048 bool customArrow = (tool->features & (QStyleOptionToolButton::HasMenu | QStyleOptionToolButton::MenuButtonPopup)); … … 3282 3137 rule.drawRule(p, opt->rect); 3283 3138 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; 3288 3150 } 3289 3151 3290 3152 QRect gr = subControlRect(cc, opt, SC_SliderGroove, w); 3291 3153 if (slider->subControls & SC_SliderGroove) { 3292 subRule.drawRule(p, gr);3154 grooveSubRule.drawRule(p, gr); 3293 3155 } 3294 3156 3295 3157 if (slider->subControls & SC_SliderHandle) { 3296 QRenderRule subRule = renderRule(w, opt, PseudoElement_SliderHandle);3297 3158 QRect hr = subControlRect(cc, opt, SC_SliderHandle, w); 3298 3159 … … 3315 3176 } 3316 3177 3317 subRule.drawRule(p, subRule.boxRect(hr, Margin));3178 handleSubRule.drawRule(p, grooveSubRule.boxRect(hr, Margin)); 3318 3179 } 3319 3180 … … 3349 3210 QRect rect = subRule.boxRect(subControlRect(CC_MdiControls, opt, control, w), Margin); 3350 3211 subRule.drawRule(p, rect); 3351 QIcon icon = standardIcon(subControlIcon(layoutButton) );3212 QIcon icon = standardIcon(subControlIcon(layoutButton), opt); 3352 3213 icon.paint(p, subRule.contentsRect(rect), Qt::AlignCenter); 3353 3214 } else { … … 3465 3326 3466 3327 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; 3470 3336 case CE_PushButtonBevel: 3471 3337 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { … … 3510 3376 Qt::Alignment textAlignment = rule.position()->textAlignment; 3511 3377 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; 3513 3381 if (!styleHint(SH_UnderlineShortcut, button, w)) 3514 3382 tf |= Qt::TextHideMnemonic; … … 3619 3487 case CE_MenuBarEmptyArea: 3620 3488 if (rule.hasDrawable()) { 3489 // Drawn by PE_Widget 3621 3490 return; 3622 3491 } … … 3736 3605 drawPrimitive(arrow, &mi, p, w); 3737 3606 } 3738 } else if (hasStyleRule(w, PseudoElement_MenuCheckMark) ) {3607 } else if (hasStyleRule(w, PseudoElement_MenuCheckMark) || hasStyleRule(w, PseudoElement_MenuRightArrow)) { 3739 3608 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 } 3740 3630 } else { 3741 3631 if (rule.hasDrawable() && !subRule.hasDrawable() && !(opt->state & QStyle::State_Selected)) { … … 3769 3659 QCommonStyle::drawControl(ce, &mi, p, w); 3770 3660 } 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 } 3771 3666 baseStyle()->drawControl(ce, &mi, p, w); 3772 3667 } … … 3790 3685 QRect iconRect(editRect); 3791 3686 iconRect.setWidth(cb->iconSize.width()); 3792 iconRect = alignedRect( QApplication::layoutDirection(),3793 3794 3687 iconRect = alignedRect(cb->direction, 3688 Qt::AlignLeft | Qt::AlignVCenter, 3689 iconRect.size(), editRect); 3795 3690 drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap); 3796 3691 … … 3802 3697 if (!cb->currentText.isEmpty() && !cb->editable) { 3803 3698 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); 3805 3700 } 3806 3701 p->restore(); … … 4093 3988 if (subRule.hasFont) 4094 3989 p->setFont(subRule.font); 4095 if (subRule.hasBox() ) {3990 if (subRule.hasBox() || !subRule.hasNativeBorder()) { 4096 3991 tabCopy.rect = ce == CE_TabBarTabShape ? subRule.borderRect(r) 4097 3992 : subRule.contentsRect(r); … … 4165 4060 frmOpt.rect = rule.borderRect(frmOpt.rect); 4166 4061 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 4170 4064 } 4171 4065 return; … … 4221 4115 4222 4116 switch (pe) { 4223 case PE_PanelStatusBar:4224 if (rule.hasDrawable()) {4225 rule.drawRule(p, opt->rect);4226 return;4227 }4228 break;4229 4117 4230 4118 case PE_FrameStatusBar: { … … 4317 4205 if (!spinboxRule.hasNativeBorder() || !spinboxRule.baseStyleCanDraw()) 4318 4206 return; 4207 rule = spinboxRule; 4319 4208 } 4320 4209 #endif … … 4338 4227 4339 4228 case PE_Widget: 4340 if (!rule.has Background()) {4229 if (!rule.hasDrawable()) { 4341 4230 QWidget *container = containerWidget(w); 4342 4231 if (autoFillDisabledWidgets->contains(container) … … 4348 4237 break; 4349 4238 } 4350 4351 4239 #ifndef QT_NO_SCROLLAREA 4352 4240 if (const QAbstractScrollArea *sa = qobject_cast<const QAbstractScrollArea *>(w)) { 4353 4241 const QAbstractScrollAreaPrivate *sap = sa->d_func(); 4354 4242 rule.drawBackground(p, opt->rect, sap->contentsOffset()); 4355 } else 4243 if (rule.hasBorder()) 4244 rule.drawBorder(p, rule.borderRect(opt->rect)); 4245 break; 4246 } 4356 4247 #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 4361 4260 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; 4370 4263 4371 4264 case PE_IndicatorToolBarSeparator: … … 4411 4304 subRule.drawRule(p, opt->rect); 4412 4305 } 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); 4430 4307 } 4431 4308 } … … 4461 4338 if (subRule.hasNativeBorder()) { 4462 4339 subRule.drawBackground(p, opt->rect); 4463 QStyleOptionTabWidgetFrame frmCopy(*frm);4340 QStyleOptionTabWidgetFrameV2 frmCopy(*frm); 4464 4341 subRule.configurePalette(&frmCopy.palette, QPalette::WindowText, QPalette::Window); 4465 4342 baseStyle()->drawPrimitive(pe, &frmCopy, p, w); … … 4492 4369 4493 4370 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;4506 4371 pseudoElement = PseudoElement_ViewItem; 4507 4372 break; … … 4510 4375 pseudoElement = PseudoElement_ScrollAreaCorner; 4511 4376 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 4512 4393 4513 4394 default: … … 4757 4638 break; 4758 4639 4640 #ifndef QT_NO_TABWIDGET 4759 4641 case PM_TabBarTabHSpace: 4760 4642 case PM_TabBarTabVSpace: … … 4780 4662 break; 4781 4663 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)) { 4784 4667 return 0; 4785 4668 } 4786 4669 break; 4670 } 4671 #endif // QT_NO_TABWIDGET 4787 4672 4788 4673 case PM_SliderThickness: // horizontal slider's height (sizeHint) … … 4842 4727 else if (subRule.hasBox() || subRule.hasBorder()) { 4843 4728 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(); 4845 4730 } 4846 4731 break; … … 4927 4812 #ifndef QT_NO_SPINBOX 4928 4813 // ### 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)) { 4930 4815 QRenderRule rule = renderRule(spinBox, opt); 4931 4816 if (rule.hasBox() || !rule.hasNativeBorder()) … … 4974 4859 return QSize(sz.width(), subRule.size().height()); 4975 4860 } 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()))); 4983 4865 } 4984 4866 } … … 5247 5129 s = QLatin1String("alignment"); 5248 5130 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 5249 5143 case SH_TabBar_ElideMode: s = QLatin1String("tabbar-elide-mode"); break; 5250 5144 case SH_TabBar_PreferNoArrows: s = QLatin1String("tabbar-prefer-no-arrows"); break; … … 5253 5147 if (qobject_cast<const QComboBox *>(w)) { 5254 5148 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 } 5258 5155 } 5259 5156 #endif // QT_NO_COMBOBOX … … 5329 5226 QRenderRule downRule = renderRule(w, opt, PseudoElement_SpinBoxDownButton); 5330 5227 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(); 5333 5230 if (ruleMatch || upRuleMatch || downRuleMatch) { 5334 5231 switch (sc) { … … 5822 5719 break; 5823 5720 } 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 } 5824 5730 #endif // QT_NO_TABBAR 5825 5731 … … 5843 5749 bool QStyleSheetStyle::event(QEvent *e) 5844 5750 { 5845 return baseStyle()->event(e) || ParentStyle::event(e);5751 return (baseStyle()->event(e) && e->isAccepted()) || ParentStyle::event(e); 5846 5752 } 5847 5753 … … 5888 5794 } 5889 5795 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 5895 5799 // Returns true if there is a new palette in pal. 5896 bool QStyleSheetStyle:: focusPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal)5800 bool QStyleSheetStyle::styleSheetPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal) 5897 5801 { 5898 5802 if (!w || !opt || !pal)
Note:
See TracChangeset
for help on using the changeset viewer.