本文整理汇总了C++中QTextCursor::charFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::charFormat方法的具体用法?C++ QTextCursor::charFormat怎么用?C++ QTextCursor::charFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::charFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fillInLinks
void KoPointedAt::fillInLinks(const QTextCursor &cursor, KoInlineTextObjectManager *inlineManager, KoTextRangeManager *rangeManager)
{
bookmark = 0;
externalHRef.clear();
note = 0;
if (!inlineManager)
return;
// Is there an href here ?
if (cursor.charFormat().isAnchor()) {
QString href = cursor.charFormat().anchorHref();
// local href starts with #
if (href.startsWith("#")) {
// however bookmark does not contain it, so strip it
href = href.right(href.size() - 1);
if (!href.isEmpty()) {
bookmark = rangeManager->bookmarkManager()->bookmark(href);
}
return;
} else {
// Nope, then it must be external;
externalHRef = href;
}
} else {
note = dynamic_cast<KoInlineNote*>(inlineManager->inlineTextObject(cursor));
}
}
示例2: updateCustomTextColor
/*!
This slot applies custom text color for user - entered text
It does not affect the text originally inserted into editor
*/
void NmEditorTextEdit::updateCustomTextColor()
{
NM_FUNCTION;
if (mCustomTextColor.first) {
QTextCursor tcursor = textCursor();
QTextCharFormat fmt;
int pos = tcursor.position();
if (pos > 0) {
// If there isn't any user-made selection - apply custom color
if (!tcursor.hasSelection() && !tcursor.hasComplexSelection()) {
// Select last added char and set its color to custom
if (tcursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor, 1)
&& tcursor.hasSelection()) {
fmt = tcursor.charFormat();
fmt.setForeground(mCustomTextColor.second);
tcursor.mergeCharFormat(fmt);
}
}
}
else {
fmt = tcursor.charFormat();
fmt.setForeground(mCustomTextColor.second);
tcursor.mergeCharFormat(fmt);
setTextCursor(tcursor);
}
}
}
示例3: textEditToPlainText
QString ChatEdit::textEditToPlainText()
{
QTextDocument *doc = document();
QString result;
result.reserve(doc->characterCount());
QTextCursor begin(doc);
QTextCursor end;
QString specialChar = QChar(QChar::ObjectReplacementCharacter);
bool first = true;
while (!begin.atEnd()) {
end = doc->find(specialChar, begin, QTextDocument::FindCaseSensitively);
QString postValue;
bool atEnd = end.isNull();
if (atEnd) {
end = QTextCursor(doc);
QTextBlock block = doc->lastBlock();
end.setPosition(block.position() + block.length() - 1);
} else {
postValue = end.charFormat().toolTip();
}
begin.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,
end.position() - begin.position() - (atEnd ? 0 : 1));
QString selectionText = begin.selection().toPlainText();
if (!first)
result += selectionText.midRef(1);
else
result += selectionText;
result += postValue;
begin = end;
end.clearSelection();
first = false;
}
return result;
}
示例4: textCursor
void
FormText::clearFormat()
{
QTextCursor c = textCursor();
if( c.hasSelection() )
{
QTextCharFormat fmt = c.charFormat();
fmt.setFontUnderline( false );
fmt.setFontItalic( false );
fmt.setFontWeight( QFont::Normal );
fmt.setFontPointSize( 10 );
textCursor().setCharFormat( fmt );
}
else
{
QFont f = font();
f.setUnderline( false );
f.setItalic( false );
f.setWeight( QFont::Normal );
f.setPointSize( 10.0 );
setFont( f );
}
QRectF r = boundingRect();
r.moveTo( pos() );
d->m_proxy->setRect( r );
}
示例5: attach
void KoTextInlineRdf::attach(KoTextInlineRdf *inlineRdf, QTextCursor &cursor)
{
QTextCharFormat format = cursor.charFormat();
QVariant v = QVariant::fromValue(inlineRdf);
format.setProperty(KoCharacterStyle::InlineRdf, v);
cursor.mergeCharFormat(format);
}
示例6: edit
text_writer( docEdit& e ) : edit( e ) {
QTextCursor cursor = edit.textCursor();
cursor.movePosition( QTextCursor::Start );
mainFrame = cursor.currentFrame();
plainFormat = cursor.charFormat();
plainFormat.setFontPointSize( 10 );
paragraphFormat = plainFormat;
paragraphFormat.setFontPointSize( 12 );
headingFormat = plainFormat;
headingFormat.setFontWeight( QFont::Bold );
headingFormat.setFontPointSize( 16 );
empasisFormat = plainFormat;
empasisFormat.setFontItalic( true );
tagFormat = plainFormat;
tagFormat.setForeground( QColor( "#990000" ) );
tagFormat.setFontUnderline( true );
underlineFormat = plainFormat;
underlineFormat.setFontUnderline( true );
frameFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Inset );
frameFormat.setBorder( 1 );
frameFormat.setMargin( 10 );
frameFormat.setPadding( 4 );
}
示例7: toggleItalicText
void ItemEditorWidget::toggleItalicText()
{
QTextCursor tc = textCursor();
QTextCharFormat format = tc.charFormat();
format.setFontItalic( !format.fontItalic() );
tc.setCharFormat(format);
}
示例8: formatError
QT_BEGIN_NAMESPACE
static void formatError(const QFormScriptRunner::Error &error,
QTextCursor &cursor)
{
const QTextCharFormat oldFormat = cursor.charFormat();
// Message
cursor.insertText(QCoreApplication::translate("ScriptErrorDialog", "An error occurred while running the scripts for \"%1\":\n").arg(error.objectName));
QTextCharFormat format(oldFormat);
// verbatim listing
format.setFontFamily(QLatin1String("Courier"));
cursor.insertText(error.script, format);
const QString newLine(QLatin1Char('\n'));
cursor.insertText(newLine);
// red error
format = oldFormat;
format.setTextOutline(QPen(Qt::red));
cursor.insertText(error.errorMessage, format);
cursor.insertText(newLine);
cursor.setCharFormat (oldFormat);
}
示例9: caretOwner
QString CaretInterface::caretOwner(const QTextCursor& cursor)
{
QTextCharFormat fmt = cursor.charFormat();
if ( fmt.objectType() == CaretFormat )
return fmt.property(Owner).toString();
return QString::null;
}
示例10: appendMessageToCurrentSession
/*! Append a new message to the current session and scroll to the end of the message protocol and
returns true if the action was successful. The \a messageColor defines the color of the message
box and should be provided as a full-color (no dimming required) color, as it is automatically
adjusted for the border and background.
*/
bool QwcPrivateMessager::appendMessageToCurrentSession(QTextDocument *document, const QString message, const QColor messageColor)
{
if (!document) { return false; }
QTextCursor cursor = document->rootFrame()->lastCursorPosition();
cursor.movePosition(QTextCursor::StartOfBlock);
QTextFrameFormat frameFormat;
frameFormat.setPadding(4);
frameFormat.setBackground(messageColor.lighter(190));
frameFormat.setMargin(0);
frameFormat.setBorder(2);
frameFormat.setBorderBrush(messageColor.lighter(150));
frameFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Outset);
// Title
QTextCharFormat backupCharFormat = cursor.charFormat();
QTextCharFormat newCharFormat;
newCharFormat.setFontPointSize(9);
QTextBlockFormat headerFormat;
headerFormat.setAlignment(Qt::AlignHCenter);
cursor.insertBlock(headerFormat);
cursor.setCharFormat(newCharFormat);
cursor.insertText(QDateTime::currentDateTime().toString());
QTextFrame *frame = cursor.insertFrame(frameFormat);
cursor.setCharFormat(backupCharFormat);
frame->firstCursorPosition().insertText(message);
return true;
}
示例11: cursorPositionChangedSlot
void TextZone::cursorPositionChangedSlot()
{
if (QApplication::mouseButtons() == Qt::NoButton) {
centerCursor();
}
emit cursorPositionChanged(this->textCursor().position());
// for textstyle :
QTextCursor tCursor = this->textCursor();
if((tCursor.atStart() == true
|| tCursor.position() == 1
|| tCursor.position() == 0) && tCursor.hasSelection() == false){
this->changeTextStyleSlot(textStyles->defaultStyleIndex());
}
int currentStyleIndex = textStyles->compareStylesWithText(tCursor.charFormat(), tCursor.blockFormat());
emit setStyleSelectionSignal(currentStyleIndex);
}
示例12: toggleUnderlineText
void ItemEditorWidget::toggleUnderlineText()
{
QTextCursor tc = textCursor();
QTextCharFormat format = tc.charFormat();
format.setFontUnderline( !format.fontUnderline() );
tc.setCharFormat(format);
}
示例13: toggleStrikethroughText
void ItemEditorWidget::toggleStrikethroughText()
{
QTextCursor tc = textCursor();
QTextCharFormat format = tc.charFormat();
format.setFontStrikeOut( !format.fontStrikeOut() );
tc.setCharFormat(format);
}
示例14: fontFamily
QString DocumentHandler::fontFamily() const
{
QTextCursor cursor = textCursor();
if (cursor.isNull())
return QString();
QTextCharFormat format = cursor.charFormat();
return format.font().family();
}
示例15: textColor
QColor DocumentHandler::textColor() const
{
QTextCursor cursor = textCursor();
if (cursor.isNull())
return QColor(Qt::black);
QTextCharFormat format = cursor.charFormat();
return format.foreground().color();
}