add alpha channel to color selector; add background color to textframe

This commit is contained in:
Werner Schweer 2012-07-20 21:46:31 +02:00
parent 65afd97a33
commit f6947290d4
14 changed files with 108 additions and 64 deletions

View file

@ -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;

View file

@ -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();
}

View file

@ -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"),
@ -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"),
@ -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();
}
//---------------------------------------------------------

View file

@ -71,6 +71,7 @@ enum ElementType {
TEXT,
INSTRUMENT_NAME,
SLUR_SEGMENT,
STAFF_LINES,
BAR_LINE,
STEM_SLASH,
LINE,
@ -121,7 +122,6 @@ enum ElementType {
NOTEDOT,
TREMOLO,
MEASURE,
STAFF_LINES,
SELECTION,
LASSO,
SHADOW_NOTE,
@ -587,6 +587,7 @@ class MScore : public QObject {
TEXT,
INSTRUMENT_NAME,
SLUR_SEGMENT,
STAFF_LINES,
BAR_LINE,
STEM_SLASH,
LINE,
@ -637,7 +638,6 @@ class MScore : public QObject {
NOTEDOT,
TREMOLO,
MEASURE,
STAFF_LINES,
SELECTION,
LASSO,
SHADOW_NOTE,

View file

@ -47,10 +47,11 @@ SimpleText::~SimpleText()
void SimpleText::draw(QPainter* p) const
{
p->setPen(textColor());
p->setFont(textStyle().fontPx(spatium()));
p->drawText(drawingRect, alignFlags(), _text);
drawFrame(p);
p->setFont(textStyle().fontPx(spatium()));
p->setBrush(Qt::NoBrush);
p->setPen(textColor());
p->drawText(drawingRect, alignFlags(), _text);
}
//---------------------------------------------------------
@ -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 {
@ -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();
}
@ -244,6 +248,15 @@ QColor SimpleText::frameColor() const
return textStyle().frameColor();
}
//---------------------------------------------------------
// backgroundColor
//---------------------------------------------------------
QColor SimpleText::backgroundColor() const
{
return textStyle().backgroundColor();
}
//---------------------------------------------------------
// frameRound
//---------------------------------------------------------

View file

@ -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;
@ -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;

View file

@ -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)
@ -681,6 +681,7 @@ TextStyleData::TextStyleData()
circle = false;
systemFlag = false;
foregroundColor = Qt::black;
backgroundColor = QColor(255, 255, 255, 0);
}
TextStyleData::TextStyleData(
@ -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;
}
@ -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()
@ -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);
@ -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")
@ -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; }
@ -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); }

View file

@ -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();
@ -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);
@ -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);

View file

@ -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,
@ -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;

View file

@ -29,15 +29,6 @@
QReadWriteLock docRenderLock;
//---------------------------------------------------------
// propertyList
//---------------------------------------------------------
Property<Text> Text::propertyList[] = {
{ P_TEXT_STYLE, &Text::pStyleIndex, 0 },
{ P_END, 0, 0 }
};
//---------------------------------------------------------
// createDoc
//---------------------------------------------------------
@ -277,6 +268,7 @@ QRectF Text::pageRectangle() const
void Text::draw(QPainter* painter) const
{
drawFrame(painter);
if (styled() && !_editMode) {
SimpleText::draw(painter);
return;
@ -309,7 +301,6 @@ void Text::draw(QPainter* painter) const
#else
_doc->documentLayout()->draw(painter, c);
#endif
drawFrame(painter);
}
//---------------------------------------------------------
@ -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;
}

View file

@ -38,8 +38,6 @@ class Text : public SimpleText {
void setUnstyledText(const QString& s);
void layoutEdit();
void* pStyleIndex() { return &_styleIndex; }
protected:
bool _editMode;
QTextCursor* _cursor;
@ -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);
};

View file

@ -423,7 +423,8 @@ void Xml::tag(const QString& name, QVariant data)
case QVariant::Color:
{
QColor color(data.value<QColor>());
*this << QString("<%1 r=\"%2\" g=\"%3\" b=\"%4\"/>\n").arg(name).arg(color.red()).arg(color.green()).arg(color.blue());
*this << QString("<%1 r=\"%2\" g=\"%3\" b=\"%4\" a=\"%5\"/>\n")
.arg(name).arg(color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha());
}
break;
case QVariant::Rect:
@ -526,6 +527,7 @@ QColor readColor(const QDomElement& e)
c.setRed(e.attribute("r").toInt());
c.setGreen(e.attribute("g").toInt());
c.setBlue(e.attribute("b").toInt());
c.setAlpha(e.attribute("a", "255").toInt());
return c;
}

View file

@ -177,6 +177,7 @@ void TextProp::setTextStyle(const TextStyle& s)
sizeIsSpatiumDependent->setChecked(s.sizeIsSpatiumDependent());
frameColor->setColor(s.frameColor());
bgColor->setColor(s.backgroundColor());
frameWidth->setValue(s.frameWidth());
frame->setChecked(s.hasFrame());
paddingWidth->setValue(s.paddingWidth());
@ -207,6 +208,7 @@ TextStyle TextProp::textStyle() const
s.setRxoff(rxOffset->value());
s.setRyoff(ryOffset->value());
s.setFrameColor(frameColor->color());
s.setBackgroundColor(bgColor->color());
s.setFrameWidth(frameWidth->value());
s.setPaddingWidth(paddingWidth->value());
s.setCircle(circleButton->isChecked());

View file

@ -888,7 +888,7 @@
</property>
</widget>
</item>
<item row="1" column="2">
<item row="2" column="0">
<widget class="QLabel" name="label_17">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
@ -897,7 +897,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Color:</string>
<string>Foreground Color:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -907,13 +907,39 @@
</property>
</widget>
</item>
<item row="1" column="3">
<item row="2" column="3">
<widget class="Awl::ColorLabel" name="bgColor">
<property name="toolTip">
<string>frame color</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Awl::ColorLabel" name="frameColor">
<property name="toolTip">
<string>frame color</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_27">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Background Color:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="indent">
<number>5</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>