100 unsigned elementCount = 0;
101 bool paragraphAlignmentFound =
false;
103 QXmlStreamReader reader(in);
104 QXmlStreamWriter writer(&out);
105 writer.setAutoFormatting(
false);
106 writer.setAutoFormattingIndent(0);
108 while (!reader.atEnd()) {
109 switch (reader.readNext()) {
110 case QXmlStreamReader::StartElement:
112 if (filterElement(reader.name())) {
113 const auto name = reader.name();
114 QXmlStreamAttributes attributes = reader.attributes();
115 filterAttributes(name, &attributes, ¶graphAlignmentFound);
116 writer.writeStartElement(name.toString());
117 if (!attributes.isEmpty())
118 writer.writeAttributes(attributes);
120 reader.readElementText();
123 case QXmlStreamReader::Characters:
124 if (!isWhiteSpace(reader.text()))
125 writer.writeCharacters(reader.text().toString());
127 case QXmlStreamReader::EndElement:
128 writer.writeEndElement();
136 *isPlainTextPtr = !paragraphAlignmentFound && elementCount == 4u;
389 m_link_action(
new QAction(
this)),
390 m_image_action(
new QAction(
this)),
391 m_color_action(
new ColorAction(
this)),
392 m_font_size_input(
new QComboBox),
397 m_font_size_input->setEditable(
false);
398 const auto font_sizes = QFontDatabase::standardSizes();
399 for (
int font_size : font_sizes)
400 m_font_size_input->addItem(QString::number(font_size));
402 connect(m_font_size_input, &QComboBox::textActivated,
404 addWidget(m_font_size_input);
410 m_bold_action = createCheckableAction(
411 createIconSet(QIcon::ThemeIcon::FormatTextBold,
412 "textbold.png"_L1), tr(
"Bold"),
this);
413 connect(m_bold_action, &QAction::triggered, editor, &RichTextEditor::setFontBold);
414 m_bold_action->setShortcut(tr(
"CTRL+B"));
415 addAction(m_bold_action);
417 m_italic_action = createCheckableAction(
418 createIconSet(QIcon::ThemeIcon::FormatTextItalic,
419 "textitalic.png"_L1), tr(
"Italic"),
this);
420 connect(m_italic_action, &QAction::triggered, editor, &RichTextEditor::setFontItalic);
421 m_italic_action->setShortcut(tr(
"CTRL+I"));
422 addAction(m_italic_action);
424 m_underline_action = createCheckableAction(
425 createIconSet(QIcon::ThemeIcon::FormatTextUnderline,
426 "textunder.png"_L1), tr(
"Underline"),
this);
427 connect(m_underline_action, &QAction::triggered, editor, &RichTextEditor::setFontUnderline);
428 m_underline_action->setShortcut(tr(
"CTRL+U"));
429 addAction(m_underline_action);
435 QActionGroup *alignment_group =
new QActionGroup(
this);
436 connect(alignment_group, &QActionGroup::triggered,
437 this, &RichTextEditorToolBar::alignmentActionTriggered);
439 m_align_left_action = createCheckableAction(
440 createIconSet(QIcon::ThemeIcon::FormatJustifyLeft,
441 "textleft.png"_L1), tr(
"Left Align"), alignment_group);
442 addAction(m_align_left_action);
444 m_align_center_action = createCheckableAction(
445 createIconSet(QIcon::ThemeIcon::FormatJustifyCenter,
446 "textcenter.png"_L1), tr(
"Center"), alignment_group);
447 addAction(m_align_center_action);
449 m_align_right_action = createCheckableAction(
450 createIconSet(QIcon::ThemeIcon::FormatJustifyRight,
451 "textright.png"_L1), tr(
"Right Align"), alignment_group);
452 addAction(m_align_right_action);
454 m_align_justify_action = createCheckableAction(
455 createIconSet(QIcon::ThemeIcon::FormatJustifyFill,
456 "textjustify.png"_L1), tr(
"Justify"), alignment_group);
457 addAction(m_align_justify_action);
459 m_layoutDirectionAction = createCheckableAction(
460 createIconSet(QIcon::ThemeIcon::FormatTextDirectionRtl,
461 "righttoleft.png"_L1), tr(
"Right to Left"));
462 connect(m_layoutDirectionAction, &QAction::triggered,
464 addAction(m_layoutDirectionAction);
470 m_valign_sup_action = createCheckableAction(
471 createIconSet(
"textsuperscript.png"_L1), tr(
"Superscript"),
this);
472 connect(m_valign_sup_action, &QAction::triggered,
474 addAction(m_valign_sup_action);
476 m_valign_sub_action = createCheckableAction(
477 createIconSet(
"textsubscript.png"_L1), tr(
"Subscript"),
this);
478 connect(m_valign_sub_action, &QAction::triggered,
480 addAction(m_valign_sub_action);
486 m_link_action->setIcon(createIconSet(
"textanchor.png"_L1));
487 m_link_action->setText(tr(
"Insert &Link"));
489 addAction(m_link_action);
491 m_image_action->setIcon(createIconSet(
"insertimage.png"_L1));
492 m_image_action->setText(tr(
"Insert &Image"));
494 addAction(m_image_action);
499 connect(m_color_action, &ColorAction::colorChanged,
500 this, &RichTextEditorToolBar::colorChanged);
501 addAction(m_color_action);
506 m_simplify_richtext_action
507 = createCheckableAction(createIconSet(
"simplifyrichtext.png"_L1), tr(
"Simplify Rich Text"));
508 connect(m_simplify_richtext_action, &QAction::triggered,
510 m_simplify_richtext_action->setChecked(m_editor->simplifyRichText());
512 m_simplify_richtext_action, &QAction::setChecked);
513 addAction(m_simplify_richtext_action);
515 connect(editor, &QTextEdit::textChanged,
this, &RichTextEditorToolBar::updateActions);
516 connect(editor, &RichTextEditor::stateChanged,
this, &RichTextEditorToolBar::updateActions);
609 if (m_editor ==
nullptr) {
614 const Qt::Alignment alignment = m_editor->alignment();
615 const QTextCursor cursor = m_editor->textCursor();
616 const QTextCharFormat charFormat = cursor.charFormat();
617 const QFont font = charFormat.font();
618 const QTextCharFormat::VerticalAlignment valign =
619 charFormat.verticalAlignment();
620 const bool superScript = valign == QTextCharFormat::AlignSuperScript;
621 const bool subScript = valign == QTextCharFormat::AlignSubScript;
623 if (alignment & Qt::AlignLeft) {
624 m_align_left_action->setChecked(
true);
625 }
else if (alignment & Qt::AlignRight) {
626 m_align_right_action->setChecked(
true);
627 }
else if (alignment & Qt::AlignHCenter) {
628 m_align_center_action->setChecked(
true);
630 m_align_justify_action->setChecked(
true);
632 m_layoutDirectionAction->setChecked(cursor.blockFormat().layoutDirection() == Qt::RightToLeft);
634 m_bold_action->setChecked(font.bold());
635 m_italic_action->setChecked(font.italic());
636 m_underline_action->setChecked(font.underline());
637 m_valign_sup_action->setChecked(superScript);
638 m_valign_sub_action->setChecked(subScript);
640 const int size = font.pointSize();
641 const int idx = m_font_size_input->findText(QString::number(size));
643 m_font_size_input->setCurrentIndex(idx);
645 m_color_action->setColor(m_editor->textColor());