729bool QWindowsVistaStylePrivate::drawBackgroundThruNativeBuffer(QWindowsThemeData &themeData,
730 qreal additionalDevicePixelRatio,
731 qreal correctionFactor)
733 QPainter *painter = themeData.painter;
734 QRectF rectF = scaleRect(QRectF(themeData.rect), additionalDevicePixelRatio);
736 if ((themeData.rotate + 90) % 180 == 0) {
737 rectF = QRectF(0, 0, rectF.height(), rectF.width());
741 const bool hasCorrectionFactor = !qFuzzyCompare(correctionFactor, qreal(1));
742 QRect rect = rectF.toRect();
743 const QRect drawRect = hasCorrectionFactor
744 ? QRectF(rectF.topLeft() / correctionFactor, rectF.size() / correctionFactor).toRect()
746 int partId = themeData.partId;
747 int stateId = themeData.stateId;
748 int w = rect.width();
749 int h = rect.height();
753 bool stateHasData =
true;
754 bool hasAlpha =
false;
755 bool partIsTransparent;
756 bool potentialInvalidAlpha;
758 QString pixmapCacheKey = QStringLiteral(u"$qt_xp_");
759 pixmapCacheKey.append(themeName(themeData.theme));
760 pixmapCacheKey.append(QLatin1Char(
'p'));
761 pixmapCacheKey.append(QString::number(partId));
762 pixmapCacheKey.append(QLatin1Char(
's'));
763 pixmapCacheKey.append(QString::number(stateId));
764 pixmapCacheKey.append(QLatin1Char(
's'));
765 pixmapCacheKey.append(themeData.noBorder ? QLatin1Char(
'0') : QLatin1Char(
'1'));
766 pixmapCacheKey.append(QLatin1Char(
'b'));
767 pixmapCacheKey.append(themeData.noContent ? QLatin1Char(
'0') : QLatin1Char(
'1'));
768 pixmapCacheKey.append(QString::number(w));
769 pixmapCacheKey.append(QLatin1Char(
'w'));
770 pixmapCacheKey.append(QString::number(h));
771 pixmapCacheKey.append(QLatin1Char(
'h'));
772 pixmapCacheKey.append(QString::number(additionalDevicePixelRatio));
773 pixmapCacheKey.append(QLatin1Char(
'd'));
774 if (hasCorrectionFactor) {
775 pixmapCacheKey.append(QLatin1Char(
'c'));
776 pixmapCacheKey.append(QString::number(correctionFactor));
779 QPixmap cachedPixmap;
783 bool haveCachedPixmap =
false;
786 partIsTransparent = data.partIsTransparent;
787 hasAlpha = data.hasAlphaChannel;
788 alphaType = data.alphaType;
789 potentialInvalidAlpha = data.hadInvalidAlpha;
791 haveCachedPixmap = QPixmapCache::find(pixmapCacheKey, &cachedPixmap);
795 ::sprintf(buf,
"+ Pixmap(%3d, %3d) ]", w, h);
796 printf(
"---[ CACHED %s--------> Name(%-10s) Part(%d) State(%d)\n",
797 haveCachedPixmap ? buf :
"]-------------------",
798 qPrintable(themeData.name), themeData.partId, themeData.stateId);
802 BOOL tmt_borderonly =
false;
803 COLORREF tmt_transparentcolor = 0x0;
804 PROPERTYORIGIN proporigin = PO_NOTFOUND;
805 GetThemeBool(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERONLY, &tmt_borderonly);
806 GetThemeColor(themeData.handle(), themeData.partId, themeData.stateId, TMT_TRANSPARENTCOLOR, &tmt_transparentcolor);
807 GetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_CAPTIONMARGINS, &proporigin);
809 partIsTransparent = isTransparent(themeData);
811 potentialInvalidAlpha =
false;
812 GetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_GLYPHTYPE, &proporigin);
813 if (proporigin == PO_PART || proporigin == PO_STATE) {
814 int tmt_glyphtype = GT_NONE;
815 GetThemeEnumValue(themeData.handle(), themeData.partId, themeData.stateId, TMT_GLYPHTYPE, &tmt_glyphtype);
816 potentialInvalidAlpha = partIsTransparent && tmt_glyphtype == GT_IMAGEGLYPH;
820 printf(
"---[ NOT CACHED ]-----------------------> Name(%-10s) Part(%d) State(%d)\n",
821 qPrintable(themeData.name), themeData.partId, themeData.stateId);
822 printf(
"-->partIsTransparen = %d\n", partIsTransparent);
823 printf(
"-->potentialInvalidAlpha = %d\n", potentialInvalidAlpha);
824 showProperties(themeData);
827 bool wasAlphaSwapped =
false;
828 bool wasAlphaFixed =
false;
834 bool addBorderContentClipping =
false;
836 QRect area = drawRect;
837 if (themeData.noBorder || themeData.noContent) {
844 PROPERTYORIGIN origin = PO_NOTFOUND;
845 GetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERSIZE, &origin);
846 GetThemeInt(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERSIZE, &borderSize);
847 borderSize *= additionalDevicePixelRatio;
850 if ((origin == PO_CLASS || origin == PO_PART || origin == PO_STATE) && borderSize > 0) {
851 if (themeData.noBorder) {
853 area = area.adjusted(-borderSize, -borderSize, borderSize, borderSize);
857 if (themeData.noContent) {
858 QRegion content = area.adjusted(borderSize, borderSize, -borderSize, -borderSize);
859 extraClip ^= content;
862 addBorderContentClipping = (themeData.noBorder | themeData.noContent);
866 if (!haveCachedPixmap) {
867 if (!buffer(drawRect.width(), drawRect.height()))
869 HDC dc = bufferHDC();
872 if (alphaType != NoAlpha) {
874 memset(bufferPixels, 0x00, bufferW * drawRect.height() * 4);
878 int dx = area.x() - drawRect.x();
879 int dy = area.y() - drawRect.y();
884 DTBGOPTS drawOptions;
885 drawOptions.dwSize =
sizeof(drawOptions);
886 drawOptions.rcClip = themeData.toRECT(rect);
887 drawOptions.dwFlags = DTBG_CLIPRECT
888 | (themeData.noBorder ? DTBG_OMITBORDER : 0)
889 | (themeData.noContent ? DTBG_OMITCONTENT : 0);
892 RECT wRect(themeData.toRECT(area));
893 DrawThemeBackgroundEx(themeData.handle(), dc, themeData.partId, themeData.stateId, &wRect, &drawOptions);
900 memset(
static_cast<
void *>(&data), 0,
sizeof(data));
901 data.dataValid =
true;
902 alphaCache.insert(key, data);
905 hasAlpha = hasAlphaChannel(rect);
906 if (!hasAlpha && partIsTransparent)
907 potentialInvalidAlpha =
true;
908#if defined(DEBUG_XP_STYLE) && 1
909 dumpNativeDIB(drawRect.width(), drawRect.height());
914 if (potentialInvalidAlpha)
915 wasAlphaFixed = fixAlphaChannel(drawRect);
917 QImage::Format format;
918 if ((partIsTransparent && !wasAlphaSwapped) || (!partIsTransparent && hasAlpha)) {
919 format = QImage::Format_ARGB32_Premultiplied;
920 alphaType = RealAlpha;
921 }
else if (wasAlphaSwapped) {
922 format = QImage::Format_ARGB32_Premultiplied;
923 alphaType = MaskAlpha;
925 format = QImage::Format_RGB32;
930 swapAlphaChannel(rect,
true);
933#if defined(DEBUG_XP_STYLE) && 1
934 printf(
"Image format is: %s\n", alphaType == RealAlpha ?
"Real Alpha" : alphaType == MaskAlpha ?
"Masked Alpha" :
"No Alpha");
936 img = QImage(bufferPixels, bufferW, bufferH, format);
937 if (themeData.invertPixels)
940 if (hasCorrectionFactor)
941 img = img.scaled(img.size() * correctionFactor, Qt::KeepAspectRatio, Qt::SmoothTransformation);
942 img.setDevicePixelRatio(additionalDevicePixelRatio);
946 bool useRegion = partIsTransparent && !hasAlpha && !wasAlphaSwapped;
951 newRegion = region(themeData);
952 oldRegion = painter->clipRegion();
953 painter->setClipRegion(newRegion);
954#if defined(DEBUG_XP_STYLE) && 0
955 printf(
"Using region:\n");
956 for (
const QRect &r : newRegion)
957 printf(
" (%d, %d, %d, %d)\n", r.x(), r.y(), r.right(), r.bottom());
961 if (addBorderContentClipping)
962 painter->setClipRegion(scaleRegion(extraClip, 1.0 / additionalDevicePixelRatio), Qt::IntersectClip);
964 if (!themeData.mirrorHorizontally && !themeData.mirrorVertically && !themeData.rotate) {
965 if (!haveCachedPixmap)
966 painter->drawImage(themeData.rect, img, rect);
968 painter->drawPixmap(themeData.rect, cachedPixmap);
976 if (!haveCachedPixmap)
977 imgCopy = img.copy(rect);
979 imgCopy = cachedPixmap.toImage();
981 if (themeData.rotate) {
982 QTransform rotMatrix;
983 rotMatrix.rotate(themeData.rotate);
984 imgCopy = imgCopy.transformed(rotMatrix);
986 Qt::Orientations orient = {};
987 if (themeData.mirrorHorizontally)
988 orient |= Qt::Horizontal;
989 if (themeData.mirrorVertically)
990 orient |= Qt::Vertical;
991 if (themeData.mirrorHorizontally || themeData.mirrorVertically)
992 imgCopy.flip(orient);
993 painter->drawImage(themeData.rect, imgCopy);
996 if (useRegion || addBorderContentClipping) {
997 if (oldRegion.isEmpty())
998 painter->setClipping(
false);
1000 painter->setClipRegion(oldRegion);
1004 if (!haveCachedPixmap && w && h) {
1005 QPixmap pix = QPixmap::fromImage(img).copy(rect);
1006 QPixmapCache::insert(pixmapCacheKey, pix);
1007#ifdef DEBUG_XP_STYLE
1008 printf(
"+++Adding pixmap to cache, size(%d, %d), wasAlphaSwapped(%d), wasAlphaFixed(%d), name(%s)\n",
1009 w, h, wasAlphaSwapped, wasAlphaFixed, qPrintable(pixmapCacheKey));
1015 memset(
static_cast<
void *>(&data), 0,
sizeof(data));
1016 data.dataValid =
true;
1017 data.partIsTransparent = partIsTransparent;
1018 data.alphaType = alphaType;
1019 data.hasAlphaChannel = hasAlpha;
1020 data.wasAlphaSwapped = wasAlphaSwapped;
1021 data.hadInvalidAlpha = wasAlphaFixed;
1022 alphaCache.insert(key, data);
1335void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element,
const QStyleOption *option,
1336 QPainter *painter,
const QWidget *widget)
const
1338 if (!QWindowsVistaStylePrivate::useVista()) {
1339 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1345 int state = option->state;
1346 QRect rect = option->rect;
1348 if ((state & State_Enabled) && d->transitionsEnabled() && canAnimate(option)) {
1349 if (supportsStateTransition(element, option, widget)) {
1352 QObject *styleObject = option->styleObject;
1353 styleObject->setProperty(
"_q_no_animation",
true);
1354 int oldState = styleObject->property(
"_q_stylestate").toInt();
1355 QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
1356 QRect newRect = rect;
1357 styleObject->setProperty(
"_q_stylestate",
int(option->state));
1358 styleObject->setProperty(
"_q_stylerect", option->rect);
1360 bool doTransition = oldState &&
1361 ((state & State_Sunken) != (oldState & State_Sunken) ||
1362 (state & State_On) != (oldState & State_On) ||
1363 (state & State_MouseOver) != (oldState & State_MouseOver));
1365 if (oldRect != newRect ||
1366 (state & State_Enabled) != (oldState & State_Enabled) ||
1367 (state & State_Active) != (oldState & State_Active))
1368 d->stopAnimation(styleObject);
1370 if (state & State_ReadOnly && element == PE_FrameLineEdit)
1371 doTransition =
false;
1374 QStyleOption *styleOption = clonedAnimationStyleOption(option);
1375 styleOption->state = QStyle::State(oldState);
1377 QWindowsVistaAnimation *animate = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
1382 QImage startImage = createAnimationBuffer(option, widget);
1383 QPainter startPainter(&startImage);
1385 QImage endImage = createAnimationBuffer(option, widget);
1392 proxy()->drawPrimitive(element, styleOption, &startPainter, widget);
1394 animate->paint(&startPainter, styleOption);
1396 transition->setStartImage(startImage);
1400 styleOption->styleObject =
nullptr;
1401 styleOption->state = option->state;
1402 proxy()->drawPrimitive(element, styleOption, &endPainter, widget);
1404 transition->setEndImage(endImage);
1413 if (element == PE_FrameLineEdit) {
1414 theme = OpenThemeData(
nullptr, L"Edit");
1415 partId = EP_EDITBORDER_NOSCROLL;
1417 if (oldState & State_HasFocus)
1418 fromState = ETS_SELECTED;
1419 else if (oldState & State_MouseOver)
1420 fromState = ETS_HOT;
1422 fromState = ETS_NORMAL;
1424 if (state & State_HasFocus)
1425 toState = ETS_SELECTED;
1426 else if (state & State_MouseOver)
1429 toState = ETS_NORMAL;
1432 theme = OpenThemeData(
nullptr, L"Button");
1433 if (element == PE_IndicatorRadioButton)
1434 partId = BP_RADIOBUTTON;
1435 else if (element == PE_IndicatorCheckBox)
1436 partId = BP_CHECKBOX;
1438 partId = BP_PUSHBUTTON;
1440 fromState = buttonStateId(oldState, partId);
1441 toState = buttonStateId(option->state, partId);
1446 && SUCCEEDED(GetThemeTransitionDuration(theme, partId, fromState, toState,
1447 TMT_TRANSITIONDURATIONS, &duration))) {
1448 transition->setDuration(
int(duration));
1450 transition->setStartTime(d->animationTime());
1452 deleteClonedAnimationStyleOption(styleOption);
1453 d->startAnimation(transition);
1455 styleObject->setProperty(
"_q_no_animation",
false);
1459 int themeNumber = -1;
1462 bool hMirrored =
false;
1463 bool vMirrored =
false;
1464 bool noBorder =
false;
1465 bool noContent =
false;
1469 case PE_PanelButtonCommand:
1470 if (
const auto *btn = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
1472 if (!(state & State_Sunken) && (state & State_On))
1473 fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1475 fill = option->palette.brush(QPalette::Button);
1476 if (btn->features & QStyleOptionButton::DefaultButton && state & State_Sunken) {
1477 painter->setPen(option->palette.dark().color());
1478 painter->setBrush(fill);
1479 painter->drawRect(rect.adjusted(0, 0, -1, -1));
1480 }
else if (state & (State_Raised | State_On | State_Sunken)) {
1481 qDrawWinButton(painter, rect, option->palette, state & (State_Sunken | State_On),
1484 painter->fillRect(rect, fill);
1489 case PE_PanelButtonTool:
1490#if QT_CONFIG(dockwidget)
1491 if (widget && widget->inherits(
"QDockWidgetTitleButton")) {
1492 if (
const QWidget *dw = widget->parentWidget())
1493 if (dw->isWindow()) {
1498 themeNumber = QWindowsVistaStylePrivate::ToolBarTheme;
1500 if (!(option->state & State_Enabled))
1501 stateId = TS_DISABLED;
1502 else if (option->state & State_Sunken)
1503 stateId = TS_PRESSED;
1504 else if (option->state & State_MouseOver)
1505 stateId = option->state & State_On ? TS_HOTCHECKED : TS_HOT;
1506 else if (option->state & State_On)
1507 stateId = TS_CHECKED;
1508 else if (!(option->state & State_AutoRaise))
1511 stateId = TS_NORMAL;
1515 case PE_IndicatorHeaderArrow:
1516 if (
const auto *header = qstyleoption_cast<
const QStyleOptionHeader *>(option)) {
1517 int stateId = HSAS_SORTEDDOWN;
1518 if (header->sortIndicator & QStyleOptionHeader::SortDown)
1519 stateId = HSAS_SORTEDUP;
1520 QWindowsThemeData theme(widget, painter,
1521 QWindowsVistaStylePrivate::HeaderTheme,
1522 HP_HEADERSORTARROW, stateId, option->rect);
1523 d->drawBackground(theme);
1528 case PE_IndicatorCheckBox:
1530 qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1531 animate->paint(painter, option);
1534 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1535 partId = BP_CHECKBOX;
1537 if (!(option->state & State_Enabled))
1538 stateId = CBS_UNCHECKEDDISABLED;
1539 else if (option->state & State_Sunken)
1540 stateId = CBS_UNCHECKEDPRESSED;
1541 else if (option->state & State_MouseOver)
1542 stateId = CBS_UNCHECKEDHOT;
1544 stateId = CBS_UNCHECKEDNORMAL;
1546 if (option->state & State_On)
1547 stateId += CBS_CHECKEDNORMAL-1;
1548 else if (option->state & State_NoChange)
1549 stateId += CBS_MIXEDNORMAL-1;
1553 case PE_IndicatorItemViewItemCheck: {
1554 QStyleOptionButton button;
1555 button.QStyleOption::operator=(*option);
1556 button.state &= ~State_MouseOver;
1557 proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
1561 case PE_IndicatorBranch: {
1562 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::VistaTreeViewTheme);
1563 static int decoration_size = 0;
1564 if (!decoration_size && theme.isValid()) {
1565 QWindowsThemeData themeSize = theme;
1566 themeSize.partId = TVP_HOTGLYPH;
1567 themeSize.stateId = GLPS_OPENED;
1568 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
1569 decoration_size = qRound(qMax(size.width(), size.height()));
1571 int mid_h = option->rect.x() + option->rect.width() / 2;
1572 int mid_v = option->rect.y() + option->rect.height() / 2;
1573 if (option->state & State_Children) {
1574 int delta = decoration_size / 2;
1575 theme.rect = QRect(mid_h - delta, mid_v - delta, decoration_size, decoration_size);
1576 theme.partId = option->state & State_MouseOver ? TVP_HOTGLYPH : TVP_GLYPH;
1577 theme.stateId = option->state & QStyle::State_Open ? GLPS_OPENED : GLPS_CLOSED;
1578 if (option->direction == Qt::RightToLeft)
1579 theme.mirrorHorizontally =
true;
1580 d->drawBackground(theme);
1585 case PE_PanelButtonBevel:
1586 if (QWindowsVistaAnimation *animate =
1587 qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1588 animate->paint(painter, option);
1592 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1593 partId = BP_PUSHBUTTON;
1594 if (!(option->state & State_Enabled))
1595 stateId = PBS_DISABLED;
1596 else if ((option->state & State_Sunken) || (option->state & State_On))
1597 stateId = PBS_PRESSED;
1598 else if (option->state & State_MouseOver)
1601 stateId = PBS_NORMAL;
1604 case PE_IndicatorRadioButton:
1605 if (QWindowsVistaAnimation *animate =
1606 qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1607 animate->paint(painter, option);
1610 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1611 partId = BP_RADIOBUTTON;
1613 if (!(option->state & State_Enabled))
1614 stateId = RBS_UNCHECKEDDISABLED;
1615 else if (option->state & State_Sunken)
1616 stateId = RBS_UNCHECKEDPRESSED;
1617 else if (option->state & State_MouseOver)
1618 stateId = RBS_UNCHECKEDHOT;
1620 stateId = RBS_UNCHECKEDNORMAL;
1622 if (option->state & State_On)
1623 stateId += RBS_CHECKEDNORMAL-1;
1628 if (widget && widget->inherits(
"QComboBoxPrivateContainer")){
1629 QStyleOption copy = *option;
1630 copy.state |= State_Raised;
1631 proxy()->drawPrimitive(PE_PanelMenu, ©, painter, widget);
1634#if QT_CONFIG(accessibility)
1635 if (QStyleHelper::isInstanceOf(option->styleObject, QAccessible::EditableText)
1636 || QStyleHelper::isInstanceOf(option->styleObject, QAccessible::StaticText) ||
1640 (widget && widget->inherits(
"QTextEdit"))) {
1642 int stateId = ETS_NORMAL;
1643 if (!(state & State_Enabled))
1644 stateId = ETS_DISABLED;
1645 else if (state & State_ReadOnly)
1646 stateId = ETS_READONLY;
1647 else if (state & State_HasFocus)
1648 stateId = ETS_SELECTED;
1649 QWindowsThemeData theme(widget, painter,
1650 QWindowsVistaStylePrivate::EditTheme,
1651 EP_EDITBORDER_HVSCROLL, stateId, option->rect);
1654 GetThemeInt(theme.handle(), theme.partId, theme.stateId, TMT_BORDERSIZE, &borderSize);
1655 QRegion clipRegion = option->rect;
1656 QRegion content = option->rect.adjusted(borderSize, borderSize, -borderSize, -borderSize);
1657 clipRegion ^= content;
1658 painter->setClipRegion(clipRegion);
1659 d->drawBackground(theme);
1663 if (option->state & State_Raised)
1666 themeNumber = QWindowsVistaStylePrivate::ListViewTheme;
1667 partId = LVP_LISTGROUP;
1668 QWindowsThemeData theme(widget,
nullptr, themeNumber, partId);
1670 if (!(option->state & State_Enabled))
1671 stateId = ETS_DISABLED;
1673 stateId = ETS_NORMAL;
1677 if (GetThemeEnumValue(theme.handle(), partId, stateId, TMT_BGTYPE, &fillType) == S_OK) {
1678 if (fillType == BT_BORDERFILL) {
1680 GetThemeColor(theme.handle(), partId, stateId, TMT_BORDERCOLOR, &bcRef);
1681 QColor bordercolor(qRgb(GetRValue(bcRef), GetGValue(bcRef), GetBValue(bcRef)));
1682 QPen oldPen = painter->pen();
1685 painter->setPen(QPen(option->palette.base().color(), 0));
1686 const qreal dpi = QStyleHelper::dpi(option);
1687 const auto topLevelAdjustment = QStyleHelper::dpiScaled(0.5, dpi);
1688 const auto bottomRightAdjustment = QStyleHelper::dpiScaled(-1, dpi);
1689 painter->drawRect(QRectF(option->rect).adjusted(topLevelAdjustment, topLevelAdjustment,
1690 bottomRightAdjustment, bottomRightAdjustment));
1692 painter->setPen(QPen(bordercolor, 0));
1693 painter->drawRect(QRectF(option->rect).adjusted(0, 0, -topLevelAdjustment, -topLevelAdjustment));
1694 painter->setPen(oldPen);
1697 if (fillType == BT_BORDERFILL || fillType == BT_NONE)
1703 case PE_FrameMenu: {
1704 int stateId = option->state & State_Active ? MB_ACTIVE : MB_INACTIVE;
1705 QWindowsThemeData theme(widget, painter,
1706 QWindowsVistaStylePrivate::MenuTheme,
1707 MENU_POPUPBORDERS, stateId, option->rect);
1708 d->drawBackground(theme);
1713 if (widget && widget->inherits(
"QComboBoxPrivateContainer")){
1715 QWindowsThemeData popupbackgroundTheme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
1716 MENU_POPUPBACKGROUND, stateId, option->rect);
1717 d->drawBackground(popupbackgroundTheme);
1722 case PE_PanelMenuBar:
1725#if QT_CONFIG(dockwidget)
1726 case PE_IndicatorDockWidgetResizeHandle:
1729 case PE_FrameDockWidget:
1730 if (
const auto *frm = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1731 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
1732 if (option->state & State_Active)
1733 stateId = FS_ACTIVE;
1735 stateId = FS_INACTIVE;
1737 int fwidth = proxy()->pixelMetric(PM_DockWidgetFrameWidth, frm, widget);
1739 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
1741 if (!theme.isValid())
1744 theme.rect = QRect(frm->rect.x(), frm->rect.y(), frm->rect.x()+fwidth, frm->rect.height()-fwidth);
1745 theme.partId = WP_SMALLFRAMELEFT;
1746 d->drawBackground(theme);
1747 theme.rect = QRect(frm->rect.width()-fwidth, frm->rect.y(), fwidth, frm->rect.height()-fwidth);
1748 theme.partId = WP_SMALLFRAMERIGHT;
1749 d->drawBackground(theme);
1750 theme.rect = QRect(frm->rect.x(), frm->rect.bottom()-fwidth+1, frm->rect.width(), fwidth);
1751 theme.partId = WP_SMALLFRAMEBOTTOM;
1752 d->drawBackground(theme);
1758 case PE_FrameTabWidget:
1759#if QT_CONFIG(tabwidget)
1760 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(option)) {
1761 themeNumber = QWindowsVistaStylePrivate::TabTheme;
1765 bool useGradient =
true;
1766 const int maxlength = 256;
1767 wchar_t themeFileName[maxlength];
1768 wchar_t themeColor[maxlength];
1770 if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength,
nullptr, 0) == S_OK) {
1771 wchar_t *offset =
nullptr;
1772 if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char(
'\\')).unicode())) !=
nullptr) {
1774 if (!lstrcmp(offset, L"Luna.msstyles") && !lstrcmp(offset, L"Metallic"))
1775 useGradient =
false;
1781 QStyleOptionTabWidgetFrame frameOpt = *tab;
1782 frameOpt.rect = widget->rect();
1783 QRect contentsRect = subElementRect(SE_TabWidgetTabContents, &frameOpt, widget);
1784 QRegion reg = option->rect;
1785 reg -= contentsRect;
1786 painter->setClipRegion(reg);
1787 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
1788 theme.mirrorHorizontally = hMirrored;
1789 theme.mirrorVertically = vMirrored;
1790 d->drawBackground(theme);
1791 painter->setClipRect(contentsRect);
1795 switch (tab->shape) {
1796 case QTabBar::RoundedNorth:
1797 case QTabBar::TriangularNorth:
1799 case QTabBar::RoundedSouth:
1800 case QTabBar::TriangularSouth:
1803 case QTabBar::RoundedEast:
1804 case QTabBar::TriangularEast:
1807 case QTabBar::RoundedWest:
1808 case QTabBar::TriangularWest:
1818 case PE_FrameStatusBarItem:
1819 themeNumber = QWindowsVistaStylePrivate::StatusTheme;
1823 case PE_FrameWindow:
1824 if (
const auto *frm = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1825 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
1826 if (option->state & State_Active)
1827 stateId = FS_ACTIVE;
1829 stateId = FS_INACTIVE;
1831 int fwidth =
int((frm->lineWidth + frm->midLineWidth) / QWindowsStylePrivate::nativeMetricScaleFactor(widget));
1833 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
1834 if (!theme.isValid())
1838 theme.rect = QRect(option->rect.x(), option->rect.y()+fwidth, option->rect.x()+fwidth, option->rect.height()-fwidth);
1839 theme.partId = WP_FRAMELEFT;
1840 if (!d->drawBackground(theme)) {
1841 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1844 theme.rect = QRect(option->rect.width()-fwidth, option->rect.y()+fwidth, fwidth, option->rect.height()-fwidth);
1845 theme.partId = WP_FRAMERIGHT;
1846 if (!d->drawBackground(theme)) {
1847 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1850 theme.rect = QRect(option->rect.x(), option->rect.height()-fwidth, option->rect.width(), fwidth);
1851 theme.partId = WP_FRAMEBOTTOM;
1852 if (!d->drawBackground(theme)) {
1853 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1856 theme.rect = QRect(option->rect.x(), option->rect.y(), option->rect.width(), option->rect.y()+fwidth);
1857 theme.partId = WP_CAPTION;
1858 if (!d->drawBackground(theme))
1859 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1864 case PE_PanelLineEdit:
1865 if (
const auto *panel = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1866 bool isEnabled = state & State_Enabled;
1867 if (QWindowsVistaStylePrivate::isLineEditBaseColorSet(option, widget)) {
1868 painter->fillRect(panel->rect, panel->palette.brush(QPalette::Base));
1870 int partId = EP_BACKGROUND;
1871 int stateId = EBS_NORMAL;
1873 stateId = EBS_DISABLED;
1874 else if (option->state & State_ReadOnly)
1875 stateId = EBS_READONLY;
1876 else if (option->state & State_MouseOver)
1879 QWindowsThemeData theme(
nullptr, painter, QWindowsVistaStylePrivate::EditTheme,
1880 partId, stateId, rect);
1881 if (!theme.isValid()) {
1882 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1886 GetThemeEnumValue(theme.handle(), partId, stateId, TMT_BGTYPE, &bgType);
1887 if (bgType == BT_IMAGEFILE) {
1888 d->drawBackground(theme);
1890 QBrush fillColor = option->palette.brush(QPalette::Base);
1892 PROPERTYORIGIN origin = PO_NOTFOUND;
1893 GetThemePropertyOrigin(theme.handle(), theme.partId, theme.stateId, TMT_FILLCOLOR, &origin);
1895 if ((origin == PO_PART || origin == PO_STATE)) {
1897 GetThemeColor(theme.handle(), partId, stateId, TMT_FILLCOLOR, &bgRef);
1898 fillColor = QBrush(qRgb(GetRValue(bgRef), GetGValue(bgRef), GetBValue(bgRef)));
1901 painter->fillRect(option->rect, fillColor);
1904 if (panel->lineWidth > 0)
1905 proxy()->drawPrimitive(PE_FrameLineEdit, panel, painter, widget);
1909 case PE_IndicatorButtonDropDown:
1910 themeNumber = QWindowsVistaStylePrivate::ToolBarTheme;
1911 partId = TP_SPLITBUTTONDROPDOWN;
1912 if (!(option->state & State_Enabled))
1913 stateId = TS_DISABLED;
1914 else if (option->state & State_Sunken)
1915 stateId = TS_PRESSED;
1916 else if (option->state & State_MouseOver)
1917 stateId = option->state & State_On ? TS_HOTCHECKED : TS_HOT;
1918 else if (option->state & State_On)
1919 stateId = TS_CHECKED;
1920 else if (!(option->state & State_AutoRaise))
1923 stateId = TS_NORMAL;
1924 if (option->direction == Qt::RightToLeft)
1928 case PE_FrameLineEdit:
1929 if (QWindowsVistaAnimation *animate = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1930 animate->paint(painter, option);
1932 if (QWindowsVistaStylePrivate::isItemViewDelegateLineEdit(widget)) {
1934 QPen oldPen = painter->pen();
1936 painter->setPen(option->palette.base().color());
1937 painter->drawRect(option->rect.adjusted(1, 1, -2, -2));
1939 painter->setPen(option->palette.shadow().color());
1940 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
1941 painter->setPen(oldPen);
1944 int stateId = ETS_NORMAL;
1945 if (!(state & State_Enabled))
1946 stateId = ETS_DISABLED;
1947 else if (state & State_ReadOnly)
1948 stateId = ETS_READONLY;
1949 else if (state & State_HasFocus)
1950 stateId = ETS_SELECTED;
1951 else if (state & State_MouseOver)
1953 QWindowsThemeData theme(widget, painter,
1954 QWindowsVistaStylePrivate::EditTheme,
1955 EP_EDITBORDER_NOSCROLL, stateId, option->rect);
1956 theme.noContent =
true;
1958 QRegion clipRegion = option->rect;
1959 clipRegion -= option->rect.adjusted(2, 2, -2, -2);
1960 painter->setClipRegion(clipRegion);
1961 d->drawBackground(theme);
1966 case PE_FrameGroupBox:
1967 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1968 partId = BP_GROUPBOX;
1969 if (!(option->state & State_Enabled))
1970 stateId = GBS_DISABLED;
1972 stateId = GBS_NORMAL;
1973 if (
const auto *frame = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1974 if (frame->features & QStyleOptionFrame::Flat) {
1976 QRect fr = frame->rect;
1977 QPoint p1(fr.x(), fr.y() + 1);
1978 QPoint p2(fr.x() + fr.width(), p1.y() + 1);
1979 rect = QRect(p1, p2);
1985 case PE_IndicatorToolBarHandle: {
1986 QWindowsThemeData theme;
1988 if (option->state & State_Horizontal) {
1989 theme = QWindowsThemeData(widget, painter,
1990 QWindowsVistaStylePrivate::RebarTheme,
1991 RP_GRIPPER, ETS_NORMAL, option->rect.adjusted(0, 1, -2, -2));
1992 rect = option->rect.adjusted(0, 1, 0, -2);
1995 theme = QWindowsThemeData(widget, painter, QWindowsVistaStylePrivate::RebarTheme,
1996 RP_GRIPPERVERT, ETS_NORMAL, option->rect.adjusted(0, 1, -2, -2));
1997 rect = option->rect.adjusted(1, 0, -1, 0);
2001 d->drawBackground(theme);
2005 case PE_IndicatorToolBarSeparator: {
2006 QPen pen = painter->pen();
2008 painter->setPen(option->palette.window().color().darker(114));
2009 if (option->state & State_Horizontal) {
2010 int x1 = option->rect.center().x();
2011 painter->drawLine(QPoint(x1, option->rect.top() + margin), QPoint(x1, option->rect.bottom() - margin));
2013 int y1 = option->rect.center().y();
2014 painter->drawLine(QPoint(option->rect.left() + margin, y1), QPoint(option->rect.right() - margin, y1));
2016 painter->setPen(pen);
2020 case PE_PanelTipLabel: {
2021 QWindowsThemeData theme(widget, painter,
2022 QWindowsVistaStylePrivate::ToolTipTheme,
2023 TTP_STANDARD, TTSS_NORMAL, option->rect);
2024 d->drawBackground(theme);
2028 case PE_FrameTabBarBase:
2029#if QT_CONFIG(tabbar)
2030 if (
const auto *tbb = qstyleoption_cast<
const QStyleOptionTabBarBase *>(option)) {
2032 switch (tbb->shape) {
2033 case QTabBar::RoundedNorth:
2034 painter->setPen(QPen(tbb->palette.dark(), 0));
2035 painter->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
2037 case QTabBar::RoundedWest:
2038 painter->setPen(QPen(tbb->palette.dark(), 0));
2039 painter->drawLine(tbb->rect.left(), tbb->rect.top(), tbb->rect.left(), tbb->rect.bottom());
2041 case QTabBar::RoundedSouth:
2042 painter->setPen(QPen(tbb->palette.dark(), 0));
2043 painter->drawLine(tbb->rect.left(), tbb->rect.top(),
2044 tbb->rect.right(), tbb->rect.top());
2046 case QTabBar::RoundedEast:
2047 painter->setPen(QPen(tbb->palette.dark(), 0));
2048 painter->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft());
2050 case QTabBar::TriangularNorth:
2051 case QTabBar::TriangularEast:
2052 case QTabBar::TriangularWest:
2053 case QTabBar::TriangularSouth:
2055 QWindowsStyle::drawPrimitive(element, option, painter, widget);
2064#if QT_CONFIG(dialogbuttonbox)
2065 const QDialogButtonBox *buttonBox =
nullptr;
2066 if (qobject_cast<
const QMessageBox *> (widget))
2067 buttonBox = widget->findChild<
const QDialogButtonBox *>(QLatin1String(
"qt_msgbox_buttonbox"));
2070 QWindowsThemeData theme(widget, painter,
2071 QWindowsVistaStylePrivate::TaskDialogTheme,
2072 TDLG_PRIMARYPANEL, 0, option->rect);
2073 QRect toprect = option->rect;
2074 toprect.setBottom(buttonBox->geometry().top());
2075 theme.rect = toprect;
2076 d->drawBackground(theme);
2079 QRect buttonRect = option->rect;
2080 buttonRect.setTop(buttonBox->geometry().top());
2081 theme.rect = buttonRect;
2082 theme.partId = TDLG_SECONDARYPANEL;
2083 d->drawBackground(theme);
2089 case PE_PanelItemViewItem: {
2090 const QStyleOptionViewItem *vopt;
2091 bool newStyle =
true;
2092 QAbstractItemView::SelectionBehavior selectionBehavior = QAbstractItemView::SelectRows;
2093 QAbstractItemView::SelectionMode selectionMode = QAbstractItemView::NoSelection;
2094 if (
const QAbstractItemView *view = qobject_cast<
const QAbstractItemView *>(widget)) {
2095 newStyle = !qobject_cast<
const QTableView*>(view);
2096 selectionBehavior = view->selectionBehavior();
2097 selectionMode = view->selectionMode();
2098#if QT_CONFIG(accessibility)
2099 }
else if (!widget) {
2100 newStyle = !QStyleHelper::hasAncestor(option->styleObject, QAccessible::MenuItem) ;
2104 if (newStyle && (vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(option))) {
2105 bool selected = vopt->state & QStyle::State_Selected;
2106 const bool hover = selectionMode != QAbstractItemView::NoSelection && (vopt->state & QStyle::State_MouseOver);
2107 bool active = vopt->state & QStyle::State_Active;
2109 if (vopt->features & QStyleOptionViewItem::Alternate)
2110 painter->fillRect(vopt->rect, vopt->palette.alternateBase());
2112 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled
2113 ? QPalette::Normal : QPalette::Disabled;
2114 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
2115 cg = QPalette::Inactive;
2117 QRect itemRect = subElementRect(QStyle::SE_ItemViewItemFocusRect, option, widget).adjusted(-1, 0, 1, 0);
2118 itemRect.setTop(vopt->rect.top());
2119 itemRect.setBottom(vopt->rect.bottom());
2121 QSize sectionSize = itemRect.size();
2122 if (vopt->showDecorationSelected)
2123 sectionSize = vopt->rect.size();
2125 if (selectionBehavior == QAbstractItemView::SelectRows)
2126 sectionSize.setWidth(vopt->rect.width());
2129 if (vopt->backgroundBrush.style() != Qt::NoBrush) {
2130 QPainterStateGuard psg(painter);
2131 painter->setBrushOrigin(vopt->rect.topLeft());
2132 painter->fillRect(vopt->rect, vopt->backgroundBrush);
2135 if (hover || selected) {
2136 if (sectionSize.width() > 0 && sectionSize.height() > 0) {
2137 QString key = QStringLiteral(u"qvdelegate-%1-%2-%3-%4-%5").arg(sectionSize.width())
2138 .arg(sectionSize.height()).arg(selected).arg(active).arg(hover);
2139 if (!QPixmapCache::find(key, &pixmap)) {
2140 pixmap = QPixmap(sectionSize);
2141 pixmap.fill(Qt::transparent);
2144 if (selected && hover)
2146 else if (selected && !active)
2155 QWindowsThemeData theme(widget, &pixmapPainter,
2156 QWindowsVistaStylePrivate::VistaTreeViewTheme,
2157 LVP_LISTITEM, state, QRect(0, 0, sectionSize.width(), sectionSize.height()));
2159 if (!theme.isValid())
2162 d->drawBackground(theme);
2163 QPixmapCache::insert(key, pixmap);
2167 if (vopt->showDecorationSelected) {
2168 const int frame = 2;
2169 QRect srcRect = QRect(0, 0, sectionSize.width(), sectionSize.height());
2170 QRect pixmapRect = vopt->rect;
2171 bool reverse = vopt->direction == Qt::RightToLeft;
2172 bool leftSection = vopt->viewItemPosition == QStyleOptionViewItem::Beginning;
2173 bool rightSection = vopt->viewItemPosition == QStyleOptionViewItem::End;
2174 if (vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne
2175 || vopt->viewItemPosition == QStyleOptionViewItem::Invalid)
2176 painter->drawPixmap(pixmapRect.topLeft(), pixmap);
2177 else if (reverse ? rightSection : leftSection){
2178 painter->drawPixmap(QRect(pixmapRect.topLeft(),
2179 QSize(frame, pixmapRect.height())), pixmap,
2180 QRect(QPoint(0, 0), QSize(frame, pixmapRect.height())));
2181 painter->drawPixmap(pixmapRect.adjusted(frame, 0, 0, 0),
2182 pixmap, srcRect.adjusted(frame, 0, -frame, 0));
2183 }
else if (reverse ? leftSection : rightSection) {
2184 painter->drawPixmap(QRect(pixmapRect.topRight() - QPoint(frame - 1, 0),
2185 QSize(frame, pixmapRect.height())), pixmap,
2186 QRect(QPoint(pixmapRect.width() - frame, 0),
2187 QSize(frame, pixmapRect.height())));
2188 painter->drawPixmap(pixmapRect.adjusted(0, 0, -frame, 0),
2189 pixmap, srcRect.adjusted(frame, 0, -frame, 0));
2190 }
else if (vopt->viewItemPosition == QStyleOptionViewItem::Middle)
2191 painter->drawPixmap(pixmapRect, pixmap,
2192 srcRect.adjusted(frame, 0, -frame, 0));
2194 if (vopt->text.isEmpty() && vopt->icon.isNull())
2196 painter->drawPixmap(itemRect.topLeft(), pixmap);
2208 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2210 if (!theme.isValid()) {
2211 QWindowsStyle::drawPrimitive(element, option, painter, widget);
2215 theme.mirrorHorizontally = hMirrored;
2216 theme.mirrorVertically = vMirrored;
2217 theme.noBorder = noBorder;
2218 theme.noContent = noContent;
2219 theme.rotate = rotate;
2221 d->drawBackground(theme);
2338void QWindowsVistaStyle::drawControl(ControlElement element,
const QStyleOption *option,
2339 QPainter *painter,
const QWidget *widget)
const
2341 if (!QWindowsVistaStylePrivate::useVista()) {
2342 QWindowsStyle::drawControl(element, option, painter, widget);
2348 bool selected = option->state & State_Selected;
2349 bool pressed = option->state & State_Sunken;
2350 bool disabled = !(option->state & State_Enabled);
2352 int state = option->state;
2353 int themeNumber = -1;
2355 QRect rect(option->rect);
2356 State flags = option->state;
2360 if (d->transitionsEnabled() && canAnimate(option)) {
2361 if (element == CE_PushButtonBevel) {
2365 QObject *styleObject = option->styleObject;
2367 int oldState = styleObject->property(
"_q_stylestate").toInt();
2368 oldRect = styleObject->property(
"_q_stylerect").toRect();
2369 newRect = option->rect;
2370 styleObject->setProperty(
"_q_stylestate",
int(option->state));
2371 styleObject->setProperty(
"_q_stylerect", option->rect);
2373 bool wasDefault =
false;
2374 bool isDefault =
false;
2375 if (
const QStyleOptionButton *button = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
2376 wasDefault = styleObject->property(
"_q_isdefault").toBool();
2377 isDefault = button->features & QStyleOptionButton::DefaultButton;
2378 styleObject->setProperty(
"_q_isdefault", isDefault);
2381 bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) ||
2382 (state & State_On) != (oldState & State_On) ||
2383 (state & State_MouseOver) != (oldState & State_MouseOver));
2385 if (oldRect != newRect || (wasDefault && !isDefault)) {
2386 doTransition =
false;
2387 d->stopAnimation(styleObject);
2391 styleObject->setProperty(
"_q_no_animation",
true);
2394 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
2395 QStyleOption *styleOption = clonedAnimationStyleOption(option);
2396 styleOption->state = QStyle::State(oldState);
2398 QImage startImage = createAnimationBuffer(option, widget);
2399 QPainter startPainter(&startImage);
2403 proxy()->drawControl(element, styleOption, &startPainter, widget);
2405 anim->paint(&startPainter, styleOption);
2406 d->stopAnimation(styleObject);
2409 t->setStartImage(startImage);
2410 QImage endImage = createAnimationBuffer(option, widget);
2412 styleOption->state = option->state;
2413 proxy()->drawControl(element, styleOption, &endPainter, widget);
2414 t->setEndImage(endImage);
2418 const HTHEME theme = OpenThemeData(
nullptr, L"Button");
2420 int fromState = buttonStateId(oldState, BP_PUSHBUTTON);
2421 int toState = buttonStateId(option->state, BP_PUSHBUTTON);
2422 if (GetThemeTransitionDuration(theme, BP_PUSHBUTTON, fromState, toState, TMT_TRANSITIONDURATIONS, &duration) == S_OK)
2423 t->setDuration(
int(duration));
2426 t->setStartTime(d->animationTime());
2427 styleObject->setProperty(
"_q_no_animation",
false);
2429 deleteClonedAnimationStyleOption(styleOption);
2430 d->startAnimation(t);
2433 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
2435 anim->paint(painter, option);
2442 bool hMirrored =
false;
2443 bool vMirrored =
false;
2447 case CE_PushButtonBevel:
2448 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
2449 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
2450 partId = BP_PUSHBUTTON;
2451 if (btn->features & QStyleOptionButton::CommandLinkButton)
2453 bool justFlat = (btn->features & QStyleOptionButton::Flat) && !(flags & (State_On|State_Sunken));
2454 if (!(flags & State_Enabled) && !(btn->features & QStyleOptionButton::Flat))
2455 stateId = PBS_DISABLED;
2458 else if (flags & (State_Sunken | State_On))
2459 stateId = PBS_PRESSED;
2460 else if (flags & State_MouseOver)
2462 else if (btn->features & QStyleOptionButton::DefaultButton && (state & State_Active))
2463 stateId = PBS_DEFAULTED;
2465 stateId = PBS_NORMAL;
2468 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2469 d->drawBackground(theme);
2472 if (btn->features & QStyleOptionButton::HasMenu) {
2473 int mbiw = 0, mbih = 0;
2474 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::ToolBarTheme,
2476 if (theme.isValid()) {
2477 const QSizeF size = theme.size() * QStyleHelper::dpiScaled(1, option);
2478 if (!size.isEmpty()) {
2479 mbiw = qRound(size.width());
2480 mbih = qRound(size.height());
2483 QRect ir = subElementRect(SE_PushButtonContents, option,
nullptr);
2484 QStyleOptionButton newBtn = *btn;
2485 newBtn.rect = QStyle::visualRect(option->direction, option->rect,
2486 QRect(ir.right() - mbiw - 2,
2487 option->rect.top() + (option->rect.height()/2) - (mbih/2),
2488 mbiw + 1, mbih + 1));
2489 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
2495 themeNumber = QWindowsVistaStylePrivate::StatusTheme;
2496 partId = SP_GRIPPER;
2497 QWindowsThemeData theme(
nullptr, painter, themeNumber, partId);
2498 QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize();
2500 if (
const auto *sg = qstyleoption_cast<
const QStyleOptionSizeGrip *>(option)) {
2501 switch (sg->corner) {
2502 case Qt::BottomRightCorner:
2503 rect = QRect(QPoint(rect.right() - size.width(), rect.bottom() - size.height()), size);
2505 case Qt::BottomLeftCorner:
2506 rect = QRect(QPoint(rect.left() + 1, rect.bottom() - size.height()), size);
2509 case Qt::TopRightCorner:
2510 rect = QRect(QPoint(rect.right() - size.width(), rect.top() + 1), size);
2513 case Qt::TopLeftCorner:
2514 rect = QRect(rect.topLeft() + QPoint(1, 1), size);
2515 hMirrored = vMirrored =
true;
2522 painter->eraseRect(option->rect);
2526#if QT_CONFIG(tabwidget)
2527 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option))
2528 stateId = tab->state & State_Enabled ? TIS_NORMAL : TIS_DISABLED;
2532 case CE_TabBarTabShape:
2533#if QT_CONFIG(tabwidget)
2534 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option)) {
2535 themeNumber = QWindowsVistaStylePrivate::TabTheme;
2536 const bool isDisabled = !(tab->state & State_Enabled);
2537 const bool hasFocus = tab->state & State_HasFocus;
2538 const bool isHot = tab->state & State_MouseOver;
2539 const bool selected = tab->state & State_Selected;
2540 bool lastTab = tab->position == QStyleOptionTab::End;
2541 bool firstTab = tab->position == QStyleOptionTab::Beginning;
2542 const bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
2543 const bool leftAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignLeft;
2544 const bool centerAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignCenter;
2545 const int borderThickness = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
2546 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, option, widget);
2549 stateId = TIS_DISABLED;
2551 stateId = TIS_SELECTED;
2553 stateId = TIS_FOCUSED;
2557 stateId = TIS_NORMAL;
2560 if (firstTab || onlyOne) {
2562 partId = TABP_TABITEMLEFTEDGE;
2563 else if (centerAligned)
2564 partId = TABP_TABITEM;
2566 partId = TABP_TABITEMRIGHTEDGE;
2568 partId = TABP_TABITEM;
2571 if (tab->direction == Qt::RightToLeft
2572 && (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth)) {
2573 bool temp = firstTab;
2578 const bool begin = firstTab || onlyOne;
2579 const bool end = lastTab || onlyOne;
2581 switch (tab->shape) {
2582 case QTabBar::RoundedNorth:
2584 rect.adjust(begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap, borderThickness);
2586 rect.adjust(begin? tabOverlap : 0, tabOverlap, end ? -tabOverlap : 0, 0);
2588 case QTabBar::RoundedSouth:
2592 rect.adjust(begin ? 0 : -tabOverlap , -borderThickness, end ? 0 : tabOverlap, 0);
2594 rect.adjust(begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0 , -tabOverlap);
2596 case QTabBar::RoundedEast:
2599 rect.adjust(-borderThickness, begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap);
2601 rect.adjust(0, begin ? tabOverlap : 0, -tabOverlap, end ? -tabOverlap : 0);
2603 case QTabBar::RoundedWest:
2607 rect.adjust(0, begin ? 0 : -tabOverlap, borderThickness, end ? 0 : tabOverlap);
2609 rect.adjust(tabOverlap, begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0);
2617 switch (tab->shape) {
2618 case QTabBar::RoundedNorth:
2619 rect.adjust(0,0, 0,-1);
2621 case QTabBar::RoundedSouth:
2622 rect.adjust(0,1, 0,0);
2624 case QTabBar::RoundedEast:
2625 rect.adjust( 1,0, 0,0);
2627 case QTabBar::RoundedWest:
2628 rect.adjust(0,0, -1,0);
2638 case CE_ProgressBarGroove: {
2639 Qt::Orientation orient = Qt::Horizontal;
2640 if (
const auto *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(option))
2641 if (!(pb->state & QStyle::State_Horizontal))
2642 orient = Qt::Vertical;
2644 partId = (orient == Qt::Horizontal) ? PP_BAR : PP_BARVERT;
2645 themeNumber = QWindowsVistaStylePrivate::ProgressTheme;
2650 case CE_ProgressBarContents:
2651 if (
const auto *bar = qstyleoption_cast<
const QStyleOptionProgressBar *>(option)) {
2652 bool isIndeterminate = (bar->minimum == 0 && bar->maximum == 0);
2653 const bool vertical = !(bar->state & QStyle::State_Horizontal);
2654 const bool inverted = bar->invertedAppearance;
2656 if (isIndeterminate || (bar->progress > 0 && (bar->progress < bar->maximum) && d->transitionsEnabled())) {
2657 if (!d->animation(styleObject(option)))
2658 d->startAnimation(
new QProgressStyleAnimation(d->animationFps, styleObject(option)));
2660 d->stopAnimation(styleObject(option));
2663 QWindowsThemeData theme(widget, painter,
2664 QWindowsVistaStylePrivate::ProgressTheme,
2665 vertical ? PP_FILLVERT : PP_FILL);
2666 theme.rect = option->rect;
2667 bool reverse = (bar->direction == Qt::LeftToRight && inverted) || (bar->direction == Qt::RightToLeft && !inverted);
2668 QTime current = d->animationTime();
2670 if (isIndeterminate) {
2671 if (
auto *progressAnimation = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2673 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2674 int animOffset = progressAnimation->startTime().msecsTo(current) / 4;
2675 if (animOffset > animationWidth)
2676 progressAnimation->setStartTime(d->animationTime());
2678 painter->setClipRect(theme.rect);
2680 QSize pixmapSize(14, 14);
2682 animRect = QRect(theme.rect.left(),
2683 inverted ? rect.top() - glowSize + animOffset :
2684 rect.bottom() + glowSize - animOffset,
2685 rect.width(), glowSize);
2686 pixmapSize.setHeight(animRect.height());
2688 animRect = QRect(rect.left() - glowSize + animOffset,
2689 rect.top(), glowSize, rect.height());
2690 animRect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2691 option->rect, animRect);
2692 pixmapSize.setWidth(animRect.width());
2694 QString name = QStringLiteral(u"qiprogress-%1-%2").arg(pixmapSize.width()).arg(pixmapSize.height());
2696 if (!QPixmapCache::find(name, &pixmap)) {
2697 QImage image(pixmapSize, QImage::Format_ARGB32);
2698 image.fill(Qt::transparent);
2700 theme.painter = &imagePainter;
2701 theme.partId = vertical ? PP_FILLVERT : PP_FILL;
2702 theme.rect = QRect(QPoint(0,0), animRect.size());
2703 QLinearGradient alphaGradient(0, 0, vertical ? 0 : image.width(),
2704 vertical ? image.height() : 0);
2705 alphaGradient.setColorAt(0, QColor(0, 0, 0, 0));
2706 alphaGradient.setColorAt(0.5, QColor(0, 0, 0, 220));
2707 alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
2708 imagePainter.fillRect(image.rect(), alphaGradient);
2709 imagePainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
2710 d->drawBackground(theme);
2712 pixmap = QPixmap::fromImage(image);
2713 QPixmapCache::insert(name, pixmap);
2715 painter->drawPixmap(animRect, pixmap);
2719 qint64 progress = qMax<qint64>(bar->progress, bar->minimum);
2722 int maxHeight = option->rect.height();
2724 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxHeight);
2725 int height = isIndeterminate ? maxHeight: qMax(
int(vc6_workaround), minHeight);
2726 theme.rect.setHeight(height);
2728 theme.rect.moveTop(rect.height() - theme.rect.height());
2730 int maxWidth = option->rect.width();
2732 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth);
2733 int width = isIndeterminate ? maxWidth : qMax(
int(vc6_workaround), minWidth);
2734 theme.rect.setWidth(width);
2735 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2736 option->rect, theme.rect);
2738 d->drawBackground(theme);
2740 if (QProgressStyleAnimation *a = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2742 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2743 int animOffset = a->startTime().msecsTo(current) / 4;
2744 theme.partId = vertical ? PP_MOVEOVERLAYVERT : PP_MOVEOVERLAY;
2745 if (animOffset > animationWidth) {
2746 if (bar->progress < bar->maximum)
2747 a->setStartTime(d->animationTime());
2749 d->stopAnimation(styleObject(option));
2753 painter->setClipRect(theme.rect);
2755 theme.rect = QRect(theme.rect.left(),
2756 inverted ? rect.top() - glowSize + animOffset :
2757 rect.bottom() + glowSize - animOffset,
2758 rect.width(), glowSize);
2760 theme.rect = QRect(rect.left() - glowSize + animOffset,rect.top(), glowSize, rect.height());
2761 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight, option->rect, theme.rect);
2763 d->drawBackground(theme);
2770 case CE_MenuBarItem:
2771 if (
const auto *mbi = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2772 if (mbi->menuItemType == QStyleOptionMenuItem::DefaultItem)
2775 QPalette::ColorRole textRole = disabled ? QPalette::Text : QPalette::ButtonText;
2776 const auto dpr = QStyleHelper::getDpr(widget);
2777 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2778 const auto pix = mbi->icon.pixmap(QSize(extent, extent), dpr, QIcon::Normal);
2780 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2781 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
2782 alignment |= Qt::TextHideMnemonic;
2784 if (widget && mbi->palette.color(QPalette::Window) != Qt::transparent) {
2786 QWindowsThemeData theme(widget, painter,
2787 QWindowsVistaStylePrivate::MenuTheme,
2788 MENU_BARBACKGROUND, 0, option->rect.adjusted(-1, 0, 2, 1));
2789 d->drawBackground(theme);
2791 int stateId = MBI_NORMAL;
2793 stateId = MBI_DISABLED;
2795 stateId = MBI_PUSHED;
2799 QWindowsThemeData theme2(widget, painter,
2800 QWindowsVistaStylePrivate::MenuTheme,
2801 MENU_BARITEM, stateId, option->rect);
2802 d->drawBackground(theme2);
2806 drawItemPixmap(painter, mbi->rect, alignment, pix);
2808 drawItemText(painter, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled, mbi->text, textRole);
2813 case CE_MenuEmptyArea:
2814 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2815 QBrush fill = menuitem->palette.brush((menuitem->state & State_Selected) ?
2816 QPalette::Highlight : QPalette::Button);
2817 painter->fillRect(rect, fill);
2823 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2825 const qreal factor = QWindowsVistaStylePrivate::nativeMetricScaleFactor(widget);
2826 int checkcol = qRound(qreal(25) * factor);
2827 const int gutterWidth = qRound(qreal(3) * factor);
2829 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::MenuTheme,
2830 MENU_POPUPCHECKBACKGROUND, MBI_HOT);
2831 QWindowsThemeData themeSize = theme;
2832 themeSize.partId = MENU_POPUPCHECK;
2833 themeSize.stateId = 0;
2834 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2835 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2836 checkcol = qMax(menuitem->maxIconWidth, qRound(gutterWidth + size.width() + margins.left() + margins.right()));
2838 QRect rect = option->rect;
2841 QWindowsThemeData popupbackgroundTheme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2842 MENU_POPUPBACKGROUND, stateId, option->rect);
2843 d->drawBackground(popupbackgroundTheme);
2846 if (option->direction == Qt::LeftToRight)
2847 checkcol += rect.x();
2848 QPoint p1 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.top()));
2849 QPoint p2 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.bottom()));
2850 QRect gutterRect(p1.x(), p1.y(), gutterWidth, p2.y() - p1.y() + 1);
2851 QWindowsThemeData theme2(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2852 MENU_POPUPGUTTER, stateId, gutterRect);
2853 d->drawBackground(theme2);
2856 menuitem->rect.getRect(&x, &y, &w, &h);
2857 int tab = menuitem->reservedShortcutWidth;
2858 bool dis = !(menuitem->state & State_Enabled);
2859 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
2860 ? menuitem->checked :
false;
2861 bool act = menuitem->state & State_Selected;
2863 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {
2864 int yoff = y-2 + h / 2;
2865 const int separatorSize = qRound(qreal(6) * QWindowsStylePrivate::nativeMetricScaleFactor(widget));
2866 QPoint p1 = QPoint(x + checkcol, yoff);
2867 QPoint p2 = QPoint(x + w + separatorSize, yoff);
2869 QRect subRect(p1.x() + (gutterWidth - menuitem->rect.x()), p1.y(),
2870 p2.x() - p1.x(), separatorSize);
2871 subRect = QStyle::visualRect(option->direction, option->rect, subRect );
2872 QWindowsThemeData theme2(widget, painter,
2873 QWindowsVistaStylePrivate::MenuTheme,
2874 MENU_POPUPSEPARATOR, stateId, subRect);
2875 d->drawBackground(theme2);
2879 QRect vCheckRect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x(),
2880 menuitem->rect.y(), checkcol - (gutterWidth + menuitem->rect.x()), menuitem->rect.height()));
2883 stateId = dis ? MBI_DISABLED : MBI_HOT;
2884 QWindowsThemeData theme2(widget, painter,
2885 QWindowsVistaStylePrivate::MenuTheme,
2886 MENU_POPUPITEM, stateId, option->rect);
2887 d->drawBackground(theme2);
2891 QWindowsThemeData theme(widget, painter,
2892 QWindowsVistaStylePrivate::MenuTheme,
2893 MENU_POPUPCHECKBACKGROUND,
2894 menuitem->icon.isNull() ? MBI_HOT : MBI_PUSHED, vCheckRect);
2895 QWindowsThemeData themeSize = theme;
2896 themeSize.partId = MENU_POPUPCHECK;
2897 themeSize.stateId = 0;
2898 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2899 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2900 QRect checkRect(0, 0, qRound(size.width() + margins.left() + margins.right()),
2901 qRound(size.height() + margins.bottom() + margins.top()));
2902 checkRect.moveCenter(vCheckRect.center());
2903 theme.rect = checkRect;
2905 d->drawBackground(theme);
2907 if (menuitem->icon.isNull()) {
2908 checkRect = QRect(QPoint(0, 0), size.toSize());
2909 checkRect.moveCenter(theme.rect.center());
2910 theme.rect = checkRect;
2912 theme.partId = MENU_POPUPCHECK;
2913 bool bullet = menuitem->checkType & QStyleOptionMenuItem::Exclusive;
2915 theme.stateId = bullet ? MC_BULLETDISABLED: MC_CHECKMARKDISABLED;
2917 theme.stateId = bullet ? MC_BULLETNORMAL: MC_CHECKMARKNORMAL;
2918 d->drawBackground(theme);
2922 if (!menuitem->icon.isNull()) {
2923 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
2925 mode = QIcon::Active;
2926 const auto size = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2927 QRect pmr(QPoint(0, 0), QSize(size, size));
2928 pmr.moveCenter(vCheckRect.center());
2929 menuitem->icon.paint(painter, pmr, Qt::AlignCenter, mode,
2930 checked ? QIcon::On : QIcon::Off);
2933 painter->setPen(menuitem->palette.buttonText().color());
2935 const QColor textColor = menuitem->palette.text().color();
2937 painter->setPen(textColor);
2939 int xm = windowsItemFrame + checkcol + windowsItemHMargin + (gutterWidth - menuitem->rect.x()) - 1;
2940 int xpos = menuitem->rect.x() + xm;
2941 QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
2942 QRect vTextRect = visualRect(option->direction, menuitem->rect, textRect);
2943 QString s = menuitem->text;
2946 int t = s.indexOf(QLatin1Char(
'\t'));
2947 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2948 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
2949 text_flags |= Qt::TextHideMnemonic;
2950 text_flags |= Qt::AlignLeft;
2952 QRect vShortcutRect = visualRect(option->direction, menuitem->rect,
2953 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
2954 painter->drawText(vShortcutRect, text_flags, s.mid(t + 1));
2957 QFont font = menuitem->font;
2958 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
2960 painter->setFont(font);
2961 painter->setPen(textColor);
2962 painter->drawText(vTextRect, text_flags, s.left(t));
2965 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {
2966 int dim = (h - 2 * windowsItemFrame) / 2;
2967 PrimitiveElement arrow;
2968 arrow = (option->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
2969 xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim;
2970 QRect vSubMenuRect = visualRect(option->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
2971 QStyleOptionMenuItem newMI = *menuitem;
2972 newMI.rect = vSubMenuRect;
2973 newMI.state = dis ? State_None : State_Enabled;
2974 proxy()->drawPrimitive(arrow, &newMI, painter, widget);
2980 case CE_HeaderSection:
2981 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(option)) {
2982 partId = HP_HEADERITEM;
2983 if (flags & State_Sunken)
2984 stateId = HIS_PRESSED;
2985 else if (flags & State_MouseOver)
2988 stateId = HIS_NORMAL;
2990 if (header->sortIndicator != QStyleOptionHeader::None)
2993 QWindowsThemeData theme(widget, painter,
2994 QWindowsVistaStylePrivate::HeaderTheme,
2995 partId, stateId, option->rect);
2996 d->drawBackground(theme);
3000 case CE_MenuBarEmptyArea: {
3001 stateId = MBI_NORMAL;
3002 if (!(state & State_Enabled))
3003 stateId = MBI_DISABLED;
3004 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
3005 MENU_BARBACKGROUND, stateId, option->rect);
3006 d->drawBackground(theme);
3011#if QT_CONFIG(toolbar)
3012 if (
const auto *toolbar = qstyleoption_cast<
const QStyleOptionToolBar *>(option)) {
3013 QPalette pal = option->palette;
3014 pal.setColor(QPalette::Dark, option->palette.window().color().darker(130));
3015 QStyleOptionToolBar copyOpt = *toolbar;
3016 copyOpt.palette = pal;
3017 QWindowsStyle::drawControl(element, ©Opt, painter, widget);
3022#if QT_CONFIG(dockwidget)
3023 case CE_DockWidgetTitle:
3024 if (
const auto *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(option)) {
3025 QRect rect = option->rect;
3026 const QDockWidget *dw = qobject_cast<
const QDockWidget *>(widget);
3027 bool isFloating = dw && dw->isFloating();
3028 int buttonMargin = 4;
3029 int mw = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, widget);
3030 int fw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, dwOpt, widget);
3032 const bool verticalTitleBar = dwOpt->verticalTitleBar;
3034 if (verticalTitleBar) {
3035 rect = rect.transposed();
3037 painter->translate(rect.left() - 1, rect.top() + rect.width());
3038 painter->rotate(-90);
3039 painter->translate(-rect.left() + 1, -rect.top());
3042 QRect r = option->rect.adjusted(0, 2, -1, -3);
3043 QRect titleRect = r;
3045 if (dwOpt->closable) {
3046 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton, dwOpt, widget).actualSize(QSize(10, 10));
3047 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3050 if (dwOpt->floatable) {
3051 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarMaxButton, dwOpt, widget).actualSize(QSize(10, 10));
3052 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3056 titleRect.adjust(0, -fw, 0, 0);
3057 if (widget && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey())
3058 titleRect.adjust(titleRect.height() + mw, 0, 0, 0);
3060 titleRect.adjust(mw, 0, 0, 0);
3061 if (!dwOpt->floatable && !dwOpt->closable)
3062 titleRect.adjust(0, 0, -mw, 0);
3065 if (!verticalTitleBar)
3066 titleRect = visualRect(dwOpt->direction, r, titleRect);
3069 const bool isActive = dwOpt->state & State_Active;
3070 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
3072 stateId = CS_ACTIVE;
3074 stateId = CS_INACTIVE;
3076 rect = rect.adjusted(-fw, -fw, fw, 0);
3078 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
3079 if (!theme.isValid())
3084 theme.partId = WP_SMALLCAPTION;
3085 d->drawBackground(theme);
3089 QIcon ico = widget->windowIcon();
3090 bool hasIcon = (ico.cacheKey() != QApplication::windowIcon().cacheKey());
3092 const auto titleHeight = rect.height() - 2;
3093 const auto dpr = QStyleHelper::getDpr(widget);
3094 const auto pxIco = ico.pixmap(QSize(titleHeight, titleHeight), dpr);
3095 if (!verticalTitleBar && dwOpt->direction == Qt::RightToLeft)
3096 painter->drawPixmap(rect.width() - titleHeight - pxIco.width(), rect.bottom() - titleHeight - 2, pxIco);
3098 painter->drawPixmap(fw, rect.bottom() - titleHeight - 2, pxIco);
3100 if (!dwOpt->title.isEmpty()) {
3101 QPen oldPen = painter->pen();
3102 QFont oldFont = painter->font();
3103 QFont titleFont = oldFont;
3104 titleFont.setBold(
true);
3105 painter->setFont(titleFont);
3107 = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
3109 int result = TST_NONE;
3110 GetThemeEnumValue(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3111 if (result != TST_NONE) {
3112 COLORREF textShadowRef;
3113 GetThemeColor(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWCOLOR, &textShadowRef);
3114 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3115 painter->setPen(textShadow);
3116 drawItemText(painter, titleRect.adjusted(1, 1, 1, 1),
3117 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3118 dwOpt->state & State_Enabled, titleText);
3121 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3122 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3123 painter->setPen(textColor);
3124 drawItemText(painter, titleRect,
3125 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3126 dwOpt->state & State_Enabled, titleText);
3127 painter->setFont(oldFont);
3128 painter->setPen(oldPen);
3131 painter->setBrush(option->palette.window().color().darker(110));
3132 painter->setPen(option->palette.window().color().darker(130));
3133 painter->drawRect(rect.adjusted(0, 1, -1, -3));
3135 if (!dwOpt->title.isEmpty()) {
3136 QString titleText = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight,
3137 verticalTitleBar ? titleRect.height() : titleRect.width());
3138 const int indent = 4;
3139 drawItemText(painter, rect.adjusted(indent + 1, 1, -indent - 1, -1),
3140 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic,
3142 dwOpt->state & State_Enabled, titleText,
3143 QPalette::WindowText);
3150#if QT_CONFIG(rubberband)
3152 if (qstyleoption_cast<
const QStyleOptionRubberBand *>(option)) {
3153 QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
3155 painter->setPen(highlight.darker(120));
3156 QColor dimHighlight(qMin(highlight.red()/2 + 110, 255),
3157 qMin(highlight.green()/2 + 110, 255),
3158 qMin(highlight.blue()/2 + 110, 255),
3159 (widget && widget->isWindow())? 255 : 127);
3160 painter->setBrush(dimHighlight);
3161 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
3168 case CE_HeaderEmptyArea:
3169 if (option->state & State_Horizontal) {
3170 themeNumber = QWindowsVistaStylePrivate::HeaderTheme;
3171 stateId = HIS_NORMAL;
3173 QWindowsStyle::drawControl(CE_HeaderEmptyArea, option, painter, widget);
3178#if QT_CONFIG(itemviews)
3179 case CE_ItemViewItem: {
3180 const QStyleOptionViewItem *vopt;
3181 const QAbstractItemView *view = qobject_cast<
const QAbstractItemView *>(widget);
3182 bool newStyle =
true;
3184 if (qobject_cast<
const QTableView*>(widget))
3187 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3189 if (newStyle && view && (vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(option))) {
3191
3192
3193
3194
3195
3196
3197 QPalette palette = vopt->palette;
3198 palette.setColor(QPalette::All, QPalette::HighlightedText, palette.color(QPalette::Active, QPalette::Text));
3200 palette.setColor(QPalette::All, QPalette::Highlight, palette.base().color().darker(108));
3201 QStyleOptionViewItem adjustedOption = *vopt;
3202 adjustedOption.palette = palette;
3204 if ((view->selectionMode() == QAbstractItemView::SingleSelection)
3205 && !(vopt->state & State_KeyboardFocusChange))
3206 adjustedOption.state &= ~State_HasFocus;
3207 if (!theme.isValid()) {
3208 QWindowsStyle::drawControl(element, &adjustedOption, painter, widget);
3212 if (!theme.isValid()) {
3213 QWindowsStyle::drawControl(element, option, painter, widget);
3218 theme.rotate = rotate;
3219 theme.mirrorHorizontally = hMirrored;
3220 theme.mirrorVertically = vMirrored;
3221 d->drawBackground(theme);
3226#if QT_CONFIG(combobox)
3227 case CE_ComboBoxLabel:
3228 QCommonStyle::drawControl(element, option, painter, widget);
3236 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3238 if (!theme.isValid()) {
3239 QWindowsStyle::drawControl(element, option, painter, widget);
3243 theme.rotate = rotate;
3244 theme.mirrorHorizontally = hMirrored;
3245 theme.mirrorVertically = vMirrored;
3247 d->drawBackground(theme);
3255void QWindowsVistaStyle::drawComplexControl(ComplexControl control,
const QStyleOptionComplex *option,
3256 QPainter *painter,
const QWidget *widget)
const
3260 if (!QWindowsVistaStylePrivate::useVista()) {
3261 QWindowsStyle::drawComplexControl(control, option, painter, widget);
3265 State state = option->state;
3266 SubControls sub = option->subControls;
3267 QRect r = option->rect;
3272 State flags = option->state;
3273 if (widget && widget->testAttribute(Qt::WA_UnderMouse) && widget->isActiveWindow())
3274 flags |= State_MouseOver;
3276 if (d->transitionsEnabled() && canAnimate(option))
3278 if (control == CC_ScrollBar || control == CC_SpinBox || control == CC_ComboBox) {
3279 QObject *styleObject = option->styleObject;
3281 int oldState = styleObject->property(
"_q_stylestate").toInt();
3282 int oldActiveControls = styleObject->property(
"_q_stylecontrols").toInt();
3284 QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
3285 styleObject->setProperty(
"_q_stylestate",
int(option->state));
3286 styleObject->setProperty(
"_q_stylecontrols",
int(option->activeSubControls));
3287 styleObject->setProperty(
"_q_stylerect", option->rect);
3289 bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken)
3290 || (state & State_On) != (oldState & State_On)
3291 || (state & State_MouseOver) != (oldState & State_MouseOver)
3292 || oldActiveControls !=
int(option->activeSubControls));
3294 if (qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3295 QRect oldSliderPos = styleObject->property(
"_q_stylesliderpos").toRect();
3296 QRect currentPos = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3297 styleObject->setProperty(
"_q_stylesliderpos", currentPos);
3298 if (oldSliderPos != currentPos) {
3299 doTransition =
false;
3300 d->stopAnimation(styleObject);
3302 }
else if (control == CC_SpinBox) {
3305 doTransition = (state & State_HasFocus) != (oldState & State_HasFocus);
3308 if (oldRect != option->rect) {
3309 doTransition =
false;
3310 d->stopAnimation(styleObject);
3314 QImage startImage = createAnimationBuffer(option, widget);
3315 QPainter startPainter(&startImage);
3317 QImage endImage = createAnimationBuffer(option, widget);
3320 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
3324 QStyleOptionComplex *styleOption = qstyleoption_cast<QStyleOptionComplex*>(clonedAnimationStyleOption(option));
3326 styleObject->setProperty(
"_q_no_animation",
true);
3330 styleOption->state = QStyle::State(oldState);
3331 styleOption->activeSubControls = QStyle::SubControl(oldActiveControls);
3332 proxy()->drawComplexControl(control, styleOption, &startPainter, widget);
3334 anim->paint(&startPainter, option);
3336 t->setStartImage(startImage);
3339 styleOption->state = option->state;
3340 styleOption->activeSubControls = option->activeSubControls;
3341 proxy()->drawComplexControl(control, styleOption, &endPainter, widget);
3343 styleObject->setProperty(
"_q_no_animation",
false);
3345 t->setEndImage(endImage);
3346 t->setStartTime(d->animationTime());
3348 if (option->state & State_MouseOver || option->state & State_Sunken)
3349 t->setDuration(150);
3351 t->setDuration(500);
3353 deleteClonedAnimationStyleOption(styleOption);
3354 d->startAnimation(t);
3356 if (QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject))) {
3357 anim->paint(painter, option);
3365#if QT_CONFIG(slider)
3367 if (
const auto *slider = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3368 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::TrackBarTheme);
3369 QRect slrect = slider->rect;
3370 QRegion tickreg = slrect;
3371 if (sub & SC_SliderGroove) {
3372 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
3373 if (slider->orientation == Qt::Horizontal) {
3375 stateId = TRS_NORMAL;
3376 theme.rect = QRect(slrect.left(), theme.rect.center().y() - 2, slrect.width(), 4);
3378 partId = TKP_TRACKVERT;
3379 stateId = TRVS_NORMAL;
3380 theme.rect = QRect(theme.rect.center().x() - 2, slrect.top(), 4, slrect.height());
3382 theme.partId = partId;
3383 theme.stateId = stateId;
3384 d->drawBackground(theme);
3385 tickreg -= theme.rect;
3387 if (sub & SC_SliderTickmarks) {
3388 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
3389 int ticks = slider->tickPosition;
3390 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
3391 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3392 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3393 int interval = slider->tickInterval;
3394 if (interval <= 0) {
3395 interval = slider->singleStep;
3396 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3398 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3400 interval = slider->pageStep;
3404 int fudge = len / 2;
3406 int bothOffset = (ticks & QSlider::TicksAbove && ticks & QSlider::TicksBelow) ? 1 : 0;
3407 painter->setPen(d->sliderTickColor);
3408 QVarLengthArray<QLine, 32> lines;
3409 int v = slider->minimum;
3410 while (v <= slider->maximum + 1) {
3411 if (v == slider->maximum + 1 && interval == 1)
3413 const int v_ = qMin(v, slider->maximum);
3414 int tickLength = (v_ == slider->minimum || v_ >= slider->maximum) ? 4 : 3;
3415 pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3416 v_, available) + fudge;
3417 if (slider->orientation == Qt::Horizontal) {
3418 if (ticks & QSlider::TicksAbove) {
3419 lines.append(QLine(pos, tickOffset - 1 - bothOffset,
3420 pos, tickOffset - 1 - bothOffset - tickLength));
3423 if (ticks & QSlider::TicksBelow) {
3424 lines.append(QLine(pos, tickOffset + thickness + bothOffset,
3425 pos, tickOffset + thickness + bothOffset + tickLength));
3428 if (ticks & QSlider::TicksAbove) {
3429 lines.append(QLine(tickOffset - 1 - bothOffset, pos,
3430 tickOffset - 1 - bothOffset - tickLength, pos));
3433 if (ticks & QSlider::TicksBelow) {
3434 lines.append(QLine(tickOffset + thickness + bothOffset, pos,
3435 tickOffset + thickness + bothOffset + tickLength, pos));
3439 int nextInterval = v + interval;
3440 if (nextInterval < v)
3444 if (!lines.isEmpty()) {
3446 painter->translate(slrect.topLeft());
3447 painter->drawLines(lines.constData(), lines.size());
3451 if (sub & SC_SliderHandle) {
3452 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
3453 if (slider->orientation == Qt::Horizontal) {
3454 if (slider->tickPosition == QSlider::TicksAbove)
3455 partId = TKP_THUMBTOP;
3456 else if (slider->tickPosition == QSlider::TicksBelow)
3457 partId = TKP_THUMBBOTTOM;
3461 if (!(slider->state & State_Enabled))
3462 stateId = TUS_DISABLED;
3463 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3464 stateId = TUS_PRESSED;
3465 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3467 else if (flags & State_HasFocus)
3468 stateId = TUS_FOCUSED;
3470 stateId = TUS_NORMAL;
3472 if (slider->tickPosition == QSlider::TicksLeft)
3473 partId = TKP_THUMBLEFT;
3474 else if (slider->tickPosition == QSlider::TicksRight)
3475 partId = TKP_THUMBRIGHT;
3477 partId = TKP_THUMBVERT;
3479 if (!(slider->state & State_Enabled))
3480 stateId = TUVS_DISABLED;
3481 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3482 stateId = TUVS_PRESSED;
3483 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3485 else if (flags & State_HasFocus)
3486 stateId = TUVS_FOCUSED;
3488 stateId = TUVS_NORMAL;
3490 theme.partId = partId;
3491 theme.stateId = stateId;
3492 d->drawBackground(theme);
3494 if (slider->state & State_HasFocus) {
3495 QStyleOptionFocusRect fropt;
3496 fropt.QStyleOption::operator=(*slider);
3497 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
3498 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3504#if QT_CONFIG(toolbutton)
3506 if (
const auto *toolbutton = qstyleoption_cast<
const QStyleOptionToolButton *>(option)) {
3507 QRect button, menuarea;
3508 button = proxy()->subControlRect(control, toolbutton, SC_ToolButton, widget);
3509 menuarea = proxy()->subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
3511 State bflags = toolbutton->state & ~State_Sunken;
3512 State mflags = bflags;
3513 bool autoRaise = flags & State_AutoRaise;
3515 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled))
3516 bflags &= ~State_Raised;
3519 if (toolbutton->state & State_Sunken) {
3520 if (toolbutton->activeSubControls & SC_ToolButton) {
3521 bflags |= State_Sunken;
3522 mflags |= State_MouseOver | State_Sunken;
3523 }
else if (toolbutton->activeSubControls & SC_ToolButtonMenu) {
3524 mflags |= State_Sunken;
3525 bflags |= State_MouseOver;
3529 QStyleOption tool = *toolbutton;
3530 if (toolbutton->subControls & SC_ToolButton) {
3531 if (flags & (State_Sunken | State_On | State_Raised) || !autoRaise) {
3532 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup && autoRaise) {
3533 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ToolBarTheme);
3534 theme.partId = TP_SPLITBUTTON;
3535 theme.rect = button;
3536 if (!(bflags & State_Enabled))
3537 stateId = TS_DISABLED;
3538 else if (bflags & State_Sunken)
3539 stateId = TS_PRESSED;
3540 else if (bflags & State_MouseOver || !(flags & State_AutoRaise))
3541 stateId = flags & State_On ? TS_HOTCHECKED : TS_HOT;
3542 else if (bflags & State_On)
3543 stateId = TS_CHECKED;
3545 stateId = TS_NORMAL;
3546 if (option->direction == Qt::RightToLeft)
3547 theme.mirrorHorizontally =
true;
3548 theme.stateId = stateId;
3549 d->drawBackground(theme);
3551 tool.rect = option->rect;
3552 tool.state = bflags;
3554 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
3556 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter, widget);
3561 if (toolbutton->state & State_HasFocus) {
3562 QStyleOptionFocusRect fr;
3563 fr.QStyleOption::operator=(*toolbutton);
3564 fr.rect.adjust(3, 3, -3, -3);
3565 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
3566 fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator,
3567 toolbutton, widget), 0);
3568 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
3570 QStyleOptionToolButton label = *toolbutton;
3571 label.state = bflags;
3574 label.state &= ~State_Sunken;
3575 label.rect = button.adjusted(fw, fw, -fw, -fw);
3576 proxy()->drawControl(CE_ToolButtonLabel, &label, painter, widget);
3578 if (toolbutton->subControls & SC_ToolButtonMenu) {
3579 tool.rect = menuarea;
3580 tool.state = mflags;
3582 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, painter, widget);
3584 tool.state = mflags;
3585 menuarea.adjust(-2, 0, 0, 0);
3587 if ((bflags & State_Sunken) != (mflags & State_Sunken)){
3589 painter->setClipRect(menuarea);
3590 tool.rect = option->rect;
3591 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter,
nullptr);
3596 painter->setPen(option->palette.dark().color());
3597 painter->drawLine(menuarea.left(), menuarea.top() + 3,
3598 menuarea.left(), menuarea.bottom() - 3);
3599 painter->setPen(option->palette.light().color());
3600 painter->drawLine(menuarea.left() - 1, menuarea.top() + 3,
3601 menuarea.left() - 1, menuarea.bottom() - 3);
3603 tool.rect = menuarea.adjusted(2, 3, -2, -1);
3604 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
3607 }
else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
3608 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
3609 QRect ir = toolbutton->rect;
3610 QStyleOptionToolButton newBtn = *toolbutton;
3611 newBtn.rect = QRect(ir.right() + 4 - mbi, ir.height() - mbi + 4, mbi - 5, mbi - 5);
3612 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
3619 if (
const auto *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(option)) {
3620 const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget);
3621 bool isActive = tb->titleBarState & QStyle::State_Active;
3622 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme);
3623 if (sub & SC_TitleBarLabel) {
3624 partId = (tb->titleBarState & Qt::WindowMinimized) ? WP_MINCAPTION : WP_CAPTION;
3625 theme.rect = option->rect;
3626 if (widget && !widget->isEnabled())
3627 stateId = CS_DISABLED;
3629 stateId = CS_ACTIVE;
3631 stateId = CS_INACTIVE;
3633 theme.partId = partId;
3634 theme.stateId = stateId;
3635 d->drawBackground(theme);
3637 QRect ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
3640 GetThemeEnumValue(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3642 COLORREF textShadowRef;
3643 GetThemeColor(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE,
TMT_TEXTSHADOWCOLOR, &textShadowRef);
3644 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3645 painter->setPen(textShadow);
3646 painter->drawText(
int(ir.x() + 3 * factor),
int(ir.y() + 2 * factor),
3647 int(ir.width() - 1 * factor), ir.height(),
3648 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3650 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3651 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3652 painter->setPen(textColor);
3653 painter->drawText(
int(ir.x() + 2 * factor),
int(ir.y() + 1 * factor),
3654 int(ir.width() - 2 * factor), ir.height(),
3655 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3657 if (sub & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3658 theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarSysMenu, widget);
3659 partId = WP_SYSBUTTON;
3660 if ((widget && !widget->isEnabled()) || !isActive)
3661 stateId = SBS_DISABLED;
3662 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_Sunken))
3663 stateId = SBS_PUSHED;
3664 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_MouseOver))
3667 stateId = SBS_NORMAL;
3668 if (!tb->icon.isNull()) {
3669 tb->icon.paint(painter, theme.rect);
3671 theme.partId = partId;
3672 theme.stateId = stateId;
3673 if (theme.size().isEmpty()) {
3674 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, tb, widget);
3675 const auto dpr = QStyleHelper::getDpr(widget);
3676 const auto icon = proxy()->standardIcon(SP_TitleBarMenuButton, tb, widget);
3677 const auto pm = icon.pixmap(QSize(extent, extent), dpr);
3678 drawItemPixmap(painter, theme.rect, Qt::AlignCenter, pm);
3680 d->drawBackground(theme);
3685 if (sub & SC_TitleBarMinButton && tb->titleBarFlags & Qt::WindowMinimizeButtonHint
3686 && !(tb->titleBarState & Qt::WindowMinimized)) {
3687 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMinButton, isActive, WP_MINBUTTON, &theme);
3688 d->drawBackground(theme);
3690 if (sub & SC_TitleBarMaxButton && tb->titleBarFlags & Qt::WindowMaximizeButtonHint
3691 && !(tb->titleBarState & Qt::WindowMaximized)) {
3692 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMaxButton, isActive, WP_MAXBUTTON, &theme);
3693 d->drawBackground(theme);
3695 if (sub & SC_TitleBarContextHelpButton
3696 && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
3697 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarContextHelpButton, isActive, WP_HELPBUTTON, &theme);
3698 d->drawBackground(theme);
3700 bool drawNormalButton = (sub & SC_TitleBarNormalButton)
3701 && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3702 && (tb->titleBarState & Qt::WindowMinimized))
3703 || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3704 && (tb->titleBarState & Qt::WindowMaximized)));
3705 if (drawNormalButton) {
3706 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarNormalButton, isActive, WP_RESTOREBUTTON, &theme);
3707 d->drawBackground(theme);
3709 if (sub & SC_TitleBarShadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3710 && !(tb->titleBarState & Qt::WindowMinimized)) {
3711 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarShadeButton, isActive, WP_MINBUTTON, &theme);
3712 d->drawBackground(theme);
3714 if (sub & SC_TitleBarUnshadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3715 && tb->titleBarState & Qt::WindowMinimized) {
3716 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarUnshadeButton, isActive, WP_RESTOREBUTTON, &theme);
3717 d->drawBackground(theme);
3719 if (sub & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3720 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarCloseButton, isActive, WP_CLOSEBUTTON, &theme);
3721 d->drawBackground(theme);
3726#if QT_CONFIG(mdiarea)
3727 case CC_MdiControls: {
3728 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme, WP_MDICLOSEBUTTON, CBS_NORMAL);
3729 if (Q_UNLIKELY(!theme.isValid()))
3732 if (option->subControls.testFlag(SC_MdiCloseButton)) {
3733 populateMdiButtonTheme(proxy(), widget, option, SC_MdiCloseButton, WP_MDICLOSEBUTTON, &theme);
3734 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3736 if (option->subControls.testFlag(SC_MdiNormalButton)) {
3737 populateMdiButtonTheme(proxy(), widget, option, SC_MdiNormalButton, WP_MDIRESTOREBUTTON, &theme);
3738 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3740 if (option->subControls.testFlag(QStyle::SC_MdiMinButton)) {
3741 populateMdiButtonTheme(proxy(), widget, option, SC_MdiMinButton, WP_MDIMINBUTTON, &theme);
3742 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3750 if (
const auto *dial = qstyleoption_cast<
const QStyleOptionSlider *>(option))
3751 QStyleHelper::drawDial(dial, painter);
3756 if (
const QStyleOptionComboBox *cmb = qstyleoption_cast<
const QStyleOptionComboBox *>(option)) {
3757 if (cmb->editable) {
3758 if (sub & SC_ComboBoxEditField) {
3759 partId = EP_EDITBORDER_NOSCROLL;
3760 if (!(flags & State_Enabled))
3761 stateId = ETS_DISABLED;
3762 else if (flags & State_MouseOver)
3764 else if (flags & State_HasFocus)
3765 stateId = ETS_FOCUSED;
3767 stateId = ETS_NORMAL;
3769 QWindowsThemeData theme(widget, painter,
3770 QWindowsVistaStylePrivate::EditTheme,
3771 partId, stateId, r);
3773 d->drawBackground(theme);
3775 if (sub & SC_ComboBoxArrow) {
3776 QRect subRect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3777 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3778 theme.rect = subRect;
3779 partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3781 if (!(cmb->state & State_Enabled))
3782 stateId = CBXS_DISABLED;
3783 else if (cmb->state & State_Sunken || cmb->state & State_On)
3784 stateId = CBXS_PRESSED;
3785 else if (cmb->state & State_MouseOver && option->activeSubControls & SC_ComboBoxArrow)
3788 stateId = CBXS_NORMAL;
3790 theme.partId = partId;
3791 theme.stateId = stateId;
3792 d->drawBackground(theme);
3796 if (sub & SC_ComboBoxFrame) {
3797 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3798 theme.rect = option->rect;
3799 theme.partId = CP_READONLY;
3800 if (!(cmb->state & State_Enabled))
3801 theme.stateId = CBXS_DISABLED;
3802 else if (cmb->state & State_Sunken || cmb->state & State_On)
3803 theme.stateId = CBXS_PRESSED;
3804 else if (cmb->state & State_MouseOver)
3805 theme.stateId = CBXS_HOT;
3807 theme.stateId = CBXS_NORMAL;
3808 d->drawBackground(theme);
3810 if (sub & SC_ComboBoxArrow) {
3811 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3812 theme.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3813 theme.partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3814 if (!(cmb->state & State_Enabled))
3815 theme.stateId = CBXS_DISABLED;
3817 theme.stateId = CBXS_NORMAL;
3818 d->drawBackground(theme);
3820 if ((sub & SC_ComboBoxEditField) && (flags & State_HasFocus)) {
3821 QStyleOptionFocusRect fropt;
3822 fropt.QStyleOption::operator=(*cmb);
3823 fropt.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget);
3824 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3831 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3832 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ScrollBarTheme);
3833 bool maxedOut = (scrollbar->maximum == scrollbar->minimum);
3835 flags &= ~State_Enabled;
3837 bool isHorz = flags & State_Horizontal;
3838 bool isRTL = option->direction == Qt::RightToLeft;
3839 if (sub & SC_ScrollBarAddLine) {
3840 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddLine, widget);
3841 partId = SBP_ARROWBTN;
3842 if (!(flags & State_Enabled))
3843 stateId = (isHorz ? (isRTL ? ABS_LEFTDISABLED : ABS_RIGHTDISABLED) : ABS_DOWNDISABLED);
3844 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_Sunken))
3845 stateId = (isHorz ? (isRTL ? ABS_LEFTPRESSED : ABS_RIGHTPRESSED) : ABS_DOWNPRESSED);
3846 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_MouseOver))
3847 stateId = (isHorz ? (isRTL ? ABS_LEFTHOT : ABS_RIGHTHOT) : ABS_DOWNHOT);
3848 else if (scrollbar->state & State_MouseOver)
3849 stateId = (isHorz ? (isRTL ? ABS_LEFTHOVER : ABS_RIGHTHOVER) : ABS_DOWNHOVER);
3851 stateId = (isHorz ? (isRTL ? ABS_LEFTNORMAL : ABS_RIGHTNORMAL) : ABS_DOWNNORMAL);
3852 theme.partId = partId;
3853 theme.stateId = stateId;
3854 d->drawBackground(theme);
3856 if (sub & SC_ScrollBarSubLine) {
3857 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubLine, widget);
3858 partId = SBP_ARROWBTN;
3859 if (!(flags & State_Enabled))
3860 stateId = (isHorz ? (isRTL ? ABS_RIGHTDISABLED : ABS_LEFTDISABLED) : ABS_UPDISABLED);
3861 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_Sunken))
3862 stateId = (isHorz ? (isRTL ? ABS_RIGHTPRESSED : ABS_LEFTPRESSED) : ABS_UPPRESSED);
3863 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_MouseOver))
3864 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOT : ABS_LEFTHOT) : ABS_UPHOT);
3865 else if (scrollbar->state & State_MouseOver)
3866 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOVER : ABS_LEFTHOVER) : ABS_UPHOVER);
3868 stateId = (isHorz ? (isRTL ? ABS_RIGHTNORMAL : ABS_LEFTNORMAL) : ABS_UPNORMAL);
3869 theme.partId = partId;
3870 theme.stateId = stateId;
3871 d->drawBackground(theme);
3874 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3875 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget));
3876 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget));
3877 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3878 stateId = SCRBS_DISABLED;
3879 theme.partId = partId;
3880 theme.stateId = stateId;
3881 d->drawBackground(theme);
3883 if (sub & SC_ScrollBarSubPage) {
3884 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget);
3885 partId = flags & State_Horizontal ? SBP_UPPERTRACKHORZ : SBP_UPPERTRACKVERT;
3886 if (!(flags & State_Enabled))
3887 stateId = SCRBS_DISABLED;
3888 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_Sunken))
3889 stateId = SCRBS_PRESSED;
3890 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_MouseOver))
3891 stateId = SCRBS_HOT;
3893 stateId = SCRBS_NORMAL;
3894 theme.partId = partId;
3895 theme.stateId = stateId;
3896 d->drawBackground(theme);
3898 if (sub & SC_ScrollBarAddPage) {
3899 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget);
3900 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3901 if (!(flags & State_Enabled))
3902 stateId = SCRBS_DISABLED;
3903 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_Sunken))
3904 stateId = SCRBS_PRESSED;
3905 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_MouseOver))
3906 stateId = SCRBS_HOT;
3908 stateId = SCRBS_NORMAL;
3909 theme.partId = partId;
3910 theme.stateId = stateId;
3911 d->drawBackground(theme);
3913 if (sub & SC_ScrollBarSlider) {
3914 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3915 if (!(flags & State_Enabled))
3916 stateId = SCRBS_DISABLED;
3917 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_Sunken))
3918 stateId = SCRBS_PRESSED;
3919 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_MouseOver))
3920 stateId = SCRBS_HOT;
3921 else if (option->state & State_MouseOver)
3922 stateId = SCRBS_HOVER;
3924 stateId = SCRBS_NORMAL;
3927 theme.partId = flags & State_Horizontal ? SBP_THUMBBTNHORZ : SBP_THUMBBTNVERT;
3928 theme.stateId = stateId;
3929 d->drawBackground(theme);
3935#if QT_CONFIG(spinbox)
3937 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(option)) {
3938 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::SpinTheme);
3939 if (sb->frame && (sub & SC_SpinBoxFrame)) {
3940 partId = EP_EDITBORDER_NOSCROLL;
3941 if (!(flags & State_Enabled))
3942 stateId = ETS_DISABLED;
3943 else if (flags & State_MouseOver)
3945 else if (flags & State_HasFocus)
3946 stateId = ETS_SELECTED;
3948 stateId = ETS_NORMAL;
3950 QWindowsThemeData ftheme(widget, painter,
3951 QWindowsVistaStylePrivate::EditTheme,
3952 partId, stateId, r);
3957 ftheme.noContent = (widget !=
nullptr);
3958 d->drawBackground(ftheme);
3960 if (sub & SC_SpinBoxUp) {
3961 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
3963 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled) || !(flags & State_Enabled))
3964 stateId = UPS_DISABLED;
3965 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken))
3966 stateId = UPS_PRESSED;
3967 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_MouseOver))
3970 stateId = UPS_NORMAL;
3971 theme.partId = partId;
3972 theme.stateId = stateId;
3973 d->drawBackground(theme);
3975 if (sub & SC_SpinBoxDown) {
3976 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
3978 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled) || !(flags & State_Enabled))
3979 stateId = DNS_DISABLED;
3980 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken))
3981 stateId = DNS_PRESSED;
3982 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_MouseOver))
3985 stateId = DNS_NORMAL;
3986 theme.partId = partId;
3987 theme.stateId = stateId;
3988 d->drawBackground(theme);
3995 QWindowsStyle::drawComplexControl(control, option, painter, widget);