diff --git a/editor.cpp b/editor.cpp index 962907d9..a3652d10 100755 --- a/editor.cpp +++ b/editor.cpp @@ -1484,9 +1484,11 @@ void MapPixmapItem::updateCurHoveredTile(QPointF pos) { void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { updateCurHoveredTile(event->pos()); + setCursor(editor->cursor); } void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { map->clearHoveredTile(); + unsetCursor(); } void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { QPointF pos = event->pos(); diff --git a/editor.h b/editor.h index 863b096f..0bc22ddb 100755 --- a/editor.h +++ b/editor.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "project.h" #include "ui_mainwindow.h" @@ -108,6 +109,8 @@ public: QList *copiedMetatileSelection = new QList; QString map_edit_mode; + QString prev_edit_mode; + QCursor cursor; void objectsView_onMousePress(QMouseEvent *event); void objectsView_onMouseMove(QMouseEvent *event); diff --git a/mainwindow.cpp b/mainwindow.cpp index b9979dc3..e47eb792 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -31,6 +33,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString))); new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo())); + new QShortcut(Qt::Key_M, this, SLOT(toggleEditModeMove())); editor = new Editor(ui); connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects())); @@ -589,6 +592,31 @@ void MainWindow::on_actionRedo_triggered() redo(); } +void MainWindow::on_actionZoom_In_triggered() { + scaleMapView(1); +} + +void MainWindow::on_actionZoom_Out_triggered() { + scaleMapView(-1); +} + +void MainWindow::scaleMapView(int s) { + editor->map->scale_exp += s; + + double base = (double)editor->map->scale_base; + double exp = editor->map->scale_exp; + double sfactor = pow(base,s); + + ui->graphicsView_Map->scale(sfactor,sfactor); + ui->graphicsView_Objects_Map->scale(sfactor,sfactor); + + ui->graphicsView_Map->setFixedSize((editor->scene->width() + 2) * pow(base,exp), + (editor->scene->height() + 2) * pow(base,exp)); + + ui->graphicsView_Objects_Map->setFixedSize((editor->scene->width() + 2) * pow(base,exp), + (editor->scene->height() + 2) * pow(base,exp)); +} + void MainWindow::addNewEvent(QString event_type) { if (editor) { @@ -876,24 +904,60 @@ void MainWindow::on_toolButton_deleteObject_clicked() void MainWindow::on_toolButton_Paint_clicked() { editor->map_edit_mode = "paint"; + editor->cursor = QCursor(QPixmap(":/icons/pencil.ico"), 0, 14); + + ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + QScroller::ungrabGesture(ui->scrollArea); + checkToolButtons(); } void MainWindow::on_toolButton_Select_clicked() { editor->map_edit_mode = "select"; + editor->cursor = QCursor(QPixmap(":/icons/cursor.ico"), 0, 0); + + ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + QScroller::ungrabGesture(ui->scrollArea); + checkToolButtons(); } void MainWindow::on_toolButton_Fill_clicked() { editor->map_edit_mode = "fill"; + editor->cursor = QCursor(QPixmap(":/icons/fill_color.ico"), 12, 10); + + ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + QScroller::ungrabGesture(ui->scrollArea); + checkToolButtons(); } void MainWindow::on_toolButton_Dropper_clicked() { editor->map_edit_mode = "pick"; + editor->cursor = QCursor(QPixmap(":/icons/pipette.ico"), 1, 14); + + ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + QScroller::ungrabGesture(ui->scrollArea); + + checkToolButtons(); +} + +void MainWindow::on_toolButton_Move_clicked() +{ + editor->map_edit_mode = "move"; + editor->cursor = QCursor(QPixmap(":/icons/move.ico"), 7, 7); + + ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture); + checkToolButtons(); } @@ -902,6 +966,25 @@ void MainWindow::checkToolButtons() { ui->toolButton_Select->setChecked(editor->map_edit_mode == "select"); ui->toolButton_Fill->setChecked(editor->map_edit_mode == "fill"); ui->toolButton_Dropper->setChecked(editor->map_edit_mode == "pick"); + ui->toolButton_Move->setChecked(editor->map_edit_mode == "move"); +} + +void MainWindow::toggleEditModeMove() { + if (editor->map_edit_mode == "move") { + if (editor->prev_edit_mode == "paint") { + on_toolButton_Paint_clicked(); + } else if (editor->prev_edit_mode == "fill") { + on_toolButton_Fill_clicked(); + } else if (editor->prev_edit_mode == "pick") { + on_toolButton_Dropper_clicked(); + } else if (editor->prev_edit_mode == "select") { + on_toolButton_Select_clicked(); + } + } + else { + editor->prev_edit_mode = editor->map_edit_mode; + on_toolButton_Move_clicked(); + } } void MainWindow::onLoadMapRequested(QString mapName, QString fromMapName) { diff --git a/mainwindow.h b/mainwindow.h index b8a12f8b..d6509a50 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -37,6 +37,8 @@ private slots: void undo(); void redo(); + void toggleEditModeMove(); + void onLoadMapRequested(QString, QString); void onMapChanged(Map *map); void onMapNeedsRedrawing(Map *map); @@ -58,6 +60,9 @@ private slots: void on_actionRedo_triggered(); + void on_actionZoom_In_triggered(); + void on_actionZoom_Out_triggered(); + void on_toolButton_deleteObject_clicked(); void addNewEvent(QString); @@ -71,6 +76,8 @@ private slots: void on_toolButton_Dropper_clicked(); + void on_toolButton_Move_clicked(); + void onOpenMapListContextMenu(const QPoint &point); void onAddNewMapToGroupClick(QAction* triggeredAction); void onTilesetChanged(QString); @@ -124,6 +131,8 @@ private: void displayMapProperties(); void checkToolButtons(); + + void scaleMapView(int); }; enum MapListUserRoles { diff --git a/mainwindow.ui b/mainwindow.ui index f3f19222..ad6b7925 100755 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -245,6 +245,23 @@ + + + + <html><head/><body><p>Move</p><p>Click to drag map around.</p></body></html> + + + ... + + + + :/icons/move.ico:/icons/move.ico + + + true + + + @@ -334,8 +351,8 @@ 0 0 - 429 - 620 + 492 + 599 @@ -362,9 +379,18 @@ 0 + + false + false + + QAbstractScrollArea::AdjustIgnored + + + QGraphicsView::NoDrag + @@ -708,7 +734,7 @@ 0 0 - 315 + 222 86 @@ -812,10 +838,10 @@ - 0 + 8 0 - 365 - 405 + 293 + 368 @@ -1050,8 +1076,8 @@ 0 0 - 381 - 657 + 371 + 643 @@ -1216,8 +1242,8 @@ 0 0 - 420 - 584 + 410 + 560 @@ -1849,8 +1875,8 @@ 0 0 - 826 - 557 + 818 + 539 @@ -2022,7 +2048,7 @@ 0 0 1117 - 21 + 22 @@ -2044,8 +2070,16 @@ + + + View + + + + + @@ -2104,6 +2138,22 @@ Export Map Image... + + + Zoom In + + + + + + + + + Zoom Out + + + - + + diff --git a/map.cpp b/map.cpp index f114884f..626724f2 100755 --- a/map.cpp +++ b/map.cpp @@ -608,10 +608,11 @@ bool Map::hasUnsavedChanges() { } void Map::hoveredTileChanged(int x, int y, int block) { - emit statusBarMessage(QString("X: %1, Y: %2, Metatile: 0x%3") + emit statusBarMessage(QString("X: %1, Y: %2, Metatile: 0x%3, Scale = %4x") .arg(x) .arg(y) - .arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper())); + .arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()) + .arg(QString::number(pow(this->scale_base,this->scale_exp)))); } void Map::clearHoveredTile() { diff --git a/map.h b/map.h index 82e70675..550e6a9b 100755 --- a/map.h +++ b/map.h @@ -9,6 +9,7 @@ #include #include #include +#include class HistoryItem { public: @@ -134,6 +135,8 @@ public: QString show_location; QString battle_scene; MapLayout *layout; + int scale_exp = 0; + double scale_base = sqrt(2); // adjust scale factor with this bool isPersistedToFile = true; diff --git a/resources/icons/move.ico b/resources/icons/move.ico new file mode 100644 index 00000000..1d247401 Binary files /dev/null and b/resources/icons/move.ico differ diff --git a/resources/images.qrc b/resources/images.qrc index dfca147d..59c14728 100755 --- a/resources/images.qrc +++ b/resources/images.qrc @@ -9,6 +9,7 @@ icons/map.ico icons/cursor.ico icons/fill_color.ico + icons/move.ico icons/pencil.ico icons/pipette.ico images/Entities_16x16.png