本文整理汇总了C++中QTextLayout::preeditAreaText方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextLayout::preeditAreaText方法的具体用法?C++ QTextLayout::preeditAreaText怎么用?C++ QTextLayout::preeditAreaText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextLayout
的用法示例。
在下文中一共展示了QTextLayout::preeditAreaText方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: anchorAt
/*!
\fn QString QAbstractTextDocumentLayout::anchorAt(const QPointF &position) const
Returns the reference of the anchor the given \a position, or an empty
string if no anchor exists at that point.
*/
QString QAbstractTextDocumentLayout::anchorAt(const QPointF& pos) const
{
int cursorPos = hitTest(pos, Qt::ExactHit);
if (cursorPos == -1)
return QString();
// compensate for preedit in the hit text block
QTextBlock block = document()->firstBlock();
while (block.isValid()) {
QRectF blockBr = blockBoundingRect(block);
if (blockBr.contains(pos)) {
QTextLayout *layout = block.layout();
int relativeCursorPos = cursorPos - block.position();
const int preeditLength = layout ? layout->preeditAreaText().length() : 0;
if (preeditLength > 0 && relativeCursorPos > layout->preeditAreaPosition())
cursorPos -= qMin(cursorPos - layout->preeditAreaPosition(), preeditLength);
break;
}
block = block.next();
}
QTextDocumentPrivate *pieceTable = qobject_cast<const QTextDocument *>(parent())->docHandle();
QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos);
QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format);
return fmt.anchorHref();
}
示例2: rectForCursorPosition
/*!
* Returns the rectangle for the cursor including the predictive text area.
* HbAbstractEditPrivate::ensurePositionVisible() uses the same algorithm.
*/
QRectF NmEditorTextEdit::rectForCursorPosition() const
{
NM_FUNCTION;
int cursorPos = cursorPosition();
QRectF rect = rectForPosition(cursorPos);
QTextDocument *doc = document();
if (doc) {
rect.adjust(0, -doc->documentMargin(), 0, doc->documentMargin());
const QTextBlock block = doc->findBlock(cursorPos);
QTextLayout *blockLayout = block.layout();
if (block.isValid() && blockLayout) {
if (blockLayout->preeditAreaText().length()) {
// Adjust cursor rect so that predictive text will be also visible
rect.adjust(0, 0, boundingRect().width() / 2, 0);
}
}
}
return rect;
}
示例3: applyFormatChanges
void QSyntaxHighlighterPrivate::applyFormatChanges()
{
QTextLayout *layout = currentBlock.layout();
QList<QTextLayout::FormatRange> ranges = layout->additionalFormats();
const int preeditAreaStart = layout->preeditAreaPosition();
const int preeditAreaLength = layout->preeditAreaText().length();
QList<QTextLayout::FormatRange>::Iterator it = ranges.begin();
while (it != ranges.end()) {
if (it->start >= preeditAreaStart
&& it->start + it->length <= preeditAreaStart + preeditAreaLength)
++it;
else
it = ranges.erase(it);
}
QTextCharFormat emptyFormat;
QTextLayout::FormatRange r;
r.start = r.length = -1;
int i = 0;
while (i < formatChanges.count()) {
while (i < formatChanges.count() && formatChanges.at(i) == emptyFormat)
++i;
if (i >= formatChanges.count())
break;
r.start = i;
r.format = formatChanges.at(i);
while (i < formatChanges.count() && formatChanges.at(i) == r.format)
++i;
if (i >= formatChanges.count())
break;
r.length = i - r.start;
if (r.start >= preeditAreaStart) {
r.start += preeditAreaLength;
} else if (r.start + r.length >= preeditAreaStart) {
r.length += preeditAreaLength;
}
ranges << r;
r.start = r.length = -1;
}
if (r.start != -1) {
r.length = formatChanges.count() - r.start;
if (r.start >= preeditAreaStart) {
r.start += preeditAreaLength;
} else if (r.start + r.length >= preeditAreaStart) {
r.length += preeditAreaLength;
}
ranges << r;
}
layout->setAdditionalFormats(ranges);
}
示例4: paintEvent
//.........这里部分代码省略.........
QAbstractTextDocumentLayout::PaintContext context = getPaintContext();
while (block.isValid()) {
QRectF r = blockBoundingRect(block).translated(offset);
QTextLayout *layout = block.layout();
if (!block.isVisible()) {
offset.ry() += r.height();
block = block.next();
continue;
}
if (r.bottom() >= er.top() && r.top() <= er.bottom()) {
QTextBlockFormat blockFormat = block.blockFormat();
QBrush bg = blockFormat.background();
if (bg != Qt::NoBrush) {
QRectF contentsRect = r;
contentsRect.setWidth(qMax(r.width(), maximumWidth));
fillBackground(&painter, contentsRect, bg);
}
QVector<QTextLayout::FormatRange> selections;
int blpos = block.position();
int bllen = block.length();
for (int i = 0; i < context.selections.size(); ++i) {
const QAbstractTextDocumentLayout::Selection &range = context.selections.at(i);
const int selStart = range.cursor.selectionStart() - blpos;
const int selEnd = range.cursor.selectionEnd() - blpos;
if (selStart < bllen && selEnd > 0
&& selEnd > selStart) {
QTextLayout::FormatRange o;
o.start = selStart;
o.length = selEnd - selStart;
o.format = range.format;
selections.append(o);
} else if (!range.cursor.hasSelection() && range.format.hasProperty(QTextFormat::FullWidthSelection)
&& block.contains(range.cursor.position())) {
// for full width selections we don't require an actual selection, just
// a position to specify the line. that's more convenience in usage.
QTextLayout::FormatRange o;
QTextLine l = layout->lineForTextPosition(range.cursor.position() - blpos);
o.start = l.textStart();
o.length = l.textLength();
if (o.start + o.length == bllen - 1)
++o.length; // include newline
o.format = range.format;
selections.append(o);
}
}
bool drawCursor = ((editable || (textInteractionFlags() & Qt::TextSelectableByKeyboard))
&& context.cursorPosition >= blpos
&& context.cursorPosition < blpos + bllen);
bool drawCursorAsBlock = drawCursor && overwriteMode() ;
if (drawCursorAsBlock) {
if (context.cursorPosition == blpos + bllen - 1) {
drawCursorAsBlock = false;
} else {
QTextLayout::FormatRange o;
o.start = context.cursorPosition - blpos;
o.length = 1;
o.format.setForeground(palette().base());
o.format.setBackground(palette().text());
selections.append(o);
}
}
layout->draw(&painter, offset, selections, er);
if ((drawCursor && !drawCursorAsBlock)
|| (editable && context.cursorPosition < -1
&& !layout->preeditAreaText().isEmpty())) {
int cpos = context.cursorPosition;
if (cpos < -1)
cpos = layout->preeditAreaPosition() - (cpos + 2);
else
cpos -= blpos;
layout->drawCursor(&painter, offset, cpos, cursorWidth());
}
}
offset.ry() += r.height();
if (offset.y() > viewportRect.height())
break;
block = block.next();
}
if (backgroundVisible() && !block.isValid() && offset.y() <= er.bottom()
&& (centerOnScroll() || verticalScrollBar()->maximum() == verticalScrollBar()->minimum())) {
painter.fillRect(QRect(QPoint((int)er.left(), (int)offset.y()), er.bottomRight()), palette().background());
}
}