Commit 659931f7 authored by Volker Krause's avatar Volker Krause
Browse files

Add field text alignment property

parent c0d9a2ad
......@@ -63,6 +63,7 @@ private slots:
field = pass->field(QLatin1String("boarding"));
QCOMPARE(field.key(), QLatin1String("boarding"));
QCOMPARE(field.value(), QLatin1String("20:25"));
QCOMPARE(field.textAlignment(), Qt::AlignLeft);
auto boardingPass = dynamic_cast<KPkPass::BoardingPass*>(pass.get());
QVERIFY(boardingPass);
......
......@@ -21,6 +21,7 @@
#include "pass.h"
#include "pass_p.h"
#include <QGuiApplication>
#include <QJsonObject>
using namespace KPkPass;
......@@ -91,3 +92,16 @@ QString Field::changeMessage() const
msg = msg.replace(QLatin1String("%@"), valueDisplayString());
return msg;
}
Qt::Alignment Field::textAlignment() const
{
const auto alignStr = d->obj.value(QLatin1String("textAlignment")).toString();
if (alignStr == QLatin1String("PKTextAlignmentLeft")) {
return Qt::AlignLeft;
} else if (alignStr == QLatin1String("PKTextAlignmentCenter")) {
return Qt::AlignHCenter;
} else if (alignStr == QLatin1String("PKTextAlignmentRight")) {
return Qt::AlignRight;
}
return QGuiApplication::layoutDirection() == Qt::LeftToRight ? Qt::AlignLeft : Qt::AlignRight;
}
......@@ -46,6 +46,7 @@ class KPKPASS_EXPORT Field
Q_PROPERTY(QVariant value READ value CONSTANT)
Q_PROPERTY(QString valueDisplayString READ valueDisplayString CONSTANT)
Q_PROPERTY(QString changeMessage READ changeMessage CONSTANT)
Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment CONSTANT)
public:
Field();
......@@ -72,7 +73,9 @@ public:
/** The localized change message for this value. */
QString changeMessage() const;
// TODO add textAlignment property
/** Text alignment. */
Qt::Alignment textAlignment() const;
private:
friend class PassPrivate;
explicit Field(const QJsonObject &obj, const Pass *pass);
......
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