mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added list controller to giveaway box to display selected channels.
This commit is contained in:
parent
3c8188e0b4
commit
33f6fc7d8c
3 changed files with 183 additions and 1 deletions
|
@ -12,11 +12,97 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_peer.h"
|
#include "data/data_peer.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "ui/effects/ripple_animation.h"
|
||||||
|
#include "ui/painter.h"
|
||||||
|
#include "styles/style_statistics.h"
|
||||||
|
|
||||||
namespace Giveaway {
|
namespace Giveaway {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class ChannelRow final : public PeerListRow {
|
||||||
|
public:
|
||||||
|
using PeerListRow::PeerListRow;
|
||||||
|
|
||||||
|
QSize rightActionSize() const override;
|
||||||
|
QMargins rightActionMargins() const override;
|
||||||
|
void rightActionPaint(
|
||||||
|
Painter &p,
|
||||||
|
int x,
|
||||||
|
int y,
|
||||||
|
int outerWidth,
|
||||||
|
bool selected,
|
||||||
|
bool actionSelected) override;
|
||||||
|
|
||||||
|
void rightActionAddRipple(
|
||||||
|
QPoint point,
|
||||||
|
Fn<void()> updateCallback) override;
|
||||||
|
void rightActionStopLastRipple() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<Ui::RippleAnimation> _actionRipple;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
QSize ChannelRow::rightActionSize() const {
|
||||||
|
return QSize(
|
||||||
|
st::giveawayGiftCodeChannelDeleteIcon.width(),
|
||||||
|
st::giveawayGiftCodeChannelDeleteIcon.height()) * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMargins ChannelRow::rightActionMargins() const {
|
||||||
|
return QMargins(
|
||||||
|
0,
|
||||||
|
(st::defaultPeerListItem.height - rightActionSize().height()) / 2,
|
||||||
|
st::giveawayRadioPosition.x() / 2,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChannelRow::rightActionPaint(
|
||||||
|
Painter &p,
|
||||||
|
int x,
|
||||||
|
int y,
|
||||||
|
int outerWidth,
|
||||||
|
bool selected,
|
||||||
|
bool actionSelected) {
|
||||||
|
if (_actionRipple) {
|
||||||
|
_actionRipple->paint(
|
||||||
|
p,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
outerWidth);
|
||||||
|
if (_actionRipple->empty()) {
|
||||||
|
_actionRipple.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const auto rect = QRect(QPoint(x, y), ChannelRow::rightActionSize());
|
||||||
|
(actionSelected
|
||||||
|
? st::giveawayGiftCodeChannelDeleteIconOver
|
||||||
|
: st::giveawayGiftCodeChannelDeleteIcon).paintInCenter(p, rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChannelRow::rightActionAddRipple(
|
||||||
|
QPoint point,
|
||||||
|
Fn<void()> updateCallback) {
|
||||||
|
if (!_actionRipple) {
|
||||||
|
auto mask = Ui::RippleAnimation::EllipseMask(rightActionSize());
|
||||||
|
_actionRipple = std::make_unique<Ui::RippleAnimation>(
|
||||||
|
st::defaultRippleAnimation,
|
||||||
|
std::move(mask),
|
||||||
|
std::move(updateCallback));
|
||||||
|
}
|
||||||
|
_actionRipple->add(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChannelRow::rightActionStopLastRipple() {
|
||||||
|
if (_actionRipple) {
|
||||||
|
_actionRipple->lastStop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
AwardMembersListController::AwardMembersListController(
|
AwardMembersListController::AwardMembersListController(
|
||||||
not_null<Window::SessionNavigation*> navigation,
|
not_null<Window::SessionNavigation*> navigation,
|
||||||
|
@ -150,4 +236,72 @@ std::unique_ptr<PeerListRow> MyChannelsListController::createRow(
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SelectedChannelsListController::SelectedChannelsListController(
|
||||||
|
not_null<PeerData*> peer)
|
||||||
|
: _peer(peer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectedChannelsListController::setTopStatus(rpl::producer<QString> s) {
|
||||||
|
_statusLifetime = std::move(
|
||||||
|
s
|
||||||
|
) | rpl::start_with_next([=](const QString &t) {
|
||||||
|
if (delegate()->peerListFullRowsCount() > 0) {
|
||||||
|
delegate()->peerListRowAt(0)->setCustomStatus(t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectedChannelsListController::rebuild(
|
||||||
|
std::vector<not_null<PeerData*>> selected) {
|
||||||
|
while (delegate()->peerListFullRowsCount() > 1) {
|
||||||
|
delegate()->peerListRemoveRow(delegate()->peerListRowAt(1));
|
||||||
|
}
|
||||||
|
for (const auto &peer : selected) {
|
||||||
|
delegate()->peerListAppendRow(createRow(peer->asChannel()));
|
||||||
|
}
|
||||||
|
delegate()->peerListRefreshRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto SelectedChannelsListController::channelRemoved() const
|
||||||
|
-> rpl::producer<not_null<PeerData*>> {
|
||||||
|
return _channelRemoved.events();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectedChannelsListController::rowClicked(not_null<PeerListRow*> row) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectedChannelsListController::rowRightActionClicked(
|
||||||
|
not_null<PeerListRow*> row) {
|
||||||
|
const auto peer = row->peer();
|
||||||
|
delegate()->peerListRemoveRow(row);
|
||||||
|
delegate()->peerListRefreshRows();
|
||||||
|
_channelRemoved.fire_copy(peer);
|
||||||
|
}
|
||||||
|
|
||||||
|
Main::Session &SelectedChannelsListController::session() const {
|
||||||
|
return _peer->session();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectedChannelsListController::prepare() {
|
||||||
|
delegate()->peerListAppendRow(createRow(_peer->asChannel()));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<PeerListRow> SelectedChannelsListController::createRow(
|
||||||
|
not_null<ChannelData*> channel) const {
|
||||||
|
if (channel->isMegagroup()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
const auto isYourChannel = (_peer->asChannel() == channel);
|
||||||
|
auto row = isYourChannel
|
||||||
|
? std::make_unique<PeerListRow>(channel)
|
||||||
|
: std::make_unique<ChannelRow>(channel);
|
||||||
|
row->setCustomStatus(isYourChannel
|
||||||
|
? QString()
|
||||||
|
: tr::lng_chat_status_subscribers(
|
||||||
|
tr::now,
|
||||||
|
lt_count,
|
||||||
|
channel->membersCount()));
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Giveaway
|
} // namespace Giveaway
|
||||||
|
|
|
@ -67,4 +67,29 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SelectedChannelsListController : public PeerListController {
|
||||||
|
public:
|
||||||
|
SelectedChannelsListController(not_null<PeerData*> peer);
|
||||||
|
|
||||||
|
void setTopStatus(rpl::producer<QString> status);
|
||||||
|
|
||||||
|
void rebuild(std::vector<not_null<PeerData*>> selected);
|
||||||
|
[[nodiscard]] rpl::producer<not_null<PeerData*>> channelRemoved() const;
|
||||||
|
|
||||||
|
Main::Session &session() const override;
|
||||||
|
void prepare() override;
|
||||||
|
void rowClicked(not_null<PeerListRow*> row) override;
|
||||||
|
void rowRightActionClicked(not_null<PeerListRow*> row) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<PeerListRow> createRow(
|
||||||
|
not_null<ChannelData*> channel) const;
|
||||||
|
|
||||||
|
const not_null<PeerData*> _peer;
|
||||||
|
|
||||||
|
rpl::event_stream<not_null<PeerData*>> _channelRemoved;
|
||||||
|
rpl::lifetime _statusLifetime;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace Giveaway
|
} // namespace Giveaway
|
||||||
|
|
|
@ -165,3 +165,6 @@ giveawayGiftCodeCountryButton: SettingsButton(reportReasonButton) {
|
||||||
}
|
}
|
||||||
giveawayGiftCodeCountrySelect: MultiSelect(defaultMultiSelect) {
|
giveawayGiftCodeCountrySelect: MultiSelect(defaultMultiSelect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
giveawayGiftCodeChannelDeleteIcon: icon {{ "dialogs/dialogs_cancel_search", dialogsMenuIconFg }};
|
||||||
|
giveawayGiftCodeChannelDeleteIconOver: icon {{ "dialogs/dialogs_cancel_search", dialogsMenuIconFgOver }};
|
||||||
|
|
Loading…
Add table
Reference in a new issue