Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Common/LtsWidgets/lts_text_edit_dialog.cpp
T
torstenandCopilot d6b6ffce7c Apply clang-format to Lts/Common and DTC/enum headers
- Formatted all CodeGen module files (9 files)
- Formatted LtsAppDescriptor module files
- Formatted LtsAppManager/AppChooser files
- Applied clang-format to all DTC and enum headers across modules
- Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/)

Cosmetic changes only, no functional modifications.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-19 14:46:29 +02:00

131 lines
3.4 KiB
C++

#include "lts_text_edit_dialog.h"
#include "lts_text_editor.h"
#include <QHBoxLayout>
#if 1
#define USE_TEXT_EDITOR_2
#else
#define USE_TEXT_EDITOR
#endif
namespace LtsWidgets
{
LtsTextEditDialog::LtsTextEditDialog(QWidget* parent)
: LtsDialog(parent, ButtonCombination::OkApplyCancel)
#ifdef USE_TEXT_EDITOR
,
m_textEditor(new LtsTextEditor(this))
#else
,
m_textEditor2(new LtsTextEditor2(this))
#endif
{
QHBoxLayout* hbox = new QHBoxLayout(this);
#ifdef USE_TEXT_EDITOR
hbox->addWidget(m_textEditor);
connect(m_textEditor->textEdit(), &QTextEdit::textChanged, this,
[this]() { emit signalTextChanged(this->getHtmlText()); });
connect(m_textEditor, &LtsTextEditor::backgroundColorChanged, this, &LtsTextEditDialog::onBackgroundColorChanged);
#else
hbox->addWidget(m_textEditor2);
connect(m_textEditor2->textEdit(), &QTextEdit::textChanged, this,
[this]() { emit signalTextChanged(this->getHtmlText()); });
connect(m_textEditor2, &LtsTextEditor2::backgroundColorChanged, this, &LtsTextEditDialog::onBackgroundColorChanged);
#endif
enableBackgroundColor(false);
}
LtsTextEditDialog::~LtsTextEditDialog() {}
void LtsTextEditDialog::enableBackgroundColor(bool onOff)
{
#ifdef USE_TEXT_EDITOR
m_textEditor->enableBackgroundColor(onOff);
#else
m_textEditor2->enableBackgroundColor(onOff);
#endif
}
void LtsTextEditDialog::retranslate()
{
QString name = tr("Edit Text");
translate(name);
}
bool LtsTextEditDialog::apply()
{
#ifdef USE_TEXT_EDITOR
QString textHtml = m_textEditor->textEdit()->document()->toHtml();
const QString backGroundColor =
QLatin1String("background-color:'%1'; ").arg(m_textEditor->backgroundColor().name());
#else
QString textHtml = m_textEditor2->textEdit()->document()->toHtml();
const QString backGroundColor =
QLatin1String("background-color:'%1'; ").arg(m_textEditor2->backgroundColor().name());
#endif
emit signalTextApplied(textHtml);
const int insertBackGroundColorIndex = textHtml.indexOf(QLatin1String("font-family"));
textHtml.insert(insertBackGroundColorIndex, backGroundColor);
emit signalTextAppliedWithBackGroundColor(textHtml);
return true;
}
void LtsTextEditDialog::setHtml(const QString& htmlText)
{
#ifdef USE_TEXT_EDITOR
m_textEditor->textEdit()->document()->setHtml(htmlText);
#else
m_textEditor2->textEdit()->document()->setHtml(htmlText);
#endif
}
QString LtsTextEditDialog::getHtmlText() const
{
#ifdef USE_TEXT_EDITOR
if (m_textEditor && m_textEditor->textEdit() && m_textEditor->textEdit()->document())
return m_textEditor->textEdit()->document()->toHtml();
#else
if (m_textEditor2 && m_textEditor2->textEdit() && m_textEditor2->textEdit()->document())
return m_textEditor2->textEdit()->document()->toHtml();
#endif
return {};
}
void LtsTextEditDialog::setInitialBackgroundColor(const QColor& bgColor)
{
#ifdef USE_TEXT_EDITOR
if (m_textEditor)
m_textEditor->setInitialBackgroundColor(bgColor);
#else
if (m_textEditor2)
m_textEditor2->setInitialBackgroundColor(bgColor);
#endif
}
void LtsTextEditDialog::dialogCanceled()
{
emit signalDialogCanceled();
BaseClass::dialogCanceled();
}
void LtsTextEditDialog::onBackgroundColorChanged(const QColor& backgroundColor)
{
slotChangesMade();
emit signalBackgroundColorChanged(backgroundColor);
}
} // namespace LtsWidgets