From 2fd3df9734424fdd9c2052668bfbe5990e9aaa86 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 25 Aug 2020 16:32:40 -0400 Subject: [PATCH] Remove straight paths checkbox and refactor --- forms/mainwindow.ui | 16 ---------------- include/mainwindow.h | 3 --- include/settings.h | 1 - include/ui/cursortilerect.h | 6 ++---- src/editor.cpp | 5 +++-- src/mainwindow.cpp | 10 ++-------- src/mainwindow_scriptapi.cpp | 8 -------- src/settings.cpp | 1 - src/ui/cursortilerect.cpp | 19 ++++--------------- src/ui/mappixmapitem.cpp | 16 ++++++++-------- 10 files changed, 19 insertions(+), 66 deletions(-) diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 02354853..0bc68401 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -626,22 +626,6 @@ - - - - Qt::LeftToRight - - - - - - Straight Paths - - - false - - - diff --git a/include/mainwindow.h b/include/mainwindow.h index 611abc3a..f6b382c2 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -100,8 +100,6 @@ public: Q_INVOKABLE bool getBorderVisibility(); Q_INVOKABLE void setSmartPathsEnabled(bool visible); Q_INVOKABLE bool getSmartPathsEnabled(); - Q_INVOKABLE void setStraightPathsEnabled(bool visible); - Q_INVOKABLE bool getStraightPathsEnabled(); Q_INVOKABLE void registerAction(QString functionName, QString actionName, QString shortcut = ""); Q_INVOKABLE void setTimeout(QJSValue callback, int milliseconds); void invokeCallback(QJSValue callback); @@ -203,7 +201,6 @@ private slots: void on_comboBox_SecondaryTileset_currentTextChanged(const QString &arg1); void on_pushButton_ChangeDimensions_clicked(); void on_checkBox_smartPaths_stateChanged(int selected); - void on_checkBox_straightPaths_stateChanged(int selected); void on_checkBox_Visibility_clicked(bool checked); void on_checkBox_ToggleBorder_stateChanged(int arg1); diff --git a/include/settings.h b/include/settings.h index 76074fe3..5b989ed5 100644 --- a/include/settings.h +++ b/include/settings.h @@ -8,7 +8,6 @@ class Settings public: Settings(); bool smartPathsEnabled; - bool straightPathsEnabled; bool betterCursors; QCursor mapCursor; bool playerViewRectEnabled; diff --git a/include/ui/cursortilerect.h b/include/ui/cursortilerect.h index d25f17c3..5d0c5f15 100644 --- a/include/ui/cursortilerect.h +++ b/include/ui/cursortilerect.h @@ -50,13 +50,12 @@ public: void stopAnchor(); void initRightClickSelectionAnchor(int coordX, int coordY); void stopRightClickSelectionAnchor(); - void setSmartPathMode(); + void setSmartPathMode(bool enable); bool getSmartPathMode() { return this->smartPathMode; } - void setStraightPathMode(); + void setStraightPathMode(bool enable); bool getStraightPathMode() { return this->straightPathMode; } void setSingleTileMode(); void stopSingleTileMode(); - void setNormalPathMode(); void updateLocation(int x, int y); void updateSelectionSize(int width, int height); void setVisibility(bool visible); @@ -76,7 +75,6 @@ private: int selectionHeight; QRgb color; bool smartPathInEffect(); - bool straightPathInEffect(); }; diff --git a/src/editor.cpp b/src/editor.cpp index 3bff37b7..95991c40 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1009,7 +1009,8 @@ void Editor::onMapEndPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *item) { this->cursorMapTileRect->stopAnchor(); } -void Editor::setSmartPathCursorMode(QGraphicsSceneMouseEvent *event) { +void Editor::setSmartPathCursorMode(QGraphicsSceneMouseEvent *event) +{ bool shiftPressed = event->modifiers() & Qt::ShiftModifier; if (settings->smartPathsEnabled) { if (!shiftPressed) { @@ -1055,13 +1056,13 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item item->floodFill(event); } } else { + this->setSmartPathCursorMode(event); this->setStraightPathCursorMode(event); if (this->cursorMapTileRect->getStraightPathMode()) { item->lockNondominantAxis(event); x = item->adjustCoord(x, MapPixmapItem::Axis::X); y = item->adjustCoord(y, MapPixmapItem::Axis::Y); } - this->setSmartPathCursorMode(event); item->paint(event); } } else if (map_edit_mode == "select") { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b4ed24b1..930f7988 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2492,18 +2492,12 @@ void MainWindow::on_checkBox_smartPaths_stateChanged(int selected) bool enabled = selected == Qt::Checked; editor->settings->smartPathsEnabled = enabled; if (enabled) { - editor->cursorMapTileRect->setSmartPathMode(); + editor->cursorMapTileRect->setSmartPathMode(true); } else { - editor->cursorMapTileRect->setNormalPathMode(); + editor->cursorMapTileRect->setSmartPathMode(false); } } -void MainWindow::on_checkBox_straightPaths_stateChanged(int selected) -{ - bool enabled = selected == Qt::Checked; - editor->settings->straightPathsEnabled = enabled; -} - void MainWindow::on_checkBox_ToggleBorder_stateChanged(int selected) { bool visible = selected != 0; diff --git a/src/mainwindow_scriptapi.cpp b/src/mainwindow_scriptapi.cpp index 1e825285..cc89fc0b 100644 --- a/src/mainwindow_scriptapi.cpp +++ b/src/mainwindow_scriptapi.cpp @@ -476,14 +476,6 @@ bool MainWindow::getSmartPathsEnabled() { return this->ui->checkBox_smartPaths->isChecked(); } -void MainWindow::setStraightPathsEnabled(bool visible) { - this->ui->checkBox_straightPaths->setChecked(visible); -} - -bool MainWindow::getStraightPathsEnabled() { - return this->ui->checkBox_straightPaths->isChecked(); -} - void MainWindow::registerAction(QString functionName, QString actionName, QString shortcut) { if (!this->ui || !this->ui->menuTools) return; diff --git a/src/settings.cpp b/src/settings.cpp index dec44f06..7da1fcbc 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -3,7 +3,6 @@ Settings::Settings() { this->smartPathsEnabled = false; - this->straightPathsEnabled = false; this->betterCursors = true; this->playerViewRectEnabled = false; this->cursorTileRectEnabled = true; diff --git a/src/ui/cursortilerect.cpp b/src/ui/cursortilerect.cpp index 0f51f41c..e53ef7d2 100644 --- a/src/ui/cursortilerect.cpp +++ b/src/ui/cursortilerect.cpp @@ -58,14 +58,14 @@ void CursorTileRect::updateSelectionSize(int width, int height) this->update(); } -void CursorTileRect::setSmartPathMode() +void CursorTileRect::setSmartPathMode(bool enable) { - this->smartPathMode = true; + this->smartPathMode = enable; } -void CursorTileRect::setStraightPathMode() +void CursorTileRect::setStraightPathMode(bool enable) { - this->straightPathMode = true; + this->straightPathMode = enable; } void CursorTileRect::setSingleTileMode() @@ -78,22 +78,11 @@ void CursorTileRect::stopSingleTileMode() this->singleTileMode = false; } -void CursorTileRect::setNormalPathMode() -{ - this->smartPathMode = false; - this->straightPathMode = false; -} - bool CursorTileRect::smartPathInEffect() { return !this->rightClickSelectionAnchored && this->smartPathMode && this->selectionHeight == 3 && this->selectionWidth == 3; } -bool CursorTileRect::straightPathInEffect() -{ - return !this->rightClickSelectionAnchored && this->straightPathMode; -} - void CursorTileRect::updateLocation(int coordX, int coordY) { if (!this->singleTileMode) { diff --git a/src/ui/mappixmapitem.cpp b/src/ui/mappixmapitem.cpp index b45cddac..67db49b7 100644 --- a/src/ui/mappixmapitem.cpp +++ b/src/ui/mappixmapitem.cpp @@ -15,8 +15,7 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) { int y = static_cast(pos.y()) / 16; // Set straight paths on/off and snap to the dominant axis when on - bool straightPathsEnabled = event->modifiers() & Qt::ControlModifier; - if (this->settings->straightPathsEnabled || straightPathsEnabled) { + if (event->modifiers() & Qt::ControlModifier) { this->lockNondominantAxis(event); x = this->adjustCoord(x, MapPixmapItem::Axis::X); y = this->adjustCoord(y, MapPixmapItem::Axis::Y); @@ -55,8 +54,7 @@ void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) { int y = static_cast(pos.y()) / 16; // Set straight paths on/off and snap to the dominant axis when on - bool straightPathsEnabled = event->modifiers() & Qt::ControlModifier; - if (this->settings->straightPathsEnabled || straightPathsEnabled) { + if (event->modifiers() & Qt::ControlModifier) { this->lockNondominantAxis(event); x = this->adjustCoord(x, MapPixmapItem::Axis::X); y = this->adjustCoord(y, MapPixmapItem::Axis::Y); @@ -302,19 +300,21 @@ void MapPixmapItem::lockNondominantAxis(QGraphicsSceneMouseEvent *event) { int xDiff = x - this->straight_path_initial_x; int yDiff = y - this->straight_path_initial_y; if ((xDiff || yDiff) && event->type() != QEvent::GraphicsSceneMouseRelease) { - if (abs(xDiff) < abs(yDiff)) + if (abs(xDiff) < abs(yDiff)) { this->lockedAxis = MapPixmapItem::Axis::X; - else + } else { this->lockedAxis = MapPixmapItem::Axis::Y; + } } } // Adjust the cooresponding coordinate when it is locked int MapPixmapItem::adjustCoord(int coord, MapPixmapItem::Axis axis) { - if (axis == MapPixmapItem::Axis::X && this->lockedAxis == MapPixmapItem::Axis::X) + if (axis == MapPixmapItem::Axis::X && this->lockedAxis == MapPixmapItem::Axis::X) { coord = this->straight_path_initial_x; - else if (axis == MapPixmapItem::Axis::Y && this->lockedAxis == MapPixmapItem::Axis::Y) + } else if (axis == MapPixmapItem::Axis::Y && this->lockedAxis == MapPixmapItem::Axis::Y) { coord = this->straight_path_initial_y; + } return coord; }