本文整理汇总了C++中QTextLine类的典型用法代码示例。如果您正苦于以下问题:C++ QTextLine类的具体用法?C++ QTextLine怎么用?C++ QTextLine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Q_ASSERT
void KTextDocumentLayout::Private::adjustSize()
{
if (parent->resizeMethod() == KTextDocument::NoResize)
return;
if (parent->shapes().isEmpty())
return;
// Limit auto-resizing to the first shape only (there won't be more
// with auto-resizing turned on, unless specifically set)
KShape *shape = parent->shapes().first();
// Determine the maximum width of all text lines
qreal width = 0;
for (QTextBlock block = parent->document()->begin(); block.isValid(); block = block.next()) {
// The block layout's wrap mode must be QTextOption::NoWrap, thus the line count
// of a valid block must be 1 (otherwise this resizing scheme wouldn't work)
Q_ASSERT(block.layout()->lineCount() == 1);
QTextLine line = block.layout()->lineAt(0);
width = qMax(width, line.naturalTextWidth());
}
// Use position and height of last text line to calculate height
QTextLine line = parent->document()->lastBlock().layout()->lineAt(0);
qreal height = line.position().y() + line.height();
shape->setSize(QSizeF(width, height));
}
示例2: position
QList<QGlyphRun> QTextFragment::glyphRuns(int pos, int len) const
{
if (!p || !n)
return QList<QGlyphRun>();
int blockNode = p->blockMap().findNode(position());
const QTextBlockData *blockData = p->blockMap().fragment(blockNode);
QTextLayout *layout = blockData->layout;
int blockPosition = p->blockMap().position(blockNode);
if (pos < 0)
pos = position() - blockPosition;
if (len < 0)
len = length();
if (len == 0)
return QList<QGlyphRun>();
QList<QGlyphRun> ret;
for (int i=0; i<layout->lineCount(); ++i) {
QTextLine textLine = layout->lineAt(i);
ret += textLine.glyphRuns(pos, len);
}
return ret;
}
示例3: initForNewTest
void TestDocumentLayout::testRightToLeftList()
{
initForNewTest("a\nb\nc");
KoParagraphStyle h1;
h1.setTextProgressionDirection(KoText::RightLeftTopBottom);
m_styleManager->add(&h1);
KoListStyle listStyle;
KoListLevelProperties llp = listStyle.levelProperties(1);
llp.setStyle(KoListStyle::DecimalItem);
listStyle.setLevelProperties(llp);
h1.setListStyle(&listStyle);
QTextBlock block = m_doc->begin();
h1.applyStyle(block);
block = block.next();
h1.applyStyle(block);
block = block.next();
h1.applyStyle(block);
block = block.next();
m_layout->layout();
block = m_doc->begin();
while (block.isValid()) {
KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
QVERIFY(data);
QVERIFY(data->counterWidth() > 2);
QVERIFY(data->counterPosition().x() > 100);
QTextLine line = block.layout()->lineAt(0);
QVERIFY(line.isValid());
QCOMPARE(line.x(), (qreal)0);
QCOMPARE(line.width() + data->counterWidth() + data->counterSpacing(), (qreal)200);
block = block.next();
}
}
示例4: cursor
void tst_QTextFormat::testTabsUsed()
{
QTextDocument doc;
QTextCursor cursor(&doc);
QList<QTextOption::Tab> tabs;
QTextBlockFormat format;
QTextOption::Tab tab;
tab.position = 100;
tabs.append(tab);
format.setTabPositions(tabs);
cursor.mergeBlockFormat(format);
cursor.insertText("foo\tbar");
//doc.setPageSize(QSizeF(200, 200));
doc.documentLayout()->pageCount(); // force layout;
QTextBlock block = doc.begin();
QTextLayout *layout = block.layout();
QVERIFY(layout);
QCOMPARE(layout->lineCount(), 1);
QTextLine line = layout->lineAt(0);
QCOMPARE(line.cursorToX(4), 100.);
QTextOption option = layout->textOption();
QCOMPARE(option.tabs().count(), tabs.count());
}
示例5: setUnicodeText
void setUnicodeText(const QString &text, const QFont &font, const QColor &color)
{
deleteContent();
QRawFont raw_font = QRawFont::fromFont(font, QFontDatabase::Latin);
qreal line_width = raw_font.averageCharWidth() * text.size();
QSGRenderContext *sgr = QQuickItemPrivate::get(m_owner)->sceneGraphRenderContext();
QTextLayout layout(text,font);
layout.beginLayout();
QTextLine line = layout.createLine();
line.setLineWidth(line_width);
//Q_ASSERT(!layout.createLine().isValid());
layout.endLayout();
QList<QGlyphRun> glyphRuns = line.glyphRuns();
qreal xpos = 0;
for (int i = 0; i < glyphRuns.size(); i++) {
QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr, false);
node->setOwnerElement(m_owner);
node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
node->setGlyphs(QPointF(xpos, raw_font.ascent()), glyphRuns.at(i));
node->setStyle(QQuickText::Normal);
node->setColor(color);
xpos += raw_font.averageCharWidth() * glyphRuns.at(i).positions().size();
node->update();
appendChildNode(node);
}
}
示例6: setContent
void setContent(const ToolTipContent &data)
{
QString html;
if (!data.mainText().isEmpty()) {
html.append("<div><b>" + data.mainText() + "</b></div>");
}
html.append(data.subText());
m_anchor.clear();
m_document->clear();
data.registerResources(m_document);
if (!html.isEmpty()) {
m_document->setHtml("<p>" + html + "</p>");
}
m_document->adjustSize();
m_haloRects.clear();
QTextLayout *layout = m_document->begin().layout();
//layout->setPosition(QPointF(textRect.x(), textBoundingRect->y()));
QTextLine line;
for (int i = 0; i < layout->lineCount(); ++i) {
line = layout->lineAt(i);
// Add halo rect only when a non empty line is found
if (line.naturalTextWidth()) {
m_haloRects.append(line.naturalTextRect().translated(layout->position().toPoint()).toRect().translated(m_margin, m_margin));
}
}
update();
}
示例7: textFontMetrics
//virtual
void PixButton::redoLabelTextLayout()
{
//TODO: somewhat wasteful. If there is no label, should just exit early and leave a layout that will be left unrendered by paint()
m_textLayoutObject.clearLayout();
m_textLayoutObject.setText(m_label);
m_textLayoutObject.setFont(m_textFont);
QTextOption textOpts;
textOpts.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
textOpts.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
m_textLayoutObject.setTextOption(textOpts);
QFontMetrics textFontMetrics(m_textFont);
int leading = textFontMetrics.leading();
int rise = textFontMetrics.ascent();
qreal height = 0;
m_textLayoutObject.beginLayout();
while (height < m_labelMaxGeom.height()) {
QTextLine line = m_textLayoutObject.createLine();
if (!line.isValid())
break;
line.setLineWidth(m_labelMaxGeom.width());
if (m_textLayoutObject.lineCount() > 1)
{
height += leading;
}
line.setPosition(QPointF(0, height));
height += line.height();
}
height = qMin((quint32)DimensionsGlobal::roundUp(height),(quint32)m_labelMaxGeom.height());
height = DimensionsGlobal::roundDown(height) - (DimensionsGlobal::roundDown(height) % 2); //force to an even #
m_textLayoutObject.endLayout();
//TODO: PIXEL-ALIGN
m_labelGeom = DimensionsGlobal::realRectAroundRealPoint(QSizeF(m_textLayoutObject.boundingRect().width(),height)).toAlignedRect();
}
示例8: textLayout
void PluginListDelegate::drawDisplay(QPainter* painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
{
QTextDocument textDocument;
textDocument.setHtml(text);
QTextLayout textLayout(textDocument.begin());
textLayout.setFont(option.font);
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0) + 1;
QRect textRect = rect.adjusted(textMargin, 0, -textMargin, 0); // remove width padding
textLayout.beginLayout();
qreal height = 0;
while (1) {
QTextLine line = textLayout.createLine();
if (!line.isValid()) {
break;
}
line.setLineWidth(textRect.width());
height += 3;
line.setPosition(QPoint(0, height));
height += line.height();
}
textLayout.endLayout();
textLayout.draw(painter, QPointF(textRect.left(), textRect.top()));
}
示例9: POINT_TO_INCH
void RowHeader::drawText(QPainter* painter, const QFont& font,
qreal ypos, qreal width, const QString& text) const
{
register Sheet * const sheet = m_pCanvas->activeSheet();
if (!sheet)
return;
const double scaleX = POINT_TO_INCH(double(KoDpi::dpiX()));
const double scaleY = POINT_TO_INCH(double(KoDpi::dpiY()));
// Qt scales the font already with the logical resolution. Do not do it twice!
painter->save();
painter->scale(1.0 / scaleX, 1.0 / scaleY);
QTextLayout textLayout(text, font);
textLayout.beginLayout();
textLayout.setTextOption(QTextOption(Qt::AlignHCenter));
forever {
QTextLine line = textLayout.createLine();
if (!line.isValid())
break;
line.setLineWidth(width * scaleX);
}
textLayout.endLayout();
QPointF loc(0, ypos * scaleY);
textLayout.draw(painter, loc);
painter->restore();
}
示例10: qstring
int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool includePartialGlyphs) const
{
QString string = qstring(run);
QTextLayout layout(string, font());
QTextLine line = setupLayout(&layout, run);
return line.xToCursor(position);
}
示例11: descriptionLayout
int JobItem::descriptionHeight(const QStyleOptionViewItem & option)
{
int textTotalWidth = 0;
int lineWidth = option.rect.width() - 2 * m_itemPadding;
QString description = m_job->description().simplified();
QTextLayout descriptionLayout(description, m_descriptionFont, m_paintDevice);
descriptionLayout.beginLayout();
for (int i = 0; i < m_descriptionLineCount - 1; ++i)
{
QTextLine line = descriptionLayout.createLine();
if (!line.isValid())
{
// There is no text left to be inserted into the layout.
break;
}
line.setLineWidth(lineWidth);
textTotalWidth += line.naturalTextWidth();
}
descriptionLayout.endLayout();
// Add space for last visible line.
textTotalWidth += lineWidth;
m_descriptionText = m_descriptionFontMetrics.elidedText(description,
Qt::ElideRight,
textTotalWidth);
m_descriptionRect =
m_descriptionFontMetrics.boundingRect(0,
0,
option.rect.width() - 2 * m_itemPadding,
0,
descriptionFlags(),
m_descriptionText);
return m_descriptionRect.height();
}
示例12: fm
void TestResultDelegate::recalculateTextLayout(const QModelIndex &index, const QString &output,
const QFont &font, int width) const
{
if (m_lastProcessedIndex == index && m_lastProcessedFont == font)
return;
const QFontMetrics fm(font);
const int leading = fm.leading();
const int fontHeight = fm.height();
m_lastProcessedIndex = index;
m_lastProcessedFont = font;
m_lastCalculatedHeight = 0;
m_lastCalculatedLayout.clearLayout();
m_lastCalculatedLayout.setText(output);
m_lastCalculatedLayout.setFont(font);
QTextOption txtOption;
txtOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
m_lastCalculatedLayout.setTextOption(txtOption);
m_lastCalculatedLayout.beginLayout();
while (true) {
QTextLine line = m_lastCalculatedLayout.createLine();
if (!line.isValid())
break;
line.setLineWidth(width);
m_lastCalculatedHeight += leading;
line.setPosition(QPoint(0, m_lastCalculatedHeight));
m_lastCalculatedHeight += fontHeight;
}
m_lastCalculatedLayout.endLayout();
}
示例13: addLine
bool addLine(QTextLine &line) {
if (line.height() > 20)
m_y += line.height();
else
m_y += 14.4;
return false;
}
示例14: tr
void UserIcon::init(){
QString text = tr(user_->name().c_str());
layout_ = new QTextLayout(text,
d_->users_scene()->font());
QFontMetricsF fm(d_->users_scene()->font());
layout_->beginLayout();
QTextLine line = layout_->createLine();
//line.setNumColumns(1);
QSizeF text_size_ = fm.boundingRect(text).size();
// TODO: Figure out what these numbers are all about, why width/4, height/4
//line.setPosition(QPointF(s.width()/4.0,
// -s.height()/4.0));
line.setPosition(QPointF());
layout_->endLayout();
layout_->setCacheEnabled(true);
menu_ = new QMenu(tr(user_->name().c_str()));
show_on_map_ = new QAction(tr("Show on map"), this);
menu_->addAction(show_on_map_);
connect(show_on_map_, SIGNAL(triggered()),
this,
SLOT(activateLastNode()));
focus_on_ = new QAction(tr("Focus on"), this);
menu_->addAction(focus_on_);
connect(focus_on_, SIGNAL(triggered()),
this,
SLOT(focusOnLastNode()));
updateDrawRect();
}
示例15: POINT_TO_INCH
void KCRowHeader::drawText(QPainter& painter, const QFont& font,
const QPointF& location, const QString& text) const
{
register KCSheet * const sheet = m_pView->activeSheet();
if (!sheet)
return;
const double scaleX = POINT_TO_INCH(double(KoDpi::dpiX()));
const double scaleY = POINT_TO_INCH(double(KoDpi::dpiY()));
// Qt scales the font already with the logical resolution. Do not do it twice!
painter.save();
painter.scale(1.0 / scaleX, 1.0 / scaleY);
QTextLayout textLayout(text, font);
textLayout.beginLayout();
forever {
QTextLine line = textLayout.createLine();
if (!line.isValid())
break;
line.setLineWidth(width() * scaleX);
}
textLayout.endLayout();
QPointF loc(location.x() * scaleX, location.y() * scaleY);
textLayout.draw(&painter, loc);
painter.restore();
}