QColor KUrlNavigatorButtonBase::foregroundColor() const { const bool isHighlighted = isDisplayHintEnabled(EnteredHint) || isDisplayHintEnabled(DraggedHint) || isDisplayHintEnabled(PopupActiveHint); QColor foregroundColor = palette().color(foregroundRole()); int alpha = m_active ? 255 : 128; if (!m_active && !isHighlighted) { alpha -= alpha / 4; } foregroundColor.setAlpha(alpha); return foregroundColor; }
void KUrlNavigatorButtonBase::drawHoverBackground(QPainter *painter) { const bool isHighlighted = isDisplayHintEnabled(EnteredHint) || isDisplayHintEnabled(DraggedHint) || isDisplayHintEnabled(PopupActiveHint); QColor backgroundColor = isHighlighted ? palette().color(QPalette::Highlight) : Qt::transparent; if (!m_active && isHighlighted) { backgroundColor.setAlpha(128); } if (backgroundColor != Qt::transparent) { // TODO: the backgroundColor should be applied to the style QStyleOptionViewItemV4 option; option.initFrom(this); option.state = QStyle::State_Enabled | QStyle::State_MouseOver; option.viewItemPosition = QStyleOptionViewItemV4::OnlyOne; style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, this); } }
void BreadcrumbItemSortButton::drawHoverBackground( QPainter *painter ) { const bool isHovered = isDisplayHintEnabled( HoverHint ); if( isHovered ) { QStyleOptionViewItemV4 option; option.initFrom(this); option.state = QStyle::State_Enabled | QStyle::State_MouseOver; option.viewItemPosition = QStyleOptionViewItemV4::OnlyOne; if( m_arrowHovered ) { option.rect = m_arrowRect; } style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, this ); } }
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); } }