Commit 4762c9ca authored by Volker Krause's avatar Volker Krause
Browse files

Fix showing PkPass rich text back fields

parent 58f6c104
......@@ -212,6 +212,7 @@ Item {
Layout.fillWidth: true
color: pass.foregroundColor
text: Util.textToHtml(modelData.valueDisplayString)
textFormat: Util.isRichText(modelData.valueDisplayString) ? Text.RichText : Text.AutoText
wrapMode: Text.WordWrap
horizontalAlignment: modelData.textAlignment
onLinkActivated: Qt.openUrlExternally(link)
......
......@@ -212,6 +212,7 @@ Item {
Layout.fillWidth: true
color: pass.foregroundColor
text: Util.textToHtml(modelData.valueDisplayString)
textFormat: Util.isRichText(modelData.valueDisplayString) ? Text.RichText : Text.AutoText
wrapMode: Text.WordWrap
horizontalAlignment: modelData.textAlignment
onLinkActivated: Qt.openUrlExternally(link)
......
......@@ -8,7 +8,6 @@
#include <KItinerary/JsonLdDocument>
#include <kcoreaddons_version.h>
#include <KTextToHTML>
#include <QAbstractItemModel>
......@@ -46,13 +45,21 @@ QVariant Util::setDateTimePreserveTimezone(const QVariant &obj, const QString& p
return o;
}
bool Util::isRichText(const QString &text) const
{
auto idx = text.indexOf(QLatin1Char('<'));
if (idx >= 0 && idx < text.size() - 2) {
return text[idx + 1].isLetter() || text[idx + 1] == QLatin1Char('/');
}
return false;
}
QString Util::textToHtml(const QString& text) const
{
#if KCOREADDONS_VERSION_MINOR >= 56
if (isRichText(text)) {
return text;
}
return KTextToHTML::convertToHtml(text, KTextToHTML::ConvertPhoneNumbers | KTextToHTML::PreserveSpaces);
#else
return text;
#endif
}
void Util::sortModel(QObject *model, int column, Qt::SortOrder sortOrder) const
......
......@@ -26,6 +26,9 @@ public:
/** Set a QDateTime property preserving the timezone of the current value. */
Q_INVOKABLE QVariant setDateTimePreserveTimezone(const QVariant &obj, const QString &propertyName, QDateTime value) const;
/** Checks whether @p text is rich-text. */
Q_INVOKABLE bool isRichText(const QString &text) const;
/** Convert links, email address and phone numbers in the given text to HTML links. */
Q_INVOKABLE QString textToHtml(const QString &text) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment