| 561 | // text formatting slots |
| 562 | |
| 563 | void LabelWidget::textChanged() { |
| 564 | // QDEBUG("############\n" << Q_FUNC_INFO << ", label text =" << m_label->text().text) |
| 565 | CONDITIONAL_LOCK_RETURN; |
| 566 | |
| 567 | const auto& plainText = ui.teLabel->toPlainText(); |
| 568 | QTextEdit te(ui.chbShowPlaceholderText->isChecked() ? m_label->text().textPlaceholder : m_label->text().text); |
| 569 | bool plainTextChanged = plainText != te.toPlainText(); |
| 570 | |
| 571 | const auto mode = static_cast<TextLabel::Mode>(ui.cbMode->currentIndex()); |
| 572 | switch (mode) { |
| 573 | case TextLabel::Mode::LaTeX: |
| 574 | case TextLabel::Mode::Markdown: { |
| 575 | QString text = ui.teLabel->toPlainText(); |
| 576 | TextLabel::TextWrapper wrapper; |
| 577 | wrapper.mode = mode; |
| 578 | |
| 579 | if (!ui.chbShowPlaceholderText->isChecked()) { |
| 580 | if (plainTextChanged) { |
| 581 | // set text only if the plain text change. otherwise the text is changed |
| 582 | // already in the setter functions |
| 583 | wrapper.text = std::move(text); |
| 584 | for (auto* label : m_labelsList) { |
| 585 | wrapper.textPlaceholder = label->text().textPlaceholder; |
| 586 | wrapper.allowPlaceholder = label->text().allowPlaceholder; |
| 587 | label->setText(wrapper); |
| 588 | } |
| 589 | } |
| 590 | } else { |
| 591 | // No need to compare if plainTextChanged |
| 592 | // Change it always. |
| 593 | wrapper.textPlaceholder = std::move(text); |
| 594 | for (auto* label : m_labelsList) { |
| 595 | wrapper.allowPlaceholder = label->text().allowPlaceholder; |
| 596 | wrapper.text = label->text().text; |
| 597 | label->setPlaceholderText(wrapper); |
| 598 | } |
| 599 | } |
| 600 | break; |
| 601 | } |
| 602 | case TextLabel::Mode::Text: { |
| 603 | // QDEBUG(Q_FUNC_INFO << ", color = " << m_label->fontColor()) |
| 604 | // QDEBUG(Q_FUNC_INFO << ", background color = " << m_label->backgroundColor()) |
| 605 | // QDEBUG(Q_FUNC_INFO << ", format color = " << ui.teLabel->currentCharFormat().foreground().color()) |
| 606 | // QDEBUG(Q_FUNC_INFO << ", Plain TEXT = " << ui.teLabel->toPlainText() << '\n') |
| 607 | // QDEBUG(Q_FUNC_INFO << ", OLD TEXT =" << m_label->text().text << '\n') |
| 608 | // save an empty string instead of html with empty body if no text is in QTextEdit |
| 609 | QString text; |
| 610 | if (!ui.teLabel->toPlainText().isEmpty()) { |
| 611 | // if the current or previous label text is empty, set the color first |
| 612 | QTextEdit pte(m_label->text().text); // te with previous text |
| 613 | if (m_label->text().text.isEmpty() || pte.toPlainText().isEmpty()) { |
| 614 | // DEBUG("EMPTY TEXT") |
| 615 | ui.teLabel->selectAll(); |
| 616 | ui.teLabel->setTextColor(m_label->fontColor()); |
| 617 | ui.teLabel->setTextBackgroundColor(m_label->backgroundColor()); |
| 618 | // clear the selection after setting the color |
| 619 | auto tc = ui.teLabel->textCursor(); |
| 620 | tc.setPosition(tc.selectionEnd()); |
nothing calls this directly
no test coverage detected