From 07a274f92781394e4dd3eeaed2c4862f05b090d8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 30 Apr 2017 16:04:38 +0300 Subject: [PATCH] Improve video message status text in a web page. Show duration / progress text in the bottom left bubble corner. --- Telegram/SourceFiles/history/history_media.h | 7 ++++ .../history/history_media_types.cpp | 32 ++++++++++++++++--- .../SourceFiles/history/history_media_types.h | 2 ++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/history/history_media.h b/Telegram/SourceFiles/history/history_media.h index cbb50f9ea..7b85cf0a9 100644 --- a/Telegram/SourceFiles/history/history_media.h +++ b/Telegram/SourceFiles/history/history_media.h @@ -151,6 +151,13 @@ public: return false; } + // An attach media in a web page can provide an + // additional text to be displayed below the attach. + // For example duration / progress for video messages. + virtual QString additionalInfoString() const { + return QString(); + } + int currentWidth() const { return _width; } diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index 23287334a..37c99000c 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -1971,7 +1971,7 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM (selected ? st::historyVideoMessageMuteSelected : st::historyVideoMessageMute).paintInCenter(p, muteRect); } - if (isRound) { + if (!isChildMedia && isRound) { auto mediaUnread = _parent->isMediaUnread(); auto statusW = st::normalFont->width(_statusText) + 2 * st::msgDateImgPadding.x(); auto statusH = st::normalFont->height + 2 * st::msgDateImgPadding.y(); @@ -1993,7 +1993,7 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM p.drawEllipse(rtlrect(statusX - st::msgDateImgPadding.x() + statusW - st::msgDateImgPadding.x() - st::mediaUnreadSize, statusY + st::mediaUnreadTop, st::mediaUnreadSize, st::mediaUnreadSize, _width)); } } - if (!isChildMedia && (via || reply || forwarded)) { + if (via || reply || forwarded) { auto rectw = _width - usew - st::msgReplyPadding.left(); auto innerw = rectw - (st::msgReplyPadding.left() + st::msgReplyPadding.right()); auto recth = st::msgReplyPadding.top() + st::msgReplyPadding.bottom(); @@ -2227,6 +2227,14 @@ void HistoryGif::updateStatusText() const { } } +QString HistoryGif::additionalInfoString() const { + if (_data->isRoundVideo()) { + updateStatusText(); + return _statusText; + } + return QString(); +} + void HistoryGif::attachToParent() { App::regDocumentItem(_data, _parent); } @@ -2946,6 +2954,9 @@ void HistoryWebPage::initDimensions() { } accumulate_max(_maxw, maxMediaWidth); _minh += _attach->minHeight() - bubble.top() - bubble.bottom(); + if (!_attach->additionalInfoString().isEmpty()) { + _minh += bottomInfoPadding(); + } } if (_data->type == WebPageVideo && _data->duration) { _duration = formatDurationText(_data->duration); @@ -3042,7 +3053,9 @@ int HistoryWebPage::resizeGetHeight(int width) { _attach->resizeGetHeight(width + bubble.left() + bubble.right()); _height += _attach->height() - bubble.top() - bubble.bottom(); - if (isBubbleBottom() && _attach->customInfoLayout() && _attach->currentWidth() + _parent->skipBlockWidth() > width + bubble.left() + bubble.right()) { + if (!_attach->additionalInfoString().isEmpty()) { + _height += bottomInfoPadding(); + } else if (isBubbleBottom() && _attach->customInfoLayout() && _attach->currentWidth() + _parent->skipBlockWidth() > width + bubble.left() + bubble.right()) { _height += bottomInfoPadding(); } } @@ -3069,7 +3082,12 @@ void HistoryWebPage::draw(Painter &p, const QRect &r, TextSelection selection, T auto tshift = padding.top(); auto bshift = padding.bottom(); width -= padding.left() + padding.right(); - if (_asArticle || (isBubbleBottom() && _attach && _attach->customInfoLayout() && _attach->currentWidth() + _parent->skipBlockWidth() > width + bubble.left() + bubble.right())) { + auto attachAdditionalInfoText = _attach ? _attach->additionalInfoString() : QString(); + if (_asArticle) { + bshift += bottomInfoPadding(); + } else if (!attachAdditionalInfoText.isEmpty()) { + bshift += bottomInfoPadding(); + } else if (isBubbleBottom() && _attach && _attach->customInfoLayout() && _attach->currentWidth() + _parent->skipBlockWidth() > width + bubble.left() + bubble.right()) { bshift += bottomInfoPadding(); } @@ -3161,6 +3179,12 @@ void HistoryWebPage::draw(Painter &p, const QRect &r, TextSelection selection, T } p.translate(-attachLeft, -attachTop); + + if (!attachAdditionalInfoText.isEmpty()) { + p.setFont(st::msgDateFont); + p.setPen(selected ? (outbg ? st::msgOutDateFgSelected : st::msgInDateFgSelected) : (outbg ? st::msgOutDateFg : st::msgInDateFg)); + p.drawTextLeft(st::msgPadding.left(), bar.y() + bar.height() + st::mediaInBubbleSkip, _width, attachAdditionalInfoText); + } } } diff --git a/Telegram/SourceFiles/history/history_media_types.h b/Telegram/SourceFiles/history/history_media_types.h index e80e9d431..7a31e00eb 100644 --- a/Telegram/SourceFiles/history/history_media_types.h +++ b/Telegram/SourceFiles/history/history_media_types.h @@ -532,6 +532,8 @@ public: bool customInfoLayout() const override { return _caption.isEmpty(); } + QString additionalInfoString() const override; + bool skipBubbleTail() const override { return isBubbleBottom() && _caption.isEmpty(); }