Allow prepare + run layer hide animation.
This commit is contained in:
parent
2a0d189ee2
commit
d6e7aa6f63
2 changed files with 65 additions and 7 deletions
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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 ¶ms);
|
const ::Window::SectionShow ¶ms);
|
||||||
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue