Remove some code duplication.

This commit is contained in:
John Preston 2024-07-25 16:09:46 +02:00
parent 4b09050061
commit 031233ea98
2 changed files with 431 additions and 435 deletions

File diff suppressed because it is too large Load diff

View file

@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/rp_widget.h" #include "ui/rp_widget.h"
class PeerListContent;
namespace Data { namespace Data {
class Thread; class Thread;
} // namespace Data } // namespace Data
@ -67,17 +69,19 @@ public:
} }
[[nodiscard]] auto recentPeerChosen() const [[nodiscard]] auto recentPeerChosen() const
-> rpl::producer<not_null<PeerData*>> { -> rpl::producer<not_null<PeerData*>> {
return _recentPeerChosen.events(); return _recent->chosen.events();
} }
[[nodiscard]] auto myChannelChosen() const [[nodiscard]] auto myChannelChosen() const
-> rpl::producer<not_null<PeerData*>> { -> rpl::producer<not_null<PeerData*>> {
return _myChannelChosen.events(); return _myChannels->chosen.events();
} }
[[nodiscard]] auto recommendationChosen() const [[nodiscard]] auto recommendationChosen() const
-> rpl::producer<not_null<PeerData*>> { -> rpl::producer<not_null<PeerData*>> {
return _recommendationChosen.events(); return _recommendations->chosen.events();
} }
class ObjectListController;
private: private:
enum class Tab : uchar { enum class Tab : uchar {
Chats, Chats,
@ -89,6 +93,17 @@ private:
AppliedAndOut, AppliedAndOut,
}; };
struct ObjectList {
not_null<Ui::SlideWrap<PeerListContent>*> wrap;
rpl::variable<int> count;
Fn<bool()> choose;
Fn<JumpResult(Qt::Key, int)> selectJump;
Fn<uint64(QPoint)> updateFromParentDrag;
Fn<void()> dragLeft;
Fn<bool(not_null<QTouchEvent*>)> processTouch;
rpl::event_stream<not_null<PeerData*>> chosen;
};
void paintEvent(QPaintEvent *e) override; void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override; void resizeEvent(QResizeEvent *e) override;
@ -104,14 +119,22 @@ private:
QPoint globalPosition); QPoint globalPosition);
[[nodiscard]] Data::Thread *fromListId(uint64 peerListRowId); [[nodiscard]] Data::Thread *fromListId(uint64 peerListRowId);
[[nodiscard]] object_ptr<Ui::SlideWrap<Ui::RpWidget>> setupRecentPeers( [[nodiscard]] std::unique_ptr<ObjectList> setupRecentPeers(
RecentPeersList recentPeers); RecentPeersList recentPeers);
[[nodiscard]] object_ptr<Ui::SlideWrap<Ui::RpWidget>> setupEmptyRecent(); [[nodiscard]] auto setupEmptyRecent()
[[nodiscard]] object_ptr<Ui::SlideWrap<Ui::RpWidget>> setupMyChannels();
[[nodiscard]] auto setupRecommendations()
-> object_ptr<Ui::SlideWrap<Ui::RpWidget>>; -> object_ptr<Ui::SlideWrap<Ui::RpWidget>>;
[[nodiscard]] std::unique_ptr<ObjectList> setupMyChannels();
[[nodiscard]] std::unique_ptr<ObjectList> setupRecommendations();
[[nodiscard]] auto setupEmptyChannels() [[nodiscard]] auto setupEmptyChannels()
-> object_ptr<Ui::SlideWrap<Ui::RpWidget>>; -> object_ptr<Ui::SlideWrap<Ui::RpWidget>>;
[[nodiscard]] std::unique_ptr<ObjectList> setupObjectList(
not_null<Ui::ElasticScroll*> scroll,
not_null<Ui::VerticalLayout*> parent,
not_null<ObjectListController*> controller,
Fn<int()> addToScroll = nullptr);
[[nodiscard]] object_ptr<Ui::SlideWrap<Ui::RpWidget>> setupEmpty( [[nodiscard]] object_ptr<Ui::SlideWrap<Ui::RpWidget>> setupEmpty(
not_null<QWidget*> parent, not_null<QWidget*> parent,
SearchEmptyIcon icon, SearchEmptyIcon icon,
@ -131,44 +154,23 @@ private:
const std::unique_ptr<Ui::ElasticScroll> _chatsScroll; const std::unique_ptr<Ui::ElasticScroll> _chatsScroll;
const not_null<Ui::VerticalLayout*> _chatsContent; const not_null<Ui::VerticalLayout*> _chatsContent;
const not_null<Ui::SlideWrap<TopPeersStrip>*> _topPeersWrap; const not_null<Ui::SlideWrap<TopPeersStrip>*> _topPeersWrap;
const not_null<TopPeersStrip*> _topPeers; const not_null<TopPeersStrip*> _topPeers;
rpl::event_stream<not_null<PeerData*>> _topPeerChosen;
const std::unique_ptr<ObjectList> _recent;
rpl::variable<int> _recentCount;
Fn<bool()> _recentPeersChoose;
Fn<JumpResult(Qt::Key, int)> _recentSelectJump;
Fn<uint64(QPoint)> _recentUpdateFromParentDrag;
Fn<void()> _recentDragLeft;
Fn<bool(not_null<QTouchEvent*>)> _recentProcessTouch;
const not_null<Ui::SlideWrap<Ui::RpWidget>*> _recentPeers;
const not_null<Ui::SlideWrap<Ui::RpWidget>*> _emptyRecent; const not_null<Ui::SlideWrap<Ui::RpWidget>*> _emptyRecent;
const std::unique_ptr<Ui::ElasticScroll> _channelsScroll; const std::unique_ptr<Ui::ElasticScroll> _channelsScroll;
const not_null<Ui::VerticalLayout*> _channelsContent; const not_null<Ui::VerticalLayout*> _channelsContent;
rpl::variable<int> _myChannelsCount; const std::unique_ptr<ObjectList> _myChannels;
Fn<bool()> _myChannelsChoose; const std::unique_ptr<ObjectList> _recommendations;
Fn<JumpResult(Qt::Key, int)> _myChannelsSelectJump;
Fn<uint64(QPoint)> _myChannelsUpdateFromParentDrag;
Fn<void()> _myChannelsDragLeft;
Fn<bool(not_null<QTouchEvent*>)> _myChannelsProcessTouch;
const not_null<Ui::SlideWrap<Ui::RpWidget>*> _myChannels;
rpl::variable<int> _recommendationsCount;
Fn<bool()> _recommendationsChoose;
Fn<JumpResult(Qt::Key, int)> _recommendationsSelectJump;
Fn<uint64(QPoint)> _recommendationsUpdateFromParentDrag;
Fn<void()> _recommendationsDragLeft;
Fn<bool(not_null<QTouchEvent*>)> _recommendationsProcessTouch;
const not_null<Ui::SlideWrap<Ui::RpWidget>*> _recommendations;
const not_null<Ui::SlideWrap<Ui::RpWidget>*> _emptyChannels; const not_null<Ui::SlideWrap<Ui::RpWidget>*> _emptyChannels;
rpl::event_stream<not_null<PeerData*>> _topPeerChosen;
rpl::event_stream<not_null<PeerData*>> _recentPeerChosen;
rpl::event_stream<not_null<PeerData*>> _myChannelChosen;
rpl::event_stream<not_null<PeerData*>> _recommendationChosen;
Ui::Animations::Simple _shownAnimation; Ui::Animations::Simple _shownAnimation;
Fn<void()> _showFinished; Fn<void()> _showFinished;
bool _hidden = false; bool _hidden = false;