Add actual preview to Export Map Stitch Image

This commit is contained in:
GriffinR 2024-10-02 01:44:09 -04:00
parent d369806c94
commit ae6312c131
3 changed files with 387 additions and 339 deletions

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>696</width>
<height>396</height>
<width>817</width>
<height>518</height>
</rect>
</property>
<property name="windowTitle">
@ -16,15 +16,299 @@
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<layout class="QGridLayout" name="gridLayout_4" columnstretch="2,1">
<item row="1" column="1">
<widget class="QFrame" name="frame_Options">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_Options">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Map</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="NoScrollComboBox" name="comboBox_MapSelection">
<property name="sizeAdjustPolicy">
<enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_Events">
<property name="title">
<string>Events</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_Event_Options">
<item row="0" column="1">
<widget class="QCheckBox" name="checkBox_Warps">
<property name="text">
<string>Warps</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_Objects">
<property name="text">
<string>Objects</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="checkBox_BGs">
<property name="text">
<string>BGs</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox_Triggers">
<property name="text">
<string>Triggers</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox_HealSpots">
<property name="text">
<string>Heal Spots</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_Connections">
<property name="title">
<string>Connections</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_Connection_Options">
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_ConnectionUp">
<property name="text">
<string>Up</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBox_ConnectionDown">
<property name="text">
<string>Down</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="checkBox_ConnectionLeft">
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QCheckBox" name="checkBox_ConnectionRight">
<property name="text">
<string>Right</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_Misc">
<property name="title">
<string>Miscellaneous</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_Misc_Options">
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_Grid">
<property name="text">
<string>Grid</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox_Elevation">
<property name="text">
<string>Collision</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBox_Border">
<property name="text">
<string>Border</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_Timelapse">
<property name="title">
<string>Timelapse</string>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="2" column="1">
<widget class="QSpinBox" name="spinBox_TimelapseDelay">
<property name="specialValueText">
<string/>
</property>
<property name="suffix">
<string>ms</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>2000</number>
</property>
<property name="value">
<number>200</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Frame Delay</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinBox_FrameSkip">
<property name="suffix">
<string/>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Edit Frame Skip</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_ActualSize">
<property name="text">
<string>Preview actual size</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_Reset">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_Cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Save">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_Preview">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Preview</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea">
<widget class="QScrollArea" name="scrollArea_Preview">
<property name="widgetResizable">
<bool>true</bool>
</property>
@ -33,12 +317,24 @@
<rect>
<x>0</x>
<y>0</y>
<width>403</width>
<height>343</height>
<width>500</width>
<height>439</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="2" column="3">
<widget class="QGraphicsView" name="graphicsView_Preview">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -53,65 +349,13 @@
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
<enum>QAbstractScrollArea::SizeAdjustPolicy::AdjustIgnored</enum>
</property>
<property name="dragMode">
<enum>QGraphicsView::NoDrag</enum>
<enum>QGraphicsView::DragMode::NoDrag</enum>
</property>
</widget>
</item>
<item row="4" column="4">
<spacer name="verticalSpacer_South">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>100</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="4">
<spacer name="verticalSpacer_North">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>100</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="5">
<spacer name="horizontalSpacer_West">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>100</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<spacer name="horizontalSpacer_East">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>100</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
@ -119,256 +363,18 @@
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_Options">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Map</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="NoScrollComboBox" name="comboBox_MapSelection">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_Events">
<property name="title">
<string>Events</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_Event_Options">
<item row="0" column="1">
<widget class="QCheckBox" name="checkBox_Warps">
<property name="text">
<string>Warps</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_Objects">
<property name="text">
<string>Objects</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="checkBox_BGs">
<property name="text">
<string>BGs</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox_Triggers">
<property name="text">
<string>Triggers</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox_HealSpots">
<property name="text">
<string>Heal Spots</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_Connections">
<property name="title">
<string>Connections</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_Connection_Options">
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_ConnectionUp">
<property name="text">
<string>Up</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBox_ConnectionDown">
<property name="text">
<string>Down</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="checkBox_ConnectionLeft">
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QCheckBox" name="checkBox_ConnectionRight">
<property name="text">
<string>Right</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_Misc">
<property name="title">
<string>Miscellaneous</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_Misc_Options">
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_Grid">
<property name="text">
<string>Grid</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox_Elevation">
<property name="text">
<string>Collision</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBox_Border">
<property name="text">
<string>Border</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_Timelapse">
<property name="title">
<string>Timelapse</string>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="2" column="1">
<widget class="QSpinBox" name="spinBox_TimelapseDelay">
<property name="specialValueText">
<string/>
</property>
<property name="suffix">
<string>ms</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>2000</number>
</property>
<property name="value">
<number>200</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Frame Delay</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinBox_FrameSkip">
<property name="suffix">
<string/>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Edit Frame Skip</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_Reset">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_Cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Save">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_Description">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>

View file

@ -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

View file

@ -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();
}