MuseScore/src/palette/palettemodule.cpp
Casper Jeukendrup 3adc827590 ScoreFont and Sym cleanup
- Moved ScoreFont from sym.h to separate file
- Cleaned the code in ScoreFont somewhat
- Reduced unnecessary includes of sym.h
2021-06-03 17:20:04 +03:00

134 lines
4.6 KiB
C++

/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "palettemodule.h"
#include <QQmlEngine>
#include "log.h"
#include "config.h"
#include "modularity/ioc.h"
#include "ui/iuiengine.h"
#include "ui/iinteractiveuriregister.h"
#include "ui/iuiactionsregister.h"
#include "internal/mu4paletteadapter.h"
#include "internal/paletteconfiguration.h"
#include "internal/palette/masterpalette.h"
#include "internal/paletteactionscontroller.h"
#include "internal/paletteuiactions.h"
#include "view/paletterootmodel.h"
#include "view/palettepropertiesmodel.h"
#include "view/palettecellpropertiesmodel.h"
#include "workspace/iworkspacedatastreamregister.h"
#include "internal/workspacepalettestream.h"
#include "internal/paletteworkspacesetup.h"
using namespace mu::palette;
using namespace mu::framework;
using namespace mu::ui;
static std::shared_ptr<MU4PaletteAdapter> s_adapter = std::make_shared<MU4PaletteAdapter>();
static std::shared_ptr<PaletteActionsController> s_actionsController = std::make_shared<PaletteActionsController>();
static std::shared_ptr<PaletteUiActions> s_paletteUiActions = std::make_shared<PaletteUiActions>(s_actionsController);
static std::shared_ptr<PaletteConfiguration> s_configuration = std::make_shared<PaletteConfiguration>();
static void palette_init_qrc()
{
Q_INIT_RESOURCE(palette);
}
std::string PaletteModule::moduleName() const
{
return "palette";
}
void PaletteModule::registerExports()
{
ioc()->registerExport<IPaletteAdapter>(moduleName(), s_adapter);
ioc()->registerExport<IPaletteConfiguration>(moduleName(), s_configuration);
}
void PaletteModule::resolveImports()
{
auto workspaceStreams = ioc()->resolve<workspace::IWorkspaceDataStreamRegister>(moduleName());
if (workspaceStreams) {
workspaceStreams->regStream(std::make_shared<WorkspacePaletteStream>());
}
auto ar = ioc()->resolve<ui::IUiActionsRegister>(moduleName());
if (ar) {
ar->reg(s_paletteUiActions);
}
auto ir = ioc()->resolve<IInteractiveUriRegister>(moduleName());
if (ir) {
ir->registerUri(Uri("musescore://palette/masterpalette"),
ContainerMeta(ContainerType::QWidgetDialog, Ms::MasterPalette::static_metaTypeId()));
ir->registerUri(Uri("musescore://palette/properties"),
ContainerMeta(ContainerType::QmlDialog, "MuseScore/Palette/PalettePropertiesDialog.qml"));
ir->registerUri(Uri("musescore://palette/cellproperties"),
ContainerMeta(ContainerType::QmlDialog, "MuseScore/Palette/PaletteCellPropertiesDialog.qml"));
}
}
void PaletteModule::registerResources()
{
palette_init_qrc();
}
void PaletteModule::registerUiTypes()
{
using namespace Ms;
qmlRegisterUncreatableType<PaletteWorkspace>("MuseScore.Palette", 1, 0, "PaletteWorkspace", "Cannot create");
qmlRegisterUncreatableType<AbstractPaletteController>("MuseScore.Palette", 1, 0, "PaletteController", "Cannot ...");
qmlRegisterUncreatableType<PaletteElementEditor>("MuseScore.Palette", 1, 0, "PaletteElementEditor", "Cannot ...");
qmlRegisterUncreatableType<PaletteTreeModel>("MuseScore.Palette", 1, 0, "PaletteTreeModel", "Cannot create");
qmlRegisterUncreatableType<FilterPaletteTreeModel>("MuseScore.Palette", 1, 0, "FilterPaletteTreeModel", "Cannot");
qmlRegisterType<PaletteRootModel>("MuseScore.Palette", 1, 0, "PaletteRootModel");
qmlRegisterType<PalettePropertiesModel>("MuseScore.Palette", 1, 0, "PalettePropertiesModel");
qmlRegisterType<PaletteCellPropertiesModel>("MuseScore.Palette", 1, 0, "PaletteCellPropertiesModel");
ioc()->resolve<ui::IUiEngine>(moduleName())->addSourceImportPath(palette_QML_IMPORT);
}
void PaletteModule::onInit(const IApplication::RunMode& mode)
{
if (framework::IApplication::RunMode::Editor != mode) {
return;
}
// load workspace
PaletteWorkspaceSetup w;
w.setup();
s_configuration->init();
s_actionsController->init();
s_paletteUiActions->init();
}