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

View File

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

View File

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