void KoTextEditor::increaseIndent() { if (isEditProtected()) { return; } class Indenter : public BlockFormatVisitor { public: void visit(QTextBlock &block) const { QTextBlockFormat format = block.blockFormat(); // TODO make the 10 configurable. if (!block.textList()) { format.setLeftMargin(format.leftMargin() + 10); } else { const QTextListFormat listFormat = block.textList()->format(); if (format.leftMargin() == 0) { format.setLeftMargin(listFormat.doubleProperty(KoListStyle::Margin) + 10); } else { format.setLeftMargin(format.leftMargin() + 10); } } QTextCursor cursor(block); cursor.setBlockFormat(format); } Qt::Alignment alignment; }; Indenter indenter; d->updateState(KoTextEditor::Private::Format, i18nc("(qtundo-format)", "Increase Indent")); BlockFormatVisitor::visitSelection(this, indenter, i18nc("(qtundo-format)", "Increase Indent")); d->updateState(KoTextEditor::Private::NoOp); emit textFormatChanged(); }
void QDeclarativeText::setTextFormat(TextFormat format) { Q_D(QDeclarativeText); if (format == d->format) return; d->format = format; bool wasRich = d->richText; d->richText = format == RichText || (format == AutoText && Qt::mightBeRichText(d->text)); if (wasRich && !d->richText) { //### delete control? (and vice-versa below) d->updateLayout(); d->markImgDirty(); } else if (!wasRich && d->richText) { if (!d->doc) { d->doc = new QTextDocument(this); d->doc->setDocumentMargin(0); } d->doc->setHtml(d->text); d->updateLayout(); d->markImgDirty(); } emit textFormatChanged(d->format); }
void KoTextEditor::setHorizontalTextAlignment(Qt::Alignment align) { if (isEditProtected()) { return; } class Aligner : public BlockFormatVisitor { public: Aligner(Qt::Alignment align) : alignment(align) {} void visit(QTextBlock &block) const { QTextBlockFormat format = block.blockFormat(); format.setAlignment(alignment); QTextCursor cursor(block); cursor.setBlockFormat(format); } Qt::Alignment alignment; }; Aligner aligner(align); d->updateState(KoTextEditor::Private::Format, i18nc("(qtundo-format)", "Change Alignment")); BlockFormatVisitor::visitSelection(this, aligner, i18nc("(qtundo-format)", "Change Alignment")); d->updateState(KoTextEditor::Private::NoOp); emit textFormatChanged(); }
void QDeclarativeTextEdit::setTextFormat(TextFormat format) { Q_D(QDeclarativeTextEdit); if (format == d->format) return; bool wasRich = d->richText; d->richText = format == RichText || (format == AutoText && Qt::mightBeRichText(d->text)); if (wasRich && !d->richText) { d->control->setPlainText(d->text); updateSize(); } else if (!wasRich && d->richText) { d->control->setHtml(d->text); updateSize(); } d->format = format; emit textFormatChanged(d->format); }