From 8f0e937f66d2aa4612d35def553eaddf980886e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 15 Aug 2024 09:06:47 +0200 Subject: [PATCH] Added "Tileset > Edit Tileset Image Parameters..." action This makes the functionality easier to discover. Previously editing the tileset image parameters was only possible by clicking the value of the Image property in the Properties view, and then the appearing "Edit" button. --- src/tiled/mainwindow.cpp | 2 ++ src/tiled/tilesetchanges.h | 9 +++------ src/tiled/tileseteditor.cpp | 40 ++++++++++++++++++++++++++++++++----- src/tiled/tileseteditor.h | 11 +++++++++- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/tiled/mainwindow.cpp b/src/tiled/mainwindow.cpp index c8ec75f53c..fc7855ae14 100644 --- a/src/tiled/mainwindow.cpp +++ b/src/tiled/mainwindow.cpp @@ -809,6 +809,8 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) mUi->menuTileset->insertAction(mUi->actionTilesetProperties, mTilesetEditor->addTilesAction()); mUi->menuTileset->insertAction(mUi->actionTilesetProperties, mTilesetEditor->removeTilesAction()); mUi->menuTileset->insertSeparator(mUi->actionTilesetProperties); + mUi->menuTileset->insertAction(mUi->actionTilesetProperties, mTilesetEditor->editTilesetParametersAction()); + mUi->menuTileset->insertSeparator(mUi->actionTilesetProperties); connect(mViewsAndToolbarsMenu, &QMenu::aboutToShow, this, &MainWindow::updateViewsAndToolbarsMenu); diff --git a/src/tiled/tilesetchanges.h b/src/tiled/tilesetchanges.h index 01db25f6b8..4c5ceaaae5 100644 --- a/src/tiled/tilesetchanges.h +++ b/src/tiled/tilesetchanges.h @@ -74,10 +74,7 @@ class ChangeTilesetTileOffset : public QUndoCommand struct TilesetParameters { - TilesetParameters() - : tileSpacing(0) - , margin(0) - {} + TilesetParameters() = default; explicit TilesetParameters(const Tileset &tileset); @@ -86,8 +83,8 @@ struct TilesetParameters QUrl imageSource; QColor transparentColor; QSize tileSize; - int tileSpacing; - int margin; + int tileSpacing = 0; + int margin = 0; }; class ChangeTilesetParameters : public QUndoCommand diff --git a/src/tiled/tileseteditor.cpp b/src/tiled/tileseteditor.cpp index 07e091c536..107a3aa3d0 100644 --- a/src/tiled/tileseteditor.cpp +++ b/src/tiled/tileseteditor.cpp @@ -33,8 +33,11 @@ #include "maintoolbar.h" #include "mapdocument.h" #include "mapobject.h" +#include "newtilesetdialog.h" #include "objectgroup.h" -#include "objecttemplate.h" +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) +#include "objecttemplate.h" // needed for static assert in QtCore/qmetatype.h +#endif #include "preferences.h" #include "propertiesdock.h" #include "session.h" @@ -131,6 +134,7 @@ TilesetEditor::TilesetEditor(QObject *parent) , mWidgetStack(new QStackedWidget(mMainWindow)) , mAddTiles(new QAction(this)) , mRemoveTiles(new QAction(this)) + , mEditTilesetParameters(new QAction(this)) , mRelocateTiles(new QAction(this)) , mShowAnimationEditor(new QAction(this)) , mDynamicWrappingToggle(new QAction(this)) @@ -154,6 +158,7 @@ TilesetEditor::TilesetEditor(QObject *parent) ActionManager::registerAction(editWang, "EditWang"); ActionManager::registerAction(mAddTiles, "AddTiles"); ActionManager::registerAction(mRemoveTiles, "RemoveTiles"); + ActionManager::registerAction(mEditTilesetParameters, "EditTilesetParameters"); ActionManager::registerAction(mRelocateTiles, "RelocateTiles"); ActionManager::registerAction(mShowAnimationEditor, "ShowAnimationEditor"); ActionManager::registerAction(mDynamicWrappingToggle, "DynamicWrappingToggle"); @@ -199,6 +204,8 @@ TilesetEditor::TilesetEditor(QObject *parent) connect(mAddTiles, &QAction::triggered, this, &TilesetEditor::openAddTilesDialog); connect(mRemoveTiles, &QAction::triggered, this, &TilesetEditor::removeTiles); + connect(mEditTilesetParameters, &QAction::triggered, this, &TilesetEditor::editTilesetParameters); + connect(mRelocateTiles, &QAction::toggled, this, &TilesetEditor::setRelocateTiles); connect(editCollision, &QAction::toggled, this, &TilesetEditor::setEditCollision); connect(editWang, &QAction::toggled, this, &TilesetEditor::setEditWang); @@ -249,7 +256,7 @@ TilesetEditor::TilesetEditor(QObject *parent) retranslateUi(); connect(Preferences::instance(), &Preferences::languageChanged, this, &TilesetEditor::retranslateUi); - updateAddRemoveActions(); + updateActions(); } void TilesetEditor::saveState() @@ -367,7 +374,7 @@ void TilesetEditor::setCurrentDocument(Document *document) currentChanged(QModelIndex()); } - updateAddRemoveActions(); + updateActions(); } Document *TilesetEditor::currentDocument() const @@ -527,7 +534,7 @@ void TilesetEditor::selectionChanged() if (!view) return; - updateAddRemoveActions(); + updateActions(); const QItemSelectionModel *s = view->selectionModel(); const QModelIndexList indexes = s->selection().indexes(); @@ -657,6 +664,26 @@ void TilesetEditor::updateTilesetView(Tileset *tileset) model->tilesetChanged(); } +void TilesetEditor::editTilesetParameters() +{ + if (!mCurrentTilesetDocument) + return; + if (mCurrentTilesetDocument->tileset()->isCollection()) + return; + + TilesetParameters parameters(*mCurrentTilesetDocument->tileset()); + NewTilesetDialog dialog(mMainWindow->window()); + + if (dialog.editTilesetParameters(parameters)) { + if (parameters != TilesetParameters(*mCurrentTilesetDocument->tileset())) { + auto command = new ChangeTilesetParameters(mCurrentTilesetDocument, + parameters); + + mCurrentTilesetDocument->undoStack()->push(command); + } + } +} + void TilesetEditor::setCurrentTile(Tile *tile) { if (mCurrentTile == tile) @@ -675,6 +702,7 @@ void TilesetEditor::retranslateUi() mAddTiles->setText(tr("Add Tiles")); mRemoveTiles->setText(tr("Remove Tiles")); + mEditTilesetParameters->setText(tr("Edit Tileset Image Parameters...")); mRelocateTiles->setText(tr("Rearrange Tiles")); mShowAnimationEditor->setText(tr("Tile Animation Editor")); mDynamicWrappingToggle->setText(tr("Dynamically Wrap Tiles")); @@ -1034,7 +1062,7 @@ void TilesetEditor::onAnimationEditorClosed() mShowAnimationEditor->setChecked(false); } -void TilesetEditor::updateAddRemoveActions() +void TilesetEditor::updateActions() { bool isCollection = false; bool hasSelection = false; @@ -1046,6 +1074,8 @@ void TilesetEditor::updateAddRemoveActions() mAddTiles->setEnabled(isCollection); mRemoveTiles->setEnabled(isCollection && hasSelection); + + mEditTilesetParameters->setEnabled(mCurrentTilesetDocument && !isCollection); } } // namespace Tiled diff --git a/src/tiled/tileseteditor.h b/src/tiled/tileseteditor.h index 1080dd5e34..361858e3a6 100644 --- a/src/tiled/tileseteditor.h +++ b/src/tiled/tileseteditor.h @@ -92,6 +92,7 @@ class TilesetEditor final : public Editor QAction *addTilesAction() const; QAction *removeTilesAction() const; + QAction *editTilesetParametersAction() const; QAction *relocateTilesAction() const; QAction *editCollisionAction() const; QAction *editWangSetsAction() const; @@ -123,6 +124,8 @@ class TilesetEditor final : public Editor void selectedTilesChanged(); void updateTilesetView(Tileset *tileset); + void editTilesetParameters(); + void openAddTilesDialog(); void addTiles(const QList &urls); void removeTiles(); @@ -133,7 +136,7 @@ class TilesetEditor final : public Editor void setEditWang(bool editWang); - void updateAddRemoveActions(); + void updateActions(); void onCurrentWangSetChanged(WangSet *wangSet); void currentWangIdChanged(WangId wangId); @@ -158,6 +161,7 @@ class TilesetEditor final : public Editor QAction *mAddTiles; QAction *mRemoveTiles; + QAction *mEditTilesetParameters; QAction *mRelocateTiles; QAction *mShowAnimationEditor; QAction *mDynamicWrappingToggle; @@ -188,6 +192,11 @@ inline QAction *TilesetEditor::removeTilesAction() const return mRemoveTiles; } +inline QAction *TilesetEditor::editTilesetParametersAction() const +{ + return mEditTilesetParameters; +} + inline QAction *TilesetEditor::relocateTilesAction() const { return mRelocateTiles;