Skip to content

Commit

Permalink
Fix #293370: Allow user to customize background when exporting as PDF…
Browse files Browse the repository at this point in the history
…\PNG\SVG
  • Loading branch information
sidharth-anand committed Feb 12, 2021
1 parent 84f6aa7 commit 6a5d5ba
Show file tree
Hide file tree
Showing 6 changed files with 664 additions and 306 deletions.
2 changes: 2 additions & 0 deletions global/settings/types/preferencekeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
48 changes: 42 additions & 6 deletions mscore/exportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -280,16 +302,24 @@ 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);
mp3BitRate->setVisible(index == 3);
mp3kBitSLabel->setVisible(index == 3);
}
else // And others have their own page again
pageStack->setCurrentIndex(index - 3);
pageStack->setCurrentIndex(index - 5);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions mscore/exportdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ExportDialog : public AbstractDialog, public Ui::ExportDialog {
Q_OBJECT

QButtonGroup* pdfSeparateOrSingleFiles;
QButtonGroup* exportBackgroundOption;

Score* cs = nullptr;

Expand Down
Loading

0 comments on commit 6a5d5ba

Please sign in to comment.