chat_search_empty.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "dialogs/ui/chat_search_empty.h"
  8. #include "base/object_ptr.h"
  9. #include "lottie/lottie_icon.h"
  10. #include "settings/settings_common.h"
  11. #include "ui/widgets/labels.h"
  12. #include "styles/style_dialogs.h"
  13. namespace Dialogs {
  14. SearchEmpty::SearchEmpty(
  15. QWidget *parent,
  16. Icon icon,
  17. rpl::producer<TextWithEntities> text)
  18. : RpWidget(parent) {
  19. setup(icon, std::move(text));
  20. }
  21. void SearchEmpty::setMinimalHeight(int minimalHeight) {
  22. const auto minimal = st::recentPeersEmptyHeightMin;
  23. resize(width(), std::max(minimalHeight, minimal));
  24. }
  25. void SearchEmpty::setup(Icon icon, rpl::producer<TextWithEntities> text) {
  26. const auto label = Ui::CreateChild<Ui::FlatLabel>(
  27. this,
  28. std::move(text),
  29. st::defaultPeerListAbout);
  30. const auto size = st::recentPeersEmptySize;
  31. const auto animation = [&] {
  32. switch (icon) {
  33. case Icon::Search: return u"search"_q;
  34. case Icon::NoResults: return u"noresults"_q;
  35. }
  36. Unexpected("Icon in SearchEmpty::setup.");
  37. }();
  38. const auto [widget, animate] = Settings::CreateLottieIcon(
  39. this,
  40. {
  41. .name = animation,
  42. .sizeOverride = { size, size },
  43. },
  44. st::recentPeersEmptyMargin);
  45. const auto animated = widget.data();
  46. sizeValue() | rpl::start_with_next([=](QSize size) {
  47. const auto padding = st::recentPeersEmptyMargin;
  48. const auto paddings = padding.left() + padding.right();
  49. label->resizeToWidth(size.width() - paddings);
  50. const auto x = (size.width() - animated->width()) / 2;
  51. const auto y = (size.height() - animated->height()) / 3;
  52. const auto top = y + animated->height() + st::recentPeersEmptySkip;
  53. const auto sub = std::max(top + label->height() - size.height(), 0);
  54. animated->move(x, y - sub);
  55. label->move((size.width() - label->width()) / 2, top - sub);
  56. }, lifetime());
  57. label->setClickHandlerFilter([=](
  58. const ClickHandlerPtr &handler,
  59. Qt::MouseButton) {
  60. _handlerActivated.fire_copy(handler);
  61. return false;
  62. });
  63. _animate = [animate] {
  64. animate(anim::repeat::once);
  65. };
  66. }
  67. void SearchEmpty::animate() {
  68. if (const auto onstack = _animate) {
  69. onstack();
  70. }
  71. }
  72. } // namespace Dialogs