Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Eric Kotato 2020-06-30 02:28:59 +03:00
commit 2a063957da
3 changed files with 71 additions and 9 deletions

View file

@ -151,9 +151,13 @@ void BoxLayerWidget::parentResized() {
void BoxLayerWidget::setTitle(rpl::producer<TextWithEntities> title) { void BoxLayerWidget::setTitle(rpl::producer<TextWithEntities> title) {
const auto wasTitle = hasTitle(); const auto wasTitle = hasTitle();
if (title) { if (title) {
_title.create(this, std::move(title), st::boxTitle); _title.create(this, rpl::duplicate(title), st::boxTitle);
_title->show(); _title->show();
updateTitlePosition(); std::move(
title
) | rpl::start_with_next([=] {
updateTitlePosition();
}, _title->lifetime());
} else { } else {
_title.destroy(); _title.destroy();
} }

View file

@ -34,6 +34,8 @@ public:
QPixmap &&specialLayerCache, QPixmap &&specialLayerCache,
QPixmap &&layerCache); QPixmap &&layerCache);
void removeBodyCache(); void removeBodyCache();
[[nodiscard]] bool hasBodyCache() const;
void refreshBodyCache(QPixmap &&bodyCache);
void startAnimation(Action action); void startAnimation(Action action);
void skipAnimation(Action action); void skipAnimation(Action action);
void finishAnimating(); void finishAnimating();
@ -102,12 +104,22 @@ void LayerStackWidget::BackgroundWidget::setCacheImages(
} }
void LayerStackWidget::BackgroundWidget::removeBodyCache() { void LayerStackWidget::BackgroundWidget::removeBodyCache() {
if (!_bodyCache.isNull()) { if (hasBodyCache()) {
_bodyCache = {}; _bodyCache = {};
setAttribute(Qt::WA_OpaquePaintEvent, false); setAttribute(Qt::WA_OpaquePaintEvent, false);
} }
} }
bool LayerStackWidget::BackgroundWidget::hasBodyCache() const {
return !_bodyCache.isNull();
}
void LayerStackWidget::BackgroundWidget::refreshBodyCache(
QPixmap &&bodyCache) {
_bodyCache = std::move(bodyCache);
setAttribute(Qt::WA_OpaquePaintEvent, !_bodyCache.isNull());
}
void LayerStackWidget::BackgroundWidget::startAnimation(Action action) { void LayerStackWidget::BackgroundWidget::startAnimation(Action action) {
if (action == Action::ShowMainMenu) { if (action == Action::ShowMainMenu) {
setMainMenuShown(true); setMainMenuShown(true);
@ -410,6 +422,25 @@ void LayerStackWidget::hideAll(anim::type animated) {
}, Action::HideAll, animated); }, Action::HideAll, animated);
} }
void LayerStackWidget::hideAllAnimatedPrepare() {
prepareAnimation([] {}, [&] {
clearLayers();
clearSpecialLayer();
_mainMenu.destroy();
}, Action::HideAll, anim::type::normal);
}
void LayerStackWidget::hideAllAnimatedRun() {
if (_background->hasBodyCache()) {
removeBodyCache();
hideChildren();
auto bodyCache = Ui::GrabWidget(parentWidget());
showChildren();
_background->refreshBodyCache(std::move(bodyCache));
}
_background->startAnimation(Action::HideAll);
}
void LayerStackWidget::hideTopLayer(anim::type animated) { void LayerStackWidget::hideTopLayer(anim::type animated) {
if (_specialLayer || _mainMenu) { if (_specialLayer || _mainMenu) {
hideLayers(animated); hideLayers(animated);
@ -548,9 +579,9 @@ bool LayerStackWidget::contentOverlapped(const QRect &globalRect) {
} }
template <typename SetupNew, typename ClearOld> template <typename SetupNew, typename ClearOld>
void LayerStackWidget::startAnimation( bool LayerStackWidget::prepareAnimation(
SetupNew setupNewWidgets, SetupNew &&setupNewWidgets,
ClearOld clearOldWidgets, ClearOld &&clearOldWidgets,
Action action, Action action,
anim::type animated) { anim::type animated) {
if (animated == anim::type::instant) { if (animated == anim::type::instant) {
@ -565,9 +596,26 @@ void LayerStackWidget::startAnimation(
clearOldWidgets(); clearOldWidgets();
if (weak) { if (weak) {
prepareForAnimation(); prepareForAnimation();
_background->startAnimation(action); return true;
} }
} }
return false;
}
template <typename SetupNew, typename ClearOld>
void LayerStackWidget::startAnimation(
SetupNew &&setupNewWidgets,
ClearOld &&clearOldWidgets,
Action action,
anim::type animated) {
const auto alive = prepareAnimation(
std::forward<SetupNew>(setupNewWidgets),
std::forward<ClearOld>(clearOldWidgets),
action,
animated);
if (alive) {
_background->startAnimation(action);
}
} }
void LayerStackWidget::resizeEvent(QResizeEvent *e) { void LayerStackWidget::resizeEvent(QResizeEvent *e) {

View file

@ -117,6 +117,10 @@ public:
void setHideByBackgroundClick(bool hide); void setHideByBackgroundClick(bool hide);
void removeBodyCache(); void removeBodyCache();
// If you need to divide animated hideAll().
void hideAllAnimatedPrepare();
void hideAllAnimatedRun();
bool showSectionInternal( bool showSectionInternal(
not_null<::Window::SectionMemento*> memento, not_null<::Window::SectionMemento*> memento,
const ::Window::SectionShow &params); const ::Window::SectionShow &params);
@ -158,9 +162,15 @@ private:
HideAll, HideAll,
}; };
template <typename SetupNew, typename ClearOld> template <typename SetupNew, typename ClearOld>
bool prepareAnimation(
SetupNew &&setupNewWidgets,
ClearOld &&clearOldWidgets,
Action action,
anim::type animated);
template <typename SetupNew, typename ClearOld>
void startAnimation( void startAnimation(
SetupNew setupNewWidgets, SetupNew &&setupNewWidgets,
ClearOld clearOldWidgets, ClearOld &&clearOldWidgets,
Action action, Action action,
anim::type animated); anim::type animated);