Fix child geometry for mega-rich popup menus.

This commit is contained in:
John Preston 2023-01-19 12:16:19 +04:00
parent e00ae912ad
commit 6e3cc8c769
2 changed files with 12 additions and 5 deletions

View file

@ -545,7 +545,10 @@ void PopupMenu::popupSubmenu(
currentSubmenu->hideMenu(true); currentSubmenu->hideMenu(true);
} }
if (submenu) { if (submenu) {
QPoint p(_inner.x() + (style::RightToLeft() ? _padding.right() : (_inner.width() - _padding.left())), _inner.y() + actionTop); const auto padding = _useTransparency
? _st.shadow.extend
: QMargins(st::lineWidth, 0, st::lineWidth, 0);
QPoint p(_inner.x() + (style::RightToLeft() ? padding.right() : (_inner.width() - padding.left())), _inner.y() + actionTop);
_activeSubmenu = submenu; _activeSubmenu = submenu;
if (_activeSubmenu->prepareGeometryFor(geometry().topLeft() + p, this)) { if (_activeSubmenu->prepareGeometryFor(geometry().topLeft() + p, this)) {
_activeSubmenu->showPrepared(source); _activeSubmenu->showPrepared(source);
@ -983,11 +986,12 @@ bool PopupMenu::prepareGeometryFor(const QPoint &p, PopupMenu *parent) {
0), 0),
_padding.top()); _padding.top());
auto r = screen ? screen->availableGeometry() : QRect(); auto r = screen ? screen->availableGeometry() : QRect();
const auto parentWidth = _parent ? _parent->inner().width() : 0;
if (style::RightToLeft()) { if (style::RightToLeft()) {
const auto badLeft = !r.isNull() && w.x() - width() < r.x() - _extents.left(); const auto badLeft = !r.isNull() && w.x() - width() < r.x() - _extents.left();
if (forceRight || (badLeft && !forceLeft)) { if (forceRight || (badLeft && !forceLeft)) {
if (_parent && (r.isNull() || w.x() + _parent->width() - _extents.left() - _extents.right() + width() - _extents.right() <= r.x() + r.width())) { if (_parent && (r.isNull() || w.x() + parentWidth - _extents.left() - _extents.right() + width() - _extents.right() <= r.x() + r.width())) {
w.setX(w.x() + _parent->width() - _extents.left() - _extents.right()); w.setX(w.x() + parentWidth - _extents.left() - _extents.right());
} else { } else {
w.setX(r.x() - _extents.left()); w.setX(r.x() - _extents.left());
} }
@ -997,8 +1001,8 @@ bool PopupMenu::prepareGeometryFor(const QPoint &p, PopupMenu *parent) {
} else { } else {
const auto badLeft = !r.isNull() && w.x() + width() - _extents.right() > r.x() + r.width(); const auto badLeft = !r.isNull() && w.x() + width() - _extents.right() > r.x() + r.width();
if (forceRight || (badLeft && !forceLeft)) { if (forceRight || (badLeft && !forceLeft)) {
if (_parent && (r.isNull() || w.x() - _parent->width() + _extents.left() + _extents.right() - width() + _extents.right() >= r.x() - _extents.left())) { if (_parent && (r.isNull() || w.x() - parentWidth + _extents.left() + _extents.right() - width() + _extents.right() >= r.x() - _extents.left())) {
w.setX(w.x() + _extents.left() + _extents.right() - _parent->width() - width() + _extents.left() + _extents.right()); w.setX(w.x() + _extents.left() + _extents.right() - parentWidth - width() + _extents.left() + _extents.right());
} else { } else {
w.setX(p.x() - width() + std::max( w.setX(p.x() - width() + std::max(
_additionalMenuPadding.right() - _st.shadow.extend.right(), _additionalMenuPadding.right() - _st.shadow.extend.right(),

View file

@ -37,6 +37,9 @@ public:
[[nodiscard]] const style::PopupMenu &st() const { [[nodiscard]] const style::PopupMenu &st() const {
return _st; return _st;
} }
[[nodiscard]] QRect inner() const {
return _inner;
}
not_null<QAction*> addAction(base::unique_qptr<Menu::ItemBase> widget); not_null<QAction*> addAction(base::unique_qptr<Menu::ItemBase> widget);
not_null<QAction*> addAction( not_null<QAction*> addAction(