mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Improve permanent link edit design.
This commit is contained in:
parent
e5320b4b4e
commit
754dedc40e
12 changed files with 332 additions and 111 deletions
BIN
Telegram/Resources/icons/info/edit/dotsmini.png
Normal file
BIN
Telegram/Resources/icons/info/edit/dotsmini.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 260 B |
BIN
Telegram/Resources/icons/info/edit/dotsmini@2x.png
Normal file
BIN
Telegram/Resources/icons/info/edit/dotsmini@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 438 B |
BIN
Telegram/Resources/icons/info/edit/dotsmini@3x.png
Normal file
BIN
Telegram/Resources/icons/info/edit/dotsmini@3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 643 B |
|
@ -254,12 +254,11 @@ void InviteLinks::setPermanent(
|
|||
not_null<PeerData*> peer,
|
||||
const MTPExportedChatInvite &invite) {
|
||||
auto link = parse(peer, invite);
|
||||
link.permanent = true; // #TODO links remove hack
|
||||
//if (!link.permanent) {
|
||||
// LOG(("API Error: "
|
||||
// "InviteLinks::setPermanent called with non-permanent link."));
|
||||
// return;
|
||||
//}
|
||||
if (!link.permanent) {
|
||||
LOG(("API Error: "
|
||||
"InviteLinks::setPermanent called with non-permanent link."));
|
||||
return;
|
||||
}
|
||||
auto i = _firstSlices.find(peer);
|
||||
if (i == end(_firstSlices)) {
|
||||
i = _firstSlices.emplace(peer).first;
|
||||
|
@ -294,9 +293,10 @@ void InviteLinks::notify(not_null<PeerData*> peer) {
|
|||
Data::PeerUpdate::Flag::InviteLinks);
|
||||
}
|
||||
|
||||
auto InviteLinks::links(not_null<PeerData*> peer) const -> Links {
|
||||
auto InviteLinks::links(not_null<PeerData*> peer) const -> const Links & {
|
||||
static const auto kEmpty = Links();
|
||||
const auto i = _firstSlices.find(peer);
|
||||
return (i != end(_firstSlices)) ? i->second : Links();
|
||||
return (i != end(_firstSlices)) ? i->second : kEmpty;
|
||||
}
|
||||
|
||||
auto InviteLinks::parseSlice(
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
void clearPermanent(not_null<PeerData*> peer);
|
||||
|
||||
void requestLinks(not_null<PeerData*> peer);
|
||||
[[nodiscard]] Links links(not_null<PeerData*> peer) const;
|
||||
[[nodiscard]] const Links &links(not_null<PeerData*> peer) const;
|
||||
|
||||
void requestMoreLinks(
|
||||
not_null<PeerData*> peer,
|
||||
|
|
91
Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp
Normal file
91
Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
#include "boxes/peers/edit_peer_invite_links.h"
|
||||
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "main/main_session.h"
|
||||
#include "api/api_invite_links.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/controls/invite_link_label.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "apiwrap.h"
|
||||
#include "styles/style_info.h"
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
|
||||
void AddPermanentLinkBlock(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<PeerData*> peer) {
|
||||
const auto computePermanentLink = [=] {
|
||||
const auto &links = peer->session().api().inviteLinks().links(
|
||||
peer).links;
|
||||
const auto link = links.empty() ? nullptr : &links.front();
|
||||
return (link && link->permanent && !link->revoked) ? link : nullptr;
|
||||
};
|
||||
auto value = peer->session().changes().peerFlagsValue(
|
||||
peer,
|
||||
Data::PeerUpdate::Flag::InviteLinks
|
||||
) | rpl::map([=] {
|
||||
const auto link = computePermanentLink();
|
||||
return link
|
||||
? std::make_tuple(link->link, link->usage)
|
||||
: std::make_tuple(QString(), 0);
|
||||
}) | rpl::start_spawning(container->lifetime());
|
||||
|
||||
const auto copyLink = [=] {
|
||||
if (const auto link = computePermanentLink()) {
|
||||
QGuiApplication::clipboard()->setText(link->link);
|
||||
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
|
||||
}
|
||||
};
|
||||
const auto shareLink = [=] {
|
||||
if (const auto link = computePermanentLink()) {
|
||||
QGuiApplication::clipboard()->setText(link->link);
|
||||
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
|
||||
}
|
||||
};
|
||||
const auto revokeLink = [=] {
|
||||
if (const auto link = computePermanentLink()) {
|
||||
QGuiApplication::clipboard()->setText(link->link);
|
||||
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
|
||||
}
|
||||
};
|
||||
|
||||
auto link = rpl::duplicate(
|
||||
value
|
||||
) | rpl::map([=](QString link, int usage) {
|
||||
const auto prefix = qstr("https://");
|
||||
return link.startsWith(prefix) ? link.mid(prefix.size()) : link;
|
||||
});
|
||||
const auto createMenu = [=] {
|
||||
auto result = base::make_unique_q<Ui::PopupMenu>(container);
|
||||
result->addAction(
|
||||
tr::lng_group_invite_context_copy(tr::now),
|
||||
copyLink);
|
||||
result->addAction(
|
||||
tr::lng_group_invite_context_share(tr::now),
|
||||
shareLink);
|
||||
result->addAction(
|
||||
tr::lng_group_invite_context_revoke(tr::now),
|
||||
revokeLink);
|
||||
return result;
|
||||
};
|
||||
const auto label = container->lifetime().make_state<Ui::InviteLinkLabel>(
|
||||
container,
|
||||
std::move(link),
|
||||
createMenu);
|
||||
container->add(
|
||||
label->take(),
|
||||
st::inviteLinkFieldPadding);
|
||||
|
||||
label->clicks(
|
||||
) | rpl::start_with_next(copyLink, label->lifetime());
|
||||
}
|
18
Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.h
Normal file
18
Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
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
|
||||
|
||||
class PeerData;
|
||||
|
||||
namespace Ui {
|
||||
class VerticalLayout;
|
||||
} // namespace Ui
|
||||
|
||||
void AddPermanentLinkBlock(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<PeerData*> peer);
|
|
@ -14,6 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/confirm_box.h"
|
||||
#include "boxes/peer_list_controllers.h"
|
||||
#include "boxes/peers/edit_participants_box.h"
|
||||
#include "boxes/peers/edit_peer_info_box.h" // CreateButton.
|
||||
#include "boxes/peers/edit_peer_invite_links.h"
|
||||
#include "chat_helpers/emoji_suggestions_widget.h"
|
||||
#include "core/application.h"
|
||||
#include "data/data_channel.h"
|
||||
|
@ -32,15 +34,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/widgets/box_content_divider.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/special_fields.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_settings.h"
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtGui/QClipboard>
|
||||
|
@ -101,8 +106,6 @@ private:
|
|||
object_ptr<Ui::RpWidget> createUsernameEdit();
|
||||
object_ptr<Ui::RpWidget> createInviteLinkBlock();
|
||||
|
||||
void observeInviteLink();
|
||||
|
||||
void privacyChanged(Privacy value);
|
||||
|
||||
void checkUsernameAvailability();
|
||||
|
@ -114,8 +117,6 @@ private:
|
|||
rpl::producer<QString> &&text,
|
||||
not_null<const style::FlatLabel*> st);
|
||||
|
||||
bool canEditInviteLink() const;
|
||||
void refreshInviteLinkBlock();
|
||||
void createInviteLink();
|
||||
void revokeInviteLink(const QString &link);
|
||||
|
||||
|
@ -178,6 +179,18 @@ void Controller::createContent() {
|
|||
_wrap->add(createInviteLinkBlock());
|
||||
_wrap->add(createUsernameEdit());
|
||||
|
||||
using namespace Settings;
|
||||
AddSkip(_wrap.get());
|
||||
_wrap->add(EditPeerInfoBox::CreateButton(
|
||||
_wrap.get(),
|
||||
tr::lng_group_invite_manage(),
|
||||
rpl::single(QString()),
|
||||
[=] { /*ShowEditInviteLinks(_navigation, _peer);*/ },
|
||||
st::manageGroupButton,
|
||||
&st::infoIconInviteLinks));
|
||||
AddSkip(_wrap.get());
|
||||
AddDividerText(_wrap.get(), tr::lng_group_invite_manage_about());
|
||||
|
||||
if (_controls.privacy->value() == Privacy::NoUsername) {
|
||||
checkUsernameAvailability();
|
||||
}
|
||||
|
@ -292,21 +305,23 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
|
|||
|
||||
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||
_wrap,
|
||||
object_ptr<Ui::VerticalLayout>(_wrap),
|
||||
st::editPeerUsernameMargins);
|
||||
object_ptr<Ui::VerticalLayout>(_wrap));
|
||||
_controls.usernameWrap = result.data();
|
||||
|
||||
const auto container = result->entity();
|
||||
container->add(object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
|
||||
container,
|
||||
|
||||
using namespace Settings;
|
||||
AddSkip(container);
|
||||
container->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
tr::lng_create_group_link(),
|
||||
st::editPeerSectionLabel),
|
||||
st::editPeerUsernameTitleLabelMargins));
|
||||
st::settingsSubsectionTitle),
|
||||
st::settingsSubsectionTitlePadding);
|
||||
|
||||
const auto placeholder = container->add(object_ptr<Ui::RpWidget>(
|
||||
container));
|
||||
const auto placeholder = container->add(
|
||||
object_ptr<Ui::RpWidget>(container),
|
||||
st::editPeerUsernameFieldMargins);
|
||||
placeholder->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
_controls.usernameInput = Ui::AttachParentChild(
|
||||
container,
|
||||
|
@ -328,13 +343,9 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
|
|||
}, placeholder->lifetime());
|
||||
_controls.usernameInput->move(placeholder->pos());
|
||||
|
||||
container->add(object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
|
||||
AddDividerText(
|
||||
container,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
tr::lng_create_channel_link_about(),
|
||||
st::editPeerPrivacyLabel),
|
||||
st::editPeerUsernameAboutLabelMargins));
|
||||
tr::lng_create_channel_link_about());
|
||||
|
||||
QObject::connect(
|
||||
_controls.usernameInput,
|
||||
|
@ -348,6 +359,11 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
|
|||
}
|
||||
|
||||
void Controller::privacyChanged(Privacy value) {
|
||||
const auto toggleInviteLink = [&] {
|
||||
_controls.inviteLinkWrap->toggle(
|
||||
(value != Privacy::HasUsername),
|
||||
anim::type::instant);
|
||||
};
|
||||
const auto toggleEditUsername = [&] {
|
||||
_controls.usernameWrap->toggle(
|
||||
(value == Privacy::HasUsername),
|
||||
|
@ -358,14 +374,14 @@ void Controller::privacyChanged(Privacy value) {
|
|||
// Otherwise box will change own Y position.
|
||||
|
||||
if (value == Privacy::HasUsername) {
|
||||
refreshInviteLinkBlock();
|
||||
toggleInviteLink();
|
||||
toggleEditUsername();
|
||||
|
||||
_controls.usernameResult = nullptr;
|
||||
checkUsernameAvailability();
|
||||
} else {
|
||||
toggleEditUsername();
|
||||
refreshInviteLinkBlock();
|
||||
toggleInviteLink();
|
||||
}
|
||||
};
|
||||
if (value == Privacy::HasUsername) {
|
||||
|
@ -538,100 +554,38 @@ void Controller::revokeInviteLink(const QString &link) {
|
|||
Ui::show(std::move(box), Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
bool Controller::canEditInviteLink() const {
|
||||
if (const auto channel = _peer->asChannel()) {
|
||||
return channel->canHaveInviteLink();
|
||||
} else if (const auto chat = _peer->asChat()) {
|
||||
return chat->canHaveInviteLink();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Controller::observeInviteLink() {
|
||||
if (!_controls.inviteLinkWrap) {
|
||||
return;
|
||||
}
|
||||
_peer->session().changes().peerFlagsValue(
|
||||
_peer,
|
||||
Data::PeerUpdate::Flag::InviteLinks
|
||||
) | rpl::start_with_next([=] {
|
||||
refreshInviteLinkBlock();
|
||||
}, _controls.inviteLinkWrap->lifetime());
|
||||
}
|
||||
|
||||
object_ptr<Ui::RpWidget> Controller::createInviteLinkBlock() {
|
||||
Expects(_wrap != nullptr);
|
||||
|
||||
if (!canEditInviteLink()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||
_wrap,
|
||||
object_ptr<Ui::VerticalLayout>(_wrap),
|
||||
st::editPeerInvitesMargins);
|
||||
object_ptr<Ui::VerticalLayout>(_wrap));
|
||||
_controls.inviteLinkWrap = result.data();
|
||||
|
||||
const auto container = result->entity();
|
||||
container->add(object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
tr::lng_profile_invite_link_section(),
|
||||
st::editPeerSectionLabel));
|
||||
container->add(object_ptr<Ui::FixedHeightWidget>(
|
||||
container,
|
||||
st::editPeerInviteLinkBoxBottomSkip));
|
||||
|
||||
_controls.inviteLink = container->add(object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
st::editPeerInviteLink));
|
||||
_controls.inviteLink->setSelectable(true);
|
||||
_controls.inviteLink->setContextCopyText(QString());
|
||||
_controls.inviteLink->setBreakEverywhere(true);
|
||||
_controls.inviteLink->setClickHandlerFilter([=](auto&&...) {
|
||||
QGuiApplication::clipboard()->setText(inviteLinkText());
|
||||
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
|
||||
return false;
|
||||
});
|
||||
using namespace Settings;
|
||||
AddSkip(container);
|
||||
container->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
tr::lng_create_permanent_link_title(),
|
||||
st::settingsSubsectionTitle),
|
||||
st::settingsSubsectionTitlePadding);
|
||||
|
||||
container->add(object_ptr<Ui::FixedHeightWidget>(
|
||||
container,
|
||||
st::editPeerInviteLinkSkip));
|
||||
container->add(object_ptr<Ui::LinkButton>(
|
||||
container,
|
||||
tr::lng_group_invite_create_new(tr::now),
|
||||
st::editPeerInviteLinkButton)
|
||||
)->addClickHandler([=] { revokeInviteLink(inviteLinkText()); });
|
||||
AddPermanentLinkBlock(container, _peer);
|
||||
|
||||
observeInviteLink();
|
||||
AddSkip(container);
|
||||
|
||||
AddDividerText(
|
||||
container,
|
||||
((_peer->isMegagroup() || _peer->asChat())
|
||||
? tr::lng_group_invite_about_permanent_group()
|
||||
: tr::lng_group_invite_about_permanent_channel()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Controller::refreshInviteLinkBlock() {
|
||||
const auto link = inviteLinkText();
|
||||
auto text = TextWithEntities();
|
||||
if (!link.isEmpty()) {
|
||||
text.text = link;
|
||||
const auto remove = qstr("https://");
|
||||
if (text.text.startsWith(remove)) {
|
||||
text.text.remove(0, remove.size());
|
||||
}
|
||||
text.entities.push_back({
|
||||
EntityType::CustomUrl,
|
||||
0,
|
||||
text.text.size(),
|
||||
link });
|
||||
}
|
||||
_controls.inviteLink->setMarkedText(text);
|
||||
|
||||
// Hack to expand FlatLabel width to naturalWidth again.
|
||||
_controls.inviteLinkWrap->resizeToWidth(st::boxWideWidth);
|
||||
|
||||
_controls.inviteLinkWrap->toggle(
|
||||
inviteLinkShown() && !link.isEmpty(),
|
||||
anim::type::instant);
|
||||
}
|
||||
|
||||
bool Controller::inviteLinkShown() {
|
||||
return !_controls.privacy
|
||||
|| (_controls.privacy->value() == Privacy::NoUsername);
|
||||
|
|
|
@ -693,8 +693,8 @@ editPeerSectionLabel: FlatLabel(boxTitle) {
|
|||
linkFontOver: font(15px semibold underline);
|
||||
}
|
||||
}
|
||||
editPeerUsernameTitleLabelMargins: margins(0px, 0px, 0px, 10px);
|
||||
editPeerUsernameAboutLabelMargins: margins(0px, 15px, 34px, 15px);
|
||||
editPeerUsernameTitleLabelMargins: margins(22px, 17px, 22px, 10px);
|
||||
editPeerUsernameFieldMargins: margins(22px, 0px, 22px, 20px);
|
||||
editPeerUsername: setupChannelLink;
|
||||
editPeerUsernameSkip: 8px;
|
||||
editPeerInviteLink: FlatLabel(defaultFlatLabel) {
|
||||
|
@ -702,7 +702,6 @@ editPeerInviteLink: FlatLabel(defaultFlatLabel) {
|
|||
style: boxTextStyle;
|
||||
}
|
||||
editPeerInviteLinkButton: boxLinkButton;
|
||||
editPeerUsernameMargins: margins(22px, 17px, 22px, 2px);
|
||||
editPeerUsernameGood: FlatLabel(defaultFlatLabel) {
|
||||
textFg: boxTextFgGood;
|
||||
style: boxTextStyle;
|
||||
|
@ -832,3 +831,21 @@ separatePanelBack: IconButton(separatePanelClose) {
|
|||
icon: infoTopBarBackIcon;
|
||||
iconOver: infoTopBarBackIconOver;
|
||||
}
|
||||
|
||||
inviteLinkField: FlatInput(defaultFlatInput) {
|
||||
font: font(fsize);
|
||||
|
||||
height: 44px;
|
||||
textMrg: margins(14px, 12px, 36px, 9px);
|
||||
}
|
||||
inviteLinkThreeDots: IconButton(defaultIconButton) {
|
||||
width: 36px;
|
||||
height: 44px;
|
||||
|
||||
icon: icon {{ "info/edit/dotsmini", dialogsMenuIconFg }};
|
||||
iconOver: icon {{ "info/edit/dotsmini", dialogsMenuIconFgOver }};
|
||||
iconPosition: point(-1px, -1px);
|
||||
|
||||
rippleAreaSize: 0px;
|
||||
}
|
||||
inviteLinkFieldPadding: margins(22px, 7px, 22px, 9px);
|
||||
|
|
102
Telegram/SourceFiles/ui/controls/invite_link_label.cpp
Normal file
102
Telegram/SourceFiles/ui/controls/invite_link_label.cpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
#include "ui/controls/invite_link_label.h"
|
||||
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "styles/style_info.h"
|
||||
|
||||
namespace Ui {
|
||||
|
||||
InviteLinkLabel::InviteLinkLabel(
|
||||
not_null<QWidget*> parent,
|
||||
rpl::producer<QString> text,
|
||||
Fn<base::unique_qptr<PopupMenu>()> createMenu)
|
||||
: _outer(std::in_place, parent) {
|
||||
_outer->resize(_outer->width(), st::inviteLinkField.height);
|
||||
const auto label = CreateChild<FlatLabel>(
|
||||
_outer.get(),
|
||||
std::move(text),
|
||||
st::defaultFlatLabel);
|
||||
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
|
||||
const auto button = CreateChild<IconButton>(
|
||||
_outer.get(),
|
||||
st::inviteLinkThreeDots);
|
||||
|
||||
_outer->widthValue(
|
||||
) | rpl::start_with_next([=](int width) {
|
||||
const auto margin = st::inviteLinkField.textMrg;
|
||||
label->resizeToWidth(width - margin.left() - margin.right());
|
||||
label->moveToLeft(margin.left(), margin.top());
|
||||
button->moveToRight(0, 0);
|
||||
}, _outer->lifetime());
|
||||
|
||||
_outer->paintRequest(
|
||||
) | rpl::start_with_next([=] {
|
||||
auto p = QPainter(_outer.get());
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(st::inviteLinkField.bgColor);
|
||||
{
|
||||
PainterHighQualityEnabler hq(p);
|
||||
p.drawRoundedRect(
|
||||
_outer->rect(),
|
||||
st::roundRadiusSmall,
|
||||
st::roundRadiusSmall);
|
||||
}
|
||||
}, _outer->lifetime());
|
||||
|
||||
_outer->setCursor(style::cur_pointer);
|
||||
|
||||
rpl::merge(
|
||||
button->clicks() | rpl::to_empty,
|
||||
_outer->events(
|
||||
) | rpl::filter([=](not_null<QEvent*> event) {
|
||||
return (event->type() == QEvent::MouseButtonPress)
|
||||
&& (static_cast<QMouseEvent*>(event.get())->button()
|
||||
== Qt::RightButton);
|
||||
}) | rpl::to_empty
|
||||
) | rpl::start_with_next([=] {
|
||||
if (_menu) {
|
||||
_menu = nullptr;
|
||||
} else if ((_menu = createMenu())) {
|
||||
_menu->popup(QCursor::pos());
|
||||
}
|
||||
}, _outer->lifetime());
|
||||
}
|
||||
|
||||
object_ptr<RpWidget> InviteLinkLabel::take() {
|
||||
return object_ptr<RpWidget>::fromRaw(_outer.get());
|
||||
}
|
||||
|
||||
rpl::producer<> InviteLinkLabel::clicks() {
|
||||
return _outer->events(
|
||||
) | rpl::filter([=](not_null<QEvent*> event) {
|
||||
return (event->type() == QEvent::MouseButtonPress)
|
||||
&& (static_cast<QMouseEvent*>(event.get())->button()
|
||||
== Qt::LeftButton);
|
||||
}) | rpl::map([=](not_null<QEvent*> event) {
|
||||
return _outer->events(
|
||||
) | rpl::filter([=](not_null<QEvent*> event) {
|
||||
return (event->type() == QEvent::MouseButtonRelease)
|
||||
&& (static_cast<QMouseEvent*>(event.get())->button()
|
||||
== Qt::LeftButton);
|
||||
}) | rpl::take(1) | rpl::filter([=](not_null<QEvent*> event) {
|
||||
return (_outer->rect().contains(
|
||||
static_cast<QMouseEvent*>(event.get())->pos()));
|
||||
});
|
||||
}) | rpl::flatten_latest() | rpl::to_empty;
|
||||
}
|
||||
|
||||
rpl::lifetime &InviteLinkLabel::lifetime() {
|
||||
return _outer->lifetime();
|
||||
}
|
||||
|
||||
} // namespace Ui
|
37
Telegram/SourceFiles/ui/controls/invite_link_label.h
Normal file
37
Telegram/SourceFiles/ui/controls/invite_link_label.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
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/object_ptr.h"
|
||||
#include "base/unique_qptr.h"
|
||||
|
||||
namespace Ui {
|
||||
|
||||
class RpWidget;
|
||||
class PopupMenu;
|
||||
|
||||
class InviteLinkLabel final {
|
||||
public:
|
||||
InviteLinkLabel(
|
||||
not_null<QWidget*> parent,
|
||||
rpl::producer<QString> text,
|
||||
Fn<base::unique_qptr<PopupMenu>()> createMenu);
|
||||
|
||||
[[nodiscard]] object_ptr<RpWidget> take();
|
||||
|
||||
[[nodiscard]] rpl::producer<> clicks();
|
||||
|
||||
[[nodiscard]] rpl::lifetime &lifetime();
|
||||
|
||||
private:
|
||||
const base::unique_qptr<RpWidget> _outer;
|
||||
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Ui
|
|
@ -88,6 +88,8 @@ PRIVATE
|
|||
ui/chat/pinned_bar.h
|
||||
ui/controls/emoji_button.cpp
|
||||
ui/controls/emoji_button.h
|
||||
ui/controls/invite_link_label.cpp
|
||||
ui/controls/invite_link_label.h
|
||||
ui/controls/send_button.cpp
|
||||
ui/controls/send_button.h
|
||||
ui/text/format_values.cpp
|
||||
|
|
Loading…
Add table
Reference in a new issue