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 QT_CONFIG(accessibility)
1630 if (QStyleHelper::isInstanceOf(option->styleObject, QAccessible::EditableText)
1631 || QStyleHelper::isInstanceOf(option->styleObject, QAccessible::StaticText) ||
1635 (widget && widget->inherits(
"QTextEdit"))) {
1637 int stateId = ETS_NORMAL;
1638 if (!(state & State_Enabled))
1639 stateId = ETS_DISABLED;
1640 else if (state & State_ReadOnly)
1641 stateId = ETS_READONLY;
1642 else if (state & State_HasFocus)
1643 stateId = ETS_SELECTED;
1644 QWindowsThemeData theme(widget, painter,
1645 QWindowsVistaStylePrivate::EditTheme,
1646 EP_EDITBORDER_HVSCROLL, stateId, option->rect);
1649 GetThemeInt(theme.handle(), theme.partId, theme.stateId, TMT_BORDERSIZE, &borderSize);
1650 QRegion clipRegion = option->rect;
1651 QRegion content = option->rect.adjusted(borderSize, borderSize, -borderSize, -borderSize);
1652 clipRegion ^= content;
1653 painter->setClipRegion(clipRegion);
1654 d->drawBackground(theme);
1658 if (option->state & State_Raised)
1661 themeNumber = QWindowsVistaStylePrivate::ListViewTheme;
1662 partId = LVP_LISTGROUP;
1663 QWindowsThemeData theme(widget,
nullptr, themeNumber, partId);
1665 if (!(option->state & State_Enabled))
1666 stateId = ETS_DISABLED;
1668 stateId = ETS_NORMAL;
1672 if (GetThemeEnumValue(theme.handle(), partId, stateId, TMT_BGTYPE, &fillType) == S_OK) {
1673 if (fillType == BT_BORDERFILL) {
1675 GetThemeColor(theme.handle(), partId, stateId, TMT_BORDERCOLOR, &bcRef);
1676 QColor bordercolor(qRgb(GetRValue(bcRef), GetGValue(bcRef), GetBValue(bcRef)));
1677 QPen oldPen = painter->pen();
1680 painter->setPen(QPen(option->palette.base().color(), 0));
1681 const qreal dpi = QStyleHelper::dpi(option);
1682 const auto topLevelAdjustment = QStyleHelper::dpiScaled(0.5, dpi);
1683 const auto bottomRightAdjustment = QStyleHelper::dpiScaled(-1, dpi);
1684 painter->drawRect(QRectF(option->rect).adjusted(topLevelAdjustment, topLevelAdjustment,
1685 bottomRightAdjustment, bottomRightAdjustment));
1687 painter->setPen(QPen(bordercolor, 0));
1688 painter->drawRect(QRectF(option->rect).adjusted(0, 0, -topLevelAdjustment, -topLevelAdjustment));
1689 painter->setPen(oldPen);
1692 if (fillType == BT_BORDERFILL || fillType == BT_NONE)
1698 case PE_FrameMenu: {
1699 int stateId = option->state & State_Active ? MB_ACTIVE : MB_INACTIVE;
1700 QWindowsThemeData theme(widget, painter,
1701 QWindowsVistaStylePrivate::MenuTheme,
1702 MENU_POPUPBORDERS, stateId, option->rect);
1703 d->drawBackground(theme);
1707 case PE_PanelMenuBar:
1710#if QT_CONFIG(dockwidget)
1711 case PE_IndicatorDockWidgetResizeHandle:
1714 case PE_FrameDockWidget:
1715 if (
const auto *frm = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1716 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
1717 if (option->state & State_Active)
1718 stateId = FS_ACTIVE;
1720 stateId = FS_INACTIVE;
1722 int fwidth = proxy()->pixelMetric(PM_DockWidgetFrameWidth, frm, widget);
1724 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
1726 if (!theme.isValid())
1729 theme.rect = QRect(frm->rect.x(), frm->rect.y(), frm->rect.x()+fwidth, frm->rect.height()-fwidth);
1730 theme.partId = WP_SMALLFRAMELEFT;
1731 d->drawBackground(theme);
1732 theme.rect = QRect(frm->rect.width()-fwidth, frm->rect.y(), fwidth, frm->rect.height()-fwidth);
1733 theme.partId = WP_SMALLFRAMERIGHT;
1734 d->drawBackground(theme);
1735 theme.rect = QRect(frm->rect.x(), frm->rect.bottom()-fwidth+1, frm->rect.width(), fwidth);
1736 theme.partId = WP_SMALLFRAMEBOTTOM;
1737 d->drawBackground(theme);
1743 case PE_FrameTabWidget:
1744#if QT_CONFIG(tabwidget)
1745 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(option)) {
1746 themeNumber = QWindowsVistaStylePrivate::TabTheme;
1750 bool useGradient =
true;
1751 const int maxlength = 256;
1752 wchar_t themeFileName[maxlength];
1753 wchar_t themeColor[maxlength];
1755 if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength,
nullptr, 0) == S_OK) {
1756 wchar_t *offset =
nullptr;
1757 if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char(
'\\')).unicode())) !=
nullptr) {
1759 if (!lstrcmp(offset, L"Luna.msstyles") && !lstrcmp(offset, L"Metallic"))
1760 useGradient =
false;
1766 QStyleOptionTabWidgetFrame frameOpt = *tab;
1767 frameOpt.rect = widget->rect();
1768 QRect contentsRect = subElementRect(SE_TabWidgetTabContents, &frameOpt, widget);
1769 QRegion reg = option->rect;
1770 reg -= contentsRect;
1771 painter->setClipRegion(reg);
1772 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
1773 theme.mirrorHorizontally = hMirrored;
1774 theme.mirrorVertically = vMirrored;
1775 d->drawBackground(theme);
1776 painter->setClipRect(contentsRect);
1780 switch (tab->shape) {
1781 case QTabBar::RoundedNorth:
1782 case QTabBar::TriangularNorth:
1784 case QTabBar::RoundedSouth:
1785 case QTabBar::TriangularSouth:
1788 case QTabBar::RoundedEast:
1789 case QTabBar::TriangularEast:
1792 case QTabBar::RoundedWest:
1793 case QTabBar::TriangularWest:
1803 case PE_FrameStatusBarItem:
1804 themeNumber = QWindowsVistaStylePrivate::StatusTheme;
1808 case PE_FrameWindow:
1809 if (
const auto *frm = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1810 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
1811 if (option->state & State_Active)
1812 stateId = FS_ACTIVE;
1814 stateId = FS_INACTIVE;
1816 int fwidth =
int((frm->lineWidth + frm->midLineWidth) / QWindowsStylePrivate::nativeMetricScaleFactor(widget));
1818 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
1819 if (!theme.isValid())
1823 theme.rect = QRect(option->rect.x(), option->rect.y()+fwidth, option->rect.x()+fwidth, option->rect.height()-fwidth);
1824 theme.partId = WP_FRAMELEFT;
1825 if (!d->drawBackground(theme)) {
1826 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1829 theme.rect = QRect(option->rect.width()-fwidth, option->rect.y()+fwidth, fwidth, option->rect.height()-fwidth);
1830 theme.partId = WP_FRAMERIGHT;
1831 if (!d->drawBackground(theme)) {
1832 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1835 theme.rect = QRect(option->rect.x(), option->rect.height()-fwidth, option->rect.width(), fwidth);
1836 theme.partId = WP_FRAMEBOTTOM;
1837 if (!d->drawBackground(theme)) {
1838 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1841 theme.rect = QRect(option->rect.x(), option->rect.y(), option->rect.width(), option->rect.y()+fwidth);
1842 theme.partId = WP_CAPTION;
1843 if (!d->drawBackground(theme))
1844 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1849 case PE_PanelLineEdit:
1850 if (
const auto *panel = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1851 bool isEnabled = state & State_Enabled;
1852 if (QWindowsVistaStylePrivate::isLineEditBaseColorSet(option, widget)) {
1853 painter->fillRect(panel->rect, panel->palette.brush(QPalette::Base));
1855 int partId = EP_BACKGROUND;
1856 int stateId = EBS_NORMAL;
1858 stateId = EBS_DISABLED;
1859 else if (option->state & State_ReadOnly)
1860 stateId = EBS_READONLY;
1861 else if (option->state & State_MouseOver)
1864 QWindowsThemeData theme(
nullptr, painter, QWindowsVistaStylePrivate::EditTheme,
1865 partId, stateId, rect);
1866 if (!theme.isValid()) {
1867 QWindowsStyle::drawPrimitive(element, option, painter, widget);
1871 GetThemeEnumValue(theme.handle(), partId, stateId, TMT_BGTYPE, &bgType);
1872 if (bgType == BT_IMAGEFILE) {
1873 d->drawBackground(theme);
1875 QBrush fillColor = option->palette.brush(QPalette::Base);
1877 PROPERTYORIGIN origin = PO_NOTFOUND;
1878 GetThemePropertyOrigin(theme.handle(), theme.partId, theme.stateId, TMT_FILLCOLOR, &origin);
1880 if ((origin == PO_PART || origin == PO_STATE)) {
1882 GetThemeColor(theme.handle(), partId, stateId, TMT_FILLCOLOR, &bgRef);
1883 fillColor = QBrush(qRgb(GetRValue(bgRef), GetGValue(bgRef), GetBValue(bgRef)));
1886 painter->fillRect(option->rect, fillColor);
1889 if (panel->lineWidth > 0)
1890 proxy()->drawPrimitive(PE_FrameLineEdit, panel, painter, widget);
1894 case PE_IndicatorButtonDropDown:
1895 themeNumber = QWindowsVistaStylePrivate::ToolBarTheme;
1896 partId = TP_SPLITBUTTONDROPDOWN;
1897 if (!(option->state & State_Enabled))
1898 stateId = TS_DISABLED;
1899 else if (option->state & State_Sunken)
1900 stateId = TS_PRESSED;
1901 else if (option->state & State_MouseOver)
1902 stateId = option->state & State_On ? TS_HOTCHECKED : TS_HOT;
1903 else if (option->state & State_On)
1904 stateId = TS_CHECKED;
1905 else if (!(option->state & State_AutoRaise))
1908 stateId = TS_NORMAL;
1909 if (option->direction == Qt::RightToLeft)
1913 case PE_FrameLineEdit:
1914 if (QWindowsVistaAnimation *animate = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)))) {
1915 animate->paint(painter, option);
1917 if (QWindowsVistaStylePrivate::isItemViewDelegateLineEdit(widget)) {
1919 QPen oldPen = painter->pen();
1921 painter->setPen(option->palette.base().color());
1922 painter->drawRect(option->rect.adjusted(1, 1, -2, -2));
1924 painter->setPen(option->palette.shadow().color());
1925 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
1926 painter->setPen(oldPen);
1929 int stateId = ETS_NORMAL;
1930 if (!(state & State_Enabled))
1931 stateId = ETS_DISABLED;
1932 else if (state & State_ReadOnly)
1933 stateId = ETS_READONLY;
1934 else if (state & State_HasFocus)
1935 stateId = ETS_SELECTED;
1936 else if (state & State_MouseOver)
1938 QWindowsThemeData theme(widget, painter,
1939 QWindowsVistaStylePrivate::EditTheme,
1940 EP_EDITBORDER_NOSCROLL, stateId, option->rect);
1941 theme.noContent =
true;
1943 QRegion clipRegion = option->rect;
1944 clipRegion -= option->rect.adjusted(2, 2, -2, -2);
1945 painter->setClipRegion(clipRegion);
1946 d->drawBackground(theme);
1951 case PE_FrameGroupBox:
1952 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
1953 partId = BP_GROUPBOX;
1954 if (!(option->state & State_Enabled))
1955 stateId = GBS_DISABLED;
1957 stateId = GBS_NORMAL;
1958 if (
const auto *frame = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1959 if (frame->features & QStyleOptionFrame::Flat) {
1961 QRect fr = frame->rect;
1962 QPoint p1(fr.x(), fr.y() + 1);
1963 QPoint p2(fr.x() + fr.width(), p1.y() + 1);
1964 rect = QRect(p1, p2);
1970 case PE_IndicatorToolBarHandle: {
1971 QWindowsThemeData theme;
1973 if (option->state & State_Horizontal) {
1974 theme = QWindowsThemeData(widget, painter,
1975 QWindowsVistaStylePrivate::RebarTheme,
1976 RP_GRIPPER, ETS_NORMAL, option->rect.adjusted(0, 1, -2, -2));
1977 rect = option->rect.adjusted(0, 1, 0, -2);
1980 theme = QWindowsThemeData(widget, painter, QWindowsVistaStylePrivate::RebarTheme,
1981 RP_GRIPPERVERT, ETS_NORMAL, option->rect.adjusted(0, 1, -2, -2));
1982 rect = option->rect.adjusted(1, 0, -1, 0);
1986 d->drawBackground(theme);
1990 case PE_IndicatorToolBarSeparator: {
1991 QPen pen = painter->pen();
1993 painter->setPen(option->palette.window().color().darker(114));
1994 if (option->state & State_Horizontal) {
1995 int x1 = option->rect.center().x();
1996 painter->drawLine(QPoint(x1, option->rect.top() + margin), QPoint(x1, option->rect.bottom() - margin));
1998 int y1 = option->rect.center().y();
1999 painter->drawLine(QPoint(option->rect.left() + margin, y1), QPoint(option->rect.right() - margin, y1));
2001 painter->setPen(pen);
2005 case PE_PanelTipLabel: {
2006 QWindowsThemeData theme(widget, painter,
2007 QWindowsVistaStylePrivate::ToolTipTheme,
2008 TTP_STANDARD, TTSS_NORMAL, option->rect);
2009 d->drawBackground(theme);
2013 case PE_FrameTabBarBase:
2014#if QT_CONFIG(tabbar)
2015 if (
const auto *tbb = qstyleoption_cast<
const QStyleOptionTabBarBase *>(option)) {
2017 switch (tbb->shape) {
2018 case QTabBar::RoundedNorth:
2019 painter->setPen(QPen(tbb->palette.dark(), 0));
2020 painter->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
2022 case QTabBar::RoundedWest:
2023 painter->setPen(QPen(tbb->palette.dark(), 0));
2024 painter->drawLine(tbb->rect.left(), tbb->rect.top(), tbb->rect.left(), tbb->rect.bottom());
2026 case QTabBar::RoundedSouth:
2027 painter->setPen(QPen(tbb->palette.dark(), 0));
2028 painter->drawLine(tbb->rect.left(), tbb->rect.top(),
2029 tbb->rect.right(), tbb->rect.top());
2031 case QTabBar::RoundedEast:
2032 painter->setPen(QPen(tbb->palette.dark(), 0));
2033 painter->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft());
2035 case QTabBar::TriangularNorth:
2036 case QTabBar::TriangularEast:
2037 case QTabBar::TriangularWest:
2038 case QTabBar::TriangularSouth:
2040 QWindowsStyle::drawPrimitive(element, option, painter, widget);
2049#if QT_CONFIG(dialogbuttonbox)
2050 const QDialogButtonBox *buttonBox =
nullptr;
2051 if (qobject_cast<
const QMessageBox *> (widget))
2052 buttonBox = widget->findChild<
const QDialogButtonBox *>(QLatin1String(
"qt_msgbox_buttonbox"));
2055 QWindowsThemeData theme(widget, painter,
2056 QWindowsVistaStylePrivate::TaskDialogTheme,
2057 TDLG_PRIMARYPANEL, 0, option->rect);
2058 QRect toprect = option->rect;
2059 toprect.setBottom(buttonBox->geometry().top());
2060 theme.rect = toprect;
2061 d->drawBackground(theme);
2064 QRect buttonRect = option->rect;
2065 buttonRect.setTop(buttonBox->geometry().top());
2066 theme.rect = buttonRect;
2067 theme.partId = TDLG_SECONDARYPANEL;
2068 d->drawBackground(theme);
2074 case PE_PanelItemViewItem: {
2075 const QStyleOptionViewItem *vopt;
2076 bool newStyle =
true;
2077 QAbstractItemView::SelectionBehavior selectionBehavior = QAbstractItemView::SelectRows;
2078 QAbstractItemView::SelectionMode selectionMode = QAbstractItemView::NoSelection;
2079 if (
const QAbstractItemView *view = qobject_cast<
const QAbstractItemView *>(widget)) {
2080 newStyle = !qobject_cast<
const QTableView*>(view);
2081 selectionBehavior = view->selectionBehavior();
2082 selectionMode = view->selectionMode();
2083#if QT_CONFIG(accessibility)
2084 }
else if (!widget) {
2085 newStyle = !QStyleHelper::hasAncestor(option->styleObject, QAccessible::MenuItem) ;
2089 if (newStyle && (vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(option))) {
2090 bool selected = vopt->state & QStyle::State_Selected;
2091 const bool hover = selectionMode != QAbstractItemView::NoSelection && (vopt->state & QStyle::State_MouseOver);
2092 bool active = vopt->state & QStyle::State_Active;
2094 if (vopt->features & QStyleOptionViewItem::Alternate)
2095 painter->fillRect(vopt->rect, vopt->palette.alternateBase());
2097 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled
2098 ? QPalette::Normal : QPalette::Disabled;
2099 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
2100 cg = QPalette::Inactive;
2102 QRect itemRect = subElementRect(QStyle::SE_ItemViewItemFocusRect, option, widget).adjusted(-1, 0, 1, 0);
2103 itemRect.setTop(vopt->rect.top());
2104 itemRect.setBottom(vopt->rect.bottom());
2106 QSize sectionSize = itemRect.size();
2107 if (vopt->showDecorationSelected)
2108 sectionSize = vopt->rect.size();
2110 if (selectionBehavior == QAbstractItemView::SelectRows)
2111 sectionSize.setWidth(vopt->rect.width());
2114 if (vopt->backgroundBrush.style() != Qt::NoBrush) {
2115 QPainterStateGuard psg(painter);
2116 painter->setBrushOrigin(vopt->rect.topLeft());
2117 painter->fillRect(vopt->rect, vopt->backgroundBrush);
2120 if (hover || selected) {
2121 if (sectionSize.width() > 0 && sectionSize.height() > 0) {
2122 QString key = QStringLiteral(u"qvdelegate-%1-%2-%3-%4-%5").arg(sectionSize.width())
2123 .arg(sectionSize.height()).arg(selected).arg(active).arg(hover);
2124 if (!QPixmapCache::find(key, &pixmap)) {
2125 pixmap = QPixmap(sectionSize);
2126 pixmap.fill(Qt::transparent);
2129 if (selected && hover)
2131 else if (selected && !active)
2140 QWindowsThemeData theme(widget, &pixmapPainter,
2141 QWindowsVistaStylePrivate::VistaTreeViewTheme,
2142 LVP_LISTITEM, state, QRect(0, 0, sectionSize.width(), sectionSize.height()));
2144 if (!theme.isValid())
2147 d->drawBackground(theme);
2148 QPixmapCache::insert(key, pixmap);
2152 if (vopt->showDecorationSelected) {
2153 const int frame = 2;
2154 QRect srcRect = QRect(0, 0, sectionSize.width(), sectionSize.height());
2155 QRect pixmapRect = vopt->rect;
2156 bool reverse = vopt->direction == Qt::RightToLeft;
2157 bool leftSection = vopt->viewItemPosition == QStyleOptionViewItem::Beginning;
2158 bool rightSection = vopt->viewItemPosition == QStyleOptionViewItem::End;
2159 if (vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne
2160 || vopt->viewItemPosition == QStyleOptionViewItem::Invalid)
2161 painter->drawPixmap(pixmapRect.topLeft(), pixmap);
2162 else if (reverse ? rightSection : leftSection){
2163 painter->drawPixmap(QRect(pixmapRect.topLeft(),
2164 QSize(frame, pixmapRect.height())), pixmap,
2165 QRect(QPoint(0, 0), QSize(frame, pixmapRect.height())));
2166 painter->drawPixmap(pixmapRect.adjusted(frame, 0, 0, 0),
2167 pixmap, srcRect.adjusted(frame, 0, -frame, 0));
2168 }
else if (reverse ? leftSection : rightSection) {
2169 painter->drawPixmap(QRect(pixmapRect.topRight() - QPoint(frame - 1, 0),
2170 QSize(frame, pixmapRect.height())), pixmap,
2171 QRect(QPoint(pixmapRect.width() - frame, 0),
2172 QSize(frame, pixmapRect.height())));
2173 painter->drawPixmap(pixmapRect.adjusted(0, 0, -frame, 0),
2174 pixmap, srcRect.adjusted(frame, 0, -frame, 0));
2175 }
else if (vopt->viewItemPosition == QStyleOptionViewItem::Middle)
2176 painter->drawPixmap(pixmapRect, pixmap,
2177 srcRect.adjusted(frame, 0, -frame, 0));
2179 if (vopt->text.isEmpty() && vopt->icon.isNull())
2181 painter->drawPixmap(itemRect.topLeft(), pixmap);
2193 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2195 if (!theme.isValid()) {
2196 QWindowsStyle::drawPrimitive(element, option, painter, widget);
2200 theme.mirrorHorizontally = hMirrored;
2201 theme.mirrorVertically = vMirrored;
2202 theme.noBorder = noBorder;
2203 theme.noContent = noContent;
2204 theme.rotate = rotate;
2206 d->drawBackground(theme);
2323void QWindowsVistaStyle::drawControl(ControlElement element,
const QStyleOption *option,
2324 QPainter *painter,
const QWidget *widget)
const
2326 if (!QWindowsVistaStylePrivate::useVista()) {
2327 QWindowsStyle::drawControl(element, option, painter, widget);
2333 bool selected = option->state & State_Selected;
2334 bool pressed = option->state & State_Sunken;
2335 bool disabled = !(option->state & State_Enabled);
2337 int state = option->state;
2338 int themeNumber = -1;
2340 QRect rect(option->rect);
2341 State flags = option->state;
2345 if (d->transitionsEnabled() && canAnimate(option)) {
2346 if (element == CE_PushButtonBevel) {
2350 QObject *styleObject = option->styleObject;
2352 int oldState = styleObject->property(
"_q_stylestate").toInt();
2353 oldRect = styleObject->property(
"_q_stylerect").toRect();
2354 newRect = option->rect;
2355 styleObject->setProperty(
"_q_stylestate",
int(option->state));
2356 styleObject->setProperty(
"_q_stylerect", option->rect);
2358 bool wasDefault =
false;
2359 bool isDefault =
false;
2360 if (
const QStyleOptionButton *button = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
2361 wasDefault = styleObject->property(
"_q_isdefault").toBool();
2362 isDefault = button->features & QStyleOptionButton::DefaultButton;
2363 styleObject->setProperty(
"_q_isdefault", isDefault);
2366 bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) ||
2367 (state & State_On) != (oldState & State_On) ||
2368 (state & State_MouseOver) != (oldState & State_MouseOver));
2370 if (oldRect != newRect || (wasDefault && !isDefault)) {
2371 doTransition =
false;
2372 d->stopAnimation(styleObject);
2376 styleObject->setProperty(
"_q_no_animation",
true);
2379 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
2380 QStyleOption *styleOption = clonedAnimationStyleOption(option);
2381 styleOption->state = QStyle::State(oldState);
2383 QImage startImage = createAnimationBuffer(option, widget);
2384 QPainter startPainter(&startImage);
2388 proxy()->drawControl(element, styleOption, &startPainter, widget);
2390 anim->paint(&startPainter, styleOption);
2391 d->stopAnimation(styleObject);
2394 t->setStartImage(startImage);
2395 QImage endImage = createAnimationBuffer(option, widget);
2397 styleOption->state = option->state;
2398 proxy()->drawControl(element, styleOption, &endPainter, widget);
2399 t->setEndImage(endImage);
2403 const HTHEME theme = OpenThemeData(
nullptr, L"Button");
2405 int fromState = buttonStateId(oldState, BP_PUSHBUTTON);
2406 int toState = buttonStateId(option->state, BP_PUSHBUTTON);
2407 if (GetThemeTransitionDuration(theme, BP_PUSHBUTTON, fromState, toState, TMT_TRANSITIONDURATIONS, &duration) == S_OK)
2408 t->setDuration(
int(duration));
2411 t->setStartTime(d->animationTime());
2412 styleObject->setProperty(
"_q_no_animation",
false);
2414 deleteClonedAnimationStyleOption(styleOption);
2415 d->startAnimation(t);
2418 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
2420 anim->paint(painter, option);
2427 bool hMirrored =
false;
2428 bool vMirrored =
false;
2432 case CE_PushButtonBevel:
2433 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
2434 themeNumber = QWindowsVistaStylePrivate::ButtonTheme;
2435 partId = BP_PUSHBUTTON;
2436 if (btn->features & QStyleOptionButton::CommandLinkButton)
2438 bool justFlat = (btn->features & QStyleOptionButton::Flat) && !(flags & (State_On|State_Sunken));
2439 if (!(flags & State_Enabled) && !(btn->features & QStyleOptionButton::Flat))
2440 stateId = PBS_DISABLED;
2443 else if (flags & (State_Sunken | State_On))
2444 stateId = PBS_PRESSED;
2445 else if (flags & State_MouseOver)
2447 else if (btn->features & QStyleOptionButton::DefaultButton && (state & State_Active))
2448 stateId = PBS_DEFAULTED;
2450 stateId = PBS_NORMAL;
2454 if (d->transitionsEnabled() && (btn->features & QStyleOptionButton::DefaultButton) &&
2455 !(state & (State_Sunken | State_On)) && !(state & State_MouseOver) &&
2456 (state & State_Enabled) && (state & State_Active))
2458 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject(option)));
2461 QImage startImage = createAnimationBuffer(option, widget);
2462 QImage alternateImage = createAnimationBuffer(option, widget);
2466 QPainter startPainter(&startImage);
2467 stateId = PBS_DEFAULTED;
2468 QWindowsThemeData theme(widget, &startPainter, themeNumber, partId, stateId, rect);
2469 d->drawBackground(theme);
2471 QPainter alternatePainter(&alternateImage);
2472 theme.stateId = PBS_DEFAULTED_ANIMATING;
2473 theme.painter = &alternatePainter;
2474 d->drawBackground(theme);
2476 pulse->setStartImage(startImage);
2477 pulse->setEndImage(alternateImage);
2478 pulse->setStartTime(d->animationTime());
2479 pulse->setDuration(2000);
2480 d->startAnimation(pulse);
2485 anim->paint(painter, option);
2487 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2488 d->drawBackground(theme);
2492 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
2493 d->drawBackground(theme);
2497 if (btn->features & QStyleOptionButton::HasMenu) {
2498 int mbiw = 0, mbih = 0;
2499 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::ToolBarTheme,
2501 if (theme.isValid()) {
2502 const QSizeF size = theme.size() * QStyleHelper::dpiScaled(1, option);
2503 if (!size.isEmpty()) {
2504 mbiw = qRound(size.width());
2505 mbih = qRound(size.height());
2508 QRect ir = subElementRect(SE_PushButtonContents, option,
nullptr);
2509 QStyleOptionButton newBtn = *btn;
2510 newBtn.rect = QStyle::visualRect(option->direction, option->rect,
2511 QRect(ir.right() - mbiw - 2,
2512 option->rect.top() + (option->rect.height()/2) - (mbih/2),
2513 mbiw + 1, mbih + 1));
2514 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
2520 themeNumber = QWindowsVistaStylePrivate::StatusTheme;
2521 partId = SP_GRIPPER;
2522 QWindowsThemeData theme(
nullptr, painter, themeNumber, partId);
2523 QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize();
2525 if (
const auto *sg = qstyleoption_cast<
const QStyleOptionSizeGrip *>(option)) {
2526 switch (sg->corner) {
2527 case Qt::BottomRightCorner:
2528 rect = QRect(QPoint(rect.right() - size.width(), rect.bottom() - size.height()), size);
2530 case Qt::BottomLeftCorner:
2531 rect = QRect(QPoint(rect.left() + 1, rect.bottom() - size.height()), size);
2534 case Qt::TopRightCorner:
2535 rect = QRect(QPoint(rect.right() - size.width(), rect.top() + 1), size);
2538 case Qt::TopLeftCorner:
2539 rect = QRect(rect.topLeft() + QPoint(1, 1), size);
2540 hMirrored = vMirrored =
true;
2547 painter->eraseRect(option->rect);
2551#if QT_CONFIG(tabwidget)
2552 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option))
2553 stateId = tab->state & State_Enabled ? TIS_NORMAL : TIS_DISABLED;
2557 case CE_TabBarTabShape:
2558#if QT_CONFIG(tabwidget)
2559 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(option)) {
2560 themeNumber = QWindowsVistaStylePrivate::TabTheme;
2561 const bool isDisabled = !(tab->state & State_Enabled);
2562 const bool hasFocus = tab->state & State_HasFocus;
2563 const bool isHot = tab->state & State_MouseOver;
2564 const bool selected = tab->state & State_Selected;
2565 bool lastTab = tab->position == QStyleOptionTab::End;
2566 bool firstTab = tab->position == QStyleOptionTab::Beginning;
2567 const bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
2568 const bool leftAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignLeft;
2569 const bool centerAligned = proxy()->styleHint(SH_TabBar_Alignment, tab, widget) == Qt::AlignCenter;
2570 const int borderThickness = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
2571 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, option, widget);
2574 stateId = TIS_DISABLED;
2576 stateId = TIS_SELECTED;
2578 stateId = TIS_FOCUSED;
2582 stateId = TIS_NORMAL;
2585 if (firstTab || onlyOne) {
2587 partId = TABP_TABITEMLEFTEDGE;
2588 else if (centerAligned)
2589 partId = TABP_TABITEM;
2591 partId = TABP_TABITEMRIGHTEDGE;
2593 partId = TABP_TABITEM;
2596 if (tab->direction == Qt::RightToLeft
2597 && (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedSouth)) {
2598 bool temp = firstTab;
2603 const bool begin = firstTab || onlyOne;
2604 const bool end = lastTab || onlyOne;
2606 switch (tab->shape) {
2607 case QTabBar::RoundedNorth:
2609 rect.adjust(begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap, borderThickness);
2611 rect.adjust(begin? tabOverlap : 0, tabOverlap, end ? -tabOverlap : 0, 0);
2613 case QTabBar::RoundedSouth:
2617 rect.adjust(begin ? 0 : -tabOverlap , -borderThickness, end ? 0 : tabOverlap, 0);
2619 rect.adjust(begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0 , -tabOverlap);
2621 case QTabBar::RoundedEast:
2624 rect.adjust(-borderThickness, begin ? 0 : -tabOverlap, 0, end ? 0 : tabOverlap);
2626 rect.adjust(0, begin ? tabOverlap : 0, -tabOverlap, end ? -tabOverlap : 0);
2628 case QTabBar::RoundedWest:
2632 rect.adjust(0, begin ? 0 : -tabOverlap, borderThickness, end ? 0 : tabOverlap);
2634 rect.adjust(tabOverlap, begin ? tabOverlap : 0, 0, end ? -tabOverlap : 0);
2642 switch (tab->shape) {
2643 case QTabBar::RoundedNorth:
2644 rect.adjust(0,0, 0,-1);
2646 case QTabBar::RoundedSouth:
2647 rect.adjust(0,1, 0,0);
2649 case QTabBar::RoundedEast:
2650 rect.adjust( 1,0, 0,0);
2652 case QTabBar::RoundedWest:
2653 rect.adjust(0,0, -1,0);
2663 case CE_ProgressBarGroove: {
2664 Qt::Orientation orient = Qt::Horizontal;
2665 if (
const auto *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(option))
2666 if (!(pb->state & QStyle::State_Horizontal))
2667 orient = Qt::Vertical;
2669 partId = (orient == Qt::Horizontal) ? PP_BAR : PP_BARVERT;
2670 themeNumber = QWindowsVistaStylePrivate::ProgressTheme;
2675 case CE_ProgressBarContents:
2676 if (
const auto *bar = qstyleoption_cast<
const QStyleOptionProgressBar *>(option)) {
2677 bool isIndeterminate = (bar->minimum == 0 && bar->maximum == 0);
2678 const bool vertical = !(bar->state & QStyle::State_Horizontal);
2679 const bool inverted = bar->invertedAppearance;
2681 if (isIndeterminate || (bar->progress > 0 && (bar->progress < bar->maximum) && d->transitionsEnabled())) {
2682 if (!d->animation(styleObject(option)))
2683 d->startAnimation(
new QProgressStyleAnimation(d->animationFps, styleObject(option)));
2685 d->stopAnimation(styleObject(option));
2688 QWindowsThemeData theme(widget, painter,
2689 QWindowsVistaStylePrivate::ProgressTheme,
2690 vertical ? PP_FILLVERT : PP_FILL);
2691 theme.rect = option->rect;
2692 bool reverse = (bar->direction == Qt::LeftToRight && inverted) || (bar->direction == Qt::RightToLeft && !inverted);
2693 QTime current = d->animationTime();
2695 if (isIndeterminate) {
2696 if (
auto *progressAnimation = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2698 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2699 int animOffset = progressAnimation->startTime().msecsTo(current) / 4;
2700 if (animOffset > animationWidth)
2701 progressAnimation->setStartTime(d->animationTime());
2703 painter->setClipRect(theme.rect);
2705 QSize pixmapSize(14, 14);
2707 animRect = QRect(theme.rect.left(),
2708 inverted ? rect.top() - glowSize + animOffset :
2709 rect.bottom() + glowSize - animOffset,
2710 rect.width(), glowSize);
2711 pixmapSize.setHeight(animRect.height());
2713 animRect = QRect(rect.left() - glowSize + animOffset,
2714 rect.top(), glowSize, rect.height());
2715 animRect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2716 option->rect, animRect);
2717 pixmapSize.setWidth(animRect.width());
2719 QString name = QStringLiteral(u"qiprogress-%1-%2").arg(pixmapSize.width()).arg(pixmapSize.height());
2721 if (!QPixmapCache::find(name, &pixmap)) {
2722 QImage image(pixmapSize, QImage::Format_ARGB32);
2723 image.fill(Qt::transparent);
2725 theme.painter = &imagePainter;
2726 theme.partId = vertical ? PP_FILLVERT : PP_FILL;
2727 theme.rect = QRect(QPoint(0,0), animRect.size());
2728 QLinearGradient alphaGradient(0, 0, vertical ? 0 : image.width(),
2729 vertical ? image.height() : 0);
2730 alphaGradient.setColorAt(0, QColor(0, 0, 0, 0));
2731 alphaGradient.setColorAt(0.5, QColor(0, 0, 0, 220));
2732 alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
2733 imagePainter.fillRect(image.rect(), alphaGradient);
2734 imagePainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
2735 d->drawBackground(theme);
2737 pixmap = QPixmap::fromImage(image);
2738 QPixmapCache::insert(name, pixmap);
2740 painter->drawPixmap(animRect, pixmap);
2744 qint64 progress = qMax<qint64>(bar->progress, bar->minimum);
2747 int maxHeight = option->rect.height();
2749 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxHeight);
2750 int height = isIndeterminate ? maxHeight: qMax(
int(vc6_workaround), minHeight);
2751 theme.rect.setHeight(height);
2753 theme.rect.moveTop(rect.height() - theme.rect.height());
2755 int maxWidth = option->rect.width();
2757 double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(
double(1.0),
double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth);
2758 int width = isIndeterminate ? maxWidth : qMax(
int(vc6_workaround), minWidth);
2759 theme.rect.setWidth(width);
2760 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight,
2761 option->rect, theme.rect);
2763 d->drawBackground(theme);
2765 if (QProgressStyleAnimation *a = qobject_cast<QProgressStyleAnimation *>(d->animation(styleObject(option)))) {
2767 int animationWidth = glowSize * 2 + (vertical ? theme.rect.height() : theme.rect.width());
2768 int animOffset = a->startTime().msecsTo(current) / 4;
2769 theme.partId = vertical ? PP_MOVEOVERLAYVERT : PP_MOVEOVERLAY;
2770 if (animOffset > animationWidth) {
2771 if (bar->progress < bar->maximum)
2772 a->setStartTime(d->animationTime());
2774 d->stopAnimation(styleObject(option));
2778 painter->setClipRect(theme.rect);
2780 theme.rect = QRect(theme.rect.left(),
2781 inverted ? rect.top() - glowSize + animOffset :
2782 rect.bottom() + glowSize - animOffset,
2783 rect.width(), glowSize);
2785 theme.rect = QRect(rect.left() - glowSize + animOffset,rect.top(), glowSize, rect.height());
2786 theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight, option->rect, theme.rect);
2788 d->drawBackground(theme);
2795 case CE_MenuBarItem:
2796 if (
const auto *mbi = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2797 if (mbi->menuItemType == QStyleOptionMenuItem::DefaultItem)
2800 QPalette::ColorRole textRole = disabled ? QPalette::Text : QPalette::ButtonText;
2801 const auto dpr = QStyleHelper::getDpr(widget);
2802 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2803 const auto pix = mbi->icon.pixmap(QSize(extent, extent), dpr, QIcon::Normal);
2805 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2806 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
2807 alignment |= Qt::TextHideMnemonic;
2809 if (widget && mbi->palette.color(QPalette::Window) != Qt::transparent) {
2811 QWindowsThemeData theme(widget, painter,
2812 QWindowsVistaStylePrivate::MenuTheme,
2813 MENU_BARBACKGROUND, 0, option->rect.adjusted(-1, 0, 2, 1));
2814 d->drawBackground(theme);
2816 int stateId = MBI_NORMAL;
2818 stateId = MBI_DISABLED;
2820 stateId = MBI_PUSHED;
2824 QWindowsThemeData theme2(widget, painter,
2825 QWindowsVistaStylePrivate::MenuTheme,
2826 MENU_BARITEM, stateId, option->rect);
2827 d->drawBackground(theme2);
2831 drawItemPixmap(painter, mbi->rect, alignment, pix);
2833 drawItemText(painter, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled, mbi->text, textRole);
2838 case CE_MenuEmptyArea:
2839 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2840 QBrush fill = menuitem->palette.brush((menuitem->state & State_Selected) ?
2841 QPalette::Highlight : QPalette::Button);
2842 painter->fillRect(rect, fill);
2848 if (
const auto *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(option)) {
2850 const qreal factor = QWindowsVistaStylePrivate::nativeMetricScaleFactor(widget);
2851 int checkcol = qRound(qreal(25) * factor);
2852 const int gutterWidth = qRound(qreal(3) * factor);
2854 QWindowsThemeData theme(widget,
nullptr, QWindowsVistaStylePrivate::MenuTheme,
2855 MENU_POPUPCHECKBACKGROUND, MBI_HOT);
2856 QWindowsThemeData themeSize = theme;
2857 themeSize.partId = MENU_POPUPCHECK;
2858 themeSize.stateId = 0;
2859 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2860 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2861 checkcol = qMax(menuitem->maxIconWidth, qRound(gutterWidth + size.width() + margins.left() + margins.right()));
2863 QRect rect = option->rect;
2866 QWindowsThemeData popupbackgroundTheme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2867 MENU_POPUPBACKGROUND, stateId, option->rect);
2868 d->drawBackground(popupbackgroundTheme);
2871 if (option->direction == Qt::LeftToRight)
2872 checkcol += rect.x();
2873 QPoint p1 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.top()));
2874 QPoint p2 = QStyle::visualPos(option->direction, menuitem->rect, QPoint(checkcol, rect.bottom()));
2875 QRect gutterRect(p1.x(), p1.y(), gutterWidth, p2.y() - p1.y() + 1);
2876 QWindowsThemeData theme2(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
2877 MENU_POPUPGUTTER, stateId, gutterRect);
2878 d->drawBackground(theme2);
2881 menuitem->rect.getRect(&x, &y, &w, &h);
2882 int tab = menuitem->reservedShortcutWidth;
2883 bool dis = !(menuitem->state & State_Enabled);
2884 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
2885 ? menuitem->checked :
false;
2886 bool act = menuitem->state & State_Selected;
2888 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {
2889 int yoff = y-2 + h / 2;
2890 const int separatorSize = qRound(qreal(6) * QWindowsStylePrivate::nativeMetricScaleFactor(widget));
2891 QPoint p1 = QPoint(x + checkcol, yoff);
2892 QPoint p2 = QPoint(x + w + separatorSize, yoff);
2894 QRect subRect(p1.x() + (gutterWidth - menuitem->rect.x()), p1.y(),
2895 p2.x() - p1.x(), separatorSize);
2896 subRect = QStyle::visualRect(option->direction, option->rect, subRect );
2897 QWindowsThemeData theme2(widget, painter,
2898 QWindowsVistaStylePrivate::MenuTheme,
2899 MENU_POPUPSEPARATOR, stateId, subRect);
2900 d->drawBackground(theme2);
2904 QRect vCheckRect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x(),
2905 menuitem->rect.y(), checkcol - (gutterWidth + menuitem->rect.x()), menuitem->rect.height()));
2908 stateId = dis ? MBI_DISABLED : MBI_HOT;
2909 QWindowsThemeData theme2(widget, painter,
2910 QWindowsVistaStylePrivate::MenuTheme,
2911 MENU_POPUPITEM, stateId, option->rect);
2912 d->drawBackground(theme2);
2916 QWindowsThemeData theme(widget, painter,
2917 QWindowsVistaStylePrivate::MenuTheme,
2918 MENU_POPUPCHECKBACKGROUND,
2919 menuitem->icon.isNull() ? MBI_HOT : MBI_PUSHED, vCheckRect);
2920 QWindowsThemeData themeSize = theme;
2921 themeSize.partId = MENU_POPUPCHECK;
2922 themeSize.stateId = 0;
2923 const QSizeF size = themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2924 const QMarginsF margins = themeSize.margins() * QWindowsStylePrivate::nativeMetricScaleFactor(widget);
2925 QRect checkRect(0, 0, qRound(size.width() + margins.left() + margins.right()),
2926 qRound(size.height() + margins.bottom() + margins.top()));
2927 checkRect.moveCenter(vCheckRect.center());
2928 theme.rect = checkRect;
2930 d->drawBackground(theme);
2932 if (menuitem->icon.isNull()) {
2933 checkRect = QRect(QPoint(0, 0), size.toSize());
2934 checkRect.moveCenter(theme.rect.center());
2935 theme.rect = checkRect;
2937 theme.partId = MENU_POPUPCHECK;
2938 bool bullet = menuitem->checkType & QStyleOptionMenuItem::Exclusive;
2940 theme.stateId = bullet ? MC_BULLETDISABLED: MC_CHECKMARKDISABLED;
2942 theme.stateId = bullet ? MC_BULLETNORMAL: MC_CHECKMARKNORMAL;
2943 d->drawBackground(theme);
2947 if (!menuitem->icon.isNull()) {
2948 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
2950 mode = QIcon::Active;
2951 const auto size = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2952 QRect pmr(QPoint(0, 0), QSize(size, size));
2953 pmr.moveCenter(vCheckRect.center());
2954 menuitem->icon.paint(painter, vCheckRect, Qt::AlignCenter, mode,
2955 checked ? QIcon::On : QIcon::Off);
2958 painter->setPen(menuitem->palette.buttonText().color());
2960 const QColor textColor = menuitem->palette.text().color();
2962 painter->setPen(textColor);
2964 int xm = windowsItemFrame + checkcol + windowsItemHMargin + (gutterWidth - menuitem->rect.x()) - 1;
2965 int xpos = menuitem->rect.x() + xm;
2966 QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
2967 QRect vTextRect = visualRect(option->direction, menuitem->rect, textRect);
2968 QString s = menuitem->text;
2971 int t = s.indexOf(QLatin1Char(
'\t'));
2972 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
2973 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
2974 text_flags |= Qt::TextHideMnemonic;
2975 text_flags |= Qt::AlignLeft;
2977 QRect vShortcutRect = visualRect(option->direction, menuitem->rect,
2978 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
2979 painter->drawText(vShortcutRect, text_flags, s.mid(t + 1));
2982 QFont font = menuitem->font;
2983 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
2985 painter->setFont(font);
2986 painter->setPen(textColor);
2987 painter->drawText(vTextRect, text_flags, s.left(t));
2990 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {
2991 int dim = (h - 2 * windowsItemFrame) / 2;
2992 PrimitiveElement arrow;
2993 arrow = (option->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
2994 xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim;
2995 QRect vSubMenuRect = visualRect(option->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
2996 QStyleOptionMenuItem newMI = *menuitem;
2997 newMI.rect = vSubMenuRect;
2998 newMI.state = dis ? State_None : State_Enabled;
2999 proxy()->drawPrimitive(arrow, &newMI, painter, widget);
3005 case CE_HeaderSection:
3006 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(option)) {
3007 partId = HP_HEADERITEM;
3008 if (flags & State_Sunken)
3009 stateId = HIS_PRESSED;
3010 else if (flags & State_MouseOver)
3013 stateId = HIS_NORMAL;
3015 if (header->sortIndicator != QStyleOptionHeader::None)
3018 QWindowsThemeData theme(widget, painter,
3019 QWindowsVistaStylePrivate::HeaderTheme,
3020 partId, stateId, option->rect);
3021 d->drawBackground(theme);
3025 case CE_MenuBarEmptyArea: {
3026 stateId = MBI_NORMAL;
3027 if (!(state & State_Enabled))
3028 stateId = MBI_DISABLED;
3029 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::MenuTheme,
3030 MENU_BARBACKGROUND, stateId, option->rect);
3031 d->drawBackground(theme);
3036#if QT_CONFIG(toolbar)
3037 if (
const auto *toolbar = qstyleoption_cast<
const QStyleOptionToolBar *>(option)) {
3038 QPalette pal = option->palette;
3039 pal.setColor(QPalette::Dark, option->palette.window().color().darker(130));
3040 QStyleOptionToolBar copyOpt = *toolbar;
3041 copyOpt.palette = pal;
3042 QWindowsStyle::drawControl(element, ©Opt, painter, widget);
3047#if QT_CONFIG(dockwidget)
3048 case CE_DockWidgetTitle:
3049 if (
const auto *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(option)) {
3050 QRect rect = option->rect;
3051 const QDockWidget *dw = qobject_cast<
const QDockWidget *>(widget);
3052 bool isFloating = dw && dw->isFloating();
3053 int buttonMargin = 4;
3054 int mw = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, widget);
3055 int fw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, dwOpt, widget);
3057 const bool verticalTitleBar = dwOpt->verticalTitleBar;
3059 if (verticalTitleBar) {
3060 rect = rect.transposed();
3062 painter->translate(rect.left() - 1, rect.top() + rect.width());
3063 painter->rotate(-90);
3064 painter->translate(-rect.left() + 1, -rect.top());
3067 QRect r = option->rect.adjusted(0, 2, -1, -3);
3068 QRect titleRect = r;
3070 if (dwOpt->closable) {
3071 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton, dwOpt, widget).actualSize(QSize(10, 10));
3072 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3075 if (dwOpt->floatable) {
3076 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarMaxButton, dwOpt, widget).actualSize(QSize(10, 10));
3077 titleRect.adjust(0, 0, -sz.width() - mw - buttonMargin, 0);
3081 titleRect.adjust(0, -fw, 0, 0);
3082 if (widget && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey())
3083 titleRect.adjust(titleRect.height() + mw, 0, 0, 0);
3085 titleRect.adjust(mw, 0, 0, 0);
3086 if (!dwOpt->floatable && !dwOpt->closable)
3087 titleRect.adjust(0, 0, -mw, 0);
3090 if (!verticalTitleBar)
3091 titleRect = visualRect(dwOpt->direction, r, titleRect);
3094 const bool isActive = dwOpt->state & State_Active;
3095 themeNumber = QWindowsVistaStylePrivate::WindowTheme;
3097 stateId = CS_ACTIVE;
3099 stateId = CS_INACTIVE;
3101 rect = rect.adjusted(-fw, -fw, fw, 0);
3103 QWindowsThemeData theme(widget, painter, themeNumber, 0, stateId);
3104 if (!theme.isValid())
3109 theme.partId = WP_SMALLCAPTION;
3110 d->drawBackground(theme);
3114 QIcon ico = widget->windowIcon();
3115 bool hasIcon = (ico.cacheKey() != QApplication::windowIcon().cacheKey());
3117 const auto titleHeight = rect.height() - 2;
3118 const auto dpr = QStyleHelper::getDpr(widget);
3119 const auto pxIco = ico.pixmap(QSize(titleHeight, titleHeight), dpr);
3120 if (!verticalTitleBar && dwOpt->direction == Qt::RightToLeft)
3121 painter->drawPixmap(rect.width() - titleHeight - pxIco.width(), rect.bottom() - titleHeight - 2, pxIco);
3123 painter->drawPixmap(fw, rect.bottom() - titleHeight - 2, pxIco);
3125 if (!dwOpt->title.isEmpty()) {
3126 QPen oldPen = painter->pen();
3127 QFont oldFont = painter->font();
3128 QFont titleFont = oldFont;
3129 titleFont.setBold(
true);
3130 painter->setFont(titleFont);
3132 = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
3134 int result = TST_NONE;
3135 GetThemeEnumValue(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3136 if (result != TST_NONE) {
3137 COLORREF textShadowRef;
3138 GetThemeColor(theme.handle(), WP_SMALLCAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWCOLOR, &textShadowRef);
3139 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3140 painter->setPen(textShadow);
3141 drawItemText(painter, titleRect.adjusted(1, 1, 1, 1),
3142 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3143 dwOpt->state & State_Enabled, titleText);
3146 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3147 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3148 painter->setPen(textColor);
3149 drawItemText(painter, titleRect,
3150 Qt::AlignLeft | Qt::AlignBottom | Qt::TextHideMnemonic, dwOpt->palette,
3151 dwOpt->state & State_Enabled, titleText);
3152 painter->setFont(oldFont);
3153 painter->setPen(oldPen);
3156 painter->setBrush(option->palette.window().color().darker(110));
3157 painter->setPen(option->palette.window().color().darker(130));
3158 painter->drawRect(rect.adjusted(0, 1, -1, -3));
3160 if (!dwOpt->title.isEmpty()) {
3161 QString titleText = painter->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight,
3162 verticalTitleBar ? titleRect.height() : titleRect.width());
3163 const int indent = 4;
3164 drawItemText(painter, rect.adjusted(indent + 1, 1, -indent - 1, -1),
3165 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic,
3167 dwOpt->state & State_Enabled, titleText,
3168 QPalette::WindowText);
3175#if QT_CONFIG(rubberband)
3177 if (qstyleoption_cast<
const QStyleOptionRubberBand *>(option)) {
3178 QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
3180 painter->setPen(highlight.darker(120));
3181 QColor dimHighlight(qMin(highlight.red()/2 + 110, 255),
3182 qMin(highlight.green()/2 + 110, 255),
3183 qMin(highlight.blue()/2 + 110, 255),
3184 (widget && widget->isWindow())? 255 : 127);
3185 painter->setBrush(dimHighlight);
3186 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
3193 case CE_HeaderEmptyArea:
3194 if (option->state & State_Horizontal) {
3195 themeNumber = QWindowsVistaStylePrivate::HeaderTheme;
3196 stateId = HIS_NORMAL;
3198 QWindowsStyle::drawControl(CE_HeaderEmptyArea, option, painter, widget);
3203#if QT_CONFIG(itemviews)
3204 case CE_ItemViewItem: {
3205 const QStyleOptionViewItem *vopt;
3206 const QAbstractItemView *view = qobject_cast<
const QAbstractItemView *>(widget);
3207 bool newStyle =
true;
3209 if (qobject_cast<
const QTableView*>(widget))
3212 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3214 if (newStyle && view && (vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(option))) {
3216
3217
3218
3219
3220
3221
3222 QPalette palette = vopt->palette;
3223 palette.setColor(QPalette::All, QPalette::HighlightedText, palette.color(QPalette::Active, QPalette::Text));
3225 palette.setColor(QPalette::All, QPalette::Highlight, palette.base().color().darker(108));
3226 QStyleOptionViewItem adjustedOption = *vopt;
3227 adjustedOption.palette = palette;
3229 if ((view->selectionMode() == QAbstractItemView::SingleSelection)
3230 && !(vopt->state & State_KeyboardFocusChange))
3231 adjustedOption.state &= ~State_HasFocus;
3232 if (!theme.isValid()) {
3233 QWindowsStyle::drawControl(element, &adjustedOption, painter, widget);
3237 if (!theme.isValid()) {
3238 QWindowsStyle::drawControl(element, option, painter, widget);
3243 theme.rotate = rotate;
3244 theme.mirrorHorizontally = hMirrored;
3245 theme.mirrorVertically = vMirrored;
3246 d->drawBackground(theme);
3251#if QT_CONFIG(combobox)
3252 case CE_ComboBoxLabel:
3253 QCommonStyle::drawControl(element, option, painter, widget);
3261 QWindowsThemeData theme(widget, painter, themeNumber, partId, stateId, rect);
3263 if (!theme.isValid()) {
3264 QWindowsStyle::drawControl(element, option, painter, widget);
3268 theme.rotate = rotate;
3269 theme.mirrorHorizontally = hMirrored;
3270 theme.mirrorVertically = vMirrored;
3272 d->drawBackground(theme);
3280void QWindowsVistaStyle::drawComplexControl(ComplexControl control,
const QStyleOptionComplex *option,
3281 QPainter *painter,
const QWidget *widget)
const
3285 if (!QWindowsVistaStylePrivate::useVista()) {
3286 QWindowsStyle::drawComplexControl(control, option, painter, widget);
3290 State state = option->state;
3291 SubControls sub = option->subControls;
3292 QRect r = option->rect;
3297 State flags = option->state;
3298 if (widget && widget->testAttribute(Qt::WA_UnderMouse) && widget->isActiveWindow())
3299 flags |= State_MouseOver;
3301 if (d->transitionsEnabled() && canAnimate(option))
3303 if (control == CC_ScrollBar || control == CC_SpinBox || control == CC_ComboBox) {
3304 QObject *styleObject = option->styleObject;
3306 int oldState = styleObject->property(
"_q_stylestate").toInt();
3307 int oldActiveControls = styleObject->property(
"_q_stylecontrols").toInt();
3309 QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
3310 styleObject->setProperty(
"_q_stylestate",
int(option->state));
3311 styleObject->setProperty(
"_q_stylecontrols",
int(option->activeSubControls));
3312 styleObject->setProperty(
"_q_stylerect", option->rect);
3314 bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken)
3315 || (state & State_On) != (oldState & State_On)
3316 || (state & State_MouseOver) != (oldState & State_MouseOver)
3317 || oldActiveControls !=
int(option->activeSubControls));
3319 if (qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3320 QRect oldSliderPos = styleObject->property(
"_q_stylesliderpos").toRect();
3321 QRect currentPos = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3322 styleObject->setProperty(
"_q_stylesliderpos", currentPos);
3323 if (oldSliderPos != currentPos) {
3324 doTransition =
false;
3325 d->stopAnimation(styleObject);
3327 }
else if (control == CC_SpinBox) {
3330 doTransition = (state & State_HasFocus) != (oldState & State_HasFocus);
3333 if (oldRect != option->rect) {
3334 doTransition =
false;
3335 d->stopAnimation(styleObject);
3339 QImage startImage = createAnimationBuffer(option, widget);
3340 QPainter startPainter(&startImage);
3342 QImage endImage = createAnimationBuffer(option, widget);
3345 QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
3349 QStyleOptionComplex *styleOption = qstyleoption_cast<QStyleOptionComplex*>(clonedAnimationStyleOption(option));
3351 styleObject->setProperty(
"_q_no_animation",
true);
3355 styleOption->state = QStyle::State(oldState);
3356 styleOption->activeSubControls = QStyle::SubControl(oldActiveControls);
3357 proxy()->drawComplexControl(control, styleOption, &startPainter, widget);
3359 anim->paint(&startPainter, option);
3361 t->setStartImage(startImage);
3364 styleOption->state = option->state;
3365 styleOption->activeSubControls = option->activeSubControls;
3366 proxy()->drawComplexControl(control, styleOption, &endPainter, widget);
3368 styleObject->setProperty(
"_q_no_animation",
false);
3370 t->setEndImage(endImage);
3371 t->setStartTime(d->animationTime());
3373 if (option->state & State_MouseOver || option->state & State_Sunken)
3374 t->setDuration(150);
3376 t->setDuration(500);
3378 deleteClonedAnimationStyleOption(styleOption);
3379 d->startAnimation(t);
3381 if (QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject))) {
3382 anim->paint(painter, option);
3390#if QT_CONFIG(slider)
3392 if (
const auto *slider = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3393 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::TrackBarTheme);
3394 QRect slrect = slider->rect;
3395 QRegion tickreg = slrect;
3396 if (sub & SC_SliderGroove) {
3397 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
3398 if (slider->orientation == Qt::Horizontal) {
3400 stateId = TRS_NORMAL;
3401 theme.rect = QRect(slrect.left(), theme.rect.center().y() - 2, slrect.width(), 4);
3403 partId = TKP_TRACKVERT;
3404 stateId = TRVS_NORMAL;
3405 theme.rect = QRect(theme.rect.center().x() - 2, slrect.top(), 4, slrect.height());
3407 theme.partId = partId;
3408 theme.stateId = stateId;
3409 d->drawBackground(theme);
3410 tickreg -= theme.rect;
3412 if (sub & SC_SliderTickmarks) {
3413 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
3414 int ticks = slider->tickPosition;
3415 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
3416 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3417 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3418 int interval = slider->tickInterval;
3419 if (interval <= 0) {
3420 interval = slider->singleStep;
3421 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3423 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3425 interval = slider->pageStep;
3429 int fudge = len / 2;
3431 int bothOffset = (ticks & QSlider::TicksAbove && ticks & QSlider::TicksBelow) ? 1 : 0;
3432 painter->setPen(d->sliderTickColor);
3433 QVarLengthArray<QLine, 32> lines;
3434 int v = slider->minimum;
3435 while (v <= slider->maximum + 1) {
3436 if (v == slider->maximum + 1 && interval == 1)
3438 const int v_ = qMin(v, slider->maximum);
3439 int tickLength = (v_ == slider->minimum || v_ >= slider->maximum) ? 4 : 3;
3440 pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3441 v_, available) + fudge;
3442 if (slider->orientation == Qt::Horizontal) {
3443 if (ticks & QSlider::TicksAbove) {
3444 lines.append(QLine(pos, tickOffset - 1 - bothOffset,
3445 pos, tickOffset - 1 - bothOffset - tickLength));
3448 if (ticks & QSlider::TicksBelow) {
3449 lines.append(QLine(pos, tickOffset + thickness + bothOffset,
3450 pos, tickOffset + thickness + bothOffset + tickLength));
3453 if (ticks & QSlider::TicksAbove) {
3454 lines.append(QLine(tickOffset - 1 - bothOffset, pos,
3455 tickOffset - 1 - bothOffset - tickLength, pos));
3458 if (ticks & QSlider::TicksBelow) {
3459 lines.append(QLine(tickOffset + thickness + bothOffset, pos,
3460 tickOffset + thickness + bothOffset + tickLength, pos));
3464 int nextInterval = v + interval;
3465 if (nextInterval < v)
3469 if (!lines.isEmpty()) {
3471 painter->translate(slrect.topLeft());
3472 painter->drawLines(lines.constData(), lines.size());
3476 if (sub & SC_SliderHandle) {
3477 theme.rect = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
3478 if (slider->orientation == Qt::Horizontal) {
3479 if (slider->tickPosition == QSlider::TicksAbove)
3480 partId = TKP_THUMBTOP;
3481 else if (slider->tickPosition == QSlider::TicksBelow)
3482 partId = TKP_THUMBBOTTOM;
3486 if (!(slider->state & State_Enabled))
3487 stateId = TUS_DISABLED;
3488 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3489 stateId = TUS_PRESSED;
3490 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3492 else if (flags & State_HasFocus)
3493 stateId = TUS_FOCUSED;
3495 stateId = TUS_NORMAL;
3497 if (slider->tickPosition == QSlider::TicksLeft)
3498 partId = TKP_THUMBLEFT;
3499 else if (slider->tickPosition == QSlider::TicksRight)
3500 partId = TKP_THUMBRIGHT;
3502 partId = TKP_THUMBVERT;
3504 if (!(slider->state & State_Enabled))
3505 stateId = TUVS_DISABLED;
3506 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_Sunken))
3507 stateId = TUVS_PRESSED;
3508 else if (slider->activeSubControls & SC_SliderHandle && (slider->state & State_MouseOver))
3510 else if (flags & State_HasFocus)
3511 stateId = TUVS_FOCUSED;
3513 stateId = TUVS_NORMAL;
3515 theme.partId = partId;
3516 theme.stateId = stateId;
3517 d->drawBackground(theme);
3519 if (slider->state & State_HasFocus) {
3520 QStyleOptionFocusRect fropt;
3521 fropt.QStyleOption::operator=(*slider);
3522 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
3523 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3529#if QT_CONFIG(toolbutton)
3531 if (
const auto *toolbutton = qstyleoption_cast<
const QStyleOptionToolButton *>(option)) {
3532 QRect button, menuarea;
3533 button = proxy()->subControlRect(control, toolbutton, SC_ToolButton, widget);
3534 menuarea = proxy()->subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
3536 State bflags = toolbutton->state & ~State_Sunken;
3537 State mflags = bflags;
3538 bool autoRaise = flags & State_AutoRaise;
3540 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled))
3541 bflags &= ~State_Raised;
3544 if (toolbutton->state & State_Sunken) {
3545 if (toolbutton->activeSubControls & SC_ToolButton) {
3546 bflags |= State_Sunken;
3547 mflags |= State_MouseOver | State_Sunken;
3548 }
else if (toolbutton->activeSubControls & SC_ToolButtonMenu) {
3549 mflags |= State_Sunken;
3550 bflags |= State_MouseOver;
3554 QStyleOption tool = *toolbutton;
3555 if (toolbutton->subControls & SC_ToolButton) {
3556 if (flags & (State_Sunken | State_On | State_Raised) || !autoRaise) {
3557 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup && autoRaise) {
3558 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ToolBarTheme);
3559 theme.partId = TP_SPLITBUTTON;
3560 theme.rect = button;
3561 if (!(bflags & State_Enabled))
3562 stateId = TS_DISABLED;
3563 else if (bflags & State_Sunken)
3564 stateId = TS_PRESSED;
3565 else if (bflags & State_MouseOver || !(flags & State_AutoRaise))
3566 stateId = flags & State_On ? TS_HOTCHECKED : TS_HOT;
3567 else if (bflags & State_On)
3568 stateId = TS_CHECKED;
3570 stateId = TS_NORMAL;
3571 if (option->direction == Qt::RightToLeft)
3572 theme.mirrorHorizontally =
true;
3573 theme.stateId = stateId;
3574 d->drawBackground(theme);
3576 tool.rect = option->rect;
3577 tool.state = bflags;
3579 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
3581 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter, widget);
3586 if (toolbutton->state & State_HasFocus) {
3587 QStyleOptionFocusRect fr;
3588 fr.QStyleOption::operator=(*toolbutton);
3589 fr.rect.adjust(3, 3, -3, -3);
3590 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
3591 fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator,
3592 toolbutton, widget), 0);
3593 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
3595 QStyleOptionToolButton label = *toolbutton;
3596 label.state = bflags;
3599 label.state &= ~State_Sunken;
3600 label.rect = button.adjusted(fw, fw, -fw, -fw);
3601 proxy()->drawControl(CE_ToolButtonLabel, &label, painter, widget);
3603 if (toolbutton->subControls & SC_ToolButtonMenu) {
3604 tool.rect = menuarea;
3605 tool.state = mflags;
3607 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, painter, widget);
3609 tool.state = mflags;
3610 menuarea.adjust(-2, 0, 0, 0);
3612 if ((bflags & State_Sunken) != (mflags & State_Sunken)){
3614 painter->setClipRect(menuarea);
3615 tool.rect = option->rect;
3616 proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, painter,
nullptr);
3621 painter->setPen(option->palette.dark().color());
3622 painter->drawLine(menuarea.left(), menuarea.top() + 3,
3623 menuarea.left(), menuarea.bottom() - 3);
3624 painter->setPen(option->palette.light().color());
3625 painter->drawLine(menuarea.left() - 1, menuarea.top() + 3,
3626 menuarea.left() - 1, menuarea.bottom() - 3);
3628 tool.rect = menuarea.adjusted(2, 3, -2, -1);
3629 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
3632 }
else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
3633 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
3634 QRect ir = toolbutton->rect;
3635 QStyleOptionToolButton newBtn = *toolbutton;
3636 newBtn.rect = QRect(ir.right() + 4 - mbi, ir.height() - mbi + 4, mbi - 5, mbi - 5);
3637 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
3644 if (
const auto *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(option)) {
3645 const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget);
3646 bool isActive = tb->titleBarState & QStyle::State_Active;
3647 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme);
3648 if (sub & SC_TitleBarLabel) {
3649 partId = (tb->titleBarState & Qt::WindowMinimized) ? WP_MINCAPTION : WP_CAPTION;
3650 theme.rect = option->rect;
3651 if (widget && !widget->isEnabled())
3652 stateId = CS_DISABLED;
3654 stateId = CS_ACTIVE;
3656 stateId = CS_INACTIVE;
3658 theme.partId = partId;
3659 theme.stateId = stateId;
3660 d->drawBackground(theme);
3662 QRect ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
3665 GetThemeEnumValue(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE, TMT_TEXTSHADOWTYPE, &result);
3667 COLORREF textShadowRef;
3668 GetThemeColor(theme.handle(), WP_CAPTION, isActive ? CS_ACTIVE : CS_INACTIVE,
TMT_TEXTSHADOWCOLOR, &textShadowRef);
3669 QColor textShadow = qRgb(GetRValue(textShadowRef), GetGValue(textShadowRef), GetBValue(textShadowRef));
3670 painter->setPen(textShadow);
3671 painter->drawText(
int(ir.x() + 3 * factor),
int(ir.y() + 2 * factor),
3672 int(ir.width() - 1 * factor), ir.height(),
3673 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3675 COLORREF captionText = GetSysColor(isActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT);
3676 QColor textColor = qRgb(GetRValue(captionText), GetGValue(captionText), GetBValue(captionText));
3677 painter->setPen(textColor);
3678 painter->drawText(
int(ir.x() + 2 * factor),
int(ir.y() + 1 * factor),
3679 int(ir.width() - 2 * factor), ir.height(),
3680 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3682 if (sub & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3683 theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarSysMenu, widget);
3684 partId = WP_SYSBUTTON;
3685 if ((widget && !widget->isEnabled()) || !isActive)
3686 stateId = SBS_DISABLED;
3687 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_Sunken))
3688 stateId = SBS_PUSHED;
3689 else if (option->activeSubControls == SC_TitleBarSysMenu && (option->state & State_MouseOver))
3692 stateId = SBS_NORMAL;
3693 if (!tb->icon.isNull()) {
3694 tb->icon.paint(painter, theme.rect);
3696 theme.partId = partId;
3697 theme.stateId = stateId;
3698 if (theme.size().isEmpty()) {
3699 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, tb, widget);
3700 const auto dpr = QStyleHelper::getDpr(widget);
3701 const auto icon = proxy()->standardIcon(SP_TitleBarMenuButton, tb, widget);
3702 const auto pm = icon.pixmap(QSize(extent, extent), dpr);
3703 drawItemPixmap(painter, theme.rect, Qt::AlignCenter, pm);
3705 d->drawBackground(theme);
3710 if (sub & SC_TitleBarMinButton && tb->titleBarFlags & Qt::WindowMinimizeButtonHint
3711 && !(tb->titleBarState & Qt::WindowMinimized)) {
3712 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMinButton, isActive, WP_MINBUTTON, &theme);
3713 d->drawBackground(theme);
3715 if (sub & SC_TitleBarMaxButton && tb->titleBarFlags & Qt::WindowMaximizeButtonHint
3716 && !(tb->titleBarState & Qt::WindowMaximized)) {
3717 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMaxButton, isActive, WP_MAXBUTTON, &theme);
3718 d->drawBackground(theme);
3720 if (sub & SC_TitleBarContextHelpButton
3721 && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
3722 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarContextHelpButton, isActive, WP_HELPBUTTON, &theme);
3723 d->drawBackground(theme);
3725 bool drawNormalButton = (sub & SC_TitleBarNormalButton)
3726 && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3727 && (tb->titleBarState & Qt::WindowMinimized))
3728 || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3729 && (tb->titleBarState & Qt::WindowMaximized)));
3730 if (drawNormalButton) {
3731 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarNormalButton, isActive, WP_RESTOREBUTTON, &theme);
3732 d->drawBackground(theme);
3734 if (sub & SC_TitleBarShadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3735 && !(tb->titleBarState & Qt::WindowMinimized)) {
3736 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarShadeButton, isActive, WP_MINBUTTON, &theme);
3737 d->drawBackground(theme);
3739 if (sub & SC_TitleBarUnshadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint
3740 && tb->titleBarState & Qt::WindowMinimized) {
3741 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarUnshadeButton, isActive, WP_RESTOREBUTTON, &theme);
3742 d->drawBackground(theme);
3744 if (sub & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3745 populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarCloseButton, isActive, WP_CLOSEBUTTON, &theme);
3746 d->drawBackground(theme);
3751#if QT_CONFIG(mdiarea)
3752 case CC_MdiControls: {
3753 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::WindowTheme, WP_MDICLOSEBUTTON, CBS_NORMAL);
3754 if (Q_UNLIKELY(!theme.isValid()))
3757 if (option->subControls.testFlag(SC_MdiCloseButton)) {
3758 populateMdiButtonTheme(proxy(), widget, option, SC_MdiCloseButton, WP_MDICLOSEBUTTON, &theme);
3759 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3761 if (option->subControls.testFlag(SC_MdiNormalButton)) {
3762 populateMdiButtonTheme(proxy(), widget, option, SC_MdiNormalButton, WP_MDIRESTOREBUTTON, &theme);
3763 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3765 if (option->subControls.testFlag(QStyle::SC_MdiMinButton)) {
3766 populateMdiButtonTheme(proxy(), widget, option, SC_MdiMinButton, WP_MDIMINBUTTON, &theme);
3767 d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget));
3775 if (
const auto *dial = qstyleoption_cast<
const QStyleOptionSlider *>(option))
3776 QStyleHelper::drawDial(dial, painter);
3781 if (
const QStyleOptionComboBox *cmb = qstyleoption_cast<
const QStyleOptionComboBox *>(option)) {
3782 if (cmb->editable) {
3783 if (sub & SC_ComboBoxEditField) {
3784 partId = EP_EDITBORDER_NOSCROLL;
3785 if (!(flags & State_Enabled))
3786 stateId = ETS_DISABLED;
3787 else if (flags & State_MouseOver)
3789 else if (flags & State_HasFocus)
3790 stateId = ETS_FOCUSED;
3792 stateId = ETS_NORMAL;
3794 QWindowsThemeData theme(widget, painter,
3795 QWindowsVistaStylePrivate::EditTheme,
3796 partId, stateId, r);
3798 d->drawBackground(theme);
3800 if (sub & SC_ComboBoxArrow) {
3801 QRect subRect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3802 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3803 theme.rect = subRect;
3804 partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3806 if (!(cmb->state & State_Enabled))
3807 stateId = CBXS_DISABLED;
3808 else if (cmb->state & State_Sunken || cmb->state & State_On)
3809 stateId = CBXS_PRESSED;
3810 else if (cmb->state & State_MouseOver && option->activeSubControls & SC_ComboBoxArrow)
3813 stateId = CBXS_NORMAL;
3815 theme.partId = partId;
3816 theme.stateId = stateId;
3817 d->drawBackground(theme);
3821 if (sub & SC_ComboBoxFrame) {
3822 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3823 theme.rect = option->rect;
3824 theme.partId = CP_READONLY;
3825 if (!(cmb->state & State_Enabled))
3826 theme.stateId = CBXS_DISABLED;
3827 else if (cmb->state & State_Sunken || cmb->state & State_On)
3828 theme.stateId = CBXS_PRESSED;
3829 else if (cmb->state & State_MouseOver)
3830 theme.stateId = CBXS_HOT;
3832 theme.stateId = CBXS_NORMAL;
3833 d->drawBackground(theme);
3835 if (sub & SC_ComboBoxArrow) {
3836 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ComboboxTheme);
3837 theme.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
3838 theme.partId = option->direction == Qt::RightToLeft ? CP_DROPDOWNBUTTONLEFT : CP_DROPDOWNBUTTONRIGHT;
3839 if (!(cmb->state & State_Enabled))
3840 theme.stateId = CBXS_DISABLED;
3842 theme.stateId = CBXS_NORMAL;
3843 d->drawBackground(theme);
3845 if ((sub & SC_ComboBoxEditField) && (flags & State_HasFocus)) {
3846 QStyleOptionFocusRect fropt;
3847 fropt.QStyleOption::operator=(*cmb);
3848 fropt.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget);
3849 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3856 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
3857 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::ScrollBarTheme);
3858 bool maxedOut = (scrollbar->maximum == scrollbar->minimum);
3860 flags &= ~State_Enabled;
3862 bool isHorz = flags & State_Horizontal;
3863 bool isRTL = option->direction == Qt::RightToLeft;
3864 if (sub & SC_ScrollBarAddLine) {
3865 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddLine, widget);
3866 partId = SBP_ARROWBTN;
3867 if (!(flags & State_Enabled))
3868 stateId = (isHorz ? (isRTL ? ABS_LEFTDISABLED : ABS_RIGHTDISABLED) : ABS_DOWNDISABLED);
3869 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_Sunken))
3870 stateId = (isHorz ? (isRTL ? ABS_LEFTPRESSED : ABS_RIGHTPRESSED) : ABS_DOWNPRESSED);
3871 else if (scrollbar->activeSubControls & SC_ScrollBarAddLine && (scrollbar->state & State_MouseOver))
3872 stateId = (isHorz ? (isRTL ? ABS_LEFTHOT : ABS_RIGHTHOT) : ABS_DOWNHOT);
3873 else if (scrollbar->state & State_MouseOver)
3874 stateId = (isHorz ? (isRTL ? ABS_LEFTHOVER : ABS_RIGHTHOVER) : ABS_DOWNHOVER);
3876 stateId = (isHorz ? (isRTL ? ABS_LEFTNORMAL : ABS_RIGHTNORMAL) : ABS_DOWNNORMAL);
3877 theme.partId = partId;
3878 theme.stateId = stateId;
3879 d->drawBackground(theme);
3881 if (sub & SC_ScrollBarSubLine) {
3882 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubLine, widget);
3883 partId = SBP_ARROWBTN;
3884 if (!(flags & State_Enabled))
3885 stateId = (isHorz ? (isRTL ? ABS_RIGHTDISABLED : ABS_LEFTDISABLED) : ABS_UPDISABLED);
3886 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_Sunken))
3887 stateId = (isHorz ? (isRTL ? ABS_RIGHTPRESSED : ABS_LEFTPRESSED) : ABS_UPPRESSED);
3888 else if (scrollbar->activeSubControls & SC_ScrollBarSubLine && (scrollbar->state & State_MouseOver))
3889 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOT : ABS_LEFTHOT) : ABS_UPHOT);
3890 else if (scrollbar->state & State_MouseOver)
3891 stateId = (isHorz ? (isRTL ? ABS_RIGHTHOVER : ABS_LEFTHOVER) : ABS_UPHOVER);
3893 stateId = (isHorz ? (isRTL ? ABS_RIGHTNORMAL : ABS_LEFTNORMAL) : ABS_UPNORMAL);
3894 theme.partId = partId;
3895 theme.stateId = stateId;
3896 d->drawBackground(theme);
3899 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3900 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget));
3901 theme.rect = theme.rect.united(proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget));
3902 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3903 stateId = SCRBS_DISABLED;
3904 theme.partId = partId;
3905 theme.stateId = stateId;
3906 d->drawBackground(theme);
3908 if (sub & SC_ScrollBarSubPage) {
3909 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubPage, widget);
3910 partId = flags & State_Horizontal ? SBP_UPPERTRACKHORZ : SBP_UPPERTRACKVERT;
3911 if (!(flags & State_Enabled))
3912 stateId = SCRBS_DISABLED;
3913 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_Sunken))
3914 stateId = SCRBS_PRESSED;
3915 else if (scrollbar->activeSubControls & SC_ScrollBarSubPage && (scrollbar->state & State_MouseOver))
3916 stateId = SCRBS_HOT;
3918 stateId = SCRBS_NORMAL;
3919 theme.partId = partId;
3920 theme.stateId = stateId;
3921 d->drawBackground(theme);
3923 if (sub & SC_ScrollBarAddPage) {
3924 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddPage, widget);
3925 partId = flags & State_Horizontal ? SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT;
3926 if (!(flags & State_Enabled))
3927 stateId = SCRBS_DISABLED;
3928 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_Sunken))
3929 stateId = SCRBS_PRESSED;
3930 else if (scrollbar->activeSubControls & SC_ScrollBarAddPage && (scrollbar->state & State_MouseOver))
3931 stateId = SCRBS_HOT;
3933 stateId = SCRBS_NORMAL;
3934 theme.partId = partId;
3935 theme.stateId = stateId;
3936 d->drawBackground(theme);
3938 if (sub & SC_ScrollBarSlider) {
3939 theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
3940 if (!(flags & State_Enabled))
3941 stateId = SCRBS_DISABLED;
3942 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_Sunken))
3943 stateId = SCRBS_PRESSED;
3944 else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_MouseOver))
3945 stateId = SCRBS_HOT;
3946 else if (option->state & State_MouseOver)
3947 stateId = SCRBS_HOVER;
3949 stateId = SCRBS_NORMAL;
3952 theme.partId = flags & State_Horizontal ? SBP_THUMBBTNHORZ : SBP_THUMBBTNVERT;
3953 theme.stateId = stateId;
3954 d->drawBackground(theme);
3960#if QT_CONFIG(spinbox)
3962 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(option)) {
3963 QWindowsThemeData theme(widget, painter, QWindowsVistaStylePrivate::SpinTheme);
3964 if (sb->frame && (sub & SC_SpinBoxFrame)) {
3965 partId = EP_EDITBORDER_NOSCROLL;
3966 if (!(flags & State_Enabled))
3967 stateId = ETS_DISABLED;
3968 else if (flags & State_MouseOver)
3970 else if (flags & State_HasFocus)
3971 stateId = ETS_SELECTED;
3973 stateId = ETS_NORMAL;
3975 QWindowsThemeData ftheme(widget, painter,
3976 QWindowsVistaStylePrivate::EditTheme,
3977 partId, stateId, r);
3982 ftheme.noContent = (widget !=
nullptr);
3983 d->drawBackground(ftheme);
3985 if (sub & SC_SpinBoxUp) {
3986 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget).adjusted(0, 0, 0, 1);
3988 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled) || !(flags & State_Enabled))
3989 stateId = UPS_DISABLED;
3990 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken))
3991 stateId = UPS_PRESSED;
3992 else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_MouseOver))
3995 stateId = UPS_NORMAL;
3996 theme.partId = partId;
3997 theme.stateId = stateId;
3998 d->drawBackground(theme);
4000 if (sub & SC_SpinBoxDown) {
4001 theme.rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
4003 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled) || !(flags & State_Enabled))
4004 stateId = DNS_DISABLED;
4005 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken))
4006 stateId = DNS_PRESSED;
4007 else if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_MouseOver))
4010 stateId = DNS_NORMAL;
4011 theme.partId = partId;
4012 theme.stateId = stateId;
4013 d->drawBackground(theme);
4020 QWindowsStyle::drawComplexControl(control, option, painter, widget);