564{
565 QPainter painter(this);
566 QStyle* const style = QWidget::style();
567
568 QStyleOptionButton opt;
569
570 opt.initFrom(this);
571 opt.state |= isDown() ? QStyle::State_Sunken : QStyle::State_Raised;
572 opt.features = QStyleOptionButton::None;
573 opt.icon = QIcon();
574 opt.text.clear();
575
576 style->drawControl(QStyle::CE_PushButtonBevel, &opt, &painter, this);
577
578 QRect labelRect = style->subElementRect(QStyle::SE_PushButtonContents, &opt, this);
579 int shift = style->pixelMetric(QStyle::PM_ButtonMargin, &opt, this) / 2;
580 labelRect.adjust(shift, shift, -shift, -shift);
582 labelRect.getRect(&x, &y, &w, &h);
583
584 if (isChecked() || isDown())
585 {
586 x += style->pixelMetric(QStyle::PM_ButtonShiftHorizontal, &opt,
this);
587 y += style->pixelMetric(QStyle::PM_ButtonShiftVertical, &opt,
this);
588 }
589
590 QColor fillCol = isEnabled() ?
d->color :
palette().color(backgroundRole());
591 qDrawShadePanel(&painter, x, y, w, h,
palette(),
true, 1, 0);
592
593 if (fillCol.isValid())
594 {
595 const QRect
rect(x + 1, y + 1, w - 2, h - 2);
596
597 if (fillCol.alpha() < 255)
598 {
599 QPixmap chessboardPattern(16, 16);
600 QPainter patternPainter(&chessboardPattern);
601 patternPainter.fillRect(0, 0, 8, 8, Qt::black);
602 patternPainter.fillRect(8, 8, 8, 8, Qt::black);
603 patternPainter.fillRect(0, 8, 8, 8, Qt::white);
604 patternPainter.fillRect(8, 0, 8, 8, Qt::white);
605 patternPainter.end();
606 painter.fillRect(
rect, QBrush(chessboardPattern));
607 }
608
609 painter.fillRect(
rect, fillCol);
610 }
611
612 if (hasFocus())
613 {
614 QRect focusRect = style->subElementRect(QStyle::SE_PushButtonFocusRect, &opt, this);
615 QStyleOptionFocusRect focusOpt;
616 focusOpt.initFrom(this);
617 focusOpt.rect = focusRect;
618 focusOpt.backgroundColor =
palette().window().color();
619 style->drawPrimitive(QStyle::PE_FrameFocusRect, &focusOpt, &painter, this);
620 }
621}
rgba palette[MAX_PALETTE]