LCOV - code coverage report
Current view: top level - src/palette/widgets - symboldialog.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 74 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 "symboldialog.h"
      24              : 
      25              : #include "engraving/style/style.h"
      26              : #include "engraving/types/symnames.h"
      27              : #include "engraving/infrastructure/smufl.h"
      28              : 
      29              : #include "engraving/dom/masterscore.h"
      30              : #include "engraving/dom/engravingitem.h"
      31              : #include "engraving/dom/symbol.h"
      32              : 
      33              : #include "notation/inotation.h"
      34              : #include "notation/inotationelements.h" // IWYU pragma: keep
      35              : 
      36              : #include "palettewidget.h"
      37              : 
      38              : using namespace mu::engraving;
      39              : using namespace mu::palette;
      40              : 
      41              : //---------------------------------------------------------
      42              : //   createSymbolPalette
      43              : //---------------------------------------------------------
      44              : 
      45            0 : void SymbolDialog::createSymbolPalette()
      46              : {
      47            0 :     m_symbolsWidget = new PaletteWidget(this, true /*setIocContext*/);
      48            0 :     createSymbols();
      49            0 : }
      50              : 
      51              : //---------------------------------------------------------
      52              : //   createSymbols
      53              : //---------------------------------------------------------
      54              : 
      55            0 : void SymbolDialog::createSymbols()
      56              : {
      57            0 :     int currentIndex = fontList->currentIndex();
      58            0 :     const IEngravingFontPtr f = engravingFonts()->fonts()[currentIndex];
      59              :     // init the font if not done yet
      60            0 :     engravingFonts()->fontByName(f->name());
      61            0 :     m_symbolsWidget->clear();
      62            0 :     auto paletteScore = paletteScoreProvider()->paletteScore();
      63            0 :     for (SymId symId : Smufl::smuflRanges().at(range)) {
      64            0 :         String symName = SymNames::translatedUserNameForSymId(symId);
      65            0 :         if (search->text().isEmpty()
      66            0 :             || symName.toQString().contains(search->text(), Qt::CaseInsensitive)) {
      67            0 :             auto s = std::make_shared<Symbol>(paletteScore->dummy());
      68            0 :             s->setSym(symId, f);
      69            0 :             m_symbolsWidget->appendElement(s, symName);
      70            0 :         }
      71            0 :     }
      72            0 : }
      73              : 
      74              : //---------------------------------------------------------
      75              : //   SymbolDialog
      76              : //---------------------------------------------------------
      77              : 
      78            0 : SymbolDialog::SymbolDialog(const QString& s, QWidget* parent)
      79            0 :     : QWidget(parent, Qt::WindowFlags(Qt::Dialog | Qt::Window)), muse::Contextable(muse::iocCtxForQWidget(this))
      80              : {
      81            0 :     setupUi(this);
      82            0 :     range = s;          // smufl symbol range
      83            0 :     int idx = 0;
      84            0 :     int currentIndex = 0;
      85            0 :     Score* score = projectSession()->currentNotation()->elements()->msScore();
      86            0 :     std::string styleFont = score ? score->style().styleSt(Sid::musicalSymbolFont).toStdString() : "";
      87            0 :     for (const IEngravingFontPtr& f : engravingFonts()->fonts()) {
      88            0 :         fontList->addItem(QString::fromStdString(f->name()));
      89            0 :         if (!styleFont.empty() && f->name() == styleFont) {
      90            0 :             currentIndex = idx;
      91            0 :             styleFont = "";
      92              :         }
      93            0 :         ++idx;
      94            0 :     }
      95            0 :     fontList->setCurrentIndex(currentIndex);
      96              : 
      97            0 :     QLayout* layout = new QVBoxLayout();
      98            0 :     frame->setLayout(layout);
      99            0 :     createSymbolPalette();
     100              : 
     101            0 :     QScrollArea* symbolsArea = new PaletteScrollArea(m_symbolsWidget);
     102            0 :     symbolsArea->setFocusProxy(m_symbolsWidget);
     103            0 :     symbolsArea->setFocusPolicy(Qt::TabFocus);
     104            0 :     layout->addWidget(symbolsArea);
     105              : 
     106            0 :     m_symbolsWidget->setAcceptDrops(false);
     107            0 :     m_symbolsWidget->setDrawGrid(true);
     108            0 :     m_symbolsWidget->setSelectable(true);
     109              : 
     110            0 :     connect(systemFlag, &QCheckBox::checkStateChanged, this, &SymbolDialog::systemFlagChanged);
     111            0 :     connect(fontList, &QComboBox::currentIndexChanged, this, &SymbolDialog::systemFontChanged);
     112              : 
     113            0 :     symbolsArea->setWidget(m_symbolsWidget);
     114              : 
     115              :     //! NOTE: It is necessary for the correct start of navigation in the dialog
     116            0 :     setFocus();
     117            0 : }
     118              : 
     119              : //---------------------------------------------------------
     120              : //   systemFlagChanged
     121              : //---------------------------------------------------------
     122              : 
     123            0 : void SymbolDialog::systemFlagChanged(Qt::CheckState state)
     124              : {
     125            0 :     bool sysFlag = state == Qt::Checked;
     126            0 :     for (int i = 0; i < m_symbolsWidget->actualCellCount(); ++i) {
     127            0 :         ElementPtr e = m_symbolsWidget->elementForCellAt(i);
     128            0 :         if (e && e->isSymbol()) {
     129            0 :             std::dynamic_pointer_cast<Symbol>(e)->setSystemFlag(sysFlag);
     130              :         }
     131            0 :     }
     132            0 : }
     133              : 
     134              : //---------------------------------------------------------
     135              : //   systemFontChanged
     136              : //---------------------------------------------------------
     137              : 
     138            0 : void SymbolDialog::systemFontChanged(int)
     139              : {
     140            0 :     createSymbols();
     141            0 : }
     142              : 
     143            0 : void SymbolDialog::on_search_textChanged(const QString& searchPhrase)
     144              : {
     145              :     Q_UNUSED(searchPhrase);
     146            0 :     createSymbols();
     147            0 : }
     148              : 
     149            0 : void SymbolDialog::on_clearSearch_clicked()
     150              : {
     151            0 :     search->clear();
     152            0 :     createSymbols();
     153            0 : }
     154              : 
     155              : //---------------------------------------------------------
     156              : //   changeEvent
     157              : //---------------------------------------------------------
     158              : 
     159            0 : void SymbolDialog::changeEvent(QEvent* event)
     160              : {
     161            0 :     QWidget::changeEvent(event);
     162            0 :     if (event->type() == QEvent::LanguageChange) {
     163            0 :         retranslate();
     164              :     }
     165            0 : }
        

Generated by: LCOV version 2.0-1