Line data Source code
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 and others
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 "stafftextpropertiesdialog.h"
24 :
25 : #include "engraving/dom/masterscore.h"
26 : #include "engraving/dom/score.h"
27 : #include "engraving/dom/staff.h"
28 : #include "engraving/dom/stafftextbase.h"
29 :
30 : #include "notation/inotation.h"
31 : #include "notation/inotationinteraction.h"
32 : #include "notation/inotationundostack.h"
33 :
34 : #include "ui/view/widgetstatestore.h"
35 :
36 : #include "translation.h"
37 :
38 : using namespace mu::notation;
39 : using namespace mu::engraving;
40 :
41 : static const QString STAFF_TEXT_PROPERTIES_DIALOG_NAME("StaffTextPropertiesDialog");
42 :
43 0 : StaffTextPropertiesDialog::StaffTextPropertiesDialog(QWidget* parent)
44 0 : : muse::ui::WidgetDialog(parent)
45 : {
46 0 : setObjectName(STAFF_TEXT_PROPERTIES_DIALOG_NAME);
47 0 : setupUi(this);
48 0 : }
49 :
50 0 : StaffTextPropertiesDialog::~StaffTextPropertiesDialog()
51 : {
52 0 : delete m_staffText;
53 0 : }
54 :
55 0 : void StaffTextPropertiesDialog::componentComplete()
56 : {
57 0 : const INotationPtr notation = projectSession()->currentNotation();
58 0 : const INotationInteractionPtr interaction = notation ? notation->interaction() : nullptr;
59 0 : EngravingItem* element = interaction ? interaction->hitElementContext().element : nullptr;
60 0 : StaffTextBase* st = element && element->isStaffTextBase() ? toStaffTextBase(element) : nullptr;
61 :
62 0 : if (!st) {
63 0 : return;
64 : }
65 :
66 0 : m_originStaffText = st;
67 :
68 0 : if (st->systemFlag()) {
69 0 : setWindowTitle(muse::qtrc("notation/stafftextproperties", "System text properties"));
70 : } else {
71 0 : setWindowTitle(muse::qtrc("notation/stafftextproperties", "Staff text properties"));
72 : }
73 :
74 0 : setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
75 0 : m_staffText = static_cast<StaffTextBase*>(st->clone());
76 :
77 0 : if (m_staffText->swing()) {
78 0 : setSwingBox->setChecked(true);
79 0 : if (m_staffText->swingParameters().swingUnit == Constants::DIVISION / 2) {
80 0 : swingBox->setEnabled(true);
81 0 : swingEighth->setChecked(true);
82 0 : swingBox->setValue(m_staffText->swingParameters().swingRatio);
83 0 : } else if (m_staffText->swingParameters().swingUnit == Constants::DIVISION / 4) {
84 0 : swingBox->setEnabled(true);
85 0 : swingSixteenth->setChecked(true);
86 0 : swingBox->setValue(m_staffText->swingParameters().swingRatio);
87 0 : } else if (m_staffText->swingParameters().swingUnit == 0) {
88 0 : swingBox->setEnabled(false);
89 0 : swingOff->setChecked(true);
90 0 : swingBox->setValue(m_staffText->swingParameters().swingRatio);
91 : }
92 : }
93 :
94 0 : connect(swingOff, &QRadioButton::toggled, this, &StaffTextPropertiesDialog::setSwingControls);
95 0 : connect(swingEighth, &QRadioButton::toggled, this, &StaffTextPropertiesDialog::setSwingControls);
96 0 : connect(swingSixteenth, &QRadioButton::toggled, this, &StaffTextPropertiesDialog::setSwingControls);
97 :
98 0 : connect(this, &QDialog::accepted, this, &StaffTextPropertiesDialog::saveValues);
99 0 : }
100 :
101 0 : void StaffTextPropertiesDialog::showEvent(QShowEvent* event)
102 : {
103 0 : muse::ui::WidgetStateStore::restoreGeometry(this);
104 0 : QDialog::showEvent(event);
105 0 : }
106 :
107 0 : void StaffTextPropertiesDialog::hideEvent(QHideEvent* event)
108 : {
109 0 : muse::ui::WidgetStateStore::saveGeometry(this);
110 0 : QDialog::hideEvent(event);
111 0 : }
112 :
113 : //---------------------------------------------------------
114 : // setSwingControls
115 : //---------------------------------------------------------
116 :
117 0 : void StaffTextPropertiesDialog::setSwingControls(bool checked)
118 : {
119 0 : if (!checked) {
120 0 : return;
121 : }
122 0 : if (swingOff->isChecked()) {
123 0 : swingBox->setEnabled(false);
124 0 : } else if (swingEighth->isChecked()) {
125 0 : swingBox->setEnabled(true);
126 0 : } else if (swingSixteenth->isChecked()) {
127 0 : swingBox->setEnabled(true);
128 : }
129 : }
130 :
131 0 : void StaffTextPropertiesDialog::saveValues()
132 : {
133 0 : if (setSwingBox->isChecked()) {
134 0 : m_staffText->setSwing(true);
135 0 : if (swingOff->isChecked()) {
136 0 : m_staffText->setSwingParameters(0, swingBox->value());
137 0 : swingBox->setEnabled(false);
138 0 : } else if (swingEighth->isChecked()) {
139 0 : m_staffText->setSwingParameters(Constants::DIVISION / 2, swingBox->value());
140 0 : swingBox->setEnabled(true);
141 0 : } else if (swingSixteenth->isChecked()) {
142 0 : m_staffText->setSwingParameters(Constants::DIVISION / 4, swingBox->value());
143 0 : swingBox->setEnabled(true);
144 : }
145 : } else {
146 0 : m_staffText->setSwing(false);
147 : }
148 :
149 0 : INotationUndoStackPtr stack = undoStack();
150 0 : IF_ASSERT_FAILED(stack) {
151 0 : return;
152 : }
153 :
154 0 : Score* score = m_originStaffText->score();
155 0 : StaffTextBase* nt = toStaffTextBase(m_staffText->clone());
156 0 : nt->setScore(score);
157 :
158 0 : stack->prepareChanges(muse::TranslatableString("undoableAction", "Edit staff text properties"));
159 0 : score->undoChangeElement(m_originStaffText, nt);
160 0 : score->masterScore()->updateChannel();
161 0 : score->updateSwing();
162 0 : stack->commitChanges();
163 0 : }
164 :
165 0 : INotationUndoStackPtr StaffTextPropertiesDialog::undoStack() const
166 : {
167 0 : INotationPtr notation = projectSession()->currentNotation();
168 0 : return notation ? notation->undoStack() : nullptr;
169 0 : }
|