diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gui/text/qcssparser.cpp | 8 | ||||
| -rw-r--r-- | src/gui/text/qtextdocumentlayout.cpp | 16 | ||||
| -rw-r--r-- | src/gui/text/qtexthtmlparser.cpp | 30 |
3 files changed, 42 insertions, 12 deletions
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index ac6ddc69a83..e5815ffce2d 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -987,9 +987,11 @@ void ValueExtractor::borderValue(const Declaration &decl, int *width, QCss::Bord } data.color = parseBrushValue(decl.d->values.at(i), pal); - *color = brushFromData(data.color, pal); - if (data.color.type != BrushData::DependsOnThePalette) - decl.d->parsed = QVariant::fromValue<BorderData>(data); + if (data.color.type != BrushData::Invalid) { + *color = brushFromData(data.color, pal); + if (data.color.type != BrushData::DependsOnThePalette) + decl.d->parsed = QVariant::fromValue<BorderData>(data); + } } static void parseShorthandBackgroundProperty(const QList<QCss::Value> &values, BrushData *brush, QString *image, Repeat *repeat, Qt::Alignment *alignment, const QPalette &pal) diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index 83abe93dbf9..baff79973f2 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -1818,11 +1818,20 @@ void QTextDocumentLayoutPrivate::drawTableCell(const QRectF &cellRect, QPainter if (r >= headerRowCount) topMargin += td->headerHeight.toReal(); - if (!td->borderCollapse && td->border != 0) { + // If cell border configured, don't draw default border for cells. It will be taken care later by + // drawTableCellBorder(). + bool cellBorderConfigured = (cell.format().hasProperty(QTextFormat::TableCellLeftBorder) || + cell.format().hasProperty(QTextFormat::TableCellTopBorder) || + cell.format().hasProperty(QTextFormat::TableCellRightBorder) || + cell.format().hasProperty(QTextFormat::TableCellBottomBorder)); + + if (!td->borderCollapse && td->border != 0 && !cellBorderConfigured) { const QBrush oldBrush = painter->brush(); const QPen oldPen = painter->pen(); - const qreal border = td->border.toReal(); + // If border is configured for the table (and not explicitly for the cell), then + // always draw 1px border around the cell + const qreal border = 1; QRectF borderRect(cellRect.left() - border, cellRect.top() - border, cellRect.width() + border, cellRect.height() + border); @@ -1885,7 +1894,8 @@ void QTextDocumentLayoutPrivate::drawTableCell(const QRectF &cellRect, QPainter } // paint over the background - otherwise we would have to adjust the background paint cellRect for the border values - drawTableCellBorder(cellRect, painter, table, td, cell); + if (cellBorderConfigured) + drawTableCellBorder(cellRect, painter, table, td, cell); const QFixed verticalOffset = td->cellVerticalOffsets.at(c + r * table->columns()); diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index 05b9a1385f1..ee92cece789 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -1181,7 +1181,7 @@ void QTextHtmlParserNode::applyCssDeclarations(const QList<QCss::Declaration> &d QCss::ValueExtractor extractor(declarations); extractor.extractBox(margin, padding); - if (id == Html_td || id == Html_th) { + auto getBorderValues = [&extractor](qreal *borderWidth, QBrush *borderBrush, QTextFrameFormat::BorderStyle *borderStyles) { QCss::BorderStyle cssStyles[4]; int cssBorder[4]; QSize cssRadii[4]; // unused @@ -1193,12 +1193,16 @@ void QTextHtmlParserNode::applyCssDeclarations(const QList<QCss::Declaration> &d // QCss::BorderWidth parsing below which expects a single value // will not work as expected - which in this case does not matter // because tableBorder is not relevant for cells. - extractor.extractBorder(cssBorder, tableCellBorderBrush, cssStyles, cssRadii); + bool hit = extractor.extractBorder(cssBorder, borderBrush, cssStyles, cssRadii); for (int i = 0; i < 4; ++i) { - tableCellBorderStyle[i] = toQTextFrameFormat(cssStyles[i]); - tableCellBorder[i] = static_cast<qreal>(cssBorder[i]); + borderStyles[i] = toQTextFrameFormat(cssStyles[i]); + borderWidth[i] = static_cast<qreal>(cssBorder[i]); } - } + return hit; + }; + + if (id == Html_td || id == Html_th) + getBorderValues(tableCellBorder, tableCellBorderBrush, tableCellBorderStyle); for (int i = 0; i < declarations.size(); ++i) { const QCss::Declaration &decl = declarations.at(i); @@ -1220,6 +1224,19 @@ void QTextHtmlParserNode::applyCssDeclarations(const QList<QCss::Declaration> &d tableBorder = borders[0]; } break; + case QCss::Border: { + qreal tblBorder[4]; + QBrush tblBorderBrush[4]; + QTextFrameFormat::BorderStyle tblBorderStyle[4]; + if (getBorderValues(tblBorder, tblBorderBrush, tblBorderStyle)) { + tableBorder = tblBorder[0]; + if (tblBorderBrush[0].color().isValid()) + borderBrush = tblBorderBrush[0]; + if (tblBorderStyle[0] != static_cast<QTextFrameFormat::BorderStyle>(-1)) + borderStyle = tblBorderStyle[0]; + } + } + break; case QCss::BorderCollapse: borderCollapse = decl.borderCollapseValue(); break; @@ -1721,7 +1738,8 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) } break; case Html_table: - if (key == "border"_L1) { + // If table border already set through css style, prefer that one otherwise consider this value + if (key == "border"_L1 && !node->tableBorder) { setFloatAttribute(&node->tableBorder, value); } else if (key == "bgcolor"_L1) { QColor c = QColor::fromString(value); |
