+/**
+ * Automatic indentation rule: if a previous line ended with
+ * ':', then add N additional spaces in the current line. If no ':' found, then
+ * the same amount of spaces as in the previous line is added. Connected to
+ * "returnPressed" signal of myText text edit.
+*/
+void SUPERVGUI_PythonEditPane::autoIndentLine() {
+ const int N = 4; // width of indentation "tab"
+ if ( myText && myText->paragraphs() ) {
+
+ // get current cursor position and previous line (the one to be analized)
+ int pos, para, i;
+ myText->getCursorPosition( ¶, &pos ); // pos==0, beginning of line
+ QString line = myText->text( para-1 ); // previous paragraph line
+
+ // construct a string containing all leading space characters of previous line (tabs, etc.)
+ QString spacesStr;
+ i = -1;
+ while ( line[++i].isSpace() ) // append all isSpace() characters at beginning of line to spacesStr
+ spacesStr += line[i];
+
+ // if ':' was found -- add more spaces to spacesStr
+ line = line.stripWhiteSpace();
+ if ( line[ line.length()-1 ] == ':' ) {
+ i = 0;
+ while ( i++ < N )
+ spacesStr += ' ';
+ }
+
+ // ok, append spacesStr at the beginning of the current line = make indentation
+ myText->insertAt( spacesStr, para, pos );
+ myText->setCursorPosition( para, pos+spacesStr.length() );
+ }
+}