📄 qwindowsstyle.cpp
字号:
QColor fillColor = (down || !enabled) ? opt->palette.button().color() : opt->palette.base().color(); p->setPen(fillColor); p->setBrush(fillColor) ; p->drawPolygon(pts5, PTSARRLEN(pts5)); p->translate(-ir.x(), -ir.y()); // restore translate if (on) { p->setPen(Qt::NoPen); p->setBrush(opt->palette.text()); p->drawRect(ir.x() + 5, ir.y() + 4, 2, 4); p->drawRect(ir.x() + 4, ir.y() + 5, 4, 2); } p->restore(); break; }#ifndef QT_NO_FRAME case PE_Frame: case PE_FrameMenu: if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { if (frame->lineWidth == 2 || pe == PE_Frame) { QPalette popupPal = frame->palette; if (pe == PE_FrameMenu) { popupPal.setColor(QPalette::Light, frame->palette.background().color()); popupPal.setColor(QPalette::Midlight, frame->palette.light().color()); } if (use2000style && pe == PE_Frame && (frame->state & State_Raised)) qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken); else if (use2000style && pe == PE_Frame && (frame->state & State_Sunken)) { popupPal.setColor(QPalette::Midlight, frame->palette.background().color()); qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken); } else qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken); } else { QCommonStyle::drawPrimitive(pe, opt, p, w); } } else { QPalette popupPal = opt->palette; popupPal.setColor(QPalette::Light, opt->palette.background().color()); popupPal.setColor(QPalette::Midlight, opt->palette.light().color()); qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken); } break;#endif // QT_NO_FRAME case PE_IndicatorBranch: { // This is _way_ too similar to the common style. static const int decoration_size = 9; int mid_h = opt->rect.x() + opt->rect.width() / 2; int mid_v = opt->rect.y() + opt->rect.height() / 2; int bef_h = mid_h; int bef_v = mid_v; int aft_h = mid_h; int aft_v = mid_v; if (opt->state & State_Children) { int delta = decoration_size / 2; bef_h -= delta; bef_v -= delta; aft_h += delta; aft_v += delta; p->drawLine(bef_h + 2, bef_v + 4, bef_h + 6, bef_v + 4); if (!(opt->state & State_Open)) p->drawLine(bef_h + 4, bef_v + 2, bef_h + 4, bef_v + 6); QPen oldPen = p->pen(); p->setPen(opt->palette.dark().color()); p->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1); p->setPen(oldPen); } QBrush brush(opt->palette.dark().color(), Qt::Dense4Pattern); if (opt->state & State_Item) { if (opt->direction == Qt::RightToLeft) p->fillRect(opt->rect.left(), mid_v, bef_h - opt->rect.left(), 1, brush); else p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush); } if (opt->state & State_Sibling) p->fillRect(mid_h, aft_v, 1, opt->rect.bottom() - aft_v + 1, brush); if (opt->state & (State_Open | State_Children | State_Item | State_Sibling)) p->fillRect(mid_h, opt->rect.y(), 1, bef_v - opt->rect.y(), brush); break; } case PE_FrameButtonBevel: case PE_PanelButtonBevel: { QBrush fill; bool panel = pe != PE_FrameButtonBevel; p->setBrushOrigin(opt->rect.topLeft()); if (!(opt->state & State_Sunken) && (opt->state & State_On)) fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern); else fill = opt->palette.brush(QPalette::Button); if (opt->state & (State_Raised | State_On | State_Sunken)) { qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On), panel ? &fill : 0); } else { if (panel) p->fillRect(opt->rect, fill); else p->drawRect(opt->rect); } break; } case PE_FrameWindow: { QPalette popupPal = opt->palette; popupPal.setColor(QPalette::Light, opt->palette.background().color()); popupPal.setColor(QPalette::Midlight, opt->palette.light().color()); qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken); break; }#ifndef QT_NO_DOCKWIDGET case PE_IndicatorDockWidgetResizeHandle: { QPen oldPen = p->pen(); p->setPen(opt->palette.light().color()); if (opt->state & State_Horizontal) { p->drawLine(opt->rect.left(), opt->rect.top(), opt->rect.right(), opt->rect.top()); p->setPen(opt->palette.dark().color()); p->drawLine(opt->rect.left(), opt->rect.bottom() - 1, opt->rect.right(), opt->rect.bottom() - 1); p->setPen(opt->palette.shadow().color()); p->drawLine(opt->rect.left(), opt->rect.bottom(), opt->rect.right(), opt->rect.bottom()); } else { p->drawLine(opt->rect.left(), opt->rect.top(), opt->rect.left(), opt->rect.bottom()); p->setPen(opt->palette.dark().color()); p->drawLine(opt->rect.right() - 1, opt->rect.top(), opt->rect.right() - 1, opt->rect.bottom()); p->setPen(opt->palette.shadow().color()); p->drawLine(opt->rect.right(), opt->rect.top(), opt->rect.right(), opt->rect.bottom()); } p->setPen(oldPen); break; }case PE_FrameDockWidget: if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) { drawPrimitive(QStyle::PE_FrameWindow, opt, p, w); } break;#endif // QT_NO_DOCKWIDGET case PE_FrameStatusBar: qDrawShadePanel(p, opt->rect, opt->palette, true, 1, 0); break;#ifndef QT_NO_PROGRESSBAR case PE_IndicatorProgressChunk: { bool vertical = false, inverted = false; if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) { vertical = (pb2->orientation == Qt::Vertical); inverted = pb2->invertedAppearance; } int space = 2; int chunksize = pixelMetric(PM_ProgressBarChunkWidth, opt, w) - space; if (!vertical) { if (opt->rect.width() <= chunksize) space = 0; if (inverted) p->fillRect(opt->rect.x() + space, opt->rect.y(), opt->rect.width() - space, opt->rect.height(), opt->palette.brush(QPalette::Highlight)); else p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width() - space, opt->rect.height(), opt->palette.brush(QPalette::Highlight)); } else { if (opt->rect.height() <= chunksize) space = 0; if (inverted) p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height() - space, opt->palette.brush(QPalette::Highlight)); else p->fillRect(opt->rect.x(), opt->rect.y() + space, opt->rect.width(), opt->rect.height() - space, opt->palette.brush(QPalette::Highlight)); } } break;#endif // QT_NO_PROGRESSBAR case PE_FrameTabWidget: if (use2000style) { QRect rect = opt->rect; QPalette pal = opt->palette; qDrawWinButton(p, opt->rect, opt->palette, false, 0); break; } default: QCommonStyle::drawPrimitive(pe, opt, p, w); }}/*! \reimp */void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p, const QWidget *widget) const{ switch (ce) {#ifndef QT_NO_RUBBERBAND case CE_RubberBand: if (qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) { // ### workaround for slow general painter path QPixmap tiledPixmap(16, 16); QPainter pixmapPainter(&tiledPixmap); pixmapPainter.setPen(Qt::NoPen); pixmapPainter.setBrush(Qt::Dense4Pattern); pixmapPainter.setBackground(Qt::white); pixmapPainter.setBackgroundMode(Qt::OpaqueMode); pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height()); pixmapPainter.end(); tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage()); p->save(); QRect r = opt->rect; QStyleHintReturnMask mask; if (styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask)) p->setClipRegion(mask.region); p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap); p->restore(); return; } break;#endif // QT_NO_RUBBERBAND#if !defined(QT_NO_MENU) && !defined(QT_NO_MAINWINDOW) case CE_MenuBarEmptyArea: if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) { p->fillRect(opt->rect, opt->palette.button()); QPen oldPen = p->pen(); p->setPen(QPen(opt->palette.dark().color())); p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight()); p->setPen(oldPen); } break;#endif#ifndef QT_NO_MENU case CE_MenuItem: if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { int x, y, w, h; menuitem->rect.getRect(&x, &y, &w, &h); int tab = menuitem->tabWidth; bool dis = !(menuitem->state & State_Enabled); bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable ? menuitem->checked : false; bool act = menuitem->state & State_Selected; // windows always has a check column, regardless whether we have an icon or not int checkcol = qMax(menuitem->maxIconWidth, use2000style ? 20 : windowsCheckMarkWidth); QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button); p->fillRect(menuitem->rect, fill); if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){ int yoff = y-1 + h / 2; p->setPen(menuitem->palette.dark().color()); p->drawLine(x + 2, yoff, x + w - 4, yoff); p->setPen(menuitem->palette.light().color()); p->drawLine(x + 2, yoff + 1, x + w - 4, yoff + 1); return; } QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height())); if (checked) { if (act && !dis) { qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &menuitem->palette.brush(QPalette::Button)); } else { QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern); qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill); } } else if (!act) { p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button)); } // On Windows Style, if we have a checkable item and an icon we // draw the icon recessed to indicate an item is checked. If we // have no icon, we draw a checkmark instead. if (!menuitem->icon.isNull()) { QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; if (act && !dis) mode = QIcon::Active; QPixmap pixmap; if (checked) pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On); else pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode); int pixw = pixmap.width(); int pixh = pixmap.height(); if (act && !dis && !checked) qDrawShadePanel(p, vCheckRect, menuitem->palette, false, 1, &menuitem->palette.brush(QPalette::Button)); QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(vCheckRect.center()); p->setPen(menuitem->palette.text().color()); p->drawPixmap(pmr.topLeft(), pixmap); } else if (checked) { QStyleOptionMenuItem newMi = *menuitem; newMi.state = State_None; if (!dis) newMi.state |= State_Enabled; if (act) newMi.state |= State_On; newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + windowsItemFrame, menuitem->rect.y() + windowsItemFrame, checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2*windowsItemFrame)); drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget); } p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color()); QColor discol; if (dis) { discol = menuitem->palette.text().color(); p->setPen(discol); } int xm = windowsItemFrame + checkcol + windowsItemHMargin; int xpos = menuitem->rect.x() + xm; QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin); QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect); QString s = menuitem->text; if (!s.isEmpty()) { // draw text p->save(); int t = s.indexOf(QLatin1Char('\t')); int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!styleHint(SH_UnderlineShortcut, menuitem, widget)) text_flags |= Qt::TextHideMnemonic; text_flags |= Qt::AlignLeft; if (t >= 0) { QRect vShortcutRect = visualRect(opt->direction, menuitem->rect, QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom()))); if (dis && !act) { p->setPen(menuitem->palette.light().color()); p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1)); p->setPen(discol); } p->drawText(vShortcutRect, text_flags, s.mid(t + 1)); s = s.left(t); } QFont font = menuitem->font; if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem) font.setBold(true); p->setFont(font); if (dis && !act) { p->setPen(menuitem->palette.light().color()); p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t)); p->setPen(discol); } p->drawText(vTextRect, text_flags, s.left(t)); p->restore(); } if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow int dim = (h - 2 * windowsItemFrame) / 2; PrimitiveElement arrow; arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight; xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim; QRect vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim)); QStyleOptionMenuItem newMI = *menuitem; newMI.rect = vSubMenuRect; newMI.state = dis ? State_None : State_Enabled; if (act) newMI.palette.setColor(QPalette::ButtonText, newMI.palette.highlightedText().color()); drawPrimitive(arrow, &newMI, p, widget); } } break;#endif // QT_NO_MENU#ifndef QT_NO_MENUBAR case CE_MenuBarItem: if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { bool active = mbi->state & State_Selected; bool hasFocus =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -