Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Common/LtsWidgets/lts_text_edit_dialog.cpp
T
torstenandCopilot 7a6be7474e Qt6 migration: Fix BUILD_RTI=OFF build errors in TrainingAreaBase
- training_area_telegrams.cpp: Fixed QJsonObject initializer syntax (Qt6 requires {{}} not ({}))
- training_area_telegrams.cpp: Fixed fromJson() methods to access m_* members directly
- training_area_telegrams.cpp: Fixed brace mismatches in multiple toJson() methods
- training_area_telegrams.h: Changed Header struct to public members for consistency
- tx_mixin.cpp: Fixed getEquipmentNumber() template for direct member access
- lts_coordinate.cpp: Added missing #include <iomanip>
- MIGRATION_STATUS.md: Added migration progress tracking document

C++17 constraint enforced due to RTI Connext DDS 7.7.0 incompatibility with C++20+

Build status: BUILD_RTI=OFF successful (0 errors, warnings only)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-23 20:49:23 +02:00

144 lines
3.7 KiB
C++

/**
* @RDE_HEADER@
* LtsTextEditDialog
* $Id$
* $HeadURL$
* $Author$
* Created by Norbert Thoden, SLSE, 2023-06-14
*/
#include "lts_text_edit_dialog.h"
#include "lts_text_editor.h"
#include <QtWidgets/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
}
///////////////////////////////////////////////////////////////////////////////
// PUBLIC
void LtsTextEditDialog::retranslate()
{
// in correct translation context
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)
{
// QTextEdit::textChanged is add via LtsDialog::addChangesMadeSignal()
// so setHtml will in turn call slotChangesMade()
#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