📄 qmotifstyle.cpp
字号:
case CE_MenuBarItem: if (opt->state & State_Selected) // active item qDrawShadePanel(p, opt->rect, opt->palette, false, motifItemFrame, &opt->palette.brush(QPalette::Button)); else // other item p->fillRect(opt->rect, opt->palette.brush(QPalette::Button)); QCommonStyle::drawControl(element, opt, p, widget); break; case CE_HeaderSection: p->save(); p->setBrushOrigin(opt->rect.topLeft()); qDrawShadePanel(p, opt->rect, opt->palette, bool(opt->state & (State_Sunken|State_On)), pixelMetric(PM_DefaultFrameWidth), &opt->palette.brush((opt->state & State_Sunken) ? QPalette::Mid : QPalette::Button)); p->restore(); break; case CE_RubberBand: { QPixmap tiledPixmap(16, 16); QPainter pixmapPainter(&tiledPixmap); pixmapPainter.setPen(Qt::NoPen); pixmapPainter.setBrush(Qt::Dense4Pattern); pixmapPainter.setBackground(QBrush(opt->palette.base())); pixmapPainter.setBackgroundMode(Qt::OpaqueMode); pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height()); pixmapPainter.end(); // ### workaround for borked XRENDER 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(); } break;#ifndef QT_NO_PROGRESSBAR case CE_ProgressBarContents: if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { QRect rect = pb->rect; bool vertical = false; bool inverted = false; // Get extra style options if version 2 const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt); if (pb2) { vertical = (pb2->orientation == Qt::Vertical); inverted = pb2->invertedAppearance; } QTransform m; if (vertical) { rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height m.rotate(90); m.translate(0, -(rect.height() + rect.y()*2)); } QPalette pal2 = pb->palette; // Correct the highlight color if it is the same as the background if (pal2.highlight() == pal2.background()) pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active, QPalette::Highlight)); bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical); if (inverted) reverse = !reverse; int w = rect.width(); if (pb->minimum == 0 && pb->maximum == 0) { QRect progressBar; Q_D(const QMotifStyle); // draw busy indicator int x = (d->animateStep*8)% (w * 2); if (x > w) x = 2 * w - x; x = reverse ? rect.right() - x : x + rect.x(); p->setTransform(m); p->setPen(QPen(pal2.highlight().color(), 4)); p->drawLine(x, rect.y(), x, rect.height()); } else QCommonStyle::drawControl(element, opt, p, widget); } break;#endif // QT_NO_PROGRESSBAR default: QCommonStyle::drawControl(element, opt, p, widget); break; }}static int get_combo_extra_width(int h, int w, int *return_awh=0){ int awh, tmp; if (h < 8) { awh = 6; } else if (h < 14) { awh = h - 2; } else { awh = h/2; } tmp = (awh * 3) / 2; if (tmp > w / 2) { awh = w / 2 - 3; tmp = w / 2 + 3; } if (return_awh) *return_awh = awh; return tmp;}static void get_combo_parameters(const QRect &r, int &ew, int &awh, int &ax, int &ay, int &sh, int &dh, int &sy){ ew = get_combo_extra_width(r.height(), r.width(), &awh); sh = (awh+3)/4; if (sh < 3) sh = 3; dh = sh/2 + 1; ay = r.y() + (r.height()-awh-sh-dh)/2; if (ay < 0) { //panic mode ay = 0; sy = r.height(); } else { sy = ay+awh+dh; } ax = r.x() + r.width() - ew; ax += (ew-awh)/2;}/*! \reimp*/void QMotifStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const{ switch (cc) { case CC_ToolButton: if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) { QRect button, menuarea; button = subControlRect(cc, toolbutton, SC_ToolButton, widget); menuarea = subControlRect(cc, toolbutton, SC_ToolButtonMenu, widget); State bflags = toolbutton->state; if (bflags & State_AutoRaise) { if (!(bflags & State_MouseOver)) { bflags &= ~State_Raised; } } State mflags = bflags; if (toolbutton->activeSubControls & SC_ToolButton) bflags |= State_Sunken; if (toolbutton->activeSubControls & SC_ToolButtonMenu) mflags |= State_Sunken; QStyleOption tool(0); tool.palette = toolbutton->palette; if (toolbutton->subControls & SC_ToolButton) { if (bflags & (State_Sunken | State_On | State_Raised)) { tool.rect = button; tool.state = bflags; drawPrimitive(PE_PanelButtonTool, &tool, p, widget); } } if (toolbutton->subControls & SC_ToolButtonMenu) { tool.rect = menuarea; tool.state = mflags; if (mflags & (State_Sunken | State_On | State_Raised)) drawPrimitive(PE_IndicatorButtonDropDown, &tool, p, widget); drawPrimitive(PE_IndicatorArrowDown, &tool, p, widget); } if ((toolbutton->state & State_HasFocus) && (!focus || !focus->isVisible())) { QStyleOptionFocusRect fr; fr.QStyleOption::operator=(*toolbutton); fr.rect = toolbutton->rect.adjusted(3, 3, -3, -3); drawPrimitive(PE_FrameFocusRect, &fr, p, widget); } QStyleOptionToolButton label = *toolbutton; int fw = pixelMetric(PM_DefaultFrameWidth, opt, widget); label.rect = button.adjusted(fw, fw, -fw, -fw); drawControl(CE_ToolButtonLabel, &label, p, widget); } break;#ifndef QT_NO_SPINBOX case CC_SpinBox: if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { QStyleOptionSpinBox copy = *spinbox; PrimitiveElement pe; if (spinbox->frame && (spinbox->subControls & SC_SpinBoxFrame)) { QRect r = subControlRect(CC_SpinBox, spinbox, SC_SpinBoxFrame, widget); qDrawShadePanel(p, r, opt->palette, false, pixelMetric(PM_SpinBoxFrameWidth)); int fw = pixelMetric(QStyle::PM_DefaultFrameWidth); r = subControlRect(CC_SpinBox, spinbox, SC_SpinBoxEditField, widget).adjusted(-fw,-fw,fw,fw); QStyleOptionFrame lineOpt; lineOpt.QStyleOption::operator=(*opt); lineOpt.rect = r; lineOpt.lineWidth = fw; lineOpt.midLineWidth = 0; lineOpt.state |= QStyle::State_Sunken; drawPrimitive(QStyle::PE_FrameLineEdit, &lineOpt, p, widget); } if (spinbox->subControls & SC_SpinBoxUp) { copy.subControls = SC_SpinBoxUp; QPalette pal2 = spinbox->palette; if (!(spinbox->stepEnabled & QAbstractSpinBox::StepUpEnabled)) { pal2.setCurrentColorGroup(QPalette::Disabled); copy.state &= ~State_Enabled; } copy.palette = pal2; if (spinbox->activeSubControls == SC_SpinBoxUp && (spinbox->state & State_Sunken)) { copy.state |= State_On; copy.state |= State_Sunken; } else { copy.state |= State_Raised; copy.state &= ~State_Sunken; } pe = (spinbox->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus : PE_IndicatorSpinUp); copy.rect = subControlRect(CC_SpinBox, spinbox, SC_SpinBoxUp, widget); drawPrimitive(pe, ©, p, widget); } if (spinbox->subControls & SC_SpinBoxDown) { copy.subControls = SC_SpinBoxDown; copy.state = spinbox->state; QPalette pal2 = spinbox->palette; if (!(spinbox->stepEnabled & QAbstractSpinBox::StepDownEnabled)) { pal2.setCurrentColorGroup(QPalette::Disabled); copy.state &= ~State_Enabled; } copy.palette = pal2; if (spinbox->activeSubControls == SC_SpinBoxDown && (spinbox->state & State_Sunken)) { copy.state |= State_On; copy.state |= State_Sunken; } else { copy.state |= State_Raised; copy.state &= ~State_Sunken; } pe = (spinbox->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus : PE_IndicatorSpinDown); copy.rect = subControlRect(CC_SpinBox, spinbox, SC_SpinBoxDown, widget); drawPrimitive(pe, ©, p, widget); } } break;#endif // QT_NO_SPINBOX#ifndef QT_NO_SLIDER case CC_Slider: if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { QRect groove = subControlRect(CC_Slider, opt, SC_SliderGroove, widget), handle = subControlRect(CC_Slider, opt, SC_SliderHandle, widget); if ((opt->subControls & SC_SliderGroove) && groove.isValid()) { qDrawShadePanel(p, groove, opt->palette, true, pixelMetric(PM_DefaultFrameWidth), &opt->palette.brush((opt->state & State_Enabled) ? QPalette::Mid : QPalette::Window)); if ((opt->state & State_HasFocus) && (!focus || !focus->isVisible())) { QStyleOption focusOpt = *opt; focusOpt.rect = subElementRect(SE_SliderFocusRect, opt, widget); drawPrimitive(PE_FrameFocusRect, &focusOpt, p, widget); } } if ((opt->subControls & SC_SliderHandle) && handle.isValid()) { QStyleOption bevelOpt = *opt; bevelOpt.state = (opt->state | State_Raised) & ~State_Sunken; bevelOpt.rect = handle; p->save(); p->setBrushOrigin(bevelOpt.rect.topLeft()); drawPrimitive(PE_PanelButtonBevel, &bevelOpt, p, widget); p->restore(); if (slider->orientation == Qt::Horizontal) { int mid = handle.x() + handle.width() / 2; qDrawShadeLine(p, mid, handle.y(), mid, handle.y() + handle.height() - 2, opt->palette, true, 1); } else { int mid = handle.y() + handle.height() / 2; qDrawShadeLine(p, handle.x(), mid, handle.x() + handle.width() - 2, mid, opt->palette, true, 1); } if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText)) p->fillRect(handle, QBrush(p->background().color(), Qt::Dense5Pattern)); } if (slider->subControls & SC_SliderTickmarks) { QStyleOptionSlider tmpSlider = *slider; tmpSlider.subControls = SC_SliderTickmarks; int frameWidth = pixelMetric(PM_DefaultFrameWidth); tmpSlider.rect.translate(frameWidth - 1, 0); QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget); } } break;#endif // QT_NO_SLIDER case CC_ComboBox: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { if (opt->subControls & SC_ComboBoxArrow) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -