info_media_common.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 "info/media/info_media_common.h"
  8. #include "history/history_item.h"
  9. #include "storage/storage_shared_media.h"
  10. #include "styles/style_info.h"
  11. #include "styles/style_overview.h"
  12. namespace Info::Media {
  13. UniversalMsgId GetUniversalId(FullMsgId itemId) {
  14. return peerIsChannel(itemId.peer)
  15. ? UniversalMsgId(itemId.msg)
  16. : UniversalMsgId(itemId.msg - ServerMaxMsgId);
  17. }
  18. UniversalMsgId GetUniversalId(not_null<const HistoryItem*> item) {
  19. return GetUniversalId(item->fullId());
  20. }
  21. UniversalMsgId GetUniversalId(not_null<const BaseLayout*> layout) {
  22. return GetUniversalId(layout->getItem()->fullId());
  23. }
  24. bool ChangeItemSelection(
  25. ListSelectedMap &selected,
  26. not_null<const HistoryItem*> item,
  27. ListItemSelectionData selectionData) {
  28. const auto changeExisting = [&](auto it) {
  29. if (it == selected.cend()) {
  30. return false;
  31. } else if (it->second != selectionData) {
  32. it->second = selectionData;
  33. return true;
  34. }
  35. return false;
  36. };
  37. if (selected.size() < MaxSelectedItems) {
  38. const auto &[i, ok] = selected.try_emplace(item, selectionData);
  39. if (ok) {
  40. return true;
  41. }
  42. return changeExisting(i);
  43. }
  44. return changeExisting(selected.find(item));
  45. }
  46. int MinItemHeight(Type type, int width) {
  47. auto &songSt = st::overviewFileLayout;
  48. switch (type) {
  49. case Type::Photo:
  50. case Type::GIF:
  51. case Type::Video:
  52. case Type::RoundFile: {
  53. auto itemsLeft = st::infoMediaSkip;
  54. auto itemsInRow = (width - itemsLeft)
  55. / (st::infoMediaMinGridSize + st::infoMediaSkip);
  56. return (st::infoMediaMinGridSize + st::infoMediaSkip) / itemsInRow;
  57. } break;
  58. case Type::RoundVoiceFile:
  59. return songSt.songPadding.top()
  60. + songSt.songThumbSize
  61. + songSt.songPadding.bottom()
  62. + st::lineWidth;
  63. case Type::File:
  64. return songSt.filePadding.top()
  65. + songSt.fileThumbSize
  66. + songSt.filePadding.bottom()
  67. + st::lineWidth;
  68. case Type::MusicFile:
  69. return songSt.songPadding.top()
  70. + songSt.songThumbSize
  71. + songSt.songPadding.bottom();
  72. case Type::Link:
  73. return st::linksPhotoSize
  74. + st::linksMargin.top()
  75. + st::linksMargin.bottom()
  76. + st::linksBorder;
  77. }
  78. Unexpected("Type in MinItemHeight()");
  79. }
  80. } // namespace Info::Media