📄 qwindowsxpstyle.cpp
字号:
QWindowsStyle, QCommonStyle, and QStyle, but the QWindowsXPStyle overloads of drawComplexControl(), drawControl(), drawControlMask(), drawPrimitive(), subControlRect(), and sizeFromContents(), are documented here. \img qwindowsxpstyle.png \sa QMacStyle, QWindowsStyle, QPlastiqueStyle, QCDEStyle, QMotifStyle*//*! Constructs a QWindowsStyle*/QWindowsXPStyle::QWindowsXPStyle() : QWindowsStyle(*new QWindowsXPStylePrivate){}/*! Destroys the style.*/QWindowsXPStyle::~QWindowsXPStyle(){}/*! \reimp */void QWindowsXPStyle::unpolish(QApplication *app){ QWindowsStyle::unpolish(app);}/*! \reimp */void QWindowsXPStyle::polish(QApplication *app){ QWindowsStyle::polish(app); if (!QWindowsXPStylePrivate::useXP()) return;}/*! \reimp */void QWindowsXPStyle::polish(QWidget *widget){ QWindowsStyle::polish(widget); if (!QWindowsXPStylePrivate::useXP()) return; if (qobject_cast<QAbstractButton*>(widget) || qobject_cast<QToolButton*>(widget) || qobject_cast<QTabBar*>(widget) || qobject_cast<QComboBox*>(widget) || qobject_cast<QScrollBar*>(widget) || qobject_cast<QSlider*>(widget) || qobject_cast<QHeaderView*>(widget) || qobject_cast<QAbstractSpinBox*>(widget) || qobject_cast<QSpinBox*>(widget) || widget->inherits("QWorkspaceChild") || widget->inherits("Q3TitleBar")) widget->setAttribute(Qt::WA_Hover);#ifndef QT_NO_RUBBERBAND if (qobject_cast<QRubberBand*>(widget)) { widget->setWindowOpacity(0.6); }#endif if (qobject_cast<QStackedWidget*>(widget) && qobject_cast<QTabWidget*>(widget->parent())) widget->parentWidget()->setAttribute(Qt::WA_ContentsPropagated); Q_D(QWindowsXPStyle); if (!d->hasInitColors) { // Get text color for group box labels COLORREF cref; XPThemeData theme(0, 0, QLatin1String("BUTTON"), 0, 0); pGetThemeColor(theme.handle(), BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, &cref); d->groupBoxTextColor = qRgb(GetRValue(cref), GetGValue(cref), GetBValue(cref)); pGetThemeColor(theme.handle(), BP_GROUPBOX, GBS_DISABLED, TMT_TEXTCOLOR, &cref); d->groupBoxTextColorDisabled = qRgb(GetRValue(cref), GetGValue(cref), GetBValue(cref)); // Where does this color come from? //pGetThemeColor(theme.handle(), TKP_TICS, TSS_NORMAL, TMT_COLOR, &cref); d->sliderTickColor = qRgb(165, 162, 148); d->hasInitColors = true; }}/*! \reimp */void QWindowsXPStyle::polish(QPalette &pal){ QWindowsStyle::polish(pal); pal.setBrush(QPalette::AlternateBase, pal.base().color().darker(110));}/*! \reimp */void QWindowsXPStyle::unpolish(QWidget *widget){#ifndef QT_NO_RUBBERBAND if (qobject_cast<QRubberBand*>(widget)) { widget->setWindowOpacity(1.0); }#endif Q_D(QWindowsXPStyle); // Unpolish of widgets is the first thing that // happens when a theme changes, or the theme // engine is turned off. So we detect it here. bool oldState = QWindowsXPStylePrivate::useXP(); bool newState = QWindowsXPStylePrivate::useXP(true); if ((oldState != newState) && newState) { d->cleanup(true); d->init(true); } else { // Cleanup handle map, if just changing style, // or turning it on. In both cases the values // already in the map might be old (other style). d->cleanupHandleMap(); } if (qobject_cast<QAbstractButton*>(widget) || qobject_cast<QToolButton*>(widget) || qobject_cast<QTabBar*>(widget) || qobject_cast<QComboBox*>(widget) || qobject_cast<QScrollBar*>(widget) || qobject_cast<QSlider*>(widget) || qobject_cast<QHeaderView*>(widget) || qobject_cast<QAbstractSpinBox*>(widget) || qobject_cast<QSpinBox*>(widget) || widget->inherits("QWorkspaceChild") || widget->inherits("Q3TitleBar")) widget->setAttribute(Qt::WA_Hover, false); QWindowsStyle::unpolish(widget);}/*! \reimp */QRect QWindowsXPStyle::subElementRect(SubElement sr, const QStyleOption *option, const QWidget *widget) const{ if (!QWindowsXPStylePrivate::useXP()) { return QWindowsStyle::subElementRect(sr, option, widget); } QRect rect(option->rect); switch(sr) { case SE_DockWidgetCloseButton: case SE_DockWidgetFloatButton: rect = QWindowsStyle::subElementRect(sr, option, widget); return rect.translated(0, 1); break; case SE_TabWidgetTabContents: if (qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option)) { rect = QWindowsStyle::subElementRect(sr, option, widget); if (sr == SE_TabWidgetTabContents) rect.adjust(0, 0, -2, -2); } break; case SE_TabWidgetTabBar: { rect = QWindowsStyle::subElementRect(sr, option, widget); const QStyleOptionTabWidgetFrame *twfOption = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option); if (twfOption && twfOption->direction == Qt::RightToLeft && (twfOption->shape == QTabBar::RoundedNorth || twfOption->shape == QTabBar::RoundedSouth)) { QStyleOptionTab otherOption; otherOption.shape = (twfOption->shape == QTabBar::RoundedNorth ? QTabBar::RoundedEast : QTabBar::RoundedSouth); int overlap = pixelMetric(PM_TabBarBaseOverlap, &otherOption, widget); int borderThickness = pixelMetric(PM_DefaultFrameWidth, option, widget); rect.adjust(-overlap + borderThickness, 0, -overlap + borderThickness, 0); } break;} case SE_PushButtonContents: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) { MARGINS borderSize; if (widget) { HTHEME theme = pOpenThemeData(QWindowsXPStylePrivate::winId(widget), L"Button"); if (theme) { int stateId; if (!(option->state & State_Enabled)) stateId = PBS_DISABLED; else if (option->state & State_Sunken) stateId = PBS_PRESSED; else if (option->state & State_MouseOver) stateId = PBS_HOT; else if (btn->features & QStyleOptionButton::DefaultButton) stateId = PBS_DEFAULTED; else stateId = PBS_NORMAL; int border = pixelMetric(PM_DefaultFrameWidth, btn, widget); rect = option->rect.adjusted(border, border, -border, -border); int result = pGetThemeMargins(theme, NULL, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, NULL, &borderSize); if (result == S_OK) { rect.adjust(borderSize.cxLeftWidth, borderSize.cyTopHeight, -borderSize.cxRightWidth, -borderSize.cyBottomHeight); rect = visualRect(option->direction, option->rect, rect); } } } } break; case SE_ProgressBarContents: rect = QCommonStyle::subElementRect(SE_ProgressBarGroove, option, widget); if (option->state & QStyle::State_Horizontal) rect.adjust(4, 3, -4, -3); else rect.adjust(3, 2, -3, -2); break; default: rect = QWindowsStyle::subElementRect(sr, option, widget); } return rect;}/*! \reimp*/void QWindowsXPStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *option, QPainter *p, const QWidget *widget) const{ QWindowsXPStylePrivate *d = const_cast<QWindowsXPStylePrivate*>(d_func()); if (!QWindowsXPStylePrivate::useXP()) { QWindowsStyle::drawPrimitive(pe, option, p, widget); return; } QString name; int partId = 0; int stateId = 0; QRect rect = option->rect; State flags = option->state; bool hMirrored = false; bool vMirrored = false; bool noBorder = false; bool noContent = false; int rotate = 0; switch (pe) { case PE_FrameTabBarBase: if (const QStyleOptionTabBarBase *tbb = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) { QRegion region(tbb->rect); p->save(); switch (tbb->shape) { case QTabBar::RoundedNorth: region -= tbb->selectedTabRect.adjusted(-1, 0 , 1, 0); p->setClipRegion(region); p->setPen(QPen(tbb->palette.dark(), 0)); p->drawLine(tbb->rect.topLeft(), tbb->rect.topRight()); break; case QTabBar::RoundedWest: region -= tbb->selectedTabRect.adjusted(0, -1 , 0, 1); p->setClipRegion(region); p->setPen(QPen(tbb->palette.dark(), 0)); p->drawLine(tbb->rect.left(), tbb->rect.top(), tbb->rect.left(), tbb->rect.bottom()); break; case QTabBar::RoundedSouth: region -= tbb->selectedTabRect.adjusted(-1, 0 , 1, 0); p->setClipRegion(region); p->setPen(QPen(tbb->palette.dark(), 0)); p->drawLine(tbb->rect.left(), tbb->rect.top(), tbb->rect.right(), tbb->rect.top()); break; case QTabBar::RoundedEast: region -= tbb->selectedTabRect.adjusted(0, -1 , 0, 1); p->setClipRegion(region); p->setPen(QPen(tbb->palette.dark(), 0)); p->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft()); break; case QTabBar::TriangularNorth: case QTabBar::TriangularEast: case QTabBar::TriangularWest: case QTabBar::TriangularSouth: p->restore(); QWindowsStyle::drawPrimitive(pe, option, p, widget); return; } p->restore(); } return; case PE_PanelButtonBevel: name = QLatin1String("BUTTON"); partId = BP_PUSHBUTTON; if (!(flags & State_Enabled)) stateId = PBS_DISABLED; else if ((flags & State_Sunken) || (flags & State_On)) stateId = PBS_PRESSED; else if (flags & State_MouseOver) stateId = PBS_HOT; //else if (flags & State_ButtonDefault) // stateId = PBS_DEFAULTED; else stateId = PBS_NORMAL; break; case PE_PanelButtonTool: if (widget && widget->inherits("QDockWidgetTitleButton")) { if (const QWidget *dw = widget->parentWidget()) if (dw->isWindow()) return; } name = QLatin1String("TOOLBAR"); partId = TP_BUTTON; if (!(flags & State_Enabled)) stateId = TS_DISABLED; else if (flags & State_Sunken) stateId = TS_PRESSED; else if (flags & State_MouseOver) stateId = flags & State_On ? TS_HOTCHECKED : TS_HOT; else if (flags & State_On) stateId = TS_CHECKED; else stateId = TS_NORMAL; break; case PE_IndicatorButtonDropDown: name = QLatin1String("TOOLBAR"); partId = TP_SPLITBUTTONDROPDOWN; if (!(flags & State_Enabled)) stateId = TS_DISABLED; else if (flags & State_Sunken) stateId = TS_PRESSED; else if (flags & State_MouseOver) stateId = flags & State_On ? TS_HOTCHECKED : TS_HOT; else if (flags & State_On) stateId = TS_CHECKED; else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -