LCOV - code coverage report
Current view: top level - src/palette/internal - paletteactionscontroller.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 "paletteactionscontroller.h"
      24              : 
      25              : #include "notation/inotation.h"
      26              : #include "notation/inotationinteraction.h"
      27              : #include "../palettecommands.h"
      28              : 
      29              : using namespace mu::palette;
      30              : using namespace muse;
      31              : using namespace muse::ui;
      32              : using namespace muse::rcommand;
      33              : 
      34              : static const muse::UriQuery MASTER_PALETTE_URI("musescore://palette/masterpalette?modal=false");
      35              : static const muse::UriQuery SPECIAL_CHARACTERS_URI("musescore://palette/specialcharacters?modal=false");
      36              : static const muse::UriQuery TIME_SIGNATURE_PROPERTIES_URI("musescore://palette/timesignatureproperties");
      37              : static const muse::UriQuery CUSTOMIZE_KIT_URI("musescore://palette/customizekit");
      38              : 
      39              : static const muse::Uri NOTATION_REVIEW_PAGE_URI("musescore://notation/review");
      40              : 
      41            0 : void PaletteActionsController::init()
      42              : {
      43            0 :     auto cd = commandDispatcher();
      44            0 :     cd->onRequest(this, TOGGLE_MASTER_PALETTE_COMMAND, [this](const rcommand::Params& params) { return toggleMasterPalette(params); });
      45            0 :     cd->onRequest(this, TOGGLE_SPECIAL_CHARACTERS_COMMAND, [this]() { toggleSpecialCharactersDialog(); return muse::make_ok(); });
      46            0 :     cd->onRequest(this, OPEN_TIME_SIGNATURE_PROPERTIES_COMMAND, [this]() { openTimeSignaturePropertiesDialog(); return muse::make_ok(); });
      47            0 :     cd->onRequest(this, OPEN_CUSTOMIZE_KIT_COMMAND, [this]() { openCustomizeKitDialog(); return muse::make_ok(); });
      48              : 
      49            0 :     cd->onRequest(this, PALETTE_TOGGLE_SINGLE_CLICK_TO_OPEN_COMMAND, [this]() { return toggleSingleClickToOpen(); });
      50            0 :     cd->onRequest(this, PALETTE_TOGGLE_SINGLE_PALETTE_COMMAND, [this]() { return toggleSinglePalette(); });
      51            0 :     cd->onRequest(this, PALETTE_TOGGLE_DRAG_ENABLED_COMMAND, [this]() { return toggleDragEnabled(); });
      52              : 
      53            0 :     cd->onRequest(this, PALETTE_SEARCH_COMMAND, [this]() { m_paletteSearchRequested.notify(); return muse::make_ok(); });
      54            0 :     cd->onRequest(this, PALETTE_APPLY_CURRENT_ELEMENT_COMMAND, [this]() { m_applyElementRequested.notify(); return muse::make_ok(); });
      55            0 :     cd->onRequest(this, PALETTE_EXPAND_ALL_COMMAND, [this]() { m_expandCollapseAllRequested.send(true); return muse::make_ok(); });
      56            0 :     cd->onRequest(this, PALETTE_COLLAPSE_ALL_COMMAND, [this]() { m_expandCollapseAllRequested.send(false); return muse::make_ok(); });
      57              : 
      58            0 :     interactive()->currentUri().ch.onReceive(this, [this](const Uri& uri) {
      59              :         //! NOTE If MasterPalette are not open, then it is reasonably to compare with the current uri,
      60              :         //! so as not to call the more expensive `interactive()->isOpened` method.
      61              :         //! If MasterPalette is open, then we will call `interactive()->isOpened`,
      62              :         //! in case if they suddenly did not close MasterPalette,
      63              :         //! but opened something else on top of MasterPalette.
      64            0 :         bool isOpened = false;
      65            0 :         if (!m_masterPaletteOpened.val) {
      66            0 :             isOpened = uri == MASTER_PALETTE_URI.uri();
      67              :         } else {
      68            0 :             isOpened = interactive()->isOpened(MASTER_PALETTE_URI.uri()).val;
      69              :         }
      70              : 
      71            0 :         if (isOpened != m_masterPaletteOpened.val) {
      72            0 :             m_masterPaletteOpened.set(isOpened);
      73              :         }
      74            0 :     });
      75            0 : }
      76              : 
      77            0 : ValCh<bool> PaletteActionsController::isMasterPaletteOpened() const
      78              : {
      79            0 :     return m_masterPaletteOpened;
      80              : }
      81              : 
      82            0 : Ret PaletteActionsController::toggleMasterPalette(const rcommand::Params& params)
      83              : {
      84            0 :     if (interactive()->isOpened(MASTER_PALETTE_URI.uri()).val) {
      85            0 :         interactive()->close(MASTER_PALETTE_URI.uri());
      86              :     } else {
      87            0 :         if (params.contains("palette_name")) {
      88            0 :             std::string paletteName = params.at("palette_name").toString();
      89            0 :             interactive()->open(MASTER_PALETTE_URI.addingParam("selectedPaletteName", Val(paletteName)));
      90            0 :         } else {
      91            0 :             interactive()->open(MASTER_PALETTE_URI);
      92              :         }
      93              :     }
      94            0 :     return muse::make_ok();
      95              : }
      96              : 
      97            0 : void PaletteActionsController::toggleSpecialCharactersDialog()
      98              : {
      99            0 :     if (interactive()->isOpened(SPECIAL_CHARACTERS_URI.uri()).val) {
     100            0 :         interactive()->close(SPECIAL_CHARACTERS_URI.uri());
     101              :     } else {
     102            0 :         auto notation = projectSession()->currentNotation();
     103            0 :         if (notation && notation->interaction()->isTextEditingStarted()) {
     104            0 :             interactive()->open(SPECIAL_CHARACTERS_URI);
     105              :         }
     106            0 :     }
     107            0 : }
     108              : 
     109            0 : void PaletteActionsController::openTimeSignaturePropertiesDialog()
     110              : {
     111            0 :     const engraving::EngravingItem* element = notationInteraction() ? notationInteraction()->hitElementContext().element : nullptr;
     112            0 :     if (!element || !element->isTimeSig()) {
     113            0 :         return;
     114              :     }
     115            0 :     interactive()->open(TIME_SIGNATURE_PROPERTIES_URI);
     116              : }
     117              : 
     118            0 : void PaletteActionsController::openCustomizeKitDialog()
     119              : {
     120            0 :     interactive()->open(CUSTOMIZE_KIT_URI);
     121            0 : }
     122              : 
     123            0 : Ret PaletteActionsController::toggleSingleClickToOpen()
     124              : {
     125            0 :     ValCh<bool> checked = configuration()->isSingleClickToOpenPalette();
     126            0 :     configuration()->setIsSingleClickToOpenPalette(!checked.val);
     127            0 :     return muse::make_ok();
     128            0 : }
     129              : 
     130            0 : muse::Ret PaletteActionsController::toggleSinglePalette()
     131              : {
     132            0 :     ValCh<bool> checked = configuration()->isSinglePalette();
     133            0 :     configuration()->setIsSinglePalette(!checked.val);
     134            0 :     return muse::make_ok();
     135            0 : }
     136              : 
     137            0 : muse::Ret PaletteActionsController::toggleDragEnabled()
     138              : {
     139            0 :     ValCh<bool> checked = configuration()->isPaletteDragEnabled();
     140            0 :     configuration()->setIsPaletteDragEnabled(!checked.val);
     141            0 :     return muse::make_ok();
     142            0 : }
     143              : 
     144            0 : mu::notation::INotationInteractionPtr PaletteActionsController::notationInteraction() const
     145              : {
     146            0 :     const notation::INotationPtr notation = projectSession()->currentNotation();
     147            0 :     return notation ? notation->interaction() : nullptr;
     148            0 : }
     149              : 
     150            0 : async::Notification PaletteActionsController::paletteSearchRequested() const
     151              : {
     152            0 :     return m_paletteSearchRequested;
     153              : }
     154              : 
     155            0 : async::Notification PaletteActionsController::applyCurrentPaletteElementRequested() const
     156              : {
     157            0 :     return m_applyElementRequested;
     158              : }
     159              : 
     160            0 : async::Channel<bool> PaletteActionsController::expandCollapseAllRequested() const
     161              : {
     162            0 :     return m_expandCollapseAllRequested;
     163              : }
        

Generated by: LCOV version 2.0-1