bot_keyboard.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/widgets/tooltip.h"
  9. #include "chat_helpers/bot_command.h"
  10. class ReplyKeyboard;
  11. namespace style {
  12. struct BotKeyboardButton;
  13. } // namespace style
  14. namespace Window {
  15. class SessionController;
  16. } // namespace Window
  17. class BotKeyboard
  18. : public TWidget
  19. , public Ui::AbstractTooltipShower
  20. , public ClickHandlerHost {
  21. public:
  22. BotKeyboard(
  23. not_null<Window::SessionController*> controller,
  24. QWidget *parent);
  25. bool moderateKeyActivate(int index, Fn<ClickContext(FullMsgId)> context);
  26. // With force=true the markup is updated even if it is
  27. // already shown for the passed history item.
  28. bool updateMarkup(HistoryItem *last, bool force = false);
  29. [[nodiscard]] bool hasMarkup() const;
  30. [[nodiscard]] bool forceReply() const;
  31. [[nodiscard]] QString placeholder() const {
  32. return _placeholder;
  33. }
  34. void step_selected(crl::time ms, bool timer);
  35. void resizeToWidth(int newWidth, int maxOuterHeight) {
  36. _maxOuterHeight = maxOuterHeight;
  37. return TWidget::resizeToWidth(newWidth);
  38. }
  39. [[nodiscard]] bool maximizeSize() const;
  40. [[nodiscard]] bool singleUse() const;
  41. [[nodiscard]] bool persistent() const;
  42. [[nodiscard]] FullMsgId forMsgId() const {
  43. return _wasForMsgId;
  44. }
  45. // AbstractTooltipShower interface
  46. QString tooltipText() const override;
  47. QPoint tooltipPos() const override;
  48. bool tooltipWindowActive() const override;
  49. // ClickHandlerHost interface
  50. void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
  51. void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
  52. rpl::producer<Bot::SendCommandRequest> sendCommandRequests() const;
  53. ~BotKeyboard();
  54. protected:
  55. int resizeGetHeight(int newWidth) override;
  56. void paintEvent(QPaintEvent *e) override;
  57. void mousePressEvent(QMouseEvent *e) override;
  58. void mouseMoveEvent(QMouseEvent *e) override;
  59. void mouseReleaseEvent(QMouseEvent *e) override;
  60. void enterEventHook(QEnterEvent *e) override;
  61. void leaveEventHook(QEvent *e) override;
  62. private:
  63. void updateSelected();
  64. void updateStyle(int newWidth);
  65. void clearSelection();
  66. const not_null<Window::SessionController*> _controller;
  67. FullMsgId _wasForMsgId;
  68. QString _placeholder;
  69. int _height = 0;
  70. int _maxOuterHeight = 0;
  71. bool _maximizeSize = false;
  72. bool _singleUse = false;
  73. bool _forceReply = false;
  74. bool _persistent = false;
  75. QPoint _lastMousePos;
  76. std::unique_ptr<ReplyKeyboard> _impl;
  77. rpl::event_stream<Bot::SendCommandRequest> _sendCommandRequests;
  78. const style::BotKeyboardButton *_st = nullptr;
  79. };