Don't lose focus when showing image editor.

This commit is contained in:
John Preston 2022-12-28 13:05:23 +04:00
parent 77078f704c
commit 17f40d6a1f
1 changed files with 20 additions and 5 deletions

View File

@ -107,21 +107,36 @@ void LayerWidget::checkBackgroundStale() {
}
QImage LayerWidget::renderBackground() {
const auto target = parentWidget()->parentWidget();
const auto parent = parentWidget();
const auto target = parent->parentWidget();
Ui::SendPendingMoveResizeEvents(target);
const auto ratio = style::DevicePixelRatio();
auto image = QImage(size() * ratio, QImage::Format_ARGB32_Premultiplied);
image.setDevicePixelRatio(ratio);
const auto shown = !parentWidget()->isHidden();
if (shown) parentWidget()->hide();
const auto shown = !parent->isHidden();
const auto focused = shown && Ui::InFocusChain(parent);
if (shown) {
if (focused) {
target->setFocus();
}
parent->hide();
}
auto p = QPainter(&image);
Ui::RenderWidget(p, target, QPoint(), geometry());
p.end();
if (shown) parentWidget()->show();
if (shown) {
parent->show();
if (focused) {
if (isHidden()) {
parent->setFocus();
} else {
setInnerFocus();
}
}
}
return image;
}