Skip to content

Commit

Permalink
add alpha channel to color selector; add background color to textframe
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Jul 20, 2012
1 parent 65afd97 commit f694729
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 63 deletions.
5 changes: 4 additions & 1 deletion awl/colorlabel.cpp
Expand Up @@ -94,7 +94,10 @@ void ColorLabel::mousePressEvent(QMouseEvent*)
{
if (_pixmap)
return;
QColor c = QColorDialog::getColor(_color, this);
QColor c = QColorDialog::getColor(_color, this,
tr("MuseScore: select color"),
QColorDialog::ShowAlphaChannel
);
if (c.isValid()) {
if (_color != c) {
_color = c;
Expand Down
3 changes: 1 addition & 2 deletions libmscore/dynamic.cpp
Expand Up @@ -111,8 +111,7 @@ void Dynamic::write(Xml& xml) const
xml.tag("velocity", _velocity);
if (_dynType != DYNAMIC_PART)
xml.tag("dynType", _dynType);
if (_subtype == 0)
Text::writeProperties(xml, subtype() == 0);
Text::writeProperties(xml, subtype() == 0);
xml.etag();
}

Expand Down
4 changes: 2 additions & 2 deletions libmscore/element.cpp
Expand Up @@ -90,6 +90,7 @@ static const char* elementNames[] = {
QT_TRANSLATE_NOOP("elementName", "Text"),
QT_TRANSLATE_NOOP("elementName", "InstrumentName"),
QT_TRANSLATE_NOOP("elementName", "SlurSegment"),
QT_TRANSLATE_NOOP("elementName", "StaffLines"),
QT_TRANSLATE_NOOP("elementName", "BarLine"),
QT_TRANSLATE_NOOP("elementName", "StemSlash"),
QT_TRANSLATE_NOOP("elementName", "Line"),
Expand Down Expand Up @@ -140,7 +141,6 @@ static const char* elementNames[] = {
QT_TRANSLATE_NOOP("elementName", "NoteDot"),
QT_TRANSLATE_NOOP("elementName", "Tremolo"),
QT_TRANSLATE_NOOP("elementName", "Measure"),
QT_TRANSLATE_NOOP("elementName", "StaffLines"),
QT_TRANSLATE_NOOP("elementName", "Selection"),
QT_TRANSLATE_NOOP("elementName", "Lasso"),
QT_TRANSLATE_NOOP("elementName", "ShadowNote"),
Expand Down Expand Up @@ -1474,7 +1474,7 @@ Element* Element::name2Element(const QString& s, Score* sc)

bool elementLessThan(const Element* const e1, const Element* const e2)
{
return e1->z() > e2->z();
return e1->z() <= e2->z();
}

//---------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions libmscore/mscore.h
Expand Up @@ -71,6 +71,7 @@ enum ElementType {
TEXT,
INSTRUMENT_NAME,
SLUR_SEGMENT,
STAFF_LINES,
BAR_LINE,
STEM_SLASH,
LINE,
Expand Down Expand Up @@ -121,7 +122,6 @@ enum ElementType {
NOTEDOT,
TREMOLO,
MEASURE,
STAFF_LINES,
SELECTION,
LASSO,
SHADOW_NOTE,
Expand Down Expand Up @@ -587,6 +587,7 @@ class MScore : public QObject {
TEXT,
INSTRUMENT_NAME,
SLUR_SEGMENT,
STAFF_LINES,
BAR_LINE,
STEM_SLASH,
LINE,
Expand Down Expand Up @@ -637,7 +638,6 @@ class MScore : public QObject {
NOTEDOT,
TREMOLO,
MEASURE,
STAFF_LINES,
SELECTION,
LASSO,
SHADOW_NOTE,
Expand Down
29 changes: 21 additions & 8 deletions libmscore/simpletext.cpp
Expand Up @@ -47,10 +47,11 @@ SimpleText::~SimpleText()

void SimpleText::draw(QPainter* p) const
{
p->setPen(textColor());
drawFrame(p);
p->setFont(textStyle().fontPx(spatium()));
p->setBrush(Qt::NoBrush);
p->setPen(textColor());
p->drawText(drawingRect, alignFlags(), _text);
drawFrame(p);
}

//---------------------------------------------------------
Expand All @@ -69,7 +70,8 @@ void SimpleText::drawFrame(QPainter* painter) const
color = Qt::blue;
QPen pen(color, frameWidth() * MScore::DPMM);
painter->setPen(pen);
painter->setBrush(Qt::NoBrush);
QColor bg(backgroundColor());
painter->setBrush(bg.alpha() ? QBrush(bg) : Qt::NoBrush);
if (circle())
painter->drawArc(frame, 0, 5760);
else {
Expand All @@ -86,11 +88,13 @@ void SimpleText::drawFrame(QPainter* painter) const

QColor SimpleText::textColor() const
{
QColor color;
if (selected())
return MScore::selectColor[0];
if (!visible())
return Qt::gray;
if (!score()->printing()) {
QColor color;
if (selected())
return MScore::selectColor[0];
if (!visible())
return Qt::gray;
}
return textStyle().foregroundColor();
}

Expand Down Expand Up @@ -244,6 +248,15 @@ QColor SimpleText::frameColor() const
return textStyle().frameColor();
}

//---------------------------------------------------------
// backgroundColor
//---------------------------------------------------------

QColor SimpleText::backgroundColor() const
{
return textStyle().backgroundColor();
}

//---------------------------------------------------------
// frameRound
//---------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions libmscore/simpletext.h
Expand Up @@ -53,8 +53,8 @@ class SimpleText : public Element {
const TextStyle& textStyle() const { return _textStyle; }
TextStyle& textStyle() { return _textStyle; }

void setText(const QString& s) { _text = s; }
QString getText() const { return _text; }
void setText(const QString& s) { _text = s; }
QString getText() const { return _text; }

virtual void draw(QPainter*) const;

Expand All @@ -70,6 +70,7 @@ class SimpleText : public Element {
void setLayoutToParentWidth(bool v) { _layoutToParentWidth = v; }

qreal frameWidth() const;
QColor backgroundColor() const;
bool hasFrame() const;
qreal paddingWidth() const;
QColor frameColor() const;
Expand Down
18 changes: 13 additions & 5 deletions libmscore/style.cpp
Expand Up @@ -641,11 +641,11 @@ TextStyle::TextStyle(
const QPointF& _off, OffsetType _ot, const QPointF& _roff,
bool sd,
qreal fw, qreal pw, int fr, QColor co, bool _circle, bool _systemFlag,
QColor fg)
QColor fg, QColor bg)
{
d = new TextStyleData(_name, _family, _size,
_bold, _italic, _underline, _align, _off, _ot, _roff,
sd, fw, pw, fr, co, _circle, _systemFlag, fg);
sd, fw, pw, fr, co, _circle, _systemFlag, fg, bg);
}

TextStyle::TextStyle(const TextStyle& s)
Expand Down Expand Up @@ -681,6 +681,7 @@ TextStyleData::TextStyleData()
circle = false;
systemFlag = false;
foregroundColor = Qt::black;
backgroundColor = QColor(255, 255, 255, 0);
}

TextStyleData::TextStyleData(
Expand All @@ -690,16 +691,16 @@ TextStyleData::TextStyleData(
const QPointF& _off, OffsetType _ot, const QPointF& _roff,
bool sd,
qreal fw, qreal pw, int fr, QColor co, bool _circle, bool _systemFlag,
QColor fg)
QColor fg, QColor bg)
:
ElementLayout(_align, _off, _ot, _roff),
name(_name), size(_size), bold(_bold),
italic(_italic), underline(_underline),
sizeIsSpatiumDependent(sd), frameWidth(fw), paddingWidth(pw),
frameRound(fr), frameColor(co), circle(_circle), systemFlag(_systemFlag),
foregroundColor(fg)
foregroundColor(fg), backgroundColor(bg)
{
hasFrame = fw != 0.0;
hasFrame = (fw != 0.0) | (bg.alpha() != 0);
family = _family;
}

Expand All @@ -724,6 +725,7 @@ bool TextStyleData::operator!=(const TextStyleData& s) const
|| s.circle != circle
|| s.systemFlag != systemFlag
|| s.foregroundColor != foregroundColor
|| s.backgroundColor != backgroundColor
|| s.align() != align()
|| s.offset() != offset()
|| s.rxoff() != rxoff()
Expand Down Expand Up @@ -806,6 +808,8 @@ void TextStyleData::writeProperties(Xml& xml) const
xml.tag("sizeIsSpatiumDependent", sizeIsSpatiumDependent);
if (foregroundColor != Qt::black)
xml.tag("foregroundColor", foregroundColor);
if (backgroundColor != QColor(255, 255, 255, 0))
xml.tag("backgroundColor", backgroundColor);

if (hasFrame) {
xml.tag("frameWidth", frameWidth);
Expand Down Expand Up @@ -878,6 +882,8 @@ bool TextStyleData::readProperties(const QDomElement& e)
frameColor = readColor(e);
else if (tag == "foregroundColor")
foregroundColor = readColor(e);
else if (tag == "backgroundColor")
backgroundColor = readColor(e);
else if (tag == "circle")
circle = val.toInt();
else if (tag == "systemFlag")
Expand Down Expand Up @@ -1268,6 +1274,7 @@ QColor TextStyle::frameColor() const { return d->frameColor;
bool TextStyle::circle() const { return d->circle; }
bool TextStyle::systemFlag() const { return d->systemFlag; }
QColor TextStyle::foregroundColor() const { return d->foregroundColor; }
QColor TextStyle::backgroundColor() const { return d->backgroundColor; }
void TextStyle::setName(const QString& s) { d->name = s; }
void TextStyle::setFamily(const QString& s) { d->family = s; }
void TextStyle::setSize(qreal v) { d->size = v; }
Expand All @@ -1289,6 +1296,7 @@ void TextStyle::setFrameColor(const QColor& v) { d->frameColor = v; }
void TextStyle::setCircle(bool v) { d->circle = v; }
void TextStyle::setSystemFlag(bool v) { d->systemFlag = v; }
void TextStyle::setForegroundColor(const QColor& v) { d->foregroundColor = v; }
void TextStyle::setBackgroundColor(const QColor& v) { d->backgroundColor = v; }
void TextStyle::write(Xml& xml) const { d->write(xml); }
void TextStyle::read(const QDomElement& v) { d->read(v); }
QFont TextStyle::font(qreal space) const { return d->font(space); }
Expand Down
4 changes: 3 additions & 1 deletion libmscore/style.h
Expand Up @@ -44,7 +44,7 @@ class TextStyle {
bool sd = false,
qreal fw = 0.0, qreal pw = 0.0, int fr = 25,
QColor co = QColor(Qt::black), bool circle = false, bool systemFlag = false,
QColor fg = QColor(Qt::black));
QColor fg = QColor(Qt::black), QColor bg = QColor(255, 255, 255, 0));

TextStyle(const TextStyle&);
~TextStyle();
Expand All @@ -71,6 +71,7 @@ class TextStyle {
bool circle() const;
bool systemFlag() const;
QColor foregroundColor() const;
QColor backgroundColor() const;
void setName(const QString& s);
void setFamily(const QString& s);
void setSize(qreal v);
Expand All @@ -92,6 +93,7 @@ class TextStyle {
void setCircle(bool v);
void setSystemFlag(bool v);
void setForegroundColor(const QColor& v);
void setBackgroundColor(const QColor& v);
void write(Xml& xml) const;
void writeProperties(Xml& xml) const;
void read(const QDomElement& v);
Expand Down
3 changes: 2 additions & 1 deletion libmscore/style_p.h
Expand Up @@ -49,6 +49,7 @@ class TextStyleData : public QSharedData, public ElementLayout {
bool circle;
bool systemFlag;
QColor foregroundColor;
QColor backgroundColor;

public:
TextStyleData(QString _name, QString _family, qreal _size,
Expand All @@ -58,7 +59,7 @@ class TextStyleData : public QSharedData, public ElementLayout {
bool sizeSpatiumDependent,
qreal fw, qreal pw, int fr,
QColor co, bool circle, bool systemFlag,
QColor fg);
QColor fg, QColor bg);
TextStyleData();

void write(Xml&) const;
Expand Down
52 changes: 22 additions & 30 deletions libmscore/text.cpp
Expand Up @@ -29,15 +29,6 @@

QReadWriteLock docRenderLock;

//---------------------------------------------------------
// propertyList
//---------------------------------------------------------

Property<Text> Text::propertyList[] = {
{ P_TEXT_STYLE, &Text::pStyleIndex, 0 },
{ P_END, 0, 0 }
};

//---------------------------------------------------------
// createDoc
//---------------------------------------------------------
Expand Down Expand Up @@ -277,6 +268,7 @@ QRectF Text::pageRectangle() const

void Text::draw(QPainter* painter) const
{
drawFrame(painter);
if (styled() && !_editMode) {
SimpleText::draw(painter);
return;
Expand Down Expand Up @@ -309,7 +301,6 @@ void Text::draw(QPainter* painter) const
#else
_doc->documentLayout()->draw(painter, c);
#endif
drawFrame(painter);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1322,36 +1313,37 @@ QTextDocumentFragment Text::getFragment() const
return QTextDocumentFragment(_doc);
}

Property<Text>* Text::property(P_ID id) const
{
for (int i = 0;; ++i) {
if (propertyList[i].id == P_END)
break;
if (propertyList[i].id == id)
return &propertyList[i];
}
return 0;
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------

QVariant Text::getProperty(P_ID propertyId) const
{
Property<Text>* p = property(propertyId);
if (p)
return getVariant(propertyId, ((*(Text*)this).*(p->data))());
return Element::getProperty(propertyId);
switch(propertyId) {
case P_TEXT_STYLE:
return QVariant(_styleIndex);
default:
return Element::getProperty(propertyId);
}
}

//---------------------------------------------------------
// setProperty
//---------------------------------------------------------

bool Text::setProperty(P_ID propertyId, const QVariant& v)
{
score()->addRefresh(canvasBoundingRect());
Property<Text>* p = property(propertyId);
bool rv = true;
if (p) {
setVariant(propertyId, ((*this).*(p->data))(), v);
setGenerated(false);
switch(propertyId) {
case P_TEXT_STYLE:
_styleIndex = v.toInt();
setGenerated(false);
break;
default:
rv = Element::setProperty(propertyId, v);
break;
}
else
rv = Element::setProperty(propertyId, v);
score()->setLayoutAll(true);
return rv;
}
Expand Down
5 changes: 0 additions & 5 deletions libmscore/text.h
Expand Up @@ -38,8 +38,6 @@ class Text : public SimpleText {
void setUnstyledText(const QString& s);
void layoutEdit();

void* pStyleIndex() { return &_styleIndex; }

protected:
bool _editMode;
QTextCursor* _cursor;
Expand Down Expand Up @@ -142,9 +140,6 @@ class Text : public SimpleText {

virtual bool systemFlag() const;

static Property<Text> propertyList[];

Property<Text>* property(P_ID id) const;
QVariant getProperty(P_ID propertyId) const;
bool setProperty(P_ID propertyId, const QVariant& v);
};
Expand Down

0 comments on commit f694729

Please sign in to comment.