author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 14 May 2010 16:40:13 +0300 | |
changeset 22 | 79de32ba3296 |
parent 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 test suite 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 |
||
43 |
#include <qapplication.h> |
|
44 |
#include <qpixmap.h> |
|
45 |
#include <qpainter.h> |
|
46 |
#include <qbitmap.h> |
|
47 |
||
48 |
static QColor baseColor( int k, int intensity ) |
|
49 |
{ |
|
50 |
int r = ( k & 1 ) * intensity; |
|
51 |
int g = ( (k>>1) & 1 ) * intensity; |
|
52 |
int b = ( (k>>2) & 1 ) * intensity; |
|
53 |
return QColor( r, g, b ); |
|
54 |
} |
|
55 |
||
56 |
static QPixmap createDestPixmap() |
|
57 |
{ |
|
58 |
const int colorbands = 3; |
|
59 |
const int intensities = 4; |
|
60 |
QPixmap pm( 32, colorbands*intensities*4 ); |
|
61 |
QPainter painter; |
|
62 |
painter.begin( &pm ); |
|
63 |
for ( int i=0; i<colorbands; i++ ) { |
|
64 |
for ( int j=0; j<intensities; j++ ) { |
|
65 |
int intensity = 255 * (j+1) / intensities; // 25%, 50%, 75% and 100% |
|
66 |
for ( int k=0; k<8; k++ ) { |
|
67 |
QColor col = baseColor( k, intensity ); |
|
68 |
painter.setPen( QPen( col, 1 ) ); |
|
69 |
painter.setBrush( col ); |
|
70 |
painter.drawRect( k*4, j*4 + i*intensities*4, 4, 4 ); |
|
71 |
} |
|
72 |
} |
|
73 |
} |
|
74 |
painter.end(); |
|
75 |
return pm; |
|
76 |
} |
|
77 |
||
78 |
static QBitmap createDestBitmap() |
|
79 |
{ |
|
80 |
// create a bitmap that looks like: |
|
81 |
// (0 is color0 and 1 is color1) |
|
82 |
// 00001111 |
|
83 |
// 00001111 |
|
84 |
// 00001111 |
|
85 |
// 00001111 |
|
86 |
// 00001111 |
|
87 |
// 00001111 |
|
88 |
// 00001111 |
|
89 |
// 00001111 |
|
90 |
QBitmap bm( 8, 8 ); |
|
91 |
QPainter painter; |
|
92 |
painter.begin( &bm ); |
|
93 |
painter.setPen( QPen( Qt::color0, 4 ) ); |
|
94 |
painter.drawLine( 2, 0, 2, 8 ); |
|
95 |
painter.setPen( QPen( Qt::color1, 4 ) ); |
|
96 |
painter.drawLine( 6, 0, 6, 8 ); |
|
97 |
painter.end(); |
|
98 |
return bm; |
|
99 |
} |
|
100 |
||
101 |
static QBitmap createSrcBitmap( int size, int border ) |
|
102 |
{ |
|
103 |
// create the source bitmap that looks like |
|
104 |
// (for size=4 and border=2): |
|
105 |
// |
|
106 |
// |
|
107 |
// 1111 |
|
108 |
// 1111 |
|
109 |
// 0000 |
|
110 |
// 0000 |
|
111 |
// |
|
112 |
// |
|
113 |
// If \a border is 0, the bitmap does not have a mask, otherwise the inner |
|
114 |
// part is masked. |
|
115 |
// \a size specifies the size of the inner (i.e. masked) part. It should be |
|
116 |
// a multiple of 2. |
|
117 |
int size2 = size/2; |
|
118 |
int totalSize = 2 * ( size2 + border ); |
|
119 |
QBitmap bm( totalSize, totalSize ); |
|
120 |
QPainter painter; |
|
121 |
painter.begin( &bm ); |
|
122 |
painter.setPen( QPen( Qt::color0, 1 ) ); |
|
123 |
painter.setBrush( Qt::color0 ); |
|
124 |
painter.drawRect( border, size2+border, size, size2 ); |
|
125 |
painter.setPen( QPen( Qt::color1, 1 ) ); |
|
126 |
painter.setBrush( Qt::color1 ); |
|
127 |
painter.drawRect( border, border, size, size2 ); |
|
128 |
painter.end(); |
|
129 |
if ( border > 0 ) { |
|
130 |
QBitmap mask( totalSize, totalSize, TRUE ); |
|
131 |
QPainter painter; |
|
132 |
painter.begin( &mask ); |
|
133 |
painter.setPen( QPen( Qt::color1, 1 ) ); |
|
134 |
painter.setBrush( Qt::color1 ); |
|
135 |
painter.drawRect( border, border, size, size ); |
|
136 |
painter.end(); |
|
137 |
bm.setMask( mask ); |
|
138 |
} |
|
139 |
return bm; |
|
140 |
} |
|
141 |
||
142 |
||
143 |
int main( int argc, char **argv ) |
|
144 |
{ |
|
145 |
QApplication a( argc, argv ); |
|
146 |
||
147 |
// input for tst_QPainter::drawLine_rop_bitmap() |
|
148 |
{ |
|
149 |
QBitmap dst = createDestBitmap(); |
|
150 |
dst.save( "../../drawLine_rop_bitmap/dst.xbm", "XBM" ); |
|
151 |
} |
|
152 |
||
153 |
// input for tst_QPainter::drawPixmap_rop_bitmap() |
|
154 |
{ |
|
155 |
QBitmap dst = createDestBitmap(); |
|
156 |
QBitmap src1 = createSrcBitmap( 4, 2 ); |
|
157 |
QBitmap src2 = createSrcBitmap( 4, 0 ); |
|
158 |
dst.save( "../../drawPixmap_rop_bitmap/dst.xbm", "XBM" ); |
|
159 |
src1.save( "../../drawPixmap_rop_bitmap/src1.xbm", "XBM" ); |
|
160 |
src1.mask()->save( "../../drawPixmap_rop_bitmap/src1-mask.xbm", "XBM" ); |
|
161 |
src2.save( "../../drawPixmap_rop_bitmap/src2.xbm", "XBM" ); |
|
162 |
} |
|
163 |
||
164 |
// input for tst_QPainter::drawPixmap_rop() |
|
165 |
{ |
|
166 |
QPixmap dst1 = createDestPixmap(); |
|
167 |
QPixmap dst2 = createDestPixmap(); |
|
168 |
dst2.resize( 32, 32 ); |
|
169 |
QBitmap src1 = createSrcBitmap( 32, 0 ); |
|
170 |
||
171 |
QBitmap src_tmp = createSrcBitmap( 32, 0 ).xForm( QWMatrix( 1, 0, 0, -1, 0, 0 ) ); |
|
172 |
src_tmp.resize( 32, 48 ); |
|
173 |
QBitmap src2 = src_tmp.xForm( QWMatrix( 1, 0, 0, -1, 0, 0 ) ); |
|
174 |
QBitmap mask( 32, 48, TRUE ); |
|
175 |
{ |
|
176 |
QPainter painter; |
|
177 |
painter.begin( &mask ); |
|
178 |
painter.setPen( QPen( Qt::color1, 1 ) ); |
|
179 |
painter.setBrush( Qt::color1 ); |
|
180 |
painter.drawRect( 0, 16, 32, 32 ); |
|
181 |
painter.end(); |
|
182 |
} |
|
183 |
src2.setMask( mask ); |
|
184 |
||
185 |
QBitmap src3 = createSrcBitmap( 32, 0 ).xForm( QWMatrix( 1, 0, 0, -1, 0, 0 ) ); |
|
186 |
||
187 |
dst1.save( "../../drawPixmap_rop/dst1.png", "PNG" ); |
|
188 |
dst2.save( "../../drawPixmap_rop/dst2.png", "PNG" ); |
|
189 |
src1.save( "../../drawPixmap_rop/src1.xbm", "XBM" ); |
|
190 |
src2.save( "../../drawPixmap_rop/src2.xbm", "XBM" ); |
|
191 |
src2.mask()->save( "../../drawPixmap_rop/src2-mask.xbm", "XBM" ); |
|
192 |
src3.save( "../../drawPixmap_rop/src3.xbm", "XBM" ); |
|
193 |
} |
|
194 |
} |