small fixes

- connect DEL key to event deletion action
- update checks for unsaved changes to map
- add an asterisk next to the map name in the
  window title when a map has unsaved changes
This commit is contained in:
garakmon 2020-07-31 17:12:08 -04:00 committed by garak
parent 4c154501f1
commit c3defd6887
6 changed files with 47 additions and 24 deletions

View file

@ -28,7 +28,8 @@ enum CommandId {
///
/// Implements a command to commit metatile paint actions
/// onto the map using the pencil tool.
class PaintMetatile : public QUndoCommand {
public:
PaintMetatile(Map *map,
@ -53,7 +54,7 @@ private:
///
/// Implements a command to commit paint actions on the map border.
class PaintBorder : public QUndoCommand {
public:
PaintBorder(Map *map,
@ -78,7 +79,8 @@ private:
///
/// Implements a command to commit flood fill metatile actions
/// with the bucket tool onto the map.
class BucketFillMetatile : public PaintMetatile {
public:
BucketFillMetatile(Map *map,
@ -92,7 +94,8 @@ public:
///
/// Implements a command to commit magic fill metatile actions
/// with the bucket or paint tool onto the map.
class MagicFillMetatile : public PaintMetatile {
public:
MagicFillMetatile(Map *map,
@ -107,7 +110,7 @@ public:
///
/// Implements a command to commit metatile shift actions.
class ShiftMetatiles : public QUndoCommand {
public:
ShiftMetatiles(Map *map,
@ -133,7 +136,7 @@ private:
///
/// Implements a command to commit a map or border resize action.
class ResizeMap : public QUndoCommand {
public:
ResizeMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions,
@ -171,7 +174,8 @@ private:
///
/// Implements a command to commit a single- or multi-Event move action.
/// Actions are merged into one until the mouse is released.
class EventMove : public QUndoCommand {
public:
EventMove(QList<Event *> events,
@ -195,7 +199,7 @@ private:
///
/// Implements a command to commit Event shift actions.
class EventShift : public EventMove {
public:
EventShift(QList<Event *> events,
@ -208,7 +212,8 @@ public:
///
/// Implements a command to commit Event create actions.
/// Works for a single Event only.
class EventCreate : public QUndoCommand {
public:
EventCreate(Editor *editor, Map *map, Event *event,
@ -229,7 +234,8 @@ private:
///
/// Implements a command to commit Event deletions.
/// Applies to every currently selected Event.
class EventDelete : public QUndoCommand {
public:
EventDelete(Editor *editor, Map *map, QList<Event *> selectedEvents,

View file

@ -30,7 +30,6 @@ public:
Blockdata *cached_blockdata = nullptr;
Blockdata *cached_collision = nullptr;
Blockdata *cached_border = nullptr;
bool has_unsaved_changes = false;
};
#endif // MAPLAYOUT_H

View file

@ -290,6 +290,8 @@ private:
void checkToolButtons();
void clickToolButtonFromEditMode(QString editMode);
void showWindowTitle();
void initWindow();
void initCustomUI();
void initExtraShortcuts();

View file

@ -14,6 +14,7 @@
Map::Map(QObject *parent) : QObject(parent)
{
editHistory.setClean();
}
void Map::setName(QString mapName) {
@ -466,5 +467,5 @@ void Map::addEvent(Event *event) {
}
bool Map::hasUnsavedChanges() {
return !metatileHistory.isSaved() || !isPersistedToFile || layout->has_unsaved_changes;
return !editHistory.isClean() || !isPersistedToFile;
}

View file

@ -107,6 +107,7 @@ void MainWindow::initExtraShortcuts() {
new QShortcut(QKeySequence("Ctrl+0"), this, SLOT(resetMapViewScale()));
new QShortcut(QKeySequence("Ctrl+G"), ui->checkBox_ToggleGrid, SLOT(toggle()));
new QShortcut(QKeySequence("Ctrl+D"), this, SLOT(duplicate()));
new QShortcut(QKeySequence::Delete, this, SLOT(on_toolButton_deleteObject_clicked()));
ui->actionZoom_In->setShortcuts({QKeySequence("Ctrl++"), QKeySequence("Ctrl+=")});
}
@ -168,6 +169,9 @@ void MainWindow::initEditor() {
//ui->comboBox_History->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
//ui->comboBox_History->setModel(undoView->model());
//ui->comboBox_History->setView(undoView);
// Toggle an asterisk in the window title when the undo state is changed
connect(&editor->editGroup, &QUndoGroup::cleanChanged, this, &MainWindow::showWindowTitle);
}
void MainWindow::initMiscHeapObjects() {
@ -211,6 +215,16 @@ void MainWindow::initMapSortOrder() {
sortOrder->setChecked(true);
}
void MainWindow::showWindowTitle() {
if (editor->map) {
setWindowTitle(QString("%1%2 - %3")
.arg(editor->map->hasUnsavedChanges() ? "* " : "")
.arg(editor->map->name)
.arg(editor->project->getProjectTitle())
);
}
}
void MainWindow::setProjectSpecificUIVisibility()
{
ui->actionUse_Encounter_Json->setChecked(projectConfig.getEncounterJsonActive());
@ -399,7 +413,7 @@ bool MainWindow::openProject(QString dir) {
}
if (success) {
setWindowTitle(editor->project->getProjectTitle());
showWindowTitle();
this->statusBar()->showMessage(QString("Opened project %1").arg(nativeDir));
} else {
this->statusBar()->showMessage(QString("Failed to open project %1").arg(nativeDir));
@ -515,7 +529,7 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(map_name)), true);
setWindowTitle(map_name + " - " + editor->project->getProjectTitle());
showWindowTitle();
connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
connect(editor->map, SIGNAL(mapNeedsRedrawing()), this, SLOT(onMapNeedsRedrawing()));
@ -2108,9 +2122,11 @@ void MainWindow::on_horizontalSlider_CollisionTransparency_valueChanged(int valu
this->editor->collision_item->draw(true);
}
// TODO: connect this to the DEL key when undo/redo history is extended to events
void MainWindow::on_toolButton_deleteObject_clicked()
{
void MainWindow::on_toolButton_deleteObject_clicked() {
if (ui->mainTabBar->currentIndex() != 1) {
// do not delete an event when not on event tab
return;
}
if (editor && editor->selected_events) {
if (editor->selected_events->length()) {
DraggablePixmapItem *next_selected_event = nullptr;
@ -2311,7 +2327,6 @@ void MainWindow::onLoadMapRequested(QString mapName, QString fromMapName) {
}
void MainWindow::onMapChanged(Map *map) {
map->layout->has_unsaved_changes = true;
updateMapList();
}

View file

@ -1120,7 +1120,7 @@ void Project::saveTilesetPalettes(Tileset *tileset) {
}
bool Project::loadMapTilesets(Map* map) {
if (map->layout->has_unsaved_changes) {
if (map->hasUnsavedChanges()) {
return true;
}
@ -1179,8 +1179,8 @@ Tileset* Project::loadTileset(QString label, Tileset *tileset) {
return tileset;
}
bool Project::loadBlockdata(Map* map) {
if (!map->isPersistedToFile || map->layout->has_unsaved_changes) {
bool Project::loadBlockdata(Map *map) {
if (map->hasUnsavedChanges()) {
return true;
}
@ -1198,7 +1198,7 @@ bool Project::loadBlockdata(Map* map) {
return true;
}
void Project::setNewMapBlockdata(Map* map) {
void Project::setNewMapBlockdata(Map *map) {
Blockdata *blockdata = new Blockdata;
for (int i = 0; i < map->getWidth() * map->getHeight(); i++) {
blockdata->addBlock(qint16(0x3001));
@ -1207,7 +1207,7 @@ void Project::setNewMapBlockdata(Map* map) {
}
bool Project::loadMapBorder(Map *map) {
if (!map->isPersistedToFile || map->layout->has_unsaved_changes) {
if (map->hasUnsavedChanges()) {
return true;
}
@ -1461,7 +1461,7 @@ void Project::saveMap(Map *map) {
updateMapLayout(map);
map->isPersistedToFile = true;
map->layout->has_unsaved_changes = false;
map->editHistory.setClean();
}
void Project::updateMapLayout(Map* map) {