From 9cabb64a4b4d02a1cbbfd0c921ef29414c8c3bc2 Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Mon, 4 Nov 2019 19:51:09 +0300 Subject: [PATCH] add option to h-center preview text, on by default --- editstringcell.cpp | 10 ++++++++-- editstringcell.ui | 25 ++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/editstringcell.cpp b/editstringcell.cpp index 3be3a2a..df6714c 100644 --- a/editstringcell.cpp +++ b/editstringcell.cpp @@ -67,6 +67,7 @@ EditStringCell::EditStringCell(QWidget *parent, const KeyValueItemsPair &keyValu connect(ui.stringEdit, SIGNAL(textChanged()), SLOT(setPreviewText())); connect(ui.stringEdit, SIGNAL(cursorPositionChanged()), SLOT(updateCurrentEditColumn())); connect(ui.reversePreviewTextCheckBox, SIGNAL(toggled(bool)), SLOT(setPreviewText())); + connect(ui.centerPreviewTextCheckBox, SIGNAL(toggled(bool)), SLOT(setPreviewText())); setItem(keyValueItemsPairToEdit); } @@ -131,6 +132,7 @@ void EditStringCell::setPreviewText() text.replace(emptyMatchIndex, matchedLength, QString(" ").repeated(matchedLength)); } + bool shouldCenterAlign = ui.centerPreviewTextCheckBox->isChecked(); const QString defaultColor = colorStrings.at(1); // text is white by default if (ui.reversePreviewTextCheckBox->isChecked()) { @@ -183,13 +185,17 @@ void EditStringCell::setPreviewText() } htmlLines += htmlLine; } - ui.stringPreview->setHtml(htmlLines.join("
")); + QString html = htmlLines.join("
"); + if (shouldCenterAlign) + html = QString("%1").arg(html); + ui.stringPreview->setHtml(html); } else { for (int i = 0; i < colors.size(); i++) // replace color codes with their hex values for HTML text.replace(colorStrings.at(i + 1), QString("").arg(colorHexString(colors.at(i)))); - ui.stringPreview->setHtml(QString("%2").arg(colorHexFromColorString(defaultColor), text.replace('\n', "
"))); + ui.stringPreview->setHtml(QString("%2").arg(colorHexFromColorString(defaultColor), text.replace('\n', "
"), + shouldCenterAlign ? QLatin1String("align=\"center\"") : QString())); } int length = ui.stringPreview->toPlainText().length(); diff --git a/editstringcell.ui b/editstringcell.ui index 0c66a3a..269ca4a 100644 --- a/editstringcell.ui +++ b/editstringcell.ui @@ -6,7 +6,7 @@ 0 0 - 239 + 367 334 @@ -317,6 +317,29 @@ + + + + Center preview text + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + +