data_location.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "data/data_location.h"
  8. #include "ui/image/image.h"
  9. #include "data/data_file_origin.h"
  10. namespace Data {
  11. namespace {
  12. [[nodiscard]] QString AsString(float64 value) {
  13. constexpr auto kPrecision = 6;
  14. return QString::number(value, 'f', kPrecision);
  15. }
  16. } // namespace
  17. LocationPoint::LocationPoint(const MTPDgeoPoint &point)
  18. : _lat(point.vlat().v)
  19. , _lon(point.vlong().v)
  20. , _access(point.vaccess_hash().v) {
  21. }
  22. LocationPoint::LocationPoint(float64 lat, float64 lon, IgnoreAccessHash)
  23. : _lat(lat)
  24. , _lon(lon) {
  25. }
  26. QString LocationPoint::latAsString() const {
  27. return AsString(_lat);
  28. }
  29. QString LocationPoint::lonAsString() const {
  30. return AsString(_lon);
  31. }
  32. MTPGeoPoint LocationPoint::toMTP() const {
  33. return MTP_geoPoint(
  34. MTP_flags(0),
  35. MTP_double(_lon),
  36. MTP_double(_lat),
  37. MTP_long(_access),
  38. MTP_int(0)); // accuracy_radius
  39. }
  40. float64 LocationPoint::lat() const {
  41. return _lat;
  42. }
  43. float64 LocationPoint::lon() const {
  44. return _lon;
  45. }
  46. uint64 LocationPoint::accessHash() const {
  47. return _access;
  48. }
  49. size_t LocationPoint::hash() const {
  50. return QtPrivate::QHashCombine().operator()(
  51. std::hash<float64>()(_lat),
  52. _lon);
  53. }
  54. GeoPointLocation ComputeLocation(const LocationPoint &point) {
  55. const auto scale = 1 + (cScale() * style::DevicePixelRatio()) / 200;
  56. const auto zoom = 13 + (scale - 1);
  57. const auto w = st::locationSize.width() / scale;
  58. const auto h = st::locationSize.height() / scale;
  59. auto result = GeoPointLocation();
  60. result.lat = point.lat();
  61. result.lon = point.lon();
  62. result.access = point.accessHash();
  63. result.width = w;
  64. result.height = h;
  65. result.zoom = zoom;
  66. result.scale = scale;
  67. return result;
  68. }
  69. } // namespace Data