00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _QFORMAT_H_
00017 #define _QFORMAT_H_
00018
00024 #include <QFont>
00025 #include <QColor>
00026 #include <QTextCharFormat>
00027
00028 template <typename T>
00029 class QVector;
00030
00031 struct QFormat
00032 {
00033 inline QFormat()
00034 : weight(QFont::Normal), italic(false), overline(false), underline(false), strikeout(false), waveUnderline(false)
00035 {}
00036
00037 inline QFormat(const QColor& c)
00038 : weight(QFont::Normal), italic(false), overline(false), underline(false), strikeout(false), waveUnderline(false), foreground(c)
00039 {}
00040
00041 inline QFormat(int w, const QColor& c)
00042 : weight(w), italic(false), overline(false), underline(false), strikeout(false), waveUnderline(false), foreground(c)
00043 {}
00044
00045 inline QFormat(int w, bool i, bool u, bool s, const QColor& c)
00046 : weight(w), italic(i), overline(false), underline(u), strikeout(s), waveUnderline(false), foreground(c)
00047 {}
00048
00049 inline QFormat(int w, bool i, bool o, bool u, bool s, bool wu, const QColor& c)
00050 : weight(w), italic(i), overline(o), underline(u), strikeout(s), waveUnderline(wu), foreground(c)
00051 {}
00052
00053 inline QFormat(const QFormat& f)
00054 : weight(f.weight), italic(f.italic),
00055 overline(f.overline), underline(f.underline), strikeout(f.strikeout), waveUnderline(f.waveUnderline),
00056 foreground(f.foreground), background(f.background), linescolor(f.linescolor)
00057 {}
00058
00059 inline QFormat& operator = (const QFormat& f)
00060 {
00061 weight = f.weight;
00062 italic = f.italic;
00063 overline = f.overline;
00064 underline = f.underline;
00065 strikeout = f.strikeout;
00066 foreground = f.foreground;
00067 background = f.background;
00068 linescolor = f.linescolor;
00069 waveUnderline = f.waveUnderline;
00070
00071 return *this;
00072 }
00073
00074 inline bool operator == (const QFormat& f) const
00075 {
00076 return (weight == f.weight)
00077 &&
00078 (italic == f.italic)
00079 &&
00080 (overline == f.overline)
00081 &&
00082 (underline == f.underline)
00083 &&
00084 (strikeout == f.strikeout)
00085 &&
00086 (foreground == f.foreground)
00087 &&
00088 (background == f.background)
00089 &&
00090 (linescolor == f.linescolor)
00091 &&
00092 (waveUnderline == f.waveUnderline)
00093 ;
00094 }
00095
00096 inline bool operator != (const QFormat& f) const
00097 {
00098 return (weight != f.weight)
00099 ||
00100 (italic != f.italic)
00101 ||
00102 (overline != f.overline)
00103 ||
00104 (underline != f.underline)
00105 ||
00106 (strikeout != f.strikeout)
00107 ||
00108 (foreground != f.foreground)
00109 ||
00110 (background != f.background)
00111 ||
00112 (linescolor != f.linescolor)
00113 ||
00114 (waveUnderline != f.waveUnderline)
00115 ;
00116 }
00117
00118 QTextCharFormat toTextCharFormat() const
00119 {
00120 QTextCharFormat f;
00121 f.setFontWeight(weight);
00122 f.setFontItalic(italic);
00123 f.setFontOverline(overline);
00124 f.setFontUnderline(underline);
00125 f.setFontStrikeOut(strikeout);
00126 f.setUnderlineColor(linescolor);
00127
00128 if ( waveUnderline )
00129 {
00130 f.setUnderlineStyle(QTextCharFormat::WaveUnderline);
00131 }
00132
00133 if ( foreground.isValid() )
00134 f.setForeground(foreground);
00135
00136 if ( background.isValid() )
00137 f.setBackground(background);
00138
00139 return f;
00140 }
00141
00142 int weight;
00143 bool italic;
00144 bool overline;
00145 bool underline;
00146 bool strikeout;
00147 bool waveUnderline;
00148 QColor foreground;
00149 QColor background;
00150 QColor linescolor;
00151 };
00152
00153 Q_DECLARE_TYPEINFO(QFormat, Q_MOVABLE_TYPE);
00154
00155 struct QFormatRange
00156 {
00157 inline QFormatRange()
00158 : offset(0), length(0), format(0)
00159 {}
00160
00161 inline QFormatRange(int o, int l, int f)
00162 : offset(o), length(l), format(f)
00163 {}
00164
00165 inline bool operator == (const QFormatRange& o)
00166 { return (offset == o.offset) && (length == o.length) && (format == o.format); }
00167
00168 inline bool operator != (const QFormatRange& o)
00169 { return (offset != o.offset) || (length != o.length) || (format != o.format); }
00170
00171 int offset;
00172 int length;
00173 int format;
00174 };
00175
00176 Q_DECLARE_TYPEINFO(QFormatRange, Q_PRIMITIVE_TYPE);
00177
00178 #endif