inline_results_widget.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. #pragma once
  8. #include "ui/rp_widget.h"
  9. #include "ui/abstract_button.h"
  10. #include "ui/cached_round_corners.h"
  11. #include "ui/widgets/tooltip.h"
  12. #include "ui/effects/animations.h"
  13. #include "ui/effects/panel_animation.h"
  14. #include "base/timer.h"
  15. #include "mtproto/sender.h"
  16. #include "inline_bots/inline_bot_layout_item.h"
  17. namespace Api {
  18. struct SendOptions;
  19. } // namespace Api
  20. namespace Ui {
  21. class ScrollArea;
  22. class IconButton;
  23. class LinkButton;
  24. class RoundButton;
  25. class FlatLabel;
  26. class RippleAnimation;
  27. class PopupMenu;
  28. } // namespace Ui
  29. namespace Dialogs {
  30. struct EntryState;
  31. } // namespace Dialogs
  32. namespace Window {
  33. class SessionController;
  34. } // namespace Window
  35. namespace InlineBots {
  36. class Result;
  37. struct ResultSelected;
  38. } // namespace InlineBots
  39. namespace SendMenu {
  40. struct Details;
  41. } // namespace SendMenu
  42. namespace InlineBots {
  43. namespace Layout {
  44. struct CacheEntry;
  45. class Inner;
  46. class Widget : public Ui::RpWidget {
  47. public:
  48. Widget(QWidget *parent, not_null<Window::SessionController*> controller);
  49. ~Widget();
  50. void moveBottom(int bottom);
  51. void hideFast();
  52. bool hiding() const {
  53. return _hiding;
  54. }
  55. void queryInlineBot(UserData *bot, PeerData *peer, QString query);
  56. void clearInlineBot();
  57. bool overlaps(const QRect &globalRect) const;
  58. void showAnimated();
  59. void hideAnimated();
  60. void setResultSelectedCallback(Fn<void(ResultSelected)> callback);
  61. void setSendMenuDetails(Fn<SendMenu::Details()> &&callback);
  62. [[nodiscard]] rpl::producer<bool> requesting() const {
  63. return _requesting.events();
  64. }
  65. protected:
  66. void paintEvent(QPaintEvent *e) override;
  67. private:
  68. void moveByBottom();
  69. void paintContent(QPainter &p);
  70. style::margins innerPadding() const;
  71. void onScroll();
  72. void onInlineRequest();
  73. // Rounded rect which has shadow around it.
  74. QRect innerRect() const;
  75. // Inner rect with removed st::roundRadiusSmall from top and bottom.
  76. // This one is allowed to be not rounded.
  77. QRect horizontalRect() const;
  78. // Inner rect with removed st::roundRadiusSmall from left and right.
  79. // This one is allowed to be not rounded.
  80. QRect verticalRect() const;
  81. QImage grabForPanelAnimation();
  82. void startShowAnimation();
  83. void startOpacityAnimation(bool hiding);
  84. void prepareCache();
  85. class Container;
  86. void opacityAnimationCallback();
  87. void hideFinished();
  88. void showStarted();
  89. void updateContentHeight();
  90. void inlineBotChanged();
  91. int showInlineRows(bool newResults);
  92. void recountContentMaxHeight();
  93. bool refreshInlineRows(int *added = nullptr);
  94. void inlineResultsDone(const MTPmessages_BotResults &result);
  95. const not_null<Window::SessionController*> _controller;
  96. MTP::Sender _api;
  97. int _contentMaxHeight = 0;
  98. int _contentHeight = 0;
  99. int _width = 0;
  100. int _height = 0;
  101. int _bottom = 0;
  102. std::unique_ptr<Ui::PanelAnimation> _showAnimation;
  103. Ui::Animations::Simple _a_show;
  104. bool _hiding = false;
  105. QPixmap _cache;
  106. Ui::Animations::Simple _a_opacity;
  107. bool _inPanelGrab = false;
  108. object_ptr<Ui::ScrollArea> _scroll;
  109. QPointer<Inner> _inner;
  110. Ui::CornersPixmaps _innerRounding;
  111. std::map<QString, std::unique_ptr<CacheEntry>> _inlineCache;
  112. base::Timer _inlineRequestTimer;
  113. UserData *_inlineBot = nullptr;
  114. PeerData *_inlineQueryPeer = nullptr;
  115. QString _inlineQuery, _inlineNextQuery, _inlineNextOffset;
  116. mtpRequestId _inlineRequestId = 0;
  117. rpl::event_stream<bool> _requesting;
  118. };
  119. } // namespace Layout
  120. } // namespace InlineBots