diff --git a/src/tiled/propertieswidget.cpp b/src/tiled/propertieswidget.cpp index 9afabf0231..3515bfc81e 100644 --- a/src/tiled/propertieswidget.cpp +++ b/src/tiled/propertieswidget.cpp @@ -25,6 +25,7 @@ #include "changemapproperty.h" #include "changeproperties.h" #include "clipboardmanager.h" +#include "compression.h" #include "mapdocument.h" #include "propertybrowser.h" #include "utils.h" @@ -93,6 +94,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent) // connect(mPropertyBrowser, &PropertyBrowser::selectedItemsChanged, // this, &PropertiesWidget::updateActions); + registerEditorFactories(); retranslateUi(); } @@ -303,6 +305,30 @@ class MapProperties : public QObject mMapDocument->undoStack()->push(command); }); + mStaggerAxisProperty = editorFactory->createProperty( + tr("Stagger Axis"), + [this]() { + return QVariant::fromValue(mMapDocument->map()->staggerAxis()); + }, + [this](const QVariant &value) { + auto command = new ChangeMapProperty(mMapDocument, + Map::StaggerAxisProperty, + value.toInt()); + mMapDocument->undoStack()->push(command); + }); + + mStaggerIndexProperty = editorFactory->createProperty( + tr("Stagger Index"), + [this]() { + return QVariant::fromValue(mMapDocument->map()->staggerIndex()); + }, + [this](const QVariant &value) { + auto command = new ChangeMapProperty(mMapDocument, + Map::StaggerIndexProperty, + value.toInt()); + mMapDocument->undoStack()->push(command); + }); + connect(mMapDocument, &MapDocument::changed, this, &MapProperties::onMapChanged); } @@ -315,8 +341,8 @@ class MapProperties : public QObject editor->addProperty(mTileSizeProperty); editor->addProperty(mInfiniteProperty); editor->addProperty(mHexSideLengthProperty); - // editor->addProperty(mStaggerAxisProperty); - // editor->addProperty(mStaggerIndexProperty); + editor->addProperty(mStaggerAxisProperty); + editor->addProperty(mStaggerIndexProperty); // editor->addProperty(mParallaxOriginProperty); // editor->addProperty(mLayerDataFormatProperty); // editor->addProperty(mChunkSizeProperty); @@ -341,8 +367,14 @@ class MapProperties : public QObject emit mInfiniteProperty->valueChanged(); break; case Map::HexSideLengthProperty: + emit mHexSideLengthProperty->valueChanged(); + break; case Map::StaggerAxisProperty: + emit mStaggerAxisProperty->valueChanged(); + break; case Map::StaggerIndexProperty: + emit mStaggerIndexProperty->valueChanged(); + break; case Map::ParallaxOriginProperty: case Map::OrientationProperty: emit mOrientationProperty->valueChanged(); @@ -782,6 +814,77 @@ void PropertiesWidget::keyPressEvent(QKeyEvent *event) } } +void PropertiesWidget::registerEditorFactories() +{ + registerEditorFactory(qMetaTypeId(), + std::make_unique( + QStringList { + tr("Unspecified"), + tr("Top Left"), + tr("Top"), + tr("Top Right"), + tr("Left"), + tr("Center"), + tr("Right"), + tr("Bottom Left"), + tr("Bottom"), + tr("Bottom Right"), + })); + + + registerEditorFactory(qMetaTypeId(), + std::make_unique( + QStringList { + tr("X"), + tr("Y"), + })); + + registerEditorFactory(qMetaTypeId(), + std::make_unique( + QStringList { + tr("Odd"), + tr("Even"), + })); + + QStringList layerFormatNames = { + QCoreApplication::translate("PreferencesDialog", "XML (deprecated)"), + QCoreApplication::translate("PreferencesDialog", "Base64 (uncompressed)"), + QCoreApplication::translate("PreferencesDialog", "Base64 (gzip compressed)"), + QCoreApplication::translate("PreferencesDialog", "Base64 (zlib compressed)"), + }; + QList layerFormatValues = { + Map::XML, + Map::Base64, + Map::Base64Gzip, + Map::Base64Zlib, + }; + + if (compressionSupported(Zstandard)) { + layerFormatNames.append(QCoreApplication::translate("PreferencesDialog", "Base64 (Zstandard compressed)")); + layerFormatValues.append(Map::Base64Zstandard); + } + + layerFormatNames.append(QCoreApplication::translate("PreferencesDialog", "CSV")); + layerFormatValues.append(Map::CSV); + + registerEditorFactory(qMetaTypeId(), + std::make_unique(layerFormatNames, layerFormatValues)); + + registerEditorFactory(qMetaTypeId(), + std::make_unique( + QStringList { + tr("Right Down"), + tr("Right Up"), + tr("Left Down"), + tr("Left Up"), + })); +} + +void PropertiesWidget::registerEditorFactory(int type, std::unique_ptr factory) +{ + mDefaultEditorFactory->registerEditorFactory(type, std::move(factory)); +} + void PropertiesWidget::retranslateUi() { mActionAddProperty->setText(QCoreApplication::translate("Tiled::PropertiesDock", "Add Property")); diff --git a/src/tiled/propertieswidget.h b/src/tiled/propertieswidget.h index 55447f7247..37db77ee6d 100644 --- a/src/tiled/propertieswidget.h +++ b/src/tiled/propertieswidget.h @@ -29,6 +29,7 @@ namespace Tiled { class Object; class Document; +class EditorFactory; class ValueTypeEditorFactory; class VariantEditor; @@ -61,6 +62,9 @@ public slots: void keyPressEvent(QKeyEvent *event) override; private: + void registerEditorFactories(); + void registerEditorFactory(int type, std::unique_ptr factory); + void currentObjectChanged(Object *object); void updateActions(); diff --git a/src/tiled/varianteditor.cpp b/src/tiled/varianteditor.cpp index 523ad504c4..081f3f8f95 100644 --- a/src/tiled/varianteditor.cpp +++ b/src/tiled/varianteditor.cpp @@ -49,7 +49,8 @@ AbstractProperty::AbstractProperty(const QString &name, QWidget *AbstractProperty::createEditor(QWidget *parent) { - return m_editorFactory->createEditor(this, parent); + return m_editorFactory ? m_editorFactory->createEditor(this, parent) + : nullptr; } @@ -316,7 +317,7 @@ VariantEditor::VariantEditor(QWidget *parent) m_gridLayout = new QGridLayout; verticalLayout->addLayout(m_gridLayout); verticalLayout->addStretch(); - verticalLayout->setContentsMargins(QMargins()); + verticalLayout->setContentsMargins(0, 0, 0, Utils::dpiScaled(6)); setWidget(m_widget); setWidgetResizable(true); @@ -330,71 +331,6 @@ VariantEditor::VariantEditor(QWidget *parent) m_gridLayout->setColumnMinimumWidth(MiddleSpacing, Utils::dpiScaled(2)); m_gridLayout->setColumnMinimumWidth(RightSpacing, Utils::dpiScaled(3)); - // auto alignmentEditorFactory = std::make_unique(); - // alignmentEditorFactory->setEnumNames({ - // tr("Unspecified"), - // tr("Top Left"), - // tr("Top"), - // tr("Top Right"), - // tr("Left"), - // tr("Center"), - // tr("Right"), - // tr("Bottom Left"), - // tr("Bottom"), - // tr("Bottom Right"), - // }); - // registerEditorFactory(qMetaTypeId(), std::move(alignmentEditorFactory)); - - - // auto staggerAxisEditorFactory = std::make_unique(); - // staggerAxisEditorFactory->setEnumNames({ - // tr("X"), - // tr("Y"), - // }); - // registerEditorFactory(qMetaTypeId(), std::move(staggerAxisEditorFactory)); - - // auto staggerIndexEditorFactory = std::make_unique(); - // staggerIndexEditorFactory->setEnumNames({ - // tr("Odd"), - // tr("Even"), - // }); - // registerEditorFactory(qMetaTypeId(), std::move(staggerIndexEditorFactory)); - - QStringList layerFormatNames = { - QCoreApplication::translate("PreferencesDialog", "XML (deprecated)"), - QCoreApplication::translate("PreferencesDialog", "Base64 (uncompressed)"), - QCoreApplication::translate("PreferencesDialog", "Base64 (gzip compressed)"), - QCoreApplication::translate("PreferencesDialog", "Base64 (zlib compressed)"), - }; - QList layerFormatValues = { - Map::XML, - Map::Base64, - Map::Base64Gzip, - Map::Base64Zlib, - }; - - if (compressionSupported(Zstandard)) { - layerFormatNames.append(QCoreApplication::translate("PreferencesDialog", "Base64 (Zstandard compressed)")); - layerFormatValues.append(Map::Base64Zstandard); - } - - layerFormatNames.append(QCoreApplication::translate("PreferencesDialog", "CSV")); - layerFormatValues.append(Map::CSV); - - // auto layerFormatEditorFactory = std::make_unique(); - // layerFormatEditorFactory->setEnumNames(layerFormatNames); - // layerFormatEditorFactory->setEnumValues(layerFormatValues); - // registerEditorFactory(qMetaTypeId(), std::move(layerFormatEditorFactory)); - - // auto renderOrderEditorFactory = std::make_unique(); - // renderOrderEditorFactory->setEnumNames({ - // tr("Right Down"), - // tr("Right Up"), - // tr("Left Down"), - // tr("Left Up"), - // }); - // registerEditorFactory(qMetaTypeId(), std::move(renderOrderEditorFactory)); - // setValue(QVariantMap { // { QStringLiteral("Name"), QVariant(QLatin1String("Hello")) }, // { QStringLiteral("Position"), QVariant(QPoint(15, 50)) }, @@ -607,24 +543,23 @@ QObjectProperty *ValueTypeEditorFactory::createQObjectProperty(QObject *qObject, this); } -ValueProperty *ValueTypeEditorFactory::createProperty(const QString &name, const QVariant &value) +ValueProperty *ValueTypeEditorFactory::createProperty(const QString &name, + const QVariant &value) { - const int type = value.userType(); - auto factory = m_factories.find(type); - if (factory != m_factories.end()) - return new ValueProperty(name, value, factory->second.get()); - return nullptr; + auto f = m_factories.find(value.userType()); + return new ValueProperty(name, value, + f != m_factories.end() ? f->second.get() + : nullptr); } AbstractProperty *ValueTypeEditorFactory::createProperty(const QString &name, std::function get, std::function set) { - const int type = get().userType(); - auto factory = m_factories.find(type); - if (factory != m_factories.end()) - return new GetSetProperty(name, get, set, factory->second.get()); - return nullptr; + auto f = m_factories.find(get().userType()); + return new GetSetProperty(name, get, set, + f != m_factories.end() ? f->second.get() + : nullptr); } QWidget *ValueTypeEditorFactory::createEditor(Property *property, QWidget *parent)