[Gui] ActionGroup can declared being a "Mode" action

This will essentially not update the tooltip when an action is checked as it isn't suitable
As example, view DrawStyle command where the group tooltip is better than the selected action tooltip

Only UserEditMode is implemented in this commit, should be pushed to DrawStyle and maybe other after merge
This commit is contained in:
0penBrain
2021-05-15 11:26:20 +02:00
parent 669821c440
commit 35c78726a9
3 changed files with 6 additions and 3 deletions

View File

@@ -227,7 +227,7 @@ void Action::setMenuRole(QAction::MenuRole menuRole)
* to the command object.
*/
ActionGroup::ActionGroup ( Command* pcCmd,QObject * parent)
: Action(pcCmd, parent), _group(0), _dropDown(false),_external(false),_toggle(false)
: Action(pcCmd, parent), _group(0), _dropDown(false),_external(false),_toggle(false),_isMode(false)
{
_group = new QActionGroup(this);
connect(_group, SIGNAL(triggered(QAction*)), this, SLOT(onActivated (QAction*)));
@@ -336,7 +336,7 @@ void ActionGroup::setCheckedAction(int i)
QAction* a = _group->actions()[i];
a->setChecked(true);
this->setIcon(a->icon());
this->setToolTip(a->toolTip());
if (!this->_isMode) this->setToolTip(a->toolTip());
this->setProperty("defaultAction", QVariant(i));
}
@@ -378,7 +378,7 @@ void ActionGroup::onActivated (QAction* a)
}
#endif
this->setIcon(a->icon());
this->setToolTip(a->toolTip());
if (!this->_isMode) this->setToolTip(a->toolTip());
this->setProperty("defaultAction", QVariant(index));
_pcCmd->invoke(index, Command::TriggerChildAction);
}

View File

@@ -107,6 +107,7 @@ public:
void setExclusive (bool);
bool isExclusive() const;
void setVisible (bool);
void setIsMode(bool b) { _isMode = b; }
void setDropDownMenu(bool b) { _dropDown = b; }
QAction* addAction(QAction*);
@@ -126,6 +127,7 @@ protected:
bool _dropDown;
bool _external;
bool _toggle;
bool _isMode;
};
// --------------------------------------------------------------------

View File

@@ -850,6 +850,7 @@ Gui::Action * StdCmdUserEditMode::createAction(void)
{
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true);
pcAction->setIsMode(true);
applyCommandData(this->className(), pcAction);
for (auto const &uem : Gui::Application::Instance->listUserEditModes()) {