void KIconListBoxItem::paint( QPainter *p ) { p->drawPixmap( 3, 0, 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(); p->drawText( pm.width() + 5, yPos, text() ); }
void KviTalListWidgetText::paint(QPainter *painter) { int itemHeight = height(listWidget()); QFontMetrics fm = painter->fontMetrics(); int yPos = ((itemHeight - fm.height()) / 2) + fm.ascent(); painter->drawText(3, yPos, text()); }
void KWD::Switcher::update () { QFontMetrics fm = Plasma::Theme::defaultTheme ()->fontMetrics (); QFont font (Plasma::Theme::defaultTheme ()-> font (Plasma::Theme::DefaultFont)); QString name; QPainter p (&mPixmap); KWD::readWindowProperty (mId, Atoms::switchSelectWindow, (long *)&mSelected); name = KWindowSystem::windowInfo (mSelected, NET::WMVisibleName, 0).visibleName (); while (fm.width (name) > mGeometry.width ()) { name.truncate (name.length () - 6); name += "..."; } p.setCompositionMode (QPainter::CompositionMode_Source); mBackground->paintFrame (&p, QRect (mBorder.left, mBorder.top + mGeometry.height () + 5, mGeometry.width (), fm.height ())); p.setFont (font); p.setPen (Plasma::Theme::defaultTheme ()->color(Plasma::Theme::TextColor)); p.drawText ((mPixmap.width () - fm.width (name)) / 2, mBorder.top + mGeometry.height () + 5 + fm.ascent (), name); }
void SBookWidget::printLabel(const QString &str) { labelPrinter->setPrinterName("Dymo LabelWriter Turbo"); QStringList list = QStringList::split(QChar('\n'), str); QPainter p(labelPrinter); QFont font("Helvitica",12); p.rotate(-90); p.setFont(font); QFontMetrics fm = p.fontMetrics(); p.drawText(-330,20,"Simson Garfinkel & Beth Rosenberg"); p.drawText(-330,40,"305 Walden St., #2"); p.drawText(-330,60,"Cambridge, MA 02138"); int x = -250; int y = 100; unsigned int i = 0; for(i=0;i<list.count();i++){ QString line = (*list.at(i)); y += fm.ascent(); p.drawText(x,y,line); y += fm.descent(); } }
void Painter::fontMetrics(float *ascent, float *descent) { QFontMetrics metrics = QFontMetrics(font()); // ascent and descent are distances, so we use lines QTransform rtform = transform().inverted(); *ascent = rtform.map(QLineF(0, 0, 0, metrics.ascent())).length(); *descent = rtform.map(QLineF(0, 0, 0, metrics.descent())).length(); }
/* Print the current entry */ void SBookWidget::menuFilePrint() { Entry *entry = selectedEntry(); if(entry){ QPrinter printer; if(printer.setup()){ int lines = entry->lines(); QPainter p(&printer); QFont font("Helvitica",12); p.setFont(font); QFontMetrics fm = p.fontMetrics(); int y = 0; int i = 0; for(i=0;i<lines;i++){ y += fm.ascent(); p.drawText(10,y,entry->getLine(i)); y += fm.descent(); } } } }
void SubListBoxItem::paint(QPainter *p) { QFontMetrics fm = p->fontMetrics(); int begin = fm.ascent(); if ( _subtitle->getProblem() ) { p->setPen( Qt::red ); } p->drawText( 3, begin, _subtitle->getTiming() ); std::vector<Subline> v = _subtitle->getSubs(); std::vector<Subline>::const_iterator it; QFont f0 = p->font(); for ( it = v.begin(); it != v.end(); it++ ) { begin += fm.lineSpacing(); if ( it->getFmt() == Subline::Italic ) { QFont f = p->font(); f.setItalic( true ); p->setFont( f ); } else if ( it->getFmt() == Subline::Bold ) { QFont f = p->font(); f.setBold( true ); p->setFont( f ); } p->drawText( 3, begin, it->getLine() ); p->setFont( f0 ); } }
void setXY( float * x , float * y , int alignMode , const QFontMetrics& metrics , const QString& str ) { if ( alignMode == VGDevice::kAlignBaseLeft ) return; float w = metrics.width( str ); float descent = metrics.descent(); float ascent = metrics.ascent(); //Vertical align if ( alignMode & VGDevice::kAlignTop ) { (*y) += ascent; } else if ( alignMode & VGDevice::kAlignBottom ) { (*y) -= descent; } else { // kAlignBase : do nothing, standard QPainter's behaviour. } // Horizontal align if( alignMode & VGDevice::kAlignRight ) (*x) -= w; else if( alignMode & VGDevice::kAlignCenter ) (*x) -= (w * 0.5); else { // kAlignLeft : do nothing, standard QPainter's behaviour. } }
//------------------------------------------------------------------------------ // void XxColoredItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { painter->save(); XxColoredItemData data = qVariantValue<XxColoredItemData>(index.data()); // Font. painter->setFont( _resources->getFontText() ); QFontMetrics fm = painter->fontMetrics(); // Don't draw background of chars since we'll draw first. painter->setBackgroundMode( Qt::TransparentMode ); painter->setPen( data._foreColor ); painter->fillRect( option.rect, data._backColor ); painter->drawText( option.rect.left()+10, option.rect.top()+1 + fm.ascent(), data._colorName ); if (option.state & QStyle::State_Selected) { QRect r = option.rect; r.adjust( 0, 0, -1, -1 ); painter->setPen( QPen( option.palette.highlight(), 1 ) ); painter->drawRect( r ); } painter->restore(); }
void AlbumWidget::paintEvent(QPaintEvent *) { QPainter painter(this); painter.fillRect(rect(), Qt::black); if (m_pixmap.isNull()) { painter.setPen(Qt::white); painter.drawText(rect(), Qt::AlignCenter, tr("Downloading cover, please wait...")); return; } painter.drawPixmap(0, 0, m_pixmap); Song* actualSong = MediaApp::getInstance()->getPlaylistInstance()->getActual(); if (actualSong != NULL) { m_nowPlaying = QString::fromStdString(actualSong->getTitle()); } else { m_nowPlaying = tr("ThePlayer"); } QFontMetrics metrics = painter.fontMetrics(); int textWidth = metrics.width(m_nowPlaying); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 127)); painter.drawRect((width() - textWidth) / 2 - 5, 0, textWidth + 10, metrics.lineSpacing() + 5); painter.setPen(Qt::white); painter.drawText((width() - textWidth) / 2, metrics.leading() + metrics.ascent() + 2, m_nowPlaying); }
void FluidWidget::paintEvent(QPaintEvent * /* event */) { QPainter painter(this); //painter.fillRect(rect(), Qt::black); if (pixmap.isNull()) { painter.setPen(Qt::white); painter.drawText(rect(), Qt::AlignCenter, tr("Rendering initial image, please wait...")); return; } painter.drawPixmap(0, 0, pixmap); QString text = tr("Use mouse wheel or the '+' and '-' keys to zoom. " "Press and hold left mouse button to scroll."); QFontMetrics metrics = painter.fontMetrics(); int textWidth = metrics.width(text); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 127)); painter.drawRect((width() - textWidth) / 2 - 5, 0, textWidth + 10, metrics.lineSpacing() + 5); painter.setPen(Qt::white); painter.drawText((width() - textWidth) / 2, metrics.leading() + metrics.ascent(), text); }
void KSplitListItem::paint( QPainter *p ) { QFontMetrics fm = p->fontMetrics(); int yPos; // vertical text position yPos = fm.ascent() + fm.leading()/2; p->drawText( 5, yPos, actionName ); p->drawText( 5 + halfWidth, yPos, keyName ); }
void TagDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { QPen p( Qt::NoPen ); QBrush b( Qt::NoBrush ); int alpha = 255; float tagRelevance = index.data( PlaydarTagCloudModel::RelevanceRole ).value<float>() * 0.8; QColor bc(54,115,213); QColor borderColor = bc; bc.setAlphaF( tagRelevance * 0.5 ); borderColor.setAlphaF( tagRelevance ); b = QBrush( bc ); p = QPen( borderColor ); QColor const dark = option.palette.color( QPalette::Highlight ).darker(); if( option.state & (QStyle::State_Selected | QStyle::State_Active) ) { b = option.state & QStyle::State_Enabled ? option.palette.highlight() : QColor(0x64, 0x64, 0x64, alpha ); } if( option.state & QStyle::State_MouseOver ) p = option.palette.color( QPalette::Highlight ); if( option.state & QStyle::State_Active ) p = dark; p.setWidth( 3 ); painter->setPen( p ); painter->setBrush( b ); painter->setRenderHint( QPainter::Antialiasing, true ); painter->drawRoundedRect( option.rect.adjusted( 2, 2, -2, -2 ), 5.0f, 5.0f ); const float weight = index.data( PlaydarTagCloudModel::LinearWeightRole ).value<float>(); painter->setFont( font( option.font, weight ) ); painter->setRenderHint( QPainter::Antialiasing, false ); QColor textColor = option.state & (QStyle::State_Selected|QStyle::State_Active) ? option.palette.color( QPalette::HighlightedText ) : option.palette.color( QPalette::Text ); textColor.setAlpha( alpha ); painter->setPen( textColor ); QString const text = index.data().toString(); QFontMetrics const metrics = painter->fontMetrics(); QPoint pt; pt.setX( option.rect.x() + (option.rect.width() - metrics.width( text ))/2 ); pt.setY( option.rect.y() + margins( weight ).height()/2 + metrics.ascent() ); painter->drawText( pt, text ); }
TransitionEditorWindow::TransitionEditorWindow(QWidget* parent) : QWidget(parent) , ui_(new Ui::TransitionEditorWindow) , special_(false) , model_(nullptr) , transition_(nullptr) , transitionType_(TRMControlModel::Transition::TYPE_INVALID) { ui_->setupUi(this); ui_->transitionTypeComboBox->addItem(typeNames[2], 2); ui_->transitionTypeComboBox->addItem(typeNames[3], 3); ui_->transitionTypeComboBox->addItem(typeNames[4], 4); ui_->equationsTree->setColumnCount(NUM_EQUATIONS_TREE_COLUMNS); ui_->equationsTree->setHeaderLabels(QStringList() << tr("Equation")); QFontMetrics fm = fontMetrics(); int rowHeight = fm.height() + fm.ascent(); QHeaderView* vHeader = ui_->pointsTable->verticalHeader(); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) vHeader->setSectionResizeMode(QHeaderView::Fixed); #else vHeader->setResizeMode(QHeaderView::Fixed); #endif vHeader->setDefaultSectionSize(rowHeight); ui_->pointsTable->setColumnCount(NUM_POINTS_TABLE_COLUMNS); ui_->pointsTable->setHorizontalHeaderLabels(QStringList() << tr("Type") << tr("Value") << tr("Is phantom?") << tr("Has slope?") << tr("Slope") << tr("Time")); //ui_->pointsTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch); // QDoubleValidator* validator = new QDoubleValidator(0.0, 1000.0, 1, this); // validator->setNotation(QDoubleValidator::StandardNotation); // ui_->ruleDurationLineEdit->setValidator(validator); // ui_->beatLineEdit->setValidator(validator); // ui_->mark1LineEdit->setValidator(validator); // ui_->mark2LineEdit->setValidator(validator); // ui_->mark3LineEdit->setValidator(validator); ui_->ruleDurationSpinBox->setRange(PARAMETERS_MIN, PARAMETERS_MAX); ui_->ruleDurationSpinBox->setDecimals(PARAMETERS_DECIMALS); ui_->beatSpinBox->setRange(PARAMETERS_MIN, PARAMETERS_MAX); ui_->beatSpinBox->setDecimals(PARAMETERS_DECIMALS); ui_->mark1SpinBox->setRange(PARAMETERS_MIN, PARAMETERS_MAX); ui_->mark1SpinBox->setDecimals(PARAMETERS_DECIMALS); ui_->mark2SpinBox->setRange(PARAMETERS_MIN, PARAMETERS_MAX); ui_->mark2SpinBox->setDecimals(PARAMETERS_DECIMALS); ui_->mark3SpinBox->setRange(PARAMETERS_MIN, PARAMETERS_MAX); ui_->mark3SpinBox->setDecimals(PARAMETERS_DECIMALS); connect(ui_->transitionWidget, SIGNAL(pointCreationRequested(unsigned int, float, float)), this, SLOT(createPoint(unsigned int, float, float))); }
void FavoritesViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 options = option; initStyleOption(&options, index); options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter); if (global.countBehavior == Global::CountNone) return; qint32 lid = index.data(Qt::UserRole).toInt(); QString test = index.data(Qt::UserRole).toString().toLower(); if (test == "stack") return; FavoritesView *tree = NULL; FavoritesViewItem *item = NULL; if (lid > 0) { tree = (FavoritesView*)options.widget; item = tree->dataStore[lid]; } else { return; } if (item->record.type == FavoritesRecord::NotebookStack || item->record.type == FavoritesRecord::LinkedStack || item->record.type == FavoritesRecord::Search) return; qint32 total = item->total; qint32 subTotal = item->subTotal; if (total < 0 || subTotal < 0) { return; } QString countString; if (total == subTotal){ countString = QString("(")+QString::number(total) + QString(")"); } else { countString = QString("(")+QString::number(subTotal) + QString("/") + QString::number(total) + QString(")"); } painter->save(); // shift text right to make icon visible QSize iconSize = options.icon.actualSize(options.rect.size()); painter->translate(options.rect.left()+iconSize.width(), options.rect.top()); QRect clip(0, 0, options.rect.width()+iconSize.width(), options.rect.height()); painter->setClipRect(clip); QFontMetrics fm = options.fontMetrics; QFont f = options.font; f.setBold(false); painter->setFont(f); painter->setPen(Qt::darkGray); painter->drawText(6+fm.width(index.data().toString()+QString(" ")),fm.ascent(),countString); painter->restore(); }
//int Utils::getClosestPointSize(QString fontName, int targetSize, int& nextSmaller, int& nextLarger, int direction, QString text) { int Utils::getClosestPointSize(PointSizeParams p) { //haha - clumsy c++ syntax :))) int closestSize = std::numeric_limits<int>::max(); int nextSmallerSize = std::numeric_limits<int>::max(); int nextLargerSize = std::numeric_limits<int>::max(); int closest = -1; *p.nextSmaller = -1; *p.nextLarger = -1; int pointSize = 1; int maxPointSize = 96; QRect boundingRect; while(pointSize <= maxPointSize) { QFontMetrics fontMetrics = QFontMetrics(QFont(p.fontName, pointSize)); int crtSize = 0; switch(p.measure) { case PointSizeParams::Measure::width: crtSize = fontMetrics.width(p.text); break; case PointSizeParams::Measure::heightAscent: crtSize = fontMetrics.ascent(); break; case PointSizeParams::Measure::height: //TODO - this bounding rect seems to be useless; find something else //boundingRect = fontMetrics.boundingRect(p.text); //crtSize = boundingRect.height(); crtSize = fontMetrics.height(); break; default: Q_ASSERT("this should not happen"); break; } //printf("%s - pointSize=%d. Results in height=%d, we need height=%d\n", // __func__, pointSize, crtSize, targetSize); if (abs(crtSize - p.targetSize) < abs(crtSize - closestSize)) { closest = pointSize; closestSize = crtSize; } if ( (crtSize < p.targetSize) && (abs(crtSize - p.targetSize) < abs(crtSize - nextSmallerSize)) ) { *p.nextSmaller = pointSize; nextSmallerSize = crtSize; } if ( (crtSize > p.targetSize) && (abs(crtSize - p.targetSize) < abs(crtSize - nextLargerSize)) ) { *p.nextLarger = pointSize; nextLargerSize = crtSize; } if ((closestSize != std::numeric_limits<int>::max()) && (nextSmallerSize != std::numeric_limits<int>::max()) && (nextLargerSize != std::numeric_limits<int>::max())) break; pointSize += 1; } //printf("%s, closest:%d:%d, smaller:%d:%d, larger:%d:%d\n", __func__, // closest, closestSize, nextSmaller, nextSmallerSize, nextLarger, nextLargerSize); return closest; }
void OptionsDialog::ColorListItem::paint( QPainter *p ) { QFontMetrics fm = p->fontMetrics(); int h = fm.height(); p->drawText( 30+3*2, fm.ascent() + fm.leading()/2, text() ); p->setPen( Qt::black ); p->drawRect( 3, 1, 30, h-1 ); p->fillRect( 4, 2, 28, h-3, mColor ); }
void NNotebookViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { #if QT_VERSION < 0x050000 QStyleOptionViewItemV4 options = option; #else QStyleOptionViewItem options = option; #endif initStyleOption(&options, index); options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter); if (global.countBehavior == Global::CountNone) return; qint32 lid = index.data(Qt::UserRole).toInt(); QString test = index.data(Qt::UserRole).toString().toLower(); if (test == "stack") return; painter->save(); NNotebookView *tree = nullptr; NNotebookViewItem *item = nullptr; if (lid > 0) { tree = (NNotebookView*)options.widget; item = tree->dataStore[lid]; } else { tree = (NNotebookView*)options.widget; item = tree->root; } qint32 total = item->total; qint32 subTotal = item->subTotal; QString countString; if (total == subTotal){ countString = QString("(")+QString::number(total) + QString(")"); } else { countString = QString("(")+QString::number(subTotal) + QString("/") + QString::number(total) + QString(")"); } // shift text right to make icon visible QSize iconSize = options.icon.actualSize(options.rect.size()); painter->translate(options.rect.left()+iconSize.width(), options.rect.top()); QRect clip(0, 0, options.rect.width()+iconSize.width(), options.rect.height()); painter->setClipRect(clip); QFontMetrics fm = options.fontMetrics; QFont f = options.font; f.setBold(false); painter->setFont(f); painter->setPen(Qt::darkGray); painter->drawText(10+fm.width(index.data().toString()+QString(" ")),fm.ascent(),countString); painter->restore(); }
void GrepListBoxItem::paint(QPainter *p) { QColor base, dim, result, bkground; if (listBox()) { const QColorGroup& group = listBox()->palette().active(); if (isSelected()) { bkground = group.button(); base = group.buttonText(); } else { bkground = group.base(); base = group.text(); } dim = blend(base, bkground); result = group.link(); } else { base = Qt::black; dim = Qt::darkGreen; result = Qt::blue; if (isSelected()) bkground = Qt::lightGray; else bkground = Qt::white; } QFontMetrics fm = p->fontMetrics(); QString stx = lineNumber + ": "; int y = fm.ascent()+fm.leading()/2; int x = 3; p->fillRect(p->window(), QBrush(bkground)); if (show) { p->setPen(dim); p->drawText(x, y, fileName); x += fm.width(fileName); } else { p->setPen(base); QFont font1(p->font()); QFont font2(font1); font2.setBold(true); p->setFont(font2); p->drawText(x, y, stx); p->setFont(font1); x += fm.width(stx); p->setPen(result); p->drawText(x, y, text); } }
/** * @brief 绘制label上显示的文字 * @param [in] 描绘事件 */ void Label::paintEvent(QPaintEvent *ev) { QLabel::paintEvent(ev); if (!customText.isEmpty()) { QPainter p(this); QFontMetrics fm = p.fontMetrics(); QPoint offset; if (flags == Qt::AlignRight) { offset.setX(19); offset.setY(0); } QPoint pos((size().width() - fm.width(customText)) / 2 + offset.x(), (size().height() - (fm.ascent() + fm.descent())) / 2 + fm.ascent() + offset.y()); p.drawText(pos, customText); } }
//! [2] void MandelbrotWidget::paintEvent(QPaintEvent * /* event */) { QPainter painter(this); painter.fillRect(rect(), Qt::black); if (pixmap.isNull()) { painter.setPen(Qt::white); painter.drawText(rect(), Qt::AlignCenter, tr("Rendering initial image, please wait...")); //! [2] //! [3] return; //! [3] //! [4] } //! [4] //! [5] if (curScale == pixmapScale) { //! [5] //! [6] painter.drawPixmap(pixmapOffset, pixmap); //! [6] //! [7] } else { //! [7] //! [8] double scaleFactor = pixmapScale / curScale; int newWidth = int(pixmap.width() * scaleFactor); int newHeight = int(pixmap.height() * scaleFactor); int newX = pixmapOffset.x() + (pixmap.width() - newWidth) / 2; int newY = pixmapOffset.y() + (pixmap.height() - newHeight) / 2; painter.save(); painter.translate(newX, newY); painter.scale(scaleFactor, scaleFactor); QRectF exposed = painter.matrix().inverted().mapRect(rect()).adjusted(-1, -1, 1, 1); painter.drawPixmap(exposed, pixmap, exposed); painter.restore(); } //! [8] //! [9] #if !defined(Q_WS_S60) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) QString text = tr("Use mouse wheel or the '+' and '-' keys to zoom. " "Press and hold left mouse button to scroll."); QFontMetrics metrics = painter.fontMetrics(); int textWidth = metrics.width(text); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 127)); painter.drawRect((width() - textWidth) / 2 - 5, 0, textWidth + 10, metrics.lineSpacing() + 5); painter.setPen(Qt::white); painter.drawText((width() - textWidth) / 2, metrics.leading() + metrics.ascent(), text); #endif }
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 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(); }
/** * Update Vim metrics */ static void update_char_metrics(const QFontMetrics& metric) { gui.char_width = metric.width("M"); // The actual linespace plus Vim's fake linespace gui.char_height = metric.lineSpacing() + p_linespace; if ( metric.underlinePos() >= metric.descent() ) { gui.char_height += metric.underlinePos() - metric.descent() + metric.lineWidth(); } gui.char_ascent = metric.ascent() + p_linespace/2 + metric.leading(); gui.char_ul_pos = metric.underlinePos(); }
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(); }
//------------------------------------------------------------ // //.F ScaleDraw::maxHeight // Return the maximum height of the scale for the // specified painter // //.u Syntax //.f int ScaleDraw::maxHeight(QPainter *p) // //.u Parameters //.p const QFontMetrics& fm -- font metrics used for calculations // int penWidth -- the width of the pen that will be used to draw the scale // //------------------------------------------------------------ int ScaleDraw::maxHeight(const QFontMetrics& fm, int /*penWidth*/) const { int rv = 0; switch (d_orient) { case Top: case Bottom: case Round: case InsideHorizontal: //rv = penWidth + d_vpad + d_majLen + fm.height(); rv = 2 * d_vpad + d_majLen + fm.ascent(); break; case Left: case Right: case InsideVertical: //rv = d_len + ((fm.height() + 1) / 2); rv = d_len + ((fm.ascent() + 1) / 2); break; } return rv; }
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; }
//! [2] void ElidedLabel::paintEvent(QPaintEvent *event) { QFrame::paintEvent(event); QPainter painter(this); QFontMetrics fontMetrics = painter.fontMetrics(); bool didElide = false; int lineSpacing = fontMetrics.lineSpacing(); int y = 0; QTextLayout textLayout(content, painter.font()); textLayout.beginLayout(); forever { QTextLine line = textLayout.createLine(); if (!line.isValid()) break; line.setLineWidth(width()); int nextLineY = y + lineSpacing; if (height() >= nextLineY + lineSpacing) { line.draw(&painter, QPoint(0, y)); y = nextLineY; //! [2] //! [3] } else { QString lastLine = content.mid(line.textStart()); QString elidedLastLine = fontMetrics.elidedText(lastLine, Qt::ElideRight, width()); painter.drawText(QPoint(0, y + fontMetrics.ascent()), elidedLastLine); line = textLayout.createLine(); didElide = line.isValid(); break; } } textLayout.endLayout(); //! [3] //! [4] if (didElide != elided) { elided = didElide; emit elisionChanged(didElide); } }
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 ); } } }