diff --git a/forms/mapimageexporter.ui b/forms/mapimageexporter.ui index d97099a7..ddce54a1 100644 --- a/forms/mapimageexporter.ui +++ b/forms/mapimageexporter.ui @@ -6,8 +6,8 @@ 0 0 - 696 - 396 + 817 + 518 @@ -16,15 +16,299 @@ true - - - + + + + + + 0 + 0 + + + + + + + + + Map + + + + + + + QComboBox::SizeAdjustPolicy::AdjustToContents + + + + + + + + + Events + + + + + + + + Warps + + + + + + + Objects + + + + + + + BGs + + + + + + + Triggers + + + + + + + Heal Spots + + + + + + + + + + + + Connections + + + + + + + + Up + + + + + + + Down + + + + + + + Left + + + + + + + Right + + + + + + + + + + + + Miscellaneous + + + + + + + + Grid + + + + + + + Collision + + + + + + + Border + + + + + + + + + + + + Timelapse + + + + + + + + + ms + + + 1 + + + 2000 + + + 200 + + + + + + + Frame Delay + + + + + + + + + + 1 + + + 999 + + + + + + + Edit Frame Skip + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + Preview actual size + + + + + + + + + Reset + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + Save + + + + + + + + + + + + + 0 + 0 + + Preview + + 6 + + + 6 + + + 6 + + + 6 + - + true @@ -33,12 +317,24 @@ 0 0 - 403 - 343 + 500 + 439 - + + 0 + + + 0 + + + 0 + + + 0 + + @@ -53,65 +349,13 @@ false - QAbstractScrollArea::AdjustIgnored + QAbstractScrollArea::SizeAdjustPolicy::AdjustIgnored - QGraphicsView::NoDrag + QGraphicsView::DragMode::NoDrag - - - - Qt::Vertical - - - - 10 - 100 - - - - - - - - Qt::Vertical - - - - 10 - 100 - - - - - - - - Qt::Horizontal - - - - 100 - 10 - - - - - - - - Qt::Horizontal - - - - 100 - 10 - - - - @@ -119,256 +363,18 @@ - - - - - - - - Map - - - - - - - QComboBox::AdjustToContents - - - - - - - - - Events - - - - - - - - Warps - - - - - - - Objects - - - - - - - BGs - - - - - - - Triggers - - - - - - - Heal Spots - - - - - - - - - - - - Connections - - - - - - - - Up - - - - - - - Down - - - - - - - Left - - - - - - - Right - - - - - - - - - - - - Miscellaneous - - - - - - - - Grid - - - - - - - Collision - - - - - - - Border - - - - - - - - - - - - Timelapse - - - - - - - - - ms - - - 1 - - - 2000 - - - 200 - - - - - - - Frame Delay - - - - - - - - - - 1 - - - 999 - - - - - - - Edit Frame Skip - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Reset - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Cancel - - - - - - - Save - - - - - - + + + + + + + Qt::AlignmentFlag::AlignCenter + + + true + + diff --git a/include/ui/mapimageexporter.h b/include/ui/mapimageexporter.h index b9cc20bd..28f404c2 100644 --- a/include/ui/mapimageexporter.h +++ b/include/ui/mapimageexporter.h @@ -45,17 +45,23 @@ private: bool showGrid = false; bool showBorder = false; bool showCollision = false; + bool previewActualSize = false; int timelapseSkipAmount = 1; int timelapseDelayMs = 200; ImageExporterMode mode = ImageExporterMode::Normal; void updatePreview(); + void scalePreview(); void updateShowBorderState(); void saveImage(); QPixmap getStitchedImage(QProgressDialog *progress, bool includeBorder); QPixmap getFormattedMapPixmap(Map *map, bool ignoreBorder = false); bool historyItemAppliesToFrame(const QUndoCommand *command); +protected: + virtual void showEvent(QShowEvent *) override; + virtual void resizeEvent(QResizeEvent *) override; + private slots: void on_checkBox_Objects_stateChanged(int state); void on_checkBox_Warps_stateChanged(int state); @@ -77,6 +83,8 @@ private slots: void on_pushButton_Cancel_pressed(); void on_spinBox_TimelapseDelay_valueChanged(int delayMs); void on_spinBox_FrameSkip_valueChanged(int skip); + + void on_checkBox_ActualSize_stateChanged(int state); }; #endif // MAPIMAGEEXPORTER_H diff --git a/src/ui/mapimageexporter.cpp b/src/ui/mapimageexporter.cpp index 10194b8b..e9c3e18c 100644 --- a/src/ui/mapimageexporter.cpp +++ b/src/ui/mapimageexporter.cpp @@ -23,6 +23,19 @@ QString getTitle(ImageExporterMode mode) { return ""; } +QString getDescription(ImageExporterMode mode) { + switch (mode) + { + case ImageExporterMode::Normal: + return "Exports an image of the selected map."; + case ImageExporterMode::Stitch: + return "Exports a combined image of all the maps connected to the selected map."; + case ImageExporterMode::Timelapse: + return "Exports a GIF of the edit history for the selected map."; + } + return ""; +} + MapImageExporter::MapImageExporter(QWidget *parent_, Editor *editor_, ImageExporterMode mode) : QDialog(parent_), ui(new Ui::MapImageExporter) @@ -33,14 +46,13 @@ MapImageExporter::MapImageExporter(QWidget *parent_, Editor *editor_, ImageExpor this->editor = editor_; this->mode = mode; this->setWindowTitle(getTitle(this->mode)); + this->ui->label_Description->setText(getDescription(this->mode)); this->ui->groupBox_Connections->setVisible(this->mode != ImageExporterMode::Stitch); this->ui->groupBox_Timelapse->setVisible(this->mode == ImageExporterMode::Timelapse); this->ui->comboBox_MapSelection->addItems(editor->project->mapNames); this->ui->comboBox_MapSelection->setCurrentText(map->name); this->ui->comboBox_MapSelection->setEnabled(false);// TODO: allow selecting map from drop-down - - updatePreview(); } MapImageExporter::~MapImageExporter() { @@ -48,6 +60,18 @@ MapImageExporter::~MapImageExporter() { delete ui; } +// Allow the window to open before displaying the preview. +void MapImageExporter::showEvent(QShowEvent *event) { + QWidget::showEvent(event); + if (!event->spontaneous()) + QTimer::singleShot(0, this, &MapImageExporter::updatePreview); +} + +void MapImageExporter::resizeEvent(QResizeEvent *event) { + QDialog::resizeEvent(event); + scalePreview(); +} + void MapImageExporter::saveImage() { QString title = getTitle(this->mode); QString defaultFilename; @@ -74,22 +98,10 @@ void MapImageExporter::saveImage() { editor->project->setImportExportPath(filepath); switch (this->mode) { case ImageExporterMode::Normal: + case ImageExporterMode::Stitch: + // Normal and Stitch modes already have the image ready to go in the preview. this->preview.save(filepath); break; - case ImageExporterMode::Stitch: { - QProgressDialog progress("Building map stitch...", "Cancel", 0, 1, this); - progress.setAutoClose(true); - progress.setWindowModality(Qt::WindowModal); - progress.setModal(true); - QPixmap pixmap = this->getStitchedImage(&progress, this->showBorder); - if (progress.wasCanceled()) { - progress.close(); - return; - } - pixmap.save(filepath); - progress.close(); - break; - } case ImageExporterMode::Timelapse: QProgressDialog progress("Building map timelapse...", "Cancel", 0, 1, this); progress.setAutoClose(true); @@ -354,19 +366,32 @@ QPixmap MapImageExporter::getStitchedImage(QProgressDialog *progress, bool inclu } void MapImageExporter::updatePreview() { - if (scene) { - delete scene; - scene = nullptr; + if (this->scene) { + delete this->scene; + this->scene = nullptr; } + this->scene = new QGraphicsScene; - preview = getFormattedMapPixmap(this->map); - scene = new QGraphicsScene; - scene->addPixmap(preview); - this->scene->setSceneRect(this->scene->itemsBoundingRect()); + if (this->mode == ImageExporterMode::Stitch) { + QProgressDialog progress("Building map stitch...", "Cancel", 0, 1, this); + progress.setAutoClose(true); + progress.setWindowModality(Qt::WindowModal); + progress.setModal(true); + this->preview = getStitchedImage(&progress, this->showBorder); + progress.close(); + } else { + // Timelapse mode doesn't currently have a real preview. It just displays the current map as in Normal mode. + this->preview = getFormattedMapPixmap(this->map); + } + this->scene->addPixmap(this->preview); + ui->graphicsView_Preview->setScene(scene); + scalePreview(); +} - this->ui->graphicsView_Preview->setScene(scene); - this->ui->graphicsView_Preview->setFixedSize(scene->itemsBoundingRect().width() + 2, - scene->itemsBoundingRect().height() + 2); +void MapImageExporter::scalePreview() { + if (this->scene && !this->previewActualSize){ + ui->graphicsView_Preview->fitInView(this->scene->sceneRect(), Qt::KeepAspectRatioByExpanding); + } } QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) { @@ -539,6 +564,15 @@ void MapImageExporter::on_checkBox_ConnectionRight_stateChanged(int state) { updatePreview(); } +void MapImageExporter::on_checkBox_ActualSize_stateChanged(int state) { + previewActualSize = (state == Qt::Checked); + if (previewActualSize) { + ui->graphicsView_Preview->resetTransform(); + } else { + scalePreview(); + } +} + void MapImageExporter::on_pushButton_Save_pressed() { saveImage(); }