tdesktop/Telegram/SourceFiles/dialogs/ui/top_peers_strip.h

152 lines
4 KiB
C
Raw Normal View History

2024-04-09 15:04:18 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/weak_ptr.h"
2024-04-22 15:01:18 +00:00
#include "ui/effects/animations.h"
2024-04-09 15:04:18 +00:00
#include "ui/widgets/menu/menu_add_action_callback.h"
2024-04-11 09:36:41 +00:00
#include "ui/round_rect.h"
2024-04-09 15:04:18 +00:00
#include "ui/rp_widget.h"
namespace Ui {
class DynamicImage;
2024-04-22 15:01:18 +00:00
class LinkButton;
2024-04-23 05:07:53 +00:00
struct ScrollToRequest;
2024-04-09 15:04:18 +00:00
} // namespace Ui
namespace Dialogs {
struct TopPeersEntry {
uint64 id = 0;
QString name;
std::shared_ptr<Ui::DynamicImage> userpic;
uint32 badge : 28 = 0;
2024-04-11 08:41:32 +00:00
uint32 unread : 1 = 0;
2024-04-09 15:04:18 +00:00
uint32 muted : 1 = 0;
uint32 online : 1 = 0;
};
struct TopPeersList {
std::vector<TopPeersEntry> entries;
};
struct ShowTopPeerMenuRequest {
uint64 id = 0;
Ui::Menu::MenuCallback callback;
};
class TopPeersStrip final : public Ui::RpWidget {
public:
TopPeersStrip(
not_null<QWidget*> parent,
rpl::producer<TopPeersList> content);
~TopPeersStrip();
[[nodiscard]] bool empty() const;
[[nodiscard]] rpl::producer<bool> emptyValue() const;
[[nodiscard]] rpl::producer<uint64> clicks() const;
2024-05-31 11:01:43 +00:00
[[nodiscard]] rpl::producer<uint64> pressed() const;
[[nodiscard]] rpl::producer<> pressCancelled() const;
2024-04-09 15:04:18 +00:00
[[nodiscard]] auto showMenuRequests() const
-> rpl::producer<ShowTopPeerMenuRequest>;
2024-04-23 05:07:53 +00:00
[[nodiscard]] auto scrollToRequests() const
-> rpl::producer<Ui::ScrollToRequest>;
2024-04-09 15:04:18 +00:00
void removeLocally(uint64 id = 0);
2024-04-11 09:12:57 +00:00
2024-04-11 09:55:38 +00:00
[[nodiscard]] bool selectedByKeyboard() const;
2024-04-23 05:07:53 +00:00
bool selectByKeyboard(Qt::Key direction);
2024-04-11 09:55:38 +00:00
void deselectByKeyboard();
bool chooseRow();
void pressLeftToContextMenu(bool shown);
2024-04-11 09:55:38 +00:00
uint64 updateFromParentDrag(QPoint globalPosition);
void dragLeft();
[[nodiscard]] auto verticalScrollEvents() const
-> rpl::producer<not_null<QWheelEvent*>>;
2024-04-09 15:04:18 +00:00
private:
struct Entry;
2024-04-22 15:01:18 +00:00
struct Layout;
2024-04-09 15:04:18 +00:00
2024-04-22 15:01:18 +00:00
int resizeGetHeight(int newWidth) override;
2024-04-09 15:04:18 +00:00
2024-04-22 15:01:18 +00:00
void setupHeader();
void setupStrip();
void paintStrip(QRect clip);
void stripWheelEvent(QWheelEvent *e);
void stripMousePressEvent(QMouseEvent *e);
void stripMouseMoveEvent(QMouseEvent *e);
void stripMouseReleaseEvent(QMouseEvent *e);
void stripContextMenuEvent(QContextMenuEvent *e);
void stripLeaveEvent(QEvent *e);
void updateScrollMax(int newWidth = 0);
2024-04-09 15:04:18 +00:00
void updateSelected();
2024-04-11 09:55:38 +00:00
void setSelected(int selected);
2024-04-22 15:01:18 +00:00
void setExpanded(bool expanded);
2024-04-11 09:55:38 +00:00
void scrollToSelected();
2024-04-09 15:04:18 +00:00
void checkDragging();
bool finishDragging();
void subscribeUserpic(Entry &entry);
void unsubscribeUserpics(bool all = false);
2024-04-22 15:01:18 +00:00
void paintUserpic(Painter &p, int x, int y, int index, bool selected);
void clearSelection();
void selectByMouse(QPoint globalPosition);
2024-04-09 15:04:18 +00:00
2024-04-11 09:36:41 +00:00
[[nodiscard]] QRect outer() const;
[[nodiscard]] QRect innerRounded() const;
2024-04-22 15:01:18 +00:00
[[nodiscard]] int scrollLeft() const;
[[nodiscard]] Layout currentLayout() const;
int clearPressed();
2024-04-09 15:04:18 +00:00
void apply(const TopPeersList &list);
void apply(Entry &entry, const TopPeersEntry &data);
2024-04-22 15:01:18 +00:00
Ui::RpWidget _header;
Ui::RpWidget _strip;
2024-04-09 15:04:18 +00:00
std::vector<Entry> _entries;
2024-04-22 15:01:18 +00:00
rpl::variable<int> _count = 0;
2024-04-11 09:12:57 +00:00
base::flat_set<uint64> _removed;
2024-04-22 15:01:18 +00:00
rpl::variable<Ui::LinkButton*> _toggleExpanded = nullptr;
2024-04-09 15:04:18 +00:00
rpl::event_stream<uint64> _clicks;
2024-05-31 11:01:43 +00:00
rpl::event_stream<uint64> _presses;
rpl::event_stream<> _pressCancelled;
2024-04-09 15:04:18 +00:00
rpl::event_stream<ShowTopPeerMenuRequest> _showMenuRequests;
rpl::event_stream<not_null<QWheelEvent*>> _verticalScrollEvents;
2024-04-23 05:07:53 +00:00
std::optional<QPoint> _lastMousePosition;
2024-04-09 15:04:18 +00:00
std::optional<QPoint> _mouseDownPosition;
int _startDraggingLeft = 0;
int _scrollLeft = 0;
int _scrollLeftMax = 0;
bool _dragging = false;
Qt::Orientation _scrollingLock = {};
int _selected = -1;
int _pressed = -1;
int _contexted = -1;
2024-04-11 09:55:38 +00:00
bool _selectionByKeyboard = false;
bool _hiddenLocally = false;
2024-04-09 15:04:18 +00:00
2024-04-22 15:01:18 +00:00
Ui::Animations::Simple _expandAnimation;
rpl::variable<bool> _expanded = false;
2024-04-23 05:07:53 +00:00
rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests;
2024-04-11 09:36:41 +00:00
Ui::RoundRect _selection;
2024-04-09 15:04:18 +00:00
base::unique_qptr<Ui::PopupMenu> _menu;
base::has_weak_ptr _menuGuard;
};
} // namespace Dialogs