99 unsigned elementCount = 0;
100 bool paragraphAlignmentFound =
false;
102 QXmlStreamReader reader(in);
103 QXmlStreamWriter writer(&out);
104 writer.setAutoFormatting(
false);
105 writer.setAutoFormattingIndent(0);
107 while (!reader.atEnd()) {
108 switch (reader.readNext()) {
109 case QXmlStreamReader::StartElement:
111 if (filterElement(reader.name())) {
112 const auto name = reader.name();
113 QXmlStreamAttributes attributes = reader.attributes();
114 filterAttributes(name, &attributes, ¶graphAlignmentFound);
115 writer.writeStartElement(name.toString());
116 if (!attributes.isEmpty())
117 writer.writeAttributes(attributes);
119 reader.readElementText();
122 case QXmlStreamReader::Characters:
123 if (!isWhiteSpace(reader.text()))
124 writer.writeCharacters(reader.text().toString());
126 case QXmlStreamReader::EndElement:
127 writer.writeEndElement();
135 *isPlainTextPtr = !paragraphAlignmentFound && elementCount == 4u;
388 m_link_action(
new QAction(
this)),
389 m_image_action(
new QAction(
this)),
390 m_color_action(
new ColorAction(
this)),
391 m_font_size_input(
new QComboBox),
396 m_font_size_input->setEditable(
false);
397 const auto font_sizes = QFontDatabase::standardSizes();
398 for (
int font_size : font_sizes)
399 m_font_size_input->addItem(QString::number(font_size));
401 connect(m_font_size_input, &QComboBox::textActivated,
402 this, &RichTextEditorToolBar::sizeInputActivated);
403 addWidget(m_font_size_input);
409 m_bold_action = createCheckableAction(
410 createIconSet(QIcon::ThemeIcon::FormatTextBold,
411 "textbold.png"_L1), tr(
"Bold"),
this);
412 connect(m_bold_action, &QAction::triggered, editor, &RichTextEditor::setFontBold);
413 m_bold_action->setShortcut(tr(
"CTRL+B"));
414 addAction(m_bold_action);
416 m_italic_action = createCheckableAction(
417 createIconSet(QIcon::ThemeIcon::FormatTextItalic,
418 "textitalic.png"_L1), tr(
"Italic"),
this);
419 connect(m_italic_action, &QAction::triggered, editor, &RichTextEditor::setFontItalic);
420 m_italic_action->setShortcut(tr(
"CTRL+I"));
421 addAction(m_italic_action);
423 m_underline_action = createCheckableAction(
424 createIconSet(QIcon::ThemeIcon::FormatTextUnderline,
425 "textunder.png"_L1), tr(
"Underline"),
this);
426 connect(m_underline_action, &QAction::triggered, editor, &RichTextEditor::setFontUnderline);
427 m_underline_action->setShortcut(tr(
"CTRL+U"));
428 addAction(m_underline_action);
434 QActionGroup *alignment_group =
new QActionGroup(
this);
435 connect(alignment_group, &QActionGroup::triggered,
436 this, &RichTextEditorToolBar::alignmentActionTriggered);
438 m_align_left_action = createCheckableAction(
439 createIconSet(QIcon::ThemeIcon::FormatJustifyLeft,
440 "textleft.png"_L1), tr(
"Left Align"), alignment_group);
441 addAction(m_align_left_action);
443 m_align_center_action = createCheckableAction(
444 createIconSet(QIcon::ThemeIcon::FormatJustifyCenter,
445 "textcenter.png"_L1), tr(
"Center"), alignment_group);
446 addAction(m_align_center_action);
448 m_align_right_action = createCheckableAction(
449 createIconSet(QIcon::ThemeIcon::FormatJustifyRight,
450 "textright.png"_L1), tr(
"Right Align"), alignment_group);
451 addAction(m_align_right_action);
453 m_align_justify_action = createCheckableAction(
454 createIconSet(QIcon::ThemeIcon::FormatJustifyFill,
455 "textjustify.png"_L1), tr(
"Justify"), alignment_group);
456 addAction(m_align_justify_action);
458 m_layoutDirectionAction = createCheckableAction(
459 createIconSet(QIcon::ThemeIcon::FormatTextDirectionRtl,
460 "righttoleft.png"_L1), tr(
"Right to Left"));
461 connect(m_layoutDirectionAction, &QAction::triggered,
462 this, &RichTextEditorToolBar::layoutDirectionChanged);
463 addAction(m_layoutDirectionAction);
469 m_valign_sup_action = createCheckableAction(
470 createIconSet(
"textsuperscript.png"_L1), tr(
"Superscript"),
this);
471 connect(m_valign_sup_action, &QAction::triggered,
472 this, &RichTextEditorToolBar::setVAlignSuper);
473 addAction(m_valign_sup_action);
475 m_valign_sub_action = createCheckableAction(
476 createIconSet(
"textsubscript.png"_L1), tr(
"Subscript"),
this);
477 connect(m_valign_sub_action, &QAction::triggered,
478 this, &RichTextEditorToolBar::setVAlignSub);
479 addAction(m_valign_sub_action);
485 m_link_action->setIcon(createIconSet(
"textanchor.png"_L1));
486 m_link_action->setText(tr(
"Insert &Link"));
487 connect(m_link_action, &QAction::triggered,
this, &RichTextEditorToolBar::insertLink);
488 addAction(m_link_action);
490 m_image_action->setIcon(createIconSet(
"insertimage.png"_L1));
491 m_image_action->setText(tr(
"Insert &Image"));
492 connect(m_image_action, &QAction::triggered,
this, &RichTextEditorToolBar::insertImage);
493 addAction(m_image_action);
498 connect(m_color_action, &ColorAction::colorChanged,
499 this, &RichTextEditorToolBar::colorChanged);
500 addAction(m_color_action);
505 m_simplify_richtext_action
506 = createCheckableAction(createIconSet(
"simplifyrichtext.png"_L1), tr(
"Simplify Rich Text"));
507 connect(m_simplify_richtext_action, &QAction::triggered,
508 m_editor, &RichTextEditor::setSimplifyRichText);
509 m_simplify_richtext_action->setChecked(m_editor->simplifyRichText());
510 connect(m_editor.data(), &RichTextEditor::simplifyRichTextChanged,
511 m_simplify_richtext_action, &QAction::setChecked);
512 addAction(m_simplify_richtext_action);
514 connect(editor, &QTextEdit::textChanged,
this, &RichTextEditorToolBar::updateActions);
515 connect(editor, &RichTextEditor::stateChanged,
this, &RichTextEditorToolBar::updateActions);
608 if (m_editor ==
nullptr) {
613 const Qt::Alignment alignment = m_editor->alignment();
614 const QTextCursor cursor = m_editor->textCursor();
615 const QTextCharFormat charFormat = cursor.charFormat();
616 const QFont font = charFormat.font();
617 const QTextCharFormat::VerticalAlignment valign =
618 charFormat.verticalAlignment();
619 const bool superScript = valign == QTextCharFormat::AlignSuperScript;
620 const bool subScript = valign == QTextCharFormat::AlignSubScript;
622 if (alignment & Qt::AlignLeft) {
623 m_align_left_action->setChecked(
true);
624 }
else if (alignment & Qt::AlignRight) {
625 m_align_right_action->setChecked(
true);
626 }
else if (alignment & Qt::AlignHCenter) {
627 m_align_center_action->setChecked(
true);
629 m_align_justify_action->setChecked(
true);
631 m_layoutDirectionAction->setChecked(cursor.blockFormat().layoutDirection() == Qt::RightToLeft);
633 m_bold_action->setChecked(font.bold());
634 m_italic_action->setChecked(font.italic());
635 m_underline_action->setChecked(font.underline());
636 m_valign_sup_action->setChecked(superScript);
637 m_valign_sub_action->setChecked(subScript);
639 const int size = font.pointSize();
640 const int idx = m_font_size_input->findText(QString::number(size));
642 m_font_size_input->setCurrentIndex(idx);
644 m_color_action->setColor(m_editor->textColor());