本文整理汇总了C++中QTextCursor::insertFragment方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::insertFragment方法的具体用法?C++ QTextCursor::insertFragment怎么用?C++ QTextCursor::insertFragment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::insertFragment方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
/*!
* \class SplitCellCommand
* \author Anders Fernström
* \date 2006-04-26
*
* \brief Split the cell
*/
void SplitCellCommand::execute()
{
try
{
if( document()->getCursor()->currentCell() )
{
if( typeid( *document()->getCursor()->currentCell() ) == typeid( TextCell ) ||
typeid( *document()->getCursor()->currentCell() ) == typeid( InputCell ) )
{
// extraxt text
QTextEdit* editor = document()->getCursor()->currentCell()->textEdit();
if( editor )
{
QTextCursor cursor = editor->textCursor();
cursor.movePosition( QTextCursor::End, QTextCursor::KeepAnchor );
QTextDocumentFragment text = cursor.selection();
cursor.removeSelectedText();
// add new cell
if( typeid( *document()->getCursor()->currentCell() ) == typeid( TextCell ) )
{
AddCellCommand addcellCommand;
addcellCommand.setApplication( application() );
addcellCommand.setDocument( document() );
addcellCommand.execute();
}
else
{
// inputcell
CreateNewCellCommand newcellCommand( "Input" );
newcellCommand.setApplication( application() );
newcellCommand.setDocument( document() );
newcellCommand.execute();
}
// add text to new cell
QTextEdit* newEditor = document()->getCursor()->currentCell()->textEdit();
QTextCursor newCursor = newEditor->textCursor();
newCursor.insertFragment( text );
newCursor.movePosition( QTextCursor::Start );
newEditor->setTextCursor( newCursor );
// update document
document()->setChanged( true );
}
}
}
}
catch( exception &e )
{
string str = string("SplitCellCommand(), Exception: ") + e.what();
throw runtime_error( str.c_str() );
}
}
示例2: duplicate_line
/**
* Duplicates the current line and inserts the copy below the line
*/
void HaiQTextEdit::duplicate_line() {
QTextCursor cursor = textCursor();
int pos(cursor.position());
cursor.beginEditBlock();
cursor.clearSelection();
cursor.movePosition(QTextCursor::EndOfLine);
cursor.select(QTextCursor::LineUnderCursor);
QTextDocumentFragment text( cursor.selection() );
cursor.clearSelection();
cursor.insertText( QString(QChar::LineSeparator) );
cursor.insertFragment( text );
cursor.setPosition(pos);
cursor.endEditBlock();
}
示例3: QTextDocument
//.........这里部分代码省略.........
if(element.tagName() == "scene" && ui->setSceneTitlesComboBox->currentIndex() != 0){
QString sceneTitle;
switch (ui->setSceneTitlesComboBox->currentIndex()){
case 1:
sceneTitle = element.attribute("name", "");
break;
case 2:
sceneTitle = "###";
break;
case 3:
sceneTitle = "***";
break;
default:
sceneTitle = element.attribute("name", "");
break;
}
edit->append("<br>");
edit->append("<h3>" + sceneTitle + "</h3>");
tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
tCursor->mergeBlockFormat(blockFormatCenter);
edit->append("<br>");
}
if(ui->synopsisCheckBox->isChecked() && !synFrag.isEmpty()){
edit->append("<br>");
edit->append("<h4>" + tr("Synopsis") + "</h4>");
tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
tCursor->mergeBlockFormat(blockFormatCenter);
edit->append("<br>");
tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
tCursor->insertBlock(blockFormatLeft, charFormatLeft);
tCursor->insertFragment(synFrag);
}
if(ui->notesCheckBox->isChecked() && !noteFrag.isEmpty()){
edit->append("<br>");
edit->append("<h4>" + tr("Note") + "</h4>");
tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
tCursor->mergeBlockFormat(blockFormatCenter);
edit->append("<br>");
tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
tCursor->insertBlock(blockFormatLeft, charFormatLeft);
tCursor->insertFragment(noteFrag);
}
if(ui->storyCheckBox->isChecked()){
if((ui->synopsisCheckBox->isChecked() || ui->notesCheckBox->isChecked()) && !textFrag.isEmpty()){
tCursor->insertBlock();
tCursor->insertHtml("<h4>" + tr("Story") + "</h4>");
tCursor->mergeBlockFormat(blockFormatCenter);
tCursor->insertBlock();
}
tCursor->insertHtml("<br>");
// tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
tCursor->insertBlock(blockFormatLeft, charFormatLeft);
tCursor->insertFragment(textFrag);
// edit->append(textFrag->toHtml());
}
}
else if(element.tagName() == "separator"){
edit->append("<br>");
edit->append("<h3>#</h3>");
tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
tCursor->mergeBlockFormat(blockFormatCenter);
edit->append("<br>");
tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
tCursor->mergeBlockFormat(blockFormatLeft);
}
progressValue += 1;
progressBar->setValue(progressValue);
}
QRegExp reg("-qt-paragraph-type:.*;|margin-top:.*;|margin-bottom:.*;|margin-left:.*;|margin-right:.*;|-qt-block-indent:.*;|text-indent:.*;|font-family:.*;|font-size:.*;");
reg.setMinimal(true);
textDocument->setHtml(textDocument->toHtml().remove(reg));
//find and change final page css style :
//textDocument->setDefaultStyleSheet("p, li { white-space: pre-wrap; } p{line-height: 2em; font-family:'Liberation Serif'; font-size:14pt;margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:72px;}");
// <style type="text/css">
// p, li { white-space: pre-wrap; }
// </style>
// tCursor
// qDebug() << textDocument->toHtml();
progressWidget->close();
return textDocument;
}
示例4: pasteSelection
void MainWindow::pasteSelection()
{
QTextCursor cursor = editor->textCursor();
cursor.insertFragment(selection);
}