Workout Editor Fix QT4 plus highlighting

.. QT code supplied was QT5 only, fixed up to compile
   on QT4 by including relevant headers

.. moved the responsibility for code highlighting back
   to the editor as it is the sensible place to do it.
This commit is contained in:
Mark Liversedge
2016-01-19 08:52:49 +00:00
parent d39caf1c05
commit 2dadafc8f5
2 changed files with 8 additions and 21 deletions

View File

@@ -38,7 +38,10 @@
**
****************************************************************************/
#include <QtWidgets>
#include <QWidget>
#include <QPlainTextEdit>
#include <QTextBlock>
#include <QPainter>
#include "codeeditor.h"
@@ -50,10 +53,10 @@ CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
//we manage highlighting within GC, this is not required.
//connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
updateLineNumberAreaWidth(0);
//highlightCurrentLine();
highlightCurrentLine();
lineAreaColor=QColor(Qt::darkGray);
lineAreaText=QColor(Qt::white);
@@ -114,9 +117,7 @@ void CodeEditor::highlightCurrentLine()
if (!isReadOnly()) {
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(Qt::yellow).lighter(160);
selection.format.setBackground(lineColor);
selection.format.setBackground(lineAreaColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = textCursor();
selection.cursor.clearSelection();

View File

@@ -824,16 +824,6 @@ WorkoutWidget::setBlockCursor()
// cursor to work with the document text
QTextCursor cursor(parent->code->document());
// highlighting block
QTextBlockFormat normal;
QTextBlockFormat highlight = cursor.blockFormat();
highlight.setBackground(QBrush(QColor(127,127,127,127)));
// set all normal before highlighting current hover
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
cursor.setBlockFormat(normal);
// look for line of code that includes the point we are
// hovering over so we can highlight it in the text edit
int indexin=0;
@@ -845,13 +835,9 @@ WorkoutWidget::setBlockCursor()
|| (i==codePoints.count()-1))) {
// we have found the line in coreStrings that we
// are hovering on and should now set it to be
// highlighted
// lets color it as a gray block
// move cursor, the line will be highlighted by the editor
cursor.setPosition(indexin, QTextCursor::MoveAnchor);
cursor.setPosition(indexin + codeStrings[i].length(), QTextCursor::KeepAnchor);
cursor.setBlockFormat(highlight);
cursor.clearSelection();
// move the visible cursor and make visible