diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp index 26c26e37ce..ccd2ddf486 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp @@ -253,18 +253,27 @@ void VoiceRecordBar::updateControlsGeometry(QSize size) { _cancelFont->width(FormatVoiceDuration(kMaxSamples)), _redCircleRect.height()); } - { - const auto left = _durationRect.x() - + _durationRect.width() - + ((_send->width() - st::historyRecordVoice.width()) / 2); - const auto right = width() - _send->width(); - const auto width = _cancelFont->width(cancelMessage()); - _messageRect = QRect( - left + (right - left - width) / 2, - st::historyRecordTextTop, - width + st::historyRecordDurationSkip, - _cancelFont->height); - } + updateMessageGeometry(); +} + +void VoiceRecordBar::updateMessageGeometry() { + const auto left = _durationRect.x() + + _durationRect.width() + + st::historyRecordTextLeft; + const auto right = width() + - _send->width() + - st::historyRecordTextRight; + const auto textWidth = _message.maxWidth(); + const auto width = ((right - left) < textWidth) + ? st::historyRecordTextWidthForWrap + : textWidth; + const auto countLines = std::ceil((float)textWidth / width); + const auto textHeight = _message.minHeight() * countLines; + _messageRect = QRect( + left + (right - left - width) / 2, + (height() - textHeight) / 2, + width, + textHeight); } void VoiceRecordBar::init() { @@ -334,10 +343,6 @@ void VoiceRecordBar::init() { _lock->hide(); _lock->locks( ) | rpl::start_with_next([=] { - - updateControlsGeometry(rect().size()); - update(_messageRect); - installClickOutsideFilter(); _send->clicks( @@ -365,6 +370,22 @@ void VoiceRecordBar::init() { _inField = enter; }, _recordingLifetime); }, lifetime()); + + rpl::merge( + _lock->locks(), + shownValue() | rpl::to_empty + ) | rpl::start_with_next([=] { + const auto direction = Qt::LayoutDirectionAuto; + _message.setText( + st::historyRecordTextStyle, + _lock->isLocked() + ? tr::lng_record_lock_cancel(tr::now) + : tr::lng_record_cancel(tr::now), + TextParseOptions{ TextParseMultiline, 0, 0, direction }); + + updateMessageGeometry(); + update(_messageRect); + }, lifetime()); } void VoiceRecordBar::activeAnimate(bool active) { @@ -563,10 +584,13 @@ void VoiceRecordBar::drawMessage(Painter &p, float64 recordActive) { st::historyRecordCancel, st::historyRecordCancelActive, 1. - recordActive)); - p.drawText( + + _message.draw( + p, _messageRect.x(), - _messageRect.y() + _cancelFont->ascent, - cancelMessage()); + _messageRect.y(), + _messageRect.width(), + style::al_center); } rpl::producer VoiceRecordBar::sendActionUpdates() const { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h index d3c6f28a76..e96ea6583a 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h @@ -55,6 +55,7 @@ private: void init(); void updateControlsGeometry(QSize size); + void updateMessageGeometry(); void recordError(); void recordUpdated(quint16 level, int samples); @@ -94,6 +95,8 @@ private: QRect _durationRect; QRect _messageRect; + Ui::Text::String _message; + Fn _escFilter; rpl::variable _recording = false; diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index 46e808eb72..0ea46b9eb4 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -344,7 +344,14 @@ historyRecordCancelActive: windowActiveTextFg; historyRecordFont: font(13px); historyRecordDurationSkip: 12px; historyRecordDurationFg: historyComposeAreaFg; -historyRecordTextTop: 14px; + +historyRecordTextStyle: TextStyle(defaultTextStyle) { + font: historyRecordFont; +} + +historyRecordTextWidthForWrap: 210px; +historyRecordTextLeft: 15px; +historyRecordTextRight: 25px; historyRecordLockShowDuration: historyToDownDuration; historyRecordLockSize: size(75px, 150px);