Skip to content

Commit

Permalink
add option to h-center preview text, on by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kambala-decapitator committed Nov 4, 2019
1 parent 26b2eb1 commit 9cabb64
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
10 changes: 8 additions & 2 deletions editstringcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -183,13 +185,17 @@ void EditStringCell::setPreviewText()
}
htmlLines += htmlLine;
}
ui.stringPreview->setHtml(htmlLines.join("<br>"));
QString html = htmlLines.join("<br>");
if (shouldCenterAlign)
html = QString("<body align=\"center\">%1</body>").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("</font><font color = \"%1\">").arg(colorHexString(colors.at(i))));
ui.stringPreview->setHtml(QString("<body style='color: %1'>%2</body>").arg(colorHexFromColorString(defaultColor), text.replace('\n', "<br>")));
ui.stringPreview->setHtml(QString("<body style='color: %1' %3>%2</body>").arg(colorHexFromColorString(defaultColor), text.replace('\n', "<br>"),
shouldCenterAlign ? QLatin1String("align=\"center\"") : QString()));
}

int length = ui.stringPreview->toPlainText().length();
Expand Down
25 changes: 24 additions & 1 deletion editstringcell.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>239</width>
<width>367</width>
<height>334</height>
</rect>
</property>
Expand Down Expand Up @@ -317,6 +317,29 @@
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="centerPreviewTextCheckBox">
<property name="text">
<string>Center preview text</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="charsPreviewCountLabel">
<property name="toolTip">
Expand Down

0 comments on commit 9cabb64

Please sign in to comment.