From b3059248d44e4beac41021f8aed6b524c39d8049 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 31 May 2018 14:13:11 +0300 Subject: [PATCH] Display colored reply preview. Fixes #4768. --- Telegram/Resources/basic.style | 18 ++++++ Telegram/SourceFiles/history/history_item.h | 2 +- .../history/history_item_components.cpp | 12 ++-- .../SourceFiles/history/history_service.cpp | 7 +- .../SourceFiles/history/history_widget.cpp | 64 +++++++------------ Telegram/SourceFiles/history/history_widget.h | 1 + 6 files changed, 55 insertions(+), 49 deletions(-) diff --git a/Telegram/Resources/basic.style b/Telegram/Resources/basic.style index 5ff0320d84..4badfb3a1b 100644 --- a/Telegram/Resources/basic.style +++ b/Telegram/Resources/basic.style @@ -172,6 +172,21 @@ inFwdTextPaletteSelected: TextPalette(defaultTextPalette) { outFwdTextPaletteSelected: TextPalette(defaultTextPalette) { linkFg: msgOutServiceFgSelected; } +inReplyTextPalette: TextPalette(inTextPalette) { + linkFg: msgInDateFg; +} +inReplyTextPaletteSelected: TextPalette(inTextPaletteSelected) { + linkFg: msgInDateFgSelected; +} +outReplyTextPalette: TextPalette(outTextPalette) { + linkFg: msgOutDateFg; +} +outReplyTextPaletteSelected: TextPalette(outTextPaletteSelected) { + linkFg: msgOutDateFgSelected; +} +imgReplyTextPalette: TextPalette(defaultTextPalette) { + linkFg: msgImgReplyBarColor; +} inSemiboldPalette: TextPalette(inTextPalette) { linkFg: msgInServiceFg; selectFg: msgInServiceFgSelected; @@ -182,6 +197,9 @@ outSemiboldPalette: TextPalette(outTextPalette) { selectFg: msgOutServiceFgSelected; selectLinkFg: msgOutServiceFgSelected; } +historyComposeAreaPalette: TextPalette(defaultTextPalette) { + linkFg: historyComposeAreaFgService; +} mediaCaptionSkip: 5px; mediaInBubbleSkip: 5px; diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index d61e41bdd5..011fe08a72 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -183,7 +183,7 @@ public: // Example: "[link1-start]You:[link1-end] [link1-start]Photo,[link1-end] caption text" virtual QString inDialogsText(DrawInDialog way) const; virtual QString inReplyText() const { - return notificationText(); + return inDialogsText(DrawInDialog::WithoutSender); } virtual TextWithEntities originalText() const { return { QString(), EntitiesInText() }; diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 1284041f15..1539dd24eb 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -149,7 +149,7 @@ bool HistoryMessageReply::updateData( if (replyToMsg) { replyToText.setText( st::messageTextStyle, - TextUtilities::Clean(replyToMsg->inReplyText()), + replyToMsg->inReplyText(), Ui::DialogTextOptions()); updateName(); @@ -271,14 +271,14 @@ void HistoryMessageReply::paint( p.drawText(x + st::msgReplyBarSkip + previewSkip + replyToName.maxWidth() + st::msgServiceFont->spacew, y + st::msgReplyPadding.top() + st::msgServiceFont->ascent, replyToVia->text); } - auto replyToAsMsg = replyToMsg->toHistoryMessage(); - if (!(flags & PaintFlag::InBubble)) { - } else if (!replyToAsMsg) { - p.setPen(outbg ? (selected ? st::msgOutDateFgSelected : st::msgOutDateFg) : (selected ? st::msgInDateFgSelected : st::msgInDateFg)); - } else { + if (flags & PaintFlag::InBubble) { p.setPen(outbg ? (selected ? st::historyTextOutFgSelected : st::historyTextOutFg) : (selected ? st::historyTextInFgSelected : st::historyTextInFg)); + p.setTextPalette(outbg ? (selected ? st::outReplyTextPaletteSelected : st::outReplyTextPalette) : (selected ? st::inReplyTextPaletteSelected : st::inReplyTextPalette)); + } else { + p.setTextPalette(st::imgReplyTextPalette); } replyToText.drawLeftElided(p, x + st::msgReplyBarSkip + previewSkip, y + st::msgReplyPadding.top() + st::msgServiceNameFont->height, w - st::msgReplyBarSkip - previewSkip, w + 2 * x); + p.setTextPalette(selected ? (outbg ? st::outTextPaletteSelected : st::inTextPaletteSelected) : (outbg ? st::outTextPalette : st::inTextPalette)); } } else { p.setFont(st::msgDateFont); diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index a7abd04c1d..a243d579c6 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -464,8 +464,11 @@ QString HistoryService::inDialogsText(DrawInDialog way) const { } QString HistoryService::inReplyText() const { - QString result = HistoryService::notificationText(); - return result.trimmed().startsWith(author()->name) ? result.trimmed().mid(author()->name.size()).trimmed() : result; + const auto result = HistoryService::notificationText(); + const auto text = result.trimmed().startsWith(author()->name) + ? result.trimmed().mid(author()->name.size()).trimmed() + : result; + return textcmdLink(1, text); } std::unique_ptr HistoryService::createView( diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 91a74c7590..7b0b815338 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -3798,12 +3798,7 @@ 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()), - Ui::DialogTextOptions()); - _fieldBarCancel->show(); - updateMouseTracking(); + updateReplyEditText(_kbReplyTo); } if (manual && _history) { _history->lastKeyboardHiddenId = 0; @@ -3820,12 +3815,7 @@ 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()), - Ui::DialogTextOptions()); - _fieldBarCancel->show(); - updateMouseTracking(); + updateReplyEditText(_kbReplyTo); } if (manual && _history) { _history->lastKeyboardHiddenId = 0; @@ -5103,12 +5093,7 @@ 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()), - Ui::DialogTextOptions()); - _fieldBarCancel->show(); - updateMouseTracking(); + updateReplyEditText(_kbReplyTo); } } else { if (!_a_show.animating()) { @@ -5835,15 +5820,8 @@ void HistoryWidget::replyToMessage(not_null item) { } else { _replyEditMsg = item; _replyToId = item->id; - _replyEditMsgText.setText( - st::messageTextStyle, - TextUtilities::Clean(_replyEditMsg->inReplyText()), - Ui::DialogTextOptions()); - + updateReplyEditText(_replyEditMsg); updateBotKeyboard(); - - if (!_field->isHidden()) _fieldBarCancel->show(); - updateMouseTracking(); updateReplyToName(); updateControlsGeometry(); updateField(); @@ -6467,6 +6445,17 @@ void HistoryWidget::messageDataReceived(ChannelData *channel, MsgId msgId) { } } +void HistoryWidget::updateReplyEditText(not_null item) { + _replyEditMsgText.setText( + st::messageTextStyle, + item->inReplyText(), + Ui::DialogTextOptions()); + if (!_field->isHidden() || _recording) { + _fieldBarCancel->show(); + updateMouseTracking(); + } +} + void HistoryWidget::updateReplyEditTexts(bool force) { if (!force) { if (_replyEditMsg || (!_editMsgId && !_replyToId)) { @@ -6477,17 +6466,8 @@ void HistoryWidget::updateReplyEditTexts(bool force) { _replyEditMsg = App::histItemById(_channel, _editMsgId ? _editMsgId : _replyToId); } if (_replyEditMsg) { - _replyEditMsgText.setText( - st::messageTextStyle, - TextUtilities::Clean(_replyEditMsg->inReplyText()), - Ui::DialogTextOptions()); - + updateReplyEditText(_replyEditMsg); updateBotKeyboard(); - - if (!_field->isHidden() || _recording) { - _fieldBarCancel->show(); - updateMouseTracking(); - } updateReplyToName(); updateField(); } else if (force) { @@ -6536,13 +6516,13 @@ void HistoryWidget::updateForwardingTexts() { if (count < 2) { text = _toForward.front()->inReplyText(); } else { - text = lng_forward_messages(lt_count, count); + text = textcmdLink(1, lng_forward_messages(lt_count, count)); } } _toForwardFrom.setText(st::msgNameStyle, from, Ui::NameTextOptions()); _toForwardText.setText( st::messageTextStyle, - TextUtilities::Clean(text), + text, Ui::DialogTextOptions()); _toForwardNameVersion = version; } @@ -6614,8 +6594,10 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) { } else { _replyToName.drawElided(p, replyLeft, backy + st::msgReplyPadding.top(), width() - replyLeft - _fieldBarCancel->width() - st::msgReplyPadding.right()); } - p.setPen(!drawMsgText->toHistoryMessage() ? st::historyComposeAreaFgService : st::historyComposeAreaFg); + p.setPen(st::historyComposeAreaFg); + p.setTextPalette(st::historyComposeAreaPalette); _replyEditMsgText.drawElided(p, replyLeft, backy + st::msgReplyPadding.top() + st::msgServiceNameFont->height, width() - replyLeft - _fieldBarCancel->width() - st::msgReplyPadding.right()); + p.restoreTextPalette(); } else { p.setFont(st::msgDateFont); p.setPen(st::historyComposeAreaFgService); @@ -6646,8 +6628,10 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) { } p.setPen(st::historyReplyNameFg); _toForwardFrom.drawElided(p, forwardLeft, backy + st::msgReplyPadding.top(), width() - forwardLeft - _fieldBarCancel->width() - st::msgReplyPadding.right()); - p.setPen(serviceColor ? st::historyComposeAreaFgService : st::historyComposeAreaFg); + p.setPen(st::historyComposeAreaFg); + p.setTextPalette(st::historyComposeAreaPalette); _toForwardText.drawElided(p, forwardLeft, backy + st::msgReplyPadding.top() + st::msgServiceNameFont->height, width() - forwardLeft - _fieldBarCancel->width() - st::msgReplyPadding.right()); + p.restoreTextPalette(); } } if (drawWebPagePreview) { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 5ca18c8754..49b3b30948 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -571,6 +571,7 @@ private: object_ptr _fieldBarCancel; void updateReplyEditTexts(bool force = false); + void updateReplyEditText(not_null item); struct PinnedBar { PinnedBar(MsgId msgId, HistoryWidget *parent);