Added ability to fill menu with custom widgets.
This commit is contained in:
parent
497452250a
commit
0c5135f671
6 changed files with 16 additions and 2 deletions
|
|
@ -53,6 +53,11 @@ void DropdownMenu::init() {
|
|||
hide();
|
||||
}
|
||||
|
||||
not_null<QAction*> DropdownMenu::addAction(
|
||||
base::unique_qptr<Menu::ItemBase> widget) {
|
||||
return _menu->addAction(std::move(widget));
|
||||
}
|
||||
|
||||
not_null<QAction*> DropdownMenu::addAction(const QString &text, Fn<void()> callback, const style::icon *icon, const style::icon *iconOver) {
|
||||
return _menu->addAction(text, std::move(callback), icon, iconOver);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class DropdownMenu : public InnerDropdown {
|
|||
public:
|
||||
DropdownMenu(QWidget *parent, const style::DropdownMenu &st = st::defaultDropdownMenu);
|
||||
|
||||
not_null<QAction*> addAction(base::unique_qptr<Menu::ItemBase> widget);
|
||||
not_null<QAction*> addAction(const QString &text, Fn<void()> callback, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr);
|
||||
not_null<QAction*> addSeparator();
|
||||
void clearActions();
|
||||
|
|
|
|||
|
|
@ -97,6 +97,8 @@ not_null<QAction*> Menu::addAction(base::unique_qptr<ItemBase> widget) {
|
|||
const auto action = widget->action();
|
||||
_actions.emplace_back(action);
|
||||
|
||||
widget->setParent(this);
|
||||
|
||||
const auto top = _actionWidgets.empty()
|
||||
? 0
|
||||
: _actionWidgets.back()->y() + _actionWidgets.back()->height();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
namespace Ui::Menu {
|
||||
|
||||
class ItemBase;
|
||||
class ToggleView;
|
||||
//class ToggleView;
|
||||
class RippleAnimation;
|
||||
|
||||
class Menu : public RpWidget {
|
||||
|
|
@ -25,6 +25,7 @@ public:
|
|||
Menu(QWidget *parent, QMenu *menu, const style::Menu &st = st::defaultMenu);
|
||||
~Menu();
|
||||
|
||||
not_null<QAction*> addAction(base::unique_qptr<ItemBase> widget);
|
||||
not_null<QAction*> addAction(
|
||||
const QString &text,
|
||||
Fn<void()> callback,
|
||||
|
|
@ -90,7 +91,6 @@ private:
|
|||
not_null<QAction*> action,
|
||||
const style::icon *icon = nullptr,
|
||||
const style::icon *iconOver = nullptr);
|
||||
not_null<QAction*> addAction(base::unique_qptr<ItemBase> widget);
|
||||
|
||||
void setSelected(int selected);
|
||||
void clearMouseSelection();
|
||||
|
|
|
|||
|
|
@ -91,6 +91,11 @@ void PopupMenu::handleMenuResize() {
|
|||
_inner = rect().marginsRemoved(_padding);
|
||||
}
|
||||
|
||||
not_null<QAction*> PopupMenu::addAction(
|
||||
base::unique_qptr<Menu::ItemBase> widget) {
|
||||
return _menu->addAction(std::move(widget));
|
||||
}
|
||||
|
||||
not_null<QAction*> PopupMenu::addAction(const QString &text, Fn<void()> callback, const style::icon *icon, const style::icon *iconOver) {
|
||||
return _menu->addAction(text, std::move(callback), icon, iconOver);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ public:
|
|||
PopupMenu(QWidget *parent, const style::PopupMenu &st = st::defaultPopupMenu);
|
||||
PopupMenu(QWidget *parent, QMenu *menu, const style::PopupMenu &st = st::defaultPopupMenu);
|
||||
|
||||
not_null<QAction*> addAction(base::unique_qptr<Menu::ItemBase> widget);
|
||||
not_null<QAction*> addAction(const QString &text, Fn<void()> callback, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr);
|
||||
not_null<QAction*> addAction(const QString &text, std::unique_ptr<PopupMenu> submenu);
|
||||
not_null<QAction*> addSeparator();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue