📄 qwindowsstyle.cpp
字号:
case SH_MainWindow_SpaceBelowMenuBar: ret = 1; break; case SH_ItemView_ChangeHighlightOnFocus:#if defined(Q_WS_WIN) if (QSysInfo::WindowsVersion != QSysInfo::WV_95 && QSysInfo::WindowsVersion != QSysInfo::WV_NT) ret = 1; else#endif ret = 0; break; case SH_ToolBox_SelectedPageTitleBold: ret = 0; break;#if defined(Q_WS_WIN) case SH_UnderlineShortcut: ret = 1; if (QSysInfo::WindowsVersion != QSysInfo::WV_95 && QSysInfo::WindowsVersion != QSysInfo::WV_98 && QSysInfo::WindowsVersion != QSysInfo::WV_NT) { BOOL cues; SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0); ret = int(cues); // Do nothing if we always paint underlines Q_D(const QWindowsStyle); if (!ret && widget && d) {#ifndef QT_NO_MENUBAR const QMenuBar *menuBar = ::qobject_cast<const QMenuBar*>(widget); if (!menuBar && ::qobject_cast<const QMenu *>(widget)) { QWidget *w = QApplication::activeWindow(); if (w && w != widget) menuBar = qFindChild<QMenuBar *>(w); } // If we paint a menubar draw underlines if it has focus, or if alt is down, // or if a popup menu belonging to the menubar is active and paints underlines if (menuBar) { if (menuBar->hasFocus() || d->altDown()) ret = 1; // Otherwise draw underlines if the toplevel widget has seen an alt-press } else#endif // QT_NO_MENUBAR if (d->hasSeenAlt(widget)) { ret = 1; } } } break;#endif#ifndef QT_NO_RUBBERBAND case SH_RubberBand_Mask: if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) { ret = 0; if (rbOpt->shape == QRubberBand::Rectangle) { ret = true; if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) { mask->region = opt->rect; int size = 1; if (widget && widget->isWindow()) size = 4; mask->region -= opt->rect.adjusted(size, size, -size, -size); } } } break;#endif // QT_NO_RUBBERBAND default: ret = QCommonStyle::styleHint(hint, opt, widget, returnData); break; } return ret;}/*! \reimp */void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const{ // Used to restore across fallthrough cases. Currently only used in PE_IndicatorCheckBox bool doRestore = false; switch (pe) {#ifndef QT_NO_TOOLBAR case PE_IndicatorToolBarSeparator: { QRect rect = opt->rect; const int margin = 2; if(opt->state & State_Horizontal){ const int offset = rect.width()/2; p->setPen(QPen(opt->palette.dark().color())); p->drawLine(rect.bottomLeft().x() + offset, rect.bottomLeft().y() - margin, rect.topLeft().x() + offset, rect.topLeft().y() + margin); p->setPen(QPen(opt->palette.light().color())); p->drawLine(rect.bottomLeft().x() + offset + 1, rect.bottomLeft().y() - margin, rect.topLeft().x() + offset + 1, rect.topLeft().y() + margin); } else{ //Draw vertical separator const int offset = rect.height()/2; p->setPen(QPen(opt->palette.dark().color())); p->drawLine(rect.topLeft().x() + margin , rect.topLeft().y() + offset, rect.topRight().x() - margin, rect.topRight().y() + offset); p->setPen(QPen(opt->palette.light().color())); p->drawLine(rect.topLeft().x() + margin , rect.topLeft().y() + offset + 1, rect.topRight().x() - margin, rect.topRight().y() + offset + 1); } } break; case PE_IndicatorToolBarHandle: p->save(); p->translate(opt->rect.x(), opt->rect.y()); if (opt->state & State_Horizontal) { int x = opt->rect.width() / 2 - 4; if (QApplication::layoutDirection() == Qt::RightToLeft) x -= 2; if (opt->rect.height() > 4) { qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4, opt->palette, false, 1, 0); qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4, opt->palette, false, 1, 0); } } else { if (opt->rect.width() > 4) { int y = opt->rect.height() / 2 - 4; qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3, opt->palette, false, 1, 0); qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3, opt->palette, false, 1, 0); } } p->restore(); break;#endif // QT_NO_TOOLBAR case PE_FrameButtonTool: case PE_PanelButtonTool: {#ifndef QT_NO_DOCKWIDGET if (w && w->inherits("QDockWidgetTitleButton")) { if (const QDockWidget *dw = qobject_cast<const QDockWidget *>(w->parent())) if (dw->isFloating()){ qDrawWinButton(p, opt->rect.adjusted(1, 1, 0, 0), opt->palette, opt->state & (State_Sunken | State_On), &opt->palette.button()); return; } }#endif // QT_NO_DOCKWIDGET QBrush fill; bool stippled; bool panel = (pe == PE_PanelButtonTool); if ((!(opt->state & State_Sunken )) && (!(opt->state & State_Enabled) || ((opt->state & State_Enabled ) && !(opt->state & State_MouseOver))) && (opt->state & State_On) && use2000style) { fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern); stippled = true; } else { fill = opt->palette.brush(QPalette::Button); stippled = false; } if (opt->state & (State_Raised | State_Sunken | State_On)) { if (opt->state & State_AutoRaise) { if(opt->state & (State_Enabled | State_Sunken | State_On)){ if (panel) qDrawShadePanel(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On), 1, &fill); else qDrawShadeRect(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On), 1); } if (stippled) { p->setPen(opt->palette.button().color()); p->drawRect(opt->rect.adjusted(1,1,-2,-2)); } } else { qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On), panel ? &fill : 0); } } else { p->fillRect(opt->rect, fill); } break; } case PE_PanelButtonCommand: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { QBrush fill; State flags = opt->state; QPalette pal = opt->palette; QRect r = opt->rect; if (! (flags & State_Sunken) && (flags & State_On)) fill = QBrush(pal.light().color(), Qt::Dense4Pattern); else fill = pal.brush(QPalette::Button); if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) { p->setPen(pal.dark().color()); p->setBrush(fill); p->drawRect(r.adjusted(0, 0, -1, -1)); } else if (flags & (State_Raised | State_Sunken | State_On | State_Sunken)) { qDrawWinButton(p, r, pal, flags & (State_Sunken | State_On), &fill); } else { p->fillRect(r, fill); } } break; case PE_FrameDefaultButton: { p->setPen(opt->palette.shadow().color()); QRect rect = opt->rect; rect.adjust(0, 0, -1, -1); p->drawRect(rect); break; } case PE_IndicatorArrowUp: case PE_IndicatorArrowDown: case PE_IndicatorArrowRight: case PE_IndicatorArrowLeft: { QPoint points[7]; switch (pe) { case PE_IndicatorArrowUp: points[0] = QPoint(-4, 1); points[1] = QPoint(2, 1); points[2] = QPoint(-3, 0); points[3] = QPoint(1, 0); points[4] = QPoint(-2, -1); points[5] = QPoint(0, -1); points[6] = QPoint(-1, -2); break; case PE_IndicatorArrowDown: points[0] = QPoint(-4, -2); points[1] = QPoint(2, -2); points[2] = QPoint(-3, -1); points[3] = QPoint(1, -1); points[4] = QPoint(-2, 0); points[5] = QPoint(0, 0); points[6] = QPoint(-1, 1); break; case PE_IndicatorArrowRight: points[0] = QPoint(-2, -3); points[1] = QPoint(-2, 3); points[2] = QPoint(-1, -2); points[3] = QPoint(-1, 2); points[4] = QPoint(0, -1); points[5] = QPoint(0, 1); points[6] = QPoint(1, 0); break; case PE_IndicatorArrowLeft: points[0] = QPoint(0, -3); points[1] = QPoint(0, 3); points[2] = QPoint(-1, -2); points[3] = QPoint(-1, 2); points[4] = QPoint(-2, -1); points[5] = QPoint(-2, 1); points[6] = QPoint(-3, 0); break; default: break; } p->save(); if (opt->state & State_Sunken) p->translate(pixelMetric(PM_ButtonShiftHorizontal), pixelMetric(PM_ButtonShiftVertical)); if (opt->state & State_Enabled) { p->translate(opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height() / 2); p->setPen(opt->palette.buttonText().color()); p->drawLine(points[0], points[1]); p->drawLine(points[2], points[3]); p->drawLine(points[4], points[5]); p->drawPoint(points[6]); } else { p->translate(opt->rect.x() + opt->rect.width() / 2 + 1, opt->rect.y() + opt->rect.height() / 2 + 1); p->setPen(opt->palette.light().color()); p->drawLine(points[0], points[1]); p->drawLine(points[2], points[3]); p->drawLine(points[4], points[5]); p->drawPoint(points[6]); p->translate(-1, -1); p->setPen(opt->palette.mid().color()); p->drawLine(points[0], points[1]); p->drawLine(points[2], points[3]); p->drawLine(points[4], points[5]); p->drawPoint(points[6]); } p->restore(); break; } case PE_IndicatorCheckBox: { QBrush fill; if (opt->state & State_NoChange) fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern); else if (opt->state & State_Sunken) fill = opt->palette.button(); else if (opt->state & State_Enabled) fill = opt->palette.base(); else fill = opt->palette.background(); p->save(); doRestore = true; qDrawWinPanel(p, opt->rect, opt->palette, true, &fill); if (opt->state & State_NoChange) p->setPen(opt->palette.dark().color()); else p->setPen(opt->palette.text().color()); } // Fall through! case PE_IndicatorViewItemCheck: case PE_Q3CheckListIndicator: if (!doRestore) { p->save(); doRestore = true; } if (pe == PE_Q3CheckListIndicator || pe == PE_IndicatorViewItemCheck) { const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt); p->setPen(itemViewOpt && itemViewOpt->showDecorationSelected && opt->state & State_Selected ? opt->palette.highlightedText().color() : opt->palette.text().color()); if (opt->state & State_NoChange) p->setBrush(opt->palette.brush(QPalette::Button)); p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11); } if (!(opt->state & State_Off)) { QLineF lines[7]; int i, xx, yy; xx = opt->rect.x() + 3; yy = opt->rect.y() + 5; for (i = 0; i < 3; ++i) { lines[i] = QLineF(xx, yy, xx, yy + 2); ++xx; ++yy; } yy -= 2; for (i = 3; i < 7; ++i) { lines[i] = QLineF(xx, yy, xx, yy + 2); ++xx; --yy; } p->drawLines(lines, 7); } if (doRestore) p->restore(); break; case PE_FrameFocusRect: if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) { if (!(fropt->state & State_KeyboardFocusChange)) return; QRect r = opt->rect; p->save(); p->setBackgroundMode(Qt::TransparentMode); QColor bg_col = fropt->backgroundColor; if (!bg_col.isValid()) bg_col = p->background().color(); // Create an "XOR" color. QColor patternCol((bg_col.red() ^ 0xff) & 0xff, (bg_col.green() ^ 0xff) & 0xff, (bg_col.blue() ^ 0xff) & 0xff); p->setBrush(QBrush(patternCol, Qt::Dense4Pattern)); p->setBrushOrigin(r.topLeft()); p->setPen(Qt::NoPen); p->drawRect(r.left(), r.top(), r.width(), 1); // Top p->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom p->drawRect(r.left(), r.top(), 1, r.height()); // Left p->drawRect(r.right(), r.top(), 1, r.height()); // Right p->restore(); } break; case PE_IndicatorRadioButton: {#define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint)) static const QPoint pts1[] = { // dark lines QPoint(1, 9), QPoint(1, 8), QPoint(0, 7), QPoint(0, 4), QPoint(1, 3), QPoint(1, 2), QPoint(2, 1), QPoint(3, 1), QPoint(4, 0), QPoint(7, 0), QPoint(8, 1), QPoint(9, 1) }; static const QPoint pts2[] = { // black lines QPoint(2, 8), QPoint(1, 7), QPoint(1, 4), QPoint(2, 3), QPoint(2, 2), QPoint(3, 2), QPoint(4, 1), QPoint(7, 1), QPoint(8, 2), QPoint(9, 2) };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -