void MessageBarIcon::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget ){ QGraphicsPixmapItem::paint(painter, option, widget); painter->save(); QRectF b = boundingRect(); QFont fnt = m_item.getDisplayFont(); QFontMetrics fm(fnt); int fnt_h = fm.height(); QRect r(0,0,0,0); r.setTop(b.height() - ( fnt_h + ((MessageIconWidget*)parent())->getInnerPadding())); r.setBottom(b.bottom()); r.setWidth(b.width()); // QBrush brush1(QColor(255, 20, 25, 255)); // brush1.setStyle(Qt::SolidPattern); // painter->setBrush(brush1); // painter->drawRect(r); painter->setClipRect(r); //qDebug() << "test onto rect: " << r; drawHtmlLine(painter, fnt, r, m_item.formattedName()); painter->restore(); }
void drawBottomHtmlLine(QPainter *painter, const QFont font, QRect rect, QString text){ QRect r = rect; QFontInfo fi(font); int height = fi.pixelSize(); r.moveTop(r.bottom() - height); drawHtmlLine(painter, font, r, text) ; }
int drawJustField(QPainter *painter, QFont font, QString htmlField, QRect rect){ //rightRect.moveRight(rect.right() - rect.width()*(1 - FIELD_NAME_RIGHTSPACE_RATIO)); htmlField = tagAs(htmlField, "b"); htmlField = tagAs(htmlField, "u"); int fieldNameFontSize = fontSize4Width( crudeHtmlFragmentToPlainText(htmlField), rect.size(), font); QString txt = htmlFontSizeFormat(htmlField, fieldNameFontSize); if(painter){ drawHtmlLine(painter, font, rect, txt); } return rect.height() ; }
int drawFieldAndValue(QPainter *painter, QFont font, QString htmlField, QString htmlFieldValue, QRect rect){ QRect rightRect = rect; rightRect.moveRight(rect.right() - rect.width()*(1 - FIELD_NAME_RIGHTSPACE_RATIO)); int fieldNameFontSize = fontSize4Width( crudeHtmlFragmentToPlainText(htmlField), rightRect.size(), font); QString txt = htmlFontSizeFormat(htmlField, fieldNameFontSize) + " " + htmlFieldValue; bool breakLine = (fieldNameFontSize < FIELD_NAME_FONT_STANDARDSIZE); if(painter){ drawHtmlLine(painter, font, rect, txt, breakLine); } return fieldNameFontSize + UI_FIELD_FONT_MARGIN; }
int drawFieldLabel(QPainter *painter, QFont font, QString htmlFieldLabel, QRect rect, bool bottomAligned){ int fieldNameFontSize = fontSize4Width( crudeHtmlFragmentToPlainText(htmlFieldLabel), rect.size(), font); font.setPointSize(fieldNameFontSize); QFontMetrics fm(font); rect.setHeight(fm.height()+ fm.leading()*2+10); if(bottomAligned){ drawBottomHtmlLine(painter, font, rect, htmlFieldLabel); } else { drawHtmlLine(painter, font, rect, htmlFieldLabel); } return rect.height(); }
void IndividualIcon::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * ){ //QGraphicsPixmapItem::paint(painter, option, widget); QRectF b = boundingRect(); QIcon ic = m_item.getActualIcon(); QRect iconRect; iconRect.setTopLeft(b.topLeft().toPoint()); iconRect.setWidth(UI_DEFAULT_MINI_ICON_SIZE); iconRect.setHeight(UI_DEFAULT_MINI_ICON_SIZE); ic.paint(painter, iconRect); painter->save(); if(this->isSelected()){ QBrush brush1(option->palette.highlight()); brush1.setStyle(Qt::SolidPattern); painter->setBrush(brush1); painter->drawRect(b); } QFont fnt = m_item.getDisplayFont(); // QFontMetrics fm(fnt); // int fnt_h = fm.height(); QRect r(0,0,0,0); r.setTop(b.height()); r.setBottom(b.bottom()); r.setWidth(b.width()); painter->setClipRect(r); //qDebug() << "test onto rect: " << r; drawHtmlLine(painter, fnt, r, m_item.formattedName()); painter->restore(); }
void drawHtmlRightAligned(QPainter *painter, const QFont font, QRect rect, QString text){ drawHtmlLine(painter, font, rect, text, false, true); }