support_autocomplete.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/layers/box_content.h"
  10. #include "history/admin_log/history_admin_log_item.h"
  11. #include "history/view/history_view_element.h"
  12. #include "history/history.h"
  13. namespace Main {
  14. class Session;
  15. } // namespace Main
  16. namespace Window {
  17. class SessionController;
  18. } // namespace Window
  19. namespace Ui {
  20. class ScrollArea;
  21. class InputField;
  22. class ChatStyle;
  23. } // namespace Ui
  24. namespace Support {
  25. struct Contact {
  26. QString comment;
  27. QString phone;
  28. QString firstName;
  29. QString lastName;
  30. };
  31. class Autocomplete final : public Ui::RpWidget {
  32. public:
  33. Autocomplete(QWidget *parent, not_null<Main::Session*> session);
  34. void activate(not_null<Ui::InputField*> field);
  35. void deactivate();
  36. void setBoundings(QRect rect);
  37. rpl::producer<QString> insertRequests() const;
  38. rpl::producer<Contact> shareContactRequests() const;
  39. protected:
  40. void keyPressEvent(QKeyEvent *e) override;
  41. private:
  42. void setupContent();
  43. void submitValue(const QString &value);
  44. not_null<Main::Session*> _session;
  45. Fn<void()> _activate;
  46. Fn<void()> _deactivate;
  47. Fn<void(int delta)> _moveSelection;
  48. rpl::event_stream<QString> _insertRequests;
  49. rpl::event_stream<Contact> _shareContactRequests;
  50. };
  51. class ConfirmContactBox
  52. : public Ui::BoxContent
  53. , public HistoryView::SimpleElementDelegate {
  54. public:
  55. ConfirmContactBox(
  56. QWidget*,
  57. not_null<Window::SessionController*> controller,
  58. not_null<History*> history,
  59. const Contact &data,
  60. Fn<void(Qt::KeyboardModifiers)> submit);
  61. using Element = HistoryView::Element;
  62. HistoryView::Context elementContext() override;
  63. protected:
  64. void prepare() override;
  65. void paintEvent(QPaintEvent *e) override;
  66. void keyPressEvent(QKeyEvent *e) override;
  67. private:
  68. std::unique_ptr<Ui::ChatStyle> _chatStyle;
  69. AdminLog::OwnedItem _comment;
  70. AdminLog::OwnedItem _contact;
  71. Fn<void(Qt::KeyboardModifiers)> _submit;
  72. };
  73. } //namespace Support