Skip to content

Commit

Permalink
Made Add Property action use inline widgets
Browse files Browse the repository at this point in the history
Use a special property that creates a name edit as label and a type
combo box as editor, instead of a modal Add Property dialog.

VariantEditorView::focusProperty now makes sure that the focused
property widget is visible.

The "add value" property is automatically removed when it loses focus.
To achieve this, each property now gets its own parent widget rather
than just having its widgets added to a nested horizontal layout. This
way, we can check whether the focus remains within the same parent
widget.

The Add button has Qt::StrongFocus policy now, otherwise the focus would
be lost to the properties view when clicking it.
  • Loading branch information
bjorn committed Nov 14, 2024
1 parent 74a952d commit 85ef006
Show file tree
Hide file tree
Showing 14 changed files with 430 additions and 410 deletions.
124 changes: 0 additions & 124 deletions src/tiled/addpropertydialog.cpp

This file was deleted.

54 changes: 0 additions & 54 deletions src/tiled/addpropertydialog.h

This file was deleted.

103 changes: 0 additions & 103 deletions src/tiled/addpropertydialog.ui

This file was deleted.

3 changes: 0 additions & 3 deletions src/tiled/libtilededitor.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ DynamicLibrary {
"actionmanager.h",
"actionsearch.cpp",
"actionsearch.h",
"addpropertydialog.cpp",
"addpropertydialog.h",
"addpropertydialog.ui",
"addremovelayer.cpp",
"addremovelayer.h",
"addremovemapobject.cpp",
Expand Down
26 changes: 20 additions & 6 deletions src/tiled/propertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "propertieswidget.h"

#include "actionmanager.h"
#include "addpropertydialog.h"
#include "changeimagelayerproperty.h"
#include "changelayer.h"
#include "changemapobject.h"
Expand Down Expand Up @@ -2166,18 +2165,20 @@ PropertiesWidget::PropertiesWidget(QWidget *parent)
mActionAddProperty->setEnabled(false);
mActionAddProperty->setIcon(QIcon(QLatin1String(":/images/16/add.png")));
connect(mActionAddProperty, &QAction::triggered,
this, &PropertiesWidget::openAddPropertyDialog);
this, &PropertiesWidget::showAddValueProperty);

mActionRemoveProperty = new QAction(this);
mActionRemoveProperty->setEnabled(false);
mActionRemoveProperty->setIcon(QIcon(QLatin1String(":/images/16/remove.png")));
mActionRemoveProperty->setShortcuts(QKeySequence::Delete);
mActionRemoveProperty->setPriority(QAction::LowPriority);
connect(mActionRemoveProperty, &QAction::triggered,
this, &PropertiesWidget::removeProperties);

mActionRenameProperty = new QAction(this);
mActionRenameProperty->setEnabled(false);
mActionRenameProperty->setIcon(QIcon(QLatin1String(":/images/16/rename.png")));
mActionRenameProperty->setPriority(QAction::LowPriority);
// connect(mActionRenameProperty, &QAction::triggered,
// this, &PropertiesWidget::renameProperty);

Expand All @@ -2188,6 +2189,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent)
QToolBar *toolBar = new QToolBar;
toolBar->setFloatable(false);
toolBar->setMovable(false);
toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
toolBar->setIconSize(Utils::smallIconSize());
toolBar->addAction(mActionAddProperty);
toolBar->addAction(mActionRemoveProperty);
Expand Down Expand Up @@ -2516,11 +2518,23 @@ void PropertiesWidget::pasteProperties()
}
}

void PropertiesWidget::openAddPropertyDialog()
void PropertiesWidget::showAddValueProperty()
{
AddPropertyDialog dialog(mPropertyBrowser);
if (dialog.exec() == AddPropertyDialog::Accepted)
addProperty(dialog.propertyName(), dialog.propertyValue());
if (!mAddValueProperty) {
mAddValueProperty = new AddValueProperty(mCustomProperties);

connect(mAddValueProperty, &Property::addRequested, this, [this] {
addProperty(mAddValueProperty->name(), mAddValueProperty->value());
mCustomProperties->deleteProperty(mAddValueProperty);
});
connect(mAddValueProperty, &Property::removeRequested, this, [this] {
mCustomProperties->deleteProperty(mAddValueProperty);
});

mCustomProperties->addProperty(mAddValueProperty);
}

mPropertyBrowser->focusProperty(mAddValueProperty, VariantEditor::FocusLabel);
}

void PropertiesWidget::addProperty(const QString &name, const QVariant &value)
Expand Down
5 changes: 4 additions & 1 deletion src/tiled/propertieswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <QMap>
#include <QPointer>
#include <QWidget>

class QScrollArea;
Expand All @@ -29,6 +30,7 @@ namespace Tiled {

class Object;

class AddValueProperty;
class CustomProperties;
class Document;
class GroupProperty;
Expand Down Expand Up @@ -73,7 +75,7 @@ public slots:
void cutProperties();
bool copyProperties();
void pasteProperties();
void openAddPropertyDialog();
void showAddValueProperty();
void addProperty(const QString &name, const QVariant &value);
void removeProperties();
void renameProperty(const QString &name);
Expand All @@ -84,6 +86,7 @@ public slots:
Document *mDocument = nullptr;
ObjectProperties *mPropertiesObject = nullptr;
CustomProperties *mCustomProperties = nullptr;
QPointer<AddValueProperty> mAddValueProperty;
QMap<int, bool> mExpandedStates;
VariantEditorView *mPropertyBrowser;
QAction *mActionAddProperty;
Expand Down
Loading

0 comments on commit 85ef006

Please sign in to comment.