Improve copy of info profile phrases.

This commit is contained in:
John Preston 2017-11-10 21:51:59 +04:00
parent dd3ae22e08
commit a6df928d45
6 changed files with 67 additions and 25 deletions

View File

@ -25,6 +25,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "ui/wrap/padding_wrap.h" #include "ui/wrap/padding_wrap.h"
#include "ui/wrap/slide_wrap.h" #include "ui/wrap/slide_wrap.h"
#include "ui/widgets/shadow.h" #include "ui/widgets/shadow.h"
#include "ui/widgets/labels.h"
#include "ui/toast/toast.h"
#include "boxes/abstract_box.h" #include "boxes/abstract_box.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "boxes/peer_list_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 "window/window_peer_menu.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "auth_session.h" #include "auth_session.h"
#include "messenger.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "application.h"
#include "styles/style_info.h" #include "styles/style_info.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
@ -180,37 +184,72 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
auto addInfoLine = [&]( auto addInfoLine = [&](
LangKey label, LangKey label,
rpl::producer<TextWithEntities> &&text, rpl::producer<TextWithEntities> &&text,
bool selectByDoubleClick = false,
const style::FlatLabel &textSt = st::infoLabeled) { const style::FlatLabel &textSt = st::infoLabeled) {
auto line = result->add(CreateTextWithLabel( auto line = CreateTextWithLabel(
result, result,
Lang::Viewer(label) | WithEmptyEntities(), Lang::Viewer(label) | WithEmptyEntities(),
std::move(text), std::move(text),
textSt, textSt,
st::infoProfileLabeledPadding, st::infoProfileLabeledPadding);
selectByDoubleClick)); tracker.track(result->add(std::move(line.wrap)));
tracker.track(line); return line.text;
return line;
}; };
auto addInfoOneLine = [&]( auto addInfoOneLine = [&](
LangKey label, LangKey label,
rpl::producer<TextWithEntities> &&text) { rpl::producer<TextWithEntities> &&text,
addInfoLine( const QString &contextCopyText) {
auto result = addInfoLine(
label, label,
std::move(text), std::move(text),
true,
st::infoLabeledOneLine); st::infoLabeledOneLine);
result->setDoubleClickSelectsParagraph(true);
result->setContextCopyText(contextCopyText);
return result;
}; };
if (auto user = _peer->asUser()) { 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) { if (user->botInfo) {
addInfoLine(lng_info_about_label, AboutValue(user)); addInfoLine(lng_info_about_label, AboutValue(user));
} else { } else {
addInfoLine(lng_info_bio_label, BioValue(user)); 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 { } 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)); addInfoLine(lng_info_about_label, AboutValue(_peer));
} }
result->add(object_ptr<Ui::SlideWrap<>>( result->add(object_ptr<Ui::SlideWrap<>>(

View File

@ -228,6 +228,7 @@ Cover::Cover(QWidget *parent, not_null<PeerData*> peer)
_peer->updateFull(); _peer->updateFull();
_name->setSelectable(true); _name->setSelectable(true);
_name->setContextCopyText(lang(lng_profile_copy_fullname));
_status->setAttribute(Qt::WA_TransparentForMouseEvents); _status->setAttribute(Qt::WA_TransparentForMouseEvents);
initUserpicButton(); initUserpicButton();

View File

@ -31,13 +31,12 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace Info { namespace Info {
namespace Profile { namespace Profile {
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>> CreateTextWithLabel( TextWithLabel CreateTextWithLabel(
QWidget *parent, QWidget *parent,
rpl::producer<TextWithEntities> &&label, rpl::producer<TextWithEntities> &&label,
rpl::producer<TextWithEntities> &&text, rpl::producer<TextWithEntities> &&text,
const style::FlatLabel &textSt, const style::FlatLabel &textSt,
const style::margins &padding, const style::margins &padding) {
bool doubleClickSelects) {
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>( auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
parent, parent,
object_ptr<Ui::VerticalLayout>(parent), object_ptr<Ui::VerticalLayout>(parent),
@ -62,14 +61,13 @@ object_ptr<Ui::SlideWrap<Ui::VerticalLayout>> CreateTextWithLabel(
std::move(nonEmptyText), std::move(nonEmptyText),
textSt)); textSt));
labeled->setSelectable(true); labeled->setSelectable(true);
labeled->setDoubleClickSelectsParagraph(doubleClickSelects);
layout->add(Ui::CreateSkipWidget(layout, st::infoLabelSkip)); layout->add(Ui::CreateSkipWidget(layout, st::infoLabelSkip));
layout->add(object_ptr<Ui::FlatLabel>( layout->add(object_ptr<Ui::FlatLabel>(
layout, layout,
std::move(label), std::move(label),
st::infoLabel)); st::infoLabel));
result->finishAnimating(); result->finishAnimating();
return result; return { std::move(result), labeled };
} }
} // namespace Profile } // namespace Profile

View File

@ -28,6 +28,7 @@ struct FlatLabel;
namespace Ui { namespace Ui {
class VerticalLayout; class VerticalLayout;
class FlatLabel;
template <typename Widget> template <typename Widget>
class SlideWrap; class SlideWrap;
} // namespace Ui } // namespace Ui
@ -35,13 +36,17 @@ class SlideWrap;
namespace Info { namespace Info {
namespace Profile { 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, QWidget *parent,
rpl::producer<TextWithEntities> &&label, rpl::producer<TextWithEntities> &&label,
rpl::producer<TextWithEntities> &&text, rpl::producer<TextWithEntities> &&text,
const style::FlatLabel &textSt, const style::FlatLabel &textSt,
const style::margins &padding, const style::margins &padding);
bool doubleClickSelects);
} // namespace Profile } // namespace Profile
} // namespace Info } // namespace Info

View File

@ -105,15 +105,14 @@ rpl::producer<TextWithEntities> AboutValue(
return rpl::single(TextWithEntities{}); return rpl::single(TextWithEntities{});
} }
rpl::producer<TextWithEntities> LinkValue( rpl::producer<QString> LinkValue(
not_null<PeerData*> peer) { not_null<PeerData*> peer) {
return PlainUsernameValue(peer) return PlainUsernameValue(peer)
| rpl::map([](QString &&username) { | rpl::map([](QString &&username) {
return username.isEmpty() return username.isEmpty()
? QString() ? QString()
: Messenger::Instance().createInternalLink(username); : Messenger::Instance().createInternalLinkFull(username);
}) });
| WithEmptyEntities();
} }
rpl::producer<bool> NotificationsEnabledValue( rpl::producer<bool> NotificationsEnabledValue(

View File

@ -59,7 +59,7 @@ rpl::producer<TextWithEntities> UsernameValue(
not_null<UserData*> user); not_null<UserData*> user);
rpl::producer<TextWithEntities> AboutValue( rpl::producer<TextWithEntities> AboutValue(
not_null<PeerData*> peer); not_null<PeerData*> peer);
rpl::producer<TextWithEntities> LinkValue( rpl::producer<QString> LinkValue(
not_null<PeerData*> peer); not_null<PeerData*> peer);
rpl::producer<bool> NotificationsEnabledValue( rpl::producer<bool> NotificationsEnabledValue(
not_null<PeerData*> peer); not_null<PeerData*> peer);