Add buttons to change scale when resizing maps

This commit is contained in:
GriffinR 2025-05-28 14:46:46 -04:00
parent fb3e93be8a
commit 4816c1c8af
3 changed files with 30 additions and 2 deletions

View File

@ -5,7 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project somewhat adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). The MAJOR version number is bumped when there are **"Breaking Changes"** in the pret projects. For more on this, see [the manual page on breaking changes](https://huderlem.github.io/porymap/manual/breaking-changes.html).
## [Unreleased]
Nothing, yet.
### Changed
- The scale of the map can now be changed while resizing the map.
### Fixed
- Fix small maps being difficult to see while resizing.
## [6.0.0] - 2025-05-26
### Breaking Changes

View File

@ -91,6 +91,8 @@ protected:
this->resetPosition();
}
void keyPressEvent(QKeyEvent *) override;
private slots:
void on_spinBox_width_valueChanged(int value);
void on_spinBox_height_valueChanged(int value);
@ -107,6 +109,9 @@ private:
BoundedPixmapItem *layoutPixmap = nullptr;
QPointer<CheckeredBgScene> scene = nullptr;
void zoom(qreal delta);
qreal scale = 1.0;
};
#endif // RESIZELAYOUTPOPUP_H

View File

@ -99,7 +99,7 @@ void ResizeLayoutPopup::resetPosition() {
}
void ResizeLayoutPopup::on_buttonBox_clicked(QAbstractButton *button) {
if(button == this->ui->buttonBox->button(QDialogButtonBox::Reset) ) {
if (button == this->ui->buttonBox->button(QDialogButtonBox::Reset) ) {
this->scene->clear();
setupLayoutView();
}
@ -170,6 +170,8 @@ void ResizeLayoutPopup::setupLayoutView() {
layoutPixmap->setBoundary(outline);
emit this->outline->rectUpdated(outline->rect().toAlignedRect());
this->scale = 1.0;
QRectF rect = this->outline->rect();
const int marginSize = 10 * 16; // Leave a margin of 10 metatiles around the map
rect += QMargins(marginSize, marginSize, marginSize, marginSize);
@ -203,3 +205,20 @@ QMargins ResizeLayoutPopup::getResult() {
QSize ResizeLayoutPopup::getBorderResult() {
return QSize(this->ui->spinBox_borderWidth->value(), this->ui->spinBox_borderHeight->value());
}
void ResizeLayoutPopup::zoom(qreal delta) {
if (this->scale + delta < 0.05 || this->scale + delta > 3.0)
return;
this->scale += delta;
this->ui->graphicsView->scale(1.0 + delta, 1.0 + delta);
}
void ResizeLayoutPopup::keyPressEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_Plus || event->key() == Qt::Key_Equal) {
zoom(+0.1);
} else if (event->key() == Qt::Key_Minus || event->key() == Qt::Key_Underscore) {
zoom(-0.1);
} else {
QDialog::keyPressEvent(event);
}
}