diff options
author | vng <viktor.govako@gmail.com> | 2011-06-12 17:42:12 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:19:27 +0300 |
commit | 250a681ef4a629fb996770e15daa7714d4617587 (patch) | |
tree | 62a8ca423fb739b6231b31f9994ceb11f96493af /qt/search_panel.cpp | |
parent | 7f26143b2c067b84c09f73094e80ddb684e6154a (diff) |
Add "System of measurement".
Use this settings in search distance.
Diffstat (limited to 'qt/search_panel.cpp')
-rw-r--r-- | qt/search_panel.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp index e947c958aa..493a6efe52 100644 --- a/qt/search_panel.cpp +++ b/qt/search_panel.cpp @@ -1,6 +1,8 @@ #include "search_panel.hpp" #include "draw_widget.hpp" +#include "../map/settings.hpp" + #include "../std/bind.hpp" #include <QtCore/QTimer> @@ -83,17 +85,33 @@ namespace return item; } - QString format_distance(double m, bool & drawDir) + QString format_distance_impl(double m, bool & drawDir, + char const * high, char const * low, double highF, double lowF) { + double const lowV = m / lowF; drawDir = true; - if (m < 1.0) + if (lowV < 1.0) { drawDir = false; - return QString::fromAscii("0 m."); + return (QString::fromAscii("0") + QString::fromAscii(low)); } - if (m >= 1.0E3) return QString("%1 km.").arg(m * 1.0E-3, 0, 'f', 1); - else return QString("%1 m.").arg(m, 0, 'f', 0); + if (m >= highF) return QString("%1").arg(m / highF, 0, 'f', 1) + QString::fromAscii(high); + else return QString("%1").arg(lowV, 0, 'f', 0) + QString::fromAscii(low); + } + + QString format_distance(double m, bool & drawDir) + { + using namespace Settings; + Units u; + if (!Settings::Get("Units", u)) u = Metric; + + switch (u) + { + case Yard: return format_distance_impl(m, drawDir, " mi", " yd", 1609.344, 0.9144); + case Foot: return format_distance_impl(m, drawDir, " mi", " ft", 1609.344, 0.3048); + default: return format_distance_impl(m, drawDir, " km", " m", 1000.0, 1.0); + } } QIcon draw_direction(double a) |