Monday, April 8, 2013

Highlighting Errors – Extra Selections

The QPlainTextEdit class, the base class for the EditBox class, contains a feature called Extra Selections, which allows for temporarily marking certain regions of the document with a given format (color and/or style).  Each extra selection is specified by the QTextEdit::ExtraSelection structure that consists of a cursor (QTextCursor) and a format (QTextCharFormat).  A list (QList) of all the extra selections is given to the plain text edit widget using the setExtraSelection() function.

The selection, the characters to temporarily format, is specified by the cursor, which is initialized from the text cursor of edit widget.  The cursor is them set to the beginning position of the selection to temporarily mark and moved to the end of the selection using the keep anchor position option.

The temporary format is specified by the format member.  The format has many options including colors (foreground and background),  and font style like italicized, bold, underlined, and curvy underline.   The underlines can even be made a different color.

For translator errors, a simple red background will be used.  Later, another color, possible yellow or light blue, will be used for warnings.  There will be no warnings from the translator, but there will be warnings from the encoder.  For example, when the beginning of an IF statement or FOR loop is entered before the END IF or NEXT is entered, or vice-versa.  These are not errors as the line is valid, but these warnings will also prevent the program from being run until corrected.

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)