Changed default behavior to trim last separator in popup menu.
This commit is contained in:
parent
6c345d2076
commit
ff821bc3d7
4 changed files with 33 additions and 0 deletions
|
|
@ -218,6 +218,24 @@ void Menu::clearActions() {
|
|||
resizeFromInner(_forceWidth ? _forceWidth : _st.widthMin, _st.skip * 2);
|
||||
}
|
||||
|
||||
void Menu::clearLastSeparator() {
|
||||
if (_actionWidgets.empty() || _actions.empty()) {
|
||||
return;
|
||||
}
|
||||
if (_actionWidgets.back()->action() == _actions.back()) {
|
||||
if (_actions.back()->isSeparator()) {
|
||||
resizeFromInner(
|
||||
width(),
|
||||
height() - _actionWidgets.back()->height());
|
||||
_actionWidgets.pop_back();
|
||||
if (_actions.back()->parent() == this) {
|
||||
delete _actions.back();
|
||||
_actions.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::finishAnimating() {
|
||||
for (const auto &widget : _actionWidgets) {
|
||||
widget->finishAnimating();
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public:
|
|||
int position,
|
||||
base::unique_qptr<ItemBase> widget);
|
||||
void clearActions();
|
||||
void clearLastSeparator();
|
||||
void finishAnimating();
|
||||
|
||||
bool empty() const;
|
||||
|
|
|
|||
|
|
@ -888,6 +888,12 @@ void PopupMenu::deleteOnHide(bool del) {
|
|||
}
|
||||
|
||||
void PopupMenu::popup(const QPoint &p) {
|
||||
if (_clearLastSeparator) {
|
||||
_menu->clearLastSeparator();
|
||||
for (const auto &[action, submenu] : _submenus) {
|
||||
submenu->menu()->clearLastSeparator();
|
||||
}
|
||||
}
|
||||
if (prepareGeometryFor(p)) {
|
||||
popupPrepared();
|
||||
return;
|
||||
|
|
@ -1046,6 +1052,10 @@ void PopupMenu::showPrepared(TriggeredSource source) {
|
|||
activateWindow();
|
||||
}
|
||||
|
||||
void PopupMenu::setClearLastSeparator(bool clear) {
|
||||
_clearLastSeparator = clear;
|
||||
}
|
||||
|
||||
PopupMenu::~PopupMenu() {
|
||||
for (const auto &[action, submenu] : base::take(_submenus)) {
|
||||
delete submenu;
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@ public:
|
|||
};
|
||||
[[nodiscard]] rpl::producer<ShowState> showStateValue() const;
|
||||
|
||||
void setClearLastSeparator(bool clear);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void focusOutEvent(QFocusEvent *e) override;
|
||||
|
|
@ -202,6 +204,8 @@ private:
|
|||
bool _reactivateParent = true;
|
||||
bool _grabbingForPanelAnimation = false;
|
||||
|
||||
bool _clearLastSeparator = true;
|
||||
|
||||
Fn<void()> _destroyedCallback;
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue