LCOV - code coverage report
Current view: top level - src/notationscene/widgets - tupletdialog.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 82 0
Test Date: 2026-11-05 04:07:02

            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 :     numberGroupBox->setAccessibleName(formatGroupBox->title() + " " + numberGroupBox->title());
      56            0 :     bracketGroupBox->setAccessibleName(formatGroupBox->title() + " " + bracketGroupBox->title());
      57            0 :     subdivision->setAccessibleName(useSelectedDurationAsLabel->text() + " " + subdivision->text());
      58            0 :     tupletLength->setAccessibleName(useSelectedDurationAsLabel->text() + " " + tupletLength->text());
      59              : 
      60              :     //! NOTE: It is necessary for the correct start of navigation in the dialog
      61            0 :     setFocus();
      62            0 : }
      63              : 
      64              : //---------------------------------------------------------
      65              : //   defaultToStyleSettings
      66              : //---------------------------------------------------------
      67              : 
      68            0 : void TupletDialog::defaultToStyleSettings()
      69              : {
      70            0 :     mu::engraving::TupletNumberType nt = mu::engraving::TupletNumberType(style()->styleValue(mu::engraving::Sid::tupletNumberType).toInt());
      71            0 :     number->setChecked(nt == mu::engraving::TupletNumberType::SHOW_NUMBER);
      72            0 :     relation->setChecked(nt == mu::engraving::TupletNumberType::SHOW_RELATION);
      73            0 :     noNumber->setChecked(nt == mu::engraving::TupletNumberType::NO_TEXT);
      74              : 
      75            0 :     mu::engraving::TupletBracketType bt = mu::engraving::TupletBracketType(style()->styleValue(
      76            0 :                                                                                mu::engraving::Sid::tupletBracketType).toInt());
      77            0 :     autoBracket->setChecked(bt == mu::engraving::TupletBracketType::AUTO_BRACKET);
      78            0 :     bracket->setChecked(bt == mu::engraving::TupletBracketType::SHOW_BRACKET);
      79            0 :     noBracket->setChecked(bt == mu::engraving::TupletBracketType::SHOW_NO_BRACKET);
      80            0 : }
      81              : 
      82            0 : TupletNumberType TupletDialog::numberType() const
      83              : {
      84            0 :     if (number->isChecked()) {
      85            0 :         return TupletNumberType::SHOW_NUMBER;
      86            0 :     } else if (relation->isChecked()) {
      87            0 :         return TupletNumberType::SHOW_RELATION;
      88            0 :     } else if (noNumber->isChecked()) {
      89            0 :         return TupletNumberType::NO_TEXT;
      90              :     }
      91              : 
      92            0 :     return TupletNumberType::SHOW_NUMBER;
      93              : }
      94              : 
      95            0 : TupletBracketType TupletDialog::bracketType() const
      96              : {
      97            0 :     if (autoBracket->isChecked()) {
      98            0 :         return TupletBracketType::AUTO_BRACKET;
      99            0 :     } else if (bracket->isChecked()) {
     100            0 :         return TupletBracketType::SHOW_BRACKET;
     101            0 :     } else if (noBracket->isChecked()) {
     102            0 :         return TupletBracketType::SHOW_NO_BRACKET;
     103              :     }
     104              : 
     105            0 :     return TupletBracketType::AUTO_BRACKET;
     106              : }
     107              : 
     108            0 : TupletSelectedDuration TupletDialog::selectedDurationAs() const
     109              : {
     110            0 :     if (tupletLength->isChecked()) {
     111            0 :         return TupletSelectedDuration::TUPLET_LENGTH;
     112              :     }
     113              : 
     114            0 :     return TupletSelectedDuration::SUBDIVISION;
     115              : }
     116              : 
     117            0 : void TupletDialog::showEvent(QShowEvent* event)
     118              : {
     119            0 :     WidgetStateStore::restoreGeometry(this);
     120            0 :     QDialog::showEvent(event);
     121            0 : }
     122              : 
     123            0 : void TupletDialog::hideEvent(QHideEvent* event)
     124              : {
     125            0 :     WidgetStateStore::saveGeometry(this);
     126            0 :     QWidget::hideEvent(event);
     127            0 : }
     128              : 
     129            0 : INotationStylePtr TupletDialog::style() const
     130              : {
     131            0 :     return notation() ? notation()->style() : nullptr;
     132              : }
     133              : 
     134            0 : INotationPtr TupletDialog::notation() const
     135              : {
     136            0 :     return projectSession()->currentNotation();
     137              : }
     138              : 
     139            0 : void TupletDialog::apply()
     140              : {
     141              :     rcommand::Params params = {
     142            0 :         { "ratio", Val(Fraction(actualNotes->value(), normalNotes->value()).toString().toStdString()) },
     143            0 :         Contract<TupletNumberType>::param(numberType()),
     144            0 :         Contract<TupletBracketType>::param(bracketType()),
     145            0 :         Contract<TupletSelectedDuration>::param(selectedDurationAs()),
     146            0 :     };
     147              : 
     148            0 :     dispatcher()->dispatch(ADD_TUPLET_COMMAND, params);
     149            0 : }
     150              : 
     151            0 : void TupletDialog::bboxClicked(QAbstractButton* button)
     152              : {
     153            0 :     QDialogButtonBox::ButtonRole br = buttonBox->buttonRole(button);
     154            0 :     switch (br) {
     155            0 :     case QDialogButtonBox::ApplyRole:
     156            0 :         apply();
     157            0 :         break;
     158            0 :     case QDialogButtonBox::AcceptRole:
     159            0 :         apply();
     160            0 :         done(1);
     161            0 :         break;
     162            0 :     case QDialogButtonBox::RejectRole:
     163            0 :         done(0);
     164            0 :         break;
     165            0 :     default:
     166            0 :         break;
     167              :     }
     168            0 : }
        

Generated by: LCOV version 2.0-1