mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 17:19:56 +00:00
IdContextMenu: if the ID field is empty show the standard context menu (if available)
This commit is contained in:
parent
814f2d3376
commit
d777c7a68a
2 changed files with 43 additions and 7 deletions
|
@ -338,16 +338,10 @@ CSVWorld::IdContextMenu::IdContextMenu(QWidget *widget, CSMWorld::ColumnBase::Di
|
|||
if (lineEdit != NULL)
|
||||
{
|
||||
mContextMenu = lineEdit->createStandardContextMenu();
|
||||
mContextMenu->setParent(mWidget);
|
||||
|
||||
QAction *action = mContextMenu->actions().first();
|
||||
mContextMenu->insertAction(action, mEditIdAction);
|
||||
mContextMenu->insertSeparator(action);
|
||||
}
|
||||
else
|
||||
{
|
||||
mContextMenu = new QMenu(mWidget);
|
||||
mContextMenu->addAction(mEditIdAction);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -368,12 +362,52 @@ QString CSVWorld::IdContextMenu::getWidgetValue() const
|
|||
return value;
|
||||
}
|
||||
|
||||
void CSVWorld::IdContextMenu::addEditIdActionToMenu(const QString &text)
|
||||
{
|
||||
mEditIdAction->setText(text);
|
||||
if (mContextMenu->actions().isEmpty())
|
||||
{
|
||||
mContextMenu->addAction(mEditIdAction);
|
||||
}
|
||||
else
|
||||
{
|
||||
QAction *action = mContextMenu->actions().first();
|
||||
mContextMenu->insertAction(action, mEditIdAction);
|
||||
mContextMenu->insertSeparator(action);
|
||||
}
|
||||
}
|
||||
|
||||
void CSVWorld::IdContextMenu::removeEditIdActionFromMenu()
|
||||
{
|
||||
if (mContextMenu->actions().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (mContextMenu->actions().first() == mEditIdAction)
|
||||
{
|
||||
mContextMenu->removeAction(mEditIdAction);
|
||||
if (!mContextMenu->actions().isEmpty() && mContextMenu->actions().first()->isSeparator())
|
||||
{
|
||||
mContextMenu->removeAction(mContextMenu->actions().first());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSVWorld::IdContextMenu::showContextMenu(const QPoint &pos)
|
||||
{
|
||||
QString value = getWidgetValue();
|
||||
if (!value.isEmpty())
|
||||
{
|
||||
mEditIdAction->setText("Edit '" + value + "'");
|
||||
addEditIdActionToMenu("Edit '" + value + "'");
|
||||
}
|
||||
else
|
||||
{
|
||||
removeEditIdActionFromMenu();
|
||||
}
|
||||
|
||||
if (!mContextMenu->actions().isEmpty())
|
||||
{
|
||||
mContextMenu->exec(mWidget->mapToGlobal(pos));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,6 +162,8 @@ namespace CSVWorld
|
|||
QAction *mEditIdAction;
|
||||
|
||||
QString getWidgetValue() const;
|
||||
void addEditIdActionToMenu(const QString &text);
|
||||
void removeEditIdActionFromMenu();
|
||||
|
||||
public:
|
||||
IdContextMenu(QWidget *widget, CSMWorld::ColumnBase::Display display);
|
||||
|
|
Loading…
Reference in a new issue