bool RenderThemeGtk::paintMenuList(RenderObject* object, const PaintInfo& info, const IntRect& rect) { if (paintButton(object, info, rect)) return true; // Menu list button painting strategy. // For buttons with appears-as-list set to false (having a separator): // | left border | Button text | xthickness | vseparator | xthickness | arrow | xthickness | right border | // For buttons with appears-as-list set to true (not having a separator): // | left border | Button text | arrow | xthickness | right border | int leftBorder = 0, rightBorder = 0, bottomBorder = 0, topBorder = 0; getButtonInnerBorder(gtkComboBoxButton(), leftBorder, topBorder, rightBorder, bottomBorder); RenderStyle* style = &object->style(); int arrowSize = comboBoxArrowSize(style); GtkStyle* buttonStyle = gtk_widget_get_style(gtkComboBoxButton()); IntRect arrowRect(0, (rect.height() - arrowSize) / 2, arrowSize, arrowSize); if (style->direction() == RTL) arrowRect.setX(leftBorder + buttonStyle->xthickness); else arrowRect.setX(rect.width() - rightBorder - buttonStyle->xthickness - arrowSize); GtkShadowType shadowType = isPressed(object) ? GTK_SHADOW_IN : GTK_SHADOW_OUT; WidgetRenderingContext widgetContext(info.context, rect); GtkStateType stateType = getGtkStateType(this, object); widgetContext.gtkPaintArrow(arrowRect, gtkComboBoxArrow(), stateType, shadowType, GTK_ARROW_DOWN, "arrow"); // Some combo boxes do not have a separator. GtkWidget* separator = gtkComboBoxSeparator(); if (!separator) return false; // We want to decrease the height of the separator based on the focus padding of the button. gint focusPadding = 0, focusWidth = 0; gtk_widget_style_get(gtkComboBoxButton(), "focus-line-width", &focusWidth, "focus-padding", &focusPadding, NULL); topBorder += focusPadding + focusWidth; bottomBorder += focusPadding + focusWidth; int separatorWidth = getComboBoxSeparatorWidth(); IntRect separatorRect(0, topBorder, separatorWidth, rect.height() - topBorder - bottomBorder); if (style->direction() == RTL) separatorRect.setX(arrowRect.x() + arrowRect.width() + buttonStyle->xthickness + separatorWidth); else separatorRect.setX(arrowRect.x() - buttonStyle->xthickness - separatorWidth); gboolean hasWideSeparators = FALSE; gtk_widget_style_get(separator, "wide-separators", &hasWideSeparators, NULL); if (hasWideSeparators) widgetContext.gtkPaintBox(separatorRect, separator, GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_OUT, "vseparator"); else widgetContext.gtkPaintVLine(separatorRect, separator, GTK_STATE_NORMAL, "vseparator"); return false; }
bool RenderThemeSymbian::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) { if (!m_selectArrow) { m_selectArrow = Image::loadPlatformResource("selectArrow"); } IntSize s = m_selectArrow->size(); // draw the bounding area i.context->save(); //i.context->setPen(Pen(Color::black,1)); i.context->setFillColor(Color::lightGray); IntRect brect(r.x() + r.width() - s.width(), r.y(), s.width(), r.height() - 3 ); i.context->drawRect(r); paintButtonDecorations(o, i, r); // draw the arrow int y = (r.height() - s.height())/2 + r.y(); IntRect arrowRect(IntPoint(r.x() + r.width() - s.width(), y), s); MScrollView* wv = scrollView(i); // don't scale the checkbox if scalingFactor is 100% or we are in the process of scaling another image if (wv->scalingFactor() <= 100 || m_bitmapScaler) { i.context->drawImage(m_selectArrow, arrowRect); } // use the cached scaled image if it has the same scaling factor else if (wv->scalingFactor() == (m_scalingForSelectArrow)) { i.context->drawImage(m_scaledSelectArrow, arrowRect); } // scale else { scaleImage(ESelectArrow, wv->scalingFactor()); if (wv->scalingFactor() == m_scalingForSelectArrow) { i.context->drawImage(m_scaledSelectArrow, arrowRect); } else { i.context->drawImage(m_selectArrow, arrowRect); } } i.context->restore(); return false; }
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return d->style->drawComplexControl(control, option, painter, widget); QRect rect = option->rect; switch (control) { case CC_ToolButton: if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { QString buttonType = widget->property("type").toString(); QRect button, menuarea; button = subControlRect(control, toolbutton, SC_ToolButton, widget); menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget); State bflags = toolbutton->state; if (bflags & State_AutoRaise) { if (!(bflags & State_MouseOver)) { bflags &= ~State_Raised; } } State mflags = bflags; if (toolbutton->state & State_Sunken) { if (toolbutton->activeSubControls & SC_ToolButton) bflags |= State_Sunken; if (toolbutton->activeSubControls & SC_ToolButtonMenu) mflags |= State_Sunken; } QStyleOption tool(0); tool.palette = toolbutton->palette; if (toolbutton->subControls & SC_ToolButton) { // if (buttonType == "dockbutton") { tool.rect = button; tool.state = bflags; drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); // } /*else { // paint status bar button style if (bflags & State_Sunken || bflags & State_On) drawCornerImage(d->buttonImage_pressed, painter, option->rect, 2, 2, 2, 2); else if (bflags & State_Enabled) { #ifndef Q_WS_MAC if (bflags & State_MouseOver) { drawCornerImage(d->buttonImage, painter, option->rect, 2, 2, 2, 2); QColor shade(255, 255, 255, 50); painter->fillRect(button.adjusted(1, 1, -1, -1), shade); } #endif } }*/ } if (toolbutton->state & State_HasFocus) { QStyleOptionFocusRect fr; fr.QStyleOption::operator=(*toolbutton); fr.rect.adjust(3, 3, -3, -3); if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup) fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator, toolbutton, widget), 0); QPen oldPen = painter->pen(); QColor focusColor = StyleHelper::panelTextColor(); focusColor.setAlpha(120); QPen outline(focusColor, 1); outline.setStyle(Qt::DotLine); painter->setPen(outline); QRect r = option->rect.adjusted(2, 2, -2, -2); painter->drawRect(r); painter->setPen(oldPen); } QStyleOptionToolButton label = *toolbutton; label.palette = panelPalette(option->palette); int fw = pixelMetric(PM_DefaultFrameWidth, option, widget); label.rect = button.adjusted(fw, fw, -fw, -fw); drawControl(CE_ToolButtonLabel, &label, painter, widget); if (toolbutton->subControls & SC_ToolButtonMenu) { tool.state = mflags; tool.rect = menuarea.adjusted(1, 1, -1, -1); if (mflags & (State_Sunken | State_On | State_Raised)) { painter->setPen(Qt::gray); painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft()); if (mflags & (State_Sunken)) { QColor shade(0, 0, 0, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #ifndef Q_WS_MAC else if (mflags & (State_MouseOver)) { QColor shade(255, 255, 255, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #endif } tool.rect = tool.rect.adjusted(2, 2, -2, -2); drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget); } else if (toolbutton->features & QStyleOptionToolButton::HasMenu) { int arrowSize = 6; QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1); QStyleOptionToolButton newBtn = *toolbutton; newBtn.palette = panelPalette(option->palette); newBtn.rect = QRect(ir.right() - arrowSize - 1, ir.height() - arrowSize - 2, arrowSize, arrowSize); drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget); } } break; case CC_ComboBox: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { painter->save(); bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull(); bool reverse = option->direction == Qt::RightToLeft; // Draw tool button QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight()); grad.setColorAt(0, QColor(255, 255, 255, 20)); grad.setColorAt(0.4, QColor(255, 255, 255, 60)); grad.setColorAt(0.7, QColor(255, 255, 255, 50)); grad.setColorAt(1, QColor(255, 255, 255, 40)); painter->setPen(QPen(grad, 0)); painter->drawLine(rect.topRight(), rect.bottomRight()); painter->drawLine(rect.topLeft(), rect.bottomLeft()); grad.setColorAt(0, QColor(0, 0, 0, 30)); grad.setColorAt(0.4, QColor(0, 0, 0, 70)); grad.setColorAt(0.7, QColor(0, 0, 0, 70)); grad.setColorAt(1, QColor(0, 0, 0, 40)); painter->setPen(QPen(grad, 0)); if (!reverse) painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0)); else painter->drawLine(rect.topLeft(), rect.bottomLeft()); QStyleOption toolbutton = *option; if (isEmpty) toolbutton.state &= ~(State_Enabled | State_Sunken); painter->save(); painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0)); drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget); painter->restore(); // Draw arrow int menuButtonWidth = 12; int left = !reverse ? rect.right() - menuButtonWidth : rect.left(); int right = !reverse ? rect.right() : rect.left() + menuButtonWidth; QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9); if (option->state & State_On) arrowRect.translate(d->style->pixelMetric(PM_ButtonShiftHorizontal, option, widget), d->style->pixelMetric(PM_ButtonShiftVertical, option, widget)); QStyleOption arrowOpt = *option; arrowOpt.rect = arrowRect; if (isEmpty) arrowOpt.state &= ~(State_Enabled | State_Sunken); if (styleHint(SH_ComboBox_Popup, option, widget)) { arrowOpt.rect.translate(0, -3); drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget); arrowOpt.rect.translate(0, 6); drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } else { drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } painter->restore(); } break; default: d->style->drawComplexControl(control, option, painter, widget); break; } }
void ScrollbarThemeGtk::paintButton(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect, ScrollbarPart part) { // The buttons will be disabled if the thumb is as the appropriate extreme. GtkShadowType shadowType = GTK_SHADOW_OUT; GtkStateType stateType = GTK_STATE_INSENSITIVE; bool pressed = (part == scrollbar->pressedPart()); if ((BackButtonStartPart == part && scrollbar->currentPos()) || (BackButtonEndPart == part && scrollbar->currentPos()) || (ForwardButtonEndPart == part && scrollbar->currentPos() != scrollbar->maximum()) || (ForwardButtonStartPart == part && scrollbar->currentPos() != scrollbar->maximum())) { stateType = GTK_STATE_NORMAL; if (pressed) { stateType = GTK_STATE_ACTIVE; shadowType = GTK_SHADOW_IN; } else if (part == scrollbar->hoveredPart()) stateType = GTK_STATE_PRELIGHT; } // Themes determine how to draw the button (which button to draw) based on the allocation // of the widget. Where the target rect is in relation to the total widget allocation // determines the button. ScrollbarOrientation orientation = scrollbar->orientation(); int buttonSize = (orientation == VerticalScrollbar) ? rect.height() : rect.width(); int totalAllocation = buttonSize * 5; // One space for each button and one extra. int buttonOffset = 0; if (ForwardButtonStartPart == part) buttonOffset = buttonSize; else if (BackButtonEndPart == part) buttonOffset = 3 * buttonSize; else if (ForwardButtonEndPart == part) buttonOffset = 4 * buttonSize; // Now we want the allocation to be relative to the origin of the painted rect. GtkWidget* widget = getWidgetForScrollbar(scrollbar); GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); allocation.x = allocation.y = 0; allocation.width = rect.width(); allocation.height = rect.height(); if (orientation == VerticalScrollbar) { allocation.height = totalAllocation; allocation.y -= buttonOffset; } else { allocation.width = totalAllocation; allocation.x -= buttonOffset; } gtk_widget_set_allocation(widget, &allocation); const char* detail = orientation == VerticalScrollbar ? "vscrollbar" : "hscrollbar"; WidgetRenderingContext widgetContext(context, rect); IntRect buttonRect(IntPoint(), rect.size()); widgetContext.gtkPaintBox(buttonRect, widget, stateType, shadowType, detail); float arrowScaling; gtk_widget_style_get(widget, "arrow-scaling", &arrowScaling, NULL); IntSize arrowSize = rect.size(); arrowSize.scale(arrowScaling); IntRect arrowRect(IntPoint(buttonRect.x() + (buttonRect.width() - arrowSize.width()) / 2, buttonRect.y() + (buttonRect.height() - arrowSize.height()) / 2), arrowSize); if (pressed) { int arrowDisplacementX, arrowDisplacementY; gtk_widget_style_get(widget, "arrow-displacement-x", &arrowDisplacementX, "arrow-displacement-y", &arrowDisplacementY, NULL); arrowRect.move(arrowDisplacementX, arrowDisplacementY); } GtkArrowType arrowType = GTK_ARROW_DOWN; if (orientation == VerticalScrollbar) { if (part == BackButtonEndPart || part == BackButtonStartPart) arrowType = GTK_ARROW_UP; } else if (orientation == HorizontalScrollbar) { arrowType = GTK_ARROW_RIGHT; if (part == BackButtonEndPart || part == BackButtonStartPart) arrowType = GTK_ARROW_LEFT; } widgetContext.gtkPaintArrow(arrowRect, widget, stateType, shadowType, arrowType, detail); }
/*! \brief Draw the button label \sa The Qt Manual on QPushButton */ void QwtArrowButton::drawButtonLabel(QPainter *p) { const bool isVertical = d_data->arrowType == Qt::UpArrow || d_data->arrowType == Qt::DownArrow; const QRect r = labelRect(); QSize boundingSize = labelRect().size(); if ( isVertical ) boundingSize.transpose(); const int w = (boundingSize.width() - (MaxNum - 1) * Spacing) / MaxNum; QSize arrow = arrowSize(Qt::RightArrow, QSize(w, boundingSize.height())); if ( isVertical ) arrow.transpose(); QRect contentsSize; // aligned rect where to paint all arrows if ( d_data->arrowType == Qt::LeftArrow || d_data->arrowType == Qt::RightArrow ) { contentsSize.setWidth(d_data->num * arrow.width() + (d_data->num - 1) * Spacing); contentsSize.setHeight(arrow.height()); } else { contentsSize.setWidth(arrow.width()); contentsSize.setHeight(d_data->num * arrow.height() + (d_data->num - 1) * Spacing); } QRect arrowRect(contentsSize); arrowRect.moveCenter(r.center()); arrowRect.setSize(arrow); p->save(); for (int i = 0; i < d_data->num; i++) { drawArrow(p, arrowRect, d_data->arrowType); int dx = 0; int dy = 0; if ( isVertical ) dy = arrow.height() + Spacing; else dx = arrow.width() + Spacing; #if QT_VERSION >= 0x040000 arrowRect.translate(dx, dy); #else arrowRect.moveBy(dx, dy); #endif } p->restore(); if ( hasFocus() ) { #if QT_VERSION >= 0x040000 QStyleOptionFocusRect option; option.init(this); option.backgroundColor = palette().color(QPalette::Background); style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, p, this); #else const QRect focusRect = style().subRect(QStyle::SR_PushButtonFocusRect, this); style().drawPrimitive(QStyle::PE_FocusRect, p, focusRect, colorGroup()); #endif } }
void ColumnItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); if ( !item ) return; QTextOption textOption( Qt::AlignVCenter | (Qt::Alignment)index.data( Qt::TextAlignmentRole ).toUInt() ); textOption.setWrapMode( QTextOption::NoWrap ); QString text; if ( !item->artist().isNull() ) { text = item->artist()->name(); } else if ( !item->album().isNull() ) { text = item->album()->name(); } else if ( !item->result().isNull() || !item->query().isNull() ) { float opacity = item->result() && item->result()->isOnline() ? 1.0 : 0.0; opacity = qMax( (float)0.3, opacity ); QColor textColor = TomahawkUtils::alphaBlend( option.palette.color( QPalette::Foreground ), option.palette.color( QPalette::Background ), opacity ); { QStyleOptionViewItemV4 o = option; initStyleOption( &o, QModelIndex() ); painter->save(); o.palette.setColor( QPalette::Text, textColor ); if ( m_view->currentIndex() == index ) o.state |= QStyle::State_Selected; else o.state &= ~QStyle::State_Selected; if ( o.state & QStyle::State_Selected && o.state & QStyle::State_Active ) { o.palette.setColor( QPalette::Text, o.palette.color( QPalette::HighlightedText ) ); } if ( item->isPlaying() ) { textColor = TomahawkStyle::NOW_PLAYING_ITEM_TEXT; o.palette.setColor( QPalette::Highlight, TomahawkStyle::NOW_PLAYING_ITEM ); o.palette.setColor( QPalette::Text, TomahawkStyle::NOW_PLAYING_ITEM_TEXT ); o.state |= QStyle::State_Selected; } int oldX = 0; // if ( m_view->header()->visualIndex( index.column() ) == 0 ) { oldX = o.rect.x(); o.rect.setX( 0 ); } qApp->style()->drawControl( QStyle::CE_ItemViewItem, &o, painter ); if ( oldX > 0 ) o.rect.setX( oldX ); /* if ( m_hoveringOver == index && !index.data().toString().isEmpty() && index.column() == 0 ) { o.rect.setWidth( o.rect.width() - o.rect.height() ); QRect arrowRect( o.rect.x() + o.rect.width(), o.rect.y() + 1, o.rect.height() - 2, o.rect.height() - 2 ); QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() ); painter->drawPixmap( arrowRect, infoIcon ); m_infoButtonRects[ index ] = arrowRect; }*/ { QRect r = o.rect.adjusted( 3, 0, 0, 0 ); // Paint Now Playing Speaker Icon if ( item->isPlaying() ) { const int pixMargin = 1; const int pixHeight = r.height() - pixMargin * 2; QRect npr = r.adjusted( pixMargin, pixMargin, pixHeight - r.width() + pixMargin, -pixMargin ); painter->drawPixmap( npr, TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() ) ); r.adjust( pixHeight + 6, 0, 0, 0 ); } painter->setPen( o.palette.text().color() ); QString text = index.data().toString(); if ( item->query()->track()->albumpos() > 0 ) { text = QString( "%1. %2" ) .arg( index.data( PlayableModel::AlbumPosRole ).toString() ) .arg( index.data().toString() ); } text = painter->fontMetrics().elidedText( text, Qt::ElideRight, r.width() - 3 ); painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, textOption ); } painter->restore(); } return; } else return; if ( text.trimmed().isEmpty() ) text = tr( "Unknown" ); QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, QModelIndex() ); const QModelIndex curIndex = m_view->currentIndex(); if ( curIndex == index || curIndex.parent() == index || curIndex.parent().parent() == index ) opt.state |= QStyle::State_Selected; else opt.state &= ~QStyle::State_Selected; qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); if ( opt.state & QStyle::State_Selected ) { opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) ); } QRect arrowRect( m_view->viewport()->width() - option.rect.height(), option.rect.y() + 1, option.rect.height() - 2, option.rect.height() - 2 ); if ( m_hoveringOver.row() == index.row() && m_hoveringOver.parent() == index.parent() ) { QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() ); painter->drawPixmap( arrowRect, infoIcon ); m_infoButtonRects[ index ] = arrowRect; } if ( index.column() > 0 ) return; painter->save(); painter->setRenderHint( QPainter::TextAntialiasing ); painter->setPen( opt.palette.color( QPalette::Text ) ); QRect r = option.rect.adjusted( 8, 2, -option.rect.width() + option.rect.height() + 4, -2 ); // painter->drawPixmap( r, QPixmap( RESPATH "images/cover-shadow.png" ) ); if ( !m_pixmaps.contains( index ) ) { if ( !item->album().isNull() ) { m_pixmaps.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::Original, false ) ) ); _detail::Closure* closure = NewClosure( m_pixmaps[ index ], SIGNAL( repaintRequest() ), const_cast<ColumnItemDelegate*>(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) ); closure->setAutoDelete( false ); } else if ( !item->artist().isNull() )
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return QProxyStyle::drawComplexControl(control, option, painter, widget); QRect rect = option->rect; switch (control) { case CC_ToolButton: if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { QRect button, menuarea; button = subControlRect(control, toolbutton, SC_ToolButton, widget); menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget); State bflags = toolbutton->state; if (bflags & State_AutoRaise) { if (!(bflags & State_MouseOver)) { bflags &= ~State_Raised; } } State mflags = bflags; if (toolbutton->state & State_Sunken) { if (toolbutton->activeSubControls & SC_ToolButton) bflags |= State_Sunken; if (toolbutton->activeSubControls & SC_ToolButtonMenu) mflags |= State_Sunken; } QStyleOption tool(0); tool.palette = toolbutton->palette; if (toolbutton->subControls & SC_ToolButton) { tool.rect = button; tool.state = bflags; drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); } QStyleOptionToolButton label = *toolbutton; label.palette = panelPalette(option->palette, lightColored(widget)); int fw = pixelMetric(PM_DefaultFrameWidth, option, widget); label.rect = button.adjusted(fw, fw, -fw, -fw); drawControl(CE_ToolButtonLabel, &label, painter, widget); if (toolbutton->subControls & SC_ToolButtonMenu) { tool.state = mflags; tool.rect = menuarea.adjusted(1, 1, -1, -1); if (mflags & (State_Sunken | State_On | State_Raised)) { painter->setPen(Qt::gray); painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft()); if (mflags & (State_Sunken)) { QColor shade(0, 0, 0, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #ifndef Q_WS_MAC else if (mflags & (State_MouseOver)) { QColor shade(255, 255, 255, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #endif } tool.rect = tool.rect.adjusted(2, 2, -2, -2); drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget); } else if (toolbutton->features & QStyleOptionToolButton::HasMenu && !widget->property("noArrow").toBool()) { int arrowSize = 6; QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1); QStyleOptionToolButton newBtn = *toolbutton; newBtn.palette = panelPalette(option->palette); newBtn.rect = QRect(ir.right() - arrowSize - 1, ir.height() - arrowSize - 2, arrowSize, arrowSize); drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget); } } break; case CC_ComboBox: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { painter->save(); bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull(); bool reverse = option->direction == Qt::RightToLeft; bool drawborder = !(widget && widget->property("hideborder").toBool()); bool alignarrow = !(widget && widget->property("alignarrow").toBool()); // Draw tool button if (drawborder) { QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight()); grad.setColorAt(0, QColor(255, 255, 255, 20)); grad.setColorAt(0.4, QColor(255, 255, 255, 60)); grad.setColorAt(0.7, QColor(255, 255, 255, 50)); grad.setColorAt(1, QColor(255, 255, 255, 40)); painter->setPen(QPen(grad, 0)); painter->drawLine(rect.topRight(), rect.bottomRight()); grad.setColorAt(0, QColor(0, 0, 0, 30)); grad.setColorAt(0.4, QColor(0, 0, 0, 70)); grad.setColorAt(0.7, QColor(0, 0, 0, 70)); grad.setColorAt(1, QColor(0, 0, 0, 40)); painter->setPen(QPen(grad, 0)); if (!reverse) painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0)); else painter->drawLine(rect.topLeft(), rect.bottomLeft()); } QStyleOption toolbutton = *option; if (isEmpty) toolbutton.state &= ~(State_Enabled | State_Sunken); painter->save(); if (drawborder) painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0)); drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget); painter->restore(); // Draw arrow int menuButtonWidth = 12; int left = !reverse ? rect.right() - menuButtonWidth : rect.left(); int right = !reverse ? rect.right() : rect.left() + menuButtonWidth; QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9); if (!alignarrow) { int labelwidth = option->fontMetrics.width(cb->currentText); if (reverse) arrowRect.moveLeft(qMax(rect.width() - labelwidth - menuButtonWidth - 2, 4)); else arrowRect.moveLeft(qMin(labelwidth + menuButtonWidth - 2, rect.width() - menuButtonWidth - 4)); } if (option->state & State_On) arrowRect.translate(QProxyStyle::pixelMetric(PM_ButtonShiftHorizontal, option, widget), QProxyStyle::pixelMetric(PM_ButtonShiftVertical, option, widget)); QStyleOption arrowOpt = *option; arrowOpt.rect = arrowRect; if (isEmpty) arrowOpt.state &= ~(State_Enabled | State_Sunken); if (styleHint(SH_ComboBox_Popup, option, widget)) { arrowOpt.rect.translate(0, -3); drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget); arrowOpt.rect.translate(0, 6); drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } else { drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } painter->restore(); } break; default: QProxyStyle::drawComplexControl(control, option, painter, widget); break; } }
void CustomStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { QColor borderColor; QPen oldPen(2); QPainterPath path; int x1, x2, y1, y2; switch (control) { #ifndef QT_NO_COMBOBOX case CC_ComboBox: if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { painter->save(); // backgroundColor = option->palette.color(widget->parentWidget()->backgroundRole()); bool isEnabled = (comboBox->state & State_Enabled); bool focus = isEnabled && (comboBox->state & State_HasFocus); oldPen = painter->pen(); painter->setPen(Qt::black); if(!focus) borderColor = mergedColors(QColor(0x06, 0x4C, 0xA4), QColor(0xd6, 0xd6, 0xd6)); else borderColor = QColor(255, 255, 0); oldPen.setColor(borderColor); painter->setPen(oldPen); // painter->setBrush(Qt::transparent); painter->fillRect(option->rect, option->palette.brush(QPalette::Base)); option->rect.getCoords(&x1, &y1, &x2, &y2); path.moveTo(x1+0, y1); path.lineTo(x2-0, y1); path.lineTo(x2, y1+0); path.lineTo(x2, y2-0); path.lineTo(x2-0, y2); path.lineTo(x1+0, y2); path.lineTo(x1, y2-0); path.lineTo(x1, y1+0); path.lineTo(x1+0, y1); painter->drawPath(path); QRect downArrowRect = subControlRect(CC_ComboBox, comboBox, SC_ComboBoxArrow, widget); if (comboBox->subControls & SC_ComboBoxArrow) { QStyleOptionButton buttonOption; buttonOption.QStyleOption::operator=(*comboBox); QRect arrowRect(option->rect.right() - downArrowRect.width(), option->rect.top(), downArrowRect.width(), downArrowRect.height()); buttonOption.rect = arrowRect; if(!focus) buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver); else buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus); // drawControl(CE_PushButtonBevel, &buttonOption, painter, widget); buttonOption.rect = downArrowRect; if(!focus) buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver); else buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus); // drawControl(CE_PushButtonBevel, &buttonOption, painter, widget); QImage imgLeftArrow(qt_scrollbar_button_arrow_left); QImage imgRightArrow(qt_scrollbar_button_arrow_right); //downArrow.setColor(1, comboBox->palette.foreground().color().rgba()); // int offset = comboBox->direction == Qt::RightToLeft ? -2 : 2; if(!focus) { imgRightArrow.setColor(1,qRgb(48,255,0)); imgLeftArrow.setColor(1,qRgb(48,255,0)); } else { imgRightArrow.setColor(1,qRgb(255,255,0)); imgLeftArrow.setColor(1,qRgb(255,255,0)); } painter->drawImage(downArrowRect.center().x() - imgLeftArrow.width() / 2,// + offset, downArrowRect.center().y() - imgLeftArrow.height() / 2 + 1, imgLeftArrow); painter->drawImage(arrowRect.center().x() - imgRightArrow.width() / 2,// + offset, arrowRect.center().y() - imgRightArrow.height() / 2 + 1, imgRightArrow); } QRect editFieldRect = subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget); if (comboBox->subControls & SC_ComboBoxEditField) { // QStyleOptionButton buttonOption; // buttonOption.rect = editFieldRect; // if(!focus) // buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver); // else // buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus); // drawPrimitive(PE_FrameLineEdit, &buttonOption, painter, widget); } painter->restore(); } break; #endif // QT_NO_COMBOBOX default: QWindowsStyle::drawComplexControl(control, option, painter, widget); break; } }
void TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); if ( !item ) return; QTextOption textOption( Qt::AlignVCenter | (Qt::Alignment)index.data( Qt::TextAlignmentRole ).toUInt() ); textOption.setWrapMode( QTextOption::NoWrap ); QString text; if ( !item->artist().isNull() ) { text = item->artist()->name(); } else if ( !item->album().isNull() ) { text = item->album()->name(); } else if ( !item->result().isNull() || !item->query().isNull() ) { float opacity = item->result().isNull() ? 0.0 : item->result()->score(); opacity = qMax( (float)0.3, opacity ); QColor textColor = TomahawkUtils::alphaBlend( option.palette.color( QPalette::Foreground ), option.palette.color( QPalette::Background ), opacity ); { QStyleOptionViewItemV4 o = option; initStyleOption( &o, QModelIndex() ); painter->save(); o.palette.setColor( QPalette::Text, textColor ); if ( o.state & QStyle::State_Selected && o.state & QStyle::State_Active ) { o.palette.setColor( QPalette::Text, o.palette.color( QPalette::HighlightedText ) ); } if ( item->isPlaying() ) { o.palette.setColor( QPalette::Highlight, o.palette.color( QPalette::Mid ) ); if ( o.state & QStyle::State_Selected ) o.palette.setColor( QPalette::Text, textColor ); o.state |= QStyle::State_Selected; } int oldX = 0; if ( m_view->header()->visualIndex( index.column() ) == 0 ) { oldX = o.rect.x(); o.rect.setX( 0 ); } qApp->style()->drawControl( QStyle::CE_ItemViewItem, &o, painter ); if ( oldX > 0 ) o.rect.setX( oldX ); if ( m_view->hoveredIndex().row() == index.row() && m_view->hoveredIndex().column() == index.column() && ( index.column() == 0 ) ) { o.rect.setWidth( o.rect.width() - 16 ); QRect arrowRect( o.rect.x() + o.rect.width(), o.rect.y() + 1, o.rect.height() - 2, o.rect.height() - 2 ); QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() ); painter->drawPixmap( arrowRect, infoIcon ); } { QRect r = o.rect.adjusted( 3, 0, 0, 0 ); // Paint Now Playing Speaker Icon if ( item->isPlaying() && m_view->header()->visualIndex( index.column() ) == 0 ) { r.adjust( 0, 0, 0, -3 ); QRect npr = r.adjusted( 3, 1, 18 - r.width(), 1 ); painter->drawPixmap( npr, TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() ) ); r.adjust( 25, 0, 0, 3 ); } painter->setPen( o.palette.text().color() ); QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 ); painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, textOption ); } painter->restore(); } return; } else return; if ( text.trimmed().isEmpty() ) text = tr( "Unknown" ); QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, QModelIndex() ); qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); if ( option.state & QStyle::State_Selected ) { opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) ); } if ( index.column() > 0 ) return; painter->save(); painter->setRenderHint( QPainter::Antialiasing ); painter->setPen( opt.palette.color( QPalette::Text ) ); QRect r = option.rect.adjusted( 4, 4, -option.rect.width() + option.rect.height() - 4, -4 ); // painter->drawPixmap( r, QPixmap( RESPATH "images/cover-shadow.png" ) ); if ( !m_pixmaps.contains( index ) ) { if ( !item->album().isNull() ) { m_pixmaps.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::ScaledCover, false ) ) ); _detail::Closure* closure = NewClosure( m_pixmaps[ index ], SIGNAL( repaintRequest() ), const_cast<TreeItemDelegate*>(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) ); closure->setAutoDelete( false ); } else if ( !item->artist().isNull() )