void ConfirmPhoneBox::prepare() { _about.create(this, st::confirmPhoneAboutLabel); TextWithEntities aboutText; auto formattedPhone = App::formatPhone(_phone); aboutText.text = lng_confirm_phone_about(lt_phone, formattedPhone); auto phonePosition = aboutText.text.indexOf(formattedPhone); if (phonePosition >= 0) { aboutText.entities.push_back(EntityInText(EntityInTextBold, phonePosition, formattedPhone.size())); } _about->setMarkedText(aboutText); _code.create(this, st::confirmPhoneCodeField, lang(lng_code_ph)); setTitle(lang(lng_confirm_phone_title)); addButton(lang(lng_confirm_phone_send), [this] { onSendCode(); }); addButton(lang(lng_cancel), [this] { closeBox(); }); setDimensions(st::boxWidth, st::usernamePadding.top() + _code->height() + st::usernameSkip + _about->height() + st::usernameSkip); connect(_code, SIGNAL(changed()), this, SLOT(onCodeChanged())); connect(_code, SIGNAL(submitted(bool)), this, SLOT(onSendCode())); connect(_callTimer, SIGNAL(timeout()), this, SLOT(onCallStatusTimer())); showChildren(); }
EntitiesInText ConvertTextTagsToEntities(const TextWithTags::Tags &tags) { EntitiesInText result; if (tags.isEmpty()) { return result; } result.reserve(tags.size()); for (const auto &tag : tags) { const auto push = [&]( EntityInTextType type, const QString &data = QString()) { result.push_back( EntityInText(type, tag.offset, tag.length, data)); }; if (IsMentionLink(tag.id)) { if (auto match = qthelp::regex_match("^(\\d+\\.\\d+)(/|$)", tag.id.midRef(kMentionTagStart.size()))) { push(EntityInTextMentionName, match->captured(1)); } } else if (tag.id == Ui::InputField::kTagBold) { push(EntityInTextBold); } else if (tag.id == Ui::InputField::kTagItalic) { push(EntityInTextItalic); } else if (tag.id == Ui::InputField::kTagCode) { push(EntityInTextCode); } else if (tag.id == Ui::InputField::kTagPre) { push(EntityInTextPre); } else /*if (ValidateUrl(tag.id)) */{ // We validate when we insert. push(EntityInTextCustomUrl, tag.id); } } return result; }
void InfoWidget::refreshBio() { TextWithEntities bioText; auto aboutText = self()->about(); if (self()->about().isEmpty()) { bioText.text = lang(lng_settings_empty_bio); } else { bioText.text = aboutText; } bioText.entities.push_back(EntityInText( EntityInTextCustomUrl, 0, bioText.text.size(), QString("internal:edit_bio"))); setLabeledText( _bio, lang(lng_profile_bio), bioText, TextWithEntities(), QString()); if (auto text = _bio->entity()->textLabel()) { text->setClickHandlerFilter([](auto&&...) { Ui::show(Box<EditBioBox>(App::self())); return false; }); } }
void InfoWidget::refreshUsername() { TextWithEntities usernameText; QString copyText; if (self()->username.isEmpty()) { usernameText.text = lang(lng_settings_choose_username); } else { usernameText.text = '@' + self()->username; copyText = lang(lng_context_copy_mention); } usernameText.entities.push_back(EntityInText( EntityInTextCustomUrl, 0, usernameText.text.size(), Messenger::Instance().createInternalLinkFull( self()->username))); setLabeledText( _username, lang(lng_profile_username), usernameText, TextWithEntities(), copyText); if (auto text = _username->entity()->textLabel()) { text->setClickHandlerFilter([](auto&&...) { Ui::show(Box<UsernameBox>()); return false; }); } }
void InviteLinkWidget::refreshLink() { _link.destroy(); TextWithEntities linkData = { getInviteLink(), EntitiesInText() }; if (linkData.text.isEmpty()) { _link.destroy(); } else { _link = new FlatLabel(this, QString(), FlatLabel::InitType::Simple, st::profileInviteLinkText); _link->show(); linkData.entities.push_back(EntityInText(EntityInTextUrl, 0, linkData.text.size())); _link->setMarkedText(linkData); _link->setSelectable(true); _link->setContextCopyText(QString()); _link->setClickHandlerHook([this](const ClickHandlerPtr &handler, Qt::MouseButton button) { auto link = getInviteLink(); if (link.isEmpty()) { return true; } QApplication::clipboard()->setText(link); Ui::showLayer(new InformBox(lang(lng_group_invite_copied))); return false; }); } }
void InfoWidget::refreshChannelLink() { TextWithEntities channelLinkText; TextWithEntities channelLinkTextShort; if (auto channel = peer()->asChannel()) { if (!channel->username.isEmpty()) { channelLinkText.text = CreateInternalLinkHttps(channel->username); channelLinkText.entities.push_back(EntityInText(EntityInTextUrl, 0, channelLinkText.text.size())); channelLinkTextShort.text = CreateInternalLink(channel->username); channelLinkTextShort.entities.push_back(EntityInText(EntityInTextCustomUrl, 0, channelLinkTextShort.text.size(), CreateInternalLinkHttps(channel->username))); } } setLabeledText(nullptr, lang(lng_profile_link), &_channelLink, channelLinkText, QString()); setLabeledText(&_channelLinkLabel, lang(lng_profile_link), &_channelLinkShort, channelLinkTextShort, QString()); if (_channelLinkShort) { _channelLinkShort->setExpandLinksMode(ExpandLinksUrlOnly); } }