23#include "KoZoomHandler.h"
24#include "KoTextFormat.h"
25#include "KoRichText.h"
26#include "KoTextParag.h"
29static const struct BorderStyle {
30 TQt::PenStyle penStyle;
32 TQCString uiStringStyle;
34 { TQt::SolidLine,
"solid",
"_________" },
35 { TQt::DashLine,
"dashed",
"___ ___ __" },
36 { TQt::DotLine,
"dotted",
"_ _ _ _ _ _" },
37 { TQt::DashDotLine,
"dot-dash",
"___ _ ___ _" },
38 { TQt::DashDotDotLine,
"dot-dot-dash",
"___ _ _ ___" },
39 { TQt::SolidLine,
"double",
"===========" }
43 : color(), m_style( SOLID )
48KoBorder::KoBorder(
const TQColor & c, BorderStyle s,
double width )
49 : color( c ), m_style( s )
54bool KoBorder::operator==(
const KoBorder _brd )
const {
55 return ( m_style == _brd.m_style && color == _brd.color && ptPenWidth == _brd.ptPenWidth );
58bool KoBorder::operator!=(
const KoBorder _brd )
const {
59 return ( m_style != _brd.m_style || color != _brd.color || ptPenWidth != _brd.ptPenWidth );
62void KoBorder::setStyle(BorderStyle _style)
65 setPenWidth( ptPenWidth );
68void KoBorder::setPenWidth(
double _w)
71 if ( m_style == KoBorder::DOUBLE_LINE && _w > 0 )
72 ptWidth = 2 * ptPenWidth + 1;
77TQPen KoBorder::borderPen(
const KoBorder & _brd,
int width, TQColor defaultColor )
79 TQPen pen( _brd.color, width );
80 if ( !_brd.color.isValid() )
81 pen.setColor( defaultColor );
83 pen.setStyle( s_borderStyles[ _brd.m_style ].penStyle );
89KoBorder KoBorder::loadBorder(
const TQDomElement & elem )
92 if ( elem.hasAttribute(
"red") )
94 int r = elem.attribute(
"red").toInt();
95 int g = elem.attribute(
"green").toInt();
96 int b = elem.attribute(
"blue").toInt();
97 bd.color.setRgb( r, g, b );
99 bd.m_style =
static_cast<BorderStyle
>( elem.attribute(
"style").toInt() );
100 bd.setPenWidth( elem.attribute(
"width").toDouble() );
104void KoBorder::loadFoBorder(
const TQString& border )
108 if (border.isEmpty() || border==
"none" || border==
"hidden") {
114 TQString _width = border.section(
' ', 0, 0);
115 TQCString _style = border.section(
' ', 1, 1).latin1();
116 TQString _color = border.section(
' ', 2, 2);
121 if ( penWidth < 1.5 )
123 else if ( penWidth < 2.5 )
125 else if ( penWidth < 3.5 )
127 else if ( penWidth < 4.5 )
129 else if ( penWidth < 5.5 )
131 else if ( penWidth < 6.5 )
133 else if ( penWidth < 7.5 )
135 else if ( penWidth < 8.5 )
137 else if ( penWidth < 9.5 )
143 for ( uint i = 0; i <
sizeof( s_borderStyles ) /
sizeof *s_borderStyles; ++i ) {
144 if ( _style == s_borderStyles[i].oasisName )
145 m_style =
static_cast<BorderStyle
>( i );
148 if ( _color.isEmpty() )
151 color.setNamedColor( _color );
154TQString KoBorder::saveFoBorder()
const
156 if ( TQABS( ptPenWidth ) < 1E-10 )
159 TQString str = TQString::number( ptPenWidth,
'g', DBL_DIG );
161 str += s_borderStyles[ m_style ].oasisName;
162 if ( color.isValid() ) {
170void KoBorder::save( TQDomElement & elem )
const
172 if (color.isValid()) {
173 elem.setAttribute(
"red", color.red());
174 elem.setAttribute(
"green", color.green());
175 elem.setAttribute(
"blue", color.blue());
177 elem.setAttribute(
"style",
static_cast<int>( m_style ));
178 elem.setAttribute(
"width", ptPenWidth);
181KoBorder::BorderStyle KoBorder::getStyle(
const TQString &style )
183 for ( uint i = 0; i <
sizeof( s_borderStyles ) /
sizeof *s_borderStyles; ++i ) {
184 if ( style == s_borderStyles[i].uiStringStyle.data() )
185 return static_cast<BorderStyle
>( i );
188 return KoBorder::SOLID;
191TQString KoBorder::getStyle(
const BorderStyle &style )
193 return s_borderStyles[style].uiStringStyle;
196int KoBorder::zoomWidthX(
double ptWidth,
KoZoomHandler * zoomHandler,
int minborder )
200 return ptWidth > 0 ? TQMAX( 1, zoomHandler->zoomItX( ptWidth ) ) : minborder;
203int KoBorder::zoomWidthY(
double ptWidth,
KoZoomHandler * zoomHandler,
int minborder )
207 return ptWidth > 0 ? TQMAX( 1, zoomHandler->zoomItY( ptWidth ) ) : minborder;
210void KoBorder::drawBorders( TQPainter& painter,
KoZoomHandler * zoomHandler,
const TQRect& rect,
const KoBorder& leftBorder,
const KoBorder& rightBorder,
const KoBorder& topBorder,
const KoBorder& bottomBorder,
int minborder,
const TQPen& defaultPen,
bool drawTopBorder ,
bool drawBottomBorder )
212 int topBorderWidth = zoomWidthY( topBorder.width(), zoomHandler, minborder );
213 int bottomBorderWidth = zoomWidthY( bottomBorder.width(), zoomHandler, minborder );
214 int leftBorderWidth = zoomWidthX( leftBorder.width(), zoomHandler, minborder );
215 int rightBorderWidth = zoomWidthX( rightBorder.width(), zoomHandler, minborder );
217 int topBorderPenWidth = zoomWidthY( topBorder.penWidth(), zoomHandler, minborder );
218 int bottomBorderPenWidth = zoomWidthY( bottomBorder.penWidth(), zoomHandler, minborder );
219 int leftBorderPenWidth = zoomWidthX( leftBorder.penWidth(), zoomHandler, minborder );
220 int rightBorderPenWidth = zoomWidthX( rightBorder.penWidth(), zoomHandler, minborder );
223 int lastPixelAdj = 1;
233 if ( topBorderWidth > 0 && drawTopBorder )
235 if ( topBorder.penWidth() > 0 )
236 painter.setPen( KoBorder::borderPen( topBorder, topBorderPenWidth, defaultColor ) );
238 painter.setPen( defaultPen );
239 int y = rect.top() - topBorderWidth + topBorderPenWidth/2;
240 if ( topBorder.m_style==KoBorder::DOUBLE_LINE)
242 painter.drawLine( rect.left()-leftBorderWidth, y, rect.right()+2*(rightBorderPenWidth+lastPixelAdj), y );
243 y += topBorderPenWidth + 1;
244 painter.drawLine( rect.left()-leftBorderPenWidth, y, rect.right()+rightBorderPenWidth+lastPixelAdj, y );
248 painter.drawLine( rect.left()-leftBorderWidth, y, rect.right()+rightBorderWidth+lastPixelAdj, y );
251 if ( bottomBorderWidth > 0 && drawBottomBorder )
253 if ( bottomBorder.penWidth() > 0 )
254 painter.setPen( KoBorder::borderPen( bottomBorder, bottomBorderPenWidth, defaultColor ) );
256 painter.setPen( defaultPen );
258 int y = rect.bottom() + bottomBorderPenWidth/2 + 1;
260 if ( bottomBorder.m_style==KoBorder::DOUBLE_LINE)
262 painter.drawLine( rect.left()-leftBorderPenWidth, y, rect.right()+rightBorderPenWidth+lastPixelAdj, y );
263 y += bottomBorderPenWidth + 1;
264 painter.drawLine( rect.left()-leftBorderWidth, y, rect.right()+2*(rightBorderPenWidth+lastPixelAdj), y );
268 painter.drawLine( rect.left()-leftBorderWidth, y, rect.right()+rightBorderWidth+lastPixelAdj, y );
271 if ( leftBorderWidth > 0 )
273 if ( leftBorder.penWidth() > 0 )
274 painter.setPen( KoBorder::borderPen( leftBorder, leftBorderPenWidth, defaultColor ) );
276 painter.setPen( defaultPen );
277 int x = rect.left() - leftBorderWidth + leftBorderPenWidth/2;
278 if ( leftBorder.m_style==KoBorder::DOUBLE_LINE)
280 painter.drawLine( x, rect.top()-topBorderWidth, x, rect.bottom()+2*(bottomBorderPenWidth+lastPixelAdj) );
281 x += leftBorderPenWidth + 1;
282 painter.drawLine( x, rect.top()-topBorderPenWidth, x, rect.bottom()+bottomBorderPenWidth+lastPixelAdj );
286 int yTop = rect.top() - topBorderWidth;
287 int yBottom = rect.bottom() + bottomBorderWidth;
291 painter.drawLine( x, yTop, x, yBottom+lastPixelAdj );
294 if ( rightBorderWidth > 0 )
296 if ( rightBorder.penWidth() > 0 )
297 painter.setPen( KoBorder::borderPen( rightBorder, rightBorderPenWidth, defaultColor ) );
299 painter.setPen( defaultPen );
300 int x = rect.right() + rightBorderPenWidth/2 + 1;
301 if ( rightBorder.m_style==KoBorder::DOUBLE_LINE)
303 painter.drawLine( x, rect.top()-topBorderPenWidth, x, rect.bottom()+bottomBorderPenWidth+lastPixelAdj );
304 x += rightBorderPenWidth + 1;
305 painter.drawLine( x, rect.top()-topBorderWidth, x, rect.bottom()+2*(bottomBorderPenWidth+lastPixelAdj) );
310 int yTop = rect.top()-topBorderWidth;
311 int yBottom = rect.bottom()+bottomBorderWidth+lastPixelAdj;
315 painter.drawLine( x, yTop, x, yBottom );
This class represents a border - for anything, like paragraph, or frame.
static TQColor defaultTextColor(TQPainter *painter)
Call this when a text color is set to 'invalid', meaning 'whatever the default for the color scheme i...
static double parseValue(TQString value, double defaultVal=0.0)
parse common KOffice and OO values, like "10cm", "5mm" to pt
This class handles the zooming and DPI stuff (conversions between pt values and pixels).