Display colored reply preview.

Fixes #4768.
This commit is contained in:
John Preston 2018-05-31 14:13:11 +03:00
parent 0cbad9098e
commit b3059248d4
6 changed files with 55 additions and 49 deletions

View File

@ -172,6 +172,21 @@ inFwdTextPaletteSelected: TextPalette(defaultTextPalette) {
outFwdTextPaletteSelected: TextPalette(defaultTextPalette) { outFwdTextPaletteSelected: TextPalette(defaultTextPalette) {
linkFg: msgOutServiceFgSelected; 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) { inSemiboldPalette: TextPalette(inTextPalette) {
linkFg: msgInServiceFg; linkFg: msgInServiceFg;
selectFg: msgInServiceFgSelected; selectFg: msgInServiceFgSelected;
@ -182,6 +197,9 @@ outSemiboldPalette: TextPalette(outTextPalette) {
selectFg: msgOutServiceFgSelected; selectFg: msgOutServiceFgSelected;
selectLinkFg: msgOutServiceFgSelected; selectLinkFg: msgOutServiceFgSelected;
} }
historyComposeAreaPalette: TextPalette(defaultTextPalette) {
linkFg: historyComposeAreaFgService;
}
mediaCaptionSkip: 5px; mediaCaptionSkip: 5px;
mediaInBubbleSkip: 5px; mediaInBubbleSkip: 5px;

View File

@ -183,7 +183,7 @@ public:
// Example: "[link1-start]You:[link1-end] [link1-start]Photo,[link1-end] caption text" // Example: "[link1-start]You:[link1-end] [link1-start]Photo,[link1-end] caption text"
virtual QString inDialogsText(DrawInDialog way) const; virtual QString inDialogsText(DrawInDialog way) const;
virtual QString inReplyText() const { virtual QString inReplyText() const {
return notificationText(); return inDialogsText(DrawInDialog::WithoutSender);
} }
virtual TextWithEntities originalText() const { virtual TextWithEntities originalText() const {
return { QString(), EntitiesInText() }; return { QString(), EntitiesInText() };

View File

@ -149,7 +149,7 @@ bool HistoryMessageReply::updateData(
if (replyToMsg) { if (replyToMsg) {
replyToText.setText( replyToText.setText(
st::messageTextStyle, st::messageTextStyle,
TextUtilities::Clean(replyToMsg->inReplyText()), replyToMsg->inReplyText(),
Ui::DialogTextOptions()); Ui::DialogTextOptions());
updateName(); 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); 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) {
if (!(flags & PaintFlag::InBubble)) {
} else if (!replyToAsMsg) {
p.setPen(outbg ? (selected ? st::msgOutDateFgSelected : st::msgOutDateFg) : (selected ? st::msgInDateFgSelected : st::msgInDateFg));
} else {
p.setPen(outbg ? (selected ? st::historyTextOutFgSelected : st::historyTextOutFg) : (selected ? st::historyTextInFgSelected : st::historyTextInFg)); 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); 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 { } else {
p.setFont(st::msgDateFont); p.setFont(st::msgDateFont);

View File

@ -464,8 +464,11 @@ QString HistoryService::inDialogsText(DrawInDialog way) const {
} }
QString HistoryService::inReplyText() const { QString HistoryService::inReplyText() const {
QString result = HistoryService::notificationText(); const auto result = HistoryService::notificationText();
return result.trimmed().startsWith(author()->name) ? result.trimmed().mid(author()->name.size()).trimmed() : result; const auto text = result.trimmed().startsWith(author()->name)
? result.trimmed().mid(author()->name.size()).trimmed()
: result;
return textcmdLink(1, text);
} }
std::unique_ptr<HistoryView::Element> HistoryService::createView( std::unique_ptr<HistoryView::Element> HistoryService::createView(

View File

@ -3798,12 +3798,7 @@ void HistoryWidget::onKbToggle(bool manual) {
_kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard->forceReply()) ? App::histItemById(_keyboard->forMsgId()) : 0; _kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard->forceReply()) ? App::histItemById(_keyboard->forMsgId()) : 0;
if (_kbReplyTo && !_editMsgId && !_replyToId && fieldEnabled) { if (_kbReplyTo && !_editMsgId && !_replyToId && fieldEnabled) {
updateReplyToName(); updateReplyToName();
_replyEditMsgText.setText( updateReplyEditText(_kbReplyTo);
st::messageTextStyle,
TextUtilities::Clean(_kbReplyTo->inReplyText()),
Ui::DialogTextOptions());
_fieldBarCancel->show();
updateMouseTracking();
} }
if (manual && _history) { if (manual && _history) {
_history->lastKeyboardHiddenId = 0; _history->lastKeyboardHiddenId = 0;
@ -3820,12 +3815,7 @@ void HistoryWidget::onKbToggle(bool manual) {
_kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard->forceReply()) ? App::histItemById(_keyboard->forMsgId()) : 0; _kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard->forceReply()) ? App::histItemById(_keyboard->forMsgId()) : 0;
if (_kbReplyTo && !_editMsgId && !_replyToId) { if (_kbReplyTo && !_editMsgId && !_replyToId) {
updateReplyToName(); updateReplyToName();
_replyEditMsgText.setText( updateReplyEditText(_kbReplyTo);
st::messageTextStyle,
TextUtilities::Clean(_kbReplyTo->inReplyText()),
Ui::DialogTextOptions());
_fieldBarCancel->show();
updateMouseTracking();
} }
if (manual && _history) { if (manual && _history) {
_history->lastKeyboardHiddenId = 0; _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; _kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard->forceReply()) ? App::histItemById(_keyboard->forMsgId()) : 0;
if (_kbReplyTo && !_replyToId) { if (_kbReplyTo && !_replyToId) {
updateReplyToName(); updateReplyToName();
_replyEditMsgText.setText( updateReplyEditText(_kbReplyTo);
st::messageTextStyle,
TextUtilities::Clean(_kbReplyTo->inReplyText()),
Ui::DialogTextOptions());
_fieldBarCancel->show();
updateMouseTracking();
} }
} else { } else {
if (!_a_show.animating()) { if (!_a_show.animating()) {
@ -5835,15 +5820,8 @@ void HistoryWidget::replyToMessage(not_null<HistoryItem*> item) {
} else { } else {
_replyEditMsg = item; _replyEditMsg = item;
_replyToId = item->id; _replyToId = item->id;
_replyEditMsgText.setText( updateReplyEditText(_replyEditMsg);
st::messageTextStyle,
TextUtilities::Clean(_replyEditMsg->inReplyText()),
Ui::DialogTextOptions());
updateBotKeyboard(); updateBotKeyboard();
if (!_field->isHidden()) _fieldBarCancel->show();
updateMouseTracking();
updateReplyToName(); updateReplyToName();
updateControlsGeometry(); updateControlsGeometry();
updateField(); updateField();
@ -6467,6 +6445,17 @@ void HistoryWidget::messageDataReceived(ChannelData *channel, MsgId msgId) {
} }
} }
void HistoryWidget::updateReplyEditText(not_null<HistoryItem*> item) {
_replyEditMsgText.setText(
st::messageTextStyle,
item->inReplyText(),
Ui::DialogTextOptions());
if (!_field->isHidden() || _recording) {
_fieldBarCancel->show();
updateMouseTracking();
}
}
void HistoryWidget::updateReplyEditTexts(bool force) { void HistoryWidget::updateReplyEditTexts(bool force) {
if (!force) { if (!force) {
if (_replyEditMsg || (!_editMsgId && !_replyToId)) { if (_replyEditMsg || (!_editMsgId && !_replyToId)) {
@ -6477,17 +6466,8 @@ void HistoryWidget::updateReplyEditTexts(bool force) {
_replyEditMsg = App::histItemById(_channel, _editMsgId ? _editMsgId : _replyToId); _replyEditMsg = App::histItemById(_channel, _editMsgId ? _editMsgId : _replyToId);
} }
if (_replyEditMsg) { if (_replyEditMsg) {
_replyEditMsgText.setText( updateReplyEditText(_replyEditMsg);
st::messageTextStyle,
TextUtilities::Clean(_replyEditMsg->inReplyText()),
Ui::DialogTextOptions());
updateBotKeyboard(); updateBotKeyboard();
if (!_field->isHidden() || _recording) {
_fieldBarCancel->show();
updateMouseTracking();
}
updateReplyToName(); updateReplyToName();
updateField(); updateField();
} else if (force) { } else if (force) {
@ -6536,13 +6516,13 @@ void HistoryWidget::updateForwardingTexts() {
if (count < 2) { if (count < 2) {
text = _toForward.front()->inReplyText(); text = _toForward.front()->inReplyText();
} else { } else {
text = lng_forward_messages(lt_count, count); text = textcmdLink(1, lng_forward_messages(lt_count, count));
} }
} }
_toForwardFrom.setText(st::msgNameStyle, from, Ui::NameTextOptions()); _toForwardFrom.setText(st::msgNameStyle, from, Ui::NameTextOptions());
_toForwardText.setText( _toForwardText.setText(
st::messageTextStyle, st::messageTextStyle,
TextUtilities::Clean(text), text,
Ui::DialogTextOptions()); Ui::DialogTextOptions());
_toForwardNameVersion = version; _toForwardNameVersion = version;
} }
@ -6614,8 +6594,10 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) {
} else { } else {
_replyToName.drawElided(p, replyLeft, backy + st::msgReplyPadding.top(), width() - replyLeft - _fieldBarCancel->width() - st::msgReplyPadding.right()); _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()); _replyEditMsgText.drawElided(p, replyLeft, backy + st::msgReplyPadding.top() + st::msgServiceNameFont->height, width() - replyLeft - _fieldBarCancel->width() - st::msgReplyPadding.right());
p.restoreTextPalette();
} else { } else {
p.setFont(st::msgDateFont); p.setFont(st::msgDateFont);
p.setPen(st::historyComposeAreaFgService); p.setPen(st::historyComposeAreaFgService);
@ -6646,8 +6628,10 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) {
} }
p.setPen(st::historyReplyNameFg); p.setPen(st::historyReplyNameFg);
_toForwardFrom.drawElided(p, forwardLeft, backy + st::msgReplyPadding.top(), width() - forwardLeft - _fieldBarCancel->width() - st::msgReplyPadding.right()); _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()); _toForwardText.drawElided(p, forwardLeft, backy + st::msgReplyPadding.top() + st::msgServiceNameFont->height, width() - forwardLeft - _fieldBarCancel->width() - st::msgReplyPadding.right());
p.restoreTextPalette();
} }
} }
if (drawWebPagePreview) { if (drawWebPagePreview) {

View File

@ -571,6 +571,7 @@ private:
object_ptr<Ui::IconButton> _fieldBarCancel; object_ptr<Ui::IconButton> _fieldBarCancel;
void updateReplyEditTexts(bool force = false); void updateReplyEditTexts(bool force = false);
void updateReplyEditText(not_null<HistoryItem*> item);
struct PinnedBar { struct PinnedBar {
PinnedBar(MsgId msgId, HistoryWidget *parent); PinnedBar(MsgId msgId, HistoryWidget *parent);