void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { QString title = VLCModel::getMeta( index, COLUMN_TITLE ); QString duration = VLCModel::getMeta( index, COLUMN_DURATION ); if( !duration.isEmpty() ) title += QString(" [%1]").arg( duration ); QString artist = VLCModel::getMeta( index, COLUMN_ARTIST ); QString album = VLCModel::getMeta( index, COLUMN_ALBUM ); QString trackNum = VLCModel::getMeta( index, COLUMN_TRACK_NUMBER ); QString artistAlbum = artist; if( !album.isEmpty() ) { if( !artist.isEmpty() ) artistAlbum += ": "; artistAlbum += album; if( !trackNum.isEmpty() ) artistAlbum += QString( " [#%1]" ).arg( trackNum ); } QPixmap artPix = VLCModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) ); //Draw selection rectangle and current playing item indication paintBackground( painter, option, index ); QRect artRect( artPix.rect() ); artRect.moveCenter( QPoint( artRect.center().x() + 3, option.rect.center().y() ) ); //Draw album art painter->drawPixmap( artRect, artPix ); //Start drawing text painter->save(); if( option.state & QStyle::State_Selected ) painter->setPen( option.palette.color( QPalette::HighlightedText ) ); QTextOption textOpt( Qt::AlignVCenter | Qt::AlignLeft ); textOpt.setWrapMode( QTextOption::NoWrap ); QFont f( index.data( Qt::FontRole ).value<QFont>() ); //Draw title info f.setItalic( true ); f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) ); f.setBold( index.data( PLModel::IsCurrentRole ).toBool() ); painter->setFont( f ); QFontMetrics fm( painter->fontMetrics() ); QRect textRect = option.rect.adjusted( LISTVIEW_ART_SIZE + 10, 0, -10, 0 ); if( !artistAlbum.isEmpty() ) { textRect.setHeight( fm.height() ); textRect.moveBottom( option.rect.center().y() - 2 ); } //Draw children indicator if( !index.data( PLModel::IsLeafNodeRole ).toBool() ) { QPixmap dirPix = QPixmap( ":/type/node" ); painter->drawPixmap( QPoint( textRect.x(), textRect.center().y() - dirPix.height() / 2 ), dirPix ); textRect.setLeft( textRect.x() + dirPix.width() + 5 ); } painter->drawText( textRect, fm.elidedText( title, Qt::ElideRight, textRect.width() ), textOpt ); // Draw artist and album info if( !artistAlbum.isEmpty() ) { f.setItalic( false ); painter->setFont( f ); fm = painter->fontMetrics(); textRect.moveTop( textRect.bottom() + 4 ); textRect.setLeft( textRect.x() + 20 ); painter->drawText( textRect, fm.elidedText( artistAlbum, Qt::ElideRight, textRect.width() ), textOpt ); } painter->restore(); }
void ezQGridBarWidget::paintEvent(QPaintEvent* e) { if (!MapFromSceneFunc.IsValid()) { QWidget::paintEvent(e); return; } QPainter Painter(this); QPainter* painter = &Painter; painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::TextAntialiasing); painter->setRenderHint(QPainter::HighQualityAntialiasing); QRect areaRect = rect(); // background painter->fillRect(areaRect, palette().button()); painter->translate(0.5, 0.5); // render fine grid stop lines { double fSceneMinX, fSceneMaxX; ezWidgetUtils::ComputeGridExtentsX(m_viewportSceneRect, m_fFineGridStops, fSceneMinX, fSceneMaxX); fSceneMinX = ezMath::Max(fSceneMinX, 0.0); painter->setPen(palette().buttonText().color()); ezHybridArray<QLine, 100> lines; // some overcompensation for the case that the GraphicsView displays a scrollbar at the side for (double x = fSceneMinX; x <= fSceneMaxX + m_fTextGridStops; x += m_fFineGridStops) { const QPoint pos = MapFromSceneFunc(QPointF(x, 0)); QLine& l = lines.ExpandAndGetRef(); l.setLine(pos.x(), areaRect.bottom() - 3, pos.x(), areaRect.bottom()); } painter->drawLines(lines.GetData(), lines.GetCount()); } // Grid Stop Value Text { double fSceneMinX, fSceneMaxX; ezWidgetUtils::ComputeGridExtentsX(m_viewportSceneRect, m_fTextGridStops, fSceneMinX, fSceneMaxX); fSceneMinX = ezMath::Max(fSceneMinX, 0.0); QTextOption textOpt(Qt::AlignCenter); QRectF textRect; painter->setPen(palette().buttonText().color()); ezStringBuilder tmp; for (double x = fSceneMinX; x <= fSceneMaxX; x += m_fTextGridStops) { const QPoint pos = MapFromSceneFunc(QPointF(x, 0)); textRect.setRect(pos.x() - 50, areaRect.top(), 99, areaRect.height()); tmp.Format("{0}", ezArgF(x)); painter->drawText(textRect, tmp.GetData(), textOpt); } } }