Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "Tileset > Edit Tileset Image Parameters..." action #4034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/tiled/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 3 additions & 6 deletions src/tiled/tilesetchanges.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ class ChangeTilesetTileOffset : public QUndoCommand

struct TilesetParameters
{
TilesetParameters()
: tileSpacing(0)
, margin(0)
{}
TilesetParameters() = default;

explicit TilesetParameters(const Tileset &tileset);

Expand All @@ -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
Expand Down
40 changes: 35 additions & 5 deletions src/tiled/tileseteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -249,7 +256,7 @@ TilesetEditor::TilesetEditor(QObject *parent)
retranslateUi();
connect(Preferences::instance(), &Preferences::languageChanged, this, &TilesetEditor::retranslateUi);

updateAddRemoveActions();
updateActions();
}

void TilesetEditor::saveState()
Expand Down Expand Up @@ -367,7 +374,7 @@ void TilesetEditor::setCurrentDocument(Document *document)
currentChanged(QModelIndex());
}

updateAddRemoveActions();
updateActions();
}

Document *TilesetEditor::currentDocument() const
Expand Down Expand Up @@ -527,7 +534,7 @@ void TilesetEditor::selectionChanged()
if (!view)
return;

updateAddRemoveActions();
updateActions();

const QItemSelectionModel *s = view->selectionModel();
const QModelIndexList indexes = s->selection().indexes();
Expand Down Expand Up @@ -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)
Expand All @@ -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"));
Expand Down Expand Up @@ -1034,7 +1062,7 @@ void TilesetEditor::onAnimationEditorClosed()
mShowAnimationEditor->setChecked(false);
}

void TilesetEditor::updateAddRemoveActions()
void TilesetEditor::updateActions()
{
bool isCollection = false;
bool hasSelection = false;
Expand All @@ -1046,6 +1074,8 @@ void TilesetEditor::updateAddRemoveActions()

mAddTiles->setEnabled(isCollection);
mRemoveTiles->setEnabled(isCollection && hasSelection);

mEditTilesetParameters->setEnabled(mCurrentTilesetDocument && !isCollection);
}

} // namespace Tiled
Expand Down
11 changes: 10 additions & 1 deletion src/tiled/tileseteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,6 +124,8 @@ class TilesetEditor final : public Editor
void selectedTilesChanged();
void updateTilesetView(Tileset *tileset);

void editTilesetParameters();

void openAddTilesDialog();
void addTiles(const QList<QUrl> &urls);
void removeTiles();
Expand All @@ -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);
Expand All @@ -158,6 +161,7 @@ class TilesetEditor final : public Editor

QAction *mAddTiles;
QAction *mRemoveTiles;
QAction *mEditTilesetParameters;
QAction *mRelocateTiles;
QAction *mShowAnimationEditor;
QAction *mDynamicWrappingToggle;
Expand Down Expand Up @@ -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;
Expand Down