0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
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 |
#include "paintcommands.h"
|
|
42 |
|
|
43 |
#include <qdir.h>
|
|
44 |
#include <qfile.h>
|
|
45 |
#include <qfileinfo.h>
|
|
46 |
#include <qpainter.h>
|
|
47 |
#include <qbitmap.h>
|
|
48 |
#include <qtextstream.h>
|
|
49 |
#include <qtextlayout.h>
|
|
50 |
#include <qdebug.h>
|
|
51 |
|
|
52 |
#ifdef QT3_SUPPORT
|
|
53 |
#include <q3painter.h>
|
|
54 |
#endif
|
|
55 |
|
|
56 |
#ifndef QT_NO_OPENGL
|
|
57 |
#include <qglpixelbuffer.h>
|
|
58 |
#endif
|
|
59 |
|
|
60 |
/*********************************************************************************
|
|
61 |
** everything to populate static tables
|
|
62 |
**********************************************************************************/
|
|
63 |
const char *PaintCommands::brushStyleTable[] = {
|
|
64 |
"NoBrush",
|
|
65 |
"SolidPattern",
|
|
66 |
"Dense1Pattern",
|
|
67 |
"Dense2Pattern",
|
|
68 |
"Dense3Pattern",
|
|
69 |
"Dense4Pattern",
|
|
70 |
"Dense5Pattern",
|
|
71 |
"Dense6Pattern",
|
|
72 |
"Dense7Pattern",
|
|
73 |
"HorPattern",
|
|
74 |
"VerPattern",
|
|
75 |
"CrossPattern",
|
|
76 |
"BDiagPattern",
|
|
77 |
"FDiagPattern",
|
|
78 |
"DiagCrossPattern",
|
|
79 |
"LinearGradientPattern"
|
|
80 |
};
|
|
81 |
|
|
82 |
const char *PaintCommands::penStyleTable[] = {
|
|
83 |
"NoPen",
|
|
84 |
"SolidLine",
|
|
85 |
"DashLine",
|
|
86 |
"DotLine",
|
|
87 |
"DashDotLine",
|
|
88 |
"DashDotDotLine"
|
|
89 |
};
|
|
90 |
|
|
91 |
const char *PaintCommands::fontWeightTable[] = {
|
|
92 |
"Light",
|
|
93 |
"Normal",
|
|
94 |
"DemiBold",
|
|
95 |
"Bold",
|
|
96 |
"Black"
|
|
97 |
};
|
|
98 |
|
|
99 |
const char *PaintCommands::clipOperationTable[] = {
|
|
100 |
"NoClip",
|
|
101 |
"ReplaceClip",
|
|
102 |
"IntersectClip",
|
|
103 |
"UniteClip"
|
|
104 |
};
|
|
105 |
|
|
106 |
const char *PaintCommands::spreadMethodTable[] = {
|
|
107 |
"PadSpread",
|
|
108 |
"ReflectSpread",
|
|
109 |
"RepeatSpread"
|
|
110 |
};
|
|
111 |
|
|
112 |
const char *PaintCommands::coordinateMethodTable[] = {
|
|
113 |
"LogicalMode",
|
|
114 |
"StretchToDeviceMode",
|
|
115 |
"ObjectBoundingMode"
|
|
116 |
};
|
|
117 |
|
|
118 |
const char *PaintCommands::sizeModeTable[] = {
|
|
119 |
"AbsoluteSize",
|
|
120 |
"RelativeSize"
|
|
121 |
};
|
|
122 |
|
|
123 |
const char *PaintCommands::compositionModeTable[] = {
|
|
124 |
"SourceOver",
|
|
125 |
"DestinationOver",
|
|
126 |
"Clear",
|
|
127 |
"Source",
|
|
128 |
"Destination",
|
|
129 |
"SourceIn",
|
|
130 |
"DestinationIn",
|
|
131 |
"SourceOut",
|
|
132 |
"DestinationOut",
|
|
133 |
"SourceAtop",
|
|
134 |
"DestinationAtop",
|
|
135 |
"Xor",
|
|
136 |
"Plus",
|
|
137 |
"Multiply",
|
|
138 |
"Screen",
|
|
139 |
"Overlay",
|
|
140 |
"Darken",
|
|
141 |
"Lighten",
|
|
142 |
"ColorDodge",
|
|
143 |
"ColorBurn",
|
|
144 |
"HardLight",
|
|
145 |
"SoftLight",
|
|
146 |
"Difference",
|
|
147 |
"Exclusion",
|
|
148 |
"SourceOrDestination",
|
|
149 |
"SourceAndDestination",
|
|
150 |
"SourceXorDestination",
|
|
151 |
"NotSourceAndNotDestination",
|
|
152 |
"NotSourceOrNotDestination",
|
|
153 |
"NotSourceXorDestination",
|
|
154 |
"NotSource",
|
|
155 |
"NotSourceAndDestination",
|
|
156 |
"SourceAndNotDestination"
|
|
157 |
};
|
|
158 |
|
|
159 |
const char *PaintCommands::imageFormatTable[] = {
|
|
160 |
"Invalid",
|
|
161 |
"Mono",
|
|
162 |
"MonoLSB",
|
|
163 |
"Indexed8",
|
|
164 |
"RGB32",
|
|
165 |
"ARGB32",
|
|
166 |
"ARGB32_Premultiplied",
|
|
167 |
"Format_RGB16",
|
|
168 |
"Format_ARGB8565_Premultiplied",
|
|
169 |
"Format_RGB666",
|
|
170 |
"Format_ARGB6666_Premultiplied",
|
|
171 |
"Format_RGB555",
|
|
172 |
"Format_ARGB8555_Premultiplied",
|
|
173 |
"Format_RGB888",
|
|
174 |
"Format_RGB444",
|
|
175 |
"Format_ARGB4444_Premultiplied"
|
|
176 |
};
|
|
177 |
|
|
178 |
int PaintCommands::translateEnum(const char *table[], const QString &pattern, int limit)
|
|
179 |
{
|
|
180 |
for (int i=0; i<limit; ++i)
|
|
181 |
if (pattern.toLower() == QString(QLatin1String(table[i])).toLower())
|
|
182 |
return i;
|
|
183 |
return -1;
|
|
184 |
}
|
|
185 |
|
|
186 |
QList<PaintCommands::PaintCommandInfos> PaintCommands::s_commandInfoTable = QList<PaintCommands::PaintCommandInfos>();
|
|
187 |
QList<QPair<QString,QStringList> > PaintCommands::s_enumsTable = QList<QPair<QString,QStringList> >();
|
|
188 |
|
|
189 |
#define DECL_PAINTCOMMAND(identifier, method, regexp, syntax, sample) \
|
|
190 |
s_commandInfoTable << PaintCommandInfos(QLatin1String(identifier), &PaintCommands::method, QRegExp(regexp), \
|
|
191 |
QLatin1String(syntax), QLatin1String(sample) );
|
|
192 |
|
|
193 |
#define DECL_PAINTCOMMANDSECTION(title) \
|
|
194 |
s_commandInfoTable << PaintCommandInfos(QLatin1String(title));
|
|
195 |
|
|
196 |
#define ADD_ENUMLIST(listCaption, cStrArray) { \
|
|
197 |
QStringList list; \
|
|
198 |
for (int i=0; i<int(sizeof(cStrArray)/sizeof(char*)); i++) \
|
|
199 |
list << cStrArray[i]; \
|
|
200 |
s_enumsTable << qMakePair(QString(listCaption), list); \
|
|
201 |
}
|
|
202 |
|
|
203 |
void PaintCommands::staticInit()
|
|
204 |
{
|
|
205 |
// check if already done
|
|
206 |
if (!s_commandInfoTable.isEmpty()) return;
|
|
207 |
|
|
208 |
// populate the command list
|
|
209 |
DECL_PAINTCOMMANDSECTION("misc");
|
|
210 |
DECL_PAINTCOMMAND("comment", command_comment,
|
|
211 |
"^\\s*#",
|
|
212 |
"# this is some comments",
|
|
213 |
"# place your comments here");
|
|
214 |
DECL_PAINTCOMMAND("import", command_import,
|
|
215 |
"^import\\s+\"(.*)\"$",
|
|
216 |
"import <qrcFilename>",
|
|
217 |
"import \"myfile.qrc\"");
|
|
218 |
DECL_PAINTCOMMAND("begin_block", command_begin_block,
|
|
219 |
"^begin_block\\s+(\\w*)$",
|
|
220 |
"begin_block <blockName>",
|
|
221 |
"begin_block blockName");
|
|
222 |
DECL_PAINTCOMMAND("end_block", command_end_block,
|
|
223 |
"^end_block$",
|
|
224 |
"end_block",
|
|
225 |
"end_block");
|
|
226 |
DECL_PAINTCOMMAND("repeat_block", command_repeat_block,
|
|
227 |
"^repeat_block\\s+(\\w*)$",
|
|
228 |
"repeat_block <blockName>",
|
|
229 |
"repeat_block blockName");
|
|
230 |
DECL_PAINTCOMMAND("textlayout_draw", command_textlayout_draw,
|
|
231 |
"^textlayout_draw\\s+\"(.*)\"\\s+([0-9.]*)$",
|
|
232 |
"textlayout_draw <text> <width>",
|
|
233 |
"textlayout_draw \"your text\" 1.0");
|
|
234 |
DECL_PAINTCOMMAND("abort", command_abort,
|
|
235 |
"^abort$",
|
|
236 |
"abort",
|
|
237 |
"abort");
|
|
238 |
DECL_PAINTCOMMAND("noop", command_noop,
|
|
239 |
"^$",
|
|
240 |
"-",
|
|
241 |
"\n");
|
|
242 |
|
|
243 |
DECL_PAINTCOMMANDSECTION("setters");
|
|
244 |
DECL_PAINTCOMMAND("setBackgroundMode", command_setBgMode,
|
|
245 |
"^(setBackgroundMode|setBgMode)\\s+(\\w*)$",
|
|
246 |
"setBackgroundMode <OpaqueMode|TransparentMode>",
|
|
247 |
"setBackgroundMode TransparentMode");
|
|
248 |
DECL_PAINTCOMMAND("setBackground", command_setBackground,
|
|
249 |
"^setBackground\\s+#?(\\w*)\\s*(\\w*)?$",
|
|
250 |
"setBackground <color> [brush style enum]",
|
|
251 |
"setBackground black SolidPattern");
|
|
252 |
DECL_PAINTCOMMAND("setOpacity", command_setOpacity,
|
|
253 |
"^setOpacity\\s+(-?\\d*\\.?\\d*)$",
|
|
254 |
"setOpacity <opacity>\n - opacity is in [0,1]",
|
|
255 |
"setOpacity 1.0");
|
|
256 |
DECL_PAINTCOMMAND("path_setFillRule", command_path_setFillRule,
|
|
257 |
"^path_setFillRule\\s+(\\w*)\\s+(\\w*)$",
|
|
258 |
"path_setFillRule <pathName> [Winding|OddEven]",
|
|
259 |
"path_setFillRule pathName Winding");
|
|
260 |
DECL_PAINTCOMMAND("setBrush", command_setBrush,
|
|
261 |
"^setBrush\\s+(#?[\\w.:\\/]*)\\s*(\\w*)?$",
|
|
262 |
"setBrush <pixmapFileName>\nsetBrush noBrush\nsetBrush <color> <brush style enum>",
|
|
263 |
"setBrush white SolidPattern");
|
|
264 |
DECL_PAINTCOMMAND("setBrushOrigin", command_setBrushOrigin,
|
|
265 |
"^setBrushOrigin\\s*(-?\\w*)\\s+(-?\\w*)$",
|
|
266 |
"setBrushOrigin <dx> <dy>",
|
|
267 |
"setBrushOrigin 0 0");
|
|
268 |
DECL_PAINTCOMMAND("brushTranslate", command_brushTranslate,
|
|
269 |
"^brushTranslate\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
|
|
270 |
"brushTranslate <tx> <ty>",
|
|
271 |
"brushTranslate 0.0 0.0");
|
|
272 |
DECL_PAINTCOMMAND("brushScale", command_brushScale,
|
|
273 |
"^brushScale\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
|
|
274 |
"brushScale <kx> <ky>",
|
|
275 |
"brushScale 0.0 0.0");
|
|
276 |
DECL_PAINTCOMMAND("brushRotate", command_brushRotate,
|
|
277 |
"^brushRotate\\s+(-?[\\w.]*)$",
|
|
278 |
"brushRotate <angle>\n - angle in degrees",
|
|
279 |
"brushRotate 0.0");
|
|
280 |
DECL_PAINTCOMMAND("brushShear", command_brushShear,
|
|
281 |
"^brushShear\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
|
|
282 |
"brushShear <sx> <sy>",
|
|
283 |
"brushShear 0.0 0.0");
|
|
284 |
DECL_PAINTCOMMAND("setCompositionMode", command_setCompositionMode,
|
|
285 |
"^setCompositionMode\\s+([\\w_0-9]*)$",
|
|
286 |
"setCompositionMode <composition mode enum>",
|
|
287 |
"setCompositionMode SourceOver");
|
|
288 |
DECL_PAINTCOMMAND("setFont", command_setFont,
|
|
289 |
"^setFont\\s+\"([\\w\\s]*)\"\\s*(\\w*)\\s*(\\w*)\\s*(\\w*)$",
|
|
290 |
"setFont <fontFace> [size] [font weight|font weight enum] [italic]\n - font weight is an integer between 0 and 99",
|
|
291 |
"setFont \"times\" normal");
|
|
292 |
DECL_PAINTCOMMAND("setPen", command_setPen,
|
|
293 |
"^setPen\\s+#?(\\w*)$",
|
|
294 |
"setPen <color>\nsetPen <pen style enum>\nsetPen brush",
|
|
295 |
"setPen black");
|
|
296 |
DECL_PAINTCOMMAND("setPen", command_setPen2,
|
|
297 |
"^setPen\\s+(#?\\w*)\\s+([\\w.]+)\\s*(\\w*)\\s*(\\w*)\\s*(\\w*)$",
|
|
298 |
"setPen brush|<color> [width] [pen style enum] [FlatCap|SquareCap|RoundCap] [MiterJoin|BevelJoin|RoundJoin]",
|
|
299 |
"setPen black 1 FlatCap MiterJoin");
|
|
300 |
DECL_PAINTCOMMAND("pen_setDashOffset", command_pen_setDashOffset,
|
|
301 |
"^pen_setDashOffset\\s+(-?[\\w.]+)$",
|
|
302 |
"pen_setDashOffset <offset>\n",
|
|
303 |
"pen_setDashOffset 1.0");
|
|
304 |
DECL_PAINTCOMMAND("pen_setDashPattern", command_pen_setDashPattern,
|
|
305 |
"^pen_setDashPattern\\s+\\[([\\w\\s.]*)\\]$",
|
|
306 |
"pen_setDashPattern <[ <dash_1> <space_1> ... <dash_n> <space_n> ]>",
|
|
307 |
"pen_setDashPattern [ 2 1 4 1 3 3 ]");
|
|
308 |
DECL_PAINTCOMMAND("pen_setCosmetic", command_pen_setCosmetic,
|
|
309 |
"^pen_setCosmetic\\s+(\\w*)$",
|
|
310 |
"pen_setCosmetic <true|false>",
|
|
311 |
"pen_setCosmetic true");
|
|
312 |
DECL_PAINTCOMMAND("setRenderHint", command_setRenderHint,
|
|
313 |
"^setRenderHint\\s+([\\w_0-9]*)\\s*(\\w*)$",
|
|
314 |
"setRenderHint <Antialiasing|SmoothPixmapTransform> <true|false>",
|
|
315 |
"setRenderHint Antialiasing true");
|
|
316 |
DECL_PAINTCOMMAND("clearRenderHint", command_clearRenderHint,
|
|
317 |
"^clearRenderHint$",
|
|
318 |
"clearRenderHint",
|
|
319 |
"clearRenderHint");
|
|
320 |
|
|
321 |
DECL_PAINTCOMMANDSECTION("gradients");
|
|
322 |
DECL_PAINTCOMMAND("gradient_appendStop", command_gradient_appendStop,
|
|
323 |
"^gradient_appendStop\\s+([\\w.]*)\\s+#?(\\w*)$",
|
|
324 |
"gradient_appendStop <pos> <color>",
|
|
325 |
"gradient_appendStop 1.0 red");
|
|
326 |
DECL_PAINTCOMMAND("gradient_clearStops", command_gradient_clearStops,
|
|
327 |
"^gradient_clearStops$",
|
|
328 |
"gradient_clearStops",
|
|
329 |
"gradient_clearStops");
|
|
330 |
DECL_PAINTCOMMAND("gradient_setConical", command_gradient_setConical,
|
|
331 |
"^gradient_setConical\\s+([\\w.]*)\\s+([\\w.]*)\\s+([\\w.]*)$",
|
|
332 |
"gradient_setConical <cx> <cy> <angle>\n - angle in degrees",
|
|
333 |
"gradient_setConical 5.0 5.0 45.0");
|
|
334 |
DECL_PAINTCOMMAND("gradient_setLinear", command_gradient_setLinear,
|
|
335 |
"^gradient_setLinear\\s+([\\w.]*)\\s+([\\w.]*)\\s+([\\w.]*)\\s+([\\w.]*)$",
|
|
336 |
"gradient_setLinear <x1> <y1> <x2> <y2>",
|
|
337 |
"gradient_setLinear 1.0 1.0 2.0 2.0");
|
|
338 |
DECL_PAINTCOMMAND("gradient_setRadial", command_gradient_setRadial,
|
|
339 |
"^gradient_setRadial\\s+([\\w.]*)\\s+([\\w.]*)\\s+([\\w.]*)\\s?([\\w.]*)\\s?([\\w.]*)$",
|
|
340 |
"gradient_setRadial <cx> <cy> <rad> <fx> <fy>\n - C is the center\n - rad is the angle in degrees\n - F is the focal point",
|
|
341 |
"gradient_setRadial 1.0 1.0 45.0 2.0 2.0");
|
|
342 |
DECL_PAINTCOMMAND("gradient_setLinearPen", command_gradient_setLinearPen,
|
|
343 |
"^gradient_setLinearPen\\s+([\\w.]*)\\s+([\\w.]*)\\s+([\\w.]*)\\s+([\\w.]*)$",
|
|
344 |
"gradient_setLinearPen <x1> <y1> <x2> <y2>",
|
|
345 |
"gradient_setLinearPen 1.0 1.0 2.0 2.0");
|
|
346 |
DECL_PAINTCOMMAND("gradient_setSpread", command_gradient_setSpread,
|
|
347 |
"^gradient_setSpread\\s+(\\w*)$",
|
|
348 |
"gradient_setSpread <spread method enum>",
|
|
349 |
"gradient_setSpread PadSpread");
|
|
350 |
DECL_PAINTCOMMAND("gradient_setCoordinateMode", command_gradient_setCoordinateMode,
|
|
351 |
"^gradient_setCoordinateMode\\s+(\\w*)$",
|
|
352 |
"gradient_setCoordinateMode <coordinate method enum>",
|
|
353 |
"gradient_setCoordinateMode ObjectBoundingMode");
|
|
354 |
#ifdef QT3_SUPPORT
|
|
355 |
DECL_PAINTCOMMANDSECTION("qt3 drawing ops");
|
|
356 |
DECL_PAINTCOMMAND("qt3_drawArc", command_qt3_drawArc,
|
|
357 |
"^qt3_drawArc\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)$",
|
|
358 |
"qt3_drawArc <x> <y> <w> <h> <angleStart> <angleArc>\n - angles are expressed in 1/16th of degree",
|
|
359 |
"qt3_drawArc 10 10 20 20 0 5760");
|
|
360 |
DECL_PAINTCOMMAND("qt3_drawChord", command_qt3_drawChord,
|
|
361 |
"^qt3_drawChord\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)$",
|
|
362 |
"qt3_drawChord <x> <y> <w> <h> <angleStart> <angleArc>\n - angles are expressed in 1/16th of degree",
|
|
363 |
"qt3_drawChord 10 10 20 20 0 5760");
|
|
364 |
DECL_PAINTCOMMAND("qt3_drawEllipse", command_qt3_drawEllipse,
|
|
365 |
"^qt3_drawEllipse\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)$",
|
|
366 |
"qt3_drawEllipse <x> <y> <w> <h>",
|
|
367 |
"qt3_drawEllipse 10 10 20 20");
|
|
368 |
DECL_PAINTCOMMAND("qt3_drawPie", command_qt3_drawPie,
|
|
369 |
"^qt3_drawPie\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)$",
|
|
370 |
"qt3_drawPie <x> <y> <w> <h> <angleStart> <angleArc>\n - angles are expressed in 1/16th of degree",
|
|
371 |
"qt3_drawPie 10 10 20 20 0 5760");
|
|
372 |
DECL_PAINTCOMMAND("qt3_drawRect", command_qt3_drawRect,
|
|
373 |
"^qt3_drawRect\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)$",
|
|
374 |
"qt3_drawRect <x> <y> <w> <h>",
|
|
375 |
"qt3_drawRect 10 10 20 20");
|
|
376 |
DECL_PAINTCOMMAND("qt3_drawRoundRect", command_qt3_drawRoundRect,
|
|
377 |
"^qt3_drawRoundRect\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s*(-?\\w)?\\s*(-?\\w)?$",
|
|
378 |
"qt3_drawRoundRect <x> <y> <w> <h> [rx] [ry]",
|
|
379 |
"qt3_drawRoundRect 10 10 20 20 3 3");
|
|
380 |
#endif
|
|
381 |
DECL_PAINTCOMMANDSECTION("drawing ops");
|
|
382 |
DECL_PAINTCOMMAND("drawPoint", command_drawPoint,
|
|
383 |
"^drawPoint\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
|
|
384 |
"drawPoint <x> <y>",
|
|
385 |
"drawPoint 10.0 10.0");
|
|
386 |
DECL_PAINTCOMMAND("drawLine", command_drawLine,
|
|
387 |
"^drawLine\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
|
|
388 |
"drawLine <x1> <y1> <x2> <y2>",
|
|
389 |
"drawLine 10.0 10.0 20.0 20.0");
|
|
390 |
DECL_PAINTCOMMAND("drawRect", command_drawRect,
|
|
391 |
"^drawRect\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
|
|
392 |
"drawRect <x> <y> <w> <h>",
|
|
393 |
"drawRect 10.0 10.0 20.0 20.0");
|
|
394 |
DECL_PAINTCOMMAND("drawRoundRect", command_drawRoundRect,
|
|
395 |
"^drawRoundRect\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s*(-?\\w*)?\\s*(-?\\w*)?$",
|
|
396 |
"drawRoundRect <x> <y> <w> <h> [rx] [ry]",
|
|
397 |
"drawRoundRect 10 10 20 20 3 3");
|
|
398 |
DECL_PAINTCOMMAND("drawRoundedRect", command_drawRoundedRect,
|
|
399 |
"^drawRoundedRect\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s*(\\w*)?$",
|
|
400 |
"drawRoundedRect <x> <y> <w> <h> <rx> <ry> [SizeMode enum]",
|
|
401 |
"drawRoundedRect 10 10 20 20 4 4 AbsoluteSize");
|
|
402 |
DECL_PAINTCOMMAND("drawArc", command_drawArc,
|
|
403 |
"^drawArc\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)$",
|
|
404 |
"drawArc <x> <y> <w> <h> <angleStart> <angleArc>\n - angles are expressed in 1/16th of degree",
|
|
405 |
"drawArc 10 10 20 20 0 5760");
|
|
406 |
DECL_PAINTCOMMAND("drawChord", command_drawChord,
|
|
407 |
"^drawChord\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)$",
|
|
408 |
"drawChord <x> <y> <w> <h> <angleStart> <angleArc>\n - angles are expressed in 1/16th of degree",
|
|
409 |
"drawChord 10 10 20 20 0 5760");
|
|
410 |
DECL_PAINTCOMMAND("drawEllipse", command_drawEllipse,
|
|
411 |
"^drawEllipse\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
|
|
412 |
"drawEllipse <x> <y> <w> <h>",
|
|
413 |
"drawEllipse 10.0 10.0 20.0 20.0");
|
|
414 |
DECL_PAINTCOMMAND("drawPath", command_drawPath,
|
|
415 |
"^drawPath\\s+(\\w*)$",
|
|
416 |
"drawPath <pathName>",
|
|
417 |
"drawPath mypath");
|
|
418 |
DECL_PAINTCOMMAND("drawPie", command_drawPie,
|
|
419 |
"^drawPie\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)$",
|
|
420 |
"drawPie <x> <y> <w> <h> <angleStart> <angleArc>\n - angles are expressed in 1/16th of degree",
|
|
421 |
"drawPie 10 10 20 20 0 5760");
|
|
422 |
DECL_PAINTCOMMAND("drawPixmap", command_drawPixmap,
|
|
423 |
"^drawPixmap\\s+([\\w.:\\-/]*)"
|
|
424 |
"\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s*(-?[\\w.]*)?\\s*(-?[\\w.]*)?" // target rect
|
|
425 |
"\\s*(-?[\\w.]*)?\\s*(-?[\\w.]*)?\\s*(-?[\\w.]*)?\\s*(-?[\\w.]*)?$", // source rect
|
|
426 |
"drawPixmap <filename> <tx> <ty> <tw> <th> <sx> <sy> <sw> <sh>"
|
|
427 |
"\n- where t means target and s means source"
|
|
428 |
"\n- a width or height of -1 means maximum space",
|
|
429 |
"drawPixmap :/images/face.png 0 0 -1 -1 0 0 -1 -1");
|
|
430 |
DECL_PAINTCOMMAND("drawImage", command_drawImage,
|
|
431 |
"^drawImage\\s+([\\w.:\\/]*)"
|
|
432 |
"\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s*(-?[\\w.]*)?\\s*(-?[\\w.]*)?" // target rect
|
|
433 |
"\\s*(-?[\\w.]*)?\\s*(-?[\\w.]*)?\\s*(-?[\\w.]*)?\\s*(-?[\\w.]*)?$", // source rect
|
|
434 |
"drawImage <filename> <tx> <ty> <tw> <th> <sx> <sy> <sw> <sh>"
|
|
435 |
"\n- where t means target and s means source"
|
|
436 |
"\n- a width or height of -1 means maximum space",
|
|
437 |
"drawImage :/images/face.png 0 0 -1 -1 0 0 -1 -1");
|
|
438 |
DECL_PAINTCOMMAND("drawPolygon", command_drawPolygon,
|
|
439 |
"^drawPolygon\\s+\\[([\\w\\s-.]*)\\]\\s*(\\w*)$",
|
|
440 |
"drawPolygon <[ <x1> <y1> ... <xn> <yn> ]> <Winding|OddEven>",
|
|
441 |
"drawPolygon [ 1 4 6 8 5 3 ] Winding");
|
|
442 |
DECL_PAINTCOMMAND("drawConvexPolygon", command_drawConvexPolygon,
|
|
443 |
"^drawConvexPolygon\\s+\\[([\\w\\s-.]*)\\]$",
|
|
444 |
"drawConvexPolygon <[ <x1> <y1> ... <xn> <yn> ]>",
|
|
445 |
"drawConvexPolygon [ 1 4 6 8 5 3 ]");
|
|
446 |
DECL_PAINTCOMMAND("drawPolyline", command_drawPolyline,
|
|
447 |
"^drawPolyline\\s+\\[([\\w\\s]*)\\]$",
|
|
448 |
"drawPolyline <[ <x1> <y1> ... <xn> <yn> ]>",
|
|
449 |
"drawPolyline [ 1 4 6 8 5 3 ]");
|
|
450 |
DECL_PAINTCOMMAND("drawText", command_drawText,
|
|
451 |
"^drawText\\s+(-?\\w*)\\s+(-?\\w*)\\s+\"(.*)\"$",
|
|
452 |
"drawText <x> <y> <text>",
|
|
453 |
"drawText 10 10 \"my text\"");
|
|
454 |
DECL_PAINTCOMMAND("drawTiledPixmap", command_drawTiledPixmap,
|
|
455 |
"^drawTiledPixmap\\s+([\\w.:\\/]*)"
|
|
456 |
"\\s+(-?\\w*)\\s+(-?\\w*)\\s*(-?\\w*)\\s*(-?\\w*)"
|
|
457 |
"\\s*(-?\\w*)\\s*(-?\\w*)$",
|
|
458 |
"drawTiledPixmap <tile image filename> <tx> <ty> <tx> <ty> <sx> <sy>"
|
|
459 |
"\n - where t means tile"
|
|
460 |
"\n - and s is an offset in the tile",
|
|
461 |
"drawTiledPixmap :/images/alpha.png ");
|
|
462 |
|
|
463 |
DECL_PAINTCOMMANDSECTION("painterPaths");
|
|
464 |
DECL_PAINTCOMMAND("path_moveTo", command_path_moveTo,
|
|
465 |
"^path_moveTo\\s+([.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)$",
|
|
466 |
"path_moveTo <pathName> <x> <y>",
|
|
467 |
"path_moveTo mypath 1.0 1.0");
|
|
468 |
DECL_PAINTCOMMAND("path_lineTo", command_path_lineTo,
|
|
469 |
"^path_lineTo\\s+([.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)$",
|
|
470 |
"path_lineTo <pathName> <x> <y>",
|
|
471 |
"path_lineTo mypath 1.0 1.0");
|
|
472 |
DECL_PAINTCOMMAND("path_addEllipse", command_path_addEllipse,
|
|
473 |
"^path_addEllipse\\s+(\\w*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)$",
|
|
474 |
"path_addEllipse <pathName> <x1> <y1> <x2> <y2>",
|
|
475 |
"path_addEllipse mypath 10.0 10.0 20.0 20.0");
|
|
476 |
DECL_PAINTCOMMAND("path_addPolygon", command_path_addPolygon,
|
|
477 |
"^path_addPolygon\\s+(\\w*)\\s+\\[([\\w\\s]*)\\]\\s*(\\w*)$",
|
|
478 |
"path_addPolygon <pathName> <[ <x1> <y1> ... <xn> <yn> ]>",
|
|
479 |
"path_addPolygon mypath [ 1 4 6 8 5 3 ]");
|
|
480 |
DECL_PAINTCOMMAND("path_addRect", command_path_addRect,
|
|
481 |
"^path_addRect\\s+(\\w*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)$",
|
|
482 |
"path_addRect <pathName> <x1> <y1> <x2> <y2>",
|
|
483 |
"path_addRect mypath 10.0 10.0 20.0 20.0");
|
|
484 |
DECL_PAINTCOMMAND("path_addText", command_path_addText,
|
|
485 |
"^path_addText\\s+(\\w*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+\"(.*)\"$",
|
|
486 |
"path_addText <pathName> <x> <y> <text>",
|
|
487 |
"path_addText mypath 10.0 20.0 \"some text\"");
|
|
488 |
DECL_PAINTCOMMAND("path_arcTo", command_path_arcTo,
|
|
489 |
"^path_arcTo\\s+(\\w*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)$",
|
|
490 |
"path_arcTo <pathName> <x> <y> <w> <h> <angleStart> <angleArc>\n - angles are expressed in degrees",
|
|
491 |
"path_arcTo mypath 0.0 0.0 10.0 10.0 0.0 360.0");
|
|
492 |
DECL_PAINTCOMMAND("path_cubicTo", command_path_cubicTo,
|
|
493 |
"^path_cubicTo\\s+(\\w*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)$",
|
|
494 |
"path_cubicTo <pathName> <x1> <y1> <x2> <y2> <x3> <y3>",
|
|
495 |
"path_cubicTo mypath 0.0 0.0 10.0 10.0 20.0 20.0");
|
|
496 |
DECL_PAINTCOMMAND("path_closeSubpath", command_path_closeSubpath,
|
|
497 |
"^path_closeSubpath\\s+(\\w*)$",
|
|
498 |
"path_closeSubpath <pathName>",
|
|
499 |
"path_closeSubpath mypath");
|
|
500 |
DECL_PAINTCOMMAND("path_createOutline", command_path_createOutline,
|
|
501 |
"^path_createOutline\\s+(\\w*)\\s+(\\w*)$",
|
|
502 |
"path_createOutline <pathName> <newName>",
|
|
503 |
"path_createOutline mypath myoutline");
|
|
504 |
DECL_PAINTCOMMAND("path_debugPrint", command_path_debugPrint,
|
|
505 |
"^path_debugPrint\\s+(\\w*)$",
|
|
506 |
"path_debugPrint <pathName>",
|
|
507 |
"path_debugPrint mypath");
|
|
508 |
|
|
509 |
DECL_PAINTCOMMANDSECTION("regions");
|
|
510 |
DECL_PAINTCOMMAND("region_addRect", command_region_addRect,
|
|
511 |
"^region_addRect\\s+(\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)$",
|
|
512 |
"region_addRect <regionName> <x1> <y1> <x2> <y2>",
|
|
513 |
"region_addRect myregion 0.0 0.0 10.0 10.0");
|
|
514 |
DECL_PAINTCOMMAND("region_addEllipse", command_region_addEllipse,
|
|
515 |
"^region_addEllipse\\s+(\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)$",
|
|
516 |
"region_addEllipse <regionName> <x1> <y1> <x2> <y2>",
|
|
517 |
"region_addEllipse myregion 0.0 0.0 10.0 10.0");
|
|
518 |
|
|
519 |
DECL_PAINTCOMMANDSECTION("clipping");
|
|
520 |
DECL_PAINTCOMMAND("region_getClipRegion", command_region_getClipRegion,
|
|
521 |
"^region_getClipRegion\\s+(\\w*)$",
|
|
522 |
"region_getClipRegion <regionName>",
|
|
523 |
"region_getClipRegion myregion");
|
|
524 |
DECL_PAINTCOMMAND("setClipRegion", command_setClipRegion,
|
|
525 |
"^setClipRegion\\s+(\\w*)\\s*(\\w*)$",
|
|
526 |
"setClipRegion <regionName> <clip operation enum>",
|
|
527 |
"setClipRegion myregion ReplaceClip");
|
|
528 |
DECL_PAINTCOMMAND("path_getClipPath", command_path_getClipPath,
|
|
529 |
"^path_getClipPath\\s+([\\w0-9]*)$",
|
|
530 |
"path_getClipPath <pathName>",
|
|
531 |
"path_getClipPath mypath");
|
|
532 |
DECL_PAINTCOMMAND("setClipPath", command_setClipPath,
|
|
533 |
"^setClipPath\\s+(\\w*)\\s*(\\w*)$",
|
|
534 |
"setClipPath <pathName> <clip operation enum>",
|
|
535 |
"setClipPath mypath ReplaceClip");
|
|
536 |
DECL_PAINTCOMMAND("setClipRect", command_setClipRect,
|
|
537 |
"^setClipRect\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s*(\\w*)$",
|
|
538 |
"setClipRect <x1> <y1> <x2> <y2> <clip operation enum>",
|
|
539 |
"setClipRect 0.0 0.0 10.0 10.0 ReplaceClip");
|
|
540 |
DECL_PAINTCOMMAND("setClipping", command_setClipping,
|
|
541 |
"^setClipping\\s+(\\w*)$",
|
|
542 |
"setClipping <true|false>",
|
|
543 |
"setClipping true");
|
|
544 |
|
|
545 |
DECL_PAINTCOMMANDSECTION("surface");
|
|
546 |
DECL_PAINTCOMMAND("surface_begin", command_surface_begin,
|
|
547 |
"^surface_begin\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
|
|
548 |
"surface_begin <x> <y> <w> <h>",
|
|
549 |
"surface_begin 0.0 0.0 10.0 10.0");
|
|
550 |
DECL_PAINTCOMMAND("surface_end", command_surface_end,
|
|
551 |
"^surface_end$",
|
|
552 |
"surface_end",
|
|
553 |
"surface_end");
|
|
554 |
|
|
555 |
DECL_PAINTCOMMANDSECTION("painter states");
|
|
556 |
DECL_PAINTCOMMAND("restore", command_restore,
|
|
557 |
"^restore$",
|
|
558 |
"restore",
|
|
559 |
"restore");
|
|
560 |
DECL_PAINTCOMMAND("save", command_save,
|
|
561 |
"^save$",
|
|
562 |
"save",
|
|
563 |
"save");
|
|
564 |
|
|
565 |
DECL_PAINTCOMMANDSECTION("pixmaps'n'images");
|
|
566 |
DECL_PAINTCOMMAND("pixmap_load", command_pixmap_load,
|
|
567 |
"^pixmap_load\\s+([\\w.:\\/]*)\\s*([\\w.:\\/]*)$",
|
|
568 |
"pixmap_load <image filename> <pixmapName>",
|
|
569 |
"pixmap_load :/images/face.png myPixmap");
|
|
570 |
DECL_PAINTCOMMAND("pixmap_setMask", command_pixmap_setMask,
|
|
571 |
"^pixmap_setMask\\s+([\\w.:\\/]*)\\s+([\\w.:\\/]*)$",
|
|
572 |
"pixmap_setMask <pixmapName> <bitmap filename>",
|
|
573 |
"pixmap_setMask myPixmap :/images/bitmap.png");
|
|
574 |
DECL_PAINTCOMMAND("bitmap_load", command_bitmap_load,
|
|
575 |
"^bitmap_load\\s+([\\w.:\\/]*)\\s*([\\w.:\\/]*)$",
|
|
576 |
"bitmap_load <bitmap filename> <bitmapName>\n - note that the image is stored as a pixmap",
|
|
577 |
"bitmap_load :/images/bitmap.png myBitmap");
|
|
578 |
DECL_PAINTCOMMAND("image_convertToFormat", command_image_convertToFormat,
|
|
579 |
"^image_convertToFormat\\s+([\\w.:\\/]*)\\s+([\\w.:\\/]+)\\s+([\\w0-9_]*)$",
|
|
580 |
"image_convertToFormat <sourceImageName> <destImageName> <image format enum>",
|
|
581 |
"image_convertToFormat myImage myNewImage Indexed8");
|
|
582 |
DECL_PAINTCOMMAND("image_load", command_image_load,
|
|
583 |
"^image_load\\s+([\\w.:\\/]*)\\s*([\\w.:\\/]*)$",
|
|
584 |
"image_load <filename> <imageName>",
|
|
585 |
"image_load :/images/face.png myImage");
|
|
586 |
DECL_PAINTCOMMAND("image_setColor", command_image_setColor,
|
|
587 |
"^image_setColor\\s+([\\w.:\\/]*)\\s+([0-9]*)\\s+#([0-9]*)$",
|
|
588 |
"image_setColor <imageName> <index> <color>",
|
|
589 |
"image_setColor myImage 0 black");
|
|
590 |
DECL_PAINTCOMMAND("image_setNumColors", command_image_setNumColors,
|
|
591 |
"^image_setNumColors\\s+([\\w.:\\/]*)\\s+([0-9]*)$",
|
|
592 |
"image_setNumColors <imageName> <nbColors>",
|
|
593 |
"image_setNumColors myImage 128");
|
|
594 |
|
|
595 |
DECL_PAINTCOMMANDSECTION("transformations");
|
|
596 |
DECL_PAINTCOMMAND("resetMatrix", command_resetMatrix,
|
|
597 |
"^resetMatrix$",
|
|
598 |
"resetMatrix",
|
|
599 |
"resetMatrix");
|
|
600 |
DECL_PAINTCOMMAND("setMatrix", command_setMatrix,
|
|
601 |
"^setMatrix\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)$",
|
|
602 |
"setMatrix <m11> <m12> <m13> <m21> <m22> <m23> <m31> <m32> <m33>",
|
|
603 |
"setMatrix 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0");
|
|
604 |
DECL_PAINTCOMMAND("translate", command_translate,
|
|
605 |
"^translate\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
|
|
606 |
"translate <tx> <ty>",
|
|
607 |
"translate 10.0 10.0");
|
|
608 |
DECL_PAINTCOMMAND("rotate", command_rotate,
|
|
609 |
"^rotate\\s+(-?[\\w.]*)$",
|
|
610 |
"rotate <angle>\n - with angle in degrees",
|
|
611 |
"rotate 30.0");
|
|
612 |
DECL_PAINTCOMMAND("rotate_x", command_rotate_x,
|
|
613 |
"^rotate_x\\s+(-?[\\w.]*)$",
|
|
614 |
"rotate_x <angle>\n - with angle in degrees",
|
|
615 |
"rotate_x 30.0");
|
|
616 |
DECL_PAINTCOMMAND("rotate_y", command_rotate_y,
|
|
617 |
"^rotate_y\\s+(-?[\\w.]*)$",
|
|
618 |
"rotate_y <angle>\n - with angle in degrees",
|
|
619 |
"rotate_y 30.0");
|
|
620 |
DECL_PAINTCOMMAND("scale", command_scale,
|
|
621 |
"^scale\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
|
|
622 |
"scale <sx> <sy>",
|
|
623 |
"scale 2.0 1.0");
|
|
624 |
DECL_PAINTCOMMAND("mapQuadToQuad", command_mapQuadToQuad,
|
|
625 |
"^mapQuadToQuad\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)$",
|
|
626 |
"mapQuadToQuad <x1> <y1> <x2> <y2> <x3> <y3> <x4> <y4> <x5> <y5> <x6> <y6> <x7> <y7> <x8> <y8>"
|
|
627 |
"\n - where vertices 1 to 4 defines the source quad and 5 to 8 the destination quad",
|
|
628 |
"mapQuadToQuad 0.0 0.0 1.0 1.0 0.0 0.0 -1.0 -1.0");
|
|
629 |
|
|
630 |
// populate the enums list
|
|
631 |
ADD_ENUMLIST("brush styles", brushStyleTable);
|
|
632 |
ADD_ENUMLIST("pen styles", penStyleTable);
|
|
633 |
ADD_ENUMLIST("font weights", fontWeightTable);
|
|
634 |
ADD_ENUMLIST("clip operations", clipOperationTable);
|
|
635 |
ADD_ENUMLIST("spread methods", spreadMethodTable);
|
|
636 |
ADD_ENUMLIST("composition modes", compositionModeTable);
|
|
637 |
ADD_ENUMLIST("image formats", imageFormatTable);
|
|
638 |
ADD_ENUMLIST("coordinate modes", coordinateMethodTable);
|
|
639 |
ADD_ENUMLIST("size modes", sizeModeTable);
|
|
640 |
}
|
|
641 |
|
|
642 |
#undef DECL_PAINTCOMMAND
|
|
643 |
#undef ADD_ENUMLIST
|
|
644 |
/*********************************************************************************
|
|
645 |
** utility
|
|
646 |
**********************************************************************************/
|
|
647 |
template <typename T> T PaintCommands::image_load(const QString &filepath)
|
|
648 |
{
|
|
649 |
T t(filepath);
|
|
650 |
|
|
651 |
if (t.isNull())
|
|
652 |
t = T(":images/" + filepath);
|
|
653 |
|
|
654 |
if (t.isNull())
|
|
655 |
t = T("images/" + filepath);
|
|
656 |
|
|
657 |
if (t.isNull()) {
|
|
658 |
QFileInfo fi(filepath);
|
|
659 |
QDir dir = fi.absoluteDir();
|
|
660 |
dir.cdUp();
|
|
661 |
dir.cd("images");
|
|
662 |
QString fileName = QString("%1/%2").arg(dir.absolutePath()).arg(fi.fileName());
|
|
663 |
t = T(fileName);
|
|
664 |
if (t.isNull() && !fileName.endsWith(".png")) {
|
|
665 |
fileName.append(".png");
|
|
666 |
t = T(fileName);
|
|
667 |
}
|
|
668 |
}
|
|
669 |
|
|
670 |
return t;
|
|
671 |
}
|
|
672 |
|
|
673 |
/*********************************************************************************
|
|
674 |
** setters
|
|
675 |
**********************************************************************************/
|
|
676 |
void PaintCommands::insertAt(int commandIndex, const QStringList &newCommands)
|
|
677 |
{
|
|
678 |
int index = 0;
|
|
679 |
int left = newCommands.size();
|
|
680 |
while (left--)
|
|
681 |
m_commands.insert(++commandIndex, newCommands.at(index++));
|
|
682 |
}
|
|
683 |
|
|
684 |
/*********************************************************************************
|
|
685 |
** run
|
|
686 |
**********************************************************************************/
|
|
687 |
void PaintCommands::runCommand(const QString &scriptLine)
|
|
688 |
{
|
|
689 |
staticInit();
|
|
690 |
foreach (PaintCommandInfos command, s_commandInfoTable)
|
|
691 |
if (!command.isSectionHeader() && command.regExp.indexIn(scriptLine) >= 0) {
|
|
692 |
(this->*(command.paintMethod))(command.regExp);
|
|
693 |
return;
|
|
694 |
}
|
|
695 |
qWarning("ERROR: unknown command or argument syntax error in \"%s\"", qPrintable(scriptLine));
|
|
696 |
}
|
|
697 |
|
|
698 |
void PaintCommands::runCommands()
|
|
699 |
{
|
|
700 |
staticInit();
|
|
701 |
int width = m_painter->window().width();
|
|
702 |
int height = m_painter->window().height();
|
|
703 |
|
|
704 |
if (width <= 0)
|
|
705 |
width = 800;
|
|
706 |
if (height <= 0)
|
|
707 |
height = 800;
|
|
708 |
|
|
709 |
// paint background
|
|
710 |
if (m_checkers_background) {
|
|
711 |
QPixmap pm(20, 20);
|
|
712 |
pm.fill(Qt::white);
|
|
713 |
QPainter pt(&pm);
|
|
714 |
pt.fillRect(0, 0, 10, 10, QColor::fromRgba(0xffdfdfdf));
|
|
715 |
pt.fillRect(10, 10, 10, 10, QColor::fromRgba(0xffdfdfdf));
|
|
716 |
|
|
717 |
m_painter->drawTiledPixmap(0, 0, width, height, pm);
|
|
718 |
} else {
|
|
719 |
m_painter->fillRect(0, 0, width, height, Qt::white);
|
|
720 |
}
|
|
721 |
|
|
722 |
// run each command
|
|
723 |
m_abort = false;
|
|
724 |
for (int i=0; i<m_commands.size() && !m_abort; ++i) {
|
|
725 |
const QString &commandNow = m_commands.at(i);
|
|
726 |
m_currentCommand = commandNow;
|
|
727 |
m_currentCommandIndex = i;
|
|
728 |
runCommand(commandNow.trimmed());
|
|
729 |
}
|
|
730 |
}
|
|
731 |
|
|
732 |
/*********************************************************************************
|
|
733 |
** conversions
|
|
734 |
**********************************************************************************/
|
|
735 |
int PaintCommands::convertToInt(const QString &str)
|
|
736 |
{
|
|
737 |
return qRound(convertToDouble(str));
|
|
738 |
}
|
|
739 |
|
|
740 |
float PaintCommands::convertToFloat(const QString &str)
|
|
741 |
{
|
|
742 |
return float(convertToDouble(str));
|
|
743 |
}
|
|
744 |
|
|
745 |
double PaintCommands::convertToDouble(const QString &str)
|
|
746 |
{
|
|
747 |
static QRegExp re("cp([0-9])([xy])");
|
|
748 |
if (str.toLower() == "width") {
|
|
749 |
if (m_painter->device()->devType() == Qt::Widget)
|
|
750 |
return m_painter->window().width();
|
|
751 |
else
|
|
752 |
return 800;
|
|
753 |
}
|
|
754 |
if (str.toLower() == "height") {
|
|
755 |
if (m_painter->device()->devType() == Qt::Widget)
|
|
756 |
return m_painter->window().height();
|
|
757 |
else
|
|
758 |
return 800;
|
|
759 |
}
|
|
760 |
if (re.indexIn(str) >= 0) {
|
|
761 |
int index = re.cap(1).toInt();
|
|
762 |
bool is_it_x = re.cap(2) == "x";
|
|
763 |
if (index < 0 || index >= m_controlPoints.size()) {
|
|
764 |
qWarning("ERROR: control point index=%d is out of bounds", index);
|
|
765 |
return 0;
|
|
766 |
}
|
|
767 |
return is_it_x ? m_controlPoints.at(index).x() : m_controlPoints.at(index).y();
|
|
768 |
}
|
|
769 |
return str.toDouble();
|
|
770 |
}
|
|
771 |
|
|
772 |
QColor PaintCommands::convertToColor(const QString &str)
|
|
773 |
{
|
|
774 |
static QRegExp alphaColor("#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})");
|
|
775 |
static QRegExp opaqueColor("#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})");
|
|
776 |
|
|
777 |
Q_ASSERT(alphaColor.isValid());
|
|
778 |
Q_ASSERT(opaqueColor.isValid());
|
|
779 |
|
|
780 |
if (alphaColor.indexIn(str) >= 0) {
|
|
781 |
return QColor(alphaColor.cap(2).toInt(0, 16),
|
|
782 |
alphaColor.cap(3).toInt(0, 16),
|
|
783 |
alphaColor.cap(4).toInt(0, 16),
|
|
784 |
alphaColor.cap(1).toInt(0, 16));
|
|
785 |
} else if (opaqueColor.indexIn(str) >= 0) {
|
|
786 |
return QColor(opaqueColor.cap(1).toInt(0, 16),
|
|
787 |
opaqueColor.cap(2).toInt(0, 16),
|
|
788 |
opaqueColor.cap(3).toInt(0, 16));
|
|
789 |
}
|
|
790 |
return QColor(str);
|
|
791 |
}
|
|
792 |
|
|
793 |
/*********************************************************************************
|
|
794 |
** command implementations
|
|
795 |
**********************************************************************************/
|
|
796 |
void PaintCommands::command_comment(QRegExp)
|
|
797 |
{
|
|
798 |
if (m_verboseMode)
|
|
799 |
printf(" -(lance) comment: %s\n", qPrintable(m_currentCommand));
|
|
800 |
}
|
|
801 |
|
|
802 |
/***************************************************************************************************/
|
|
803 |
void PaintCommands::command_import(QRegExp re)
|
|
804 |
{
|
|
805 |
QString importFile(re.cap(1));
|
|
806 |
QFileInfo fi(m_filepath);
|
|
807 |
QDir dir = fi.absoluteDir();
|
|
808 |
QFile *file = new QFile(dir.absolutePath() + QDir::separator() + importFile);
|
|
809 |
|
|
810 |
if (importFile.isEmpty() || !file->exists()) {
|
|
811 |
dir.cdUp();
|
|
812 |
dir.cd("data");
|
|
813 |
dir.cd("qps");
|
|
814 |
delete file;
|
|
815 |
file = new QFile(dir.absolutePath() + QDir::separator() + importFile);
|
|
816 |
}
|
|
817 |
|
|
818 |
if (importFile.isEmpty() || !file->exists()) {
|
|
819 |
dir.cdUp();
|
|
820 |
dir.cd("images");
|
|
821 |
delete file;
|
|
822 |
file = new QFile(dir.absolutePath() + QDir::separator() + importFile);
|
|
823 |
}
|
|
824 |
|
|
825 |
if (importFile.isEmpty() || !file->exists()) {
|
|
826 |
printf(" - importing non-existing file at line %d (%s)\n", m_currentCommandIndex,
|
|
827 |
qPrintable(file->fileName()));
|
|
828 |
delete file;
|
|
829 |
return;
|
|
830 |
}
|
|
831 |
|
|
832 |
if (!file->open(QIODevice::ReadOnly)) {
|
|
833 |
printf(" - failed to read file: '%s'\n", qPrintable(file->fileName()));
|
|
834 |
delete file;
|
|
835 |
return;
|
|
836 |
}
|
|
837 |
if (m_verboseMode)
|
|
838 |
printf(" -(lance) importing file at line %d (%s)\n", m_currentCommandIndex,
|
|
839 |
qPrintable(fi.fileName()));
|
|
840 |
|
|
841 |
QFileInfo fileinfo(*file);
|
|
842 |
m_commands[m_currentCommandIndex] = QString("# import file (%1) start").arg(fileinfo.fileName());
|
|
843 |
QTextStream textFile(file);
|
|
844 |
QString rawContent = textFile.readAll();
|
|
845 |
QStringList importedData = rawContent.split('\n', QString::SkipEmptyParts);
|
|
846 |
importedData.append(QString("# import file (%1) end ---").arg(fileinfo.fileName()));
|
|
847 |
insertAt(m_currentCommandIndex, importedData);
|
|
848 |
|
|
849 |
if (m_verboseMode) {
|
|
850 |
printf(" -(lance) Command buffer now looks like:\n");
|
|
851 |
for (int i = 0; i < m_commands.count(); ++i)
|
|
852 |
printf(" ---> {%s}\n", qPrintable(m_commands.at(i)));
|
|
853 |
}
|
|
854 |
delete file;
|
|
855 |
}
|
|
856 |
|
|
857 |
/***************************************************************************************************/
|
|
858 |
void PaintCommands::command_begin_block(QRegExp re)
|
|
859 |
{
|
|
860 |
const QString &blockName = re.cap(1);
|
|
861 |
if (m_verboseMode)
|
|
862 |
printf(" -(lance) begin_block (%s)\n", qPrintable(blockName));
|
|
863 |
|
|
864 |
m_commands[m_currentCommandIndex] = QString("# begin block (%1)").arg(blockName);
|
|
865 |
QStringList newBlock;
|
|
866 |
int i = m_currentCommandIndex + 1;
|
|
867 |
for (; i < m_commands.count(); ++i) {
|
|
868 |
const QString &nextCmd = m_commands.at(i);
|
|
869 |
if (nextCmd.startsWith("end_block")) {
|
|
870 |
m_commands[i] = QString("# end block (%1)").arg(blockName);
|
|
871 |
break;
|
|
872 |
}
|
|
873 |
newBlock += nextCmd;
|
|
874 |
}
|
|
875 |
|
|
876 |
if (m_verboseMode)
|
|
877 |
for (int j = 0; j < newBlock.count(); ++j)
|
|
878 |
printf(" %d: %s\n", j, qPrintable(newBlock.at(j)));
|
|
879 |
|
|
880 |
if (i >= m_commands.count())
|
|
881 |
printf(" - Warning! Block doesn't have an 'end_block' marker!\n");
|
|
882 |
|
|
883 |
m_blockMap.insert(blockName, newBlock);
|
|
884 |
}
|
|
885 |
|
|
886 |
/***************************************************************************************************/
|
|
887 |
void PaintCommands::command_end_block(QRegExp)
|
|
888 |
{
|
|
889 |
printf(" - end_block should be consumed by begin_block command.\n");
|
|
890 |
printf(" You will never see this if your block markers are in sync\n");
|
|
891 |
printf(" (noop)\n");
|
|
892 |
}
|
|
893 |
|
|
894 |
/***************************************************************************************************/
|
|
895 |
void PaintCommands::command_repeat_block(QRegExp re)
|
|
896 |
{
|
|
897 |
QString blockName = re.cap(1);
|
|
898 |
if (m_verboseMode)
|
|
899 |
printf(" -(lance) repeating block (%s)\n", qPrintable(blockName));
|
|
900 |
|
|
901 |
QStringList block = m_blockMap.value(blockName);
|
|
902 |
if (block.isEmpty()) {
|
|
903 |
printf(" - repeated block (%s) is empty!\n", qPrintable(blockName));
|
|
904 |
return;
|
|
905 |
}
|
|
906 |
|
|
907 |
m_commands[m_currentCommandIndex] = QString("# repeated block (%1)").arg(blockName);
|
|
908 |
insertAt(m_currentCommandIndex, block);
|
|
909 |
}
|
|
910 |
|
|
911 |
/***************************************************************************************************/
|
|
912 |
void PaintCommands::command_drawLine(QRegExp re)
|
|
913 |
{
|
|
914 |
QStringList caps = re.capturedTexts();
|
|
915 |
double x1 = convertToDouble(caps.at(1));
|
|
916 |
double y1 = convertToDouble(caps.at(2));
|
|
917 |
double x2 = convertToDouble(caps.at(3));
|
|
918 |
double y2 = convertToDouble(caps.at(4));
|
|
919 |
|
|
920 |
if (m_verboseMode)
|
|
921 |
printf(" -(lance) drawLine((%.2f, %.2f), (%.2f, %.2f))\n", x1, y1, x2, y2);
|
|
922 |
|
|
923 |
m_painter->drawLine(QLineF(x1, y1, x2, y2));
|
|
924 |
}
|
|
925 |
|
|
926 |
/***************************************************************************************************/
|
|
927 |
void PaintCommands::command_drawPath(QRegExp re)
|
|
928 |
{
|
|
929 |
if (m_verboseMode)
|
|
930 |
printf(" -(lance) drawPath(name=%s)\n", qPrintable(re.cap(1)));
|
|
931 |
|
|
932 |
QPainterPath &path = m_pathMap[re.cap(1)];
|
|
933 |
m_painter->drawPath(path);
|
|
934 |
}
|
|
935 |
|
|
936 |
/***************************************************************************************************/
|
|
937 |
void PaintCommands::command_drawPixmap(QRegExp re)
|
|
938 |
{
|
|
939 |
QPixmap pm;
|
|
940 |
pm = m_pixmapMap[re.cap(1)]; // try cache first
|
|
941 |
if (pm.isNull())
|
|
942 |
pm = image_load<QPixmap>(re.cap(1));
|
|
943 |
if (pm.isNull()) {
|
|
944 |
QFileInfo fi(m_filepath);
|
|
945 |
QDir dir = fi.absoluteDir();
|
|
946 |
dir.cdUp();
|
|
947 |
dir.cd("images");
|
|
948 |
QString fileName = QString("%1/%2").arg(dir.absolutePath()).arg(re.cap(1));
|
|
949 |
pm = QPixmap(fileName);
|
|
950 |
if (pm.isNull() && !fileName.endsWith(".png")) {
|
|
951 |
fileName.append(".png");
|
|
952 |
pm = QPixmap(fileName);
|
|
953 |
}
|
|
954 |
}
|
|
955 |
if (pm.isNull()) {
|
|
956 |
fprintf(stderr, "ERROR(drawPixmap): failed to load pixmap: '%s'\n",
|
|
957 |
qPrintable(re.cap(1)));
|
|
958 |
return;
|
|
959 |
}
|
|
960 |
|
|
961 |
qreal tx = convertToFloat(re.cap(2));
|
|
962 |
qreal ty = convertToFloat(re.cap(3));
|
|
963 |
qreal tw = convertToFloat(re.cap(4));
|
|
964 |
qreal th = convertToFloat(re.cap(5));
|
|
965 |
|
|
966 |
qreal sx = convertToFloat(re.cap(6));
|
|
967 |
qreal sy = convertToFloat(re.cap(7));
|
|
968 |
qreal sw = convertToFloat(re.cap(8));
|
|
969 |
qreal sh = convertToFloat(re.cap(9));
|
|
970 |
|
|
971 |
if (tw == 0) tw = -1;
|
|
972 |
if (th == 0) th = -1;
|
|
973 |
if (sw == 0) sw = -1;
|
|
974 |
if (sh == 0) sh = -1;
|
|
975 |
|
|
976 |
if (m_verboseMode)
|
|
977 |
printf(" -(lance) drawPixmap('%s' dim=(%d, %d), depth=%d, (%d, %d, %d, %d), (%d, %d, %d, %d)\n",
|
|
978 |
qPrintable(re.cap(1)), pm.width(), pm.height(), pm.depth(),
|
|
979 |
tx, ty, tw, th, sx, sy, sw, sh);
|
|
980 |
|
|
981 |
m_painter->drawPixmap(QRectF(tx, ty, tw, th), pm, QRectF(sx, sy, sw, sh));
|
|
982 |
}
|
|
983 |
|
|
984 |
/***************************************************************************************************/
|
|
985 |
void PaintCommands::command_drawImage(QRegExp re)
|
|
986 |
{
|
|
987 |
QImage im;
|
|
988 |
im = m_imageMap[re.cap(1)]; // try cache first
|
|
989 |
if (im.isNull())
|
|
990 |
im = image_load<QImage>(re.cap(1));
|
|
991 |
|
|
992 |
if (im.isNull()) {
|
|
993 |
QFileInfo fi(m_filepath);
|
|
994 |
QDir dir = fi.absoluteDir();
|
|
995 |
dir.cdUp();
|
|
996 |
dir.cd("images");
|
|
997 |
QString fileName = QString("%1/%2").arg(dir.absolutePath()).arg(re.cap(1));
|
|
998 |
im = QImage(fileName);
|
|
999 |
if (im.isNull() && !fileName.endsWith(".png")) {
|
|
1000 |
fileName.append(".png");
|
|
1001 |
im = QImage(fileName);
|
|
1002 |
}
|
|
1003 |
}
|
|
1004 |
if (im.isNull()) {
|
|
1005 |
fprintf(stderr, "ERROR(drawImage): failed to load image: '%s'\n", qPrintable(re.cap(1)));
|
|
1006 |
return;
|
|
1007 |
}
|
|
1008 |
|
|
1009 |
qreal tx = convertToFloat(re.cap(2));
|
|
1010 |
qreal ty = convertToFloat(re.cap(3));
|
|
1011 |
qreal tw = convertToFloat(re.cap(4));
|
|
1012 |
qreal th = convertToFloat(re.cap(5));
|
|
1013 |
|
|
1014 |
qreal sx = convertToFloat(re.cap(6));
|
|
1015 |
qreal sy = convertToFloat(re.cap(7));
|
|
1016 |
qreal sw = convertToFloat(re.cap(8));
|
|
1017 |
qreal sh = convertToFloat(re.cap(9));
|
|
1018 |
|
|
1019 |
if (tw == 0) tw = -1;
|
|
1020 |
if (th == 0) th = -1;
|
|
1021 |
if (sw == 0) sw = -1;
|
|
1022 |
if (sh == 0) sh = -1;
|
|
1023 |
|
|
1024 |
if (m_verboseMode)
|
|
1025 |
printf(" -(lance) drawImage('%s' dim=(%d, %d), (%d, %d, %d, %d), (%d, %d, %d, %d)\n",
|
|
1026 |
qPrintable(re.cap(1)), im.width(), im.height(), tx, ty, tw, th, sx, sy, sw, sh);
|
|
1027 |
|
|
1028 |
m_painter->drawImage(QRectF(tx, ty, tw, th), im, QRectF(sx, sy, sw, sh), Qt::OrderedDither | Qt::OrderedAlphaDither);
|
|
1029 |
}
|
|
1030 |
|
|
1031 |
/***************************************************************************************************/
|
|
1032 |
void PaintCommands::command_drawTiledPixmap(QRegExp re)
|
|
1033 |
{
|
|
1034 |
QPixmap pm;
|
|
1035 |
pm = m_pixmapMap[re.cap(1)]; // try cache first
|
|
1036 |
if (pm.isNull())
|
|
1037 |
pm = image_load<QPixmap>(re.cap(1));
|
|
1038 |
if (pm.isNull()) {
|
|
1039 |
QFileInfo fi(m_filepath);
|
|
1040 |
QDir dir = fi.absoluteDir();
|
|
1041 |
dir.cdUp();
|
|
1042 |
dir.cd("images");
|
|
1043 |
QString fileName = QString("%1/%2").arg(dir.absolutePath()).arg(re.cap(1));
|
|
1044 |
pm = QPixmap(fileName);
|
|
1045 |
if (pm.isNull() && !fileName.endsWith(".png")) {
|
|
1046 |
fileName.append(".png");
|
|
1047 |
pm = QPixmap(fileName);
|
|
1048 |
}
|
|
1049 |
}
|
|
1050 |
if (pm.isNull()) {
|
|
1051 |
fprintf(stderr, "ERROR(drawTiledPixmap): failed to load pixmap: '%s'\n",
|
|
1052 |
qPrintable(re.cap(1)));
|
|
1053 |
return;
|
|
1054 |
}
|
|
1055 |
|
|
1056 |
int tx = convertToInt(re.cap(2));
|
|
1057 |
int ty = convertToInt(re.cap(3));
|
|
1058 |
int tw = convertToInt(re.cap(4));
|
|
1059 |
int th = convertToInt(re.cap(5));
|
|
1060 |
|
|
1061 |
int sx = convertToInt(re.cap(6));
|
|
1062 |
int sy = convertToInt(re.cap(7));
|
|
1063 |
|
|
1064 |
if (tw == 0) tw = -1;
|
|
1065 |
if (th == 0) th = -1;
|
|
1066 |
|
|
1067 |
if (m_verboseMode)
|
|
1068 |
printf(" -(lance) drawTiledPixmap('%s' dim=(%d, %d), (%d, %d, %d, %d), (%d, %d)\n",
|
|
1069 |
qPrintable(re.cap(1)), pm.width(), pm.height(), tx, ty, tw, th, sx, sy);
|
|
1070 |
|
|
1071 |
m_painter->drawTiledPixmap(tx, ty, tw, th, pm, sx, sy);
|
|
1072 |
}
|
|
1073 |
|
|
1074 |
/***************************************************************************************************/
|
|
1075 |
void PaintCommands::command_drawPoint(QRegExp re)
|
|
1076 |
{
|
|
1077 |
QStringList caps = re.capturedTexts();
|
|
1078 |
float x = convertToFloat(caps.at(1));
|
|
1079 |
float y = convertToFloat(caps.at(2));
|
|
1080 |
|
|
1081 |
if (m_verboseMode)
|
|
1082 |
printf(" -(lance) drawPoint(%.2f, %.2f)\n", x, y);
|
|
1083 |
|
|
1084 |
m_painter->drawPoint(QPointF(x, y));
|
|
1085 |
}
|
|
1086 |
|
|
1087 |
/***************************************************************************************************/
|
|
1088 |
void PaintCommands::command_drawPolygon(QRegExp re)
|
|
1089 |
{
|
|
1090 |
static QRegExp separators("\\s");
|
|
1091 |
QStringList caps = re.capturedTexts();
|
|
1092 |
QString cap = caps.at(1);
|
|
1093 |
QStringList numbers = cap.split(separators, QString::SkipEmptyParts);
|
|
1094 |
|
|
1095 |
QPolygonF array;
|
|
1096 |
for (int i=0; i + 1<numbers.size(); i+=2)
|
|
1097 |
array.append(QPointF(convertToDouble(numbers.at(i)), convertToDouble(numbers.at(i+1))));
|
|
1098 |
|
|
1099 |
if (m_verboseMode)
|
|
1100 |
printf(" -(lance) drawPolygon(size=%d)\n", array.size());
|
|
1101 |
|
|
1102 |
m_painter->drawPolygon(array, caps.at(2).toLower() == "winding" ? Qt::WindingFill : Qt::OddEvenFill);
|
|
1103 |
}
|
|
1104 |
|
|
1105 |
/***************************************************************************************************/
|
|
1106 |
void PaintCommands::command_drawPolyline(QRegExp re)
|
|
1107 |
{
|
|
1108 |
static QRegExp separators("\\s");
|
|
1109 |
QStringList numbers = re.cap(1).split(separators, QString::SkipEmptyParts);
|
|
1110 |
|
|
1111 |
QPolygonF array;
|
|
1112 |
for (int i=0; i + 1<numbers.size(); i+=2)
|
|
1113 |
array.append(QPointF(numbers.at(i).toFloat(),numbers.at(i+1).toFloat()));
|
|
1114 |
|
|
1115 |
if (m_verboseMode)
|
|
1116 |
printf(" -(lance) drawPolyline(size=%d)\n", array.size());
|
|
1117 |
|
|
1118 |
m_painter->drawPolyline(array.toPolygon());
|
|
1119 |
}
|
|
1120 |
|
|
1121 |
/***************************************************************************************************/
|
|
1122 |
void PaintCommands::command_drawRect(QRegExp re)
|
|
1123 |
{
|
|
1124 |
QStringList caps = re.capturedTexts();
|
|
1125 |
float x = convertToFloat(caps.at(1));
|
|
1126 |
float y = convertToFloat(caps.at(2));
|
|
1127 |
float w = convertToFloat(caps.at(3));
|
|
1128 |
float h = convertToFloat(caps.at(4));
|
|
1129 |
|
|
1130 |
if (m_verboseMode)
|
|
1131 |
printf(" -(lance) drawRect(%.2f, %.2f, %.2f, %.2f)\n", x, y, w, h);
|
|
1132 |
|
|
1133 |
m_painter->drawRect(QRectF(x, y, w, h));
|
|
1134 |
}
|
|
1135 |
|
|
1136 |
/***************************************************************************************************/
|
|
1137 |
void PaintCommands::command_drawRoundedRect(QRegExp re)
|
|
1138 |
{
|
|
1139 |
QStringList caps = re.capturedTexts();
|
|
1140 |
float x = convertToFloat(caps.at(1));
|
|
1141 |
float y = convertToFloat(caps.at(2));
|
|
1142 |
float w = convertToFloat(caps.at(3));
|
|
1143 |
float h = convertToFloat(caps.at(4));
|
|
1144 |
float xr = convertToFloat(caps.at(5));
|
|
1145 |
float yr = convertToFloat(caps.at(6));
|
|
1146 |
|
|
1147 |
int mode = translateEnum(sizeModeTable, caps.at(7), sizeof(sizeModeTable)/sizeof(char *));
|
|
1148 |
if (mode < 0)
|
|
1149 |
mode = Qt::AbsoluteSize;
|
|
1150 |
|
|
1151 |
if (m_verboseMode)
|
|
1152 |
printf(" -(lance) drawRoundRect(%f, %f, %f, %f, %f, %f, %s)\n", x, y, w, h, xr, yr, mode ? "RelativeSize" : "AbsoluteSize");
|
|
1153 |
|
|
1154 |
m_painter->drawRoundedRect(QRectF(x, y, w, h), xr, yr, Qt::SizeMode(mode));
|
|
1155 |
}
|
|
1156 |
|
|
1157 |
/***************************************************************************************************/
|
|
1158 |
void PaintCommands::command_drawRoundRect(QRegExp re)
|
|
1159 |
{
|
|
1160 |
QStringList caps = re.capturedTexts();
|
|
1161 |
int x = convertToInt(caps.at(1));
|
|
1162 |
int y = convertToInt(caps.at(2));
|
|
1163 |
int w = convertToInt(caps.at(3));
|
|
1164 |
int h = convertToInt(caps.at(4));
|
|
1165 |
int xs = caps.at(5).isEmpty() ? 50 : convertToInt(caps.at(5));
|
|
1166 |
int ys = caps.at(6).isEmpty() ? 50 : convertToInt(caps.at(6));
|
|
1167 |
|
|
1168 |
if (m_verboseMode)
|
|
1169 |
printf(" -(lance) drawRoundRect(%d, %d, %d, %d, [%d, %d])\n", x, y, w, h, xs, ys);
|
|
1170 |
|
|
1171 |
m_painter->drawRoundRect(x, y, w, h, xs, ys);
|
|
1172 |
}
|
|
1173 |
|
|
1174 |
/***************************************************************************************************/
|
|
1175 |
void PaintCommands::command_drawEllipse(QRegExp re)
|
|
1176 |
{
|
|
1177 |
QStringList caps = re.capturedTexts();
|
|
1178 |
float x = convertToFloat(caps.at(1));
|
|
1179 |
float y = convertToFloat(caps.at(2));
|
|
1180 |
float w = convertToFloat(caps.at(3));
|
|
1181 |
float h = convertToFloat(caps.at(4));
|
|
1182 |
|
|
1183 |
if (m_verboseMode)
|
|
1184 |
printf(" -(lance) drawEllipse(%.2f, %.2f, %.2f, %.2f)\n", x, y, w, h);
|
|
1185 |
|
|
1186 |
m_painter->drawEllipse(QRectF(x, y, w, h));
|
|
1187 |
}
|
|
1188 |
|
|
1189 |
/***************************************************************************************************/
|
|
1190 |
void PaintCommands::command_drawPie(QRegExp re)
|
|
1191 |
{
|
|
1192 |
QStringList caps = re.capturedTexts();
|
|
1193 |
int x = convertToInt(caps.at(1));
|
|
1194 |
int y = convertToInt(caps.at(2));
|
|
1195 |
int w = convertToInt(caps.at(3));
|
|
1196 |
int h = convertToInt(caps.at(4));
|
|
1197 |
int angle = convertToInt(caps.at(5));
|
|
1198 |
int sweep = convertToInt(caps.at(6));
|
|
1199 |
|
|
1200 |
if (m_verboseMode)
|
|
1201 |
printf(" -(lance) drawPie(%d, %d, %d, %d, %d, %d)\n", x, y, w, h, angle, sweep);
|
|
1202 |
|
|
1203 |
m_painter->drawPie(x, y, w, h, angle, sweep);
|
|
1204 |
}
|
|
1205 |
|
|
1206 |
/***************************************************************************************************/
|
|
1207 |
void PaintCommands::command_drawChord(QRegExp re)
|
|
1208 |
{
|
|
1209 |
QStringList caps = re.capturedTexts();
|
|
1210 |
int x = convertToInt(caps.at(1));
|
|
1211 |
int y = convertToInt(caps.at(2));
|
|
1212 |
int w = convertToInt(caps.at(3));
|
|
1213 |
int h = convertToInt(caps.at(4));
|
|
1214 |
int angle = convertToInt(caps.at(5));
|
|
1215 |
int sweep = convertToInt(caps.at(6));
|
|
1216 |
|
|
1217 |
if (m_verboseMode)
|
|
1218 |
printf(" -(lance) drawChord(%d, %d, %d, %d, %d, %d)\n", x, y, w, h, angle, sweep);
|
|
1219 |
|
|
1220 |
m_painter->drawChord(x, y, w, h, angle, sweep);
|
|
1221 |
}
|
|
1222 |
|
|
1223 |
/***************************************************************************************************/
|
|
1224 |
void PaintCommands::command_drawArc(QRegExp re)
|
|
1225 |
{
|
|
1226 |
QStringList caps = re.capturedTexts();
|
|
1227 |
int x = convertToInt(caps.at(1));
|
|
1228 |
int y = convertToInt(caps.at(2));
|
|
1229 |
int w = convertToInt(caps.at(3));
|
|
1230 |
int h = convertToInt(caps.at(4));
|
|
1231 |
int angle = convertToInt(caps.at(5));
|
|
1232 |
int sweep = convertToInt(caps.at(6));
|
|
1233 |
|
|
1234 |
if (m_verboseMode)
|
|
1235 |
printf(" -(lance) drawArc(%d, %d, %d, %d, %d, %d)\n", x, y, w, h, angle, sweep);
|
|
1236 |
|
|
1237 |
m_painter->drawArc(x, y, w, h, angle, sweep);
|
|
1238 |
}
|
|
1239 |
|
|
1240 |
#ifdef QT3_SUPPORT
|
|
1241 |
/***************************************************************************************************/
|
|
1242 |
void PaintCommands::command_qt3_drawRect(QRegExp re)
|
|
1243 |
{
|
|
1244 |
Q_UNUSED(re);
|
|
1245 |
#ifdef QT3_SUPPORT
|
|
1246 |
QStringList caps = re.capturedTexts();
|
|
1247 |
int x = convertToInt(caps.at(1));
|
|
1248 |
int y = convertToInt(caps.at(2));
|
|
1249 |
int w = convertToInt(caps.at(3));
|
|
1250 |
int h = convertToInt(caps.at(4));
|
|
1251 |
|
|
1252 |
if (m_verboseMode)
|
|
1253 |
printf(" -(lance) qt3_drawRect(%d, %d, %d, %d)\n", x, y, w, h);
|
|
1254 |
|
|
1255 |
static_cast<Q3Painter*>(m_painter)->drawRect(x, y, w, h);
|
|
1256 |
#endif
|
|
1257 |
}
|
|
1258 |
|
|
1259 |
/***************************************************************************************************/
|
|
1260 |
void PaintCommands::command_qt3_drawRoundRect(QRegExp re)
|
|
1261 |
{
|
|
1262 |
Q_UNUSED(re);
|
|
1263 |
#ifdef QT3_SUPPORT
|
|
1264 |
QStringList caps = re.capturedTexts();
|
|
1265 |
int x = convertToInt(caps.at(1));
|
|
1266 |
int y = convertToInt(caps.at(2));
|
|
1267 |
int w = convertToInt(caps.at(3));
|
|
1268 |
int h = convertToInt(caps.at(4));
|
|
1269 |
int xrnd = caps.at(5).isEmpty() ? 25 : convertToInt(caps.at(5));
|
|
1270 |
int yrnd = caps.at(6).isEmpty() ? 25 : convertToInt(caps.at(6));
|
|
1271 |
|
|
1272 |
if (m_verboseMode)
|
|
1273 |
printf(" -(lance) qt3_drawRoundRect(%d, %d, %d, %d), %d, %d\n", x, y, w, h, xrnd, yrnd);
|
|
1274 |
|
|
1275 |
static_cast<Q3Painter*>(m_painter)->drawRoundRect(x, y, w, h, xrnd, yrnd);
|
|
1276 |
#endif
|
|
1277 |
}
|
|
1278 |
|
|
1279 |
/***************************************************************************************************/
|
|
1280 |
void PaintCommands::command_qt3_drawEllipse(QRegExp re)
|
|
1281 |
{
|
|
1282 |
Q_UNUSED(re);
|
|
1283 |
#ifdef QT3_SUPPORT
|
|
1284 |
QStringList caps = re.capturedTexts();
|
|
1285 |
int x = convertToInt(caps.at(1));
|
|
1286 |
int y = convertToInt(caps.at(2));
|
|
1287 |
int w = convertToInt(caps.at(3));
|
|
1288 |
int h = convertToInt(caps.at(4));
|
|
1289 |
|
|
1290 |
if (m_verboseMode)
|
|
1291 |
printf(" -(lance) qt3_drawEllipse(%d, %d, %d, %d)\n", x, y, w, h);
|
|
1292 |
|
|
1293 |
static_cast<Q3Painter*>(m_painter)->drawEllipse(x, y, w, h);
|
|
1294 |
#endif
|
|
1295 |
}
|
|
1296 |
|
|
1297 |
/***************************************************************************************************/
|
|
1298 |
void PaintCommands::command_qt3_drawPie(QRegExp re)
|
|
1299 |
{
|
|
1300 |
Q_UNUSED(re);
|
|
1301 |
#ifdef QT3_SUPPORT
|
|
1302 |
QStringList caps = re.capturedTexts();
|
|
1303 |
int x = convertToInt(caps.at(1));
|
|
1304 |
int y = convertToInt(caps.at(2));
|
|
1305 |
int w = convertToInt(caps.at(3));
|
|
1306 |
int h = convertToInt(caps.at(4));
|
|
1307 |
int angle = convertToInt(caps.at(5));
|
|
1308 |
int sweep = convertToInt(caps.at(6));
|
|
1309 |
|
|
1310 |
if (m_verboseMode)
|
|
1311 |
printf(" -(lance) qt3_drawPie(%d, %d, %d, %d, %d, %d)\n", x, y, w, h, angle, sweep);
|
|
1312 |
|
|
1313 |
static_cast<Q3Painter*>(m_painter)->drawPie(x, y, w, h, angle, sweep);
|
|
1314 |
#endif
|
|
1315 |
}
|
|
1316 |
|
|
1317 |
/***************************************************************************************************/
|
|
1318 |
void PaintCommands::command_qt3_drawChord(QRegExp re)
|
|
1319 |
{
|
|
1320 |
Q_UNUSED(re);
|
|
1321 |
#ifdef QT3_SUPPORT
|
|
1322 |
QStringList caps = re.capturedTexts();
|
|
1323 |
int x = convertToInt(caps.at(1));
|
|
1324 |
int y = convertToInt(caps.at(2));
|
|
1325 |
int w = convertToInt(caps.at(3));
|
|
1326 |
int h = convertToInt(caps.at(4));
|
|
1327 |
int angle = convertToInt(caps.at(5));
|
|
1328 |
int sweep = convertToInt(caps.at(6));
|
|
1329 |
|
|
1330 |
if (m_verboseMode)
|
|
1331 |
printf(" -(lance) qt3_drawChord(%d, %d, %d, %d, %d, %d)\n", x, y, w, h, angle, sweep);
|
|
1332 |
|
|
1333 |
static_cast<Q3Painter*>(m_painter)->drawChord(x, y, w, h, angle, sweep);
|
|
1334 |
#endif
|
|
1335 |
}
|
|
1336 |
|
|
1337 |
/***************************************************************************************************/
|
|
1338 |
void PaintCommands::command_qt3_drawArc(QRegExp re)
|
|
1339 |
{
|
|
1340 |
Q_UNUSED(re);
|
|
1341 |
#ifdef QT3_SUPPORT
|
|
1342 |
QStringList caps = re.capturedTexts();
|
|
1343 |
int x = convertToInt(caps.at(1));
|
|
1344 |
int y = convertToInt(caps.at(2));
|
|
1345 |
int w = convertToInt(caps.at(3));
|
|
1346 |
int h = convertToInt(caps.at(4));
|
|
1347 |
int angle = convertToInt(caps.at(5));
|
|
1348 |
int sweep = convertToInt(caps.at(6));
|
|
1349 |
|
|
1350 |
if (m_verboseMode)
|
|
1351 |
printf(" -(lance) qt3_drawArc(%d, %d, %d, %d, %d, %d)\n", x, y, w, h, angle, sweep);
|
|
1352 |
|
|
1353 |
static_cast<Q3Painter*>(m_painter)->drawArc(x, y, w, h, angle, sweep);
|
|
1354 |
#endif
|
|
1355 |
}
|
|
1356 |
#endif //QT3_SUPPORT
|
|
1357 |
/***************************************************************************************************/
|
|
1358 |
void PaintCommands::command_drawText(QRegExp re)
|
|
1359 |
{
|
|
1360 |
QStringList caps = re.capturedTexts();
|
|
1361 |
int x = convertToInt(caps.at(1));
|
|
1362 |
int y = convertToInt(caps.at(2));
|
|
1363 |
QString txt = caps.at(3);
|
|
1364 |
|
|
1365 |
if (m_verboseMode)
|
|
1366 |
printf(" -(lance) drawText(%d, %d, %s)\n", x, y, qPrintable(txt));
|
|
1367 |
|
|
1368 |
m_painter->drawText(x, y, txt);
|
|
1369 |
}
|
|
1370 |
|
|
1371 |
/***************************************************************************************************/
|
|
1372 |
void PaintCommands::command_noop(QRegExp)
|
|
1373 |
{
|
|
1374 |
if (m_verboseMode)
|
|
1375 |
printf(" -(lance) noop: %s\n", qPrintable(m_currentCommand));
|
|
1376 |
|
|
1377 |
if (!m_currentCommand.trimmed().isEmpty()) {
|
|
1378 |
fprintf(stderr, "unknown command: '%s'\n", qPrintable(m_currentCommand.trimmed()));
|
|
1379 |
}
|
|
1380 |
}
|
|
1381 |
|
|
1382 |
/***************************************************************************************************/
|
|
1383 |
void PaintCommands::command_path_addText(QRegExp re)
|
|
1384 |
{
|
|
1385 |
QStringList caps = re.capturedTexts();
|
|
1386 |
QString name = caps.at(1);
|
|
1387 |
double x = convertToDouble(caps.at(2));
|
|
1388 |
double y = convertToDouble(caps.at(3));
|
|
1389 |
QString text = caps.at(4);
|
|
1390 |
|
|
1391 |
if (m_verboseMode)
|
|
1392 |
printf(" -(lance) path_addText(%s, %.2f, %.2f, text=%s\n", qPrintable(name), x, y, qPrintable(text));
|
|
1393 |
|
|
1394 |
m_pathMap[name].addText(x, y, m_painter->font(), text);
|
|
1395 |
}
|
|
1396 |
|
|
1397 |
/***************************************************************************************************/
|
|
1398 |
void PaintCommands::command_path_addEllipse(QRegExp re)
|
|
1399 |
{
|
|
1400 |
QStringList caps = re.capturedTexts();
|
|
1401 |
QString name = caps.at(1);
|
|
1402 |
double x = convertToDouble(caps.at(2));
|
|
1403 |
double y = convertToDouble(caps.at(3));
|
|
1404 |
double w = convertToDouble(caps.at(4));
|
|
1405 |
double h = convertToDouble(caps.at(5));
|
|
1406 |
|
|
1407 |
if (m_verboseMode)
|
|
1408 |
printf(" -(lance) path_addEllipse(%s, %.2f, %.2f, %.2f, %.2f)\n", qPrintable(name), x, y, w, h);
|
|
1409 |
|
|
1410 |
m_pathMap[name].addEllipse(x, y, w, h);
|
|
1411 |
}
|
|
1412 |
|
|
1413 |
/***************************************************************************************************/
|
|
1414 |
void PaintCommands::command_path_addRect(QRegExp re)
|
|
1415 |
{
|
|
1416 |
QStringList caps = re.capturedTexts();
|
|
1417 |
QString name = caps.at(1);
|
|
1418 |
double x = convertToDouble(caps.at(2));
|
|
1419 |
double y = convertToDouble(caps.at(3));
|
|
1420 |
double w = convertToDouble(caps.at(4));
|
|
1421 |
double h = convertToDouble(caps.at(5));
|
|
1422 |
|
|
1423 |
if (m_verboseMode)
|
|
1424 |
printf(" -(lance) path_addRect(%s, %.2f, %.2f, %.2f, %.2f)\n", qPrintable(name), x, y, w, h);
|
|
1425 |
|
|
1426 |
m_pathMap[name].addRect(x, y, w, h);
|
|
1427 |
}
|
|
1428 |
|
|
1429 |
/***************************************************************************************************/
|
|
1430 |
void PaintCommands::command_path_addPolygon(QRegExp re)
|
|
1431 |
{
|
|
1432 |
static QRegExp separators("\\s");
|
|
1433 |
QStringList caps = re.capturedTexts();
|
|
1434 |
QString name = caps.at(1);
|
|
1435 |
QString cap = caps.at(2);
|
|
1436 |
QStringList numbers = cap.split(separators, QString::SkipEmptyParts);
|
|
1437 |
|
|
1438 |
QPolygonF array;
|
|
1439 |
for (int i=0; i + 1<numbers.size(); i+=2)
|
|
1440 |
array.append(QPointF(numbers.at(i).toFloat(),numbers.at(i+1).toFloat()));
|
|
1441 |
|
|
1442 |
if (m_verboseMode)
|
|
1443 |
printf(" -(lance) path_addPolygon(name=%s, size=%d)\n", qPrintable(name), array.size());
|
|
1444 |
|
|
1445 |
m_pathMap[name].addPolygon(array);
|
|
1446 |
}
|
|
1447 |
|
|
1448 |
/***************************************************************************************************/
|
|
1449 |
void PaintCommands::command_path_arcTo(QRegExp re)
|
|
1450 |
{
|
|
1451 |
QStringList caps = re.capturedTexts();
|
|
1452 |
QString name = caps.at(1);
|
|
1453 |
double x = convertToDouble(caps.at(2));
|
|
1454 |
double y = convertToDouble(caps.at(3));
|
|
1455 |
double w = convertToDouble(caps.at(4));
|
|
1456 |
double h = convertToDouble(caps.at(5));
|
|
1457 |
double angle = convertToDouble(caps.at(6));
|
|
1458 |
double length = convertToDouble(caps.at(7));
|
|
1459 |
|
|
1460 |
if (m_verboseMode)
|
|
1461 |
printf(" -(lance) path_arcTo(%s, %.2f, %.2f, %.2f, %.2f, angle=%.2f, len=%.2f)\n", qPrintable(name), x, y, w, h, angle, length);
|
|
1462 |
|
|
1463 |
m_pathMap[name].arcTo(x, y, w, h, angle, length);
|
|
1464 |
}
|
|
1465 |
|
|
1466 |
/***************************************************************************************************/
|
|
1467 |
void PaintCommands::command_path_createOutline(QRegExp re)
|
|
1468 |
{
|
|
1469 |
QStringList caps = re.capturedTexts();
|
|
1470 |
QString name = caps.at(1);
|
|
1471 |
QString newName = caps.at(2);
|
|
1472 |
QPen pen = m_painter->pen();
|
|
1473 |
|
|
1474 |
if (m_verboseMode)
|
|
1475 |
printf(" -(lance) path_createOutline(%s, name=%s, width=%d)\n",
|
|
1476 |
qPrintable(name), qPrintable(newName), pen.width());
|
|
1477 |
|
|
1478 |
if (!m_pathMap.contains(name)) {
|
|
1479 |
fprintf(stderr, "createOutline(), unknown path: %s\n", qPrintable(name));
|
|
1480 |
return;
|
|
1481 |
}
|
|
1482 |
QPainterPathStroker stroker;
|
|
1483 |
stroker.setWidth(pen.widthF());
|
|
1484 |
stroker.setDashPattern(pen.style());
|
|
1485 |
stroker.setCapStyle(pen.capStyle());
|
|
1486 |
stroker.setJoinStyle(pen.joinStyle());
|
|
1487 |
m_pathMap[newName] = stroker.createStroke(m_pathMap[name]);
|
|
1488 |
}
|
|
1489 |
|
|
1490 |
/***************************************************************************************************/
|
|
1491 |
void PaintCommands::command_path_cubicTo(QRegExp re)
|
|
1492 |
{
|
|
1493 |
QStringList caps = re.capturedTexts();
|
|
1494 |
QString name = caps.at(1);
|
|
1495 |
double x1 = convertToDouble(caps.at(2));
|
|
1496 |
double y1 = convertToDouble(caps.at(3));
|
|
1497 |
double x2 = convertToDouble(caps.at(4));
|
|
1498 |
double y2 = convertToDouble(caps.at(5));
|
|
1499 |
double x3 = convertToDouble(caps.at(6));
|
|
1500 |
double y3 = convertToDouble(caps.at(7));
|
|
1501 |
|
|
1502 |
if (m_verboseMode)
|
|
1503 |
printf(" -(lance) path_cubicTo(%s, (%.2f, %.2f), (%.2f, %.2f), (%.2f, %.2f))\n", qPrintable(name), x1, y1, x2, y2, x3, y3);
|
|
1504 |
|
|
1505 |
m_pathMap[name].cubicTo(x1, y1, x2, y2, x3, y3);
|
|
1506 |
}
|
|
1507 |
|
|
1508 |
/***************************************************************************************************/
|
|
1509 |
void PaintCommands::command_path_moveTo(QRegExp re)
|
|
1510 |
{
|
|
1511 |
QStringList caps = re.capturedTexts();
|
|
1512 |
QString name = caps.at(1);
|
|
1513 |
double x1 = convertToDouble(caps.at(2));
|
|
1514 |
double y1 = convertToDouble(caps.at(3));
|
|
1515 |
|
|
1516 |
if (m_verboseMode)
|
|
1517 |
printf(" -(lance) path_moveTo(%s, (%.2f, %.2f))\n", qPrintable(name), x1, y1);
|
|
1518 |
|
|
1519 |
m_pathMap[name].moveTo(x1, y1);
|
|
1520 |
}
|
|
1521 |
|
|
1522 |
/***************************************************************************************************/
|
|
1523 |
void PaintCommands::command_path_lineTo(QRegExp re)
|
|
1524 |
{
|
|
1525 |
QStringList caps = re.capturedTexts();
|
|
1526 |
QString name = caps.at(1);
|
|
1527 |
double x1 = convertToDouble(caps.at(2));
|
|
1528 |
double y1 = convertToDouble(caps.at(3));
|
|
1529 |
|
|
1530 |
if (m_verboseMode)
|
|
1531 |
printf(" -(lance) path_lineTo(%s, (%.2f, %.2f))\n", qPrintable(name), x1, y1);
|
|
1532 |
|
|
1533 |
m_pathMap[name].lineTo(x1, y1);
|
|
1534 |
}
|
|
1535 |
|
|
1536 |
/***************************************************************************************************/
|
|
1537 |
void PaintCommands::command_path_setFillRule(QRegExp re)
|
|
1538 |
{
|
|
1539 |
QStringList caps = re.capturedTexts();
|
|
1540 |
QString name = caps.at(1);
|
|
1541 |
bool winding = caps.at(2).toLower() == "winding";
|
|
1542 |
|
|
1543 |
if (m_verboseMode)
|
|
1544 |
printf(" -(lance) path_setFillRule(name=%s, winding=%d)\n", qPrintable(name), winding);
|
|
1545 |
|
|
1546 |
m_pathMap[name].setFillRule(winding ? Qt::WindingFill : Qt::OddEvenFill);
|
|
1547 |
}
|
|
1548 |
|
|
1549 |
/***************************************************************************************************/
|
|
1550 |
void PaintCommands::command_path_closeSubpath(QRegExp re)
|
|
1551 |
{
|
|
1552 |
QStringList caps = re.capturedTexts();
|
|
1553 |
QString name = caps.at(1);
|
|
1554 |
|
|
1555 |
if (m_verboseMode)
|
|
1556 |
printf(" -(lance) path_closeSubpath(name=%s)\n", qPrintable(name));
|
|
1557 |
|
|
1558 |
m_pathMap[name].closeSubpath();
|
|
1559 |
}
|
|
1560 |
|
|
1561 |
/***************************************************************************************************/
|
|
1562 |
void PaintCommands::command_path_getClipPath(QRegExp re)
|
|
1563 |
{
|
|
1564 |
QStringList caps = re.capturedTexts();
|
|
1565 |
QString name = caps.at(1);
|
|
1566 |
|
|
1567 |
if (m_verboseMode)
|
|
1568 |
printf(" -(lance) path_closeSubpath(name=%s)\n", qPrintable(name));
|
|
1569 |
|
|
1570 |
m_pathMap[name] = m_painter->clipPath();
|
|
1571 |
}
|
|
1572 |
|
|
1573 |
/***************************************************************************************************/
|
|
1574 |
static void qt_debug_path(const QPainterPath &path, const QString &name)
|
|
1575 |
{
|
|
1576 |
const char *names[] = {
|
|
1577 |
"MoveTo ",
|
|
1578 |
"LineTo ",
|
|
1579 |
"CurveTo ",
|
|
1580 |
"CurveToData"
|
|
1581 |
};
|
|
1582 |
|
|
1583 |
printf("\nQPainterPath (%s): elementCount=%d\n", qPrintable(name), path.elementCount());
|
|
1584 |
for (int i=0; i<path.elementCount(); ++i) {
|
|
1585 |
const QPainterPath::Element &e = path.elementAt(i);
|
|
1586 |
Q_ASSERT(e.type >= 0 && e.type <= QPainterPath::CurveToDataElement);
|
|
1587 |
printf(" - %3d:: %s, (%.2f, %.2f)\n", i, names[e.type], e.x, e.y);
|
|
1588 |
}
|
|
1589 |
}
|
|
1590 |
|
|
1591 |
/***************************************************************************************************/
|
|
1592 |
void PaintCommands::command_path_debugPrint(QRegExp re)
|
|
1593 |
{
|
|
1594 |
QStringList caps = re.capturedTexts();
|
|
1595 |
QString name = caps.at(1);
|
|
1596 |
qt_debug_path(m_pathMap[name], name);
|
|
1597 |
}
|
|
1598 |
|
|
1599 |
/***************************************************************************************************/
|
|
1600 |
void PaintCommands::command_region_addRect(QRegExp re)
|
|
1601 |
{
|
|
1602 |
QStringList caps = re.capturedTexts();
|
|
1603 |
QString name = caps.at(1);
|
|
1604 |
int x = convertToInt(caps.at(2));
|
|
1605 |
int y = convertToInt(caps.at(3));
|
|
1606 |
int w = convertToInt(caps.at(4));
|
|
1607 |
int h = convertToInt(caps.at(5));
|
|
1608 |
|
|
1609 |
if (m_verboseMode)
|
|
1610 |
printf(" -(lance) region_addRect(%s, %d, %d, %d, %d)\n", qPrintable(name), x, y, w, h);
|
|
1611 |
|
|
1612 |
m_regionMap[name] += QRect(x, y, w, h);
|
|
1613 |
}
|
|
1614 |
|
|
1615 |
/***************************************************************************************************/
|
|
1616 |
void PaintCommands::command_region_addEllipse(QRegExp re)
|
|
1617 |
{
|
|
1618 |
QStringList caps = re.capturedTexts();
|
|
1619 |
QString name = caps.at(1);
|
|
1620 |
int x = convertToInt(caps.at(2));
|
|
1621 |
int y = convertToInt(caps.at(3));
|
|
1622 |
int w = convertToInt(caps.at(4));
|
|
1623 |
int h = convertToInt(caps.at(5));
|
|
1624 |
|
|
1625 |
if (m_verboseMode)
|
|
1626 |
printf(" -(lance) region_addEllipse(%s, %d, %d, %d, %d)\n", qPrintable(name), x, y, w, h);
|
|
1627 |
|
|
1628 |
m_regionMap[name] += QRegion(x, y, w, h, QRegion::Ellipse);
|
|
1629 |
}
|
|
1630 |
|
|
1631 |
/***************************************************************************************************/
|
|
1632 |
void PaintCommands::command_region_getClipRegion(QRegExp re)
|
|
1633 |
{
|
|
1634 |
QStringList caps = re.capturedTexts();
|
|
1635 |
QString name = caps.at(1);
|
|
1636 |
QRegion region = m_painter->clipRegion();
|
|
1637 |
|
|
1638 |
if (m_verboseMode)
|
|
1639 |
printf(" -(lance) region_getClipRegion(name=%s), bounds=[%d, %d, %d, %d]\n", qPrintable(name),
|
|
1640 |
region.boundingRect().x(),
|
|
1641 |
region.boundingRect().y(),
|
|
1642 |
region.boundingRect().width(),
|
|
1643 |
region.boundingRect().height());
|
|
1644 |
|
|
1645 |
m_regionMap[name] = region;
|
|
1646 |
}
|
|
1647 |
|
|
1648 |
/***************************************************************************************************/
|
|
1649 |
void PaintCommands::command_resetMatrix(QRegExp)
|
|
1650 |
{
|
|
1651 |
if (m_verboseMode)
|
|
1652 |
printf(" -(lance) resetMatrix()\n");
|
|
1653 |
|
|
1654 |
m_painter->resetTransform();
|
|
1655 |
}
|
|
1656 |
|
|
1657 |
/***************************************************************************************************/
|
|
1658 |
void PaintCommands::command_restore(QRegExp)
|
|
1659 |
{
|
|
1660 |
if (m_verboseMode)
|
|
1661 |
printf(" -(lance) restore()\n");
|
|
1662 |
|
|
1663 |
m_painter->restore();
|
|
1664 |
}
|
|
1665 |
|
|
1666 |
/***************************************************************************************************/
|
|
1667 |
void PaintCommands::command_rotate(QRegExp re)
|
|
1668 |
{
|
|
1669 |
QStringList caps = re.capturedTexts();
|
|
1670 |
double angle = convertToDouble(caps.at(1));
|
|
1671 |
|
|
1672 |
if (m_verboseMode)
|
|
1673 |
printf(" -(lance) rotate(%.2f)\n", angle);
|
|
1674 |
|
|
1675 |
m_painter->rotate(angle);
|
|
1676 |
}
|
|
1677 |
|
|
1678 |
/***************************************************************************************************/
|
|
1679 |
void PaintCommands::command_rotate_x(QRegExp re)
|
|
1680 |
{
|
|
1681 |
QStringList caps = re.capturedTexts();
|
|
1682 |
double angle = convertToDouble(caps.at(1));
|
|
1683 |
|
|
1684 |
if (m_verboseMode)
|
|
1685 |
printf(" -(lance) rotate_x(%.2f)\n", angle);
|
|
1686 |
|
|
1687 |
QTransform transform;
|
|
1688 |
transform.rotate(angle, Qt::XAxis);
|
|
1689 |
m_painter->setTransform(transform, true);
|
|
1690 |
}
|
|
1691 |
|
|
1692 |
/***************************************************************************************************/
|
|
1693 |
void PaintCommands::command_rotate_y(QRegExp re)
|
|
1694 |
{
|
|
1695 |
QStringList caps = re.capturedTexts();
|
|
1696 |
double angle = convertToDouble(caps.at(1));
|
|
1697 |
|
|
1698 |
if (m_verboseMode)
|
|
1699 |
printf(" -(lance) rotate_y(%.2f)\n", angle);
|
|
1700 |
|
|
1701 |
QTransform transform;
|
|
1702 |
transform.rotate(angle, Qt::YAxis);
|
|
1703 |
m_painter->setTransform(transform, true);
|
|
1704 |
}
|
|
1705 |
|
|
1706 |
/***************************************************************************************************/
|
|
1707 |
void PaintCommands::command_save(QRegExp)
|
|
1708 |
{
|
|
1709 |
if (m_verboseMode)
|
|
1710 |
printf(" -(lance) save()\n");
|
|
1711 |
|
|
1712 |
m_painter->save();
|
|
1713 |
}
|
|
1714 |
|
|
1715 |
/***************************************************************************************************/
|
|
1716 |
void PaintCommands::command_mapQuadToQuad(QRegExp re)
|
|
1717 |
{
|
|
1718 |
QStringList caps = re.capturedTexts();
|
|
1719 |
double x1 = convertToDouble(caps.at(1));
|
|
1720 |
double y1 = convertToDouble(caps.at(2));
|
|
1721 |
double x2 = convertToDouble(caps.at(3));
|
|
1722 |
double y2 = convertToDouble(caps.at(4));
|
|
1723 |
double x3 = convertToDouble(caps.at(5));
|
|
1724 |
double y3 = convertToDouble(caps.at(6));
|
|
1725 |
double x4 = convertToDouble(caps.at(7));
|
|
1726 |
double y4 = convertToDouble(caps.at(8));
|
|
1727 |
QPolygonF poly1(4);
|
|
1728 |
poly1[0] = QPointF(x1, y1);
|
|
1729 |
poly1[1] = QPointF(x2, y2);
|
|
1730 |
poly1[2] = QPointF(x3, y3);
|
|
1731 |
poly1[3] = QPointF(x4, y4);
|
|
1732 |
|
|
1733 |
double x5 = convertToDouble(caps.at(9));
|
|
1734 |
double y5 = convertToDouble(caps.at(10));
|
|
1735 |
double x6 = convertToDouble(caps.at(11));
|
|
1736 |
double y6 = convertToDouble(caps.at(12));
|
|
1737 |
double x7 = convertToDouble(caps.at(13));
|
|
1738 |
double y7 = convertToDouble(caps.at(14));
|
|
1739 |
double x8 = convertToDouble(caps.at(15));
|
|
1740 |
double y8 = convertToDouble(caps.at(16));
|
|
1741 |
QPolygonF poly2(4);
|
|
1742 |
poly2[0] = QPointF(x5, y5);
|
|
1743 |
poly2[1] = QPointF(x6, y6);
|
|
1744 |
poly2[2] = QPointF(x7, y7);
|
|
1745 |
poly2[3] = QPointF(x8, y8);
|
|
1746 |
|
|
1747 |
if (m_verboseMode)
|
|
1748 |
printf(" -(lance) mapQuadToQuad(%.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f ->\n\t"
|
|
1749 |
",%.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
|
|
1750 |
x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6, x7, y7, x8, y8);
|
|
1751 |
|
|
1752 |
QTransform trans;
|
|
1753 |
|
|
1754 |
if (!QTransform::quadToQuad(poly1, poly2, trans)) {
|
|
1755 |
qWarning("Couldn't perform quad to quad transformation!");
|
|
1756 |
}
|
|
1757 |
|
|
1758 |
m_painter->setTransform(trans, true);
|
|
1759 |
}
|
|
1760 |
|
|
1761 |
/***************************************************************************************************/
|
|
1762 |
void PaintCommands::command_setMatrix(QRegExp re)
|
|
1763 |
{
|
|
1764 |
QStringList caps = re.capturedTexts();
|
|
1765 |
double m11 = convertToDouble(caps.at(1));
|
|
1766 |
double m12 = convertToDouble(caps.at(2));
|
|
1767 |
double m13 = convertToDouble(caps.at(3));
|
|
1768 |
double m21 = convertToDouble(caps.at(4));
|
|
1769 |
double m22 = convertToDouble(caps.at(5));
|
|
1770 |
double m23 = convertToDouble(caps.at(6));
|
|
1771 |
double m31 = convertToDouble(caps.at(7));
|
|
1772 |
double m32 = convertToDouble(caps.at(8));
|
|
1773 |
double m33 = convertToDouble(caps.at(9));
|
|
1774 |
|
|
1775 |
if (m_verboseMode)
|
|
1776 |
printf(" -(lance) setMatrix(%.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
|
|
1777 |
m11, m12, m13, m21, m22, m23, m31, m32, m33);
|
|
1778 |
|
|
1779 |
QTransform trans;
|
|
1780 |
trans.setMatrix(m11, m12, m13,
|
|
1781 |
m21, m22, m23,
|
|
1782 |
m31, m32, m33);
|
|
1783 |
|
|
1784 |
m_painter->setTransform(trans, true);
|
|
1785 |
}
|
|
1786 |
|
|
1787 |
/***************************************************************************************************/
|
|
1788 |
void PaintCommands::command_scale(QRegExp re)
|
|
1789 |
{
|
|
1790 |
QStringList caps = re.capturedTexts();
|
|
1791 |
double sx = convertToDouble(caps.at(1));
|
|
1792 |
double sy = convertToDouble(caps.at(2));
|
|
1793 |
|
|
1794 |
if (m_verboseMode)
|
|
1795 |
printf(" -(lance) scale(%.2f, %.2f)\n", sx, sy);
|
|
1796 |
|
|
1797 |
|
|
1798 |
m_painter->scale(sx, sy);
|
|
1799 |
}
|
|
1800 |
|
|
1801 |
/***************************************************************************************************/
|
|
1802 |
void PaintCommands::command_setBackground(QRegExp re)
|
|
1803 |
{
|
|
1804 |
QStringList caps = re.capturedTexts();
|
|
1805 |
QColor color = convertToColor(caps.at(1));
|
|
1806 |
QString pattern = caps.at(2);
|
|
1807 |
|
|
1808 |
int style = translateEnum(brushStyleTable, pattern, Qt::LinearGradientPattern);
|
|
1809 |
if (style < 0)
|
|
1810 |
style = Qt::SolidPattern;
|
|
1811 |
|
|
1812 |
if (m_verboseMode)
|
|
1813 |
printf(" -(lance) setBackground(%s, %s)\n", qPrintable(color.name()), qPrintable(pattern));
|
|
1814 |
|
|
1815 |
m_painter->setBackground(QBrush(color, Qt::BrushStyle(style)));
|
|
1816 |
}
|
|
1817 |
|
|
1818 |
/***************************************************************************************************/
|
|
1819 |
void PaintCommands::command_setOpacity(QRegExp re)
|
|
1820 |
{
|
|
1821 |
QStringList caps = re.capturedTexts();
|
|
1822 |
double opacity = convertToDouble(caps.at(1));
|
|
1823 |
|
|
1824 |
if (m_verboseMode)
|
|
1825 |
printf(" -(lance) setOpacity(%lf)\n", opacity);
|
|
1826 |
|
|
1827 |
m_painter->setOpacity(opacity);
|
|
1828 |
}
|
|
1829 |
|
|
1830 |
/***************************************************************************************************/
|
|
1831 |
void PaintCommands::command_setBgMode(QRegExp re)
|
|
1832 |
{
|
|
1833 |
QString cap = re.cap(2);
|
|
1834 |
Qt::BGMode mode = Qt::TransparentMode;
|
|
1835 |
if (cap.toLower() == QLatin1String("opaquemode") || cap.toLower() == QLatin1String("opaque"))
|
|
1836 |
mode = Qt::OpaqueMode;
|
|
1837 |
|
|
1838 |
if (m_verboseMode)
|
|
1839 |
printf(" -(lance) setBackgroundMode(%s)\n", mode == Qt::OpaqueMode ? "OpaqueMode" : "TransparentMode");
|
|
1840 |
|
|
1841 |
m_painter->setBackgroundMode(mode);
|
|
1842 |
}
|
|
1843 |
|
|
1844 |
/***************************************************************************************************/
|
|
1845 |
void PaintCommands::command_setBrush(QRegExp re)
|
|
1846 |
{
|
|
1847 |
QStringList caps = re.capturedTexts();
|
|
1848 |
|
|
1849 |
QPixmap pm = image_load<QPixmap>(caps.at(1));
|
|
1850 |
if (!pm.isNull()) { // Assume pixmap
|
|
1851 |
if (m_verboseMode)
|
|
1852 |
printf(" -(lance) setBrush(pixmap=%s, width=%d, height=%d)\n",
|
|
1853 |
qPrintable(caps.at(1)), pm.width(), pm.height());
|
|
1854 |
|
|
1855 |
m_painter->setBrush(QBrush(pm));
|
|
1856 |
} else if (caps.at(1).toLower() == "nobrush") {
|
|
1857 |
m_painter->setBrush(Qt::NoBrush);
|
|
1858 |
if (m_verboseMode)
|
|
1859 |
printf(" -(lance) setBrush(Qt::NoBrush)\n");
|
|
1860 |
} else {
|
|
1861 |
QColor color = convertToColor(caps.at(1));
|
|
1862 |
QString pattern = caps.at(2);
|
|
1863 |
|
|
1864 |
int style = translateEnum(brushStyleTable, pattern, Qt::LinearGradientPattern);
|
|
1865 |
if (style < 0)
|
|
1866 |
style = Qt::SolidPattern;
|
|
1867 |
|
|
1868 |
if (m_verboseMode)
|
|
1869 |
printf(" -(lance) setBrush(%s, %s (%d))\n", qPrintable(color.name()), qPrintable(pattern), style);
|
|
1870 |
|
|
1871 |
m_painter->setBrush(QBrush(color, Qt::BrushStyle(style)));
|
|
1872 |
}
|
|
1873 |
}
|
|
1874 |
|
|
1875 |
/***************************************************************************************************/
|
|
1876 |
void PaintCommands::command_setBrushOrigin(QRegExp re)
|
|
1877 |
{
|
|
1878 |
int x = convertToInt(re.cap(1));
|
|
1879 |
int y = convertToInt(re.cap(2));
|
|
1880 |
|
|
1881 |
if (m_verboseMode)
|
|
1882 |
printf(" -(lance) setBrushOrigin(%d, %d)\n", x, y);
|
|
1883 |
|
|
1884 |
m_painter->setBrushOrigin(x, y);
|
|
1885 |
}
|
|
1886 |
|
|
1887 |
/***************************************************************************************************/
|
|
1888 |
void PaintCommands::command_brushTranslate(QRegExp re)
|
|
1889 |
{
|
|
1890 |
QStringList caps = re.capturedTexts();
|
|
1891 |
double dx = convertToDouble(caps.at(1));
|
|
1892 |
double dy = convertToDouble(caps.at(2));
|
|
1893 |
|
|
1894 |
if (m_verboseMode)
|
|
1895 |
printf(" -(lance) brushTranslate(%f, %f)\n", dx, dy);
|
|
1896 |
|
|
1897 |
QBrush new_brush = m_painter->brush();
|
|
1898 |
QTransform brush_matrix = new_brush.transform();
|
|
1899 |
brush_matrix.translate(dx, dy);
|
|
1900 |
new_brush.setTransform(brush_matrix);
|
|
1901 |
m_painter->setBrush(new_brush);
|
|
1902 |
}
|
|
1903 |
|
|
1904 |
/***************************************************************************************************/
|
|
1905 |
void PaintCommands::command_brushScale(QRegExp re)
|
|
1906 |
{
|
|
1907 |
QStringList caps = re.capturedTexts();
|
|
1908 |
double sx = convertToDouble(caps.at(1));
|
|
1909 |
double sy = convertToDouble(caps.at(2));
|
|
1910 |
|
|
1911 |
if (m_verboseMode)
|
|
1912 |
printf(" -(lance) brushScale(%f, %f)\n", sx, sy);
|
|
1913 |
|
|
1914 |
QBrush new_brush = m_painter->brush();
|
|
1915 |
QTransform brush_matrix = new_brush.transform();
|
|
1916 |
brush_matrix.scale(sx, sy);
|
|
1917 |
new_brush.setTransform(brush_matrix);
|
|
1918 |
m_painter->setBrush(new_brush);
|
|
1919 |
}
|
|
1920 |
|
|
1921 |
/***************************************************************************************************/
|
|
1922 |
void PaintCommands::command_brushRotate(QRegExp re)
|
|
1923 |
{
|
|
1924 |
QStringList caps = re.capturedTexts();
|
|
1925 |
double rot = convertToDouble(caps.at(1));
|
|
1926 |
|
|
1927 |
if (m_verboseMode)
|
|
1928 |
printf(" -(lance) brushScale(%f)\n", rot);
|
|
1929 |
|
|
1930 |
QBrush new_brush = m_painter->brush();
|
|
1931 |
QTransform brush_matrix = new_brush.transform();
|
|
1932 |
brush_matrix.rotate(rot);
|
|
1933 |
new_brush.setTransform(brush_matrix);
|
|
1934 |
m_painter->setBrush(new_brush);
|
|
1935 |
}
|
|
1936 |
|
|
1937 |
/***************************************************************************************************/
|
|
1938 |
void PaintCommands::command_brushShear(QRegExp re)
|
|
1939 |
{
|
|
1940 |
QStringList caps = re.capturedTexts();
|
|
1941 |
double sx = convertToDouble(caps.at(1));
|
|
1942 |
double sy = convertToDouble(caps.at(2));
|
|
1943 |
|
|
1944 |
if (m_verboseMode)
|
|
1945 |
printf(" -(lance) brushShear(%f, %f)\n", sx, sy);
|
|
1946 |
|
|
1947 |
QBrush new_brush = m_painter->brush();
|
|
1948 |
QTransform brush_matrix = new_brush.transform();
|
|
1949 |
brush_matrix.shear(sx, sy);
|
|
1950 |
new_brush.setTransform(brush_matrix);
|
|
1951 |
m_painter->setBrush(new_brush);
|
|
1952 |
}
|
|
1953 |
|
|
1954 |
/***************************************************************************************************/
|
|
1955 |
void PaintCommands::command_setClipping(QRegExp re)
|
|
1956 |
{
|
|
1957 |
bool clipping = re.cap(1).toLower() == "true";
|
|
1958 |
|
|
1959 |
if (m_verboseMode)
|
|
1960 |
printf(" -(lance) setClipping(%d)\n", clipping);
|
|
1961 |
|
|
1962 |
m_painter->setClipping(clipping);
|
|
1963 |
}
|
|
1964 |
|
|
1965 |
/***************************************************************************************************/
|
|
1966 |
void PaintCommands::command_setClipRect(QRegExp re)
|
|
1967 |
{
|
|
1968 |
QStringList caps = re.capturedTexts();
|
|
1969 |
int x = convertToInt(caps.at(1));
|
|
1970 |
int y = convertToInt(caps.at(2));
|
|
1971 |
int w = convertToInt(caps.at(3));
|
|
1972 |
int h = convertToInt(caps.at(4));
|
|
1973 |
|
|
1974 |
int combine = translateEnum(clipOperationTable, caps.at(5), Qt::UniteClip + 1);
|
|
1975 |
if (combine == -1)
|
|
1976 |
combine = Qt::ReplaceClip;
|
|
1977 |
|
|
1978 |
if (m_verboseMode)
|
|
1979 |
printf(" -(lance) setClipRect(%d, %d, %d, %d), %s\n", x, y, w, h, clipOperationTable[combine]);
|
|
1980 |
|
|
1981 |
m_painter->setClipRect(x, y, w, h, Qt::ClipOperation(combine));
|
|
1982 |
}
|
|
1983 |
|
|
1984 |
/***************************************************************************************************/
|
|
1985 |
void PaintCommands::command_setClipPath(QRegExp re)
|
|
1986 |
{
|
|
1987 |
int combine = translateEnum(clipOperationTable, re.cap(2), Qt::UniteClip + 1);
|
|
1988 |
if (combine == -1)
|
|
1989 |
combine = Qt::ReplaceClip;
|
|
1990 |
|
|
1991 |
if (m_verboseMode)
|
|
1992 |
printf(" -(lance) setClipPath(name=%s), %s\n", qPrintable(re.cap(1)), clipOperationTable[combine]);
|
|
1993 |
|
|
1994 |
if (!m_pathMap.contains(re.cap(1)))
|
|
1995 |
fprintf(stderr, " - setClipPath, no such path");
|
|
1996 |
m_painter->setClipPath(m_pathMap[re.cap(1)], Qt::ClipOperation(combine));
|
|
1997 |
}
|
|
1998 |
|
|
1999 |
/***************************************************************************************************/
|
|
2000 |
void PaintCommands::command_setClipRegion(QRegExp re)
|
|
2001 |
{
|
|
2002 |
int combine = translateEnum(clipOperationTable, re.cap(2), Qt::UniteClip + 1);
|
|
2003 |
if (combine == -1)
|
|
2004 |
combine = Qt::ReplaceClip;
|
|
2005 |
QRegion r = m_regionMap[re.cap(1)];
|
|
2006 |
|
|
2007 |
if (m_verboseMode)
|
|
2008 |
printf(" -(lance) setClipRegion(name=%s), bounds=[%d, %d, %d, %d], %s\n",
|
|
2009 |
qPrintable(re.cap(1)),
|
|
2010 |
r.boundingRect().x(),
|
|
2011 |
r.boundingRect().y(),
|
|
2012 |
r.boundingRect().width(),
|
|
2013 |
r.boundingRect().height(),
|
|
2014 |
clipOperationTable[combine]);
|
|
2015 |
|
|
2016 |
m_painter->setClipRegion(m_regionMap[re.cap(1)], Qt::ClipOperation(combine));
|
|
2017 |
}
|
|
2018 |
|
|
2019 |
/***************************************************************************************************/
|
|
2020 |
void PaintCommands::command_setFont(QRegExp re)
|
|
2021 |
{
|
|
2022 |
QStringList caps = re.capturedTexts();
|
|
2023 |
QString family = caps.at(1);
|
|
2024 |
int size = convertToInt(caps.at(2));
|
|
2025 |
|
|
2026 |
int weight = translateEnum(fontWeightTable, re.cap(3).toLower(), 5);
|
|
2027 |
if (weight != -1) {
|
|
2028 |
switch (weight) {
|
|
2029 |
case 0: weight = QFont::Light; break;
|
|
2030 |
case 1: weight = QFont::Normal; break;
|
|
2031 |
case 2: weight = QFont::DemiBold; break;
|
|
2032 |
case 3: weight = QFont::Bold; break;
|
|
2033 |
case 4: weight = QFont::Black; break;
|
|
2034 |
}
|
|
2035 |
} else {
|
|
2036 |
weight = convertToInt(re.cap(3));
|
|
2037 |
}
|
|
2038 |
|
|
2039 |
bool italic = caps.at(4).toLower() == "true" || caps.at(4).toLower() == "italic";
|
|
2040 |
|
|
2041 |
if (m_verboseMode)
|
|
2042 |
printf(" -(lance) setFont(family=%s, size=%d, weight=%d, italic=%d\n",
|
|
2043 |
qPrintable(family), size, weight, italic);
|
|
2044 |
|
|
2045 |
m_painter->setFont(QFont(family, size, weight, italic));
|
|
2046 |
}
|
|
2047 |
|
|
2048 |
/***************************************************************************************************/
|
|
2049 |
void PaintCommands::command_setPen(QRegExp re)
|
|
2050 |
{
|
|
2051 |
QString cap = re.cap(1);
|
|
2052 |
int style = translateEnum(penStyleTable, cap, Qt::DashDotDotLine + 1);
|
|
2053 |
if (style >= 0) {
|
|
2054 |
if (m_verboseMode)
|
|
2055 |
printf(" -(lance) setPen(%s)\n", qPrintable(cap));
|
|
2056 |
|
|
2057 |
m_painter->setPen(Qt::PenStyle(style));
|
|
2058 |
} else if (cap.toLower() == "brush") {
|
|
2059 |
QPen pen(m_painter->brush(), 0);
|
|
2060 |
if (m_verboseMode) {
|
|
2061 |
printf(" -(lance) setPen(brush), style=%d, color=%08x\n",
|
|
2062 |
pen.brush().style(), pen.color().rgba());
|
|
2063 |
}
|
|
2064 |
m_painter->setPen(pen);
|
|
2065 |
} else {
|
|
2066 |
QColor color = convertToColor(cap);
|
|
2067 |
if (m_verboseMode)
|
|
2068 |
printf(" -(lance) setPen(%s)\n", qPrintable(color.name()));
|
|
2069 |
|
|
2070 |
m_painter->setPen(color);
|
|
2071 |
}
|
|
2072 |
}
|
|
2073 |
|
|
2074 |
/***************************************************************************************************/
|
|
2075 |
void PaintCommands::command_setPen2(QRegExp re)
|
|
2076 |
{
|
|
2077 |
QStringList caps = re.capturedTexts();
|
|
2078 |
|
|
2079 |
QBrush brush;
|
|
2080 |
|
|
2081 |
if (caps.at(1).toLower() == "brush")
|
|
2082 |
brush = m_painter->brush();
|
|
2083 |
else
|
|
2084 |
brush = convertToColor(caps.at(1));
|
|
2085 |
|
|
2086 |
double width = convertToDouble(caps.at(2));
|
|
2087 |
int penStyle = translateEnum(penStyleTable, caps.at(3), Qt::DashDotDotLine + 1);
|
|
2088 |
if (penStyle < 0)
|
|
2089 |
penStyle = Qt::SolidLine;
|
|
2090 |
|
|
2091 |
Qt::PenCapStyle capStyle = Qt::SquareCap;
|
|
2092 |
if (caps.at(4).toLower() == "flatcap") capStyle = Qt::FlatCap;
|
|
2093 |
else if (caps.at(4).toLower() == "squarecap") capStyle = Qt::SquareCap;
|
|
2094 |
else if (caps.at(4).toLower() == "roundcap") capStyle = Qt::RoundCap;
|
|
2095 |
else if (!caps.at(4).isEmpty())
|
|
2096 |
fprintf(stderr, "ERROR: setPen, unknown capStyle: %s\n", qPrintable(caps.at(4)));
|
|
2097 |
|
|
2098 |
Qt::PenJoinStyle joinStyle = Qt::BevelJoin;
|
|
2099 |
if (caps.at(5).toLower() == "miterjoin") joinStyle = Qt::MiterJoin;
|
|
2100 |
else if (caps.at(5).toLower() == "beveljoin") joinStyle = Qt::BevelJoin;
|
|
2101 |
else if (caps.at(5).toLower() == "roundjoin") joinStyle = Qt::RoundJoin;
|
|
2102 |
else if (!caps.at(5).isEmpty())
|
|
2103 |
fprintf(stderr, "ERROR: setPen, unknown joinStyle: %s\n", qPrintable(caps.at(5)));
|
|
2104 |
|
|
2105 |
if (m_verboseMode)
|
|
2106 |
printf(" -(lance) setPen(%s, width=%f, style=%d, cap=%d, join=%d)\n",
|
|
2107 |
qPrintable(brush.color().name()), width, penStyle, capStyle, joinStyle);
|
|
2108 |
|
|
2109 |
m_painter->setPen(QPen(brush, width, Qt::PenStyle(penStyle), capStyle, joinStyle));
|
|
2110 |
}
|
|
2111 |
|
|
2112 |
/***************************************************************************************************/
|
|
2113 |
void PaintCommands::command_setRenderHint(QRegExp re)
|
|
2114 |
{
|
|
2115 |
QString hintString = re.cap(1).toLower();
|
|
2116 |
bool on = re.cap(2).isEmpty() || re.cap(2).toLower() == "true";
|
|
2117 |
if (hintString.contains("antialiasing")) {
|
|
2118 |
if (m_verboseMode)
|
|
2119 |
printf(" -(lance) setRenderHint Antialiasing\n");
|
|
2120 |
|
|
2121 |
m_painter->setRenderHint(QPainter::Antialiasing, on);
|
|
2122 |
} else if (hintString.contains("smoothpixmaptransform")) {
|
|
2123 |
if (m_verboseMode)
|
|
2124 |
printf(" -(lance) setRenderHint SmoothPixmapTransform\n");
|
|
2125 |
m_painter->setRenderHint(QPainter::SmoothPixmapTransform, on);
|
|
2126 |
} else {
|
|
2127 |
fprintf(stderr, "ERROR(setRenderHint): unknown hint '%s'\n", qPrintable(hintString));
|
|
2128 |
}
|
|
2129 |
}
|
|
2130 |
|
|
2131 |
/***************************************************************************************************/
|
|
2132 |
void PaintCommands::command_clearRenderHint(QRegExp /*re*/)
|
|
2133 |
{
|
|
2134 |
m_painter->setRenderHint(QPainter::Antialiasing, false);
|
|
2135 |
m_painter->setRenderHint(QPainter::SmoothPixmapTransform, false);
|
|
2136 |
if (m_verboseMode)
|
|
2137 |
printf(" -(lance) clearRenderHint\n");
|
|
2138 |
}
|
|
2139 |
|
|
2140 |
/***************************************************************************************************/
|
|
2141 |
void PaintCommands::command_setCompositionMode(QRegExp re)
|
|
2142 |
{
|
|
2143 |
QString modeString = re.cap(1).toLower();
|
|
2144 |
int mode = translateEnum(compositionModeTable, modeString, 33);
|
|
2145 |
|
|
2146 |
if (mode < 0 || mode > QPainter::RasterOp_SourceAndNotDestination) {
|
|
2147 |
fprintf(stderr, "ERROR: invalid mode: %s\n", qPrintable(modeString));
|
|
2148 |
return;
|
|
2149 |
}
|
|
2150 |
|
|
2151 |
if (m_verboseMode)
|
|
2152 |
printf(" -(lance) setCompositionMode: %d: %s\n", mode, qPrintable(modeString));
|
|
2153 |
|
|
2154 |
m_painter->setCompositionMode(QPainter::CompositionMode(mode));
|
|
2155 |
}
|
|
2156 |
|
|
2157 |
/***************************************************************************************************/
|
|
2158 |
void PaintCommands::command_translate(QRegExp re)
|
|
2159 |
{
|
|
2160 |
QStringList caps = re.capturedTexts();
|
|
2161 |
double dx = convertToDouble(caps.at(1));
|
|
2162 |
double dy = convertToDouble(caps.at(2));
|
|
2163 |
|
|
2164 |
if (m_verboseMode)
|
|
2165 |
printf(" -(lance) translate(%f, %f)\n", dx, dy);
|
|
2166 |
|
|
2167 |
m_painter->translate(dx, dy);
|
|
2168 |
}
|
|
2169 |
|
|
2170 |
/***************************************************************************************************/
|
|
2171 |
void PaintCommands::command_pixmap_load(QRegExp re)
|
|
2172 |
{
|
|
2173 |
QStringList caps = re.capturedTexts();
|
|
2174 |
|
|
2175 |
QString fileName = caps.at(1);
|
|
2176 |
QString name = caps.at(2);
|
|
2177 |
|
|
2178 |
if (name.isEmpty())
|
|
2179 |
name = fileName;
|
|
2180 |
|
|
2181 |
QImage im = image_load<QImage>(fileName);
|
|
2182 |
QPixmap px = QPixmap::fromImage(im, Qt::OrderedDither | Qt::OrderedAlphaDither);
|
|
2183 |
|
|
2184 |
if (m_verboseMode)
|
|
2185 |
printf(" -(lance) pixmap_load(%s as %s), size=[%d, %d], depth=%d\n",
|
|
2186 |
qPrintable(fileName), qPrintable(name),
|
|
2187 |
px.width(), px.height(), px.depth());
|
|
2188 |
|
|
2189 |
m_pixmapMap[name] = px;
|
|
2190 |
}
|
|
2191 |
|
|
2192 |
/***************************************************************************************************/
|
|
2193 |
void PaintCommands::command_bitmap_load(QRegExp re)
|
|
2194 |
{
|
|
2195 |
QStringList caps = re.capturedTexts();
|
|
2196 |
|
|
2197 |
QString fileName = caps.at(1);
|
|
2198 |
QString name = caps.at(2);
|
|
2199 |
|
|
2200 |
if (name.isEmpty())
|
|
2201 |
name = fileName;
|
|
2202 |
|
|
2203 |
QBitmap bm = image_load<QBitmap>(fileName);
|
|
2204 |
|
|
2205 |
if (m_verboseMode)
|
|
2206 |
printf(" -(lance) bitmap_load(%s as %s), size=[%d, %d], depth=%d\n",
|
|
2207 |
qPrintable(fileName), qPrintable(name),
|
|
2208 |
bm.width(), bm.height(), bm.depth());
|
|
2209 |
|
|
2210 |
m_pixmapMap[name] = bm;
|
|
2211 |
}
|
|
2212 |
|
|
2213 |
/***************************************************************************************************/
|
|
2214 |
void PaintCommands::command_pixmap_setMask(QRegExp re)
|
|
2215 |
{
|
|
2216 |
QStringList caps = re.capturedTexts();
|
|
2217 |
QBitmap mask = image_load<QBitmap>(caps.at(2));
|
|
2218 |
|
|
2219 |
if (m_verboseMode)
|
|
2220 |
printf(" -(lance) pixmap_setMask(%s, %s)\n", qPrintable(caps.at(1)), qPrintable(caps.at(2)));
|
|
2221 |
|
|
2222 |
if (!m_pixmapMap[caps.at(1)].isNull())
|
|
2223 |
m_pixmapMap[caps.at(1)].setMask(mask);
|
|
2224 |
}
|
|
2225 |
|
|
2226 |
/***************************************************************************************************/
|
|
2227 |
void PaintCommands::command_image_load(QRegExp re)
|
|
2228 |
{
|
|
2229 |
QStringList caps = re.capturedTexts();
|
|
2230 |
|
|
2231 |
QString fileName = caps.at(1);
|
|
2232 |
QString name = caps.at(2);
|
|
2233 |
|
|
2234 |
if (name.isEmpty())
|
|
2235 |
name = fileName;
|
|
2236 |
|
|
2237 |
QImage image = image_load<QImage>(fileName);
|
|
2238 |
|
|
2239 |
if (m_verboseMode)
|
|
2240 |
printf(" -(lance) image_load(%s as %s), size=[%d, %d], format=%d\n",
|
|
2241 |
qPrintable(fileName), qPrintable(name),
|
|
2242 |
image.width(), image.height(), image.format());
|
|
2243 |
|
|
2244 |
m_imageMap[name] = image;
|
|
2245 |
}
|
|
2246 |
|
|
2247 |
/***************************************************************************************************/
|
|
2248 |
void PaintCommands::command_image_setNumColors(QRegExp re)
|
|
2249 |
{
|
|
2250 |
QStringList caps = re.capturedTexts();
|
|
2251 |
|
|
2252 |
QString name = caps.at(1);
|
|
2253 |
int count = convertToInt(caps.at(2));
|
|
2254 |
|
|
2255 |
if (m_verboseMode)
|
|
2256 |
printf(" -(lance) image_setNumColors(%s), %d -> %d\n",
|
|
2257 |
qPrintable(name), m_imageMap[name].numColors(), count);
|
|
2258 |
|
|
2259 |
m_imageMap[name].setNumColors(count);
|
|
2260 |
}
|
|
2261 |
|
|
2262 |
/***************************************************************************************************/
|
|
2263 |
void PaintCommands::command_image_setColor(QRegExp re)
|
|
2264 |
{
|
|
2265 |
QStringList caps = re.capturedTexts();
|
|
2266 |
|
|
2267 |
QString name = caps.at(1);
|
|
2268 |
int index = convertToInt(caps.at(2));
|
|
2269 |
QColor color = convertToColor(caps.at(3));
|
|
2270 |
|
|
2271 |
if (m_verboseMode)
|
|
2272 |
printf(" -(lance) image_setColor(%s), %d = %08x\n", qPrintable(name), index, color.rgba());
|
|
2273 |
|
|
2274 |
m_imageMap[name].setColor(index, color.rgba());
|
|
2275 |
}
|
|
2276 |
|
|
2277 |
/***************************************************************************************************/
|
|
2278 |
void PaintCommands::command_abort(QRegExp)
|
|
2279 |
{
|
|
2280 |
m_abort = true;
|
|
2281 |
}
|
|
2282 |
|
|
2283 |
/***************************************************************************************************/
|
|
2284 |
void PaintCommands::command_gradient_clearStops(QRegExp)
|
|
2285 |
{
|
|
2286 |
if (m_verboseMode)
|
|
2287 |
printf(" -(lance) gradient_clearStops\n");
|
|
2288 |
m_gradientStops.clear();
|
|
2289 |
}
|
|
2290 |
|
|
2291 |
/***************************************************************************************************/
|
|
2292 |
void PaintCommands::command_gradient_appendStop(QRegExp re)
|
|
2293 |
{
|
|
2294 |
QStringList caps = re.capturedTexts();
|
|
2295 |
double pos = convertToDouble(caps.at(1));
|
|
2296 |
QColor color = convertToColor(caps.at(2));
|
|
2297 |
|
|
2298 |
if (m_verboseMode)
|
|
2299 |
printf(" -(lance) gradient_appendStop(%.2f, %x)\n", pos, color.rgba());
|
|
2300 |
|
|
2301 |
m_gradientStops << QGradientStop(pos, color);
|
|
2302 |
}
|
|
2303 |
|
|
2304 |
/***************************************************************************************************/
|
|
2305 |
void PaintCommands::command_gradient_setLinear(QRegExp re)
|
|
2306 |
{
|
|
2307 |
QStringList caps = re.capturedTexts();
|
|
2308 |
double x1 = convertToDouble(caps.at(1));
|
|
2309 |
double y1 = convertToDouble(caps.at(2));
|
|
2310 |
double x2 = convertToDouble(caps.at(3));
|
|
2311 |
double y2 = convertToDouble(caps.at(4));
|
|
2312 |
|
|
2313 |
if (m_verboseMode)
|
|
2314 |
printf(" -(lance) gradient_setLinear (%.2f, %.2f), (%.2f, %.2f), spread=%d\n",
|
|
2315 |
x1, y1, x2, y2, m_gradientSpread);
|
|
2316 |
|
|
2317 |
QLinearGradient lg(QPointF(x1, y1), QPointF(x2, y2));
|
|
2318 |
lg.setStops(m_gradientStops);
|
|
2319 |
lg.setSpread(m_gradientSpread);
|
|
2320 |
lg.setCoordinateMode(m_gradientCoordinate);
|
|
2321 |
QBrush brush(lg);
|
|
2322 |
QTransform brush_matrix = m_painter->brush().transform();
|
|
2323 |
brush.setTransform(brush_matrix);
|
|
2324 |
m_painter->setBrush(brush);
|
|
2325 |
}
|
|
2326 |
|
|
2327 |
/***************************************************************************************************/
|
|
2328 |
void PaintCommands::command_gradient_setLinearPen(QRegExp re)
|
|
2329 |
{
|
|
2330 |
QStringList caps = re.capturedTexts();
|
|
2331 |
double x1 = convertToDouble(caps.at(1));
|
|
2332 |
double y1 = convertToDouble(caps.at(2));
|
|
2333 |
double x2 = convertToDouble(caps.at(3));
|
|
2334 |
double y2 = convertToDouble(caps.at(4));
|
|
2335 |
|
|
2336 |
if (m_verboseMode)
|
|
2337 |
printf(" -(lance) gradient_setLinear (%.2f, %.2f), (%.2f, %.2f), spread=%d\n",
|
|
2338 |
x1, y1, x2, y2, m_gradientSpread);
|
|
2339 |
|
|
2340 |
QLinearGradient lg(QPointF(x1, y1), QPointF(x2, y2));
|
|
2341 |
lg.setStops(m_gradientStops);
|
|
2342 |
lg.setSpread(m_gradientSpread);
|
|
2343 |
lg.setCoordinateMode(m_gradientCoordinate);
|
|
2344 |
QPen pen = m_painter->pen();
|
|
2345 |
pen.setBrush(lg);
|
|
2346 |
m_painter->setPen(pen);
|
|
2347 |
}
|
|
2348 |
|
|
2349 |
/***************************************************************************************************/
|
|
2350 |
void PaintCommands::command_gradient_setRadial(QRegExp re)
|
|
2351 |
{
|
|
2352 |
QStringList caps = re.capturedTexts();
|
|
2353 |
double cx = convertToDouble(caps.at(1));
|
|
2354 |
double cy = convertToDouble(caps.at(2));
|
|
2355 |
double rad = convertToDouble(caps.at(3));
|
|
2356 |
double fx = convertToDouble(caps.at(4));
|
|
2357 |
double fy = convertToDouble(caps.at(5));
|
|
2358 |
|
|
2359 |
if (m_verboseMode)
|
|
2360 |
printf(" -(lance) gradient_setRadial center=(%.2f, %.2f), radius=%.2f focal=(%.2f, %.2f), "
|
|
2361 |
"spread=%d\n",
|
|
2362 |
cx, cy, rad, fx, fy, m_gradientSpread);
|
|
2363 |
|
|
2364 |
QRadialGradient rg(QPointF(cx, cy), rad, QPointF(fx, fy));
|
|
2365 |
rg.setStops(m_gradientStops);
|
|
2366 |
rg.setSpread(m_gradientSpread);
|
|
2367 |
rg.setCoordinateMode(m_gradientCoordinate);
|
|
2368 |
QBrush brush(rg);
|
|
2369 |
QTransform brush_matrix = m_painter->brush().transform();
|
|
2370 |
brush.setTransform(brush_matrix);
|
|
2371 |
m_painter->setBrush(brush);
|
|
2372 |
}
|
|
2373 |
|
|
2374 |
/***************************************************************************************************/
|
|
2375 |
void PaintCommands::command_gradient_setConical(QRegExp re)
|
|
2376 |
{
|
|
2377 |
QStringList caps = re.capturedTexts();
|
|
2378 |
double cx = convertToDouble(caps.at(1));
|
|
2379 |
double cy = convertToDouble(caps.at(2));
|
|
2380 |
double angle = convertToDouble(caps.at(3));
|
|
2381 |
|
|
2382 |
if (m_verboseMode) {
|
|
2383 |
printf(" -(lance) gradient_setConical center=(%.2f, %.2f), angle=%.2f\n, spread=%d",
|
|
2384 |
cx, cy, angle, m_gradientSpread);
|
|
2385 |
}
|
|
2386 |
|
|
2387 |
QConicalGradient cg(QPointF(cx, cy), angle);
|
|
2388 |
cg.setStops(m_gradientStops);
|
|
2389 |
cg.setSpread(m_gradientSpread);
|
|
2390 |
cg.setCoordinateMode(m_gradientCoordinate);
|
|
2391 |
QBrush brush(cg);
|
|
2392 |
QTransform brush_matrix = m_painter->brush().transform();
|
|
2393 |
brush.setTransform(brush_matrix);
|
|
2394 |
m_painter->setBrush(brush);
|
|
2395 |
}
|
|
2396 |
|
|
2397 |
/***************************************************************************************************/
|
|
2398 |
void PaintCommands::command_gradient_setSpread(QRegExp re)
|
|
2399 |
{
|
|
2400 |
int spreadMethod = translateEnum(spreadMethodTable, re.cap(1), 3);
|
|
2401 |
|
|
2402 |
if (m_verboseMode)
|
|
2403 |
printf(" -(lance) gradient_setSpread %d=[%s]\n", spreadMethod, spreadMethodTable[spreadMethod]);
|
|
2404 |
|
|
2405 |
m_gradientSpread = QGradient::Spread(spreadMethod);
|
|
2406 |
}
|
|
2407 |
|
|
2408 |
void PaintCommands::command_gradient_setCoordinateMode(QRegExp re)
|
|
2409 |
{
|
|
2410 |
int coord = translateEnum(coordinateMethodTable, re.cap(1), 3);
|
|
2411 |
|
|
2412 |
if (m_verboseMode)
|
|
2413 |
printf(" -(lance) gradient_setCoordinateMode %d=[%s]\n", coord,
|
|
2414 |
coordinateMethodTable[coord]);
|
|
2415 |
|
|
2416 |
m_gradientCoordinate = QGradient::CoordinateMode(coord);
|
|
2417 |
}
|
|
2418 |
|
|
2419 |
/***************************************************************************************************/
|
|
2420 |
void PaintCommands::command_surface_begin(QRegExp re)
|
|
2421 |
{
|
|
2422 |
QStringList caps = re.capturedTexts();
|
|
2423 |
double x = convertToDouble(caps.at(1));
|
|
2424 |
double y = convertToDouble(caps.at(2));
|
|
2425 |
double w = convertToDouble(caps.at(3));
|
|
2426 |
double h = convertToDouble(caps.at(4));
|
|
2427 |
|
|
2428 |
if (m_surface_painter) {
|
|
2429 |
fprintf(stderr, "ERROR: surface already active");
|
|
2430 |
return;
|
|
2431 |
}
|
|
2432 |
|
|
2433 |
if (m_verboseMode)
|
|
2434 |
printf(" -(lance) surface_begin, pos=[%.2f, %.2f], size=[%.2f, %.2f]\n", x, y, w, h);
|
|
2435 |
|
|
2436 |
m_surface_painter = m_painter;
|
|
2437 |
|
|
2438 |
if (m_type == OpenGLType || m_type == OpenGLPBufferType) {
|
|
2439 |
#ifndef QT_NO_OPENGL
|
|
2440 |
m_surface_pbuffer = new QGLPixelBuffer(qRound(w), qRound(h));
|
|
2441 |
m_painter = new QPainter(m_surface_pbuffer);
|
|
2442 |
m_painter->fillRect(QRect(0, 0, qRound(w), qRound(h)), Qt::transparent);
|
|
2443 |
#endif
|
|
2444 |
#ifdef Q_WS_X11
|
|
2445 |
} else if (m_type == WidgetType) {
|
|
2446 |
m_surface_pixmap = QPixmap(qRound(w), qRound(h));
|
|
2447 |
m_surface_pixmap.fill(Qt::transparent);
|
|
2448 |
m_painter = new QPainter(&m_surface_pixmap);
|
|
2449 |
#endif
|
|
2450 |
} else {
|
|
2451 |
m_surface_image = QImage(qRound(w), qRound(h), QImage::Format_ARGB32_Premultiplied);
|
|
2452 |
m_surface_image.fill(0);
|
|
2453 |
m_painter = new QPainter(&m_surface_image);
|
|
2454 |
}
|
|
2455 |
m_surface_rect = QRectF(x, y, w, h);
|
|
2456 |
}
|
|
2457 |
|
|
2458 |
/***************************************************************************************************/
|
|
2459 |
void PaintCommands::command_surface_end(QRegExp)
|
|
2460 |
{
|
|
2461 |
if (!m_surface_painter) {
|
|
2462 |
fprintf(stderr, "ERROR: surface not active");
|
|
2463 |
return;
|
|
2464 |
}
|
|
2465 |
|
|
2466 |
if (m_verboseMode)
|
|
2467 |
printf(" -(lance) surface_end, pos=[%.2f, %.2f], size=[%.2f, %.2f]\n",
|
|
2468 |
m_surface_rect.x(),
|
|
2469 |
m_surface_rect.y(),
|
|
2470 |
m_surface_rect.width(),
|
|
2471 |
m_surface_rect.height());
|
|
2472 |
m_painter->end();
|
|
2473 |
|
|
2474 |
delete m_painter;
|
|
2475 |
m_painter = m_surface_painter;
|
|
2476 |
m_surface_painter = 0;
|
|
2477 |
|
|
2478 |
if (m_type == OpenGLType || m_type == OpenGLPBufferType) {
|
|
2479 |
#ifndef QT_NO_OPENGL
|
|
2480 |
QImage image = m_surface_pbuffer->toImage();
|
|
2481 |
QImage new_image(image.bits(), image.width(),
|
|
2482 |
image.height(), QImage::Format_ARGB32_Premultiplied);
|
|
2483 |
QPaintDevice *pdev = m_painter->device();
|
|
2484 |
if (pdev->devType() == QInternal::Widget) {
|
|
2485 |
QWidget *w = static_cast<QWidget *>(pdev);
|
|
2486 |
static_cast<QGLWidget *>(w)->makeCurrent();
|
|
2487 |
} else if (pdev->devType() == QInternal::Pbuffer) {
|
|
2488 |
static_cast<QGLPixelBuffer *>(pdev)->makeCurrent();
|
|
2489 |
}
|
|
2490 |
|
|
2491 |
m_painter->drawImage(m_surface_rect, new_image);
|
|
2492 |
|
|
2493 |
delete m_surface_pbuffer;
|
|
2494 |
m_surface_pbuffer = 0;
|
|
2495 |
#endif
|
|
2496 |
#ifdef Q_WS_X11
|
|
2497 |
} else if (m_type == WidgetType) {
|
|
2498 |
m_painter->drawPixmap(m_surface_rect.topLeft(), m_surface_pixmap);
|
|
2499 |
m_surface_pixmap = QPixmap();
|
|
2500 |
#endif
|
|
2501 |
} else {
|
|
2502 |
m_painter->drawImage(m_surface_rect, m_surface_image);
|
|
2503 |
m_surface_image = QImage();
|
|
2504 |
}
|
|
2505 |
m_surface_rect = QRectF();
|
|
2506 |
}
|
|
2507 |
|
|
2508 |
/***************************************************************************************************/
|
|
2509 |
void PaintCommands::command_image_convertToFormat(QRegExp re)
|
|
2510 |
{
|
|
2511 |
QStringList caps = re.capturedTexts();
|
|
2512 |
|
|
2513 |
QString srcName = caps.at(1);
|
|
2514 |
QString destName = caps.at(2);
|
|
2515 |
|
|
2516 |
if (!m_imageMap.contains(srcName)) {
|
|
2517 |
fprintf(stderr, "ERROR(convertToFormat): no such image '%s'\n", qPrintable(srcName));
|
|
2518 |
return;
|
|
2519 |
}
|
|
2520 |
|
|
2521 |
int format = translateEnum(imageFormatTable, caps.at(3), QImage::NImageFormats);
|
|
2522 |
if (format < 0 || format >= QImage::NImageFormats) {
|
|
2523 |
fprintf(stderr, "ERROR(convertToFormat): invalid format %d = '%s'\n",
|
|
2524 |
format, qPrintable(caps.at(3)));
|
|
2525 |
return;
|
|
2526 |
}
|
|
2527 |
|
|
2528 |
QImage src = m_imageMap[srcName];
|
|
2529 |
QImage dest = src.convertToFormat(QImage::Format(format),
|
|
2530 |
Qt::OrderedAlphaDither | Qt::OrderedDither);
|
|
2531 |
|
|
2532 |
if (m_verboseMode) {
|
|
2533 |
printf(" -(lance) convertToFormat %s:%d -> %s:%d\n",
|
|
2534 |
qPrintable(srcName), src.format(),
|
|
2535 |
qPrintable(destName), dest.format());
|
|
2536 |
}
|
|
2537 |
|
|
2538 |
m_imageMap[destName] = dest;
|
|
2539 |
}
|
|
2540 |
|
|
2541 |
/***************************************************************************************************/
|
|
2542 |
void PaintCommands::command_textlayout_draw(QRegExp re)
|
|
2543 |
{
|
|
2544 |
QStringList caps = re.capturedTexts();
|
|
2545 |
|
|
2546 |
QString text = caps.at(1);
|
|
2547 |
double width = convertToDouble(caps.at(2));
|
|
2548 |
|
|
2549 |
if (m_verboseMode)
|
|
2550 |
printf(" -(lance) textlayout_draw text='%s', width=%f\n",
|
|
2551 |
qPrintable(text), width);
|
|
2552 |
|
|
2553 |
QFont copy = m_painter->font();
|
|
2554 |
copy.setPointSize(10);
|
|
2555 |
|
|
2556 |
QTextLayout layout(text, copy, m_painter->device());
|
|
2557 |
layout.beginLayout();
|
|
2558 |
|
|
2559 |
double y_offset = 0;
|
|
2560 |
|
|
2561 |
while (true) {
|
|
2562 |
QTextLine line = layout.createLine();
|
|
2563 |
if (!line.isValid())
|
|
2564 |
break;
|
|
2565 |
line.setLineWidth(width);
|
|
2566 |
line.setPosition(QPointF(0, y_offset));
|
|
2567 |
|
|
2568 |
y_offset += line.height();
|
|
2569 |
}
|
|
2570 |
|
|
2571 |
layout.draw(m_painter, QPointF(0, 0));
|
|
2572 |
}
|
|
2573 |
|
|
2574 |
/***************************************************************************************************/
|
|
2575 |
void PaintCommands::command_pen_setDashOffset(QRegExp re)
|
|
2576 |
{
|
|
2577 |
QStringList caps = re.capturedTexts();
|
|
2578 |
double offset = convertToDouble(caps.at(1));
|
|
2579 |
|
|
2580 |
if (m_verboseMode)
|
|
2581 |
printf(" -(lance) setDashOffset(%lf)\n", offset);
|
|
2582 |
|
|
2583 |
QPen p = m_painter->pen();
|
|
2584 |
p.setDashOffset(offset);
|
|
2585 |
m_painter->setPen(p);
|
|
2586 |
}
|
|
2587 |
|
|
2588 |
/***************************************************************************************************/
|
|
2589 |
void PaintCommands::command_pen_setDashPattern(QRegExp re)
|
|
2590 |
{
|
|
2591 |
static QRegExp separators("\\s");
|
|
2592 |
QStringList caps = re.capturedTexts();
|
|
2593 |
QString cap = caps.at(1);
|
|
2594 |
QStringList numbers = cap.split(separators, QString::SkipEmptyParts);
|
|
2595 |
|
|
2596 |
QVector<qreal> pattern;
|
|
2597 |
for (int i=0; i<numbers.size(); ++i)
|
|
2598 |
pattern.append(convertToDouble(numbers.at(i)));
|
|
2599 |
|
|
2600 |
if (m_verboseMode)
|
|
2601 |
printf(" -(lance) pen_setDashPattern(size=%d)\n", pattern.size());
|
|
2602 |
|
|
2603 |
QPen p = m_painter->pen();
|
|
2604 |
p.setDashPattern(pattern);
|
|
2605 |
m_painter->setPen(p);
|
|
2606 |
}
|
|
2607 |
|
|
2608 |
/***************************************************************************************************/
|
|
2609 |
void PaintCommands::command_pen_setCosmetic(QRegExp re)
|
|
2610 |
{
|
|
2611 |
QString hm = re.capturedTexts().at(1);
|
|
2612 |
bool on = hm == "true" || hm == "yes" || hm == "on";
|
|
2613 |
|
|
2614 |
if (m_verboseMode) {
|
|
2615 |
printf(" -(lance) pen_setCosmetic(%s)\n", on ? "true" : "false");
|
|
2616 |
}
|
|
2617 |
|
|
2618 |
QPen p = m_painter->pen();
|
|
2619 |
p.setCosmetic(on);
|
|
2620 |
|
|
2621 |
m_painter->setPen(p);
|
|
2622 |
}
|
|
2623 |
|
|
2624 |
/***************************************************************************************************/
|
|
2625 |
void PaintCommands::command_drawConvexPolygon(QRegExp re)
|
|
2626 |
{
|
|
2627 |
static QRegExp separators("\\s");
|
|
2628 |
QStringList caps = re.capturedTexts();
|
|
2629 |
QString cap = caps.at(1);
|
|
2630 |
QStringList numbers = cap.split(separators, QString::SkipEmptyParts);
|
|
2631 |
|
|
2632 |
QPolygonF array;
|
|
2633 |
for (int i=0; i + 1<numbers.size(); i+=2)
|
|
2634 |
array.append(QPointF(convertToDouble(numbers.at(i)), convertToDouble(numbers.at(i+1))));
|
|
2635 |
|
|
2636 |
if (m_verboseMode)
|
|
2637 |
printf(" -(lance) drawConvexPolygon(size=%d)\n", array.size());
|
|
2638 |
|
|
2639 |
|
|
2640 |
m_painter->drawConvexPolygon(array);
|
|
2641 |
}
|