Skip to content

Commit

Permalink
remove unstyled text
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Mar 14, 2014
1 parent 48ebde2 commit 080cddb
Show file tree
Hide file tree
Showing 31 changed files with 229 additions and 476 deletions.
3 changes: 1 addition & 2 deletions libmscore/chordrest.cpp
Expand Up @@ -717,8 +717,7 @@ Element* ChordRest::drop(const DropData& data)
TempoText* tt = static_cast<TempoText*>(e);
tt->setParent(segment());
int st = tt->textStyleType();
if (st != TEXT_STYLE_UNKNOWN)
tt->setTextStyleType(st);
tt->setTextStyleType(st);
score()->undoAddElement(tt);
}
return e;
Expand Down
3 changes: 1 addition & 2 deletions libmscore/dynamic.cpp
Expand Up @@ -274,9 +274,8 @@ void Dynamic::startEdit(MuseScoreView* v, const QPointF& p)
void Dynamic::endEdit()
{
Text::endEdit();
if (!styled() || text() != QString::fromUtf8(dynList[_dynamicType].text)) {
if (text() != QString::fromUtf8(dynList[_dynamicType].text))
_dynamicType = DYNAMIC_OTHER;
}
}

//---------------------------------------------------------
Expand Down
49 changes: 49 additions & 0 deletions libmscore/elementlayout.cpp
Expand Up @@ -75,6 +75,55 @@ void ElementLayout::layout(Element* e) const
e->setPos(p + o);
}

//---------------------------------------------------------
// writeProperties
// writout only differences to l
//---------------------------------------------------------

void ElementLayout::writeProperties(Xml& xml, const ElementLayout& l) const
{
if ((l._align & ALIGN_HMASK) != (_align & ALIGN_HMASK)) {
const char* p;
if (_align & ALIGN_HCENTER)
p = "center";
else if (_align & ALIGN_RIGHT)
p = "right";
else
p = "left";
xml.tag("halign", p);
}

if ((l._align & ALIGN_VMASK) != (_align & ALIGN_VMASK)) {
const char* p;
if (_align & ALIGN_BOTTOM)
p = "bottom";
else if (_align & ALIGN_VCENTER)
p = "center";
else if (_align & ALIGN_BASELINE)
p = "baseline";
else
p = "top";
xml.tag("valign", p);
}

if (l._offset != _offset) {
QPointF pt(_offset);
if (offsetType() == OFFSET_ABS)
pt *= INCH;
xml.tag("xoffset", pt.x()); // save in spatium or metric mm
xml.tag("yoffset", pt.y());
}

if (_offsetType != l._offsetType) {
const char* p = 0;
switch(_offsetType) {
case OFFSET_SPATIUM: p = "spatium"; break;
case OFFSET_ABS: p = "absolute"; break;
}
xml.tag("offsetType", p);
}
}

//---------------------------------------------------------
// writeProperties
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/elementlayout.h
Expand Up @@ -49,6 +49,7 @@ class ElementLayout {
void setOffsetType(OffsetType val) { _offsetType = val; }
void layout(Element*) const;
void writeProperties(Xml& xml) const;
void writeProperties(Xml& xml, const ElementLayout&) const;
bool readProperties(XmlReader& e);
};

Expand Down
12 changes: 5 additions & 7 deletions libmscore/figuredbass.cpp
Expand Up @@ -937,16 +937,15 @@ void FiguredBass::write(Xml& xml) const
xml.tag("ticks", ticks());
// if unparseable items or non-standard style, write full text data
if (items.size() < 1 || textStyleType() != TEXT_STYLE_FIGURED_BASS) {
if (items.size() < 1 || textStyleType() == TEXT_STYLE_UNSTYLED)
if (items.size() < 1)
Text::writeProperties(xml, true);
else
// if all items parsed and not unstled, we simnply have a special style: write it
xml.tag("style", textStyle().name());
}
foreach(FiguredBassItem item, items)
item.write(xml);
if (textStyleType() != TEXT_STYLE_UNSTYLED)
Element::writeProperties(xml);
Element::writeProperties(xml);
xml.etag();
}

Expand Down Expand Up @@ -980,9 +979,8 @@ void FiguredBass::read(XmlReader& e)
else if (!Text::readProperties(e))
e.unknown();
}
// if items could be parsed and text is styled, set normalized text
if(items.size() > 0 && textStyleType() != TEXT_STYLE_UNSTYLED)
setText(normalizedText); // this is the text to show while editing
// if items could be parsed set normalized text
setText(normalizedText); // this is the text to show while editing
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1197,7 +1195,7 @@ void FiguredBass::endEdit()
normalizedText.append(pItem->normalizedText());
}
// if all items parsed and text is styled, replaced entered text with normalized text
if(items.size() > 0 && textStyleType() != TEXT_STYLE_UNSTYLED) {
if (items.size()) {
setText(normalizedText);
layout();
}
Expand Down
1 change: 0 additions & 1 deletion libmscore/harmony.cpp
Expand Up @@ -137,7 +137,6 @@ Harmony::Harmony(Score* s)
: Text(s)
{
setTextStyleType(TEXT_STYLE_HARMONY);
setUnstyled();
_rootTpc = INVALID_TPC;
_baseTpc = INVALID_TPC;
_id = -1;
Expand Down
3 changes: 0 additions & 3 deletions libmscore/mscore.h
Expand Up @@ -253,9 +253,6 @@ const int STAFF_GROUP_MAX = TAB_STAFF_GROUP + 1; // out of enum to avoid co
//---------------------------------------------------------

enum {
TEXT_STYLE_UNSTYLED = -1,
TEXT_STYLE_UNKNOWN = -2,

TEXT_STYLE_DEFAULT = 0,
TEXT_STYLE_TITLE,
TEXT_STYLE_SUBTITLE,
Expand Down
3 changes: 1 addition & 2 deletions libmscore/note.cpp
Expand Up @@ -1096,8 +1096,7 @@ Element* Note::drop(const DropData& data)
// set style
Fingering* f = static_cast<Fingering*>(e);
int st = f->textStyleType();
if (st != TEXT_STYLE_UNKNOWN)
f->setTextStyleType(st);
f->setTextStyleType(st);
}
return e;

Expand Down
49 changes: 47 additions & 2 deletions libmscore/style.cpp
Expand Up @@ -779,6 +779,50 @@ void TextStyleData::writeProperties(Xml& xml) const
xml.tag("systemFlag", systemFlag);
}

//---------------------------------------------------------
// writeProperties
// write only changes to the reference r
//---------------------------------------------------------

void TextStyleData::writeProperties(Xml& xml, const TextStyleData& r) const
{
ElementLayout::writeProperties(xml, r);
if (!name.isEmpty() && name != r.name)
xml.tag("name", name);
if (family != r.family)
xml.tag("family", family);
if (size != r.size)
xml.tag("size", size);
if (bold != r.bold)
xml.tag("bold", bold);
if (italic != r.italic)
xml.tag("italic", italic);
if (underline != r.underline)
xml.tag("underline", underline);
if (sizeIsSpatiumDependent != r.sizeIsSpatiumDependent)
xml.tag("sizeIsSpatiumDependent", sizeIsSpatiumDependent);
if (foregroundColor != r.foregroundColor)
xml.tag("foregroundColor", foregroundColor);
if (backgroundColor != r.backgroundColor)
xml.tag("backgroundColor", backgroundColor);
if (hasFrame != r.hasFrame)
xml.tag("frame", hasFrame);
if (hasFrame) {
if (frameWidth.val() != r.frameWidth.val())
xml.tag("frameWidthS", frameWidth.val());
if (paddingWidth.val() != r.paddingWidth.val())
xml.tag("paddingWidthS", paddingWidth.val());
if (frameRound != r.frameRound)
xml.tag("frameRound", frameRound);
if (frameColor != r.frameColor)
xml.tag("frameColor", frameColor);
if (circle != r.circle)
xml.tag("circle", circle);
}
if (systemFlag != r.systemFlag)
xml.tag("systemFlag", systemFlag);
}

//---------------------------------------------------------
// read
//---------------------------------------------------------
Expand Down Expand Up @@ -830,7 +874,7 @@ bool TextStyleData::readProperties(XmlReader& e)
hasFrame = true;
frameWidth = Spatium(e.readDouble());
}
else if (tag == "frame") // obsolete
else if (tag == "frame")
hasFrame = e.readInt();
else if (tag == "paddingWidth") // obsolete
paddingWidthMM = e.readDouble();
Expand Down Expand Up @@ -1151,7 +1195,7 @@ int StyleData::textStyleType(const QString& name) const
if (name == "Dynamics2")
return TEXT_STYLE_DYNAMICS;
qDebug("TextStyleType <%s> not found", qPrintable(name));
return TEXT_STYLE_UNKNOWN;
return TEXT_STYLE_DEFAULT;
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1226,6 +1270,7 @@ QFontMetricsF TextStyle::fontMetrics(qreal space) const { return d->fontMetrics
bool TextStyle::operator!=(const TextStyle& s) const { return d->operator!=(*s.d); }
void TextStyle::layout(Element* e) const { d->layout(e); }
void TextStyle::writeProperties(Xml& xml) const { d->writeProperties(xml); }
void TextStyle::writeProperties(Xml& xml, const TextStyle& r) const { d->writeProperties(xml, *r.d); }
bool TextStyle::readProperties(XmlReader& v) { return d->readProperties(v); }

//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/style.h
Expand Up @@ -109,6 +109,7 @@ class TextStyle {
Hidden hidden() const { return _hidden; }
void write(Xml& xml) const;
void writeProperties(Xml& xml) const;
void writeProperties(Xml& xml, const TextStyle&) const;
void read(XmlReader& v);
bool readProperties(XmlReader& v);
QFont font(qreal spatium) const;
Expand Down
1 change: 1 addition & 0 deletions libmscore/style_p.h
Expand Up @@ -69,6 +69,7 @@ class TextStyleData : public QSharedData, public ElementLayout {

void write(Xml&) const;
void writeProperties(Xml& xml) const;
void writeProperties(Xml& xml, const TextStyleData&) const;
void read(XmlReader&);
bool readProperties(XmlReader& v);

Expand Down
23 changes: 7 additions & 16 deletions libmscore/text.cpp
Expand Up @@ -1737,10 +1737,10 @@ void Text::read(XmlReader& e)
void Text::writeProperties(Xml& xml, bool writeText, bool writeStyle) const
{
Element::writeProperties(xml);
if (xml.clipboardmode || styled())
if (writeStyle) {
xml.tag("style", textStyle().name());
if ((xml.clipboardmode || !styled()) && writeStyle)
_textStyle.writeProperties(xml);
_textStyle.writeProperties(xml, textStyle());
}
if (writeText)
xml.writeXml("text", text());
}
Expand All @@ -1761,7 +1761,6 @@ bool Text::readProperties(XmlReader& e)
if (ok) {
// obsolete old text styles
switch (i) {
case 1: i = TEXT_STYLE_UNSTYLED; break;
case 2: i = TEXT_STYLE_TITLE; break;
case 3: i = TEXT_STYLE_SUBTITLE; break;
case 4: i = TEXT_STYLE_COMPOSER; break;
Expand Down Expand Up @@ -1802,20 +1801,14 @@ bool Text::readProperties(XmlReader& e)
case 0:
default:
qDebug("Text:readProperties: style %d<%s> invalid", i, qPrintable(val));
i = TEXT_STYLE_UNSTYLED;
i = TEXT_STYLE_DEFAULT;
break;
}
st = i;
}
else
st = score()->style()->textStyleType(val);

if (st == TEXT_STYLE_UNSTYLED)
setUnstyled();
else if (st == TEXT_STYLE_UNKNOWN)
_styleIndex = st;
else
setTextStyleType(st);
setTextStyleType(st);
}
else if (tag == "styleName") // obsolete, unstyled text
e.skipCurrentElement(); // _styleName = val;
Expand Down Expand Up @@ -1869,8 +1862,7 @@ bool Text::readProperties(XmlReader& e)

void Text::textStyleChanged()
{
if (_styleIndex != TEXT_STYLE_UNKNOWN && _styleIndex != TEXT_STYLE_UNSTYLED)
setTextStyle(score()->textStyle(_styleIndex));
setTextStyle(score()->textStyle(_styleIndex));
score()->setLayoutAll(true);
}

Expand All @@ -1881,8 +1873,7 @@ void Text::textStyleChanged()
void Text::setTextStyleType(int st)
{
_styleIndex = st;
if (st != TEXT_STYLE_UNKNOWN && st != TEXT_STYLE_UNSTYLED)
setTextStyle(score()->textStyle(st));
setTextStyle(score()->textStyle(st));
}

//---------------------------------------------------------
Expand Down
13 changes: 5 additions & 8 deletions libmscore/text.h
Expand Up @@ -170,7 +170,7 @@ class Text : public Element {
QString _text;
QList<TextBlock> _layout;
QRectF frame; // calculated in layout()
int _styleIndex; // set to TEXT_STYLE_UNTEXT if not styled
int _styleIndex;

bool _layoutToParentWidth;
bool _editMode;
Expand Down Expand Up @@ -207,20 +207,18 @@ class Text : public Element {

virtual void draw(QPainter*) const override;

bool editMode() const { return _editMode; }
void setEditMode(bool val) { _editMode = val; }
bool editMode() const { return _editMode; }
void setEditMode(bool val) { _editMode = val; }

void setTextStyle(const TextStyle& st) { _textStyle = st; }
const TextStyle& textStyle() const { return _textStyle; }
TextStyle& textStyle() { return _textStyle; }
void setUnstyled() { _styleIndex = TEXT_STYLE_UNSTYLED; }
bool styled() const { return _styleIndex != TEXT_STYLE_UNSTYLED; }
int textStyleType() const { return _styleIndex; }
int textStyleType() const { return _styleIndex; }
void setTextStyleType(int);

void setPlainText(const QString&);
void setText(const QString&);
QString text() const { return _text; }
QString text() const { return _text; }
void insertText(const QString&);

virtual void layout() override;
Expand Down Expand Up @@ -262,7 +260,6 @@ class Text : public Element {
void writeProperties(Xml&, bool = true, bool = true) const;
bool readProperties(XmlReader&);


void spellCheckUnderline(bool) {}
virtual void textStyleChanged();

Expand Down
10 changes: 2 additions & 8 deletions libmscore/textline.cpp
Expand Up @@ -175,10 +175,7 @@ void TextLineSegment::layout1()
_text->setParent(this);
}
else {
if (tl->_beginText->styled())
_text->setTextStyleType(tl->_beginText->textStyleType());
else
_text->setTextStyle(tl->_beginText->textStyle());
_text->setTextStyleType(tl->_beginText->textStyleType());
_text->setText(tl->_beginText->text());
}
}
Expand All @@ -196,10 +193,7 @@ void TextLineSegment::layout1()
_text->setParent(this);
}
else {
if (tl->_beginText->styled())
_text->setTextStyleType(tl->_beginText->textStyleType());
else
_text->setTextStyle(tl->_beginText->textStyle());
_text->setTextStyleType(tl->_beginText->textStyleType());
_text->setText(tl->_continueText->text());
}
}
Expand Down

0 comments on commit 080cddb

Please sign in to comment.