Merge pull request #17281 from njantony1/11264-gap-between-text-and-line

added ability to adjust gap between text and line
This commit is contained in:
RomanPudashkin 2023-04-26 10:49:08 +03:00 committed by GitHub
commit e89682f107
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 6 deletions

View file

@ -322,6 +322,7 @@ static constexpr PropertyMetaData propertyList[] = {
{ Pid::BEGIN_FONT_SIZE, false, "beginFontSize", P_TYPE::REAL, DUMMY_QT_TR_NOOP("propertyName", "begin font size") },
{ Pid::BEGIN_FONT_STYLE, false, "beginFontStyle", P_TYPE::INT, DUMMY_QT_TR_NOOP("propertyName", "begin font style") },
{ Pid::BEGIN_TEXT_OFFSET, false, "beginTextOffset", P_TYPE::POINT, DUMMY_QT_TR_NOOP("propertyName", "begin text offset") },
{ Pid::GAP_BETWEEN_TEXT_AND_LINE, false, "gapBetweenTextAndLine", P_TYPE::SPATIUM, DUMMY_QT_TR_NOOP("propertyName", "gap between text and line") },
{ Pid::CONTINUE_TEXT, true, "continueText", P_TYPE::STRING, DUMMY_QT_TR_NOOP("propertyName", "continue text") },
{ Pid::CONTINUE_TEXT_ALIGN, false, "continueTextAlign", P_TYPE::ALIGN, DUMMY_QT_TR_NOOP("propertyName", "continue text align") },

View file

@ -330,6 +330,7 @@ enum class Pid {
BEGIN_FONT_SIZE,
BEGIN_FONT_STYLE,
BEGIN_TEXT_OFFSET,
GAP_BETWEEN_TEXT_AND_LINE,
CONTINUE_TEXT,
CONTINUE_TEXT_ALIGN,

View file

@ -156,6 +156,7 @@ TextLine::TextLine(EngravingItem* parent, bool system)
setEndHookType(HookType::NONE);
setBeginHookHeight(Spatium(1.5));
setEndHookHeight(Spatium(1.5));
setGapBetweenTextAndLine(Spatium(0.5));
initElementStyle(&textLineStyle);

View file

@ -395,10 +395,10 @@ void TextLineBaseSegment::layout()
double l = 0.0;
if (!_text->empty()) {
double textlineTextDistance = _spatium * .5;
double gapBetweenTextAndLine = _spatium * tl->gapBetweenTextAndLine().val();
if ((isSingleBeginType() && (tl->beginTextPlace() == TextPlace::LEFT || tl->beginTextPlace() == TextPlace::AUTO))
|| (!isSingleBeginType() && (tl->continueTextPlace() == TextPlace::LEFT || tl->continueTextPlace() == TextPlace::AUTO))) {
l = _text->pos().x() + _text->bbox().width() + textlineTextDistance;
l = _text->pos().x() + _text->bbox().width() + gapBetweenTextAndLine;
}
double h = _text->height();
@ -545,12 +545,13 @@ void TextLineBaseSegment::spatiumChanged(double ov, double nv)
_endText->spatiumChanged(ov, nv);
}
static constexpr std::array<Pid, 26> TextLineBasePropertyId = { {
static constexpr std::array<Pid, 27> TextLineBasePropertyId = { {
Pid::LINE_VISIBLE,
Pid::BEGIN_HOOK_TYPE,
Pid::BEGIN_HOOK_HEIGHT,
Pid::END_HOOK_TYPE,
Pid::END_HOOK_HEIGHT,
Pid::GAP_BETWEEN_TEXT_AND_LINE,
Pid::BEGIN_TEXT,
Pid::BEGIN_TEXT_ALIGN,
Pid::BEGIN_TEXT_PLACE,
@ -574,7 +575,7 @@ static constexpr std::array<Pid, 26> TextLineBasePropertyId = { {
Pid::END_TEXT_OFFSET,
} };
const std::array<Pid, 26>& TextLineBase::textLineBasePropertyIds()
const std::array<Pid, 27>& TextLineBase::textLineBasePropertyIds()
{
return TextLineBasePropertyId;
}
@ -602,6 +603,7 @@ TextLineBase::TextLineBase(const ElementType& type, EngravingItem* parent, Eleme
{
setBeginHookHeight(Spatium(1.9));
setEndHookHeight(Spatium(1.9));
setGapBetweenTextAndLine(Spatium(0.5));
}
//---------------------------------------------------------
@ -661,6 +663,8 @@ PropertyValue TextLineBase::getProperty(Pid id) const
return _endHookType;
case Pid::END_HOOK_HEIGHT:
return _endHookHeight;
case Pid::GAP_BETWEEN_TEXT_AND_LINE:
return _gapBetweenTextAndLine;
case Pid::END_FONT_FACE:
return _endFontFamily;
case Pid::END_FONT_SIZE:
@ -721,6 +725,9 @@ bool TextLineBase::setProperty(Pid id, const PropertyValue& v)
case Pid::BEGIN_TEXT_OFFSET:
setBeginTextOffset(v.value<PointF>());
break;
case Pid::GAP_BETWEEN_TEXT_AND_LINE:
_gapBetweenTextAndLine = v.value<Spatium>();
break;
case Pid::CONTINUE_TEXT_OFFSET:
setContinueTextOffset(v.value<PointF>());
break;
@ -775,4 +782,14 @@ bool TextLineBase::setProperty(Pid id, const PropertyValue& v)
triggerLayout();
return true;
}
mu::engraving::PropertyValue TextLineBase::propertyDefault(Pid propertyId) const
{
switch (propertyId) {
case Pid::GAP_BETWEEN_TEXT_AND_LINE:
return Spatium(0.5);
default:
return SLine::propertyDefault(propertyId);
}
}
}

View file

@ -82,6 +82,7 @@ class TextLineBase : public SLine
M_PROPERTY2(HookType, endHookType, setEndHookType, HookType::NONE)
M_PROPERTY(Spatium, beginHookHeight, setBeginHookHeight)
M_PROPERTY(Spatium, endHookHeight, setEndHookHeight)
M_PROPERTY(Spatium, gapBetweenTextAndLine, setGapBetweenTextAndLine)
M_PROPERTY2(TextPlace, beginTextPlace, setBeginTextPlace, TextPlace::AUTO)
M_PROPERTY(String, beginText, setBeginText)
@ -115,8 +116,9 @@ public:
PropertyValue getProperty(Pid id) const override;
bool setProperty(Pid propertyId, const PropertyValue&) override;
PropertyValue propertyDefault(Pid) const override;
static const std::array<Pid, 26>& textLineBasePropertyIds();
static const std::array<Pid, 27>& textLineBasePropertyIds();
protected:
friend class TextLineBaseSegment;

View file

@ -82,6 +82,8 @@ void TextLineSettingsModel::createProperties()
m_startHookHeight = buildPropertyItem(Pid::BEGIN_HOOK_HEIGHT);
m_endHookHeight = buildPropertyItem(Pid::END_HOOK_HEIGHT);
m_gapBetweenTextAndLine = buildPropertyItem(Pid::GAP_BETWEEN_TEXT_AND_LINE, applyPropertyValueAndUpdateAvailability);
m_thickness = buildPropertyItem(Pid::LINE_WIDTH);
m_dashLineLength = buildPropertyItem(Pid::DASH_LINE_LEN);
m_dashGapLength = buildPropertyItem(Pid::DASH_GAP_LEN);
@ -118,6 +120,7 @@ void TextLineSettingsModel::loadProperties()
Pid::DASH_GAP_LEN,
Pid::END_HOOK_HEIGHT,
Pid::BEGIN_HOOK_HEIGHT,
Pid::GAP_BETWEEN_TEXT_AND_LINE,
Pid::PLACEMENT,
Pid::BEGIN_TEXT,
Pid::BEGIN_TEXT_OFFSET,
@ -143,6 +146,7 @@ void TextLineSettingsModel::resetProperties()
m_endHookType,
m_startHookHeight,
m_endHookHeight,
m_gapBetweenTextAndLine,
m_placement,
m_beginningText,
m_beginningTextOffset,
@ -209,6 +213,11 @@ PropertyItem* TextLineSettingsModel::endHookHeight() const
return m_endHookHeight;
}
PropertyItem* TextLineSettingsModel::gapBetweenTextAndLine() const
{
return m_gapBetweenTextAndLine;
}
PropertyItem* TextLineSettingsModel::placement() const
{
return m_placement;
@ -287,6 +296,8 @@ void TextLineSettingsModel::onUpdateLinePropertiesAvailability()
m_lineStyle->setIsEnabled(isLineAvailable);
m_thickness->setIsEnabled(isLineAvailable);
m_gapBetweenTextAndLine->setIsEnabled(isLineAvailable);
auto currentStyle = static_cast<LineTypes::LineStyle>(m_lineStyle->value().toInt());
bool areDashPropertiesAvailable = currentStyle == LineTypes::LineStyle::LINE_STYLE_DASHED;
@ -357,6 +368,10 @@ void TextLineSettingsModel::loadProperties(const PropertyIdSet& propertyIdSet)
loadPropertyItem(m_endHookHeight);
}
if (mu::contains(propertyIdSet, Pid::GAP_BETWEEN_TEXT_AND_LINE)) {
loadPropertyItem(m_gapBetweenTextAndLine);
}
if (mu::contains(propertyIdSet, Pid::PLACEMENT)) {
loadPropertyItem(m_placement);
}

View file

@ -44,6 +44,7 @@ class TextLineSettingsModel : public AbstractInspectorModel
Q_PROPERTY(PropertyItem * endHookType READ endHookType CONSTANT)
Q_PROPERTY(PropertyItem * startHookHeight READ startHookHeight CONSTANT)
Q_PROPERTY(PropertyItem * endHookHeight READ endHookHeight CONSTANT)
Q_PROPERTY(PropertyItem * gapBetweenTextAndLine READ gapBetweenTextAndLine CONSTANT)
Q_PROPERTY(PropertyItem * placement READ placement CONSTANT)
@ -73,6 +74,7 @@ public:
PropertyItem* endHookType() const;
PropertyItem* startHookHeight() const;
PropertyItem* endHookHeight() const;
PropertyItem* gapBetweenTextAndLine() const;
PropertyItem* placement() const;
@ -142,6 +144,7 @@ private:
PropertyItem* m_endHookType = nullptr;
PropertyItem* m_startHookHeight = nullptr;
PropertyItem* m_endHookHeight = nullptr;
PropertyItem* m_gapBetweenTextAndLine = nullptr;
PropertyItem* m_beginningText = nullptr;
PointFPropertyItem* m_beginningTextOffset = nullptr;

View file

@ -67,13 +67,34 @@ FocusableItem {
SeparatorLine { anchors.margins: -12 }
SpinBoxPropertyView {
id: gapBetweenTextAndLineControl
anchors.left: parent.left
anchors.right: parent.right
anchors.rightMargin: 2
titleText: qsTrc("inspector", "Gap between text and line")
propertyItem: root.model ? root.model.gapBetweenTextAndLine : null
step: 0.1
maxValue: 100.0
minValue: 0.0
decimals: 2
navigationName: "GapBetweenTextAndLine"
navigationPanel: root.navigationPanel
navigationRowStart: beginningTextOffsetSection.navigationRowEnd + 1
}
SeparatorLine { anchors.margins: -12 }
TextSection {
id: continuousTextSection
titleText: qsTrc("inspector", "Text when continuing to a new system")
propertyItem: root.model ? root.model.continuousText : null
navigationPanel: root.navigationPanel
navigationRowStart: beginningTextOffsetSection.navigationRowEnd + 1
navigationRowStart: gapBetweenTextAndLineControl.navigationRowEnd + 1
}
OffsetSection {