Merge pull request #619 from GriffinRichards/stitch-preview

Add actual preview to Export Map Stitch Image
This commit is contained in:
GriffinR 2024-10-10 13:40:18 -04:00 committed by GitHub
commit 426faddad7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 555 additions and 420 deletions

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>696</width> <width>817</width>
<height>396</height> <height>535</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -16,110 +16,15 @@
<property name="sizeGripEnabled"> <property name="sizeGripEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QGridLayout" name="gridLayout_4" columnstretch="2,1">
<item> <item row="1" column="1">
<widget class="QGroupBox" name="groupBox"> <widget class="QFrame" name="frame_Options">
<property name="title">
<string>Preview</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>403</width>
<height>343</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="4">
<widget class="QGraphicsView" name="graphicsView_Preview">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="dragMode">
<enum>QGraphicsView::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>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_Options"> <layout class="QVBoxLayout" name="verticalLayout_Options">
<item> <item>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
@ -133,7 +38,7 @@
<item row="0" column="1"> <item row="0" column="1">
<widget class="NoScrollComboBox" name="comboBox_MapSelection"> <widget class="NoScrollComboBox" name="comboBox_MapSelection">
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum> <enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
</property> </property>
</widget> </widget>
</item> </item>
@ -147,7 +52,28 @@
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_Event_Options"> <layout class="QGridLayout" name="gridLayout_Event_Options">
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox_Triggers">
<property name="text">
<string>Triggers</string>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QCheckBox" name="checkBox_Objects">
<property name="text">
<string>Objects</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="checkBox_HealLocations">
<property name="text">
<string>Heal Locations</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="checkBox_Warps"> <widget class="QCheckBox" name="checkBox_Warps">
<property name="text"> <property name="text">
<string>Warps</string> <string>Warps</string>
@ -155,30 +81,16 @@
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QCheckBox" name="checkBox_Objects"> <widget class="QCheckBox" name="checkBox_AllEvents">
<property name="text"> <property name="text">
<string>Objects</string> <string>All</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="checkBox_BGs">
<property name="text">
<string>BGs</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QCheckBox" name="checkBox_Triggers"> <widget class="QCheckBox" name="checkBox_BGs">
<property name="text"> <property name="text">
<string>Triggers</string> <string>BGs</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox_HealSpots">
<property name="text">
<string>Heal Spots</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -195,34 +107,41 @@
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_Connection_Options"> <layout class="QGridLayout" name="gridLayout_Connection_Options">
<item row="0" column="0"> <item row="1" column="2">
<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"> <widget class="QCheckBox" name="checkBox_ConnectionLeft">
<property name="text"> <property name="text">
<string>Left</string> <string>Left</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="3"> <item row="1" column="0">
<widget class="QCheckBox" name="checkBox_ConnectionUp">
<property name="text">
<string>Up</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QCheckBox" name="checkBox_ConnectionRight"> <widget class="QCheckBox" name="checkBox_ConnectionRight">
<property name="text"> <property name="text">
<string>Right</string> <string>Right</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox_ConnectionDown">
<property name="text">
<string>Down</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_AllConnections">
<property name="text">
<string>All</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@ -320,7 +239,7 @@
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Orientation::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
@ -330,6 +249,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QCheckBox" name="checkBox_ActualSize">
<property name="text">
<string>Preview actual size</string>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
@ -342,7 +268,7 @@
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Orientation::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
@ -369,6 +295,100 @@
</layout> </layout>
</item> </item>
</layout> </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_Preview">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>469</width>
<height>464</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<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">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::SizeAdjustPolicy::AdjustIgnored</enum>
</property>
<property name="dragMode">
<enum>QGraphicsView::DragMode::NoDrag</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
<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> </item>
</layout> </layout>
</widget> </widget>

View file

@ -16,6 +16,24 @@ enum ImageExporterMode {
Timelapse, Timelapse,
}; };
struct ImageExporterSettings {
bool showObjects = false;
bool showWarps = false;
bool showBGs = false;
bool showTriggers = false;
bool showHealLocations = false;
bool showUpConnections = false;
bool showDownConnections = false;
bool showLeftConnections = false;
bool showRightConnections = false;
bool showGrid = false;
bool showBorder = false;
bool showCollision = false;
bool previewActualSize = false;
int timelapseSkipAmount = 1;
int timelapseDelayMs = 200;
};
class MapImageExporter : public QDialog class MapImageExporter : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -33,50 +51,44 @@ private:
QPixmap preview; QPixmap preview;
bool showObjects = false; ImageExporterSettings settings;
bool showWarps = false;
bool showBGs = false;
bool showTriggers = false;
bool showHealSpots = false;
bool showUpConnections = false;
bool showDownConnections = false;
bool showLeftConnections = false;
bool showRightConnections = false;
bool showGrid = false;
bool showBorder = false;
bool showCollision = false;
int timelapseSkipAmount = 1;
int timelapseDelayMs = 200;
ImageExporterMode mode = ImageExporterMode::Normal; ImageExporterMode mode = ImageExporterMode::Normal;
void updatePreview(); void updatePreview();
void scalePreview();
void updateShowBorderState(); void updateShowBorderState();
void saveImage(); void saveImage();
QPixmap getStitchedImage(QProgressDialog *progress, bool includeBorder); QPixmap getStitchedImage(QProgressDialog *progress, bool includeBorder);
QPixmap getFormattedMapPixmap(Map *map, bool ignoreBorder = false); QPixmap getFormattedMapPixmap(Map *map, bool ignoreBorder = false);
bool historyItemAppliesToFrame(const QUndoCommand *command); bool historyItemAppliesToFrame(const QUndoCommand *command);
protected:
virtual void showEvent(QShowEvent *) override;
virtual void resizeEvent(QResizeEvent *) override;
private slots: private slots:
void on_checkBox_Objects_stateChanged(int state); void on_checkBox_Objects_stateChanged(int state);
void on_checkBox_Warps_stateChanged(int state); void on_checkBox_Warps_stateChanged(int state);
void on_checkBox_BGs_stateChanged(int state); void on_checkBox_BGs_stateChanged(int state);
void on_checkBox_Triggers_stateChanged(int state); void on_checkBox_Triggers_stateChanged(int state);
void on_checkBox_HealSpots_stateChanged(int state); void on_checkBox_HealLocations_stateChanged(int state);
void on_checkBox_AllEvents_stateChanged(int state);
void on_checkBox_ConnectionUp_stateChanged(int state); void on_checkBox_ConnectionUp_stateChanged(int state);
void on_checkBox_ConnectionDown_stateChanged(int state); void on_checkBox_ConnectionDown_stateChanged(int state);
void on_checkBox_ConnectionLeft_stateChanged(int state); void on_checkBox_ConnectionLeft_stateChanged(int state);
void on_checkBox_ConnectionRight_stateChanged(int state); void on_checkBox_ConnectionRight_stateChanged(int state);
void on_checkBox_AllConnections_stateChanged(int state);
void on_checkBox_Elevation_stateChanged(int state); void on_checkBox_Elevation_stateChanged(int state);
void on_checkBox_Grid_stateChanged(int state); void on_checkBox_Grid_stateChanged(int state);
void on_checkBox_Border_stateChanged(int state); void on_checkBox_Border_stateChanged(int state);
void on_pushButton_Save_pressed();
void on_pushButton_Reset_pressed(); void on_pushButton_Reset_pressed();
void on_pushButton_Cancel_pressed();
void on_spinBox_TimelapseDelay_valueChanged(int delayMs); void on_spinBox_TimelapseDelay_valueChanged(int delayMs);
void on_spinBox_FrameSkip_valueChanged(int skip); void on_spinBox_FrameSkip_valueChanged(int skip);
void on_checkBox_ActualSize_stateChanged(int state);
}; };
#endif // MAPIMAGEEXPORTER_H #endif // MAPIMAGEEXPORTER_H

View file

@ -23,6 +23,19 @@ QString getTitle(ImageExporterMode mode) {
return ""; 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) : MapImageExporter::MapImageExporter(QWidget *parent_, Editor *editor_, ImageExporterMode mode) :
QDialog(parent_), QDialog(parent_),
ui(new Ui::MapImageExporter) ui(new Ui::MapImageExporter)
@ -33,6 +46,7 @@ MapImageExporter::MapImageExporter(QWidget *parent_, Editor *editor_, ImageExpor
this->editor = editor_; this->editor = editor_;
this->mode = mode; this->mode = mode;
this->setWindowTitle(getTitle(this->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_Connections->setVisible(this->mode != ImageExporterMode::Stitch);
this->ui->groupBox_Timelapse->setVisible(this->mode == ImageExporterMode::Timelapse); this->ui->groupBox_Timelapse->setVisible(this->mode == ImageExporterMode::Timelapse);
@ -40,7 +54,8 @@ MapImageExporter::MapImageExporter(QWidget *parent_, Editor *editor_, ImageExpor
this->ui->comboBox_MapSelection->setCurrentText(map->name); this->ui->comboBox_MapSelection->setCurrentText(map->name);
this->ui->comboBox_MapSelection->setEnabled(false);// TODO: allow selecting map from drop-down this->ui->comboBox_MapSelection->setEnabled(false);// TODO: allow selecting map from drop-down
updatePreview(); connect(ui->pushButton_Save, &QPushButton::pressed, this, &MapImageExporter::saveImage);
connect(ui->pushButton_Cancel, &QPushButton::pressed, this, &MapImageExporter::close);
} }
MapImageExporter::~MapImageExporter() { MapImageExporter::~MapImageExporter() {
@ -48,7 +63,25 @@ MapImageExporter::~MapImageExporter() {
delete ui; 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() { void MapImageExporter::saveImage() {
// Make sure preview is up-to-date before we save.
if (this->preview.isNull())
updatePreview();
if (this->preview.isNull())
return;
QString title = getTitle(this->mode); QString title = getTitle(this->mode);
QString defaultFilename; QString defaultFilename;
switch (this->mode) switch (this->mode)
@ -74,22 +107,10 @@ void MapImageExporter::saveImage() {
editor->project->setImportExportPath(filepath); editor->project->setImportExportPath(filepath);
switch (this->mode) { switch (this->mode) {
case ImageExporterMode::Normal: case ImageExporterMode::Normal:
case ImageExporterMode::Stitch:
// Normal and Stitch modes already have the image ready to go in the preview.
this->preview.save(filepath); this->preview.save(filepath);
break; 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: case ImageExporterMode::Timelapse:
QProgressDialog progress("Building map timelapse...", "Cancel", 0, 1, this); QProgressDialog progress("Building map timelapse...", "Cancel", 0, 1, this);
progress.setAutoClose(true); progress.setAutoClose(true);
@ -100,7 +121,7 @@ void MapImageExporter::saveImage() {
int maxWidth = this->map->getWidth() * 16; int maxWidth = this->map->getWidth() * 16;
int maxHeight = this->map->getHeight() * 16; int maxHeight = this->map->getHeight() * 16;
if (showBorder) { if (this->settings.showBorder) {
maxWidth += 2 * STITCH_MODE_BORDER_DISTANCE * 16; maxWidth += 2 * STITCH_MODE_BORDER_DISTANCE * 16;
maxHeight += 2 * STITCH_MODE_BORDER_DISTANCE * 16; maxHeight += 2 * STITCH_MODE_BORDER_DISTANCE * 16;
} }
@ -111,7 +132,7 @@ void MapImageExporter::saveImage() {
this->map->editHistory.undo(); this->map->editHistory.undo();
int width = this->map->getWidth() * 16; int width = this->map->getWidth() * 16;
int height = this->map->getHeight() * 16; int height = this->map->getHeight() * 16;
if (showBorder) { if (this->settings.showBorder) {
width += 2 * STITCH_MODE_BORDER_DISTANCE * 16; width += 2 * STITCH_MODE_BORDER_DISTANCE * 16;
height += 2 * STITCH_MODE_BORDER_DISTANCE * 16; height += 2 * STITCH_MODE_BORDER_DISTANCE * 16;
} }
@ -124,7 +145,7 @@ void MapImageExporter::saveImage() {
i++; i++;
} }
QGifImage timelapseImg(QSize(maxWidth, maxHeight)); QGifImage timelapseImg(QSize(maxWidth, maxHeight));
timelapseImg.setDefaultDelay(timelapseDelayMs); timelapseImg.setDefaultDelay(this->settings.timelapseDelayMs);
timelapseImg.setDefaultTransparentColor(QColor(0, 0, 0)); timelapseImg.setDefaultTransparentColor(QColor(0, 0, 0));
// Draw each frame, skpping the specified number of map edits in // Draw each frame, skpping the specified number of map edits in
// the undo history. // the undo history.
@ -154,7 +175,7 @@ void MapImageExporter::saveImage() {
pixmap = pixmap2; pixmap = pixmap2;
} }
timelapseImg.addFrame(pixmap.toImage()); timelapseImg.addFrame(pixmap.toImage());
for (int j = 0; j < timelapseSkipAmount; j++) { for (int j = 0; j < this->settings.timelapseSkipAmount; j++) {
if (i > 0) { if (i > 0) {
i--; i--;
this->map->editHistory.redo(); this->map->editHistory.redo();
@ -192,26 +213,26 @@ bool MapImageExporter::historyItemAppliesToFrame(const QUndoCommand *command) {
case CommandId::ID_PaintCollision: case CommandId::ID_PaintCollision:
case CommandId::ID_BucketFillCollision: case CommandId::ID_BucketFillCollision:
case CommandId::ID_MagicFillCollision: case CommandId::ID_MagicFillCollision:
return this->showCollision; return this->settings.showCollision;
case CommandId::ID_PaintBorder: case CommandId::ID_PaintBorder:
return this->showBorder; return this->settings.showBorder;
case CommandId::ID_MapConnectionMove: case CommandId::ID_MapConnectionMove:
case CommandId::ID_MapConnectionChangeDirection: case CommandId::ID_MapConnectionChangeDirection:
case CommandId::ID_MapConnectionChangeMap: case CommandId::ID_MapConnectionChangeMap:
case CommandId::ID_MapConnectionAdd: case CommandId::ID_MapConnectionAdd:
case CommandId::ID_MapConnectionRemove: case CommandId::ID_MapConnectionRemove:
return this->showUpConnections || this->showDownConnections || this->showLeftConnections || this->showRightConnections; return this->settings.showUpConnections || this->settings.showDownConnections || this->settings.showLeftConnections || this->settings.showRightConnections;
case CommandId::ID_EventMove: case CommandId::ID_EventMove:
case CommandId::ID_EventShift: case CommandId::ID_EventShift:
case CommandId::ID_EventCreate: case CommandId::ID_EventCreate:
case CommandId::ID_EventDelete: case CommandId::ID_EventDelete:
case CommandId::ID_EventDuplicate: { case CommandId::ID_EventDuplicate: {
bool eventTypeIsApplicable = bool eventTypeIsApplicable =
(this->showObjects && (command->id() & IDMask_EventType_Object) != 0) (this->settings.showObjects && (command->id() & IDMask_EventType_Object) != 0)
|| (this->showWarps && (command->id() & IDMask_EventType_Warp) != 0) || (this->settings.showWarps && (command->id() & IDMask_EventType_Warp) != 0)
|| (this->showBGs && (command->id() & IDMask_EventType_BG) != 0) || (this->settings.showBGs && (command->id() & IDMask_EventType_BG) != 0)
|| (this->showTriggers && (command->id() & IDMask_EventType_Trigger) != 0) || (this->settings.showTriggers && (command->id() & IDMask_EventType_Trigger) != 0)
|| (this->showHealSpots && (command->id() & IDMask_EventType_Heal) != 0); || (this->settings.showHealLocations && (command->id() & IDMask_EventType_Heal) != 0);
return eventTypeIsApplicable; return eventTypeIsApplicable;
} }
default: default:
@ -354,19 +375,33 @@ QPixmap MapImageExporter::getStitchedImage(QProgressDialog *progress, bool inclu
} }
void MapImageExporter::updatePreview() { void MapImageExporter::updatePreview() {
if (scene) { if (this->scene) {
delete scene; delete this->scene;
scene = nullptr; this->scene = nullptr;
} }
this->scene = new QGraphicsScene;
preview = getFormattedMapPixmap(this->map); if (this->mode == ImageExporterMode::Stitch) {
scene = new QGraphicsScene; QProgressDialog progress("Building map stitch...", "Cancel", 0, 1, this);
scene->addPixmap(preview); progress.setAutoClose(true);
this->scene->setSceneRect(this->scene->itemsBoundingRect()); progress.setWindowModality(Qt::WindowModal);
progress.setModal(true);
progress.setMinimumDuration(1000);
this->preview = getStitchedImage(&progress, this->settings.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); void MapImageExporter::scalePreview() {
this->ui->graphicsView_Preview->setFixedSize(scene->itemsBoundingRect().width() + 2, if (this->scene && !this->settings.previewActualSize){
scene->itemsBoundingRect().height() + 2); ui->graphicsView_Preview->fitInView(this->scene->sceneRect(), Qt::KeepAspectRatioByExpanding);
}
} }
QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) { QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
@ -376,7 +411,7 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
map->render(true); map->render(true);
pixmap = map->pixmap; pixmap = map->pixmap;
if (showCollision) { if (this->settings.showCollision) {
QPainter collisionPainter(&pixmap); QPainter collisionPainter(&pixmap);
map->renderCollision(true); map->renderCollision(true);
collisionPainter.setOpacity(editor->collisionOpacity); collisionPainter.setOpacity(editor->collisionOpacity);
@ -387,7 +422,7 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
// draw map border // draw map border
// note: this will break when allowing map to be selected from drop down maybe // note: this will break when allowing map to be selected from drop down maybe
int borderHeight = 0, borderWidth = 0; int borderHeight = 0, borderWidth = 0;
if (!ignoreBorder && this->showBorder) { if (!ignoreBorder && this->settings.showBorder) {
int borderDistance = this->mode ? STITCH_MODE_BORDER_DISTANCE : BORDER_DISTANCE; int borderDistance = this->mode ? STITCH_MODE_BORDER_DISTANCE : BORDER_DISTANCE;
map->renderBorder(); map->renderBorder();
int borderHorzDist = editor->getBorderDrawDistance(map->getBorderWidth()); int borderHorzDist = editor->getBorderDrawDistance(map->getBorderWidth());
@ -406,15 +441,16 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
pixmap = newPixmap; pixmap = newPixmap;
} }
if (!ignoreBorder && (this->showUpConnections || this->showDownConnections || this->showLeftConnections || this->showRightConnections)) { if (!ignoreBorder && (this->settings.showUpConnections || this->settings.showDownConnections || this->settings.showLeftConnections || this->settings.showRightConnections)) {
// if showing connections, draw on outside of image // if showing connections, draw on outside of image
QPainter connectionPainter(&pixmap); QPainter connectionPainter(&pixmap);
// TODO: Reading the connections from the editor and not 'map' is incorrect.
for (auto connectionItem : editor->connection_items) { for (auto connectionItem : editor->connection_items) {
const QString direction = connectionItem->connection->direction(); const QString direction = connectionItem->connection->direction();
if ((showUpConnections && direction == "up") if ((this->settings.showUpConnections && direction == "up")
|| (showDownConnections && direction == "down") || (this->settings.showDownConnections && direction == "down")
|| (showLeftConnections && direction == "left") || (this->settings.showLeftConnections && direction == "left")
|| (showRightConnections && direction == "right")) || (this->settings.showRightConnections && direction == "right"))
connectionPainter.drawImage(connectionItem->x() + borderWidth, connectionItem->y() + borderHeight, connectionPainter.drawImage(connectionItem->x() + borderWidth, connectionItem->y() + borderHeight,
connectionItem->connection->getPixmap().toImage()); connectionItem->connection->getPixmap().toImage());
} }
@ -422,27 +458,30 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
} }
// draw events // draw events
if (this->settings.showObjects || this->settings.showWarps || this->settings.showBGs || this->settings.showTriggers || this->settings.showHealLocations) {
QPainter eventPainter(&pixmap); QPainter eventPainter(&pixmap);
QList<Event *> events = map->getAllEvents();
int pixelOffset = 0; int pixelOffset = 0;
if (!ignoreBorder && this->showBorder) { if (!ignoreBorder && this->settings.showBorder) {
pixelOffset = this->mode == ImageExporterMode::Normal ? BORDER_DISTANCE * 16 : STITCH_MODE_BORDER_DISTANCE * 16; pixelOffset = this->mode == ImageExporterMode::Normal ? BORDER_DISTANCE * 16 : STITCH_MODE_BORDER_DISTANCE * 16;
} }
for (Event *event : events) { const QList<Event *> events = map->getAllEvents();
editor->project->setEventPixmap(event); for (const auto &event : events) {
Event::Group group = event->getEventGroup(); Event::Group group = event->getEventGroup();
if ((showObjects && group == Event::Group::Object) if ((this->settings.showObjects && group == Event::Group::Object)
|| (showWarps && group == Event::Group::Warp) || (this->settings.showWarps && group == Event::Group::Warp)
|| (showBGs && group == Event::Group::Bg) || (this->settings.showBGs && group == Event::Group::Bg)
|| (showTriggers && group == Event::Group::Coord) || (this->settings.showTriggers && group == Event::Group::Coord)
|| (showHealSpots && group == Event::Group::Heal)) || (this->settings.showHealLocations && group == Event::Group::Heal)) {
editor->project->setEventPixmap(event);
eventPainter.drawImage(QPoint(event->getPixelX() + pixelOffset, event->getPixelY() + pixelOffset), event->getPixmap().toImage()); eventPainter.drawImage(QPoint(event->getPixelX() + pixelOffset, event->getPixelY() + pixelOffset), event->getPixmap().toImage());
} }
}
eventPainter.end(); eventPainter.end();
}
// draw grid directly onto the pixmap // draw grid directly onto the pixmap
// since the last grid lines are outside of the pixmap, add a pixel to the bottom and right // since the last grid lines are outside of the pixmap, add a pixel to the bottom and right
if (showGrid) { if (this->settings.showGrid) {
int addX = 1, addY = 1; int addX = 1, addY = 1;
if (borderHeight) addY = 0; if (borderHeight) addY = 0;
if (borderWidth) addX = 0; if (borderWidth) addX = 0;
@ -465,97 +504,161 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
void MapImageExporter::updateShowBorderState() { void MapImageExporter::updateShowBorderState() {
// If any of the Connections settings are enabled then this setting is locked (it's implicitly enabled) // If any of the Connections settings are enabled then this setting is locked (it's implicitly enabled)
bool on = (this->settings.showUpConnections || this->settings.showDownConnections || this->settings.showLeftConnections || this->settings.showRightConnections);
const QSignalBlocker blocker(ui->checkBox_Border); const QSignalBlocker blocker(ui->checkBox_Border);
if (showUpConnections || showDownConnections || showLeftConnections || showRightConnections) { ui->checkBox_Border->setChecked(on);
ui->checkBox_Border->setChecked(true); ui->checkBox_Border->setDisabled(on);
ui->checkBox_Border->setDisabled(true); this->settings.showBorder = on;
showBorder = true;
} else {
ui->checkBox_Border->setDisabled(false);
}
} }
void MapImageExporter::on_checkBox_Elevation_stateChanged(int state) { void MapImageExporter::on_checkBox_Elevation_stateChanged(int state) {
showCollision = (state == Qt::Checked); this->settings.showCollision = (state == Qt::Checked);
updatePreview(); updatePreview();
} }
void MapImageExporter::on_checkBox_Grid_stateChanged(int state) { void MapImageExporter::on_checkBox_Grid_stateChanged(int state) {
showGrid = (state == Qt::Checked); this->settings.showGrid = (state == Qt::Checked);
updatePreview(); updatePreview();
} }
void MapImageExporter::on_checkBox_Border_stateChanged(int state) { void MapImageExporter::on_checkBox_Border_stateChanged(int state) {
showBorder = (state == Qt::Checked); this->settings.showBorder = (state == Qt::Checked);
updatePreview(); updatePreview();
} }
void MapImageExporter::on_checkBox_Objects_stateChanged(int state) { void MapImageExporter::on_checkBox_Objects_stateChanged(int state) {
showObjects = (state == Qt::Checked); this->settings.showObjects = (state == Qt::Checked);
updatePreview(); updatePreview();
} }
void MapImageExporter::on_checkBox_Warps_stateChanged(int state) { void MapImageExporter::on_checkBox_Warps_stateChanged(int state) {
showWarps = (state == Qt::Checked); this->settings.showWarps = (state == Qt::Checked);
updatePreview(); updatePreview();
} }
void MapImageExporter::on_checkBox_BGs_stateChanged(int state) { void MapImageExporter::on_checkBox_BGs_stateChanged(int state) {
showBGs = (state == Qt::Checked); this->settings.showBGs = (state == Qt::Checked);
updatePreview(); updatePreview();
} }
void MapImageExporter::on_checkBox_Triggers_stateChanged(int state) { void MapImageExporter::on_checkBox_Triggers_stateChanged(int state) {
showTriggers = (state == Qt::Checked); this->settings.showTriggers = (state == Qt::Checked);
updatePreview(); updatePreview();
} }
void MapImageExporter::on_checkBox_HealSpots_stateChanged(int state) { void MapImageExporter::on_checkBox_HealLocations_stateChanged(int state) {
showHealSpots = (state == Qt::Checked); this->settings.showHealLocations = (state == Qt::Checked);
updatePreview();
}
// Shortcut setting for enabling all events
void MapImageExporter::on_checkBox_AllEvents_stateChanged(int state) {
bool on = (state == Qt::Checked);
const QSignalBlocker b_Objects(ui->checkBox_Objects);
ui->checkBox_Objects->setChecked(on);
ui->checkBox_Objects->setDisabled(on);
this->settings.showObjects = on;
const QSignalBlocker b_Warps(ui->checkBox_Warps);
ui->checkBox_Warps->setChecked(on);
ui->checkBox_Warps->setDisabled(on);
this->settings.showWarps = on;
const QSignalBlocker b_BGs(ui->checkBox_BGs);
ui->checkBox_BGs->setChecked(on);
ui->checkBox_BGs->setDisabled(on);
this->settings.showBGs = on;
const QSignalBlocker b_Triggers(ui->checkBox_Triggers);
ui->checkBox_Triggers->setChecked(on);
ui->checkBox_Triggers->setDisabled(on);
this->settings.showTriggers = on;
const QSignalBlocker b_HealLocations(ui->checkBox_HealLocations);
ui->checkBox_HealLocations->setChecked(on);
ui->checkBox_HealLocations->setDisabled(on);
this->settings.showHealLocations = on;
updatePreview(); updatePreview();
} }
void MapImageExporter::on_checkBox_ConnectionUp_stateChanged(int state) { void MapImageExporter::on_checkBox_ConnectionUp_stateChanged(int state) {
showUpConnections = (state == Qt::Checked); this->settings.showUpConnections = (state == Qt::Checked);
updateShowBorderState(); updateShowBorderState();
updatePreview(); updatePreview();
} }
void MapImageExporter::on_checkBox_ConnectionDown_stateChanged(int state) { void MapImageExporter::on_checkBox_ConnectionDown_stateChanged(int state) {
showDownConnections = (state == Qt::Checked); this->settings.showDownConnections = (state == Qt::Checked);
updateShowBorderState(); updateShowBorderState();
updatePreview(); updatePreview();
} }
void MapImageExporter::on_checkBox_ConnectionLeft_stateChanged(int state) { void MapImageExporter::on_checkBox_ConnectionLeft_stateChanged(int state) {
showLeftConnections = (state == Qt::Checked); this->settings.showLeftConnections = (state == Qt::Checked);
updateShowBorderState(); updateShowBorderState();
updatePreview(); updatePreview();
} }
void MapImageExporter::on_checkBox_ConnectionRight_stateChanged(int state) { void MapImageExporter::on_checkBox_ConnectionRight_stateChanged(int state) {
showRightConnections = (state == Qt::Checked); this->settings.showRightConnections = (state == Qt::Checked);
updateShowBorderState(); updateShowBorderState();
updatePreview(); updatePreview();
} }
void MapImageExporter::on_pushButton_Save_pressed() { // Shortcut setting for enabling all connection directions
saveImage(); void MapImageExporter::on_checkBox_AllConnections_stateChanged(int state) {
bool on = (state == Qt::Checked);
const QSignalBlocker b_Up(ui->checkBox_ConnectionUp);
ui->checkBox_ConnectionUp->setChecked(on);
ui->checkBox_ConnectionUp->setDisabled(on);
this->settings.showUpConnections = on;
const QSignalBlocker b_Down(ui->checkBox_ConnectionDown);
ui->checkBox_ConnectionDown->setChecked(on);
ui->checkBox_ConnectionDown->setDisabled(on);
this->settings.showDownConnections = on;
const QSignalBlocker b_Left(ui->checkBox_ConnectionLeft);
ui->checkBox_ConnectionLeft->setChecked(on);
ui->checkBox_ConnectionLeft->setDisabled(on);
this->settings.showLeftConnections = on;
const QSignalBlocker b_Right(ui->checkBox_ConnectionRight);
ui->checkBox_ConnectionRight->setChecked(on);
ui->checkBox_ConnectionRight->setDisabled(on);
this->settings.showRightConnections = on;
updateShowBorderState();
updatePreview();
}
void MapImageExporter::on_checkBox_ActualSize_stateChanged(int state) {
this->settings.previewActualSize = (state == Qt::Checked);
if (this->settings.previewActualSize) {
ui->graphicsView_Preview->resetTransform();
} else {
scalePreview();
}
} }
void MapImageExporter::on_pushButton_Reset_pressed() { void MapImageExporter::on_pushButton_Reset_pressed() {
for (auto widget : this->findChildren<QCheckBox *>()) this->settings = {};
for (auto widget : this->findChildren<QCheckBox *>()) {
const QSignalBlocker b(widget); // Prevent calls to updatePreview
widget->setChecked(false); widget->setChecked(false);
} }
ui->spinBox_TimelapseDelay->setValue(this->settings.timelapseDelayMs);
void MapImageExporter::on_pushButton_Cancel_pressed() { ui->spinBox_FrameSkip->setValue(this->settings.timelapseSkipAmount);
this->close(); updatePreview();
} }
void MapImageExporter::on_spinBox_TimelapseDelay_valueChanged(int delayMs) { void MapImageExporter::on_spinBox_TimelapseDelay_valueChanged(int delayMs) {
timelapseDelayMs = delayMs; this->settings.timelapseDelayMs = delayMs;
} }
void MapImageExporter::on_spinBox_FrameSkip_valueChanged(int skip) { void MapImageExporter::on_spinBox_FrameSkip_valueChanged(int skip) {
timelapseSkipAmount = skip; this->settings.timelapseSkipAmount = skip;
} }