Added ability to pass custom layer widgets to stack.

This commit is contained in:
23rd 2021-02-17 08:50:16 +03:00
parent baf4d80867
commit 8c7ebd89f6
2 changed files with 62 additions and 49 deletions

View file

@ -652,37 +652,6 @@ void LayerStackWidget::resizeEvent(QResizeEvent *e) {
updateLayerBoxes();
}
void LayerStackWidget::showBox(
object_ptr<BoxContent> box,
LayerOptions options,
anim::type animated) {
if (options & LayerOption::KeepOther) {
if (options & LayerOption::ShowAfterOther) {
prependBox(std::move(box), animated);
} else {
appendBox(std::move(box), animated);
}
} else {
replaceBox(std::move(box), animated);
}
}
void LayerStackWidget::replaceBox(
object_ptr<BoxContent> box,
anim::type animated) {
const auto pointer = pushBox(std::move(box), animated);
const auto removeTill = ranges::find(
_layers,
pointer,
&std::unique_ptr<LayerWidget>::get);
_closingLayers.insert(
end(_closingLayers),
std::make_move_iterator(begin(_layers)),
std::make_move_iterator(removeTill));
_layers.erase(begin(_layers), removeTill);
clearClosingLayers();
}
void LayerStackWidget::prepareForAnimation() {
if (isHidden()) {
show();
@ -789,14 +758,33 @@ void LayerStackWidget::showMainMenu(
}, Action::ShowMainMenu, animated);
}
void LayerStackWidget::appendBox(
void LayerStackWidget::showBox(
object_ptr<BoxContent> box,
LayerOptions options,
anim::type animated) {
pushBox(std::move(box), animated);
showLayer(
std::make_unique<BoxLayerWidget>(this, std::move(box)),
options,
animated);
}
LayerWidget *LayerStackWidget::pushBox(
object_ptr<BoxContent> box,
void LayerStackWidget::showLayer(
std::unique_ptr<LayerWidget> layer,
LayerOptions options,
anim::type animated) {
if (options & LayerOption::KeepOther) {
if (options & LayerOption::ShowAfterOther) {
prependLayer(std::move(layer), animated);
} else {
appendLayer(std::move(layer), animated);
}
} else {
replaceLayer(std::move(layer), animated);
}
}
LayerWidget *LayerStackWidget::pushLayer(
std::unique_ptr<LayerWidget> layer,
anim::type animated) {
const auto oldLayer = currentLayer();
if (oldLayer) {
@ -805,8 +793,7 @@ LayerWidget *LayerStackWidget::pushBox(
}
oldLayer->hide();
}
_layers.push_back(
std::make_unique<BoxLayerWidget>(this, std::move(box)));
_layers.push_back(std::move(layer));
const auto raw = _layers.back().get();
initChildLayer(raw);
@ -824,21 +811,43 @@ LayerWidget *LayerStackWidget::pushBox(
return raw;
}
void LayerStackWidget::prependBox(
object_ptr<BoxContent> box,
void LayerStackWidget::appendLayer(
std::unique_ptr<LayerWidget> layer,
anim::type animated) {
pushLayer(std::move(layer), animated);
}
void LayerStackWidget::prependLayer(
std::unique_ptr<LayerWidget> layer,
anim::type animated) {
if (_layers.empty()) {
replaceBox(std::move(box), animated);
replaceLayer(std::move(layer), animated);
return;
}
_layers.insert(
begin(_layers),
std::make_unique<BoxLayerWidget>(this, std::move(box)));
std::move(layer));
const auto raw = _layers.front().get();
raw->hide();
initChildLayer(raw);
}
void LayerStackWidget::replaceLayer(
std::unique_ptr<LayerWidget> layer,
anim::type animated) {
const auto pointer = pushLayer(std::move(layer), animated);
const auto removeTill = ranges::find(
_layers,
pointer,
&std::unique_ptr<LayerWidget>::get);
_closingLayers.insert(
end(_closingLayers),
std::make_move_iterator(begin(_layers)),
std::make_move_iterator(removeTill));
_layers.erase(begin(_layers), removeTill);
clearClosingLayers();
}
bool LayerStackWidget::takeToThirdSection() {
return _specialLayer
? _specialLayer->takeToThirdSection()

View file

@ -111,6 +111,10 @@ public:
object_ptr<BoxContent> box,
LayerOptions options,
anim::type animated);
void showLayer(
std::unique_ptr<LayerWidget> layer,
LayerOptions options,
anim::type animated);
void showSpecialLayer(
object_ptr<LayerWidget> layer,
anim::type animated);
@ -149,19 +153,19 @@ protected:
void resizeEvent(QResizeEvent *e) override;
private:
void appendBox(
object_ptr<BoxContent> box,
void appendLayer(
std::unique_ptr<LayerWidget> layer,
anim::type animated);
void prependBox(
object_ptr<BoxContent> box,
void prependLayer(
std::unique_ptr<LayerWidget> layer,
anim::type animated);
void replaceBox(
object_ptr<BoxContent> box,
void replaceLayer(
std::unique_ptr<LayerWidget> layer,
anim::type animated);
void backgroundClicked();
LayerWidget *pushBox(
object_ptr<BoxContent> box,
LayerWidget *pushLayer(
std::unique_ptr<LayerWidget> layer,
anim::type animated);
void showFinished();
void hideCurrent(anim::type animated);