QTextDocument: allow css-styling of table cell borders
This allows to set the width, style and color of each table cell's edge (left, right, top, bottom). Setting the table's border-collapse mode will disable explicit cell spacing. The basic CSS border collision rules are applied (wider border wins, vertical over horizontal). Setting the table's border width to a value >= 1 and enabling borderCollapse will now draw a simple and clean table grid (1px) with an outer border of the specified width and color. [ChangeLog][QtGui][QTextDocument] Added CSS style table cell border formatting with border-collapse mode. Change-Id: I324d82284802df4c88c13c5b902fec1f4768b67e Fixes: QTBUG-36152 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
bab8262bce
commit
8664ee610d
@ -1175,12 +1175,75 @@
|
||||
\row \li \c vertical-align
|
||||
\li baseline | sub | super | middle | top | bottom
|
||||
\li Vertical text alignment. For vertical alignment in text table cells only middle, top, and bottom apply.
|
||||
\row \li \c border-collapse
|
||||
\li collapse | separate
|
||||
\li Border Collapse mode for text tables. If set to collapse, cell-spacing will not be applied.
|
||||
\row \li \c border-color
|
||||
\li <color>
|
||||
\li Border color for text tables.
|
||||
\li Border color for text tables and table cells.
|
||||
\row \li \c border-top-color
|
||||
\li <color>
|
||||
\li Top border color for table cells.
|
||||
\row \li \c border-bottom-color
|
||||
\li <color>
|
||||
\li Bottom border color for table cells.
|
||||
\row \li \c border-left-color
|
||||
\li <color>
|
||||
\li Left border color for table cells.
|
||||
\row \li \c border-right-color
|
||||
\li <color>
|
||||
\li Right border color for table cells.
|
||||
\row \li \c border-style
|
||||
\li none | dotted | dashed | dot-dash | dot-dot-dash | solid | double | groove | ridge | inset | outset
|
||||
\li Border style for text tables.
|
||||
\li Border style for text tables and table cells.
|
||||
\row \li \c border-top-style
|
||||
\li <color>
|
||||
\li Top border style for table cells.
|
||||
\row \li \c border-bottom-style
|
||||
\li <color>
|
||||
\li Bottom border style for table cells.
|
||||
\row \li \c border-left-style
|
||||
\li <color>
|
||||
\li Left border style for table cells.
|
||||
\row \li \c border-right-style
|
||||
\li <color>
|
||||
\li Right border style for table cells.
|
||||
\row \li \c border-width
|
||||
\li <width>px
|
||||
\li Width of table or cell border
|
||||
\row \li \c border-top-width
|
||||
\li <length>px
|
||||
\li Top border width for table cells.
|
||||
\row \li \c border-bottom-width
|
||||
\li <length>px
|
||||
\li Bottom border width for table cells.
|
||||
\row \li \c border-left-width
|
||||
\li <length>px
|
||||
\li Left border width for table cells.
|
||||
\row \li \c border-right-width
|
||||
\li <length>px
|
||||
\li Right border width for table cells.
|
||||
\row \li \c border-top
|
||||
\li <width>px <border-style> <border-color>
|
||||
\li Shorthand for setting top border width, style and color
|
||||
\row \li \c border-bottom
|
||||
\li <width>px <border-style> <border-color>
|
||||
\li Shorthand for setting bottom border width, style and color
|
||||
\row \li \c border-left
|
||||
\li <width>px <border-style> <border-color>
|
||||
\li Shorthand for setting left border width, style and color
|
||||
\row \li \c border-right
|
||||
\li <width>px <border-style> <border-color>
|
||||
\li Shorthand for setting right border width, style and color
|
||||
\row \li \c border-top
|
||||
\li <width>px <border-style> <border-color>
|
||||
\li Shorthand for setting top border width, style and color
|
||||
\row \li \c border-bottom
|
||||
\li <width>px <border-style> <border-color>
|
||||
\li Shorthand for setting bottom border width, style and color
|
||||
\row \li \c border
|
||||
\li <width>px <border-style> <border-color>
|
||||
\li Shorthand for setting all four border's width, style and color
|
||||
\row \li \c background
|
||||
\li [ <'background-color'> || <'background-image'> ]
|
||||
\li Background shorthand property
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -660,6 +660,23 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
|
||||
\value TableCellTopPadding
|
||||
\value TableCellBottomPadding
|
||||
|
||||
Table cell properties intended for use with \l QTextTableFormat::borderCollapse enabled
|
||||
|
||||
\value TableCellTopBorder
|
||||
\value TableCellBottomBorder
|
||||
\value TableCellLeftBorder
|
||||
\value TableCellRightBorder
|
||||
|
||||
\value TableCellTopBorderStyle
|
||||
\value TableCellBottomBorderStyle
|
||||
\value TableCellLeftBorderStyle
|
||||
\value TableCellRightBorderStyle
|
||||
|
||||
\value TableCellTopBorderBrush
|
||||
\value TableCellBottomBorderBrush
|
||||
\value TableCellLeftBorderBrush
|
||||
\value TableCellRightBorderBrush
|
||||
|
||||
Image properties
|
||||
|
||||
\value ImageName The filename or source of the image.
|
||||
@ -3100,6 +3117,8 @@ QTextTableFormat::QTextTableFormat(const QTextFormat &fmt)
|
||||
|
||||
Sets the cell \a spacing for the table. This determines the distance
|
||||
between adjacent cells.
|
||||
|
||||
This property will be ignored if \l borderCollapse is enabled.
|
||||
*/
|
||||
|
||||
/*!
|
||||
@ -3150,6 +3169,44 @@ QTextTableFormat::QTextTableFormat(const QTextFormat &fmt)
|
||||
\sa setHeaderRowCount()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableFormat::setBorderCollapse(bool borderCollapse)
|
||||
\since 5.14
|
||||
|
||||
Enabling \a borderCollapse will have the following implications:
|
||||
\list
|
||||
\li The borders and grid of the table will be rendered following the
|
||||
CSS table \c border-collapse: \c collapse rules
|
||||
\li Setting the \c border property to a minimum value of \c 1 will render a
|
||||
one pixel solid inner table grid using the \l borderBrush property and an
|
||||
outer border as specified
|
||||
\li The various border style properties of \l QTextTableCellFormat can be used to
|
||||
customize the grid and have precedence over the border and grid of the table
|
||||
\li The \l cellSpacing property will be ignored
|
||||
\li For print pagination:
|
||||
\list
|
||||
\li Columns continued on a page will not have their top cell border rendered
|
||||
\li Repeated header rows will always have their bottom cell border rendered
|
||||
\endlist
|
||||
\endlist
|
||||
|
||||
With borderCollapse disabled, cell borders can still be styled
|
||||
using QTextTableCellFormat but styling will be applied only within
|
||||
the cell's frame, which is probably not very useful in practice.
|
||||
|
||||
\sa setBorder(), setBorderBrush(), setBorderStyle()
|
||||
\sa QTextTableCellFormat
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QTextTableFormat::borderCollapse() const
|
||||
\since 5.14
|
||||
|
||||
Returns true if borderCollapse is enabled.
|
||||
|
||||
\sa setBorderCollapse()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextFormat::setBackground(const QBrush &brush)
|
||||
|
||||
@ -3488,6 +3545,228 @@ QTextImageFormat::QTextImageFormat(const QTextFormat &fmt)
|
||||
\sa setLeftPadding(), setRightPadding(), setTopPadding(), setBottomPadding()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setTopBorder(qreal width)
|
||||
\since 5.14
|
||||
|
||||
Sets the top border \a width of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn qreal QTextTableCellFormat::topBorder() const
|
||||
\since 5.14
|
||||
|
||||
Returns the top border width of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setBottomBorder(qreal width)
|
||||
\since 5.14
|
||||
|
||||
Sets the bottom border \a width of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn qreal QTextTableCellFormat::bottomBorder() const
|
||||
\since 5.14
|
||||
|
||||
Returns the bottom border width of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setLeftBorder(qreal width)
|
||||
\since 5.14
|
||||
|
||||
Sets the left border \a width of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn qreal QTextTableCellFormat::leftBorder() const
|
||||
\since 5.14
|
||||
|
||||
Returns the left border width of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setRightBorder(qreal width)
|
||||
\since 5.14
|
||||
|
||||
Sets the right border \a width of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn qreal QTextTableCellFormat::rightBorder() const
|
||||
\since 5.14
|
||||
|
||||
Returns the right border width of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setBorder(qreal width)
|
||||
\since 5.14
|
||||
|
||||
Sets the left, right, top, and bottom border \a width of the table cell.
|
||||
|
||||
\sa setLeftBorder(), setRightBorder(), setTopBorder(), setBottomBorder()
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setTopBorderStyle(QTextFrameFormat::BorderStyle style)
|
||||
\since 5.14
|
||||
|
||||
Sets the top border \a style of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QTextFrameFormat::BorderStyle QTextTableCellFormat::topBorderStyle() const
|
||||
\since 5.14
|
||||
|
||||
Returns the top border style of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setBottomBorderStyle(QTextFrameFormat::BorderStyle style)
|
||||
\since 5.14
|
||||
|
||||
Sets the bottom border \a style of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QTextFrameFormat::BorderStyle QTextTableCellFormat::bottomBorderStyle() const
|
||||
\since 5.14
|
||||
|
||||
Returns the bottom border style of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setLeftBorderStyle(QTextFrameFormat::BorderStyle style)
|
||||
\since 5.14
|
||||
|
||||
Sets the left border \a style of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QTextFrameFormat::BorderStyle QTextTableCellFormat::leftBorderStyle() const
|
||||
\since 5.14
|
||||
|
||||
Returns the left border style of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setRightBorderStyle(QTextFrameFormat::BorderStyle style)
|
||||
\since 5.14
|
||||
|
||||
Sets the right border \a style of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QTextFrameFormat::BorderStyle QTextTableCellFormat::rightBorderStyle() const
|
||||
\since 5.14
|
||||
|
||||
Returns the right border style of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setBorderStyle(QTextFrameFormat::BorderStyle style)
|
||||
\since 5.14
|
||||
|
||||
Sets the left, right, top, and bottom border \a style of the table cell.
|
||||
|
||||
\sa setLeftBorderStyle(), setRightBorderStyle(), setTopBorderStyle(), setBottomBorderStyle()
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setTopBorderBrush(const QBrush &brush)
|
||||
\since 5.14
|
||||
|
||||
Sets the top border \a brush of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QBrush QTextTableCellFormat::topBorderBrush() const
|
||||
\since 5.14
|
||||
|
||||
Returns the top border brush of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setBottomBorderBrush(const QBrush &brush)
|
||||
\since 5.14
|
||||
|
||||
Sets the bottom border \a brush of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QBrush QTextTableCellFormat::bottomBorderBrush() const
|
||||
\since 5.14
|
||||
|
||||
Returns the bottom border brush of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setLeftBorderBrush(const QBrush &brush)
|
||||
\since 5.14
|
||||
|
||||
Sets the left border \a brush of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QBrush QTextTableCellFormat::leftBorderBrush() const
|
||||
\since 5.14
|
||||
|
||||
Returns the left border brush of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setRightBorderBrush(const QBrush &brush)
|
||||
\since 5.14
|
||||
|
||||
Sets the right border \a brush of the table cell.
|
||||
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QBrush QTextTableCellFormat::rightBorderBrush() const
|
||||
\since 5.14
|
||||
|
||||
Returns the right border brush of the table cell.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QTextTableCellFormat::setBorderBrush(const QBrush &brush)
|
||||
\since 5.14
|
||||
|
||||
Sets the left, right, top, and bottom border \a brush of the table cell.
|
||||
|
||||
\sa setLeftBorderBrush(), setRightBorderBrush(), setTopBorderBrush(), setBottomBorderBrush()
|
||||
\sa QTextTableFormat::setBorderCollapse
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QTextTableCellFormat::isValid() const
|
||||
\since 4.4
|
||||
|
@ -242,6 +242,7 @@ public:
|
||||
TableCellSpacing = 0x4102,
|
||||
TableCellPadding = 0x4103,
|
||||
TableHeaderRowCount = 0x4104,
|
||||
TableBorderCollapse = 0x4105,
|
||||
|
||||
// table cell properties
|
||||
TableCellRowSpan = 0x4810,
|
||||
@ -252,6 +253,21 @@ public:
|
||||
TableCellLeftPadding = 0x4814,
|
||||
TableCellRightPadding = 0x4815,
|
||||
|
||||
TableCellTopBorder = 0x4816,
|
||||
TableCellBottomBorder = 0x4817,
|
||||
TableCellLeftBorder = 0x4818,
|
||||
TableCellRightBorder = 0x4819,
|
||||
|
||||
TableCellTopBorderStyle = 0x481a,
|
||||
TableCellBottomBorderStyle = 0x481b,
|
||||
TableCellLeftBorderStyle = 0x481c,
|
||||
TableCellRightBorderStyle = 0x481d,
|
||||
|
||||
TableCellTopBorderBrush = 0x481e,
|
||||
TableCellBottomBorderBrush = 0x481f,
|
||||
TableCellLeftBorderBrush = 0x4820,
|
||||
TableCellRightBorderBrush = 0x4821,
|
||||
|
||||
// image properties
|
||||
ImageName = 0x5000,
|
||||
ImageTitle = 0x5001,
|
||||
@ -966,6 +982,11 @@ public:
|
||||
inline int headerRowCount() const
|
||||
{ return intProperty(TableHeaderRowCount); }
|
||||
|
||||
inline void setBorderCollapse(bool borderCollapse)
|
||||
{ setProperty(TableBorderCollapse, borderCollapse); }
|
||||
inline bool borderCollapse() const
|
||||
{ return boolProperty(TableBorderCollapse); }
|
||||
|
||||
protected:
|
||||
explicit QTextTableFormat(const QTextFormat &fmt);
|
||||
friend class QTextFormat;
|
||||
@ -1007,6 +1028,72 @@ public:
|
||||
|
||||
inline void setPadding(qreal padding);
|
||||
|
||||
inline void setTopBorder(qreal width)
|
||||
{ setProperty(TableCellTopBorder, width); }
|
||||
inline qreal topBorder() const
|
||||
{ return doubleProperty(TableCellTopBorder); }
|
||||
|
||||
inline void setBottomBorder(qreal width)
|
||||
{ setProperty(TableCellBottomBorder, width); }
|
||||
inline qreal bottomBorder() const
|
||||
{ return doubleProperty(TableCellBottomBorder); }
|
||||
|
||||
inline void setLeftBorder(qreal width)
|
||||
{ setProperty(TableCellLeftBorder, width); }
|
||||
inline qreal leftBorder() const
|
||||
{ return doubleProperty(TableCellLeftBorder); }
|
||||
|
||||
inline void setRightBorder(qreal width)
|
||||
{ setProperty(TableCellRightBorder, width); }
|
||||
inline qreal rightBorder() const
|
||||
{ return doubleProperty(TableCellRightBorder); }
|
||||
|
||||
inline void setBorder(qreal width);
|
||||
|
||||
inline void setTopBorderStyle(QTextFrameFormat::BorderStyle style)
|
||||
{ setProperty(TableCellTopBorderStyle, style); }
|
||||
inline QTextFrameFormat::BorderStyle topBorderStyle() const
|
||||
{ return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellTopBorderStyle)); }
|
||||
|
||||
inline void setBottomBorderStyle(QTextFrameFormat::BorderStyle style)
|
||||
{ setProperty(TableCellBottomBorderStyle, style); }
|
||||
inline QTextFrameFormat::BorderStyle bottomBorderStyle() const
|
||||
{ return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellBottomBorderStyle)); }
|
||||
|
||||
inline void setLeftBorderStyle(QTextFrameFormat::BorderStyle style)
|
||||
{ setProperty(TableCellLeftBorderStyle, style); }
|
||||
inline QTextFrameFormat::BorderStyle leftBorderStyle() const
|
||||
{ return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellLeftBorderStyle)); }
|
||||
|
||||
inline void setRightBorderStyle(QTextFrameFormat::BorderStyle style)
|
||||
{ setProperty(TableCellRightBorderStyle, style); }
|
||||
inline QTextFrameFormat::BorderStyle rightBorderStyle() const
|
||||
{ return static_cast<QTextFrameFormat::BorderStyle>(intProperty(TableCellRightBorderStyle)); }
|
||||
|
||||
inline void setBorderStyle(QTextFrameFormat::BorderStyle style);
|
||||
|
||||
inline void setTopBorderBrush(const QBrush &brush)
|
||||
{ setProperty(TableCellTopBorderBrush, brush); }
|
||||
inline QBrush topBorderBrush() const
|
||||
{ return brushProperty(TableCellTopBorderBrush); }
|
||||
|
||||
inline void setBottomBorderBrush(const QBrush &brush)
|
||||
{ setProperty(TableCellBottomBorderBrush, brush); }
|
||||
inline QBrush bottomBorderBrush() const
|
||||
{ return brushProperty(TableCellBottomBorderBrush); }
|
||||
|
||||
inline void setLeftBorderBrush(const QBrush &brush)
|
||||
{ setProperty(TableCellLeftBorderBrush, brush); }
|
||||
inline QBrush leftBorderBrush() const
|
||||
{ return brushProperty(TableCellLeftBorderBrush); }
|
||||
|
||||
inline void setRightBorderBrush(const QBrush &brush)
|
||||
{ setProperty(TableCellRightBorderBrush, brush); }
|
||||
inline QBrush rightBorderBrush() const
|
||||
{ return brushProperty(TableCellRightBorderBrush); }
|
||||
|
||||
inline void setBorderBrush(const QBrush &brush);
|
||||
|
||||
protected:
|
||||
explicit QTextTableCellFormat(const QTextFormat &fmt);
|
||||
friend class QTextFormat;
|
||||
@ -1062,6 +1149,29 @@ inline void QTextTableCellFormat::setPadding(qreal padding)
|
||||
setRightPadding(padding);
|
||||
}
|
||||
|
||||
inline void QTextTableCellFormat::setBorder(qreal width)
|
||||
{
|
||||
setTopBorder(width);
|
||||
setBottomBorder(width);
|
||||
setLeftBorder(width);
|
||||
setRightBorder(width);
|
||||
}
|
||||
|
||||
inline void QTextTableCellFormat::setBorderStyle(QTextFrameFormat::BorderStyle style)
|
||||
{
|
||||
setTopBorderStyle(style);
|
||||
setBottomBorderStyle(style);
|
||||
setLeftBorderStyle(style);
|
||||
setRightBorderStyle(style);
|
||||
}
|
||||
|
||||
inline void QTextTableCellFormat::setBorderBrush(const QBrush &brush)
|
||||
{
|
||||
setTopBorderBrush(brush);
|
||||
setBottomBorderBrush(brush);
|
||||
setLeftBorderBrush(brush);
|
||||
setRightBorderBrush(brush);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user