From 7826d0246df63c2eb0353f212a6f26169a9dd8f4 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 9 Nov 2020 21:56:05 +0300 Subject: [PATCH] Added duration display of recorded voice data. const qptr --- .../history_view_voice_record_bar.cpp | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) 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 4243ffb5d..e8171167a 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 @@ -79,7 +79,8 @@ class ListenWrap final { public: ListenWrap( not_null parent, - ::Media::Capture::Result &&data); + ::Media::Capture::Result &&data, + const style::font &font); void requestPaintProgress(float64 progress); rpl::producer<> stopRequests() const; @@ -95,9 +96,13 @@ private: const std::unique_ptr _voiceData; const std::unique_ptr<::Media::Capture::Result> _data; const style::IconButton &_stDelete; - base::unique_qptr _delete; + const base::unique_qptr _delete; + const style::font &_durationFont; + const QString _duration; + const int _durationWidth; QRect _waveformBgRect; + QRect _durationRect; rpl::variable _showProgress = 0.; @@ -107,12 +112,17 @@ private: ListenWrap::ListenWrap( not_null parent, - ::Media::Capture::Result &&data) + ::Media::Capture::Result &&data, + const style::font &font) : _parent(parent) , _voiceData(ProcessCaptureResult(data)) , _data(std::make_unique<::Media::Capture::Result>(std::move(data))) , _stDelete(st::historyRecordDelete) -, _delete(base::make_unique_q(parent, _stDelete)) { +, _delete(base::make_unique_q(parent, _stDelete)) +, _durationFont(font) +, _duration(Ui::FormatDurationText( + float64(_data->samples) / ::Media::Player::kDefaultFrequency)) +, _durationWidth(_durationFont->width(_duration)) { init(); } @@ -173,12 +183,29 @@ void ListenWrap::init() { p.drawEllipse(bgRightCircleRect); p.fillRect(bgCenterRect, st::historyRecordCancelActive); + // Duration paint. + { + p.setFont(_durationFont); + p.setPen(st::historyRecordVoiceFgActiveIcon); + + const auto top = computeTopMargin(_durationFont->ascent); + const auto rect = bgCenterRect.marginsRemoved( + style::margins( + bgCenterRect.width() - _durationWidth, + top, + 0, + top)); + p.drawText(rect, style::al_left, _duration); + } + // Waveform paint. { const auto top = (bgCenterRect.height() - st::msgWaveformMax) / 2; + const auto right = st::historyRecordWaveformLeftSkip + + _durationWidth; const auto rect = bgCenterRect.marginsRemoved( - style::margins(halfHeight, top, halfHeight, top)); + style::margins(halfHeight, top, right, top)); if (rect.width() > 0) { p.translate(rect.topLeft()); HistoryDocumentVoice::PaintWaveform( @@ -877,7 +904,10 @@ void VoiceRecordBar::stopRecording(StopType type) { if (type == StopType::Send) { _sendVoiceRequests.fire({ data.bytes, data.waveform, duration }); } else if (type == StopType::Listen) { - _listen = std::make_unique(this, std::move(data)); + _listen = std::make_unique( + this, + std::move(data), + _cancelFont); _listenChanges.fire({}); _lockShowing = false;