From 140b66862a2c18380834cf5e78ca68c25a790800 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 26 Jan 2024 10:54:05 -0500 Subject: [PATCH 1/7] Remove some unnecessary redrawing --- src/ui/tileseteditor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 2b097083..75590927 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -333,9 +333,11 @@ void TilesetEditor::refresh() { } } + this->ui->graphicsView_Tiles->setSceneRect(0, 0, this->tileSelector->pixmap().width(), this->tileSelector->pixmap().height()); + this->ui->graphicsView_Metatiles->setSceneRect(0, 0, this->metatileSelector->pixmap().width(), this->metatileSelector->pixmap().height()); + this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); this->redrawTileSelector(); this->redrawMetatileSelector(); - this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); } void TilesetEditor::drawSelectedTiles() { @@ -1191,7 +1193,6 @@ void TilesetEditor::on_horizontalSlider_MetatilesZoom_valueChanged(int value) { void TilesetEditor::redrawMetatileSelector() { QSize size(this->metatileSelector->pixmap().width(), this->metatileSelector->pixmap().height()); - this->ui->graphicsView_Metatiles->setSceneRect(0, 0, size.width() + 2, size.height() + 2); double scale = pow(3.0, static_cast(porymapConfig.getTilesetEditorMetatilesZoom() - 30) / 30.0); QTransform transform; @@ -1213,7 +1214,6 @@ void TilesetEditor::on_horizontalSlider_TilesZoom_valueChanged(int value) { void TilesetEditor::redrawTileSelector() { QSize size(this->tileSelector->pixmap().width(), this->tileSelector->pixmap().height()); - this->ui->graphicsView_Tiles->setSceneRect(0, 0, size.width() + 2, size.height() + 2); double scale = pow(3.0, static_cast(porymapConfig.getTilesetEditorTilesZoom() - 30) / 30.0); QTransform transform; From 4cb7e8a9aaa9cb8c8331153db92283551a013ecc Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 26 Jan 2024 11:40:32 -0500 Subject: [PATCH 2/7] Fix selectors jumping when zooming --- forms/mainwindow.ui | 10 +++--- forms/tileseteditor.ui | 78 +++++++--------------------------------- src/mainwindow.cpp | 15 +++++--- src/ui/tileseteditor.cpp | 4 +++ 4 files changed, 32 insertions(+), 75 deletions(-) diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index d70180d4..45316d33 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -764,7 +764,7 @@ true - + 0 @@ -883,7 +883,7 @@ true - + 0 @@ -984,7 +984,7 @@ Qt::AlignHCenter|Qt::AlignTop - + true @@ -1184,11 +1184,11 @@ - + true - + 0 diff --git a/forms/tileseteditor.ui b/forms/tileseteditor.ui index 34e13d55..0e70da25 100644 --- a/forms/tileseteditor.ui +++ b/forms/tileseteditor.ui @@ -58,9 +58,9 @@ true - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignHCenter|Qt::AlignTop - + 0 @@ -85,20 +85,7 @@ 6 - - - - Qt::Vertical - - - - 20 - 40 - - - - - + Qt::ScrollBarAlwaysOff @@ -108,28 +95,15 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + + - Qt::Horizontal + Qt::Vertical - 40 - 20 + 20 + 40 @@ -561,9 +535,9 @@ true - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignHCenter|Qt::AlignTop - + 0 @@ -585,20 +559,7 @@ 0 - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + Qt::ScrollBarAlwaysOff @@ -608,8 +569,8 @@ - - + + Qt::Vertical @@ -621,19 +582,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 58ba3f13..109233f3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -734,10 +734,10 @@ void MainWindow::refreshMapScene() ui->graphicsView_Metatiles->setFixedSize(editor->metatile_selector_item->pixmap().width() + 2, editor->metatile_selector_item->pixmap().height() + 2); ui->graphicsView_BorderMetatile->setScene(editor->scene_selected_border_metatiles); - ui->graphicsView_BorderMetatile->setFixedSize(editor->selected_border_metatiles_item->pixmap().width() + 2, editor->selected_border_metatiles_item->pixmap().height() + 2); + ui->graphicsView_BorderMetatile->setFixedSize(editor->selected_border_metatiles_item->pixmap().width(), editor->selected_border_metatiles_item->pixmap().height()); ui->graphicsView_currentMetatileSelection->setScene(editor->scene_current_metatile_selection); - ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width() + 2, editor->current_metatile_selection_item->pixmap().height() + 2); + ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width(), editor->current_metatile_selection_item->pixmap().height()); ui->graphicsView_Collision->setScene(editor->scene_collision_metatiles); //ui->graphicsView_Collision->setSceneRect(editor->scene_collision_metatiles->sceneRect()); @@ -1373,7 +1373,8 @@ void MainWindow::redrawMetatileSelection() transform.scale(scale, scale); ui->graphicsView_currentMetatileSelection->setTransform(transform); - ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width() * scale + 2, editor->current_metatile_selection_item->pixmap().height() * scale + 2); + ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width() * scale, editor->current_metatile_selection_item->pixmap().height() * scale); + ui->scrollAreaWidgetContents_SelectedMetatiles->adjustSize(); QPoint size = editor->metatile_selector_item->getSelectionDimensions(); if (size.x() == 1 && size.y() == 1) { @@ -2828,8 +2829,11 @@ void MainWindow::on_horizontalSlider_MetatileZoom_valueChanged(int value) { ui->graphicsView_Metatiles->setFixedSize(size.width() + 2, size.height() + 2); ui->graphicsView_BorderMetatile->setTransform(transform); - ui->graphicsView_BorderMetatile->setFixedSize(ceil(static_cast(editor->selected_border_metatiles_item->pixmap().width()) * scale) + 2, - ceil(static_cast(editor->selected_border_metatiles_item->pixmap().height()) * scale) + 2); + ui->graphicsView_BorderMetatile->setFixedSize(ceil(static_cast(editor->selected_border_metatiles_item->pixmap().width()) * scale), + ceil(static_cast(editor->selected_border_metatiles_item->pixmap().height()) * scale)); + + ui->scrollAreaWidgetContents_MetatileSelector->adjustSize(); + ui->scrollAreaWidgetContents_BorderMetatiles->adjustSize(); redrawMetatileSelection(); } @@ -2847,6 +2851,7 @@ void MainWindow::on_horizontalSlider_CollisionZoom_valueChanged(int value) { ui->graphicsView_Collision->setResizeAnchor(QGraphicsView::NoAnchor); ui->graphicsView_Collision->setTransform(transform); ui->graphicsView_Collision->setFixedSize(size.width() + 2, size.height() + 2); + ui->scrollAreaWidgetContents_Collision->adjustSize(); } void MainWindow::on_spinBox_SelectedCollision_valueChanged(int collision) { diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 75590927..5e089635 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -1204,6 +1204,8 @@ void TilesetEditor::redrawMetatileSelector() { QPoint pos = this->metatileSelector->getMetatileIdCoordsOnWidget(this->getSelectedMetatileId()); pos *= scale; + + this->ui->scrollAreaWidgetContents_Metatiles->adjustSize(); this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale); } @@ -1223,6 +1225,8 @@ void TilesetEditor::redrawTileSelector() { this->ui->graphicsView_Tiles->setTransform(transform); this->ui->graphicsView_Tiles->setFixedSize(size.width() + 2, size.height() + 2); + this->ui->scrollAreaWidgetContents_Tiles->adjustSize(); + auto tiles = this->tileSelector->getSelectedTiles(); if (!tiles.isEmpty()) { QPoint pos = this->tileSelector->getTileCoordsOnWidget(tiles[0].tileId); From 895c9466d75dd48abb4710720570dd9060b88c1e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 26 Jan 2024 15:29:48 -0500 Subject: [PATCH 3/7] Center selection when zooming --- include/mainwindow.h | 2 ++ include/ui/metatileselector.h | 3 ++- src/mainwindow.cpp | 39 +++++++++++++++++++++++++---------- src/ui/metatileselector.cpp | 13 ++++++------ src/ui/tileseteditor.cpp | 6 ++++-- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index 7d939595..6f969eba 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -390,7 +390,9 @@ private slots: void openProjectSettingsEditor(int tab); bool isProjectOpen(); void showExportMapImageWindow(ImageExporterMode mode); + double getMetatilesZoomScale(); void redrawMetatileSelection(); + void scrollMetatileSelectorToSelection(); QObjectList shortcutableObjects() const; void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false); diff --git a/include/ui/metatileselector.h b/include/ui/metatileselector.h index eaf357ca..ec2c49f4 100644 --- a/include/ui/metatileselector.h +++ b/include/ui/metatileselector.h @@ -45,13 +45,14 @@ class MetatileSelector: public SelectablePixmapItem { QPoint getSelectionDimensions(); void draw(); bool select(uint16_t metatile); - bool selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation); + void selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation); void setTilesets(Tileset*, Tileset*); MetatileSelection getMetatileSelection(); void setPrefabSelection(MetatileSelection selection); void setExternalSelection(int, int, QList, QList>); QPoint getMetatileIdCoordsOnWidget(uint16_t); void setMap(Map*); + bool isInternalSelection() const { return (!this->externalSelection && !this->prefabSelection); } Tileset *primaryTileset; Tileset *secondaryTileset; protected: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 109233f3..33f11d54 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1366,32 +1366,48 @@ void MainWindow::updateTilesetEditor() { } } -void MainWindow::redrawMetatileSelection() -{ - double scale = pow(3.0, static_cast(porymapConfig.getMetatilesZoom() - 30) / 30.0); +double MainWindow::getMetatilesZoomScale() { + return pow(3.0, static_cast(porymapConfig.getMetatilesZoom() - 30) / 30.0); +} + +void MainWindow::redrawMetatileSelection() { + auto scale = getMetatilesZoomScale(); QTransform transform; transform.scale(scale, scale); ui->graphicsView_currentMetatileSelection->setTransform(transform); ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width() * scale, editor->current_metatile_selection_item->pixmap().height() * scale); ui->scrollAreaWidgetContents_SelectedMetatiles->adjustSize(); +} +void MainWindow::scrollMetatileSelectorToSelection() { + // Internal selections or 1x1 external selections can be scrolled to + if (!editor->metatile_selector_item->isInternalSelection() && editor->metatile_selector_item->getSelectionDimensions() != QPoint(1, 1)) + return; + + MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection(); + if (selection.metatileItems.isEmpty()) + return; + + QPoint pos = editor->metatile_selector_item->getMetatileIdCoordsOnWidget(selection.metatileItems.first().metatileId); QPoint size = editor->metatile_selector_item->getSelectionDimensions(); - if (size.x() == 1 && size.y() == 1) { - MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection(); - QPoint pos = editor->metatile_selector_item->getMetatileIdCoordsOnWidget(selection.metatileItems.first().metatileId); - pos *= scale; - ui->scrollArea_MetatileSelector->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale); - } + pos += QPoint(size.x() - 1, size.y() - 1) * 16 / 2; // We want to focus on the center of the whole selection + pos *= getMetatilesZoomScale(); + + auto viewport = ui->scrollArea_MetatileSelector->viewport(); + ui->scrollArea_MetatileSelector->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2); } -void MainWindow::currentMetatilesSelectionChanged() -{ +void MainWindow::currentMetatilesSelectionChanged() { redrawMetatileSelection(); if (this->tilesetEditor) { MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection(); this->tilesetEditor->selectMetatile(selection.metatileItems.first().metatileId); } + + // Don't scroll to internal selections here, it will disrupt the user while they make their selection. + if (!editor->metatile_selector_item->isInternalSelection()) + scrollMetatileSelectorToSelection(); } void MainWindow::on_mapList_activated(const QModelIndex &index) @@ -2836,6 +2852,7 @@ void MainWindow::on_horizontalSlider_MetatileZoom_valueChanged(int value) { ui->scrollAreaWidgetContents_BorderMetatiles->adjustSize(); redrawMetatileSelection(); + scrollMetatileSelectorToSelection(); } void MainWindow::on_horizontalSlider_CollisionZoom_valueChanged(int value) { diff --git a/src/ui/metatileselector.cpp b/src/ui/metatileselector.cpp index 2c4a5fb3..074b7758 100644 --- a/src/ui/metatileselector.cpp +++ b/src/ui/metatileselector.cpp @@ -59,12 +59,9 @@ bool MetatileSelector::select(uint16_t metatileId) { return true; } -bool MetatileSelector::selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation) { - if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false; - this->select(metatileId); - this->selection.collisionItems.append(CollisionSelectionItem{true, collision, elevation}); - this->selection.hasCollision = true; - return true; +void MetatileSelector::selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation) { + QPair movePermissions(collision, elevation); + this->setExternalSelection(1, 1, {metatileId}, {movePermissions}); } void MetatileSelector::setTilesets(Tileset *primaryTileset, Tileset *secondaryTileset) { @@ -100,6 +97,10 @@ void MetatileSelector::setExternalSelection(int width, int height, QListselection.metatileItems.append(MetatileSelectionItem{true, metatileId}); } + if (this->selection.metatileItems.length() == 1) { + QPoint coords = this->getMetatileIdCoords(this->selection.metatileItems.first().metatileId); + SelectablePixmapItem::select(coords.x(), coords.y(), 0, 0); + } this->draw(); emit selectedMetatilesChanged(); diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 5e089635..ff79066b 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -1206,7 +1206,8 @@ void TilesetEditor::redrawMetatileSelector() { pos *= scale; this->ui->scrollAreaWidgetContents_Metatiles->adjustSize(); - this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale); + auto viewport = this->ui->scrollArea_Metatiles->viewport(); + this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2); } void TilesetEditor::on_horizontalSlider_TilesZoom_valueChanged(int value) { @@ -1231,6 +1232,7 @@ void TilesetEditor::redrawTileSelector() { if (!tiles.isEmpty()) { QPoint pos = this->tileSelector->getTileCoordsOnWidget(tiles[0].tileId); pos *= scale; - this->ui->scrollArea_Tiles->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale); + auto viewport = this->ui->scrollArea_Tiles->viewport(); + this->ui->scrollArea_Tiles->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2); } } From 0c03676f204a78655a9498a63a20fbcef3ed8c9d Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 26 Jan 2024 15:34:42 -0500 Subject: [PATCH 4/7] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d1b6e6b..8b322cb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,10 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ### Changed - If Wild Encounters fail to load they are now only disabled for that session, and the settings remain unchanged. - Defaults are used if project constants are missing, rather than failing to open the project or changing settings. +- Selector images now center on the selection when eyedropping or zooming. ### Fixed -- Fix the Tileset Editor selectors scrolling to the wrong selection when zoomed. +- Fix some minor visual issues with the various zoom sliders. - Fix the Tileset Editor selectors getting extra white space when changing tilesets. - Fix a crash when adding disabled events with the Pencil tool. From d7f25f9ae5ac4db04e3275cd4a4bed2ceb3fc821 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 26 Jan 2024 15:55:29 -0500 Subject: [PATCH 5/7] More selection image fixes --- src/mainwindow.cpp | 15 ++++++++++----- src/ui/tileseteditor.cpp | 12 +++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 33f11d54..6f9e10b3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -734,10 +734,10 @@ void MainWindow::refreshMapScene() ui->graphicsView_Metatiles->setFixedSize(editor->metatile_selector_item->pixmap().width() + 2, editor->metatile_selector_item->pixmap().height() + 2); ui->graphicsView_BorderMetatile->setScene(editor->scene_selected_border_metatiles); - ui->graphicsView_BorderMetatile->setFixedSize(editor->selected_border_metatiles_item->pixmap().width(), editor->selected_border_metatiles_item->pixmap().height()); + ui->graphicsView_BorderMetatile->setFixedSize(editor->selected_border_metatiles_item->pixmap().width() + 2, editor->selected_border_metatiles_item->pixmap().height() + 2); ui->graphicsView_currentMetatileSelection->setScene(editor->scene_current_metatile_selection); - ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width(), editor->current_metatile_selection_item->pixmap().height()); + ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width() + 2, editor->current_metatile_selection_item->pixmap().height() + 2); ui->graphicsView_Collision->setScene(editor->scene_collision_metatiles); //ui->graphicsView_Collision->setSceneRect(editor->scene_collision_metatiles->sceneRect()); @@ -1371,12 +1371,16 @@ double MainWindow::getMetatilesZoomScale() { } void MainWindow::redrawMetatileSelection() { + QSize size(editor->current_metatile_selection_item->pixmap().width(), editor->current_metatile_selection_item->pixmap().height()); + ui->graphicsView_currentMetatileSelection->setSceneRect(0, 0, size.width(), size.height()); + auto scale = getMetatilesZoomScale(); QTransform transform; transform.scale(scale, scale); + size *= scale; ui->graphicsView_currentMetatileSelection->setTransform(transform); - ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width() * scale, editor->current_metatile_selection_item->pixmap().height() * scale); + ui->graphicsView_currentMetatileSelection->setFixedSize(size.width() + 2, size.height() + 2); ui->scrollAreaWidgetContents_SelectedMetatiles->adjustSize(); } @@ -1394,6 +1398,7 @@ void MainWindow::scrollMetatileSelectorToSelection() { pos += QPoint(size.x() - 1, size.y() - 1) * 16 / 2; // We want to focus on the center of the whole selection pos *= getMetatilesZoomScale(); + // TODO: This snaps focus to the position if it's out of view. It should scroll slowly toward this target instead auto viewport = ui->scrollArea_MetatileSelector->viewport(); ui->scrollArea_MetatileSelector->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2); } @@ -2845,8 +2850,8 @@ void MainWindow::on_horizontalSlider_MetatileZoom_valueChanged(int value) { ui->graphicsView_Metatiles->setFixedSize(size.width() + 2, size.height() + 2); ui->graphicsView_BorderMetatile->setTransform(transform); - ui->graphicsView_BorderMetatile->setFixedSize(ceil(static_cast(editor->selected_border_metatiles_item->pixmap().width()) * scale), - ceil(static_cast(editor->selected_border_metatiles_item->pixmap().height()) * scale)); + ui->graphicsView_BorderMetatile->setFixedSize(ceil(static_cast(editor->selected_border_metatiles_item->pixmap().width()) * scale) + 2, + ceil(static_cast(editor->selected_border_metatiles_item->pixmap().height()) * scale) + 2); ui->scrollAreaWidgetContents_MetatileSelector->adjustSize(); ui->scrollAreaWidgetContents_BorderMetatiles->adjustSize(); diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index ff79066b..4813790a 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -317,7 +317,6 @@ void TilesetEditor::refresh() { this->tileSelector->setTilesets(this->primaryTileset, this->secondaryTileset); this->metatileSelector->setTilesets(this->primaryTileset, this->secondaryTileset); this->metatileSelector->select(this->getSelectedMetatileId()); - this->drawSelectedTiles(); if (metatileSelector) { if (metatileSelector->selectorShowUnused || metatileSelector->selectorShowCounts) { @@ -333,11 +332,9 @@ void TilesetEditor::refresh() { } } - this->ui->graphicsView_Tiles->setSceneRect(0, 0, this->tileSelector->pixmap().width(), this->tileSelector->pixmap().height()); - this->ui->graphicsView_Metatiles->setSceneRect(0, 0, this->metatileSelector->pixmap().width(), this->metatileSelector->pixmap().height()); - this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); this->redrawTileSelector(); this->redrawMetatileSelector(); + this->drawSelectedTiles(); } void TilesetEditor::drawSelectedTiles() { @@ -363,7 +360,10 @@ void TilesetEditor::drawSelectedTiles() { this->selectedTilePixmapItem = new QGraphicsPixmapItem(QPixmap::fromImage(selectionImage)); this->selectedTileScene->addItem(this->selectedTilePixmapItem); - this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); + + QSize size(this->selectedTilePixmapItem->pixmap().width(), this->selectedTilePixmapItem->pixmap().height()); + this->ui->graphicsView_selectedTile->setSceneRect(0, 0, size.width(), size.height()); + this->ui->graphicsView_selectedTile->setFixedSize(size.width() + 2, size.height() + 2); } void TilesetEditor::onHoveredMetatileChanged(uint16_t metatileId) { @@ -1193,6 +1193,7 @@ void TilesetEditor::on_horizontalSlider_MetatilesZoom_valueChanged(int value) { void TilesetEditor::redrawMetatileSelector() { QSize size(this->metatileSelector->pixmap().width(), this->metatileSelector->pixmap().height()); + this->ui->graphicsView_Metatiles->setSceneRect(0, 0, size.width(), size.height()); double scale = pow(3.0, static_cast(porymapConfig.getTilesetEditorMetatilesZoom() - 30) / 30.0); QTransform transform; @@ -1217,6 +1218,7 @@ void TilesetEditor::on_horizontalSlider_TilesZoom_valueChanged(int value) { void TilesetEditor::redrawTileSelector() { QSize size(this->tileSelector->pixmap().width(), this->tileSelector->pixmap().height()); + this->ui->graphicsView_Tiles->setSceneRect(0, 0, size.width(), size.height()); double scale = pow(3.0, static_cast(porymapConfig.getTilesetEditorTilesZoom() - 30) / 30.0); QTransform transform; From 13f14757beffefb8f90f49b1cb2593213eabeecc Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 28 Jan 2024 14:15:45 -0500 Subject: [PATCH 6/7] Smooth out scrolling for graphics views nested in scroll areas --- CHANGELOG.md | 1 + forms/mainwindow.ui | 13 +++++++++---- forms/tileseteditor.ui | 9 +++++++-- include/ui/graphicsview.h | 17 ++++++++++++++--- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b322cb5..2a03f48c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ### Fixed - Fix some minor visual issues with the various zoom sliders. +- Smooth out scrolling when mouse is over tile/metatile images. - Fix the Tileset Editor selectors getting extra white space when changing tilesets. - Fix a crash when adding disabled events with the Pencil tool. diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 45316d33..d1ef7767 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -803,7 +803,7 @@ - + 0 @@ -922,7 +922,7 @@ - + 0 @@ -1032,7 +1032,7 @@ - + true @@ -1227,7 +1227,7 @@ - + 0 @@ -3435,6 +3435,11 @@ QWidget
mapview.h
+ + NoScrollGraphicsView + QGraphicsView +
mapview.h
+
diff --git a/forms/tileseteditor.ui b/forms/tileseteditor.ui index 0e70da25..c144e5f2 100644 --- a/forms/tileseteditor.ui +++ b/forms/tileseteditor.ui @@ -86,7 +86,7 @@ 6
- + Qt::ScrollBarAlwaysOff @@ -560,7 +560,7 @@ 0
- + Qt::ScrollBarAlwaysOff @@ -806,6 +806,11 @@ QComboBox
noscrollcombobox.h
+ + NoScrollGraphicsView + QGraphicsView +
mapview.h
+
diff --git a/include/ui/graphicsview.h b/include/ui/graphicsview.h index cee19293..c0d1592c 100644 --- a/include/ui/graphicsview.h +++ b/include/ui/graphicsview.h @@ -4,12 +4,23 @@ #include #include -class ClickableGraphicsView : public QGraphicsView +class NoScrollGraphicsView : public QGraphicsView { Q_OBJECT public: - ClickableGraphicsView() : QGraphicsView() {} - ClickableGraphicsView(QWidget *parent) : QGraphicsView(parent) {} + NoScrollGraphicsView(QWidget *parent = nullptr) : QGraphicsView(parent) {} + +protected: + void wheelEvent(QWheelEvent *event) { + event->ignore(); + } +}; + +class ClickableGraphicsView : public NoScrollGraphicsView +{ + Q_OBJECT +public: + ClickableGraphicsView(QWidget *parent = nullptr) : NoScrollGraphicsView(parent) {} public: void mouseReleaseEvent(QMouseEvent *event) override { From dc0d6fe267e8a1722d3d0cb59b2dd9e2510c0ab3 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 7 Feb 2024 16:20:09 -0500 Subject: [PATCH 7/7] Remove leftover comment --- src/mainwindow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6f9e10b3..f7e0dee1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1398,7 +1398,6 @@ void MainWindow::scrollMetatileSelectorToSelection() { pos += QPoint(size.x() - 1, size.y() - 1) * 16 / 2; // We want to focus on the center of the whole selection pos *= getMetatilesZoomScale(); - // TODO: This snaps focus to the position if it's out of view. It should scroll slowly toward this target instead auto viewport = ui->scrollArea_MetatileSelector->viewport(); ui->scrollArea_MetatileSelector->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2); }