本文整理汇总了C++中QTextDocument::documentLayout方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::documentLayout方法的具体用法?C++ QTextDocument::documentLayout怎么用?C++ QTextDocument::documentLayout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::documentLayout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paint
void KPrPlaceholderTextStrategy::paint( QPainter & painter, const KoViewConverter &converter, const QRectF & rect, KoShapePaintingContext &paintcontext)
{
if ( m_textShape ) {
painter.save();
m_textShape->setSize( rect.size() );
// this code is needed to make sure the text of the textshape is layouted before it is painted
KoTextShapeData * shapeData = qobject_cast<KoTextShapeData*>( m_textShape->userData() );
QTextDocument * document = shapeData->document();
KoTextDocumentLayout * lay = qobject_cast<KoTextDocumentLayout*>( document->documentLayout() );
if ( lay ) {
lay->layout();
}
m_textShape->paint( painter, converter, paintcontext);
KoShape::applyConversion( painter, converter );
QPen pen(Qt::gray, 0);
//pen.setStyle( Qt::DashLine ); // endless loop
painter.setPen( pen );
painter.drawRect( rect );
painter.restore();
}
else {
KPrPlaceholderStrategy::paint( painter, converter, rect, paintcontext);
}
}
示例2: paint
void MessageViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItemV4 optionV4 = option;
initStyleOption(&optionV4, index);
QStyle *style = optionV4.widget? optionV4.widget->style() : QApplication::style();
QTextDocument doc;
QString align(index.data(MessageModel::TypeRole) == 1 ? "left" : "right");
QString html = "<p align=\"" + align + "\" style=\"color:black;\">" + index.data(MessageModel::HTMLRole).toString() + "</p>";
doc.setHtml(html);
/// Painting item without text
optionV4.text = QString();
style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);
QAbstractTextDocumentLayout::PaintContext ctx;
// Highlighting text if item is selected
if (optionV4.state & QStyle::State_Selected)
ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText));
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4);
doc.setTextWidth( textRect.width() );
painter->save();
painter->translate(textRect.topLeft());
painter->setClipRect(textRect.translated(-textRect.topLeft()));
doc.documentLayout()->draw(painter, ctx);
painter->restore();
}
示例3: drawSimpleRichText
/*!
Draw a text document into a rectangle
\param painter Painter
\param rect Traget rectangle
\param flags Alignments/Text flags, see QPainter::drawText()
\param text Text document
*/
void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect,
int flags, const QTextDocument &text )
{
QTextDocument *txt = text.clone();
painter->save();
painter->setFont( txt->defaultFont() );
qwtUnscaleFont( painter );
txt->setDefaultFont( painter->font() );
txt->setPageSize( QSizeF( rect.width(), QWIDGETSIZE_MAX ) );
QAbstractTextDocumentLayout* layout = txt->documentLayout();
const double height = layout->documentSize().height();
double y = rect.y();
if ( flags & Qt::AlignBottom )
y += ( rect.height() - height );
else if ( flags & Qt::AlignVCenter )
y += ( rect.height() - height ) / 2;
QAbstractTextDocumentLayout::PaintContext context;
context.palette.setColor( QPalette::Text, painter->pen().color() );
painter->translate( rect.x(), y );
layout->draw( painter, context );
painter->restore();
delete txt;
}
示例4: initStyleOption
void
SqlSearchDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QStyleOptionViewItemV4 optionV4 = option;
initStyleOption(&optionV4, index);
QStyle *style = optionV4.widget? optionV4.widget->style() : QApplication::style();
QTextDocument doc;
doc.setHtml(optionV4.text);
optionV4.text = QString();
style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);
QAbstractTextDocumentLayout::PaintContext ctx;
QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
(option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive : QPalette::Disabled;
if (optionV4.state & QStyle::State_Selected)
ctx.palette.setColor(QPalette::Text, optionV4.palette.color(cg, QPalette::HighlightedText));
else
ctx.palette.setColor(QPalette::Text, optionV4.palette.color(cg, QPalette::WindowText));
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4);
painter->save();
painter->translate(textRect.topLeft());
painter->setClipRect(textRect.translated(-textRect.topLeft()));
doc.documentLayout()->draw(painter, ctx);
painter->restore();
}
示例5: testPrefixMerge
void TestChangeTrackedDelete::testPrefixMerge()
{
TextTool *textTool = new TextTool(new MockCanvas);
KoTextEditor *textEditor = textTool->textEditor();
QVERIFY(textEditor);
QTextDocument *document = textEditor->document();
KTextDocumentLayout *layout = qobject_cast<KTextDocumentLayout*>(document->documentLayout());
QTextCursor *cursor = textEditor->cursor();
cursor->insertText("Hello World");
cursor->setPosition(3);
ChangeTrackedDeleteCommand *delCommand = new ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, textTool);
textEditor->addCommand(delCommand);
QCOMPARE(document->characterAt(3).unicode(), (ushort)(QChar::ObjectReplacementCharacter));
cursor->setPosition(4);
delCommand = new ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, textTool);
textEditor->addCommand(delCommand);
// This is wierd. Without this loop present the succeeding call to inlineTextObject returs NULL. Why ??????
for (int i=0; i<document->characterCount(); i++) {
cursor->setPosition(i);
}
cursor->setPosition(4);
KDeleteChangeMarker *testMarker = dynamic_cast<KDeleteChangeMarker*>(layout->inlineTextObjectManager()->inlineTextObject(*cursor));
QTextDocumentFragment deleteData = KTextDocument(document).changeTracker()->elementById(testMarker->changeId())->deleteData();
QCOMPARE(deleteData.toPlainText(), QString("lo"));
delete textTool;
}
示例6:
QAbstractTextDocumentLayout *QTextDocumentProto::documentLayout() const
{
QTextDocument *item = qscriptvalue_cast<QTextDocument*>(thisObject());
if (item)
return item->documentLayout();
return 0;
}
示例7: drawSimpleRichText
void QwtPainter::drawSimpleRichText(QPainter *painter, const QRect &rect,
int flags, QTextDocument &text)
{
const QRect scaledRect = d_metricsMap.layoutToDevice(rect, painter);
text.setPageSize(QSize(scaledRect.width(), QWIDGETSIZE_MAX));
QAbstractTextDocumentLayout* layout = text.documentLayout();
const int height = qRound(layout->documentSize().height());
int y = scaledRect.y();
if (flags & Qt::AlignBottom)
y += (scaledRect.height() - height);
else if (flags & Qt::AlignVCenter)
y += (scaledRect.height() - height)/2;
QAbstractTextDocumentLayout::PaintContext context;
context.palette.setColor(QPalette::Text, painter->pen().color());
painter->save();
painter->translate(scaledRect.x(), y);
layout->draw(painter, context);
painter->restore();
}
示例8: paint
void HtmlDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,const QModelIndex &index) const
{
QStyleOptionViewItemV4 optionV4(option);
initStyleOption(&optionV4, index);
QStyle *style = optionV4.widget ? optionV4.widget->style() : QApplication::style();
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &optionV4, painter, optionV4.widget);
QTextDocument doc;
QString text = optionV4.text;
doc.setHtml(text);
doc.setPageSize( option.rect.size() );
/// Painting item without text
optionV4.text.clear();
style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);
QAbstractTextDocumentLayout::PaintContext ctx;
// Highlighting text if item is selected
if (optionV4.state & QStyle::State_Selected)
ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText));
QRect textRect = option.rect;
painter->save();
painter->translate(textRect.topLeft());
painter->setClipRect(textRect.translated(-textRect.topLeft()));
doc.documentLayout()->draw(painter, ctx);
painter->restore();
}
示例9: heightForWidth
//-----------------------------------------------------------------------------
int ctkFittedTextBrowser::heightForWidth(int _width) const
{
QTextDocument* doc = this->document();
qreal savedWidth = doc->textWidth();
// Fudge factor. This is the difference between the frame and the
// viewport.
int fudge = 2 * this->frameWidth();
// Do the calculation assuming no scrollbars
doc->setTextWidth(_width - fudge);
int noScrollbarHeight =
doc->documentLayout()->documentSize().height() + fudge;
// (If noScrollbarHeight is greater than the maximum height we'll be
// allowed, then there will be scrollbars, and the actual required
// height will be even higher. But since in this case we've already
// hit the maximum height, it doesn't matter that we underestimate.)
// Get minimum height (even if string is empty): one line of text
int _minimumHeight = QFontMetrics(doc->defaultFont()).lineSpacing() + fudge;
int ret = qMax(noScrollbarHeight, _minimumHeight);
doc->setTextWidth(savedWidth);
return ret;
}
示例10: testTabsUsed
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());
}
示例11: sizeHint
QSize KviTalIconAndRichTextItemDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QString szText = index.data(Qt::DisplayRole).toString();
QTextDocument doc;
doc.setHtml(szText);
doc.setDefaultFont(option.font);
doc.setTextWidth(((QListWidget *)parent())->viewport()->width() - LVI_AFTER_ICON - LVI_BORDER);
int iHeight = doc.documentLayout()->documentSize().toSize().height();
//qDebug("Size hint (%d,%d)",((QListWidget *)parent())->minimumWidth(), iHeight + (2 * LVI_BORDER));
int iIconWidth = m_oIconSize.width() + (2 * LVI_BORDER);
int iIconHeight = m_oIconSize.height() + (2 * LVI_BORDER);
int w = ((QListWidget *)parent())->minimumWidth();
if(w < iIconWidth)
w = iIconWidth;
if(w < m_oMinimumSize.width())
w = m_oMinimumSize.width();
int h = iHeight + (2 * LVI_BORDER);
if(h < iIconHeight)
h = iIconHeight;
if(h < m_oMinimumSize.height())
h = m_oMinimumSize.height();
return { w, h };
}
示例12: paint
void ChannelsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt,
const QModelIndex &index) const
{
QVariant data = index.data();
if (data.canConvert<QTextDocument *>()) {
QTextDocument *textDocument = data.value<QTextDocument *>();
QStyleOptionViewItemV4 option(opt);
QStyle *style = option.widget ? option.widget->style() : QApplication::style();
painter->save();
// Draw background.
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, option.widget);
// Draw text using QTextDocument.
int pad = 1;
QRect textRect = option.rect.adjusted(pad, pad, -pad, -pad);
QRect clipRect(0, 0, textRect.width(), textRect.height());
painter->translate(textRect.x(), textRect.y());
painter->setClipRect(clipRect);
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette = option.palette;
ctx.clip = QRect(clipRect);
textDocument->documentLayout()->draw(painter, ctx);
painter->restore();
} else {
QStyledItemDelegate::paint(painter, opt, index);
}
}
示例13: allTextVisible
void ExpandingLabel::allTextVisible() {
QTextDocument *doc = document();
doc->setTextWidth(width());
int height = doc->documentLayout()->documentSize().toSize().height();
setStyleSheet("border: 0px; background-color: transparent; margin-top: 0px; margin-bottom: 0px;");
setFixedHeight(height);
}
示例14: paint
void EventItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
painter->save();
QStyleOptionViewItemV4 opt = option;
initStyleOption(&opt, index);
QVariant value = index.data();
QBrush bgBrush = qvariant_cast<QBrush>(index.data(Qt::BackgroundRole));
QBrush fgBrush = qvariant_cast<QBrush>(index.data(Qt::ForegroundRole));
painter->setClipRect( opt.rect );
painter->setBackgroundMode(Qt::OpaqueMode);
painter->setBackground(Qt::transparent);
painter->setBrush(bgBrush);
if (bgBrush.style() != Qt::NoBrush) {
QPen bgPen;
bgPen.setColor(bgBrush.color().darker(250));
bgPen.setStyle(Qt::SolidLine);
bgPen.setWidth(1);
painter->setPen(bgPen);
painter->drawRoundedRect(opt.rect.x(), opt.rect.y(), opt.rect.width() - bgPen.width(), opt.rect.height() - bgPen.width(), 3.0, 3.0);
}
QTextDocument doc;
doc.setDocumentMargin(3);
doc.setDefaultStyleSheet("* {color: " + fgBrush.color().name() + ";}");
doc.setHtml("<html><qt></head><meta name=\"qrichtext\" content=\"1\" />" + displayText(value, QLocale::system()) + "</qt></html>");
QAbstractTextDocumentLayout::PaintContext context;
doc.setPageSize( opt.rect.size());
painter->translate(opt.rect.x(), opt.rect.y());
doc.documentLayout()->draw(painter, context);
painter->restore();
}
示例15: paint
void HTMLDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const
{
QStyleOptionViewItemV4 options = option;
initStyleOption(&options, index);
painter->save();
QTextDocument doc;
doc.setHtml(options.text);
options.text = "";
options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);
// 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());
//doc.drawContents(painter, clip);
painter->setClipRect(clip);
QAbstractTextDocumentLayout::PaintContext ctx;
// set text color to red for selected item
if (option.state & QStyle::State_Selected)
ctx.palette.setColor(QPalette::Text, QColor("red"));
ctx.clip = clip;
doc.documentLayout()->draw(painter, ctx);
painter->restore();
}