peer_lists_box.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 "boxes/peer_list_box.h"
  9. class PeerListsBox : public Ui::BoxContent {
  10. public:
  11. PeerListsBox(
  12. QWidget*,
  13. std::vector<std::unique_ptr<PeerListController>> controllers,
  14. Fn<void(not_null<PeerListsBox*>)> init);
  15. [[nodiscard]] std::vector<not_null<PeerData*>> collectSelectedRows();
  16. protected:
  17. void prepare() override;
  18. void setInnerFocus() override;
  19. void keyPressEvent(QKeyEvent *e) override;
  20. void resizeEvent(QResizeEvent *e) override;
  21. void paintEvent(QPaintEvent *e) override;
  22. private:
  23. class Delegate final : public PeerListContentDelegate {
  24. public:
  25. Delegate(
  26. not_null<PeerListsBox*> box,
  27. not_null<PeerListController*> controller);
  28. void peerListSetTitle(rpl::producer<QString> title) override;
  29. void peerListSetAdditionalTitle(rpl::producer<QString> title) override;
  30. void peerListSetSearchMode(PeerListSearchMode mode) override;
  31. void peerListSetRowChecked(
  32. not_null<PeerListRow*> row,
  33. bool checked) override;
  34. void peerListSetForeignRowChecked(
  35. not_null<PeerListRow*> row,
  36. bool checked,
  37. anim::type animated) override;
  38. bool peerListIsRowChecked(not_null<PeerListRow*> row) override;
  39. int peerListSelectedRowsCount() override;
  40. void peerListScrollToTop() override;
  41. void peerListAddSelectedPeerInBunch(not_null<PeerData*> peer) override {
  42. _box->addSelectItem(peer, anim::type::instant);
  43. }
  44. void peerListAddSelectedRowInBunch(not_null<PeerListRow*> row) override {
  45. _box->addSelectItem(row, anim::type::instant);
  46. }
  47. void peerListFinishSelectedRowsBunch() override;
  48. std::shared_ptr<Main::SessionShow> peerListUiShow() override;
  49. private:
  50. const not_null<PeerListsBox*> _box;
  51. const not_null<PeerListController*> _controller;
  52. const std::shared_ptr<Main::SessionShow> _show;
  53. };
  54. struct List {
  55. std::unique_ptr<PeerListController> controller;
  56. std::unique_ptr<Delegate> delegate;
  57. PeerListContent *content = nullptr;
  58. };
  59. friend class Delegate;
  60. [[nodiscard]] List makeList(
  61. std::unique_ptr<PeerListController> controller);
  62. [[nodiscard]] std::vector<List> makeLists(
  63. std::vector<std::unique_ptr<PeerListController>> controllers);
  64. [[nodiscard]] not_null<PeerListController*> firstController() const;
  65. void addSelectItem(
  66. not_null<PeerData*> peer,
  67. anim::type animated);
  68. void addSelectItem(
  69. not_null<PeerListRow*> row,
  70. anim::type animated);
  71. void addSelectItem(
  72. uint64 itemId,
  73. const QString &text,
  74. PaintRoundImageCallback paintUserpic,
  75. anim::type animated);
  76. void setSearchMode(PeerListSearchMode mode);
  77. void createMultiSelect();
  78. int getTopScrollSkip() const;
  79. void updateScrollSkips();
  80. void searchQueryChanged(const QString &query);
  81. object_ptr<Ui::SlideWrap<Ui::MultiSelect>> _select = { nullptr };
  82. std::vector<List> _lists;
  83. Fn<void(PeerListsBox*)> _init;
  84. bool _scrollBottomFixed = false;
  85. };