int TextRenderer::draw( int x, int y, const QString &string ) { assert(d->textmode); if( string.isEmpty() ) return 0; glPushMatrix(); glLoadIdentity(); glTranslatef( x, d->glwidget->height() - y, 0 ); d->do_draw(string); glPopMatrix(); const QFontMetrics fontMetrics ( d->font ); return fontMetrics.height(); }
/*! \reimp */ QSize QProgressBar::sizeHint() const { ensurePolished(); QFontMetrics fm = fontMetrics(); QStyleOptionProgressBarV2 opt; initStyleOption(&opt); int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, this); QSize size = QSize(qMax(9, cw) * 7 + fm.width(QLatin1Char('0')) * 4, fm.height() + 8); if (opt.orientation == Qt::Vertical) size.transpose(); return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this); }
void AnimationButton::mouseMoveEvent(QMouseEvent* e) { if (_dragging) { // If the left button isn't pressed anymore then return if ( !buttonDownIsLeft(e) ) { return; } // If the distance is too small then return if ( (e->pos() - _dragPos).manhattanLength() < QApplication::startDragDistance() ) { return; } // initiate Drag _knob->onCopyAnimationActionTriggered(); QDrag* drag = new QDrag(this); QMimeData* mimeData = new QMimeData; mimeData->setData("Animation", ""); drag->setMimeData(mimeData); QFontMetrics fmetrics = fontMetrics(); QString textFirstLine( tr("Copying animation from:") ); QString textSecondLine( _knob->getKnob()->getDescription().c_str() ); QString textThirdLine( tr("Drag it to another animation button.") ); int textWidth = std::max( std::max( fmetrics.width(textFirstLine), fmetrics.width(textSecondLine) ),fmetrics.width(textThirdLine) ); QImage dragImg(textWidth,(fmetrics.height() + 5) * 3,QImage::Format_ARGB32); dragImg.fill( QColor(243,137,0) ); QPainter p(&dragImg); p.drawText(QPointF(0,dragImg.height() - 2.5), textThirdLine); p.drawText(QPointF(0,dragImg.height() - fmetrics.height() - 5), textSecondLine); p.drawText(QPointF(0,dragImg.height() - fmetrics.height() * 2 - 10), textFirstLine); drag->setPixmap( QPixmap::fromImage(dragImg) ); setDown(false); drag->exec(); } else { QPushButton::mouseMoveEvent(e); } }
void OSD::paintEvent(QPaintEvent *) { QPainter painter (this); painter.setPen( QColor (Qt::black) ); // draw the background and the frame QRect thisRect(0, 0, width() - 1 , height() - 1); painter.fillRect(thisRect, QColor::fromRgb(58, 117, 177) ); if (! osd_interr) { // progress graph painter.setPen(QColor ("#3AD5FF")); int square_width_each = ( width() - 2 ) / sizeof(osd_data); int max_square_height = height() * 0.6; int x = 0.5 * ( width() - sizeof(osd_data) * square_width_each ) , y = 0; for (size_t i = osd_idx ; i < sizeof(osd_data) + osd_idx; ++ i) { if ( osd_data [i % sizeof(osd_data)] > osd_maxSpeed ) { QRect rect (x, height() - 1 - max_square_height, square_width_each , max_square_height); painter.fillRect(rect, QBrush (QColor ("#3AD5FF")) ); } else { y = max_square_height * (double)osd_data [i % sizeof(osd_data)] / osd_maxSpeed; QRect rect (x, height() - 1 - y , square_width_each , y ); painter.fillRect( rect , QBrush (QColor ("#3AD5FF")) ); } x += square_width_each; } // progress text painter.setPen(QColor(Qt::white)); QFontMetrics fm (font ()); QRect fontRect ( (width() - fm.width(m_text)) / 2, 2, fm.width(m_text), fm.height()); painter.drawText(fontRect, Qt::AlignCenter, m_text); } // frame painter.setPen( QColor (Qt::black) ); painter.drawRect( thisRect ); }
QSize PosEdit::sizeHint() const { //QFontMetrics fm(font()); QFontMetrics fm = fontMetrics(); int fw = style()->pixelMetric(QStyle::PM_SpinBoxFrameWidth); int h = fm.height() + fw * 2; int w = fw * 4 + 10; // HACK: 10 = spinbox up/down arrows if (_smpte) w += 2 + fm.width('9') * 9 + fm.width(':') * 3 + fw * 4; else w += 2 + fm.width('9') * 9 + fm.width('.') * 2 + fw * 4; return QSize(w, h).expandedTo(QApplication::globalStrut()); }
void ChoiceItem::paint( QPainter* painter ) { int itemHeight = height( listBox() ); QFontMetrics fm = painter->fontMetrics(); int yPos = ( ( itemHeight - fm.height() ) / 2 ) + fm.ascent(); painter->drawText( 3, yPos, item ); //int xPos = fm.width( item ); int xPos = QMAX(fm.width(item), minNameWidth); if( !isSelected() ) painter->setPen( listBox()->palette().disabled().text().dark() ); painter->drawText( 10 + xPos, yPos, desc ); }
void Completer::showToolTip(QListWidgetItem * current, QListWidgetItem * /*previous */) { QString s = current->toolTip(); if(QToolTip::isVisible()) QToolTip::hideText(); if(!s.isEmpty() && mEditor){ QPoint pos = mEditor->mapToGlobal( mEditor->cursorRect().topLeft() ); QFontMetrics fm = QApplication::fontMetrics(); pos.ry() -= fm.height()+3; QToolTip::showText(pos, s); } }
// Function to limit table data shown based on search criteria void US_XpnRunAuc::limit_data( const QString& sfilt ) { bool have_search = ! sfilt.isEmpty(); qDebug() << "LimData: sfilt" << sfilt << "have_search" << have_search; QFont tw_font( US_Widgets::fixedFont().family(), US_GuiSettings::fontSize() ); QFontMetrics* fm = new QFontMetrics( tw_font ); int rowht = fm->height() + 2; tw->clearContents(); tw->setSortingEnabled( false ); qDebug() << "LimData: runInfo size" << runInfo.size(); for ( int ii = 0; ii < runInfo.size(); ii++ ) { QTableWidgetItem* item; RunInfo rr = runInfo[ ii ]; QString tripk = QString().sprintf( "%5d", rr.ntriple ); qDebug() << "LimData: ii" << ii << "runID" << rr.runID; // Skip item if search text exists and runID does not contain it if ( have_search && ! rr.runID.contains( sfilt, Qt::CaseInsensitive ) ) continue; item = new QTableWidgetItem( rr.runID ); item->setFlags( item->flags() ^ Qt::ItemIsEditable ); tw ->setItem( ii, 0, item ); item = new QTableWidgetItem( rr.date ); item->setFlags( item->flags() ^ Qt::ItemIsEditable ); tw ->setItem( ii, 1, item ); item = new QTableWidgetItem( tripk ); item->setFlags( item->flags() ^ Qt::ItemIsEditable ); tw ->setItem( ii, 2, item ); qDebug() << "setItems ii" << ii << "date runID dbId" << rr.date << rr.runID << rr.dbId; tw ->setRowHeight( ii, rowht ); } tw->setSortingEnabled( true ); tw->sortByColumn( 1, Qt::DescendingOrder ); tw->resizeColumnsToContents(); tw->adjustSize(); // tw->update(); // update(); tw->resize( size().width() - 4, tw->size().height() ); qApp->processEvents(); }
void TRasterImageUtils::addSceneNumbering(const TRasterImageP &ri, int globalIndex, const std::wstring &sceneName, int sceneIndex) { if (!ri) return; TRasterP raster = ri->getRaster(); int lx = raster->getLx(), ly = raster->getLy(); QColor greyOverlay(100, 100, 100, 140); QImage image = rasterToQImage(raster, true, false); QPainter p(&image); QFont numberingFont = QFont(); numberingFont.setPixelSize(ly * 0.04); numberingFont.setBold(true); p.setFont(numberingFont); QMatrix matrix; p.setMatrix(matrix.translate(0, ly).scale(1, -1), true); QFontMetrics fm = p.fontMetrics(); int fontHeight = fm.height(); int offset = fontHeight * 0.2; //write the scenename and the scene frame QString sceneFrame = QString::number(sceneIndex); while (sceneFrame.size() < 4) sceneFrame.push_front("0"); QString sceneNumberingString = QString::fromStdWString(sceneName) + ": " + sceneFrame; int sceneNumberingWidth = fm.width(sceneNumberingString); p.setPen(Qt::NoPen); p.setBrush(QColor(255, 255, 255, 255)); p.drawRect(offset, ly - offset - fontHeight, sceneNumberingWidth + offset * 2, fontHeight); p.setBrush(greyOverlay); p.drawRect(offset, ly - offset - fontHeight, sceneNumberingWidth + offset * 2, fontHeight); p.setPen(Qt::white); p.drawText(2 * offset, ly - 2 * offset, sceneNumberingString); //write the global frame QString globalFrame = QString::number(globalIndex); while (globalFrame.size() < 4) globalFrame.push_front("0"); int gloablNumberingWidth = fm.width(globalFrame); p.setPen(Qt::NoPen); p.setBrush(QColor(255, 255, 255, 255)); p.drawRect(lx - 3 * offset - gloablNumberingWidth, ly - offset - fontHeight, gloablNumberingWidth + offset * 2, fontHeight); p.setBrush(greyOverlay); p.drawRect(lx - 3 * offset - gloablNumberingWidth, ly - offset - fontHeight, gloablNumberingWidth + offset * 2, fontHeight); p.setPen(Qt::white); p.drawText(lx - 2 * offset - gloablNumberingWidth, ly - 2 * offset, globalFrame); p.end(); }
void KDirListBoxItem::paint( QPainter *p ) { if(italic) { p->save(); QFont f = p->font(); f.setItalic(true); p->setFont(f); } p->drawPixmap( 3, 2, *pm ); QFontMetrics fm = p->fontMetrics(); int yPos; // vertical text position if ( (pm->height()) < fm.height() ) yPos = fm.ascent() + fm.leading()/2; else yPos = pm->height()/2 - fm.height()/2 + fm.ascent(); yPos= yPos+2; p->drawText( pm->width() + 5, yPos, text() ); if(italic) p->restore(); }
// virtual QPainterPath Guide::shape() const { QPainterPath path; if (!scene()) return path; double width = m_pen.widthF() * 2; path.addRect(line().x1() - width / 2 , line().y1(), width, line().y2() - line().y1()); if (KdenliveSettings::showmarkers() && scene()->views().count()) { const QFontMetrics metric = m_view->fontMetrics(); int offset = scene()->views()[0]->verticalScrollBar()->value(); QRectF txtBounding(line().x1(), line().y1() + offset, m_width, metric.height()); path.addRect(txtBounding); } return path; }
void TabBarPrivate::drawTab(QPainter& painter, QRect& rect, const QString& text, bool active) { QPolygon polygon; if (tabbar->isLeftToRight()) polygon << QPoint(rect.x(), rect.y()) << QPoint(rect.x(), rect.bottom() - 3) << QPoint(rect.x() + 2, rect.bottom()) << QPoint(rect.right() - 4, rect.bottom()) << QPoint(rect.right() - 2, rect.bottom() - 2) << QPoint(rect.right() + 5, rect.top()); else polygon << QPoint(rect.right(), rect.top()) << QPoint(rect.right(), rect.bottom() - 3) << QPoint(rect.right() - 2, rect.bottom()) << QPoint(rect.x() + 4, rect.bottom()) << QPoint(rect.x() + 2, rect.bottom() - 2) << QPoint(rect.x() - 5, rect.top()); painter.save(); // fill it first QBrush bg = tabbar->palette().background(); if (active) bg = tabbar->palette().base(); painter.setBrush(bg); painter.setPen(QPen(Qt::NoPen)); painter.drawPolygon(polygon); // draw the lines painter.setPen(tabbar->palette().color(QPalette::Dark)); painter.setRenderHint(QPainter::Antialiasing); if (!active) { const bool reverseLayout = tabbar->isRightToLeft(); painter.drawLine(rect.x() - (reverseLayout ? 5 : 0), rect.y(), rect.right() + (reverseLayout ? 0 : 5), rect.top()); } painter.drawPolyline(polygon); painter.setPen(tabbar->palette().color(QPalette::ButtonText)); QFont f = font(active); painter.setFont(f); QFontMetrics fm = painter.fontMetrics(); int tx = rect.x() + (rect.width() - fm.width(text)) / 2; int ty = rect.y() + (rect.height() - fm.height()) / 2 + fm.ascent(); painter.drawText(tx, ty, text); painter.restore(); }
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { if (!index.isValid()) { return QSize(0, 0); } const QString text = index.model()->data(index, Qt::DisplayRole).toString(); const QIcon icon = index.model()->data(index, Qt::DecorationRole).value<QIcon>(); const QPixmap pixmap = icon.pixmap(iconSize, iconSize); QFontMetrics fm = option.fontMetrics; int gap = fm.height(); int wp = pixmap.width(); int hp = pixmap.height(); if (hp == 0) { /** * No pixmap loaded yet, we'll use the default icon size in this case. */ hp = iconSize; wp = iconSize; } QTextLayout iconTextLayout(text, option.font); int wt = layoutText(&iconTextLayout, qMax(3 * wp, 8 * fm.height())); int ht = iconTextLayout.boundingRect().height(); int width, height; if (text.isEmpty()) { height = hp; } else { height = hp + ht + 10; } width = qMax(wt, wp) + gap; return QSize(width, height); }
void QGroupBox::setTextSpacer() { if ( !d->spacer ) return; int h = 0; int w = 0; if ( isCheckable() || lenvisible ) { QFontMetrics fm = fontMetrics(); int fh = fm.height(); if ( isCheckable() ) { #ifndef QT_NO_CHECKBOX fh = d->checkbox->sizeHint().height() + 2; w = d->checkbox->sizeHint().width() + 2*fm.width( "xx" ); #endif } else { fh = fm.height(); w = fm.width( str, lenvisible ) + 2*fm.width( "xx" ); } h = frameRect().y(); if ( layout() ) { int m = layout()->margin(); int sp = layout()->spacing(); // do we have a child layout? for ( QLayoutIterator it = layout()->iterator(); it.current(); ++it ) { if ( it.current()->layout() ) { m += it.current()->layout()->margin(); sp = QMAX( sp, it.current()->layout()->spacing() ); break; } } h = QMAX( fh-m, h ); h += QMAX( sp - (h+m - fh), 0 ); } } d->spacer->changeSize( w, h, QSizePolicy::Minimum, QSizePolicy::Fixed ); }
WindowHeader(QWidget* parent = NULL): QWidget(parent), m_text("H.265 Encoder"), m_logo(":/Logo") { setFixedHeight(76); const int kLabelBaseline = 48; const int kLabelXPos = 29; setFont(CommonGui::font(CommonGui::kSentinelLight)); QFontMetrics qf = fontMetrics(); int labelWidth = qf.width(m_text) + 4; // Add a few pixels for safety int labelHeight = qf.height(); int labelYPos = kLabelBaseline + qf.descent() - labelHeight; m_textRect = QRect(kLabelXPos, labelYPos, labelWidth, labelHeight); }
QSize FastSizeHintItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { int lineCount=1; int nPos=20; if (index.column()!=TMDBModel::Filepath && index.column()!=TMDBModel::TransationStatus) { QString text=index.data().toString(); nPos=text.indexOf('\n'); if (nPos==-1) nPos=text.size(); else lineCount+=text.count('\n'); } static QFontMetrics metrics(option.font); return QSize(metrics.averageCharWidth()*nPos, metrics.height()*lineCount); }
/* * Returns a *hint* to the view of how big the item should be */ QSize NodeItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { QFontMetrics fontMetrics = option.fontMetrics; // Return an arbitrary standard size of a NodeItem if the index is invalid if (!index.isValid()) return QSize(fontMetrics.width("abcdef") + BORDER_PADDING*2 + BORDER_WIDTH*2, fontMetrics.height() + BORDER_PADDING*2 + BORDER_WIDTH*2); QString text = index.model()->data(index, Qt::DisplayRole).toString(); int textWidth = fontMetrics.width(text); int textHeight = fontMetrics.height(); // Return the size of the item, border width and paddin included return QSize(textWidth + BORDER_PADDING*2 + BORDER_WIDTH*2, textHeight + BORDER_PADDING*2 + BORDER_WIDTH*2); }
void Atom::drawLabel(Viewer& viewer, LabelType const type, QFontMetrics& fontMetrics) { Vec pos(getPosition()); Vec shift = viewer.camera()->position() - pos; shift.normalize(); QString label(getLabel(type)); pos = pos + 1.05 * shift * getRadius(true); pos = viewer.camera()->projectedCoordinatesOf(pos); pos.x -= fontMetrics.width(label)/2.0; pos.y += fontMetrics.height()/4.0; pos = viewer.camera()->unprojectedCoordinatesOf(pos); glColor3f(0.1, 0.1, 0.1); viewer.renderText(pos[0], pos[1], pos[2], label, viewer.labelFont()); }
QRect PrimerLineEdit::placeHolderRect() const { QStyleOptionFrame panel; initStyleOption(&panel); QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); r.setX(r.x() + textMargins().left()); r.setY(r.y() + textMargins().top()); r.setRight(r.right() - textMargins().right()); r.setBottom(r.bottom() - textMargins().bottom()); QFontMetrics fm = fontMetrics(); int minLB = qMax(0, -fm.minLeftBearing()); int minRB = qMax(0, -fm.minRightBearing()); int vscroll = r.y() + (r.height() - fm.height() + 1) / 2; static const int horizontalMargin = 2; // QLineEditPrivate::horizontalMargin QRect lineRect(r.x() + horizontalMargin, vscroll, r.width() - 2*horizontalMargin, fm.height()); return lineRect.adjusted(minLB, 0, -minRB, 0); }
static int popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm ) { int h = 0; if ( mi->isSeparator() ) // separator height h = motifSepHeight; else if ( mi->pixmap() ) // pixmap height h = mi->pixmap()->height() + 2*motifItemFrame; else // text height h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame - 1; if ( !mi->isSeparator() && mi->iconSet() != 0 ) { h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame ); } if ( mi->custom() ) h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1; return h; }
QSize FastSizeHintItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { int lineCount=1; int nPos=20; int column=qMax(index.column(),0); if (!singleLineColumns.at(column)) { QString text=index.data().toString(); nPos=text.indexOf('\n'); if (nPos==-1) nPos=text.size(); else lineCount+=text.count('\n'); } static QFontMetrics metrics(option.font); return QSize(metrics.averageCharWidth()*nPos, metrics.height()*lineCount); }
void QHexScrollArea::mouseReleaseEvent(QMouseEvent *e) { QScrollArea::mouseReleaseEvent(e); QFont font = this->font(); QFontMetrics fm = this->fontMetrics(); int ssw = fm.width(" "); // width of space symbol // int zsw = fm.width("0"); // width of zero symbol qint64 rnw = getRowNumberWidth(); // width of row number panel qint64 bnw = getByteNumberWidth(); // width of bytes number panel qint64 dpw = getDataPanelWidth(); qint64 dnw = rnw + bnw; int x = e->pos().x(); int y = e->pos().y(); qint64 selectedCol = -1; if ( dnw < x && x < dnw + dpw + ssw * 0.5) { if ((dnw + ssw * 0.5) <= x && x < (dnw + ssw * 3.5)) selectedCol = 0; if ((dnw + ssw * 3.5) <= x && x < (dnw + ssw * 6.5)) selectedCol = 1; if ((dnw + ssw * 6.5) <= x && x < (dnw + ssw * 9.5)) selectedCol = 2; if ((dnw + ssw * 9.5) <= x && x < (dnw + ssw * 12.5)) selectedCol = 3; if ((dnw + ssw * 13.5) <= x && x < (dnw + ssw * 16.5)) selectedCol = 4; if ((dnw + ssw * 16.5) <= x && x < (dnw + ssw * 19.5)) selectedCol = 5; if ((dnw + ssw * 19.5) <= x && x < (dnw + ssw * 22.5)) selectedCol = 6; if ((dnw + ssw * 22.5) <= x && x < (dnw + ssw * 25.5)) selectedCol = 7; if ((dnw + ssw * 27.5) <= x && x < (dnw + ssw * 30.5)) selectedCol = 8; if ((dnw + ssw * 30.5) <= x && x < (dnw + ssw * 33.5)) selectedCol = 9; if ((dnw + ssw * 33.5) <= x && x < (dnw + ssw * 36.5)) selectedCol = 10; if ((dnw + ssw * 36.5) <= x && x < (dnw + ssw * 39.5)) selectedCol = 11; if ((dnw + ssw * 40.5) <= x && x < (dnw + ssw * 43.5)) selectedCol = 12; if ((dnw + ssw * 43.5) <= x && x < (dnw + ssw * 46.5)) selectedCol = 13; if ((dnw + ssw * 46.5) <= x && x < (dnw + ssw * 49.5)) selectedCol = 14; if ((dnw + ssw * 49.5) <= x && x < (dnw + ssw * 52.5)) selectedCol = 15; qint64 selectedRow = ((y-4) / fm.height())-1 ; qint64 vsbValue = verticalScrollBar()->value(); selectedRow += vsbValue; selectedByte = selectedRow * 16 + selectedCol; } viewport()->update(); }
void tst_QProgressBar::sizeHint() { ProgressBar bar; bar.setMinimum(0); bar.setMaximum(10); bar.setValue(5); //test if the sizeHint is big enough QFontMetrics fm = bar.fontMetrics(); QStyleOptionProgressBarV2 opt; bar.initStyleOption(&opt); QSize size = QSize(9 * 7 + fm.width(QLatin1Char('0')) * 4, fm.height() + 8); size= bar.style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, &bar); QSize barSize = bar.sizeHint(); QVERIFY(barSize.width() >= size.width()); QCOMPARE(barSize.height(), size.height()); }
void KviTalListWidgetPixmap::paint(QPainter *painter) { int itemHeight = height(listWidget()); int yPos; const QPixmap *pm = pixmap(); if (pm && ! pm->isNull()) { yPos = (itemHeight - pm->height()) / 2; painter->drawPixmap(3, yPos, *pm); } if (!text().isEmpty()) { QFontMetrics fm = painter->fontMetrics(); yPos = ((itemHeight - fm.height()) / 2) + fm.ascent(); painter->drawText(pm->width() + 5, yPos, text()); } }
int Context2D::baseLineOffset(Context2D::TextBaseLine value, const QFontMetrics &metrics) { int offset = 0; switch (value) { case Context2D::Top: break; case Context2D::Alphabetic: case Context2D::Middle: case Context2D::Hanging: offset = metrics.ascent(); break; case Context2D::Bottom: offset = metrics.height(); break; } return offset; }
void KPageListViewDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const { if ( !index.isValid() ) return; QStyleOptionViewItemV4 opt(option); opt.showDecorationSelected = true; QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize); const QString text = index.model()->data( index, Qt::DisplayRole ).toString(); const QIcon icon = index.model()->data( index, Qt::DecorationRole ).value<QIcon>(); const QPixmap pixmap = icon.pixmap( iconSize, iconSize ); QFontMetrics fm = painter->fontMetrics(); int wp = pixmap.width(); int hp = pixmap.height(); QTextLayout iconTextLayout( text, option.font ); QTextOption textOption( Qt::AlignHCenter ); iconTextLayout.setTextOption( textOption ); int maxWidth = qMax( 3 * wp, 8 * fm.height() ); layoutText( &iconTextLayout, maxWidth ); QPen pen = painter->pen(); QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; if ( cg == QPalette::Normal && !(option.state & QStyle::State_Active) ) cg = QPalette::Inactive; style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget); if ( option.state & QStyle::State_Selected ) { painter->setPen( option.palette.color( cg, QPalette::HighlightedText ) ); } else { painter->setPen( option.palette.color( cg, QPalette::Text ) ); } painter->drawPixmap( option.rect.x() + (option.rect.width()/2)-(wp/2), option.rect.y() + 5, pixmap ); if ( !text.isEmpty() ) iconTextLayout.draw( painter, QPoint( option.rect.x() + (option.rect.width()/2)-(maxWidth/2), option.rect.y() + hp+7 ) ); painter->setPen( pen ); drawFocus( painter, option, option.rect ); }
void VisiblePlacemark::drawLabelText(QPainter &labelPainter, const QString &text, const QFont &labelFont, LabelStyle labelStyle, const QColor &color ) { QFont font = labelFont; QFontMetrics metrics = QFontMetrics( font ); int fontAscent = metrics.ascent(); switch ( labelStyle ) { case Selected: { labelPainter.setPen( color ); labelPainter.setFont( font ); QRect textRect( 0, 0, metrics.width( text ), metrics.height() ); labelPainter.fillRect( textRect, QApplication::palette().highlight() ); labelPainter.setPen( QPen( QApplication::palette().highlightedText(), 1 ) ); labelPainter.drawText( 0, fontAscent, text ); break; } case Glow: { font.setWeight( 75 ); fontAscent = QFontMetrics( font ).ascent(); QPen outlinepen( color == QColor( Qt::white ) ? Qt::black : Qt::white ); outlinepen.setWidthF( s_labelOutlineWidth ); QBrush outlinebrush( color ); QPainterPath outlinepath; const QPointF baseline( s_labelOutlineWidth / 2.0, fontAscent ); outlinepath.addText( baseline, font, text ); labelPainter.setRenderHint( QPainter::Antialiasing, true ); labelPainter.setPen( outlinepen ); labelPainter.setBrush( outlinebrush ); labelPainter.drawPath( outlinepath ); labelPainter.setPen( Qt::NoPen ); labelPainter.drawPath( outlinepath ); labelPainter.setRenderHint( QPainter::Antialiasing, false ); break; } default: { labelPainter.setPen( color ); labelPainter.setFont( font ); labelPainter.drawText( 0, fontAscent, text ); } } }
HistoryCompletionView::HistoryCompletionView(QWidget *parent) : QTableView(parent) { horizontalHeader()->hide(); verticalHeader()->hide(); setShowGrid(false); setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::SingleSelection); setTextElideMode(Qt::ElideRight); QFontMetrics metrics = fontMetrics(); verticalHeader()->setDefaultSectionSize(metrics.height()); // As URLs are always LRT, this should be LRT as well setLayoutDirection(Qt::LeftToRight); }
void gcTextList::draw(gcDrawingImpl &impl) const { static const size_t V_OFF_START = 10; static const size_t V_OFF_PAD = 5; impl.SetColor(Qt::white); size_t voffset = V_OFF_START; QFontMetrics met (impl.curFont()); for (tagged_cb gcbPair : list) { glbStringCallback_p gcb (gcbPair.second); if (gcb.isNull() || gcb->msg() == "") continue; impl.Draw(QString::fromStdString(gcb->msg()), QPoint(0, voffset)); voffset += met.height() + V_OFF_PAD; } }
void PMenu::create_pixmap( QPixmap &buf, PMenuItem *item, QPopupMenu *menu) { int w, h; QPainter p; QFontMetrics fm = menu->fontMetrics(); // size of font set for this widget w = 2 + item->pixmap.width() + 4 + fm.width( item->text_name ) + 2; h = ( item->pixmap.height() > fm.height() ? item->pixmap.height() : fm.height() ) + 4; buf.resize( w, h ); // resize pixmap buf.fill( menu->backgroundColor() ); // clear it p.begin( &buf ); p.drawPixmap( 2, 2, item->pixmap ); // use 2x2 border p.setFont( menu->font() ); p.drawText( 2 + item->pixmap.width() + 4, // center text in item 0, w, h, AlignVCenter | ShowPrefix | DontClip | SingleLine, item->text_name ); p.end(); }