Another attempt to fix TTL tooltip.

This commit is contained in:
John Preston 2024-01-18 12:44:35 +04:00
parent 80ee38f9fb
commit abf9764640

View file

@ -282,6 +282,7 @@ private:
const QRect _rippleRect; const QRect _rippleRect;
Ui::Animations::Simple _activeAnimation; Ui::Animations::Simple _activeAnimation;
base::unique_qptr<Ui::ImportantTooltip> _tooltip;
}; };
@ -305,16 +306,20 @@ TTLButton::TTLButton(
st::historyRecordVoiceShowDuration); st::historyRecordVoiceShowDuration);
}); });
Ui::RpWidget::shownValue() | rpl::filter( Ui::RpWidget::shownValue() | rpl::start_with_next([=](bool shown) {
rpl::mappers::_1 if (!shown) {
) | rpl::take(1) | rpl::start_with_next([=] { _tooltip = nullptr;
return;
} else if (_tooltip) {
return;
}
auto text = rpl::conditional( auto text = rpl::conditional(
Core::App().settings().ttlVoiceClickTooltipHiddenValue(), Core::App().settings().ttlVoiceClickTooltipHiddenValue(),
tr::lng_record_once_active_tooltip( tr::lng_record_once_active_tooltip(
Ui::Text::RichLangValue), Ui::Text::RichLangValue),
tr::lng_record_once_first_tooltip( tr::lng_record_once_first_tooltip(
Ui::Text::RichLangValue)); Ui::Text::RichLangValue));
const auto tooltip = Ui::CreateChild<Ui::ImportantTooltip>( _tooltip.reset(Ui::CreateChild<Ui::ImportantTooltip>(
parent.get(), parent.get(),
object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>( object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
parent.get(), parent.get(),
@ -324,13 +329,13 @@ TTLButton::TTLButton(
st::historyMessagesTTLLabel.minWidth, st::historyMessagesTTLLabel.minWidth,
st::ttlMediaImportantTooltipLabel), st::ttlMediaImportantTooltipLabel),
st::defaultImportantTooltip.padding), st::defaultImportantTooltip.padding),
st::historyRecordTooltip); st::historyRecordTooltip));
Ui::RpWidget::geometryValue( Ui::RpWidget::geometryValue(
) | rpl::start_with_next([=](const QRect &r) { ) | rpl::start_with_next([=](const QRect &r) {
if (r.isEmpty()) { if (r.isEmpty()) {
return; return;
} }
tooltip->pointAt(r, RectPart::Right, [=](QSize size) { _tooltip->pointAt(r, RectPart::Right, [=](QSize size) {
return QPoint( return QPoint(
r.left() r.left()
- size.width() - size.width()
@ -340,28 +345,28 @@ TTLButton::TTLButton(
- size.height() - size.height()
+ st::historyRecordTooltip.padding.top()); + st::historyRecordTooltip.padding.top());
}); });
}, tooltip->lifetime()); }, _tooltip->lifetime());
tooltip->show(); _tooltip->show();
if (!Core::App().settings().ttlVoiceClickTooltipHidden()) { if (!Core::App().settings().ttlVoiceClickTooltipHidden()) {
clicks( clicks(
) | rpl::take(1) | rpl::start_with_next([=] { ) | rpl::take(1) | rpl::start_with_next([=] {
Core::App().settings().setTtlVoiceClickTooltipHidden(true); Core::App().settings().setTtlVoiceClickTooltipHidden(true);
}, tooltip->lifetime()); }, _tooltip->lifetime());
tooltip->toggleAnimated(true); _tooltip->toggleAnimated(true);
} else { } else {
tooltip->toggleFast(false); _tooltip->toggleFast(false);
} }
clicks( clicks(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
const auto toggled = !Ui::AbstractButton::isDisabled(); const auto toggled = !Ui::AbstractButton::isDisabled();
tooltip->toggleAnimated(toggled); _tooltip->toggleAnimated(toggled);
if (toggled) { if (toggled) {
constexpr auto kTimeout = crl::time(3000); constexpr auto kTimeout = crl::time(3000);
tooltip->hideAfter(kTimeout); _tooltip->hideAfter(kTimeout);
} }
}, tooltip->lifetime()); }, _tooltip->lifetime());
Ui::RpWidget::geometryValue( Ui::RpWidget::geometryValue(
) | rpl::map([=](const QRect &r) { ) | rpl::map([=](const QRect &r) {
@ -371,9 +376,9 @@ TTLButton::TTLButton(
const auto isFirstTooltip = const auto isFirstTooltip =
!Core::App().settings().ttlVoiceClickTooltipHidden(); !Core::App().settings().ttlVoiceClickTooltipHidden();
if (isFirstTooltip || (!isFirstTooltip && toHide)) { if (isFirstTooltip || (!isFirstTooltip && toHide)) {
tooltip->toggleAnimated(!toHide); _tooltip->toggleAnimated(!toHide);
} }
}, tooltip->lifetime()); }, _tooltip->lifetime());
}, lifetime()); }, lifetime());
paintRequest( paintRequest(