From 2dadafc8f58f8a723732d22df962f0d55f408128 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Tue, 19 Jan 2016 08:52:49 +0000 Subject: [PATCH] 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. --- qtsolutions/codeeditor/codeeditor.cpp | 13 +++++++------ src/WorkoutWidget.cpp | 16 +--------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/qtsolutions/codeeditor/codeeditor.cpp b/qtsolutions/codeeditor/codeeditor.cpp index 7811dc4b4..812a4e7fd 100644 --- a/qtsolutions/codeeditor/codeeditor.cpp +++ b/qtsolutions/codeeditor/codeeditor.cpp @@ -38,7 +38,10 @@ ** ****************************************************************************/ -#include +#include +#include +#include +#include #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(); diff --git a/src/WorkoutWidget.cpp b/src/WorkoutWidget.cpp index 5e5e91e84..44cc08623 100644 --- a/src/WorkoutWidget.cpp +++ b/src/WorkoutWidget.cpp @@ -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