733bool QWindowsVistaStylePrivate::drawBackgroundThruNativeBuffer(QWindowsThemeData &themeData,
734 qreal additionalDevicePixelRatio,
735 qreal correctionFactor)
737 QPainter *painter = themeData.painter;
738 QRectF rectF = scaleRect(QRectF(themeData.rect), additionalDevicePixelRatio);
740 if ((themeData.rotate + 90) % 180 == 0) {
741 rectF = QRectF(0, 0, rectF.height(), rectF.width());
745 const bool hasCorrectionFactor = !qFuzzyCompare(correctionFactor, qreal(1));
746 QRect rect = rectF.toRect();
747 const QRect drawRect = hasCorrectionFactor
748 ? QRectF(rectF.topLeft() / correctionFactor, rectF.size() / correctionFactor).toRect()
750 int partId = themeData.partId;
751 int stateId = themeData.stateId;
752 int w = rect.width();
753 int h = rect.height();
757 bool stateHasData =
true;
758 bool hasAlpha =
false;
759 bool partIsTransparent;
760 bool potentialInvalidAlpha;
762 QString pixmapCacheKey = QStringLiteral(u"$qt_xp_");
763 pixmapCacheKey.append(themeName(themeData.theme));
764 pixmapCacheKey.append(QLatin1Char(
'p'));
765 pixmapCacheKey.append(QString::number(partId));
766 pixmapCacheKey.append(QLatin1Char(
's'));
767 pixmapCacheKey.append(QString::number(stateId));
768 pixmapCacheKey.append(QLatin1Char(
's'));
769 pixmapCacheKey.append(themeData.noBorder ? QLatin1Char(
'0') : QLatin1Char(
'1'));
770 pixmapCacheKey.append(QLatin1Char(
'b'));
771 pixmapCacheKey.append(themeData.noContent ? QLatin1Char(
'0') : QLatin1Char(
'1'));
772 pixmapCacheKey.append(QString::number(w));
773 pixmapCacheKey.append(QLatin1Char(
'w'));
774 pixmapCacheKey.append(QString::number(h));
775 pixmapCacheKey.append(QLatin1Char(
'h'));
776 pixmapCacheKey.append(QString::number(additionalDevicePixelRatio));
777 pixmapCacheKey.append(QLatin1Char(
'd'));
778 if (hasCorrectionFactor) {
779 pixmapCacheKey.append(QLatin1Char(
'c'));
780 pixmapCacheKey.append(QString::number(correctionFactor));
783 QPixmap cachedPixmap;
787 bool haveCachedPixmap =
false;
790 partIsTransparent = data.partIsTransparent;
791 hasAlpha = data.hasAlphaChannel;
792 alphaType = data.alphaType;
793 potentialInvalidAlpha = data.hadInvalidAlpha;
795 haveCachedPixmap = QPixmapCache::find(pixmapCacheKey, &cachedPixmap);
799 ::sprintf(buf,
"+ Pixmap(%3d, %3d) ]", w, h);
800 printf(
"---[ CACHED %s--------> Name(%-10s) Part(%d) State(%d)\n",
801 haveCachedPixmap ? buf :
"]-------------------",
802 qPrintable(themeData.name), themeData.partId, themeData.stateId);
806 BOOL tmt_borderonly =
false;
807 COLORREF tmt_transparentcolor = 0x0;
808 PROPERTYORIGIN proporigin = PO_NOTFOUND;
809 GetThemeBool(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERONLY, &tmt_borderonly);
810 GetThemeColor(themeData.handle(), themeData.partId, themeData.stateId, TMT_TRANSPARENTCOLOR, &tmt_transparentcolor);
811 GetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_CAPTIONMARGINS, &proporigin);
813 partIsTransparent = isTransparent(themeData);
815 potentialInvalidAlpha =
false;
816 GetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_GLYPHTYPE, &proporigin);
817 if (proporigin == PO_PART || proporigin == PO_STATE) {
818 int tmt_glyphtype = GT_NONE;
819 GetThemeEnumValue(themeData.handle(), themeData.partId, themeData.stateId, TMT_GLYPHTYPE, &tmt_glyphtype);
820 potentialInvalidAlpha = partIsTransparent && tmt_glyphtype == GT_IMAGEGLYPH;
824 printf(
"---[ NOT CACHED ]-----------------------> Name(%-10s) Part(%d) State(%d)\n",
825 qPrintable(themeData.name), themeData.partId, themeData.stateId);
826 printf(
"-->partIsTransparen = %d\n", partIsTransparent);
827 printf(
"-->potentialInvalidAlpha = %d\n", potentialInvalidAlpha);
828 showProperties(themeData);
831 bool wasAlphaSwapped =
false;
832 bool wasAlphaFixed =
false;
838 bool addBorderContentClipping =
false;
840 QRect area = drawRect;
841 if (themeData.noBorder || themeData.noContent) {
848 PROPERTYORIGIN origin = PO_NOTFOUND;
849 GetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERSIZE, &origin);
850 GetThemeInt(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERSIZE, &borderSize);
851 borderSize *= additionalDevicePixelRatio;
854 if ((origin == PO_CLASS || origin == PO_PART || origin == PO_STATE) && borderSize > 0) {
855 if (themeData.noBorder) {
857 area = area.adjusted(-borderSize, -borderSize, borderSize, borderSize);
861 if (themeData.noContent) {
862 QRegion content = area.adjusted(borderSize, borderSize, -borderSize, -borderSize);
863 extraClip ^= content;
866 addBorderContentClipping = (themeData.noBorder | themeData.noContent);
870 if (!haveCachedPixmap) {
871 if (!buffer(drawRect.width(), drawRect.height()))
873 HDC dc = bufferHDC();
876 if (alphaType != NoAlpha) {
878 memset(bufferPixels, 0x00, bufferW * drawRect.height() * 4);
882 int dx = area.x() - drawRect.x();
883 int dy = area.y() - drawRect.y();
888 DTBGOPTS drawOptions;
889 drawOptions.dwSize =
sizeof(drawOptions);
890 drawOptions.rcClip = themeData.toRECT(rect);
891 drawOptions.dwFlags = DTBG_CLIPRECT
892 | (themeData.noBorder ? DTBG_OMITBORDER : 0)
893 | (themeData.noContent ? DTBG_OMITCONTENT : 0);
896 RECT wRect(themeData.toRECT(area));
897 DrawThemeBackgroundEx(themeData.handle(), dc, themeData.partId, themeData.stateId, &wRect, &drawOptions);
904 memset(
static_cast<
void *>(&data), 0,
sizeof(data));
905 data.dataValid =
true;
906 alphaCache.insert(key, data);
909 hasAlpha = hasAlphaChannel(rect);
910 if (!hasAlpha && partIsTransparent)
911 potentialInvalidAlpha =
true;
912#if defined(DEBUG_XP_STYLE) && 1
913 dumpNativeDIB(drawRect.width(), drawRect.height());
918 if (potentialInvalidAlpha)
919 wasAlphaFixed = fixAlphaChannel(drawRect);
921 QImage::Format format;
922 if ((partIsTransparent && !wasAlphaSwapped) || (!partIsTransparent && hasAlpha)) {
923 format = QImage::Format_ARGB32_Premultiplied;
924 alphaType = RealAlpha;
925 }
else if (wasAlphaSwapped) {
926 format = QImage::Format_ARGB32_Premultiplied;
927 alphaType = MaskAlpha;
929 format = QImage::Format_RGB32;
934 swapAlphaChannel(rect,
true);
937#if defined(DEBUG_XP_STYLE) && 1
938 printf(
"Image format is: %s\n", alphaType == RealAlpha ?
"Real Alpha" : alphaType == MaskAlpha ?
"Masked Alpha" :
"No Alpha");
940 img = QImage(bufferPixels, bufferW, bufferH, format);
941 if (themeData.invertPixels)
944 if (hasCorrectionFactor)
945 img = img.scaled(img.size() * correctionFactor, Qt::KeepAspectRatio, Qt::SmoothTransformation);
946 img.setDevicePixelRatio(additionalDevicePixelRatio);
950 bool useRegion = partIsTransparent && !hasAlpha && !wasAlphaSwapped;
955 newRegion = region(themeData);
956 oldRegion = painter->clipRegion();
957 painter->setClipRegion(newRegion);
958#if defined(DEBUG_XP_STYLE) && 0
959 printf(
"Using region:\n");
960 for (
const QRect &r : newRegion)
961 printf(
" (%d, %d, %d, %d)\n", r.x(), r.y(), r.right(), r.bottom());
965 if (addBorderContentClipping)
966 painter->setClipRegion(scaleRegion(extraClip, 1.0 / additionalDevicePixelRatio), Qt::IntersectClip);
968 if (!themeData.mirrorHorizontally && !themeData.mirrorVertically && !themeData.rotate) {
969 if (!haveCachedPixmap)
970 painter->drawImage(themeData.rect, img, rect);
972 painter->drawPixmap(themeData.rect, cachedPixmap);
980 if (!haveCachedPixmap)
981 imgCopy = img.copy(rect);
983 imgCopy = cachedPixmap.toImage();
985 if (themeData.rotate) {
986 QTransform rotMatrix;
987 rotMatrix.rotate(themeData.rotate);
988 imgCopy = imgCopy.transformed(rotMatrix);
990 Qt::Orientations orient = {};
991 if (themeData.mirrorHorizontally)
992 orient |= Qt::Horizontal;
993 if (themeData.mirrorVertically)
994 orient |= Qt::Vertical;
995 if (themeData.mirrorHorizontally || themeData.mirrorVertically)
996 imgCopy.flip(orient);
997 painter->drawImage(themeData.rect, imgCopy);
1000 if (useRegion || addBorderContentClipping) {
1001 if (oldRegion.isEmpty())
1002 painter->setClipping(
false);
1004 painter->setClipRegion(oldRegion);
1008 if (!haveCachedPixmap && w && h) {
1009 QPixmap pix = QPixmap::fromImage(img).copy(rect);
1010 QPixmapCache::insert(pixmapCacheKey, pix);
1011#ifdef DEBUG_XP_STYLE
1012 printf(
"+++Adding pixmap to cache, size(%d, %d), wasAlphaSwapped(%d), wasAlphaFixed(%d), name(%s)\n",
1013 w, h, wasAlphaSwapped, wasAlphaFixed, qPrintable(pixmapCacheKey));
1019 memset(
static_cast<
void *>(&data), 0,
sizeof(data));
1020 data.dataValid =
true;
1021 data.partIsTransparent = partIsTransparent;
1022 data.alphaType = alphaType;
1023 data.hasAlphaChannel = hasAlpha;
1024 data.wasAlphaSwapped = wasAlphaSwapped;
1025 data.hadInvalidAlpha = wasAlphaFixed;
1026 alphaCache.insert(key, data);
1339void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element,
const QStyleOption *option,
1340 QPainter *painter,
const QWidget *widget)
const
1342 if (!QWindowsVistaStylePrivate::useVista()) {
1343 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1349 int state = option->state;
1350 QRect rect = option->rect;
1352 if ((state & State_Enabled) && d->transitionsEnabled() && canAnimate(option)) {
1353 if (supportsStateTransition(element, option, widget)) {
1356 QObject *styleObject = option->styleObject;
1357 styleObject->setProperty(
"_q_no_animation",
true);
1358 int oldState = styleObject->property(
"_q_stylestate").toInt();
1359 QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
1360 QRect newRect = rect;
1361 styleObject->setProperty(
"_q_stylestate",
int(option->state));
1362 styleObject->setProperty(
"_q_stylerect", option->rect);
1364 bool doTransition = oldState &&
1365 ((state & State_Sunken) != (oldState & State_Sunken) ||
1366 (state & State_On) != (oldState & State_On) ||
1367 (state & State_MouseOver) != (oldState & State_MouseOver));
1369 if (oldRect != newRect ||
1370 (state & State_Enabled) != (oldState & State_Enabled) ||
1371 (state & State_Active) != (oldState & State_Active))
1372 d->stopAnimation(styleObject);
1374 if (state & State_ReadOnly && element == PE_FrameLineEdit)
1375 doTransition =
false;
1378 QStyleOption *styleOption = clonedAnimationStyleOption(option);
1379 styleOption->state = QStyle::State(oldState);
1381 QWindowsVistaAnimation *animate = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
1386 QImage startImage = createAnimationBuffer(option, widget);
1387 QPainter startPainter(&startImage);
1389 QImage endImage = createAnimationBuffer(option, widget);
1396 proxy()->drawPrimitive(element, styleOption, &startPainter, widget);
1398 animate->paint(&startPainter, styleOption);
1400 transition->setStartImage(startImage);
1404 styleOption->styleObject =
nullptr;
1405 styleOption->state = option->state;
1406 proxy()->drawPrimitive(element, styleOption, &endPainter, widget);
1408 transition->setEndImage(endImage);
1417 if (element == PE_FrameLineEdit) {
1418 theme = OpenThemeData(
nullptr, L"Edit");
1419 partId = EP_EDITBORDER_NOSCROLL;
1421 if (oldState & State_HasFocus)
1422 fromState = ETS_SELECTED;
1423 else if (oldState & State_MouseOver)
1424 fromState = ETS_HOT;
1426 fromState = ETS_NORMAL;
1428 if (state & State_HasFocus)
1429 toState = ETS_SELECTED;
1430 else if (state & State_MouseOver)
1433 toState = ETS_NORMAL;
1436 theme = OpenThemeData(
nullptr, L"Button");
1437 if (element == PE_IndicatorRadioButton)
1438 partId = BP_RADIOBUTTON;
1439 else if (element == PE_IndicatorCheckBox)
1440 partId = BP_CHECKBOX;
1442 partId = BP_PUSHBUTTON;
1444 fromState = buttonStateId(oldState, partId);
1445 toState = buttonStateId(option->state, partId);
1450 && SUCCEEDED(GetThemeTransitionDuration(theme, partId, fromState, toState,
1451 TMT_TRANSITIONDURATIONS, &duration))) {
1452 transition->setDuration(
int(duration));
1454 transition->setStartTime(d->animationTime());
1456 deleteClonedAnimationStyleOption(styleOption);
1457 d->startAnimation(transition);
1459 styleObject->setProperty(
"_q_no_animation",
false);
1463 int themeNumber = -1;
1466 bool hMirrored =
false;
1467 bool vMirrored =
false;
1468 bool noBorder =
false;
1469 bool noContent =
false;
1473 case PE_PanelButtonCommand:
1474 if (
const auto *btn = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
1476 if (!(state & State_Sunken) && (state & State_On))
1477 fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1479 fill = option->palette.brush(QPalette::Button);
1480 if (btn->features & QStyleOptionButton::DefaultButton && state & State_Sunken) {
1481 painter->setPen(option->palette.dark().color());
1482 painter->setBrush(fill);
1483 painter->drawRect(rect.adjusted(0, 0, -1, -1));
1484 }
else if (state & (State_Raised | State_On | State_Sunken)) {
1485 qDrawWinButton(painter, rect, option->palette, state & (State_Sunken | State_On),
1488 painter->fillRect(rect, fill);
1493 case PE_PanelButtonTool:
1494#if QT_CONFIG(dockwidget)
1495 if (widget && widget->inherits(
"QDockWidgetTitleButton")) {
1496 if (
const QWidget *dw = widget->parentWidget())
1497 if (dw->isWindow()) {
1502 themeNumber = QWindowsVistaStylePrivate::ToolBarTheme;
1504 if (!(option->state & State_Enabled))
1505 stateId = TS_DISABLED;
1506 else if (option->state & State_Sunken)
1507 stateId = TS_PRESSED;
1508 else if (option->state & State_MouseOver)
1509 stateId = option->state & State_On ? TS_HOTCHECKED : TS_HOT;
1510 else if (option->state & State_On)
1511 stateId = TS_CHECKED;
1512 else if (!(option->state & State_AutoRaise))
1515 stateId = TS_NORMAL;
1519 case PE_IndicatorHeaderArrow:
1520 if (
const auto *header = qstyleoption_cast<
const QStyleOptionHeader *>(option)) {
1521 int stateId = HSAS_SORTEDDOWN;
1522 if (header->sortIndicator & QStyleOptionHeader::SortDown)
1523 stateId = HSAS_SORTEDUP;
1524 QWindowsThemeData theme(widget, painter,
1525 QWindowsVistaStylePrivate::HeaderTheme,
1526 HP_HEADERSORTARROW, stateId, option->rect);
1527 d->drawBackground(theme);
1532 case PE_IndicatorCheckBox:
1534 qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1535 animate->paint(painter, option);
1538 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1539 partId = BP_CHECKBOX;
1541 if (!(option->state & State_Enabled))
1542 stateId = CBS_UNCHECKEDDISABLED;
1543 else if (option->state & State_Sunken)
1544 stateId = CBS_UNCHECKEDPRESSED;
1545 else if (option->state & State_MouseOver)
1546 stateId = CBS_UNCHECKEDHOT;
1548 stateId = CBS_UNCHECKEDNORMAL;
1550 if (option->state & State_On)
1551 stateId += CBS_CHECKEDNORMAL-1;
1552 else if (option->state & State_NoChange)
1553 stateId += CBS_MIXEDNORMAL-1;
1557 case PE_IndicatorItemViewItemCheck: {
1558 QStyleOptionButton button;
1559 button.QStyleOption::operator=(*option);
1560 button.state &= ~State_MouseOver;
1561 proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
1565 case PE_IndicatorBranch: {
1566 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::VistaTreeViewTheme);
1567 static int decoration_size = 0;
1568 if (!decoration_size && theme.isValid()) {
1569 QWindowsThemeData themeSize = theme;
1570 themeSize.partId = TVP_HOTGLYPH;
1571 themeSize.stateId = GLPS_OPENED;
1572 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
1573 decoration_size = qRound(qMax(size.width(), size.height()));
1575 int mid_h = option->rect.x() + option->rect.width() / 2;
1576 int mid_v = option->rect.y() + option->rect.height() / 2;
1577 if (option->state & State_Children) {
1578 int delta = decoration_size / 2;
1579 theme.rect = QRect(mid_h - delta, mid_v - delta, decoration_size, decoration_size);
1580 theme.partId = option->state & State_MouseOver ? TVP_HOTGLYPH : TVP_GLYPH;
1581 theme.stateId = option->state & QStyle::State_Open ? GLPS_OPENED : GLPS_CLOSED;
1582 if (option->direction == Qt::RightToLeft)
1583 theme.mirrorHorizontally =
true;
1584 d->drawBackground(theme);
1589 case PE_PanelButtonBevel:
1590 if (QWindowsVistaAnimation *animate =
1591 qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1592 animate->paint(painter, option);
1596 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1597 partId = BP_PUSHBUTTON;
1598 if (!(option->state & State_Enabled))
1599 stateId = PBS_DISABLED;
1600 else if ((option->state & State_Sunken) || (option->state & State_On))
1601 stateId = PBS_PRESSED;
1602 else if (option->state & State_MouseOver)
1605 stateId = PBS_NORMAL;
1608 case PE_IndicatorRadioButton:
1609 if (QWindowsVistaAnimation *animate =
1610 qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1611 animate->paint(painter, option);
1614 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1615 partId = BP_RADIOBUTTON;
1617 if (!(option->state & State_Enabled))
1618 stateId = RBS_UNCHECKEDDISABLED;
1619 else if (option->state & State_Sunken)
1620 stateId = RBS_UNCHECKEDPRESSED;
1621 else if (option->state & State_MouseOver)
1622 stateId = RBS_UNCHECKEDHOT;
1624 stateId = RBS_UNCHECKEDNORMAL;
1626 if (option->state & State_On)
1627 stateId += RBS_CHECKEDNORMAL-1;
1632 if (widget && widget->inherits(
"QComboBoxPrivateContainer")){
1633 QStyleOption copy = *option;
1634 copy.state |= State_Raised;
1635 proxy()->drawPrimitive(PE_PanelMenu, ©, painter, widget);
1638#if QT_CONFIG(accessibility)
1639 if (QStyleHelper::isInstanceOf(option->styleObject, QAccessible::EditableText)
1640 || QStyleHelper::isInstanceOf(option->styleObject, QAccessible::StaticText) ||
1644 (widget && widget->inherits(
"QTextEdit"))) {
1646 int stateId = ETS_NORMAL;
1647 if (!(state & State_Enabled))
1648 stateId = ETS_DISABLED;
1649 else if (state & State_ReadOnly)
1650 stateId = ETS_READONLY;
1651 else if (state & State_HasFocus)
1652 stateId = ETS_SELECTED;
1653 QWindowsThemeData theme(widget, painter,
1654 QWindowsVistaStylePrivate::EditTheme,
1655 EP_EDITBORDER_HVSCROLL, stateId, option->rect);
1658 GetThemeInt(theme.handle(), theme.partId, theme.stateId, TMT_BORDERSIZE, &borderSize);
1659 QRegion clipRegion = option->rect;
1660 QRegion content = option->rect.adjusted(borderSize, borderSize, -borderSize, -borderSize);
1661 clipRegion ^= content;
1662 painter->setClipRegion(clipRegion);
1663 d->drawBackground(theme);
1667 if (option->state & State_Raised)
1670 themeNumber = QWindowsVistaStylePrivate::ListViewTheme;
1671 partId = LVP_LISTGROUP;
1672 QWindowsThemeData theme(widget,
nullptr, themeNumber, partId);
1674 if (!(option->state & State_Enabled))
1675 stateId = ETS_DISABLED;
1677 stateId = ETS_NORMAL;
1681 if (GetThemeEnumValue(theme.handle(), partId, stateId, TMT_BGTYPE, &fillType) == S_OK) {
1682 if (fillType == BT_BORDERFILL) {
1684 GetThemeColor(theme.handle(), partId, stateId, TMT_BORDERCOLOR, &bcRef);
1685 QColor bordercolor(qRgb(GetRValue(bcRef), GetGValue(bcRef), GetBValue(bcRef)));
1686 QPen oldPen = painter->pen();
1689 painter->setPen(QPen(option->palette.base().color(), 0));
1690 const qreal dpi = QStyleHelper::dpi(option);
1691 const auto topLevelAdjustment = QStyleHelper::dpiScaled(0.5, dpi);
1692 const auto bottomRightAdjustment = QStyleHelper::dpiScaled(-1, dpi);
1693 painter->drawRect(QRectF(option->rect).adjusted(topLevelAdjustment, topLevelAdjustment,
1694 bottomRightAdjustment, bottomRightAdjustment));
1696 painter->setPen(QPen(bordercolor, 0));
1697 painter->drawRect(QRectF(option->rect).adjusted(0, 0, -topLevelAdjustment, -topLevelAdjustment));
1698 painter->setPen(oldPen);
1701 if (fillType == BT_BORDERFILL || fillType == BT_NONE)
1707 case PE_FrameMenu: {
1708 int stateId = option->state & State_Active ? MB_ACTIVE : MB_INACTIVE;
1709 QWindowsThemeData theme(widget, painter,
1710 QWindowsVistaStylePrivate::MenuTheme,
1711 MENU_POPUPBORDERS, stateId, option->rect);
1712 d->drawBackground(theme);
1717 if (widget && widget->inherits(
"QComboBoxPrivateContainer")){
1719 QWindowsThemeData popupbackgroundTheme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
1720 MENU_POPUPBACKGROUND, stateId, option->rect);
1721 d->drawBackground(popupbackgroundTheme);
1726 case PE_PanelMenuBar:
1729#if QT_CONFIG(dockwidget)
1730 case PE_IndicatorDockWidgetResizeHandle:
1733 case PE_FrameDockWidget:
1734 if (
const auto *frm = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1735 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
1736 if (option->state & State_Active)
1737 stateId = FS_ACTIVE;
1739 stateId = FS_INACTIVE;
1741 int fwidth = proxy()->pixelMetric(PM_DockWidgetFrameWidth, frm, widget);
1743 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
1745 if (!theme.isValid())
1748 theme.rect = QRect(frm->rect.x(), frm->rect.y(), frm->rect.x()+fwidth, frm->rect.height()-fwidth);
1749 theme.partId = WP_SMALLFRAMELEFT;
1750 d->drawBackground(theme);
1751 theme.rect = QRect(frm->rect.width()-fwidth, frm->rect.y(), fwidth, frm->rect.height()-fwidth);
1752 theme.partId = WP_SMALLFRAMERIGHT;
1753 d->drawBackground(theme);
1754 theme.rect = QRect(frm->rect.x(), frm->rect.bottom()-fwidth+1, frm->rect.width(), fwidth);
1755 theme.partId = WP_SMALLFRAMEBOTTOM;
1756 d->drawBackground(theme);
1762 case PE_FrameTabWidget:
1763#if QT_CONFIG(tabwidget)
1764 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(option)) {
1765 themeNumber = QWindowsVistaStylePrivate::TabTheme;
1769 bool useGradient =
true;
1770 const int maxlength = 256;
1771 wchar_t themeFileName[maxlength];
1772 wchar_t themeColor[maxlength];
1774 if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength,
nullptr, 0) == S_OK) {
1775 wchar_t *offset =
nullptr;
1776 if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char(
'\\')).unicode())) !=
nullptr) {
1778 if (!lstrcmp(offset, L"Luna.msstyles") && !lstrcmp(offset, L"Metallic"))
1779 useGradient =
false;
1785 QStyleOptionTabWidgetFrame frameOpt = *tab;
1786 frameOpt.rect = widget->rect();
1787 QRect contentsRect = subElementRect(SE_TabWidgetTabContents, &frameOpt, widget);
1788 QRegion reg = option->rect;
1789 reg -= contentsRect;
1790 painter->setClipRegion(reg);
1791 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
1792 theme.mirrorHorizontally = hMirrored;
1793 theme.mirrorVertically = vMirrored;
1794 d->drawBackground(theme);
1795 painter->setClipRect(contentsRect);
1799 switch (tab->shape) {
1800 case QTabBar::RoundedNorth:
1801 case QTabBar::TriangularNorth:
1803 case QTabBar::RoundedSouth:
1804 case QTabBar::TriangularSouth:
1807 case QTabBar::RoundedEast:
1808 case QTabBar::TriangularEast:
1811 case QTabBar::RoundedWest:
1812 case QTabBar::TriangularWest:
1822 case PE_FrameStatusBarItem:
1823 themeNumber = QWindowsVistaStylePrivate::StatusTheme;
1827 case PE_FrameWindow:
1828 if (
const auto *frm = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1829 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
1830 if (option->state & State_Active)
1831 stateId = FS_ACTIVE;
1833 stateId = FS_INACTIVE;
1835 int fwidth =
int((frm->lineWidth + frm->midLineWidth) / QWindowsStylePrivate::nativeMetricScaleFactor(widget));
1837 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
1838 if (!theme.isValid())
1842 theme.rect = QRect(option->rect.x(), option->rect.y()+fwidth, option->rect.x()+fwidth, option->rect.height()-fwidth);
1843 theme.partId = WP_FRAMELEFT;
1844 if (!d->drawBackground(theme)) {
1845 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1848 theme.rect = QRect(option->rect.width()-fwidth, option->rect.y()+fwidth, fwidth, option->rect.height()-fwidth);
1849 theme.partId = WP_FRAMERIGHT;
1850 if (!d->drawBackground(theme)) {
1851 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1854 theme.rect = QRect(option->rect.x(), option->rect.height()-fwidth, option->rect.width(), fwidth);
1855 theme.partId = WP_FRAMEBOTTOM;
1856 if (!d->drawBackground(theme)) {
1857 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1860 theme.rect = QRect(option->rect.x(), option->rect.y(), option->rect.width(), option->rect.y()+fwidth);
1861 theme.partId = WP_CAPTION;
1862 if (!d->drawBackground(theme))
1863 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1868 case PE_PanelLineEdit:
1869 if (
const auto *panel = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1870 bool isEnabled = state & State_Enabled;
1871 if (QWindowsVistaStylePrivate::isLineEditBaseColorSet(option, widget)) {
1872 painter->fillRect(panel->rect, panel->palette.brush(QPalette::Base));
1874 int partId = EP_BACKGROUND;
1875 int stateId = EBS_NORMAL;
1877 stateId = EBS_DISABLED;
1878 else if (option->state & State_ReadOnly)
1879 stateId = EBS_READONLY;
1880 else if (option->state & State_MouseOver)
1883 QWindowsThemeData theme(
nullptr, painter, QWindowsVistaStylePrivate::EditTheme,
1884 partId, stateId, rect);
1885 if (!theme.isValid()) {
1886 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1890 GetThemeEnumValue(theme.handle(), partId, stateId, TMT_BGTYPE, &bgType);
1891 if (bgType == BT_IMAGEFILE) {
1892 d->drawBackground(theme);
1894 QBrush fillColor = option->palette.brush(QPalette::Base);
1896 PROPERTYORIGIN origin = PO_NOTFOUND;
1897 GetThemePropertyOrigin(theme.handle(), theme.partId, theme.stateId, TMT_FILLCOLOR, &origin);
1899 if ((origin == PO_PART || origin == PO_STATE)) {
1901 GetThemeColor(theme.handle(), partId, stateId, TMT_FILLCOLOR, &bgRef);
1902 fillColor = QBrush(qRgb(GetRValue(bgRef), GetGValue(bgRef), GetBValue(bgRef)));
1905 painter->fillRect(option->rect, fillColor);
1908 if (panel->lineWidth > 0)
1909 proxy()->drawPrimitive(PE_FrameLineEdit, panel, painter, widget);
1913 case PE_IndicatorButtonDropDown:
1914 themeNumber = QWindowsVistaStylePrivate::ToolBarTheme;
1915 partId = TP_SPLITBUTTONDROPDOWN;
1916 if (!(option->state & State_Enabled))
1917 stateId = TS_DISABLED;
1918 else if (option->state & State_Sunken)
1919 stateId = TS_PRESSED;
1920 else if (option->state & State_MouseOver)
1921 stateId = option->state & State_On ? TS_HOTCHECKED : TS_HOT;
1922 else if (option->state & State_On)
1923 stateId = TS_CHECKED;
1924 else if (!(option->state & State_AutoRaise))
1927 stateId = TS_NORMAL;
1928 if (option->direction == Qt::RightToLeft)
1932 case PE_FrameLineEdit:
1933 if (QWindowsVistaAnimation *animate = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1934 animate->paint(painter, option);
1936 if (QWindowsVistaStylePrivate::isItemViewDelegateLineEdit(widget)) {
1938 QPen oldPen = painter->pen();
1940 painter->setPen(option->palette.base().color());
1941 painter->drawRect(option->rect.adjusted(1, 1, -2, -2));
1943 painter->setPen(option->palette.shadow().color());
1944 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
1945 painter->setPen(oldPen);
1948 int stateId = ETS_NORMAL;
1949 if (!(state & State_Enabled))
1950 stateId = ETS_DISABLED;
1951 else if (state & State_ReadOnly)
1952 stateId = ETS_READONLY;
1953 else if (state & State_HasFocus)
1954 stateId = ETS_SELECTED;
1955 else if (state & State_MouseOver)
1957 QWindowsThemeData theme(widget, painter,
1958 QWindowsVistaStylePrivate::EditTheme,
1959 EP_EDITBORDER_NOSCROLL, stateId, option->rect);
1960 theme.noContent =
true;
1962 QRegion clipRegion = option->rect;
1963 clipRegion -= option->rect.adjusted(2, 2, -2, -2);
1964 painter->setClipRegion(clipRegion);
1965 d->drawBackground(theme);
1970 case PE_FrameGroupBox:
1971 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1972 partId = BP_GROUPBOX;
1973 if (!(option->state & State_Enabled))
1974 stateId = GBS_DISABLED;
1976 stateId = GBS_NORMAL;
1977 if (
const auto *frame = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1978 if (frame->features & QStyleOptionFrame::Flat) {
1980 QRect fr = frame->rect;
1981 QPoint p1(fr.x(), fr.y() + 1);
1982 QPoint p2(fr.x() + fr.width(), p1.y() + 1);
1983 rect = QRect(p1, p2);
1989 case PE_IndicatorToolBarHandle: {
1990 QWindowsThemeData theme;
1992 if (option->state & State_Horizontal) {
1993 theme = QWindowsThemeData(widget, painter,
1994 QWindowsVistaStylePrivate::RebarTheme,
1995 RP_GRIPPER, ETS_NORMAL, option->rect.adjusted(0, 1, -2, -2));
1996 rect = option->rect.adjusted(0, 1, 0, -2);
1999 theme = QWindowsThemeData(widget, painter, QWindowsVistaStylePrivate::RebarTheme,
2000 RP_GRIPPERVERT, ETS_NORMAL, option->rect.adjusted(0, 1, -2, -2));
2001 rect = option->rect.adjusted(1, 0, -1, 0);
2005 d->drawBackground(theme);
2009 case PE_IndicatorToolBarSeparator: {
2010 QPen pen = painter->pen();
2012 painter->setPen(option->palette.window().color().darker(114));
2013 if (option->state & State_Horizontal) {
2014 int x1 = option->rect.center().x();
2015 painter->drawLine(QPoint(x1, option->rect.top() + margin), QPoint(x1, option->rect.bottom() - margin));
2017 int y1 = option->rect.center().y();
2018 painter->drawLine(QPoint(option->rect.left() + margin, y1), QPoint(option->rect.right() - margin, y1));
2020 painter->setPen(pen);
2024 case PE_PanelTipLabel: {
2025 QWindowsThemeData theme(widget, painter,
2026 QWindowsVistaStylePrivate::ToolTipTheme,
2027 TTP_STANDARD, TTSS_NORMAL, option->rect);
2028 d->drawBackground(theme);
2032 case PE_FrameTabBarBase:
2033#if QT_CONFIG(tabbar)
2034 if (
const auto *tbb = qstyleoption_cast<
const QStyleOptionTabBarBase *>(option)) {
2036 switch (tbb->shape) {
2037 case QTabBar::RoundedNorth:
2038 painter->setPen(QPen(tbb->palette.dark(), 0));
2039 painter->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
2041 case QTabBar::RoundedWest:
2042 painter->setPen(QPen(tbb->palette.dark(), 0));
2043 painter->drawLine(tbb->rect.left(), tbb->rect.top(), tbb->rect.left(), tbb->rect.bottom());
2045 case QTabBar::RoundedSouth:
2046 painter->setPen(QPen(tbb->palette.dark(), 0));
2047 painter->drawLine(tbb->rect.left(), tbb->rect.top(),
2048 tbb->rect.right(), tbb->rect.top());
2050 case QTabBar::RoundedEast:
2051 painter->setPen(QPen(tbb->palette.dark(), 0));
2052 painter->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft());
2054 case QTabBar::TriangularNorth:
2055 case QTabBar::TriangularEast:
2056 case QTabBar::TriangularWest:
2057 case QTabBar::TriangularSouth:
2059 QWindowsStyle::drawPrimitive(element, option, painter, widget);
2068#if QT_CONFIG(dialogbuttonbox)
2069 const QDialogButtonBox *buttonBox =
nullptr;
2070 if (qobject_cast<
const QMessageBox *> (widget))
2071 buttonBox = widget->findChild<
const QDialogButtonBox *>(QLatin1String(
"qt_msgbox_buttonbox"));
2074 QWindowsThemeData theme(widget, painter,
2075 QWindowsVistaStylePrivate::TaskDialogTheme,
2076 TDLG_PRIMARYPANEL, 0, option->rect);
2077 QRect toprect = option->rect;
2078 toprect.setBottom(buttonBox->geometry().top());
2079 theme.rect = toprect;
2080 d->drawBackground(theme);
2083 QRect buttonRect = option->rect;
2084 buttonRect.setTop(buttonBox->geometry().top());
2085 theme.rect = buttonRect;
2086 theme.partId = TDLG_SECONDARYPANEL;
2087 d->drawBackground(theme);
2093 case PE_PanelItemViewItem: {
2094 const QStyleOptionViewItem *vopt;
2095 bool newStyle =
true;
2096 QAbstractItemView::SelectionBehavior selectionBehavior = QAbstractItemView::SelectRows;
2097 QAbstractItemView::SelectionMode selectionMode = QAbstractItemView::NoSelection;
2098 if (
const QAbstractItemView *view = qobject_cast<
const QAbstractItemView *>(widget)) {
2099 newStyle = !qobject_cast<
const QTableView*>(view);
2100 selectionBehavior = view->selectionBehavior();
2101 selectionMode = view->selectionMode();
2102#if QT_CONFIG(accessibility)
2103 }
else if (!widget) {
2104 newStyle = !QStyleHelper::hasAncestor(option->styleObject, QAccessible::MenuItem) ;
2108 if (newStyle && (vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(option))) {
2109 bool selected = vopt->state & QStyle::State_Selected;
2110 const bool hover = selectionMode != QAbstractItemView::NoSelection && (vopt->state & QStyle::State_MouseOver);
2111 bool active = vopt->state & QStyle::State_Active;
2113 if (vopt->features & QStyleOptionViewItem::Alternate)
2114 painter->fillRect(vopt->rect, vopt->palette.alternateBase());
2116 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled
2117 ? QPalette::Normal : QPalette::Disabled;
2118 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
2119 cg = QPalette::Inactive;
2121 QRect itemRect = subElementRect(QStyle::SE_ItemViewItemFocusRect, option, widget).adjusted(-1, 0, 1, 0);
2122 itemRect.setTop(vopt->rect.top());
2123 itemRect.setBottom(vopt->rect.bottom());
2125 QSize sectionSize = itemRect.size();
2126 if (vopt->showDecorationSelected)
2127 sectionSize = vopt->rect.size();
2129 if (selectionBehavior == QAbstractItemView::SelectRows)
2130 sectionSize.setWidth(vopt->rect.width());
2133 if (vopt->backgroundBrush.style() != Qt::NoBrush) {
2134 QPainterStateGuard psg(painter);
2135 painter->setBrushOrigin(vopt->rect.topLeft());
2136 painter->fillRect(vopt->rect, vopt->backgroundBrush);
2139 if (hover || selected) {
2140 if (sectionSize.width() > 0 && sectionSize.height() > 0) {
2141 QString key = QStringLiteral(u"qvdelegate-%1-%2-%3-%4-%5").arg(sectionSize.width())
2142 .arg(sectionSize.height()).arg(selected).arg(active).arg(hover);
2143 if (!QPixmapCache::find(key, &pixmap)) {
2144 pixmap = QPixmap(sectionSize);
2145 pixmap.fill(Qt::transparent);
2148 if (selected && hover)
2150 else if (selected && !active)
2159 QWindowsThemeData theme(widget, &pixmapPainter,
2160 QWindowsVistaStylePrivate::VistaTreeViewTheme,
2161 LVP_LISTITEM, state, QRect(0, 0, sectionSize.width(), sectionSize.height()));
2163 if (!theme.isValid())
2166 d->drawBackground(theme);
2167 QPixmapCache::insert(key, pixmap);
2171 if (vopt->showDecorationSelected) {
2172 const int frame = 2;
2173 QRect srcRect = QRect(0, 0, sectionSize.width(), sectionSize.height());
2174 QRect pixmapRect = vopt->rect;
2175 bool reverse = vopt->direction == Qt::RightToLeft;
2176 bool leftSection = vopt->viewItemPosition == QStyleOptionViewItem::Beginning;
2177 bool rightSection = vopt->viewItemPosition == QStyleOptionViewItem::End;
2178 if (vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne
2179 || vopt->viewItemPosition == QStyleOptionViewItem::Invalid)
2180 painter->drawPixmap(pixmapRect.topLeft(), pixmap);
2181 else if (reverse ? rightSection : leftSection){
2182 painter->drawPixmap(QRect(pixmapRect.topLeft(),
2183 QSize(frame, pixmapRect.height())), pixmap,
2184 QRect(QPoint(0, 0), QSize(frame, pixmapRect.height())));
2185 painter->drawPixmap(pixmapRect.adjusted(frame, 0, 0, 0),
2186 pixmap, srcRect.adjusted(frame, 0, -frame, 0));
2187 }
else if (reverse ? leftSection : rightSection) {
2188 painter->drawPixmap(QRect(pixmapRect.topRight() - QPoint(frame - 1, 0),
2189 QSize(frame, pixmapRect.height())), pixmap,
2190 QRect(QPoint(pixmapRect.width() - frame, 0),
2191 QSize(frame, pixmapRect.height())));
2192 painter->drawPixmap(pixmapRect.adjusted(0, 0, -frame, 0),
2193 pixmap, srcRect.adjusted(frame, 0, -frame, 0));
2194 }
else if (vopt->viewItemPosition == QStyleOptionViewItem::Middle)
2195 painter->drawPixmap(pixmapRect, pixmap,
2196 srcRect.adjusted(frame, 0, -frame, 0));
2198 if (vopt->text.isEmpty() && vopt->icon.isNull())
2200 painter->drawPixmap(itemRect.topLeft(), pixmap);
2212 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2214 if (!theme.isValid()) {
2215 QWindowsStyle::drawPrimitive(element, option, painter, widget);
2219 theme.mirrorHorizontally = hMirrored;
2220 theme.mirrorVertically = vMirrored;
2221 theme.noBorder = noBorder;
2222 theme.noContent = noContent;
2223 theme.rotate = rotate;
2225 d->drawBackground(theme);
2342void QWindowsVistaStyle::drawControl(ControlElement element,
const QStyleOption *option,
2343 QPainter *painter,
const QWidget *widget)
const
2345 if (!QWindowsVistaStylePrivate::useVista()) {
2346 QWindowsStyle::drawControl(element, option, painter, widget);
2352 bool selected = option->state & State_Selected;
2353 bool pressed = option->state & State_Sunken;
2354 bool disabled = !(option->state & State_Enabled);
2356 int state = option->state;
2357 int themeNumber = -1;
2359 QRect rect(option->rect);
2360 State flags = option->state;
2364 if (d->transitionsEnabled() && canAnimate(option)) {
2365 if (element == CE_PushButtonBevel) {
2369 QObject *styleObject = option->styleObject;
2371 int oldState = styleObject->property(
"_q_stylestate").toInt();
2372 oldRect = styleObject->property(
"_q_stylerect").toRect();
2373 newRect = option->rect;
2374 styleObject->setProperty(
"_q_stylestate",
int(option->state));
2375 styleObject->setProperty(
"_q_stylerect", option->rect);
2377 bool wasDefault =
false;
2378 bool isDefault =
false;
2379 if (
const QStyleOptionButton *button = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
2380 wasDefault = styleObject->property(
"_q_isdefault").toBool();
2381 isDefault = button->features & QStyleOptionButton::DefaultButton;
2382 styleObject->setProperty(
"_q_isdefault", isDefault);
2385 bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) ||
2386 (state & State_On) != (oldState & State_On) ||
2387 (state & State_MouseOver) != (oldState & State_MouseOver));
2389 if (oldRect != newRect || (wasDefault && !isDefault)) {
2390 doTransition =
false;
2391 d->stopAnimation(styleObject);
2395 styleObject->setProperty(
"_q_no_animation",
true);
2398 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
2399 QStyleOption *styleOption = clonedAnimationStyleOption(option);
2400 styleOption->state = QStyle::State(oldState);
2402 QImage startImage = createAnimationBuffer(option, widget);
2403 QPainter startPainter(&startImage);
2407 proxy()->drawControl(element, styleOption, &startPainter, widget);
2409 anim->paint(&startPainter, styleOption);
2410 d->stopAnimation(styleObject);
2413 t->setStartImage(startImage);
2414 QImage endImage = createAnimationBuffer(option, widget);
2416 styleOption->state = option->state;
2417 proxy()->drawControl(element, styleOption, &endPainter, widget);
2418 t->setEndImage(endImage);
2422 const HTHEME theme = OpenThemeData(
nullptr, L"Button");
2424 int fromState = buttonStateId(oldState, BP_PUSHBUTTON);
2425 int toState = buttonStateId(option->state, BP_PUSHBUTTON);
2426 if (GetThemeTransitionDuration(theme, BP_PUSHBUTTON, fromState, toState, TMT_TRANSITIONDURATIONS, &duration) == S_OK)
2427 t->setDuration(
int(duration));
2430 t->setStartTime(d->animationTime());
2431 styleObject->setProperty(
"_q_no_animation",
false);
2433 deleteClonedAnimationStyleOption(styleOption);
2434 d->startAnimation(t);
2437 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
2439 anim->paint(painter, option);
2446 bool hMirrored =
false;
2447 bool vMirrored =
false;
2451 case CE_PushButtonBevel:
2452 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
2453 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
2454 partId = BP_PUSHBUTTON;
2455 if (btn->features & QStyleOptionButton::CommandLinkButton)
2457 bool justFlat = (btn->features & QStyleOptionButton::Flat) && !(flags & (State_On|State_Sunken));
2458 if (!(flags & State_Enabled) && !(btn->features & QStyleOptionButton::Flat))
2459 stateId = PBS_DISABLED;
2462 else if (flags & (State_Sunken | State_On))
2463 stateId = PBS_PRESSED;
2464 else if (flags & State_MouseOver)
2466 else if (btn->features & QStyleOptionButton::DefaultButton && (state & State_Active))
2467 stateId = PBS_DEFAULTED;
2469 stateId = PBS_NORMAL;
2472 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2473 d->drawBackground(theme);
2476 if (btn->features & QStyleOptionButton::HasMenu) {
2477 int mbiw = 0, mbih = 0;
2478 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::ToolBarTheme,
2480 if (theme.isValid()) {
2481 const QSizeF size = theme.size() * QStyleHelper::dpiScaled(1, option);
2482 if (!size.isEmpty()) {
2483 mbiw = qRound(size.width());
2484 mbih = qRound(size.height());
2487 QRect ir = subElementRect(SE_PushButtonContents, option,
nullptr);
2488 QStyleOptionButton newBtn = *btn;
2489 newBtn.rect = QStyle::visualRect(option->direction, option->rect,
2490 QRect(ir.right() - mbiw - 2,
2491 option->rect.top() + (option->rect.height()/2) - (mbih/2),
2492 mbiw + 1, mbih + 1));
2493 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
2499 themeNumber = QWindowsVistaStylePrivate::StatusTheme;
2500 partId = SP_GRIPPER;
2501 QWindowsThemeData theme(
nullptr, painter, themeNumber, partId);
2502 QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize();
2504 if (
const auto *sg = qstyleoption_cast<
const QStyleOptionSizeGrip *>(option)) {
2505 switch (sg->corner) {
2506 case Qt::BottomRightCorner:
2507 rect = QRect(QPoint(rect.right() - size.width(), rect.bottom() - size.height()), size);
2509 case Qt::BottomLeftCorner:
2510 rect = QRect(QPoint(rect.left() + 1, rect.bottom() - size.height()), size);
2513 case Qt::TopRightCorner:
2514 rect = QRect(QPoint(rect.right() - size.width(), rect.top() + 1), size);
2517 case Qt::TopLeftCorner:
2518 rect = QRect(rect.topLeft() + QPoint(1, 1), size);
2519 hMirrored = vMirrored =
true;
2526 painter->eraseRect(option->rect);
2530#if QT_CONFIG(tabwidget)
2531 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option))
2532 stateId = tab->state & State_Enabled ? TIS_NORMAL : TIS_DISABLED;
2536 case CE_TabBarTabShape:
2537#if QT_CONFIG(tabwidget)
2538 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option)) {
2539 themeNumber = QWindowsVistaStylePrivate::TabTheme;
2540 const bool isDisabled = !(tab->state & State_Enabled);
2541 const bool hasFocus = tab->state & State_HasFocus;
2542 const bool isHot = tab->state & State_MouseOver;
2543 const bool selected = tab->state & State_Selected;
2544 bool lastTab = tab->position == QStyleOptionTab::End;
2545 bool firstTab = tab->position == QStyleOptionTab::Beginning;
2546 const bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
2547 const bool leftAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignLeft;
2548 const bool centerAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignCenter;
2549 const int borderThickness = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
2550 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, option, widget);
2553 stateId = TIS_DISABLED;
2555 stateId = TIS_SELECTED;
2557 stateId = TIS_FOCUSED;
2561 stateId = TIS_NORMAL;
2564 if (firstTab || onlyOne) {
2566 partId = TABP_TABITEMLEFTEDGE;
2567 else if (centerAligned)
2568 partId = TABP_TABITEM;
2570 partId = TABP_TABITEMRIGHTEDGE;
2572 partId = TABP_TABITEM;
2575 if (tab->direction == Qt::RightToLeft
2576 && (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth)) {
2577 bool temp = firstTab;
2582 const bool begin = firstTab || onlyOne;
2583 const bool end = lastTab || onlyOne;
2585 switch (tab->shape) {
2586 case QTabBar::RoundedNorth:
2588 rect.adjust(begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap, borderThickness);
2590 rect.adjust(begin? tabOverlap : 0, tabOverlap, end ? -tabOverlap : 0, 0);
2592 case QTabBar::RoundedSouth:
2596 rect.adjust(begin ? 0 : -tabOverlap , -borderThickness, end ? 0 : tabOverlap, 0);
2598 rect.adjust(begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0 , -tabOverlap);
2600 case QTabBar::RoundedEast:
2603 rect.adjust(-borderThickness, begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap);
2605 rect.adjust(0, begin ? tabOverlap : 0, -tabOverlap, end ? -tabOverlap : 0);
2607 case QTabBar::RoundedWest:
2611 rect.adjust(0, begin ? 0 : -tabOverlap, borderThickness, end ? 0 : tabOverlap);
2613 rect.adjust(tabOverlap, begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0);
2621 switch (tab->shape) {
2622 case QTabBar::RoundedNorth:
2623 rect.adjust(0,0, 0,-1);
2625 case QTabBar::RoundedSouth:
2626 rect.adjust(0,1, 0,0);
2628 case QTabBar::RoundedEast:
2629 rect.adjust( 1,0, 0,0);
2631 case QTabBar::RoundedWest:
2632 rect.adjust(0,0, -1,0);
2642 case CE_ProgressBarGroove: {
2643 Qt::Orientation orient = Qt::Horizontal;
2644 if (
const auto *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(option))
2645 if (!(pb->state & QStyle::State_Horizontal))
2646 orient = Qt::Vertical;
2648 partId = (orient == Qt::Horizontal) ? PP_BAR : PP_BARVERT;
2649 themeNumber = QWindowsVistaStylePrivate::ProgressTheme;
2654 case CE_ProgressBarContents:
2655 if (
const auto *bar = qstyleoption_cast<
const QStyleOptionProgressBar *>(option)) {
2656 bool isIndeterminate = (bar->minimum == 0 && bar->maximum == 0);
2657 const bool vertical = !(bar->state & QStyle::State_Horizontal);
2658 const bool inverted = bar->invertedAppearance;
2660 if (isIndeterminate || (bar->progress > 0 && (bar->progress < bar->maximum) && d->transitionsEnabled())) {
2661 if (!d->animation(styleObject(option)))
2662 d->startAnimation(
new QProgressStyleAnimation(d->animationFps, styleObject(option)));
2664 d->stopAnimation(styleObject(option));
2667 QWindowsThemeData theme(widget, painter,
2668 QWindowsVistaStylePrivate::ProgressTheme,
2669 vertical ? PP_FILLVERT : PP_FILL);
2670 theme.rect = option->rect;
2671 bool reverse = (bar->direction == Qt::LeftToRight && inverted) || (bar->direction == Qt::RightToLeft && !inverted);
2672 QTime current = d->animationTime();
2674 if (isIndeterminate) {
2675 if (
auto *progressAnimation = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2677 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2678 int animOffset = progressAnimation->startTime().msecsTo(current) / 4;
2679 if (animOffset > animationWidth)
2680 progressAnimation->setStartTime(d->animationTime());
2682 painter->setClipRect(theme.rect);
2684 QSize pixmapSize(14, 14);
2686 animRect = QRect(theme.rect.left(),
2687 inverted ? rect.top() - glowSize + animOffset :
2688 rect.bottom() + glowSize - animOffset,
2689 rect.width(), glowSize);
2690 pixmapSize.setHeight(animRect.height());
2692 animRect = QRect(rect.left() - glowSize + animOffset,
2693 rect.top(), glowSize, rect.height());
2694 animRect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2695 option->rect, animRect);
2696 pixmapSize.setWidth(animRect.width());
2698 QString name = QStringLiteral(u"qiprogress-%1-%2").arg(pixmapSize.width()).arg(pixmapSize.height());
2700 if (!QPixmapCache::find(name, &pixmap)) {
2701 QImage image(pixmapSize, QImage::Format_ARGB32);
2702 image.fill(Qt::transparent);
2704 theme.painter = &imagePainter;
2705 theme.partId = vertical ? PP_FILLVERT : PP_FILL;
2706 theme.rect = QRect(QPoint(0,0), animRect.size());
2707 QLinearGradient alphaGradient(0, 0, vertical ? 0 : image.width(),
2708 vertical ? image.height() : 0);
2709 alphaGradient.setColorAt(0, QColor(0, 0, 0, 0));
2710 alphaGradient.setColorAt(0.5, QColor(0, 0, 0, 220));
2711 alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
2712 imagePainter.fillRect(image.rect(), alphaGradient);
2713 imagePainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
2714 d->drawBackground(theme);
2716 pixmap = QPixmap::fromImage(image);
2717 QPixmapCache::insert(name, pixmap);
2719 painter->drawPixmap(animRect, pixmap);
2723 qint64 progress = qMax<qint64>(bar->progress, bar->minimum);
2726 int maxHeight = option->rect.height();
2728 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxHeight);
2729 int height = isIndeterminate ? maxHeight: qMax(
int(vc6_workaround), minHeight);
2730 theme.rect.setHeight(height);
2732 theme.rect.moveTop(rect.height() - theme.rect.height());
2734 int maxWidth = option->rect.width();
2736 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth);
2737 int width = isIndeterminate ? maxWidth : qMax(
int(vc6_workaround), minWidth);
2738 theme.rect.setWidth(width);
2739 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2740 option->rect, theme.rect);
2742 d->drawBackground(theme);
2744 if (QProgressStyleAnimation *a = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2746 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2747 int animOffset = a->startTime().msecsTo(current) / 4;
2748 theme.partId = vertical ? PP_MOVEOVERLAYVERT : PP_MOVEOVERLAY;
2749 if (animOffset > animationWidth) {
2750 if (bar->progress < bar->maximum)
2751 a->setStartTime(d->animationTime());
2753 d->stopAnimation(styleObject(option));
2757 painter->setClipRect(theme.rect);
2759 theme.rect = QRect(theme.rect.left(),
2760 inverted ? rect.top() - glowSize + animOffset :
2761 rect.bottom() + glowSize - animOffset,
2762 rect.width(), glowSize);
2764 theme.rect = QRect(rect.left() - glowSize + animOffset,rect.top(), glowSize, rect.height());
2765 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight, option->rect, theme.rect);
2767 d->drawBackground(theme);
2774 case CE_MenuBarItem:
2775 if (
const auto *mbi = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2776 if (mbi->menuItemType == QStyleOptionMenuItem::DefaultItem)
2779 QPalette::ColorRole textRole = disabled ? QPalette::Text : QPalette::ButtonText;
2780 const auto dpr = QStyleHelper::getDpr(widget);
2781 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2782 const auto pix = mbi->icon.pixmap(QSize(extent, extent), dpr, QIcon::Normal);
2784 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2785 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
2786 alignment |= Qt::TextHideMnemonic;
2788 if (widget && mbi->palette.color(QPalette::Window) != Qt::transparent) {
2790 QWindowsThemeData theme(widget, painter,
2791 QWindowsVistaStylePrivate::MenuTheme,
2792 MENU_BARBACKGROUND, 0, option->rect.adjusted(-1, 0, 2, 1));
2793 d->drawBackground(theme);
2795 int stateId = MBI_NORMAL;
2797 stateId = MBI_DISABLED;
2799 stateId = MBI_PUSHED;
2803 QWindowsThemeData theme2(widget, painter,
2804 QWindowsVistaStylePrivate::MenuTheme,
2805 MENU_BARITEM, stateId, option->rect);
2806 d->drawBackground(theme2);
2810 drawItemPixmap(painter, mbi->rect, alignment, pix);
2812 drawItemText(painter, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled, mbi->text, textRole);
2817 case CE_MenuEmptyArea:
2818 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2819 QBrush fill = menuitem->palette.brush((menuitem->state & State_Selected) ?
2820 QPalette::Highlight : QPalette::Button);
2821 painter->fillRect(rect, fill);
2827 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2829 const qreal factor = QWindowsVistaStylePrivate::nativeMetricScaleFactor(widget);
2830 int checkcol = qRound(qreal(25) * factor);
2831 const int gutterWidth = qRound(qreal(3) * factor);
2833 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::MenuTheme,
2834 MENU_POPUPCHECKBACKGROUND, MBI_HOT);
2835 QWindowsThemeData themeSize = theme;
2836 themeSize.partId = MENU_POPUPCHECK;
2837 themeSize.stateId = 0;
2838 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2839 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2840 checkcol = qMax(menuitem->maxIconWidth, qRound(gutterWidth + size.width() + margins.left() + margins.right()));
2842 QRect rect = option->rect;
2845 QWindowsThemeData popupbackgroundTheme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2846 MENU_POPUPBACKGROUND, stateId, option->rect);
2847 d->drawBackground(popupbackgroundTheme);
2850 if (option->direction == Qt::LeftToRight)
2851 checkcol += rect.x();
2852 QPoint p1 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.top()));
2853 QPoint p2 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.bottom()));
2854 QRect gutterRect(p1.x(), p1.y(), gutterWidth, p2.y() - p1.y() + 1);
2855 QWindowsThemeData theme2(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2856 MENU_POPUPGUTTER, stateId, gutterRect);
2857 d->drawBackground(theme2);
2860 menuitem->rect.getRect(&x, &y, &w, &h);
2861 int tab = menuitem->reservedShortcutWidth;
2862 bool dis = !(menuitem->state & State_Enabled);
2863 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
2864 ? menuitem->checked :
false;
2865 bool act = menuitem->state & State_Selected;
2867 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {
2868 int yoff = y-2 + h / 2;
2869 const int separatorSize = qRound(qreal(6) * QWindowsStylePrivate::nativeMetricScaleFactor(widget));
2870 QPoint p1 = QPoint(x + checkcol, yoff);
2871 QPoint p2 = QPoint(x + w + separatorSize, yoff);
2873 QRect subRect(p1.x() + (gutterWidth - menuitem->rect.x()), p1.y(),
2874 p2.x() - p1.x(), separatorSize);
2875 subRect = QStyle::visualRect(option->direction, option->rect, subRect );
2876 QWindowsThemeData theme2(widget, painter,
2877 QWindowsVistaStylePrivate::MenuTheme,
2878 MENU_POPUPSEPARATOR, stateId, subRect);
2879 d->drawBackground(theme2);
2883 QRect vCheckRect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x(),
2884 menuitem->rect.y(), checkcol - (gutterWidth + menuitem->rect.x()), menuitem->rect.height()));
2887 stateId = dis ? MBI_DISABLED : MBI_HOT;
2888 QWindowsThemeData theme2(widget, painter,
2889 QWindowsVistaStylePrivate::MenuTheme,
2890 MENU_POPUPITEM, stateId, option->rect);
2891 d->drawBackground(theme2);
2895 QWindowsThemeData theme(widget, painter,
2896 QWindowsVistaStylePrivate::MenuTheme,
2897 MENU_POPUPCHECKBACKGROUND,
2898 menuitem->icon.isNull() ? MBI_HOT : MBI_PUSHED, vCheckRect);
2899 QWindowsThemeData themeSize = theme;
2900 themeSize.partId = MENU_POPUPCHECK;
2901 themeSize.stateId = 0;
2902 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2903 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2904 QRect checkRect(0, 0, qRound(size.width() + margins.left() + margins.right()),
2905 qRound(size.height() + margins.bottom() + margins.top()));
2906 checkRect.moveCenter(vCheckRect.center());
2907 theme.rect = checkRect;
2909 d->drawBackground(theme);
2911 if (menuitem->icon.isNull()) {
2912 checkRect = QRect(QPoint(0, 0), size.toSize());
2913 checkRect.moveCenter(theme.rect.center());
2914 theme.rect = checkRect;
2916 theme.partId = MENU_POPUPCHECK;
2917 bool bullet = menuitem->checkType & QStyleOptionMenuItem::Exclusive;
2919 theme.stateId = bullet ? MC_BULLETDISABLED: MC_CHECKMARKDISABLED;
2921 theme.stateId = bullet ? MC_BULLETNORMAL: MC_CHECKMARKNORMAL;
2922 d->drawBackground(theme);
2926 if (!menuitem->icon.isNull()) {
2927 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
2929 mode = QIcon::Active;
2930 const auto size = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2931 QRect pmr(QPoint(0, 0), QSize(size, size));
2932 pmr.moveCenter(vCheckRect.center());
2933 menuitem->icon.paint(painter, vCheckRect, Qt::AlignCenter, mode,
2934 checked ? QIcon::On : QIcon::Off);
2937 painter->setPen(menuitem->palette.buttonText().color());
2939 const QColor textColor = menuitem->palette.text().color();
2941 painter->setPen(textColor);
2943 int xm = windowsItemFrame + checkcol + windowsItemHMargin + (gutterWidth - menuitem->rect.x()) - 1;
2944 int xpos = menuitem->rect.x() + xm;
2945 QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
2946 QRect vTextRect = visualRect(option->direction, menuitem->rect, textRect);
2947 QString s = menuitem->text;
2950 int t = s.indexOf(QLatin1Char(
'\t'));
2951 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2952 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
2953 text_flags |= Qt::TextHideMnemonic;
2954 text_flags |= Qt::AlignLeft;
2956 QRect vShortcutRect = visualRect(option->direction, menuitem->rect,
2957 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
2958 painter->drawText(vShortcutRect, text_flags, s.mid(t + 1));
2961 QFont font = menuitem->font;
2962 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
2964 painter->setFont(font);
2965 painter->setPen(textColor);
2966 painter->drawText(vTextRect, text_flags, s.left(t));
2969 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {
2970 int dim = (h - 2 * windowsItemFrame) / 2;
2971 PrimitiveElement arrow;
2972 arrow = (option->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
2973 xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim;
2974 QRect vSubMenuRect = visualRect(option->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
2975 QStyleOptionMenuItem newMI = *menuitem;
2976 newMI.rect = vSubMenuRect;
2977 newMI.state = dis ? State_None : State_Enabled;
2978 proxy()->drawPrimitive(arrow, &newMI, painter, widget);
2984 case CE_HeaderSection:
2985 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(option)) {
2986 partId = HP_HEADERITEM;
2987 if (flags & State_Sunken)
2988 stateId = HIS_PRESSED;
2989 else if (flags & State_MouseOver)
2992 stateId = HIS_NORMAL;
2994 if (header->sortIndicator != QStyleOptionHeader::None)
2997 QWindowsThemeData theme(widget, painter,
2998 QWindowsVistaStylePrivate::HeaderTheme,
2999 partId, stateId, option->rect);
3000 d->drawBackground(theme);
3004 case CE_MenuBarEmptyArea: {
3005 stateId = MBI_NORMAL;
3006 if (!(state & State_Enabled))
3007 stateId = MBI_DISABLED;
3008 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
3009 MENU_BARBACKGROUND, stateId, option->rect);
3010 d->drawBackground(theme);
3015#if QT_CONFIG(toolbar)
3016 if (
const auto *toolbar = qstyleoption_cast<
const QStyleOptionToolBar *>(option)) {
3017 QPalette pal = option->palette;
3018 pal.setColor(QPalette::Dark, option->palette.window().color().darker(130));
3019 QStyleOptionToolBar copyOpt = *toolbar;
3020 copyOpt.palette = pal;
3021 QWindowsStyle::drawControl(element, ©Opt, painter, widget);
3026#if QT_CONFIG(dockwidget)
3027 case CE_DockWidgetTitle:
3028 if (
const auto *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(option)) {
3029 QRect rect = option->rect;
3030 const QDockWidget *dw = qobject_cast<
const QDockWidget *>(widget);
3031 bool isFloating = dw && dw->isFloating();
3032 int buttonMargin = 4;
3033 int mw = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, widget);
3034 int fw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, dwOpt, widget);
3036 const bool verticalTitleBar = dwOpt->verticalTitleBar;
3038 if (verticalTitleBar) {
3039 rect = rect.transposed();
3041 painter->translate(rect.left() - 1, rect.top() + rect.width());
3042 painter->rotate(-90);
3043 painter->translate(-rect.left() + 1, -rect.top());
3046 QRect r = option->rect.adjusted(0, 2, -1, -3);
3047 QRect titleRect = r;
3049 if (dwOpt->closable) {
3050 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton, dwOpt, widget).actualSize(QSize(10, 10));
3051 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3054 if (dwOpt->floatable) {
3055 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarMaxButton, dwOpt, widget).actualSize(QSize(10, 10));
3056 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3060 titleRect.adjust(0, -fw, 0, 0);
3061 if (widget && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey())
3062 titleRect.adjust(titleRect.height() + mw, 0, 0, 0);
3064 titleRect.adjust(mw, 0, 0, 0);
3065 if (!dwOpt->floatable && !dwOpt->closable)
3066 titleRect.adjust(0, 0, -mw, 0);
3069 if (!verticalTitleBar)
3070 titleRect = visualRect(dwOpt->direction, r, titleRect);
3073 const bool isActive = dwOpt->state & State_Active;
3074 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
3076 stateId = CS_ACTIVE;
3078 stateId = CS_INACTIVE;
3080 rect = rect.adjusted(-fw, -fw, fw, 0);
3082 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
3083 if (!theme.isValid())
3088 theme.partId = WP_SMALLCAPTION;
3089 d->drawBackground(theme);
3093 QIcon ico = widget->windowIcon();
3094 bool hasIcon = (ico.cacheKey() != QApplication::windowIcon().cacheKey());
3096 const auto titleHeight = rect.height() - 2;
3097 const auto dpr = QStyleHelper::getDpr(widget);
3098 const auto pxIco = ico.pixmap(QSize(titleHeight, titleHeight), dpr);
3099 if (!verticalTitleBar && dwOpt->direction == Qt::RightToLeft)
3100 painter->drawPixmap(rect.width() - titleHeight - pxIco.width(), rect.bottom() - titleHeight - 2, pxIco);
3102 painter->drawPixmap(fw, rect.bottom() - titleHeight - 2, pxIco);
3104 if (!dwOpt->title.isEmpty()) {
3105 QPen oldPen = painter->pen();
3106 QFont oldFont = painter->font();
3107 QFont titleFont = oldFont;
3108 titleFont.setBold(
true);
3109 painter->setFont(titleFont);
3111 = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
3113 int result = TST_NONE;
3114 GetThemeEnumValue(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3115 if (result != TST_NONE) {
3116 COLORREF textShadowRef;
3117 GetThemeColor(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWCOLOR, &textShadowRef);
3118 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3119 painter->setPen(textShadow);
3120 drawItemText(painter, titleRect.adjusted(1, 1, 1, 1),
3121 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3122 dwOpt->state & State_Enabled, titleText);
3125 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3126 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3127 painter->setPen(textColor);
3128 drawItemText(painter, titleRect,
3129 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3130 dwOpt->state & State_Enabled, titleText);
3131 painter->setFont(oldFont);
3132 painter->setPen(oldPen);
3135 painter->setBrush(option->palette.window().color().darker(110));
3136 painter->setPen(option->palette.window().color().darker(130));
3137 painter->drawRect(rect.adjusted(0, 1, -1, -3));
3139 if (!dwOpt->title.isEmpty()) {
3140 QString titleText = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight,
3141 verticalTitleBar ? titleRect.height() : titleRect.width());
3142 const int indent = 4;
3143 drawItemText(painter, rect.adjusted(indent + 1, 1, -indent - 1, -1),
3144 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic,
3146 dwOpt->state & State_Enabled, titleText,
3147 QPalette::WindowText);
3154#if QT_CONFIG(rubberband)
3156 if (qstyleoption_cast<
const QStyleOptionRubberBand *>(option)) {
3157 QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
3159 painter->setPen(highlight.darker(120));
3160 QColor dimHighlight(qMin(highlight.red()/2 + 110, 255),
3161 qMin(highlight.green()/2 + 110, 255),
3162 qMin(highlight.blue()/2 + 110, 255),
3163 (widget && widget->isWindow())? 255 : 127);
3164 painter->setBrush(dimHighlight);
3165 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
3172 case CE_HeaderEmptyArea:
3173 if (option->state & State_Horizontal) {
3174 themeNumber = QWindowsVistaStylePrivate::HeaderTheme;
3175 stateId = HIS_NORMAL;
3177 QWindowsStyle::drawControl(CE_HeaderEmptyArea, option, painter, widget);
3182#if QT_CONFIG(itemviews)
3183 case CE_ItemViewItem: {
3184 const QStyleOptionViewItem *vopt;
3185 const QAbstractItemView *view = qobject_cast<
const QAbstractItemView *>(widget);
3186 bool newStyle =
true;
3188 if (qobject_cast<
const QTableView*>(widget))
3191 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3193 if (newStyle && view && (vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(option))) {
3195
3196
3197
3198
3199
3200
3201 QPalette palette = vopt->palette;
3202 palette.setColor(QPalette::All, QPalette::HighlightedText, palette.color(QPalette::Active, QPalette::Text));
3204 palette.setColor(QPalette::All, QPalette::Highlight, palette.base().color().darker(108));
3205 QStyleOptionViewItem adjustedOption = *vopt;
3206 adjustedOption.palette = palette;
3208 if ((view->selectionMode() == QAbstractItemView::SingleSelection)
3209 && !(vopt->state & State_KeyboardFocusChange))
3210 adjustedOption.state &= ~State_HasFocus;
3211 if (!theme.isValid()) {
3212 QWindowsStyle::drawControl(element, &adjustedOption, painter, widget);
3216 if (!theme.isValid()) {
3217 QWindowsStyle::drawControl(element, option, painter, widget);
3222 theme.rotate = rotate;
3223 theme.mirrorHorizontally = hMirrored;
3224 theme.mirrorVertically = vMirrored;
3225 d->drawBackground(theme);
3230#if QT_CONFIG(combobox)
3231 case CE_ComboBoxLabel:
3232 QCommonStyle::drawControl(element, option, painter, widget);
3240 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3242 if (!theme.isValid()) {
3243 QWindowsStyle::drawControl(element, option, painter, widget);
3247 theme.rotate = rotate;
3248 theme.mirrorHorizontally = hMirrored;
3249 theme.mirrorVertically = vMirrored;
3251 d->drawBackground(theme);
3259void QWindowsVistaStyle::drawComplexControl(ComplexControl control,
const QStyleOptionComplex *option,
3260 QPainter *painter,
const QWidget *widget)
const
3264 if (!QWindowsVistaStylePrivate::useVista()) {
3265 QWindowsStyle::drawComplexControl(control, option, painter, widget);
3269 State state = option->state;
3270 SubControls sub = option->subControls;
3271 QRect r = option->rect;
3276 State flags = option->state;
3277 if (widget && widget->testAttribute(Qt::WA_UnderMouse) && widget->isActiveWindow())
3278 flags |= State_MouseOver;
3280 if (d->transitionsEnabled() && canAnimate(option))
3282 if (control == CC_ScrollBar || control == CC_SpinBox || control == CC_ComboBox) {
3283 QObject *styleObject = option->styleObject;
3285 int oldState = styleObject->property(
"_q_stylestate").toInt();
3286 int oldActiveControls = styleObject->property(
"_q_stylecontrols").toInt();
3288 QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
3289 styleObject->setProperty(
"_q_stylestate",
int(option->state));
3290 styleObject->setProperty(
"_q_stylecontrols",
int(option->activeSubControls));
3291 styleObject->setProperty(
"_q_stylerect", option->rect);
3293 bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken)
3294 || (state & State_On) != (oldState & State_On)
3295 || (state & State_MouseOver) != (oldState & State_MouseOver)
3296 || oldActiveControls !=
int(option->activeSubControls));
3298 if (qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3299 QRect oldSliderPos = styleObject->property(
"_q_stylesliderpos").toRect();
3300 QRect currentPos = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3301 styleObject->setProperty(
"_q_stylesliderpos", currentPos);
3302 if (oldSliderPos != currentPos) {
3303 doTransition =
false;
3304 d->stopAnimation(styleObject);
3306 }
else if (control == CC_SpinBox) {
3309 doTransition = (state & State_HasFocus) != (oldState & State_HasFocus);
3312 if (oldRect != option->rect) {
3313 doTransition =
false;
3314 d->stopAnimation(styleObject);
3318 QImage startImage = createAnimationBuffer(option, widget);
3319 QPainter startPainter(&startImage);
3321 QImage endImage = createAnimationBuffer(option, widget);
3324 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
3328 QStyleOptionComplex *styleOption = qstyleoption_cast<QStyleOptionComplex*>(clonedAnimationStyleOption(option));
3330 styleObject->setProperty(
"_q_no_animation",
true);
3334 styleOption->state = QStyle::State(oldState);
3335 styleOption->activeSubControls = QStyle::SubControl(oldActiveControls);
3336 proxy()->drawComplexControl(control, styleOption, &startPainter, widget);
3338 anim->paint(&startPainter, option);
3340 t->setStartImage(startImage);
3343 styleOption->state = option->state;
3344 styleOption->activeSubControls = option->activeSubControls;
3345 proxy()->drawComplexControl(control, styleOption, &endPainter, widget);
3347 styleObject->setProperty(
"_q_no_animation",
false);
3349 t->setEndImage(endImage);
3350 t->setStartTime(d->animationTime());
3352 if (option->state & State_MouseOver || option->state & State_Sunken)
3353 t->setDuration(150);
3355 t->setDuration(500);
3357 deleteClonedAnimationStyleOption(styleOption);
3358 d->startAnimation(t);
3360 if (QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject))) {
3361 anim->paint(painter, option);
3369#if QT_CONFIG(slider)
3371 if (
const auto *slider = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3372 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::TrackBarTheme);
3373 QRect slrect = slider->rect;
3374 QRegion tickreg = slrect;
3375 if (sub & SC_SliderGroove) {
3376 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
3377 if (slider->orientation == Qt::Horizontal) {
3379 stateId = TRS_NORMAL;
3380 theme.rect = QRect(slrect.left(), theme.rect.center().y() - 2, slrect.width(), 4);
3382 partId = TKP_TRACKVERT;
3383 stateId = TRVS_NORMAL;
3384 theme.rect = QRect(theme.rect.center().x() - 2, slrect.top(), 4, slrect.height());
3386 theme.partId = partId;
3387 theme.stateId = stateId;
3388 d->drawBackground(theme);
3389 tickreg -= theme.rect;
3391 if (sub & SC_SliderTickmarks) {
3392 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
3393 int ticks = slider->tickPosition;
3394 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
3395 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3396 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3397 int interval = slider->tickInterval;
3398 if (interval <= 0) {
3399 interval = slider->singleStep;
3400 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3402 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3404 interval = slider->pageStep;
3408 int fudge = len / 2;
3410 int bothOffset = (ticks & QSlider::TicksAbove && ticks & QSlider::TicksBelow) ? 1 : 0;
3411 painter->setPen(d->sliderTickColor);
3412 QVarLengthArray<QLine, 32> lines;
3413 int v = slider->minimum;
3414 while (v <= slider->maximum + 1) {
3415 if (v == slider->maximum + 1 && interval == 1)
3417 const int v_ = qMin(v, slider->maximum);
3418 int tickLength = (v_ == slider->minimum || v_ >= slider->maximum) ? 4 : 3;
3419 pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3420 v_, available) + fudge;
3421 if (slider->orientation == Qt::Horizontal) {
3422 if (ticks & QSlider::TicksAbove) {
3423 lines.append(QLine(pos, tickOffset - 1 - bothOffset,
3424 pos, tickOffset - 1 - bothOffset - tickLength));
3427 if (ticks & QSlider::TicksBelow) {
3428 lines.append(QLine(pos, tickOffset + thickness + bothOffset,
3429 pos, tickOffset + thickness + bothOffset + tickLength));
3432 if (ticks & QSlider::TicksAbove) {
3433 lines.append(QLine(tickOffset - 1 - bothOffset, pos,
3434 tickOffset - 1 - bothOffset - tickLength, pos));
3437 if (ticks & QSlider::TicksBelow) {
3438 lines.append(QLine(tickOffset + thickness + bothOffset, pos,
3439 tickOffset + thickness + bothOffset + tickLength, pos));
3443 int nextInterval = v + interval;
3444 if (nextInterval < v)
3448 if (!lines.isEmpty()) {
3450 painter->translate(slrect.topLeft());
3451 painter->drawLines(lines.constData(), lines.size());
3455 if (sub & SC_SliderHandle) {
3456 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
3457 if (slider->orientation == Qt::Horizontal) {
3458 if (slider->tickPosition == QSlider::TicksAbove)
3459 partId = TKP_THUMBTOP;
3460 else if (slider->tickPosition == QSlider::TicksBelow)
3461 partId = TKP_THUMBBOTTOM;
3465 if (!(slider->state & State_Enabled))
3466 stateId = TUS_DISABLED;
3467 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3468 stateId = TUS_PRESSED;
3469 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3471 else if (flags & State_HasFocus)
3472 stateId = TUS_FOCUSED;
3474 stateId = TUS_NORMAL;
3476 if (slider->tickPosition == QSlider::TicksLeft)
3477 partId = TKP_THUMBLEFT;
3478 else if (slider->tickPosition == QSlider::TicksRight)
3479 partId = TKP_THUMBRIGHT;
3481 partId = TKP_THUMBVERT;
3483 if (!(slider->state & State_Enabled))
3484 stateId = TUVS_DISABLED;
3485 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3486 stateId = TUVS_PRESSED;
3487 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3489 else if (flags & State_HasFocus)
3490 stateId = TUVS_FOCUSED;
3492 stateId = TUVS_NORMAL;
3494 theme.partId = partId;
3495 theme.stateId = stateId;
3496 d->drawBackground(theme);
3498 if (slider->state & State_HasFocus) {
3499 QStyleOptionFocusRect fropt;
3500 fropt.QStyleOption::operator=(*slider);
3501 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
3502 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3508#if QT_CONFIG(toolbutton)
3510 if (
const auto *toolbutton = qstyleoption_cast<
const QStyleOptionToolButton *>(option)) {
3511 QRect button, menuarea;
3512 button = proxy()->subControlRect(control, toolbutton, SC_ToolButton, widget);
3513 menuarea = proxy()->subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
3515 State bflags = toolbutton->state & ~State_Sunken;
3516 State mflags = bflags;
3517 bool autoRaise = flags & State_AutoRaise;
3519 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled))
3520 bflags &= ~State_Raised;
3523 if (toolbutton->state & State_Sunken) {
3524 if (toolbutton->activeSubControls & SC_ToolButton) {
3525 bflags |= State_Sunken;
3526 mflags |= State_MouseOver | State_Sunken;
3527 }
else if (toolbutton->activeSubControls & SC_ToolButtonMenu) {
3528 mflags |= State_Sunken;
3529 bflags |= State_MouseOver;
3533 QStyleOption tool = *toolbutton;
3534 if (toolbutton->subControls & SC_ToolButton) {
3535 if (flags & (State_Sunken | State_On | State_Raised) || !autoRaise) {
3536 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup && autoRaise) {
3537 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ToolBarTheme);
3538 theme.partId = TP_SPLITBUTTON;
3539 theme.rect = button;
3540 if (!(bflags & State_Enabled))
3541 stateId = TS_DISABLED;
3542 else if (bflags & State_Sunken)
3543 stateId = TS_PRESSED;
3544 else if (bflags & State_MouseOver || !(flags & State_AutoRaise))
3545 stateId = flags & State_On ? TS_HOTCHECKED : TS_HOT;
3546 else if (bflags & State_On)
3547 stateId = TS_CHECKED;
3549 stateId = TS_NORMAL;
3550 if (option->direction == Qt::RightToLeft)
3551 theme.mirrorHorizontally =
true;
3552 theme.stateId = stateId;
3553 d->drawBackground(theme);
3555 tool.rect = option->rect;
3556 tool.state = bflags;
3558 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
3560 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter, widget);
3565 if (toolbutton->state & State_HasFocus) {
3566 QStyleOptionFocusRect fr;
3567 fr.QStyleOption::operator=(*toolbutton);
3568 fr.rect.adjust(3, 3, -3, -3);
3569 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
3570 fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator,
3571 toolbutton, widget), 0);
3572 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
3574 QStyleOptionToolButton label = *toolbutton;
3575 label.state = bflags;
3578 label.state &= ~State_Sunken;
3579 label.rect = button.adjusted(fw, fw, -fw, -fw);
3580 proxy()->drawControl(CE_ToolButtonLabel, &label, painter, widget);
3582 if (toolbutton->subControls & SC_ToolButtonMenu) {
3583 tool.rect = menuarea;
3584 tool.state = mflags;
3586 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, painter, widget);
3588 tool.state = mflags;
3589 menuarea.adjust(-2, 0, 0, 0);
3591 if ((bflags & State_Sunken) != (mflags & State_Sunken)){
3593 painter->setClipRect(menuarea);
3594 tool.rect = option->rect;
3595 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter,
nullptr);
3600 painter->setPen(option->palette.dark().color());
3601 painter->drawLine(menuarea.left(), menuarea.top() + 3,
3602 menuarea.left(), menuarea.bottom() - 3);
3603 painter->setPen(option->palette.light().color());
3604 painter->drawLine(menuarea.left() - 1, menuarea.top() + 3,
3605 menuarea.left() - 1, menuarea.bottom() - 3);
3607 tool.rect = menuarea.adjusted(2, 3, -2, -1);
3608 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
3611 }
else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
3612 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
3613 QRect ir = toolbutton->rect;
3614 QStyleOptionToolButton newBtn = *toolbutton;
3615 newBtn.rect = QRect(ir.right() + 4 - mbi, ir.height() - mbi + 4, mbi - 5, mbi - 5);
3616 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
3623 if (
const auto *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(option)) {
3624 const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget);
3625 bool isActive = tb->titleBarState & QStyle::State_Active;
3626 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme);
3627 if (sub & SC_TitleBarLabel) {
3628 partId = (tb->titleBarState & Qt::WindowMinimized) ? WP_MINCAPTION : WP_CAPTION;
3629 theme.rect = option->rect;
3630 if (widget && !widget->isEnabled())
3631 stateId = CS_DISABLED;
3633 stateId = CS_ACTIVE;
3635 stateId = CS_INACTIVE;
3637 theme.partId = partId;
3638 theme.stateId = stateId;
3639 d->drawBackground(theme);
3641 QRect ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
3644 GetThemeEnumValue(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3646 COLORREF textShadowRef;
3647 GetThemeColor(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE,
TMT_TEXTSHADOWCOLOR, &textShadowRef);
3648 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3649 painter->setPen(textShadow);
3650 painter->drawText(
int(ir.x() + 3 * factor),
int(ir.y() + 2 * factor),
3651 int(ir.width() - 1 * factor), ir.height(),
3652 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3654 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3655 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3656 painter->setPen(textColor);
3657 painter->drawText(
int(ir.x() + 2 * factor),
int(ir.y() + 1 * factor),
3658 int(ir.width() - 2 * factor), ir.height(),
3659 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3661 if (sub & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3662 theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarSysMenu, widget);
3663 partId = WP_SYSBUTTON;
3664 if ((widget && !widget->isEnabled()) || !isActive)
3665 stateId = SBS_DISABLED;
3666 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_Sunken))
3667 stateId = SBS_PUSHED;
3668 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_MouseOver))
3671 stateId = SBS_NORMAL;
3672 if (!tb->icon.isNull()) {
3673 tb->icon.paint(painter, theme.rect);
3675 theme.partId = partId;
3676 theme.stateId = stateId;
3677 if (theme.size().isEmpty()) {
3678 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, tb, widget);
3679 const auto dpr = QStyleHelper::getDpr(widget);
3680 const auto icon = proxy()->standardIcon(SP_TitleBarMenuButton, tb, widget);
3681 const auto pm = icon.pixmap(QSize(extent, extent), dpr);
3682 drawItemPixmap(painter, theme.rect, Qt::AlignCenter, pm);
3684 d->drawBackground(theme);
3689 if (sub & SC_TitleBarMinButton && tb->titleBarFlags & Qt::WindowMinimizeButtonHint
3690 && !(tb->titleBarState & Qt::WindowMinimized)) {
3691 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMinButton, isActive, WP_MINBUTTON, &theme);
3692 d->drawBackground(theme);
3694 if (sub & SC_TitleBarMaxButton && tb->titleBarFlags & Qt::WindowMaximizeButtonHint
3695 && !(tb->titleBarState & Qt::WindowMaximized)) {
3696 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMaxButton, isActive, WP_MAXBUTTON, &theme);
3697 d->drawBackground(theme);
3699 if (sub & SC_TitleBarContextHelpButton
3700 && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
3701 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarContextHelpButton, isActive, WP_HELPBUTTON, &theme);
3702 d->drawBackground(theme);
3704 bool drawNormalButton = (sub & SC_TitleBarNormalButton)
3705 && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3706 && (tb->titleBarState & Qt::WindowMinimized))
3707 || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3708 && (tb->titleBarState & Qt::WindowMaximized)));
3709 if (drawNormalButton) {
3710 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarNormalButton, isActive, WP_RESTOREBUTTON, &theme);
3711 d->drawBackground(theme);
3713 if (sub & SC_TitleBarShadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3714 && !(tb->titleBarState & Qt::WindowMinimized)) {
3715 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarShadeButton, isActive, WP_MINBUTTON, &theme);
3716 d->drawBackground(theme);
3718 if (sub & SC_TitleBarUnshadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3719 && tb->titleBarState & Qt::WindowMinimized) {
3720 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarUnshadeButton, isActive, WP_RESTOREBUTTON, &theme);
3721 d->drawBackground(theme);
3723 if (sub & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3724 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarCloseButton, isActive, WP_CLOSEBUTTON, &theme);
3725 d->drawBackground(theme);
3730#if QT_CONFIG(mdiarea)
3731 case CC_MdiControls: {
3732 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme, WP_MDICLOSEBUTTON, CBS_NORMAL);
3733 if (Q_UNLIKELY(!theme.isValid()))
3736 if (option->subControls.testFlag(SC_MdiCloseButton)) {
3737 populateMdiButtonTheme(proxy(), widget, option, SC_MdiCloseButton, WP_MDICLOSEBUTTON, &theme);
3738 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3740 if (option->subControls.testFlag(SC_MdiNormalButton)) {
3741 populateMdiButtonTheme(proxy(), widget, option, SC_MdiNormalButton, WP_MDIRESTOREBUTTON, &theme);
3742 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3744 if (option->subControls.testFlag(QStyle::SC_MdiMinButton)) {
3745 populateMdiButtonTheme(proxy(), widget, option, SC_MdiMinButton, WP_MDIMINBUTTON, &theme);
3746 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3754 if (
const auto *dial = qstyleoption_cast<
const QStyleOptionSlider *>(option))
3755 QStyleHelper::drawDial(dial, painter);
3760 if (
const QStyleOptionComboBox *cmb = qstyleoption_cast<
const QStyleOptionComboBox *>(option)) {
3761 if (cmb->editable) {
3762 if (sub & SC_ComboBoxEditField) {
3763 partId = EP_EDITBORDER_NOSCROLL;
3764 if (!(flags & State_Enabled))
3765 stateId = ETS_DISABLED;
3766 else if (flags & State_MouseOver)
3768 else if (flags & State_HasFocus)
3769 stateId = ETS_FOCUSED;
3771 stateId = ETS_NORMAL;
3773 QWindowsThemeData theme(widget, painter,
3774 QWindowsVistaStylePrivate::EditTheme,
3775 partId, stateId, r);
3777 d->drawBackground(theme);
3779 if (sub & SC_ComboBoxArrow) {
3780 QRect subRect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3781 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3782 theme.rect = subRect;
3783 partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3785 if (!(cmb->state & State_Enabled))
3786 stateId = CBXS_DISABLED;
3787 else if (cmb->state & State_Sunken || cmb->state & State_On)
3788 stateId = CBXS_PRESSED;
3789 else if (cmb->state & State_MouseOver && option->activeSubControls & SC_ComboBoxArrow)
3792 stateId = CBXS_NORMAL;
3794 theme.partId = partId;
3795 theme.stateId = stateId;
3796 d->drawBackground(theme);
3800 if (sub & SC_ComboBoxFrame) {
3801 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3802 theme.rect = option->rect;
3803 theme.partId = CP_READONLY;
3804 if (!(cmb->state & State_Enabled))
3805 theme.stateId = CBXS_DISABLED;
3806 else if (cmb->state & State_Sunken || cmb->state & State_On)
3807 theme.stateId = CBXS_PRESSED;
3808 else if (cmb->state & State_MouseOver)
3809 theme.stateId = CBXS_HOT;
3811 theme.stateId = CBXS_NORMAL;
3812 d->drawBackground(theme);
3814 if (sub & SC_ComboBoxArrow) {
3815 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3816 theme.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3817 theme.partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3818 if (!(cmb->state & State_Enabled))
3819 theme.stateId = CBXS_DISABLED;
3821 theme.stateId = CBXS_NORMAL;
3822 d->drawBackground(theme);
3824 if ((sub & SC_ComboBoxEditField) && (flags & State_HasFocus)) {
3825 QStyleOptionFocusRect fropt;
3826 fropt.QStyleOption::operator=(*cmb);
3827 fropt.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget);
3828 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3835 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3836 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ScrollBarTheme);
3837 bool maxedOut = (scrollbar->maximum == scrollbar->minimum);
3839 flags &= ~State_Enabled;
3841 bool isHorz = flags & State_Horizontal;
3842 bool isRTL = option->direction == Qt::RightToLeft;
3843 if (sub & SC_ScrollBarAddLine) {
3844 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddLine, widget);
3845 partId = SBP_ARROWBTN;
3846 if (!(flags & State_Enabled))
3847 stateId = (isHorz ? (isRTL ? ABS_LEFTDISABLED : ABS_RIGHTDISABLED) : ABS_DOWNDISABLED);
3848 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_Sunken))
3849 stateId = (isHorz ? (isRTL ? ABS_LEFTPRESSED : ABS_RIGHTPRESSED) : ABS_DOWNPRESSED);
3850 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_MouseOver))
3851 stateId = (isHorz ? (isRTL ? ABS_LEFTHOT : ABS_RIGHTHOT) : ABS_DOWNHOT);
3852 else if (scrollbar->state & State_MouseOver)
3853 stateId = (isHorz ? (isRTL ? ABS_LEFTHOVER : ABS_RIGHTHOVER) : ABS_DOWNHOVER);
3855 stateId = (isHorz ? (isRTL ? ABS_LEFTNORMAL : ABS_RIGHTNORMAL) : ABS_DOWNNORMAL);
3856 theme.partId = partId;
3857 theme.stateId = stateId;
3858 d->drawBackground(theme);
3860 if (sub & SC_ScrollBarSubLine) {
3861 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubLine, widget);
3862 partId = SBP_ARROWBTN;
3863 if (!(flags & State_Enabled))
3864 stateId = (isHorz ? (isRTL ? ABS_RIGHTDISABLED : ABS_LEFTDISABLED) : ABS_UPDISABLED);
3865 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_Sunken))
3866 stateId = (isHorz ? (isRTL ? ABS_RIGHTPRESSED : ABS_LEFTPRESSED) : ABS_UPPRESSED);
3867 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_MouseOver))
3868 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOT : ABS_LEFTHOT) : ABS_UPHOT);
3869 else if (scrollbar->state & State_MouseOver)
3870 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOVER : ABS_LEFTHOVER) : ABS_UPHOVER);
3872 stateId = (isHorz ? (isRTL ? ABS_RIGHTNORMAL : ABS_LEFTNORMAL) : ABS_UPNORMAL);
3873 theme.partId = partId;
3874 theme.stateId = stateId;
3875 d->drawBackground(theme);
3878 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3879 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget));
3880 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget));
3881 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3882 stateId = SCRBS_DISABLED;
3883 theme.partId = partId;
3884 theme.stateId = stateId;
3885 d->drawBackground(theme);
3887 if (sub & SC_ScrollBarSubPage) {
3888 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget);
3889 partId = flags & State_Horizontal ? SBP_UPPERTRACKHORZ : SBP_UPPERTRACKVERT;
3890 if (!(flags & State_Enabled))
3891 stateId = SCRBS_DISABLED;
3892 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_Sunken))
3893 stateId = SCRBS_PRESSED;
3894 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_MouseOver))
3895 stateId = SCRBS_HOT;
3897 stateId = SCRBS_NORMAL;
3898 theme.partId = partId;
3899 theme.stateId = stateId;
3900 d->drawBackground(theme);
3902 if (sub & SC_ScrollBarAddPage) {
3903 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget);
3904 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3905 if (!(flags & State_Enabled))
3906 stateId = SCRBS_DISABLED;
3907 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_Sunken))
3908 stateId = SCRBS_PRESSED;
3909 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_MouseOver))
3910 stateId = SCRBS_HOT;
3912 stateId = SCRBS_NORMAL;
3913 theme.partId = partId;
3914 theme.stateId = stateId;
3915 d->drawBackground(theme);
3917 if (sub & SC_ScrollBarSlider) {
3918 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3919 if (!(flags & State_Enabled))
3920 stateId = SCRBS_DISABLED;
3921 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_Sunken))
3922 stateId = SCRBS_PRESSED;
3923 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_MouseOver))
3924 stateId = SCRBS_HOT;
3925 else if (option->state & State_MouseOver)
3926 stateId = SCRBS_HOVER;
3928 stateId = SCRBS_NORMAL;
3931 theme.partId = flags & State_Horizontal ? SBP_THUMBBTNHORZ : SBP_THUMBBTNVERT;
3932 theme.stateId = stateId;
3933 d->drawBackground(theme);
3939#if QT_CONFIG(spinbox)
3941 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(option)) {
3942 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::SpinTheme);
3943 if (sb->frame && (sub & SC_SpinBoxFrame)) {
3944 partId = EP_EDITBORDER_NOSCROLL;
3945 if (!(flags & State_Enabled))
3946 stateId = ETS_DISABLED;
3947 else if (flags & State_MouseOver)
3949 else if (flags & State_HasFocus)
3950 stateId = ETS_SELECTED;
3952 stateId = ETS_NORMAL;
3954 QWindowsThemeData ftheme(widget, painter,
3955 QWindowsVistaStylePrivate::EditTheme,
3956 partId, stateId, r);
3961 ftheme.noContent = (widget !=
nullptr);
3962 d->drawBackground(ftheme);
3964 if (sub & SC_SpinBoxUp) {
3965 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
3967 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled) || !(flags & State_Enabled))
3968 stateId = UPS_DISABLED;
3969 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken))
3970 stateId = UPS_PRESSED;
3971 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_MouseOver))
3974 stateId = UPS_NORMAL;
3975 theme.partId = partId;
3976 theme.stateId = stateId;
3977 d->drawBackground(theme);
3979 if (sub & SC_SpinBoxDown) {
3980 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
3982 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled) || !(flags & State_Enabled))
3983 stateId = DNS_DISABLED;
3984 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken))
3985 stateId = DNS_PRESSED;
3986 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_MouseOver))
3989 stateId = DNS_NORMAL;
3990 theme.partId = partId;
3991 theme.stateId = stateId;
3992 d->drawBackground(theme);
3999 QWindowsStyle::drawComplexControl(control, option, painter, widget);