LCOV - code coverage report
Current view: top level - src/notationscene/widgets - tupletdialog.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 86 0
Test Date: 2026-11-19 04:14:36

            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 "tupletdialog.h"
      24              : 
      25              : #include "notation/inotation.h"
      26              : #include "notation/inotationstyle.h"
      27              : #include "notationcommands.h"
      28              : 
      29              : #include "ui/view/widgetstatestore.h"
      30              : 
      31              : using namespace mu::notation;
      32              : using namespace mu::engraving;
      33              : using namespace muse::ui;
      34              : using namespace muse;
      35              : using namespace muse::rcommand;
      36              : 
      37              : //---------------------------------------------------------
      38              : //   TupletDialog
      39              : //---------------------------------------------------------
      40              : 
      41            0 : TupletDialog::TupletDialog(QWidget* parent)
      42            0 :     : muse::ui::WidgetDialog(parent)
      43              : {
      44            0 :     setObjectName("TupletDialog");
      45            0 :     setupUi(this);
      46            0 :     setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
      47            0 : }
      48              : 
      49            0 : void TupletDialog::componentComplete()
      50              : {
      51            0 :     connect(buttonBox, &QDialogButtonBox::clicked, this, &TupletDialog::bboxClicked);
      52              : 
      53            0 :     defaultToStyleSettings();
      54              : 
      55            0 :     const TupletSelectedDuration selectedDurationAsPreference = configuration()->tupletCommandsSelectedDurationAs();
      56            0 :     subdivision->setChecked(selectedDurationAsPreference == TupletSelectedDuration::SUBDIVISION);
      57            0 :     tupletLength->setChecked(selectedDurationAsPreference == TupletSelectedDuration::TUPLET_LENGTH);
      58              : 
      59            0 :     numberGroupBox->setAccessibleName(formatGroupBox->title() + " " + numberGroupBox->title());
      60            0 :     bracketGroupBox->setAccessibleName(formatGroupBox->title() + " " + bracketGroupBox->title());
      61            0 :     subdivision->setAccessibleName(useSelectedDurationAsLabel->text() + " " + subdivision->text());
      62            0 :     tupletLength->setAccessibleName(useSelectedDurationAsLabel->text() + " " + tupletLength->text());
      63              : 
      64              :     //! NOTE: It is necessary for the correct start of navigation in the dialog
      65            0 :     setFocus();
      66            0 : }
      67              : 
      68              : //---------------------------------------------------------
      69              : //   defaultToStyleSettings
      70              : //---------------------------------------------------------
      71              : 
      72            0 : void TupletDialog::defaultToStyleSettings()
      73              : {
      74            0 :     mu::engraving::TupletNumberType nt = mu::engraving::TupletNumberType(style()->styleValue(mu::engraving::Sid::tupletNumberType).toInt());
      75            0 :     number->setChecked(nt == mu::engraving::TupletNumberType::SHOW_NUMBER);
      76            0 :     relation->setChecked(nt == mu::engraving::TupletNumberType::SHOW_RELATION);
      77            0 :     noNumber->setChecked(nt == mu::engraving::TupletNumberType::NO_TEXT);
      78              : 
      79            0 :     mu::engraving::TupletBracketType bt = mu::engraving::TupletBracketType(style()->styleValue(
      80            0 :                                                                                mu::engraving::Sid::tupletBracketType).toInt());
      81            0 :     autoBracket->setChecked(bt == mu::engraving::TupletBracketType::AUTO_BRACKET);
      82            0 :     bracket->setChecked(bt == mu::engraving::TupletBracketType::SHOW_BRACKET);
      83            0 :     noBracket->setChecked(bt == mu::engraving::TupletBracketType::SHOW_NO_BRACKET);
      84            0 : }
      85              : 
      86            0 : TupletNumberType TupletDialog::numberType() const
      87              : {
      88            0 :     if (number->isChecked()) {
      89            0 :         return TupletNumberType::SHOW_NUMBER;
      90            0 :     } else if (relation->isChecked()) {
      91            0 :         return TupletNumberType::SHOW_RELATION;
      92            0 :     } else if (noNumber->isChecked()) {
      93            0 :         return TupletNumberType::NO_TEXT;
      94              :     }
      95              : 
      96            0 :     return TupletNumberType::SHOW_NUMBER;
      97              : }
      98              : 
      99            0 : TupletBracketType TupletDialog::bracketType() const
     100              : {
     101            0 :     if (autoBracket->isChecked()) {
     102            0 :         return TupletBracketType::AUTO_BRACKET;
     103            0 :     } else if (bracket->isChecked()) {
     104            0 :         return TupletBracketType::SHOW_BRACKET;
     105            0 :     } else if (noBracket->isChecked()) {
     106            0 :         return TupletBracketType::SHOW_NO_BRACKET;
     107              :     }
     108              : 
     109            0 :     return TupletBracketType::AUTO_BRACKET;
     110              : }
     111              : 
     112            0 : TupletSelectedDuration TupletDialog::selectedDurationAs() const
     113              : {
     114            0 :     if (tupletLength->isChecked()) {
     115            0 :         return TupletSelectedDuration::TUPLET_LENGTH;
     116              :     }
     117              : 
     118            0 :     return TupletSelectedDuration::SUBDIVISION;
     119              : }
     120              : 
     121            0 : void TupletDialog::showEvent(QShowEvent* event)
     122              : {
     123            0 :     WidgetStateStore::restoreGeometry(this);
     124            0 :     QDialog::showEvent(event);
     125            0 : }
     126              : 
     127            0 : void TupletDialog::hideEvent(QHideEvent* event)
     128              : {
     129            0 :     WidgetStateStore::saveGeometry(this);
     130            0 :     QWidget::hideEvent(event);
     131            0 : }
     132              : 
     133            0 : INotationStylePtr TupletDialog::style() const
     134              : {
     135            0 :     return notation() ? notation()->style() : nullptr;
     136              : }
     137              : 
     138            0 : INotationPtr TupletDialog::notation() const
     139              : {
     140            0 :     return projectSession()->currentNotation();
     141              : }
     142              : 
     143            0 : void TupletDialog::apply()
     144              : {
     145            0 :     AddTupletCommand cmd;
     146            0 :     cmd.ratio = Fraction(actualNotes->value(), normalNotes->value()).toString().toStdString();
     147            0 :     cmd.numberType = numberType();
     148            0 :     cmd.bracketType = bracketType();
     149            0 :     cmd.selectedDurationAs = selectedDurationAs();
     150            0 :     cmd.autoBaseLen = false;
     151              : 
     152            0 :     dispatcher()->dispatch(cmd);
     153            0 : }
     154              : 
     155            0 : void TupletDialog::bboxClicked(QAbstractButton* button)
     156              : {
     157            0 :     QDialogButtonBox::ButtonRole br = buttonBox->buttonRole(button);
     158            0 :     switch (br) {
     159            0 :     case QDialogButtonBox::ApplyRole:
     160            0 :         apply();
     161            0 :         break;
     162            0 :     case QDialogButtonBox::AcceptRole:
     163            0 :         apply();
     164            0 :         done(1);
     165            0 :         break;
     166            0 :     case QDialogButtonBox::RejectRole:
     167            0 :         done(0);
     168            0 :         break;
     169            0 :     default:
     170            0 :         break;
     171              :     }
     172            0 : }
        

Generated by: LCOV version 2.0-1