Added right button to rows of usernames list for reorder.

This commit is contained in:
23rd 2022-10-13 02:17:50 +03:00 committed by John Preston
parent 00df4625e2
commit 4207995ef0
3 changed files with 56 additions and 2 deletions

View file

@ -28,6 +28,35 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QGuiApplication> #include <QtGui/QGuiApplication>
namespace {
class RightAction final : public Ui::RpWidget {
public:
RightAction(not_null<Ui::RpWidget*> parent);
protected:
void paintEvent(QPaintEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
};
RightAction::RightAction(not_null<Ui::RpWidget*> parent)
: RpWidget(parent) {
setCursor(style::cur_sizeall);
const auto &st = st::inviteLinkThreeDots;
resize(st.width, st.height);
}
void RightAction::paintEvent(QPaintEvent *e) {
auto p = Painter(this);
st::usernamesReorderIcon.paintInCenter(p, rect());
}
void RightAction::mousePressEvent(QMouseEvent *e) {
}
} // namespace
class UsernamesList::Row final : public Ui::SettingsButton { class UsernamesList::Row final : public Ui::SettingsButton {
public: public:
Row( Row(
@ -37,6 +66,7 @@ public:
QString link); QString link);
[[nodiscard]] const Data::Username &username() const; [[nodiscard]] const Data::Username &username() const;
[[nodiscard]] not_null<Ui::RpWidget*> rightAction() const;
int resizeGetHeight(int newWidth) override; int resizeGetHeight(int newWidth) override;
@ -47,6 +77,7 @@ private:
const style::PeerListItem &_st; const style::PeerListItem &_st;
const Data::Username _data; const Data::Username _data;
const QString _status; const QString _status;
const not_null<Ui::RpWidget*> _rightAction;
const QRect _iconRect; const QRect _iconRect;
std::shared_ptr<Ui::Show> _show; std::shared_ptr<Ui::Show> _show;
Ui::Text::String _title; Ui::Text::String _title;
@ -65,6 +96,7 @@ UsernamesList::Row::Row(
, _status(data.active , _status(data.active
? tr::lng_usernames_active(tr::now) ? tr::lng_usernames_active(tr::now)
: tr::lng_usernames_non_active(tr::now)) : tr::lng_usernames_non_active(tr::now))
, _rightAction(Ui::CreateChild<RightAction>(this))
, _iconRect( , _iconRect(
_st.photoPosition.x() + st::inviteLinkIconSkip, _st.photoPosition.x() + st::inviteLinkIconSkip,
_st.photoPosition.y() + st::inviteLinkIconSkip, _st.photoPosition.y() + st::inviteLinkIconSkip,
@ -91,12 +123,24 @@ UsernamesList::Row::Row(
_menu->popup(QCursor::pos()); _menu->popup(QCursor::pos());
return base::EventFilterResult::Cancel; return base::EventFilterResult::Cancel;
}); });
_rightAction->setVisible(data.active);
sizeValue(
) | rpl::start_with_next([=](const QSize &s) {
_rightAction->moveToLeft(
s.width() - _rightAction->width() - st::inviteLinkThreeDotsSkip,
(s.height() - _rightAction->height()) / 2);
}, _rightAction->lifetime());
} }
const Data::Username &UsernamesList::Row::username() const { const Data::Username &UsernamesList::Row::username() const {
return _data; return _data;
} }
not_null<Ui::RpWidget*> UsernamesList::Row::rightAction() const {
return _rightAction;
}
int UsernamesList::Row::resizeGetHeight(int newWidth) { int UsernamesList::Row::resizeGetHeight(int newWidth) {
return _st.height; return _st.height;
} }
@ -252,6 +296,9 @@ void UsernamesList::rebuild(const Data::Usernames &usernames) {
} }
_reorder = std::make_unique<Ui::VerticalLayoutReorder>(content); _reorder = std::make_unique<Ui::VerticalLayoutReorder>(content);
_reorder->setMouseEventProxy([=](int i) {
return _rows[i]->rightAction();
});
{ {
const auto it = ranges::find_if(usernames, [&]( const auto it = ranges::find_if(usernames, [&](
@ -262,6 +309,10 @@ void UsernamesList::rebuild(const Data::Usernames &usernames) {
const auto from = std::distance(begin(usernames), it); const auto from = std::distance(begin(usernames), it);
const auto length = std::distance(it, end(usernames)); const auto length = std::distance(it, end(usernames));
_reorder->addPinnedInterval(from, length); _reorder->addPinnedInterval(from, length);
if (from == 1) {
// Can't be reordered.
_rows[0]->rightAction()->hide();
}
} }
} }
_reorder->start(); _reorder->start();

View file

@ -38,10 +38,11 @@ private:
class Row; class Row;
const std::shared_ptr<Ui::Show> _show;
const not_null<PeerData*> _peer;
base::unique_qptr<Ui::VerticalLayout> _container; base::unique_qptr<Ui::VerticalLayout> _container;
std::unique_ptr<Ui::VerticalLayoutReorder> _reorder; std::unique_ptr<Ui::VerticalLayoutReorder> _reorder;
std::shared_ptr<Ui::Show> _show;
const not_null<PeerData*> _peer;
std::vector<Row*> _rows; std::vector<Row*> _rows;
int _reordering = 0; int _reordering = 0;

View file

@ -853,6 +853,8 @@ inviteLinkQrSkip: 24px;
inviteLinkQrMargin: margins(0px, 0px, 0px, 13px); inviteLinkQrMargin: margins(0px, 0px, 0px, 13px);
inviteLinkQrValuePadding: margins(22px, 0px, 22px, 12px); inviteLinkQrValuePadding: margins(22px, 0px, 22px, 12px);
usernamesReorderIcon: icon {{ "stickers_reorder", dialogsMenuIconFg }};
infoAboutGigagroup: FlatLabel(defaultFlatLabel) { infoAboutGigagroup: FlatLabel(defaultFlatLabel) {
minWidth: 274px; minWidth: 274px;
} }