📄 qmotifstyle.cpp
字号:
if (pe == PE_IndicatorArrowUp || pe == PE_IndicatorArrowLeft) { if (vertical) { rot(bFill,3); rot(bLeft,3); rot(bTop,3); rot(bBot,3); bFill.translate(0, rect.height() - 1); bLeft.translate(0, rect.height() - 1); bTop.translate(0, rect.height() - 1); bBot.translate(0, rect.height() - 1); } else { rot(bFill,2); rot(bLeft,2); rot(bTop,2); rot(bBot,2); bFill.translate(rect.width() - 1, rect.height() - 1); bLeft.translate(rect.width() - 1, rect.height() - 1); bTop.translate(rect.width() - 1, rect.height() - 1); bBot.translate(rect.width() - 1, rect.height() - 1); } if (opt->state & State_Sunken) colspec = horizontal ? 0x2334 : 0x2343; else colspec = horizontal ? 0x1443 : 0x1434; } else { if (vertical) { rot(bFill,1); rot(bLeft,1); rot(bTop,1); rot(bBot,1); bFill.translate(rect.width() - 1, 0); bLeft.translate(rect.width() - 1, 0); bTop.translate(rect.width() - 1, 0); bBot.translate(rect.width() - 1, 0); } if (opt->state & State_Sunken) colspec = horizontal ? 0x2443 : 0x2434; else colspec = horizontal ? 0x1334 : 0x1343; } bFill.translate(rect.x(), rect.y()); bLeft.translate(rect.x(), rect.y()); bTop.translate(rect.x(), rect.y()); bBot.translate(rect.x(), rect.y()); const QColor *cols[5]; if (opt->state & State_Enabled) { cols[0] = 0; cols[1] = &opt->palette.button().color(); cols[2] = &opt->palette.mid().color(); cols[3] = &opt->palette.light().color(); cols[4] = &opt->palette.dark().color(); } else { cols[0] = 0; cols[1] = &opt->palette.mid().color(); cols[2] = &opt->palette.mid().color(); cols[3] = &opt->palette.mid().color(); cols[4] = &opt->palette.mid().color(); }#define CMID *cols[(colspec>>12) & 0xf]#define CLEFT *cols[(colspec>>8) & 0xf]#define CTOP *cols[(colspec>>4) & 0xf]#define CBOT *cols[colspec & 0xf] QPen savePen = p->pen(); QBrush saveBrush = p->brush(); QPen pen(Qt::NoPen); QBrush brush = opt->palette.brush((opt->state & State_Enabled) ? QPalette::Button : QPalette::Mid); p->setPen(pen); p->setBrush(brush); p->drawPolygon(bFill); p->setBrush(Qt::NoBrush); p->setPen(CLEFT); p->drawPolyline(bLeft); p->setPen(CTOP); p->drawPolyline(bTop); p->setPen(CBOT); p->drawPolyline(bBot); p->setBrush(saveBrush); p->setPen(savePen);#undef CMID#undef CLEFT#undef CTOP#undef CBOT if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText)) p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern)); break; } case PE_IndicatorDockWidgetResizeHandle: { const int motifOffset = 10; int sw = pixelMetric(PM_SplitterWidth); if (opt->state & State_Horizontal) { int yPos = opt->rect.y() + opt->rect.height() / 2; int kPos = opt->rect.right() - motifOffset - sw; int kSize = sw - 2; qDrawShadeLine(p, opt->rect.left(), yPos, kPos, yPos, opt->palette); qDrawShadePanel(p, kPos, yPos - sw / 2 + 1, kSize, kSize, opt->palette, false, 1, &opt->palette.brush(QPalette::Button)); qDrawShadeLine(p, kPos + kSize - 1, yPos, opt->rect.right(), yPos, opt->palette); } else { int xPos = opt->rect.x() + opt->rect.width() / 2; int kPos = motifOffset; int kSize = sw - 2; qDrawShadeLine(p, xPos, opt->rect.top() + kPos + kSize - 1, xPos, opt->rect.bottom(), opt->palette); qDrawShadePanel(p, xPos - sw / 2 + 1, opt->rect.top() + kPos, kSize, kSize, opt->palette, false, 1, &opt->palette.brush(QPalette::Button)); qDrawShadeLine(p, xPos, opt->rect.top(), xPos, opt->rect.top() + kPos, opt->palette); } break; } case PE_IndicatorMenuCheckMark: { const int markW = 6; const int markH = 6; int posX = opt->rect.x() + (opt->rect.width() - markW) / 2 - 1; int posY = opt->rect.y() + (opt->rect.height() - markH) / 2; int dfw = pixelMetric(PM_DefaultFrameWidth); if (dfw < 2) { // Could do with some optimizing/caching... QPolygon a(7*2); int i, xx, yy; xx = posX; yy = 3 + posY; for (i=0; i<3; i++) { a.setPoint(2*i, xx, yy); a.setPoint(2*i+1, xx, yy+2); xx++; yy++; } yy -= 2; for (i=3; i<7; i++) { a.setPoint(2*i, xx, yy); a.setPoint(2*i+1, xx, yy+2); xx++; yy--; } if (! (opt->state & State_Enabled) && ! (opt->state & State_On)) { int pnt; p->setPen(opt->palette.highlightedText().color()); QPoint offset(1,1); for (pnt = 0; pnt < (int)a.size(); pnt++) a[pnt] += offset; p->drawPolyline(a); for (pnt = 0; pnt < (int)a.size(); pnt++) a[pnt] -= offset; } p->setPen(opt->palette.text().color()); p->drawPolyline(a); qDrawShadePanel(p, posX-2, posY-2, markW+4, markH+6, opt->palette, true, dfw); } else qDrawShadePanel(p, posX, posY, markW, markH, opt->palette, true, dfw, &opt->palette.brush(QPalette::Mid)); break; } case PE_IndicatorProgressChunk: { bool vertical = false; if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) vertical = (pb2->orientation == Qt::Vertical); if (!vertical) { p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height(), opt->palette.brush(QPalette::Highlight)); } else { p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height(), opt->palette.brush(QPalette::Highlight)); } } break; default: QCommonStyle::drawPrimitive(pe, opt, p, w); break; }}/*! \reimp*/void QMotifStyle::drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *widget) const{ switch(element) { case CE_Splitter: { QStyleOption handleOpt = *opt; if (handleOpt.state & State_Horizontal) handleOpt.state &= ~State_Horizontal; else handleOpt.state |= State_Horizontal; drawPrimitive(PE_IndicatorDockWidgetResizeHandle, &handleOpt, p, widget); break; } case CE_ScrollBarSubLine: case CE_ScrollBarAddLine:{ PrimitiveElement pe; if (element == CE_ScrollBarAddLine) pe = (opt->state & State_Horizontal) ? (opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft) : PE_IndicatorArrowDown; else pe = (opt->state & State_Horizontal) ? (opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight) : PE_IndicatorArrowUp; QStyleOption arrowOpt = *opt; arrowOpt.state |= State_Enabled; drawPrimitive(pe, &arrowOpt, p, widget); if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText)) { int fw = pixelMetric(PM_DefaultFrameWidth); p->fillRect(opt->rect.adjusted(fw, fw, -fw, -fw), QBrush(p->background().color(), Qt::Dense5Pattern)); } }break; case CE_ScrollBarSubPage: case CE_ScrollBarAddPage: p->fillRect(opt->rect, opt->palette.brush((opt->state & State_Enabled) ? QPalette::Mid : QPalette::Window)); break; case CE_ScrollBarSlider: { QStyleOption bevelOpt = *opt; bevelOpt.state |= State_Raised; bevelOpt.state &= ~(State_Sunken | State_On); p->save(); p->setBrushOrigin(bevelOpt.rect.topLeft()); drawPrimitive(PE_PanelButtonBevel, &bevelOpt, p, widget); p->restore(); if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText)) p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern)); break; } case CE_RadioButton: case CE_CheckBox: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { bool isRadio = (element == CE_RadioButton); QStyleOptionButton subopt = *btn; subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator : SE_CheckBoxIndicator, btn, widget); drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox, &subopt, p, widget); subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents : SE_CheckBoxContents, btn, widget); drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, p, widget); if ((btn->state & State_HasFocus) && (!focus || !focus->isVisible())) { QStyleOptionFocusRect fropt; fropt.QStyleOption::operator=(*btn); fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect : SE_CheckBoxFocusRect, btn, widget); drawPrimitive(PE_FrameFocusRect, &fropt, p, widget); } } break; case CE_PushButton: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { drawControl(CE_PushButtonBevel, btn, p, widget); QStyleOptionButton subopt = *btn; subopt.rect = subElementRect(SE_PushButtonContents, btn, widget); drawControl(CE_PushButtonLabel, &subopt, p, widget); if ((btn->state & State_HasFocus) && (!focus || !focus->isVisible())) { QStyleOptionFocusRect fropt; fropt.QStyleOption::operator=(*btn); fropt.rect = subElementRect(SE_PushButtonFocusRect, btn, widget); drawPrimitive(PE_FrameFocusRect, &fropt, p, widget); } } break; case CE_PushButtonBevel: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { int diw, x1, y1, x2, y2; p->setPen(opt->palette.foreground().color()); p->setBrush(QBrush(opt->palette.button().color(), Qt::NoBrush)); diw = pixelMetric(PM_ButtonDefaultIndicator); opt->rect.getCoords(&x1, &y1, &x2, &y2); if (btn->features & (QStyleOptionButton::AutoDefaultButton|QStyleOptionButton::DefaultButton)) { x1 += diw; y1 += diw; x2 -= diw; y2 -= diw; } if (btn->features & QStyleOptionButton::DefaultButton) { if (diw == 0) { QPolygon a; a.setPoints(9, x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1, x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1); p->setPen(opt->palette.shadow().color()); p->drawPolygon(a); x1 += 2; y1 += 2; x2 -= 2; y2 -= 2; } else { qDrawShadePanel(p, opt->rect.adjusted(1, 1, -1, -1), opt->palette, true); } } if (!(btn->features & QStyleOptionButton::Flat) || (btn->state & (State_Sunken | State_On))) { QStyleOptionButton newOpt = *btn; newOpt.rect = QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1); p->setBrushOrigin(p->brushOrigin()); drawPrimitive(PE_PanelButtonCommand, &newOpt, p, widget); } if (btn->features & QStyleOptionButton::HasMenu) { int mbi = pixelMetric(PM_MenuButtonIndicator, btn, widget); QRect ir = btn->rect; QStyleOptionButton newBtn = *btn; newBtn.rect = QRect(ir.right() - mbi - 3, ir.y() + 4, mbi, ir.height() - 8); drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget); } break; }#ifndef QT_NO_TABBAR case CE_TabBarTabShape: if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { const int default_frame = pixelMetric(PM_DefaultFrameWidth, tab, widget); const int frame_offset = (default_frame > 1) ? 1 : 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -