00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef KOCHARACTERSTYLE_H
00019 #define KOCHARACTERSTYLE_H
00020
00021 #include <QObject>
00022 #include <QVector>
00023 #include <QVariant>
00024 #include <QString>
00025 #include <QTextCharFormat>
00026 #include <koffice_export.h>
00027
00028 class StylePrivate;
00029 class QTextBlock;
00030
00042 class KOTEXT_EXPORT KoCharacterStyle : public QObject {
00043 Q_OBJECT
00044 public:
00045 enum Property {
00046 StyleId = QTextFormat::UserProperty+1
00047 };
00048
00049 KoCharacterStyle(QObject *parent = 0);
00050 ~KoCharacterStyle();
00051
00052
00053
00054
00055
00056
00058 void setFontFamily (const QString &family) { setProperty(QTextFormat::FontFamily, family); }
00060 QString fontFamily () const { return propertyString(QTextFormat::FontFamily); }
00062 void setFontPointSize (qreal size) { setProperty(QTextFormat::FontPointSize, size); }
00064 double fontPointSize () const { return propertyDouble(QTextFormat::FontPointSize); }
00066 void setFontWeight (int weight) { setProperty(QTextFormat::FontWeight, weight); }
00068 int fontWeight () const { return propertyInt(QTextFormat::FontWeight); }
00070 void setFontItalic (bool italic) { setProperty(QTextFormat::FontItalic, italic); }
00072 bool fontItalic () const { return propertyBoolean(QTextFormat::FontItalic); }
00074 void setFontOverline (bool overline) { setProperty(QTextFormat::FontOverline, overline); }
00076 bool fontOverline () const { return propertyBoolean(QTextFormat::FontOverline); }
00078 void setFontStrikeOut (bool strikeOut) { setProperty(QTextFormat::FontStrikeOut, strikeOut); }
00080 bool fontStrikeOut () const { return propertyBoolean(QTextFormat::FontStrikeOut); }
00082 void setUnderlineColor (const QColor &color) { setProperty(QTextFormat::TextUnderlineColor, color); }
00084 QColor underlineColor () const;
00086 void setFontFixedPitch (bool fixedPitch) { setProperty(QTextFormat::FontFixedPitch, fixedPitch); }
00088 bool fontFixedPitch () const { return propertyBoolean(QTextFormat::FontFixedPitch); }
00090 void setUnderlineStyle (QTextCharFormat::UnderlineStyle style) {
00091 setProperty(QTextFormat::TextUnderlineStyle, style);
00092 }
00094 QTextCharFormat::UnderlineStyle underlineStyle () const {
00095 return static_cast<QTextCharFormat::UnderlineStyle> (propertyInt(QTextFormat::TextUnderlineStyle));
00096 }
00098 void setVerticalAlignment (QTextCharFormat::VerticalAlignment alignment) {
00099 setProperty(QTextFormat::TextVerticalAlignment, alignment);
00100 }
00102 QTextCharFormat::VerticalAlignment verticalAlignment () const {
00103 return static_cast<QTextCharFormat::VerticalAlignment> (propertyInt(QTextFormat::TextVerticalAlignment));
00104 }
00106 void setTextOutline (const QPen &pen) { setProperty(QTextFormat::TextOutline, pen); }
00108 QPen textOutline () const;
00109
00111 void setBackground (const QBrush &brush) { setProperty(QTextFormat::BackgroundBrush, brush); }
00113 QBrush background () const;
00115 void clearBackground ();
00116
00118 void setForeground (const QBrush &brush) { setProperty(QTextFormat::ForegroundBrush, brush); }
00120 QBrush foreground () const;
00122 void clearForeground ();
00123
00124
00126 const QString& name() const { return m_name; }
00127
00129 void setName(const QString &name) { m_name = name; }
00130
00132 int styleId() const { return propertyInt(StyleId); }
00133
00135 void setStyleId(int id) { setProperty(StyleId, id); }
00136
00141 void applyStyle(QTextCharFormat &format) const;
00146 void applyStyle(QTextBlock &block) const;
00150 void applyStyle(QTextCursor *selection) const;
00151
00152 private:
00153 void setProperty(int key, const QVariant &value);
00154 const QVariant *get(int key) const;
00155 double propertyDouble(int key) const;
00156 int propertyInt(int key) const;
00157 QString propertyString(int key) const;
00158 bool propertyBoolean(int key) const;
00159
00160 private:
00161 QString m_name;
00162 StylePrivate *m_stylesPrivate;
00163 };
00164
00165 #endif