[nostalgia/core/studio] Add delete tile

This commit is contained in:
Gary Talent 2020-03-22 01:34:09 -05:00
parent 4ae0becf79
commit 7ae0befc37
3 changed files with 28 additions and 3 deletions

View File

@ -95,6 +95,14 @@ Rectangle {
sheetData.insertTileCmd(tile.tileNumber);
}
}
MenuItem {
text: "Delete Tile"
onTriggered: {
var tile = mouseArea.tileAt(contextMenu.x, contextMenu.y);
sheetData.deleteTileCmd(tile.tileNumber);
}
}
}
onPositionChanged: sheetData.updatePixel(pixelAt(mouseX, mouseY))

View File

@ -190,11 +190,13 @@ class InsertTileCommand: public QUndoCommand {
private:
SheetData *m_sheetData = nullptr;
int m_idx = 0;
bool m_delete = false;
public:
InsertTileCommand(SheetData *sheetData, int idx) {
InsertTileCommand(SheetData *sheetData, int idx, bool del = false) {
m_sheetData = sheetData;
m_idx = idx;
m_delete = del;
}
virtual ~InsertTileCommand() = default;
@ -204,11 +206,19 @@ class InsertTileCommand: public QUndoCommand {
}
void redo() override {
m_sheetData->insertTile(m_idx);
if (m_delete) {
m_sheetData->deleteTile(m_idx);
} else {
m_sheetData->insertTile(m_idx);
}
}
void undo() override {
m_sheetData->deleteTile(m_idx);
if (m_delete) {
m_sheetData->insertTile(m_idx);
} else {
m_sheetData->deleteTile(m_idx);
}
}
};
@ -235,6 +245,10 @@ void SheetData::insertTileCmd(int tileIdx) {
m_cmdStack.push(new InsertTileCommand(this, tileIdx));
}
void SheetData::deleteTileCmd(int tileIdx) {
m_cmdStack.push(new InsertTileCommand(this, tileIdx, true));
}
int SheetData::columns() const {
return m_columns;
}
@ -311,6 +325,7 @@ void SheetData::insertTile(int tileIdx) {
void SheetData::deleteTile(int tileIdx) {
m_pixels.remove(tileIdx * PixelsPerTile, PixelsPerTile);
emit pixelsChanged();
emit changeOccurred();
}
void SheetData::setSelectedColor(int index) {

View File

@ -45,6 +45,8 @@ class SheetData: public QObject {
Q_INVOKABLE void insertTileCmd(int tileIdx);
Q_INVOKABLE void deleteTileCmd(int tileIdx);
[[nodiscard]] int columns() const;
[[nodiscard]] int rows() const;