📄 qwindowsstyle.cpp
字号:
static const QPoint pts3[] = { // background lines QPoint(2, 9), QPoint(3, 9), QPoint(4, 10), QPoint(7, 10), QPoint(8, 9), QPoint(9, 9), QPoint(9, 8), QPoint(10, 7), QPoint(10, 4), QPoint(9, 3) }; static const QPoint pts4[] = { // white lines QPoint(2, 10), QPoint(3, 10), QPoint(4, 11), QPoint(7, 11), QPoint(8, 10), QPoint(9, 10), QPoint(10, 9), QPoint(10, 8), QPoint(11, 7), QPoint(11, 4), QPoint(10, 3), QPoint(10, 2) }; static const QPoint pts5[] = { // inner fill QPoint(4, 2), QPoint(7, 2), QPoint(9, 4), QPoint(9, 7), QPoint(7, 9), QPoint(4, 9), QPoint(2, 7), QPoint(2, 4) }; // make sure the indicator is square QRect ir = opt->rect; if (opt->rect.width() < opt->rect.height()) { ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2); ir.setHeight(opt->rect.width()); } else if (opt->rect.height() < opt->rect.width()) { ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2); ir.setWidth(opt->rect.height()); } p->save(); bool down = opt->state & State_Sunken; bool enabled = opt->state & State_Enabled; bool on = opt->state & State_On; QPolygon a; p->translate(ir.x(), ir.y()); p->setPen(opt->palette.dark().color()); p->drawPolyline(pts1, PTSARRLEN(pts1)); p->setPen(opt->palette.shadow().color()); p->drawPolyline(pts2, PTSARRLEN(pts2)); p->setPen(opt->palette.midlight().color()); p->drawPolyline(pts3, PTSARRLEN(pts3)); p->setPen(opt->palette.light().color()); p->drawPolyline(pts4, PTSARRLEN(pts4)); 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 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken); } else { QCommonStyle::drawPrimitive(pe, opt, p, w); } } 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_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())) { QPen oldPen = p->pen(); p->setPen(QPen(opt->palette.dark().color())); p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight()); } 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, yoff, x + w, yoff); p->setPen(menuitem->palette.light().color()); p->drawLine(x, yoff + 1, x + w, 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('\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(), menuitem->rect.bottomRight())); 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 = mbi->state & State_HasFocus; bool down = mbi->state & State_Sunken; QStyleOptionMenuItem newMbi = *mbi; p->fillRect(mbi->rect, mbi->palette.brush(QPalette::Button)); if (active || hasFocus) { QBrush b = mbi->palette.brush(QPalette::Button); if (active && down) p->setBrushOrigin(p->brushOrigin() + QPoint(1, 1)); if (active && hasFocus) qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(), mbi->rect.height(), mbi->palette, active && down, 1, 0, &b); if (active && down) { newMbi.rect.translate(pixelMetric(PM_ButtonShiftHorizontal, mbi, widget), pixelMetric(PM_ButtonShiftVertical, mbi, widget)); p->setBrushOrigin(p->brushOrigin() - QPoint(1, 1)); } } QCommonStyle::drawControl(ce, &newMbi, p, widget); } break;#endif // QT_NO_M
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -