chat_search_in.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "base/unique_qptr.h"
  9. #include "ui/rp_widget.h"
  10. namespace Ui {
  11. class PlainShadow;
  12. class DynamicImage;
  13. class IconButton;
  14. class PopupMenu;
  15. } // namespace Ui
  16. namespace Dialogs {
  17. enum class ChatSearchTab : uchar {
  18. MyMessages,
  19. ThisTopic,
  20. ThisPeer,
  21. PublicPosts,
  22. };
  23. enum class ChatSearchPeerTabType : uchar {
  24. Chat,
  25. Channel,
  26. Group,
  27. };
  28. class ChatSearchIn final : public Ui::RpWidget {
  29. public:
  30. explicit ChatSearchIn(QWidget *parent);
  31. ~ChatSearchIn();
  32. struct PossibleTab {
  33. ChatSearchTab tab = {};
  34. std::shared_ptr<Ui::DynamicImage> icon;
  35. };
  36. void apply(
  37. std::vector<PossibleTab> tabs,
  38. ChatSearchTab active,
  39. ChatSearchPeerTabType peerTabType,
  40. std::shared_ptr<Ui::DynamicImage> fromUserpic,
  41. QString fromName);
  42. [[nodiscard]] rpl::producer<> cancelInRequests() const;
  43. [[nodiscard]] rpl::producer<> cancelFromRequests() const;
  44. [[nodiscard]] rpl::producer<> changeFromRequests() const;
  45. [[nodiscard]] rpl::producer<ChatSearchTab> tabChanges() const;
  46. private:
  47. struct Section {
  48. std::unique_ptr<Ui::RpWidget> outer;
  49. std::unique_ptr<Ui::IconButton> cancel;
  50. std::unique_ptr<Ui::PlainShadow> shadow;
  51. std::shared_ptr<Ui::DynamicImage> image;
  52. Ui::Text::String text;
  53. rpl::event_stream<> clicks;
  54. rpl::event_stream<> cancelRequests;
  55. bool subscribed = false;
  56. void update();
  57. };
  58. int resizeGetHeight(int newWidth) override;
  59. void paintEvent(QPaintEvent *e) override;
  60. void showMenu();
  61. void updateSection(
  62. not_null<Section*> section,
  63. std::shared_ptr<Ui::DynamicImage> image,
  64. TextWithEntities text);
  65. Section _in;
  66. Section _from;
  67. rpl::variable<ChatSearchTab> _active;
  68. base::unique_qptr<Ui::PopupMenu> _menu;
  69. std::vector<PossibleTab> _tabs;
  70. ChatSearchPeerTabType _peerTabType = ChatSearchPeerTabType::Chat;
  71. };
  72. enum class HashOrCashtag : uchar {
  73. None,
  74. Hashtag,
  75. Cashtag,
  76. };
  77. struct FixedHashtagSearchQuery {
  78. QString text;
  79. int cursorPosition = 0;
  80. };
  81. [[nodiscard]] FixedHashtagSearchQuery FixHashtagSearchQuery(
  82. const QString &query,
  83. int cursorPosition,
  84. HashOrCashtag tag);
  85. [[nodiscard]] HashOrCashtag IsHashOrCashtagSearchQuery(const QString &query);
  86. } // namespace Dialogs