mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Moved important tooltip for stories in dialogs to MainWidget.
This commit is contained in:
parent
ebbef70d42
commit
73373e373f
4 changed files with 57 additions and 29 deletions
|
@ -802,6 +802,9 @@ public:
|
|||
[[nodiscard]] std::optional<uint64> macRoundIconDigest() const {
|
||||
return _macRoundIconDigest;
|
||||
}
|
||||
[[nodiscard]] bool storiesClickTooltipHidden() const {
|
||||
return _storiesClickTooltipHidden.current();
|
||||
}
|
||||
[[nodiscard]] rpl::producer<bool> storiesClickTooltipHiddenValue() const {
|
||||
return _storiesClickTooltipHidden.value();
|
||||
}
|
||||
|
|
|
@ -798,16 +798,21 @@ void Widget::setupStories() {
|
|||
_scroll->viewportEvent(e);
|
||||
}, _stories->lifetime());
|
||||
|
||||
const auto hideTooltip = [=] {
|
||||
Core::App().settings().setStoriesClickTooltipHidden(true);
|
||||
Core::App().saveSettingsDelayed();
|
||||
};
|
||||
_stories->setShowTooltip(
|
||||
rpl::combine(
|
||||
Core::App().settings().storiesClickTooltipHiddenValue(),
|
||||
shownValue(),
|
||||
!rpl::mappers::_1 && rpl::mappers::_2),
|
||||
hideTooltip);
|
||||
if (!Core::App().settings().storiesClickTooltipHidden()) {
|
||||
// Don't create tooltip
|
||||
// until storiesClickTooltipHidden can be returned to false.
|
||||
const auto hideTooltip = [=] {
|
||||
Core::App().settings().setStoriesClickTooltipHidden(true);
|
||||
Core::App().saveSettingsDelayed();
|
||||
};
|
||||
_stories->setShowTooltip(
|
||||
parentWidget(),
|
||||
rpl::combine(
|
||||
Core::App().settings().storiesClickTooltipHiddenValue(),
|
||||
shownValue(),
|
||||
!rpl::mappers::_1 && rpl::mappers::_2),
|
||||
hideTooltip);
|
||||
}
|
||||
|
||||
_storiesContents.fire(Stories::ContentForSession(
|
||||
&controller()->session(),
|
||||
|
|
|
@ -916,19 +916,21 @@ TextWithEntities List::computeTooltipText() const {
|
|||
Ui::Text::WithEntities);
|
||||
}
|
||||
|
||||
void List::setShowTooltip(rpl::producer<bool> shown, Fn<void()> hide) {
|
||||
void List::setShowTooltip(
|
||||
not_null<QWidget*> tooltipParent,
|
||||
rpl::producer<bool> shown,
|
||||
Fn<void()> hide) {
|
||||
_tooltip = nullptr;
|
||||
_tooltipHide = std::move(hide);
|
||||
_tooltipNotHidden = std::move(shown);
|
||||
_tooltipText = computeTooltipText();
|
||||
const auto window = this->window();
|
||||
const auto notEmpty = [](const TextWithEntities &text) {
|
||||
return !text.empty();
|
||||
};
|
||||
_tooltip = std::make_unique<Ui::ImportantTooltip>(
|
||||
window,
|
||||
tooltipParent,
|
||||
MakeTooltipContent(
|
||||
window,
|
||||
tooltipParent,
|
||||
_tooltipText.value() | rpl::filter(notEmpty),
|
||||
_tooltipHide),
|
||||
st::dialogsStoriesTooltip);
|
||||
|
@ -937,7 +939,7 @@ void List::setShowTooltip(rpl::producer<bool> shown, Fn<void()> hide) {
|
|||
tooltip->toggleFast(false);
|
||||
updateTooltipGeometry();
|
||||
|
||||
const auto handle = window->windowHandle();
|
||||
const auto handle = tooltipParent->window()->windowHandle();
|
||||
auto windowActive = rpl::single(
|
||||
handle->isActive()
|
||||
) | rpl::then(base::qt_signal_producer(
|
||||
|
@ -947,16 +949,29 @@ void List::setShowTooltip(rpl::producer<bool> shown, Fn<void()> hide) {
|
|||
return handle->isActive();
|
||||
})) | rpl::distinct_until_changed();
|
||||
|
||||
for (auto parent = parentWidget()
|
||||
; parent != window
|
||||
; parent = parent->parentWidget()) {
|
||||
{
|
||||
const auto recompute = [=] {
|
||||
updateTooltipGeometry();
|
||||
tooltip->raise();
|
||||
};
|
||||
using namespace base;
|
||||
install_event_filter(parent, tooltip, [=](not_null<QEvent*> e) {
|
||||
if (e->type() == QEvent::Move) {
|
||||
updateTooltipGeometry();
|
||||
using Event = not_null<QEvent*>;
|
||||
install_event_filter(tooltip, tooltipParent, [=](Event e) {
|
||||
if ((e->type() == QEvent::Move)
|
||||
|| (e->type() == QEvent::ChildAdded)
|
||||
|| (e->type() == QEvent::ChildRemoved)) {
|
||||
recompute();
|
||||
}
|
||||
return EventFilterResult::Continue;
|
||||
});
|
||||
for (const auto &child : tooltipParent->children()) {
|
||||
install_event_filter(tooltip, child, [=](Event e) {
|
||||
if (e->type() == QEvent::ZOrderChange) {
|
||||
recompute();
|
||||
}
|
||||
return EventFilterResult::Continue;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
rpl::combine(
|
||||
|
@ -985,14 +1000,16 @@ void List::toggleTooltip(bool fast) {
|
|||
&& _tooltipNotHidden.current()
|
||||
&& !_tooltipText.current().empty()
|
||||
&& window()->windowHandle()->isActive();
|
||||
if (_tooltip) {
|
||||
if (fast) {
|
||||
_tooltip->toggleFast(shown);
|
||||
} else {
|
||||
_tooltip->toggleAnimated(shown);
|
||||
}
|
||||
}
|
||||
if (shown) {
|
||||
updateTooltipGeometry();
|
||||
}
|
||||
if (fast) {
|
||||
_tooltip->toggleFast(shown);
|
||||
} else {
|
||||
_tooltip->toggleAnimated(shown);
|
||||
}
|
||||
}
|
||||
|
||||
void List::updateTooltipGeometry() {
|
||||
|
@ -1001,7 +1018,7 @@ void List::updateTooltipGeometry() {
|
|||
}
|
||||
const auto collapsed = collapsedGeometryCurrent();
|
||||
const auto geometry = Ui::MapFrom(
|
||||
window(),
|
||||
_tooltip->parentWidget(),
|
||||
parentWidget(),
|
||||
QRect(
|
||||
collapsed.geometry.x(),
|
||||
|
@ -1012,7 +1029,7 @@ void List::updateTooltipGeometry() {
|
|||
const auto countPosition = [=](QSize size) {
|
||||
const auto left = geometry.x()
|
||||
+ (geometry.width() - size.width()) / 2;
|
||||
const auto right = window()->width()
|
||||
const auto right = _tooltip->parentWidget()->width()
|
||||
- st::dialogsStoriesTooltip.padding.right();
|
||||
return QPoint(
|
||||
std::max(std::min(left, right - size.width()), 0),
|
||||
|
|
|
@ -73,7 +73,10 @@ public:
|
|||
QPoint positionSmall,
|
||||
style::align alignSmall,
|
||||
QRect geometryFull = QRect());
|
||||
void setShowTooltip(rpl::producer<bool> shown, Fn<void()> hide);
|
||||
void setShowTooltip(
|
||||
not_null<QWidget*> tooltipParent,
|
||||
rpl::producer<bool> shown,
|
||||
Fn<void()> hide);
|
||||
struct CollapsedGeometry {
|
||||
QRect geometry;
|
||||
float64 expanded = 0.;
|
||||
|
|
Loading…
Add table
Reference in a new issue