diff --git a/src/importexport/imagesexport/iimagesexportconfiguration.h b/src/importexport/imagesexport/iimagesexportconfiguration.h index 415d772f30028..4f402ab5add4b 100644 --- a/src/importexport/imagesexport/iimagesexportconfiguration.h +++ b/src/importexport/imagesexport/iimagesexportconfiguration.h @@ -39,6 +39,9 @@ class IImagesExportConfiguration : MODULE_EXPORT_INTERFACE virtual int exportPdfDpiResolution() const = 0; virtual void setExportPdfDpiResolution(int dpi) = 0; + virtual bool exportPdfWithTransparentBackground() const = 0; + virtual void setExportPdfWithTransparentBackground(bool transparent) = 0; + // Png virtual float exportPngDpiResolution() const = 0; virtual void setExportPngDpiResolution(float dpi) = 0; diff --git a/src/importexport/imagesexport/internal/imagesexportconfiguration.cpp b/src/importexport/imagesexport/internal/imagesexportconfiguration.cpp index 1f7b2bdd0d2ac..44d8e7ce1141a 100644 --- a/src/importexport/imagesexport/internal/imagesexportconfiguration.cpp +++ b/src/importexport/imagesexport/internal/imagesexportconfiguration.cpp @@ -30,6 +30,7 @@ using namespace mu; using namespace mu::iex::imagesexport; static const Settings::Key EXPORT_PDF_DPI_RESOLUTION_KEY("iex_imagesexport", "export/pdf/dpi"); +static const Settings::Key EXPORT_PDF_USE_TRANSPARENCY_KEY("iex_imagesexport", "export/pdf/useTransparency"); static const Settings::Key EXPORT_PNG_DPI_RESOLUTION_KEY("iex_imagesexport", "export/png/resolution"); static const Settings::Key EXPORT_PNG_USE_TRANSPARENCY_KEY("iex_imagesexport", "export/png/useTransparency"); static const Settings::Key EXPORT_SVG_USE_TRANSPARENCY_KEY("iex_imagesexport", "export/svg/useTransparency"); @@ -51,6 +52,16 @@ void ImagesExportConfiguration::setExportPdfDpiResolution(int dpi) settings()->setSharedValue(EXPORT_PDF_DPI_RESOLUTION_KEY, Val(dpi)); } +bool ImagesExportConfiguration::exportPdfWithTransparentBackground() const +{ + return settings()->value(EXPORT_PDF_USE_TRANSPARENCY_KEY).toBool(); +} + +void ImagesExportConfiguration::setExportPdfWithTransparentBackground(bool transparent) +{ + settings()->setSharedValue(EXPORT_PDF_USE_TRANSPARENCY_KEY, Val(transparent)); +} + float ImagesExportConfiguration::exportPngDpiResolution() const { if (m_customExportPngDpiOverride) { diff --git a/src/importexport/imagesexport/internal/imagesexportconfiguration.h b/src/importexport/imagesexport/internal/imagesexportconfiguration.h index 36570c64003aa..be4e2b3bc73cd 100644 --- a/src/importexport/imagesexport/internal/imagesexportconfiguration.h +++ b/src/importexport/imagesexport/internal/imagesexportconfiguration.h @@ -33,6 +33,9 @@ class ImagesExportConfiguration : public IImagesExportConfiguration int exportPdfDpiResolution() const override; void setExportPdfDpiResolution(int dpi) override; + bool exportPdfWithTransparentBackground() const override; + void setExportPdfWithTransparentBackground(bool transparent) override; + float exportPngDpiResolution() const override; void setExportPngDpiResolution(float dpi) override; void setExportPngDpiResolutionOverride(std::optional dpi) override; diff --git a/src/importexport/imagesexport/internal/pdfwriter.cpp b/src/importexport/imagesexport/internal/pdfwriter.cpp index fefdf29ab48b5..fd00acb667ed1 100644 --- a/src/importexport/imagesexport/internal/pdfwriter.cpp +++ b/src/importexport/imagesexport/internal/pdfwriter.cpp @@ -65,9 +65,13 @@ Ret PdfWriter::write(INotationPtr notation, io::IODevice& destinationDevice, con return false; } + const bool TRANSPARENT_BACKGROUND = muse::value(options, OptionKey::TRANSPARENT_BACKGROUND, + Val(configuration()->exportPdfWithTransparentBackground())).toBool(); + INotationPainting::Options opt; opt.deviceDpi = pdfWriter.logicalDpiX(); opt.onNewPage = [&pdfWriter]() { pdfWriter.newPage(); }; + opt.printPageBackground = !TRANSPARENT_BACKGROUND; notation->painting()->paintPdf(&painter, opt); @@ -107,9 +111,13 @@ Ret PdfWriter::writeList(const INotationPtrList& notations, io::IODevice& destin return false; } + const bool TRANSPARENT_BACKGROUND = muse::value(options, OptionKey::TRANSPARENT_BACKGROUND, + Val(configuration()->exportPdfWithTransparentBackground())).toBool(); + INotationPainting::Options opt; opt.deviceDpi = pdfWriter.logicalDpiX(); opt.onNewPage = [&pdfWriter]() { pdfWriter.newPage(); }; + opt.printPageBackground = !TRANSPARENT_BACKGROUND; for (const auto& notation : notations) { IF_ASSERT_FAILED(notation) { diff --git a/src/project/qml/MuseScore/Project/internal/Export/PdfSettingsPage.qml b/src/project/qml/MuseScore/Project/internal/Export/PdfSettingsPage.qml index 85338b14cd72c..1296f582d3e08 100644 --- a/src/project/qml/MuseScore/Project/internal/Export/PdfSettingsPage.qml +++ b/src/project/qml/MuseScore/Project/internal/Export/PdfSettingsPage.qml @@ -55,4 +55,19 @@ ExportSettingsPage { } } } + + CheckBox { + width: parent.width + text: qsTrc("project/export", "Transparent background") + + navigation.name: "TransparentBackgroundCheckbox" + navigation.panel: root.navigationPanel + navigation.row: root.navigationOrder + 2 + + checked: root.model.pdfTransparentBackground + + onClicked: { + root.model.pdfTransparentBackground = !checked + } + } } diff --git a/src/project/view/exportdialogmodel.cpp b/src/project/view/exportdialogmodel.cpp index 5d0c92b0fbca3..b3a918b034d56 100644 --- a/src/project/view/exportdialogmodel.cpp +++ b/src/project/view/exportdialogmodel.cpp @@ -406,6 +406,21 @@ void ExportDialogModel::setPdfResolution(const int& resolution) emit pdfResolutionChanged(resolution); } +bool ExportDialogModel::pdfTransparentBackground() const +{ + return imageExportConfiguration()->exportPdfWithTransparentBackground(); +} + +void ExportDialogModel::setPdfTransparentBackground(const bool& transparent) +{ + if (transparent == pdfTransparentBackground()) { + return; + } + + imageExportConfiguration()->setExportPdfWithTransparentBackground(transparent); + emit pdfTransparentBackgroundChanged(transparent); +} + int ExportDialogModel::pngResolution() const { return imageExportConfiguration()->exportPngDpiResolution(); diff --git a/src/project/view/exportdialogmodel.h b/src/project/view/exportdialogmodel.h index f883132215d01..13724d7bdef76 100644 --- a/src/project/view/exportdialogmodel.h +++ b/src/project/view/exportdialogmodel.h @@ -67,6 +67,9 @@ class ExportDialogModel : public QAbstractListModel, public muse::async::Asyncab Q_PROPERTY(int selectedUnitType READ selectedUnitType WRITE setUnitType NOTIFY selectedUnitTypeChanged) Q_PROPERTY(int pdfResolution READ pdfResolution WRITE setPdfResolution NOTIFY pdfResolutionChanged) + Q_PROPERTY( + bool pdfTransparentBackground READ pdfTransparentBackground WRITE setPdfTransparentBackground NOTIFY pdfTransparentBackgroundChanged) + Q_PROPERTY(int pngResolution READ pngResolution WRITE setPngResolution NOTIFY pngResolutionChanged) Q_PROPERTY( bool pngTransparentBackground READ pngTransparentBackground WRITE setPngTransparentBackground NOTIFY pngTransparentBackgroundChanged) @@ -117,6 +120,9 @@ class ExportDialogModel : public QAbstractListModel, public muse::async::Asyncab int pdfResolution() const; void setPdfResolution(const int& resolution); + bool pdfTransparentBackground() const; + void setPdfTransparentBackground(const bool& transparent); + int pngResolution() const; void setPngResolution(const int& resolution); @@ -167,6 +173,8 @@ class ExportDialogModel : public QAbstractListModel, public muse::async::Asyncab void selectedUnitTypeChanged(project::INotationWriter::UnitType newUnitType); void pdfResolutionChanged(int resolution); + void pdfTransparentBackgroundChanged(bool transparent); + void pngResolutionChanged(int resolution); void pngTransparentBackgroundChanged(bool transparent);