void AnimatedBarWidget::paintEvent( QPaintEvent* event ) { Q_UNUSED(event); QPainter painter(this); const int buttonHeight = height(); int buttonWidth = width(); drawHoverBackground(&painter); int left, top, right, bottom; getContentsMargins ( &left, &top, &right, &bottom ); const int padding = 2; const int iconWidth = iconSize().width(); const int iconHeight = iconSize().height(); const int iconTop = ( (buttonHeight - top - bottom) - iconHeight ) / 2; if( !m_animating ) { const QRect iconRect( left + padding, iconTop, iconWidth, iconHeight ); painter.drawPixmap( iconRect, icon().pixmap( iconSize() ) ); } else m_animatedWidget->move( left + padding, iconTop ); const QRect textRect( left + (padding * 3) + iconWidth, top, buttonWidth - (left + padding * 3 + iconWidth) - padding, buttonHeight); QFontMetrics fm( font() ); painter.drawText( textRect, Qt::AlignVCenter | Qt::TextWordWrap, text() ); }
void KUrlNavigatorPlacesSelector::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); drawHoverBackground(&painter); // draw icon const QPixmap pixmap = icon().pixmap(QSize(22, 22).expandedTo(iconSize()), QIcon::Normal); style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, pixmap); }
void KUrlNavigatorToggleButton::paintEvent(QPaintEvent* event) { QPainter painter(this); painter.setClipRect(event->rect()); const int buttonWidth = width(); const int buttonHeight = height(); if (isChecked()) { drawHoverBackground(&painter); const int x = (buttonWidth - m_pixmap.width()) / 2; const int y = (buttonHeight - m_pixmap.height()) / 2; painter.drawPixmap(QRect(x, y, m_pixmap.width(), m_pixmap.height()), m_pixmap); } else if (isDisplayHintEnabled(EnteredHint)) { painter.setPen(Qt::NoPen); painter.setBrush(palette().color(foregroundRole())); const int verticalGap = 4; const int caretWidth = 2; const int x = (layoutDirection() == Qt::LeftToRight) ? 0 : width() - caretWidth; painter.drawRect(x, verticalGap, caretWidth, buttonHeight - 2 * verticalGap); } }
void BreadcrumbItemSortButton::paintEvent( QPaintEvent *event ) { Q_UNUSED( event ) QPainter painter(this); const int buttonHeight = height(); const int preferredWidth = qMax( minimumWidth(), sizeHint().width() ); const int buttonWidth = qMin( preferredWidth, width() ); int left, top, right, bottom; getContentsMargins ( &left, &top, &right, &bottom ); const int padding = 2; const int arrowLeft = buttonWidth - m_arrowWidth - padding; const int arrowTop = ( ( buttonHeight - top - bottom) - m_arrowHeight )/2; m_arrowRect = QRect( arrowLeft, arrowTop, m_arrowWidth, m_arrowHeight ); drawHoverBackground( &painter ); const QColor fgColor = foregroundColor(); QStyleOption option; option.initFrom(this); option.rect = m_arrowRect; option.palette = palette(); option.palette.setColor(QPalette::Text, fgColor); option.palette.setColor(QPalette::WindowText, fgColor); option.palette.setColor(QPalette::ButtonText, fgColor); if( m_order == Qt::DescendingOrder ) style()->drawPrimitive( QStyle::PE_IndicatorArrowDown, &option, &painter, this ); else style()->drawPrimitive( QStyle::PE_IndicatorArrowUp, &option, &painter, this ); QRect newPaintRect( 0, 0, buttonWidth - m_arrowWidth - padding, buttonHeight ); QPaintEvent newEvent( newPaintRect ); BreadcrumbItemButton::paintEvent( &newEvent ); }
void KUrlNavigatorDropDownButton::paintEvent(QPaintEvent* event) { Q_UNUSED(event); QPainter painter(this); drawHoverBackground(&painter); const QColor fgColor = foregroundColor(); QStyleOption option; option.initFrom(this); option.rect = QRect(0, 0, width(), height()); option.palette = palette(); option.palette.setColor(QPalette::Text, fgColor); option.palette.setColor(QPalette::WindowText, fgColor); option.palette.setColor(QPalette::ButtonText, fgColor); if (layoutDirection() == Qt::LeftToRight) { style()->drawPrimitive(QStyle::PE_IndicatorArrowRight, &option, &painter, this); } else { style()->drawPrimitive(QStyle::PE_IndicatorArrowLeft, &option, &painter, this); } }