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 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); } }
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 MainWindow::highlightListItems() { QTextCursor cursor = editor->textCursor(); QTextList *list = cursor.currentList(); if (!list) return; cursor.beginEditBlock(); //! [0] for (int index = 0; index < list->count(); ++index) { QTextBlock listItem = list->item(index); //! [0] QTextBlockFormat newBlockFormat = listItem.blockFormat(); newBlockFormat.setBackground(Qt::lightGray); QTextCursor itemCursor = cursor; itemCursor.setPosition(listItem.position()); //itemCursor.movePosition(QTextCursor::StartOfBlock); itemCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); itemCursor.setBlockFormat(newBlockFormat); /* //! [1] processListItem(listItem); //! [1] */ //! [2] } //! [2] cursor.endEditBlock(); }
void TextEditWidget::sl_IncreaseListIndent_Triggered() { QTextCursor cursor = this->textField->textCursor(); QTextList *textList = cursor.currentList(); if (!textList) {return;} QTextListFormat format = textList->format(); format.setIndent(format.indent() + 1); textList->setFormat(format); }
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); } }
void TextEditWidget::sl_TextEdit_CursorPositionChanged() { ACTBold->setChecked(textField->fontWeight() == QFont::Bold); ACTItalic->setChecked(textField->fontItalic()); ACTUnderline->setChecked(textField->fontUnderline()); strikeOutAction->setChecked(textField->StrikedOut()); ACTAlignLeft->setChecked(textField->GetAlignment() == Qt::AlignLeft); ACTAlignCenter->setChecked(textField->GetAlignment() == Qt::AlignHCenter); ACTAlignRight->setChecked(textField->GetAlignment() == Qt::AlignRight); alignJustifyAction->setChecked(textField->GetAlignment() == Qt::AlignJustify); listButton->blockSignals(true); const QTextCursor cursor = textField->textCursor(); const QTextList *textList = cursor.currentList(); listButton->setChecked(textList != 0); increaseListIndentAction->setVisible(textList != 0); decreaseListIndentAction->setVisible(textList != 0); listButton->blockSignals(false); fontComboBox->blockSignals(true); const QFont temp = textField->currentFont(); fontComboBox->setCurrentFont(temp); fontComboBox->blockSignals(false); fontSizeComboBox->blockSignals(true); const int size = this->textField->currentFont().pointSize(); const int index = fontSizeComboBox->findData(size); if (index != -1) { fontSizeComboBox->setCurrentIndex(index); } fontSizeComboBox->blockSignals(false); const QTextTable* table = textField->textCursor().currentTable(); const bool tablePresent = (table != 0); insertRowAction->setEnabled(tablePresent); insertColumnAction->setEnabled(tablePresent); removeRowAction->setEnabled(tablePresent); removeColumnAction->setEnabled(tablePresent); mergeCellsAction->setEnabled(tablePresent); tablePropertiesAction->setEnabled(tablePresent); if (tablePresent) { createTableAction->setText("Edit table..."); } else { createTableAction->setText("Create table"); } }
void MainWindow::insertList() { QTextCursor cursor = editor->textCursor(); cursor.beginEditBlock(); QTextList *list = cursor.currentList(); QTextListFormat listFormat; if (list) listFormat = list->format(); listFormat.setStyle(QTextListFormat::ListDisc); listFormat.setIndent(listFormat.indent() + 1); cursor.insertList(listFormat); cursor.endEditBlock(); }
void TextEditWidget::sl_ListButton_Triggered(QAction* action) { if (!action) { WARNING("Null pointer recieved"); return; } QTextListFormat::Style style = (QTextListFormat::Style)action->data().toInt(); QTextCursor cursor = this->textField->textCursor(); QTextList *textList = cursor.currentList(); if (!textList) { WARNING("Wrong button state"); return; } QTextListFormat format = textList->format(); format.setStyle(style); textList->setFormat(format); }
void MainWindow::insertList() { QTextCursor cursor = editor->textCursor(); cursor.beginEditBlock(); QTextList *list = cursor.currentList(); //! [0] listFormat = QTextListFormat() if list: listFormat = list.format() listFormat.setIndent(listFormat.indent() + 1) listFormat.setStyle(QTextListFormat.ListDisc) cursor.insertList(listFormat) //! [0] cursor.endEditBlock(); }
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(); }