mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-14 08:38:45 +00:00
Python Chart Editor Cosmetics
.. when working with a light background the syntax highlighting renders the text almost impossible to read because it uses very light colors .. additionally, when the colors/theme are changed the python editor does not reflect the change until a restart .. we should likely apply the same changes to the datafilter editor in the user chart
This commit is contained in:
@@ -299,6 +299,7 @@ PythonChart::PythonChart(Context *context, bool ridesummary) : GcChartWindow(con
|
||||
// sert no render widget
|
||||
canvas=NULL;
|
||||
plot=NULL;
|
||||
syntax=NULL;
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->setSpacing(0);
|
||||
@@ -515,8 +516,12 @@ PythonChart::configChanged(qint32)
|
||||
palette.setColor(QPalette::Text, GColor(CPLOTMARKER));
|
||||
palette.setColor(QPalette::Base, GCColor::alternateColor(GColor(CPLOTBACKGROUND)));
|
||||
setPalette(palette);
|
||||
script->setPalette(palette);
|
||||
script->setStyleSheet(AbstractView::ourStyleSheet());
|
||||
|
||||
// refresh
|
||||
// refresh highlighter
|
||||
if (syntax) delete syntax;
|
||||
syntax = new PythonSyntax(script->document(), GCColor::luminance(GColor(CPLOTBACKGROUND)) < 127);
|
||||
runScript();
|
||||
}
|
||||
|
||||
@@ -549,7 +554,6 @@ PythonChart::setScript(QString string)
|
||||
{
|
||||
if (python && script) {
|
||||
script->setText(string);
|
||||
new PythonSyntax(script->document());
|
||||
}
|
||||
text = string;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <QUrl>
|
||||
#include <QtCharts>
|
||||
#include <QGraphicsItem>
|
||||
#include <QSyntaxHighlighter>
|
||||
|
||||
#include "GoldenCheetah.h"
|
||||
#include "Context.h"
|
||||
@@ -162,6 +163,7 @@ class PythonChart : public GcChartWindow, public PythonHost {
|
||||
Context *context;
|
||||
QString text; // if Rtool not alive
|
||||
bool ridesummary;
|
||||
QSyntaxHighlighter *syntax;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ AbstractView::ourStyleSheet()
|
||||
return QString::fromUtf8("QScrollBar { background-color: %1; border: 0px; }"
|
||||
"QTabWidget { background: %1; }"
|
||||
"QTabWidget::pane { border: 1px solid %2; } "
|
||||
"QTextEdit { background: %1; }"
|
||||
"QTextEdit { background: %1; color: %7; }"
|
||||
"QTextEdit#metadata { background: %3; }"
|
||||
"QTreeView { background: %1; }"
|
||||
"QScrollBar:vertical {"
|
||||
@@ -247,6 +247,7 @@ AbstractView::ourStyleSheet()
|
||||
.arg(8 * dpiXFactor) // width
|
||||
.arg(4 * dpiXFactor) // border radius
|
||||
.arg(GColor(CPLOTMARKER).name())
|
||||
.arg(GCColor::invertColor(GColor(CPLOTBACKGROUND)).name())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
#include "PythonSyntax.h"
|
||||
|
||||
|
||||
PythonSyntax::PythonSyntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
|
||||
PythonSyntax::PythonSyntax(QTextDocument *parent, bool dark) : QSyntaxHighlighter(parent)
|
||||
{
|
||||
HighlightingRule rule;
|
||||
|
||||
assignmentFormat.setForeground(QColor(255,204,000));
|
||||
assignmentFormat.setForeground(dark ? QColor(255,204,000): Qt::black);
|
||||
rule.pattern = QRegExp("<{1,2}[-]");
|
||||
rule.format = assignmentFormat;
|
||||
highlightingRules.append(rule);
|
||||
@@ -35,7 +35,7 @@ PythonSyntax::PythonSyntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
|
||||
|
||||
|
||||
// function: anything followed by (
|
||||
functionFormat.setForeground(Qt::cyan);
|
||||
functionFormat.setForeground(dark ? Qt::cyan : Qt::darkBlue);
|
||||
//functionFormat.setFontItalic(true);
|
||||
rule.pattern = QRegExp("\\b[A-Za-z0-9_\\.]+(?=[ ]*\\()");
|
||||
rule.format = functionFormat;
|
||||
@@ -49,7 +49,7 @@ PythonSyntax::PythonSyntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
|
||||
highlightingRules.append(rule);
|
||||
|
||||
// numbers
|
||||
numberFormat.setForeground(Qt::red);
|
||||
numberFormat.setForeground(dark ? Qt::red : Qt::darkRed);
|
||||
QStringList numberPatterns;
|
||||
numberPatterns << "\\b[0-9]+[\\.]?[0-9]*\\b" << "\\b[\\.][0-9]+\\b";
|
||||
foreach (QString pattern, numberPatterns) {
|
||||
@@ -59,7 +59,7 @@ PythonSyntax::PythonSyntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
|
||||
}
|
||||
|
||||
// constants: TRUE FALSE NA NULL Inf NaN
|
||||
constantFormat.setForeground(Qt::red);
|
||||
constantFormat.setForeground(dark ? Qt::red : Qt::darkRed);
|
||||
QStringList constantPatterns;
|
||||
constantPatterns << "\\bTrue\\b" << "\\bFalse\\b" << "\\bNone\\b" << "\\bNull\\b" << "\\bInf\\b" << "\\bNaN\\b";
|
||||
foreach (QString pattern, constantPatterns) {
|
||||
@@ -70,7 +70,7 @@ PythonSyntax::PythonSyntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
|
||||
|
||||
// keywords: while for in repeat if else switch break next
|
||||
// function return message warning stop
|
||||
keywordFormat.setForeground(QColor(255,204,000));
|
||||
keywordFormat.setForeground(dark ? QColor(255,204,000) : Qt::black);
|
||||
//keywordFormat.setFontItalic(true);
|
||||
QStringList keywordPatterns;
|
||||
keywordPatterns << "\\bas\\b" << "\\bassert\\b" << "\\bbreak\\b"
|
||||
@@ -88,7 +88,7 @@ PythonSyntax::PythonSyntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
|
||||
|
||||
// common functions (says who? (I hate attach)): library attach
|
||||
// detach source require
|
||||
commonFunctionFormat.setForeground(QColor(40,255,40));
|
||||
commonFunctionFormat.setForeground(dark ? QColor(40,255,40) : Qt::darkGray);
|
||||
QStringList commonFunctionPatterns;
|
||||
commonFunctionPatterns << "\\bGC\\b" << "\\bdef\\b" << "\\bself\\b";
|
||||
foreach (QString pattern, commonFunctionPatterns) {
|
||||
@@ -98,7 +98,7 @@ PythonSyntax::PythonSyntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
|
||||
}
|
||||
|
||||
// operators
|
||||
operatorFormat.setForeground(QColor(255,204,000));
|
||||
operatorFormat.setForeground(dark ? QColor(255,204,000) : Qt::black);
|
||||
//operatorFormat.setForeground(Qt::darkCyan);
|
||||
//operatorFormat.setFontWeight(QFont::Bold);
|
||||
QStringList operatorPatterns;
|
||||
@@ -120,7 +120,7 @@ PythonSyntax::PythonSyntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
|
||||
|
||||
// quotes: only activated after quotes are closed. Does not
|
||||
// span lines.
|
||||
quotationFormat.setForeground(Qt::red);
|
||||
quotationFormat.setForeground(dark ? Qt::red : Qt::darkRed);
|
||||
rule.pattern = QRegExp("\"[^\"]*\"");
|
||||
rule.format = quotationFormat;
|
||||
highlightingRules.append(rule);
|
||||
@@ -129,7 +129,7 @@ PythonSyntax::PythonSyntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
|
||||
highlightingRules.append(rule);
|
||||
|
||||
// comments (should override everything else)
|
||||
commentFormat.setForeground(QColor(100,149,237));
|
||||
commentFormat.setForeground(dark ? QColor(100,149,237) : Qt::darkBlue);
|
||||
rule.pattern = QRegExp("#[^\n]*");
|
||||
rule.format = commentFormat;
|
||||
highlightingRules.append(rule);
|
||||
|
||||
@@ -31,7 +31,7 @@ class PythonSyntax : public QSyntaxHighlighter
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PythonSyntax(QTextDocument *parent = 0);
|
||||
PythonSyntax(QTextDocument *parent = 0, bool dark=true);
|
||||
|
||||
protected:
|
||||
void highlightBlock(const QString &text);
|
||||
|
||||
Reference in New Issue
Block a user