QCodeEdit  2.2
qformat.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
4 **
5 ** This file is part of the Edyuk project <http://edyuk.org>
6 **
7 ** This file may be used under the terms of the GNU General Public License
8 ** version 3 as published by the Free Software Foundation and appearing in the
9 ** file GPL.txt included in the packaging of this file.
10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 **
14 ****************************************************************************/
15 
16 #ifndef _QFORMAT_H_
17 #define _QFORMAT_H_
18 
24 #include <QFont>
25 #include <QColor>
26 #include <QTextCharFormat>
27 
28 template <typename T>
29 class QVector;
30 
31 struct QFormat
32 {
33  inline QFormat()
34  : weight(QFont::Normal), italic(false), overline(false), underline(false), strikeout(false), waveUnderline(false)
35  {}
36 
37  inline QFormat(const QColor& c)
38  : weight(QFont::Normal), italic(false), overline(false), underline(false), strikeout(false), waveUnderline(false), foreground(c)
39  {}
40 
41  inline QFormat(int w, const QColor& c)
42  : weight(w), italic(false), overline(false), underline(false), strikeout(false), waveUnderline(false), foreground(c)
43  {}
44 
45  inline QFormat(int w, bool i, bool u, bool s, const QColor& c)
46  : weight(w), italic(i), overline(false), underline(u), strikeout(s), waveUnderline(false), foreground(c)
47  {}
48 
49  inline QFormat(int w, bool i, bool o, bool u, bool s, bool wu, const QColor& c)
50  : weight(w), italic(i), overline(o), underline(u), strikeout(s), waveUnderline(wu), foreground(c)
51  {}
52 
53  inline QFormat(const QFormat& f)
54  : weight(f.weight), italic(f.italic),
55  overline(f.overline), underline(f.underline), strikeout(f.strikeout), waveUnderline(f.waveUnderline),
56  foreground(f.foreground), background(f.background), linescolor(f.linescolor)
57  {}
58 
59  inline QFormat& operator = (const QFormat& f)
60  {
61  weight = f.weight;
62  italic = f.italic;
63  overline = f.overline;
64  underline = f.underline;
65  strikeout = f.strikeout;
66  foreground = f.foreground;
67  background = f.background;
68  linescolor = f.linescolor;
69  waveUnderline = f.waveUnderline;
70 
71  return *this;
72  }
73 
74  inline bool operator == (const QFormat& f) const
75  {
76  return (weight == f.weight)
77  &&
78  (italic == f.italic)
79  &&
80  (overline == f.overline)
81  &&
82  (underline == f.underline)
83  &&
84  (strikeout == f.strikeout)
85  &&
86  (foreground == f.foreground)
87  &&
88  (background == f.background)
89  &&
90  (linescolor == f.linescolor)
91  &&
92  (waveUnderline == f.waveUnderline)
93  ;
94  }
95 
96  inline bool operator != (const QFormat& f) const
97  {
98  return (weight != f.weight)
99  ||
100  (italic != f.italic)
101  ||
102  (overline != f.overline)
103  ||
104  (underline != f.underline)
105  ||
106  (strikeout != f.strikeout)
107  ||
108  (foreground != f.foreground)
109  ||
110  (background != f.background)
111  ||
112  (linescolor != f.linescolor)
113  ||
114  (waveUnderline != f.waveUnderline)
115  ;
116  }
117 
118  QTextCharFormat toTextCharFormat() const
119  {
120  QTextCharFormat f;
121  f.setFontWeight(weight);
122  f.setFontItalic(italic);
123  f.setFontOverline(overline);
124  f.setFontUnderline(underline);
125  f.setFontStrikeOut(strikeout);
126  f.setUnderlineColor(linescolor);
127 
128  if ( waveUnderline )
129  {
130  f.setUnderlineStyle(QTextCharFormat::WaveUnderline);
131  }
132 
133  if ( foreground.isValid() )
134  f.setForeground(foreground);
135 
136  if ( background.isValid() )
137  f.setBackground(background);
138 
139  return f;
140  }
141 
142  int weight;
143  bool italic;
144  bool overline;
145  bool underline;
146  bool strikeout;
147  bool waveUnderline;
148  QColor foreground;
149  QColor background;
150  QColor linescolor;
151 };
152 
153 Q_DECLARE_TYPEINFO(QFormat, Q_MOVABLE_TYPE);
154 
156 {
157  inline QFormatRange()
158  : offset(0), length(0), format(0)
159  {}
160 
161  inline QFormatRange(int o, int l, int f)
162  : offset(o), length(l), format(f)
163  {}
164 
165  inline bool operator == (const QFormatRange& o)
166  { return (offset == o.offset) && (length == o.length) && (format == o.format); }
167 
168  inline bool operator != (const QFormatRange& o)
169  { return (offset != o.offset) || (length != o.length) || (format != o.format); }
170 
171  int offset;
172  int length;
173  int format;
174 };
175 
176 Q_DECLARE_TYPEINFO(QFormatRange, Q_PRIMITIVE_TYPE);
177 
178 #endif
Definition: qformat.h:155
Definition: qformat.h:29
Definition: qformat.h:31