本文整理汇总了C++中QTextEdit::document方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextEdit::document方法的具体用法?C++ QTextEdit::document怎么用?C++ QTextEdit::document使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextEdit
的用法示例。
在下文中一共展示了QTextEdit::document方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find
void FindDialog::find(bool backwards)
{
QString text = m_find_string->text();
if (text.isEmpty()) {
return;
}
QTextDocument::FindFlags flags;
if (!m_ignore_case->isChecked()) {
flags |= QTextDocument::FindCaseSensitively;
}
if (m_whole_words->isChecked()) {
flags |= QTextDocument::FindWholeWords;
}
if (backwards) {
flags |= QTextDocument::FindBackward;
}
QTextEdit* document = m_documents->currentDocument()->text();
QTextCursor cursor = document->document()->find(text, document->textCursor(), flags);
if (cursor.isNull()) {
cursor = document->textCursor();
cursor.movePosition(!backwards ? QTextCursor::Start : QTextCursor::End);
cursor = document->document()->find(text, cursor, flags);
}
if (!cursor.isNull()) {
document->setTextCursor(cursor);
} else {
QMessageBox::information(this, tr("Sorry"), tr("Phrase not found."));
}
}
示例2: initTextEditor
void MainWindow::initTextEditor()
{
//create tab
QWidget *tab = new QWidget(this);
QString objName = QString("tab"),
fileName = "";
tab->setObjectName(objName);
//create layout
QHBoxLayout *layout = new QHBoxLayout(tab);
layout->setSpacing(0);
layout->setContentsMargins(11, 11, 11, 11);
layout->setObjectName(QString("horizontalLayout"));
layout->setContentsMargins(0, 0, 0, 0);
//create textedit
QTextEdit *edit = new QTextEdit(tab);
edit->setObjectName(QString("textEdit"));
layout->addWidget(edit);
ui->tabs->addWidget(tab);
//slot and signal
//font change signal
connect(edit, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
this, SLOT(currentCharFormatChanged(QTextCharFormat)));
connect(edit, SIGNAL(cursorPositionChanged()),
this, SLOT(cursorPositionChanged()));
//modification
connect(edit->document(), SIGNAL(modificationChanged(bool)),
ui->actionSave, SLOT(setEnabled(bool)));
connect(edit->document(), SIGNAL(modificationChanged(bool)),
this, SLOT(setWindowModified(bool)));
connect(edit->document(), SIGNAL(undoAvailable(bool)),
ui->actionUndo, SLOT(setEnabled(bool)));
connect(edit->document(), SIGNAL(redoAvailable(bool)),
ui->actionRedo, SLOT(setEnabled(bool)));
//redo undo
connect(ui->actionUndo, SIGNAL(triggered()), edit, SLOT(undo()));
connect(ui->actionRedo, SIGNAL(triggered()), edit, SLOT(redo()));
//cut copy paste
connect(ui->actionCut, SIGNAL(triggered()), edit, SLOT(cut()));
connect(ui->actionCopy, SIGNAL(triggered()), edit, SLOT(copy()));
connect(ui->actionPaste, SIGNAL(triggered()), edit, SLOT(paste()));
connect(edit, SIGNAL(copyAvailable(bool)), ui->actionCut, SLOT(setEnabled(bool)));
connect(edit, SIGNAL(copyAvailable(bool)), ui->actionCopy, SLOT(setEnabled(bool)));
textEditor.tab = tab;
textEditor.editor = edit;
textEditor.layout = layout;
textEditor.objName = objName;
textEditor.fileName = fileName;
}
示例3:
QTextDocument *QTextEditProto::document() const
{
QTextEdit *item = qscriptvalue_cast<QTextEdit*>(thisObject());
if (DEBUG) qDebug("QTextEditProto::document() item = %p", item);
if (item)
{
if (DEBUG) qDebug("QTextEditProto::document() item->document() = %p", item->document());
return item->document();
}
return 0;
}
示例4: fileSave
bool MainWindow::fileSave()
{
QTextEdit *pEdit = textEditor.editor;
QString fileName = textEditor.fileName;
if (fileName.isEmpty())
return fileSaveAs();
QTextDocumentWriter writer(fileName);
bool success = writer.write(pEdit->document());
if (success)
pEdit->document()->setModified(false);
return success;
}
示例5: replaceAll
void FindDialog::replaceAll()
{
QString text = m_find_string->text();
if (text.isEmpty()) {
return;
}
QTextDocument::FindFlags flags;
if (!m_ignore_case->isChecked()) {
flags |= QTextDocument::FindCaseSensitively;
}
if (m_whole_words->isChecked()) {
flags |= QTextDocument::FindWholeWords;
}
// Count instances
int found = 0;
QTextEdit* document = m_documents->currentDocument()->text();
QTextCursor cursor = document->textCursor();
cursor.movePosition(QTextCursor::Start);
forever {
cursor = document->document()->find(text, cursor, flags);
if (!cursor.isNull()) {
found++;
} else {
break;
}
}
if (found) {
if (QMessageBox::question(this, tr("Question"), tr("Replace %n instance(s)?", "", found), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
return;
}
} else {
QMessageBox::information(this, tr("Sorry"), tr("Phrase not found."));
return;
}
// Replace instances
QTextCursor start_cursor = document->textCursor();
forever {
cursor = document->document()->find(text, cursor, flags);
if (!cursor.isNull()) {
cursor.insertText(m_replace_string->text());
document->setTextCursor(cursor);
} else {
break;
}
}
document->setTextCursor(start_cursor);
}
示例6: on_listWidgetFormats_currentItemChanged
void ClipboardDialog::on_listWidgetFormats_currentItemChanged(
QListWidgetItem *current, QListWidgetItem *)
{
ui->actionRemove_Format->setEnabled(current != NULL);
QTextEdit *edit = ui->textEditContent;
QString mime = current ? current->text() : QString();
edit->clear();
const QByteArray bytes = m_data.value(mime).toByteArray();
if ( mime.startsWith(QString("image")) ) {
edit->document()->addResource( QTextDocument::ImageResource,
QUrl("data://1"), bytes );
edit->setHtml( QString("<img src=\"data://1\" />") );
} else {
QTextCodec *codec = QTextCodec::codecForName("utf-8");
if (mime == QLatin1String("text/html"))
codec = QTextCodec::codecForHtml(bytes, codec);
else
codec = QTextCodec::codecForUtfText(bytes, codec);
edit->setPlainText( codec ? codec->toUnicode(bytes) : QString() );
}
ui->labelProperties->setText(
tr("<strong> mime:</strong> %1 <strong>size:</strong> %2 bytes")
.arg(escapeHtml(mime))
.arg(QString::number(bytes.size())));
}
示例7: replaceAll
void FindDialog::replaceAll()
{
QString text = m_find_string->text();
if (text.isEmpty()) {
return;
}
QRegExp regex(text, !m_ignore_case->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::RegExp2);
QTextDocument::FindFlags flags;
if (!m_ignore_case->isChecked()) {
flags |= QTextDocument::FindCaseSensitively;
}
if (m_whole_words->isChecked() && !m_regular_expressions->isChecked()) {
flags |= QTextDocument::FindWholeWords;
}
// Count instances
int found = 0;
QTextEdit* document = m_documents->currentDocument()->text();
QTextCursor cursor = document->textCursor();
cursor.movePosition(QTextCursor::Start);
if (!m_regular_expressions->isChecked()) {
forever {
cursor = document->document()->find(text, cursor, flags);
if (!cursor.isNull()) {
found++;
} else {
break;
}
}
} else {
示例8: getSetCheck
// Testing get/set functions
void tst_QTextObject::getSetCheck()
{
QTextEdit edit;
QTextFrame obj1(edit.document());
// QTextFrameLayoutData * QTextFrame::layoutData()
// void QTextFrame::setLayoutData(QTextFrameLayoutData *)
QTextFrameLayoutData *var1 = new QTextFrameLayoutData;
obj1.setLayoutData(var1);
QCOMPARE(var1, obj1.layoutData());
obj1.setLayoutData((QTextFrameLayoutData *)0);
QCOMPARE((QTextFrameLayoutData *)0, obj1.layoutData());
// delete var1; // No delete, since QTextFrame takes ownership
QTextBlock obj2 = edit.textCursor().block();
// QTextBlockUserData * QTextBlock::userData()
// void QTextBlock::setUserData(QTextBlockUserData *)
QTextBlockUserData *var2 = new QTextBlockUserData;
obj2.setUserData(var2);
QCOMPARE(var2, obj2.userData());
obj2.setUserData((QTextBlockUserData *)0);
QCOMPARE((QTextBlockUserData *)0, obj2.userData());
// int QTextBlock::userState()
// void QTextBlock::setUserState(int)
obj2.setUserState(0);
QCOMPARE(0, obj2.userState());
obj2.setUserState(INT_MIN);
QCOMPARE(INT_MIN, obj2.userState());
obj2.setUserState(INT_MAX);
QCOMPARE(INT_MAX, obj2.userState());
}
示例9: getPuzzleDocumentForPrinting
QTextDocument* Printer::getPuzzleDocumentForPrinting(crossword::CrosswordBase& puzzle) const
{
QDir dir;
QString postalAddress = assets::getPostalAddress();
QString textToPrint;
textToPrint.append(puzzle.getInformation().append("<br/><br/>"));
//copy and sort by calendar date
std::vector<crossword::CrosswordEntry> entries = puzzle.getEntries();
std::sort(entries.begin(), entries.end(), crossword::SortByIdentifier());
for (unsigned int i = 0; i < entries.size(); i++) {
QString id = entries.at(i).getIdentifier();
QString entryName = entries.at(i).getEntry();
QString direction = entries.at(i).getDirection();
QString answer = entries.at(i).getGuess().getString();
// QTextEdit understands a HTML subset and \n is treated as a space, so using <br/> tag for newlines instead
textToPrint.append(id).append(" - ").append(entryName).append(" ").append(
direction).append(" --- ").append(answer).append("<br/>");
}
textToPrint.append("<br/>").append(postalAddress);
QTextEdit* textViewer = new QTextEdit(textToPrint);
QTextDocument* document = textViewer->document();
return document;
}
示例10: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTextEdit *editor = new QTextEdit;
//! [0]
QTextDocument *document = editor->document();
QTextCursor redCursor(document);
//! [0] //! [1]
QTextCursor blueCursor(document);
//! [1]
QTextCharFormat redFormat(redCursor.charFormat());
redFormat.setForeground(Qt::red);
QTextCharFormat blueFormat(blueCursor.charFormat());
blueFormat.setForeground(Qt::blue);
redCursor.setCharFormat(redFormat);
blueCursor.setCharFormat(blueFormat);
for (int i = 0; i < 20; ++i) {
if (i % 2 == 0)
redCursor.insertText(tr("%1 ").arg(i), redFormat);
if (i % 5 == 0)
blueCursor.insertText(tr("%1 ").arg(i), blueFormat);
}
editor->setWindowTitle(tr("Text Document Cursors"));
editor->resize(320, 480);
editor->show();
return app.exec();
}
示例11: wrapDescription
// Extract the wrapped text from a text edit, which performs
// the wrapping only optically.
void SubmitEditorWidget::wrapDescription()
{
if (!lineWrap())
return;
const QChar newLine = QLatin1Char('\n');
QTextEdit e;
e.setVisible(false);
e.setMinimumWidth(1000);
e.setFontPointSize(1.0);
e.setLineWrapColumnOrWidth(d->m_ui.description->lineWrapColumnOrWidth());
e.setLineWrapMode(d->m_ui.description->lineWrapMode());
e.setWordWrapMode(d->m_ui.description->wordWrapMode());
e.setPlainText(d->m_description);
d->m_description.clear();
QTextCursor cursor(e.document());
cursor.movePosition(QTextCursor::Start);
while (!cursor.atEnd()) {
const QString block = cursor.block().text();
if (block.startsWith(QLatin1Char('\t'))) { // Don't wrap
d->m_description += block + newLine;
cursor.movePosition(QTextCursor::EndOfBlock);
} else {
forever {
cursor.select(QTextCursor::LineUnderCursor);
d->m_description += cursor.selectedText();
d->m_description += newLine;
cursor.clearSelection();
if (cursor.atBlockEnd())
break;
cursor.movePosition(QTextCursor::NextCharacter);
}
}
cursor.movePosition(QTextCursor::NextBlock);
}
}
示例12: unwrapSmoke
SEXP
qt_qsetRSyntaxHighlighter(SEXP x)
{
QTextEdit *edit = unwrapSmoke(x, QTextEdit);
RSyntaxHighlighter *highlighter = new RSyntaxHighlighter(edit->document());
highlighter->setActive(true);
return R_NilValue;
}
示例13: setModelData
void ItemWidget::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QTextEdit *textEdit = qobject_cast<QTextEdit*>(editor);
if (textEdit != NULL) {
model->setData(index, textEdit->toPlainText());
textEdit->document()->setModified(false);
}
}
示例14: execute
/*!
* \class TextCursorChangeBorder
* \author Anders Fernström
* \date 2005-11-03
* \date 2005-11-07 (update)
*
* \brief Command for changing border
*
* 2005-11-07 AF, implemented the function
*/
void TextCursorChangeBorder::execute()
{
QTextEdit *editor = document()->getCursor()->currentCell()->textEdit();
if( editor )
{
QTextFrameFormat format = editor->document()->rootFrame()->frameFormat();
format.setBorder( border_ );
editor->document()->rootFrame()->setFrameFormat( format );
// create a rule for the border
QString ruleValue;
ruleValue.setNum( border_ );
Rule *rule = new Rule( "OMNotebook_Border", ruleValue );
document()->getCursor()->currentCell()->addRule( rule );
// update the cells style
document()->getCursor()->currentCell()->style()->textFrameFormat()->setBorder( border_ );
}
}
示例15: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
LineEdit l;
l.show();
QTextEdit* text = new QTextEdit;
text->setPlainText("Simple text2");
QTextDocumentWriter writer;
writer.setFileName("teeeext.txt");
writer.write(text->document());
QTextEdit* pdf = new QTextEdit("PDF text");
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("output.pdf");
pdf->document()->print(&printer);
return a.exec();
}