add move drag mode with changing cursor
This commit is contained in:
parent
6f3c5c25dd
commit
f5f763d32c
9 changed files with 167 additions and 15 deletions
|
@ -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();
|
||||
|
|
3
editor.h
3
editor.h
|
@ -7,6 +7,7 @@
|
|||
#include <QGraphicsItemAnimation>
|
||||
#include <QComboBox>
|
||||
#include <QCheckBox>
|
||||
#include <QCursor>
|
||||
|
||||
#include "project.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
@ -108,6 +109,8 @@ public:
|
|||
QList<int> *copiedMetatileSelection = new QList<int>;
|
||||
|
||||
QString map_edit_mode;
|
||||
QString prev_edit_mode;
|
||||
QCursor cursor;
|
||||
|
||||
void objectsView_onMousePress(QMouseEvent *event);
|
||||
void objectsView_onMouseMove(QMouseEvent *event);
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include <QScrollBar>
|
||||
#include <QMessageBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QScroller>
|
||||
#include <math.h>
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -245,6 +245,23 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_Move">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Move</p><p>Click to drag map around.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="resources/images.qrc">
|
||||
<normaloff>:/icons/move.ico</normaloff>:/icons/move.ico</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_smartPaths">
|
||||
<property name="toolTip">
|
||||
|
@ -334,8 +351,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>429</width>
|
||||
<height>620</height>
|
||||
<width>492</width>
|
||||
<height>599</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_8">
|
||||
|
@ -362,9 +379,18 @@
|
|||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustIgnored</enum>
|
||||
</property>
|
||||
<property name="dragMode">
|
||||
<enum>QGraphicsView::NoDrag</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
|
@ -708,7 +734,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>315</width>
|
||||
<width>222</width>
|
||||
<height>86</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -812,10 +838,10 @@
|
|||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<x>8</x>
|
||||
<y>0</y>
|
||||
<width>365</width>
|
||||
<height>405</height>
|
||||
<width>293</width>
|
||||
<height>368</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -1050,8 +1076,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>381</width>
|
||||
<height>657</height>
|
||||
<width>371</width>
|
||||
<height>643</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_7">
|
||||
|
@ -1216,8 +1242,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>584</height>
|
||||
<width>410</width>
|
||||
<height>560</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -1849,8 +1875,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>826</width>
|
||||
<height>557</height>
|
||||
<width>818</width>
|
||||
<height>539</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_14">
|
||||
|
@ -2022,7 +2048,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1117</width>
|
||||
<height>21</height>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
@ -2044,8 +2070,16 @@
|
|||
<addaction name="actionUndo"/>
|
||||
<addaction name="actionRedo"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuView">
|
||||
<property name="title">
|
||||
<string>View</string>
|
||||
</property>
|
||||
<addaction name="actionZoom_In"/>
|
||||
<addaction name="actionZoom_Out"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuEdit"/>
|
||||
<addaction name="menuView"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<action name="action_Save_Project">
|
||||
|
@ -2104,6 +2138,22 @@
|
|||
<string>Export Map Image...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionZoom_In">
|
||||
<property name="text">
|
||||
<string>Zoom In</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>+</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionZoom_Out">
|
||||
<property name="text">
|
||||
<string>Zoom Out</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>-</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
|
|
5
map.cpp
5
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() {
|
||||
|
|
3
map.h
3
map.h
|
@ -9,6 +9,7 @@
|
|||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <math.h>
|
||||
|
||||
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;
|
||||
|
||||
|
|
BIN
resources/icons/move.ico
Normal file
BIN
resources/icons/move.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -9,6 +9,7 @@
|
|||
<file>icons/map.ico</file>
|
||||
<file>icons/cursor.ico</file>
|
||||
<file>icons/fill_color.ico</file>
|
||||
<file>icons/move.ico</file>
|
||||
<file>icons/pencil.ico</file>
|
||||
<file>icons/pipette.ico</file>
|
||||
<file>images/Entities_16x16.png</file>
|
||||
|
|
Loading…
Reference in a new issue