Warning, file /office/calligra/libs/odf/KoBorder.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * 0003 * Copyright (C) 2009 Inge wallin <inge@lysator.liu.se> 0004 * Copyright (C) 2009 Thomas Zander <zander@kde.org> 0005 * Copyright (C) 2011 Pierre Ducroquet <pinaraf@pinaraf.info> 0006 * 0007 * This library is free software; you can redistribute it and/or 0008 * modify it under the terms of the GNU Library General Public 0009 * License as published by the Free Software Foundation; either 0010 * version 2 of the License, or (at your option) any later version. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Library General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Library General Public License 0018 * along with this library; see the file COPYING.LIB. If not, write to 0019 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 * Boston, MA 02110-1301, USA. 0021 */ 0022 0023 0024 #ifndef KOBORDER_H 0025 #define KOBORDER_H 0026 0027 #include "koodf_export.h" 0028 0029 #include <QPen> 0030 #include <QSharedData> 0031 #include <QMetaType> 0032 0033 #include "KoXmlReaderForward.h" 0034 #include "KoGenStyle.h" 0035 0036 class QPainter; 0037 class KoStyleStack; 0038 class KoBorderPrivate; 0039 0040 class QColor; 0041 0042 /** 0043 * A container for all properties of a generic border as defined by ODF. 0044 * 0045 * A border is used in at least the following contexts: 0046 * - paragraph 0047 * - page 0048 * - table 0049 * - table cell 0050 * 0051 */ 0052 0053 class KOODF_EXPORT KoBorder 0054 { 0055 public: 0056 0057 // Names of the border sides. 0058 // 0059 // The "rect" we refer to below is the rectangle around the object 0060 // with the border. This could be a page, a cell, a paragraph, etc. 0061 enum BorderSide { 0062 TopBorder = 0, ///< References the border at the top of the rect 0063 LeftBorder, ///< References the border at the left side of the rect 0064 BottomBorder, ///< References the border at the bottom of the rect 0065 RightBorder, ///< References the border at the right side of the rect 0066 TlbrBorder, ///< References the border from top left corner to bottom right corner of cell 0067 BltrBorder ///< References the border from bottom left corner to top right corner of cell 0068 }; 0069 0070 /// Names of the different types of borders. 0071 // 0072 // Note that some of the border types are legacies from the old Words format. 0073 enum BorderStyle { 0074 BorderNone, ///< no border. This value forces the computed value of 'border-width' to be '0'. 0075 BorderDotted, ///< The border is a series of dots. 0076 BorderDashed, ///< The border is a series of short line segments. 0077 BorderSolid, ///< The border is a single line segment. 0078 BorderDouble, ///< The border is two solid lines. The sum of the two lines and the space between them equals the value of 'border-width'. 0079 BorderGroove, ///< The border looks as though it were carved into the canvas. (old words type) 0080 BorderRidge, ///< The opposite of 'groove': the border looks as though it were coming out of the canvas. (old words type) 0081 BorderInset, ///< The border makes the entire box look as though it were embedded in the canvas. (old words type) 0082 BorderOutset, ///< The opposite of 'inset': the border makes the entire box look as though it were coming out of the canvas. (old words type) 0083 0084 BorderDashedLong, ///< Dashed single border with long spaces 0085 BorderTriple, ///< Triple lined border 0086 BorderSlash, ///< slash border 0087 BorderWave, ///< wave border 0088 BorderDoubleWave, ///< double wave border 0089 0090 // words legacy 0091 BorderDashDot, 0092 BorderDashDotDot 0093 }; 0094 0095 /// Holds data about one border line. 0096 struct KOODF_EXPORT BorderData { 0097 BorderData(); 0098 0099 /// Compare the border data with another one 0100 bool operator==(const BorderData &other) const; 0101 0102 BorderStyle style; ///< The border style. (see KoBorder::BorderStyle) 0103 QPen outerPen; ///< Holds the outer line when borderstyle is double and the whole line otherwise 0104 QPen innerPen; ///< Holds the inner line when borderstyle is double 0105 qreal spacing; ///< Holds the spacing between the outer and inner lines. 0106 }; 0107 0108 0109 /// Constructor 0110 KoBorder(); 0111 KoBorder(const KoBorder &kb); 0112 0113 /// Destructor 0114 ~KoBorder(); 0115 0116 /// Assignment 0117 KoBorder &operator=(const KoBorder &other); 0118 0119 /// Compare the border with another one 0120 bool operator==(const KoBorder &other) const; 0121 bool operator!=(const KoBorder &other) const { return !operator==(other); } 0122 0123 void setBorderStyle(BorderSide side, BorderStyle style); 0124 BorderStyle borderStyle(BorderSide side) const; 0125 void setBorderColor(BorderSide side, const QColor &color); 0126 QColor borderColor(BorderSide side) const; 0127 void setBorderWidth(BorderSide side, qreal width); 0128 qreal borderWidth(BorderSide side) const; 0129 void setOuterBorderWidth(BorderSide side, qreal width); 0130 qreal outerBorderWidth(BorderSide side) const; 0131 void setInnerBorderWidth(BorderSide side, qreal width); 0132 qreal innerBorderWidth(BorderSide side) const; 0133 void setBorderSpacing(BorderSide side, qreal width); 0134 qreal borderSpacing(BorderSide side) const; 0135 0136 BorderData borderData(BorderSide side) const; 0137 void setBorderData(BorderSide side, const BorderData &data); 0138 0139 bool hasBorder() const; 0140 bool hasBorder(BorderSide side) const; 0141 0142 enum BorderPaintArea { 0143 PaintOnLine, 0144 PaintInsideLine 0145 }; 0146 void paint(QPainter &painter, const QRectF &borderRect, 0147 BorderPaintArea whereToPaint = PaintInsideLine) const; 0148 0149 /** 0150 * Load the style from the element 0151 * 0152 * @param style the element containing the style to read from 0153 * @return true when border attributes were found 0154 */ 0155 bool loadOdf(const KoXmlElement &style); 0156 bool loadOdf(const KoStyleStack &styleStack); 0157 void saveOdf(KoGenStyle &style, KoGenStyle::PropertyType type = KoGenStyle::DefaultType) const; 0158 0159 0160 // Some public functions used in other places where borders are handled. 0161 // Example: KoParagraphStyle 0162 // FIXME: These places should be made to use KoBorder instead. 0163 static BorderStyle odfBorderStyle(const QString &borderstyle, bool *converted = 0); 0164 static QString odfBorderStyleString(BorderStyle borderstyle); 0165 static QString msoBorderStyleString(BorderStyle borderstyle); 0166 0167 private: 0168 void paintBorderSide(QPainter &painter, QPointF lineStart, QPointF lineEnd, 0169 BorderData *borderData, bool isVertical, 0170 BorderData *neighbour1, BorderData *neighbor2, 0171 int inwardsAcross) const; 0172 0173 void parseAndSetBorder(const QString &border, 0174 bool hasSpecialBorder, const QString &specialBorderString); 0175 void parseAndSetBorder(const BorderSide borderSide, const QString &border, 0176 bool hasSpecialBorder, const QString &specialBorderString); 0177 0178 private: 0179 QSharedDataPointer<KoBorderPrivate> d; 0180 }; 0181 0182 Q_DECLARE_METATYPE(KoBorder) 0183 0184 0185 #endif