本文整理汇总了C++中QTextCursor::insertBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::insertBlock方法的具体用法?C++ QTextCursor::insertBlock怎么用?C++ QTextCursor::insertBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::insertBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertFromMimeData
void ScCodeEditor::insertFromMimeData ( const QMimeData * data )
{
if (data->hasUrls()) {
QTextCursor cursor = textCursor();
QList<QUrl> urls = data->urls();
bool multiple = urls.size() > 1;
if (multiple) {
cursor.insertText("[");
cursor.insertBlock();
}
for (int i = 0; i < urls.size(); ++ i) {
QUrl url = urls[i];
cursor.insertText("\"");
if ( QURL_IS_LOCAL_FILE(url) )
cursor.insertText(url.toLocalFile());
else
cursor.insertText(url.toString());
cursor.insertText("\"");
if (i < urls.size() - 1) {
cursor.insertText(",");
cursor.insertBlock();
}
}
if (multiple) {
cursor.insertBlock();
cursor.insertText("]");
}
}
else
QPlainTextEdit::insertFromMimeData(data);
}
示例2: moveLineUpDown
void GenericCodeEditor::moveLineUpDown(bool up)
{
// directly taken from qtcreator
// Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
// GNU Lesser General Public License
QTextCursor cursor = textCursor();
QTextCursor move = cursor;
move.setVisualNavigation(false); // this opens folded items instead of destroying them
move.beginEditBlock();
bool hasSelection = cursor.hasSelection();
if (cursor.hasSelection()) {
move.setPosition(cursor.selectionStart());
move.movePosition(QTextCursor::StartOfBlock);
move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor);
move.movePosition(move.atBlockStart() ? QTextCursor::Left: QTextCursor::EndOfBlock,
QTextCursor::KeepAnchor);
} else {
move.movePosition(QTextCursor::StartOfBlock);
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
}
QString text = move.selectedText();
move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
move.removeSelectedText();
if (up) {
move.movePosition(QTextCursor::PreviousBlock);
move.insertBlock();
move.movePosition(QTextCursor::Left);
} else {
move.movePosition(QTextCursor::EndOfBlock);
if (move.atBlockStart()) { // empty block
move.movePosition(QTextCursor::NextBlock);
move.insertBlock();
move.movePosition(QTextCursor::Left);
} else {
move.insertBlock();
}
}
int start = move.position();
move.clearSelection();
move.insertText(text);
int end = move.position();
if (hasSelection) {
move.setPosition(start);
move.setPosition(end, QTextCursor::KeepAnchor);
}
move.endEditBlock();
setTextCursor(move);
}
示例3: copyUpDown
void GenericCodeEditor::copyUpDown(bool up)
{
// directly taken from qtcreator
// Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
// GNU Lesser General Public License
QTextCursor cursor = textCursor();
QTextCursor move = cursor;
move.beginEditBlock();
bool hasSelection = cursor.hasSelection();
if (hasSelection) {
move.setPosition(cursor.selectionStart());
move.movePosition(QTextCursor::StartOfBlock);
move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor);
move.movePosition(move.atBlockStart() ? QTextCursor::Left: QTextCursor::EndOfBlock,
QTextCursor::KeepAnchor);
} else {
move.movePosition(QTextCursor::StartOfBlock);
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
}
QString text = move.selectedText();
if (up) {
move.setPosition(cursor.selectionStart());
move.movePosition(QTextCursor::StartOfBlock);
move.insertBlock();
move.movePosition(QTextCursor::Left);
} else {
move.movePosition(QTextCursor::EndOfBlock);
if (move.atBlockStart()) {
move.movePosition(QTextCursor::NextBlock);
move.insertBlock();
move.movePosition(QTextCursor::Left);
} else {
move.insertBlock();
}
}
int start = move.position();
move.clearSelection();
move.insertText(text);
int end = move.position();
move.setPosition(start);
move.setPosition(end, QTextCursor::KeepAnchor);
move.endEditBlock();
setTextCursor(move);
}
示例4: addParagraph
void MainWindow::addParagraph(const QString ¶graph){
if (paragraph.isEmpty())
return;
QTextDocument *document = chatbox->document();
QTextCursor cursor = document->find(tr("Yours sincerely,"));
if (cursor.isNull())
return;
cursor.beginEditBlock();
cursor.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor, 2);
cursor.insertBlock();
cursor.insertText(paragraph);
cursor.insertBlock();
cursor.endEditBlock();
}
示例5: BuildContactsSection
// 3) CONTACTS
void ResWaReport::BuildContactsSection(QTextCursor& cursor)
{
cursor.movePosition(QTextCursor::End);
cursor.insertBlock();
cursor.insertText("\n\n3) Contacts (proactive outreach events\n", _headerFormat);
cursor.insertText("!! This information is not available !!\n", _headerFormat);
}
示例6: BuildTrainingSection
// 4) TRAINING
void ResWaReport::BuildTrainingSection(QTextCursor& cursor)
{
cursor.movePosition(QTextCursor::End);
cursor.insertBlock();
cursor.insertText("\n\n4) TRAINING & IN-SERVICES\n");
// VALUES
int numTrainings;
int numAttendingTrainings;
CalculateTraining(numTrainings, numAttendingTrainings);
// cursor.insertText("\t\t\t# of trainings: " + QString::number(numTrainings) + "\n");
// cursor.insertText("\t\t\t# attending trainings: " + QString::number(numAttendingTrainings) + "\n");
QTextTableFormat tableFormat;
tableFormat.setHeaderRowCount(1);
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 35);
constraints << QTextLength(QTextLength::PercentageLength, 35);
tableFormat.setColumnWidthConstraints(constraints);
QTextTable *table = cursor.insertTable(2, 2, tableFormat);
// HEADERS
TextToCell(table, 0, 0, "# of trainings (observers)", &_tableTextFormat);
TextToCell(table, 0, 1, "# attending trainings (all people in room)", &_tableTextFormat);
// VALUES
TextToCell(table, 1, 0, QString::number(numTrainings), &_tableCellBlue);
TextToCell(table, 1, 1, QString::number(numAttendingTrainings), &_tableCellBlue);
}
示例7: addProgressText
void ZModemDialog::addProgressText(const QString& text)
{
QTextCursor cursor = _textEdit->textCursor();
cursor.insertBlock();
cursor.insertText(text);
}
示例8: BuildHeaderSection
void MediationProcess::BuildHeaderSection(QTextCursor& cursor)
{
cursor.movePosition(QTextCursor::End);
cursor.insertBlock(); // Is this necessary?
cursor.insertText("\nMediation\n", _headerFormat);
cursor.insertText("Inquiry, Mediation and Session types and statuses\n", _tableTextFormat);
}
示例9: slotPasteAsQuotation
void ComposerTextEdit::slotPasteAsQuotation()
{
QString text = qApp->clipboard()->text();
if (text.isEmpty())
return;
QStringList lines = text.split(QLatin1Char('\n'));
for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it) {
it->remove(QLatin1Char('\r'));
if (it->startsWith(QLatin1Char('>'))) {
*it = QLatin1Char('>') + *it;
} else {
*it = QLatin1String("> ") + *it;
}
}
text = lines.join(QStringLiteral("\n"));
if (!text.endsWith(QLatin1Char('\n'))) {
text += QLatin1Char('\n');
}
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
cursor.insertBlock();
cursor.insertText(text);
cursor.endEditBlock();
setTextCursor(cursor);
}
示例10: exp
QTextList *tryReadList(QTextList *list, const QString &line)
{
QTextList *listOut = list;
QRegularExpression exp("^( *)(\\d+\\.|\\*) (.*)$");
QRegularExpressionMatch match = exp.match(line);
if (match.hasMatch())
{
const int indent = match.captured(1).size() / 2 + 1;
const QString contents = match.captured(3);
const bool ordered = match.captured(2) != "*";
QTextListFormat fmt;
fmt.setStyle(ordered ? QTextListFormat::ListDecimal : QTextListFormat::ListDisc);
fmt.setIndent(indent);
if (!listOut || fmt != listOut->format())
{
listOut = cursor.insertList(fmt);
}
else
{
cursor.insertBlock();
}
readInlineText(contents);
listOut->add(cursor.block());
return listOut;
}
else
{
return 0;
}
}
示例11: _insertPrompt
void TabTerminal::_insertPrompt()
{
QTextCursor cursor = textCursor();
cursor.insertBlock();
insertHtml(_userPrompt);
ensureCursorVisible();
}
示例12: setTextFont
// 设置字体格式
void MainWindow::setTextFont(bool checked)
{
// 如果处于选中状态
if(checked){
QTextCursor cursor = ui->textEdit->textCursor();
// 文本块格式
QTextBlockFormat blockFormat;
// 水平居中
blockFormat.setAlignment(Qt::AlignCenter);
// 使用文本块格式
cursor.insertBlock(blockFormat);
// 字符格式
QTextCharFormat charFormat;
// 背景色
charFormat.setBackground(Qt::lightGray);
// 字体颜色
charFormat.setForeground(Qt::blue);
// 使用宋体,12号,加粗,倾斜
charFormat.setFont(QFont(tr("宋体"),12,QFont::Bold,true));
// 使用下划线
charFormat.setFontUnderline(true);
// 使用字符格式
cursor.setCharFormat(charFormat);
// 插入文本
cursor.insertText(tr("测试字体"));
}
// 如果处于非选中状态,可以进行其他操作
else{/*恢复默认的字体格式*/}
}
示例13: 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;
}
示例14: textCursor
// Flush the message history by flushing all current events
void
WChatLog::ChatLog_EventsRemoveAll()
{
clear();
QTextCursor oTextCursor = textCursor();
oTextCursor.insertBlock();
m_oTextBlockComposing = oTextCursor.block();
}
示例15: beginNewLine
QTextCursor IrcChatBuffer::beginNewLine()
{
QTextCursor cur (this->document());
cur.movePosition(QTextCursor::End);
cur.insertBlock();
return cur;
}