mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 10:15:38 +08:00
[5.14.1] UI adjustments
* OS native check of screen resolution (Qt free, experimental) * changed rounding * use string for scale factor so we can use fractions as 2/3 * utility functions to clean numbers, parse fractions It looks like: * my WIN10 scaling is 250% * obviously swift rounds that to 3 (device ratio) * now using FLOOR policy down-rounding to 2 * rational: scaling up (scale factor) is better as down-scaling as the factors would be clearer * 2->3 1.5, but 3->2 means 0.66667
This commit is contained in:
committed by
Mat Sutcliffe
parent
52de67a72f
commit
8f4c4a249c
@@ -491,6 +491,64 @@ namespace BlackMisc
|
||||
return (c % 2) == 0;
|
||||
}
|
||||
|
||||
double parseFraction(const QString &fraction, double failDefault)
|
||||
{
|
||||
if (fraction.isEmpty()) { return failDefault; }
|
||||
bool ok;
|
||||
|
||||
double r = failDefault;
|
||||
if (fraction.contains('/'))
|
||||
{
|
||||
const QStringList parts = fraction.split('/');
|
||||
if (parts.size() != 2) { return failDefault; }
|
||||
const double c = parts.front().trimmed().toDouble(&ok);
|
||||
if (!ok) { return failDefault; }
|
||||
|
||||
const double d = parts.last().trimmed().toDouble(&ok);
|
||||
if (!ok) { return failDefault; }
|
||||
if (qFuzzyCompare(0.0, d)) { return failDefault; }
|
||||
r = c / d;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = fraction.trimmed().toDouble(&ok);
|
||||
if (!ok) { return failDefault; }
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
QString cleanNumber(const QString &number)
|
||||
{
|
||||
QString n = number.trimmed();
|
||||
if (n.isEmpty()) { return QString(); }
|
||||
|
||||
int dp = n.indexOf('.');
|
||||
if (dp < 0) { dp = n.indexOf(','); }
|
||||
|
||||
// clean all trailing stuff
|
||||
while (dp >= 0 && !n.isEmpty())
|
||||
{
|
||||
const QChar l = n.at(n.size() - 1);
|
||||
if (l == '0')
|
||||
{
|
||||
n.chop(1);
|
||||
continue;
|
||||
}
|
||||
else if (l == '.' || l == ',')
|
||||
{
|
||||
n.chop(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
while (n.startsWith("00"))
|
||||
{
|
||||
n.remove(0, 1);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
} // ns
|
||||
|
||||
//! \endcond
|
||||
|
||||
@@ -308,6 +308,12 @@ namespace BlackMisc
|
||||
//! Contains any string of the list?
|
||||
BLACKMISC_EXPORT bool containsAny(const QString &testString, const QStringList &any, Qt::CaseSensitivity cs);
|
||||
|
||||
//! Parse a fraction like 2/3
|
||||
BLACKMISC_EXPORT double parseFraction(const QString &fraction, double failDefault = std::numeric_limits<double>::quiet_NaN());
|
||||
|
||||
//! Remove leading 0, trailing 0, " ", and "." from a number
|
||||
BLACKMISC_EXPORT QString cleanNumber(const QString &number);
|
||||
|
||||
namespace Mixin
|
||||
{
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user