From 5b4694a4eba6223c4a37e2926760368aa271996f Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 28 Dec 2017 16:06:06 +0300 Subject: [PATCH] Move text options constant to a separate module. Also start MediaView group thumbs code. --- .../SourceFiles/boxes/add_contact_box.cpp | 12 +- .../SourceFiles/boxes/edit_caption_box.cpp | 3 +- .../boxes/edit_participant_box.cpp | 8 +- Telegram/SourceFiles/boxes/peer_list_box.cpp | 5 +- Telegram/SourceFiles/boxes/send_files_box.cpp | 8 +- Telegram/SourceFiles/boxes/share_box.cpp | 7 +- Telegram/SourceFiles/data/data_peer.cpp | 15 +- .../dialogs/dialogs_inner_widget.cpp | 5 +- .../SourceFiles/dialogs/dialogs_layout.cpp | 3 +- Telegram/SourceFiles/history/history.cpp | 13 +- Telegram/SourceFiles/history/history.h | 2 - .../history/history_inner_widget.cpp | 6 +- Telegram/SourceFiles/history/history_item.cpp | 3 +- .../history/history_item_components.cpp | 15 +- .../history/history_media_grouped.cpp | 3 +- .../history/history_media_types.cpp | 112 ++++---- .../SourceFiles/history/history_media_types.h | 1 - .../SourceFiles/history/history_message.cpp | 28 +- .../SourceFiles/history/history_message.h | 1 - .../SourceFiles/history/history_service.cpp | 13 +- .../SourceFiles/history/history_service.h | 2 - .../SourceFiles/history/history_widget.cpp | 67 ++++- Telegram/SourceFiles/layout.cpp | 59 ---- Telegram/SourceFiles/layout.h | 8 - Telegram/SourceFiles/mainwidget.cpp | 3 +- .../media/view/media_view_group_thumbs.cpp | 42 +++ .../media/view/media_view_group_thumbs.h | 40 +++ Telegram/SourceFiles/mediaview.cpp | 132 ++++++--- Telegram/SourceFiles/mediaview.h | 17 +- Telegram/SourceFiles/messenger.cpp | 4 +- .../SourceFiles/overview/overview_layout.cpp | 7 +- .../profile/profile_block_peer_list.cpp | 6 +- Telegram/SourceFiles/ui/text_options.cpp | 257 ++++++++++++++++++ Telegram/SourceFiles/ui/text_options.h | 49 ++++ .../SourceFiles/ui/widgets/multi_select.cpp | 3 +- .../window/themes/window_theme_preview.cpp | 15 +- Telegram/gyp/telegram_sources.txt | 4 + 37 files changed, 721 insertions(+), 257 deletions(-) create mode 100644 Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp create mode 100644 Telegram/SourceFiles/media/view/media_view_group_thumbs.h create mode 100644 Telegram/SourceFiles/ui/text_options.cpp create mode 100644 Telegram/SourceFiles/ui/text_options.h diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index ad4a819cf7..db0a4c9446 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -36,6 +36,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/labels.h" #include "ui/toast/toast.h" #include "ui/special_buttons.h" +#include "ui/text_options.h" #include "mainwidget.h" #include "mainwindow.h" #include "apiwrap.h" @@ -1378,8 +1379,15 @@ RevokePublicLinkBox::Inner::Inner(QWidget *parent, base::lambda revokeCa auto row = ChatRow(peer); row.peer = peer; - row.name.setText(st::contactsNameStyle, peer->name, _textNameOptions); - row.status.setText(st::defaultTextStyle, Messenger::Instance().createInternalLink(textcmdLink(1, peer->userName())), _textDlgOptions); + row.name.setText( + st::contactsNameStyle, + peer->name, + Ui::NameTextOptions()); + row.status.setText( + st::defaultTextStyle, + Messenger::Instance().createInternalLink( + textcmdLink(1, peer->userName())), + Ui::DialogTextOptions()); _rows.push_back(std::move(row)); } } diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index db02046214..54b2a338bf 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "boxes/edit_caption_box.h" #include "ui/widgets/input_fields.h" +#include "ui/text_options.h" #include "media/media_clip_reader.h" #include "history/history_media_types.h" #include "lang/lang_keys.h" @@ -106,7 +107,7 @@ EditCaptionBox::EditCaptionBox( _name.setText( st::semiboldTextStyle, nameString, - _textNameOptions); + Ui::NameTextOptions()); _status = formatSizeText(doc->size); _statusw = qMax( _name.maxWidth(), diff --git a/Telegram/SourceFiles/boxes/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/edit_participant_box.cpp index 8896c7012f..f092244334 100644 --- a/Telegram/SourceFiles/boxes/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_participant_box.cpp @@ -24,10 +24,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/checkbox.h" #include "ui/widgets/labels.h" #include "ui/widgets/buttons.h" -#include "styles/style_boxes.h" +#include "ui/text_options.h" #include "ui/special_buttons.h" #include "boxes/calendar_box.h" #include "data/data_peer_values.h" +#include "styles/style_boxes.h" namespace { @@ -128,7 +129,10 @@ EditParticipantBox::Inner::Inner( st::rightsPhotoButton) , _hasAdminRights(hasAdminRights) { _userPhoto->setPointerCursor(false); - _userName.setText(st::rightsNameStyle, App::peerName(_user), _textNameOptions); + _userName.setText( + st::rightsNameStyle, + App::peerName(_user), + Ui::NameTextOptions()); } void EditParticipantBox::Inner::removeControl(QPointer widget) { diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 60183df2ff..5e652ace7b 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -34,6 +34,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/effects/ripple_animation.h" #include "ui/empty_userpic.h" #include "ui/wrap/slide_wrap.h" +#include "ui/text_options.h" #include "lang/lang_keys.h" #include "observer_peer.h" #include "storage/file_download.h" @@ -391,7 +392,7 @@ void PeerListRow::refreshName(const style::PeerListItem &st) { const auto text = _isSavedMessagesChat ? lang(lng_saved_messages) : peer()->name; - _name.setText(st.nameStyle, text, _textNameOptions); + _name.setText(st.nameStyle, text, Ui::NameTextOptions()); } PeerListRow::~PeerListRow() = default; @@ -516,7 +517,7 @@ void PeerListRow::paintDisabledCheckUserpic( } void PeerListRow::setStatusText(const QString &text) { - _status.setText(st::defaultTextStyle, text, _textNameOptions); + _status.setText(st::defaultTextStyle, text, Ui::NameTextOptions()); } float64 PeerListRow::checkedRatio() { diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 3b6666d881..1571ba826e 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -32,6 +32,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/scroll_area.h" #include "ui/wrap/fade_wrap.h" #include "ui/grouped_layout.h" +#include "ui/text_options.h" #include "media/media_clip_reader.h" #include "window/window_controller.h" #include "styles/style_history.h" @@ -796,7 +797,10 @@ void SingleFilePreview::preparePreview(const Storage::PreparedFile &file) { const auto filepath = file.path; if (filepath.isEmpty()) { auto filename = filedialogDefaultName(qsl("image"), qsl(".png"), QString(), true); - _nameText.setText(st::semiboldTextStyle, filename, _textNameOptions); + _nameText.setText( + st::semiboldTextStyle, + filename, + Ui::NameTextOptions()); _statusText = qsl("%1x%2").arg(preview.width()).arg(preview.height()); _statusWidth = qMax(_nameText.maxWidth(), st::normalFont->width(_statusText)); _fileIsImage = true; @@ -823,7 +827,7 @@ void SingleFilePreview::preparePreview(const Storage::PreparedFile &file) { _nameText.setText( st::semiboldTextStyle, nameString, - _textNameOptions); + Ui::NameTextOptions()); _statusText = formatSizeText(fileinfo.size()); _statusWidth = qMax( _nameText.maxWidth(), diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 0a1e8d0103..f974c3fa86 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -33,10 +33,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "apiwrap.h" #include "ui/toast/toast.h" #include "ui/widgets/multi_select.h" -#include "history/history_media_types.h" -#include "history/history_message.h" #include "ui/widgets/buttons.h" #include "ui/widgets/scroll_area.h" +#include "ui/text_options.h" +#include "history/history_media_types.h" +#include "history/history_message.h" #include "window/themes/window_theme.h" #include "boxes/peer_list_box.h" #include "auth_session.h" @@ -377,7 +378,7 @@ void ShareBox::Inner::updateChatName( not_null chat, not_null peer) { const auto text = peer->isSelf() ? lang(lng_saved_messages) : peer->name; - chat->name.setText(st::shareNameStyle, text, _textNameOptions); + chat->name.setText(st::shareNameStyle, text, Ui::NameTextOptions()); } void ShareBox::Inner::repaintChatAtIndex(int index) { diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index d46d228c5f..fe0c6a3fd3 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -36,6 +36,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "mainwindow.h" #include "window/window_controller.h" #include "ui/empty_userpic.h" +#include "ui/text_options.h" namespace { @@ -100,7 +101,7 @@ void PeerClickHandler::onClick(Qt::MouseButton button) const { PeerData::PeerData(const PeerId &id) : id(id) , _userpicEmpty(createEmptyUserpic()) { - nameText.setText(st::msgNameStyle, QString(), _textNameOptions); + nameText.setText(st::msgNameStyle, QString(), Ui::NameTextOptions()); } void PeerData::updateNameDelayed( @@ -124,7 +125,7 @@ void PeerData::updateNameDelayed( ++nameVersion; name = newName; - nameText.setText(st::msgNameStyle, name, _textNameOptions); + nameText.setText(st::msgNameStyle, name, Ui::NameTextOptions()); refreshEmptyUserpic(); Notify::PeerUpdate update(this); @@ -351,7 +352,10 @@ PeerData::~PeerData() = default; const Text &BotCommand::descriptionText() const { if (_descriptionText.isEmpty() && !_description.isEmpty()) { - _descriptionText.setText(st::defaultTextStyle, _description, _textNameOptions); + _descriptionText.setText( + st::defaultTextStyle, + _description, + Ui::NameTextOptions()); } return _descriptionText; } @@ -491,7 +495,10 @@ void UserData::setBotInfo(const MTPBotInfo &info) { void UserData::setNameOrPhone(const QString &newNameOrPhone) { if (nameOrPhone != newNameOrPhone) { nameOrPhone = newNameOrPhone; - phoneText.setText(st::msgNameStyle, nameOrPhone, _textNameOptions); + phoneText.setText( + st::msgNameStyle, + nameOrPhone, + Ui::NameTextOptions()); } } diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index ca1edfd55b..3556e7c096 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -28,6 +28,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "styles/style_window.h" #include "ui/widgets/buttons.h" #include "ui/widgets/popup_menu.h" +#include "ui/text_options.h" #include "data/data_drafts.h" #include "lang/lang_keys.h" #include "mainwindow.h" @@ -1799,7 +1800,7 @@ void DialogsInner::searchInPeer(PeerData *peer, UserData *from) { _searchInSavedText.setText( st::msgNameStyle, lang(lng_saved_messages), - _textDlgOptions); + Ui::DialogTextOptions()); } } else { _cancelSearchInPeer->hide(); @@ -1811,7 +1812,7 @@ void DialogsInner::searchInPeer(PeerData *peer, UserData *from) { _searchFromUserText.setText( st::dialogsSearchFromStyle, fromUserText, - _textDlgOptions); + Ui::DialogTextOptions()); _cancelSearchFromUser->show(); } else { _cancelSearchFromUser->hide(); diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp index 974ba87317..1942f51460 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp @@ -26,6 +26,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "styles/style_dialogs.h" #include "storage/localstorage.h" #include "ui/empty_userpic.h" +#include "ui/text_options.h" #include "lang/lang_keys.h" namespace Dialogs { @@ -156,7 +157,7 @@ void paintRow( if (history->cloudDraftTextCache.isEmpty()) { auto draftWrapped = textcmdLink(1, lng_dialogs_text_from_wrapped(lt_from, lang(lng_from_draft))); auto draftText = lng_dialogs_text_with_from(lt_from_part, draftWrapped, lt_message, TextUtilities::Clean(draft->textWithTags.text)); - history->cloudDraftTextCache.setText(st::dialogsTextStyle, draftText, _textDlgOptions); + history->cloudDraftTextCache.setText(st::dialogsTextStyle, draftText, Ui::DialogTextOptions()); } p.setPen(active ? st::dialogsTextFgActive : (selected ? st::dialogsTextFgOver : st::dialogsTextFg)); p.setTextPalette(active ? st::dialogsTextPaletteDraftActive : (selected ? st::dialogsTextPaletteDraftOver : st::dialogsTextPaletteDraft)); diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 5225afda3d..a794212a01 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -39,6 +39,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "storage/storage_facade.h" #include "storage/storage_shared_media.h" #include "data/data_channel_admins.h" +#include "ui/text_options.h" #include "core/crash_reports.h" namespace { @@ -62,7 +63,7 @@ auto GlobalPinnedIndex = 0; HistoryItem *createUnsupportedMessage(History *history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from) { auto text = TextWithEntities { lng_message_unsupported(lt_link, qsl("https://desktop.telegram.org")) }; - TextUtilities::ParseEntities(text, _historyTextNoMonoOptions.flags); + TextUtilities::ParseEntities(text, Ui::ItemTextNoMonoOptions().flags); text.entities.push_front(EntityInText(EntityInTextItalic, 0, text.text.size())); flags &= ~MTPDmessage::Flag::f_post_author; return HistoryMessage::create(history, msgId, flags, replyTo, viaBotId, date, from, QString(), text); @@ -70,11 +71,6 @@ HistoryItem *createUnsupportedMessage(History *history, MsgId msgId, MTPDmessage } // namespace -void HistoryInit() { - HistoryInitMessages(); - HistoryInitMedia(); -} - History::History(const PeerId &peerId) : peer(App::peer(peerId)) , lastItemTextCache(st::dialogsTextWidthMin) @@ -364,7 +360,10 @@ bool History::updateSendActionNeedsAnimating(TimeMs ms, bool force) { } if (_sendActionString != newTypingString) { _sendActionString = newTypingString; - _sendActionText.setText(st::dialogsTextStyle, _sendActionString, _textNameOptions); + _sendActionText.setText( + st::dialogsTextStyle, + _sendActionString, + Ui::NameTextOptions()); } } auto result = (!_typing.isEmpty() || !_sendActions.isEmpty()); diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index afad9794c0..3186d8e64a 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -30,8 +30,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "base/flat_set.h" #include "base/flags.h" -void HistoryInit(); - class HistoryItem; using HistoryItemsList = std::vector>; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 5e14a378c5..4fe24da949 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -27,6 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "history/history_service_layout.h" #include "history/history_media_types.h" #include "history/history_item_components.h" +#include "ui/text_options.h" #include "ui/widgets/popup_menu.h" #include "window/window_controller.h" #include "window/window_peer_menu.h" @@ -1836,7 +1837,10 @@ void HistoryInner::updateBotInfo(bool recount) { int newh = 0; if (_botAbout && !_botAbout->info->description.isEmpty()) { if (_botAbout->info->text.isEmpty()) { - _botAbout->info->text.setText(st::messageTextStyle, _botAbout->info->description, _historyBotNoMonoOptions); + _botAbout->info->text.setText( + st::messageTextStyle, + _botAbout->info->description, + Ui::ItemTextBotNoMonoOptions()); if (recount) { int32 tw = _scroll->width() - st::msgMargin.left() - st::msgMargin.right(); if (tw > st::msgMaxWidth) tw = st::msgMaxWidth; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 730f0a9cc5..92fe1842ea 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -31,6 +31,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "styles/style_dialogs.h" #include "styles/style_history.h" #include "ui/effects/ripple_animation.h" +#include "ui/text_options.h" #include "storage/file_upload.h" #include "storage/storage_facade.h" #include "storage/storage_shared_media.h" @@ -1032,7 +1033,7 @@ void HistoryItem::drawInDialog( Text &cache) const { if (cacheFor != this) { cacheFor = this; - cache.setText(st::dialogsTextStyle, inDialogsText(way), _textDlgOptions); + cache.setText(st::dialogsTextStyle, inDialogsText(way), Ui::DialogTextOptions()); } if (r.width()) { p.setTextPalette(active ? st::dialogsTextPaletteActive : (selected ? st::dialogsTextPaletteOver : st::dialogsTextPalette)); diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index b2654ac600..11343ccea8 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -22,6 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "lang/lang_keys.h" #include "ui/effects/ripple_animation.h" +#include "ui/text_options.h" #include "history/history_service_layout.h" #include "history/history_message.h" #include "history/history_media.h" @@ -63,7 +64,10 @@ void HistoryMessageSigned::refresh(const QString &date) { if (timew + namew > st::maxSignatureSize) { name = st::msgDateFont->elided(author, st::maxSignatureSize - timew); } - signature.setText(st::msgDateTextStyle, name + time, _textNameOptions); + signature.setText( + st::msgDateTextStyle, + name + time, + Ui::NameTextOptions()); } int HistoryMessageSigned::maxWidth() const { @@ -72,7 +76,7 @@ int HistoryMessageSigned::maxWidth() const { void HistoryMessageEdited::refresh(const QString &date, bool displayed) { const auto prefix = displayed ? (lang(lng_edited) + ' ') : QString(); - text.setText(st::msgDateTextStyle, prefix + date, _textNameOptions); + text.setText(st::msgDateTextStyle, prefix + date, Ui::NameTextOptions()); } int HistoryMessageEdited::maxWidth() const { @@ -151,7 +155,10 @@ bool HistoryMessageReply::updateData(HistoryMessage *holder, bool force) { } if (replyToMsg) { - replyToText.setText(st::messageTextStyle, TextUtilities::Clean(replyToMsg->inReplyText()), _textDlgOptions); + replyToText.setText( + st::messageTextStyle, + TextUtilities::Clean(replyToMsg->inReplyText()), + Ui::DialogTextOptions()); updateName(); @@ -193,7 +200,7 @@ void HistoryMessageReply::updateName() const { QString name = (replyToVia && replyToMsg->author()->isUser()) ? replyToMsg->author()->asUser()->firstName : App::peerName(replyToMsg->author()); - replyToName.setText(st::fwdTextStyle, name, _textNameOptions); + replyToName.setText(st::fwdTextStyle, name, Ui::NameTextOptions()); replyToVersion = replyToMsg->author()->nameVersion; bool hasPreview = replyToMsg->getMedia() ? replyToMsg->getMedia()->hasReplyPreview() : false; int32 previewSkip = hasPreview ? (st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x()) : 0; diff --git a/Telegram/SourceFiles/history/history_media_grouped.cpp b/Telegram/SourceFiles/history/history_media_grouped.cpp index c4085bc769..83dd32ef0a 100644 --- a/Telegram/SourceFiles/history/history_media_grouped.cpp +++ b/Telegram/SourceFiles/history/history_media_grouped.cpp @@ -26,6 +26,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "storage/storage_shared_media.h" #include "lang/lang_keys.h" #include "ui/grouped_layout.h" +#include "ui/text_options.h" #include "styles/style_history.h" HistoryGroupedMedia::Element::Element(not_null item) @@ -441,7 +442,7 @@ void HistoryGroupedMedia::updateNeedBubbleState() { _caption.setText( st::messageTextStyle, captionText.text + _parent->skipBlock(), - itemTextNoMonoOptions(_parent)); + Ui::ItemTextNoMonoOptions(_parent)); _needBubble = computeNeedBubble(); } diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index 4abb7b76f4..9b080a7430 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -41,44 +41,13 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "calls/calls_instance.h" #include "ui/empty_userpic.h" #include "ui/grouped_layout.h" +#include "ui/text_options.h" namespace { constexpr auto kMaxGifForwardedBarLines = 4; constexpr auto kMaxOriginalEntryLines = 8192; -TextParseOptions _webpageTitleOptions = { - TextParseMultiline | TextParseRichText, // flags - 0, // maxw - 0, // maxh - Qt::LayoutDirectionAuto, // dir -}; -TextParseOptions _webpageDescriptionOptions = { - TextParseLinks | TextParseMentions | TextParseHashtags | TextParseMultiline | TextParseRichText | TextParseMarkdown, // flags - 0, // maxw - 0, // maxh - Qt::LayoutDirectionAuto, // dir -}; -TextParseOptions _twitterDescriptionOptions = { - TextParseLinks | TextParseMentions | TextTwitterMentions | TextParseHashtags | TextTwitterHashtags | TextParseMultiline | TextParseRichText, // flags - 0, // maxw - 0, // maxh - Qt::LayoutDirectionAuto, // dir -}; -TextParseOptions _instagramDescriptionOptions = { - TextParseLinks | TextParseMentions | TextInstagramMentions | TextParseHashtags | TextInstagramHashtags | TextParseMultiline | TextParseRichText, // flags - 0, // maxw - 0, // maxh - Qt::LayoutDirectionAuto, // dir -}; - -inline void initTextOptions() { - _webpageTitleOptions.maxw = st::msgMaxWidth - st::msgPadding.left() - st::msgPadding.right() - st::webPageLeft; - _webpageTitleOptions.maxh = st::webPageTitleFont->height * 2; - _webpageDescriptionOptions.maxw = st::msgMaxWidth - st::msgPadding.left() - st::msgPadding.right() - st::webPageLeft; - _webpageDescriptionOptions.maxh = st::webPageDescriptionFont->height * 3; -} - bool needReSetInlineResultDocument(const MTPMessageMedia &media, DocumentData *existing) { if (media.type() == mtpc_messageMediaDocument) { auto &mediaDocument = media.c_messageMediaDocument(); @@ -121,10 +90,6 @@ int32 gifMaxStatusWidth(DocumentData *document) { } // namespace -void HistoryInitMedia() { - initTextOptions(); -} - TextWithEntities WithCaptionSelectedText( const QString &attachType, const Text &caption, @@ -263,7 +228,7 @@ HistoryPhoto::HistoryPhoto( _caption.setText( st::messageTextStyle, caption + _parent->skipBlock(), - itemTextNoMonoOptions(_parent)); + Ui::ItemTextNoMonoOptions(_parent)); } init(); } @@ -864,7 +829,7 @@ HistoryVideo::HistoryVideo( _caption.setText( st::messageTextStyle, caption + _parent->skipBlock(), - itemTextNoMonoOptions(_parent)); + Ui::ItemTextNoMonoOptions(_parent)); } setDocumentLinks(_data, parent); @@ -1386,7 +1351,10 @@ HistoryDocument::HistoryDocument( setStatusSize(FileStatusSizeReady); if (auto captioned = Get()) { - captioned->_caption.setText(st::messageTextStyle, caption + _parent->skipBlock(), itemTextNoMonoOptions(_parent)); + captioned->_caption.setText( + st::messageTextStyle, + caption + _parent->skipBlock(), + Ui::ItemTextNoMonoOptions(_parent)); } } @@ -2174,7 +2142,10 @@ HistoryGif::HistoryGif( setStatusSize(FileStatusSizeReady); if (!caption.isEmpty() && !_data->isVideoMessage()) { - _caption.setText(st::messageTextStyle, caption + _parent->skipBlock(), itemTextNoMonoOptions(_parent)); + _caption.setText( + st::messageTextStyle, + caption + _parent->skipBlock(), + Ui::ItemTextNoMonoOptions(_parent)); } _data->thumb->load(); @@ -3310,7 +3281,10 @@ HistoryContact::HistoryContact(not_null parent, int32 userId, cons , _fname(first) , _lname(last) , _phone(App::formatPhone(phone)) { - _name.setText(st::semiboldTextStyle, lng_full_name(lt_first_name, first, lt_last_name, last).trimmed(), _textNameOptions); + _name.setText( + st::semiboldTextStyle, + lng_full_name(lt_first_name, first, lt_last_name, last).trimmed(), + Ui::NameTextOptions()); _phonew = st::normalFont->width(_phone); } @@ -3701,12 +3675,6 @@ void HistoryWebPage::initDimensions() { if (textFloatsAroundInfo) { text.text += _parent->skipBlock(); } - auto opts = &_webpageDescriptionOptions; - if (_data->siteName == qstr("Twitter")) { - opts = &_twitterDescriptionOptions; - } else if (_data->siteName == qstr("Instagram")) { - opts = &_instagramDescriptionOptions; - } if (isLogEntryOriginal()) { // Fix layout for small bubbles (narrow media caption edit log entries). _description = Text(st::minPhotoSize @@ -3714,13 +3682,19 @@ void HistoryWebPage::initDimensions() { - st::msgPadding.right() - st::webPageLeft); } - _description.setMarkedText(st::webPageDescriptionStyle, text, *opts); + _description.setMarkedText( + st::webPageDescriptionStyle, + text, + Ui::WebpageTextDescriptionOptions(_data->siteName)); } if (_title.isEmpty() && !title.isEmpty()) { if (textFloatsAroundInfo && _description.isEmpty()) { title += _parent->skipBlock(); } - _title.setText(st::webPageTitleStyle, title, _webpageTitleOptions); + _title.setText( + st::webPageTitleStyle, + title, + Ui::WebpageTextTitleOptions()); } if (!_siteNameWidth && !_data->siteName.isEmpty()) { _siteNameWidth = st::webPageTitleFont->width(_data->siteName); @@ -4263,11 +4237,17 @@ void HistoryGame::initDimensions() { auto marked = TextWithEntities { text }; auto parseFlags = TextParseLinks | TextParseMultiline | TextParseRichText; TextUtilities::ParseEntities(marked, parseFlags); - _description.setMarkedText(st::webPageDescriptionStyle, marked, _webpageDescriptionOptions); + _description.setMarkedText( + st::webPageDescriptionStyle, + marked, + Ui::WebpageTextDescriptionOptions()); } } if (_title.isEmpty() && !title.isEmpty()) { - _title.setText(st::webPageTitleStyle, title, _webpageTitleOptions); + _title.setText( + st::webPageTitleStyle, + title, + Ui::WebpageTextTitleOptions()); } // init dimensions @@ -4529,7 +4509,10 @@ TextSelection HistoryGame::adjustSelection(TextSelection selection, TextSelectTy } bool HistoryGame::consumeMessageText(const TextWithEntities &textWithEntities) { - _description.setMarkedText(st::webPageDescriptionStyle, textWithEntities, itemTextOptions(_parent)); + _description.setMarkedText( + st::webPageDescriptionStyle, + textWithEntities, + Ui::ItemTextOptions(_parent)); return true; } @@ -4702,7 +4685,10 @@ void HistoryInvoice::fillFromData(const MTPDmessageMediaInvoice &data) { }; statusText.entities.push_back(EntityInText(EntityInTextBold, 0, statusText.text.size())); statusText.text += ' ' + labelText().toUpper(); - _status.setMarkedText(st::defaultTextStyle, statusText, itemTextOptions(_parent)); + _status.setMarkedText( + st::defaultTextStyle, + statusText, + Ui::ItemTextOptions(_parent)); _receiptMsgId = data.has_receipt_msg_id() ? data.vreceipt_msg_id.v : 0; @@ -4712,11 +4698,17 @@ void HistoryInvoice::fillFromData(const MTPDmessageMediaInvoice &data) { auto marked = TextWithEntities { description }; auto parseFlags = TextParseLinks | TextParseMultiline | TextParseRichText; TextUtilities::ParseEntities(marked, parseFlags); - _description.setMarkedText(st::webPageDescriptionStyle, marked, _webpageDescriptionOptions); + _description.setMarkedText( + st::webPageDescriptionStyle, + marked, + Ui::WebpageTextDescriptionOptions()); } auto title = TextUtilities::SingleLine(qs(data.vtitle)); if (!title.isEmpty()) { - _title.setText(st::webPageTitleStyle, title, _webpageTitleOptions); + _title.setText( + st::webPageTitleStyle, + title, + Ui::WebpageTextTitleOptions()); } } @@ -5031,13 +5023,19 @@ HistoryLocation::HistoryLocation(not_null parent, const LocationCo , _description(st::msgMinWidth) , _link(std::make_shared(coords)) { if (!title.isEmpty()) { - _title.setText(st::webPageTitleStyle, TextUtilities::Clean(title), _webpageTitleOptions); + _title.setText( + st::webPageTitleStyle, + TextUtilities::Clean(title), + Ui::WebpageTextTitleOptions()); } if (!description.isEmpty()) { auto marked = TextWithEntities { TextUtilities::Clean(description) }; auto parseFlags = TextParseLinks | TextParseMultiline | TextParseRichText; TextUtilities::ParseEntities(marked, parseFlags); - _description.setMarkedText(st::webPageDescriptionStyle, marked, _webpageDescriptionOptions); + _description.setMarkedText( + st::webPageDescriptionStyle, + marked, + Ui::WebpageTextDescriptionOptions()); } } diff --git a/Telegram/SourceFiles/history/history_media_types.h b/Telegram/SourceFiles/history/history_media_types.h index 9b3e6a19e8..ccd62ab8e1 100644 --- a/Telegram/SourceFiles/history/history_media_types.h +++ b/Telegram/SourceFiles/history/history_media_types.h @@ -43,7 +43,6 @@ namespace Ui { class EmptyUserpic; } // namespace Ui -void HistoryInitMedia(); TextWithEntities WithCaptionSelectedText( const QString &attachType, const Text &caption, diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 7a4bab9052..ad738b905e 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -33,6 +33,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "boxes/share_box.h" #include "boxes/confirm_box.h" #include "ui/toast/toast.h" +#include "ui/text_options.h" #include "messenger.h" #include "styles/style_dialogs.h" #include "styles/style_widgets.h" @@ -138,11 +139,6 @@ int KeyboardStyle::minButtonWidth( return result; } -inline void initTextOptions() { - _historySrvOptions.dir = _textNameOptions.dir = _textDlgOptions.dir = cLangDir(); - _textDlgOptions.maxw = st::columnMaximalWidthLeft * 2; -} - QString AdminBadgeText() { return lang(lng_admin_badge); } @@ -409,10 +405,6 @@ void FastShareMessage(not_null item) { std::move(filterCallback))); } -void HistoryInitMessages() { - initTextOptions(); -} - base::lambda HistoryDependentItemCallback( const FullMsgId &msgId) { return [dependent = msgId](ChannelData *channel, MsgId msgId) { @@ -1501,9 +1493,18 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) { } else { auto mediaOnBottom = (_media && _media->isDisplayed() && _media->isBubbleBottom()) || Has(); if (mediaOnBottom) { - _text.setMarkedText(st::messageTextStyle, textWithEntities, itemTextOptions(this)); + _text.setMarkedText( + st::messageTextStyle, + textWithEntities, + Ui::ItemTextOptions(this)); } else { - _text.setMarkedText(st::messageTextStyle, { textWithEntities.text + skipBlock(), textWithEntities.entities }, itemTextOptions(this)); + _text.setMarkedText( + st::messageTextStyle, + { + textWithEntities.text + skipBlock(), + textWithEntities.entities + }, + Ui::ItemTextOptions(this)); } _textWidth = -1; _textHeight = 0; @@ -1511,7 +1512,10 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) { } void HistoryMessage::setEmptyText() { - _text.setMarkedText(st::messageTextStyle, { QString(), EntitiesInText() }, itemTextOptions(this)); + _text.setMarkedText( + st::messageTextStyle, + { QString(), EntitiesInText() }, + Ui::ItemTextOptions(this)); _textWidth = -1; _textHeight = 0; diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 9cfdb2fac2..3ab5ca561e 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -24,7 +24,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org struct HistoryMessageEdited; -void HistoryInitMessages(); base::lambda HistoryDependentItemCallback( const FullMsgId &msgId); MTPDmessage::Flags NewMessageFlags(not_null peer); diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 15c9ca2190..1be38049b2 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -30,6 +30,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "auth_session.h" #include "window/notifications_manager.h" #include "storage/storage_shared_media.h" +#include "ui/text_options.h" namespace { @@ -37,13 +38,6 @@ constexpr auto kPinnedMessageTextLimit = 16; } // namespace -TextParseOptions _historySrvOptions = { - TextParseLinks | TextParseMentions | TextParseHashtags/* | TextParseMultiline*/ | TextParseRichText, // flags - 0, // maxw - 0, // maxh - Qt::LayoutDirectionAuto, // lang-dependent -}; - void HistoryService::setMessageByAction(const MTPmessageAction &action) { auto prepareChatAddUserText = [this](const MTPDmessageActionChatAddUser &action) { auto result = PreparedText {}; @@ -495,7 +489,10 @@ QString HistoryService::inReplyText() const { } void HistoryService::setServiceText(const PreparedText &prepared) { - _text.setText(st::serviceTextStyle, prepared.text, _historySrvOptions); + _text.setText( + st::serviceTextStyle, + prepared.text, + Ui::ItemTextServiceOptions()); auto linkIndex = 0; for_const (auto &link, prepared.links) { // Link indices start with 1. diff --git a/Telegram/SourceFiles/history/history_service.h b/Telegram/SourceFiles/history/history_service.h index 33084e6463..4346cff69a 100644 --- a/Telegram/SourceFiles/history/history_service.h +++ b/Telegram/SourceFiles/history/history_service.h @@ -182,5 +182,3 @@ private: static PreparedText GenerateText(not_null history, not_null inviter); }; - -extern TextParseOptions _historySrvOptions; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index acda3262e7..d9cd2896a5 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -74,6 +74,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "observer_peer.h" #include "base/qthelp_regex.h" #include "ui/widgets/popup_menu.h" +#include "ui/text_options.h" #include "auth_session.h" #include "window/themes/window_theme.h" #include "window/notifications_manager.h" @@ -382,7 +383,7 @@ bool HistoryHider::offerPeer(PeerId peer) { return false; } - _toText.setText(st::boxLabelStyle, phrase, _textNameOptions); + _toText.setText(st::boxLabelStyle, phrase, Ui::NameTextOptions()); _toTextWidth = _toText.maxWidth(); if (_toTextWidth > _box.width() - st::boxPadding.left() - st::boxLayerButtonPadding.right()) { _toTextWidth = _box.width() - st::boxPadding.left() - st::boxLayerButtonPadding.right(); @@ -2776,7 +2777,7 @@ void HistoryWidget::saveEditMsg() { WebPageId webPageId = _previewCancelled ? CancelledWebPageId : ((_previewData && _previewData->pendingTill >= 0) ? _previewData->id : 0); auto &textWithTags = _field->getTextWithTags(); - auto prepareFlags = itemTextOptions(_history, App::self()).flags; + auto prepareFlags = Ui::ItemTextOptions(_history, App::self()).flags; auto sending = TextWithEntities(); auto left = TextWithEntities { textWithTags.text, ConvertTextTagsToEntities(textWithTags.tags) }; TextUtilities::PrepareForSending(left, prepareFlags); @@ -3664,7 +3665,10 @@ void HistoryWidget::onKbToggle(bool manual) { _kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard->forceReply()) ? App::histItemById(_keyboard->forMsgId()) : 0; if (_kbReplyTo && !_editMsgId && !_replyToId && fieldEnabled) { updateReplyToName(); - _replyEditMsgText.setText(st::messageTextStyle, TextUtilities::Clean(_kbReplyTo->inReplyText()), _textDlgOptions); + _replyEditMsgText.setText( + st::messageTextStyle, + TextUtilities::Clean(_kbReplyTo->inReplyText()), + Ui::DialogTextOptions()); _fieldBarCancel->show(); updateMouseTracking(); } @@ -3683,7 +3687,10 @@ void HistoryWidget::onKbToggle(bool manual) { _kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard->forceReply()) ? App::histItemById(_keyboard->forMsgId()) : 0; if (_kbReplyTo && !_editMsgId && !_replyToId) { updateReplyToName(); - _replyEditMsgText.setText(st::messageTextStyle, TextUtilities::Clean(_kbReplyTo->inReplyText()), _textDlgOptions); + _replyEditMsgText.setText( + st::messageTextStyle, + TextUtilities::Clean(_kbReplyTo->inReplyText()), + Ui::DialogTextOptions()); _fieldBarCancel->show(); updateMouseTracking(); } @@ -4877,7 +4884,10 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { _kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard->forceReply()) ? App::histItemById(_keyboard->forMsgId()) : 0; if (_kbReplyTo && !_replyToId) { updateReplyToName(); - _replyEditMsgText.setText(st::messageTextStyle, TextUtilities::Clean(_kbReplyTo->inReplyText()), _textDlgOptions); + _replyEditMsgText.setText( + st::messageTextStyle, + TextUtilities::Clean(_kbReplyTo->inReplyText()), + Ui::DialogTextOptions()); _fieldBarCancel->show(); updateMouseTracking(); } @@ -5211,7 +5221,10 @@ void HistoryWidget::updatePinnedBar(bool force) { _pinnedBar->msg = App::histItemById(_history->channelId(), _pinnedBar->msgId); } if (_pinnedBar->msg) { - _pinnedBar->text.setText(st::messageTextStyle, TextUtilities::Clean(_pinnedBar->msg->notificationText()), _textDlgOptions); + _pinnedBar->text.setText( + st::messageTextStyle, + TextUtilities::Clean(_pinnedBar->msg->notificationText()), + Ui::DialogTextOptions()); update(); } else if (force) { if (auto channel = _peer ? _peer->asChannel() : nullptr) { @@ -5508,7 +5521,10 @@ void HistoryWidget::onReplyToMessage() { } else { _replyEditMsg = to; _replyToId = to->id; - _replyEditMsgText.setText(st::messageTextStyle, TextUtilities::Clean(_replyEditMsg->inReplyText()), _textDlgOptions); + _replyEditMsgText.setText( + st::messageTextStyle, + TextUtilities::Clean(_replyEditMsg->inReplyText()), + Ui::DialogTextOptions()); updateBotKeyboard(); @@ -5864,13 +5880,19 @@ void HistoryWidget::updatePreview() { _fieldBarCancel->show(); updateMouseTracking(); if (_previewData->pendingTill) { - _previewTitle.setText(st::msgNameStyle, lang(lng_preview_loading), _textNameOptions); + _previewTitle.setText( + st::msgNameStyle, + lang(lng_preview_loading), + Ui::NameTextOptions()); #ifndef OS_MAC_OLD auto linkText = _previewLinks.splitRef(' ').at(0).toString(); #else // OS_MAC_OLD auto linkText = _previewLinks.split(' ').at(0); #endif // OS_MAC_OLD - _previewDescription.setText(st::messageTextStyle, TextUtilities::Clean(linkText), _textDlgOptions); + _previewDescription.setText( + st::messageTextStyle, + TextUtilities::Clean(linkText), + Ui::DialogTextOptions()); int32 t = (_previewData->pendingTill - unixtime()) * 1000; if (t <= 0) t = 1; @@ -5901,8 +5923,14 @@ void HistoryWidget::updatePreview() { title = lang(lng_attach_photo); } } - _previewTitle.setText(st::msgNameStyle, title, _textNameOptions); - _previewDescription.setText(st::messageTextStyle, TextUtilities::Clean(desc), _textDlgOptions); + _previewTitle.setText( + st::msgNameStyle, + title, + Ui::NameTextOptions()); + _previewDescription.setText( + st::messageTextStyle, + TextUtilities::Clean(desc), + Ui::DialogTextOptions()); } } else if (!readyToForward() && !replyToId() && !_editMsgId) { _fieldBarCancel->hide(); @@ -6122,7 +6150,10 @@ void HistoryWidget::updateReplyEditTexts(bool force) { _replyEditMsg = App::histItemById(_channel, _editMsgId ? _editMsgId : _replyToId); } if (_replyEditMsg) { - _replyEditMsgText.setText(st::messageTextStyle, TextUtilities::Clean(_replyEditMsg->inReplyText()), _textDlgOptions); + _replyEditMsgText.setText( + st::messageTextStyle, + TextUtilities::Clean(_replyEditMsg->inReplyText()), + Ui::DialogTextOptions()); updateBotKeyboard(); @@ -6181,8 +6212,11 @@ void HistoryWidget::updateForwardingTexts() { text = lng_forward_messages(lt_count, count); } } - _toForwardFrom.setText(st::msgNameStyle, from, _textNameOptions); - _toForwardText.setText(st::messageTextStyle, TextUtilities::Clean(text), _textDlgOptions); + _toForwardFrom.setText(st::msgNameStyle, from, Ui::NameTextOptions()); + _toForwardText.setText( + st::messageTextStyle, + TextUtilities::Clean(text), + Ui::DialogTextOptions()); _toForwardNameVersion = version; } @@ -6201,7 +6235,10 @@ void HistoryWidget::checkForwardingInfo() { void HistoryWidget::updateReplyToName() { if (_editMsgId) return; if (!_replyEditMsg && (_replyToId || !_kbReplyTo)) return; - _replyToName.setText(st::msgNameStyle, App::peerName((_replyEditMsg ? _replyEditMsg : _kbReplyTo)->author()), _textNameOptions); + _replyToName.setText( + st::msgNameStyle, + App::peerName((_replyEditMsg ? _replyEditMsg : _kbReplyTo)->author()), + Ui::NameTextOptions()); _replyToNameVersion = (_replyEditMsg ? _replyEditMsg : _kbReplyTo)->author()->nameVersion; } diff --git a/Telegram/SourceFiles/layout.cpp b/Telegram/SourceFiles/layout.cpp index fe4b082b8b..e7df5a1bba 100644 --- a/Telegram/SourceFiles/layout.cpp +++ b/Telegram/SourceFiles/layout.cpp @@ -32,65 +32,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "media/media_audio.h" #include "storage/localstorage.h" -TextParseOptions _textNameOptions = { - 0, // flags - 4096, // maxw - 1, // maxh - Qt::LayoutDirectionAuto, // lang-dependent -}; -TextParseOptions _textDlgOptions = { - TextParseRichText, // flags - 0, // maxw is style-dependent - 1, // maxh - Qt::LayoutDirectionAuto, // lang-dependent -}; -TextParseOptions _historyTextOptions = { - TextParseLinks | TextParseMentions | TextParseHashtags | TextParseMultiline | TextParseRichText | TextParseMarkdown, // flags - 0, // maxw - 0, // maxh - Qt::LayoutDirectionAuto, // dir -}; -TextParseOptions _historyBotOptions = { - TextParseLinks | TextParseMentions | TextParseHashtags | TextParseBotCommands | TextParseMultiline | TextParseRichText | TextParseMarkdown, // flags - 0, // maxw - 0, // maxh - Qt::LayoutDirectionAuto, // dir -}; -TextParseOptions _historyTextNoMonoOptions = { - TextParseLinks | TextParseMentions | TextParseHashtags | TextParseMultiline | TextParseRichText, // flags - 0, // maxw - 0, // maxh - Qt::LayoutDirectionAuto, // dir -}; -TextParseOptions _historyBotNoMonoOptions = { - TextParseLinks | TextParseMentions | TextParseHashtags | TextParseBotCommands | TextParseMultiline | TextParseRichText, // flags - 0, // maxw - 0, // maxh - Qt::LayoutDirectionAuto, // dir -}; - -const TextParseOptions &itemTextOptions(History *h, PeerData *f) { - if ((h->peer->isUser() && h->peer->asUser()->botInfo) || (f->isUser() && f->asUser()->botInfo) || (h->peer->isChat() && h->peer->asChat()->botStatus >= 0) || (h->peer->isMegagroup() && h->peer->asChannel()->mgInfo->botStatus >= 0)) { - return _historyBotOptions; - } - return _historyTextOptions; -} - -const TextParseOptions &itemTextOptions(const HistoryItem *item) { - return itemTextOptions(item->history(), item->author()); -} - -const TextParseOptions &itemTextNoMonoOptions(History *h, PeerData *f) { - if ((h->peer->isUser() && h->peer->asUser()->botInfo) || (f->isUser() && f->asUser()->botInfo) || (h->peer->isChat() && h->peer->asChat()->botStatus >= 0) || (h->peer->isMegagroup() && h->peer->asChannel()->mgInfo->botStatus >= 0)) { - return _historyBotNoMonoOptions; - } - return _historyTextNoMonoOptions; -} - -const TextParseOptions &itemTextNoMonoOptions(const HistoryItem *item) { - return itemTextNoMonoOptions(item->history(), item->author()); -} - QString formatSizeText(qint64 size) { if (size >= 1024 * 1024) { // more than 1 mb qint64 sizeTenthMb = (size * 10 / (1024 * 1024)); diff --git a/Telegram/SourceFiles/layout.h b/Telegram/SourceFiles/layout.h index d5f16e9f2c..a13534be2c 100644 --- a/Telegram/SourceFiles/layout.h +++ b/Telegram/SourceFiles/layout.h @@ -58,14 +58,6 @@ inline bool IsGroupItemSelection( : selection; } -extern TextParseOptions _textNameOptions, _textDlgOptions; -extern TextParseOptions _historyTextOptions, _historyBotOptions, _historyTextNoMonoOptions, _historyBotNoMonoOptions; - -const TextParseOptions &itemTextOptions(History *h, PeerData *f); -const TextParseOptions &itemTextOptions(const HistoryItem *item); -const TextParseOptions &itemTextNoMonoOptions(History *h, PeerData *f); -const TextParseOptions &itemTextNoMonoOptions(const HistoryItem *item); - enum RoundCorners { SmallMaskCorners = 0x00, // for images LargeMaskCorners, diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index f2ac185369..4f45e5a65c 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -39,6 +39,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/dropdown_menu.h" #include "ui/focus_persister.h" #include "ui/resize_area.h" +#include "ui/text_options.h" #include "ui/toast/toast.h" #include "chat_helpers/message_field.h" #include "chat_helpers/stickers.h" @@ -1456,7 +1457,7 @@ void MainWidget::sendMessage(const MessageToSend &message) { auto sending = TextWithEntities(); auto left = TextWithEntities { textWithTags.text, ConvertTextTagsToEntities(textWithTags.tags) }; - auto prepareFlags = itemTextOptions(history, App::self()).flags; + auto prepareFlags = Ui::ItemTextOptions(history, App::self()).flags; TextUtilities::PrepareForSending(left, prepareFlags); HistoryItem *lastMessage = nullptr; diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp new file mode 100644 index 0000000000..bfb119b13b --- /dev/null +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp @@ -0,0 +1,42 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org +*/ +#include "media/view/media_view_group_thumbs.h" + +namespace Media { +namespace View { + +GroupThumbs::GroupThumbs() { +} + +void GroupThumbs::resizeToWidth(int newWidth) { + +} + +int GroupThumbs::height() const { + return 0; +} + +QRect GroupThumbs::paintedRect() const { + return QRect(); +} + +} // namespace View +} // namespace Media diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.h b/Telegram/SourceFiles/media/view/media_view_group_thumbs.h new file mode 100644 index 0000000000..0556e71957 --- /dev/null +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.h @@ -0,0 +1,40 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org +*/ +#pragma once + +namespace Media { +namespace View { + +class GroupThumbs { +public: + GroupThumbs(); + + void resizeToWidth(int newWidth); + int height() const; + + QRect paintedRect() const; + +private: + +}; + +} // namespace View +} // namespace Media diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index e378210555..5da303769b 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -27,10 +27,10 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "core/file_utilities.h" #include "ui/widgets/popup_menu.h" #include "ui/widgets/buttons.h" +#include "ui/text_options.h" #include "media/media_clip_reader.h" #include "media/view/media_clip_controller.h" -#include "styles/style_mediaview.h" -#include "styles/style_history.h" +#include "media/view/media_view_group_thumbs.h" #include "media/media_audio.h" #include "history/history_message.h" #include "history/history_media_types.h" @@ -42,26 +42,15 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "messenger.h" #include "storage/file_download.h" #include "calls/calls_instance.h" +#include "styles/style_mediaview.h" +#include "styles/style_history.h" namespace { constexpr auto kPreloadCount = 4; -TextParseOptions _captionTextOptions = { - TextParseLinks | TextParseMentions | TextParseHashtags | TextParseMultiline | TextParseRichText, // flags - 0, // maxw - 0, // maxh - Qt::LayoutDirectionAuto, // dir -}; -TextParseOptions _captionBotOptions = { - TextParseLinks | TextParseMentions | TextParseHashtags | TextParseMultiline | TextParseRichText | TextParseBotCommands, // flags - 0, // maxw - 0, // maxh - Qt::LayoutDirectionAuto, // dir -}; - // Preload X message ids before and after current. -constexpr auto kIdsLimit = 32; +constexpr auto kIdsLimit = 48; // Preload next messages if we went further from current than that. constexpr auto kIdsPreloadAfter = 28; @@ -84,7 +73,8 @@ struct MediaView::UserPhotos { rpl::lifetime lifetime; }; -MediaView::MediaView() : TWidget(nullptr) +MediaView::MediaView() +: TWidget(nullptr) , _transparentBrush(style::transparentPlaceholderBrush()) , _animStarted(getms()) , _docDownload(this, lang(lng_media_download), st::mediaviewFileLink) @@ -99,7 +89,7 @@ MediaView::MediaView() : TWidget(nullptr) TextCustomTagsMap custom; custom.insert(QChar('c'), qMakePair(textcmdStartLink(1), textcmdStopLink())); - _saveMsgText.setRichText(st::mediaviewSaveMsgStyle, lang(lng_mediaview_saved), _textDlgOptions, custom); + _saveMsgText.setRichText(st::mediaviewSaveMsgStyle, lang(lng_mediaview_saved), Ui::DialogTextOptions(), custom); _saveMsg = QRect(0, 0, _saveMsgText.maxWidth() + st::mediaviewSaveMsgPadding.left() + st::mediaviewSaveMsgPadding.right(), st::mediaviewSaveMsgStyle.font->height + st::mediaviewSaveMsgPadding.top() + st::mediaviewSaveMsgPadding.bottom()); _saveMsgText.setLink(1, std::make_shared([this] { showSaveMsgFile(); })); @@ -361,7 +351,7 @@ void MediaView::updateControls() { _dateText = lng_mediaview_date_time(lt_date, d.date().toString(qsl("dd.MM.yy")), lt_time, d.time().toString(cTimeFormat())); } if (_from) { - _fromName.setText(st::mediaviewTextStyle, (_from->migrateTo() ? _from->migrateTo() : _from)->name, _textNameOptions); + _fromName.setText(st::mediaviewTextStyle, (_from->migrateTo() ? _from->migrateTo() : _from)->name, Ui::NameTextOptions()); _nameNav = myrtlrect(st::mediaviewTextLeft, height() - st::mediaviewTextTop, qMin(_fromName.maxWidth(), width() / 3), st::mediaviewFont->height); _dateNav = myrtlrect(st::mediaviewTextLeft + _nameNav.width() + st::mediaviewTextSkip, height() - st::mediaviewTextTop, st::mediaviewFont->width(_dateText), st::mediaviewFont->height); } else { @@ -370,20 +360,54 @@ void MediaView::updateControls() { } updateHeader(); refreshNavVisibility(); + resizeCenteredControls(); + + updateOver(mapFromGlobal(QCursor::pos())); + update(); +} + +void MediaView::resizeCenteredControls() { + const auto bottomSkip = std::max( + _dateNav.left() + _dateNav.width(), + _headerNav.left() + _headerNav.width()); + const auto bottomWidth = std::max( + width() - 2 * bottomSkip - 2 * st::mediaviewCaptionMargin.width(), + st::msgMinWidth + + st::mediaviewCaptionPadding.left() + + st::mediaviewCaptionPadding.right()); + if (_groupThumbs) { + _groupThumbs->resizeToWidth(bottomWidth); + _groupThumbsTop = height() - _groupThumbs->height(); + } if (!_caption.isEmpty()) { - int32 skipw = qMax(_dateNav.left() + _dateNav.width(), _headerNav.left() + _headerNav.width()); - int32 maxw = qMin(qMax(width() - 2 * skipw - st::mediaviewCaptionPadding.left() - st::mediaviewCaptionPadding.right() - 2 * st::mediaviewCaptionMargin.width(), int(st::msgMinWidth)), _caption.maxWidth()); - int32 maxh = qMin(_caption.countHeight(maxw), int(height() / 4 - st::mediaviewCaptionPadding.top() - st::mediaviewCaptionPadding.bottom() - 2 * st::mediaviewCaptionMargin.height())); - _captionRect = QRect((width() - maxw) / 2, height() - maxh - st::mediaviewCaptionPadding.bottom() - st::mediaviewCaptionMargin.height(), maxw, maxh); + const auto captionBottom = groupThumbsDisplayed() + ? _groupThumbsTop + : height() - st::mediaviewCaptionMargin.height(); + const auto captionWidth = std::min( + bottomWidth + - st::mediaviewCaptionPadding.left() + - st::mediaviewCaptionPadding.right(), + _caption.maxWidth()); + const auto captionHeight = std::min( + _caption.countHeight(captionWidth), + height() / 4 + - st::mediaviewCaptionPadding.top() + - st::mediaviewCaptionPadding.bottom() + - 2 * st::mediaviewCaptionMargin.height()); + _captionRect = QRect( + (width() - captionWidth) / 2, + captionBottom + - captionHeight + - st::mediaviewCaptionPadding.bottom(), + captionWidth, + captionHeight); } else { _captionRect = QRect(); } if (_clipController) { setClipControllerGeometry(); } - updateOver(mapFromGlobal(QCursor::pos())); - update(); } void MediaView::updateActions() { @@ -1198,6 +1222,31 @@ void MediaView::refreshMediaViewer() { preloadData(0); } +void MediaView::refreshCaption(HistoryItem *item) { + _caption = Text(); + + const auto media = item ? item->getMedia() : nullptr; + if (!media) { + return; + } + + const auto caption = media->getCaption(); + if (caption.text.isEmpty()) { + return; + } + const auto asBot = [&] { + if (const auto author = item->author()->asUser()) { + return author->botInfo != nullptr; + } + return false; + }(); + _caption = Text(st::msgMinWidth); + _caption.setMarkedText( + st::mediaviewCaptionStyle, + caption, + Ui::ItemTextOptions(item)); +} + void MediaView::showPhoto(not_null photo, HistoryItem *context) { if (context) { setContext(context); @@ -1292,21 +1341,7 @@ void MediaView::displayPhoto(not_null photo, HistoryItem *item) { _zoom = 0; - _caption = Text(); - if (const auto media = item ? item->getMedia() : nullptr) { - const auto caption = media->getCaption(); - if (!caption.text.isEmpty()) { - auto asBot = (item->author()->isUser() - && item->author()->asUser()->botInfo); - auto skipw = qMax(_dateNav.left() + _dateNav.width(), _headerNav.left() + _headerNav.width()); - auto maxw = qMin(qMax(width() - 2 * skipw - st::mediaviewCaptionPadding.left() - st::mediaviewCaptionPadding.right() - 2 * st::mediaviewCaptionMargin.width(), int(st::msgMinWidth)), _caption.maxWidth()); - _caption = Text(maxw); - _caption.setMarkedText( - st::mediaviewCaptionStyle, - caption, - itemTextOptions(item)); - } - } + refreshCaption(item); _zoomToScreen = 0; Auth().downloader().clearPriorities(); @@ -2901,3 +2936,20 @@ float64 MediaView::overLevel(OverState control) const { auto i = _animOpacities.constFind(control); return (i == _animOpacities.cend()) ? (_over == control ? 1 : 0) : i->current(); } + +bool MediaView::groupThumbsDisplayed() const { + return _groupThumbs != nullptr; +} + +QRect MediaView::groupThumbsRect() const { + Expects(_groupThumbs != nullptr); + + auto result = _groupThumbs->paintedRect(); + result.moveTopLeft(result.topLeft() + + QPoint(_groupThumbsLeft, _groupThumbsTop)); + return result; +} + +QRect MediaView::groupThumbsFullRect() const { + return QRect(0, width(), _groupThumbsTop, height() - _groupThumbsTop); +} diff --git a/Telegram/SourceFiles/mediaview.h b/Telegram/SourceFiles/mediaview.h index 6ee48aaf95..b2d0b1b020 100644 --- a/Telegram/SourceFiles/mediaview.h +++ b/Telegram/SourceFiles/mediaview.h @@ -32,6 +32,9 @@ struct TrackState; namespace Clip { class Controller; } // namespace Clip +namespace View { +class GroupThumbs; +} // namespace View } // namespace Media namespace Ui { @@ -50,7 +53,7 @@ namespace Notify { struct PeerUpdate; } // namespace Notify -class MediaView : public TWidget, private base::Subscriber, public RPCSender, public ClickHandlerHost { +class MediaView : public TWidget, private base::Subscriber, public ClickHandlerHost { Q_OBJECT public: @@ -183,6 +186,7 @@ private: void validateUserPhotos(); void handleUserPhotosUpdate(UserPhotosSlice &&update); + void refreshCaption(HistoryItem *item); void refreshMediaViewer(); void refreshNavVisibility(); @@ -190,6 +194,7 @@ private: void updateDocSize(); void updateControls(); void updateActions(); + void resizeCenteredControls(); void displayPhoto(not_null photo, HistoryItem *item); void displayDocument(DocumentData *document, HistoryItem *item); @@ -225,9 +230,6 @@ private: void radialStart(); TimeMs radialTimeShift() const; - void deletePhotosDone(const MTPVector &result); - bool deletePhotosFail(const RPCError &error); - void updateHeader(); void snapXY(); @@ -246,6 +248,10 @@ private: bool updateOverState(OverState newState); float64 overLevel(OverState control) const; + bool groupThumbsDisplayed() const; + QRect groupThumbsRect() const; + QRect groupThumbsFullRect() const; + QBrush _transparentBrush; PhotoData *_photo = nullptr; @@ -272,6 +278,9 @@ private: bool _fullScreenVideo = false; int _fullScreenZoomCache = 0; + std::unique_ptr _groupThumbs; + int _groupThumbsLeft = 0; + int _groupThumbsTop = 0; Text _caption; QRect _captionRect; diff --git a/Telegram/SourceFiles/messenger.cpp b/Telegram/SourceFiles/messenger.cpp index 7feca11246..ee20c574b7 100644 --- a/Telegram/SourceFiles/messenger.cpp +++ b/Telegram/SourceFiles/messenger.cpp @@ -47,6 +47,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "window/themes/window_theme.h" #include "history/history_location_manager.h" #include "ui/widgets/tooltip.h" +#include "ui/text_options.h" #include "storage/serialize_common.h" #include "window/window_controller.h" #include "base/qthelp_regex.h" @@ -115,7 +116,7 @@ Messenger::Messenger(not_null launcher) style::startManager(); anim::startManager(); - HistoryInit(); + Ui::InitTextOptions(); Media::Player::start(); DEBUG_LOG(("Application Info: inited...")); @@ -986,7 +987,6 @@ void Messenger::checkMediaViewActivation() { void Messenger::loggedOut() { if (_mediaView) { hideMediaView(); - _mediaView->rpcClear(); _mediaView->clearData(); } } diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 07c79e5409..47e3d15d58 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -37,6 +37,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "history/history_media_types.h" #include "history/history_item_components.h" #include "ui/effects/round_checkbox.h" +#include "ui/text_options.h" namespace Overview { namespace Layout { @@ -754,12 +755,12 @@ void Voice::updateName() { auto version = 0; if (const auto forwarded = parent()->Get()) { if (parent()->fromOriginal()->isChannel()) { - _name.setText(st::semiboldTextStyle, lng_forwarded_channel(lt_channel, App::peerName(parent()->fromOriginal())), _textNameOptions); + _name.setText(st::semiboldTextStyle, lng_forwarded_channel(lt_channel, App::peerName(parent()->fromOriginal())), Ui::NameTextOptions()); } else { - _name.setText(st::semiboldTextStyle, lng_forwarded(lt_user, App::peerName(parent()->fromOriginal())), _textNameOptions); + _name.setText(st::semiboldTextStyle, lng_forwarded(lt_user, App::peerName(parent()->fromOriginal())), Ui::NameTextOptions()); } } else { - _name.setText(st::semiboldTextStyle, App::peerName(parent()->from()), _textNameOptions); + _name.setText(st::semiboldTextStyle, App::peerName(parent()->from()), Ui::NameTextOptions()); } version = parent()->fromOriginal()->nameVersion; _nameVersion = version; diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp index fb04d58c62..d2d291be27 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp @@ -22,6 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/effects/ripple_animation.h" #include "ui/widgets/popup_menu.h" +#include "ui/text_options.h" #include "styles/style_profile.h" #include "styles/style_widgets.h" #include "auth_session.h" @@ -100,7 +101,10 @@ void PeerListWidget::paintItem(Painter &p, int x, int y, Item *item, bool select item->peer->paintUserpicLeft(p, x + _st.photoPosition.x(), y + _st.photoPosition.y(), width(), _st.photoSize); if (item->name.isEmpty()) { - item->name.setText(st::msgNameStyle, App::peerName(item->peer), _textNameOptions); + item->name.setText( + st::msgNameStyle, + App::peerName(item->peer), + Ui::NameTextOptions()); } int nameLeft = x + _st.namePosition.x(); int nameTop = y + _st.namePosition.y(); diff --git a/Telegram/SourceFiles/ui/text_options.cpp b/Telegram/SourceFiles/ui/text_options.cpp new file mode 100644 index 0000000000..8bc3180b7e --- /dev/null +++ b/Telegram/SourceFiles/ui/text_options.cpp @@ -0,0 +1,257 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org +*/ +#include "ui/text_options.h" + +#include "styles/style_window.h" + +namespace Ui { +namespace { + +TextParseOptions HistoryTextOptions = { + TextParseLinks + | TextParseMentions + | TextParseHashtags + | TextParseMultiline + | TextParseRichText + | TextParseMarkdown, // flags + 0, // maxw + 0, // maxh + Qt::LayoutDirectionAuto, // dir +}; + +TextParseOptions HistoryBotOptions = { + TextParseLinks + | TextParseMentions + | TextParseHashtags + | TextParseBotCommands + | TextParseMultiline + | TextParseRichText + | TextParseMarkdown, // flags + 0, // maxw + 0, // maxh + Qt::LayoutDirectionAuto, // dir +}; + +TextParseOptions HistoryServiceOptions = { + TextParseLinks + | TextParseMentions + | TextParseHashtags + //| TextParseMultiline + | TextParseRichText, // flags + 0, // maxw + 0, // maxh + Qt::LayoutDirectionAuto, // lang-dependent +}; + +TextParseOptions HistoryTextNoMonoOptions = { + TextParseLinks + | TextParseMentions + | TextParseHashtags + | TextParseMultiline + | TextParseRichText, // flags + 0, // maxw + 0, // maxh + Qt::LayoutDirectionAuto, // dir +}; + +TextParseOptions HistoryBotNoMonoOptions = { + TextParseLinks + | TextParseMentions + | TextParseHashtags + | TextParseBotCommands + | TextParseMultiline + | TextParseRichText, // flags + 0, // maxw + 0, // maxh + Qt::LayoutDirectionAuto, // dir +}; + +TextParseOptions TextNameOptions = { + 0, // flags + 4096, // maxw + 1, // maxh + Qt::LayoutDirectionAuto, // lang-dependent +}; + +TextParseOptions TextDialogOptions = { + TextParseRichText, // flags + 0, // maxw is style-dependent + 1, // maxh + Qt::LayoutDirectionAuto, // lang-dependent +}; + +TextParseOptions WebpageTitleOptions = { + TextParseMultiline | TextParseRichText, // flags + 0, // maxw + 0, // maxh + Qt::LayoutDirectionAuto, // dir +}; + +TextParseOptions WebpageDescriptionOptions = { + TextParseLinks + | TextParseMentions + | TextParseHashtags + | TextParseMultiline + | TextParseRichText + | TextParseMarkdown, // flags + 0, // maxw + 0, // maxh + Qt::LayoutDirectionAuto, // dir +}; + +TextParseOptions TwitterDescriptionOptions = { + TextParseLinks + | TextParseMentions + | TextTwitterMentions + | TextParseHashtags + | TextTwitterHashtags + | TextParseMultiline + | TextParseRichText, // flags + 0, // maxw + 0, // maxh + Qt::LayoutDirectionAuto, // dir +}; + +TextParseOptions InstagramDescriptionOptions = { + TextParseLinks + | TextParseMentions + | TextInstagramMentions + | TextParseHashtags + | TextInstagramHashtags + | TextParseMultiline + | TextParseRichText, // flags + 0, // maxw + 0, // maxh + Qt::LayoutDirectionAuto, // dir +}; + +bool UseBotTextOptions( + not_null history, + not_null author) { + if (const auto user = history->peer->asUser()) { + if (user->botInfo) { + return true; + } + } else if (const auto chat = history->peer->asChat()) { + if (chat->botStatus >= 0) { + return true; + } + } else if (const auto group = history->peer->asMegagroup()) { + if (group->mgInfo->botStatus >= 0) { + return true; + } + } + if (const auto user = author->asUser()) { + if (user->botInfo) { + return true; + } + } + return false; +} + +} // namespace + +void InitTextOptions() { + HistoryServiceOptions.dir + = TextNameOptions.dir + = TextDialogOptions.dir + = cLangDir(); + TextDialogOptions.maxw = st::columnMaximalWidthLeft * 2; + WebpageTitleOptions.maxh = st::webPageTitleFont->height * 2; + WebpageTitleOptions.maxw + = WebpageDescriptionOptions.maxw + = TwitterDescriptionOptions.maxw + = InstagramDescriptionOptions.maxw + = st::msgMaxWidth + - st::msgPadding.left() + - st::webPageLeft + - st::msgPadding.right(); + WebpageDescriptionOptions.maxh = st::webPageDescriptionFont->height * 3; +} + +const TextParseOptions &ItemTextDefaultOptions() { + return HistoryTextOptions; +} + +const TextParseOptions &ItemTextBotDefaultOptions() { + return HistoryBotOptions; +} + +const TextParseOptions &ItemTextNoMonoOptions() { + return HistoryTextNoMonoOptions; +} + +const TextParseOptions &ItemTextBotNoMonoOptions() { + return HistoryBotNoMonoOptions; +} + +const TextParseOptions &ItemTextServiceOptions() { + return HistoryServiceOptions; +} + +const TextParseOptions &WebpageTextTitleOptions() { + return WebpageTitleOptions; +} + +const TextParseOptions &WebpageTextDescriptionOptions( + const QString &siteName) { + if (siteName == qstr("Twitter")) { + return TwitterDescriptionOptions; + } else if (siteName == qstr("Instagram")) { + return InstagramDescriptionOptions; + } + return WebpageDescriptionOptions; +} + +const TextParseOptions &NameTextOptions() { + return TextNameOptions; +} + +const TextParseOptions &DialogTextOptions() { + return TextDialogOptions; +} + +const TextParseOptions &ItemTextOptions( + not_null history, + not_null author) { + return UseBotTextOptions(history, author) + ? HistoryBotOptions + : HistoryTextOptions; +} + +const TextParseOptions &ItemTextOptions(not_null item) { + return ItemTextOptions(item->history(), item->author()); +} + +const TextParseOptions &ItemTextNoMonoOptions( + not_null history, + not_null author) { + return UseBotTextOptions(history, author) + ? HistoryBotNoMonoOptions + : HistoryTextNoMonoOptions; +} + +const TextParseOptions &ItemTextNoMonoOptions( + not_null item) { + return ItemTextNoMonoOptions(item->history(), item->author()); +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/text_options.h b/Telegram/SourceFiles/ui/text_options.h new file mode 100644 index 0000000000..4af89aad15 --- /dev/null +++ b/Telegram/SourceFiles/ui/text_options.h @@ -0,0 +1,49 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org +*/ +#pragma once + +namespace Ui { + +void InitTextOptions(); + +const TextParseOptions &ItemTextDefaultOptions(); +const TextParseOptions &ItemTextBotDefaultOptions(); +const TextParseOptions &ItemTextNoMonoOptions(); +const TextParseOptions &ItemTextBotNoMonoOptions(); +const TextParseOptions &ItemTextServiceOptions(); + +const TextParseOptions &WebpageTextTitleOptions(); +const TextParseOptions &WebpageTextDescriptionOptions( + const QString &siteName = QString()); + +const TextParseOptions &NameTextOptions(); +const TextParseOptions &DialogTextOptions(); + +const TextParseOptions &ItemTextOptions( + not_null history, + not_null author); +const TextParseOptions &ItemTextNoMonoOptions( + not_null history, + not_null author); +const TextParseOptions &ItemTextOptions(not_null item); +const TextParseOptions &ItemTextNoMonoOptions(not_null item); + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/widgets/multi_select.cpp b/Telegram/SourceFiles/ui/widgets/multi_select.cpp index 232a15c295..f4c23861c6 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.cpp +++ b/Telegram/SourceFiles/ui/widgets/multi_select.cpp @@ -25,6 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/input_fields.h" #include "ui/widgets/scroll_area.h" #include "ui/effects/cross_animation.h" +#include "ui/text_options.h" #include "lang/lang_keys.h" namespace Ui { @@ -43,7 +44,7 @@ MultiSelect::Item::Item(const style::MultiSelectItem &st, uint64 id, const QStri } void MultiSelect::Item::setText(const QString &text) { - _text.setText(_st.style, text, _textNameOptions); + _text.setText(_st.style, text, NameTextOptions()); _width = _st.height + _st.padding.left() + _text.maxWidth() + _st.padding.right(); accumulate_min(_width, _st.maxWidth); } diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp index aa87b79bb3..e1037ebdf7 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp @@ -23,6 +23,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "window/themes/window_theme.h" #include "lang/lang_keys.h" #include "platform/platform_window_title.h" +#include "ui/text_options.h" #include "styles/style_widgets.h" #include "styles/style_window.h" #include "styles/style_mediaview.h" @@ -213,13 +214,13 @@ void Generator::prepare() { void Generator::addRow(QString name, int peerIndex, QString date, QString text) { Row row; - row.name.setText(st::msgNameStyle, name, _textNameOptions); + row.name.setText(st::msgNameStyle, name, Ui::NameTextOptions()); row.letters = fillLetters(name); row.peerIndex = peerIndex; row.date = date; - row.text.setRichText(st::dialogsTextStyle, text, _textDlgOptions); + row.text.setRichText(st::dialogsTextStyle, text, Ui::DialogTextOptions()); _rows.push_back(std::move(row)); } @@ -268,7 +269,7 @@ int Generator::computeInfoWidth(Status status, QString date) { void Generator::addTextBubble(QString text, QString date, Status status) { Bubble bubble; auto skipBlock = computeSkipBlock(status, date); - bubble.text.setRichText(st::messageTextStyle, text + textcmdSkipBlock(skipBlock.width(), skipBlock.height()), _historyTextOptions); + bubble.text.setRichText(st::messageTextStyle, text + textcmdSkipBlock(skipBlock.width(), skipBlock.height()), Ui::ItemTextDefaultOptions()); auto width = _history.width() - st::msgMargin.left() - st::msgMargin.right(); accumulate_min(width, st::msgPadding.left() + bubble.text.maxWidth() + st::msgPadding.right()); @@ -292,7 +293,7 @@ void Generator::addPhotoBubble(QString image, QString caption, QString date, Sta bubble.photoWidth = convertScale(bubble.photo.width() / 2); bubble.photoHeight = convertScale(bubble.photo.height() / 2); auto skipBlock = computeSkipBlock(status, date); - bubble.text.setRichText(st::messageTextStyle, caption + textcmdSkipBlock(skipBlock.width(), skipBlock.height()), _historyTextOptions); + bubble.text.setRichText(st::messageTextStyle, caption + textcmdSkipBlock(skipBlock.width(), skipBlock.height()), Ui::ItemTextDefaultOptions()); auto width = _history.width() - st::msgMargin.left() - st::msgMargin.right(); accumulate_min(width, bubble.photoWidth); @@ -325,7 +326,7 @@ void Generator::generateData() { _rows.back().status = Status::Received; addRow("Davy Jones", 5, "4:00", textcmdLink(1, "Keynote.pdf")); - _topBarName.setText(st::msgNameStyle, "Eva Summer", _textNameOptions); + _topBarName.setText(st::msgNameStyle, "Eva Summer", Ui::NameTextOptions()); _topBarStatus = "online"; _topBarStatusActive = true; @@ -345,8 +346,8 @@ void Generator::generateData() { _bubbles.back().attached = true; _bubbles.back().tail = true; addTextBubble("Reminds me of a Chinese proverb: the best time to plant a tree was 20 years ago. The second best time is now.", "11:00", Status::None); - _bubbles.back().replyName.setText(st::msgNameStyle, "Alex Cassio", _textNameOptions); - _bubbles.back().replyText.setText(st::messageTextStyle, "Mark Twain said that " + QString() + QChar(9757) + QChar(55356) + QChar(57339), _textDlgOptions); + _bubbles.back().replyName.setText(st::msgNameStyle, "Alex Cassio", Ui::NameTextOptions()); + _bubbles.back().replyText.setText(st::messageTextStyle, "Mark Twain said that " + QString() + QChar(9757) + QChar(55356) + QChar(57339), Ui::DialogTextOptions()); } Generator::Generator(const Instance &theme, const CurrentData ¤t) diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index ac61482f48..f407a4f5ce 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -343,6 +343,8 @@ <(src_loc)/media/view/media_clip_playback.h <(src_loc)/media/view/media_clip_volume_controller.cpp <(src_loc)/media/view/media_clip_volume_controller.h +<(src_loc)/media/view/media_view_group_thumbs.cpp +<(src_loc)/media/view/media_view_group_thumbs.h <(src_loc)/media/media_audio.cpp <(src_loc)/media/media_audio.h <(src_loc)/media/media_audio_capture.cpp @@ -628,6 +630,8 @@ <(src_loc)/ui/search_field_controller.h <(src_loc)/ui/special_buttons.cpp <(src_loc)/ui/special_buttons.h +<(src_loc)/ui/text_options.cpp +<(src_loc)/ui/text_options.h <(src_loc)/ui/twidget.cpp <(src_loc)/ui/twidget.h <(src_loc)/ui/unread_badge.cpp