diff --git a/global/settings/types/preferencekeys.h b/global/settings/types/preferencekeys.h index 56d79b4ed1f68..6c9eb10c0cf59 100644 --- a/global/settings/types/preferencekeys.h +++ b/global/settings/types/preferencekeys.h @@ -66,6 +66,8 @@ #define PREF_EXPORT_PDF_DPI "export/pdf/dpi" #define PREF_EXPORT_PNG_RESOLUTION "export/png/resolution" #define PREF_EXPORT_PNG_USETRANSPARENCY "export/png/useTransparency" +#define PREF_EXPORT_BG_STYLE "export/bg/style" +#define PREF_EXPORT_BG_CUSTOM_COLOR "export/bg/customcolor" #define PREF_IMPORT_GUITARPRO_CHARSET "import/guitarpro/charset" #define PREF_IMPORT_MUSICXML_IMPORTBREAKS "import/musicXML/importBreaks" #define PREF_IMPORT_MUSICXML_IMPORTLAYOUT "import/musicXML/importLayout" diff --git a/mscore/exportdialog.cpp b/mscore/exportdialog.cpp index 7d4a3b101aa0b..ba639c975f499 100644 --- a/mscore/exportdialog.cpp +++ b/mscore/exportdialog.cpp @@ -68,6 +68,11 @@ ExportDialog::ExportDialog(Score* s, QWidget* parent) pdfSeparateOrSingleFiles->addButton(pdfSeparateFilesRadioButton, 0); pdfSeparateOrSingleFiles->addButton(pdfOneFileRadioButton, 1); + exportBackgroundOption = new QButtonGroup(this); + exportBackgroundOption->addButton(transparentBackgroundRadioButton, 0); + exportBackgroundOption->addButton(scoreBackgroundRadioButton, 1); + exportBackgroundOption->addButton(customBackgroundRadioButton, 2); + #if !defined(HAS_AUDIOFILE) || !defined(USE_LAME) // Disable audio options that are unavailable // Source: https://stackoverflow.com/a/38915478 @@ -89,8 +94,13 @@ ExportDialog::ExportDialog(Score* s, QWidget* parent) fileTypeComboBox->setCurrentIndex(0); pageStack->setCurrentIndex(0); + pngDpiWidget->setVisible(false); + pngFileOptionWidget->setVisible(false); + svgFileOptionWidget->setVisible(false); pdfSeparateFilesRadioButton->setChecked(true); + transparentBackgroundRadioButton->setChecked(true); + customBackgroundColorLabel->setDisabled(true); audioSampleRate->clear(); audioSampleRate->addItem(tr("32000"), 32000); @@ -156,7 +166,19 @@ void ExportDialog::loadValues() pdfDpiSpinbox->setValue(preferences.getInt(PREF_EXPORT_PDF_DPI)); pngDpiSpinbox->setValue(preferences.getDouble(PREF_EXPORT_PNG_RESOLUTION)); - pngTransparentBackgroundCheckBox->setChecked(preferences.getBool(PREF_EXPORT_PNG_USETRANSPARENCY)); + + switch (preferences.getInt(PREF_EXPORT_BG_STYLE)) { + case 0: + transparentBackgroundRadioButton->setChecked(true); + break; + case 1: + scoreBackgroundRadioButton->setChecked(true); + break; + case 2: + customBackgroundRadioButton->setChecked(true); + break; + } + customBackgroundColorLabel->setColor(preferences.getColor(PREF_EXPORT_BG_CUSTOM_COLOR)); audioNormaliseCheckBox->setChecked(preferences.getBool(PREF_EXPORT_AUDIO_NORMALIZE)); int audioSampleRateIndex = audioSampleRate->findData(preferences.getInt(PREF_EXPORT_AUDIO_SAMPLERATE)); @@ -280,8 +302,16 @@ void ExportDialog::setOkButtonEnabled() void ExportDialog::fileTypeChosen(int index) { - if (index <= 2) // Pdf, png and svg - pageStack->setCurrentIndex(index); + if (index <= 2) { // Pdf, png and svg + pageStack->setCurrentWidget(visualPage); + pdfDpiWidget->setVisible(index == 0); + pdfFileOptionWidget->setVisible(index == 0); + + pngDpiWidget->setVisible(index == 1); + pngFileOptionWidget->setVisible(index == 1); + + svgFileOptionWidget->setVisible(index == 2); + } else if (index <= 6) { // Audio formats share their page (because they share many settings) pageStack->setCurrentWidget(audioPage); mp3BitRateLabel->setVisible(index == 3); @@ -289,7 +319,7 @@ void ExportDialog::fileTypeChosen(int index) mp3kBitSLabel->setVisible(index == 3); } else // And others have their own page again - pageStack->setCurrentIndex(index - 3); + pageStack->setCurrentIndex(index - 5); } //--------------------------------------------------------- @@ -377,6 +407,14 @@ void ExportDialog::accept() QString saveFormat; int currentIndex = fileTypeComboBox->currentIndex(); + + if (currentIndex <= 2) { + if (exportBackgroundOption->checkedId() != preferences.getInt(PREF_EXPORT_BG_STYLE)) + preferences.setPreference(PREF_EXPORT_BG_STYLE, exportBackgroundOption->checkedId()); + if (customBackgroundColorLabel->color() != preferences.getColor(PREF_EXPORT_BG_CUSTOM_COLOR)) + preferences.setPreference(PREF_EXPORT_BG_CUSTOM_COLOR, customBackgroundColorLabel->color()); + } + if (currentIndex == 0) { saveFormat = "pdf"; if (pdfDpiSpinbox->value() != preferences.getInt(PREF_EXPORT_PDF_DPI)) @@ -385,8 +423,6 @@ void ExportDialog::accept() saveFormat = "png"; if (pngDpiSpinbox->value() != preferences.getDouble(PREF_EXPORT_PNG_RESOLUTION)) preferences.setPreference(PREF_EXPORT_PNG_RESOLUTION, pngDpiSpinbox->value()); - if (pngTransparentBackgroundCheckBox->isChecked() != preferences.getBool(PREF_EXPORT_PNG_USETRANSPARENCY)) - preferences.setPreference(PREF_EXPORT_PNG_USETRANSPARENCY, pngTransparentBackgroundCheckBox->isChecked()); } else if (currentIndex == 2) { saveFormat = "svg"; } else if (currentIndex <= 6) { // The audio formats share some settings diff --git a/mscore/exportdialog.h b/mscore/exportdialog.h index 5eaff74ed03f2..87aced5d72985 100644 --- a/mscore/exportdialog.h +++ b/mscore/exportdialog.h @@ -54,6 +54,7 @@ class ExportDialog : public AbstractDialog, public Ui::ExportDialog { Q_OBJECT QButtonGroup* pdfSeparateOrSingleFiles; + QButtonGroup* exportBackgroundOption; Score* cs = nullptr; diff --git a/mscore/exportdialog.ui b/mscore/exportdialog.ui index f2d063799bf2c..911c248362cfd 100644 --- a/mscore/exportdialog.ui +++ b/mscore/exportdialog.ui @@ -9,8 +9,8 @@ 0 0 - 691 - 383 + 757 + 415 @@ -23,108 +23,55 @@ Export - - - - 8 - - - 8 + + 0 + + + 0 + + + 0 + + + 0 + + + + + What to export - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - Export To: - - - - - - - - PDF File - - - - - PNG Images - - - - - SVG Images - - - - - MP3 Audio - - - - - WAV Audio + + + + + Select all - - - - FLAC Audio + + Select the score and all parts - - - OGG Audio + Select all - - - - MIDI + + + + + + Select nothing - - - - MusicXML + + Select nothing - - - Uncompressed MuseScore File + Clear selection - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - + + + + + + + @@ -135,190 +82,370 @@ - 0 + 1 - - - - - - Resolution: - - - - - - - - - Resolution DPI - - - Choose resolution DPI - - - DPI - - - 75 - - - 2400 - - - 300 - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - - - Export each score as a separate file - - - - - - - All scores combined into one file - - - - - - - - - - - Resolution: - + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 0 + + + + Resolution: + + + + + + + + 0 + 0 + + + + + 62 + 0 + + + + DPI + + + + + + 720 + + + 300 + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + - - - - - - Resolution DPI - - - Choose resolution DPI - - - DPI - - - 32 - - - 5000 - - - 360 - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - - Transparent background - - - Transparent background - + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 0 + + + + Resolution: + + + + + + + + 0 + 0 + + + + + 62 + 0 + + + + DPI + + + + + + 720 + + + 300 + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + - - - - Qt::Vertical - - + + + 0 0 - + + + 0 + + + + + + 0 + 0 + + + + Export each score + + + + + + + As a separate file + + + + + + + Combined into a single file + + + + + - - + + - + 0 0 - - Each page of the selected scores will be exported as a separate PNG file. - - - true + + + 0 + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 0 + 0 + + + + + + + + Each page of the selected scores will be exported as a separate PNG file. + + + Qt::AlignCenter + + + + - - - - - - - - Qt::Vertical - - + + + 0 0 - + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + Each page of the selected scores will be exported as a separate SVG file. + + + Qt::AlignCenter + + + + + - - - - - 0 - 0 - - - - Each page of the selected scores will be exported as a separate SVG file. - - - true + + + + + 0 + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Export with transparent background + + + + + + + Export with background present in score + + + + + + + Export with custom background color + + + + + + + + 0 + 0 + + + + Background Options: + + + + + + + + + + + @@ -776,50 +903,133 @@ - - - - What to export + + + + + 0 + 0 + - - - - - Select all + + + 0 + 30 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + false + + + + + + + 8 + + + 8 + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Export To: + + + + + + + + PDF File - - Select the score and all parts + + + + PNG Images + + - Select all + SVG Images - - - - - - Select nothing + + + + MP3 Audio - - Select nothing + + + + WAV Audio + + - Clear selection + FLAC Audio - - - - - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + OGG Audio + + + + + MIDI + + + + + MusicXML + + + + + Uncompressed MuseScore File + + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + @@ -832,6 +1042,12 @@ clicked() + + Awl::ColorLabel + QPushButton +
awl/colorlabel.h
+ 1 +
@@ -900,34 +1116,34 @@ - musicxmlExportAllBreaksLabel + musicxmlExportAllLayoutLabel clicked() - musicxmlExportAllBreaks + musicxmlExportAllLayout animateClick() 563 - 227 + 203 412 - 228 + 204 - musicxmlExportAllLayoutLabel + musicxmlExportAllBreaksLabel clicked() - musicxmlExportAllLayout + musicxmlExportAllBreaks animateClick() 563 - 203 + 227 412 - 204 + 228 @@ -947,6 +1163,22 @@ + + customBackgroundRadioButton + toggled(bool) + customBackgroundColorLabel + setEnabled(bool) + + + 495 + 212 + + + 673 + 212 + + + musicxmlExportNoBreaksLabel clicked() diff --git a/mscore/file.cpp b/mscore/file.cpp index 5c9c424a96a1c..4d5f7150bd3b8 100644 --- a/mscore/file.cpp +++ b/mscore/file.cpp @@ -2107,10 +2107,31 @@ bool MuseScore::savePdf(Score* cs_, QPrinter& printer) const QList pl = cs_->pages(); int pages = pl.size(); bool firstPage = true; + + const QRect fillRect(0.0, 0.0, size.width() * DPI, size.height() * DPI); + int exportBgStyle = preferences.getInt(PREF_EXPORT_BG_STYLE); + bool useFgColor = preferences.getBool(PREF_UI_CANVAS_FG_USECOLOR); + const QColor fgColor = preferences.getColor(PREF_UI_CANVAS_FG_COLOR); + const QColor customColor = preferences.getColor(PREF_EXPORT_BG_CUSTOM_COLOR); + const QPixmap fgPixMap(preferences.getString(PREF_UI_CANVAS_FG_WALLPAPER)); + for (int n = 0; n < pages; ++n) { if (!firstPage) printer.newPage(); firstPage = false; + switch (exportBgStyle) { + case 1: + if (useFgColor) + p.fillRect(fillRect, fgColor); + else + p.drawTiledPixmap(fillRect, fgPixMap, fillRect.topLeft()); + break; + case 2: + p.fillRect(fillRect, customColor); + break; + default: + break; + } cs_->print(&p, n); } p.end(); @@ -2161,6 +2182,14 @@ bool MuseScore::savePdf(QList cs_, const QString& saveName) double pr = MScore::pixelRatio; bool firstPage = true; + + const QRect fillRect(0.0, 0.0, size.width() * DPI, size.height() * DPI); + int exportBgStyle = preferences.getInt(PREF_EXPORT_BG_STYLE); + bool useFgColor = preferences.getBool(PREF_UI_CANVAS_FG_USECOLOR); + const QColor fgColor = preferences.getColor(PREF_UI_CANVAS_FG_COLOR); + const QColor customColor = preferences.getColor(PREF_EXPORT_BG_CUSTOM_COLOR); + const QPixmap fgPixMap(preferences.getString(PREF_UI_CANVAS_FG_WALLPAPER)); + for (Score* s : cs_) { LayoutMode layoutMode = s->layoutMode(); if (layoutMode != LayoutMode::PAGE) { @@ -2187,6 +2216,21 @@ bool MuseScore::savePdf(QList cs_, const QString& saveName) if (!firstPage) printer.newPage(); firstPage = false; + + switch (exportBgStyle) { + case 1: + if (useFgColor) + p.fillRect(fillRect, fgColor); + else + p.drawTiledPixmap(fillRect, fgPixMap, fillRect.topLeft()); + break; + case 2: + p.fillRect(fillRect, customColor); + break; + default: + break; + } + s->print(&p, n); } MScore::pixelRatio = pr; @@ -2654,8 +2698,8 @@ bool MuseScore::savePng(Score* score, const QString& name, SaveReplacePolicy* re bool MuseScore::savePng(Score* score, QIODevice* device, int pageNumber, bool drawPageBackground) { const bool screenshot = false; - const bool transparent = preferences.getBool(PREF_EXPORT_PNG_USETRANSPARENCY) && !drawPageBackground; const double convDpi = preferences.getDouble(PREF_EXPORT_PNG_RESOLUTION); + //TODO: fix transparency const int localTrimMargin = trimMargin; const QImage::Format format = QImage::Format_ARGB32_Premultiplied; @@ -2686,7 +2730,31 @@ bool MuseScore::savePng(Score* score, QIODevice* device, int pageNumber, bool dr printer.setDotsPerMeterX(lrint((convDpi * 1000) / INCH)); printer.setDotsPerMeterY(lrint((convDpi * 1000) / INCH)); - printer.fill(transparent ? 0 : 0xffffffff); + int exportBgStyle = preferences.getInt(PREF_EXPORT_BG_STYLE); + bool useFgColor = preferences.getBool(PREF_UI_CANVAS_FG_USECOLOR); + const QColor fgColor = preferences.getColor(PREF_UI_CANVAS_FG_COLOR); + const QColor customColor = preferences.getColor(PREF_EXPORT_BG_CUSTOM_COLOR); + const QPixmap fgPixMap(preferences.getString(PREF_UI_CANVAS_FG_WALLPAPER)); + + switch (exportBgStyle) { + case 0: + printer.fill(0); + break; + case 1: + if (useFgColor) + printer.fill(fgColor); + else { + QPainter painter(&printer); + painter.drawTiledPixmap(printer.rect(), fgPixMap, printer.rect().topLeft()); + } + break; + case 2: + printer.fill(customColor); + break; + default: + break; + } + double mag_ = convDpi / DPI; MScore::pixelRatio = 1.0 / mag_; @@ -2704,7 +2772,7 @@ bool MuseScore::savePng(Score* score, QIODevice* device, int pageNumber, bool dr //convert to grayscale & respect alpha QVector colorTable; colorTable.push_back(QColor(0, 0, 0, 0).rgba()); - if (!transparent) { + if (exportBgStyle != 0) { for (int i = 1; i < 256; i++) colorTable.push_back(QColor(i, i, i).rgb()); } @@ -2964,8 +3032,25 @@ bool MuseScore::saveSvg(Score* score, QIODevice* device, int pageNumber, bool dr p.translate(-r.topLeft()); MScore::pixelRatio = DPI / printer.logicalDpiX(); - if (drawPageBackground) - p.fillRect(r, Qt::white); + int exportBgStyle = preferences.getInt(PREF_EXPORT_BG_STYLE); + bool useFgColor = preferences.getBool(PREF_UI_CANVAS_FG_USECOLOR); + const QColor fgColor = preferences.getColor(PREF_UI_CANVAS_FG_COLOR); + const QColor customColor = preferences.getColor(PREF_EXPORT_BG_CUSTOM_COLOR); + const QPixmap fgPixMap(preferences.getString(PREF_UI_CANVAS_FG_WALLPAPER)); + + switch (exportBgStyle) { + case 1: + if (useFgColor) + p.fillRect(r, fgColor); + else + p.drawTiledPixmap(r, fgPixMap, r.topLeft()); + break; + case 2: + p.fillRect(r, customColor); + break; + default: + break; + } // 1st pass: StaffLines for (System* s : page->systems()) { diff --git a/mscore/preferences.cpp b/mscore/preferences.cpp index 8880b041d6143..1d8cdd02736fd 100644 --- a/mscore/preferences.cpp +++ b/mscore/preferences.cpp @@ -169,6 +169,8 @@ void Preferences::init(bool storeInMemoryOnly) {PREF_EXPORT_PDF_DPI, new IntPreference(DPI, false)}, {PREF_EXPORT_PNG_RESOLUTION, new DoublePreference(DPI, false)}, {PREF_EXPORT_PNG_USETRANSPARENCY, new BoolPreference(true, false)}, + {PREF_EXPORT_BG_STYLE, new IntPreference(1, false)}, + {PREF_EXPORT_BG_CUSTOM_COLOR, new ColorPreference(QColor(0xffffff), false)}, {PREF_IMPORT_GUITARPRO_CHARSET, new StringPreference("UTF-8", false)}, {PREF_IMPORT_MUSICXML_IMPORTBREAKS, new BoolPreference(true, false)}, {PREF_IMPORT_MUSICXML_IMPORTLAYOUT, new BoolPreference(true, false)},