Support CSS text-decoration-color in underlines, overlines, strikethrough
Also add a feature to the textedit example to set this value. [ChangeLog][QtGui][CSS] The CSS text-decoration-color attribute is now supported in rich text spans with underlines, overlines and strikethrough. Fixes: QTBUG-82114 Task-number: QTBUG-39617 Change-Id: I0065cb5431833da55b0f503ce7ff2b83b74b718a Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
parent
05f7dd5ead
commit
688602704d
BIN
examples/widgets/richtext/textedit/images/mac/textundercolor.png
Normal file
BIN
examples/widgets/richtext/textedit/images/mac/textundercolor.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
BIN
examples/widgets/richtext/textedit/images/win/textundercolor.png
Normal file
BIN
examples/widgets/richtext/textedit/images/win/textundercolor.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
@ -354,6 +354,10 @@ void TextEdit::setupTextActions()
|
|||||||
actionTextColor = menu->addAction(pix, tr("&Color..."), this, &TextEdit::textColor);
|
actionTextColor = menu->addAction(pix, tr("&Color..."), this, &TextEdit::textColor);
|
||||||
tb->addAction(actionTextColor);
|
tb->addAction(actionTextColor);
|
||||||
|
|
||||||
|
const QIcon underlineColorIcon(rsrcPath + "/textundercolor.png");
|
||||||
|
actionUnderlineColor = menu->addAction(underlineColorIcon, tr("Underline color..."), this, &TextEdit::underlineColor);
|
||||||
|
tb->addAction(actionUnderlineColor);
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
const QIcon checkboxIcon = QIcon::fromTheme("status-checkbox-checked", QIcon(rsrcPath + "/checkbox-checked.png"));
|
const QIcon checkboxIcon = QIcon::fromTheme("status-checkbox-checked", QIcon(rsrcPath + "/checkbox-checked.png"));
|
||||||
@ -729,6 +733,17 @@ void TextEdit::textColor()
|
|||||||
colorChanged(col);
|
colorChanged(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEdit::underlineColor()
|
||||||
|
{
|
||||||
|
QColor col = QColorDialog::getColor(Qt::black, this);
|
||||||
|
if (!col.isValid())
|
||||||
|
return;
|
||||||
|
QTextCharFormat fmt;
|
||||||
|
fmt.setUnderlineColor(col);
|
||||||
|
mergeFormatOnWordOrSelection(fmt);
|
||||||
|
colorChanged(col);
|
||||||
|
}
|
||||||
|
|
||||||
void TextEdit::textAlign(QAction *a)
|
void TextEdit::textAlign(QAction *a)
|
||||||
{
|
{
|
||||||
if (a == actionAlignLeft)
|
if (a == actionAlignLeft)
|
||||||
|
@ -95,6 +95,7 @@ private slots:
|
|||||||
void textSize(const QString &p);
|
void textSize(const QString &p);
|
||||||
void textStyle(int styleIndex);
|
void textStyle(int styleIndex);
|
||||||
void textColor();
|
void textColor();
|
||||||
|
void underlineColor();
|
||||||
void textAlign(QAction *a);
|
void textAlign(QAction *a);
|
||||||
void setChecked(bool checked);
|
void setChecked(bool checked);
|
||||||
void indent();
|
void indent();
|
||||||
@ -125,6 +126,7 @@ private:
|
|||||||
QAction *actionTextUnderline;
|
QAction *actionTextUnderline;
|
||||||
QAction *actionTextItalic;
|
QAction *actionTextItalic;
|
||||||
QAction *actionTextColor;
|
QAction *actionTextColor;
|
||||||
|
QAction *actionUnderlineColor;
|
||||||
QAction *actionAlignLeft;
|
QAction *actionAlignLeft;
|
||||||
QAction *actionAlignCenter;
|
QAction *actionAlignCenter;
|
||||||
QAction *actionAlignRight;
|
QAction *actionAlignRight;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
<file>images/mac/textleft.png</file>
|
<file>images/mac/textleft.png</file>
|
||||||
<file>images/mac/textright.png</file>
|
<file>images/mac/textright.png</file>
|
||||||
<file>images/mac/textunder.png</file>
|
<file>images/mac/textunder.png</file>
|
||||||
|
<file>images/mac/textundercolor.png</file>
|
||||||
<file>images/mac/zoomin.png</file>
|
<file>images/mac/zoomin.png</file>
|
||||||
<file>images/mac/zoomout.png</file>
|
<file>images/mac/zoomout.png</file>
|
||||||
<file>images/win/checkbox.png</file>
|
<file>images/win/checkbox.png</file>
|
||||||
@ -45,6 +46,7 @@
|
|||||||
<file>images/win/textleft.png</file>
|
<file>images/win/textleft.png</file>
|
||||||
<file>images/win/textright.png</file>
|
<file>images/win/textright.png</file>
|
||||||
<file>images/win/textunder.png</file>
|
<file>images/win/textunder.png</file>
|
||||||
|
<file>images/win/textundercolor.png</file>
|
||||||
<file>images/win/zoomin.png</file>
|
<file>images/win/zoomin.png</file>
|
||||||
<file>images/win/zoomout.png</file>
|
<file>images/win/zoomout.png</file>
|
||||||
<file>example.html</file>
|
<file>example.html</file>
|
||||||
|
@ -6061,6 +6061,9 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const
|
|||||||
if (flags & QTextItem::StrikeOut) {
|
if (flags & QTextItem::StrikeOut) {
|
||||||
QLineF strikeOutLine = line;
|
QLineF strikeOutLine = line;
|
||||||
strikeOutLine.translate(0., - fe->ascent().toReal() / 3.);
|
strikeOutLine.translate(0., - fe->ascent().toReal() / 3.);
|
||||||
|
QColor uc = charFormat.underlineColor();
|
||||||
|
if (uc.isValid())
|
||||||
|
pen.setColor(uc);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
if (textEngine)
|
if (textEngine)
|
||||||
textEngine->addStrikeOut(painter, strikeOutLine);
|
textEngine->addStrikeOut(painter, strikeOutLine);
|
||||||
@ -6071,6 +6074,9 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const
|
|||||||
if (flags & QTextItem::Overline) {
|
if (flags & QTextItem::Overline) {
|
||||||
QLineF overline = line;
|
QLineF overline = line;
|
||||||
overline.translate(0., - fe->ascent().toReal());
|
overline.translate(0., - fe->ascent().toReal());
|
||||||
|
QColor uc = charFormat.underlineColor();
|
||||||
|
if (uc.isValid())
|
||||||
|
pen.setColor(uc);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
if (textEngine)
|
if (textEngine)
|
||||||
textEngine->addOverline(painter, overline);
|
textEngine->addOverline(painter, overline);
|
||||||
|
@ -166,6 +166,7 @@ static const QCssKnownValue properties[NumProperties - 1] = {
|
|||||||
{ "subcontrol-position", QtPosition },
|
{ "subcontrol-position", QtPosition },
|
||||||
{ "text-align", TextAlignment },
|
{ "text-align", TextAlignment },
|
||||||
{ "text-decoration", TextDecoration },
|
{ "text-decoration", TextDecoration },
|
||||||
|
{ "text-decoration-color", TextDecorationColor },
|
||||||
{ "text-indent", TextIndent },
|
{ "text-indent", TextIndent },
|
||||||
{ "text-transform", TextTransform },
|
{ "text-transform", TextTransform },
|
||||||
{ "text-underline-style", TextUnderlineStyle },
|
{ "text-underline-style", TextUnderlineStyle },
|
||||||
|
@ -201,6 +201,7 @@ enum Property {
|
|||||||
QtIcon,
|
QtIcon,
|
||||||
LetterSpacing,
|
LetterSpacing,
|
||||||
WordSpacing,
|
WordSpacing,
|
||||||
|
TextDecorationColor,
|
||||||
NumProperties
|
NumProperties
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2560,6 +2560,11 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format)
|
|||||||
if (!atLeastOneDecorationSet)
|
if (!atLeastOneDecorationSet)
|
||||||
html += QLatin1String("none");
|
html += QLatin1String("none");
|
||||||
html += QLatin1Char(';');
|
html += QLatin1Char(';');
|
||||||
|
if (format.hasProperty(QTextFormat::TextUnderlineColor)) {
|
||||||
|
html += QLatin1String(" text-decoration-color:");
|
||||||
|
html += colorValue(format.underlineColor());
|
||||||
|
html += QLatin1Char(';');
|
||||||
|
}
|
||||||
attributesEmitted = true;
|
attributesEmitted = true;
|
||||||
} else {
|
} else {
|
||||||
html.chop(decorationTag.size());
|
html.chop(decorationTag.size());
|
||||||
|
@ -642,7 +642,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
|
|||||||
\omitvalue FirstFontProperty
|
\omitvalue FirstFontProperty
|
||||||
\omitvalue LastFontProperty
|
\omitvalue LastFontProperty
|
||||||
|
|
||||||
\value TextUnderlineColor
|
\value TextUnderlineColor Specifies the color to draw underlines, overlines and strikeouts.
|
||||||
\value TextVerticalAlignment
|
\value TextVerticalAlignment
|
||||||
\value TextOutline
|
\value TextOutline
|
||||||
\value TextUnderlineStyle
|
\value TextUnderlineStyle
|
||||||
@ -1984,8 +1984,8 @@ QStringList QTextCharFormat::anchorNames() const
|
|||||||
/*!
|
/*!
|
||||||
\fn void QTextCharFormat::setUnderlineColor(const QColor &color)
|
\fn void QTextCharFormat::setUnderlineColor(const QColor &color)
|
||||||
|
|
||||||
Sets the underline color used for the characters with this format to
|
Sets the color used to draw underlines, overlines and strikeouts on the
|
||||||
the \a color specified.
|
characters with this format to the \a color specified.
|
||||||
|
|
||||||
\sa underlineColor()
|
\sa underlineColor()
|
||||||
*/
|
*/
|
||||||
@ -1993,7 +1993,8 @@ QStringList QTextCharFormat::anchorNames() const
|
|||||||
/*!
|
/*!
|
||||||
\fn QColor QTextCharFormat::underlineColor() const
|
\fn QColor QTextCharFormat::underlineColor() const
|
||||||
|
|
||||||
Returns the color used to underline the characters with this format.
|
Returns the color used to draw underlines, overlines and strikeouts
|
||||||
|
on the characters with this format.
|
||||||
|
|
||||||
\sa setUnderlineColor()
|
\sa setUnderlineColor()
|
||||||
*/
|
*/
|
||||||
|
@ -1346,6 +1346,7 @@ void QTextHtmlParserNode::applyCssDeclarations(const QList<QCss::Declaration> &d
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case QCss::TextDecorationColor: charFormat.setUnderlineColor(decl.colorValue()); break;
|
||||||
case QCss::ListStyleType:
|
case QCss::ListStyleType:
|
||||||
case QCss::ListStyle:
|
case QCss::ListStyle:
|
||||||
setListStyle(decl.d->values);
|
setListStyle(decl.d->values);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user