use enum class for edit modes

This commit is contained in:
garak 2023-02-03 13:09:25 -05:00
parent 18eb3ceb1e
commit e2253939fc
4 changed files with 62 additions and 95 deletions

View file

@ -155,9 +155,13 @@ public:
QList<DraggablePixmapItem *> *selected_events = nullptr; QList<DraggablePixmapItem *> *selected_events = nullptr;
enum class EditAction { None, Paint, Select, Fill, Shift, Pick, Move };
EditAction mapEditAction = EditAction::Paint;
EditAction objectEditAction = EditAction::Select;
/// !TODO this /// !TODO this
QString map_edit_mode = "paint"; enum class EditMode { None, Map, Layout };
QString obj_edit_mode = "select"; EditMode editMode = EditMode::Map;
int scaleIndex = 2; int scaleIndex = 2;
qreal collisionOpacity = 0.5; qreal collisionOpacity = 0.5;

View file

@ -321,12 +321,6 @@ private:
LayoutTreeModel *layoutTreeModel; LayoutTreeModel *layoutTreeModel;
// QStandardItemModel *mapListModel;
// QList<QStandardItem*> *mapGroupItemsList;
// QMap<QString, QModelIndex> mapListIndexes;
// QIcon* mapIcon;
// QIcon* mapEditedIcon;
// QIcon* mapOpenedIcon;
QAction *undoAction = nullptr; QAction *undoAction = nullptr;
QAction *redoAction = nullptr; QAction *redoAction = nullptr;
@ -374,12 +368,11 @@ private:
void setRecentMap(QString map_name); void setRecentMap(QString map_name);
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum); QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
void drawMapListIcons(QAbstractItemModel *model);
void updateMapList(); void updateMapList();
void displayMapProperties(); void displayMapProperties();
void checkToolButtons(); void checkToolButtons();
void clickToolButtonFromEditMode(QString editMode); void clickToolButtonFromEditAction(Editor::EditAction editAction);
void markMapEdited(); void markMapEdited();
void showWindowTitle(); void showWindowTitle();

View file

@ -158,7 +158,7 @@ void Editor::setMapEditingButtonsEnabled(bool enabled) {
this->ui->pushButton_ChangeDimensions->setEnabled(enabled); this->ui->pushButton_ChangeDimensions->setEnabled(enabled);
// If the fill button is pressed, unpress it and select the pointer. // If the fill button is pressed, unpress it and select the pointer.
if (!enabled && (this->ui->toolButton_Fill->isChecked() || this->ui->toolButton_Dropper->isChecked())) { if (!enabled && (this->ui->toolButton_Fill->isChecked() || this->ui->toolButton_Dropper->isChecked())) {
this->map_edit_mode = "select"; this->mapEditAction = EditAction::Select;
this->settings->mapCursor = QCursor(); this->settings->mapCursor = QCursor();
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->ui->toolButton_Fill->setChecked(false); this->ui->toolButton_Fill->setChecked(false);
@ -1145,7 +1145,7 @@ bool Editor::setLayout(QString layoutId) {
} }
map_ruler->setMapDimensions(QSize(this->layout->getWidth(), this->layout->getHeight())); map_ruler->setMapDimensions(QSize(this->layout->getWidth(), this->layout->getHeight()));
connect(map, &Map::mapDimensionsChanged, map_ruler, &MapRuler::setMapDimensions); connect(this->layout, &Layout::layoutDimensionsChanged, map_ruler, &MapRuler::setMapDimensions);
return true; return true;
} }
@ -1156,7 +1156,7 @@ void Editor::onMapStartPaint(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *
} }
QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
if (event->buttons() & Qt::RightButton && (map_edit_mode == "paint" || map_edit_mode == "fill")) { if (event->buttons() & Qt::RightButton && (mapEditAction == EditAction::Paint || mapEditAction == EditAction::Fill)) {
this->cursorMapTileRect->initRightClickSelectionAnchor(pos.x(), pos.y()); this->cursorMapTileRect->initRightClickSelectionAnchor(pos.x(), pos.y());
} else { } else {
this->cursorMapTileRect->initAnchor(pos.x(), pos.y()); this->cursorMapTileRect->initAnchor(pos.x(), pos.y());
@ -1206,7 +1206,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i
QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
if (item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) { if (item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) {
if (map_edit_mode == "paint") { if (mapEditAction == EditAction::Paint) {
if (event->buttons() & Qt::RightButton) { if (event->buttons() & Qt::RightButton) {
item->updateMetatileSelection(event); item->updateMetatileSelection(event);
} else if (event->buttons() & Qt::MiddleButton) { } else if (event->buttons() & Qt::MiddleButton) {
@ -1228,9 +1228,9 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i
} }
item->paint(event); item->paint(event);
} }
} else if (map_edit_mode == "select") { } else if (mapEditAction == EditAction::Select) {
item->select(event); item->select(event);
} else if (map_edit_mode == "fill") { } else if (mapEditAction == EditAction::Fill) {
if (event->buttons() & Qt::RightButton) { if (event->buttons() & Qt::RightButton) {
item->updateMetatileSelection(event); item->updateMetatileSelection(event);
} else if (event->modifiers() & Qt::ControlModifier) { } else if (event->modifiers() & Qt::ControlModifier) {
@ -1238,13 +1238,13 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i
} else { } else {
item->floodFill(event); item->floodFill(event);
} }
} else if (map_edit_mode == "pick") { } else if (mapEditAction == EditAction::Pick) {
if (event->buttons() & Qt::RightButton) { if (event->buttons() & Qt::RightButton) {
item->updateMetatileSelection(event); item->updateMetatileSelection(event);
} else { } else {
item->pick(event); item->pick(event);
} }
} else if (map_edit_mode == "shift") { } else if (mapEditAction == EditAction::Shift) {
this->setStraightPathCursorMode(event); this->setStraightPathCursorMode(event);
if (this->cursorMapTileRect->getStraightPathMode()) { if (this->cursorMapTileRect->getStraightPathMode()) {
item->lockNondominantAxis(event); item->lockNondominantAxis(event);
@ -1253,10 +1253,10 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i
item->shift(event); item->shift(event);
} }
} else if (item->paintingMode == LayoutPixmapItem::PaintMode::EventObjects) { } else if (item->paintingMode == LayoutPixmapItem::PaintMode::EventObjects) {
if (obj_edit_mode == "paint" && event->type() == QEvent::GraphicsSceneMousePress) { if (objectEditAction == EditAction::Paint && event->type() == QEvent::GraphicsSceneMousePress) {
// Right-clicking while in paint mode will change mode to select. // Right-clicking while in paint mode will change mode to select.
if (event->buttons() & Qt::RightButton) { if (event->buttons() & Qt::RightButton) {
this->obj_edit_mode = "select"; this->objectEditAction = EditAction::Select;
this->settings->mapCursor = QCursor(); this->settings->mapCursor = QCursor();
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->ui->toolButton_Paint->setChecked(false); this->ui->toolButton_Paint->setChecked(false);
@ -1278,9 +1278,9 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i
} }
} }
} }
} else if (obj_edit_mode == "select") { } else if (objectEditAction == EditAction::Select) {
// do nothing here, at least for now // do nothing here, at least for now
} else if (obj_edit_mode == "shift") { } else if (objectEditAction == EditAction::Shift) {
static QPoint selection_origin; static QPoint selection_origin;
static unsigned actionId = 0; static unsigned actionId = 0;
@ -1316,7 +1316,7 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
if (map_edit_mode == "paint") { if (mapEditAction == EditAction::Paint) {
if (event->buttons() & Qt::RightButton) { if (event->buttons() & Qt::RightButton) {
item->updateMovementPermissionSelection(event); item->updateMovementPermissionSelection(event);
} else if (event->buttons() & Qt::MiddleButton) { } else if (event->buttons() & Qt::MiddleButton) {
@ -1333,9 +1333,9 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
} }
item->paint(event); item->paint(event);
} }
} else if (map_edit_mode == "select") { } else if (mapEditAction == EditAction::Select) {
item->select(event); item->select(event);
} else if (map_edit_mode == "fill") { } else if (mapEditAction == EditAction::Fill) {
if (event->buttons() & Qt::RightButton) { if (event->buttons() & Qt::RightButton) {
item->pick(event); item->pick(event);
} else if (event->modifiers() & Qt::ControlModifier) { } else if (event->modifiers() & Qt::ControlModifier) {
@ -1343,9 +1343,9 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
} else { } else {
item->floodFill(event); item->floodFill(event);
} }
} else if (map_edit_mode == "pick") { } else if (mapEditAction == EditAction::Pick) {
item->pick(event); item->pick(event);
} else if (map_edit_mode == "shift") { } else if (mapEditAction == EditAction::Shift) {
this->setStraightPathCursorMode(event); this->setStraightPathCursorMode(event);
if (this->cursorMapTileRect->getStraightPathMode()) { if (this->cursorMapTileRect->getStraightPathMode()) {
item->lockNondominantAxis(event); item->lockNondominantAxis(event);
@ -2247,8 +2247,8 @@ void Editor::objectsView_onMousePress(QMouseEvent *event) {
if (map_item && map_item->paintingMode != LayoutPixmapItem::PaintMode::EventObjects) { if (map_item && map_item->paintingMode != LayoutPixmapItem::PaintMode::EventObjects) {
return; return;
} }
if (this->obj_edit_mode == "paint" && event->buttons() & Qt::RightButton) { if (this->objectEditAction == EditAction::Paint && event->buttons() & Qt::RightButton) {
this->obj_edit_mode = "select"; this->objectEditAction = EditAction::Select;
this->settings->mapCursor = QCursor(); this->settings->mapCursor = QCursor();
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->ui->toolButton_Paint->setChecked(false); this->ui->toolButton_Paint->setChecked(false);

View file

@ -625,7 +625,6 @@ void MainWindow::unsetMap() {
this->editor->unsetMap(); this->editor->unsetMap();
// disable other tabs // disable other tabs
this->ui->mainTabBar->setTabEnabled(0, true);
this->ui->mainTabBar->setTabEnabled(1, false); this->ui->mainTabBar->setTabEnabled(1, false);
this->ui->mainTabBar->setTabEnabled(2, false); this->ui->mainTabBar->setTabEnabled(2, false);
this->ui->mainTabBar->setTabEnabled(3, false); this->ui->mainTabBar->setTabEnabled(3, false);
@ -653,6 +652,11 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
ui->mapList->setExpanded(groupListProxyModel->mapFromSource(mapGroupModel->indexOfMap(map_name)), false); ui->mapList->setExpanded(groupListProxyModel->mapFromSource(mapGroupModel->indexOfMap(map_name)), false);
} }
this->ui->mainTabBar->setTabEnabled(1, true);
this->ui->mainTabBar->setTabEnabled(2, true);
this->ui->mainTabBar->setTabEnabled(3, true);
this->ui->mainTabBar->setTabEnabled(4, true);
refreshMapScene(); refreshMapScene();
displayMapProperties(); displayMapProperties();
@ -1492,39 +1496,7 @@ void MainWindow::on_layoutList_activated(const QModelIndex &index) {
} }
} }
/// !TODO something with the projectHasUnsavedChanges var
void MainWindow::drawMapListIcons(QAbstractItemModel *model) {
// projectHasUnsavedChanges = false;
// QList<QModelIndex> list;
// list.append(QModelIndex());
// while (list.length()) {
// QModelIndex parent = list.takeFirst();
// for (int i = 0; i < model->rowCount(parent); i++) {
// QModelIndex index = model->index(i, 0, parent);
// if (model->hasChildren(index)) {
// list.append(index);
// }
// QVariant data = index.data(Qt::UserRole);
// if (!data.isNull()) {
// QString map_name = data.toString();
// if (editor->project && editor->project->mapCache.contains(map_name)) {
// QStandardItem *map = mapListModel->itemFromIndex(mapListIndexes.value(map_name));
// map->setIcon(*mapIcon);
// if (editor->project->mapCache.value(map_name)->hasUnsavedChanges()) {
// map->setIcon(*mapEditedIcon);
// projectHasUnsavedChanges = true;
// }
// if (editor->map->name == map_name) {
// map->setIcon(*mapOpenedIcon);
// }
// }
// }
// }
// }
}
void MainWindow::updateMapList() { void MainWindow::updateMapList() {
//MapGroupModel *model = static_cast<MapGroupModel *>(this->ui->mapList->model());
if (this->editor->map) { if (this->editor->map) {
mapGroupModel->setMap(this->editor->map->name); mapGroupModel->setMap(this->editor->map->name);
groupListProxyModel->layoutChanged(); groupListProxyModel->layoutChanged();
@ -1534,8 +1506,6 @@ void MainWindow::updateMapList() {
layoutTreeModel->setLayout(this->editor->layout->id); layoutTreeModel->setLayout(this->editor->layout->id);
layoutListProxyModel->layoutChanged(); layoutListProxyModel->layoutChanged();
} }
//mapGroupModel->layoutChanged();
// drawMapListIcons(mapListModel);
} }
void MainWindow::on_action_Save_Project_triggered() { void MainWindow::on_action_Save_Project_triggered() {
@ -1846,11 +1816,11 @@ void MainWindow::on_mainTabBar_tabBarClicked(int index)
if (index == 0) { if (index == 0) {
ui->stackedWidget_MapEvents->setCurrentIndex(0); ui->stackedWidget_MapEvents->setCurrentIndex(0);
on_mapViewTab_tabBarClicked(ui->mapViewTab->currentIndex()); on_mapViewTab_tabBarClicked(ui->mapViewTab->currentIndex());
clickToolButtonFromEditMode(editor->map_edit_mode); clickToolButtonFromEditAction(editor->mapEditAction);
} else if (index == 1) { } else if (index == 1) {
ui->stackedWidget_MapEvents->setCurrentIndex(1); ui->stackedWidget_MapEvents->setCurrentIndex(1);
editor->setEditingObjects(); editor->setEditingObjects();
clickToolButtonFromEditMode(editor->obj_edit_mode); clickToolButtonFromEditAction(editor->objectEditAction);
} else if (index == 3) { } else if (index == 3) {
editor->setEditingConnections(); editor->setEditingConnections();
} }
@ -2324,9 +2294,9 @@ void MainWindow::on_toolButton_deleteObject_clicked() {
void MainWindow::on_toolButton_Paint_clicked() void MainWindow::on_toolButton_Paint_clicked()
{ {
if (ui->mainTabBar->currentIndex() == 0) if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "paint"; editor->mapEditAction = Editor::EditAction::Paint;
else else
editor->obj_edit_mode = "paint"; editor->objectEditAction = Editor::EditAction::Paint;
editor->settings->mapCursor = QCursor(QPixmap(":/icons/pencil_cursor.ico"), 10, 10); editor->settings->mapCursor = QCursor(QPixmap(":/icons/pencil_cursor.ico"), 10, 10);
@ -2345,9 +2315,9 @@ void MainWindow::on_toolButton_Paint_clicked()
void MainWindow::on_toolButton_Select_clicked() void MainWindow::on_toolButton_Select_clicked()
{ {
if (ui->mainTabBar->currentIndex() == 0) if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "select"; editor->mapEditAction = Editor::EditAction::Select;
else else
editor->obj_edit_mode = "select"; editor->objectEditAction = Editor::EditAction::Select;
editor->settings->mapCursor = QCursor(); editor->settings->mapCursor = QCursor();
editor->cursorMapTileRect->setSingleTileMode(); editor->cursorMapTileRect->setSingleTileMode();
@ -2363,9 +2333,9 @@ void MainWindow::on_toolButton_Select_clicked()
void MainWindow::on_toolButton_Fill_clicked() void MainWindow::on_toolButton_Fill_clicked()
{ {
if (ui->mainTabBar->currentIndex() == 0) if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "fill"; editor->mapEditAction = Editor::EditAction::Fill;
else else
editor->obj_edit_mode = "fill"; editor->objectEditAction = Editor::EditAction::Fill;
editor->settings->mapCursor = QCursor(QPixmap(":/icons/fill_color_cursor.ico"), 10, 10); editor->settings->mapCursor = QCursor(QPixmap(":/icons/fill_color_cursor.ico"), 10, 10);
editor->cursorMapTileRect->setSingleTileMode(); editor->cursorMapTileRect->setSingleTileMode();
@ -2381,9 +2351,9 @@ void MainWindow::on_toolButton_Fill_clicked()
void MainWindow::on_toolButton_Dropper_clicked() void MainWindow::on_toolButton_Dropper_clicked()
{ {
if (ui->mainTabBar->currentIndex() == 0) if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "pick"; editor->mapEditAction = Editor::EditAction::Pick;
else else
editor->obj_edit_mode = "pick"; editor->objectEditAction = Editor::EditAction::Pick;
editor->settings->mapCursor = QCursor(QPixmap(":/icons/pipette_cursor.ico"), 10, 10); editor->settings->mapCursor = QCursor(QPixmap(":/icons/pipette_cursor.ico"), 10, 10);
editor->cursorMapTileRect->setSingleTileMode(); editor->cursorMapTileRect->setSingleTileMode();
@ -2399,9 +2369,9 @@ void MainWindow::on_toolButton_Dropper_clicked()
void MainWindow::on_toolButton_Move_clicked() void MainWindow::on_toolButton_Move_clicked()
{ {
if (ui->mainTabBar->currentIndex() == 0) if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "move"; editor->mapEditAction = Editor::EditAction::Move;
else else
editor->obj_edit_mode = "move"; editor->objectEditAction = Editor::EditAction::Move;
editor->settings->mapCursor = QCursor(QPixmap(":/icons/move.ico"), 7, 7); editor->settings->mapCursor = QCursor(QPixmap(":/icons/move.ico"), 7, 7);
editor->cursorMapTileRect->setSingleTileMode(); editor->cursorMapTileRect->setSingleTileMode();
@ -2417,9 +2387,9 @@ void MainWindow::on_toolButton_Move_clicked()
void MainWindow::on_toolButton_Shift_clicked() void MainWindow::on_toolButton_Shift_clicked()
{ {
if (ui->mainTabBar->currentIndex() == 0) if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "shift"; editor->mapEditAction = Editor::EditAction::Shift;
else else
editor->obj_edit_mode = "shift"; editor->objectEditAction = Editor::EditAction::Shift;
editor->settings->mapCursor = QCursor(QPixmap(":/icons/shift_cursor.ico"), 10, 10); editor->settings->mapCursor = QCursor(QPixmap(":/icons/shift_cursor.ico"), 10, 10);
editor->cursorMapTileRect->setSingleTileMode(); editor->cursorMapTileRect->setSingleTileMode();
@ -2433,37 +2403,37 @@ void MainWindow::on_toolButton_Shift_clicked()
} }
void MainWindow::checkToolButtons() { void MainWindow::checkToolButtons() {
QString edit_mode; Editor::EditAction editAction;
if (ui->mainTabBar->currentIndex() == 0) { if (ui->mainTabBar->currentIndex() == 0) {
edit_mode = editor->map_edit_mode; editAction = editor->mapEditAction;
} else { } else {
edit_mode = editor->obj_edit_mode; editAction = editor->objectEditAction;
if (edit_mode == "select" && editor->map_ruler) if (editAction == Editor::EditAction::Select && editor->map_ruler)
editor->map_ruler->setEnabled(true); editor->map_ruler->setEnabled(true);
else if (editor->map_ruler) else if (editor->map_ruler)
editor->map_ruler->setEnabled(false); editor->map_ruler->setEnabled(false);
} }
ui->toolButton_Paint->setChecked(edit_mode == "paint"); ui->toolButton_Paint->setChecked(editAction == Editor::EditAction::Paint);
ui->toolButton_Select->setChecked(edit_mode == "select"); ui->toolButton_Select->setChecked(editAction == Editor::EditAction::Select);
ui->toolButton_Fill->setChecked(edit_mode == "fill"); ui->toolButton_Fill->setChecked(editAction == Editor::EditAction::Fill);
ui->toolButton_Dropper->setChecked(edit_mode == "pick"); ui->toolButton_Dropper->setChecked(editAction == Editor::EditAction::Pick);
ui->toolButton_Move->setChecked(edit_mode == "move"); ui->toolButton_Move->setChecked(editAction == Editor::EditAction::Move);
ui->toolButton_Shift->setChecked(edit_mode == "shift"); ui->toolButton_Shift->setChecked(editAction == Editor::EditAction::Shift);
} }
void MainWindow::clickToolButtonFromEditMode(QString editMode) { void MainWindow::clickToolButtonFromEditAction(Editor::EditAction editAction) {
if (editMode == "paint") { if (editAction == Editor::EditAction::Paint) {
on_toolButton_Paint_clicked(); on_toolButton_Paint_clicked();
} else if (editMode == "select") { } else if (editAction == Editor::EditAction::Select) {
on_toolButton_Select_clicked(); on_toolButton_Select_clicked();
} else if (editMode == "fill") { } else if (editAction == Editor::EditAction::Fill) {
on_toolButton_Fill_clicked(); on_toolButton_Fill_clicked();
} else if (editMode == "pick") { } else if (editAction == Editor::EditAction::Pick) {
on_toolButton_Dropper_clicked(); on_toolButton_Dropper_clicked();
} else if (editMode == "move") { } else if (editAction == Editor::EditAction::Move) {
on_toolButton_Move_clicked(); on_toolButton_Move_clicked();
} else if (editMode == "shift") { } else if (editAction == Editor::EditAction::Shift) {
on_toolButton_Shift_clicked(); on_toolButton_Shift_clicked();
} }
} }