00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef KOPARAGRAPHSTYLE_H
00019 #define KOPARAGRAPHSTYLE_H
00020
00021 #include <QObject>
00022 #include <QVector>
00023 #include <QString>
00024 #include <QVariant>
00025 #include <QTextFormat>
00026 #include <koffice_export.h>
00027
00028 struct Property;
00029 class KoCharacterStyle;
00030 class KoListStyle;
00031 class StylePrivate;
00032 class QTextBlock;
00033
00042 class KOTEXT_EXPORT KoParagraphStyle : public QObject {
00043 Q_OBJECT
00044 public:
00045 enum Property {
00046 StyleId = QTextFormat::UserProperty+1,
00047
00048 FixedLineHeight,
00049 MinimumLineHeight,
00050 LineSpacing,
00051 LineSpacingFromFont,
00052 AlignLastLine,
00053 WidowThreshold,
00054 OrphanThreshold,
00055 DropCaps,
00056 DropCapsLength,
00057 DropCapsLines,
00058 DropCapsDistance,
00059 FollowDocBaseline,
00060 BreakBefore,
00061 BreakAfter,
00062 HasLeftBorder,
00063 HasTopBorder,
00064 HasRightBorder,
00065 HasBottomBorder,
00066 BorderLineWidth,
00067 SecondBorderLineWidth,
00068 DistanceToSecondBorder,
00069 LeftPadding,
00070 TopPadding,
00071 RightPadding,
00072 BottomPadding,
00073 LeftBorderWidth,
00074 LeftInnerBorderWidth,
00075 LeftBorderSpacing,
00076 LeftBorderStyle,
00077 LeftBorderColor,
00078 TopBorderWidth,
00079 TopInnerBorderWidth,
00080 TopBorderSpacing,
00081 TopBorderStyle,
00082 TopBorderColor,
00083 RightBorderWidth,
00084 RightInnerBorderWidth,
00085 RightBorderSpacing,
00086 RightBorderStyle,
00087 RightBorderColor,
00088 BottomBorderWidth,
00089 BottomInnerBorderWidth,
00090 BottomBorderSpacing,
00091 BottomBorderStyle,
00092 BottomBorderColor,
00093
00094
00095
00096 };
00097
00098 enum BorderStyle {
00099 BorderNone,
00100 BorderDotted,
00101 BorderDashed,
00102 BorderSolid,
00103 BorderDouble,
00104 BorderGroove,
00105 BorderRidge,
00106 BorderInset,
00107 BorderOutset,
00108
00109
00110 BorderDashDotPattern,
00111 BorderDashDotDotPattern
00112 };
00113
00114
00115 KoParagraphStyle();
00117 KoParagraphStyle(const KoParagraphStyle &orig);
00118 ~KoParagraphStyle();
00119
00120
00126 void setLineHeightPercent(int lineHeight)
00127 {setProperty(FixedLineHeight, lineHeight); remove(LineSpacing);}
00128 int lineHeightPercent() const { return propertyInt(FixedLineHeight); }
00129
00133 void setLineHeightAbsolute(double height)
00134 {setProperty(FixedLineHeight, height); remove(LineSpacing);}
00135 double lineHeightAbsolute() const {return propertyDouble(FixedLineHeight); }
00136
00140 void setMinimumLineHeight(double height) {setProperty(MinimumLineHeight, height); }
00141 double minimumLineHeight() const { return propertyDouble(MinimumLineHeight); }
00142
00146 void setLineSpacing(double spacing)
00147 {setProperty(LineSpacing, spacing); remove(FixedLineHeight); }
00148 double lineSpacing() const {return propertyDouble(LineSpacing); }
00149
00157 void setLineSpacingFromFont(bool on) {setProperty(LineSpacingFromFont, on); }
00161 bool lineSpacingFromFont() const {return propertyBoolean(LineSpacingFromFont); }
00162
00163
00169 void setAlignLastLine(Qt::Alignment alignment ) { setProperty(AlignLastLine, (int) alignment); }
00173 Qt::Alignment alignLastLine() const {
00174 return static_cast<Qt::Alignment> (propertyInt(QTextFormat::BlockAlignment));
00175 }
00184 void setWidowThreshold(int lines) { setProperty(WidowThreshold, lines); }
00188 int widowThreshold() const { return propertyInt(WidowThreshold); }
00197 void setOrphanThreshold(int lines) { setProperty(OrphanThreshold, lines); }
00201 int orphanThreshold() const { return propertyInt(OrphanThreshold); }
00208 void setDropCaps(bool on) { setProperty(DropCaps, on); }
00212 bool dropCaps() const { return propertyBoolean(DropCaps); }
00219 void setDropCapsLength(int characters) { setProperty(DropCapsLength, characters); }
00224 int dropCapsLength() const { return propertyInt(DropCapsLength); }
00231 void setDropCapsLines(int lines) { setProperty(DropCapsLines, lines); }
00236 int dropCapsLines() const { return propertyInt(DropCapsLines); }
00243 void setDropCapsDistance(double distance) { setProperty(DropCapsDistance, distance); }
00248 double dropCapsDistance() const { return propertyDouble(DropCapsDistance); }
00252 void setFollowDocBaseline(bool on) { setProperty(FollowDocBaseline, on); }
00257 bool followDocBaseline() const { return propertyBoolean(FollowDocBaseline); }
00258
00259 void setBreakBefore(bool on) { setProperty(BreakBefore, on); }
00260 bool breakBefore() { return propertyBoolean(BreakBefore); }
00261 void setBreakAfter(bool on) { setProperty(BreakAfter, on); }
00262 bool breakAfter() { return propertyBoolean(BreakAfter); }
00263 void setLeftPadding(double padding) { setProperty(LeftPadding, padding); }
00264 double leftPadding() { return propertyDouble(LeftPadding); }
00265 void setTopPadding(double padding) { setProperty(TopPadding, padding); }
00266 double topPadding() { return propertyDouble(TopPadding); }
00267 void setRightPadding(double padding) { setProperty(RightPadding, padding); }
00268 double rightPadding() { return propertyDouble(RightPadding); }
00269 void setBottomPadding(double padding) { setProperty(BottomPadding, padding); }
00270 double bottomPadding() { return propertyDouble(BottomPadding); }
00271
00272 void setLeftBorderWidth(double width) { setProperty(LeftBorderWidth, width); }
00273 double leftBorderWidth() { return propertyDouble(LeftBorderWidth); }
00274 void setLeftInnerBorderWidth(double width) { setProperty(LeftInnerBorderWidth, width); }
00275 double leftInnerBorderWidth() { return propertyDouble(LeftInnerBorderWidth); }
00276 void setLeftBorderSpacing(double width) { setProperty(LeftBorderSpacing, width); }
00277 double leftBorderSpacing() { return propertyDouble(LeftBorderSpacing); }
00278 void setLeftBorderStyle(BorderStyle style) { setProperty(LeftBorderStyle, style); }
00279 BorderStyle leftBorderStyle() { return static_cast<BorderStyle> (propertyInt(LeftBorderStyle)); }
00280 void setLeftBorderColor(QColor color) { setProperty(LeftBorderColor, color); }
00281 QColor leftBorderColor() { return propertyColor(LeftBorderColor); }
00282 void setTopBorderWidth(double width) { setProperty(TopBorderWidth, width); }
00283 double topBorderWidth() { return propertyDouble(TopBorderWidth); }
00284 void setTopInnerBorderWidth(double width) { setProperty(TopInnerBorderWidth, width); }
00285 double topInnerBorderWidth() { return propertyDouble(TopInnerBorderWidth); }
00286 void setTopBorderSpacing(double width) { setProperty(TopBorderSpacing, width); }
00287 double topBorderSpacing() { return propertyDouble(TopBorderSpacing); }
00288 void setTopBorderStyle(BorderStyle style) { setProperty(TopBorderStyle, style); }
00289 BorderStyle topBorderStyle() { return static_cast<BorderStyle> (propertyInt(TopBorderStyle)); }
00290 void setTopBorderColor(QColor color) { setProperty(TopBorderColor, color); }
00291 QColor topBorderColor() { return propertyColor(TopBorderColor); }
00292 void setRightBorderWidth(double width) { setProperty(RightBorderWidth, width); }
00293 double rightBorderWidth() { return propertyDouble(RightBorderWidth); }
00294 void setRightInnerBorderWidth(double width) { setProperty(RightInnerBorderWidth, width); }
00295 double rightInnerBorderWidth() { return propertyDouble(RightInnerBorderWidth); }
00296 void setRightBorderSpacing(double width) { setProperty(RightBorderSpacing, width); }
00297 double rightBorderSpacing() { return propertyDouble(RightBorderSpacing); }
00298 void setRightBorderStyle(BorderStyle style) { setProperty(RightBorderStyle, style); }
00299 BorderStyle rightBorderStyle() { return static_cast<BorderStyle> (propertyInt(RightBorderStyle)); }
00300 void setRightBorderColor(QColor color) { setProperty(RightBorderColor, color); }
00301 QColor rightBorderColor() { return propertyColor(RightBorderColor); }
00302 void setBottomBorderWidth(double width) { setProperty(BottomBorderWidth, width); }
00303 double bottomBorderWidth() { return propertyDouble(BottomBorderWidth); }
00304 void setBottomInnerBorderWidth(double width) { setProperty(BottomInnerBorderWidth, width); }
00305 double bottomInnerBorderWidth() { return propertyDouble(BottomInnerBorderWidth); }
00306 void setBottomBorderSpacing(double width) { setProperty(BottomBorderSpacing, width); }
00307 double bottomBorderSpacing() { return propertyDouble(BottomBorderSpacing); }
00308 void setBottomBorderStyle(BorderStyle style) { setProperty(BottomBorderStyle, style); }
00309 BorderStyle bottomBorderStyle() { return static_cast<BorderStyle> (propertyInt(BottomBorderStyle)); }
00310 void setBottomBorderColor(QColor color) { setProperty(BottomBorderColor, color); }
00311 QColor bottomBorderColor() { return propertyColor(BottomBorderColor); }
00312
00313
00314
00316 void setTopMargin(double topMargin) { setProperty(QTextFormat::BlockTopMargin, topMargin); }
00318 double topMargin() const { return propertyDouble(QTextFormat::BlockTopMargin); }
00319
00321 void setBottomMargin (double margin) { setProperty(QTextFormat::BlockBottomMargin, margin); }
00323 double bottomMargin () const { return propertyDouble(QTextFormat::BlockBottomMargin); }
00325 void setLeftMargin (double margin) { setProperty(QTextFormat::BlockLeftMargin, margin); }
00327 double leftMargin () const { return propertyDouble(QTextFormat::BlockLeftMargin); }
00329 void setRightMargin (double margin) { setProperty(QTextFormat::BlockRightMargin, margin); }
00331 double rightMargin () const { return propertyDouble(QTextFormat::BlockRightMargin); }
00332
00334 void setAlignment (Qt::Alignment alignment) {
00335 setProperty(QTextFormat::BlockAlignment, (int) alignment);
00336 }
00338 Qt::Alignment alignment () const {
00339 return static_cast<Qt::Alignment> (propertyInt(QTextFormat::BlockAlignment));
00340 }
00342 void setTextIndent (double margin) { setProperty(QTextFormat::TextIndent, margin); }
00344 double textIndent () const { return propertyDouble(QTextFormat::TextIndent); }
00346 void setIndent (int indent) { setProperty(QTextFormat::BlockIndent, indent); }
00348 int indent () const { return propertyInt(QTextFormat::BlockIndent); }
00350 void setNonBreakableLines(bool on) { setProperty(QTextFormat::BlockNonBreakableLines, on); }
00352 bool nonBreakableLines() const { return propertyBoolean(QTextFormat::BlockNonBreakableLines); }
00353
00355 void setParent(KoParagraphStyle *parent);
00356
00358 KoParagraphStyle *parent() const { return m_parent; }
00359
00361 void setNextStyle(int next) { m_next = next; }
00362
00364 int nextStyle() const { return m_next; }
00365
00367 const QString& name() const { return m_name; }
00368
00370 void setName(const QString &name) { m_name = name; }
00371
00373 int styleId() const { return propertyInt(StyleId); }
00374
00376 void setStyleId(int id) { setProperty(StyleId, id); if(m_next == 0) m_next=id; }
00377
00383 void applyStyle(QTextBlockFormat &format) const;
00384
00389 void applyStyle(QTextBlock &block) const;
00390
00391 KoCharacterStyle *characterStyle() { return m_charStyle; }
00392 const KoCharacterStyle *characterStyle() const { return m_charStyle; }
00393
00394 KoListStyle *listStyle() { return m_listStyle; }
00395 const KoListStyle *listStyle() const { return m_listStyle; }
00396
00397 void setListStyle(const KoListStyle &style);
00398 void removeListStyle();
00399
00400 private:
00401 void setProperty(int key, const QVariant &value);
00402 void remove(int key);
00403 double propertyDouble(int key) const;
00404 int propertyInt(int key) const;
00405 bool propertyBoolean(int key) const;
00406 QColor propertyColor(int key) const;
00407 QVariant const *get(int key) const;
00408
00409 private:
00410 QString m_name;
00411 KoCharacterStyle *m_charStyle;
00412 KoListStyle *m_listStyle;
00413 KoParagraphStyle *m_parent;
00414 int m_next;
00415 StylePrivate *m_stylesPrivate;
00416 };
00417
00418 #endif