void KNoteEdit::textList() { QTextCursor c = textCursor(); c.beginEditBlock(); if ( m_textList->isChecked() ) { QTextListFormat lf; QTextBlockFormat bf = c.blockFormat(); lf.setIndent( bf.indent() + 1 ); bf.setIndent( 0 ); lf.setStyle( QTextListFormat::ListDisc ); c.setBlockFormat( bf ); c.createList( lf ); } else { QTextBlockFormat bf; bf.setObjectIndex( -1 ); c.setBlockFormat( bf ); } c.endEditBlock(); }
void GraphicTextDialog::textStyle(int styleIndex) { QTextCursor cursor = textEdit->textCursor(); if(styleIndex != 0) { QTextListFormat::Style style = QTextListFormat::ListDisc; switch (styleIndex) { default: case 1: style = QTextListFormat::ListDisc; break; case 2: style = QTextListFormat::ListCircle; break; case 3: style = QTextListFormat::ListSquare; break; case 4: style = QTextListFormat::ListDecimal; break; case 5: style = QTextListFormat::ListLowerAlpha; break; case 6: style = QTextListFormat::ListUpperAlpha; break; } cursor.beginEditBlock(); QTextBlockFormat blockFmt = cursor.blockFormat(); QTextListFormat listFmt; if(cursor.currentList()) { listFmt = cursor.currentList()->format(); } else { listFmt.setIndent(blockFmt.indent() + 1); blockFmt.setIndent(0); cursor.setBlockFormat(blockFmt); } listFmt.setStyle(style); cursor.createList(listFmt); cursor.endEditBlock(); } else { // #### QTextBlockFormat bfmt; bfmt.setObjectIndex(-1); cursor.mergeBlockFormat(bfmt); } }
void MRichTextEdit::list(bool checked, QTextListFormat::Style style) { QTextCursor cursor = f_textedit->textCursor(); cursor.beginEditBlock(); if (!checked) { QTextBlockFormat obfmt = cursor.blockFormat(); QTextBlockFormat bfmt; bfmt.setIndent(obfmt.indent()); cursor.setBlockFormat(bfmt); } else { QTextListFormat listFmt; if (cursor.currentList()) { listFmt = cursor.currentList()->format(); } listFmt.setStyle(style); cursor.createList(listFmt); } cursor.endEditBlock(); }
//段落标号、编号 void MyChild::setStyle(int style) { QTextCursor cursor = this->textCursor(); if (style != 0) { QTextListFormat::Style stylename = QTextListFormat::ListDisc; switch (style) { default: case 1: stylename = QTextListFormat::ListDisc; break; case 2: stylename = QTextListFormat::ListCircle; break; case 3: stylename = QTextListFormat::ListSquare; break; case 4: stylename = QTextListFormat::ListDecimal; break; case 5: stylename = QTextListFormat::ListLowerAlpha; break; case 6: stylename = QTextListFormat::ListUpperAlpha; break; case 7: stylename = QTextListFormat::ListLowerRoman; break; case 8: stylename = QTextListFormat::ListUpperRoman; break; } cursor.beginEditBlock(); QTextBlockFormat blockFmt = cursor.blockFormat(); QTextListFormat listFmt; if (cursor.currentList()) { listFmt = cursor.currentList()->format(); } else { listFmt.setIndent(blockFmt.indent() + 1); blockFmt.setIndent(0); cursor.setBlockFormat(blockFmt); } listFmt.setStyle(stylename); cursor.createList(listFmt); cursor.endEditBlock(); } else { QTextBlockFormat bfmt; bfmt.setObjectIndex(-1); cursor.mergeBlockFormat(bfmt); } }
/*! * \brief Changes the list attribute of the selected text to \a v */ void QwwRichTextEdit::setList(bool v){ QTextCursor cur = textCursor(); if(v){ QTextListFormat listFormat; listFormat.setStyle(QTextListFormat::ListDisc); currentList = cur.createList(listFormat); } else { cur.setBlockFormat(QTextBlockFormat()); // cur.movePosition(QTextCursor::NextBlock); // cur.insertBlock(QTextBlockFormat()); setTextCursor(cur); currentList = 0; } }
/*! * \internal */ bool QwwRichTextEdit::event(QEvent *e){ if(e->type()!=QEvent::KeyPress) return QTextEdit::event(e); QKeyEvent *ke = (QKeyEvent*)e; currentList = textCursor().currentList(); if(currentList){ if(ke->key()==Qt::Key_Tab || ke->key() ==Qt::Key_Backtab){ QTextCursor cur = textCursor(); QTextListFormat listFormat = currentList->format(); listFormat.setIndent(currentList->format().indent()+ (ke->key()== Qt::Key_Tab ? 1 : -1)); // listFormat.setStyle(QTextListFormat::ListDisc); currentList = cur.createList(listFormat); return true; } } return QTextEdit::event(e); }
void MainWindow::toggleList(QTextListFormat::Style style) { QTextCursor cursor = ui->textNote->textCursor(); QTextBlockFormat blockFmt = cursor.blockFormat(); QTextListFormat listFmt; bool list = (cursor.currentList() != 0); // change style if list exists and is a different style if(list && cursor.currentList()->format().style() != style) { listFmt.setStyle(style); cursor.currentList()->setFormat(listFmt); } // remove list if exists and matches style else if(list&& cursor.currentList()->format().style() == style) { cursor.currentList()->removeItem(0); blockFmt = ui->textNote->textCursor().blockFormat(); cursor = ui->textNote->textCursor(); blockFmt.setIndent(0); cursor.setBlockFormat(blockFmt); // create list if not exists } else { cursor.beginEditBlock(); if (cursor.currentList()) { listFmt = cursor.currentList()->format(); } else { listFmt.setIndent(blockFmt.indent() + 1); blockFmt.setIndent(0); cursor.setBlockFormat(blockFmt); } listFmt.setStyle(style); cursor.createList(listFmt); cursor.endEditBlock(); } updateMenus(); }
void TextEditWidget::sl_ListButton_Toggled(bool toggle) { QTextCursor cursor = this->textField->textCursor(); if (toggle) { if (cursor.currentList()) { WARNING("Wrong button state"); return; } QTextListFormat format; format.setStyle(QTextListFormat::ListDisc); cursor.createList(format); } else { QTextList *textList = cursor.currentList(); if (!cursor.currentList()) { WARNING("Wrong button state"); return; } QTextBlock block = cursor.block(); textList->remove(block); QTextBlockFormat format = block.blockFormat(); format.setIndent(0); cursor.setBlockFormat(format); } }