|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: GPL-3.0-only |
| 3 | + * MuseScore-Studio-CLA-applies |
| 4 | + * |
| 5 | + * MuseScore Studio |
| 6 | + * Music Composition & Notation |
| 7 | + * |
| 8 | + * Copyright (C) 2021 MuseScore Limited |
| 9 | + * |
| 10 | + * This program is free software: you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU General Public License version 3 as |
| 12 | + * published by the Free Software Foundation. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 21 | + */ |
| 22 | + |
| 23 | +#include "pagebreaksdialog.h" |
| 24 | + |
| 25 | +using namespace mu::notation; |
| 26 | + |
| 27 | +static constexpr int DEFAULT_INTERVAL = 4; |
| 28 | + |
| 29 | +//--------------------------------------------------------- |
| 30 | +// PageBreaksDialog |
| 31 | +//--------------------------------------------------------- |
| 32 | + |
| 33 | +PageBreaksDialog::PageBreaksDialog(QWidget* parent) |
| 34 | + : QDialog(parent), muse::Injectable(muse::iocCtxForQWidget(this)) |
| 35 | +{ |
| 36 | + setupUi(this); |
| 37 | + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); |
| 38 | + intervalButton->setChecked(true); |
| 39 | + intervalBox->setValue(DEFAULT_INTERVAL); |
| 40 | + |
| 41 | + //: `%1` will be replaced with a number input field. |
| 42 | + //: Text before it will appear before that number field, text after will appear after the field. |
| 43 | + QString text = muse::qtrc("notation/add-remove-system-breaks", "Break pages every %1 systems"); |
| 44 | + QStringList pieces = text.split(QStringLiteral("%1")); |
| 45 | + |
| 46 | + IF_ASSERT_FAILED(pieces.size() >= 2) { |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + QString part1 = pieces[0].trimmed(); |
| 51 | + QString part2 = pieces[1].trimmed(); |
| 52 | + intervalButton->setText(part1); |
| 53 | + intervalLabel2->setText(part2); |
| 54 | +} |
| 55 | + |
| 56 | +//--------------------------------------------------------- |
| 57 | +// accept |
| 58 | +//--------------------------------------------------------- |
| 59 | + |
| 60 | +void PageBreaksDialog::accept() |
| 61 | +{ |
| 62 | + INotationPtr notation = context()->currentNotation(); |
| 63 | + if (!notation) { |
| 64 | + return; |
| 65 | + } |
| 66 | + |
| 67 | + INotationInteractionPtr interaction = notation->interaction(); |
| 68 | + |
| 69 | + int interval = intervalButton->isChecked() ? intervalBox->value() : 0; |
| 70 | + AddRemovePageBreaksType intervalType = AddRemovePageBreaksType::SystemsInterval; |
| 71 | + |
| 72 | + if (removeButton->isChecked()) { |
| 73 | + intervalType = AddRemovePageBreaksType::None; |
| 74 | + } else if (pageBreaksButton->isChecked()) { |
| 75 | + intervalType = AddRemovePageBreaksType::AfterEachPage; |
| 76 | + } |
| 77 | + |
| 78 | + interaction->addRemovePageBreaks(intervalType, interval); |
| 79 | + |
| 80 | + if (_allSelected) { |
| 81 | + interaction->clearSelection(); |
| 82 | + } |
| 83 | + |
| 84 | + QDialog::accept(); |
| 85 | +} |
| 86 | + |
| 87 | +//--------------------------------------------------------- |
| 88 | +// showEvent |
| 89 | +//--------------------------------------------------------- |
| 90 | + |
| 91 | +void PageBreaksDialog::showEvent(QShowEvent* ev) |
| 92 | +{ |
| 93 | + INotationPtr notation = context()->currentNotation(); |
| 94 | + if (!notation) { |
| 95 | + return; |
| 96 | + } |
| 97 | + |
| 98 | + INotationInteractionPtr interaction = notation->interaction(); |
| 99 | + INotationSelectionPtr selection = interaction->selection(); |
| 100 | + |
| 101 | + if (!selection->isRange()) { |
| 102 | + interaction->selectAll(); |
| 103 | + _allSelected = true; |
| 104 | + } else { |
| 105 | + _allSelected = false; |
| 106 | + } |
| 107 | + |
| 108 | + QWidget::showEvent(ev); |
| 109 | +} |
0 commit comments