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);
|
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() {
|
void Menu::finishAnimating() {
|
||||||
for (const auto &widget : _actionWidgets) {
|
for (const auto &widget : _actionWidgets) {
|
||||||
widget->finishAnimating();
|
widget->finishAnimating();
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ public:
|
||||||
int position,
|
int position,
|
||||||
base::unique_qptr<ItemBase> widget);
|
base::unique_qptr<ItemBase> widget);
|
||||||
void clearActions();
|
void clearActions();
|
||||||
|
void clearLastSeparator();
|
||||||
void finishAnimating();
|
void finishAnimating();
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
|
|
|
||||||
|
|
@ -888,6 +888,12 @@ void PopupMenu::deleteOnHide(bool del) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopupMenu::popup(const QPoint &p) {
|
void PopupMenu::popup(const QPoint &p) {
|
||||||
|
if (_clearLastSeparator) {
|
||||||
|
_menu->clearLastSeparator();
|
||||||
|
for (const auto &[action, submenu] : _submenus) {
|
||||||
|
submenu->menu()->clearLastSeparator();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (prepareGeometryFor(p)) {
|
if (prepareGeometryFor(p)) {
|
||||||
popupPrepared();
|
popupPrepared();
|
||||||
return;
|
return;
|
||||||
|
|
@ -1046,6 +1052,10 @@ void PopupMenu::showPrepared(TriggeredSource source) {
|
||||||
activateWindow();
|
activateWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PopupMenu::setClearLastSeparator(bool clear) {
|
||||||
|
_clearLastSeparator = clear;
|
||||||
|
}
|
||||||
|
|
||||||
PopupMenu::~PopupMenu() {
|
PopupMenu::~PopupMenu() {
|
||||||
for (const auto &[action, submenu] : base::take(_submenus)) {
|
for (const auto &[action, submenu] : base::take(_submenus)) {
|
||||||
delete submenu;
|
delete submenu;
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,8 @@ public:
|
||||||
};
|
};
|
||||||
[[nodiscard]] rpl::producer<ShowState> showStateValue() const;
|
[[nodiscard]] rpl::producer<ShowState> showStateValue() const;
|
||||||
|
|
||||||
|
void setClearLastSeparator(bool clear);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void focusOutEvent(QFocusEvent *e) override;
|
void focusOutEvent(QFocusEvent *e) override;
|
||||||
|
|
@ -202,6 +204,8 @@ private:
|
||||||
bool _reactivateParent = true;
|
bool _reactivateParent = true;
|
||||||
bool _grabbingForPanelAnimation = false;
|
bool _grabbingForPanelAnimation = false;
|
||||||
|
|
||||||
|
bool _clearLastSeparator = true;
|
||||||
|
|
||||||
Fn<void()> _destroyedCallback;
|
Fn<void()> _destroyedCallback;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue