From 4cb7e8a9aaa9cb8c8331153db92283551a013ecc Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 26 Jan 2024 11:40:32 -0500 Subject: [PATCH] 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 + Qt::Vertical - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 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);