Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/gui/print_widget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2021 Kai Pastor
* Copyright 2012-2021, 2025 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -301,6 +301,10 @@ PrintWidget::PrintWidget(Map* map, MainWindow* main_window, MapView* main_view,
layout->addRow(world_file_check);
world_file_check->hide();

transparent_background_check = new QCheckBox(tr("Transparent background"));
layout->addRow(transparent_background_check);
transparent_background_check->hide();

scrolling_content = new QWidget();
scrolling_content->setLayout(layout);

Expand Down Expand Up @@ -670,6 +674,8 @@ void PrintWidget::setTarget(const QPrinterInfo* target)
// no point in writing a world file.
world_file_check->setChecked(!map->getGeoreferencing().toProjectedCoords(MapCoordF{}).isNull());

transparent_background_check->setVisible(is_image_target);

updateColorMode();
}

Expand Down Expand Up @@ -1154,6 +1160,7 @@ void PrintWidget::overprintingClicked(bool checked)
map_printer->setSimulateOverprinting(checked);
}


void PrintWidget::colorModeChanged()
{
if (color_mode_combo->currentData().toBool())
Expand Down Expand Up @@ -1299,11 +1306,20 @@ void PrintWidget::exportToImage()
return;
}

bool transparent_background = transparent_background_check->isChecked();
if (transparent_background
&& !path.endsWith(QLatin1String(".png"), Qt::CaseInsensitive)
&& !path.endsWith(QLatin1String(".tif"), Qt::CaseInsensitive) && !path.endsWith(QLatin1String(".tiff"), Qt::CaseInsensitive) )
{
transparent_background = false;
QMessageBox::information(this, tr("Information"), tr("Transparent background is not supported for this file format.\nUsing a white background instead."));
}

int dots_per_meter = qRound(pixel_per_mm * 1000);
image.setDotsPerMeterX(dots_per_meter);
image.setDotsPerMeterY(dots_per_meter);

image.fill(QColor(Qt::white));
image.fill(QColor(transparent_background ? Qt::transparent : Qt::white));

#if 0 // Pointless unless drawPage drives the event loop and sends progress
PrintProgressDialog progress(map_printer, main_window);
Expand Down
10 changes: 5 additions & 5 deletions src/gui/print_widget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2021 Kai Pastor
* Copyright 2012-2021, 2025 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -209,7 +209,7 @@ protected slots:

/** This slot reacts to changes of the "Simulate overprinting" option. */
void overprintingClicked(bool checked);

/** This slot reacts to changes of the "Color mode" option. */
void colorModeChanged();

Expand Down Expand Up @@ -303,6 +303,7 @@ protected slots:
QCheckBox* show_grid_check;
QCheckBox* overprinting_check;
QCheckBox* world_file_check;
QCheckBox* transparent_background_check;
QCheckBox* different_scale_check;
QSpinBox* different_scale_edit;
QComboBox* color_mode_combo;
Expand Down Expand Up @@ -344,7 +345,6 @@ protected slots:
Q_DECLARE_OPERATORS_FOR_FLAGS(OpenOrienteering::PrintWidget::TaskFlags)


#endif

#endif // OPENORIENTEERING_PRINT_WIDGET_H

#endif
#endif // QT_PRINTSUPPORT_LIB