inherited CrescendoSettingsModel from LineSettingsModel

This commit is contained in:
Roman Pudashkin 2021-09-16 15:07:50 +02:00
parent 8d44242bf4
commit d7420fba29
8 changed files with 168 additions and 345 deletions

View file

@ -114,8 +114,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/models/notation/chordsymbols/chordsymbolsettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/notation/clefs/clefsettingsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/models/notation/clefs/clefsettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/notation/crescendos/crescendosettingsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/models/notation/crescendos/crescendosettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/notation/lines/crescendosettingsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/models/notation/lines/crescendosettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/notation/fermatas/fermatasettingsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/models/notation/fermatas/fermatasettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/notation/frames/horizontalframesettingsmodel.cpp

View file

@ -41,7 +41,7 @@
#include "notation/spacers/spacersettingsmodel.h"
#include "notation/clefs/clefsettingsmodel.h"
#include "notation/lines/hairpinsettingsmodel.h"
#include "notation/crescendos/crescendosettingsmodel.h"
#include "notation/lines/crescendosettingsmodel.h"
#include "notation/stafftype/stafftypesettingsmodel.h"
#include "notation/frames/textframesettingsmodel.h"
#include "notation/frames/verticalframesettingsmodel.h"

View file

@ -1,237 +0,0 @@
/*
* 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 "crescendosettingsmodel.h"
#include "libmscore/hairpin.h"
#include "translation.h"
#include "types/crescendotypes.h"
#include "dataformatter.h"
using namespace mu::inspector;
CrescendoSettingsModel::CrescendoSettingsModel(QObject* parent, IElementRepositoryService* repository)
: AbstractInspectorModel(parent, repository)
{
setModelType(InspectorModelType::TYPE_CRESCENDO);
setTitle(qtrc("inspector", "Crescendo"));
setIcon(ui::IconCode::Code::CRESCENDO_LINE);
createProperties();
}
void CrescendoSettingsModel::createProperties()
{
m_isLineVisible = buildPropertyItem(Ms::Pid::LINE_VISIBLE, [this](const int pid, const QVariant& newValue) {
onPropertyValueChanged(static_cast<Ms::Pid>(pid), newValue);
updateLinePropertiesAvailability();
});
m_endHookType = buildPropertyItem(Ms::Pid::END_HOOK_TYPE);
m_thickness = buildPropertyItem(Ms::Pid::LINE_WIDTH);
m_hookHeight = buildPropertyItem(Ms::Pid::END_HOOK_HEIGHT);
m_lineStyle = buildPropertyItem(Ms::Pid::LINE_STYLE, [this](const int pid, const QVariant& newValue) {
onPropertyValueChanged(static_cast<Ms::Pid>(pid), newValue);
updateLinePropertiesAvailability();
});
m_dashLineLength = buildPropertyItem(Ms::Pid::DASH_LINE_LEN);
m_dashGapLength = buildPropertyItem(Ms::Pid::DASH_GAP_LEN);
m_placement = buildPropertyItem(Ms::Pid::PLACEMENT);
m_beginningText = buildPropertyItem(Ms::Pid::BEGIN_TEXT);
m_beginningTextHorizontalOffset = buildPropertyItem(Ms::Pid::BEGIN_TEXT_OFFSET, [this](const int pid, const QVariant& newValue) {
onPropertyValueChanged(static_cast<Ms::Pid>(pid), PointF(newValue.toDouble(), m_beginningTextVerticalOffset->value().toDouble()));
});
m_beginningTextVerticalOffset = buildPropertyItem(Ms::Pid::BEGIN_TEXT_OFFSET, [this](const int pid, const QVariant& newValue) {
onPropertyValueChanged(static_cast<Ms::Pid>(pid), PointF(m_beginningTextHorizontalOffset->value().toDouble(),
newValue.toDouble()));
});
m_continiousText = buildPropertyItem(Ms::Pid::CONTINUE_TEXT);
m_continiousTextHorizontalOffset = buildPropertyItem(Ms::Pid::CONTINUE_TEXT_OFFSET, [this](const int pid, const QVariant& newValue) {
onPropertyValueChanged(static_cast<Ms::Pid>(pid), PointF(newValue.toDouble(), m_continiousTextVerticalOffset->value().toDouble()));
});
m_continiousTextVerticalOffset = buildPropertyItem(Ms::Pid::CONTINUE_TEXT_OFFSET, [this](const int pid, const QVariant& newValue) {
onPropertyValueChanged(static_cast<Ms::Pid>(pid), PointF(m_continiousTextHorizontalOffset->value().toDouble(),
newValue.toDouble()));
});
}
void CrescendoSettingsModel::requestElements()
{
m_elementList = m_repository->findElementsByType(Ms::ElementType::HAIRPIN, [](const Ms::EngravingItem* element) -> bool {
const Ms::Hairpin* hairpin = Ms::toHairpin(element);
if (!hairpin) {
return false;
}
return hairpin->hairpinType() == Ms::HairpinType::CRESC_LINE || hairpin->hairpinType() == Ms::HairpinType::DECRESC_LINE;
});
}
void CrescendoSettingsModel::loadProperties()
{
loadPropertyItem(m_isLineVisible);
loadPropertyItem(m_endHookType);
auto formatDoubleFunc = [](const QVariant& elementPropertyValue) -> QVariant {
return DataFormatter::roundDouble(elementPropertyValue.toDouble());
};
loadPropertyItem(m_thickness, formatDoubleFunc);
loadPropertyItem(m_hookHeight, formatDoubleFunc);
loadPropertyItem(m_lineStyle);
loadPropertyItem(m_dashLineLength, formatDoubleFunc);
loadPropertyItem(m_dashGapLength, formatDoubleFunc);
loadPropertyItem(m_placement);
loadPropertyItem(m_beginningText);
loadPropertyItem(m_beginningTextHorizontalOffset, [](const QVariant& elementPropertyValue) -> QVariant {
return DataFormatter::roundDouble(elementPropertyValue.value<PointF>().x());
});
loadPropertyItem(m_beginningTextVerticalOffset, [](const QVariant& elementPropertyValue) -> QVariant {
return DataFormatter::roundDouble(elementPropertyValue.value<PointF>().x());
});
loadPropertyItem(m_continiousText);
loadPropertyItem(m_continiousTextHorizontalOffset, [](const QVariant& elementPropertyValue) -> QVariant {
return DataFormatter::roundDouble(elementPropertyValue.value<PointF>().x());
});
loadPropertyItem(m_continiousTextVerticalOffset, [](const QVariant& elementPropertyValue) -> QVariant {
return DataFormatter::roundDouble(elementPropertyValue.value<PointF>().x());
});
updateLinePropertiesAvailability();
}
void CrescendoSettingsModel::resetProperties()
{
m_isLineVisible->resetToDefault();
m_endHookType->resetToDefault();
m_thickness->resetToDefault();
m_hookHeight->resetToDefault();
m_lineStyle->resetToDefault();
m_dashLineLength->resetToDefault();
m_dashGapLength->resetToDefault();
m_placement->resetToDefault();
m_beginningText->resetToDefault();
m_beginningTextHorizontalOffset->resetToDefault();
m_beginningTextVerticalOffset->resetToDefault();
m_continiousText->resetToDefault();
m_continiousTextHorizontalOffset->resetToDefault();
m_continiousTextVerticalOffset->resetToDefault();
}
PropertyItem* CrescendoSettingsModel::isLineVisible() const
{
return m_isLineVisible;
}
PropertyItem* CrescendoSettingsModel::endHookType() const
{
return m_endHookType;
}
PropertyItem* CrescendoSettingsModel::thickness() const
{
return m_thickness;
}
PropertyItem* CrescendoSettingsModel::hookHeight() const
{
return m_hookHeight;
}
PropertyItem* CrescendoSettingsModel::lineStyle() const
{
return m_lineStyle;
}
PropertyItem* CrescendoSettingsModel::dashLineLength() const
{
return m_dashLineLength;
}
PropertyItem* CrescendoSettingsModel::dashGapLength() const
{
return m_dashGapLength;
}
PropertyItem* CrescendoSettingsModel::placement() const
{
return m_placement;
}
PropertyItem* CrescendoSettingsModel::beginningText() const
{
return m_beginningText;
}
PropertyItem* CrescendoSettingsModel::beginningTextHorizontalOffset() const
{
return m_beginningTextHorizontalOffset;
}
PropertyItem* CrescendoSettingsModel::beginningTextVerticalOffset() const
{
return m_beginningTextVerticalOffset;
}
PropertyItem* CrescendoSettingsModel::continiousText() const
{
return m_continiousText;
}
PropertyItem* CrescendoSettingsModel::continiousTextHorizontalOffset() const
{
return m_continiousTextHorizontalOffset;
}
PropertyItem* CrescendoSettingsModel::continiousTextVerticalOffset() const
{
return m_continiousTextVerticalOffset;
}
void CrescendoSettingsModel::updateLinePropertiesAvailability()
{
bool isLineAvailable = m_isLineVisible->value().toBool();
m_endHookType->setIsEnabled(isLineAvailable);
m_thickness->setIsEnabled(isLineAvailable);
m_hookHeight->setIsEnabled(isLineAvailable);
m_lineStyle->setIsEnabled(isLineAvailable);
CrescendoTypes::LineStyle currentStyle = static_cast<CrescendoTypes::LineStyle>(m_lineStyle->value().toInt());
bool areDashPropertiesAvailable = currentStyle == CrescendoTypes::LineStyle::LINE_STYLE_CUSTOM;
m_dashLineLength->setIsEnabled(isLineAvailable && areDashPropertiesAvailable);
m_dashGapLength->setIsEnabled(isLineAvailable && areDashPropertiesAvailable);
}

View file

@ -1,96 +0,0 @@
/*
* 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/>.
*/
#ifndef MU_INSPECTOR_CRESCENDOSETTINGSMODEL_H
#define MU_INSPECTOR_CRESCENDOSETTINGSMODEL_H
#include "models/abstractinspectormodel.h"
namespace mu::inspector {
class CrescendoSettingsModel : public AbstractInspectorModel
{
Q_OBJECT
Q_PROPERTY(PropertyItem * isLineVisible READ isLineVisible CONSTANT)
Q_PROPERTY(PropertyItem * endHookType READ endHookType CONSTANT)
Q_PROPERTY(PropertyItem * thickness READ thickness CONSTANT)
Q_PROPERTY(PropertyItem * hookHeight READ hookHeight CONSTANT)
Q_PROPERTY(PropertyItem * lineStyle READ lineStyle CONSTANT)
Q_PROPERTY(PropertyItem * dashLineLength READ dashLineLength CONSTANT)
Q_PROPERTY(PropertyItem * dashGapLength READ dashGapLength CONSTANT)
Q_PROPERTY(PropertyItem * placement READ placement CONSTANT)
Q_PROPERTY(PropertyItem * beginningText READ beginningText CONSTANT)
Q_PROPERTY(PropertyItem * beginningTextHorizontalOffset READ beginningTextHorizontalOffset CONSTANT)
Q_PROPERTY(PropertyItem * beginningTextVerticalOffset READ beginningTextVerticalOffset CONSTANT)
Q_PROPERTY(PropertyItem * continiousText READ continiousText CONSTANT)
Q_PROPERTY(PropertyItem * continiousTextHorizontalOffset READ continiousTextHorizontalOffset CONSTANT)
Q_PROPERTY(PropertyItem * continiousTextVerticalOffset READ continiousTextVerticalOffset CONSTANT)
public:
explicit CrescendoSettingsModel(QObject* parent, IElementRepositoryService* repository);
void createProperties() override;
void requestElements() override;
void loadProperties() override;
void resetProperties() override;
PropertyItem* isLineVisible() const;
PropertyItem* endHookType() const;
PropertyItem* thickness() const;
PropertyItem* hookHeight() const;
PropertyItem* lineStyle() const;
PropertyItem* dashLineLength() const;
PropertyItem* dashGapLength() const;
PropertyItem* placement() const;
PropertyItem* beginningText() const;
PropertyItem* beginningTextHorizontalOffset() const;
PropertyItem* beginningTextVerticalOffset() const;
PropertyItem* continiousText() const;
PropertyItem* continiousTextHorizontalOffset() const;
PropertyItem* continiousTextVerticalOffset() const;
private:
void updateLinePropertiesAvailability();
PropertyItem* m_isLineVisible = nullptr;
PropertyItem* m_endHookType = nullptr;
PropertyItem* m_thickness = nullptr;
PropertyItem* m_hookHeight = nullptr;
PropertyItem* m_lineStyle = nullptr;
PropertyItem* m_dashLineLength = nullptr;
PropertyItem* m_dashGapLength = nullptr;
PropertyItem* m_placement = nullptr;
PropertyItem* m_beginningText = nullptr;
PropertyItem* m_beginningTextHorizontalOffset = nullptr;
PropertyItem* m_beginningTextVerticalOffset = nullptr;
PropertyItem* m_continiousText = nullptr;
PropertyItem* m_continiousTextHorizontalOffset = nullptr;
PropertyItem* m_continiousTextVerticalOffset = nullptr;
};
}
#endif // MU_INSPECTOR_CRESCENDOSETTINGSMODEL_H

View file

@ -0,0 +1,102 @@
/*
* 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 "crescendosettingsmodel.h"
#include "libmscore/hairpin.h"
#include "translation.h"
#include "types/crescendotypes.h"
using namespace mu::inspector;
CrescendoSettingsModel::CrescendoSettingsModel(QObject* parent, IElementRepositoryService* repository)
: LineSettingsModel(parent, repository)
{
setModelType(InspectorModelType::TYPE_CRESCENDO);
setTitle(qtrc("inspector", "Crescendo"));
setIcon(ui::IconCode::Code::CRESCENDO_LINE);
createProperties();
}
void CrescendoSettingsModel::createProperties()
{
LineSettingsModel::createProperties();
m_endHookType = buildPropertyItem(Ms::Pid::END_HOOK_TYPE);
m_hookHeight = buildPropertyItem(Ms::Pid::END_HOOK_HEIGHT);
}
void CrescendoSettingsModel::requestElements()
{
m_elementList = m_repository->findElementsByType(Ms::ElementType::HAIRPIN, [](const Ms::EngravingItem* element) -> bool {
const Ms::Hairpin* hairpin = Ms::toHairpin(element);
if (!hairpin) {
return false;
}
return hairpin->hairpinType() == Ms::HairpinType::CRESC_LINE || hairpin->hairpinType() == Ms::HairpinType::DECRESC_LINE;
});
}
void CrescendoSettingsModel::loadProperties()
{
LineSettingsModel::loadProperties();
loadPropertyItem(m_endHookType);
loadPropertyItem(m_hookHeight);
}
void CrescendoSettingsModel::resetProperties()
{
LineSettingsModel::resetProperties();
m_endHookType->resetToDefault();
m_hookHeight->resetToDefault();
}
PropertyItem* CrescendoSettingsModel::endHookType() const
{
return m_endHookType;
}
PropertyItem* CrescendoSettingsModel::hookHeight() const
{
return m_hookHeight;
}
void CrescendoSettingsModel::onUpdateLinePropertiesAvailability()
{
bool isLineAvailable = isLineVisible()->value().toBool();
endHookType()->setIsEnabled(isLineAvailable);
thickness()->setIsEnabled(isLineAvailable);
hookHeight()->setIsEnabled(isLineAvailable);
lineStyle()->setIsEnabled(isLineAvailable);
CrescendoTypes::LineStyle currentStyle = static_cast<CrescendoTypes::LineStyle>(lineStyle()->value().toInt());
bool areDashPropertiesAvailable = currentStyle == CrescendoTypes::LineStyle::LINE_STYLE_CUSTOM;
dashLineLength()->setIsEnabled(isLineAvailable && areDashPropertiesAvailable);
dashGapLength()->setIsEnabled(isLineAvailable && areDashPropertiesAvailable);
}

View file

@ -0,0 +1,54 @@
/*
* 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/>.
*/
#ifndef MU_INSPECTOR_CRESCENDOSETTINGSMODEL_H
#define MU_INSPECTOR_CRESCENDOSETTINGSMODEL_H
#include "linesettingsmodel.h"
namespace mu::inspector {
class CrescendoSettingsModel : public LineSettingsModel
{
Q_OBJECT
Q_PROPERTY(PropertyItem * endHookType READ endHookType CONSTANT)
Q_PROPERTY(PropertyItem * hookHeight READ hookHeight CONSTANT)
public:
explicit CrescendoSettingsModel(QObject* parent, IElementRepositoryService* repository);
PropertyItem* endHookType() const;
PropertyItem* hookHeight() const;
private:
void createProperties() override;
void requestElements() override;
void loadProperties() override;
void resetProperties() override;
void onUpdateLinePropertiesAvailability() override;
PropertyItem* m_endHookType = nullptr;
PropertyItem* m_hookHeight = nullptr;
};
}
#endif // MU_INSPECTOR_CRESCENDOSETTINGSMODEL_H

View file

@ -46,7 +46,7 @@ void LineSettingsModel::createProperties()
m_dashLineLength = buildPropertyItem(Ms::Pid::DASH_LINE_LEN);
m_dashGapLength = buildPropertyItem(Ms::Pid::DASH_GAP_LEN);
m_lineVisible = buildPropertyItem(Ms::Pid::LINE_VISIBLE);
m_isLineVisible = buildPropertyItem(Ms::Pid::LINE_VISIBLE);
m_isDiagonalLocked = buildPropertyItem(Ms::Pid::DIAGONAL);
if (isTextVisible(BeginingText)) {
@ -98,7 +98,7 @@ void LineSettingsModel::loadProperties()
loadPropertyItem(m_dashLineLength, formatDoubleFunc);
loadPropertyItem(m_dashGapLength, formatDoubleFunc);
loadPropertyItem(m_lineVisible);
loadPropertyItem(m_isLineVisible);
loadPropertyItem(m_isDiagonalLocked);
loadPropertyItem(m_beginingText);
@ -136,7 +136,7 @@ void LineSettingsModel::resetProperties()
m_thickness,
m_dashLineLength,
m_dashGapLength,
m_lineVisible,
m_isLineVisible,
m_isDiagonalLocked,
m_beginingText,
m_beginingTextHorizontalOffset,
@ -181,9 +181,9 @@ PropertyItem* LineSettingsModel::placement() const
return m_placement;
}
PropertyItem* LineSettingsModel::lineVisible() const
PropertyItem* LineSettingsModel::isLineVisible() const
{
return m_lineVisible;
return m_isLineVisible;
}
PropertyItem* LineSettingsModel::isDiagonalLocked() const
@ -237,7 +237,7 @@ PropertyItem* LineSettingsModel::endTextVerticalOffset() const
}
void LineSettingsModel::onUpdateLinePropertiesAvailability()
{
{
}
bool LineSettingsModel::isTextVisible(TextType) const

View file

@ -36,7 +36,7 @@ class LineSettingsModel : public AbstractInspectorModel
Q_PROPERTY(PropertyItem * dashLineLength READ dashLineLength CONSTANT)
Q_PROPERTY(PropertyItem * dashGapLength READ dashGapLength CONSTANT)
Q_PROPERTY(PropertyItem * lineVisible READ lineVisible CONSTANT)
Q_PROPERTY(PropertyItem * isLineVisible READ isLineVisible CONSTANT)
Q_PROPERTY(PropertyItem * isDiagonalLocked READ isDiagonalLocked CONSTANT)
Q_PROPERTY(PropertyItem * beginingText READ beginingText CONSTANT)
@ -61,7 +61,7 @@ public:
PropertyItem* dashLineLength() const;
PropertyItem* dashGapLength() const;
PropertyItem* lineVisible() const;
PropertyItem* isLineVisible() const;
PropertyItem* isDiagonalLocked() const;
PropertyItem* beginingText() const;
@ -99,7 +99,7 @@ private:
PropertyItem* m_dashLineLength = nullptr;
PropertyItem* m_dashGapLength = nullptr;
PropertyItem* m_lineVisible = nullptr;
PropertyItem* m_isLineVisible = nullptr;
PropertyItem* m_isDiagonalLocked = nullptr;
PropertyItem* m_beginingText = nullptr;