📄 qplastiquestyle.cpp
字号:
painter->save(); // Fill the line edit insides QRect filledRect = lineEdit->rect.adjusted(1, 1, -1, -1); QBrush baseBrush = qMapBrushToRect(lineEdit->palette.base(), filledRect); painter->setBrushOrigin(filledRect.topLeft()); painter->fillRect(filledRect.adjusted(1, 1, -1, -1), baseBrush); painter->setPen(QPen(baseBrush, 0)); const QLine lines[4] = { QLine(filledRect.left(), filledRect.top() + 1, filledRect.left(), filledRect.bottom() - 1), QLine(filledRect.right(), filledRect.top() + 1, filledRect.right(), filledRect.bottom() - 1), QLine(filledRect.left() + 1, filledRect.top(), filledRect.right() - 1, filledRect.top()), QLine(filledRect.left() + 1, filledRect.bottom(), filledRect.right() - 1, filledRect.bottom()) }; painter->drawLines(lines, 4); if (lineEdit->lineWidth != 0) qt_plastique_draw_frame(painter, option->rect, option, QFrame::Sunken); painter->restore(); break; }#endif // QT_NO_LINEEDIT case PE_FrameDockWidget: case PE_FrameMenu: case PE_FrameStatusBar: { // Draws the frame around a popup menu. QPen oldPen = painter->pen(); painter->setPen(borderColor); painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); painter->setPen(alphaCornerColor); const QPoint points[4] = { QPoint(option->rect.topLeft()), QPoint(option->rect.topRight()), QPoint(option->rect.bottomLeft()), QPoint(option->rect.bottomRight()) }; painter->drawPoints(points, 4); painter->setPen(oldPen); break; }#ifdef QT3_SUPPORT case PE_Q3DockWindowSeparator: { QPen oldPen = painter->pen(); painter->setPen(alphaCornerColor); QRect rect = option->rect; if (option->state & State_Horizontal) { painter->drawLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 1); } else { painter->drawLine(rect.left() + 2, rect.bottom(), rect.right() - 1, rect.bottom()); } painter->setPen(oldPen); break; } case PE_Q3Separator: { QPen oldPen = painter->pen(); painter->setPen(alphaCornerColor); if ((option->state & State_Horizontal) == 0) painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight()); else painter->drawLine(option->rect.topRight(), option->rect.bottomRight()); painter->setPen(option->palette.background().color().lighter(104)); if ((option->state & State_Horizontal) == 0) painter->drawLine(option->rect.topLeft(), option->rect.topRight()); else painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft()); painter->setPen(oldPen); break; }#endif // QT3_SUPPORT#ifndef QT_NO_MAINWINDOW case PE_PanelMenuBar: if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())#ifdef QT3_SUPPORT || (widget->parentWidget() && widget->parentWidget()->inherits("Q3MainWindow"))#endif ) { // Draws the light line above and the dark line below menu bars and // tool bars. QPen oldPen = painter->pen(); if (element == PE_PanelMenuBar || (option->state & State_Horizontal)) { painter->setPen(alphaCornerColor); painter->drawLine(option->rect.left(), option->rect.bottom(), option->rect.right(), option->rect.bottom()); painter->setPen(option->palette.background().color().lighter(104)); painter->drawLine(option->rect.left(), option->rect.top(), option->rect.right(), option->rect.top()); } else { painter->setPen(option->palette.background().color().lighter(104)); painter->drawLine(option->rect.left(), option->rect.top(), option->rect.left(), option->rect.bottom()); painter->setPen(alphaCornerColor); painter->drawLine(option->rect.right(), option->rect.top(), option->rect.right(), option->rect.bottom()); } painter->setPen(oldPen); } break;#endif // QT_NO_MAINWINDOW case PE_IndicatorHeaderArrow: { bool usedAntialiasing = painter->renderHints() & QPainter::Antialiasing; if (!usedAntialiasing) painter->setRenderHint(QPainter::Antialiasing); QWindowsStyle::drawPrimitive(element, option, painter, widget); if (!usedAntialiasing) painter->setRenderHint(QPainter::Antialiasing, false); break; } case PE_PanelButtonTool: // Draws a tool button (f.ex., in QToolBar and QTabBar) if ((option->state & State_Enabled) || !(option->state & State_AutoRaise)) qt_plastique_drawShadedPanel(painter, option, true, widget); break;#ifndef QT_NO_TOOLBAR case PE_IndicatorToolBarHandle: { QPixmap cache; QRect rect = option->rect;#ifdef QT3_SUPPORT if (widget && widget->inherits("Q3DockWindowHandle") && widget->parentWidget()->inherits("Q3DockWindow")) { if (!(option->state & State_Horizontal)) rect.adjust(2, 0, -2, 0); }#endif QString pixmapName = uniqueName(QLatin1String("toolbarhandle"), option, rect.size()); if (!UsePixmapCache || !QPixmapCache::find(pixmapName, cache)) { cache = QPixmap(rect.size()); cache.fill(Qt::transparent); QPainter cachePainter(&cache); QRect cacheRect(QPoint(0, 0), rect.size()); if (widget) cachePainter.fillRect(cacheRect, option->palette.brush(widget->backgroundRole())); else cachePainter.fillRect(cacheRect, option->palette.background()); QImage handle(qt_toolbarhandle); handle.setColor(1, alphaCornerColor.rgba()); handle.setColor(2, mergedColors(alphaCornerColor, option->palette.base().color()).rgba()); handle.setColor(3, option->palette.base().color().rgba()); if (option->state & State_Horizontal) { int nchunks = cacheRect.height() / handle.height(); int indent = (cacheRect.height() - (nchunks * handle.height())) / 2; for (int i = 0; i < nchunks; ++i) cachePainter.drawImage(QPoint(cacheRect.left() + 3, cacheRect.top() + indent + i * handle.height()), handle); } else { int nchunks = cacheRect.width() / handle.width(); int indent = (cacheRect.width() - (nchunks * handle.width())) / 2; for (int i = 0; i < nchunks; ++i) cachePainter.drawImage(QPoint(cacheRect.left() + indent + i * handle.width(), cacheRect.top() + 3), handle); } cachePainter.end(); if (UsePixmapCache) QPixmapCache::insert(pixmapName, cache); } painter->drawPixmap(rect.topLeft(), cache); break; } case PE_IndicatorToolBarSeparator: { QPen oldPen = painter->pen(); painter->setPen(alphaCornerColor); if (option->state & State_Horizontal) { painter->drawLine(option->rect.left(), option->rect.top() + 1, option->rect.left(), option->rect.bottom() - 2); painter->setPen(option->palette.base().color()); painter->drawLine(option->rect.right(), option->rect.top() + 1, option->rect.right(), option->rect.bottom() - 2); } else { painter->drawLine(option->rect.left() + 1, option->rect.top(), option->rect.right() - 2, option->rect.top()); painter->setPen(option->palette.base().color()); painter->drawLine(option->rect.left() + 1, option->rect.bottom(), option->rect.right() - 2, option->rect.bottom()); } painter->setPen(oldPen); break; }#endif // QT_NO_TOOLBAR case PE_PanelButtonCommand: if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { bool sunken = (button->state & State_Sunken) || (button->state & State_On); if ((button->features & QStyleOptionButton::Flat) && !sunken) break; bool defaultButton = (button->features & (QStyleOptionButton::DefaultButton | QStyleOptionButton::AutoDefaultButton)); BEGIN_PLASTIQUE_PIXMAPCACHE(QString::fromLatin1("pushbutton-%1").arg(defaultButton)) QPen oldPen = p->pen(); bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver); // Give the painter a different brush origin for sunken buttons if (sunken) { // ### No such function // p->setPenOrigin(rect.left() + 1, rect.top() + 1); p->setBrushOrigin(rect.left() + 1, rect.top() + 1); } // Draw border qt_plastique_draw_frame(p, rect, option); // Fill the panel QRectF fillRect = rect.adjusted(2, 2, -2, -2); // Button colors QBrush alphaCornerBrush = qMapBrushToRect(qBrushDark(option->palette.button(), 165), rect); qBrushSetAlphaF(&alphaCornerBrush, 0.5); QBrush buttonGradientBrush; QBrush leftLineGradientBrush; QBrush rightLineGradientBrush; QBrush sunkenButtonGradientBrush; QBrush sunkenLeftLineGradientBrush; QBrush sunkenRightLineGradientBrush; QBrush buttonBrush = qMapBrushToRect(option->palette.button(), rect); if (buttonBrush.gradient() || !buttonBrush.texture().isNull()) { buttonGradientBrush = buttonBrush; sunkenButtonGradientBrush = qBrushDark(buttonBrush, 108); leftLineGradientBrush = qBrushLight(buttonBrush, 105); rightLineGradientBrush = qBrushDark(buttonBrush, 105); sunkenLeftLineGradientBrush = qBrushDark(buttonBrush, 110); sunkenRightLineGradientBrush = qBrushDark(buttonBrush, 106); } else { // Generate gradients QLinearGradient buttonGradient(rect.topLeft(), rect.bottomLeft()); buttonGradient.setColorAt(0.0, buttonBrush.color().lighter(104)); buttonGradient.setColorAt(1.0, buttonBrush.color().darker(110)); buttonGradientBrush = QBrush(buttonGradient); QLinearGradient buttonGradient2(rect.topLeft(), rect.bottomLeft()); buttonGradient2.setColorAt(0.0, buttonBrush.color().darker(113)); buttonGradient2.setColorAt(1.0, buttonBrush.color().darker(103)); sunkenButtonGradientBrush = QBrush(buttonGradient2); QLinearGradient buttonGradient3(rect.topLeft(), rect.bottomLeft()); buttonGradient3.setColorAt(0.0, buttonBrush.color().lighter(105)); buttonGradient3.setColorAt(1.0, buttonBrush.color()); leftLineGradientBrush = QBrush(buttonGradient3); QLinearGradient buttonGradient4(rect.topLeft(), rect.bottomLeft()); buttonGradient4.setColorAt(0.0, buttonBrush.color()); buttonGradient4.setColorAt(1.0, buttonBrush.color().darker(110)); rightLineGradientBrush = QBrush(buttonGradient4); QLinearGradient buttonGradient5(rect.topLeft(), rect.bottomLeft()); buttonGradient5.setColorAt(0.0, buttonBrush.color().darker(113)); buttonGradient5.setColorAt(1.0, buttonBrush.color().darker(107)); sunkenLeftLineGradientBrush = QBrush(buttonGradient5); QLinearGradient buttonGradient6(rect.topLeft(), rect.bottomLeft()); buttonGradient6.setColorAt(0.0, buttonBrush.color().darker(108)); buttonGradient6.setColorAt(1.0, buttonBrush.color().darker(103)); sunkenRightLineGradientBrush = QBrush(buttonGradient6); } // Main fill p->fillRect(fillRect, qMapBrushToRect(sunken ? sunkenButtonGradientBrush : buttonGradientBrush, rect)); // Top line p->setPen(QPen(qBrushLight(qMapBrushToRect(sunken ? sunkenButtonGradientBrush : buttonGradientBrush, rect), 105), 0)); p->drawLine(QPointF(rect.left() + 2, rect.top() + 1), QPointF(rect.right() - 2, rect.top() + 1)); // Bottom line p->setPen(QPen(qBrushDark(qMapBrushToRect(sunken ? sunkenButtonGradientBrush : buttonGradientBrush, rect), 105), 0)); p->drawLine(QPointF(rect.left() + 2, rect.bottom() - 1), QPointF(rect.right() - 2, rect.bottom() - 1)); // Left line p->setPen(QPen(qMapBrushToRect(sunken ? sunkenLeftLineGradientBrush : leftLineGradientBrush, rect), 1)); p->drawLine(QPointF(rect.left() + 1, rect.top() + 2), QPointF(rect.left() + 1, rect.bottom() - 2)); // Right line p->setPen(QPen(qMapBrushToRect(sunken ? sunkenRightLineGradientBrush : rightLineGradientBrush, rect), 1)); p->drawLine(QPointF(rect.right() - 1, rect.top() + 2), QPointF(rect.right() - 1, rect.bottom() - 2)); // Hovering if (hover && !sunken) { QBrush hover = qMapBrushToRect(option->palette.highlight(), rect); QBrush hoverOuter = hover; qBrushSetAlphaF(&hoverOuter, 0.7); QLine lines[2]; p->setPen(QPen(hover, 0)); lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top()); lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom()); p->drawLines(lines, 2); p->setPen(QPen(hoverOuter, 0)); lines[0] = QLine(rect.left() + 1, rect.top() + 1, rect.right() - 1, rect.top() + 1); lines[1] = QLine(rect.left() + 1, rect.bottom() - 1, rect.right() - 1, rect.bottom() - 1); p->drawLines(lines, 2); QBrush hoverInner = hover; qBrushSetAlphaF(&hoverInner, 0.45); p->setPen(QPen(hoverInner, 0)); lines[0] = QLine(rect.left() + 1, rect.top() + 2, rect.right() - 1, rect.top() + 2); lines[1] = QLine(rect.left() + 1, rect.bottom() - 2, rect.right() - 1, rect.bottom() - 2); p->drawLines(lines, 2); QBrush hoverSide = hover; qBrushSetAlphaF(&hoverSide, 0.075); p->setPen(QPen(hoverSide, 0)); lines[0] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2); lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2); p->drawLines(lines, 2); } p->setPen(oldPen); END_PLASTIQUE_PIXMAPCACHE } break; case PE_IndicatorCheckBox: if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { BEGIN_PLASTIQUE_PIXMAPCACHE(QLatin1String("checkbox")) p->save(); // Outline QBrush border = option->palette.shadow(); qBrushSetAlp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -