GUI: Improved scrolling in code display

This commit is contained in:
Daniel Marjamäki 2018-02-21 22:49:50 +01:00
parent 4a46690990
commit bd21d7fff6
3 changed files with 13 additions and 8 deletions

View File

@ -144,6 +144,8 @@ void CodeEditor::setError(const QString &code, int errorLine, const QStringList
tc.setPosition(mErrorPosition);
setTextCursor(tc);
centerCursor();
highlightErrorLine();
}
int CodeEditor::lineNumberAreaWidth()
@ -182,12 +184,8 @@ void CodeEditor::resizeEvent(QResizeEvent *event)
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
}
void CodeEditor::highlightCurrentLine()
void CodeEditor::highlightErrorLine()
{
QTextCursor tc = textCursor();
tc.setPosition(mErrorPosition);
setTextCursor(tc);
QList<QTextEdit::ExtraSelection> extraSelections;
QTextEdit::ExtraSelection selection;
@ -196,7 +194,8 @@ void CodeEditor::highlightCurrentLine()
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = textCursor();
selection.cursor = QTextCursor(document());
selection.cursor.setPosition(mErrorPosition);
selection.cursor.clearSelection();
extraSelections.append(selection);

View File

@ -61,7 +61,7 @@ protected:
private slots:
void updateLineNumberAreaWidth(int newBlockCount);
void highlightCurrentLine();
void highlightErrorLine();
void updateLineNumberArea(const QRect &, int);
private:

View File

@ -140,9 +140,15 @@
<verstretch>4</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>