A number of changes were made to display the line numbers in the program view similar to the edit box. The paint function in the program line delegate was updated to display the line number and the program line in separate rectangles. The background color of the line number rectangle is displayed in light gray like the edit box. To space the characters in these rectangles nicely, a half character space was added on both sides of the line number and in front of the program line text.
Before the line number can be drawn, the width of the line number rectangle needs to be determined, which is based on the number of lines present in the program. A new update width function was added that is called with a new line count each time it changes. This function calculates the number of digits the new line count will take plus one character to account for the two half spaces on either side of the line number. The number of pixels required is calculated and if different from the previous value calculated, the new value is stored into a new member variable and a signal is emitted to indicate that the program view needs to be updated on the screen.
Two other members were added to the class, the pixel width of a digit and the base line number (the number of the first line). The constructor was modified with two new arguments, one for the base line number, which is stored, and the font metrics of the font used for the program view, which is used to get the pixel widget of one digit and is stored for the new width update function.
The lines to set up the program line delegate and program view in the main window constructor needed to be moved to before the initial program is loaded so that the correct line number count gets to the program line delegate. The program changed slot was modified to check when the program line count has changed by checking a new program line count member variable, which is then stored and the update width function is called.
Finally, the program view update signal is connected to a new main window slot that updates the program view rectangle. This slot and the program line count member variable are temporary until a more advanced program model is implemented. Currently the program model is a simple string list model that is unaware of the program. The other commit made was to have the program view use the same fixed width font of the edit box.
[commit 3b68b11d11] [commit a7f38c99e4]
Wednesday, March 13, 2013
Subscribe to:
Post Comments (Atom)
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.)