Skip to content

Commit

Permalink
Properties view: Added action for adding a property to context menu
Browse files Browse the repository at this point in the history
Closes #2796
  • Loading branch information
bjorn committed May 13, 2020
1 parent baa115a commit 4025028
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/tiled/propertiesdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void PropertiesDock::renamePropertyTo(const QString &name)
undoStack->push(new RenameProperty(mDocument, mDocument->currentObjects(), oldName, name));
}

void PropertiesDock::showContextMenu(const QPoint& pos)
void PropertiesDock::showContextMenu(const QPoint &pos)
{
const Object *object = mDocument->currentObject();
if (!object)
Expand Down Expand Up @@ -395,9 +395,15 @@ void PropertiesDock::showContextMenu(const QPoint& pos)
QAction *copyAction = contextMenu.addAction(tr("&Copy"), this, &PropertiesDock::copyProperties);
QAction *pasteAction = contextMenu.addAction(tr("&Paste"), this, &PropertiesDock::pasteProperties);
contextMenu.addSeparator();
QMenu *convertMenu = contextMenu.addMenu(tr("Convert To"));
contextMenu.addAction(mActionRenameProperty);
contextMenu.addAction(mActionRemoveProperty);
QMenu *convertMenu = nullptr;

if (customPropertiesSelected) {
convertMenu = contextMenu.addMenu(tr("Convert To"));
contextMenu.addAction(mActionRemoveProperty);
contextMenu.addAction(mActionRenameProperty);
} else {
contextMenu.addAction(mActionAddProperty);
}

cutAction->setShortcuts(QKeySequence::Cut);
cutAction->setIcon(QIcon(QLatin1String(":/images/16/edit-cut.png")));
Expand All @@ -413,7 +419,7 @@ void PropertiesDock::showContextMenu(const QPoint& pos)
Utils::setThemeIcon(copyAction, "edit-copy");
Utils::setThemeIcon(pasteAction, "edit-paste");

if (customPropertiesSelected) {
if (convertMenu) {
const int convertTo[] = {
QVariant::Bool,
QVariant::Color,
Expand Down Expand Up @@ -445,14 +451,15 @@ void PropertiesDock::showContextMenu(const QPoint& pos)
action->setData(toType);
}
}

convertMenu->setEnabled(!convertMenu->actions().isEmpty());
}

convertMenu->setEnabled(!convertMenu->actions().isEmpty());

const QPoint globalPos = mPropertyBrowser->mapToGlobal(pos);
const QAction *selectedItem = contextMenu.exec(globalPos);

if (selectedItem && selectedItem->parentWidget() == convertMenu) {
if (selectedItem && convertMenu && selectedItem->parentWidget() == convertMenu) {
QUndoStack *undoStack = mDocument->undoStack();
undoStack->beginMacro(tr("Convert Property/Properties", nullptr, items.size()));

Expand Down Expand Up @@ -514,7 +521,7 @@ void PropertiesDock::retranslateUi()
{
setWindowTitle(tr("Properties"));

mActionAddProperty->setToolTip(tr("Add Property"));
mActionAddProperty->setText(tr("Add Property"));

mActionRemoveProperty->setText(tr("Remove"));
mActionRemoveProperty->setToolTip(tr("Remove Property"));
Expand Down
2 changes: 1 addition & 1 deletion src/tiled/propertiesdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public slots:
void removeProperties();
void renameProperty();
void renamePropertyTo(const QString &name);
void showContextMenu(const QPoint& pos);
void showContextMenu(const QPoint &pos);

void retranslateUi();

Expand Down

0 comments on commit 4025028

Please sign in to comment.