From 83fc19e14371beaad865371e7c0e79ea7e7a6374 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 16 Jan 2024 16:12:46 +0300 Subject: [PATCH] Changed behavior in voice record bar to create ttl button on demand. --- .../history_view_voice_record_bar.cpp | 25 +++++++++++++------ .../controls/history_view_voice_record_bar.h | 2 +- 2 files changed, 19 insertions(+), 8 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 3714bbf8f..04c649c29 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 @@ -292,9 +292,10 @@ TTLButton::TTLButton( , _st(st) , _rippleRect(Rect(Size(st::historyRecordLockTopShadow.width())) - (st::historyRecordLockRippleMargin)) { - resize(Size(st::historyRecordLockTopShadow.width())); + QWidget::resize(Size(st::historyRecordLockTopShadow.width())); + Ui::AbstractButton::setDisabled(true); - setClickedCallback([=] { + Ui::AbstractButton::setClickedCallback([=] { Ui::AbstractButton::setDisabled(!Ui::AbstractButton::isDisabled()); const auto isActive = !Ui::AbstractButton::isDisabled(); _activeAnimation.start( @@ -306,7 +307,7 @@ TTLButton::TTLButton( Ui::RpWidget::shownValue() | rpl::filter( rpl::mappers::_1 - ) | rpl::skip(1) | rpl::take(1) | rpl::start_with_next([=] { + ) | rpl::take(1) | rpl::start_with_next([=] { auto text = rpl::conditional( Core::App().settings().ttlVoiceClickTooltipHiddenValue(), tr::lng_record_once_active_tooltip( @@ -400,7 +401,7 @@ TTLButton::TTLButton( void TTLButton::clearState() { Ui::AbstractButton::setDisabled(true); - update(); + QWidget::update(); Ui::RpWidget::hide(); } @@ -1168,7 +1169,6 @@ VoiceRecordBar::VoiceRecordBar( , _show(std::move(descriptor.show)) , _send(std::move(descriptor.send)) , _lock(std::make_unique(_outerContainer, _st.lock)) -, _ttlButton(std::make_unique(_outerContainer, _st)) , _level(std::make_unique(_outerContainer, _st)) , _cancel(std::make_unique(this, _st, descriptor.recorderHeight)) , _startTimer([=] { startRecording(); }) @@ -1247,6 +1247,9 @@ void VoiceRecordBar::updateLockGeometry() { void VoiceRecordBar::updateTTLGeometry( TTLAnimationType type, float64 progress) { + if (!_ttlButton) { + return; + } const auto parent = parentWidget(); const auto me = Ui::MapFrom(_outerContainer, parent, geometry()); const auto anyTop = me.y() - st::historyRecordLockPosition.y(); @@ -1406,6 +1409,11 @@ void VoiceRecordBar::init() { _lock->locks( ) | rpl::start_with_next([=] { if (_hasTTLFilter && _hasTTLFilter()) { + if (!_ttlButton) { + _ttlButton = std::make_unique( + _outerContainer, + _st); + } _ttlButton->show(); } updateTTLGeometry(TTLAnimationType::RightTopStatic, 0); @@ -1869,7 +1877,7 @@ bool VoiceRecordBar::isRecordingByAnotherBar() const { } bool VoiceRecordBar::isTTLButtonShown() const { - return !_ttlButton->isHidden(); + return _ttlButton && !_ttlButton->isHidden(); } bool VoiceRecordBar::hasDuration() const { @@ -1904,10 +1912,13 @@ void VoiceRecordBar::computeAndSetLockProgress(QPoint globalPos) { } bool VoiceRecordBar::peekTTLState() const { - return !_ttlButton->isDisabled(); + return _ttlButton && !_ttlButton->isDisabled(); } bool VoiceRecordBar::takeTTLState() const { + if (!_ttlButton) { + return false; + } const auto hasTtl = !_ttlButton->isDisabled(); _ttlButton->clearState(); return hasTtl; 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 964614597..f1a58465e 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 @@ -157,9 +157,9 @@ private: const std::shared_ptr _show; const std::shared_ptr _send; const std::unique_ptr _lock; - const std::unique_ptr _ttlButton; const std::unique_ptr _level; const std::unique_ptr _cancel; + std::unique_ptr _ttlButton; std::unique_ptr _listen; base::Timer _startTimer;