void NorwegianWoodStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { switch (element) { case PE_PanelButtonCommand: { int delta = (option->state & State_MouseOver) ? 64 : 0; QColor slightOpaqueBlack(0, 0, 0, 63); QColor semiTransparentWhite(255, 255, 255, 127 + delta); QColor semiTransparentBlack(0, 0, 0, 127 - delta); int x, y, width, height; option->rect.getRect(&x, &y, &width, &height); QPainterPath roundRect = roundRectPath(option->rect); int radius = qMin(width, height) / 2; QBrush brush; bool darker; const QStyleOptionButton *buttonOption = qstyleoption_cast<const QStyleOptionButton *>(option); if (buttonOption && (buttonOption->features & QStyleOptionButton::Flat)) { brush = option->palette.background(); darker = (option->state & (State_Sunken | State_On)); } else { if (option->state & (State_Sunken | State_On)) { brush = option->palette.mid(); darker = !(option->state & State_Sunken); } else { brush = option->palette.button(); darker = false; } } painter->save(); painter->setRenderHint(QPainter::Antialiasing, true); painter->fillPath(roundRect, brush); if (darker) { QColor slightlyOpaqueBlack(0, 0, 0, 63); painter->fillPath(roundRect, slightlyOpaqueBlack); } int penWidth; if (radius < 10) { penWidth = 3; } else if (radius < 20) { penWidth = 5; } else { penWidth = 7; } QPen topPen(semiTransparentWhite, penWidth); QPen bottomPen(semiTransparentBlack, penWidth); if (option->state & (State_Sunken | State_On)) { qSwap(topPen, bottomPen); } int x1 = x; int x2 = x + radius; int x3 = x + width - radius; int x4 = x + width; if (option->direction == Qt::RightToLeft) { qSwap(x1, x4); qSwap(x2, x3); } QPolygon topHalf; topHalf << QPoint(x1, y) << QPoint(x4, y) << QPoint(x3, y + radius) << QPoint(x2, y + height - radius) << QPoint(x4, y + height); painter->setClipPath(roundRect); painter->setClipRegion(topHalf, Qt::IntersectClip); painter->setPen(topPen); painter->drawPath(roundRect); QPolygon bottomHalf = topHalf; bottomHalf[0] = QPoint(x4, y + height); painter->setClipPath(roundRect); painter->setClipRegion(bottomHalf, Qt::IntersectClip); painter->setPen(bottomPen); painter->drawPath(roundRect); painter->setPen(option->palette.foreground().color()); painter->setClipping(false); painter->drawPath(roundRect); painter->restore(); } break; default: QMotifStyle::drawPrimitive(element, option, painter, widget); } }
void CustomStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { QColor backgroundColor; QPen oldPen(2); QPainterPath path; int x1, x2, y1, y2; switch (element) { case CE_PushButtonBevel: if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { bool hover = (button->state & State_HasFocus); // if (hover) // drawHoverRect(painter, widget->rect()); QColor slightlyOpaqueBlack(0, 0, 0, 63); int x, y, width, height; option->rect.getRect(&x, &y, &width, &height); QPainterPath roundRect = roundRectPath(option->rect); // int radius = qMin(width, height) / 2; QBrush brush; bool darker; const QStyleOptionButton *buttonOption = qstyleoption_cast<const QStyleOptionButton *>(option); if (buttonOption && (buttonOption->features & QStyleOptionButton::Flat)) { brush = option->palette.mid(); darker = (option->state & (State_Sunken | State_On)); } else { if (option->state & (State_Sunken | State_On)) { brush = option->palette.mid(); darker = !(option->state & State_Sunken); } else { brush = option->palette.button(); darker = false; } } painter->save(); painter->setRenderHint(QPainter::Antialiasing, true); painter->fillPath(roundRect, brush); // Draw Image ... if (darker) painter->fillPath(roundRect, slightlyOpaqueBlack); QBrush normalBrush(QBrush(QColor(145, 116, 255))); painter->fillPath(roundRect, normalBrush); if (!hover) { QBrush highlightBrush(QBrush(QColor(142, 163, 133))); painter->fillPath(roundRect, highlightBrush); /* x1 =x;x2 =x+width;y1=y;y2=y+height; QLineF line1(x1+2, y1, x2-2, y1); QLineF line2(x2-2,y1,x2,y2+2); QLineF line3(x2,y2+2,x2,y2-2); QLineF line4(x2,y2-2,x2-2,y2); QLineF line5(x2-2,y2,x1,y2-2); QLineF line6(x1,y2-2,x1,y2-2); QLineF line7(x1,y2-2,x1,y1+2); QLineF line8(x1,y1+2,x1+2,y1); QPen linePen(QPen(QColor(92,135,75))); painter->drawLine(line1); painter->drawLine(line8); painter->drawLine(line7); linePen.setColor(QColor(34,63,22)); painter->drawLine(line8); painter->drawLine(line8); painter->drawLine(line8); painter->drawLine(line8); painter->drawLine(line8);*/ } /* else { QPen myPen(QPen(QColor(145, 116, 255))); painter->setPen(myPen); painter->drawRect(option->rect); QBrush normalBrush1(QBrush(QColor(145, 116, 255))); painter->fillRect(option->rect, normalBrush1); }*/ /* int penWidth; if (radius < 10) penWidth = 1; else if (radius < 20) penWidth = 1; else penWidth = 1; int delta = (option->state & State_MouseOver) ? 64 : 0; QColor semiTransparentWhite(255, 255, 255, 127 + delta); QColor semiTransparentBlack(0, 0, 0, 127 - delta); QColor semiFocusTop(255, 0, 0, 127 + delta); QColor semiFocusDown(200, 0, 100, 127 - delta); QPen topPen((hover ? semiFocusTop:semiTransparentWhite), penWidth); QPen bottomPen((hover ? semiFocusDown:semiTransparentBlack), penWidth); if (option->state & (State_Sunken | State_On)) qSwap(topPen, bottomPen); int x1 = x; int x2 = x + radius; int x3 = x + width - radius; int x4 = x + width; if (option->direction == Qt::RightToLeft) { qSwap(x1, x4); qSwap(x2, x3); } QPolygon topHalf; topHalf << QPoint(x1, y) << QPoint(x4, y) << QPoint(x3, y + radius) << QPoint(x2, y + height - radius) << QPoint(x1, y + height); painter->setClipPath(roundRect); painter->setClipRegion(topHalf, Qt::IntersectClip); painter->setPen(topPen); painter->drawPath(roundRect); // Border draw ... QPolygon bottomHalf = topHalf; bottomHalf[0] = QPoint(x4, y + height); painter->setClipPath(roundRect); painter->setClipRegion(bottomHalf, Qt::IntersectClip); painter->setPen(bottomPen); painter->drawPath(roundRect); painter->setPen(option->palette.foreground().color()); painter->setClipping(false); painter->drawPath(roundRect); */ painter->restore(); } break; case CE_PushButtonLabel: { QStyleOptionButton myButtonOption; const QStyleOptionButton *buttonOption = qstyleoption_cast<const QStyleOptionButton *>(option); if (buttonOption) { myButtonOption = *buttonOption; if (myButtonOption.palette.currentColorGroup() != QPalette::Disabled) { if (myButtonOption.state & (State_Sunken | State_On)) { myButtonOption.palette.setBrush(QPalette::ButtonText, myButtonOption.palette.brightText()); } } } QWindowsStyle::drawControl(element, &myButtonOption, painter, widget); } break; #ifndef QT_NO_PROGRESSBAR case CE_ProgressBarGroove: if (/*const QStyleOptionProgressBar *bar = */qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { painter->save(); // backgroundColor = option->palette.color(widget->parentWidget()->backgroundRole()); oldPen = painter->pen(); painter->setPen(Qt::black); backgroundColor = mergedColors(QColor(0x06, 0x4C, 0xA4), QColor(0xd6, 0xd6, 0xd6)); oldPen.setColor(backgroundColor); painter->setPen(oldPen); option->rect.getCoords(&x1, &y1, &x2, &y2); path.moveTo(x1, y1); path.lineTo(x2, y1); path.lineTo(x2, y2); path.lineTo(x1, y2); path.lineTo(x1, y1); painter->drawPath(path); painter->restore(); } break; #endif default: QWindowsStyle::drawControl(element, option, painter, widget); } }