mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-18 17:40:59 +00:00
Improve copy of info profile phrases.
This commit is contained in:
parent
dd3ae22e08
commit
a6df928d45
@ -25,6 +25,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/widgets/shadow.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "boxes/abstract_box.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "boxes/peer_list_box.h"
|
||||
@ -42,7 +44,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "window/window_peer_menu.h"
|
||||
#include "mainwidget.h"
|
||||
#include "auth_session.h"
|
||||
#include "messenger.h"
|
||||
#include "apiwrap.h"
|
||||
#include "application.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
@ -180,37 +184,72 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
|
||||
auto addInfoLine = [&](
|
||||
LangKey label,
|
||||
rpl::producer<TextWithEntities> &&text,
|
||||
bool selectByDoubleClick = false,
|
||||
const style::FlatLabel &textSt = st::infoLabeled) {
|
||||
auto line = result->add(CreateTextWithLabel(
|
||||
auto line = CreateTextWithLabel(
|
||||
result,
|
||||
Lang::Viewer(label) | WithEmptyEntities(),
|
||||
std::move(text),
|
||||
textSt,
|
||||
st::infoProfileLabeledPadding,
|
||||
selectByDoubleClick));
|
||||
tracker.track(line);
|
||||
return line;
|
||||
st::infoProfileLabeledPadding);
|
||||
tracker.track(result->add(std::move(line.wrap)));
|
||||
return line.text;
|
||||
};
|
||||
auto addInfoOneLine = [&](
|
||||
LangKey label,
|
||||
rpl::producer<TextWithEntities> &&text) {
|
||||
addInfoLine(
|
||||
rpl::producer<TextWithEntities> &&text,
|
||||
const QString &contextCopyText) {
|
||||
auto result = addInfoLine(
|
||||
label,
|
||||
std::move(text),
|
||||
true,
|
||||
st::infoLabeledOneLine);
|
||||
result->setDoubleClickSelectsParagraph(true);
|
||||
result->setContextCopyText(contextCopyText);
|
||||
return result;
|
||||
};
|
||||
if (auto user = _peer->asUser()) {
|
||||
addInfoOneLine(lng_info_mobile_label, PhoneValue(user));
|
||||
addInfoOneLine(
|
||||
lng_info_mobile_label,
|
||||
PhoneValue(user),
|
||||
lang(lng_profile_copy_phone));
|
||||
if (user->botInfo) {
|
||||
addInfoLine(lng_info_about_label, AboutValue(user));
|
||||
} else {
|
||||
addInfoLine(lng_info_bio_label, BioValue(user));
|
||||
}
|
||||
addInfoOneLine(lng_info_username_label, UsernameValue(user));
|
||||
addInfoOneLine(
|
||||
lng_info_username_label,
|
||||
UsernameValue(user),
|
||||
lang(lng_context_copy_mention));
|
||||
} else {
|
||||
addInfoOneLine(lng_info_link_label, LinkValue(_peer));
|
||||
auto linkText = LinkValue(_peer)
|
||||
| rpl::map([](const QString &link) {
|
||||
auto result = TextWithEntities{ link, {} };
|
||||
if (!link.isEmpty()) {
|
||||
auto remove = qstr("https://");
|
||||
if (result.text.startsWith(remove)) {
|
||||
result.text.remove(0, remove.size());
|
||||
}
|
||||
result.entities.push_back(EntityInText(
|
||||
EntityInTextCustomUrl,
|
||||
0,
|
||||
result.text.size(),
|
||||
link));
|
||||
}
|
||||
return result;
|
||||
});
|
||||
auto link = addInfoOneLine(
|
||||
lng_info_link_label,
|
||||
std::move(linkText),
|
||||
QString());
|
||||
link->setClickHandlerHook([peer = _peer](auto&&...) {
|
||||
auto link = Messenger::Instance().createInternalLinkFull(
|
||||
peer->userName());
|
||||
if (!link.isEmpty()) {
|
||||
Application::clipboard()->setText(link);
|
||||
Ui::Toast::Show(lang(lng_username_copied));
|
||||
}
|
||||
return false;
|
||||
});
|
||||
addInfoLine(lng_info_about_label, AboutValue(_peer));
|
||||
}
|
||||
result->add(object_ptr<Ui::SlideWrap<>>(
|
||||
|
@ -228,6 +228,7 @@ Cover::Cover(QWidget *parent, not_null<PeerData*> peer)
|
||||
_peer->updateFull();
|
||||
|
||||
_name->setSelectable(true);
|
||||
_name->setContextCopyText(lang(lng_profile_copy_fullname));
|
||||
_status->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
|
||||
initUserpicButton();
|
||||
|
@ -31,13 +31,12 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
namespace Info {
|
||||
namespace Profile {
|
||||
|
||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>> CreateTextWithLabel(
|
||||
TextWithLabel CreateTextWithLabel(
|
||||
QWidget *parent,
|
||||
rpl::producer<TextWithEntities> &&label,
|
||||
rpl::producer<TextWithEntities> &&text,
|
||||
const style::FlatLabel &textSt,
|
||||
const style::margins &padding,
|
||||
bool doubleClickSelects) {
|
||||
const style::margins &padding) {
|
||||
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||
parent,
|
||||
object_ptr<Ui::VerticalLayout>(parent),
|
||||
@ -62,14 +61,13 @@ object_ptr<Ui::SlideWrap<Ui::VerticalLayout>> CreateTextWithLabel(
|
||||
std::move(nonEmptyText),
|
||||
textSt));
|
||||
labeled->setSelectable(true);
|
||||
labeled->setDoubleClickSelectsParagraph(doubleClickSelects);
|
||||
layout->add(Ui::CreateSkipWidget(layout, st::infoLabelSkip));
|
||||
layout->add(object_ptr<Ui::FlatLabel>(
|
||||
layout,
|
||||
std::move(label),
|
||||
st::infoLabel));
|
||||
result->finishAnimating();
|
||||
return result;
|
||||
return { std::move(result), labeled };
|
||||
}
|
||||
|
||||
} // namespace Profile
|
||||
|
@ -28,6 +28,7 @@ struct FlatLabel;
|
||||
|
||||
namespace Ui {
|
||||
class VerticalLayout;
|
||||
class FlatLabel;
|
||||
template <typename Widget>
|
||||
class SlideWrap;
|
||||
} // namespace Ui
|
||||
@ -35,13 +36,17 @@ class SlideWrap;
|
||||
namespace Info {
|
||||
namespace Profile {
|
||||
|
||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>> CreateTextWithLabel(
|
||||
struct TextWithLabel {
|
||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>> wrap;
|
||||
not_null<Ui::FlatLabel*> text;
|
||||
};
|
||||
|
||||
TextWithLabel CreateTextWithLabel(
|
||||
QWidget *parent,
|
||||
rpl::producer<TextWithEntities> &&label,
|
||||
rpl::producer<TextWithEntities> &&text,
|
||||
const style::FlatLabel &textSt,
|
||||
const style::margins &padding,
|
||||
bool doubleClickSelects);
|
||||
const style::margins &padding);
|
||||
|
||||
} // namespace Profile
|
||||
} // namespace Info
|
||||
|
@ -105,15 +105,14 @@ rpl::producer<TextWithEntities> AboutValue(
|
||||
return rpl::single(TextWithEntities{});
|
||||
}
|
||||
|
||||
rpl::producer<TextWithEntities> LinkValue(
|
||||
rpl::producer<QString> LinkValue(
|
||||
not_null<PeerData*> peer) {
|
||||
return PlainUsernameValue(peer)
|
||||
| rpl::map([](QString &&username) {
|
||||
return username.isEmpty()
|
||||
? QString()
|
||||
: Messenger::Instance().createInternalLink(username);
|
||||
})
|
||||
| WithEmptyEntities();
|
||||
: Messenger::Instance().createInternalLinkFull(username);
|
||||
});
|
||||
}
|
||||
|
||||
rpl::producer<bool> NotificationsEnabledValue(
|
||||
|
@ -59,7 +59,7 @@ rpl::producer<TextWithEntities> UsernameValue(
|
||||
not_null<UserData*> user);
|
||||
rpl::producer<TextWithEntities> AboutValue(
|
||||
not_null<PeerData*> peer);
|
||||
rpl::producer<TextWithEntities> LinkValue(
|
||||
rpl::producer<QString> LinkValue(
|
||||
not_null<PeerData*> peer);
|
||||
rpl::producer<bool> NotificationsEnabledValue(
|
||||
not_null<PeerData*> peer);
|
||||
|
Loading…
Reference in New Issue
Block a user