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);
1336void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element,
const QStyleOption *option,
1337 QPainter *painter,
const QWidget *widget)
const
1339 if (!QWindowsVistaStylePrivate::useVista()) {
1340 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1346 const int state = option->state;
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 const QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
1356 styleObject->setProperty(
"_q_stylestate",
int(option->state));
1357 styleObject->setProperty(
"_q_stylerect", option->rect);
1359 bool doTransition = oldState &&
1360 ((state & State_Sunken) != (oldState & State_Sunken) ||
1361 (state & State_On) != (oldState & State_On) ||
1362 (state & State_MouseOver) != (oldState & State_MouseOver));
1364 if (oldRect != option->rect ||
1365 (state & State_Enabled) != (oldState & State_Enabled) ||
1366 (state & State_Active) != (oldState & State_Active))
1367 d->stopAnimation(styleObject);
1369 if (state & State_ReadOnly && element == PE_FrameLineEdit)
1370 doTransition =
false;
1373 QStyleOption *styleOption = clonedAnimationStyleOption(option);
1374 styleOption->state = QStyle::State(oldState);
1376 QWindowsVistaAnimation *animate = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
1381 QImage startImage = createAnimationBuffer(option, widget);
1382 QPainter startPainter(&startImage);
1384 QImage endImage = createAnimationBuffer(option, widget);
1391 proxy()->drawPrimitive(element, styleOption, &startPainter, widget);
1393 animate->paint(&startPainter, styleOption);
1395 transition->setStartImage(startImage);
1399 styleOption->styleObject =
nullptr;
1400 styleOption->state = option->state;
1401 proxy()->drawPrimitive(element, styleOption, &endPainter, widget);
1403 transition->setEndImage(endImage);
1412 if (element == PE_FrameLineEdit) {
1413 theme = OpenThemeData(
nullptr, L"Edit");
1414 partId = EP_EDITBORDER_NOSCROLL;
1416 if (oldState & State_HasFocus)
1417 fromState = ETS_SELECTED;
1418 else if (oldState & State_MouseOver)
1419 fromState = ETS_HOT;
1421 fromState = ETS_NORMAL;
1423 if (state & State_HasFocus)
1424 toState = ETS_SELECTED;
1425 else if (state & State_MouseOver)
1428 toState = ETS_NORMAL;
1431 theme = OpenThemeData(
nullptr, L"Button");
1432 if (element == PE_IndicatorRadioButton)
1433 partId = BP_RADIOBUTTON;
1434 else if (element == PE_IndicatorCheckBox)
1435 partId = BP_CHECKBOX;
1437 partId = BP_PUSHBUTTON;
1439 fromState = buttonStateId(oldState, partId);
1440 toState = buttonStateId(option->state, partId);
1445 && SUCCEEDED(GetThemeTransitionDuration(theme, partId, fromState, toState,
1446 TMT_TRANSITIONDURATIONS, &duration))) {
1447 transition->setDuration(
int(duration));
1449 transition->setStartTime(d->animationTime());
1451 deleteClonedAnimationStyleOption(styleOption);
1452 d->startAnimation(transition);
1454 styleObject->setProperty(
"_q_no_animation",
false);
1458 int themeNumber = -1;
1461 bool hMirrored =
false;
1462 bool vMirrored =
false;
1463 bool noBorder =
false;
1464 bool noContent =
false;
1468 case PE_PanelButtonCommand:
1469 if (
const auto *btn = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
1471 if (!(state & State_Sunken) && (state & State_On))
1472 fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1474 fill = option->palette.brush(QPalette::Button);
1475 const auto &rect = option->rect;
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, option->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, option->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) {
1981 case PE_IndicatorToolBarHandle: {
1982 QWindowsThemeData theme;
1984 if (option->state & State_Horizontal) {
1985 theme = QWindowsThemeData(widget, painter,
1986 QWindowsVistaStylePrivate::RebarTheme,
1987 RP_GRIPPER, ETS_NORMAL, option->rect.adjusted(0, 1, -2, -2));
1988 rect = option->rect.adjusted(0, 1, 0, -2);
1991 theme = QWindowsThemeData(widget, painter, QWindowsVistaStylePrivate::RebarTheme,
1992 RP_GRIPPERVERT, ETS_NORMAL, option->rect.adjusted(0, 1, -2, -2));
1993 rect = option->rect.adjusted(1, 0, -1, 0);
1997 d->drawBackground(theme);
2001 case PE_IndicatorToolBarSeparator: {
2002 QPen pen = painter->pen();
2004 painter->setPen(option->palette.window().color().darker(114));
2005 if (option->state & State_Horizontal) {
2006 int x1 = option->rect.center().x();
2007 painter->drawLine(QPoint(x1, option->rect.top() + margin), QPoint(x1, option->rect.bottom() - margin));
2009 int y1 = option->rect.center().y();
2010 painter->drawLine(QPoint(option->rect.left() + margin, y1), QPoint(option->rect.right() - margin, y1));
2012 painter->setPen(pen);
2016 case PE_PanelTipLabel: {
2017 QWindowsThemeData theme(widget, painter,
2018 QWindowsVistaStylePrivate::ToolTipTheme,
2019 TTP_STANDARD, TTSS_NORMAL, option->rect);
2020 d->drawBackground(theme);
2024 case PE_FrameTabBarBase:
2025#if QT_CONFIG(tabbar)
2026 if (
const auto *tbb = qstyleoption_cast<
const QStyleOptionTabBarBase *>(option)) {
2028 switch (tbb->shape) {
2029 case QTabBar::RoundedNorth:
2030 painter->setPen(QPen(tbb->palette.dark(), 0));
2031 painter->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
2033 case QTabBar::RoundedWest:
2034 painter->setPen(QPen(tbb->palette.dark(), 0));
2035 painter->drawLine(tbb->rect.left(), tbb->rect.top(), tbb->rect.left(), tbb->rect.bottom());
2037 case QTabBar::RoundedSouth:
2038 painter->setPen(QPen(tbb->palette.dark(), 0));
2039 painter->drawLine(tbb->rect.left(), tbb->rect.top(),
2040 tbb->rect.right(), tbb->rect.top());
2042 case QTabBar::RoundedEast:
2043 painter->setPen(QPen(tbb->palette.dark(), 0));
2044 painter->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft());
2046 case QTabBar::TriangularNorth:
2047 case QTabBar::TriangularEast:
2048 case QTabBar::TriangularWest:
2049 case QTabBar::TriangularSouth:
2051 QWindowsStyle::drawPrimitive(element, option, painter, widget);
2060#if QT_CONFIG(dialogbuttonbox)
2061 const QDialogButtonBox *buttonBox =
nullptr;
2062 if (qobject_cast<
const QMessageBox *> (widget))
2063 buttonBox = widget->findChild<
const QDialogButtonBox *>(QLatin1String(
"qt_msgbox_buttonbox"));
2066 QWindowsThemeData theme(widget, painter,
2067 QWindowsVistaStylePrivate::TaskDialogTheme,
2068 TDLG_PRIMARYPANEL, 0, option->rect);
2069 QRect toprect = option->rect;
2070 toprect.setBottom(buttonBox->geometry().top());
2071 theme.rect = toprect;
2072 d->drawBackground(theme);
2075 QRect buttonRect = option->rect;
2076 buttonRect.setTop(buttonBox->geometry().top());
2077 theme.rect = buttonRect;
2078 theme.partId = TDLG_SECONDARYPANEL;
2079 d->drawBackground(theme);
2085 case PE_PanelItemViewItem: {
2086 const QStyleOptionViewItem *vopt;
2087 bool newStyle =
true;
2088 QAbstractItemView::SelectionBehavior selectionBehavior = QAbstractItemView::SelectRows;
2089 QAbstractItemView::SelectionMode selectionMode = QAbstractItemView::NoSelection;
2090 if (
const QAbstractItemView *view = qobject_cast<
const QAbstractItemView *>(widget)) {
2091 newStyle = !qobject_cast<
const QTableView*>(view);
2092 selectionBehavior = view->selectionBehavior();
2093 selectionMode = view->selectionMode();
2094#if QT_CONFIG(accessibility)
2095 }
else if (!widget) {
2096 newStyle = !QStyleHelper::hasAncestor(option->styleObject, QAccessible::MenuItem) ;
2100 if (newStyle && (vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(option))) {
2101 bool selected = vopt->state & QStyle::State_Selected;
2102 const bool hover = selectionMode != QAbstractItemView::NoSelection && (vopt->state & QStyle::State_MouseOver);
2103 bool active = vopt->state & QStyle::State_Active;
2105 if (vopt->features & QStyleOptionViewItem::Alternate)
2106 painter->fillRect(vopt->rect, vopt->palette.alternateBase());
2108 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled
2109 ? QPalette::Normal : QPalette::Disabled;
2110 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
2111 cg = QPalette::Inactive;
2113 QRect itemRect = subElementRect(QStyle::SE_ItemViewItemFocusRect, option, widget).adjusted(-1, 0, 1, 0);
2114 itemRect.setTop(vopt->rect.top());
2115 itemRect.setBottom(vopt->rect.bottom());
2117 QSize sectionSize = itemRect.size();
2118 if (vopt->showDecorationSelected)
2119 sectionSize = vopt->rect.size();
2121 if (selectionBehavior == QAbstractItemView::SelectRows)
2122 sectionSize.setWidth(vopt->rect.width());
2125 if (vopt->backgroundBrush.style() != Qt::NoBrush) {
2126 QPainterStateGuard psg(painter);
2127 painter->setBrushOrigin(vopt->rect.topLeft());
2128 painter->fillRect(vopt->rect, vopt->backgroundBrush);
2131 if (hover || selected) {
2132 if (sectionSize.width() > 0 && sectionSize.height() > 0) {
2133 QString key = QStringLiteral(u"qvdelegate-%1-%2-%3-%4-%5").arg(sectionSize.width())
2134 .arg(sectionSize.height()).arg(selected).arg(active).arg(hover);
2135 if (!QPixmapCache::find(key, &pixmap)) {
2136 pixmap = QPixmap(sectionSize);
2137 pixmap.fill(Qt::transparent);
2140 if (selected && hover)
2142 else if (selected && !active)
2151 QWindowsThemeData theme(widget, &pixmapPainter,
2152 QWindowsVistaStylePrivate::VistaTreeViewTheme,
2153 LVP_LISTITEM, state, QRect(0, 0, sectionSize.width(), sectionSize.height()));
2155 if (!theme.isValid())
2158 d->drawBackground(theme);
2159 QPixmapCache::insert(key, pixmap);
2163 if (vopt->showDecorationSelected) {
2164 const int frame = 2;
2165 QRect srcRect = QRect(0, 0, sectionSize.width(), sectionSize.height());
2166 QRect pixmapRect = vopt->rect;
2167 bool reverse = vopt->direction == Qt::RightToLeft;
2168 bool leftSection = vopt->viewItemPosition == QStyleOptionViewItem::Beginning;
2169 bool rightSection = vopt->viewItemPosition == QStyleOptionViewItem::End;
2170 if (vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne
2171 || vopt->viewItemPosition == QStyleOptionViewItem::Invalid)
2172 painter->drawPixmap(pixmapRect.topLeft(), pixmap);
2173 else if (reverse ? rightSection : leftSection){
2174 painter->drawPixmap(QRect(pixmapRect.topLeft(),
2175 QSize(frame, pixmapRect.height())), pixmap,
2176 QRect(QPoint(0, 0), QSize(frame, pixmapRect.height())));
2177 painter->drawPixmap(pixmapRect.adjusted(frame, 0, 0, 0),
2178 pixmap, srcRect.adjusted(frame, 0, -frame, 0));
2179 }
else if (reverse ? leftSection : rightSection) {
2180 painter->drawPixmap(QRect(pixmapRect.topRight() - QPoint(frame - 1, 0),
2181 QSize(frame, pixmapRect.height())), pixmap,
2182 QRect(QPoint(pixmapRect.width() - frame, 0),
2183 QSize(frame, pixmapRect.height())));
2184 painter->drawPixmap(pixmapRect.adjusted(0, 0, -frame, 0),
2185 pixmap, srcRect.adjusted(frame, 0, -frame, 0));
2186 }
else if (vopt->viewItemPosition == QStyleOptionViewItem::Middle)
2187 painter->drawPixmap(pixmapRect, pixmap,
2188 srcRect.adjusted(frame, 0, -frame, 0));
2190 if (vopt->text.isEmpty() && vopt->icon.isNull())
2192 painter->drawPixmap(itemRect.topLeft(), pixmap);
2204 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, option->rect);
2206 if (!theme.isValid()) {
2207 QWindowsStyle::drawPrimitive(element, option, painter, widget);
2211 theme.mirrorHorizontally = hMirrored;
2212 theme.mirrorVertically = vMirrored;
2213 theme.noBorder = noBorder;
2214 theme.noContent = noContent;
2215 theme.rotate = rotate;
2217 d->drawBackground(theme);
2334void QWindowsVistaStyle::drawControl(ControlElement element,
const QStyleOption *option,
2335 QPainter *painter,
const QWidget *widget)
const
2337 if (!QWindowsVistaStylePrivate::useVista()) {
2338 QWindowsStyle::drawControl(element, option, painter, widget);
2344 bool selected = option->state & State_Selected;
2345 bool pressed = option->state & State_Sunken;
2346 bool disabled = !(option->state & State_Enabled);
2348 int state = option->state;
2349 int themeNumber = -1;
2351 QRect rect(option->rect);
2352 State flags = option->state;
2356 if (d->transitionsEnabled() && canAnimate(option)) {
2357 if (element == CE_PushButtonBevel) {
2358 QObject *styleObject = option->styleObject;
2360 int oldState = styleObject->property(
"_q_stylestate").toInt();
2361 const QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
2362 styleObject->setProperty(
"_q_stylestate",
int(option->state));
2363 styleObject->setProperty(
"_q_stylerect", option->rect);
2365 bool wasDefault =
false;
2366 bool isDefault =
false;
2367 if (
const QStyleOptionButton *button = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
2368 wasDefault = styleObject->property(
"_q_isdefault").toBool();
2369 isDefault = button->features & QStyleOptionButton::DefaultButton;
2370 styleObject->setProperty(
"_q_isdefault", isDefault);
2373 bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) ||
2374 (state & State_On) != (oldState & State_On) ||
2375 (state & State_MouseOver) != (oldState & State_MouseOver));
2377 if (oldRect != option->rect || (wasDefault && !isDefault)) {
2378 doTransition =
false;
2379 d->stopAnimation(styleObject);
2383 styleObject->setProperty(
"_q_no_animation",
true);
2386 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
2387 QStyleOption *styleOption = clonedAnimationStyleOption(option);
2388 styleOption->state = QStyle::State(oldState);
2390 QImage startImage = createAnimationBuffer(option, widget);
2391 QPainter startPainter(&startImage);
2395 proxy()->drawControl(element, styleOption, &startPainter, widget);
2397 anim->paint(&startPainter, styleOption);
2398 d->stopAnimation(styleObject);
2401 t->setStartImage(startImage);
2402 QImage endImage = createAnimationBuffer(option, widget);
2404 styleOption->state = option->state;
2405 proxy()->drawControl(element, styleOption, &endPainter, widget);
2406 t->setEndImage(endImage);
2410 const HTHEME theme = OpenThemeData(
nullptr, L"Button");
2412 int fromState = buttonStateId(oldState, BP_PUSHBUTTON);
2413 int toState = buttonStateId(option->state, BP_PUSHBUTTON);
2414 if (GetThemeTransitionDuration(theme, BP_PUSHBUTTON, fromState, toState, TMT_TRANSITIONDURATIONS, &duration) == S_OK)
2415 t->setDuration(
int(duration));
2418 t->setStartTime(d->animationTime());
2419 styleObject->setProperty(
"_q_no_animation",
false);
2421 deleteClonedAnimationStyleOption(styleOption);
2422 d->startAnimation(t);
2425 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
2427 anim->paint(painter, option);
2434 bool hMirrored =
false;
2435 bool vMirrored =
false;
2439 case CE_PushButtonBevel:
2440 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
2441 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
2442 partId = BP_PUSHBUTTON;
2443 if (btn->features & QStyleOptionButton::CommandLinkButton)
2445 bool justFlat = (btn->features & QStyleOptionButton::Flat) && !(flags & (State_On|State_Sunken));
2446 if (!(flags & State_Enabled) && !(btn->features & QStyleOptionButton::Flat))
2447 stateId = PBS_DISABLED;
2450 else if (flags & (State_Sunken | State_On))
2451 stateId = PBS_PRESSED;
2452 else if (flags & State_MouseOver)
2454 else if (btn->features & QStyleOptionButton::DefaultButton && (state & State_Active))
2455 stateId = PBS_DEFAULTED;
2457 stateId = PBS_NORMAL;
2460 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2461 d->drawBackground(theme);
2464 if (btn->features & QStyleOptionButton::HasMenu) {
2465 int mbiw = 0, mbih = 0;
2466 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::ToolBarTheme,
2468 if (theme.isValid()) {
2469 const QSizeF size = theme.size() * QStyleHelper::dpiScaled(1, option);
2470 if (!size.isEmpty()) {
2471 mbiw = qRound(size.width());
2472 mbih = qRound(size.height());
2475 QRect ir = subElementRect(SE_PushButtonContents, option,
nullptr);
2476 QStyleOptionButton newBtn = *btn;
2477 newBtn.rect = QStyle::visualRect(option->direction, option->rect,
2478 QRect(ir.right() - mbiw - 2,
2479 option->rect.top() + (option->rect.height()/2) - (mbih/2),
2480 mbiw + 1, mbih + 1));
2481 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
2487 themeNumber = QWindowsVistaStylePrivate::StatusTheme;
2488 partId = SP_GRIPPER;
2489 QWindowsThemeData theme(
nullptr, painter, themeNumber, partId);
2490 QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize();
2492 if (
const auto *sg = qstyleoption_cast<
const QStyleOptionSizeGrip *>(option)) {
2493 switch (sg->corner) {
2494 case Qt::BottomRightCorner:
2495 rect = QRect(QPoint(rect.right() - size.width(), rect.bottom() - size.height()), size);
2497 case Qt::BottomLeftCorner:
2498 rect = QRect(QPoint(rect.left() + 1, rect.bottom() - size.height()), size);
2501 case Qt::TopRightCorner:
2502 rect = QRect(QPoint(rect.right() - size.width(), rect.top() + 1), size);
2505 case Qt::TopLeftCorner:
2506 rect = QRect(rect.topLeft() + QPoint(1, 1), size);
2507 hMirrored = vMirrored =
true;
2514 painter->eraseRect(option->rect);
2518#if QT_CONFIG(tabwidget)
2519 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option))
2520 stateId = tab->state & State_Enabled ? TIS_NORMAL : TIS_DISABLED;
2524 case CE_TabBarTabShape:
2525#if QT_CONFIG(tabwidget)
2526 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option)) {
2527 themeNumber = QWindowsVistaStylePrivate::TabTheme;
2528 const bool isDisabled = !(tab->state & State_Enabled);
2529 const bool hasFocus = tab->state & State_HasFocus;
2530 const bool isHot = tab->state & State_MouseOver;
2531 const bool selected = tab->state & State_Selected;
2532 bool lastTab = tab->position == QStyleOptionTab::End;
2533 bool firstTab = tab->position == QStyleOptionTab::Beginning;
2534 const bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
2535 const bool leftAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignLeft;
2536 const bool centerAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignCenter;
2537 const int borderThickness = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
2538 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, option, widget);
2541 stateId = TIS_DISABLED;
2543 stateId = TIS_SELECTED;
2545 stateId = TIS_FOCUSED;
2549 stateId = TIS_NORMAL;
2552 if (firstTab || onlyOne) {
2554 partId = TABP_TABITEMLEFTEDGE;
2555 else if (centerAligned)
2556 partId = TABP_TABITEM;
2558 partId = TABP_TABITEMRIGHTEDGE;
2560 partId = TABP_TABITEM;
2563 if (tab->direction == Qt::RightToLeft
2564 && (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth)) {
2565 bool temp = firstTab;
2570 const bool begin = firstTab || onlyOne;
2571 const bool end = lastTab || onlyOne;
2573 switch (tab->shape) {
2574 case QTabBar::RoundedNorth:
2576 rect.adjust(begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap, borderThickness);
2578 rect.adjust(begin? tabOverlap : 0, tabOverlap, end ? -tabOverlap : 0, 0);
2580 case QTabBar::RoundedSouth:
2584 rect.adjust(begin ? 0 : -tabOverlap , -borderThickness, end ? 0 : tabOverlap, 0);
2586 rect.adjust(begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0 , -tabOverlap);
2588 case QTabBar::RoundedEast:
2591 rect.adjust(-borderThickness, begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap);
2593 rect.adjust(0, begin ? tabOverlap : 0, -tabOverlap, end ? -tabOverlap : 0);
2595 case QTabBar::RoundedWest:
2599 rect.adjust(0, begin ? 0 : -tabOverlap, borderThickness, end ? 0 : tabOverlap);
2601 rect.adjust(tabOverlap, begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0);
2609 switch (tab->shape) {
2610 case QTabBar::RoundedNorth:
2611 rect.adjust(0,0, 0,-1);
2613 case QTabBar::RoundedSouth:
2614 rect.adjust(0,1, 0,0);
2616 case QTabBar::RoundedEast:
2617 rect.adjust( 1,0, 0,0);
2619 case QTabBar::RoundedWest:
2620 rect.adjust(0,0, -1,0);
2630 case CE_ProgressBarGroove: {
2631 Qt::Orientation orient = Qt::Horizontal;
2632 if (
const auto *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(option))
2633 if (!(pb->state & QStyle::State_Horizontal))
2634 orient = Qt::Vertical;
2636 partId = (orient == Qt::Horizontal) ? PP_BAR : PP_BARVERT;
2637 themeNumber = QWindowsVistaStylePrivate::ProgressTheme;
2642 case CE_ProgressBarContents:
2643 if (
const auto *bar = qstyleoption_cast<
const QStyleOptionProgressBar *>(option)) {
2644 bool isIndeterminate = (bar->minimum == 0 && bar->maximum == 0);
2645 const bool vertical = !(bar->state & QStyle::State_Horizontal);
2646 const bool inverted = bar->invertedAppearance;
2648 if (isIndeterminate || (bar->progress > 0 && (bar->progress < bar->maximum) && d->transitionsEnabled())) {
2649 if (!d->animation(styleObject(option)))
2650 d->startAnimation(
new QProgressStyleAnimation(d->animationFps, styleObject(option)));
2652 d->stopAnimation(styleObject(option));
2655 QWindowsThemeData theme(widget, painter,
2656 QWindowsVistaStylePrivate::ProgressTheme,
2657 vertical ? PP_FILLVERT : PP_FILL);
2658 theme.rect = option->rect;
2659 bool reverse = (bar->direction == Qt::LeftToRight && inverted) || (bar->direction == Qt::RightToLeft && !inverted);
2660 QTime current = d->animationTime();
2662 if (isIndeterminate) {
2663 if (
auto *progressAnimation = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2665 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2666 int animOffset = progressAnimation->startTime().msecsTo(current) / 4;
2667 if (animOffset > animationWidth)
2668 progressAnimation->setStartTime(d->animationTime());
2670 painter->setClipRect(theme.rect);
2672 QSize pixmapSize(14, 14);
2674 animRect = QRect(theme.rect.left(),
2675 inverted ? rect.top() - glowSize + animOffset :
2676 rect.bottom() + glowSize - animOffset,
2677 rect.width(), glowSize);
2678 pixmapSize.setHeight(animRect.height());
2680 animRect = QRect(rect.left() - glowSize + animOffset,
2681 rect.top(), glowSize, rect.height());
2682 animRect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2683 option->rect, animRect);
2684 pixmapSize.setWidth(animRect.width());
2686 QString name = QStringLiteral(u"qiprogress-%1-%2").arg(pixmapSize.width()).arg(pixmapSize.height());
2688 if (!QPixmapCache::find(name, &pixmap)) {
2689 QImage image(pixmapSize, QImage::Format_ARGB32);
2690 image.fill(Qt::transparent);
2692 theme.painter = &imagePainter;
2693 theme.partId = vertical ? PP_FILLVERT : PP_FILL;
2694 theme.rect = QRect(QPoint(0,0), animRect.size());
2695 QLinearGradient alphaGradient(0, 0, vertical ? 0 : image.width(),
2696 vertical ? image.height() : 0);
2697 alphaGradient.setColorAt(0, QColor(0, 0, 0, 0));
2698 alphaGradient.setColorAt(0.5, QColor(0, 0, 0, 220));
2699 alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
2700 imagePainter.fillRect(image.rect(), alphaGradient);
2701 imagePainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
2702 d->drawBackground(theme);
2704 pixmap = QPixmap::fromImage(image);
2705 QPixmapCache::insert(name, pixmap);
2707 painter->drawPixmap(animRect, pixmap);
2711 qint64 progress = qMax<qint64>(bar->progress, bar->minimum);
2714 int maxHeight = option->rect.height();
2716 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxHeight);
2717 int height = isIndeterminate ? maxHeight: qMax(
int(vc6_workaround), minHeight);
2718 theme.rect.setHeight(height);
2720 theme.rect.moveTop(rect.height() - theme.rect.height());
2722 int maxWidth = option->rect.width();
2724 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth);
2725 int width = isIndeterminate ? maxWidth : qMax(
int(vc6_workaround), minWidth);
2726 theme.rect.setWidth(width);
2727 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2728 option->rect, theme.rect);
2730 d->drawBackground(theme);
2732 if (QProgressStyleAnimation *a = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2734 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2735 int animOffset = a->startTime().msecsTo(current) / 4;
2736 theme.partId = vertical ? PP_MOVEOVERLAYVERT : PP_MOVEOVERLAY;
2737 if (animOffset > animationWidth) {
2738 if (bar->progress < bar->maximum)
2739 a->setStartTime(d->animationTime());
2741 d->stopAnimation(styleObject(option));
2745 painter->setClipRect(theme.rect);
2747 theme.rect = QRect(theme.rect.left(),
2748 inverted ? rect.top() - glowSize + animOffset :
2749 rect.bottom() + glowSize - animOffset,
2750 rect.width(), glowSize);
2752 theme.rect = QRect(rect.left() - glowSize + animOffset,rect.top(), glowSize, rect.height());
2753 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight, option->rect, theme.rect);
2755 d->drawBackground(theme);
2762 case CE_MenuBarItem:
2763 if (
const auto *mbi = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2764 if (mbi->menuItemType == QStyleOptionMenuItem::DefaultItem)
2767 QPalette::ColorRole textRole = disabled ? QPalette::Text : QPalette::ButtonText;
2768 const auto dpr = QStyleHelper::getDpr(widget);
2769 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2770 const auto pix = mbi->icon.pixmap(QSize(extent, extent), dpr, QIcon::Normal);
2772 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2773 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
2774 alignment |= Qt::TextHideMnemonic;
2776 if (widget && mbi->palette.color(QPalette::Window) != Qt::transparent) {
2778 QWindowsThemeData theme(widget, painter,
2779 QWindowsVistaStylePrivate::MenuTheme,
2780 MENU_BARBACKGROUND, 0, option->rect.adjusted(-1, 0, 2, 1));
2781 d->drawBackground(theme);
2783 int stateId = MBI_NORMAL;
2785 stateId = MBI_DISABLED;
2787 stateId = MBI_PUSHED;
2791 QWindowsThemeData theme2(widget, painter,
2792 QWindowsVistaStylePrivate::MenuTheme,
2793 MENU_BARITEM, stateId, option->rect);
2794 d->drawBackground(theme2);
2798 drawItemPixmap(painter, mbi->rect, alignment, pix);
2800 drawItemText(painter, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled, mbi->text, textRole);
2805 case CE_MenuEmptyArea:
2806 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2807 QBrush fill = menuitem->palette.brush((menuitem->state & State_Selected) ?
2808 QPalette::Highlight : QPalette::Button);
2809 painter->fillRect(rect, fill);
2815 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2817 const qreal factor = QWindowsVistaStylePrivate::nativeMetricScaleFactor(widget);
2818 int checkcol = qRound(qreal(25) * factor);
2819 const int gutterWidth = qRound(qreal(3) * factor);
2821 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::MenuTheme,
2822 MENU_POPUPCHECKBACKGROUND, MBI_HOT);
2823 QWindowsThemeData themeSize = theme;
2824 themeSize.partId = MENU_POPUPCHECK;
2825 themeSize.stateId = 0;
2826 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2827 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2828 checkcol = qMax(menuitem->maxIconWidth, qRound(gutterWidth + size.width() + margins.left() + margins.right()));
2830 QRect rect = option->rect;
2833 QWindowsThemeData popupbackgroundTheme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2834 MENU_POPUPBACKGROUND, stateId, option->rect);
2835 d->drawBackground(popupbackgroundTheme);
2838 if (option->direction == Qt::LeftToRight)
2839 checkcol += rect.x();
2840 QPoint p1 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.top()));
2841 QPoint p2 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.bottom()));
2842 QRect gutterRect(p1.x(), p1.y(), gutterWidth, p2.y() - p1.y() + 1);
2843 QWindowsThemeData theme2(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2844 MENU_POPUPGUTTER, stateId, gutterRect);
2845 d->drawBackground(theme2);
2848 menuitem->rect.getRect(&x, &y, &w, &h);
2849 int tab = menuitem->reservedShortcutWidth;
2850 bool dis = !(menuitem->state & State_Enabled);
2851 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
2852 ? menuitem->checked :
false;
2853 bool act = menuitem->state & State_Selected;
2855 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {
2856 int yoff = y-2 + h / 2;
2857 const int separatorSize = qRound(qreal(6) * QWindowsStylePrivate::nativeMetricScaleFactor(widget));
2858 QPoint p1 = QPoint(x + checkcol, yoff);
2859 QPoint p2 = QPoint(x + w + separatorSize, yoff);
2861 QRect subRect(p1.x() + (gutterWidth - menuitem->rect.x()), p1.y(),
2862 p2.x() - p1.x(), separatorSize);
2863 subRect = QStyle::visualRect(option->direction, option->rect, subRect );
2864 QWindowsThemeData theme2(widget, painter,
2865 QWindowsVistaStylePrivate::MenuTheme,
2866 MENU_POPUPSEPARATOR, stateId, subRect);
2867 d->drawBackground(theme2);
2871 QRect vCheckRect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x(),
2872 menuitem->rect.y(), checkcol - (gutterWidth + menuitem->rect.x()), menuitem->rect.height()));
2875 stateId = dis ? MBI_DISABLED : MBI_HOT;
2876 QWindowsThemeData theme2(widget, painter,
2877 QWindowsVistaStylePrivate::MenuTheme,
2878 MENU_POPUPITEM, stateId, option->rect);
2879 d->drawBackground(theme2);
2883 QWindowsThemeData theme(widget, painter,
2884 QWindowsVistaStylePrivate::MenuTheme,
2885 MENU_POPUPCHECKBACKGROUND,
2886 menuitem->icon.isNull() ? MBI_HOT : MBI_PUSHED, vCheckRect);
2887 QWindowsThemeData themeSize = theme;
2888 themeSize.partId = MENU_POPUPCHECK;
2889 themeSize.stateId = 0;
2890 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2891 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2892 QRect checkRect(0, 0, qRound(size.width() + margins.left() + margins.right()),
2893 qRound(size.height() + margins.bottom() + margins.top()));
2894 checkRect.moveCenter(vCheckRect.center());
2895 theme.rect = checkRect;
2897 d->drawBackground(theme);
2899 if (menuitem->icon.isNull()) {
2900 checkRect = QRect(QPoint(0, 0), size.toSize());
2901 checkRect.moveCenter(theme.rect.center());
2902 theme.rect = checkRect;
2904 theme.partId = MENU_POPUPCHECK;
2905 bool bullet = menuitem->checkType & QStyleOptionMenuItem::Exclusive;
2907 theme.stateId = bullet ? MC_BULLETDISABLED: MC_CHECKMARKDISABLED;
2909 theme.stateId = bullet ? MC_BULLETNORMAL: MC_CHECKMARKNORMAL;
2910 d->drawBackground(theme);
2914 if (!menuitem->icon.isNull()) {
2915 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
2917 mode = QIcon::Active;
2918 const auto size = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2919 QRect pmr(QPoint(0, 0), QSize(size, size));
2920 pmr.moveCenter(vCheckRect.center());
2921 menuitem->icon.paint(painter, pmr, Qt::AlignCenter, mode,
2922 checked ? QIcon::On : QIcon::Off);
2925 painter->setPen(menuitem->palette.buttonText().color());
2927 const QColor textColor = menuitem->palette.text().color();
2929 painter->setPen(textColor);
2931 int xm = windowsItemFrame + checkcol + windowsItemHMargin + (gutterWidth - menuitem->rect.x()) - 1;
2932 int xpos = menuitem->rect.x() + xm;
2933 QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
2934 QRect vTextRect = visualRect(option->direction, menuitem->rect, textRect);
2935 QString s = menuitem->text;
2938 int t = s.indexOf(QLatin1Char(
'\t'));
2939 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2940 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
2941 text_flags |= Qt::TextHideMnemonic;
2942 text_flags |= Qt::AlignLeft;
2944 QRect vShortcutRect = visualRect(option->direction, menuitem->rect,
2945 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
2946 painter->drawText(vShortcutRect, text_flags, s.mid(t + 1));
2949 QFont font = menuitem->font;
2950 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
2952 painter->setFont(font);
2953 painter->setPen(textColor);
2954 painter->drawText(vTextRect, text_flags, s.left(t));
2957 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {
2958 int dim = (h - 2 * windowsItemFrame) / 2;
2959 PrimitiveElement arrow;
2960 arrow = (option->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
2961 xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim;
2962 QRect vSubMenuRect = visualRect(option->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
2963 QStyleOptionMenuItem newMI = *menuitem;
2964 newMI.rect = vSubMenuRect;
2965 newMI.state = dis ? State_None : State_Enabled;
2966 proxy()->drawPrimitive(arrow, &newMI, painter, widget);
2972 case CE_HeaderSection:
2973 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(option)) {
2974 partId = HP_HEADERITEM;
2975 if (flags & State_Sunken)
2976 stateId = HIS_PRESSED;
2977 else if (flags & State_MouseOver)
2980 stateId = HIS_NORMAL;
2982 if (header->sortIndicator != QStyleOptionHeader::None)
2985 QWindowsThemeData theme(widget, painter,
2986 QWindowsVistaStylePrivate::HeaderTheme,
2987 partId, stateId, option->rect);
2988 d->drawBackground(theme);
2992 case CE_MenuBarEmptyArea: {
2993 stateId = MBI_NORMAL;
2994 if (!(state & State_Enabled))
2995 stateId = MBI_DISABLED;
2996 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2997 MENU_BARBACKGROUND, stateId, option->rect);
2998 d->drawBackground(theme);
3003#if QT_CONFIG(toolbar)
3004 if (
const auto *toolbar = qstyleoption_cast<
const QStyleOptionToolBar *>(option)) {
3005 QPalette pal = option->palette;
3006 pal.setColor(QPalette::Dark, option->palette.window().color().darker(130));
3007 QStyleOptionToolBar copyOpt = *toolbar;
3008 copyOpt.palette = pal;
3009 QWindowsStyle::drawControl(element, ©Opt, painter, widget);
3014#if QT_CONFIG(dockwidget)
3015 case CE_DockWidgetTitle:
3016 if (
const auto *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(option)) {
3017 QRect rect = option->rect;
3018 const QDockWidget *dw = qobject_cast<
const QDockWidget *>(widget);
3019 bool isFloating = dw && dw->isFloating();
3020 int buttonMargin = 4;
3021 int mw = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, widget);
3022 int fw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, dwOpt, widget);
3024 const bool verticalTitleBar = dwOpt->verticalTitleBar;
3026 if (verticalTitleBar) {
3027 rect = rect.transposed();
3029 painter->translate(rect.left() - 1, rect.top() + rect.width());
3030 painter->rotate(-90);
3031 painter->translate(-rect.left() + 1, -rect.top());
3034 QRect r = option->rect.adjusted(0, 2, -1, -3);
3035 QRect titleRect = r;
3037 if (dwOpt->closable) {
3038 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton, dwOpt, widget).actualSize(QSize(10, 10));
3039 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3042 if (dwOpt->floatable) {
3043 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarMaxButton, dwOpt, widget).actualSize(QSize(10, 10));
3044 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3048 titleRect.adjust(0, -fw, 0, 0);
3049 if (widget && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey())
3050 titleRect.adjust(titleRect.height() + mw, 0, 0, 0);
3052 titleRect.adjust(mw, 0, 0, 0);
3053 if (!dwOpt->floatable && !dwOpt->closable)
3054 titleRect.adjust(0, 0, -mw, 0);
3057 if (!verticalTitleBar)
3058 titleRect = visualRect(dwOpt->direction, r, titleRect);
3061 const bool isActive = dwOpt->state & State_Active;
3062 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
3064 stateId = CS_ACTIVE;
3066 stateId = CS_INACTIVE;
3068 rect = rect.adjusted(-fw, -fw, fw, 0);
3070 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
3071 if (!theme.isValid())
3076 theme.partId = WP_SMALLCAPTION;
3077 d->drawBackground(theme);
3081 QIcon ico = widget->windowIcon();
3082 bool hasIcon = (ico.cacheKey() != QApplication::windowIcon().cacheKey());
3084 const auto titleHeight = rect.height() - 2;
3085 const auto dpr = QStyleHelper::getDpr(widget);
3086 const auto pxIco = ico.pixmap(QSize(titleHeight, titleHeight), dpr);
3087 if (!verticalTitleBar && dwOpt->direction == Qt::RightToLeft)
3088 painter->drawPixmap(rect.width() - titleHeight - pxIco.width(), rect.bottom() - titleHeight - 2, pxIco);
3090 painter->drawPixmap(fw, rect.bottom() - titleHeight - 2, pxIco);
3092 if (!dwOpt->title.isEmpty()) {
3093 QPen oldPen = painter->pen();
3094 QFont oldFont = painter->font();
3095 QFont titleFont = oldFont;
3096 titleFont.setBold(
true);
3097 painter->setFont(titleFont);
3099 = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
3101 int result = TST_NONE;
3102 GetThemeEnumValue(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3103 if (result != TST_NONE) {
3104 COLORREF textShadowRef;
3105 GetThemeColor(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWCOLOR, &textShadowRef);
3106 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3107 painter->setPen(textShadow);
3108 drawItemText(painter, titleRect.adjusted(1, 1, 1, 1),
3109 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3110 dwOpt->state & State_Enabled, titleText);
3113 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3114 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3115 painter->setPen(textColor);
3116 drawItemText(painter, titleRect,
3117 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3118 dwOpt->state & State_Enabled, titleText);
3119 painter->setFont(oldFont);
3120 painter->setPen(oldPen);
3123 painter->setBrush(option->palette.window().color().darker(110));
3124 painter->setPen(option->palette.window().color().darker(130));
3125 painter->drawRect(rect.adjusted(0, 1, -1, -3));
3127 if (!dwOpt->title.isEmpty()) {
3128 QString titleText = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight,
3129 verticalTitleBar ? titleRect.height() : titleRect.width());
3130 const int indent = 4;
3131 drawItemText(painter, rect.adjusted(indent + 1, 1, -indent - 1, -1),
3132 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic,
3134 dwOpt->state & State_Enabled, titleText,
3135 QPalette::WindowText);
3142#if QT_CONFIG(rubberband)
3144 if (qstyleoption_cast<
const QStyleOptionRubberBand *>(option)) {
3145 QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
3147 painter->setPen(highlight.darker(120));
3148 QColor dimHighlight(qMin(highlight.red()/2 + 110, 255),
3149 qMin(highlight.green()/2 + 110, 255),
3150 qMin(highlight.blue()/2 + 110, 255),
3151 (widget && widget->isWindow())? 255 : 127);
3152 painter->setBrush(dimHighlight);
3153 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
3160 case CE_HeaderEmptyArea:
3161 if (option->state & State_Horizontal) {
3162 themeNumber = QWindowsVistaStylePrivate::HeaderTheme;
3163 stateId = HIS_NORMAL;
3165 QWindowsStyle::drawControl(CE_HeaderEmptyArea, option, painter, widget);
3170#if QT_CONFIG(itemviews)
3171 case CE_ItemViewItem: {
3172 const QStyleOptionViewItem *vopt;
3173 const QAbstractItemView *view = qobject_cast<
const QAbstractItemView *>(widget);
3174 bool newStyle =
true;
3176 if (qobject_cast<
const QTableView*>(widget))
3179 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3181 if (newStyle && view && (vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(option))) {
3183
3184
3185
3186
3187
3188
3189 QPalette palette = vopt->palette;
3190 palette.setColor(QPalette::All, QPalette::HighlightedText, palette.color(QPalette::Active, QPalette::Text));
3192 palette.setColor(QPalette::All, QPalette::Highlight, palette.base().color().darker(108));
3193 QStyleOptionViewItem adjustedOption = *vopt;
3194 adjustedOption.palette = palette;
3196 if ((view->selectionMode() == QAbstractItemView::SingleSelection)
3197 && !(vopt->state & State_KeyboardFocusChange))
3198 adjustedOption.state &= ~State_HasFocus;
3199 if (!theme.isValid()) {
3200 QWindowsStyle::drawControl(element, &adjustedOption, painter, widget);
3204 if (!theme.isValid()) {
3205 QWindowsStyle::drawControl(element, option, painter, widget);
3210 theme.rotate = rotate;
3211 theme.mirrorHorizontally = hMirrored;
3212 theme.mirrorVertically = vMirrored;
3213 d->drawBackground(theme);
3218#if QT_CONFIG(combobox)
3219 case CE_ComboBoxLabel:
3220 QCommonStyle::drawControl(element, option, painter, widget);
3228 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3230 if (!theme.isValid()) {
3231 QWindowsStyle::drawControl(element, option, painter, widget);
3235 theme.rotate = rotate;
3236 theme.mirrorHorizontally = hMirrored;
3237 theme.mirrorVertically = vMirrored;
3239 d->drawBackground(theme);
3247void QWindowsVistaStyle::drawComplexControl(ComplexControl control,
const QStyleOptionComplex *option,
3248 QPainter *painter,
const QWidget *widget)
const
3252 if (!QWindowsVistaStylePrivate::useVista()) {
3253 QWindowsStyle::drawComplexControl(control, option, painter, widget);
3257 State state = option->state;
3258 SubControls sub = option->subControls;
3263 State flags = option->state;
3264 if (widget && widget->testAttribute(Qt::WA_UnderMouse) && widget->isActiveWindow())
3265 flags |= State_MouseOver;
3267 if (d->transitionsEnabled() && canAnimate(option))
3269 if (control == CC_ScrollBar || control == CC_SpinBox || control == CC_ComboBox) {
3270 QObject *styleObject = option->styleObject;
3272 int oldState = styleObject->property(
"_q_stylestate").toInt();
3273 int oldActiveControls = styleObject->property(
"_q_stylecontrols").toInt();
3275 QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
3276 styleObject->setProperty(
"_q_stylestate",
int(option->state));
3277 styleObject->setProperty(
"_q_stylecontrols",
int(option->activeSubControls));
3278 styleObject->setProperty(
"_q_stylerect", option->rect);
3280 bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken)
3281 || (state & State_On) != (oldState & State_On)
3282 || (state & State_MouseOver) != (oldState & State_MouseOver)
3283 || oldActiveControls !=
int(option->activeSubControls));
3285 if (qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3286 QRect oldSliderPos = styleObject->property(
"_q_stylesliderpos").toRect();
3287 QRect currentPos = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3288 styleObject->setProperty(
"_q_stylesliderpos", currentPos);
3289 if (oldSliderPos != currentPos) {
3290 doTransition =
false;
3291 d->stopAnimation(styleObject);
3293 }
else if (control == CC_SpinBox) {
3296 doTransition = (state & State_HasFocus) != (oldState & State_HasFocus);
3299 if (oldRect != option->rect) {
3300 doTransition =
false;
3301 d->stopAnimation(styleObject);
3305 QImage startImage = createAnimationBuffer(option, widget);
3306 QPainter startPainter(&startImage);
3308 QImage endImage = createAnimationBuffer(option, widget);
3311 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
3315 QStyleOptionComplex *styleOption = qstyleoption_cast<QStyleOptionComplex*>(clonedAnimationStyleOption(option));
3317 styleObject->setProperty(
"_q_no_animation",
true);
3321 styleOption->state = QStyle::State(oldState);
3322 styleOption->activeSubControls = QStyle::SubControl(oldActiveControls);
3323 proxy()->drawComplexControl(control, styleOption, &startPainter, widget);
3325 anim->paint(&startPainter, option);
3327 t->setStartImage(startImage);
3330 styleOption->state = option->state;
3331 styleOption->activeSubControls = option->activeSubControls;
3332 proxy()->drawComplexControl(control, styleOption, &endPainter, widget);
3334 styleObject->setProperty(
"_q_no_animation",
false);
3336 t->setEndImage(endImage);
3337 t->setStartTime(d->animationTime());
3339 if (option->state & State_MouseOver || option->state & State_Sunken)
3340 t->setDuration(150);
3342 t->setDuration(500);
3344 deleteClonedAnimationStyleOption(styleOption);
3345 d->startAnimation(t);
3347 if (QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject))) {
3348 anim->paint(painter, option);
3356#if QT_CONFIG(slider)
3358 if (
const auto *slider = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3359 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::TrackBarTheme);
3360 QRect slrect = slider->rect;
3361 QRegion tickreg = slrect;
3362 if (sub & SC_SliderGroove) {
3363 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
3364 if (slider->orientation == Qt::Horizontal) {
3366 stateId = TRS_NORMAL;
3367 theme.rect = QRect(slrect.left(), theme.rect.center().y() - 2, slrect.width(), 4);
3369 partId = TKP_TRACKVERT;
3370 stateId = TRVS_NORMAL;
3371 theme.rect = QRect(theme.rect.center().x() - 2, slrect.top(), 4, slrect.height());
3373 theme.partId = partId;
3374 theme.stateId = stateId;
3375 d->drawBackground(theme);
3376 tickreg -= theme.rect;
3378 if (sub & SC_SliderTickmarks) {
3379 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
3380 int ticks = slider->tickPosition;
3381 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
3382 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3383 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3384 int interval = slider->tickInterval;
3385 if (interval <= 0) {
3386 interval = slider->singleStep;
3387 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3389 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3391 interval = slider->pageStep;
3395 int fudge = len / 2;
3397 int bothOffset = (ticks & QSlider::TicksAbove && ticks & QSlider::TicksBelow) ? 1 : 0;
3398 painter->setPen(d->sliderTickColor);
3399 QVarLengthArray<QLine, 32> lines;
3400 int v = slider->minimum;
3401 while (v <= slider->maximum + 1) {
3402 if (v == slider->maximum + 1 && interval == 1)
3404 const int v_ = qMin(v, slider->maximum);
3405 int tickLength = (v_ == slider->minimum || v_ >= slider->maximum) ? 4 : 3;
3406 pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3407 v_, available) + fudge;
3408 if (slider->orientation == Qt::Horizontal) {
3409 if (ticks & QSlider::TicksAbove) {
3410 lines.append(QLine(pos, tickOffset - 1 - bothOffset,
3411 pos, tickOffset - 1 - bothOffset - tickLength));
3414 if (ticks & QSlider::TicksBelow) {
3415 lines.append(QLine(pos, tickOffset + thickness + bothOffset,
3416 pos, tickOffset + thickness + bothOffset + tickLength));
3419 if (ticks & QSlider::TicksAbove) {
3420 lines.append(QLine(tickOffset - 1 - bothOffset, pos,
3421 tickOffset - 1 - bothOffset - tickLength, pos));
3424 if (ticks & QSlider::TicksBelow) {
3425 lines.append(QLine(tickOffset + thickness + bothOffset, pos,
3426 tickOffset + thickness + bothOffset + tickLength, pos));
3430 int nextInterval = v + interval;
3431 if (nextInterval < v)
3435 if (!lines.isEmpty()) {
3437 painter->translate(slrect.topLeft());
3438 painter->drawLines(lines.constData(), lines.size());
3442 if (sub & SC_SliderHandle) {
3443 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
3444 if (slider->orientation == Qt::Horizontal) {
3445 if (slider->tickPosition == QSlider::TicksAbove)
3446 partId = TKP_THUMBTOP;
3447 else if (slider->tickPosition == QSlider::TicksBelow)
3448 partId = TKP_THUMBBOTTOM;
3452 if (!(slider->state & State_Enabled))
3453 stateId = TUS_DISABLED;
3454 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3455 stateId = TUS_PRESSED;
3456 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3458 else if (flags & State_HasFocus)
3459 stateId = TUS_FOCUSED;
3461 stateId = TUS_NORMAL;
3463 if (slider->tickPosition == QSlider::TicksLeft)
3464 partId = TKP_THUMBLEFT;
3465 else if (slider->tickPosition == QSlider::TicksRight)
3466 partId = TKP_THUMBRIGHT;
3468 partId = TKP_THUMBVERT;
3470 if (!(slider->state & State_Enabled))
3471 stateId = TUVS_DISABLED;
3472 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3473 stateId = TUVS_PRESSED;
3474 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3476 else if (flags & State_HasFocus)
3477 stateId = TUVS_FOCUSED;
3479 stateId = TUVS_NORMAL;
3481 theme.partId = partId;
3482 theme.stateId = stateId;
3483 d->drawBackground(theme);
3485 if (slider->state & State_HasFocus) {
3486 QStyleOptionFocusRect fropt;
3487 fropt.QStyleOption::operator=(*slider);
3488 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
3489 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3495#if QT_CONFIG(toolbutton)
3497 if (
const auto *toolbutton = qstyleoption_cast<
const QStyleOptionToolButton *>(option)) {
3498 QRect button, menuarea;
3499 button = proxy()->subControlRect(control, toolbutton, SC_ToolButton, widget);
3500 menuarea = proxy()->subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
3502 State bflags = toolbutton->state & ~State_Sunken;
3503 State mflags = bflags;
3504 bool autoRaise = flags & State_AutoRaise;
3506 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled))
3507 bflags &= ~State_Raised;
3510 if (toolbutton->state & State_Sunken) {
3511 if (toolbutton->activeSubControls & SC_ToolButton) {
3512 bflags |= State_Sunken;
3513 mflags |= State_MouseOver | State_Sunken;
3514 }
else if (toolbutton->activeSubControls & SC_ToolButtonMenu) {
3515 mflags |= State_Sunken;
3516 bflags |= State_MouseOver;
3520 QStyleOption tool = *toolbutton;
3521 if (toolbutton->subControls & SC_ToolButton) {
3522 if (flags & (State_Sunken | State_On | State_Raised) || !autoRaise) {
3523 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup && autoRaise) {
3524 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ToolBarTheme);
3525 theme.partId = TP_SPLITBUTTON;
3526 theme.rect = button;
3527 if (!(bflags & State_Enabled))
3528 stateId = TS_DISABLED;
3529 else if (bflags & State_Sunken)
3530 stateId = TS_PRESSED;
3531 else if (bflags & State_MouseOver || !(flags & State_AutoRaise))
3532 stateId = flags & State_On ? TS_HOTCHECKED : TS_HOT;
3533 else if (bflags & State_On)
3534 stateId = TS_CHECKED;
3536 stateId = TS_NORMAL;
3537 if (option->direction == Qt::RightToLeft)
3538 theme.mirrorHorizontally =
true;
3539 theme.stateId = stateId;
3540 d->drawBackground(theme);
3542 tool.rect = option->rect;
3543 tool.state = bflags;
3545 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
3547 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter, widget);
3552 if (toolbutton->state & State_HasFocus) {
3553 QStyleOptionFocusRect fr;
3554 fr.QStyleOption::operator=(*toolbutton);
3555 fr.rect.adjust(3, 3, -3, -3);
3556 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
3557 fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator,
3558 toolbutton, widget), 0);
3559 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
3561 QStyleOptionToolButton label = *toolbutton;
3562 label.state = bflags;
3565 label.state &= ~State_Sunken;
3566 label.rect = button.adjusted(fw, fw, -fw, -fw);
3567 proxy()->drawControl(CE_ToolButtonLabel, &label, painter, widget);
3569 if (toolbutton->subControls & SC_ToolButtonMenu) {
3570 tool.rect = menuarea;
3571 tool.state = mflags;
3573 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, painter, widget);
3575 tool.state = mflags;
3576 menuarea.adjust(-2, 0, 0, 0);
3578 if ((bflags & State_Sunken) != (mflags & State_Sunken)){
3580 painter->setClipRect(menuarea);
3581 tool.rect = option->rect;
3582 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter,
nullptr);
3587 painter->setPen(option->palette.dark().color());
3588 painter->drawLine(menuarea.left(), menuarea.top() + 3,
3589 menuarea.left(), menuarea.bottom() - 3);
3590 painter->setPen(option->palette.light().color());
3591 painter->drawLine(menuarea.left() - 1, menuarea.top() + 3,
3592 menuarea.left() - 1, menuarea.bottom() - 3);
3594 tool.rect = menuarea.adjusted(2, 3, -2, -1);
3595 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
3598 }
else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
3599 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
3600 QRect ir = toolbutton->rect;
3601 QStyleOptionToolButton newBtn = *toolbutton;
3602 newBtn.rect = QRect(ir.right() + 4 - mbi, ir.height() - mbi + 4, mbi - 5, mbi - 5);
3603 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
3610 if (
const auto *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(option)) {
3611 const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget);
3612 bool isActive = tb->titleBarState & QStyle::State_Active;
3613 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme);
3614 if (sub & SC_TitleBarLabel) {
3615 partId = (tb->titleBarState & Qt::WindowMinimized) ? WP_MINCAPTION : WP_CAPTION;
3616 theme.rect = option->rect;
3617 if (widget && !widget->isEnabled())
3618 stateId = CS_DISABLED;
3620 stateId = CS_ACTIVE;
3622 stateId = CS_INACTIVE;
3624 theme.partId = partId;
3625 theme.stateId = stateId;
3626 d->drawBackground(theme);
3628 QRect ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
3631 GetThemeEnumValue(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3633 COLORREF textShadowRef;
3634 GetThemeColor(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE,
TMT_TEXTSHADOWCOLOR, &textShadowRef);
3635 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3636 painter->setPen(textShadow);
3637 painter->drawText(
int(ir.x() + 3 * factor),
int(ir.y() + 2 * factor),
3638 int(ir.width() - 1 * factor), ir.height(),
3639 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3641 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3642 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3643 painter->setPen(textColor);
3644 painter->drawText(
int(ir.x() + 2 * factor),
int(ir.y() + 1 * factor),
3645 int(ir.width() - 2 * factor), ir.height(),
3646 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3648 if (sub & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3649 theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarSysMenu, widget);
3650 partId = WP_SYSBUTTON;
3651 if ((widget && !widget->isEnabled()) || !isActive)
3652 stateId = SBS_DISABLED;
3653 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_Sunken))
3654 stateId = SBS_PUSHED;
3655 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_MouseOver))
3658 stateId = SBS_NORMAL;
3659 if (!tb->icon.isNull()) {
3660 tb->icon.paint(painter, theme.rect);
3662 theme.partId = partId;
3663 theme.stateId = stateId;
3664 if (theme.size().isEmpty()) {
3665 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, tb, widget);
3666 const auto dpr = QStyleHelper::getDpr(widget);
3667 const auto icon = proxy()->standardIcon(SP_TitleBarMenuButton, tb, widget);
3668 const auto pm = icon.pixmap(QSize(extent, extent), dpr);
3669 drawItemPixmap(painter, theme.rect, Qt::AlignCenter, pm);
3671 d->drawBackground(theme);
3676 if (sub & SC_TitleBarMinButton && tb->titleBarFlags & Qt::WindowMinimizeButtonHint
3677 && !(tb->titleBarState & Qt::WindowMinimized)) {
3678 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMinButton, isActive, WP_MINBUTTON, &theme);
3679 d->drawBackground(theme);
3681 if (sub & SC_TitleBarMaxButton && tb->titleBarFlags & Qt::WindowMaximizeButtonHint
3682 && !(tb->titleBarState & Qt::WindowMaximized)) {
3683 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMaxButton, isActive, WP_MAXBUTTON, &theme);
3684 d->drawBackground(theme);
3686 if (sub & SC_TitleBarContextHelpButton
3687 && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
3688 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarContextHelpButton, isActive, WP_HELPBUTTON, &theme);
3689 d->drawBackground(theme);
3691 bool drawNormalButton = (sub & SC_TitleBarNormalButton)
3692 && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3693 && (tb->titleBarState & Qt::WindowMinimized))
3694 || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3695 && (tb->titleBarState & Qt::WindowMaximized)));
3696 if (drawNormalButton) {
3697 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarNormalButton, isActive, WP_RESTOREBUTTON, &theme);
3698 d->drawBackground(theme);
3700 if (sub & SC_TitleBarShadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3701 && !(tb->titleBarState & Qt::WindowMinimized)) {
3702 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarShadeButton, isActive, WP_MINBUTTON, &theme);
3703 d->drawBackground(theme);
3705 if (sub & SC_TitleBarUnshadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3706 && tb->titleBarState & Qt::WindowMinimized) {
3707 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarUnshadeButton, isActive, WP_RESTOREBUTTON, &theme);
3708 d->drawBackground(theme);
3710 if (sub & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3711 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarCloseButton, isActive, WP_CLOSEBUTTON, &theme);
3712 d->drawBackground(theme);
3717#if QT_CONFIG(mdiarea)
3718 case CC_MdiControls: {
3719 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme, WP_MDICLOSEBUTTON, CBS_NORMAL);
3720 if (Q_UNLIKELY(!theme.isValid()))
3723 if (option->subControls.testFlag(SC_MdiCloseButton)) {
3724 populateMdiButtonTheme(proxy(), widget, option, SC_MdiCloseButton, WP_MDICLOSEBUTTON, &theme);
3725 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3727 if (option->subControls.testFlag(SC_MdiNormalButton)) {
3728 populateMdiButtonTheme(proxy(), widget, option, SC_MdiNormalButton, WP_MDIRESTOREBUTTON, &theme);
3729 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3731 if (option->subControls.testFlag(QStyle::SC_MdiMinButton)) {
3732 populateMdiButtonTheme(proxy(), widget, option, SC_MdiMinButton, WP_MDIMINBUTTON, &theme);
3733 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3741 if (
const auto *dial = qstyleoption_cast<
const QStyleOptionSlider *>(option))
3742 QStyleHelper::drawDial(dial, painter);
3747 if (
const QStyleOptionComboBox *cmb = qstyleoption_cast<
const QStyleOptionComboBox *>(option)) {
3748 if (cmb->editable) {
3749 if (sub & SC_ComboBoxEditField) {
3750 partId = EP_EDITBORDER_NOSCROLL;
3751 if (!(flags & State_Enabled))
3752 stateId = ETS_DISABLED;
3753 else if (flags & State_MouseOver)
3755 else if (flags & State_HasFocus)
3756 stateId = ETS_FOCUSED;
3758 stateId = ETS_NORMAL;
3760 QWindowsThemeData theme(widget, painter,
3761 QWindowsVistaStylePrivate::EditTheme,
3762 partId, stateId, option->rect);
3764 d->drawBackground(theme);
3766 if (sub & SC_ComboBoxArrow) {
3767 QRect subRect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3768 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3769 theme.rect = subRect;
3770 partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3772 if (!(cmb->state & State_Enabled))
3773 stateId = CBXS_DISABLED;
3774 else if (cmb->state & State_Sunken || cmb->state & State_On)
3775 stateId = CBXS_PRESSED;
3776 else if (cmb->state & State_MouseOver && option->activeSubControls & SC_ComboBoxArrow)
3779 stateId = CBXS_NORMAL;
3781 theme.partId = partId;
3782 theme.stateId = stateId;
3783 d->drawBackground(theme);
3787 if (sub & SC_ComboBoxFrame) {
3788 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3789 theme.rect = option->rect;
3790 theme.partId = CP_READONLY;
3791 if (!(cmb->state & State_Enabled))
3792 theme.stateId = CBXS_DISABLED;
3793 else if (cmb->state & State_Sunken || cmb->state & State_On)
3794 theme.stateId = CBXS_PRESSED;
3795 else if (cmb->state & State_MouseOver)
3796 theme.stateId = CBXS_HOT;
3798 theme.stateId = CBXS_NORMAL;
3799 d->drawBackground(theme);
3801 if (sub & SC_ComboBoxArrow) {
3802 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3803 theme.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3804 theme.partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3805 if (!(cmb->state & State_Enabled))
3806 theme.stateId = CBXS_DISABLED;
3808 theme.stateId = CBXS_NORMAL;
3809 d->drawBackground(theme);
3811 if ((sub & SC_ComboBoxEditField) && (flags & State_HasFocus)) {
3812 QStyleOptionFocusRect fropt;
3813 fropt.QStyleOption::operator=(*cmb);
3814 fropt.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget);
3815 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3822 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3823 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ScrollBarTheme);
3824 bool maxedOut = (scrollbar->maximum == scrollbar->minimum);
3826 flags &= ~State_Enabled;
3828 bool isHorz = flags & State_Horizontal;
3829 bool isRTL = option->direction == Qt::RightToLeft;
3830 if (sub & SC_ScrollBarAddLine) {
3831 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddLine, widget);
3832 partId = SBP_ARROWBTN;
3833 if (!(flags & State_Enabled))
3834 stateId = (isHorz ? (isRTL ? ABS_LEFTDISABLED : ABS_RIGHTDISABLED) : ABS_DOWNDISABLED);
3835 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_Sunken))
3836 stateId = (isHorz ? (isRTL ? ABS_LEFTPRESSED : ABS_RIGHTPRESSED) : ABS_DOWNPRESSED);
3837 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_MouseOver))
3838 stateId = (isHorz ? (isRTL ? ABS_LEFTHOT : ABS_RIGHTHOT) : ABS_DOWNHOT);
3839 else if (scrollbar->state & State_MouseOver)
3840 stateId = (isHorz ? (isRTL ? ABS_LEFTHOVER : ABS_RIGHTHOVER) : ABS_DOWNHOVER);
3842 stateId = (isHorz ? (isRTL ? ABS_LEFTNORMAL : ABS_RIGHTNORMAL) : ABS_DOWNNORMAL);
3843 theme.partId = partId;
3844 theme.stateId = stateId;
3845 d->drawBackground(theme);
3847 if (sub & SC_ScrollBarSubLine) {
3848 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubLine, widget);
3849 partId = SBP_ARROWBTN;
3850 if (!(flags & State_Enabled))
3851 stateId = (isHorz ? (isRTL ? ABS_RIGHTDISABLED : ABS_LEFTDISABLED) : ABS_UPDISABLED);
3852 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_Sunken))
3853 stateId = (isHorz ? (isRTL ? ABS_RIGHTPRESSED : ABS_LEFTPRESSED) : ABS_UPPRESSED);
3854 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_MouseOver))
3855 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOT : ABS_LEFTHOT) : ABS_UPHOT);
3856 else if (scrollbar->state & State_MouseOver)
3857 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOVER : ABS_LEFTHOVER) : ABS_UPHOVER);
3859 stateId = (isHorz ? (isRTL ? ABS_RIGHTNORMAL : ABS_LEFTNORMAL) : ABS_UPNORMAL);
3860 theme.partId = partId;
3861 theme.stateId = stateId;
3862 d->drawBackground(theme);
3865 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3866 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget));
3867 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget));
3868 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3869 stateId = SCRBS_DISABLED;
3870 theme.partId = partId;
3871 theme.stateId = stateId;
3872 d->drawBackground(theme);
3874 if (sub & SC_ScrollBarSubPage) {
3875 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget);
3876 partId = flags & State_Horizontal ? SBP_UPPERTRACKHORZ : SBP_UPPERTRACKVERT;
3877 if (!(flags & State_Enabled))
3878 stateId = SCRBS_DISABLED;
3879 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_Sunken))
3880 stateId = SCRBS_PRESSED;
3881 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_MouseOver))
3882 stateId = SCRBS_HOT;
3884 stateId = SCRBS_NORMAL;
3885 theme.partId = partId;
3886 theme.stateId = stateId;
3887 d->drawBackground(theme);
3889 if (sub & SC_ScrollBarAddPage) {
3890 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget);
3891 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3892 if (!(flags & State_Enabled))
3893 stateId = SCRBS_DISABLED;
3894 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_Sunken))
3895 stateId = SCRBS_PRESSED;
3896 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_MouseOver))
3897 stateId = SCRBS_HOT;
3899 stateId = SCRBS_NORMAL;
3900 theme.partId = partId;
3901 theme.stateId = stateId;
3902 d->drawBackground(theme);
3904 if (sub & SC_ScrollBarSlider) {
3905 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3906 if (!(flags & State_Enabled))
3907 stateId = SCRBS_DISABLED;
3908 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_Sunken))
3909 stateId = SCRBS_PRESSED;
3910 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_MouseOver))
3911 stateId = SCRBS_HOT;
3912 else if (option->state & State_MouseOver)
3913 stateId = SCRBS_HOVER;
3915 stateId = SCRBS_NORMAL;
3918 theme.partId = flags & State_Horizontal ? SBP_THUMBBTNHORZ : SBP_THUMBBTNVERT;
3919 theme.stateId = stateId;
3920 d->drawBackground(theme);
3926#if QT_CONFIG(spinbox)
3928 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(option)) {
3929 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::SpinTheme);
3930 if (sb->frame && (sub & SC_SpinBoxFrame)) {
3931 partId = EP_EDITBORDER_NOSCROLL;
3932 if (!(flags & State_Enabled))
3933 stateId = ETS_DISABLED;
3934 else if (flags & State_MouseOver)
3936 else if (flags & State_HasFocus)
3937 stateId = ETS_SELECTED;
3939 stateId = ETS_NORMAL;
3941 QWindowsThemeData ftheme(widget, painter,
3942 QWindowsVistaStylePrivate::EditTheme,
3943 partId, stateId, option->rect);
3948 ftheme.noContent = (widget !=
nullptr);
3949 d->drawBackground(ftheme);
3951 if (sub & SC_SpinBoxUp) {
3952 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
3954 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled) || !(flags & State_Enabled))
3955 stateId = UPS_DISABLED;
3956 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken))
3957 stateId = UPS_PRESSED;
3958 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_MouseOver))
3961 stateId = UPS_NORMAL;
3962 theme.partId = partId;
3963 theme.stateId = stateId;
3964 d->drawBackground(theme);
3966 if (sub & SC_SpinBoxDown) {
3967 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
3969 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled) || !(flags & State_Enabled))
3970 stateId = DNS_DISABLED;
3971 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken))
3972 stateId = DNS_PRESSED;
3973 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_MouseOver))
3976 stateId = DNS_NORMAL;
3977 theme.partId = partId;
3978 theme.stateId = stateId;
3979 d->drawBackground(theme);
3986 QWindowsStyle::drawComplexControl(control, option, painter, widget);