Update usage of QFontMetrics::width() to new API
QFontMetrics(F)::width() has been deprecated and is replaced by horizontalAdvance(). This updates all usage of it in tests and documentation. It is worth noting that many or most of the usages of QFontMetrics::width() probably intended to use boundingRect().width(), but since it currently works, I have not looked into that, just replaced the function name mechanically. Change-Id: Iec382e5bad0b50f37a6cfff841bfb46ed4d4555f Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
cd56e843cc
commit
4d88d79aa5
@ -126,7 +126,7 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
|
||||
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);
|
||||
int textWidth = metrics.horizontalAdvance(text);
|
||||
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(QColor(0, 0, 0, 127));
|
||||
|
@ -129,12 +129,12 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
// Set header resize modes and initial section sizes
|
||||
QFontMetrics fm = fontMetrics();
|
||||
QHeaderView *header = torrentView->header();
|
||||
header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
|
||||
header->resizeSection(1, fm.width(headers.at(1) + " "));
|
||||
header->resizeSection(2, fm.width(headers.at(2) + " "));
|
||||
header->resizeSection(3, qMax(fm.width(headers.at(3) + " "), fm.width(" 1234.0 KB/s ")));
|
||||
header->resizeSection(4, qMax(fm.width(headers.at(4) + " "), fm.width(" 1234.0 KB/s ")));
|
||||
header->resizeSection(5, qMax(fm.width(headers.at(5) + " "), fm.width(tr("Downloading") + " ")));
|
||||
header->resizeSection(0, fm.horizontalAdvance("typical-name-for-a-torrent.torrent"));
|
||||
header->resizeSection(1, fm.horizontalAdvance(headers.at(1) + " "));
|
||||
header->resizeSection(2, fm.horizontalAdvance(headers.at(2) + " "));
|
||||
header->resizeSection(3, qMax(fm.horizontalAdvance(headers.at(3) + " "), fm.horizontalAdvance(" 1234.0 KB/s ")));
|
||||
header->resizeSection(4, qMax(fm.horizontalAdvance(headers.at(4) + " "), fm.horizontalAdvance(" 1234.0 KB/s ")));
|
||||
header->resizeSection(5, qMax(fm.horizontalAdvance(headers.at(5) + " "), fm.horizontalAdvance(tr("Downloading") + " ")));
|
||||
|
||||
// Create common actions
|
||||
QAction *newTorrentAction = new QAction(QIcon(":/icons/bottom.png"), tr("Add &new torrent"), this);
|
||||
@ -174,14 +174,14 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
bottomBar->addWidget(new QLabel(tr("Max download:")));
|
||||
bottomBar->addWidget(downloadLimitSlider);
|
||||
bottomBar->addWidget((downloadLimitLabel = new QLabel(tr("0 KB/s"))));
|
||||
downloadLimitLabel->setFixedSize(QSize(fm.width(tr("99999 KB/s")), fm.lineSpacing()));
|
||||
downloadLimitLabel->setFixedSize(QSize(fm.horizontalAdvance(tr("99999 KB/s")), fm.lineSpacing()));
|
||||
bottomBar->addSeparator();
|
||||
uploadLimitSlider = new QSlider(Qt::Horizontal);
|
||||
uploadLimitSlider->setRange(0, 1000);
|
||||
bottomBar->addWidget(new QLabel(tr("Max upload:")));
|
||||
bottomBar->addWidget(uploadLimitSlider);
|
||||
bottomBar->addWidget((uploadLimitLabel = new QLabel(tr("0 KB/s"))));
|
||||
uploadLimitLabel->setFixedSize(QSize(fm.width(tr("99999 KB/s")), fm.lineSpacing()));
|
||||
uploadLimitLabel->setFixedSize(QSize(fm.horizontalAdvance(tr("99999 KB/s")), fm.lineSpacing()));
|
||||
|
||||
#ifdef Q_OS_OSX
|
||||
setUnifiedTitleAndToolBarOnMac(true);
|
||||
@ -220,7 +220,7 @@ QSize MainWindow::sizeHint() const
|
||||
// Add up the sizes of all header sections. The last section is
|
||||
// stretched, so its size is relative to the size of the width;
|
||||
// instead of counting it, we count the size of its largest value.
|
||||
int width = fontMetrics().width(tr("Downloading") + " ");
|
||||
int width = fontMetrics().horizontalAdvance(tr("Downloading") + " ");
|
||||
for (int i = 0; i < header->count() - 1; ++i)
|
||||
width += header->sectionSize(i);
|
||||
|
||||
|
@ -143,10 +143,10 @@
|
||||
position on the wiggly line based on \c step. In addition, \c x
|
||||
is incremented by the character's width.
|
||||
|
||||
For simplicity, we assume that QFontMetrics::width(\c text)
|
||||
returns the sum of the individual character widths
|
||||
(QFontMetrics::width(\c text[i])). In practice, this is not
|
||||
always the case because QFontMetrics::width(\c text) also takes
|
||||
For simplicity, we assume that QFontMetrics::horizontalAdvance(\c text)
|
||||
returns the sum of the individual character advances
|
||||
(QFontMetrics::horizontalAdvance(\c text[i])). In practice, this is not
|
||||
always the case because QFontMetrics::horizontalAdvance(\c text) also takes
|
||||
into account the kerning between certain letters (e.g., 'A' and
|
||||
'V'). The result is that the text isn't perfectly centered. You
|
||||
can verify this by typing "AVAVAVAVAVAV" in the line edit.
|
||||
|
@ -108,7 +108,7 @@ void FadeMessage::setupScene()
|
||||
int fh = fontMetrics.height();
|
||||
|
||||
QString sceneText = "Qt Everywhere!";
|
||||
int sceneTextWidth = fontMetrics.width(sceneText);
|
||||
int sceneTextWidth = fontMetrics.horizontalAdvance(sceneText);
|
||||
|
||||
QGraphicsRectItem *block = m_scene.addRect(50, 300, sceneTextWidth, fh + 3);
|
||||
block->setPen(Qt::NoPen);
|
||||
|
@ -364,7 +364,7 @@ void PathDeformRenderer::setText(const QString &text)
|
||||
path.addText(advance, f, text.mid(i, 1));
|
||||
m_pathBounds |= path.boundingRect();
|
||||
m_paths << path;
|
||||
advance += QPointF(fm.width(text.mid(i, 1)), 0);
|
||||
advance += QPointF(fm.horizontalAdvance(text.mid(i, 1)), 0);
|
||||
}
|
||||
} else {
|
||||
QPainterPath path;
|
||||
|
@ -294,7 +294,7 @@ void ArthurStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
|
||||
QPixmap titleLeft = cached(":res/images/title_cap_left.png");
|
||||
QPixmap titleRight = cached(":res/images/title_cap_right.png");
|
||||
QPixmap titleStretch = cached(":res/images/title_stretch.png");
|
||||
int txt_width = groupBox->fontMetrics.width(groupBox->text) + 20;
|
||||
int txt_width = groupBox->fontMetrics.horizontalAdvance(groupBox->text) + 20;
|
||||
painter->drawPixmap(r.center().x() - txt_width/2, 0, titleLeft);
|
||||
QRect tileRect = subControlRect(control, groupBox, SC_GroupBoxLabel, widget);
|
||||
painter->drawTiledPixmap(tileRect, titleStretch);
|
||||
@ -385,7 +385,7 @@ QRect ArthurStyle::subControlRect(ComplexControl control, const QStyleOptionComp
|
||||
QPixmap titleLeft = cached(":res/images/title_cap_left.png");
|
||||
QPixmap titleRight = cached(":res/images/title_cap_right.png");
|
||||
QPixmap titleStretch = cached(":res/images/title_stretch.png");
|
||||
int txt_width = group->fontMetrics.width(group->text) + 20;
|
||||
int txt_width = group->fontMetrics.horizontalAdvance(group->text) + 20;
|
||||
rect = QRect(group->rect.center().x() - txt_width/2 + titleLeft.width(), 0,
|
||||
txt_width - titleLeft.width() - titleRight.width(),
|
||||
titleStretch.height());
|
||||
|
@ -98,7 +98,7 @@ void Window::paintEvent(QPaintEvent * /* event */)
|
||||
QFontMetrics metrics(font());
|
||||
QPainter painter(this);
|
||||
int fontHeight = metrics.height();
|
||||
int fontWidth = metrics.width('X');
|
||||
int fontWidth = metrics.horizontalAdvance('X');
|
||||
int yPos = fontHeight;
|
||||
int xPos;
|
||||
|
||||
@ -177,7 +177,7 @@ QSize Window::sizeHint() const
|
||||
{
|
||||
QFontMetrics metrics(font());
|
||||
|
||||
return QSize(metrics.width('X') * WIDTH, metrics.height() * (HEIGHT + 1));
|
||||
return QSize(metrics.horizontalAdvance('X') * WIDTH, metrics.height() * (HEIGHT + 1));
|
||||
}
|
||||
|
||||
//![2]
|
||||
|
@ -181,7 +181,7 @@ void CharacterWidget::paintEvent(QPaintEvent *event)
|
||||
if (key == lastKey)
|
||||
painter.fillRect(column*squareSize + 1, row*squareSize + 1, squareSize, squareSize, QBrush(Qt::red));
|
||||
|
||||
painter.drawText(column*squareSize + (squareSize / 2) - fontMetrics.width(QChar(key))/2,
|
||||
painter.drawText(column*squareSize + (squareSize / 2) - fontMetrics.horizontalAdvance(QChar(key))/2,
|
||||
row*squareSize + 4 + fontMetrics.ascent(),
|
||||
QString(QChar(key)));
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ int CodeEditor::lineNumberAreaWidth()
|
||||
++digits;
|
||||
}
|
||||
|
||||
int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
|
||||
int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits;
|
||||
|
||||
return space;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ void WigglyWidget::paintEvent(QPaintEvent * /* event */)
|
||||
};
|
||||
|
||||
QFontMetrics metrics(font());
|
||||
int x = (width() - metrics.width(text)) / 2;
|
||||
int x = (width() - metrics.horizontalAdvance(text)) / 2;
|
||||
int y = (height() + metrics.ascent() - metrics.descent()) / 2;
|
||||
QColor color;
|
||||
//! [2]
|
||||
@ -91,7 +91,7 @@ void WigglyWidget::paintEvent(QPaintEvent * /* event */)
|
||||
painter.setPen(color);
|
||||
painter.drawText(x, y - ((sineTable[index] * metrics.height()) / 400),
|
||||
QString(text[i]));
|
||||
x += metrics.width(text[i]);
|
||||
x += metrics.horizontalAdvance(text[i]);
|
||||
}
|
||||
}
|
||||
//! [4]
|
||||
|
@ -72,6 +72,6 @@ QString family = info.family();
|
||||
|
||||
//! [4]
|
||||
QFontMetrics fm(f1);
|
||||
int textWidthInPixels = fm.width("How many pixels wide is this text?");
|
||||
int textWidthInPixels = fm.horizontalAdvance("How many pixels wide is this text?");
|
||||
int textHeightInPixels = fm.height();
|
||||
//! [4]
|
||||
|
@ -51,7 +51,7 @@
|
||||
//! [0]
|
||||
QFont font("times", 24);
|
||||
QFontMetrics fm(font);
|
||||
int pixelsWide = fm.width("What's the width of this text?");
|
||||
int pixelsWide = fm.horizontalAdvance("What's the width of this text?");
|
||||
int pixelsHigh = fm.height();
|
||||
//! [0]
|
||||
|
||||
@ -59,6 +59,6 @@ int pixelsHigh = fm.height();
|
||||
//! [1]
|
||||
QFont font("times", 24);
|
||||
QFontMetricsF fm(font);
|
||||
qreal pixelsWide = fm.width("What's the width of this text?");
|
||||
qreal pixelsWide = fm.horizontalAdvance("What's the width of this text?");
|
||||
qreal pixelsHigh = fm.height();
|
||||
//! [1]
|
||||
|
@ -7478,7 +7478,7 @@ start_lengthVariant:
|
||||
if (!expandtabs) {
|
||||
text[offset] = QLatin1Char(' ');
|
||||
} else if (!tabarraylen && !tabstops) {
|
||||
tabstops = qRound(fm.width(QLatin1Char('x'))*8);
|
||||
tabstops = qRound(fm.horizontalAdvance(QLatin1Char('x'))*8);
|
||||
}
|
||||
} else if (chr == QChar(ushort(0x9c))) {
|
||||
// string with multiple length variants
|
||||
|
@ -809,7 +809,7 @@ void QTextDocument::adjustSize()
|
||||
// Pull this private function in from qglobal.cpp
|
||||
QFont f = defaultFont();
|
||||
QFontMetrics fm(f);
|
||||
int mw = fm.width(QLatin1Char('x')) * 80;
|
||||
int mw = fm.horizontalAdvance(QLatin1Char('x')) * 80;
|
||||
int w = mw;
|
||||
setTextWidth(w);
|
||||
QSizeF size = documentLayout()->documentSize();
|
||||
@ -1902,7 +1902,7 @@ static void printPage(int index, QPainter *painter, const QTextDocument *doc, co
|
||||
painter->setFont(QFont(doc->defaultFont()));
|
||||
const QString pageString = QString::number(index);
|
||||
|
||||
painter->drawText(qRound(pageNumberPos.x() - painter->fontMetrics().width(pageString)),
|
||||
painter->drawText(qRound(pageNumberPos.x() - painter->fontMetrics().horizontalAdvance(pageString)),
|
||||
qRound(pageNumberPos.y() + view.top()),
|
||||
pageString);
|
||||
}
|
||||
|
@ -1427,7 +1427,7 @@ void QTextDocumentLayoutPrivate::drawListItem(const QPointF &offset, QPainter *p
|
||||
case QTextListFormat::ListLowerRoman:
|
||||
case QTextListFormat::ListUpperRoman:
|
||||
itemText = static_cast<QTextList *>(object)->itemText(bl);
|
||||
size.setWidth(fontMetrics.width(itemText));
|
||||
size.setWidth(fontMetrics.horizontalAdvance(itemText));
|
||||
size.setHeight(fontMetrics.height());
|
||||
break;
|
||||
|
||||
@ -1445,7 +1445,7 @@ void QTextDocumentLayoutPrivate::drawListItem(const QPointF &offset, QPainter *p
|
||||
|
||||
QRectF r(pos, size);
|
||||
|
||||
qreal xoff = fontMetrics.width(QLatin1Char(' '));
|
||||
qreal xoff = fontMetrics.horizontalAdvance(QLatin1Char(' '));
|
||||
if (dir == Qt::LeftToRight)
|
||||
xoff = -xoff - size.width();
|
||||
r.translate( xoff, (fontMetrics.height() / 2) - (size.height() / 2));
|
||||
@ -2613,7 +2613,7 @@ void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosi
|
||||
QFixed extraMargin;
|
||||
if (docPrivate->defaultTextOption.flags() & QTextOption::AddSpaceForLineAndParagraphSeparators) {
|
||||
QFontMetricsF fm(bl.charFormat().font());
|
||||
extraMargin = QFixed::fromReal(fm.width(QChar(QChar(0x21B5))));
|
||||
extraMargin = QFixed::fromReal(fm.horizontalAdvance(QChar(QChar(0x21B5))));
|
||||
}
|
||||
|
||||
const QFixed indent = this->blockIndent(blockFormat);
|
||||
|
@ -2453,7 +2453,7 @@ void QTextLine::draw(QPainter *p, const QPointF &pos, const QTextLayout::FormatR
|
||||
|
||||
const qreal lineHeight = line.height().toReal();
|
||||
QRectF r(pos.x() + line.x.toReal(), pos.y() + line.y.toReal(),
|
||||
lineHeight / 2, QFontMetrics(eng->font()).width(QLatin1Char(' ')));
|
||||
lineHeight / 2, QFontMetrics(eng->font()).horizontalAdvance(QLatin1Char(' ')));
|
||||
setPenAndDrawBackground(p, QPen(), selection->format, r);
|
||||
p->setPen(pen);
|
||||
}
|
||||
@ -2540,7 +2540,7 @@ void QTextLine::draw(QPainter *p, const QPointF &pos, const QTextLayout::FormatR
|
||||
QPainterPrivate::get(p)->drawTextItem(QPointF(iterator.x.toReal(), y.toReal()), gf, eng);
|
||||
if (eng->option.flags() & QTextOption::ShowTabsAndSpaces) {
|
||||
QChar visualTab(0x2192);
|
||||
int w = QFontMetrics(f).width(visualTab);
|
||||
int w = QFontMetrics(f).horizontalAdvance(visualTab);
|
||||
qreal x = iterator.itemWidth.toReal() - w; // Right-aligned
|
||||
if (x < 0)
|
||||
p->setClipRect(QRectF(iterator.x.toReal(), line.y.toReal(),
|
||||
|
@ -188,7 +188,7 @@ QPixmap QCocoaDrag::dragPixmap(QDrag *drag, QPoint &hotSpot) const
|
||||
if (s.length() > dragImageMaxChars)
|
||||
s = s.left(dragImageMaxChars -3) + QChar(0x2026);
|
||||
if (!s.isEmpty()) {
|
||||
const int width = fm.width(s);
|
||||
const int width = fm.horizontalAdvance(s);
|
||||
const int height = fm.height();
|
||||
if (width > 0 && height > 0) {
|
||||
qreal dpr = 1.0;
|
||||
|
@ -921,7 +921,7 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg
|
||||
height = qMax(height, qMax(iconSize.height(), pmSize.height()));
|
||||
}
|
||||
if (!bt->text().isNull() && bt->toolButtonStyle() != Qt::ToolButtonIconOnly) {
|
||||
int text_width = bt->fontMetrics().width(bt->text()),
|
||||
int text_width = bt->fontMetrics().horizontalAdvance(bt->text()),
|
||||
text_height = bt->fontMetrics().height();
|
||||
if (bt->toolButtonStyle() == Qt::ToolButtonTextUnderIcon) {
|
||||
width = qMax(width, text_width);
|
||||
@ -5516,10 +5516,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
|
||||
QRect br = p->clipRegion().boundingRect();
|
||||
int x = br.x(),
|
||||
y = br.y() + (titlebar->rect.height() / 2 - p->fontMetrics().height() / 2);
|
||||
if (br.width() <= (p->fontMetrics().width(titlebar->text) + iw * 2))
|
||||
if (br.width() <= (p->fontMetrics().horizontalAdvance(titlebar->text) + iw * 2))
|
||||
x += iw;
|
||||
else
|
||||
x += br.width() / 2 - p->fontMetrics().width(titlebar->text) / 2;
|
||||
x += br.width() / 2 - p->fontMetrics().horizontalAdvance(titlebar->text) / 2;
|
||||
if (iw) {
|
||||
int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
|
||||
p->drawPixmap(x - iw, y,
|
||||
|
@ -484,7 +484,7 @@ void QPrintPreviewDialogPrivate::updatePageNumLabel()
|
||||
int numPages = preview->pageCount();
|
||||
int maxChars = QString::number(numPages).length();
|
||||
pageNumLabel->setText(QString::fromLatin1("/ %1").arg(numPages));
|
||||
int cyphersWidth = q->fontMetrics().width(QString().fill(QLatin1Char('8'), maxChars));
|
||||
int cyphersWidth = q->fontMetrics().horizontalAdvance(QString().fill(QLatin1Char('8'), maxChars));
|
||||
int maxWidth = pageNumEdit->minimumSizeHint().width() + cyphersWidth;
|
||||
pageNumEdit->setMinimumWidth(maxWidth);
|
||||
pageNumEdit->setMaximumWidth(maxWidth);
|
||||
|
@ -716,7 +716,7 @@ QRect QAccessibleTextWidget::characterRect(int offset) const
|
||||
QFontMetrics fm(format.font());
|
||||
const QString ch = text(offset, offset + 1);
|
||||
if (!ch.isEmpty()) {
|
||||
int w = fm.width(ch);
|
||||
int w = fm.horizontalAdvance(ch);
|
||||
int h = fm.height();
|
||||
r = QRect(layoutPosition.x() + x, layoutPosition.y() + line.y() + line.ascent() + fm.descent() - h,
|
||||
w, h);
|
||||
|
@ -777,7 +777,7 @@ QRect QAccessibleLineEdit::characterRect(int offset) const
|
||||
const QString ch = text(offset, offset + 1);
|
||||
if (ch.isEmpty())
|
||||
return QRect();
|
||||
int w = fm.width(ch);
|
||||
int w = fm.horizontalAdvance(ch);
|
||||
int h = fm.height();
|
||||
QRect r(x, y, w, h);
|
||||
r.moveTo(lineEdit()->mapToGlobal(r.topLeft()));
|
||||
|
@ -2950,10 +2950,10 @@ void QFileDialogPrivate::createWidgets()
|
||||
qFileDialogUi->treeView->setModel(model);
|
||||
QHeaderView *treeHeader = qFileDialogUi->treeView->header();
|
||||
QFontMetrics fm(q->font());
|
||||
treeHeader->resizeSection(0, fm.width(QLatin1String("wwwwwwwwwwwwwwwwwwwwwwwwww")));
|
||||
treeHeader->resizeSection(1, fm.width(QLatin1String("128.88 GB")));
|
||||
treeHeader->resizeSection(2, fm.width(QLatin1String("mp3Folder")));
|
||||
treeHeader->resizeSection(3, fm.width(QLatin1String("10/29/81 02:02PM")));
|
||||
treeHeader->resizeSection(0, fm.horizontalAdvance(QLatin1String("wwwwwwwwwwwwwwwwwwwwwwwwww")));
|
||||
treeHeader->resizeSection(1, fm.horizontalAdvance(QLatin1String("128.88 GB")));
|
||||
treeHeader->resizeSection(2, fm.horizontalAdvance(QLatin1String("mp3Folder")));
|
||||
treeHeader->resizeSection(3, fm.horizontalAdvance(QLatin1String("10/29/81 02:02PM")));
|
||||
treeHeader->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
|
||||
QActionGroup *showActionGroup = new QActionGroup(q);
|
||||
|
@ -415,7 +415,7 @@ void QMessageBoxPrivate::updateSize()
|
||||
}
|
||||
|
||||
QFontMetrics fm(QApplication::font("QMdiSubWindowTitleBar"));
|
||||
int windowTitleWidth = qMin(fm.width(q->windowTitle()) + 50, hardLimit);
|
||||
int windowTitleWidth = qMin(fm.horizontalAdvance(q->windowTitle()) + 50, hardLimit);
|
||||
if (windowTitleWidth > width)
|
||||
width = windowTitleWidth;
|
||||
|
||||
|
@ -214,7 +214,7 @@ void JavaStyle::drawControl(ControlElement control, const QStyleOption *option,
|
||||
painter->translate(box->rect.width(), -box->rect.height());
|
||||
}
|
||||
|
||||
int textWidth = box->fontMetrics.width(box->text) + 20;
|
||||
int textWidth = box->fontMetrics.horizontalAdvance(box->text) + 20;
|
||||
|
||||
QPolygon innerLine;
|
||||
innerLine << (box->rect.topLeft() + QPoint(0, 1)) <<
|
||||
@ -1016,7 +1016,7 @@ void JavaStyle::drawControl(ControlElement control, const QStyleOption *option,
|
||||
int h = pixmap.height();
|
||||
|
||||
if (!button->text.isEmpty())
|
||||
w += button->fontMetrics.width(button->text) + 2;
|
||||
w += button->fontMetrics.horizontalAdvance(button->text) + 2;
|
||||
|
||||
point = QPoint(ir.x() + ir.width() / 2 - w / 2,
|
||||
ir.y() + ir.height() / 2 - h / 2);
|
||||
@ -2453,7 +2453,7 @@ QRect JavaStyle::subElementRect(SubElement element,
|
||||
|
||||
rect.moveTopLeft(box->rect.topLeft() + QPoint(0, 2));
|
||||
rect.setHeight(box->rect.height() - 4);
|
||||
rect.setWidth(box->fontMetrics.width(box->text) + 15);
|
||||
rect.setWidth(box->fontMetrics.horizontalAdvance(box->text) + 15);
|
||||
break;
|
||||
}
|
||||
case SE_ProgressBarLabel:
|
||||
@ -2467,7 +2467,7 @@ QRect JavaStyle::subElementRect(SubElement element,
|
||||
qstyleoption_cast<const QStyleOptionButton *>(option);
|
||||
|
||||
rect = btn->fontMetrics.boundingRect(btn->text);
|
||||
rect = QRect(0, 0, btn->fontMetrics.width(btn->text),
|
||||
rect = QRect(0, 0, btn->fontMetrics.horizontalAdvance(btn->text),
|
||||
rect.height());
|
||||
|
||||
if (!btn->icon.isNull()) {
|
||||
|
@ -587,7 +587,7 @@ void QExpandingLineEdit::resizeToContents()
|
||||
originalWidth = oldWidth;
|
||||
if (QWidget *parent = parentWidget()) {
|
||||
QPoint position = pos();
|
||||
int hintWidth = minimumWidth() + fontMetrics().width(displayText());
|
||||
int hintWidth = minimumWidth() + fontMetrics().horizontalAdvance(displayText());
|
||||
int parentWidth = parent->width();
|
||||
int maxWidth = isRightToLeft() ? position.x() + oldWidth : parentWidth - position.x();
|
||||
int newWidth = qBound(originalWidth, hintWidth, maxWidth);
|
||||
|
@ -2499,7 +2499,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt,
|
||||
const bool vertical = pb->orientation == Qt::Vertical;
|
||||
if (!vertical) {
|
||||
if (pb->textVisible)
|
||||
textw = qMax(pb->fontMetrics.width(pb->text), pb->fontMetrics.width(QLatin1String("100%"))) + 6;
|
||||
textw = qMax(pb->fontMetrics.horizontalAdvance(pb->text), pb->fontMetrics.horizontalAdvance(QLatin1String("100%"))) + 6;
|
||||
}
|
||||
|
||||
if ((pb->textAlignment & Qt::AlignCenter) == 0) {
|
||||
|
@ -1536,7 +1536,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
|
||||
proxy()->drawItemText(painter, menuItem->rect.adjusted(margin, 0, -margin, 0), Qt::AlignLeft | Qt::AlignVCenter,
|
||||
menuItem->palette, menuItem->state & State_Enabled, menuItem->text,
|
||||
QPalette::Text);
|
||||
w = menuItem->fontMetrics.width(menuItem->text) + margin;
|
||||
w = menuItem->fontMetrics.horizontalAdvance(menuItem->text) + margin;
|
||||
}
|
||||
painter->setPen(shadow.lighter(106));
|
||||
bool reverse = menuItem->direction == Qt::RightToLeft;
|
||||
@ -3216,7 +3216,7 @@ QSize QFusionStyle::sizeFromContents(ContentsType type, const QStyleOption *opti
|
||||
QFont fontBold = menuItem->font;
|
||||
fontBold.setBold(true);
|
||||
QFontMetrics fmBold(fontBold);
|
||||
w += fmBold.width(menuItem->text) - fm.width(menuItem->text);
|
||||
w += fmBold.width(menuItem->text) - fm.horizontalAdvance(menuItem->text);
|
||||
}
|
||||
const int checkcol = qMax<int>(maxpmw, QStyleHelper::dpiScaled(QFusionStylePrivate::menuCheckMarkWidth)); // Windows always shows a check column
|
||||
w += checkcol;
|
||||
|
@ -833,7 +833,7 @@ QHash<QStyle::SubControl, QRect> QStyleSheetStyle::titleBarLayout(const QWidget
|
||||
continue;
|
||||
}
|
||||
if (info.element == PseudoElement_TitleBar) {
|
||||
info.width = tb->fontMetrics.width(tb->text) + 6;
|
||||
info.width = tb->fontMetrics.horizontalAdvance(tb->text) + 6;
|
||||
subRule.geo = new QStyleSheetGeometryData(info.width, tb->fontMetrics.height(), -1, -1, -1, -1);
|
||||
} else {
|
||||
subRule = renderRule(w, tb, info.element);
|
||||
@ -5485,7 +5485,7 @@ QRect QStyleSheetStyle::subControlRect(ComplexControl cc, const QStyleOptionComp
|
||||
groupBox.rect = rule.borderRect(opt->rect);
|
||||
return baseStyle()->subControlRect(cc, &groupBox, sc, w);
|
||||
}
|
||||
int tw = opt->fontMetrics.width(gb->text);
|
||||
int tw = opt->fontMetrics.horizontalAdvance(gb->text);
|
||||
int th = opt->fontMetrics.height();
|
||||
int spacing = pixelMetric(QStyle::PM_CheckBoxLabelSpacing, opt, w);
|
||||
int iw = pixelMetric(QStyle::PM_IndicatorWidth, opt, w);
|
||||
|
@ -2388,7 +2388,7 @@ QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
|
||||
QFont fontBold = mi->font;
|
||||
fontBold.setBold(true);
|
||||
QFontMetrics fmBold(fontBold);
|
||||
w += fmBold.width(mi->text) - fm.width(mi->text);
|
||||
w += fmBold.horizontalAdvance(mi->text) - fm.horizontalAdvance(mi->text);
|
||||
}
|
||||
|
||||
int checkcol = qMax<int>(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth); // Windows always shows a check column
|
||||
|
@ -870,15 +870,15 @@ QSize QAbstractSpinBox::sizeHint() const
|
||||
s = d->textFromValue(d->minimum);
|
||||
s.truncate(18);
|
||||
s += fixedContent;
|
||||
w = qMax(w, fm.width(s));
|
||||
w = qMax(w, fm.horizontalAdvance(s));
|
||||
s = d->textFromValue(d->maximum);
|
||||
s.truncate(18);
|
||||
s += fixedContent;
|
||||
w = qMax(w, fm.width(s));
|
||||
w = qMax(w, fm.horizontalAdvance(s));
|
||||
|
||||
if (d->specialValueText.size()) {
|
||||
s = d->specialValueText;
|
||||
w = qMax(w, fm.width(s));
|
||||
w = qMax(w, fm.horizontalAdvance(s));
|
||||
}
|
||||
w += 2; // cursor blinking space
|
||||
|
||||
@ -911,15 +911,15 @@ QSize QAbstractSpinBox::minimumSizeHint() const
|
||||
s = d->textFromValue(d->minimum);
|
||||
s.truncate(18);
|
||||
s += fixedContent;
|
||||
w = qMax(w, fm.width(s));
|
||||
w = qMax(w, fm.horizontalAdvance(s));
|
||||
s = d->textFromValue(d->maximum);
|
||||
s.truncate(18);
|
||||
s += fixedContent;
|
||||
w = qMax(w, fm.width(s));
|
||||
w = qMax(w, fm.horizontalAdvance(s));
|
||||
|
||||
if (d->specialValueText.size()) {
|
||||
s = d->specialValueText;
|
||||
w = qMax(w, fm.width(s));
|
||||
w = qMax(w, fm.horizontalAdvance(s));
|
||||
}
|
||||
w += 2; // cursor blinking space
|
||||
|
||||
|
@ -2196,7 +2196,7 @@ QSize QCalendarWidget::minimumSizeHint() const
|
||||
} else {
|
||||
for (int i = 1; i <= 7; i++) {
|
||||
QFontMetrics fm(d->m_model->formatForCell(0, i).font());
|
||||
w = qMax(w, fm.width(d->m_model->dayName(d->m_model->dayOfWeekForColumn(i))) + marginH);
|
||||
w = qMax(w, fm.horizontalAdvance(d->m_model->dayName(d->m_model->dayOfWeekForColumn(i))) + marginH);
|
||||
h = qMax(h, fm.height());
|
||||
}
|
||||
}
|
||||
@ -2207,14 +2207,14 @@ QSize QCalendarWidget::minimumSizeHint() const
|
||||
for (int i = 1; i <= 6; i++) {
|
||||
QFontMetrics fm(d->m_model->formatForCell(i, 0).font());
|
||||
for (int j = 1; j < end; j++)
|
||||
w = qMax(w, fm.width(QString::number(j)) + marginH);
|
||||
w = qMax(w, fm.horizontalAdvance(QString::number(j)) + marginH);
|
||||
h = qMax(h, fm.height());
|
||||
}
|
||||
}
|
||||
|
||||
QFontMetrics fm(d->m_model->formatForCell(1, 1).font());
|
||||
for (int i = 1; i <= end; i++) {
|
||||
w = qMax(w, fm.width(QString::number(i)) + marginH);
|
||||
w = qMax(w, fm.horizontalAdvance(QString::number(i)) + marginH);
|
||||
h = qMax(h, fm.height());
|
||||
}
|
||||
|
||||
|
@ -312,7 +312,7 @@ int QComboBoxPrivate::computeWidthHint() const
|
||||
const QFontMetrics &fontMetrics = q->fontMetrics();
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const int textWidth = fontMetrics.width(q->itemText(i));
|
||||
const int textWidth = fontMetrics.horizontalAdvance(q->itemText(i));
|
||||
if (q->itemIcon(i).isNull())
|
||||
width = (qMax(width, textWidth));
|
||||
else
|
||||
@ -341,7 +341,7 @@ QSize QComboBoxPrivate::recomputeSizeHint(QSize &sh) const
|
||||
case QComboBox::AdjustToContents:
|
||||
case QComboBox::AdjustToContentsOnFirstShow:
|
||||
if (count == 0) {
|
||||
sh.rwidth() = 7 * fm.width(QLatin1Char('x'));
|
||||
sh.rwidth() = 7 * fm.horizontalAdvance(QLatin1Char('x'));
|
||||
} else {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (!q->itemIcon(i).isNull()) {
|
||||
@ -364,7 +364,7 @@ QSize QComboBoxPrivate::recomputeSizeHint(QSize &sh) const
|
||||
hasIcon = !q->itemIcon(i).isNull();
|
||||
}
|
||||
if (minimumContentsLength > 0)
|
||||
sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.width(QLatin1Char('X')) + (hasIcon ? iconSize.width() + 4 : 0)));
|
||||
sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.horizontalAdvance(QLatin1Char('X')) + (hasIcon ? iconSize.width() + 4 : 0)));
|
||||
|
||||
|
||||
// height
|
||||
|
@ -318,7 +318,7 @@ QSize QCommandLinkButton::sizeHint() const
|
||||
|
||||
QSize size = QPushButton::sizeHint();
|
||||
QFontMetrics fm(d->titleFont());
|
||||
int textWidth = qMax(fm.width(text()), 135);
|
||||
int textWidth = qMax(fm.horizontalAdvance(text()), 135);
|
||||
int buttonWidth = textWidth + d->textOffset() + d->rightMargin();
|
||||
int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin();
|
||||
|
||||
|
@ -966,12 +966,12 @@ QSize QDateTimeEdit::sizeHint() const
|
||||
int w = 0;
|
||||
QString s;
|
||||
s = d->textFromValue(d->minimum) + QLatin1Char(' ');
|
||||
w = qMax<int>(w, fm.width(s));
|
||||
w = qMax<int>(w, fm.horizontalAdvance(s));
|
||||
s = d->textFromValue(d->maximum) + QLatin1Char(' ');
|
||||
w = qMax<int>(w, fm.width(s));
|
||||
w = qMax<int>(w, fm.horizontalAdvance(s));
|
||||
if (d->specialValueText.size()) {
|
||||
s = d->specialValueText;
|
||||
w = qMax<int>(w, fm.width(s));
|
||||
w = qMax<int>(w, fm.horizontalAdvance(s));
|
||||
}
|
||||
w += 2; // cursor blinking space
|
||||
|
||||
|
@ -263,7 +263,7 @@ void QFontFamilyDelegate::paint(QPainter *painter,
|
||||
system = writingSystem;
|
||||
|
||||
if (system != QFontDatabase::Any) {
|
||||
int w = painter->fontMetrics().width(text + QLatin1String(" "));
|
||||
int w = painter->fontMetrics().horizontalAdvance(text + QLatin1String(" "));
|
||||
painter->setFont(font2);
|
||||
QString sample = QFontDatabase().writingSystemSample(system);
|
||||
if (option.direction == Qt::RightToLeft)
|
||||
@ -287,7 +287,7 @@ QSize QFontFamilyDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
// font.setFamily(text);
|
||||
font.setPointSize(QFontInfo(font).pointSize() * 3/2);
|
||||
QFontMetrics fontMetrics(font);
|
||||
return QSize(fontMetrics.width(text), fontMetrics.height());
|
||||
return QSize(fontMetrics.horizontalAdvance(text), fontMetrics.height());
|
||||
}
|
||||
|
||||
|
||||
@ -554,7 +554,7 @@ QSize QFontComboBox::sizeHint() const
|
||||
{
|
||||
QSize sz = QComboBox::sizeHint();
|
||||
QFontMetrics fm(font());
|
||||
sz.setWidth(fm.width(QLatin1Char('m'))*14);
|
||||
sz.setWidth(fm.horizontalAdvance(QLatin1Char('m'))*14);
|
||||
return sz;
|
||||
}
|
||||
|
||||
|
@ -484,7 +484,7 @@ QSize QGroupBox::minimumSizeHint() const
|
||||
|
||||
QFontMetrics metrics(fontMetrics());
|
||||
|
||||
int baseWidth = metrics.width(d->title) + metrics.width(QLatin1Char(' '));
|
||||
int baseWidth = metrics.horizontalAdvance(d->title) + metrics.horizontalAdvance(QLatin1Char(' '));
|
||||
int baseHeight = metrics.height();
|
||||
if (d->checkable) {
|
||||
baseWidth += style()->pixelMetric(QStyle::PM_IndicatorWidth);
|
||||
|
@ -583,7 +583,7 @@ QSize QLabelPrivate::sizeForWidth(int w) const
|
||||
int m = indent;
|
||||
|
||||
if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
|
||||
m = fm.width(QLatin1Char('x')) - margin*2;
|
||||
m = fm.horizontalAdvance(QLatin1Char('x')) - margin*2;
|
||||
if (m > 0) {
|
||||
if ((align & Qt::AlignLeft) || (align & Qt::AlignRight))
|
||||
hextra += m;
|
||||
@ -1440,7 +1440,7 @@ QRect QLabelPrivate::documentRect() const
|
||||
: q->layoutDirection(), QFlag(this->align));
|
||||
int m = indent;
|
||||
if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
|
||||
m = q->fontMetrics().width(QLatin1Char('x')) / 2 - margin;
|
||||
m = q->fontMetrics().horizontalAdvance(QLatin1Char('x')) / 2 - margin;
|
||||
if (m > 0) {
|
||||
if (align & Qt::AlignLeft)
|
||||
cr.setLeft(cr.left() + m);
|
||||
|
@ -682,7 +682,7 @@ QSize QLineEdit::sizeHint() const
|
||||
int h = qMax(fm.height(), 14) + 2*d->verticalMargin
|
||||
+ d->topTextMargin + d->bottomTextMargin
|
||||
+ d->topmargin + d->bottommargin;
|
||||
int w = fm.width(QLatin1Char('x')) * 17 + 2*d->horizontalMargin
|
||||
int w = fm.horizontalAdvance(QLatin1Char('x')) * 17 + 2*d->horizontalMargin
|
||||
+ d->effectiveLeftTextMargin() + d->effectiveRightTextMargin()
|
||||
+ d->leftmargin + d->rightmargin; // "some"
|
||||
QStyleOptionFrame opt;
|
||||
|
@ -435,13 +435,13 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const
|
||||
QString s = action->text();
|
||||
int t = s.indexOf(QLatin1Char('\t'));
|
||||
if (t != -1) {
|
||||
tabWidth = qMax(int(tabWidth), qfm.width(s.mid(t+1)));
|
||||
tabWidth = qMax(int(tabWidth), qfm.horizontalAdvance(s.mid(t+1)));
|
||||
s = s.left(t);
|
||||
#ifndef QT_NO_SHORTCUT
|
||||
} else if (action->isShortcutVisibleInContextMenu() || !contextMenu) {
|
||||
QKeySequence seq = action->shortcut();
|
||||
if (!seq.isEmpty())
|
||||
tabWidth = qMax(int(tabWidth), qfm.width(seq.toString(QKeySequence::NativeText)));
|
||||
tabWidth = qMax(int(tabWidth), qfm.horizontalAdvance(seq.toString(QKeySequence::NativeText)));
|
||||
#endif
|
||||
}
|
||||
sz.setWidth(fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, s).width());
|
||||
|
@ -364,7 +364,7 @@ void QPlainTextDocumentLayout::layoutBlock(const QTextBlock &block)
|
||||
int extraMargin = 0;
|
||||
if (option.flags() & QTextOption::AddSpaceForLineAndParagraphSeparators) {
|
||||
QFontMetrics fm(block.charFormat().font());
|
||||
extraMargin += fm.width(QChar(0x21B5));
|
||||
extraMargin += fm.horizontalAdvance(QChar(0x21B5));
|
||||
}
|
||||
tl->beginLayout();
|
||||
qreal availableWidth = d->width;
|
||||
|
@ -421,7 +421,7 @@ QSize QProgressBar::sizeHint() const
|
||||
QStyleOptionProgressBar 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);
|
||||
QSize size = QSize(qMax(9, cw) * 7 + fm.horizontalAdvance(QLatin1Char('0')) * 4, fm.height() + 8);
|
||||
if (opt.orientation == Qt::Vertical)
|
||||
size = size.transposed();
|
||||
return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this);
|
||||
|
@ -348,7 +348,7 @@ QSize QToolButton::sizeHint() const
|
||||
|
||||
if (opt.toolButtonStyle != Qt::ToolButtonIconOnly) {
|
||||
QSize textSize = fm.size(Qt::TextShowMnemonic, text());
|
||||
textSize.setWidth(textSize.width() + fm.width(QLatin1Char(' '))*2);
|
||||
textSize.setWidth(textSize.width() + fm.horizontalAdvance(QLatin1Char(' '))*2);
|
||||
if (opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
|
||||
h += 4 + textSize.height();
|
||||
if (textSize.width() > w)
|
||||
|
@ -1414,7 +1414,7 @@ QRectF QWidgetTextControlPrivate::rectForPosition(int position) const
|
||||
if (relativePos < line.textLength() - line.textStart())
|
||||
w = line.cursorToX(relativePos + 1) - x;
|
||||
else
|
||||
w = QFontMetrics(block.layout()->font()).width(QLatin1Char(' ')); // in sync with QTextLine::draw()
|
||||
w = QFontMetrics(block.layout()->font()).horizontalAdvance(QLatin1Char(' ')); // in sync with QTextLine::draw()
|
||||
}
|
||||
r = QRectF(layoutPos.x() + x, layoutPos.y() + line.y(),
|
||||
cursorWidth + w, line.height());
|
||||
|
@ -4498,7 +4498,7 @@ void tst_QPainter::drawText_subPixelPositionsInRaster_qtbug5053()
|
||||
{
|
||||
QFontMetricsF fm(qApp->font());
|
||||
|
||||
QImage baseLine(fm.width(QChar::fromLatin1('e')), fm.height(), QImage::Format_RGB32);
|
||||
QImage baseLine(fm.horizontalAdvance(QChar::fromLatin1('e')), fm.height(), QImage::Format_RGB32);
|
||||
baseLine.fill(Qt::white);
|
||||
{
|
||||
QPainter p(&baseLine);
|
||||
|
@ -312,7 +312,7 @@ void tst_QFontDatabase::condensedFontWidth()
|
||||
QFont testFontCondensed("QtBidiTestFontCondensed");
|
||||
QFontMetrics fmTF(testFont);
|
||||
QFontMetrics fmTFC(testFontCondensed);
|
||||
QVERIFY(fmTF.width(testString()) > fmTFC.width(testString()));
|
||||
QVERIFY(fmTF.horizontalAdvance(testString()) > fmTFC.horizontalAdvance(testString()));
|
||||
|
||||
}
|
||||
|
||||
@ -335,15 +335,15 @@ void tst_QFontDatabase::condensedFontMatching()
|
||||
QEXPECT_FAIL("","No matching of sub-family by stretch on Windows", Continue);
|
||||
#endif
|
||||
|
||||
QCOMPARE(QFontMetrics(tfcByStretch).width(testString()),
|
||||
QFontMetrics(tfcByStyleName).width(testString()));
|
||||
QCOMPARE(QFontMetrics(tfcByStretch).horizontalAdvance(testString()),
|
||||
QFontMetrics(tfcByStyleName).horizontalAdvance(testString()));
|
||||
|
||||
if (!db.hasFamily("QtBidiTestFontCondensed"))
|
||||
QSKIP("This platform doesn't support font sub-family names (QTBUG-55625)");
|
||||
|
||||
QFont tfcBySubfamilyName("QtBidiTestFontCondensed");
|
||||
QCOMPARE(QFontMetrics(tfcByStyleName).width(testString()),
|
||||
QFontMetrics(tfcBySubfamilyName).width(testString()));
|
||||
QCOMPARE(QFontMetrics(tfcByStyleName).horizontalAdvance(testString()),
|
||||
QFontMetrics(tfcBySubfamilyName).horizontalAdvance(testString()));
|
||||
}
|
||||
|
||||
void tst_QFontDatabase::rasterFonts()
|
||||
|
@ -167,7 +167,7 @@ void tst_QFontMetrics::elidedText()
|
||||
QFETCH(QFont, font);
|
||||
QFETCH(QString, text);
|
||||
QFontMetrics fm(font);
|
||||
int w = fm.width(text);
|
||||
int w = fm.horizontalAdvance(text);
|
||||
QString newtext = fm.elidedText(text,Qt::ElideRight,w+1, 0);
|
||||
QCOMPARE(text,newtext); // should not elide
|
||||
newtext = fm.elidedText(text,Qt::ElideRight,w-1, 0);
|
||||
@ -202,7 +202,7 @@ void tst_QFontMetrics::bypassShaping()
|
||||
QVERIFY(textWidth != 0);
|
||||
int charsWidth = 0;
|
||||
for (int i = 0; i < text.size(); ++i)
|
||||
charsWidth += fm.width(text[i]);
|
||||
charsWidth += fm.horizontalAdvance(text[i]);
|
||||
// This assertion is needed in Qt WebKit's WebCore::Font::offsetForPositionForSimpleText
|
||||
QCOMPARE(textWidth, charsWidth);
|
||||
}
|
||||
@ -226,7 +226,7 @@ template<class FontMetrics, typename PrimitiveType> void elidedMultiLength_helpe
|
||||
// Not even wide enough for "small" - should use ellipsis
|
||||
QChar ellipsisChar(0x2026);
|
||||
QString text1_el = QString::fromLatin1("s") + ellipsisChar;
|
||||
PrimitiveType width_small = fm.width(text1_el);
|
||||
PrimitiveType width_small = fm.horizontalAdvance(text1_el);
|
||||
QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_small + 1), text1_el);
|
||||
}
|
||||
|
||||
|
@ -639,7 +639,7 @@ void tst_QStaticText::setPenPlainText()
|
||||
font.setStyleStrategy(QFont::NoAntialias);
|
||||
|
||||
QFontMetricsF fm(font);
|
||||
QImage image(qCeil(fm.width("XXXXX")), qCeil(fm.height()), format);
|
||||
QImage image(qCeil(fm.horizontalAdvance("XXXXX")), qCeil(fm.height()), format);
|
||||
image.fill(Qt::white);
|
||||
{
|
||||
QPainter p(&image);
|
||||
@ -662,7 +662,7 @@ void tst_QStaticText::setPenRichText()
|
||||
font.setStyleStrategy(QFont::NoAntialias);
|
||||
|
||||
QFontMetricsF fm(font);
|
||||
QPixmap image(qCeil(fm.width("XXXXX")), qCeil(fm.height()));
|
||||
QPixmap image(qCeil(fm.horizontalAdvance("XXXXX")), qCeil(fm.height()));
|
||||
image.fill(Qt::white);
|
||||
{
|
||||
QPainter p(&image);
|
||||
@ -686,7 +686,7 @@ void tst_QStaticText::richTextOverridesPen()
|
||||
font.setStyleStrategy(QFont::NoAntialias);
|
||||
|
||||
QFontMetricsF fm(font);
|
||||
QPixmap image(qCeil(fm.width("XXXXX")), qCeil(fm.height()));
|
||||
QPixmap image(qCeil(fm.horizontalAdvance("XXXXX")), qCeil(fm.height()));
|
||||
image.fill(Qt::white);
|
||||
{
|
||||
QPainter p(&image);
|
||||
|
@ -611,7 +611,7 @@ void tst_QTextDocument::task240325()
|
||||
QFontMetrics fm(p.font());
|
||||
|
||||
// Set page size to contain image and one "Foobar"
|
||||
doc->setPageSize(QSize(100 + fm.width("Foobar")*2, 1000));
|
||||
doc->setPageSize(QSize(100 + fm.horizontalAdvance("Foobar")*2, 1000));
|
||||
|
||||
// Force layout
|
||||
doc->drawContents(&p);
|
||||
|
@ -203,7 +203,7 @@ void tst_QTextLayout::init()
|
||||
testFont.setPixelSize(TESTFONT_SIZE);
|
||||
testFont.setWeight(QFont::Normal);
|
||||
#ifdef QT_BUILD_INTERNAL
|
||||
QCOMPARE(QFontMetrics(testFont).width('a'), testFont.pixelSize());
|
||||
QCOMPARE(QFontMetrics(testFont).horizontalAdvance('a'), testFont.pixelSize());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1695,7 +1695,7 @@ static QRect characterRect(const QTextEdit &edit, int offset)
|
||||
++it;
|
||||
QFontMetrics fm(it.fragment().charFormat().font());
|
||||
QChar ch = edit.document()->characterAt(offset);
|
||||
int w = fm.width(ch);
|
||||
int w = fm.horizontalAdvance(ch);
|
||||
int h = fm.height();
|
||||
|
||||
qreal x = line.cursorToX(relativeOffset);
|
||||
@ -1766,9 +1766,9 @@ void tst_QAccessibility::textEditTest()
|
||||
QCOMPARE(endOffset, 31);
|
||||
QCOMPARE(textIface->characterCount(), 48);
|
||||
QFontMetrics fm(edit.document()->defaultFont());
|
||||
QCOMPARE(textIface->characterRect(0).size(), QSize(fm.width("h"), fm.height()));
|
||||
QCOMPARE(textIface->characterRect(5).size(), QSize(fm.width(" "), fm.height()));
|
||||
QCOMPARE(textIface->characterRect(6).size(), QSize(fm.width("w"), fm.height()));
|
||||
QCOMPARE(textIface->characterRect(0).size(), QSize(fm.horizontalAdvance("h"), fm.height()));
|
||||
QCOMPARE(textIface->characterRect(5).size(), QSize(fm.horizontalAdvance(" "), fm.height()));
|
||||
QCOMPARE(textIface->characterRect(6).size(), QSize(fm.horizontalAdvance("w"), fm.height()));
|
||||
|
||||
int offset = 10;
|
||||
QCOMPARE(textIface->text(offset, offset + 1), QStringLiteral("d"));
|
||||
|
@ -4270,7 +4270,7 @@ void tst_QTableView::changeHeaderData()
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
||||
|
||||
QString text = "long long long text";
|
||||
const int textWidth = view.verticalHeader()->fontMetrics().width(text);
|
||||
const int textWidth = view.verticalHeader()->fontMetrics().horizontalAdvance(text);
|
||||
QVERIFY(view.verticalHeader()->width() < textWidth);
|
||||
|
||||
model.setHeaderData(2, Qt::Vertical, text);
|
||||
|
@ -3278,7 +3278,7 @@ void tst_QTreeWidget::task239150_editorWidth()
|
||||
QVERIFY(tree.itemWidget(&item, 0) == 0);
|
||||
tree.editItem(&item);
|
||||
QVERIFY(tree.itemWidget(&item, 0));
|
||||
QVERIFY(tree.itemWidget(&item, 0)->width() >= minWidth + tree.fontMetrics().width(item.text(0)));
|
||||
QVERIFY(tree.itemWidget(&item, 0)->width() >= minWidth + tree.fontMetrics().horizontalAdvance(item.text(0)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ void tst_QFontComboBox::sizeHint()
|
||||
SubQFontComboBox box;
|
||||
QSize sizeHint = box.QComboBox::sizeHint();
|
||||
QFontMetrics fm(box.font());
|
||||
sizeHint.setWidth(qMax(sizeHint.width(), fm.width(QLatin1Char('m'))*14));
|
||||
sizeHint.setWidth(qMax(sizeHint.width(), fm.horizontalAdvance(QLatin1Char('m'))*14));
|
||||
QCOMPARE(box.sizeHint(), sizeHint);
|
||||
}
|
||||
|
||||
|
@ -3436,8 +3436,8 @@ void tst_QLineEdit::textMargin_data()
|
||||
|
||||
// Different styles generate different offsets, so
|
||||
// calculate the width rather than hardcode it.
|
||||
const int pixelWidthOfM = metrics.width(s, 1);
|
||||
const int pixelWidthOfMMM_MM = metrics.width(s, 6);
|
||||
const int pixelWidthOfM = metrics.horizontalAdvance(s, 1);
|
||||
const int pixelWidthOfMMM_MM = metrics.horizontalAdvance(s, 6);
|
||||
|
||||
QTest::newRow("default-0") << 0 << 0 << 0 << 0 << QPoint(pixelWidthOfMMM_MM, 0) << 6;
|
||||
QTest::newRow("default-1") << 0 << 0 << 0 << 0 << QPoint(1, 1) << 0;
|
||||
|
@ -870,7 +870,7 @@ void tst_QPlainTextEdit::lineWrapModes()
|
||||
// QPlainTextEdit does lazy line layout on resize, only for the visible blocks.
|
||||
// We thus need to make it wide enough to show something visible.
|
||||
int minimumWidth = 2 * ed->document()->documentMargin();
|
||||
minimumWidth += ed->fontMetrics().width(QLatin1Char('a'));
|
||||
minimumWidth += ed->fontMetrics().horizontalAdvance(QLatin1Char('a'));
|
||||
minimumWidth += ed->frameWidth();
|
||||
ed->resize(minimumWidth, 1000);
|
||||
QCOMPARE(lineCount(), 26);
|
||||
|
@ -293,7 +293,7 @@ void tst_QProgressBar::sizeHint()
|
||||
QFontMetrics fm = bar.fontMetrics();
|
||||
QStyleOptionProgressBar opt;
|
||||
bar.initStyleOption(&opt);
|
||||
QSize size = QSize(9 * 7 + fm.width(QLatin1Char('0')) * 4, fm.height() + 8);
|
||||
QSize size = QSize(9 * 7 + fm.horizontalAdvance(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());
|
||||
|
@ -123,7 +123,7 @@ QSizeF Button::sizeHint(Qt::SizeHint which,
|
||||
case Qt::PreferredSize:
|
||||
{
|
||||
QFontMetricsF fm(d->textItem->font());
|
||||
return QSizeF(fm.width(d->textItem->text()), fm.height());
|
||||
return QSizeF(fm.horizontalAdvance(d->textItem->text()), fm.height());
|
||||
}
|
||||
default:
|
||||
return QGraphicsWidget::sizeHint(which, constraint);
|
||||
|
@ -73,7 +73,7 @@ QSizeF Label::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
||||
// fall thru
|
||||
case Qt::PreferredSize: {
|
||||
QFontMetricsF fm(m_textItem->font());
|
||||
return QSizeF(fm.width(m_textItem->text()), fm.height());
|
||||
return QSizeF(fm.horizontalAdvance(m_textItem->text()), fm.height());
|
||||
}
|
||||
default:
|
||||
return GvbWidget::sizeHint(which, constraint);
|
||||
|
@ -544,13 +544,13 @@ public:
|
||||
m_staticTexts.append(staticText);
|
||||
|
||||
QFontMetrics fm(p->font());
|
||||
m_size = QSize(fm.width(m_text, m_text.length()), fm.height());
|
||||
m_size = QSize(fm.horizontalAdvance(m_text, m_text.length()), fm.height());
|
||||
|
||||
break;
|
||||
}
|
||||
case PainterQPointMode: {
|
||||
QFontMetrics fm(p->font());
|
||||
m_size = QSize(fm.width(m_text, m_text.length()), fm.height());
|
||||
m_size = QSize(fm.horizontalAdvance(m_text, m_text.length()), fm.height());
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user