From 47ce60cbe1a1d77be8067b7b9103113499be17a5 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Sun, 4 Mar 2018 16:07:52 -0800 Subject: [PATCH 1/2] Display grid lines on map editor --- editor.cpp | 14 ++++++++++++++ editor.h | 1 + 2 files changed, 15 insertions(+) diff --git a/editor.cpp b/editor.cpp index 6fb302ca..4311a316 100755 --- a/editor.cpp +++ b/editor.cpp @@ -156,6 +156,7 @@ void Editor::displayMap() { displayMapObjects(); displayMapConnections(); displayMapBorder(); + displayMapGrid(); } void Editor::displayMetatiles() { @@ -244,6 +245,19 @@ void Editor::displayMapBorder() { } } +void Editor::displayMapGrid() { + int pixelWidth = map->getWidth() * 16; + int pixelHeight = map->getHeight() * 16; + for (int i = 0; i <= map->getWidth(); i++) { + int x = i * 16; + QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight); + } + for (int j = 0; j <= map->getHeight(); j++) { + int y = j * 16; + QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y); + } +} + void MetatilesPixmapItem::paintTileChanged(Map *map) { draw(); } diff --git a/editor.h b/editor.h index 76e1d65a..f81a00c3 100755 --- a/editor.h +++ b/editor.h @@ -37,6 +37,7 @@ public: void displayMapObjects(); void displayMapConnections(); void displayMapBorder(); + void displayMapGrid(); void setEditingMap(); void setEditingCollision(); From eeaa347f17e4eaa88dde997aefe7f96a331dc9af Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Sun, 4 Mar 2018 16:20:18 -0800 Subject: [PATCH 2/2] Add checkbox to toggle grid lines --- editor.cpp | 5 ++ editor.h | 2 + mainwindow.cpp | 1 + mainwindow.h | 2 + mainwindow.ui | 210 ++++++++++++++++++++++++++----------------------- 5 files changed, 123 insertions(+), 97 deletions(-) diff --git a/editor.cpp b/editor.cpp index 4311a316..c9e0ccb5 100755 --- a/editor.cpp +++ b/editor.cpp @@ -1,4 +1,5 @@ #include "editor.h" +#include #include #include @@ -251,10 +252,14 @@ void Editor::displayMapGrid() { for (int i = 0; i <= map->getWidth(); i++) { int x = i * 16; QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight); + line->setVisible(gridToggleCheckbox->isChecked()); + connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);}); } for (int j = 0; j <= map->getHeight(); j++) { int y = j * 16; QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y); + line->setVisible(gridToggleCheckbox->isChecked()); + connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);}); } } diff --git a/editor.h b/editor.h index f81a00c3..b4792eee 100755 --- a/editor.h +++ b/editor.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "project.h" @@ -25,6 +26,7 @@ public: QObject *parent = NULL; Project *project = NULL; Map *map = NULL; + QCheckBox *gridToggleCheckbox = NULL; void saveProject(); void save(); void undo(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 79e1e13e..a630322b 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -27,6 +27,7 @@ MainWindow::MainWindow(QWidget *parent) : new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo())); editor = new Editor; + editor->gridToggleCheckbox = ui->checkBox_ToggleGrid; connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects())); connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects())); diff --git a/mainwindow.h b/mainwindow.h index 67d18aa9..a392b515 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -72,6 +72,8 @@ private slots: void onOpenMapListContextMenu(const QPoint &point); void onAddNewMapToGroupClick(QAction* triggeredAction); + void on_checkBox_ToggleGrid_toggled(bool checked); + private: Ui::MainWindow *ui; QStandardItemModel *mapListModel; diff --git a/mainwindow.ui b/mainwindow.ui index a3f7a857..8a493db5 100755 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -126,7 +126,7 @@ - + 0 0 @@ -143,98 +143,114 @@ QFrame::Raised - - - true + + + 4 - - - 0 - 0 - 31 - 31 - + + 4 - - Paint + + 4 - - - :/icons/pencil.ico:/icons/pencil.ico + + 4 - - true + + 4 - - true - - - false - - - - - true - - - - 30 - 0 - 31 - 31 - - - - Select - - - - :/icons/cursor.ico:/icons/cursor.ico - - - true - - - - - - 60 - 0 - 31 - 31 - - - - Fill - - - - :/icons/fill_color.ico:/icons/fill_color.ico - - - true - - - - - - 90 - 0 - 31 - 31 - - - - Dropper - - - - :/icons/pipette.ico:/icons/pipette.ico - - - true - - + + + + true + + + Paint + + + + :/icons/pencil.ico:/icons/pencil.ico + + + true + + + true + + + false + + + + + + + true + + + Select + + + + :/icons/cursor.ico:/icons/cursor.ico + + + true + + + + + + + Fill + + + + :/icons/fill_color.ico:/icons/fill_color.ico + + + true + + + + + + + Dropper + + + + :/icons/pipette.ico:/icons/pipette.ico + + + true + + + + + + + margin-left: 10px + + + Show Grid + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -274,8 +290,8 @@ 0 0 - 617 - 602 + 614 + 621 @@ -462,8 +478,8 @@ 0 0 - 186 - 609 + 180 + 629 @@ -675,8 +691,8 @@ 0 0 - 385 - 638 + 381 + 657 @@ -841,8 +857,8 @@ 0 0 - 416 - 557 + 420 + 584 @@ -1194,7 +1210,7 @@ 0 0 1117 - 20 + 21