summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textundercolor.pngbin0 -> 6916 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textundercolor.pngbin0 -> 6916 bytes
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp15
-rw-r--r--examples/widgets/richtext/textedit/textedit.h2
-rw-r--r--examples/widgets/richtext/textedit/textedit.qrc2
-rw-r--r--src/gui/painting/qpainter.cpp6
-rw-r--r--src/gui/text/qcssparser.cpp1
-rw-r--r--src/gui/text/qcssparser_p.h1
-rw-r--r--src/gui/text/qtextdocument.cpp5
-rw-r--r--src/gui/text/qtextformat.cpp9
-rw-r--r--src/gui/text/qtexthtmlparser.cpp1
11 files changed, 38 insertions, 4 deletions
diff --git a/examples/widgets/richtext/textedit/images/mac/textundercolor.png b/examples/widgets/richtext/textedit/images/mac/textundercolor.png
new file mode 100644
index 0000000000..30e24e61c3
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textundercolor.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textundercolor.png b/examples/widgets/richtext/textedit/images/win/textundercolor.png
new file mode 100644
index 0000000000..30e24e61c3
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textundercolor.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp
index 3a1b3321a1..ed91f6e250 100644
--- a/examples/widgets/richtext/textedit/textedit.cpp
+++ b/examples/widgets/richtext/textedit/textedit.cpp
@@ -354,6 +354,10 @@ void TextEdit::setupTextActions()
actionTextColor = menu->addAction(pix, tr("&Color..."), this, &TextEdit::textColor);
tb->addAction(actionTextColor);
+ const QIcon underlineColorIcon(rsrcPath + "/textundercolor.png");
+ actionUnderlineColor = menu->addAction(underlineColorIcon, tr("Underline color..."), this, &TextEdit::underlineColor);
+ tb->addAction(actionUnderlineColor);
+
menu->addSeparator();
const QIcon checkboxIcon = QIcon::fromTheme("status-checkbox-checked", QIcon(rsrcPath + "/checkbox-checked.png"));
@@ -729,6 +733,17 @@ void TextEdit::textColor()
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)
{
if (a == actionAlignLeft)
diff --git a/examples/widgets/richtext/textedit/textedit.h b/examples/widgets/richtext/textedit/textedit.h
index 07a307f83d..debc401150 100644
--- a/examples/widgets/richtext/textedit/textedit.h
+++ b/examples/widgets/richtext/textedit/textedit.h
@@ -95,6 +95,7 @@ private slots:
void textSize(const QString &p);
void textStyle(int styleIndex);
void textColor();
+ void underlineColor();
void textAlign(QAction *a);
void setChecked(bool checked);
void indent();
@@ -125,6 +126,7 @@ private:
QAction *actionTextUnderline;
QAction *actionTextItalic;
QAction *actionTextColor;
+ QAction *actionUnderlineColor;
QAction *actionAlignLeft;
QAction *actionAlignCenter;
QAction *actionAlignRight;
diff --git a/examples/widgets/richtext/textedit/textedit.qrc b/examples/widgets/richtext/textedit/textedit.qrc
index 1641acc207..a30d50fdbf 100644
--- a/examples/widgets/richtext/textedit/textedit.qrc
+++ b/examples/widgets/richtext/textedit/textedit.qrc
@@ -22,6 +22,7 @@
<file>images/mac/textleft.png</file>
<file>images/mac/textright.png</file>
<file>images/mac/textunder.png</file>
+ <file>images/mac/textundercolor.png</file>
<file>images/mac/zoomin.png</file>
<file>images/mac/zoomout.png</file>
<file>images/win/checkbox.png</file>
@@ -45,6 +46,7 @@
<file>images/win/textleft.png</file>
<file>images/win/textright.png</file>
<file>images/win/textunder.png</file>
+ <file>images/win/textundercolor.png</file>
<file>images/win/zoomin.png</file>
<file>images/win/zoomout.png</file>
<file>example.html</file>
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index 38ce9bf604..01400a0bc8 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -6061,6 +6061,9 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const
if (flags & QTextItem::StrikeOut) {
QLineF strikeOutLine = line;
strikeOutLine.translate(0., - fe->ascent().toReal() / 3.);
+ QColor uc = charFormat.underlineColor();
+ if (uc.isValid())
+ pen.setColor(uc);
painter->setPen(pen);
if (textEngine)
textEngine->addStrikeOut(painter, strikeOutLine);
@@ -6071,6 +6074,9 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const
if (flags & QTextItem::Overline) {
QLineF overline = line;
overline.translate(0., - fe->ascent().toReal());
+ QColor uc = charFormat.underlineColor();
+ if (uc.isValid())
+ pen.setColor(uc);
painter->setPen(pen);
if (textEngine)
textEngine->addOverline(painter, overline);
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp
index 46ed67ea7d..4cc310c7e7 100644
--- a/src/gui/text/qcssparser.cpp
+++ b/src/gui/text/qcssparser.cpp
@@ -166,6 +166,7 @@ static const QCssKnownValue properties[NumProperties - 1] = {
{ "subcontrol-position", QtPosition },
{ "text-align", TextAlignment },
{ "text-decoration", TextDecoration },
+ { "text-decoration-color", TextDecorationColor },
{ "text-indent", TextIndent },
{ "text-transform", TextTransform },
{ "text-underline-style", TextUnderlineStyle },
diff --git a/src/gui/text/qcssparser_p.h b/src/gui/text/qcssparser_p.h
index 1ccfc45d21..56af5c8bb2 100644
--- a/src/gui/text/qcssparser_p.h
+++ b/src/gui/text/qcssparser_p.h
@@ -201,6 +201,7 @@ enum Property {
QtIcon,
LetterSpacing,
WordSpacing,
+ TextDecorationColor,
NumProperties
};
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index 2c0c3582ed..d3bec57bd4 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -2560,6 +2560,11 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format)
if (!atLeastOneDecorationSet)
html += QLatin1String("none");
html += QLatin1Char(';');
+ if (format.hasProperty(QTextFormat::TextUnderlineColor)) {
+ html += QLatin1String(" text-decoration-color:");
+ html += colorValue(format.underlineColor());
+ html += QLatin1Char(';');
+ }
attributesEmitted = true;
} else {
html.chop(decorationTag.size());
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index 44986c337c..80c7845410 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -642,7 +642,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
\omitvalue FirstFontProperty
\omitvalue LastFontProperty
- \value TextUnderlineColor
+ \value TextUnderlineColor Specifies the color to draw underlines, overlines and strikeouts.
\value TextVerticalAlignment
\value TextOutline
\value TextUnderlineStyle
@@ -1984,8 +1984,8 @@ QStringList QTextCharFormat::anchorNames() const
/*!
\fn void QTextCharFormat::setUnderlineColor(const QColor &color)
- Sets the underline color used for the characters with this format to
- the \a color specified.
+ Sets the color used to draw underlines, overlines and strikeouts on the
+ characters with this format to the \a color specified.
\sa underlineColor()
*/
@@ -1993,7 +1993,8 @@ QStringList QTextCharFormat::anchorNames() 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()
*/
diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp
index a242d5e645..3ad0938268 100644
--- a/src/gui/text/qtexthtmlparser.cpp
+++ b/src/gui/text/qtexthtmlparser.cpp
@@ -1346,6 +1346,7 @@ void QTextHtmlParserNode::applyCssDeclarations(const QList<QCss::Declaration> &d
default: break;
}
break;
+ case QCss::TextDecorationColor: charFormat.setUnderlineColor(decl.colorValue()); break;
case QCss::ListStyleType:
case QCss::ListStyle:
setListStyle(decl.d->values);