qscilexerpov.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. // This module implements the QsciLexerPOV class.
  2. //
  3. // Copyright (c) 2017 Riverbank Computing Limited <info@riverbankcomputing.com>
  4. //
  5. // This file is part of QScintilla.
  6. //
  7. // This file may be used under the terms of the GNU General Public License
  8. // version 3.0 as published by the Free Software Foundation and appearing in
  9. // the file LICENSE included in the packaging of this file. Please review the
  10. // following information to ensure the GNU General Public License version 3.0
  11. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  12. //
  13. // If you do not wish to use this file under the terms of the GPL version 3.0
  14. // then you may purchase a commercial license. For more information contact
  15. // info@riverbankcomputing.com.
  16. //
  17. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  18. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19. #include "Qsci/qscilexerpov.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. // The ctor.
  24. QsciLexerPOV::QsciLexerPOV(QObject *parent)
  25. : QsciLexer(parent),
  26. fold_comments(false), fold_compact(true), fold_directives(false)
  27. {
  28. }
  29. // The dtor.
  30. QsciLexerPOV::~QsciLexerPOV()
  31. {
  32. }
  33. // Returns the language name.
  34. const char *QsciLexerPOV::language() const
  35. {
  36. return "POV";
  37. }
  38. // Returns the lexer name.
  39. const char *QsciLexerPOV::lexer() const
  40. {
  41. return "pov";
  42. }
  43. // Return the style used for braces.
  44. int QsciLexerPOV::braceStyle() const
  45. {
  46. return Operator;
  47. }
  48. // Return the string of characters that comprise a word.
  49. const char *QsciLexerPOV::wordCharacters() const
  50. {
  51. return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_#";
  52. }
  53. // Returns the foreground colour of the text for a style.
  54. QColor QsciLexerPOV::defaultColor(int style) const
  55. {
  56. switch (style)
  57. {
  58. case Default:
  59. return QColor(0xff,0x00,0x80);
  60. case Comment:
  61. case CommentLine:
  62. return QColor(0x00,0x7f,0x00);
  63. case Number:
  64. return QColor(0x00,0x7f,0x7f);
  65. case Operator:
  66. return QColor(0x00,0x00,0x00);
  67. case String:
  68. return QColor(0x7f,0x00,0x7f);
  69. case Directive:
  70. return QColor(0x7f,0x7f,0x00);
  71. case BadDirective:
  72. return QColor(0x80,0x40,0x20);
  73. case ObjectsCSGAppearance:
  74. case TypesModifiersItems:
  75. case PredefinedIdentifiers:
  76. case PredefinedFunctions:
  77. case KeywordSet6:
  78. case KeywordSet7:
  79. case KeywordSet8:
  80. return QColor(0x00,0x00,0x7f);
  81. }
  82. return QsciLexer::defaultColor(style);
  83. }
  84. // Returns the end-of-line fill for a style.
  85. bool QsciLexerPOV::defaultEolFill(int style) const
  86. {
  87. if (style == UnclosedString)
  88. return true;
  89. return QsciLexer::defaultEolFill(style);
  90. }
  91. // Returns the font of the text for a style.
  92. QFont QsciLexerPOV::defaultFont(int style) const
  93. {
  94. QFont f;
  95. switch (style)
  96. {
  97. case Comment:
  98. case CommentLine:
  99. #if defined(Q_OS_WIN)
  100. f = QFont("Comic Sans MS",9);
  101. #elif defined(Q_OS_MAC)
  102. f = QFont("Comic Sans MS", 12);
  103. #else
  104. f = QFont("Bitstream Vera Serif",9);
  105. #endif
  106. break;
  107. case UnclosedString:
  108. case PredefinedIdentifiers:
  109. f = QsciLexer::defaultFont(style);
  110. f.setBold(true);
  111. break;
  112. case BadDirective:
  113. #if defined(Q_OS_WIN)
  114. f = QFont("Comic Sans MS",9);
  115. #elif defined(Q_OS_MAC)
  116. f = QFont("Comic Sans MS", 12);
  117. #else
  118. f = QFont("Bitstream Vera Serif",9);
  119. #endif
  120. f.setItalic(true);
  121. break;
  122. default:
  123. f = QsciLexer::defaultFont(style);
  124. }
  125. return f;
  126. }
  127. // Returns the set of keywords.
  128. const char *QsciLexerPOV::keywords(int set) const
  129. {
  130. if (set == 1)
  131. return
  132. "declare local include undef fopen fclose read write "
  133. "default version case range break debug error "
  134. "warning if ifdef ifndef switch while macro else end";
  135. if (set == 2)
  136. return
  137. "camera light_source light_group object blob sphere "
  138. "cylinder box cone height_field julia_fractal lathe "
  139. "prism sphere_sweep superellipsoid sor text torus "
  140. "bicubic_patch disc mesh mesh2 polygon triangle "
  141. "smooth_triangle plane poly cubic quartic quadric "
  142. "isosurface parametric union intersection difference "
  143. "merge function array spline vertex_vectors "
  144. "normal_vectors uv_vectors face_indices "
  145. "normal_indices uv_indices texture texture_list "
  146. "interior_texture texture_map material_map image_map "
  147. "color_map colour_map pigment_map normal_map "
  148. "slope_map bump_map density_map pigment normal "
  149. "material interior finish reflection irid slope "
  150. "pigment_pattern image_pattern warp media scattering "
  151. "density background fog sky_sphere rainbow "
  152. "global_settings radiosity photons pattern transform "
  153. "looks_like projected_through contained_by "
  154. "clipped_by bounded_by";
  155. if (set == 3)
  156. return
  157. "linear_spline quadratic_spline cubic_spline "
  158. "natural_spline bezier_spline b_spline read write "
  159. "append inverse open perspective orthographic "
  160. "fisheye ultra_wide_angle omnimax panoramic "
  161. "spherical spotlight jitter circular orient "
  162. "media_attenuation media_interaction shadowless "
  163. "parallel refraction collect pass_through "
  164. "global_lights hierarchy sturm smooth gif tga iff "
  165. "pot png pgm ppm jpeg tiff sys ttf quaternion "
  166. "hypercomplex linear_sweep conic_sweep type "
  167. "all_intersections split_union cutaway_textures "
  168. "no_shadow no_image no_reflection double_illuminate "
  169. "hollow uv_mapping all use_index use_color "
  170. "use_colour no_bump_scale conserve_energy fresnel "
  171. "average agate boxed bozo bumps cells crackle "
  172. "cylindrical density_file dents facets granite "
  173. "leopard marble onion planar quilted radial ripples "
  174. "spotted waves wood wrinkles solid use_alpha "
  175. "interpolate magnet noise_generator toroidal "
  176. "ramp_wave triangle_wave sine_wave scallop_wave "
  177. "cubic_wave poly_wave once map_type method fog_type "
  178. "hf_gray_16 charset ascii utf8 rotate scale "
  179. "translate matrix location right up direction sky "
  180. "angle look_at aperture blur_samples focal_point "
  181. "confidence variance radius falloff tightness "
  182. "point_at area_light adaptive fade_distance "
  183. "fade_power threshold strength water_level tolerance "
  184. "max_iteration precision slice u_steps v_steps "
  185. "flatness inside_vector accuracy max_gradient "
  186. "evaluate max_trace precompute target ior dispersion "
  187. "dispersion_samples caustics color colour rgb rgbf "
  188. "rgbt rgbft red green blue filter transmit gray hf "
  189. "fade_color fade_colour quick_color quick_colour "
  190. "brick checker hexagon brick_size mortar bump_size "
  191. "ambient diffuse brilliance crand phong phong_size "
  192. "metallic specular roughness reflection_exponent "
  193. "exponent thickness gradient spiral1 spiral2 "
  194. "agate_turb form metric offset df3 coords size "
  195. "mandel exterior julia control0 control1 altitude "
  196. "turbulence octaves omega lambda repeat flip "
  197. "black-hole orientation dist_exp major_radius "
  198. "frequency phase intervals samples ratio absorption "
  199. "emission aa_threshold aa_level eccentricity "
  200. "extinction distance turb_depth fog_offset fog_alt "
  201. "width arc_angle falloff_angle adc_bailout "
  202. "ambient_light assumed_gamma irid_wavelength "
  203. "number_of_waves always_sample brigthness count "
  204. "error_bound gray_threshold load_file "
  205. "low_error_factor max_sample minimum_reuse "
  206. "nearest_count pretrace_end pretrace_start "
  207. "recursion_limit save_file spacing gather "
  208. "max_trace_level autostop expand_thresholds";
  209. if (set == 4)
  210. return
  211. "x y z t u v yes no true false on off clock "
  212. "clock_delta clock_on final_clock final_frame "
  213. "frame_number image_height image_width initial_clock "
  214. "initial_frame pi version";
  215. if (set == 5)
  216. return
  217. "abs acos acosh asc asin asinh atan atanh atan2 ceil "
  218. "cos cosh defined degrees dimensions dimension_size "
  219. "div exp file_exists floor inside int ln log max min "
  220. "mod pow prod radians rand seed select sin sinh sqrt "
  221. "strcmp strlen sum tan tanh val vdot vlength "
  222. "min_extent max_extent trace vaxis_rotate vcross "
  223. "vrotate vnormalize vturbulence chr concat str "
  224. "strlwr strupr substr vstr sqr cube reciprocal pwr";
  225. return 0;
  226. }
  227. // Returns the user name of a style.
  228. QString QsciLexerPOV::description(int style) const
  229. {
  230. switch (style)
  231. {
  232. case Default:
  233. return tr("Default");
  234. case Comment:
  235. return tr("Comment");
  236. case CommentLine:
  237. return tr("Comment line");
  238. case Number:
  239. return tr("Number");
  240. case Operator:
  241. return tr("Operator");
  242. case Identifier:
  243. return tr("Identifier");
  244. case String:
  245. return tr("String");
  246. case UnclosedString:
  247. return tr("Unclosed string");
  248. case Directive:
  249. return tr("Directive");
  250. case BadDirective:
  251. return tr("Bad directive");
  252. case ObjectsCSGAppearance:
  253. return tr("Objects, CSG and appearance");
  254. case TypesModifiersItems:
  255. return tr("Types, modifiers and items");
  256. case PredefinedIdentifiers:
  257. return tr("Predefined identifiers");
  258. case PredefinedFunctions:
  259. return tr("Predefined functions");
  260. case KeywordSet6:
  261. return tr("User defined 1");
  262. case KeywordSet7:
  263. return tr("User defined 2");
  264. case KeywordSet8:
  265. return tr("User defined 3");
  266. }
  267. return QString();
  268. }
  269. // Returns the background colour of the text for a style.
  270. QColor QsciLexerPOV::defaultPaper(int style) const
  271. {
  272. switch (style)
  273. {
  274. case UnclosedString:
  275. return QColor(0xe0,0xc0,0xe0);
  276. case ObjectsCSGAppearance:
  277. return QColor(0xff,0xd0,0xd0);
  278. case TypesModifiersItems:
  279. return QColor(0xff,0xff,0xd0);
  280. case PredefinedFunctions:
  281. return QColor(0xd0,0xd0,0xff);
  282. case KeywordSet6:
  283. return QColor(0xd0,0xff,0xd0);
  284. case KeywordSet7:
  285. return QColor(0xd0,0xd0,0xd0);
  286. case KeywordSet8:
  287. return QColor(0xe0,0xe0,0xe0);
  288. }
  289. return QsciLexer::defaultPaper(style);
  290. }
  291. // Refresh all properties.
  292. void QsciLexerPOV::refreshProperties()
  293. {
  294. setCommentProp();
  295. setCompactProp();
  296. setDirectiveProp();
  297. }
  298. // Read properties from the settings.
  299. bool QsciLexerPOV::readProperties(QSettings &qs,const QString &prefix)
  300. {
  301. int rc = true;
  302. fold_comments = qs.value(prefix + "foldcomments", false).toBool();
  303. fold_compact = qs.value(prefix + "foldcompact", true).toBool();
  304. fold_directives = qs.value(prefix + "folddirectives", false).toBool();
  305. return rc;
  306. }
  307. // Write properties to the settings.
  308. bool QsciLexerPOV::writeProperties(QSettings &qs,const QString &prefix) const
  309. {
  310. int rc = true;
  311. qs.setValue(prefix + "foldcomments", fold_comments);
  312. qs.setValue(prefix + "foldcompact", fold_compact);
  313. qs.setValue(prefix + "folddirectives", fold_directives);
  314. return rc;
  315. }
  316. // Return true if comments can be folded.
  317. bool QsciLexerPOV::foldComments() const
  318. {
  319. return fold_comments;
  320. }
  321. // Set if comments can be folded.
  322. void QsciLexerPOV::setFoldComments(bool fold)
  323. {
  324. fold_comments = fold;
  325. setCommentProp();
  326. }
  327. // Set the "fold.comment" property.
  328. void QsciLexerPOV::setCommentProp()
  329. {
  330. emit propertyChanged("fold.comment",(fold_comments ? "1" : "0"));
  331. }
  332. // Return true if folds are compact.
  333. bool QsciLexerPOV::foldCompact() const
  334. {
  335. return fold_compact;
  336. }
  337. // Set if folds are compact
  338. void QsciLexerPOV::setFoldCompact(bool fold)
  339. {
  340. fold_compact = fold;
  341. setCompactProp();
  342. }
  343. // Set the "fold.compact" property.
  344. void QsciLexerPOV::setCompactProp()
  345. {
  346. emit propertyChanged("fold.compact",(fold_compact ? "1" : "0"));
  347. }
  348. // Return true if directives can be folded.
  349. bool QsciLexerPOV::foldDirectives() const
  350. {
  351. return fold_directives;
  352. }
  353. // Set if directives can be folded.
  354. void QsciLexerPOV::setFoldDirectives(bool fold)
  355. {
  356. fold_directives = fold;
  357. setDirectiveProp();
  358. }
  359. // Set the "fold.directive" property.
  360. void QsciLexerPOV::setDirectiveProp()
  361. {
  362. emit propertyChanged("fold.directive",(fold_directives ? "1" : "0"));
  363. }