author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qbrush.h" |
|
43 |
#include "qpixmap.h" |
|
44 |
#include "qbitmap.h" |
|
45 |
#include "qpixmapcache.h" |
|
46 |
#include "qdatastream.h" |
|
47 |
#include "qvariant.h" |
|
48 |
#include "qline.h" |
|
49 |
#include "qdebug.h" |
|
50 |
#include <QtCore/qcoreapplication.h> |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
51 |
#include "private/qstylehelper_p.h" |
0 | 52 |
|
53 |
QT_BEGIN_NAMESPACE |
|
54 |
||
55 |
const uchar *qt_patternForBrush(int brushStyle, bool invert) |
|
56 |
{ |
|
57 |
Q_ASSERT(brushStyle > Qt::SolidPattern && brushStyle < Qt::LinearGradientPattern); |
|
58 |
if(invert) { |
|
59 |
static const uchar dense1_pat[] = { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff }; |
|
60 |
static const uchar dense2_pat[] = { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff }; |
|
61 |
static const uchar dense3_pat[] = { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee }; |
|
62 |
static const uchar dense4_pat[] = { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }; |
|
63 |
static const uchar dense5_pat[] = { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 }; |
|
64 |
static const uchar dense6_pat[] = { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 }; |
|
65 |
static const uchar dense7_pat[] = { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 }; |
|
66 |
static const uchar hor_pat[] = { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }; |
|
67 |
static const uchar ver_pat[] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }; |
|
68 |
static const uchar cross_pat[] = { 0x10, 0x10, 0x10, 0xff, 0x10, 0x10, 0x10, 0x10 }; |
|
69 |
static const uchar bdiag_pat[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; |
|
70 |
static const uchar fdiag_pat[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; |
|
71 |
static const uchar dcross_pat[] = { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }; |
|
72 |
static const uchar *const pat_tbl[] = { |
|
73 |
dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat, |
|
74 |
dense6_pat, dense7_pat, |
|
75 |
hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat }; |
|
76 |
return pat_tbl[brushStyle - Qt::Dense1Pattern]; |
|
77 |
} |
|
78 |
static const uchar dense1_pat[] = { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 }; |
|
79 |
static const uchar dense2_pat[] = { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 }; |
|
80 |
static const uchar dense3_pat[] = { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 }; |
|
81 |
static const uchar dense4_pat[] = { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa }; |
|
82 |
static const uchar dense5_pat[] = { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee }; |
|
83 |
static const uchar dense6_pat[] = { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff }; |
|
84 |
static const uchar dense7_pat[] = { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff }; |
|
85 |
static const uchar hor_pat[] = { 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff }; |
|
86 |
static const uchar ver_pat[] = { 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef }; |
|
87 |
static const uchar cross_pat[] = { 0xef, 0xef, 0xef, 0x00, 0xef, 0xef, 0xef, 0xef }; |
|
88 |
static const uchar bdiag_pat[] = { 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe }; |
|
89 |
static const uchar fdiag_pat[] = { 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f }; |
|
90 |
static const uchar dcross_pat[] = { 0x7e, 0xbd, 0xdb, 0xe7, 0xe7, 0xdb, 0xbd, 0x7e }; |
|
91 |
static const uchar *const pat_tbl[] = { |
|
92 |
dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat, |
|
93 |
dense6_pat, dense7_pat, |
|
94 |
hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat }; |
|
95 |
return pat_tbl[brushStyle - Qt::Dense1Pattern]; |
|
96 |
} |
|
97 |
||
98 |
QPixmap qt_pixmapForBrush(int brushStyle, bool invert) |
|
99 |
{ |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
100 |
|
0 | 101 |
QPixmap pm; |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
102 |
QString key = QLatin1Literal("$qt-brush$") |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
103 |
% HexString<uint>(brushStyle) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
104 |
% QLatin1Char(invert ? '1' : '0'); |
0 | 105 |
if (!QPixmapCache::find(key, pm)) { |
106 |
pm = QBitmap::fromData(QSize(8, 8), qt_patternForBrush(brushStyle, invert), |
|
107 |
QImage::Format_MonoLSB); |
|
108 |
QPixmapCache::insert(key, pm); |
|
109 |
} |
|
110 |
||
111 |
return pm; |
|
112 |
} |
|
113 |
||
114 |
class QBrushPatternImageCache |
|
115 |
{ |
|
116 |
public: |
|
117 |
QBrushPatternImageCache() |
|
118 |
: m_initialized(false) |
|
119 |
{ |
|
120 |
init(); |
|
121 |
} |
|
122 |
||
123 |
void init() |
|
124 |
{ |
|
125 |
for (int style = Qt::Dense1Pattern; style <= Qt::DiagCrossPattern; ++style) { |
|
126 |
int i = style - Qt::Dense1Pattern; |
|
127 |
m_images[i][0] = QImage(qt_patternForBrush(style, 0), 8, 8, 1, QImage::Format_MonoLSB); |
|
128 |
m_images[i][1] = QImage(qt_patternForBrush(style, 1), 8, 8, 1, QImage::Format_MonoLSB); |
|
129 |
} |
|
130 |
m_initialized = true; |
|
131 |
} |
|
132 |
||
133 |
QImage getImage(int brushStyle, bool invert) const |
|
134 |
{ |
|
135 |
Q_ASSERT(brushStyle >= Qt::Dense1Pattern && brushStyle <= Qt::DiagCrossPattern); |
|
136 |
if (!m_initialized) |
|
137 |
const_cast<QBrushPatternImageCache*>(this)->init(); |
|
138 |
return m_images[brushStyle - Qt::Dense1Pattern][invert]; |
|
139 |
} |
|
140 |
||
141 |
void cleanup() { |
|
142 |
for (int style = Qt::Dense1Pattern; style <= Qt::DiagCrossPattern; ++style) { |
|
143 |
int i = style - Qt::Dense1Pattern; |
|
144 |
m_images[i][0] = QImage(); |
|
145 |
m_images[i][1] = QImage(); |
|
146 |
} |
|
147 |
m_initialized = false; |
|
148 |
} |
|
149 |
||
150 |
private: |
|
151 |
QImage m_images[Qt::DiagCrossPattern - Qt::Dense1Pattern + 1][2]; |
|
152 |
bool m_initialized; |
|
153 |
}; |
|
154 |
||
155 |
static void qt_cleanup_brush_pattern_image_cache(); |
|
156 |
Q_GLOBAL_STATIC_WITH_INITIALIZER(QBrushPatternImageCache, qt_brushPatternImageCache, |
|
157 |
{ |
|
158 |
qAddPostRoutine(qt_cleanup_brush_pattern_image_cache); |
|
159 |
}) |
|
160 |
||
161 |
static void qt_cleanup_brush_pattern_image_cache() |
|
162 |
{ |
|
163 |
qt_brushPatternImageCache()->cleanup(); |
|
164 |
} |
|
165 |
||
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
166 |
Q_GUI_EXPORT QImage qt_imageForBrush(int brushStyle, bool invert) |
0 | 167 |
{ |
168 |
return qt_brushPatternImageCache()->getImage(brushStyle, invert); |
|
169 |
} |
|
170 |
||
171 |
struct QTexturedBrushData : public QBrushData |
|
172 |
{ |
|
173 |
QTexturedBrushData() { |
|
174 |
m_has_pixmap_texture = false; |
|
175 |
m_pixmap = 0; |
|
176 |
} |
|
177 |
~QTexturedBrushData() { |
|
178 |
delete m_pixmap; |
|
179 |
} |
|
180 |
||
181 |
void setPixmap(const QPixmap &pm) { |
|
182 |
delete m_pixmap; |
|
183 |
||
184 |
if (pm.isNull()) { |
|
185 |
m_pixmap = 0; |
|
186 |
m_has_pixmap_texture = false; |
|
187 |
} else { |
|
188 |
m_pixmap = new QPixmap(pm); |
|
189 |
m_has_pixmap_texture = true; |
|
190 |
} |
|
191 |
||
192 |
m_image = QImage(); |
|
193 |
} |
|
194 |
||
195 |
void setImage(const QImage &image) { |
|
196 |
m_image = image; |
|
197 |
delete m_pixmap; |
|
198 |
m_pixmap = 0; |
|
199 |
m_has_pixmap_texture = false; |
|
200 |
} |
|
201 |
||
202 |
QPixmap &pixmap() { |
|
203 |
if (!m_pixmap) { |
|
204 |
m_pixmap = new QPixmap(QPixmap::fromImage(m_image)); |
|
205 |
} |
|
206 |
return *m_pixmap; |
|
207 |
} |
|
208 |
||
209 |
QImage &image() { |
|
210 |
if (m_image.isNull() && m_pixmap) |
|
211 |
m_image = m_pixmap->toImage(); |
|
212 |
return m_image; |
|
213 |
} |
|
214 |
||
215 |
QPixmap *m_pixmap; |
|
216 |
QImage m_image; |
|
217 |
bool m_has_pixmap_texture; |
|
218 |
}; |
|
219 |
||
220 |
// returns true if the brush has a pixmap (or bitmap) set as the |
|
221 |
// brush texture, false otherwise |
|
222 |
bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush) |
|
223 |
{ |
|
224 |
if (brush.style() != Qt::TexturePattern) |
|
225 |
return false; |
|
226 |
QTexturedBrushData *tx_data = static_cast<QTexturedBrushData *>(brush.d.data()); |
|
227 |
return tx_data->m_has_pixmap_texture; |
|
228 |
} |
|
229 |
||
230 |
struct QGradientBrushData : public QBrushData |
|
231 |
{ |
|
232 |
QGradient gradient; |
|
233 |
}; |
|
234 |
||
235 |
struct QBrushDataPointerDeleter |
|
236 |
{ |
|
237 |
static inline void deleteData(QBrushData *d) |
|
238 |
{ |
|
239 |
switch (d->style) { |
|
240 |
case Qt::TexturePattern: |
|
241 |
delete static_cast<QTexturedBrushData*>(d); |
|
242 |
break; |
|
243 |
case Qt::LinearGradientPattern: |
|
244 |
case Qt::RadialGradientPattern: |
|
245 |
case Qt::ConicalGradientPattern: |
|
246 |
delete static_cast<QGradientBrushData*>(d); |
|
247 |
break; |
|
248 |
default: |
|
249 |
delete d; |
|
250 |
} |
|
251 |
} |
|
252 |
||
253 |
static inline void cleanup(QBrushData *d) |
|
254 |
{ |
|
255 |
if (d && !d->ref.deref()) { |
|
256 |
deleteData(d); |
|
257 |
} |
|
258 |
} |
|
259 |
}; |
|
260 |
||
261 |
/*! |
|
262 |
\class QBrush |
|
263 |
\ingroup painting |
|
264 |
\ingroup shared |
|
265 |
||
266 |
\brief The QBrush class defines the fill pattern of shapes drawn |
|
267 |
by QPainter. |
|
268 |
||
269 |
A brush has a style, a color, a gradient and a texture. |
|
270 |
||
271 |
The brush style() defines the fill pattern using the |
|
272 |
Qt::BrushStyle enum. The default brush style is Qt::NoBrush |
|
273 |
(depending on how you construct a brush). This style tells the |
|
274 |
painter to not fill shapes. The standard style for filling is |
|
275 |
Qt::SolidPattern. The style can be set when the brush is created |
|
276 |
using the appropriate constructor, and in addition the setStyle() |
|
277 |
function provides means for altering the style once the brush is |
|
278 |
constructed. |
|
279 |
||
280 |
\image brush-styles.png Brush Styles |
|
281 |
||
282 |
The brush color() defines the color of the fill pattern. The color |
|
283 |
can either be one of Qt's predefined colors, Qt::GlobalColor, or |
|
284 |
any other custom QColor. The currently set color can be retrieved |
|
285 |
and altered using the color() and setColor() functions, |
|
286 |
respectively. |
|
287 |
||
288 |
The gradient() defines the gradient fill used when the current |
|
289 |
style is either Qt::LinearGradientPattern, |
|
290 |
Qt::RadialGradientPattern or Qt::ConicalGradientPattern. Gradient |
|
291 |
brushes are created by giving a QGradient as a constructor |
|
292 |
argument when creating the QBrush. Qt provides three different |
|
293 |
gradients: QLinearGradient, QConicalGradient, and QRadialGradient |
|
294 |
- all of which inherit QGradient. |
|
295 |
||
296 |
\snippet doc/src/snippets/brush/gradientcreationsnippet.cpp 0 |
|
297 |
||
298 |
The texture() defines the pixmap used when the current style is |
|
299 |
Qt::TexturePattern. You can create a brush with a texture by |
|
300 |
providing the pixmap when the brush is created or by using |
|
301 |
setTexture(). |
|
302 |
||
303 |
Note that applying setTexture() makes style() == |
|
304 |
Qt::TexturePattern, regardless of previous style |
|
305 |
settings. Also, calling setColor() will not make a difference if |
|
306 |
the style is a gradient. The same is the case if the style is |
|
307 |
Qt::TexturePattern style unless the current texture is a QBitmap. |
|
308 |
||
309 |
The isOpaque() function returns true if the brush is fully opaque |
|
310 |
otherwise false. A brush is considered opaque if: |
|
311 |
||
312 |
\list |
|
313 |
\o The alpha component of the color() is 255. |
|
314 |
\o Its texture() does not have an alpha channel and is not a QBitmap. |
|
315 |
\o The colors in the gradient() all have an alpha component that is 255. |
|
316 |
\endlist |
|
317 |
||
318 |
\table 100% |
|
319 |
\row |
|
320 |
\o \inlineimage brush-outline.png Outlines |
|
321 |
\o |
|
322 |
||
323 |
To specify the style and color of lines and outlines, use the |
|
324 |
QPainter's \l {QPen}{pen} combined with Qt::PenStyle and |
|
325 |
Qt::GlobalColor: |
|
326 |
||
327 |
\snippet doc/src/snippets/code/src_gui_painting_qbrush.cpp 0 |
|
328 |
||
329 |
Note that, by default, QPainter renders the outline (using the |
|
330 |
currently set pen) when drawing shapes. Use \l {Qt::NoPen}{\c |
|
331 |
painter.setPen(Qt::NoPen)} to disable this behavior. |
|
332 |
||
333 |
\endtable |
|
334 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
335 |
For more information about painting in general, see the \l{Paint |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
336 |
System}. |
0 | 337 |
|
338 |
\sa Qt::BrushStyle, QPainter, QColor |
|
339 |
*/ |
|
340 |
||
341 |
#ifndef QT_NO_THREAD |
|
342 |
// Special deleter that only deletes if the ref-count goes to zero |
|
343 |
template <> |
|
344 |
class QGlobalStaticDeleter<QBrushData> |
|
345 |
{ |
|
346 |
public: |
|
347 |
QGlobalStatic<QBrushData> &globalStatic; |
|
348 |
QGlobalStaticDeleter(QGlobalStatic<QBrushData> &_globalStatic) |
|
349 |
: globalStatic(_globalStatic) |
|
350 |
{ } |
|
351 |
||
352 |
inline ~QGlobalStaticDeleter() |
|
353 |
{ |
|
354 |
if (!globalStatic.pointer->ref.deref()) |
|
355 |
delete globalStatic.pointer; |
|
356 |
globalStatic.pointer = 0; |
|
357 |
globalStatic.destroyed = true; |
|
358 |
} |
|
359 |
}; |
|
360 |
#endif |
|
361 |
||
362 |
Q_GLOBAL_STATIC_WITH_INITIALIZER(QBrushData, nullBrushInstance, |
|
363 |
{ |
|
364 |
x->ref = 1; |
|
365 |
x->style = Qt::BrushStyle(0); |
|
366 |
x->color = Qt::black; |
|
367 |
}) |
|
368 |
||
369 |
static bool qbrush_check_type(Qt::BrushStyle style) { |
|
370 |
switch (style) { |
|
371 |
case Qt::TexturePattern: |
|
372 |
qWarning("QBrush: Incorrect use of TexturePattern"); |
|
373 |
break; |
|
374 |
case Qt::LinearGradientPattern: |
|
375 |
case Qt::RadialGradientPattern: |
|
376 |
case Qt::ConicalGradientPattern: |
|
377 |
qWarning("QBrush: Wrong use of a gradient pattern"); |
|
378 |
break; |
|
379 |
default: |
|
380 |
return true; |
|
381 |
} |
|
382 |
return false; |
|
383 |
} |
|
384 |
||
385 |
/*! |
|
386 |
\internal |
|
387 |
Initializes the brush. |
|
388 |
*/ |
|
389 |
||
390 |
void QBrush::init(const QColor &color, Qt::BrushStyle style) |
|
391 |
{ |
|
392 |
switch(style) { |
|
393 |
case Qt::NoBrush: |
|
394 |
d.reset(nullBrushInstance()); |
|
395 |
d->ref.ref(); |
|
396 |
if (d->color != color) setColor(color); |
|
397 |
return; |
|
398 |
case Qt::TexturePattern: |
|
399 |
d.reset(new QTexturedBrushData); |
|
400 |
break; |
|
401 |
case Qt::LinearGradientPattern: |
|
402 |
case Qt::RadialGradientPattern: |
|
403 |
case Qt::ConicalGradientPattern: |
|
404 |
d.reset(new QGradientBrushData); |
|
405 |
break; |
|
406 |
default: |
|
407 |
d.reset(new QBrushData); |
|
408 |
break; |
|
409 |
} |
|
410 |
d->ref = 1; |
|
411 |
d->style = style; |
|
412 |
d->color = color; |
|
413 |
} |
|
414 |
||
415 |
/*! |
|
416 |
Constructs a default black brush with the style Qt::NoBrush |
|
417 |
(i.e. this brush will not fill shapes). |
|
418 |
*/ |
|
419 |
||
420 |
QBrush::QBrush() |
|
421 |
: d(nullBrushInstance()) |
|
422 |
{ |
|
423 |
Q_ASSERT(d); |
|
424 |
d->ref.ref(); |
|
425 |
} |
|
426 |
||
427 |
/*! |
|
428 |
Constructs a brush with a black color and a texture set to the |
|
429 |
given \a pixmap. The style is set to Qt::TexturePattern. |
|
430 |
||
431 |
\sa setTexture() |
|
432 |
*/ |
|
433 |
||
434 |
QBrush::QBrush(const QPixmap &pixmap) |
|
435 |
{ |
|
436 |
init(Qt::black, Qt::TexturePattern); |
|
437 |
setTexture(pixmap); |
|
438 |
} |
|
439 |
||
440 |
||
441 |
/*! |
|
442 |
Constructs a brush with a black color and a texture set to the |
|
443 |
given \a image. The style is set to Qt::TexturePattern. |
|
444 |
||
445 |
\sa setTextureImage() |
|
446 |
*/ |
|
447 |
||
448 |
QBrush::QBrush(const QImage &image) |
|
449 |
{ |
|
450 |
init(Qt::black, Qt::TexturePattern); |
|
451 |
setTextureImage(image); |
|
452 |
} |
|
453 |
||
454 |
/*! |
|
455 |
Constructs a black brush with the given \a style. |
|
456 |
||
457 |
\sa setStyle() |
|
458 |
*/ |
|
459 |
||
460 |
QBrush::QBrush(Qt::BrushStyle style) |
|
461 |
{ |
|
462 |
if (qbrush_check_type(style)) |
|
463 |
init(Qt::black, style); |
|
464 |
else { |
|
465 |
d.reset(nullBrushInstance()); |
|
466 |
d->ref.ref(); |
|
467 |
} |
|
468 |
} |
|
469 |
||
470 |
/*! |
|
471 |
Constructs a brush with the given \a color and \a style. |
|
472 |
||
473 |
\sa setColor(), setStyle() |
|
474 |
*/ |
|
475 |
||
476 |
QBrush::QBrush(const QColor &color, Qt::BrushStyle style) |
|
477 |
{ |
|
478 |
if (qbrush_check_type(style)) |
|
479 |
init(color, style); |
|
480 |
else { |
|
481 |
d.reset(nullBrushInstance()); |
|
482 |
d->ref.ref(); |
|
483 |
} |
|
484 |
} |
|
485 |
||
486 |
/*! |
|
487 |
\fn QBrush::QBrush(Qt::GlobalColor color, Qt::BrushStyle style) |
|
488 |
||
489 |
Constructs a brush with the given \a color and \a style. |
|
490 |
||
491 |
\sa setColor(), setStyle() |
|
492 |
*/ |
|
493 |
QBrush::QBrush(Qt::GlobalColor color, Qt::BrushStyle style) |
|
494 |
{ |
|
495 |
if (qbrush_check_type(style)) |
|
496 |
init(color, style); |
|
497 |
else { |
|
498 |
d.reset(nullBrushInstance()); |
|
499 |
d->ref.ref(); |
|
500 |
} |
|
501 |
} |
|
502 |
||
503 |
/*! |
|
504 |
Constructs a brush with the given \a color and the custom pattern |
|
505 |
stored in \a pixmap. |
|
506 |
||
507 |
The style is set to Qt::TexturePattern. The color will only have |
|
508 |
an effect for QBitmaps. |
|
509 |
||
510 |
\sa setColor(), setPixmap() |
|
511 |
*/ |
|
512 |
||
513 |
QBrush::QBrush(const QColor &color, const QPixmap &pixmap) |
|
514 |
{ |
|
515 |
init(color, Qt::TexturePattern); |
|
516 |
setTexture(pixmap); |
|
517 |
} |
|
518 |
||
519 |
/*! |
|
520 |
||
521 |
Constructs a brush with the given \a color and the custom pattern |
|
522 |
stored in \a pixmap. |
|
523 |
||
524 |
The style is set to Qt::TexturePattern. The color will only have |
|
525 |
an effect for QBitmaps. |
|
526 |
||
527 |
\sa setColor(), setPixmap() |
|
528 |
*/ |
|
529 |
QBrush::QBrush(Qt::GlobalColor color, const QPixmap &pixmap) |
|
530 |
{ |
|
531 |
init(color, Qt::TexturePattern); |
|
532 |
setTexture(pixmap); |
|
533 |
} |
|
534 |
||
535 |
/*! |
|
536 |
Constructs a copy of \a other. |
|
537 |
*/ |
|
538 |
||
539 |
QBrush::QBrush(const QBrush &other) |
|
540 |
: d(other.d.data()) |
|
541 |
{ |
|
542 |
d->ref.ref(); |
|
543 |
} |
|
544 |
||
545 |
/*! |
|
546 |
Constructs a brush based on the given \a gradient. |
|
547 |
||
548 |
The brush style is set to the corresponding gradient style (either |
|
549 |
Qt::LinearGradientPattern, Qt::RadialGradientPattern or |
|
550 |
Qt::ConicalGradientPattern). |
|
551 |
*/ |
|
552 |
QBrush::QBrush(const QGradient &gradient) |
|
553 |
{ |
|
554 |
Q_ASSERT_X(gradient.type() != QGradient::NoGradient, "QBrush::QBrush", |
|
555 |
"QGradient should not be used directly, use the linear, radial\n" |
|
556 |
"or conical gradients instead"); |
|
557 |
||
558 |
const Qt::BrushStyle enum_table[] = { |
|
559 |
Qt::LinearGradientPattern, |
|
560 |
Qt::RadialGradientPattern, |
|
561 |
Qt::ConicalGradientPattern |
|
562 |
}; |
|
563 |
||
564 |
init(QColor(), enum_table[gradient.type()]); |
|
565 |
QGradientBrushData *grad = static_cast<QGradientBrushData *>(d.data()); |
|
566 |
grad->gradient = gradient; |
|
567 |
} |
|
568 |
||
569 |
/*! |
|
570 |
Destroys the brush. |
|
571 |
*/ |
|
572 |
||
573 |
QBrush::~QBrush() |
|
574 |
{ |
|
575 |
} |
|
576 |
||
577 |
void QBrush::cleanUp(QBrushData *x) |
|
578 |
{ |
|
579 |
QBrushDataPointerDeleter::deleteData(x); |
|
580 |
} |
|
581 |
||
582 |
||
583 |
void QBrush::detach(Qt::BrushStyle newStyle) |
|
584 |
{ |
|
585 |
if (newStyle == d->style && d->ref == 1) |
|
586 |
return; |
|
587 |
||
588 |
QScopedPointer<QBrushData> x; |
|
589 |
switch(newStyle) { |
|
590 |
case Qt::TexturePattern: { |
|
591 |
QTexturedBrushData *tbd = new QTexturedBrushData; |
|
592 |
if (d->style == Qt::TexturePattern) { |
|
593 |
QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data()); |
|
594 |
if (data->m_has_pixmap_texture) |
|
595 |
tbd->setPixmap(data->pixmap()); |
|
596 |
else |
|
597 |
tbd->setImage(data->image()); |
|
598 |
} |
|
599 |
x.reset(tbd); |
|
600 |
break; |
|
601 |
} |
|
602 |
case Qt::LinearGradientPattern: |
|
603 |
case Qt::RadialGradientPattern: |
|
604 |
case Qt::ConicalGradientPattern: |
|
605 |
x.reset(new QGradientBrushData); |
|
606 |
static_cast<QGradientBrushData *>(x.data())->gradient = |
|
607 |
static_cast<QGradientBrushData *>(d.data())->gradient; |
|
608 |
break; |
|
609 |
default: |
|
610 |
x.reset(new QBrushData); |
|
611 |
break; |
|
612 |
} |
|
613 |
x->ref = 1; |
|
614 |
x->style = newStyle; |
|
615 |
x->color = d->color; |
|
616 |
x->transform = d->transform; |
|
617 |
d.reset(x.take()); |
|
618 |
} |
|
619 |
||
620 |
||
621 |
/*! |
|
622 |
\fn QBrush &QBrush::operator=(const QBrush &brush) |
|
623 |
||
624 |
Assigns the given \a brush to \e this brush and returns a |
|
625 |
reference to \e this brush. |
|
626 |
*/ |
|
627 |
||
628 |
QBrush &QBrush::operator=(const QBrush &b) |
|
629 |
{ |
|
630 |
if (d == b.d) |
|
631 |
return *this; |
|
632 |
||
633 |
b.d->ref.ref(); |
|
634 |
d.reset(b.d.data()); |
|
635 |
return *this; |
|
636 |
} |
|
637 |
||
638 |
/*! |
|
639 |
Returns the brush as a QVariant |
|
640 |
*/ |
|
641 |
QBrush::operator QVariant() const |
|
642 |
{ |
|
643 |
return QVariant(QVariant::Brush, this); |
|
644 |
} |
|
645 |
||
646 |
/*! |
|
647 |
\fn Qt::BrushStyle QBrush::style() const |
|
648 |
||
649 |
Returns the brush style. |
|
650 |
||
651 |
\sa setStyle() |
|
652 |
*/ |
|
653 |
||
654 |
/*! |
|
655 |
Sets the brush style to \a style. |
|
656 |
||
657 |
\sa style() |
|
658 |
*/ |
|
659 |
||
660 |
void QBrush::setStyle(Qt::BrushStyle style) |
|
661 |
{ |
|
662 |
if (d->style == style) |
|
663 |
return; |
|
664 |
||
665 |
if (qbrush_check_type(style)) { |
|
666 |
detach(style); |
|
667 |
d->style = style; |
|
668 |
} |
|
669 |
} |
|
670 |
||
671 |
||
672 |
/*! |
|
673 |
\fn const QColor &QBrush::color() const |
|
674 |
||
675 |
Returns the brush color. |
|
676 |
||
677 |
\sa setColor() |
|
678 |
*/ |
|
679 |
||
680 |
/*! |
|
681 |
\fn void QBrush::setColor(const QColor &color) |
|
682 |
||
683 |
Sets the brush color to the given \a color. |
|
684 |
||
685 |
Note that calling setColor() will not make a difference if the |
|
686 |
style is a gradient. The same is the case if the style is |
|
687 |
Qt::TexturePattern style unless the current texture is a QBitmap. |
|
688 |
||
689 |
\sa color() |
|
690 |
*/ |
|
691 |
||
692 |
void QBrush::setColor(const QColor &c) |
|
693 |
{ |
|
694 |
detach(d->style); |
|
695 |
d->color = c; |
|
696 |
} |
|
697 |
||
698 |
/*! |
|
699 |
\fn void QBrush::setColor(Qt::GlobalColor color) |
|
700 |
\overload |
|
701 |
||
702 |
Sets the brush color to the given \a color. |
|
703 |
*/ |
|
704 |
||
705 |
||
706 |
#ifdef QT3_SUPPORT |
|
707 |
||
708 |
/*! |
|
709 |
\fn void QBrush::setPixmap(const QPixmap &pixmap) |
|
710 |
||
711 |
\compat |
|
712 |
||
713 |
Sets a custom pattern for this brush. |
|
714 |
||
715 |
Use setTexture() instead. |
|
716 |
*/ |
|
717 |
||
718 |
/*! |
|
719 |
\fn QPixmap *QBrush::pixmap() const |
|
720 |
||
721 |
Returns a pointer to the custom brush pattern. |
|
722 |
||
723 |
Use texture() instead. |
|
724 |
*/ |
|
725 |
QPixmap *QBrush::pixmap() const |
|
726 |
{ |
|
727 |
if (d->style != Qt::TexturePattern) |
|
728 |
return 0; |
|
729 |
QTexturedBrushData *data = static_cast<QTexturedBrushData*>(d.data()); |
|
730 |
QPixmap &pixmap = data->pixmap(); |
|
731 |
return pixmap.isNull() ? 0 : &pixmap; |
|
732 |
} |
|
733 |
#endif |
|
734 |
||
735 |
/*! |
|
736 |
\fn QPixmap QBrush::texture() const |
|
737 |
||
738 |
Returns the custom brush pattern, or a null pixmap if no custom brush pattern |
|
739 |
has been set. |
|
740 |
||
741 |
\sa setTexture() |
|
742 |
*/ |
|
743 |
QPixmap QBrush::texture() const |
|
744 |
{ |
|
745 |
return d->style == Qt::TexturePattern |
|
746 |
? (static_cast<QTexturedBrushData *>(d.data()))->pixmap() |
|
747 |
: QPixmap(); |
|
748 |
} |
|
749 |
||
750 |
/*! |
|
751 |
Sets the brush pixmap to \a pixmap. The style is set to |
|
752 |
Qt::TexturePattern. |
|
753 |
||
754 |
The current brush color will only have an effect for monochrome |
|
755 |
pixmaps, i.e. for QPixmap::depth() == 1 (\l {QBitmap}{QBitmaps}). |
|
756 |
||
757 |
\sa texture() |
|
758 |
*/ |
|
759 |
||
760 |
void QBrush::setTexture(const QPixmap &pixmap) |
|
761 |
{ |
|
762 |
if (!pixmap.isNull()) { |
|
763 |
detach(Qt::TexturePattern); |
|
764 |
QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data()); |
|
765 |
data->setPixmap(pixmap); |
|
766 |
} else { |
|
767 |
detach(Qt::NoBrush); |
|
768 |
} |
|
769 |
} |
|
770 |
||
771 |
||
772 |
/*! |
|
773 |
\since 4.2 |
|
774 |
||
775 |
Returns the custom brush pattern, or a null image if no custom |
|
776 |
brush pattern has been set. |
|
777 |
||
778 |
If the texture was set as a QPixmap it will be converted to a |
|
779 |
QImage. |
|
780 |
||
781 |
\sa setTextureImage() |
|
782 |
*/ |
|
783 |
||
784 |
QImage QBrush::textureImage() const |
|
785 |
{ |
|
786 |
return d->style == Qt::TexturePattern |
|
787 |
? (static_cast<QTexturedBrushData *>(d.data()))->image() |
|
788 |
: QImage(); |
|
789 |
} |
|
790 |
||
791 |
||
792 |
/*! |
|
793 |
\since 4.2 |
|
794 |
||
795 |
Sets the brush image to \a image. The style is set to |
|
796 |
Qt::TexturePattern. |
|
797 |
||
798 |
Note the current brush color will \e not have any affect on |
|
799 |
monochrome images, as opposed to calling setTexture() with a |
|
800 |
QBitmap. If you want to change the color of monochrome image |
|
801 |
brushes, either convert the image to QBitmap with \c |
|
802 |
QBitmap::fromImage() and set the resulting QBitmap as a texture, |
|
803 |
or change the entries in the color table for the image. |
|
804 |
||
805 |
\sa textureImage(), setTexture() |
|
806 |
*/ |
|
807 |
||
808 |
void QBrush::setTextureImage(const QImage &image) |
|
809 |
{ |
|
810 |
if (!image.isNull()) { |
|
811 |
detach(Qt::TexturePattern); |
|
812 |
QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data()); |
|
813 |
data->setImage(image); |
|
814 |
} else { |
|
815 |
detach(Qt::NoBrush); |
|
816 |
} |
|
817 |
} |
|
818 |
||
819 |
||
820 |
/*! |
|
821 |
Returns the gradient describing this brush. |
|
822 |
*/ |
|
823 |
const QGradient *QBrush::gradient() const |
|
824 |
{ |
|
825 |
if (d->style == Qt::LinearGradientPattern |
|
826 |
|| d->style == Qt::RadialGradientPattern |
|
827 |
|| d->style == Qt::ConicalGradientPattern) { |
|
828 |
return &static_cast<const QGradientBrushData *>(d.data())->gradient; |
|
829 |
} |
|
830 |
return 0; |
|
831 |
} |
|
832 |
||
833 |
||
834 |
/*! |
|
835 |
Returns true if the brush is fully opaque otherwise false. A brush |
|
836 |
is considered opaque if: |
|
837 |
||
838 |
\list |
|
839 |
\i The alpha component of the color() is 255. |
|
840 |
\i Its texture() does not have an alpha channel and is not a QBitmap. |
|
841 |
\i The colors in the gradient() all have an alpha component that is 255. |
|
842 |
\endlist |
|
843 |
*/ |
|
844 |
||
845 |
bool QBrush::isOpaque() const |
|
846 |
{ |
|
847 |
bool opaqueColor = d->color.alpha() == 255; |
|
848 |
||
849 |
// Test awfully simple case first |
|
850 |
if (d->style == Qt::SolidPattern) |
|
851 |
return opaqueColor; |
|
852 |
||
853 |
if (d->style == Qt::LinearGradientPattern |
|
854 |
|| d->style == Qt::RadialGradientPattern |
|
855 |
|| d->style == Qt::ConicalGradientPattern) { |
|
856 |
QGradientStops stops = gradient()->stops(); |
|
857 |
for (int i=0; i<stops.size(); ++i) |
|
858 |
if (stops.at(i).second.alpha() != 255) |
|
859 |
return false; |
|
860 |
return true; |
|
861 |
} else if (d->style == Qt::TexturePattern) { |
|
862 |
return qHasPixmapTexture(*this) |
|
863 |
? !texture().hasAlphaChannel() && !texture().isQBitmap() |
|
864 |
: !textureImage().hasAlphaChannel(); |
|
865 |
} |
|
866 |
||
867 |
return false; |
|
868 |
} |
|
869 |
||
870 |
||
871 |
/*! |
|
872 |
\since 4.2 |
|
873 |
||
874 |
Sets \a matrix as an explicit transformation matrix on the |
|
875 |
current brush. The brush transformation matrix is merged with |
|
876 |
QPainter transformation matrix to produce the final result. |
|
877 |
||
878 |
\sa matrix() |
|
879 |
*/ |
|
880 |
void QBrush::setMatrix(const QMatrix &matrix) |
|
881 |
{ |
|
882 |
setTransform(QTransform(matrix)); |
|
883 |
} |
|
884 |
||
885 |
/*! |
|
886 |
\since 4.3 |
|
887 |
||
888 |
Sets \a matrix as an explicit transformation matrix on the |
|
889 |
current brush. The brush transformation matrix is merged with |
|
890 |
QPainter transformation matrix to produce the final result. |
|
891 |
||
892 |
\sa transform() |
|
893 |
*/ |
|
894 |
void QBrush::setTransform(const QTransform &matrix) |
|
895 |
{ |
|
896 |
detach(d->style); |
|
897 |
d->transform = matrix; |
|
898 |
} |
|
899 |
||
900 |
||
901 |
/*! |
|
902 |
\fn void QBrush::matrix() const |
|
903 |
\since 4.2 |
|
904 |
||
905 |
Returns the current transformation matrix for the brush. |
|
906 |
||
907 |
\sa setMatrix() |
|
908 |
*/ |
|
909 |
||
910 |
/*! |
|
911 |
\fn bool QBrush::operator!=(const QBrush &brush) const |
|
912 |
||
913 |
Returns true if the brush is different from the given \a brush; |
|
914 |
otherwise returns false. |
|
915 |
||
916 |
Two brushes are different if they have different styles, colors or |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
917 |
transforms or different pixmaps or gradients depending on the style. |
0 | 918 |
|
919 |
\sa operator==() |
|
920 |
*/ |
|
921 |
||
922 |
/*! |
|
923 |
\fn bool QBrush::operator==(const QBrush &brush) const |
|
924 |
||
925 |
Returns true if the brush is equal to the given \a brush; |
|
926 |
otherwise returns false. |
|
927 |
||
928 |
Two brushes are equal if they have equal styles, colors and |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
929 |
transforms and equal pixmaps or gradients depending on the style. |
0 | 930 |
|
931 |
\sa operator!=() |
|
932 |
*/ |
|
933 |
||
934 |
bool QBrush::operator==(const QBrush &b) const |
|
935 |
{ |
|
936 |
if (b.d == d) |
|
937 |
return true; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
938 |
if (b.d->style != d->style || b.d->color != d->color || b.d->transform != d->transform) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
939 |
return false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
940 |
switch (d->style) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
941 |
case Qt::TexturePattern: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
942 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
943 |
const QPixmap &us = (static_cast<QTexturedBrushData *>(d.data()))->pixmap(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
944 |
const QPixmap &them = (static_cast<QTexturedBrushData *>(b.d.data()))->pixmap(); |
0 | 945 |
return ((us.isNull() && them.isNull()) || us.cacheKey() == them.cacheKey()); |
946 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
947 |
case Qt::LinearGradientPattern: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
948 |
case Qt::RadialGradientPattern: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
949 |
case Qt::ConicalGradientPattern: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
950 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
951 |
const QGradientBrushData *d1 = static_cast<QGradientBrushData *>(d.data()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
952 |
const QGradientBrushData *d2 = static_cast<QGradientBrushData *>(b.d.data()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
953 |
return d1->gradient == d2->gradient; |
0 | 954 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
955 |
default: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
956 |
return true; |
0 | 957 |
} |
958 |
} |
|
959 |
||
960 |
/*! |
|
961 |
\fn QBrush::operator const QColor&() const |
|
962 |
||
963 |
Returns the brush's color. |
|
964 |
||
965 |
Use color() instead. |
|
966 |
*/ |
|
967 |
||
968 |
#ifndef QT_NO_DEBUG_STREAM |
|
969 |
/*! |
|
970 |
\internal |
|
971 |
*/ |
|
972 |
QDebug operator<<(QDebug dbg, const QBrush &b) |
|
973 |
{ |
|
974 |
#ifndef Q_BROKEN_DEBUG_STREAM |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
975 |
static const char *BRUSH_STYLES[] = { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
976 |
"NoBrush", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
977 |
"SolidPattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
978 |
"Dense1Pattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
979 |
"Dense2Pattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
980 |
"Dense3Pattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
981 |
"Dense4Pattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
982 |
"Dense5Pattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
983 |
"Dense6Pattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
984 |
"Dense7Pattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
985 |
"HorPattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
986 |
"VerPattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
987 |
"CrossPattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
988 |
"BDiagPattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
989 |
"FDiagPattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
990 |
"DiagCrossPattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
991 |
"LinearGradientPattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
992 |
"RadialGradientPattern", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
993 |
"ConicalGradientPattern", |
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
994 |
0, 0, 0, 0, 0, 0, |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
995 |
"TexturePattern" // 24 |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
996 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
997 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
998 |
dbg.nospace() << "QBrush(" << b.color() << ',' << BRUSH_STYLES[b.style()] << ')'; |
0 | 999 |
return dbg.space(); |
1000 |
#else |
|
1001 |
qWarning("This compiler doesn't support streaming QBrush to QDebug"); |
|
1002 |
return dbg; |
|
1003 |
Q_UNUSED(b); |
|
1004 |
#endif |
|
1005 |
} |
|
1006 |
#endif |
|
1007 |
||
1008 |
/***************************************************************************** |
|
1009 |
QBrush stream functions |
|
1010 |
*****************************************************************************/ |
|
1011 |
#ifndef QT_NO_DATASTREAM |
|
1012 |
/*! |
|
1013 |
\fn QDataStream &operator<<(QDataStream &stream, const QBrush &brush) |
|
1014 |
\relates QBrush |
|
1015 |
||
1016 |
Writes the given \a brush to the given \a stream and returns a |
|
1017 |
reference to the \a stream. |
|
1018 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1019 |
\sa {Serializing Qt Data Types} |
0 | 1020 |
*/ |
1021 |
||
1022 |
QDataStream &operator<<(QDataStream &s, const QBrush &b) |
|
1023 |
{ |
|
1024 |
quint8 style = (quint8) b.style(); |
|
1025 |
bool gradient_style = false; |
|
1026 |
||
1027 |
if (style == Qt::LinearGradientPattern || style == Qt::RadialGradientPattern |
|
1028 |
|| style == Qt::ConicalGradientPattern) |
|
1029 |
gradient_style = true; |
|
1030 |
||
1031 |
if (s.version() < QDataStream::Qt_4_0 && gradient_style) |
|
1032 |
style = Qt::NoBrush; |
|
1033 |
||
1034 |
s << style << b.color(); |
|
1035 |
if (b.style() == Qt::TexturePattern) { |
|
1036 |
s << b.texture(); |
|
1037 |
} else if (s.version() >= QDataStream::Qt_4_0 && gradient_style) { |
|
1038 |
const QGradient *gradient = b.gradient(); |
|
1039 |
int type_as_int = int(gradient->type()); |
|
1040 |
s << type_as_int; |
|
1041 |
if (s.version() >= QDataStream::Qt_4_3) { |
|
1042 |
s << int(gradient->spread()); |
|
1043 |
s << int(gradient->coordinateMode()); |
|
1044 |
} |
|
1045 |
||
1046 |
if (s.version() >= QDataStream::Qt_4_5) |
|
1047 |
s << int(gradient->interpolationMode()); |
|
1048 |
||
1049 |
if (sizeof(qreal) == sizeof(double)) { |
|
1050 |
s << gradient->stops(); |
|
1051 |
} else { |
|
1052 |
// ensure that we write doubles here instead of streaming the stops |
|
1053 |
// directly; otherwise, platforms that redefine qreal might generate |
|
1054 |
// data that cannot be read on other platforms. |
|
1055 |
QVector<QGradientStop> stops = gradient->stops(); |
|
1056 |
s << quint32(stops.size()); |
|
1057 |
for (int i = 0; i < stops.size(); ++i) { |
|
1058 |
const QGradientStop &stop = stops.at(i); |
|
1059 |
s << QPair<double, QColor>(double(stop.first), stop.second); |
|
1060 |
} |
|
1061 |
} |
|
1062 |
||
1063 |
if (gradient->type() == QGradient::LinearGradient) { |
|
1064 |
s << static_cast<const QLinearGradient *>(gradient)->start(); |
|
1065 |
s << static_cast<const QLinearGradient *>(gradient)->finalStop(); |
|
1066 |
} else if (gradient->type() == QGradient::RadialGradient) { |
|
1067 |
s << static_cast<const QRadialGradient *>(gradient)->center(); |
|
1068 |
s << static_cast<const QRadialGradient *>(gradient)->focalPoint(); |
|
1069 |
s << (double) static_cast<const QRadialGradient *>(gradient)->radius(); |
|
1070 |
} else { // type == Conical |
|
1071 |
s << static_cast<const QConicalGradient *>(gradient)->center(); |
|
1072 |
s << (double) static_cast<const QConicalGradient *>(gradient)->angle(); |
|
1073 |
} |
|
1074 |
} |
|
1075 |
if (s.version() >= QDataStream::Qt_4_3) |
|
1076 |
s << b.transform(); |
|
1077 |
return s; |
|
1078 |
} |
|
1079 |
||
1080 |
/*! |
|
1081 |
\fn QDataStream &operator>>(QDataStream &stream, QBrush &brush) |
|
1082 |
\relates QBrush |
|
1083 |
||
1084 |
Reads the given \a brush from the given \a stream and returns a |
|
1085 |
reference to the \a stream. |
|
1086 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1087 |
\sa {Serializing Qt Data Types} |
0 | 1088 |
*/ |
1089 |
||
1090 |
QDataStream &operator>>(QDataStream &s, QBrush &b) |
|
1091 |
{ |
|
1092 |
quint8 style; |
|
1093 |
QColor color; |
|
1094 |
s >> style; |
|
1095 |
s >> color; |
|
1096 |
if (style == Qt::TexturePattern) { |
|
1097 |
QPixmap pm; |
|
1098 |
s >> pm; |
|
1099 |
b = QBrush(color, pm); |
|
1100 |
} else if (style == Qt::LinearGradientPattern |
|
1101 |
|| style == Qt::RadialGradientPattern |
|
1102 |
|| style == Qt::ConicalGradientPattern) { |
|
1103 |
||
1104 |
int type_as_int; |
|
1105 |
QGradient::Type type; |
|
1106 |
QGradientStops stops; |
|
1107 |
QGradient::CoordinateMode cmode = QGradient::LogicalMode; |
|
1108 |
QGradient::Spread spread = QGradient::PadSpread; |
|
1109 |
QGradient::InterpolationMode imode = QGradient::ColorInterpolation; |
|
1110 |
||
1111 |
s >> type_as_int; |
|
1112 |
type = QGradient::Type(type_as_int); |
|
1113 |
if (s.version() >= QDataStream::Qt_4_3) { |
|
1114 |
s >> type_as_int; |
|
1115 |
spread = QGradient::Spread(type_as_int); |
|
1116 |
s >> type_as_int; |
|
1117 |
cmode = QGradient::CoordinateMode(type_as_int); |
|
1118 |
} |
|
1119 |
||
1120 |
if (s.version() >= QDataStream::Qt_4_5) { |
|
1121 |
s >> type_as_int; |
|
1122 |
imode = QGradient::InterpolationMode(type_as_int); |
|
1123 |
} |
|
1124 |
||
1125 |
if (sizeof(qreal) == sizeof(double)) { |
|
1126 |
s >> stops; |
|
1127 |
} else { |
|
1128 |
quint32 numStops; |
|
1129 |
double n; |
|
1130 |
QColor c; |
|
1131 |
||
1132 |
s >> numStops; |
|
1133 |
for (quint32 i = 0; i < numStops; ++i) { |
|
1134 |
s >> n >> c; |
|
1135 |
stops << QPair<qreal, QColor>(n, c); |
|
1136 |
} |
|
1137 |
} |
|
1138 |
||
1139 |
if (type == QGradient::LinearGradient) { |
|
1140 |
QPointF p1, p2; |
|
1141 |
s >> p1; |
|
1142 |
s >> p2; |
|
1143 |
QLinearGradient lg(p1, p2); |
|
1144 |
lg.setStops(stops); |
|
1145 |
lg.setSpread(spread); |
|
1146 |
lg.setCoordinateMode(cmode); |
|
1147 |
lg.setInterpolationMode(imode); |
|
1148 |
b = QBrush(lg); |
|
1149 |
} else if (type == QGradient::RadialGradient) { |
|
1150 |
QPointF center, focal; |
|
1151 |
double radius; |
|
1152 |
s >> center; |
|
1153 |
s >> focal; |
|
1154 |
s >> radius; |
|
1155 |
QRadialGradient rg(center, radius, focal); |
|
1156 |
rg.setStops(stops); |
|
1157 |
rg.setSpread(spread); |
|
1158 |
rg.setCoordinateMode(cmode); |
|
1159 |
rg.setInterpolationMode(imode); |
|
1160 |
b = QBrush(rg); |
|
1161 |
} else { // type == QGradient::ConicalGradient |
|
1162 |
QPointF center; |
|
1163 |
double angle; |
|
1164 |
s >> center; |
|
1165 |
s >> angle; |
|
1166 |
QConicalGradient cg(center, angle); |
|
1167 |
cg.setStops(stops); |
|
1168 |
cg.setSpread(spread); |
|
1169 |
cg.setCoordinateMode(cmode); |
|
1170 |
cg.setInterpolationMode(imode); |
|
1171 |
b = QBrush(cg); |
|
1172 |
} |
|
1173 |
} else { |
|
1174 |
b = QBrush(color, (Qt::BrushStyle)style); |
|
1175 |
} |
|
1176 |
if (s.version() >= QDataStream::Qt_4_3) { |
|
1177 |
QTransform transform; |
|
1178 |
s >> transform; |
|
1179 |
b.setTransform(transform); |
|
1180 |
} |
|
1181 |
return s; |
|
1182 |
} |
|
1183 |
#endif // QT_NO_DATASTREAM |
|
1184 |
||
1185 |
/******************************************************************************* |
|
1186 |
* QGradient implementations |
|
1187 |
*/ |
|
1188 |
||
1189 |
||
1190 |
/*! |
|
1191 |
\class QGradient |
|
1192 |
\ingroup painting |
|
1193 |
\ingroup shared |
|
1194 |
||
1195 |
\brief The QGradient class is used in combination with QBrush to |
|
1196 |
specify gradient fills. |
|
1197 |
||
1198 |
Qt currently supports three types of gradient fills: |
|
1199 |
||
1200 |
\list |
|
1201 |
\o \e Linear gradients interpolate colors between start and end points. |
|
1202 |
\o \e Radial gradients interpolate colors between a focal point and end |
|
1203 |
points on a circle surrounding it. |
|
1204 |
\o \e Conical gradients interpolate colors around a center point. |
|
1205 |
\endlist |
|
1206 |
||
1207 |
A gradient's type can be retrieved using the type() function. |
|
1208 |
Each of the types is represented by a subclass of QGradient: |
|
1209 |
||
1210 |
\table |
|
1211 |
\row |
|
1212 |
\o \inlineimage qgradient-linear.png |
|
1213 |
\o \inlineimage qgradient-radial.png |
|
1214 |
\o \inlineimage qgradient-conical.png |
|
1215 |
\header |
|
1216 |
\o QLinearGradient |
|
1217 |
\o QRadialGradient |
|
1218 |
\o QConicalGradient |
|
1219 |
\endtable |
|
1220 |
||
1221 |
The colors in a gradient is defined using stop points of the |
|
1222 |
QGradientStop type, i.e. a position and a color. Use the |
|
1223 |
setColorAt() function to define a single stop |
|
1224 |
point. Alternatively, use the setStops() function to define |
|
1225 |
several stop points in one go. Note that the latter function \e |
|
1226 |
replaces the current set of stop points. |
|
1227 |
||
1228 |
It is the gradient's complete set of stop points (accessible |
|
1229 |
through the stops() function) that describes how the gradient area |
|
1230 |
should be filled. If no stop points have been specified, a |
|
1231 |
gradient of black at 0 to white at 1 is used. |
|
1232 |
||
1233 |
A diagonal linear gradient from black at (100, 100) to white at |
|
1234 |
(200, 200) could be specified like this: |
|
1235 |
||
1236 |
\snippet doc/src/snippets/brush/brush.cpp 0 |
|
1237 |
||
1238 |
A gradient can have an arbitrary number of stop points. The |
|
1239 |
following would create a radial gradient starting with |
|
1240 |
red in the center, blue and then green on the edges: |
|
1241 |
||
1242 |
\snippet doc/src/snippets/brush/brush.cpp 1 |
|
1243 |
||
1244 |
It is possible to repeat or reflect the gradient outside its area |
|
1245 |
by specifiying the \l {QGradient::Spread}{spread method} using the |
|
1246 |
setSpread() function. The default is to pad the outside area with |
|
1247 |
the color at the closest stop point. The currently set \l |
|
1248 |
{QGradient::Spread}{spread method} can be retrieved using the |
|
1249 |
spread() function. The QGradient::Spread enum defines three |
|
1250 |
different methods: |
|
1251 |
||
1252 |
\table |
|
1253 |
\row |
|
1254 |
\o \inlineimage qradialgradient-pad.png |
|
1255 |
\o \inlineimage qradialgradient-repeat.png |
|
1256 |
\o \inlineimage qradialgradient-reflect.png |
|
1257 |
\row |
|
1258 |
\o \l {QGradient::PadSpread}{PadSpread} |
|
1259 |
\o \l {QGradient::RepeatSpread}{RepeatSpread} |
|
1260 |
\o \l {QGradient::ReflectSpread}{ReflectSpread} |
|
1261 |
\endtable |
|
1262 |
||
1263 |
Note that the setSpread() function only has effect for linear and |
|
1264 |
radial gradients. The reason is that the conical gradient is |
|
1265 |
closed by definition, i.e. the \e conical gradient fills the |
|
1266 |
entire circle from 0 - 360 degrees, while the boundary of a radial |
|
1267 |
or a linear gradient can be specified through its radius or final |
|
1268 |
stop points, respectively. |
|
1269 |
||
1270 |
The gradient coordinates can be specified in logical coordinates, |
|
1271 |
relative to device coordinates, or relative to object bounding box coordinates. |
|
1272 |
The \l {QGradient::CoordinateMode}{coordinate mode} can be set using the |
|
1273 |
setCoordinateMode() function. The default is LogicalMode, where the |
|
1274 |
gradient coordinates are specified in the same way as the object |
|
1275 |
coordinates. To retrieve the currently set \l {QGradient::CoordinateMode} |
|
1276 |
{coordinate mode} use coordinateMode(). |
|
1277 |
||
1278 |
||
1279 |
\sa {demos/gradients}{The Gradients Demo}, QBrush |
|
1280 |
*/ |
|
1281 |
||
1282 |
/*! |
|
1283 |
\internal |
|
1284 |
*/ |
|
1285 |
QGradient::QGradient() |
|
1286 |
: m_type(NoGradient), dummy(0) |
|
1287 |
{ |
|
1288 |
} |
|
1289 |
||
1290 |
||
1291 |
/*! |
|
1292 |
\enum QGradient::Type |
|
1293 |
||
1294 |
Specifies the type of gradient. |
|
1295 |
||
1296 |
\value LinearGradient Interpolates colors between start and end points |
|
1297 |
(QLinearGradient). |
|
1298 |
||
1299 |
\value RadialGradient Interpolate colors between a focal point and end |
|
1300 |
points on a circle surrounding it (QRadialGradient). |
|
1301 |
||
1302 |
\value ConicalGradient Interpolate colors around a center point (QConicalGradient). |
|
1303 |
\value NoGradient No gradient is used. |
|
1304 |
||
1305 |
\sa type() |
|
1306 |
*/ |
|
1307 |
||
1308 |
/*! |
|
1309 |
\enum QGradient::Spread |
|
1310 |
||
1311 |
Specifies how the area outside the gradient area should be |
|
1312 |
filled. |
|
1313 |
||
1314 |
\value PadSpread The area is filled with the closest stop |
|
1315 |
color. This is the default. |
|
1316 |
||
1317 |
\value RepeatSpread The gradient is repeated outside the gradient |
|
1318 |
area. |
|
1319 |
||
1320 |
\value ReflectSpread The gradient is reflected outside the |
|
1321 |
gradient area. |
|
1322 |
||
1323 |
\sa spread(), setSpread() |
|
1324 |
*/ |
|
1325 |
||
1326 |
/*! |
|
1327 |
\fn void QGradient::setSpread(Spread method) |
|
1328 |
||
1329 |
Specifies the spread \a method that should be used for this |
|
1330 |
gradient. |
|
1331 |
||
1332 |
Note that this function only has effect for linear and radial |
|
1333 |
gradients. |
|
1334 |
||
1335 |
\sa spread() |
|
1336 |
*/ |
|
1337 |
||
1338 |
/*! |
|
1339 |
\fn QGradient::Spread QGradient::spread() const |
|
1340 |
||
1341 |
Returns the spread method use by this gradient. The default is |
|
1342 |
PadSpread. |
|
1343 |
||
1344 |
\sa setSpread() |
|
1345 |
*/ |
|
1346 |
||
1347 |
/*! |
|
1348 |
\fn QGradient::Type QGradient::type() const |
|
1349 |
||
1350 |
Returns the type of gradient. |
|
1351 |
*/ |
|
1352 |
||
1353 |
/*! |
|
1354 |
\fn void QGradient::setColorAt(qreal position, const QColor &color) |
|
1355 |
||
1356 |
Creates a stop point at the given \a position with the given \a |
|
1357 |
color. The given \a position must be in the range 0 to 1. |
|
1358 |
||
1359 |
\sa setStops(), stops() |
|
1360 |
*/ |
|
1361 |
||
1362 |
void QGradient::setColorAt(qreal pos, const QColor &color) |
|
1363 |
{ |
|
1364 |
if (pos > 1 || pos < 0) { |
|
1365 |
qWarning("QGradient::setColorAt: Color position must be specified in the range 0 to 1"); |
|
1366 |
return; |
|
1367 |
} |
|
1368 |
||
1369 |
int index = 0; |
|
1370 |
while (index < m_stops.size() && m_stops.at(index).first < pos) ++index; |
|
1371 |
||
1372 |
if (index < m_stops.size() && m_stops.at(index).first == pos) |
|
1373 |
m_stops[index].second = color; |
|
1374 |
else |
|
1375 |
m_stops.insert(index, QGradientStop(pos, color)); |
|
1376 |
} |
|
1377 |
||
1378 |
/*! |
|
1379 |
\fn void QGradient::setStops(const QGradientStops &stopPoints) |
|
1380 |
||
1381 |
Replaces the current set of stop points with the given \a |
|
1382 |
stopPoints. The positions of the points must be in the range 0 to |
|
1383 |
1, and must be sorted with the lowest point first. |
|
1384 |
||
1385 |
\sa setColorAt(), stops() |
|
1386 |
*/ |
|
1387 |
void QGradient::setStops(const QGradientStops &stops) |
|
1388 |
{ |
|
1389 |
m_stops.clear(); |
|
1390 |
for (int i=0; i<stops.size(); ++i) |
|
1391 |
setColorAt(stops.at(i).first, stops.at(i).second); |
|
1392 |
} |
|
1393 |
||
1394 |
||
1395 |
/*! |
|
1396 |
Returns the stop points for this gradient. |
|
1397 |
||
1398 |
If no stop points have been specified, a gradient of black at 0 to white |
|
1399 |
at 1 is used. |
|
1400 |
||
1401 |
\sa setStops(), setColorAt() |
|
1402 |
*/ |
|
1403 |
QGradientStops QGradient::stops() const |
|
1404 |
{ |
|
1405 |
if (m_stops.isEmpty()) { |
|
1406 |
QGradientStops tmp; |
|
1407 |
tmp << QGradientStop(0, Qt::black) << QGradientStop(1, Qt::white); |
|
1408 |
return tmp; |
|
1409 |
} |
|
1410 |
return m_stops; |
|
1411 |
} |
|
1412 |
||
1413 |
#define Q_DUMMY_ACCESSOR union {void *p; uint i;}; p = dummy; |
|
1414 |
||
1415 |
/*! |
|
1416 |
\enum QGradient::CoordinateMode |
|
1417 |
\since 4.4 |
|
1418 |
||
1419 |
This enum specifies how gradient coordinates map to the paint |
|
1420 |
device on which the gradient is used. |
|
1421 |
||
1422 |
\value LogicalMode This is the default mode. The gradient coordinates |
|
1423 |
are specified logical space just like the object coordinates. |
|
1424 |
\value StretchToDeviceMode In this mode the gradient coordinates |
|
1425 |
are relative to the bounding rectangle of the paint device, |
|
1426 |
with (0,0) in the top left corner, and (1,1) in the bottom right |
|
1427 |
corner of the paint device. |
|
1428 |
\value ObjectBoundingMode In this mode the gradient coordinates are |
|
1429 |
relative to the bounding rectangle of the object being drawn, with |
|
1430 |
(0,0) in the top left corner, and (1,1) in the bottom right corner |
|
1431 |
of the object's bounding rectangle. |
|
1432 |
*/ |
|
1433 |
||
1434 |
/*! |
|
1435 |
\since 4.4 |
|
1436 |
||
1437 |
Returns the coordinate mode of this gradient. The default mode is |
|
1438 |
LogicalMode. |
|
1439 |
*/ |
|
1440 |
QGradient::CoordinateMode QGradient::coordinateMode() const |
|
1441 |
{ |
|
1442 |
Q_DUMMY_ACCESSOR |
|
1443 |
return CoordinateMode(i & 0x03); |
|
1444 |
} |
|
1445 |
||
1446 |
/*! |
|
1447 |
\since 4.4 |
|
1448 |
||
1449 |
Sets the coordinate mode of this gradient to \a mode. The default |
|
1450 |
mode is LogicalMode. |
|
1451 |
*/ |
|
1452 |
void QGradient::setCoordinateMode(CoordinateMode mode) |
|
1453 |
{ |
|
1454 |
Q_DUMMY_ACCESSOR |
|
1455 |
i &= ~0x03; |
|
1456 |
i |= uint(mode); |
|
1457 |
dummy = p; |
|
1458 |
} |
|
1459 |
||
1460 |
/*! |
|
1461 |
\enum QGradient::InterpolationMode |
|
1462 |
\since 4.5 |
|
1463 |
\internal |
|
1464 |
||
1465 |
\value ComponentInterpolation The color components and the alpha component are |
|
1466 |
independently linearly interpolated. |
|
1467 |
\value ColorInterpolation The colors are linearly interpolated in |
|
1468 |
premultiplied color space. |
|
1469 |
*/ |
|
1470 |
||
1471 |
/*! |
|
1472 |
\since 4.5 |
|
1473 |
\internal |
|
1474 |
||
1475 |
Returns the interpolation mode of this gradient. The default mode is |
|
1476 |
ColorInterpolation. |
|
1477 |
*/ |
|
1478 |
QGradient::InterpolationMode QGradient::interpolationMode() const |
|
1479 |
{ |
|
1480 |
Q_DUMMY_ACCESSOR |
|
1481 |
return InterpolationMode((i >> 2) & 0x01); |
|
1482 |
} |
|
1483 |
||
1484 |
/*! |
|
1485 |
\since 4.5 |
|
1486 |
\internal |
|
1487 |
||
1488 |
Sets the interpolation mode of this gradient to \a mode. The default |
|
1489 |
mode is ColorInterpolation. |
|
1490 |
*/ |
|
1491 |
void QGradient::setInterpolationMode(InterpolationMode mode) |
|
1492 |
{ |
|
1493 |
Q_DUMMY_ACCESSOR |
|
1494 |
i &= ~(1 << 2); |
|
1495 |
i |= (uint(mode) << 2); |
|
1496 |
dummy = p; |
|
1497 |
} |
|
1498 |
||
1499 |
#undef Q_DUMMY_ACCESSOR |
|
1500 |
||
1501 |
/*! |
|
1502 |
\fn bool QGradient::operator!=(const QGradient &gradient) const |
|
1503 |
\since 4.2 |
|
1504 |
||
1505 |
Returns true if the gradient is the same as the other \a gradient |
|
1506 |
specified; otherwise returns false. |
|
1507 |
||
1508 |
\sa operator==() |
|
1509 |
*/ |
|
1510 |
||
1511 |
/*! |
|
1512 |
Returns true if the gradient is the same as the other \a gradient |
|
1513 |
specified; otherwise returns false. |
|
1514 |
||
1515 |
\sa operator!=() |
|
1516 |
*/ |
|
1517 |
bool QGradient::operator==(const QGradient &gradient) const |
|
1518 |
{ |
|
1519 |
if (gradient.m_type != m_type |
|
1520 |
|| gradient.m_spread != m_spread |
|
1521 |
|| gradient.dummy != dummy) return false; |
|
1522 |
||
1523 |
if (m_type == LinearGradient) { |
|
1524 |
if (m_data.linear.x1 != gradient.m_data.linear.x1 |
|
1525 |
|| m_data.linear.y1 != gradient.m_data.linear.y1 |
|
1526 |
|| m_data.linear.x2 != gradient.m_data.linear.x2 |
|
1527 |
|| m_data.linear.y2 != gradient.m_data.linear.y2) |
|
1528 |
return false; |
|
1529 |
} else if (m_type == RadialGradient) { |
|
1530 |
if (m_data.radial.cx != gradient.m_data.radial.cx |
|
1531 |
|| m_data.radial.cy != gradient.m_data.radial.cy |
|
1532 |
|| m_data.radial.fx != gradient.m_data.radial.fx |
|
1533 |
|| m_data.radial.fy != gradient.m_data.radial.fy |
|
1534 |
|| m_data.radial.radius != gradient.m_data.radial.radius) |
|
1535 |
return false; |
|
1536 |
} else { // m_type == ConicalGradient |
|
1537 |
if (m_data.conical.cx != gradient.m_data.conical.cx |
|
1538 |
|| m_data.conical.cy != gradient.m_data.conical.cy |
|
1539 |
|| m_data.conical.angle != gradient.m_data.conical.angle) |
|
1540 |
return false; |
|
1541 |
} |
|
1542 |
||
1543 |
return stops() == gradient.stops(); |
|
1544 |
} |
|
1545 |
||
1546 |
/*! |
|
1547 |
\internal |
|
1548 |
*/ |
|
1549 |
bool QGradient::operator==(const QGradient &gradient) |
|
1550 |
{ |
|
1551 |
return const_cast<const QGradient *>(this)->operator==(gradient); |
|
1552 |
} |
|
1553 |
||
1554 |
/*! |
|
1555 |
\class QLinearGradient |
|
1556 |
\ingroup painting |
|
1557 |
||
1558 |
\brief The QLinearGradient class is used in combination with QBrush to |
|
1559 |
specify a linear gradient brush. |
|
1560 |
||
1561 |
Linear gradients interpolate colors between start and end |
|
1562 |
points. Outside these points the gradient is either padded, |
|
1563 |
reflected or repeated depending on the currently set \l |
|
1564 |
{QGradient::Spread}{spread} method: |
|
1565 |
||
1566 |
\table |
|
1567 |
\row |
|
1568 |
\o \inlineimage qlineargradient-pad.png |
|
1569 |
\o \inlineimage qlineargradient-reflect.png |
|
1570 |
\o \inlineimage qlineargradient-repeat.png |
|
1571 |
\row |
|
1572 |
\o \l {QGradient::PadSpread}{PadSpread} (default) |
|
1573 |
\o \l {QGradient::ReflectSpread}{ReflectSpread} |
|
1574 |
\o \l {QGradient::RepeatSpread}{RepeatSpread} |
|
1575 |
\endtable |
|
1576 |
||
1577 |
The colors in a gradient is defined using stop points of the |
|
1578 |
QGradientStop type, i.e. a position and a color. Use the |
|
1579 |
QGradient::setColorAt() or the QGradient::setStops() function to |
|
1580 |
define the stop points. It is the gradient's complete set of stop |
|
1581 |
points that describes how the gradient area should be filled. If |
|
1582 |
no stop points have been specified, a gradient of black at 0 to |
|
1583 |
white at 1 is used. |
|
1584 |
||
1585 |
In addition to the functions inherited from QGradient, the |
|
1586 |
QLinearGradient class provides the finalStop() function which |
|
1587 |
returns the final stop point of the gradient, and the start() |
|
1588 |
function returning the start point of the gradient. |
|
1589 |
||
1590 |
\sa QRadialGradient, QConicalGradient, {demos/gradients}{The |
|
1591 |
Gradients Demo} |
|
1592 |
*/ |
|
1593 |
||
1594 |
||
1595 |
/*! |
|
1596 |
Constructs a default linear gradient with interpolation area |
|
1597 |
between (0, 0) and (1, 1). |
|
1598 |
||
1599 |
\sa QGradient::setColorAt(), setStart(), setFinalStop() |
|
1600 |
*/ |
|
1601 |
||
1602 |
QLinearGradient::QLinearGradient() |
|
1603 |
{ |
|
1604 |
m_type = LinearGradient; |
|
1605 |
m_spread = PadSpread; |
|
1606 |
m_data.linear.x1 = 0; |
|
1607 |
m_data.linear.y1 = 0; |
|
1608 |
m_data.linear.x2 = 1; |
|
1609 |
m_data.linear.y2 = 1; |
|
1610 |
} |
|
1611 |
||
1612 |
||
1613 |
/*! |
|
1614 |
Constructs a linear gradient with interpolation area between the |
|
1615 |
given \a start point and \a finalStop. |
|
1616 |
||
1617 |
\note The expected parameter values are in pixels. |
|
1618 |
||
1619 |
\sa QGradient::setColorAt(), QGradient::setStops() |
|
1620 |
*/ |
|
1621 |
QLinearGradient::QLinearGradient(const QPointF &start, const QPointF &finalStop) |
|
1622 |
{ |
|
1623 |
m_type = LinearGradient; |
|
1624 |
m_spread = PadSpread; |
|
1625 |
m_data.linear.x1 = start.x(); |
|
1626 |
m_data.linear.y1 = start.y(); |
|
1627 |
m_data.linear.x2 = finalStop.x(); |
|
1628 |
m_data.linear.y2 = finalStop.y(); |
|
1629 |
} |
|
1630 |
||
1631 |
/*! |
|
1632 |
\fn QLinearGradient::QLinearGradient(qreal x1, qreal y1, qreal x2, qreal y2) |
|
1633 |
||
1634 |
Constructs a linear gradient with interpolation area between (\a |
|
1635 |
x1, \a y1) and (\a x2, \a y2). |
|
1636 |
||
1637 |
\note The expected parameter values are in pixels. |
|
1638 |
||
1639 |
\sa QGradient::setColorAt(), QGradient::setStops() |
|
1640 |
*/ |
|
1641 |
QLinearGradient::QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop) |
|
1642 |
{ |
|
1643 |
m_type = LinearGradient; |
|
1644 |
m_spread = PadSpread; |
|
1645 |
m_data.linear.x1 = xStart; |
|
1646 |
m_data.linear.y1 = yStart; |
|
1647 |
m_data.linear.x2 = xFinalStop; |
|
1648 |
m_data.linear.y2 = yFinalStop; |
|
1649 |
} |
|
1650 |
||
1651 |
||
1652 |
/*! |
|
1653 |
Returns the start point of this linear gradient in logical coordinates. |
|
1654 |
||
1655 |
\sa QGradient::stops() |
|
1656 |
*/ |
|
1657 |
||
1658 |
QPointF QLinearGradient::start() const |
|
1659 |
{ |
|
1660 |
Q_ASSERT(m_type == LinearGradient); |
|
1661 |
return QPointF(m_data.linear.x1, m_data.linear.y1); |
|
1662 |
} |
|
1663 |
||
1664 |
/*! |
|
1665 |
\fn void QLinearGradient::setStart(qreal x, qreal y) |
|
1666 |
\overload |
|
1667 |
\since 4.2 |
|
1668 |
||
1669 |
Sets the start point of this linear gradient in logical |
|
1670 |
coordinates to \a x, \a y. |
|
1671 |
||
1672 |
\sa start() |
|
1673 |
*/ |
|
1674 |
||
1675 |
/*! |
|
1676 |
\since 4.2 |
|
1677 |
||
1678 |
Sets the start point of this linear gradient in logical |
|
1679 |
coordinates to \a start. |
|
1680 |
||
1681 |
\sa start() |
|
1682 |
*/ |
|
1683 |
||
1684 |
void QLinearGradient::setStart(const QPointF &start) |
|
1685 |
{ |
|
1686 |
Q_ASSERT(m_type == LinearGradient); |
|
1687 |
m_data.linear.x1 = start.x(); |
|
1688 |
m_data.linear.y1 = start.y(); |
|
1689 |
} |
|
1690 |
||
1691 |
||
1692 |
/*! |
|
1693 |
\fn void QLinearGradient::setFinalStop(qreal x, qreal y) |
|
1694 |
\overload |
|
1695 |
\since 4.2 |
|
1696 |
||
1697 |
Sets the final stop point of this linear gradient in logical |
|
1698 |
coordinates to \a x, \a y. |
|
1699 |
||
1700 |
\sa start() |
|
1701 |
*/ |
|
1702 |
||
1703 |
/*! |
|
1704 |
Returns the final stop point of this linear gradient in logical coordinates. |
|
1705 |
||
1706 |
\sa QGradient::stops() |
|
1707 |
*/ |
|
1708 |
||
1709 |
QPointF QLinearGradient::finalStop() const |
|
1710 |
{ |
|
1711 |
Q_ASSERT(m_type == LinearGradient); |
|
1712 |
return QPointF(m_data.linear.x2, m_data.linear.y2); |
|
1713 |
} |
|
1714 |
||
1715 |
||
1716 |
/*! |
|
1717 |
\since 4.2 |
|
1718 |
||
1719 |
Sets the final stop point of this linear gradient in logical |
|
1720 |
coordinates to \a stop. |
|
1721 |
||
1722 |
\sa finalStop() |
|
1723 |
*/ |
|
1724 |
||
1725 |
void QLinearGradient::setFinalStop(const QPointF &stop) |
|
1726 |
{ |
|
1727 |
Q_ASSERT(m_type == LinearGradient); |
|
1728 |
m_data.linear.x2 = stop.x(); |
|
1729 |
m_data.linear.y2 = stop.y(); |
|
1730 |
} |
|
1731 |
||
1732 |
||
1733 |
/*! |
|
1734 |
\class QRadialGradient |
|
1735 |
\ingroup painting |
|
1736 |
||
1737 |
\brief The QRadialGradient class is used in combination with QBrush to |
|
1738 |
specify a radial gradient brush. |
|
1739 |
||
1740 |
Radial gradients interpolate colors between a focal point and end |
|
1741 |
points on a circle surrounding it. Outside the end points the |
|
1742 |
gradient is either padded, reflected or repeated depending on the |
|
1743 |
currently set \l {QGradient::Spread}{spread} method: |
|
1744 |
||
1745 |
\table |
|
1746 |
\row |
|
1747 |
\o \inlineimage qradialgradient-pad.png |
|
1748 |
\o \inlineimage qradialgradient-reflect.png |
|
1749 |
\o \inlineimage qradialgradient-repeat.png |
|
1750 |
\row |
|
1751 |
\o \l {QGradient::PadSpread}{PadSpread} (default) |
|
1752 |
\o \l {QGradient::ReflectSpread}{ReflectSpread} |
|
1753 |
\o \l {QGradient::RepeatSpread}{RepeatSpread} |
|
1754 |
\endtable |
|
1755 |
||
1756 |
The colors in a gradient is defined using stop points of the |
|
1757 |
QGradientStop type, i.e. a position and a color. Use the |
|
1758 |
QGradient::setColorAt() or the QGradient::setStops() function to |
|
1759 |
define the stop points. It is the gradient's complete set of stop |
|
1760 |
points that describes how the gradient area should be filled. If |
|
1761 |
no stop points have been specified, a gradient of black at 0 to |
|
1762 |
white at 1 is used. |
|
1763 |
||
1764 |
In addition to the functions inherited from QGradient, the |
|
1765 |
QRadialGradient class provides the center(), focalPoint() and |
|
1766 |
radius() functions returning the gradient's center, focal point |
|
1767 |
and radius respectively. |
|
1768 |
||
1769 |
\sa QLinearGradient, QConicalGradient, {demos/gradients}{The |
|
1770 |
Gradients Demo} |
|
1771 |
*/ |
|
1772 |
||
1773 |
static QPointF qt_radial_gradient_adapt_focal_point(const QPointF ¢er, |
|
1774 |
qreal radius, |
|
1775 |
const QPointF &focalPoint) |
|
1776 |
{ |
|
1777 |
// We have a one pixel buffer zone to avoid numerical instability on the |
|
1778 |
// circle border |
|
1779 |
//### this is hacky because technically we should adjust based on current matrix |
|
1780 |
const qreal compensated_radius = radius - radius * 0.001; |
|
1781 |
QLineF line(center, focalPoint); |
|
1782 |
if (line.length() > (compensated_radius)) |
|
1783 |
line.setLength(compensated_radius); |
|
1784 |
return line.p2(); |
|
1785 |
} |
|
1786 |
||
1787 |
/*! |
|
1788 |
Constructs a radial gradient with the given \a center, \a |
|
1789 |
radius and \a focalPoint. |
|
1790 |
||
1791 |
\sa QGradient::setColorAt(), QGradient::setStops() |
|
1792 |
*/ |
|
1793 |
||
1794 |
QRadialGradient::QRadialGradient(const QPointF ¢er, qreal radius, const QPointF &focalPoint) |
|
1795 |
{ |
|
1796 |
m_type = RadialGradient; |
|
1797 |
m_spread = PadSpread; |
|
1798 |
m_data.radial.cx = center.x(); |
|
1799 |
m_data.radial.cy = center.y(); |
|
1800 |
m_data.radial.radius = radius; |
|
1801 |
||
1802 |
QPointF adapted_focal = qt_radial_gradient_adapt_focal_point(center, radius, focalPoint); |
|
1803 |
m_data.radial.fx = adapted_focal.x(); |
|
1804 |
m_data.radial.fy = adapted_focal.y(); |
|
1805 |
} |
|
1806 |
||
1807 |
/*! |
|
1808 |
Constructs a radial gradient with the given \a center, \a |
|
1809 |
radius and the focal point in the circle center. |
|
1810 |
||
1811 |
\sa QGradient::setColorAt(), QGradient::setStops() |
|
1812 |
*/ |
|
1813 |
QRadialGradient::QRadialGradient(const QPointF ¢er, qreal radius) |
|
1814 |
{ |
|
1815 |
m_type = RadialGradient; |
|
1816 |
m_spread = PadSpread; |
|
1817 |
m_data.radial.cx = center.x(); |
|
1818 |
m_data.radial.cy = center.y(); |
|
1819 |
m_data.radial.radius = radius; |
|
1820 |
m_data.radial.fx = center.x(); |
|
1821 |
m_data.radial.fy = center.y(); |
|
1822 |
} |
|
1823 |
||
1824 |
||
1825 |
/*! |
|
1826 |
Constructs a radial gradient with the given center (\a cx, \a cy), |
|
1827 |
\a radius and focal point (\a fx, \a fy). |
|
1828 |
||
1829 |
\sa QGradient::setColorAt(), QGradient::setStops() |
|
1830 |
*/ |
|
1831 |
||
1832 |
QRadialGradient::QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy) |
|
1833 |
{ |
|
1834 |
m_type = RadialGradient; |
|
1835 |
m_spread = PadSpread; |
|
1836 |
m_data.radial.cx = cx; |
|
1837 |
m_data.radial.cy = cy; |
|
1838 |
m_data.radial.radius = radius; |
|
1839 |
||
1840 |
QPointF adapted_focal = qt_radial_gradient_adapt_focal_point(QPointF(cx, cy), |
|
1841 |
radius, |
|
1842 |
QPointF(fx, fy)); |
|
1843 |
||
1844 |
m_data.radial.fx = adapted_focal.x(); |
|
1845 |
m_data.radial.fy = adapted_focal.y(); |
|
1846 |
} |
|
1847 |
||
1848 |
/*! |
|
1849 |
Constructs a radial gradient with the center at (\a cx, \a cy) and the |
|
1850 |
specified \a radius. The focal point lies at the center of the circle. |
|
1851 |
||
1852 |
\sa QGradient::setColorAt(), QGradient::setStops() |
|
1853 |
*/ |
|
1854 |
QRadialGradient::QRadialGradient(qreal cx, qreal cy, qreal radius) |
|
1855 |
{ |
|
1856 |
m_type = RadialGradient; |
|
1857 |
m_spread = PadSpread; |
|
1858 |
m_data.radial.cx = cx; |
|
1859 |
m_data.radial.cy = cy; |
|
1860 |
m_data.radial.radius = radius; |
|
1861 |
m_data.radial.fx = cx; |
|
1862 |
m_data.radial.fy = cy; |
|
1863 |
} |
|
1864 |
||
1865 |
||
1866 |
/*! |
|
1867 |
Constructs a radial gradient with the center and focal point at |
|
1868 |
(0, 0) with a radius of 1. |
|
1869 |
*/ |
|
1870 |
QRadialGradient::QRadialGradient() |
|
1871 |
{ |
|
1872 |
m_type = RadialGradient; |
|
1873 |
m_spread = PadSpread; |
|
1874 |
m_data.radial.cx = 0; |
|
1875 |
m_data.radial.cy = 0; |
|
1876 |
m_data.radial.radius = 1; |
|
1877 |
m_data.radial.fx = 0; |
|
1878 |
m_data.radial.fy = 0; |
|
1879 |
} |
|
1880 |
||
1881 |
||
1882 |
/*! |
|
1883 |
Returns the center of this radial gradient in logical coordinates. |
|
1884 |
||
1885 |
\sa QGradient::stops() |
|
1886 |
*/ |
|
1887 |
||
1888 |
QPointF QRadialGradient::center() const |
|
1889 |
{ |
|
1890 |
Q_ASSERT(m_type == RadialGradient); |
|
1891 |
return QPointF(m_data.radial.cx, m_data.radial.cy); |
|
1892 |
} |
|
1893 |
||
1894 |
/*! |
|
1895 |
\fn void QRadialGradient::setCenter(qreal x, qreal y) |
|
1896 |
\overload |
|
1897 |
\since 4.2 |
|
1898 |
||
1899 |
Sets the center of this radial gradient in logical coordinates |
|
1900 |
to (\a x, \a y). |
|
1901 |
||
1902 |
\sa center() |
|
1903 |
*/ |
|
1904 |
||
1905 |
/*! |
|
1906 |
\since 4.2 |
|
1907 |
||
1908 |
Sets the center of this radial gradient in logical coordinates |
|
1909 |
to \a center. |
|
1910 |
||
1911 |
\sa center() |
|
1912 |
*/ |
|
1913 |
||
1914 |
void QRadialGradient::setCenter(const QPointF ¢er) |
|
1915 |
{ |
|
1916 |
Q_ASSERT(m_type == RadialGradient); |
|
1917 |
m_data.radial.cx = center.x(); |
|
1918 |
m_data.radial.cy = center.y(); |
|
1919 |
} |
|
1920 |
||
1921 |
||
1922 |
/*! |
|
1923 |
Returns the radius of this radial gradient in logical coordinates. |
|
1924 |
||
1925 |
\sa QGradient::stops() |
|
1926 |
*/ |
|
1927 |
||
1928 |
qreal QRadialGradient::radius() const |
|
1929 |
{ |
|
1930 |
Q_ASSERT(m_type == RadialGradient); |
|
1931 |
return m_data.radial.radius; |
|
1932 |
} |
|
1933 |
||
1934 |
||
1935 |
/*! |
|
1936 |
\since 4.2 |
|
1937 |
||
1938 |
Sets the radius of this radial gradient in logical coordinates |
|
1939 |
to \a radius |
|
1940 |
*/ |
|
1941 |
void QRadialGradient::setRadius(qreal radius) |
|
1942 |
{ |
|
1943 |
Q_ASSERT(m_type == RadialGradient); |
|
1944 |
m_data.radial.radius = radius; |
|
1945 |
} |
|
1946 |
||
1947 |
||
1948 |
/*! |
|
1949 |
Returns the focal point of this radial gradient in logical |
|
1950 |
coordinates. |
|
1951 |
||
1952 |
\sa QGradient::stops() |
|
1953 |
*/ |
|
1954 |
||
1955 |
QPointF QRadialGradient::focalPoint() const |
|
1956 |
{ |
|
1957 |
Q_ASSERT(m_type == RadialGradient); |
|
1958 |
return QPointF(m_data.radial.fx, m_data.radial.fy); |
|
1959 |
} |
|
1960 |
||
1961 |
/*! |
|
1962 |
\fn void QRadialGradient::setFocalPoint(qreal x, qreal y) |
|
1963 |
\overload |
|
1964 |
\since 4.2 |
|
1965 |
||
1966 |
Sets the focal point of this radial gradient in logical |
|
1967 |
coordinates to (\a x, \a y). |
|
1968 |
||
1969 |
\sa focalPoint() |
|
1970 |
*/ |
|
1971 |
||
1972 |
/*! |
|
1973 |
\since 4.2 |
|
1974 |
||
1975 |
Sets the focal point of this radial gradient in logical |
|
1976 |
coordinates to \a focalPoint. |
|
1977 |
||
1978 |
\sa focalPoint() |
|
1979 |
*/ |
|
1980 |
||
1981 |
void QRadialGradient::setFocalPoint(const QPointF &focalPoint) |
|
1982 |
{ |
|
1983 |
Q_ASSERT(m_type == RadialGradient); |
|
1984 |
m_data.radial.fx = focalPoint.x(); |
|
1985 |
m_data.radial.fy = focalPoint.y(); |
|
1986 |
} |
|
1987 |
||
1988 |
||
1989 |
||
1990 |
/*! |
|
1991 |
\class QConicalGradient |
|
1992 |
\ingroup painting |
|
1993 |
||
1994 |
\brief The QConicalGradient class is used in combination with QBrush to |
|
1995 |
specify a conical gradient brush. |
|
1996 |
||
1997 |
Conical gradients interpolate interpolate colors counter-clockwise |
|
1998 |
around a center point. |
|
1999 |
||
2000 |
\image qconicalgradient.png |
|
2001 |
||
2002 |
The colors in a gradient is defined using stop points of the |
|
2003 |
QGradientStop type, i.e. a position and a color. Use the |
|
2004 |
QGradient::setColorAt() or the QGradient::setStops() function to |
|
2005 |
define the stop points. It is the gradient's complete set of stop |
|
2006 |
points that describes how the gradient area should be filled. If |
|
2007 |
no stop points have been specified, a gradient of black at 0 to |
|
2008 |
white at 1 is used. |
|
2009 |
||
2010 |
In addition to the functions inherited from QGradient, the |
|
2011 |
QConicalGradient class provides the angle() and center() functions |
|
2012 |
returning the start angle and center of the gradient. |
|
2013 |
||
2014 |
Note that the setSpread() function has no effect for conical |
|
2015 |
gradients. The reason is that the conical gradient is closed by |
|
2016 |
definition, i.e. the conical gradient fills the entire circle from |
|
2017 |
0 - 360 degrees, while the boundary of a radial or a linear |
|
2018 |
gradient can be specified through its radius or final stop points, |
|
2019 |
respectively. |
|
2020 |
||
2021 |
\sa QLinearGradient, QRadialGradient, {demos/gradients}{The |
|
2022 |
Gradients Demo} |
|
2023 |
*/ |
|
2024 |
||
2025 |
||
2026 |
/*! |
|
2027 |
Constructs a conical gradient with the given \a center, starting |
|
2028 |
the interpolation at the given \a angle. The \a angle must be |
|
2029 |
specified in degrees between 0 and 360. |
|
2030 |
||
2031 |
\sa QGradient::setColorAt(), QGradient::setStops() |
|
2032 |
*/ |
|
2033 |
||
2034 |
QConicalGradient::QConicalGradient(const QPointF ¢er, qreal angle) |
|
2035 |
{ |
|
2036 |
m_type = ConicalGradient; |
|
2037 |
m_spread = PadSpread; |
|
2038 |
m_data.conical.cx = center.x(); |
|
2039 |
m_data.conical.cy = center.y(); |
|
2040 |
m_data.conical.angle = angle; |
|
2041 |
} |
|
2042 |
||
2043 |
||
2044 |
/*! |
|
2045 |
Constructs a conical gradient with the given center (\a cx, \a |
|
2046 |
cy), starting the interpolation at the given \a angle. The angle |
|
2047 |
must be specified in degrees between 0 and 360. |
|
2048 |
||
2049 |
\sa QGradient::setColorAt(), QGradient::setStops() |
|
2050 |
*/ |
|
2051 |
||
2052 |
QConicalGradient::QConicalGradient(qreal cx, qreal cy, qreal angle) |
|
2053 |
{ |
|
2054 |
m_type = ConicalGradient; |
|
2055 |
m_spread = PadSpread; |
|
2056 |
m_data.conical.cx = cx; |
|
2057 |
m_data.conical.cy = cy; |
|
2058 |
m_data.conical.angle = angle; |
|
2059 |
} |
|
2060 |
||
2061 |
||
2062 |
/*! |
|
2063 |
Constructs a conical with center at (0, 0) starting the |
|
2064 |
interpolation at angle 0. |
|
2065 |
||
2066 |
\sa QGradient::setColorAt(), setCenter(), setAngle() |
|
2067 |
*/ |
|
2068 |
||
2069 |
QConicalGradient::QConicalGradient() |
|
2070 |
{ |
|
2071 |
m_type = ConicalGradient; |
|
2072 |
m_spread = PadSpread; |
|
2073 |
m_data.conical.cx = 0; |
|
2074 |
m_data.conical.cy = 0; |
|
2075 |
m_data.conical.angle = 0; |
|
2076 |
} |
|
2077 |
||
2078 |
||
2079 |
/*! |
|
2080 |
Returns the center of the conical gradient in logical |
|
2081 |
coordinates. |
|
2082 |
||
2083 |
\sa stops() |
|
2084 |
*/ |
|
2085 |
||
2086 |
QPointF QConicalGradient::center() const |
|
2087 |
{ |
|
2088 |
Q_ASSERT(m_type == ConicalGradient); |
|
2089 |
return QPointF(m_data.conical.cx, m_data.conical.cy); |
|
2090 |
} |
|
2091 |
||
2092 |
||
2093 |
/*! |
|
2094 |
\fn void QConicalGradient::setCenter(qreal x, qreal y) |
|
2095 |
||
2096 |
\overload |
|
2097 |
||
2098 |
Sets the center of this conical gradient in logical coordinates to |
|
2099 |
(\a x, \a y). |
|
2100 |
||
2101 |
\sa center() |
|
2102 |
*/ |
|
2103 |
||
2104 |
/*! |
|
2105 |
Sets the center of this conical gradient in logical coordinates to |
|
2106 |
\a center. |
|
2107 |
||
2108 |
\sa center() |
|
2109 |
*/ |
|
2110 |
||
2111 |
void QConicalGradient::setCenter(const QPointF ¢er) |
|
2112 |
{ |
|
2113 |
Q_ASSERT(m_type == ConicalGradient); |
|
2114 |
m_data.conical.cx = center.x(); |
|
2115 |
m_data.conical.cy = center.y(); |
|
2116 |
} |
|
2117 |
||
2118 |
/*! |
|
2119 |
Returns the start angle of the conical gradient in logical |
|
2120 |
coordinates. |
|
2121 |
||
2122 |
\sa stops() |
|
2123 |
*/ |
|
2124 |
||
2125 |
qreal QConicalGradient::angle() const |
|
2126 |
{ |
|
2127 |
Q_ASSERT(m_type == ConicalGradient); |
|
2128 |
return m_data.conical.angle; |
|
2129 |
} |
|
2130 |
||
2131 |
||
2132 |
/*! |
|
2133 |
\since 4.2 |
|
2134 |
||
2135 |
Sets \a angle to be the start angle for this conical gradient in |
|
2136 |
logical coordinates. |
|
2137 |
||
2138 |
\sa angle() |
|
2139 |
*/ |
|
2140 |
||
2141 |
void QConicalGradient::setAngle(qreal angle) |
|
2142 |
{ |
|
2143 |
Q_ASSERT(m_type == ConicalGradient); |
|
2144 |
m_data.conical.angle = angle; |
|
2145 |
} |
|
2146 |
||
2147 |
/*! |
|
2148 |
\typedef QGradientStop |
|
2149 |
\relates QGradient |
|
2150 |
||
2151 |
Typedef for QPair<\l qreal, QColor>. |
|
2152 |
*/ |
|
2153 |
||
2154 |
/*! |
|
2155 |
\typedef QGradientStops |
|
2156 |
\relates QGradient |
|
2157 |
||
2158 |
Typedef for QVector<QGradientStop>. |
|
2159 |
*/ |
|
2160 |
||
2161 |
/*! |
|
2162 |
\typedef QBrush::DataPtr |
|
2163 |
\internal |
|
2164 |
*/ |
|
2165 |
||
2166 |
/*! |
|
2167 |
\fn DataPtr &QBrush::data_ptr() |
|
2168 |
\internal |
|
2169 |
*/ |
|
2170 |
||
2171 |
||
2172 |
/*! |
|
2173 |
\fn bool QBrush::isDetached() const |
|
2174 |
\internal |
|
2175 |
*/ |
|
2176 |
||
2177 |
/*! |
|
2178 |
\fn QTransform QBrush::transform() const |
|
2179 |
\since 4.3 |
|
2180 |
||
2181 |
Returns the current transformation matrix for the brush. |
|
2182 |
||
2183 |
\sa setTransform() |
|
2184 |
*/ |
|
2185 |
||
2186 |
QT_END_NAMESPACE |