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 int state = option->state;
1347 QRect rect = option->rect;
1349 if ((state & State_Enabled) && d->transitionsEnabled() && canAnimate(option)) {
1350 if (supportsStateTransition(element, option, widget)) {
1353 QObject *styleObject = option->styleObject;
1354 styleObject->setProperty(
"_q_no_animation",
true);
1355 int oldState = styleObject->property(
"_q_stylestate").toInt();
1356 QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
1357 QRect newRect = rect;
1358 styleObject->setProperty(
"_q_stylestate",
int(option->state));
1359 styleObject->setProperty(
"_q_stylerect", option->rect);
1361 bool doTransition = oldState &&
1362 ((state & State_Sunken) != (oldState & State_Sunken) ||
1363 (state & State_On) != (oldState & State_On) ||
1364 (state & State_MouseOver) != (oldState & State_MouseOver));
1366 if (oldRect != newRect ||
1367 (state & State_Enabled) != (oldState & State_Enabled) ||
1368 (state & State_Active) != (oldState & State_Active))
1369 d->stopAnimation(styleObject);
1371 if (state & State_ReadOnly && element == PE_FrameLineEdit)
1372 doTransition =
false;
1375 QStyleOption *styleOption = clonedAnimationStyleOption(option);
1376 styleOption->state = QStyle::State(oldState);
1378 QWindowsVistaAnimation *animate = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
1383 QImage startImage = createAnimationBuffer(option, widget);
1384 QPainter startPainter(&startImage);
1386 QImage endImage = createAnimationBuffer(option, widget);
1393 proxy()->drawPrimitive(element, styleOption, &startPainter, widget);
1395 animate->paint(&startPainter, styleOption);
1397 transition->setStartImage(startImage);
1401 styleOption->styleObject =
nullptr;
1402 styleOption->state = option->state;
1403 proxy()->drawPrimitive(element, styleOption, &endPainter, widget);
1405 transition->setEndImage(endImage);
1414 if (element == PE_FrameLineEdit) {
1415 theme = OpenThemeData(
nullptr, L"Edit");
1416 partId = EP_EDITBORDER_NOSCROLL;
1418 if (oldState & State_HasFocus)
1419 fromState = ETS_SELECTED;
1420 else if (oldState & State_MouseOver)
1421 fromState = ETS_HOT;
1423 fromState = ETS_NORMAL;
1425 if (state & State_HasFocus)
1426 toState = ETS_SELECTED;
1427 else if (state & State_MouseOver)
1430 toState = ETS_NORMAL;
1433 theme = OpenThemeData(
nullptr, L"Button");
1434 if (element == PE_IndicatorRadioButton)
1435 partId = BP_RADIOBUTTON;
1436 else if (element == PE_IndicatorCheckBox)
1437 partId = BP_CHECKBOX;
1439 partId = BP_PUSHBUTTON;
1441 fromState = buttonStateId(oldState, partId);
1442 toState = buttonStateId(option->state, partId);
1447 && SUCCEEDED(GetThemeTransitionDuration(theme, partId, fromState, toState,
1448 TMT_TRANSITIONDURATIONS, &duration))) {
1449 transition->setDuration(
int(duration));
1451 transition->setStartTime(d->animationTime());
1453 deleteClonedAnimationStyleOption(styleOption);
1454 d->startAnimation(transition);
1456 styleObject->setProperty(
"_q_no_animation",
false);
1460 int themeNumber = -1;
1463 bool hMirrored =
false;
1464 bool vMirrored =
false;
1465 bool noBorder =
false;
1466 bool noContent =
false;
1470 case PE_PanelButtonCommand:
1471 if (
const auto *btn = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
1473 if (!(state & State_Sunken) && (state & State_On))
1474 fill = QBrush(option->palette.light().color(), Qt::Dense4Pattern);
1476 fill = option->palette.brush(QPalette::Button);
1477 if (btn->features & QStyleOptionButton::DefaultButton && state & State_Sunken) {
1478 painter->setPen(option->palette.dark().color());
1479 painter->setBrush(fill);
1480 painter->drawRect(rect.adjusted(0, 0, -1, -1));
1481 }
else if (state & (State_Raised | State_On | State_Sunken)) {
1482 qDrawWinButton(painter, rect, option->palette, state & (State_Sunken | State_On),
1485 painter->fillRect(rect, fill);
1490 case PE_PanelButtonTool:
1491#if QT_CONFIG(dockwidget)
1492 if (widget && widget->inherits(
"QDockWidgetTitleButton")) {
1493 if (
const QWidget *dw = widget->parentWidget())
1494 if (dw->isWindow()) {
1499 themeNumber = QWindowsVistaStylePrivate::ToolBarTheme;
1501 if (!(option->state & State_Enabled))
1502 stateId = TS_DISABLED;
1503 else if (option->state & State_Sunken)
1504 stateId = TS_PRESSED;
1505 else if (option->state & State_MouseOver)
1506 stateId = option->state & State_On ? TS_HOTCHECKED : TS_HOT;
1507 else if (option->state & State_On)
1508 stateId = TS_CHECKED;
1509 else if (!(option->state & State_AutoRaise))
1512 stateId = TS_NORMAL;
1516 case PE_IndicatorHeaderArrow:
1517 if (
const auto *header = qstyleoption_cast<
const QStyleOptionHeader *>(option)) {
1518 int stateId = HSAS_SORTEDDOWN;
1519 if (header->sortIndicator & QStyleOptionHeader::SortDown)
1520 stateId = HSAS_SORTEDUP;
1521 QWindowsThemeData theme(widget, painter,
1522 QWindowsVistaStylePrivate::HeaderTheme,
1523 HP_HEADERSORTARROW, stateId, option->rect);
1524 d->drawBackground(theme);
1529 case PE_IndicatorCheckBox:
1531 qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1532 animate->paint(painter, option);
1535 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1536 partId = BP_CHECKBOX;
1538 if (!(option->state & State_Enabled))
1539 stateId = CBS_UNCHECKEDDISABLED;
1540 else if (option->state & State_Sunken)
1541 stateId = CBS_UNCHECKEDPRESSED;
1542 else if (option->state & State_MouseOver)
1543 stateId = CBS_UNCHECKEDHOT;
1545 stateId = CBS_UNCHECKEDNORMAL;
1547 if (option->state & State_On)
1548 stateId += CBS_CHECKEDNORMAL-1;
1549 else if (option->state & State_NoChange)
1550 stateId += CBS_MIXEDNORMAL-1;
1554 case PE_IndicatorItemViewItemCheck: {
1555 QStyleOptionButton button;
1556 button.QStyleOption::operator=(*option);
1557 button.state &= ~State_MouseOver;
1558 proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
1562 case PE_IndicatorBranch: {
1563 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::VistaTreeViewTheme);
1564 static int decoration_size = 0;
1565 if (!decoration_size && theme.isValid()) {
1566 QWindowsThemeData themeSize = theme;
1567 themeSize.partId = TVP_HOTGLYPH;
1568 themeSize.stateId = GLPS_OPENED;
1569 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
1570 decoration_size = qRound(qMax(size.width(), size.height()));
1572 int mid_h = option->rect.x() + option->rect.width() / 2;
1573 int mid_v = option->rect.y() + option->rect.height() / 2;
1574 if (option->state & State_Children) {
1575 int delta = decoration_size / 2;
1576 theme.rect = QRect(mid_h - delta, mid_v - delta, decoration_size, decoration_size);
1577 theme.partId = option->state & State_MouseOver ? TVP_HOTGLYPH : TVP_GLYPH;
1578 theme.stateId = option->state & QStyle::State_Open ? GLPS_OPENED : GLPS_CLOSED;
1579 if (option->direction == Qt::RightToLeft)
1580 theme.mirrorHorizontally =
true;
1581 d->drawBackground(theme);
1586 case PE_PanelButtonBevel:
1587 if (QWindowsVistaAnimation *animate =
1588 qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1589 animate->paint(painter, option);
1593 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1594 partId = BP_PUSHBUTTON;
1595 if (!(option->state & State_Enabled))
1596 stateId = PBS_DISABLED;
1597 else if ((option->state & State_Sunken) || (option->state & State_On))
1598 stateId = PBS_PRESSED;
1599 else if (option->state & State_MouseOver)
1602 stateId = PBS_NORMAL;
1605 case PE_IndicatorRadioButton:
1606 if (QWindowsVistaAnimation *animate =
1607 qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1608 animate->paint(painter, option);
1611 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1612 partId = BP_RADIOBUTTON;
1614 if (!(option->state & State_Enabled))
1615 stateId = RBS_UNCHECKEDDISABLED;
1616 else if (option->state & State_Sunken)
1617 stateId = RBS_UNCHECKEDPRESSED;
1618 else if (option->state & State_MouseOver)
1619 stateId = RBS_UNCHECKEDHOT;
1621 stateId = RBS_UNCHECKEDNORMAL;
1623 if (option->state & State_On)
1624 stateId += RBS_CHECKEDNORMAL-1;
1629 if (widget && widget->inherits(
"QComboBoxPrivateContainer")){
1630 QStyleOption copy = *option;
1631 copy.state |= State_Raised;
1632 proxy()->drawPrimitive(PE_PanelMenu, ©, painter, widget);
1635#if QT_CONFIG(accessibility)
1636 if (QStyleHelper::isInstanceOf(option->styleObject, QAccessible::EditableText)
1637 || QStyleHelper::isInstanceOf(option->styleObject, QAccessible::StaticText) ||
1641 (widget && widget->inherits(
"QTextEdit"))) {
1643 int stateId = ETS_NORMAL;
1644 if (!(state & State_Enabled))
1645 stateId = ETS_DISABLED;
1646 else if (state & State_ReadOnly)
1647 stateId = ETS_READONLY;
1648 else if (state & State_HasFocus)
1649 stateId = ETS_SELECTED;
1650 QWindowsThemeData theme(widget, painter,
1651 QWindowsVistaStylePrivate::EditTheme,
1652 EP_EDITBORDER_HVSCROLL, stateId, option->rect);
1655 GetThemeInt(theme.handle(), theme.partId, theme.stateId, TMT_BORDERSIZE, &borderSize);
1656 QRegion clipRegion = option->rect;
1657 QRegion content = option->rect.adjusted(borderSize, borderSize, -borderSize, -borderSize);
1658 clipRegion ^= content;
1659 painter->setClipRegion(clipRegion);
1660 d->drawBackground(theme);
1664 if (option->state & State_Raised)
1667 themeNumber = QWindowsVistaStylePrivate::ListViewTheme;
1668 partId = LVP_LISTGROUP;
1669 QWindowsThemeData theme(widget,
nullptr, themeNumber, partId);
1671 if (!(option->state & State_Enabled))
1672 stateId = ETS_DISABLED;
1674 stateId = ETS_NORMAL;
1678 if (GetThemeEnumValue(theme.handle(), partId, stateId, TMT_BGTYPE, &fillType) == S_OK) {
1679 if (fillType == BT_BORDERFILL) {
1681 GetThemeColor(theme.handle(), partId, stateId, TMT_BORDERCOLOR, &bcRef);
1682 QColor bordercolor(qRgb(GetRValue(bcRef), GetGValue(bcRef), GetBValue(bcRef)));
1683 QPen oldPen = painter->pen();
1686 painter->setPen(QPen(option->palette.base().color(), 0));
1687 const qreal dpi = QStyleHelper::dpi(option);
1688 const auto topLevelAdjustment = QStyleHelper::dpiScaled(0.5, dpi);
1689 const auto bottomRightAdjustment = QStyleHelper::dpiScaled(-1, dpi);
1690 painter->drawRect(QRectF(option->rect).adjusted(topLevelAdjustment, topLevelAdjustment,
1691 bottomRightAdjustment, bottomRightAdjustment));
1693 painter->setPen(QPen(bordercolor, 0));
1694 painter->drawRect(QRectF(option->rect).adjusted(0, 0, -topLevelAdjustment, -topLevelAdjustment));
1695 painter->setPen(oldPen);
1698 if (fillType == BT_BORDERFILL || fillType == BT_NONE)
1704 case PE_FrameMenu: {
1705 int stateId = option->state & State_Active ? MB_ACTIVE : MB_INACTIVE;
1706 QWindowsThemeData theme(widget, painter,
1707 QWindowsVistaStylePrivate::MenuTheme,
1708 MENU_POPUPBORDERS, stateId, option->rect);
1709 d->drawBackground(theme);
1714 if (widget && widget->inherits(
"QComboBoxPrivateContainer")){
1716 QWindowsThemeData popupbackgroundTheme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
1717 MENU_POPUPBACKGROUND, stateId, option->rect);
1718 d->drawBackground(popupbackgroundTheme);
1723 case PE_PanelMenuBar:
1726#if QT_CONFIG(dockwidget)
1727 case PE_IndicatorDockWidgetResizeHandle:
1730 case PE_FrameDockWidget:
1731 if (
const auto *frm = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1732 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
1733 if (option->state & State_Active)
1734 stateId = FS_ACTIVE;
1736 stateId = FS_INACTIVE;
1738 int fwidth = proxy()->pixelMetric(PM_DockWidgetFrameWidth, frm, widget);
1740 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
1742 if (!theme.isValid())
1745 theme.rect = QRect(frm->rect.x(), frm->rect.y(), frm->rect.x()+fwidth, frm->rect.height()-fwidth);
1746 theme.partId = WP_SMALLFRAMELEFT;
1747 d->drawBackground(theme);
1748 theme.rect = QRect(frm->rect.width()-fwidth, frm->rect.y(), fwidth, frm->rect.height()-fwidth);
1749 theme.partId = WP_SMALLFRAMERIGHT;
1750 d->drawBackground(theme);
1751 theme.rect = QRect(frm->rect.x(), frm->rect.bottom()-fwidth+1, frm->rect.width(), fwidth);
1752 theme.partId = WP_SMALLFRAMEBOTTOM;
1753 d->drawBackground(theme);
1759 case PE_FrameTabWidget:
1760#if QT_CONFIG(tabwidget)
1761 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(option)) {
1762 themeNumber = QWindowsVistaStylePrivate::TabTheme;
1766 bool useGradient =
true;
1767 const int maxlength = 256;
1768 wchar_t themeFileName[maxlength];
1769 wchar_t themeColor[maxlength];
1771 if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength,
nullptr, 0) == S_OK) {
1772 wchar_t *offset =
nullptr;
1773 if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char(
'\\')).unicode())) !=
nullptr) {
1775 if (!lstrcmp(offset, L"Luna.msstyles") && !lstrcmp(offset, L"Metallic"))
1776 useGradient =
false;
1782 QStyleOptionTabWidgetFrame frameOpt = *tab;
1783 frameOpt.rect = widget->rect();
1784 QRect contentsRect = subElementRect(SE_TabWidgetTabContents, &frameOpt, widget);
1785 QRegion reg = option->rect;
1786 reg -= contentsRect;
1787 painter->setClipRegion(reg);
1788 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
1789 theme.mirrorHorizontally = hMirrored;
1790 theme.mirrorVertically = vMirrored;
1791 d->drawBackground(theme);
1792 painter->setClipRect(contentsRect);
1796 switch (tab->shape) {
1797 case QTabBar::RoundedNorth:
1798 case QTabBar::TriangularNorth:
1800 case QTabBar::RoundedSouth:
1801 case QTabBar::TriangularSouth:
1804 case QTabBar::RoundedEast:
1805 case QTabBar::TriangularEast:
1808 case QTabBar::RoundedWest:
1809 case QTabBar::TriangularWest:
1819 case PE_FrameStatusBarItem:
1820 themeNumber = QWindowsVistaStylePrivate::StatusTheme;
1824 case PE_FrameWindow:
1825 if (
const auto *frm = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1826 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
1827 if (option->state & State_Active)
1828 stateId = FS_ACTIVE;
1830 stateId = FS_INACTIVE;
1832 int fwidth =
int((frm->lineWidth + frm->midLineWidth) / QWindowsStylePrivate::nativeMetricScaleFactor(widget));
1834 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
1835 if (!theme.isValid())
1839 theme.rect = QRect(option->rect.x(), option->rect.y()+fwidth, option->rect.x()+fwidth, option->rect.height()-fwidth);
1840 theme.partId = WP_FRAMELEFT;
1841 if (!d->drawBackground(theme)) {
1842 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1845 theme.rect = QRect(option->rect.width()-fwidth, option->rect.y()+fwidth, fwidth, option->rect.height()-fwidth);
1846 theme.partId = WP_FRAMERIGHT;
1847 if (!d->drawBackground(theme)) {
1848 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1851 theme.rect = QRect(option->rect.x(), option->rect.height()-fwidth, option->rect.width(), fwidth);
1852 theme.partId = WP_FRAMEBOTTOM;
1853 if (!d->drawBackground(theme)) {
1854 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1857 theme.rect = QRect(option->rect.x(), option->rect.y(), option->rect.width(), option->rect.y()+fwidth);
1858 theme.partId = WP_CAPTION;
1859 if (!d->drawBackground(theme))
1860 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1865 case PE_PanelLineEdit:
1866 if (
const auto *panel = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1867 bool isEnabled = state & State_Enabled;
1868 if (QWindowsVistaStylePrivate::isLineEditBaseColorSet(option, widget)) {
1869 painter->fillRect(panel->rect, panel->palette.brush(QPalette::Base));
1871 int partId = EP_BACKGROUND;
1872 int stateId = EBS_NORMAL;
1874 stateId = EBS_DISABLED;
1875 else if (option->state & State_ReadOnly)
1876 stateId = EBS_READONLY;
1877 else if (option->state & State_MouseOver)
1880 QWindowsThemeData theme(
nullptr, painter, QWindowsVistaStylePrivate::EditTheme,
1881 partId, stateId, rect);
1882 if (!theme.isValid()) {
1883 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1887 GetThemeEnumValue(theme.handle(), partId, stateId, TMT_BGTYPE, &bgType);
1888 if (bgType == BT_IMAGEFILE) {
1889 d->drawBackground(theme);
1891 QBrush fillColor = option->palette.brush(QPalette::Base);
1893 PROPERTYORIGIN origin = PO_NOTFOUND;
1894 GetThemePropertyOrigin(theme.handle(), theme.partId, theme.stateId, TMT_FILLCOLOR, &origin);
1896 if ((origin == PO_PART || origin == PO_STATE)) {
1898 GetThemeColor(theme.handle(), partId, stateId, TMT_FILLCOLOR, &bgRef);
1899 fillColor = QBrush(qRgb(GetRValue(bgRef), GetGValue(bgRef), GetBValue(bgRef)));
1902 painter->fillRect(option->rect, fillColor);
1905 if (panel->lineWidth > 0)
1906 proxy()->drawPrimitive(PE_FrameLineEdit, panel, painter, widget);
1910 case PE_IndicatorButtonDropDown:
1911 themeNumber = QWindowsVistaStylePrivate::ToolBarTheme;
1912 partId = TP_SPLITBUTTONDROPDOWN;
1913 if (!(option->state & State_Enabled))
1914 stateId = TS_DISABLED;
1915 else if (option->state & State_Sunken)
1916 stateId = TS_PRESSED;
1917 else if (option->state & State_MouseOver)
1918 stateId = option->state & State_On ? TS_HOTCHECKED : TS_HOT;
1919 else if (option->state & State_On)
1920 stateId = TS_CHECKED;
1921 else if (!(option->state & State_AutoRaise))
1924 stateId = TS_NORMAL;
1925 if (option->direction == Qt::RightToLeft)
1929 case PE_FrameLineEdit:
1930 if (QWindowsVistaAnimation *animate = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1931 animate->paint(painter, option);
1933 if (QWindowsVistaStylePrivate::isItemViewDelegateLineEdit(widget)) {
1935 QPen oldPen = painter->pen();
1937 painter->setPen(option->palette.base().color());
1938 painter->drawRect(option->rect.adjusted(1, 1, -2, -2));
1940 painter->setPen(option->palette.shadow().color());
1941 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
1942 painter->setPen(oldPen);
1945 int stateId = ETS_NORMAL;
1946 if (!(state & State_Enabled))
1947 stateId = ETS_DISABLED;
1948 else if (state & State_ReadOnly)
1949 stateId = ETS_READONLY;
1950 else if (state & State_HasFocus)
1951 stateId = ETS_SELECTED;
1952 else if (state & State_MouseOver)
1954 QWindowsThemeData theme(widget, painter,
1955 QWindowsVistaStylePrivate::EditTheme,
1956 EP_EDITBORDER_NOSCROLL, stateId, option->rect);
1957 theme.noContent =
true;
1959 QRegion clipRegion = option->rect;
1960 clipRegion -= option->rect.adjusted(2, 2, -2, -2);
1961 painter->setClipRegion(clipRegion);
1962 d->drawBackground(theme);
1967 case PE_FrameGroupBox:
1968 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1969 partId = BP_GROUPBOX;
1970 if (!(option->state & State_Enabled))
1971 stateId = GBS_DISABLED;
1973 stateId = GBS_NORMAL;
1974 if (
const auto *frame = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1975 if (frame->features & QStyleOptionFrame::Flat) {
1977 QRect fr = frame->rect;
1978 QPoint p1(fr.x(), fr.y() + 1);
1979 QPoint p2(fr.x() + fr.width(), p1.y() + 1);
1980 rect = QRect(p1, p2);
1986 case PE_IndicatorToolBarHandle: {
1987 QWindowsThemeData theme;
1989 if (option->state & State_Horizontal) {
1990 theme = QWindowsThemeData(widget, painter,
1991 QWindowsVistaStylePrivate::RebarTheme,
1992 RP_GRIPPER, ETS_NORMAL, option->rect.adjusted(0, 1, -2, -2));
1993 rect = option->rect.adjusted(0, 1, 0, -2);
1996 theme = QWindowsThemeData(widget, painter, QWindowsVistaStylePrivate::RebarTheme,
1997 RP_GRIPPERVERT, ETS_NORMAL, option->rect.adjusted(0, 1, -2, -2));
1998 rect = option->rect.adjusted(1, 0, -1, 0);
2002 d->drawBackground(theme);
2006 case PE_IndicatorToolBarSeparator: {
2007 QPen pen = painter->pen();
2009 painter->setPen(option->palette.window().color().darker(114));
2010 if (option->state & State_Horizontal) {
2011 int x1 = option->rect.center().x();
2012 painter->drawLine(QPoint(x1, option->rect.top() + margin), QPoint(x1, option->rect.bottom() - margin));
2014 int y1 = option->rect.center().y();
2015 painter->drawLine(QPoint(option->rect.left() + margin, y1), QPoint(option->rect.right() - margin, y1));
2017 painter->setPen(pen);
2021 case PE_PanelTipLabel: {
2022 QWindowsThemeData theme(widget, painter,
2023 QWindowsVistaStylePrivate::ToolTipTheme,
2024 TTP_STANDARD, TTSS_NORMAL, option->rect);
2025 d->drawBackground(theme);
2029 case PE_FrameTabBarBase:
2030#if QT_CONFIG(tabbar)
2031 if (
const auto *tbb = qstyleoption_cast<
const QStyleOptionTabBarBase *>(option)) {
2033 switch (tbb->shape) {
2034 case QTabBar::RoundedNorth:
2035 painter->setPen(QPen(tbb->palette.dark(), 0));
2036 painter->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
2038 case QTabBar::RoundedWest:
2039 painter->setPen(QPen(tbb->palette.dark(), 0));
2040 painter->drawLine(tbb->rect.left(), tbb->rect.top(), tbb->rect.left(), tbb->rect.bottom());
2042 case QTabBar::RoundedSouth:
2043 painter->setPen(QPen(tbb->palette.dark(), 0));
2044 painter->drawLine(tbb->rect.left(), tbb->rect.top(),
2045 tbb->rect.right(), tbb->rect.top());
2047 case QTabBar::RoundedEast:
2048 painter->setPen(QPen(tbb->palette.dark(), 0));
2049 painter->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft());
2051 case QTabBar::TriangularNorth:
2052 case QTabBar::TriangularEast:
2053 case QTabBar::TriangularWest:
2054 case QTabBar::TriangularSouth:
2056 QWindowsStyle::drawPrimitive(element, option, painter, widget);
2065#if QT_CONFIG(dialogbuttonbox)
2066 const QDialogButtonBox *buttonBox =
nullptr;
2067 if (qobject_cast<
const QMessageBox *> (widget))
2068 buttonBox = widget->findChild<
const QDialogButtonBox *>(QLatin1String(
"qt_msgbox_buttonbox"));
2071 QWindowsThemeData theme(widget, painter,
2072 QWindowsVistaStylePrivate::TaskDialogTheme,
2073 TDLG_PRIMARYPANEL, 0, option->rect);
2074 QRect toprect = option->rect;
2075 toprect.setBottom(buttonBox->geometry().top());
2076 theme.rect = toprect;
2077 d->drawBackground(theme);
2080 QRect buttonRect = option->rect;
2081 buttonRect.setTop(buttonBox->geometry().top());
2082 theme.rect = buttonRect;
2083 theme.partId = TDLG_SECONDARYPANEL;
2084 d->drawBackground(theme);
2090 case PE_PanelItemViewItem: {
2091 const QStyleOptionViewItem *vopt;
2092 bool newStyle =
true;
2093 QAbstractItemView::SelectionBehavior selectionBehavior = QAbstractItemView::SelectRows;
2094 QAbstractItemView::SelectionMode selectionMode = QAbstractItemView::NoSelection;
2095 if (
const QAbstractItemView *view = qobject_cast<
const QAbstractItemView *>(widget)) {
2096 newStyle = !qobject_cast<
const QTableView*>(view);
2097 selectionBehavior = view->selectionBehavior();
2098 selectionMode = view->selectionMode();
2099#if QT_CONFIG(accessibility)
2100 }
else if (!widget) {
2101 newStyle = !QStyleHelper::hasAncestor(option->styleObject, QAccessible::MenuItem) ;
2105 if (newStyle && (vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(option))) {
2106 bool selected = vopt->state & QStyle::State_Selected;
2107 const bool hover = selectionMode != QAbstractItemView::NoSelection && (vopt->state & QStyle::State_MouseOver);
2108 bool active = vopt->state & QStyle::State_Active;
2110 if (vopt->features & QStyleOptionViewItem::Alternate)
2111 painter->fillRect(vopt->rect, vopt->palette.alternateBase());
2113 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled
2114 ? QPalette::Normal : QPalette::Disabled;
2115 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
2116 cg = QPalette::Inactive;
2118 QRect itemRect = subElementRect(QStyle::SE_ItemViewItemFocusRect, option, widget).adjusted(-1, 0, 1, 0);
2119 itemRect.setTop(vopt->rect.top());
2120 itemRect.setBottom(vopt->rect.bottom());
2122 QSize sectionSize = itemRect.size();
2123 if (vopt->showDecorationSelected)
2124 sectionSize = vopt->rect.size();
2126 if (selectionBehavior == QAbstractItemView::SelectRows)
2127 sectionSize.setWidth(vopt->rect.width());
2130 if (vopt->backgroundBrush.style() != Qt::NoBrush) {
2131 QPainterStateGuard psg(painter);
2132 painter->setBrushOrigin(vopt->rect.topLeft());
2133 painter->fillRect(vopt->rect, vopt->backgroundBrush);
2136 if (hover || selected) {
2137 if (sectionSize.width() > 0 && sectionSize.height() > 0) {
2138 QString key = QStringLiteral(u"qvdelegate-%1-%2-%3-%4-%5").arg(sectionSize.width())
2139 .arg(sectionSize.height()).arg(selected).arg(active).arg(hover);
2140 if (!QPixmapCache::find(key, &pixmap)) {
2141 pixmap = QPixmap(sectionSize);
2142 pixmap.fill(Qt::transparent);
2145 if (selected && hover)
2147 else if (selected && !active)
2156 QWindowsThemeData theme(widget, &pixmapPainter,
2157 QWindowsVistaStylePrivate::VistaTreeViewTheme,
2158 LVP_LISTITEM, state, QRect(0, 0, sectionSize.width(), sectionSize.height()));
2160 if (!theme.isValid())
2163 d->drawBackground(theme);
2164 QPixmapCache::insert(key, pixmap);
2168 if (vopt->showDecorationSelected) {
2169 const int frame = 2;
2170 QRect srcRect = QRect(0, 0, sectionSize.width(), sectionSize.height());
2171 QRect pixmapRect = vopt->rect;
2172 bool reverse = vopt->direction == Qt::RightToLeft;
2173 bool leftSection = vopt->viewItemPosition == QStyleOptionViewItem::Beginning;
2174 bool rightSection = vopt->viewItemPosition == QStyleOptionViewItem::End;
2175 if (vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne
2176 || vopt->viewItemPosition == QStyleOptionViewItem::Invalid)
2177 painter->drawPixmap(pixmapRect.topLeft(), pixmap);
2178 else if (reverse ? rightSection : leftSection){
2179 painter->drawPixmap(QRect(pixmapRect.topLeft(),
2180 QSize(frame, pixmapRect.height())), pixmap,
2181 QRect(QPoint(0, 0), QSize(frame, pixmapRect.height())));
2182 painter->drawPixmap(pixmapRect.adjusted(frame, 0, 0, 0),
2183 pixmap, srcRect.adjusted(frame, 0, -frame, 0));
2184 }
else if (reverse ? leftSection : rightSection) {
2185 painter->drawPixmap(QRect(pixmapRect.topRight() - QPoint(frame - 1, 0),
2186 QSize(frame, pixmapRect.height())), pixmap,
2187 QRect(QPoint(pixmapRect.width() - frame, 0),
2188 QSize(frame, pixmapRect.height())));
2189 painter->drawPixmap(pixmapRect.adjusted(0, 0, -frame, 0),
2190 pixmap, srcRect.adjusted(frame, 0, -frame, 0));
2191 }
else if (vopt->viewItemPosition == QStyleOptionViewItem::Middle)
2192 painter->drawPixmap(pixmapRect, pixmap,
2193 srcRect.adjusted(frame, 0, -frame, 0));
2195 if (vopt->text.isEmpty() && vopt->icon.isNull())
2197 painter->drawPixmap(itemRect.topLeft(), pixmap);
2209 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2211 if (!theme.isValid()) {
2212 QWindowsStyle::drawPrimitive(element, option, painter, widget);
2216 theme.mirrorHorizontally = hMirrored;
2217 theme.mirrorVertically = vMirrored;
2218 theme.noBorder = noBorder;
2219 theme.noContent = noContent;
2220 theme.rotate = rotate;
2222 d->drawBackground(theme);
2339void QWindowsVistaStyle::drawControl(ControlElement element,
const QStyleOption *option,
2340 QPainter *painter,
const QWidget *widget)
const
2342 if (!QWindowsVistaStylePrivate::useVista()) {
2343 QWindowsStyle::drawControl(element, option, painter, widget);
2349 bool selected = option->state & State_Selected;
2350 bool pressed = option->state & State_Sunken;
2351 bool disabled = !(option->state & State_Enabled);
2353 int state = option->state;
2354 int themeNumber = -1;
2356 QRect rect(option->rect);
2357 State flags = option->state;
2361 if (d->transitionsEnabled() && canAnimate(option)) {
2362 if (element == CE_PushButtonBevel) {
2366 QObject *styleObject = option->styleObject;
2368 int oldState = styleObject->property(
"_q_stylestate").toInt();
2369 oldRect = styleObject->property(
"_q_stylerect").toRect();
2370 newRect = option->rect;
2371 styleObject->setProperty(
"_q_stylestate",
int(option->state));
2372 styleObject->setProperty(
"_q_stylerect", option->rect);
2374 bool wasDefault =
false;
2375 bool isDefault =
false;
2376 if (
const QStyleOptionButton *button = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
2377 wasDefault = styleObject->property(
"_q_isdefault").toBool();
2378 isDefault = button->features & QStyleOptionButton::DefaultButton;
2379 styleObject->setProperty(
"_q_isdefault", isDefault);
2382 bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) ||
2383 (state & State_On) != (oldState & State_On) ||
2384 (state & State_MouseOver) != (oldState & State_MouseOver));
2386 if (oldRect != newRect || (wasDefault && !isDefault)) {
2387 doTransition =
false;
2388 d->stopAnimation(styleObject);
2392 styleObject->setProperty(
"_q_no_animation",
true);
2395 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
2396 QStyleOption *styleOption = clonedAnimationStyleOption(option);
2397 styleOption->state = QStyle::State(oldState);
2399 QImage startImage = createAnimationBuffer(option, widget);
2400 QPainter startPainter(&startImage);
2404 proxy()->drawControl(element, styleOption, &startPainter, widget);
2406 anim->paint(&startPainter, styleOption);
2407 d->stopAnimation(styleObject);
2410 t->setStartImage(startImage);
2411 QImage endImage = createAnimationBuffer(option, widget);
2413 styleOption->state = option->state;
2414 proxy()->drawControl(element, styleOption, &endPainter, widget);
2415 t->setEndImage(endImage);
2419 const HTHEME theme = OpenThemeData(
nullptr, L"Button");
2421 int fromState = buttonStateId(oldState, BP_PUSHBUTTON);
2422 int toState = buttonStateId(option->state, BP_PUSHBUTTON);
2423 if (GetThemeTransitionDuration(theme, BP_PUSHBUTTON, fromState, toState, TMT_TRANSITIONDURATIONS, &duration) == S_OK)
2424 t->setDuration(
int(duration));
2427 t->setStartTime(d->animationTime());
2428 styleObject->setProperty(
"_q_no_animation",
false);
2430 deleteClonedAnimationStyleOption(styleOption);
2431 d->startAnimation(t);
2434 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
2436 anim->paint(painter, option);
2443 bool hMirrored =
false;
2444 bool vMirrored =
false;
2448 case CE_PushButtonBevel:
2449 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
2450 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
2451 partId = BP_PUSHBUTTON;
2452 if (btn->features & QStyleOptionButton::CommandLinkButton)
2454 bool justFlat = (btn->features & QStyleOptionButton::Flat) && !(flags & (State_On|State_Sunken));
2455 if (!(flags & State_Enabled) && !(btn->features & QStyleOptionButton::Flat))
2456 stateId = PBS_DISABLED;
2459 else if (flags & (State_Sunken | State_On))
2460 stateId = PBS_PRESSED;
2461 else if (flags & State_MouseOver)
2463 else if (btn->features & QStyleOptionButton::DefaultButton && (state & State_Active))
2464 stateId = PBS_DEFAULTED;
2466 stateId = PBS_NORMAL;
2469 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2470 d->drawBackground(theme);
2473 if (btn->features & QStyleOptionButton::HasMenu) {
2474 int mbiw = 0, mbih = 0;
2475 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::ToolBarTheme,
2477 if (theme.isValid()) {
2478 const QSizeF size = theme.size() * QStyleHelper::dpiScaled(1, option);
2479 if (!size.isEmpty()) {
2480 mbiw = qRound(size.width());
2481 mbih = qRound(size.height());
2484 QRect ir = subElementRect(SE_PushButtonContents, option,
nullptr);
2485 QStyleOptionButton newBtn = *btn;
2486 newBtn.rect = QStyle::visualRect(option->direction, option->rect,
2487 QRect(ir.right() - mbiw - 2,
2488 option->rect.top() + (option->rect.height()/2) - (mbih/2),
2489 mbiw + 1, mbih + 1));
2490 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
2496 themeNumber = QWindowsVistaStylePrivate::StatusTheme;
2497 partId = SP_GRIPPER;
2498 QWindowsThemeData theme(
nullptr, painter, themeNumber, partId);
2499 QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize();
2501 if (
const auto *sg = qstyleoption_cast<
const QStyleOptionSizeGrip *>(option)) {
2502 switch (sg->corner) {
2503 case Qt::BottomRightCorner:
2504 rect = QRect(QPoint(rect.right() - size.width(), rect.bottom() - size.height()), size);
2506 case Qt::BottomLeftCorner:
2507 rect = QRect(QPoint(rect.left() + 1, rect.bottom() - size.height()), size);
2510 case Qt::TopRightCorner:
2511 rect = QRect(QPoint(rect.right() - size.width(), rect.top() + 1), size);
2514 case Qt::TopLeftCorner:
2515 rect = QRect(rect.topLeft() + QPoint(1, 1), size);
2516 hMirrored = vMirrored =
true;
2523 painter->eraseRect(option->rect);
2527#if QT_CONFIG(tabwidget)
2528 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option))
2529 stateId = tab->state & State_Enabled ? TIS_NORMAL : TIS_DISABLED;
2533 case CE_TabBarTabShape:
2534#if QT_CONFIG(tabwidget)
2535 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option)) {
2536 themeNumber = QWindowsVistaStylePrivate::TabTheme;
2537 const bool isDisabled = !(tab->state & State_Enabled);
2538 const bool hasFocus = tab->state & State_HasFocus;
2539 const bool isHot = tab->state & State_MouseOver;
2540 const bool selected = tab->state & State_Selected;
2541 bool lastTab = tab->position == QStyleOptionTab::End;
2542 bool firstTab = tab->position == QStyleOptionTab::Beginning;
2543 const bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
2544 const bool leftAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignLeft;
2545 const bool centerAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignCenter;
2546 const int borderThickness = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
2547 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, option, widget);
2550 stateId = TIS_DISABLED;
2552 stateId = TIS_SELECTED;
2554 stateId = TIS_FOCUSED;
2558 stateId = TIS_NORMAL;
2561 if (firstTab || onlyOne) {
2563 partId = TABP_TABITEMLEFTEDGE;
2564 else if (centerAligned)
2565 partId = TABP_TABITEM;
2567 partId = TABP_TABITEMRIGHTEDGE;
2569 partId = TABP_TABITEM;
2572 if (tab->direction == Qt::RightToLeft
2573 && (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth)) {
2574 bool temp = firstTab;
2579 const bool begin = firstTab || onlyOne;
2580 const bool end = lastTab || onlyOne;
2582 switch (tab->shape) {
2583 case QTabBar::RoundedNorth:
2585 rect.adjust(begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap, borderThickness);
2587 rect.adjust(begin? tabOverlap : 0, tabOverlap, end ? -tabOverlap : 0, 0);
2589 case QTabBar::RoundedSouth:
2593 rect.adjust(begin ? 0 : -tabOverlap , -borderThickness, end ? 0 : tabOverlap, 0);
2595 rect.adjust(begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0 , -tabOverlap);
2597 case QTabBar::RoundedEast:
2600 rect.adjust(-borderThickness, begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap);
2602 rect.adjust(0, begin ? tabOverlap : 0, -tabOverlap, end ? -tabOverlap : 0);
2604 case QTabBar::RoundedWest:
2608 rect.adjust(0, begin ? 0 : -tabOverlap, borderThickness, end ? 0 : tabOverlap);
2610 rect.adjust(tabOverlap, begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0);
2618 switch (tab->shape) {
2619 case QTabBar::RoundedNorth:
2620 rect.adjust(0,0, 0,-1);
2622 case QTabBar::RoundedSouth:
2623 rect.adjust(0,1, 0,0);
2625 case QTabBar::RoundedEast:
2626 rect.adjust( 1,0, 0,0);
2628 case QTabBar::RoundedWest:
2629 rect.adjust(0,0, -1,0);
2639 case CE_ProgressBarGroove: {
2640 Qt::Orientation orient = Qt::Horizontal;
2641 if (
const auto *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(option))
2642 if (!(pb->state & QStyle::State_Horizontal))
2643 orient = Qt::Vertical;
2645 partId = (orient == Qt::Horizontal) ? PP_BAR : PP_BARVERT;
2646 themeNumber = QWindowsVistaStylePrivate::ProgressTheme;
2651 case CE_ProgressBarContents:
2652 if (
const auto *bar = qstyleoption_cast<
const QStyleOptionProgressBar *>(option)) {
2653 bool isIndeterminate = (bar->minimum == 0 && bar->maximum == 0);
2654 const bool vertical = !(bar->state & QStyle::State_Horizontal);
2655 const bool inverted = bar->invertedAppearance;
2657 if (isIndeterminate || (bar->progress > 0 && (bar->progress < bar->maximum) && d->transitionsEnabled())) {
2658 if (!d->animation(styleObject(option)))
2659 d->startAnimation(
new QProgressStyleAnimation(d->animationFps, styleObject(option)));
2661 d->stopAnimation(styleObject(option));
2664 QWindowsThemeData theme(widget, painter,
2665 QWindowsVistaStylePrivate::ProgressTheme,
2666 vertical ? PP_FILLVERT : PP_FILL);
2667 theme.rect = option->rect;
2668 bool reverse = (bar->direction == Qt::LeftToRight && inverted) || (bar->direction == Qt::RightToLeft && !inverted);
2669 QTime current = d->animationTime();
2671 if (isIndeterminate) {
2672 if (
auto *progressAnimation = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2674 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2675 int animOffset = progressAnimation->startTime().msecsTo(current) / 4;
2676 if (animOffset > animationWidth)
2677 progressAnimation->setStartTime(d->animationTime());
2679 painter->setClipRect(theme.rect);
2681 QSize pixmapSize(14, 14);
2683 animRect = QRect(theme.rect.left(),
2684 inverted ? rect.top() - glowSize + animOffset :
2685 rect.bottom() + glowSize - animOffset,
2686 rect.width(), glowSize);
2687 pixmapSize.setHeight(animRect.height());
2689 animRect = QRect(rect.left() - glowSize + animOffset,
2690 rect.top(), glowSize, rect.height());
2691 animRect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2692 option->rect, animRect);
2693 pixmapSize.setWidth(animRect.width());
2695 QString name = QStringLiteral(u"qiprogress-%1-%2").arg(pixmapSize.width()).arg(pixmapSize.height());
2697 if (!QPixmapCache::find(name, &pixmap)) {
2698 QImage image(pixmapSize, QImage::Format_ARGB32);
2699 image.fill(Qt::transparent);
2701 theme.painter = &imagePainter;
2702 theme.partId = vertical ? PP_FILLVERT : PP_FILL;
2703 theme.rect = QRect(QPoint(0,0), animRect.size());
2704 QLinearGradient alphaGradient(0, 0, vertical ? 0 : image.width(),
2705 vertical ? image.height() : 0);
2706 alphaGradient.setColorAt(0, QColor(0, 0, 0, 0));
2707 alphaGradient.setColorAt(0.5, QColor(0, 0, 0, 220));
2708 alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
2709 imagePainter.fillRect(image.rect(), alphaGradient);
2710 imagePainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
2711 d->drawBackground(theme);
2713 pixmap = QPixmap::fromImage(image);
2714 QPixmapCache::insert(name, pixmap);
2716 painter->drawPixmap(animRect, pixmap);
2720 qint64 progress = qMax<qint64>(bar->progress, bar->minimum);
2723 int maxHeight = option->rect.height();
2725 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxHeight);
2726 int height = isIndeterminate ? maxHeight: qMax(
int(vc6_workaround), minHeight);
2727 theme.rect.setHeight(height);
2729 theme.rect.moveTop(rect.height() - theme.rect.height());
2731 int maxWidth = option->rect.width();
2733 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth);
2734 int width = isIndeterminate ? maxWidth : qMax(
int(vc6_workaround), minWidth);
2735 theme.rect.setWidth(width);
2736 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2737 option->rect, theme.rect);
2739 d->drawBackground(theme);
2741 if (QProgressStyleAnimation *a = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2743 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2744 int animOffset = a->startTime().msecsTo(current) / 4;
2745 theme.partId = vertical ? PP_MOVEOVERLAYVERT : PP_MOVEOVERLAY;
2746 if (animOffset > animationWidth) {
2747 if (bar->progress < bar->maximum)
2748 a->setStartTime(d->animationTime());
2750 d->stopAnimation(styleObject(option));
2754 painter->setClipRect(theme.rect);
2756 theme.rect = QRect(theme.rect.left(),
2757 inverted ? rect.top() - glowSize + animOffset :
2758 rect.bottom() + glowSize - animOffset,
2759 rect.width(), glowSize);
2761 theme.rect = QRect(rect.left() - glowSize + animOffset,rect.top(), glowSize, rect.height());
2762 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight, option->rect, theme.rect);
2764 d->drawBackground(theme);
2771 case CE_MenuBarItem:
2772 if (
const auto *mbi = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2773 if (mbi->menuItemType == QStyleOptionMenuItem::DefaultItem)
2776 QPalette::ColorRole textRole = disabled ? QPalette::Text : QPalette::ButtonText;
2777 const auto dpr = QStyleHelper::getDpr(widget);
2778 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2779 const auto pix = mbi->icon.pixmap(QSize(extent, extent), dpr, QIcon::Normal);
2781 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2782 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
2783 alignment |= Qt::TextHideMnemonic;
2785 if (widget && mbi->palette.color(QPalette::Window) != Qt::transparent) {
2787 QWindowsThemeData theme(widget, painter,
2788 QWindowsVistaStylePrivate::MenuTheme,
2789 MENU_BARBACKGROUND, 0, option->rect.adjusted(-1, 0, 2, 1));
2790 d->drawBackground(theme);
2792 int stateId = MBI_NORMAL;
2794 stateId = MBI_DISABLED;
2796 stateId = MBI_PUSHED;
2800 QWindowsThemeData theme2(widget, painter,
2801 QWindowsVistaStylePrivate::MenuTheme,
2802 MENU_BARITEM, stateId, option->rect);
2803 d->drawBackground(theme2);
2807 drawItemPixmap(painter, mbi->rect, alignment, pix);
2809 drawItemText(painter, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled, mbi->text, textRole);
2814 case CE_MenuEmptyArea:
2815 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2816 QBrush fill = menuitem->palette.brush((menuitem->state & State_Selected) ?
2817 QPalette::Highlight : QPalette::Button);
2818 painter->fillRect(rect, fill);
2824 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2826 const qreal factor = QWindowsVistaStylePrivate::nativeMetricScaleFactor(widget);
2827 int checkcol = qRound(qreal(25) * factor);
2828 const int gutterWidth = qRound(qreal(3) * factor);
2830 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::MenuTheme,
2831 MENU_POPUPCHECKBACKGROUND, MBI_HOT);
2832 QWindowsThemeData themeSize = theme;
2833 themeSize.partId = MENU_POPUPCHECK;
2834 themeSize.stateId = 0;
2835 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2836 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2837 checkcol = qMax(menuitem->maxIconWidth, qRound(gutterWidth + size.width() + margins.left() + margins.right()));
2839 QRect rect = option->rect;
2842 QWindowsThemeData popupbackgroundTheme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2843 MENU_POPUPBACKGROUND, stateId, option->rect);
2844 d->drawBackground(popupbackgroundTheme);
2847 if (option->direction == Qt::LeftToRight)
2848 checkcol += rect.x();
2849 QPoint p1 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.top()));
2850 QPoint p2 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.bottom()));
2851 QRect gutterRect(p1.x(), p1.y(), gutterWidth, p2.y() - p1.y() + 1);
2852 QWindowsThemeData theme2(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2853 MENU_POPUPGUTTER, stateId, gutterRect);
2854 d->drawBackground(theme2);
2857 menuitem->rect.getRect(&x, &y, &w, &h);
2858 int tab = menuitem->reservedShortcutWidth;
2859 bool dis = !(menuitem->state & State_Enabled);
2860 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
2861 ? menuitem->checked :
false;
2862 bool act = menuitem->state & State_Selected;
2864 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {
2865 int yoff = y-2 + h / 2;
2866 const int separatorSize = qRound(qreal(6) * QWindowsStylePrivate::nativeMetricScaleFactor(widget));
2867 QPoint p1 = QPoint(x + checkcol, yoff);
2868 QPoint p2 = QPoint(x + w + separatorSize, yoff);
2870 QRect subRect(p1.x() + (gutterWidth - menuitem->rect.x()), p1.y(),
2871 p2.x() - p1.x(), separatorSize);
2872 subRect = QStyle::visualRect(option->direction, option->rect, subRect );
2873 QWindowsThemeData theme2(widget, painter,
2874 QWindowsVistaStylePrivate::MenuTheme,
2875 MENU_POPUPSEPARATOR, stateId, subRect);
2876 d->drawBackground(theme2);
2880 QRect vCheckRect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x(),
2881 menuitem->rect.y(), checkcol - (gutterWidth + menuitem->rect.x()), menuitem->rect.height()));
2884 stateId = dis ? MBI_DISABLED : MBI_HOT;
2885 QWindowsThemeData theme2(widget, painter,
2886 QWindowsVistaStylePrivate::MenuTheme,
2887 MENU_POPUPITEM, stateId, option->rect);
2888 d->drawBackground(theme2);
2892 QWindowsThemeData theme(widget, painter,
2893 QWindowsVistaStylePrivate::MenuTheme,
2894 MENU_POPUPCHECKBACKGROUND,
2895 menuitem->icon.isNull() ? MBI_HOT : MBI_PUSHED, vCheckRect);
2896 QWindowsThemeData themeSize = theme;
2897 themeSize.partId = MENU_POPUPCHECK;
2898 themeSize.stateId = 0;
2899 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2900 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2901 QRect checkRect(0, 0, qRound(size.width() + margins.left() + margins.right()),
2902 qRound(size.height() + margins.bottom() + margins.top()));
2903 checkRect.moveCenter(vCheckRect.center());
2904 theme.rect = checkRect;
2906 d->drawBackground(theme);
2908 if (menuitem->icon.isNull()) {
2909 checkRect = QRect(QPoint(0, 0), size.toSize());
2910 checkRect.moveCenter(theme.rect.center());
2911 theme.rect = checkRect;
2913 theme.partId = MENU_POPUPCHECK;
2914 bool bullet = menuitem->checkType & QStyleOptionMenuItem::Exclusive;
2916 theme.stateId = bullet ? MC_BULLETDISABLED: MC_CHECKMARKDISABLED;
2918 theme.stateId = bullet ? MC_BULLETNORMAL: MC_CHECKMARKNORMAL;
2919 d->drawBackground(theme);
2923 if (!menuitem->icon.isNull()) {
2924 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
2926 mode = QIcon::Active;
2927 const auto size = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2928 QRect pmr(QPoint(0, 0), QSize(size, size));
2929 pmr.moveCenter(vCheckRect.center());
2930 menuitem->icon.paint(painter, pmr, Qt::AlignCenter, mode,
2931 checked ? QIcon::On : QIcon::Off);
2934 painter->setPen(menuitem->palette.buttonText().color());
2936 const QColor textColor = menuitem->palette.text().color();
2938 painter->setPen(textColor);
2940 int xm = windowsItemFrame + checkcol + windowsItemHMargin + (gutterWidth - menuitem->rect.x()) - 1;
2941 int xpos = menuitem->rect.x() + xm;
2942 QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
2943 QRect vTextRect = visualRect(option->direction, menuitem->rect, textRect);
2944 QString s = menuitem->text;
2947 int t = s.indexOf(QLatin1Char(
'\t'));
2948 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2949 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
2950 text_flags |= Qt::TextHideMnemonic;
2951 text_flags |= Qt::AlignLeft;
2953 QRect vShortcutRect = visualRect(option->direction, menuitem->rect,
2954 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
2955 painter->drawText(vShortcutRect, text_flags, s.mid(t + 1));
2958 QFont font = menuitem->font;
2959 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
2961 painter->setFont(font);
2962 painter->setPen(textColor);
2963 painter->drawText(vTextRect, text_flags, s.left(t));
2966 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {
2967 int dim = (h - 2 * windowsItemFrame) / 2;
2968 PrimitiveElement arrow;
2969 arrow = (option->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
2970 xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim;
2971 QRect vSubMenuRect = visualRect(option->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
2972 QStyleOptionMenuItem newMI = *menuitem;
2973 newMI.rect = vSubMenuRect;
2974 newMI.state = dis ? State_None : State_Enabled;
2975 proxy()->drawPrimitive(arrow, &newMI, painter, widget);
2981 case CE_HeaderSection:
2982 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(option)) {
2983 partId = HP_HEADERITEM;
2984 if (flags & State_Sunken)
2985 stateId = HIS_PRESSED;
2986 else if (flags & State_MouseOver)
2989 stateId = HIS_NORMAL;
2991 if (header->sortIndicator != QStyleOptionHeader::None)
2994 QWindowsThemeData theme(widget, painter,
2995 QWindowsVistaStylePrivate::HeaderTheme,
2996 partId, stateId, option->rect);
2997 d->drawBackground(theme);
3001 case CE_MenuBarEmptyArea: {
3002 stateId = MBI_NORMAL;
3003 if (!(state & State_Enabled))
3004 stateId = MBI_DISABLED;
3005 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
3006 MENU_BARBACKGROUND, stateId, option->rect);
3007 d->drawBackground(theme);
3012#if QT_CONFIG(toolbar)
3013 if (
const auto *toolbar = qstyleoption_cast<
const QStyleOptionToolBar *>(option)) {
3014 QPalette pal = option->palette;
3015 pal.setColor(QPalette::Dark, option->palette.window().color().darker(130));
3016 QStyleOptionToolBar copyOpt = *toolbar;
3017 copyOpt.palette = pal;
3018 QWindowsStyle::drawControl(element, ©Opt, painter, widget);
3023#if QT_CONFIG(dockwidget)
3024 case CE_DockWidgetTitle:
3025 if (
const auto *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(option)) {
3026 QRect rect = option->rect;
3027 const QDockWidget *dw = qobject_cast<
const QDockWidget *>(widget);
3028 bool isFloating = dw && dw->isFloating();
3029 int buttonMargin = 4;
3030 int mw = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, widget);
3031 int fw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, dwOpt, widget);
3033 const bool verticalTitleBar = dwOpt->verticalTitleBar;
3035 if (verticalTitleBar) {
3036 rect = rect.transposed();
3038 painter->translate(rect.left() - 1, rect.top() + rect.width());
3039 painter->rotate(-90);
3040 painter->translate(-rect.left() + 1, -rect.top());
3043 QRect r = option->rect.adjusted(0, 2, -1, -3);
3044 QRect titleRect = r;
3046 if (dwOpt->closable) {
3047 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton, dwOpt, widget).actualSize(QSize(10, 10));
3048 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3051 if (dwOpt->floatable) {
3052 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarMaxButton, dwOpt, widget).actualSize(QSize(10, 10));
3053 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3057 titleRect.adjust(0, -fw, 0, 0);
3058 if (widget && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey())
3059 titleRect.adjust(titleRect.height() + mw, 0, 0, 0);
3061 titleRect.adjust(mw, 0, 0, 0);
3062 if (!dwOpt->floatable && !dwOpt->closable)
3063 titleRect.adjust(0, 0, -mw, 0);
3066 if (!verticalTitleBar)
3067 titleRect = visualRect(dwOpt->direction, r, titleRect);
3070 const bool isActive = dwOpt->state & State_Active;
3071 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
3073 stateId = CS_ACTIVE;
3075 stateId = CS_INACTIVE;
3077 rect = rect.adjusted(-fw, -fw, fw, 0);
3079 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
3080 if (!theme.isValid())
3085 theme.partId = WP_SMALLCAPTION;
3086 d->drawBackground(theme);
3090 QIcon ico = widget->windowIcon();
3091 bool hasIcon = (ico.cacheKey() != QApplication::windowIcon().cacheKey());
3093 const auto titleHeight = rect.height() - 2;
3094 const auto dpr = QStyleHelper::getDpr(widget);
3095 const auto pxIco = ico.pixmap(QSize(titleHeight, titleHeight), dpr);
3096 if (!verticalTitleBar && dwOpt->direction == Qt::RightToLeft)
3097 painter->drawPixmap(rect.width() - titleHeight - pxIco.width(), rect.bottom() - titleHeight - 2, pxIco);
3099 painter->drawPixmap(fw, rect.bottom() - titleHeight - 2, pxIco);
3101 if (!dwOpt->title.isEmpty()) {
3102 QPen oldPen = painter->pen();
3103 QFont oldFont = painter->font();
3104 QFont titleFont = oldFont;
3105 titleFont.setBold(
true);
3106 painter->setFont(titleFont);
3108 = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
3110 int result = TST_NONE;
3111 GetThemeEnumValue(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3112 if (result != TST_NONE) {
3113 COLORREF textShadowRef;
3114 GetThemeColor(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWCOLOR, &textShadowRef);
3115 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3116 painter->setPen(textShadow);
3117 drawItemText(painter, titleRect.adjusted(1, 1, 1, 1),
3118 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3119 dwOpt->state & State_Enabled, titleText);
3122 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3123 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3124 painter->setPen(textColor);
3125 drawItemText(painter, titleRect,
3126 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3127 dwOpt->state & State_Enabled, titleText);
3128 painter->setFont(oldFont);
3129 painter->setPen(oldPen);
3132 painter->setBrush(option->palette.window().color().darker(110));
3133 painter->setPen(option->palette.window().color().darker(130));
3134 painter->drawRect(rect.adjusted(0, 1, -1, -3));
3136 if (!dwOpt->title.isEmpty()) {
3137 QString titleText = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight,
3138 verticalTitleBar ? titleRect.height() : titleRect.width());
3139 const int indent = 4;
3140 drawItemText(painter, rect.adjusted(indent + 1, 1, -indent - 1, -1),
3141 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic,
3143 dwOpt->state & State_Enabled, titleText,
3144 QPalette::WindowText);
3151#if QT_CONFIG(rubberband)
3153 if (qstyleoption_cast<
const QStyleOptionRubberBand *>(option)) {
3154 QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
3156 painter->setPen(highlight.darker(120));
3157 QColor dimHighlight(qMin(highlight.red()/2 + 110, 255),
3158 qMin(highlight.green()/2 + 110, 255),
3159 qMin(highlight.blue()/2 + 110, 255),
3160 (widget && widget->isWindow())? 255 : 127);
3161 painter->setBrush(dimHighlight);
3162 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
3169 case CE_HeaderEmptyArea:
3170 if (option->state & State_Horizontal) {
3171 themeNumber = QWindowsVistaStylePrivate::HeaderTheme;
3172 stateId = HIS_NORMAL;
3174 QWindowsStyle::drawControl(CE_HeaderEmptyArea, option, painter, widget);
3179#if QT_CONFIG(itemviews)
3180 case CE_ItemViewItem: {
3181 const QStyleOptionViewItem *vopt;
3182 const QAbstractItemView *view = qobject_cast<
const QAbstractItemView *>(widget);
3183 bool newStyle =
true;
3185 if (qobject_cast<
const QTableView*>(widget))
3188 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3190 if (newStyle && view && (vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(option))) {
3192
3193
3194
3195
3196
3197
3198 QPalette palette = vopt->palette;
3199 palette.setColor(QPalette::All, QPalette::HighlightedText, palette.color(QPalette::Active, QPalette::Text));
3201 palette.setColor(QPalette::All, QPalette::Highlight, palette.base().color().darker(108));
3202 QStyleOptionViewItem adjustedOption = *vopt;
3203 adjustedOption.palette = palette;
3205 if ((view->selectionMode() == QAbstractItemView::SingleSelection)
3206 && !(vopt->state & State_KeyboardFocusChange))
3207 adjustedOption.state &= ~State_HasFocus;
3208 if (!theme.isValid()) {
3209 QWindowsStyle::drawControl(element, &adjustedOption, painter, widget);
3213 if (!theme.isValid()) {
3214 QWindowsStyle::drawControl(element, option, painter, widget);
3219 theme.rotate = rotate;
3220 theme.mirrorHorizontally = hMirrored;
3221 theme.mirrorVertically = vMirrored;
3222 d->drawBackground(theme);
3227#if QT_CONFIG(combobox)
3228 case CE_ComboBoxLabel:
3229 QCommonStyle::drawControl(element, option, painter, widget);
3237 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3239 if (!theme.isValid()) {
3240 QWindowsStyle::drawControl(element, option, painter, widget);
3244 theme.rotate = rotate;
3245 theme.mirrorHorizontally = hMirrored;
3246 theme.mirrorVertically = vMirrored;
3248 d->drawBackground(theme);
3256void QWindowsVistaStyle::drawComplexControl(ComplexControl control,
const QStyleOptionComplex *option,
3257 QPainter *painter,
const QWidget *widget)
const
3261 if (!QWindowsVistaStylePrivate::useVista()) {
3262 QWindowsStyle::drawComplexControl(control, option, painter, widget);
3266 State state = option->state;
3267 SubControls sub = option->subControls;
3268 QRect r = option->rect;
3273 State flags = option->state;
3274 if (widget && widget->testAttribute(Qt::WA_UnderMouse) && widget->isActiveWindow())
3275 flags |= State_MouseOver;
3277 if (d->transitionsEnabled() && canAnimate(option))
3279 if (control == CC_ScrollBar || control == CC_SpinBox || control == CC_ComboBox) {
3280 QObject *styleObject = option->styleObject;
3282 int oldState = styleObject->property(
"_q_stylestate").toInt();
3283 int oldActiveControls = styleObject->property(
"_q_stylecontrols").toInt();
3285 QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
3286 styleObject->setProperty(
"_q_stylestate",
int(option->state));
3287 styleObject->setProperty(
"_q_stylecontrols",
int(option->activeSubControls));
3288 styleObject->setProperty(
"_q_stylerect", option->rect);
3290 bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken)
3291 || (state & State_On) != (oldState & State_On)
3292 || (state & State_MouseOver) != (oldState & State_MouseOver)
3293 || oldActiveControls !=
int(option->activeSubControls));
3295 if (qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3296 QRect oldSliderPos = styleObject->property(
"_q_stylesliderpos").toRect();
3297 QRect currentPos = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3298 styleObject->setProperty(
"_q_stylesliderpos", currentPos);
3299 if (oldSliderPos != currentPos) {
3300 doTransition =
false;
3301 d->stopAnimation(styleObject);
3303 }
else if (control == CC_SpinBox) {
3306 doTransition = (state & State_HasFocus) != (oldState & State_HasFocus);
3309 if (oldRect != option->rect) {
3310 doTransition =
false;
3311 d->stopAnimation(styleObject);
3315 QImage startImage = createAnimationBuffer(option, widget);
3316 QPainter startPainter(&startImage);
3318 QImage endImage = createAnimationBuffer(option, widget);
3321 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
3325 QStyleOptionComplex *styleOption = qstyleoption_cast<QStyleOptionComplex*>(clonedAnimationStyleOption(option));
3327 styleObject->setProperty(
"_q_no_animation",
true);
3331 styleOption->state = QStyle::State(oldState);
3332 styleOption->activeSubControls = QStyle::SubControl(oldActiveControls);
3333 proxy()->drawComplexControl(control, styleOption, &startPainter, widget);
3335 anim->paint(&startPainter, option);
3337 t->setStartImage(startImage);
3340 styleOption->state = option->state;
3341 styleOption->activeSubControls = option->activeSubControls;
3342 proxy()->drawComplexControl(control, styleOption, &endPainter, widget);
3344 styleObject->setProperty(
"_q_no_animation",
false);
3346 t->setEndImage(endImage);
3347 t->setStartTime(d->animationTime());
3349 if (option->state & State_MouseOver || option->state & State_Sunken)
3350 t->setDuration(150);
3352 t->setDuration(500);
3354 deleteClonedAnimationStyleOption(styleOption);
3355 d->startAnimation(t);
3357 if (QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject))) {
3358 anim->paint(painter, option);
3366#if QT_CONFIG(slider)
3368 if (
const auto *slider = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3369 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::TrackBarTheme);
3370 QRect slrect = slider->rect;
3371 QRegion tickreg = slrect;
3372 if (sub & SC_SliderGroove) {
3373 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
3374 if (slider->orientation == Qt::Horizontal) {
3376 stateId = TRS_NORMAL;
3377 theme.rect = QRect(slrect.left(), theme.rect.center().y() - 2, slrect.width(), 4);
3379 partId = TKP_TRACKVERT;
3380 stateId = TRVS_NORMAL;
3381 theme.rect = QRect(theme.rect.center().x() - 2, slrect.top(), 4, slrect.height());
3383 theme.partId = partId;
3384 theme.stateId = stateId;
3385 d->drawBackground(theme);
3386 tickreg -= theme.rect;
3388 if (sub & SC_SliderTickmarks) {
3389 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
3390 int ticks = slider->tickPosition;
3391 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
3392 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3393 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3394 int interval = slider->tickInterval;
3395 if (interval <= 0) {
3396 interval = slider->singleStep;
3397 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3399 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3401 interval = slider->pageStep;
3405 int fudge = len / 2;
3407 int bothOffset = (ticks & QSlider::TicksAbove && ticks & QSlider::TicksBelow) ? 1 : 0;
3408 painter->setPen(d->sliderTickColor);
3409 QVarLengthArray<QLine, 32> lines;
3410 int v = slider->minimum;
3411 while (v <= slider->maximum + 1) {
3412 if (v == slider->maximum + 1 && interval == 1)
3414 const int v_ = qMin(v, slider->maximum);
3415 int tickLength = (v_ == slider->minimum || v_ >= slider->maximum) ? 4 : 3;
3416 pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3417 v_, available) + fudge;
3418 if (slider->orientation == Qt::Horizontal) {
3419 if (ticks & QSlider::TicksAbove) {
3420 lines.append(QLine(pos, tickOffset - 1 - bothOffset,
3421 pos, tickOffset - 1 - bothOffset - tickLength));
3424 if (ticks & QSlider::TicksBelow) {
3425 lines.append(QLine(pos, tickOffset + thickness + bothOffset,
3426 pos, tickOffset + thickness + bothOffset + tickLength));
3429 if (ticks & QSlider::TicksAbove) {
3430 lines.append(QLine(tickOffset - 1 - bothOffset, pos,
3431 tickOffset - 1 - bothOffset - tickLength, pos));
3434 if (ticks & QSlider::TicksBelow) {
3435 lines.append(QLine(tickOffset + thickness + bothOffset, pos,
3436 tickOffset + thickness + bothOffset + tickLength, pos));
3440 int nextInterval = v + interval;
3441 if (nextInterval < v)
3445 if (!lines.isEmpty()) {
3447 painter->translate(slrect.topLeft());
3448 painter->drawLines(lines.constData(), lines.size());
3452 if (sub & SC_SliderHandle) {
3453 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
3454 if (slider->orientation == Qt::Horizontal) {
3455 if (slider->tickPosition == QSlider::TicksAbove)
3456 partId = TKP_THUMBTOP;
3457 else if (slider->tickPosition == QSlider::TicksBelow)
3458 partId = TKP_THUMBBOTTOM;
3462 if (!(slider->state & State_Enabled))
3463 stateId = TUS_DISABLED;
3464 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3465 stateId = TUS_PRESSED;
3466 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3468 else if (flags & State_HasFocus)
3469 stateId = TUS_FOCUSED;
3471 stateId = TUS_NORMAL;
3473 if (slider->tickPosition == QSlider::TicksLeft)
3474 partId = TKP_THUMBLEFT;
3475 else if (slider->tickPosition == QSlider::TicksRight)
3476 partId = TKP_THUMBRIGHT;
3478 partId = TKP_THUMBVERT;
3480 if (!(slider->state & State_Enabled))
3481 stateId = TUVS_DISABLED;
3482 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3483 stateId = TUVS_PRESSED;
3484 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3486 else if (flags & State_HasFocus)
3487 stateId = TUVS_FOCUSED;
3489 stateId = TUVS_NORMAL;
3491 theme.partId = partId;
3492 theme.stateId = stateId;
3493 d->drawBackground(theme);
3495 if (slider->state & State_HasFocus) {
3496 QStyleOptionFocusRect fropt;
3497 fropt.QStyleOption::operator=(*slider);
3498 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
3499 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3505#if QT_CONFIG(toolbutton)
3507 if (
const auto *toolbutton = qstyleoption_cast<
const QStyleOptionToolButton *>(option)) {
3508 QRect button, menuarea;
3509 button = proxy()->subControlRect(control, toolbutton, SC_ToolButton, widget);
3510 menuarea = proxy()->subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
3512 State bflags = toolbutton->state & ~State_Sunken;
3513 State mflags = bflags;
3514 bool autoRaise = flags & State_AutoRaise;
3516 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled))
3517 bflags &= ~State_Raised;
3520 if (toolbutton->state & State_Sunken) {
3521 if (toolbutton->activeSubControls & SC_ToolButton) {
3522 bflags |= State_Sunken;
3523 mflags |= State_MouseOver | State_Sunken;
3524 }
else if (toolbutton->activeSubControls & SC_ToolButtonMenu) {
3525 mflags |= State_Sunken;
3526 bflags |= State_MouseOver;
3530 QStyleOption tool = *toolbutton;
3531 if (toolbutton->subControls & SC_ToolButton) {
3532 if (flags & (State_Sunken | State_On | State_Raised) || !autoRaise) {
3533 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup && autoRaise) {
3534 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ToolBarTheme);
3535 theme.partId = TP_SPLITBUTTON;
3536 theme.rect = button;
3537 if (!(bflags & State_Enabled))
3538 stateId = TS_DISABLED;
3539 else if (bflags & State_Sunken)
3540 stateId = TS_PRESSED;
3541 else if (bflags & State_MouseOver || !(flags & State_AutoRaise))
3542 stateId = flags & State_On ? TS_HOTCHECKED : TS_HOT;
3543 else if (bflags & State_On)
3544 stateId = TS_CHECKED;
3546 stateId = TS_NORMAL;
3547 if (option->direction == Qt::RightToLeft)
3548 theme.mirrorHorizontally =
true;
3549 theme.stateId = stateId;
3550 d->drawBackground(theme);
3552 tool.rect = option->rect;
3553 tool.state = bflags;
3555 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
3557 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter, widget);
3562 if (toolbutton->state & State_HasFocus) {
3563 QStyleOptionFocusRect fr;
3564 fr.QStyleOption::operator=(*toolbutton);
3565 fr.rect.adjust(3, 3, -3, -3);
3566 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
3567 fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator,
3568 toolbutton, widget), 0);
3569 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
3571 QStyleOptionToolButton label = *toolbutton;
3572 label.state = bflags;
3575 label.state &= ~State_Sunken;
3576 label.rect = button.adjusted(fw, fw, -fw, -fw);
3577 proxy()->drawControl(CE_ToolButtonLabel, &label, painter, widget);
3579 if (toolbutton->subControls & SC_ToolButtonMenu) {
3580 tool.rect = menuarea;
3581 tool.state = mflags;
3583 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, painter, widget);
3585 tool.state = mflags;
3586 menuarea.adjust(-2, 0, 0, 0);
3588 if ((bflags & State_Sunken) != (mflags & State_Sunken)){
3590 painter->setClipRect(menuarea);
3591 tool.rect = option->rect;
3592 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter,
nullptr);
3597 painter->setPen(option->palette.dark().color());
3598 painter->drawLine(menuarea.left(), menuarea.top() + 3,
3599 menuarea.left(), menuarea.bottom() - 3);
3600 painter->setPen(option->palette.light().color());
3601 painter->drawLine(menuarea.left() - 1, menuarea.top() + 3,
3602 menuarea.left() - 1, menuarea.bottom() - 3);
3604 tool.rect = menuarea.adjusted(2, 3, -2, -1);
3605 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
3608 }
else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
3609 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
3610 QRect ir = toolbutton->rect;
3611 QStyleOptionToolButton newBtn = *toolbutton;
3612 newBtn.rect = QRect(ir.right() + 4 - mbi, ir.height() - mbi + 4, mbi - 5, mbi - 5);
3613 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
3620 if (
const auto *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(option)) {
3621 const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget);
3622 bool isActive = tb->titleBarState & QStyle::State_Active;
3623 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme);
3624 if (sub & SC_TitleBarLabel) {
3625 partId = (tb->titleBarState & Qt::WindowMinimized) ? WP_MINCAPTION : WP_CAPTION;
3626 theme.rect = option->rect;
3627 if (widget && !widget->isEnabled())
3628 stateId = CS_DISABLED;
3630 stateId = CS_ACTIVE;
3632 stateId = CS_INACTIVE;
3634 theme.partId = partId;
3635 theme.stateId = stateId;
3636 d->drawBackground(theme);
3638 QRect ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
3641 GetThemeEnumValue(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3643 COLORREF textShadowRef;
3644 GetThemeColor(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE,
TMT_TEXTSHADOWCOLOR, &textShadowRef);
3645 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3646 painter->setPen(textShadow);
3647 painter->drawText(
int(ir.x() + 3 * factor),
int(ir.y() + 2 * factor),
3648 int(ir.width() - 1 * factor), ir.height(),
3649 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3651 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3652 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3653 painter->setPen(textColor);
3654 painter->drawText(
int(ir.x() + 2 * factor),
int(ir.y() + 1 * factor),
3655 int(ir.width() - 2 * factor), ir.height(),
3656 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3658 if (sub & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3659 theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarSysMenu, widget);
3660 partId = WP_SYSBUTTON;
3661 if ((widget && !widget->isEnabled()) || !isActive)
3662 stateId = SBS_DISABLED;
3663 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_Sunken))
3664 stateId = SBS_PUSHED;
3665 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_MouseOver))
3668 stateId = SBS_NORMAL;
3669 if (!tb->icon.isNull()) {
3670 tb->icon.paint(painter, theme.rect);
3672 theme.partId = partId;
3673 theme.stateId = stateId;
3674 if (theme.size().isEmpty()) {
3675 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, tb, widget);
3676 const auto dpr = QStyleHelper::getDpr(widget);
3677 const auto icon = proxy()->standardIcon(SP_TitleBarMenuButton, tb, widget);
3678 const auto pm = icon.pixmap(QSize(extent, extent), dpr);
3679 drawItemPixmap(painter, theme.rect, Qt::AlignCenter, pm);
3681 d->drawBackground(theme);
3686 if (sub & SC_TitleBarMinButton && tb->titleBarFlags & Qt::WindowMinimizeButtonHint
3687 && !(tb->titleBarState & Qt::WindowMinimized)) {
3688 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMinButton, isActive, WP_MINBUTTON, &theme);
3689 d->drawBackground(theme);
3691 if (sub & SC_TitleBarMaxButton && tb->titleBarFlags & Qt::WindowMaximizeButtonHint
3692 && !(tb->titleBarState & Qt::WindowMaximized)) {
3693 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMaxButton, isActive, WP_MAXBUTTON, &theme);
3694 d->drawBackground(theme);
3696 if (sub & SC_TitleBarContextHelpButton
3697 && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
3698 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarContextHelpButton, isActive, WP_HELPBUTTON, &theme);
3699 d->drawBackground(theme);
3701 bool drawNormalButton = (sub & SC_TitleBarNormalButton)
3702 && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3703 && (tb->titleBarState & Qt::WindowMinimized))
3704 || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3705 && (tb->titleBarState & Qt::WindowMaximized)));
3706 if (drawNormalButton) {
3707 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarNormalButton, isActive, WP_RESTOREBUTTON, &theme);
3708 d->drawBackground(theme);
3710 if (sub & SC_TitleBarShadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3711 && !(tb->titleBarState & Qt::WindowMinimized)) {
3712 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarShadeButton, isActive, WP_MINBUTTON, &theme);
3713 d->drawBackground(theme);
3715 if (sub & SC_TitleBarUnshadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3716 && tb->titleBarState & Qt::WindowMinimized) {
3717 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarUnshadeButton, isActive, WP_RESTOREBUTTON, &theme);
3718 d->drawBackground(theme);
3720 if (sub & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3721 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarCloseButton, isActive, WP_CLOSEBUTTON, &theme);
3722 d->drawBackground(theme);
3727#if QT_CONFIG(mdiarea)
3728 case CC_MdiControls: {
3729 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme, WP_MDICLOSEBUTTON, CBS_NORMAL);
3730 if (Q_UNLIKELY(!theme.isValid()))
3733 if (option->subControls.testFlag(SC_MdiCloseButton)) {
3734 populateMdiButtonTheme(proxy(), widget, option, SC_MdiCloseButton, WP_MDICLOSEBUTTON, &theme);
3735 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3737 if (option->subControls.testFlag(SC_MdiNormalButton)) {
3738 populateMdiButtonTheme(proxy(), widget, option, SC_MdiNormalButton, WP_MDIRESTOREBUTTON, &theme);
3739 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3741 if (option->subControls.testFlag(QStyle::SC_MdiMinButton)) {
3742 populateMdiButtonTheme(proxy(), widget, option, SC_MdiMinButton, WP_MDIMINBUTTON, &theme);
3743 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3751 if (
const auto *dial = qstyleoption_cast<
const QStyleOptionSlider *>(option))
3752 QStyleHelper::drawDial(dial, painter);
3757 if (
const QStyleOptionComboBox *cmb = qstyleoption_cast<
const QStyleOptionComboBox *>(option)) {
3758 if (cmb->editable) {
3759 if (sub & SC_ComboBoxEditField) {
3760 partId = EP_EDITBORDER_NOSCROLL;
3761 if (!(flags & State_Enabled))
3762 stateId = ETS_DISABLED;
3763 else if (flags & State_MouseOver)
3765 else if (flags & State_HasFocus)
3766 stateId = ETS_FOCUSED;
3768 stateId = ETS_NORMAL;
3770 QWindowsThemeData theme(widget, painter,
3771 QWindowsVistaStylePrivate::EditTheme,
3772 partId, stateId, r);
3774 d->drawBackground(theme);
3776 if (sub & SC_ComboBoxArrow) {
3777 QRect subRect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3778 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3779 theme.rect = subRect;
3780 partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3782 if (!(cmb->state & State_Enabled))
3783 stateId = CBXS_DISABLED;
3784 else if (cmb->state & State_Sunken || cmb->state & State_On)
3785 stateId = CBXS_PRESSED;
3786 else if (cmb->state & State_MouseOver && option->activeSubControls & SC_ComboBoxArrow)
3789 stateId = CBXS_NORMAL;
3791 theme.partId = partId;
3792 theme.stateId = stateId;
3793 d->drawBackground(theme);
3797 if (sub & SC_ComboBoxFrame) {
3798 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3799 theme.rect = option->rect;
3800 theme.partId = CP_READONLY;
3801 if (!(cmb->state & State_Enabled))
3802 theme.stateId = CBXS_DISABLED;
3803 else if (cmb->state & State_Sunken || cmb->state & State_On)
3804 theme.stateId = CBXS_PRESSED;
3805 else if (cmb->state & State_MouseOver)
3806 theme.stateId = CBXS_HOT;
3808 theme.stateId = CBXS_NORMAL;
3809 d->drawBackground(theme);
3811 if (sub & SC_ComboBoxArrow) {
3812 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3813 theme.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3814 theme.partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3815 if (!(cmb->state & State_Enabled))
3816 theme.stateId = CBXS_DISABLED;
3818 theme.stateId = CBXS_NORMAL;
3819 d->drawBackground(theme);
3821 if ((sub & SC_ComboBoxEditField) && (flags & State_HasFocus)) {
3822 QStyleOptionFocusRect fropt;
3823 fropt.QStyleOption::operator=(*cmb);
3824 fropt.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget);
3825 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3832 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3833 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ScrollBarTheme);
3834 bool maxedOut = (scrollbar->maximum == scrollbar->minimum);
3836 flags &= ~State_Enabled;
3838 bool isHorz = flags & State_Horizontal;
3839 bool isRTL = option->direction == Qt::RightToLeft;
3840 if (sub & SC_ScrollBarAddLine) {
3841 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddLine, widget);
3842 partId = SBP_ARROWBTN;
3843 if (!(flags & State_Enabled))
3844 stateId = (isHorz ? (isRTL ? ABS_LEFTDISABLED : ABS_RIGHTDISABLED) : ABS_DOWNDISABLED);
3845 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_Sunken))
3846 stateId = (isHorz ? (isRTL ? ABS_LEFTPRESSED : ABS_RIGHTPRESSED) : ABS_DOWNPRESSED);
3847 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_MouseOver))
3848 stateId = (isHorz ? (isRTL ? ABS_LEFTHOT : ABS_RIGHTHOT) : ABS_DOWNHOT);
3849 else if (scrollbar->state & State_MouseOver)
3850 stateId = (isHorz ? (isRTL ? ABS_LEFTHOVER : ABS_RIGHTHOVER) : ABS_DOWNHOVER);
3852 stateId = (isHorz ? (isRTL ? ABS_LEFTNORMAL : ABS_RIGHTNORMAL) : ABS_DOWNNORMAL);
3853 theme.partId = partId;
3854 theme.stateId = stateId;
3855 d->drawBackground(theme);
3857 if (sub & SC_ScrollBarSubLine) {
3858 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubLine, widget);
3859 partId = SBP_ARROWBTN;
3860 if (!(flags & State_Enabled))
3861 stateId = (isHorz ? (isRTL ? ABS_RIGHTDISABLED : ABS_LEFTDISABLED) : ABS_UPDISABLED);
3862 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_Sunken))
3863 stateId = (isHorz ? (isRTL ? ABS_RIGHTPRESSED : ABS_LEFTPRESSED) : ABS_UPPRESSED);
3864 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_MouseOver))
3865 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOT : ABS_LEFTHOT) : ABS_UPHOT);
3866 else if (scrollbar->state & State_MouseOver)
3867 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOVER : ABS_LEFTHOVER) : ABS_UPHOVER);
3869 stateId = (isHorz ? (isRTL ? ABS_RIGHTNORMAL : ABS_LEFTNORMAL) : ABS_UPNORMAL);
3870 theme.partId = partId;
3871 theme.stateId = stateId;
3872 d->drawBackground(theme);
3875 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3876 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget));
3877 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget));
3878 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3879 stateId = SCRBS_DISABLED;
3880 theme.partId = partId;
3881 theme.stateId = stateId;
3882 d->drawBackground(theme);
3884 if (sub & SC_ScrollBarSubPage) {
3885 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget);
3886 partId = flags & State_Horizontal ? SBP_UPPERTRACKHORZ : SBP_UPPERTRACKVERT;
3887 if (!(flags & State_Enabled))
3888 stateId = SCRBS_DISABLED;
3889 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_Sunken))
3890 stateId = SCRBS_PRESSED;
3891 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_MouseOver))
3892 stateId = SCRBS_HOT;
3894 stateId = SCRBS_NORMAL;
3895 theme.partId = partId;
3896 theme.stateId = stateId;
3897 d->drawBackground(theme);
3899 if (sub & SC_ScrollBarAddPage) {
3900 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget);
3901 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3902 if (!(flags & State_Enabled))
3903 stateId = SCRBS_DISABLED;
3904 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_Sunken))
3905 stateId = SCRBS_PRESSED;
3906 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_MouseOver))
3907 stateId = SCRBS_HOT;
3909 stateId = SCRBS_NORMAL;
3910 theme.partId = partId;
3911 theme.stateId = stateId;
3912 d->drawBackground(theme);
3914 if (sub & SC_ScrollBarSlider) {
3915 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3916 if (!(flags & State_Enabled))
3917 stateId = SCRBS_DISABLED;
3918 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_Sunken))
3919 stateId = SCRBS_PRESSED;
3920 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_MouseOver))
3921 stateId = SCRBS_HOT;
3922 else if (option->state & State_MouseOver)
3923 stateId = SCRBS_HOVER;
3925 stateId = SCRBS_NORMAL;
3928 theme.partId = flags & State_Horizontal ? SBP_THUMBBTNHORZ : SBP_THUMBBTNVERT;
3929 theme.stateId = stateId;
3930 d->drawBackground(theme);
3936#if QT_CONFIG(spinbox)
3938 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(option)) {
3939 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::SpinTheme);
3940 if (sb->frame && (sub & SC_SpinBoxFrame)) {
3941 partId = EP_EDITBORDER_NOSCROLL;
3942 if (!(flags & State_Enabled))
3943 stateId = ETS_DISABLED;
3944 else if (flags & State_MouseOver)
3946 else if (flags & State_HasFocus)
3947 stateId = ETS_SELECTED;
3949 stateId = ETS_NORMAL;
3951 QWindowsThemeData ftheme(widget, painter,
3952 QWindowsVistaStylePrivate::EditTheme,
3953 partId, stateId, r);
3958 ftheme.noContent = (widget !=
nullptr);
3959 d->drawBackground(ftheme);
3961 if (sub & SC_SpinBoxUp) {
3962 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
3964 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled) || !(flags & State_Enabled))
3965 stateId = UPS_DISABLED;
3966 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken))
3967 stateId = UPS_PRESSED;
3968 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_MouseOver))
3971 stateId = UPS_NORMAL;
3972 theme.partId = partId;
3973 theme.stateId = stateId;
3974 d->drawBackground(theme);
3976 if (sub & SC_SpinBoxDown) {
3977 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
3979 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled) || !(flags & State_Enabled))
3980 stateId = DNS_DISABLED;
3981 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken))
3982 stateId = DNS_PRESSED;
3983 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_MouseOver))
3986 stateId = DNS_NORMAL;
3987 theme.partId = partId;
3988 theme.stateId = stateId;
3989 d->drawBackground(theme);
3996 QWindowsStyle::drawComplexControl(control, option, painter, widget);