Added ability to set index to menu item.
This commit is contained in:
parent
df0a8ff589
commit
497452250a
7 changed files with 14 additions and 13 deletions
|
|
@ -86,7 +86,6 @@ not_null<QAction*> Menu::addAction(
|
|||
auto item = base::make_unique_q<Action>(
|
||||
this,
|
||||
_st,
|
||||
0,
|
||||
std::move(action),
|
||||
icon,
|
||||
iconOver ? iconOver : icon,
|
||||
|
|
@ -105,6 +104,8 @@ not_null<QAction*> Menu::addAction(base::unique_qptr<ItemBase> widget) {
|
|||
widget->moveToLeft(0, top);
|
||||
widget->show();
|
||||
|
||||
widget->setIndex(_actionWidgets.size());
|
||||
|
||||
widget->selects(
|
||||
) | rpl::start_with_next([=](const CallbackData &data) {
|
||||
if (!data.selected) {
|
||||
|
|
@ -156,7 +157,7 @@ not_null<QAction*> Menu::addAction(base::unique_qptr<ItemBase> widget) {
|
|||
not_null<QAction*> Menu::addSeparator() {
|
||||
const auto separator = new QAction(this);
|
||||
separator->setSeparator(true);
|
||||
auto item = base::make_unique_q<Separator>(this, _st, 0, separator);
|
||||
auto item = base::make_unique_q<Separator>(this, _st, separator);
|
||||
return addAction(std::move(item));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,12 +49,11 @@ TextParseOptions MenuTextOptions = {
|
|||
Action::Action(
|
||||
not_null<RpWidget*> parent,
|
||||
const style::Menu &st,
|
||||
int index,
|
||||
not_null<QAction*> action,
|
||||
const style::icon *icon,
|
||||
const style::icon *iconOver,
|
||||
bool hasSubmenu)
|
||||
: ItemBase(parent, st, index)
|
||||
: ItemBase(parent, st)
|
||||
, _action(action)
|
||||
, _st(st)
|
||||
, _icon(icon)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ public:
|
|||
Action(
|
||||
not_null<RpWidget*> parent,
|
||||
const style::Menu &st,
|
||||
int index,
|
||||
not_null<QAction*> action,
|
||||
const style::icon *icon,
|
||||
const style::icon *iconOver,
|
||||
|
|
|
|||
|
|
@ -10,9 +10,8 @@ namespace Ui::Menu {
|
|||
|
||||
ItemBase::ItemBase(
|
||||
not_null<RpWidget*> parent,
|
||||
const style::Menu &st, int index)
|
||||
: RippleButton(parent, st.ripple)
|
||||
, _index(index) {
|
||||
const style::Menu &st)
|
||||
: RippleButton(parent, st.ripple) {
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +47,10 @@ int ItemBase::index() const {
|
|||
return _index;
|
||||
}
|
||||
|
||||
void ItemBase::setIndex(int index) {
|
||||
_index = index;
|
||||
}
|
||||
|
||||
void ItemBase::setClicked(TriggeredSource source) {
|
||||
if (isEnabled()) {
|
||||
_lastTriggeredSource = source;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Ui::Menu {
|
|||
|
||||
class ItemBase : public RippleButton {
|
||||
public:
|
||||
ItemBase(not_null<RpWidget*> parent, const style::Menu &st, int index);
|
||||
ItemBase(not_null<RpWidget*> parent, const style::Menu &st);
|
||||
|
||||
TriggeredSource lastTriggeredSource() const;
|
||||
|
||||
|
|
@ -26,6 +26,7 @@ public:
|
|||
bool isSelected() const;
|
||||
|
||||
int index() const;
|
||||
void setIndex(int index);
|
||||
|
||||
void setClicked(TriggeredSource source = TriggeredSource::Mouse);
|
||||
|
||||
|
|
@ -48,7 +49,7 @@ protected:
|
|||
virtual int contentHeight() const = 0;
|
||||
|
||||
private:
|
||||
const int _index;
|
||||
int _index = -1;
|
||||
|
||||
bool _hasSubmenu = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@ namespace Ui::Menu {
|
|||
Separator::Separator(
|
||||
not_null<RpWidget*> parent,
|
||||
const style::Menu &st,
|
||||
int index,
|
||||
not_null<QAction*> action)
|
||||
: ItemBase(parent, st, index)
|
||||
: ItemBase(parent, st)
|
||||
, _lineWidth(st.separatorWidth)
|
||||
, _padding(st.separatorPadding)
|
||||
, _fg(st.separatorFg)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ public:
|
|||
Separator(
|
||||
not_null<RpWidget*> parent,
|
||||
const style::Menu &st,
|
||||
int index,
|
||||
not_null<QAction*> action);
|
||||
|
||||
QAction *action() const override;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue