mirror of
https://github.com/huderlem/porymap.git
synced 2026-07-02 00:02:04 -05:00
Fix drag mode cursor icon not updating properly
This commit is contained in:
parent
440c0f9d5c
commit
1ab07cf3c7
|
|
@ -10,7 +10,6 @@ public:
|
|||
Settings();
|
||||
bool smartPathsEnabled;
|
||||
bool betterCursors;
|
||||
QCursor mapCursor;
|
||||
bool playerViewRectEnabled;
|
||||
bool cursorTileRectEnabled;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -86,9 +86,6 @@ public:
|
|||
void lockNondominantAxis(QGraphicsSceneMouseEvent *event);
|
||||
QPoint adjustCoords(QPoint pos);
|
||||
|
||||
void setEditsEnabled(bool enabled) { this->editsEnabled = enabled; }
|
||||
bool getEditsEnabled() { return this->editsEnabled; }
|
||||
|
||||
private:
|
||||
void paintSmartPath(int x, int y, bool fromScriptCall = false);
|
||||
static QList<int> smartPathTable;
|
||||
|
|
@ -96,8 +93,6 @@ private:
|
|||
|
||||
unsigned actionId_ = 0;
|
||||
|
||||
bool editsEnabled = true;
|
||||
|
||||
signals:
|
||||
void startPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *);
|
||||
void endPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *);
|
||||
|
|
|
|||
|
|
@ -155,7 +155,6 @@ void Editor::setEditMode(EditMode editMode) {
|
|||
break;
|
||||
}
|
||||
|
||||
map_item->setEditsEnabled(this->editMode != EditMode::Connections);
|
||||
map_item->draw();
|
||||
collision_item->draw();
|
||||
|
||||
|
|
@ -207,16 +206,35 @@ void Editor::setEditAction(EditAction editAction) {
|
|||
// The tile cursor can only grow while painting metatiles
|
||||
this->cursorMapTileRect->setSingleTileMode(!(editAction == EditAction::Paint && this->editMode == EditMode::Metatiles));
|
||||
|
||||
auto dragMode = (editAction == EditAction::Move) ? QGraphicsView::ScrollHandDrag : QGraphicsView::NoDrag;
|
||||
ui->graphicsView_Map->setDragMode(dragMode);
|
||||
ui->graphicsView_Connections->setDragMode(dragMode);
|
||||
|
||||
// Update cursor
|
||||
static const QMap<EditAction, QCursor> cursors = {
|
||||
{EditAction::Paint, QCursor(QPixmap(":/icons/pencil_cursor.ico"), 10, 10)},
|
||||
{EditAction::Select, QCursor(Qt::ArrowCursor)},
|
||||
{EditAction::Fill, QCursor(QPixmap(":/icons/fill_color_cursor.ico"), 10, 10)},
|
||||
{EditAction::Pick, QCursor(QPixmap(":/icons/pipette_cursor.ico"), 10, 10)},
|
||||
{EditAction::Move, QCursor(Qt::OpenHandCursor)},
|
||||
{EditAction::Shift, QCursor(QPixmap(":/icons/shift_cursor.ico"), 10, 10)},
|
||||
};
|
||||
this->settings->mapCursor = cursors.value(editAction);
|
||||
if (this->settings->betterCursors) {
|
||||
static const QMap<EditAction, QCursor> cursors = {
|
||||
{EditAction::Paint, QCursor(QPixmap(":/icons/pencil_cursor.ico"), 10, 10)},
|
||||
{EditAction::Fill, QCursor(QPixmap(":/icons/fill_color_cursor.ico"), 10, 10)},
|
||||
{EditAction::Pick, QCursor(QPixmap(":/icons/pipette_cursor.ico"), 10, 10)},
|
||||
{EditAction::Shift, QCursor(QPixmap(":/icons/shift_cursor.ico"), 10, 10)},
|
||||
};
|
||||
|
||||
// Paint tools don't apply on the Connections tab, so don't show the cursor.
|
||||
// We specifically unset the cursor for Move rather than explicitly set Qt::OpenHandCursor
|
||||
// because otherwise the cursor may persist outside the map after the tool changes.
|
||||
if (this->editMode == EditMode::Connections || editAction == EditAction::Move) {
|
||||
if (this->map_item)
|
||||
this->map_item->unsetCursor();
|
||||
if (this->collision_item)
|
||||
this->collision_item->unsetCursor();
|
||||
} else {
|
||||
auto cursor = cursors.value(editAction);
|
||||
if (this->map_item)
|
||||
this->map_item->setCursor(cursor);
|
||||
if (this->collision_item)
|
||||
this->collision_item->setCursor(cursor);
|
||||
}
|
||||
}
|
||||
emit editActionSet(editAction);
|
||||
}
|
||||
|
||||
|
|
@ -1396,14 +1414,14 @@ void Editor::adjustStraightPathPos(QGraphicsSceneMouseEvent *event, LayoutPixmap
|
|||
|
||||
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item) {
|
||||
auto editAction = getEditAction();
|
||||
if (!item->getEditsEnabled() || editAction == EditAction::Move) {
|
||||
if (editAction == EditAction::Move) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
|
||||
if (this->getEditingLayout()) {
|
||||
if (this->editMode == EditMode::Metatiles) {
|
||||
if (editAction == EditAction::Paint) {
|
||||
if (event->buttons() & Qt::RightButton) {
|
||||
item->updateMetatileSelection(event);
|
||||
|
|
@ -1487,7 +1505,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i
|
|||
|
||||
void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item) {
|
||||
auto editAction = getEditAction();
|
||||
if (!item->getEditsEnabled() || editAction == EditAction::Move) {
|
||||
if (this->editMode != EditMode::Collision || editAction == EditAction::Move) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2579,12 +2579,6 @@ void MainWindow::on_toolButton_Move_clicked() { editor->setEditAction(Editor:
|
|||
void MainWindow::on_toolButton_Shift_clicked() { editor->setEditAction(Editor::EditAction::Shift); }
|
||||
|
||||
void MainWindow::setEditActionUi(Editor::EditAction editAction) {
|
||||
// TODO: Viewport's hand cursor is not reliably cleared when changing to QGraphicsView::NoDrag.
|
||||
auto dragMode = (editAction == Editor::EditAction::Move) ? QGraphicsView::ScrollHandDrag : QGraphicsView::NoDrag;
|
||||
ui->graphicsView_Connections->setDragMode(dragMode);
|
||||
ui->graphicsView_Map->setDragMode(dragMode);
|
||||
ui->graphicsView_Map->setFocus();
|
||||
|
||||
ui->toolButton_Paint->setChecked(editAction == Editor::EditAction::Paint);
|
||||
ui->toolButton_Select->setChecked(editAction == Editor::EditAction::Select);
|
||||
ui->toolButton_Fill->setChecked(editAction == Editor::EditAction::Fill);
|
||||
|
|
|
|||
|
|
@ -8,9 +8,6 @@ void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
|||
this->previousPos = pos;
|
||||
emit this->hoverChanged(pos);
|
||||
}
|
||||
if (this->settings->betterCursors && this->getEditsEnabled()) {
|
||||
setCursor(this->settings->mapCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void CollisionPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
|
||||
|
|
@ -20,9 +17,6 @@ void CollisionPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
|
|||
}
|
||||
|
||||
void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||
if (this->settings->betterCursors && this->getEditsEnabled()){
|
||||
unsetCursor();
|
||||
}
|
||||
this->has_mouse = false;
|
||||
emit this->hoverCleared();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -697,21 +697,15 @@ void LayoutPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
|||
this->metatilePos = pos;
|
||||
emit this->hoverChanged(pos);
|
||||
}
|
||||
if (this->settings->betterCursors && this->editsEnabled) {
|
||||
setCursor(this->settings->mapCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
|
||||
void LayoutPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
|
||||
this->has_mouse = true;
|
||||
this->metatilePos = Metatile::coordFromPixmapCoord(event->pos());
|
||||
emit this->hoverEntered(this->metatilePos);
|
||||
}
|
||||
|
||||
void LayoutPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||
if (this->settings->betterCursors && this->editsEnabled) {
|
||||
unsetCursor();
|
||||
}
|
||||
this->has_mouse = false;
|
||||
emit this->hoverCleared();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user