730bool QWindowsVistaStylePrivate::drawBackgroundThruNativeBuffer(QWindowsThemeData &themeData,
731 qreal additionalDevicePixelRatio,
732 qreal correctionFactor)
734 QPainter *painter = themeData.painter;
735 QRectF rectF = scaleRect(QRectF(themeData.rect), additionalDevicePixelRatio);
737 if ((themeData.rotate + 90) % 180 == 0) {
738 rectF = QRectF(0, 0, rectF.height(), rectF.width());
742 const bool hasCorrectionFactor = !qFuzzyCompare(correctionFactor, qreal(1));
743 QRect rect = rectF.toRect();
744 const QRect drawRect = hasCorrectionFactor
745 ? QRectF(rectF.topLeft() / correctionFactor, rectF.size() / correctionFactor).toRect()
747 int partId = themeData.partId;
748 int stateId = themeData.stateId;
749 int w = rect.width();
750 int h = rect.height();
754 bool stateHasData =
true;
755 bool hasAlpha =
false;
756 bool partIsTransparent;
757 bool potentialInvalidAlpha;
759 QString pixmapCacheKey = QStringLiteral(u"$qt_xp_");
760 pixmapCacheKey.append(themeName(themeData.theme));
761 pixmapCacheKey.append(QLatin1Char(
'p'));
762 pixmapCacheKey.append(QString::number(partId));
763 pixmapCacheKey.append(QLatin1Char(
's'));
764 pixmapCacheKey.append(QString::number(stateId));
765 pixmapCacheKey.append(QLatin1Char(
's'));
766 pixmapCacheKey.append(themeData.noBorder ? QLatin1Char(
'0') : QLatin1Char(
'1'));
767 pixmapCacheKey.append(QLatin1Char(
'b'));
768 pixmapCacheKey.append(themeData.noContent ? QLatin1Char(
'0') : QLatin1Char(
'1'));
769 pixmapCacheKey.append(QString::number(w));
770 pixmapCacheKey.append(QLatin1Char(
'w'));
771 pixmapCacheKey.append(QString::number(h));
772 pixmapCacheKey.append(QLatin1Char(
'h'));
773 pixmapCacheKey.append(QString::number(additionalDevicePixelRatio));
774 pixmapCacheKey.append(QLatin1Char(
'd'));
775 if (hasCorrectionFactor) {
776 pixmapCacheKey.append(QLatin1Char(
'c'));
777 pixmapCacheKey.append(QString::number(correctionFactor));
780 QPixmap cachedPixmap;
784 bool haveCachedPixmap =
false;
787 partIsTransparent = data.partIsTransparent;
788 hasAlpha = data.hasAlphaChannel;
789 alphaType = data.alphaType;
790 potentialInvalidAlpha = data.hadInvalidAlpha;
792 haveCachedPixmap = QPixmapCache::find(pixmapCacheKey, &cachedPixmap);
796 ::sprintf(buf,
"+ Pixmap(%3d, %3d) ]", w, h);
797 printf(
"---[ CACHED %s--------> Name(%-10s) Part(%d) State(%d)\n",
798 haveCachedPixmap ? buf :
"]-------------------",
799 qPrintable(themeData.name), themeData.partId, themeData.stateId);
803 BOOL tmt_borderonly =
false;
804 COLORREF tmt_transparentcolor = 0x0;
805 PROPERTYORIGIN proporigin = PO_NOTFOUND;
806 GetThemeBool(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERONLY, &tmt_borderonly);
807 GetThemeColor(themeData.handle(), themeData.partId, themeData.stateId, TMT_TRANSPARENTCOLOR, &tmt_transparentcolor);
808 GetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_CAPTIONMARGINS, &proporigin);
810 partIsTransparent = isTransparent(themeData);
812 potentialInvalidAlpha =
false;
813 GetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_GLYPHTYPE, &proporigin);
814 if (proporigin == PO_PART || proporigin == PO_STATE) {
815 int tmt_glyphtype = GT_NONE;
816 GetThemeEnumValue(themeData.handle(), themeData.partId, themeData.stateId, TMT_GLYPHTYPE, &tmt_glyphtype);
817 potentialInvalidAlpha = partIsTransparent && tmt_glyphtype == GT_IMAGEGLYPH;
821 printf(
"---[ NOT CACHED ]-----------------------> Name(%-10s) Part(%d) State(%d)\n",
822 qPrintable(themeData.name), themeData.partId, themeData.stateId);
823 printf(
"-->partIsTransparen = %d\n", partIsTransparent);
824 printf(
"-->potentialInvalidAlpha = %d\n", potentialInvalidAlpha);
825 showProperties(themeData);
828 bool wasAlphaSwapped =
false;
829 bool wasAlphaFixed =
false;
835 bool addBorderContentClipping =
false;
837 QRect area = drawRect;
838 if (themeData.noBorder || themeData.noContent) {
845 PROPERTYORIGIN origin = PO_NOTFOUND;
846 GetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERSIZE, &origin);
847 GetThemeInt(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERSIZE, &borderSize);
848 borderSize *= additionalDevicePixelRatio;
851 if ((origin == PO_CLASS || origin == PO_PART || origin == PO_STATE) && borderSize > 0) {
852 if (themeData.noBorder) {
854 area = area.adjusted(-borderSize, -borderSize, borderSize, borderSize);
858 if (themeData.noContent) {
859 QRegion content = area.adjusted(borderSize, borderSize, -borderSize, -borderSize);
860 extraClip ^= content;
863 addBorderContentClipping = (themeData.noBorder | themeData.noContent);
867 if (!haveCachedPixmap) {
868 if (!buffer(drawRect.width(), drawRect.height()))
870 HDC dc = bufferHDC();
873 if (alphaType != NoAlpha) {
875 memset(bufferPixels, 0x00, bufferW * drawRect.height() * 4);
879 int dx = area.x() - drawRect.x();
880 int dy = area.y() - drawRect.y();
885 DTBGOPTS drawOptions;
886 drawOptions.dwSize =
sizeof(drawOptions);
887 drawOptions.rcClip = themeData.toRECT(rect);
888 drawOptions.dwFlags = DTBG_CLIPRECT
889 | (themeData.noBorder ? DTBG_OMITBORDER : 0)
890 | (themeData.noContent ? DTBG_OMITCONTENT : 0);
893 RECT wRect(themeData.toRECT(area));
894 DrawThemeBackgroundEx(themeData.handle(), dc, themeData.partId, themeData.stateId, &wRect, &drawOptions);
901 memset(
static_cast<
void *>(&data), 0,
sizeof(data));
902 data.dataValid =
true;
903 alphaCache.insert(key, data);
906 hasAlpha = hasAlphaChannel(rect);
907 if (!hasAlpha && partIsTransparent)
908 potentialInvalidAlpha =
true;
909#if defined(DEBUG_XP_STYLE) && 1
910 dumpNativeDIB(drawRect.width(), drawRect.height());
915 if (potentialInvalidAlpha)
916 wasAlphaFixed = fixAlphaChannel(drawRect);
918 QImage::Format format;
919 if ((partIsTransparent && !wasAlphaSwapped) || (!partIsTransparent && hasAlpha)) {
920 format = QImage::Format_ARGB32_Premultiplied;
921 alphaType = RealAlpha;
922 }
else if (wasAlphaSwapped) {
923 format = QImage::Format_ARGB32_Premultiplied;
924 alphaType = MaskAlpha;
926 format = QImage::Format_RGB32;
931 swapAlphaChannel(rect,
true);
934#if defined(DEBUG_XP_STYLE) && 1
935 printf(
"Image format is: %s\n", alphaType == RealAlpha ?
"Real Alpha" : alphaType == MaskAlpha ?
"Masked Alpha" :
"No Alpha");
937 img = QImage(bufferPixels, bufferW, bufferH, format);
938 if (themeData.invertPixels)
941 if (hasCorrectionFactor)
942 img = img.scaled(img.size() * correctionFactor, Qt::KeepAspectRatio, Qt::SmoothTransformation);
943 img.setDevicePixelRatio(additionalDevicePixelRatio);
947 bool useRegion = partIsTransparent && !hasAlpha && !wasAlphaSwapped;
952 newRegion = region(themeData);
953 oldRegion = painter->clipRegion();
954 painter->setClipRegion(newRegion);
955#if defined(DEBUG_XP_STYLE) && 0
956 printf(
"Using region:\n");
957 for (
const QRect &r : newRegion)
958 printf(
" (%d, %d, %d, %d)\n", r.x(), r.y(), r.right(), r.bottom());
962 if (addBorderContentClipping)
963 painter->setClipRegion(scaleRegion(extraClip, 1.0 / additionalDevicePixelRatio), Qt::IntersectClip);
965 if (!themeData.mirrorHorizontally && !themeData.mirrorVertically && !themeData.rotate) {
966 if (!haveCachedPixmap)
967 painter->drawImage(themeData.rect, img, rect);
969 painter->drawPixmap(themeData.rect, cachedPixmap);
977 if (!haveCachedPixmap)
978 imgCopy = img.copy(rect);
980 imgCopy = cachedPixmap.toImage();
982 if (themeData.rotate) {
983 QTransform rotMatrix;
984 rotMatrix.rotate(themeData.rotate);
985 imgCopy = imgCopy.transformed(rotMatrix);
987 Qt::Orientations orient = {};
988 if (themeData.mirrorHorizontally)
989 orient |= Qt::Horizontal;
990 if (themeData.mirrorVertically)
991 orient |= Qt::Vertical;
992 if (themeData.mirrorHorizontally || themeData.mirrorVertically)
993 imgCopy.flip(orient);
994 painter->drawImage(themeData.rect, imgCopy);
997 if (useRegion || addBorderContentClipping) {
998 if (oldRegion.isEmpty())
999 painter->setClipping(
false);
1001 painter->setClipRegion(oldRegion);
1005 if (!haveCachedPixmap && w && h) {
1006 QPixmap pix = QPixmap::fromImage(img).copy(rect);
1007 QPixmapCache::insert(pixmapCacheKey, pix);
1008#ifdef DEBUG_XP_STYLE
1009 printf(
"+++Adding pixmap to cache, size(%d, %d), wasAlphaSwapped(%d), wasAlphaFixed(%d), name(%s)\n",
1010 w, h, wasAlphaSwapped, wasAlphaFixed, qPrintable(pixmapCacheKey));
1016 memset(
static_cast<
void *>(&data), 0,
sizeof(data));
1017 data.dataValid =
true;
1018 data.partIsTransparent = partIsTransparent;
1019 data.alphaType = alphaType;
1020 data.hasAlphaChannel = hasAlpha;
1021 data.wasAlphaSwapped = wasAlphaSwapped;
1022 data.hadInvalidAlpha = wasAlphaFixed;
1023 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;
2470 if (d->transitionsEnabled() && (btn->features & QStyleOptionButton::DefaultButton) &&
2471 !(state & (State_Sunken | State_On)) && !(state & State_MouseOver) &&
2472 (state & State_Enabled) && (state & State_Active))
2474 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)));
2477 QImage startImage = createAnimationBuffer(option, widget);
2478 QImage alternateImage = createAnimationBuffer(option, widget);
2482 QPainter startPainter(&startImage);
2483 stateId = PBS_DEFAULTED;
2484 QWindowsThemeData theme(widget, &startPainter, themeNumber, partId, stateId, rect);
2485 d->drawBackground(theme);
2487 QPainter alternatePainter(&alternateImage);
2488 theme.stateId = PBS_DEFAULTED_ANIMATING;
2489 theme.painter = &alternatePainter;
2490 d->drawBackground(theme);
2492 pulse->setStartImage(startImage);
2493 pulse->setEndImage(alternateImage);
2494 pulse->setStartTime(d->animationTime());
2495 pulse->setDuration(2000);
2496 d->startAnimation(pulse);
2501 anim->paint(painter, option);
2503 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2504 d->drawBackground(theme);
2508 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2509 d->drawBackground(theme);
2513 if (btn->features & QStyleOptionButton::HasMenu) {
2514 int mbiw = 0, mbih = 0;
2515 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::ToolBarTheme,
2517 if (theme.isValid()) {
2518 const QSizeF size = theme.size() * QStyleHelper::dpiScaled(1, option);
2519 if (!size.isEmpty()) {
2520 mbiw = qRound(size.width());
2521 mbih = qRound(size.height());
2524 QRect ir = subElementRect(SE_PushButtonContents, option,
nullptr);
2525 QStyleOptionButton newBtn = *btn;
2526 newBtn.rect = QStyle::visualRect(option->direction, option->rect,
2527 QRect(ir.right() - mbiw - 2,
2528 option->rect.top() + (option->rect.height()/2) - (mbih/2),
2529 mbiw + 1, mbih + 1));
2530 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
2536 themeNumber = QWindowsVistaStylePrivate::StatusTheme;
2537 partId = SP_GRIPPER;
2538 QWindowsThemeData theme(
nullptr, painter, themeNumber, partId);
2539 QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize();
2541 if (
const auto *sg = qstyleoption_cast<
const QStyleOptionSizeGrip *>(option)) {
2542 switch (sg->corner) {
2543 case Qt::BottomRightCorner:
2544 rect = QRect(QPoint(rect.right() - size.width(), rect.bottom() - size.height()), size);
2546 case Qt::BottomLeftCorner:
2547 rect = QRect(QPoint(rect.left() + 1, rect.bottom() - size.height()), size);
2550 case Qt::TopRightCorner:
2551 rect = QRect(QPoint(rect.right() - size.width(), rect.top() + 1), size);
2554 case Qt::TopLeftCorner:
2555 rect = QRect(rect.topLeft() + QPoint(1, 1), size);
2556 hMirrored = vMirrored =
true;
2563 painter->eraseRect(option->rect);
2567#if QT_CONFIG(tabwidget)
2568 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option))
2569 stateId = tab->state & State_Enabled ? TIS_NORMAL : TIS_DISABLED;
2573 case CE_TabBarTabShape:
2574#if QT_CONFIG(tabwidget)
2575 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option)) {
2576 themeNumber = QWindowsVistaStylePrivate::TabTheme;
2577 const bool isDisabled = !(tab->state & State_Enabled);
2578 const bool hasFocus = tab->state & State_HasFocus;
2579 const bool isHot = tab->state & State_MouseOver;
2580 const bool selected = tab->state & State_Selected;
2581 bool lastTab = tab->position == QStyleOptionTab::End;
2582 bool firstTab = tab->position == QStyleOptionTab::Beginning;
2583 const bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
2584 const bool leftAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignLeft;
2585 const bool centerAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignCenter;
2586 const int borderThickness = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
2587 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, option, widget);
2590 stateId = TIS_DISABLED;
2592 stateId = TIS_SELECTED;
2594 stateId = TIS_FOCUSED;
2598 stateId = TIS_NORMAL;
2601 if (firstTab || onlyOne) {
2603 partId = TABP_TABITEMLEFTEDGE;
2604 else if (centerAligned)
2605 partId = TABP_TABITEM;
2607 partId = TABP_TABITEMRIGHTEDGE;
2609 partId = TABP_TABITEM;
2612 if (tab->direction == Qt::RightToLeft
2613 && (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth)) {
2614 bool temp = firstTab;
2619 const bool begin = firstTab || onlyOne;
2620 const bool end = lastTab || onlyOne;
2622 switch (tab->shape) {
2623 case QTabBar::RoundedNorth:
2625 rect.adjust(begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap, borderThickness);
2627 rect.adjust(begin? tabOverlap : 0, tabOverlap, end ? -tabOverlap : 0, 0);
2629 case QTabBar::RoundedSouth:
2633 rect.adjust(begin ? 0 : -tabOverlap , -borderThickness, end ? 0 : tabOverlap, 0);
2635 rect.adjust(begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0 , -tabOverlap);
2637 case QTabBar::RoundedEast:
2640 rect.adjust(-borderThickness, begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap);
2642 rect.adjust(0, begin ? tabOverlap : 0, -tabOverlap, end ? -tabOverlap : 0);
2644 case QTabBar::RoundedWest:
2648 rect.adjust(0, begin ? 0 : -tabOverlap, borderThickness, end ? 0 : tabOverlap);
2650 rect.adjust(tabOverlap, begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0);
2658 switch (tab->shape) {
2659 case QTabBar::RoundedNorth:
2660 rect.adjust(0,0, 0,-1);
2662 case QTabBar::RoundedSouth:
2663 rect.adjust(0,1, 0,0);
2665 case QTabBar::RoundedEast:
2666 rect.adjust( 1,0, 0,0);
2668 case QTabBar::RoundedWest:
2669 rect.adjust(0,0, -1,0);
2679 case CE_ProgressBarGroove: {
2680 Qt::Orientation orient = Qt::Horizontal;
2681 if (
const auto *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(option))
2682 if (!(pb->state & QStyle::State_Horizontal))
2683 orient = Qt::Vertical;
2685 partId = (orient == Qt::Horizontal) ? PP_BAR : PP_BARVERT;
2686 themeNumber = QWindowsVistaStylePrivate::ProgressTheme;
2691 case CE_ProgressBarContents:
2692 if (
const auto *bar = qstyleoption_cast<
const QStyleOptionProgressBar *>(option)) {
2693 bool isIndeterminate = (bar->minimum == 0 && bar->maximum == 0);
2694 const bool vertical = !(bar->state & QStyle::State_Horizontal);
2695 const bool inverted = bar->invertedAppearance;
2697 if (isIndeterminate || (bar->progress > 0 && (bar->progress < bar->maximum) && d->transitionsEnabled())) {
2698 if (!d->animation(styleObject(option)))
2699 d->startAnimation(
new QProgressStyleAnimation(d->animationFps, styleObject(option)));
2701 d->stopAnimation(styleObject(option));
2704 QWindowsThemeData theme(widget, painter,
2705 QWindowsVistaStylePrivate::ProgressTheme,
2706 vertical ? PP_FILLVERT : PP_FILL);
2707 theme.rect = option->rect;
2708 bool reverse = (bar->direction == Qt::LeftToRight && inverted) || (bar->direction == Qt::RightToLeft && !inverted);
2709 QTime current = d->animationTime();
2711 if (isIndeterminate) {
2712 if (
auto *progressAnimation = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2714 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2715 int animOffset = progressAnimation->startTime().msecsTo(current) / 4;
2716 if (animOffset > animationWidth)
2717 progressAnimation->setStartTime(d->animationTime());
2719 painter->setClipRect(theme.rect);
2721 QSize pixmapSize(14, 14);
2723 animRect = QRect(theme.rect.left(),
2724 inverted ? rect.top() - glowSize + animOffset :
2725 rect.bottom() + glowSize - animOffset,
2726 rect.width(), glowSize);
2727 pixmapSize.setHeight(animRect.height());
2729 animRect = QRect(rect.left() - glowSize + animOffset,
2730 rect.top(), glowSize, rect.height());
2731 animRect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2732 option->rect, animRect);
2733 pixmapSize.setWidth(animRect.width());
2735 QString name = QStringLiteral(u"qiprogress-%1-%2").arg(pixmapSize.width()).arg(pixmapSize.height());
2737 if (!QPixmapCache::find(name, &pixmap)) {
2738 QImage image(pixmapSize, QImage::Format_ARGB32);
2739 image.fill(Qt::transparent);
2741 theme.painter = &imagePainter;
2742 theme.partId = vertical ? PP_FILLVERT : PP_FILL;
2743 theme.rect = QRect(QPoint(0,0), animRect.size());
2744 QLinearGradient alphaGradient(0, 0, vertical ? 0 : image.width(),
2745 vertical ? image.height() : 0);
2746 alphaGradient.setColorAt(0, QColor(0, 0, 0, 0));
2747 alphaGradient.setColorAt(0.5, QColor(0, 0, 0, 220));
2748 alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
2749 imagePainter.fillRect(image.rect(), alphaGradient);
2750 imagePainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
2751 d->drawBackground(theme);
2753 pixmap = QPixmap::fromImage(image);
2754 QPixmapCache::insert(name, pixmap);
2756 painter->drawPixmap(animRect, pixmap);
2760 qint64 progress = qMax<qint64>(bar->progress, bar->minimum);
2763 int maxHeight = option->rect.height();
2765 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxHeight);
2766 int height = isIndeterminate ? maxHeight: qMax(
int(vc6_workaround), minHeight);
2767 theme.rect.setHeight(height);
2769 theme.rect.moveTop(rect.height() - theme.rect.height());
2771 int maxWidth = option->rect.width();
2773 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth);
2774 int width = isIndeterminate ? maxWidth : qMax(
int(vc6_workaround), minWidth);
2775 theme.rect.setWidth(width);
2776 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2777 option->rect, theme.rect);
2779 d->drawBackground(theme);
2781 if (QProgressStyleAnimation *a = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2783 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2784 int animOffset = a->startTime().msecsTo(current) / 4;
2785 theme.partId = vertical ? PP_MOVEOVERLAYVERT : PP_MOVEOVERLAY;
2786 if (animOffset > animationWidth) {
2787 if (bar->progress < bar->maximum)
2788 a->setStartTime(d->animationTime());
2790 d->stopAnimation(styleObject(option));
2794 painter->setClipRect(theme.rect);
2796 theme.rect = QRect(theme.rect.left(),
2797 inverted ? rect.top() - glowSize + animOffset :
2798 rect.bottom() + glowSize - animOffset,
2799 rect.width(), glowSize);
2801 theme.rect = QRect(rect.left() - glowSize + animOffset,rect.top(), glowSize, rect.height());
2802 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight, option->rect, theme.rect);
2804 d->drawBackground(theme);
2811 case CE_MenuBarItem:
2812 if (
const auto *mbi = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2813 if (mbi->menuItemType == QStyleOptionMenuItem::DefaultItem)
2816 QPalette::ColorRole textRole = disabled ? QPalette::Text : QPalette::ButtonText;
2817 const auto dpr = QStyleHelper::getDpr(widget);
2818 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2819 const auto pix = mbi->icon.pixmap(QSize(extent, extent), dpr, QIcon::Normal);
2821 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2822 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
2823 alignment |= Qt::TextHideMnemonic;
2825 if (widget && mbi->palette.color(QPalette::Window) != Qt::transparent) {
2827 QWindowsThemeData theme(widget, painter,
2828 QWindowsVistaStylePrivate::MenuTheme,
2829 MENU_BARBACKGROUND, 0, option->rect.adjusted(-1, 0, 2, 1));
2830 d->drawBackground(theme);
2832 int stateId = MBI_NORMAL;
2834 stateId = MBI_DISABLED;
2836 stateId = MBI_PUSHED;
2840 QWindowsThemeData theme2(widget, painter,
2841 QWindowsVistaStylePrivate::MenuTheme,
2842 MENU_BARITEM, stateId, option->rect);
2843 d->drawBackground(theme2);
2847 drawItemPixmap(painter, mbi->rect, alignment, pix);
2849 drawItemText(painter, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled, mbi->text, textRole);
2854 case CE_MenuEmptyArea:
2855 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2856 QBrush fill = menuitem->palette.brush((menuitem->state & State_Selected) ?
2857 QPalette::Highlight : QPalette::Button);
2858 painter->fillRect(rect, fill);
2864 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2866 const qreal factor = QWindowsVistaStylePrivate::nativeMetricScaleFactor(widget);
2867 int checkcol = qRound(qreal(25) * factor);
2868 const int gutterWidth = qRound(qreal(3) * factor);
2870 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::MenuTheme,
2871 MENU_POPUPCHECKBACKGROUND, MBI_HOT);
2872 QWindowsThemeData themeSize = theme;
2873 themeSize.partId = MENU_POPUPCHECK;
2874 themeSize.stateId = 0;
2875 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2876 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2877 checkcol = qMax(menuitem->maxIconWidth, qRound(gutterWidth + size.width() + margins.left() + margins.right()));
2879 QRect rect = option->rect;
2882 QWindowsThemeData popupbackgroundTheme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2883 MENU_POPUPBACKGROUND, stateId, option->rect);
2884 d->drawBackground(popupbackgroundTheme);
2887 if (option->direction == Qt::LeftToRight)
2888 checkcol += rect.x();
2889 QPoint p1 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.top()));
2890 QPoint p2 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.bottom()));
2891 QRect gutterRect(p1.x(), p1.y(), gutterWidth, p2.y() - p1.y() + 1);
2892 QWindowsThemeData theme2(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2893 MENU_POPUPGUTTER, stateId, gutterRect);
2894 d->drawBackground(theme2);
2897 menuitem->rect.getRect(&x, &y, &w, &h);
2898 int tab = menuitem->reservedShortcutWidth;
2899 bool dis = !(menuitem->state & State_Enabled);
2900 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
2901 ? menuitem->checked :
false;
2902 bool act = menuitem->state & State_Selected;
2904 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {
2905 int yoff = y-2 + h / 2;
2906 const int separatorSize = qRound(qreal(6) * QWindowsStylePrivate::nativeMetricScaleFactor(widget));
2907 QPoint p1 = QPoint(x + checkcol, yoff);
2908 QPoint p2 = QPoint(x + w + separatorSize, yoff);
2910 QRect subRect(p1.x() + (gutterWidth - menuitem->rect.x()), p1.y(),
2911 p2.x() - p1.x(), separatorSize);
2912 subRect = QStyle::visualRect(option->direction, option->rect, subRect );
2913 QWindowsThemeData theme2(widget, painter,
2914 QWindowsVistaStylePrivate::MenuTheme,
2915 MENU_POPUPSEPARATOR, stateId, subRect);
2916 d->drawBackground(theme2);
2920 QRect vCheckRect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x(),
2921 menuitem->rect.y(), checkcol - (gutterWidth + menuitem->rect.x()), menuitem->rect.height()));
2924 stateId = dis ? MBI_DISABLED : MBI_HOT;
2925 QWindowsThemeData theme2(widget, painter,
2926 QWindowsVistaStylePrivate::MenuTheme,
2927 MENU_POPUPITEM, stateId, option->rect);
2928 d->drawBackground(theme2);
2932 QWindowsThemeData theme(widget, painter,
2933 QWindowsVistaStylePrivate::MenuTheme,
2934 MENU_POPUPCHECKBACKGROUND,
2935 menuitem->icon.isNull() ? MBI_HOT : MBI_PUSHED, vCheckRect);
2936 QWindowsThemeData themeSize = theme;
2937 themeSize.partId = MENU_POPUPCHECK;
2938 themeSize.stateId = 0;
2939 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2940 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2941 QRect checkRect(0, 0, qRound(size.width() + margins.left() + margins.right()),
2942 qRound(size.height() + margins.bottom() + margins.top()));
2943 checkRect.moveCenter(vCheckRect.center());
2944 theme.rect = checkRect;
2946 d->drawBackground(theme);
2948 if (menuitem->icon.isNull()) {
2949 checkRect = QRect(QPoint(0, 0), size.toSize());
2950 checkRect.moveCenter(theme.rect.center());
2951 theme.rect = checkRect;
2953 theme.partId = MENU_POPUPCHECK;
2954 bool bullet = menuitem->checkType & QStyleOptionMenuItem::Exclusive;
2956 theme.stateId = bullet ? MC_BULLETDISABLED: MC_CHECKMARKDISABLED;
2958 theme.stateId = bullet ? MC_BULLETNORMAL: MC_CHECKMARKNORMAL;
2959 d->drawBackground(theme);
2963 if (!menuitem->icon.isNull()) {
2964 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
2966 mode = QIcon::Active;
2967 const auto size = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2968 QRect pmr(QPoint(0, 0), QSize(size, size));
2969 pmr.moveCenter(vCheckRect.center());
2970 menuitem->icon.paint(painter, vCheckRect, Qt::AlignCenter, mode,
2971 checked ? QIcon::On : QIcon::Off);
2974 painter->setPen(menuitem->palette.buttonText().color());
2976 const QColor textColor = menuitem->palette.text().color();
2978 painter->setPen(textColor);
2980 int xm = windowsItemFrame + checkcol + windowsItemHMargin + (gutterWidth - menuitem->rect.x()) - 1;
2981 int xpos = menuitem->rect.x() + xm;
2982 QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
2983 QRect vTextRect = visualRect(option->direction, menuitem->rect, textRect);
2984 QString s = menuitem->text;
2987 int t = s.indexOf(QLatin1Char(
'\t'));
2988 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2989 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
2990 text_flags |= Qt::TextHideMnemonic;
2991 text_flags |= Qt::AlignLeft;
2993 QRect vShortcutRect = visualRect(option->direction, menuitem->rect,
2994 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
2995 painter->drawText(vShortcutRect, text_flags, s.mid(t + 1));
2998 QFont font = menuitem->font;
2999 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
3001 painter->setFont(font);
3002 painter->setPen(textColor);
3003 painter->drawText(vTextRect, text_flags, s.left(t));
3006 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {
3007 int dim = (h - 2 * windowsItemFrame) / 2;
3008 PrimitiveElement arrow;
3009 arrow = (option->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
3010 xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim;
3011 QRect vSubMenuRect = visualRect(option->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
3012 QStyleOptionMenuItem newMI = *menuitem;
3013 newMI.rect = vSubMenuRect;
3014 newMI.state = dis ? State_None : State_Enabled;
3015 proxy()->drawPrimitive(arrow, &newMI, painter, widget);
3021 case CE_HeaderSection:
3022 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(option)) {
3023 partId = HP_HEADERITEM;
3024 if (flags & State_Sunken)
3025 stateId = HIS_PRESSED;
3026 else if (flags & State_MouseOver)
3029 stateId = HIS_NORMAL;
3031 if (header->sortIndicator != QStyleOptionHeader::None)
3034 QWindowsThemeData theme(widget, painter,
3035 QWindowsVistaStylePrivate::HeaderTheme,
3036 partId, stateId, option->rect);
3037 d->drawBackground(theme);
3041 case CE_MenuBarEmptyArea: {
3042 stateId = MBI_NORMAL;
3043 if (!(state & State_Enabled))
3044 stateId = MBI_DISABLED;
3045 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
3046 MENU_BARBACKGROUND, stateId, option->rect);
3047 d->drawBackground(theme);
3052#if QT_CONFIG(toolbar)
3053 if (
const auto *toolbar = qstyleoption_cast<
const QStyleOptionToolBar *>(option)) {
3054 QPalette pal = option->palette;
3055 pal.setColor(QPalette::Dark, option->palette.window().color().darker(130));
3056 QStyleOptionToolBar copyOpt = *toolbar;
3057 copyOpt.palette = pal;
3058 QWindowsStyle::drawControl(element, ©Opt, painter, widget);
3063#if QT_CONFIG(dockwidget)
3064 case CE_DockWidgetTitle:
3065 if (
const auto *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(option)) {
3066 QRect rect = option->rect;
3067 const QDockWidget *dw = qobject_cast<
const QDockWidget *>(widget);
3068 bool isFloating = dw && dw->isFloating();
3069 int buttonMargin = 4;
3070 int mw = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, widget);
3071 int fw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, dwOpt, widget);
3073 const bool verticalTitleBar = dwOpt->verticalTitleBar;
3075 if (verticalTitleBar) {
3076 rect = rect.transposed();
3078 painter->translate(rect.left() - 1, rect.top() + rect.width());
3079 painter->rotate(-90);
3080 painter->translate(-rect.left() + 1, -rect.top());
3083 QRect r = option->rect.adjusted(0, 2, -1, -3);
3084 QRect titleRect = r;
3086 if (dwOpt->closable) {
3087 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton, dwOpt, widget).actualSize(QSize(10, 10));
3088 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3091 if (dwOpt->floatable) {
3092 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarMaxButton, dwOpt, widget).actualSize(QSize(10, 10));
3093 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3097 titleRect.adjust(0, -fw, 0, 0);
3098 if (widget && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey())
3099 titleRect.adjust(titleRect.height() + mw, 0, 0, 0);
3101 titleRect.adjust(mw, 0, 0, 0);
3102 if (!dwOpt->floatable && !dwOpt->closable)
3103 titleRect.adjust(0, 0, -mw, 0);
3106 if (!verticalTitleBar)
3107 titleRect = visualRect(dwOpt->direction, r, titleRect);
3110 const bool isActive = dwOpt->state & State_Active;
3111 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
3113 stateId = CS_ACTIVE;
3115 stateId = CS_INACTIVE;
3117 rect = rect.adjusted(-fw, -fw, fw, 0);
3119 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
3120 if (!theme.isValid())
3125 theme.partId = WP_SMALLCAPTION;
3126 d->drawBackground(theme);
3130 QIcon ico = widget->windowIcon();
3131 bool hasIcon = (ico.cacheKey() != QApplication::windowIcon().cacheKey());
3133 const auto titleHeight = rect.height() - 2;
3134 const auto dpr = QStyleHelper::getDpr(widget);
3135 const auto pxIco = ico.pixmap(QSize(titleHeight, titleHeight), dpr);
3136 if (!verticalTitleBar && dwOpt->direction == Qt::RightToLeft)
3137 painter->drawPixmap(rect.width() - titleHeight - pxIco.width(), rect.bottom() - titleHeight - 2, pxIco);
3139 painter->drawPixmap(fw, rect.bottom() - titleHeight - 2, pxIco);
3141 if (!dwOpt->title.isEmpty()) {
3142 QPen oldPen = painter->pen();
3143 QFont oldFont = painter->font();
3144 QFont titleFont = oldFont;
3145 titleFont.setBold(
true);
3146 painter->setFont(titleFont);
3148 = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
3150 int result = TST_NONE;
3151 GetThemeEnumValue(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3152 if (result != TST_NONE) {
3153 COLORREF textShadowRef;
3154 GetThemeColor(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWCOLOR, &textShadowRef);
3155 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3156 painter->setPen(textShadow);
3157 drawItemText(painter, titleRect.adjusted(1, 1, 1, 1),
3158 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3159 dwOpt->state & State_Enabled, titleText);
3162 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3163 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3164 painter->setPen(textColor);
3165 drawItemText(painter, titleRect,
3166 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3167 dwOpt->state & State_Enabled, titleText);
3168 painter->setFont(oldFont);
3169 painter->setPen(oldPen);
3172 painter->setBrush(option->palette.window().color().darker(110));
3173 painter->setPen(option->palette.window().color().darker(130));
3174 painter->drawRect(rect.adjusted(0, 1, -1, -3));
3176 if (!dwOpt->title.isEmpty()) {
3177 QString titleText = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight,
3178 verticalTitleBar ? titleRect.height() : titleRect.width());
3179 const int indent = 4;
3180 drawItemText(painter, rect.adjusted(indent + 1, 1, -indent - 1, -1),
3181 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic,
3183 dwOpt->state & State_Enabled, titleText,
3184 QPalette::WindowText);
3191#if QT_CONFIG(rubberband)
3193 if (qstyleoption_cast<
const QStyleOptionRubberBand *>(option)) {
3194 QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
3196 painter->setPen(highlight.darker(120));
3197 QColor dimHighlight(qMin(highlight.red()/2 + 110, 255),
3198 qMin(highlight.green()/2 + 110, 255),
3199 qMin(highlight.blue()/2 + 110, 255),
3200 (widget && widget->isWindow())? 255 : 127);
3201 painter->setBrush(dimHighlight);
3202 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
3209 case CE_HeaderEmptyArea:
3210 if (option->state & State_Horizontal) {
3211 themeNumber = QWindowsVistaStylePrivate::HeaderTheme;
3212 stateId = HIS_NORMAL;
3214 QWindowsStyle::drawControl(CE_HeaderEmptyArea, option, painter, widget);
3219#if QT_CONFIG(itemviews)
3220 case CE_ItemViewItem: {
3221 const QStyleOptionViewItem *vopt;
3222 const QAbstractItemView *view = qobject_cast<
const QAbstractItemView *>(widget);
3223 bool newStyle =
true;
3225 if (qobject_cast<
const QTableView*>(widget))
3228 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3230 if (newStyle && view && (vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(option))) {
3232
3233
3234
3235
3236
3237
3238 QPalette palette = vopt->palette;
3239 palette.setColor(QPalette::All, QPalette::HighlightedText, palette.color(QPalette::Active, QPalette::Text));
3241 palette.setColor(QPalette::All, QPalette::Highlight, palette.base().color().darker(108));
3242 QStyleOptionViewItem adjustedOption = *vopt;
3243 adjustedOption.palette = palette;
3245 if ((view->selectionMode() == QAbstractItemView::SingleSelection)
3246 && !(vopt->state & State_KeyboardFocusChange))
3247 adjustedOption.state &= ~State_HasFocus;
3248 if (!theme.isValid()) {
3249 QWindowsStyle::drawControl(element, &adjustedOption, painter, widget);
3253 if (!theme.isValid()) {
3254 QWindowsStyle::drawControl(element, option, painter, widget);
3259 theme.rotate = rotate;
3260 theme.mirrorHorizontally = hMirrored;
3261 theme.mirrorVertically = vMirrored;
3262 d->drawBackground(theme);
3267#if QT_CONFIG(combobox)
3268 case CE_ComboBoxLabel:
3269 QCommonStyle::drawControl(element, option, painter, widget);
3277 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3279 if (!theme.isValid()) {
3280 QWindowsStyle::drawControl(element, option, painter, widget);
3284 theme.rotate = rotate;
3285 theme.mirrorHorizontally = hMirrored;
3286 theme.mirrorVertically = vMirrored;
3288 d->drawBackground(theme);
3296void QWindowsVistaStyle::drawComplexControl(ComplexControl control,
const QStyleOptionComplex *option,
3297 QPainter *painter,
const QWidget *widget)
const
3301 if (!QWindowsVistaStylePrivate::useVista()) {
3302 QWindowsStyle::drawComplexControl(control, option, painter, widget);
3306 State state = option->state;
3307 SubControls sub = option->subControls;
3308 QRect r = option->rect;
3313 State flags = option->state;
3314 if (widget && widget->testAttribute(Qt::WA_UnderMouse) && widget->isActiveWindow())
3315 flags |= State_MouseOver;
3317 if (d->transitionsEnabled() && canAnimate(option))
3319 if (control == CC_ScrollBar || control == CC_SpinBox || control == CC_ComboBox) {
3320 QObject *styleObject = option->styleObject;
3322 int oldState = styleObject->property(
"_q_stylestate").toInt();
3323 int oldActiveControls = styleObject->property(
"_q_stylecontrols").toInt();
3325 QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
3326 styleObject->setProperty(
"_q_stylestate",
int(option->state));
3327 styleObject->setProperty(
"_q_stylecontrols",
int(option->activeSubControls));
3328 styleObject->setProperty(
"_q_stylerect", option->rect);
3330 bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken)
3331 || (state & State_On) != (oldState & State_On)
3332 || (state & State_MouseOver) != (oldState & State_MouseOver)
3333 || oldActiveControls !=
int(option->activeSubControls));
3335 if (qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3336 QRect oldSliderPos = styleObject->property(
"_q_stylesliderpos").toRect();
3337 QRect currentPos = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3338 styleObject->setProperty(
"_q_stylesliderpos", currentPos);
3339 if (oldSliderPos != currentPos) {
3340 doTransition =
false;
3341 d->stopAnimation(styleObject);
3343 }
else if (control == CC_SpinBox) {
3346 doTransition = (state & State_HasFocus) != (oldState & State_HasFocus);
3349 if (oldRect != option->rect) {
3350 doTransition =
false;
3351 d->stopAnimation(styleObject);
3355 QImage startImage = createAnimationBuffer(option, widget);
3356 QPainter startPainter(&startImage);
3358 QImage endImage = createAnimationBuffer(option, widget);
3361 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
3365 QStyleOptionComplex *styleOption = qstyleoption_cast<QStyleOptionComplex*>(clonedAnimationStyleOption(option));
3367 styleObject->setProperty(
"_q_no_animation",
true);
3371 styleOption->state = QStyle::State(oldState);
3372 styleOption->activeSubControls = QStyle::SubControl(oldActiveControls);
3373 proxy()->drawComplexControl(control, styleOption, &startPainter, widget);
3375 anim->paint(&startPainter, option);
3377 t->setStartImage(startImage);
3380 styleOption->state = option->state;
3381 styleOption->activeSubControls = option->activeSubControls;
3382 proxy()->drawComplexControl(control, styleOption, &endPainter, widget);
3384 styleObject->setProperty(
"_q_no_animation",
false);
3386 t->setEndImage(endImage);
3387 t->setStartTime(d->animationTime());
3389 if (option->state & State_MouseOver || option->state & State_Sunken)
3390 t->setDuration(150);
3392 t->setDuration(500);
3394 deleteClonedAnimationStyleOption(styleOption);
3395 d->startAnimation(t);
3397 if (QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject))) {
3398 anim->paint(painter, option);
3406#if QT_CONFIG(slider)
3408 if (
const auto *slider = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3409 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::TrackBarTheme);
3410 QRect slrect = slider->rect;
3411 QRegion tickreg = slrect;
3412 if (sub & SC_SliderGroove) {
3413 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
3414 if (slider->orientation == Qt::Horizontal) {
3416 stateId = TRS_NORMAL;
3417 theme.rect = QRect(slrect.left(), theme.rect.center().y() - 2, slrect.width(), 4);
3419 partId = TKP_TRACKVERT;
3420 stateId = TRVS_NORMAL;
3421 theme.rect = QRect(theme.rect.center().x() - 2, slrect.top(), 4, slrect.height());
3423 theme.partId = partId;
3424 theme.stateId = stateId;
3425 d->drawBackground(theme);
3426 tickreg -= theme.rect;
3428 if (sub & SC_SliderTickmarks) {
3429 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
3430 int ticks = slider->tickPosition;
3431 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
3432 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3433 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3434 int interval = slider->tickInterval;
3435 if (interval <= 0) {
3436 interval = slider->singleStep;
3437 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3439 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3441 interval = slider->pageStep;
3445 int fudge = len / 2;
3447 int bothOffset = (ticks & QSlider::TicksAbove && ticks & QSlider::TicksBelow) ? 1 : 0;
3448 painter->setPen(d->sliderTickColor);
3449 QVarLengthArray<QLine, 32> lines;
3450 int v = slider->minimum;
3451 while (v <= slider->maximum + 1) {
3452 if (v == slider->maximum + 1 && interval == 1)
3454 const int v_ = qMin(v, slider->maximum);
3455 int tickLength = (v_ == slider->minimum || v_ >= slider->maximum) ? 4 : 3;
3456 pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3457 v_, available) + fudge;
3458 if (slider->orientation == Qt::Horizontal) {
3459 if (ticks & QSlider::TicksAbove) {
3460 lines.append(QLine(pos, tickOffset - 1 - bothOffset,
3461 pos, tickOffset - 1 - bothOffset - tickLength));
3464 if (ticks & QSlider::TicksBelow) {
3465 lines.append(QLine(pos, tickOffset + thickness + bothOffset,
3466 pos, tickOffset + thickness + bothOffset + tickLength));
3469 if (ticks & QSlider::TicksAbove) {
3470 lines.append(QLine(tickOffset - 1 - bothOffset, pos,
3471 tickOffset - 1 - bothOffset - tickLength, pos));
3474 if (ticks & QSlider::TicksBelow) {
3475 lines.append(QLine(tickOffset + thickness + bothOffset, pos,
3476 tickOffset + thickness + bothOffset + tickLength, pos));
3480 int nextInterval = v + interval;
3481 if (nextInterval < v)
3485 if (!lines.isEmpty()) {
3487 painter->translate(slrect.topLeft());
3488 painter->drawLines(lines.constData(), lines.size());
3492 if (sub & SC_SliderHandle) {
3493 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
3494 if (slider->orientation == Qt::Horizontal) {
3495 if (slider->tickPosition == QSlider::TicksAbove)
3496 partId = TKP_THUMBTOP;
3497 else if (slider->tickPosition == QSlider::TicksBelow)
3498 partId = TKP_THUMBBOTTOM;
3502 if (!(slider->state & State_Enabled))
3503 stateId = TUS_DISABLED;
3504 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3505 stateId = TUS_PRESSED;
3506 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3508 else if (flags & State_HasFocus)
3509 stateId = TUS_FOCUSED;
3511 stateId = TUS_NORMAL;
3513 if (slider->tickPosition == QSlider::TicksLeft)
3514 partId = TKP_THUMBLEFT;
3515 else if (slider->tickPosition == QSlider::TicksRight)
3516 partId = TKP_THUMBRIGHT;
3518 partId = TKP_THUMBVERT;
3520 if (!(slider->state & State_Enabled))
3521 stateId = TUVS_DISABLED;
3522 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3523 stateId = TUVS_PRESSED;
3524 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3526 else if (flags & State_HasFocus)
3527 stateId = TUVS_FOCUSED;
3529 stateId = TUVS_NORMAL;
3531 theme.partId = partId;
3532 theme.stateId = stateId;
3533 d->drawBackground(theme);
3535 if (slider->state & State_HasFocus) {
3536 QStyleOptionFocusRect fropt;
3537 fropt.QStyleOption::operator=(*slider);
3538 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
3539 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3545#if QT_CONFIG(toolbutton)
3547 if (
const auto *toolbutton = qstyleoption_cast<
const QStyleOptionToolButton *>(option)) {
3548 QRect button, menuarea;
3549 button = proxy()->subControlRect(control, toolbutton, SC_ToolButton, widget);
3550 menuarea = proxy()->subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
3552 State bflags = toolbutton->state & ~State_Sunken;
3553 State mflags = bflags;
3554 bool autoRaise = flags & State_AutoRaise;
3556 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled))
3557 bflags &= ~State_Raised;
3560 if (toolbutton->state & State_Sunken) {
3561 if (toolbutton->activeSubControls & SC_ToolButton) {
3562 bflags |= State_Sunken;
3563 mflags |= State_MouseOver | State_Sunken;
3564 }
else if (toolbutton->activeSubControls & SC_ToolButtonMenu) {
3565 mflags |= State_Sunken;
3566 bflags |= State_MouseOver;
3570 QStyleOption tool = *toolbutton;
3571 if (toolbutton->subControls & SC_ToolButton) {
3572 if (flags & (State_Sunken | State_On | State_Raised) || !autoRaise) {
3573 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup && autoRaise) {
3574 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ToolBarTheme);
3575 theme.partId = TP_SPLITBUTTON;
3576 theme.rect = button;
3577 if (!(bflags & State_Enabled))
3578 stateId = TS_DISABLED;
3579 else if (bflags & State_Sunken)
3580 stateId = TS_PRESSED;
3581 else if (bflags & State_MouseOver || !(flags & State_AutoRaise))
3582 stateId = flags & State_On ? TS_HOTCHECKED : TS_HOT;
3583 else if (bflags & State_On)
3584 stateId = TS_CHECKED;
3586 stateId = TS_NORMAL;
3587 if (option->direction == Qt::RightToLeft)
3588 theme.mirrorHorizontally =
true;
3589 theme.stateId = stateId;
3590 d->drawBackground(theme);
3592 tool.rect = option->rect;
3593 tool.state = bflags;
3595 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
3597 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter, widget);
3602 if (toolbutton->state & State_HasFocus) {
3603 QStyleOptionFocusRect fr;
3604 fr.QStyleOption::operator=(*toolbutton);
3605 fr.rect.adjust(3, 3, -3, -3);
3606 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
3607 fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator,
3608 toolbutton, widget), 0);
3609 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
3611 QStyleOptionToolButton label = *toolbutton;
3612 label.state = bflags;
3615 label.state &= ~State_Sunken;
3616 label.rect = button.adjusted(fw, fw, -fw, -fw);
3617 proxy()->drawControl(CE_ToolButtonLabel, &label, painter, widget);
3619 if (toolbutton->subControls & SC_ToolButtonMenu) {
3620 tool.rect = menuarea;
3621 tool.state = mflags;
3623 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, painter, widget);
3625 tool.state = mflags;
3626 menuarea.adjust(-2, 0, 0, 0);
3628 if ((bflags & State_Sunken) != (mflags & State_Sunken)){
3630 painter->setClipRect(menuarea);
3631 tool.rect = option->rect;
3632 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter,
nullptr);
3637 painter->setPen(option->palette.dark().color());
3638 painter->drawLine(menuarea.left(), menuarea.top() + 3,
3639 menuarea.left(), menuarea.bottom() - 3);
3640 painter->setPen(option->palette.light().color());
3641 painter->drawLine(menuarea.left() - 1, menuarea.top() + 3,
3642 menuarea.left() - 1, menuarea.bottom() - 3);
3644 tool.rect = menuarea.adjusted(2, 3, -2, -1);
3645 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
3648 }
else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
3649 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
3650 QRect ir = toolbutton->rect;
3651 QStyleOptionToolButton newBtn = *toolbutton;
3652 newBtn.rect = QRect(ir.right() + 4 - mbi, ir.height() - mbi + 4, mbi - 5, mbi - 5);
3653 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
3660 if (
const auto *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(option)) {
3661 const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget);
3662 bool isActive = tb->titleBarState & QStyle::State_Active;
3663 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme);
3664 if (sub & SC_TitleBarLabel) {
3665 partId = (tb->titleBarState & Qt::WindowMinimized) ? WP_MINCAPTION : WP_CAPTION;
3666 theme.rect = option->rect;
3667 if (widget && !widget->isEnabled())
3668 stateId = CS_DISABLED;
3670 stateId = CS_ACTIVE;
3672 stateId = CS_INACTIVE;
3674 theme.partId = partId;
3675 theme.stateId = stateId;
3676 d->drawBackground(theme);
3678 QRect ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
3681 GetThemeEnumValue(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3683 COLORREF textShadowRef;
3684 GetThemeColor(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE,
TMT_TEXTSHADOWCOLOR, &textShadowRef);
3685 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3686 painter->setPen(textShadow);
3687 painter->drawText(
int(ir.x() + 3 * factor),
int(ir.y() + 2 * factor),
3688 int(ir.width() - 1 * factor), ir.height(),
3689 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3691 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3692 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3693 painter->setPen(textColor);
3694 painter->drawText(
int(ir.x() + 2 * factor),
int(ir.y() + 1 * factor),
3695 int(ir.width() - 2 * factor), ir.height(),
3696 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3698 if (sub & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3699 theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarSysMenu, widget);
3700 partId = WP_SYSBUTTON;
3701 if ((widget && !widget->isEnabled()) || !isActive)
3702 stateId = SBS_DISABLED;
3703 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_Sunken))
3704 stateId = SBS_PUSHED;
3705 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_MouseOver))
3708 stateId = SBS_NORMAL;
3709 if (!tb->icon.isNull()) {
3710 tb->icon.paint(painter, theme.rect);
3712 theme.partId = partId;
3713 theme.stateId = stateId;
3714 if (theme.size().isEmpty()) {
3715 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, tb, widget);
3716 const auto dpr = QStyleHelper::getDpr(widget);
3717 const auto icon = proxy()->standardIcon(SP_TitleBarMenuButton, tb, widget);
3718 const auto pm = icon.pixmap(QSize(extent, extent), dpr);
3719 drawItemPixmap(painter, theme.rect, Qt::AlignCenter, pm);
3721 d->drawBackground(theme);
3726 if (sub & SC_TitleBarMinButton && tb->titleBarFlags & Qt::WindowMinimizeButtonHint
3727 && !(tb->titleBarState & Qt::WindowMinimized)) {
3728 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMinButton, isActive, WP_MINBUTTON, &theme);
3729 d->drawBackground(theme);
3731 if (sub & SC_TitleBarMaxButton && tb->titleBarFlags & Qt::WindowMaximizeButtonHint
3732 && !(tb->titleBarState & Qt::WindowMaximized)) {
3733 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMaxButton, isActive, WP_MAXBUTTON, &theme);
3734 d->drawBackground(theme);
3736 if (sub & SC_TitleBarContextHelpButton
3737 && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
3738 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarContextHelpButton, isActive, WP_HELPBUTTON, &theme);
3739 d->drawBackground(theme);
3741 bool drawNormalButton = (sub & SC_TitleBarNormalButton)
3742 && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3743 && (tb->titleBarState & Qt::WindowMinimized))
3744 || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3745 && (tb->titleBarState & Qt::WindowMaximized)));
3746 if (drawNormalButton) {
3747 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarNormalButton, isActive, WP_RESTOREBUTTON, &theme);
3748 d->drawBackground(theme);
3750 if (sub & SC_TitleBarShadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3751 && !(tb->titleBarState & Qt::WindowMinimized)) {
3752 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarShadeButton, isActive, WP_MINBUTTON, &theme);
3753 d->drawBackground(theme);
3755 if (sub & SC_TitleBarUnshadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3756 && tb->titleBarState & Qt::WindowMinimized) {
3757 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarUnshadeButton, isActive, WP_RESTOREBUTTON, &theme);
3758 d->drawBackground(theme);
3760 if (sub & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3761 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarCloseButton, isActive, WP_CLOSEBUTTON, &theme);
3762 d->drawBackground(theme);
3767#if QT_CONFIG(mdiarea)
3768 case CC_MdiControls: {
3769 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme, WP_MDICLOSEBUTTON, CBS_NORMAL);
3770 if (Q_UNLIKELY(!theme.isValid()))
3773 if (option->subControls.testFlag(SC_MdiCloseButton)) {
3774 populateMdiButtonTheme(proxy(), widget, option, SC_MdiCloseButton, WP_MDICLOSEBUTTON, &theme);
3775 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3777 if (option->subControls.testFlag(SC_MdiNormalButton)) {
3778 populateMdiButtonTheme(proxy(), widget, option, SC_MdiNormalButton, WP_MDIRESTOREBUTTON, &theme);
3779 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3781 if (option->subControls.testFlag(QStyle::SC_MdiMinButton)) {
3782 populateMdiButtonTheme(proxy(), widget, option, SC_MdiMinButton, WP_MDIMINBUTTON, &theme);
3783 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3791 if (
const auto *dial = qstyleoption_cast<
const QStyleOptionSlider *>(option))
3792 QStyleHelper::drawDial(dial, painter);
3797 if (
const QStyleOptionComboBox *cmb = qstyleoption_cast<
const QStyleOptionComboBox *>(option)) {
3798 if (cmb->editable) {
3799 if (sub & SC_ComboBoxEditField) {
3800 partId = EP_EDITBORDER_NOSCROLL;
3801 if (!(flags & State_Enabled))
3802 stateId = ETS_DISABLED;
3803 else if (flags & State_MouseOver)
3805 else if (flags & State_HasFocus)
3806 stateId = ETS_FOCUSED;
3808 stateId = ETS_NORMAL;
3810 QWindowsThemeData theme(widget, painter,
3811 QWindowsVistaStylePrivate::EditTheme,
3812 partId, stateId, r);
3814 d->drawBackground(theme);
3816 if (sub & SC_ComboBoxArrow) {
3817 QRect subRect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3818 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3819 theme.rect = subRect;
3820 partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3822 if (!(cmb->state & State_Enabled))
3823 stateId = CBXS_DISABLED;
3824 else if (cmb->state & State_Sunken || cmb->state & State_On)
3825 stateId = CBXS_PRESSED;
3826 else if (cmb->state & State_MouseOver && option->activeSubControls & SC_ComboBoxArrow)
3829 stateId = CBXS_NORMAL;
3831 theme.partId = partId;
3832 theme.stateId = stateId;
3833 d->drawBackground(theme);
3837 if (sub & SC_ComboBoxFrame) {
3838 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3839 theme.rect = option->rect;
3840 theme.partId = CP_READONLY;
3841 if (!(cmb->state & State_Enabled))
3842 theme.stateId = CBXS_DISABLED;
3843 else if (cmb->state & State_Sunken || cmb->state & State_On)
3844 theme.stateId = CBXS_PRESSED;
3845 else if (cmb->state & State_MouseOver)
3846 theme.stateId = CBXS_HOT;
3848 theme.stateId = CBXS_NORMAL;
3849 d->drawBackground(theme);
3851 if (sub & SC_ComboBoxArrow) {
3852 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3853 theme.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3854 theme.partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3855 if (!(cmb->state & State_Enabled))
3856 theme.stateId = CBXS_DISABLED;
3858 theme.stateId = CBXS_NORMAL;
3859 d->drawBackground(theme);
3861 if ((sub & SC_ComboBoxEditField) && (flags & State_HasFocus)) {
3862 QStyleOptionFocusRect fropt;
3863 fropt.QStyleOption::operator=(*cmb);
3864 fropt.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget);
3865 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3872 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3873 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ScrollBarTheme);
3874 bool maxedOut = (scrollbar->maximum == scrollbar->minimum);
3876 flags &= ~State_Enabled;
3878 bool isHorz = flags & State_Horizontal;
3879 bool isRTL = option->direction == Qt::RightToLeft;
3880 if (sub & SC_ScrollBarAddLine) {
3881 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddLine, widget);
3882 partId = SBP_ARROWBTN;
3883 if (!(flags & State_Enabled))
3884 stateId = (isHorz ? (isRTL ? ABS_LEFTDISABLED : ABS_RIGHTDISABLED) : ABS_DOWNDISABLED);
3885 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_Sunken))
3886 stateId = (isHorz ? (isRTL ? ABS_LEFTPRESSED : ABS_RIGHTPRESSED) : ABS_DOWNPRESSED);
3887 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_MouseOver))
3888 stateId = (isHorz ? (isRTL ? ABS_LEFTHOT : ABS_RIGHTHOT) : ABS_DOWNHOT);
3889 else if (scrollbar->state & State_MouseOver)
3890 stateId = (isHorz ? (isRTL ? ABS_LEFTHOVER : ABS_RIGHTHOVER) : ABS_DOWNHOVER);
3892 stateId = (isHorz ? (isRTL ? ABS_LEFTNORMAL : ABS_RIGHTNORMAL) : ABS_DOWNNORMAL);
3893 theme.partId = partId;
3894 theme.stateId = stateId;
3895 d->drawBackground(theme);
3897 if (sub & SC_ScrollBarSubLine) {
3898 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubLine, widget);
3899 partId = SBP_ARROWBTN;
3900 if (!(flags & State_Enabled))
3901 stateId = (isHorz ? (isRTL ? ABS_RIGHTDISABLED : ABS_LEFTDISABLED) : ABS_UPDISABLED);
3902 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_Sunken))
3903 stateId = (isHorz ? (isRTL ? ABS_RIGHTPRESSED : ABS_LEFTPRESSED) : ABS_UPPRESSED);
3904 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_MouseOver))
3905 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOT : ABS_LEFTHOT) : ABS_UPHOT);
3906 else if (scrollbar->state & State_MouseOver)
3907 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOVER : ABS_LEFTHOVER) : ABS_UPHOVER);
3909 stateId = (isHorz ? (isRTL ? ABS_RIGHTNORMAL : ABS_LEFTNORMAL) : ABS_UPNORMAL);
3910 theme.partId = partId;
3911 theme.stateId = stateId;
3912 d->drawBackground(theme);
3915 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3916 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget));
3917 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget));
3918 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3919 stateId = SCRBS_DISABLED;
3920 theme.partId = partId;
3921 theme.stateId = stateId;
3922 d->drawBackground(theme);
3924 if (sub & SC_ScrollBarSubPage) {
3925 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget);
3926 partId = flags & State_Horizontal ? SBP_UPPERTRACKHORZ : SBP_UPPERTRACKVERT;
3927 if (!(flags & State_Enabled))
3928 stateId = SCRBS_DISABLED;
3929 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_Sunken))
3930 stateId = SCRBS_PRESSED;
3931 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_MouseOver))
3932 stateId = SCRBS_HOT;
3934 stateId = SCRBS_NORMAL;
3935 theme.partId = partId;
3936 theme.stateId = stateId;
3937 d->drawBackground(theme);
3939 if (sub & SC_ScrollBarAddPage) {
3940 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget);
3941 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3942 if (!(flags & State_Enabled))
3943 stateId = SCRBS_DISABLED;
3944 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_Sunken))
3945 stateId = SCRBS_PRESSED;
3946 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_MouseOver))
3947 stateId = SCRBS_HOT;
3949 stateId = SCRBS_NORMAL;
3950 theme.partId = partId;
3951 theme.stateId = stateId;
3952 d->drawBackground(theme);
3954 if (sub & SC_ScrollBarSlider) {
3955 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3956 if (!(flags & State_Enabled))
3957 stateId = SCRBS_DISABLED;
3958 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_Sunken))
3959 stateId = SCRBS_PRESSED;
3960 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_MouseOver))
3961 stateId = SCRBS_HOT;
3962 else if (option->state & State_MouseOver)
3963 stateId = SCRBS_HOVER;
3965 stateId = SCRBS_NORMAL;
3968 theme.partId = flags & State_Horizontal ? SBP_THUMBBTNHORZ : SBP_THUMBBTNVERT;
3969 theme.stateId = stateId;
3970 d->drawBackground(theme);
3976#if QT_CONFIG(spinbox)
3978 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(option)) {
3979 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::SpinTheme);
3980 if (sb->frame && (sub & SC_SpinBoxFrame)) {
3981 partId = EP_EDITBORDER_NOSCROLL;
3982 if (!(flags & State_Enabled))
3983 stateId = ETS_DISABLED;
3984 else if (flags & State_MouseOver)
3986 else if (flags & State_HasFocus)
3987 stateId = ETS_SELECTED;
3989 stateId = ETS_NORMAL;
3991 QWindowsThemeData ftheme(widget, painter,
3992 QWindowsVistaStylePrivate::EditTheme,
3993 partId, stateId, r);
3998 ftheme.noContent = (widget !=
nullptr);
3999 d->drawBackground(ftheme);
4001 if (sub & SC_SpinBoxUp) {
4002 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget).adjusted(0, 0, 0, 1);
4004 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled) || !(flags & State_Enabled))
4005 stateId = UPS_DISABLED;
4006 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken))
4007 stateId = UPS_PRESSED;
4008 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_MouseOver))
4011 stateId = UPS_NORMAL;
4012 theme.partId = partId;
4013 theme.stateId = stateId;
4014 d->drawBackground(theme);
4016 if (sub & SC_SpinBoxDown) {
4017 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
4019 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled) || !(flags & State_Enabled))
4020 stateId = DNS_DISABLED;
4021 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken))
4022 stateId = DNS_PRESSED;
4023 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_MouseOver))
4026 stateId = DNS_NORMAL;
4027 theme.partId = partId;
4028 theme.stateId = stateId;
4029 d->drawBackground(theme);
4036 QWindowsStyle::drawComplexControl(control, option, painter, widget);