Skip to content

Commit f5ee8e7

Browse files
committed
Dark Theme
1 parent 43b9656 commit f5ee8e7

File tree

5 files changed

+69
-85
lines changed

5 files changed

+69
-85
lines changed

CodeEditor/codeeditor.cpp

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/****************************************************************************
22
**
3+
**
34
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
45
** Contact: http://www.qt-project.org/legal
56
**
@@ -36,6 +37,7 @@
3637
**
3738
** $QT_END_LICENSE$
3839
**
40+
** -----------Modified By Bhathiya Perera-------------
3941
****************************************************************************/
4042

4143
#include <QtWidgets>
@@ -48,10 +50,13 @@ CodeEditor::CodeEditor(QWidget* parent)
4850

4951
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
5052
connect(this, SIGNAL(updateRequest(QRect, int)), this, SLOT(updateLineNumberArea(QRect, int)));
51-
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
5253

5354
updateLineNumberAreaWidth(0);
54-
highlightCurrentLine();
55+
56+
QPalette p = this->palette();
57+
p.setColor(QPalette::Base, Qt::black);
58+
p.setColor(QPalette::Text, Qt::white);
59+
this->setPalette(p);
5560
}
5661

5762
int CodeEditor::lineNumberAreaWidth()
@@ -94,42 +99,22 @@ void CodeEditor::resizeEvent(QResizeEvent* e)
9499

95100
void CodeEditor::keyPressEvent(QKeyEvent* e)
96101
{
102+
//TODO handle automatical indentation
103+
//TODO backspace auto unindent
104+
//TODO indent selected text
97105
switch (e->key()) {
98106
case Qt::Key_Tab:
99107
QPlainTextEdit::insertPlainText(" ");
100108
break;
101-
// TODO Indentation
102-
// case Qt::Key_Enter:
103-
// case Qt::Key_Return:
104-
// break;
105109
default:
106110
QPlainTextEdit::keyPressEvent(e);
107111
}
108112
}
109113

110-
void CodeEditor::highlightCurrentLine()
111-
{
112-
QList<QTextEdit::ExtraSelection> extraSelections;
113-
114-
if (!isReadOnly()) {
115-
QTextEdit::ExtraSelection selection;
116-
117-
QColor lineColor = QColor(Qt::yellow).lighter(160);
118-
119-
selection.format.setBackground(lineColor);
120-
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
121-
selection.cursor = textCursor();
122-
selection.cursor.clearSelection();
123-
extraSelections.append(selection);
124-
}
125-
126-
setExtraSelections(extraSelections);
127-
}
128-
129114
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event)
130115
{
131116
QPainter painter(lineNumberArea);
132-
painter.fillRect(event->rect(), Qt::lightGray);
117+
painter.fillRect(event->rect(), Qt::darkGray);
133118

134119
QTextBlock block = firstVisibleBlock();
135120
int blockNumber = block.blockNumber();

CodeEditor/codeeditor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class CodeEditor : public QPlainTextEdit {
6666

6767
private slots:
6868
void updateLineNumberAreaWidth(int newBlockCount);
69-
void highlightCurrentLine();
7069
void updateLineNumberArea(const QRect&, int);
7170

7271
private:

CodeEditor/pythonsyntaxhighlighter.cpp

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
/*
2-
$Id: PythonSyntaxHighlighter.cpp 167 2013-11-03 17:01:22Z oliver $
3-
This is a C++ port of the following PyQt example
4-
http://diotavelli.net/PyQtWiki/Python%20syntax%20highlighting
5-
C++ port by Frankie Simon (www.kickdrive.de, www.fuh-edv.de)
6-
7-
The following free software license applies for this file ("X11 license"):
8-
9-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10-
and associated documentation files (the "Software"), to deal in the Software without restriction,
11-
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12-
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13-
subject to the following conditions:
14-
15-
The above copyright notice and this permission notice shall be included in all copies or substantial
16-
portions of the Software.
17-
18-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
19-
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20-
IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21-
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22-
USE OR OTHER DEALINGS IN THE SOFTWARE.
1+
/* $Id: PythonSyntaxHighlighter.cpp 167 2013-11-03 17:01:22Z oliver $
2+
*
3+
* This is a C++ port of the following PyQt example
4+
* http://diotavelli.net/PyQtWiki/Python%20syntax%20highlighting
5+
* C++ port by Frankie Simon (www.kickdrive.de, www.fuh-edv.de)
6+
*
7+
* The following free software license applies for this file ("X11 license"):
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
11+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13+
* subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all copies or substantial
16+
* portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
19+
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
* IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22+
* USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*
24+
* -----------Modified By Bhathiya Perera-------------
2325
*/
2426

2527
#include "CodeEditor/PythonSyntaxHighlighter.h"
@@ -60,30 +62,26 @@ PythonSyntaxHighlighter::PythonSyntaxHighlighter(QTextDocument* parent)
6062
<< "True"
6163
<< "False";
6264

63-
operators = QStringList() << "=" <<
64-
// Comparison
65-
"=="
65+
operators = QStringList() << "="
66+
<< "=="
6667
<< "!="
6768
<< "<"
6869
<< "<="
6970
<< ">"
70-
<< ">=" <<
71-
// Arithmetic
72-
"\\+"
71+
<< ">="
72+
<< "\\+"
7373
<< "-"
7474
<< "\\*"
7575
<< "/"
7676
<< "//"
7777
<< "%"
78-
<< "\\*\\*" <<
79-
// In-place
80-
"\\+="
78+
<< "\\*\\*"
79+
<< "\\+="
8180
<< "-="
8281
<< "\\*="
8382
<< "/="
84-
<< "%=" <<
85-
// Bitwise
86-
"\\^"
83+
<< "%="
84+
<< "\\^"
8785
<< "\\|"
8886
<< "&"
8987
<< "~"
@@ -97,11 +95,6 @@ PythonSyntaxHighlighter::PythonSyntaxHighlighter(QTextDocument* parent)
9795
<< "\\["
9896
<< "]";
9997

100-
QFont* font = new QFont();
101-
font->setFamily("Courier New");
102-
font->setFixedPitch(true);
103-
font->setPointSize(10);
104-
10598
setStyles();
10699

107100
triSingleQuote.setPattern("'''");
@@ -112,16 +105,16 @@ PythonSyntaxHighlighter::PythonSyntaxHighlighter(QTextDocument* parent)
112105

113106
void PythonSyntaxHighlighter::setStyles()
114107
{
115-
basicStyles.insert("keyword", getTextCharFormat("blue"));
108+
basicStyles.insert("keyword", getTextCharFormat("orange", "bold"));
116109
basicStyles.insert("operator", getTextCharFormat("red"));
117-
basicStyles.insert("brace", getTextCharFormat("darkGray"));
118-
basicStyles.insert("defclass", getTextCharFormat("black", "bold"));
119-
basicStyles.insert("brace", getTextCharFormat("darkGray"));
110+
basicStyles.insert("brace", getTextCharFormat("red", "bold"));
111+
basicStyles.insert("defclass", getTextCharFormat("white", "bold"));
120112
basicStyles.insert("string", getTextCharFormat("magenta"));
121113
basicStyles.insert("string2", getTextCharFormat("darkMagenta"));
122-
basicStyles.insert("comment", getTextCharFormat("darkGreen", "italic"));
123-
basicStyles.insert("self", getTextCharFormat("black", "italic"));
124-
basicStyles.insert("numbers", getTextCharFormat("brown"));
114+
basicStyles.insert("comment", getTextCharFormat("darkGreen", "bold"));
115+
basicStyles.insert("self", getTextCharFormat("white", "bold"));
116+
basicStyles.insert("numbers", getTextCharFormat("cyan"));
117+
basicStyles.insert("bugs", getTextCharFormat("yellow", "bold", "red"));
125118
}
126119

127120
void PythonSyntaxHighlighter::initializeRules()
@@ -139,27 +132,25 @@ void PythonSyntaxHighlighter::initializeRules()
139132
rules.append(HighlightingRule("\\bself\\b", 0, basicStyles.value("self")));
140133

141134
// Double-quoted string, possibly containing escape sequences
142-
// FF: originally in python : r'"[^"\\]*(\\.[^"\\]*)*"'
143135
rules.append(HighlightingRule("\"[^\"\\\\]*(\\\\.[^\"\\\\]*)*\"", 0, basicStyles.value("string")));
144136
// Single-quoted string, possibly containing escape sequences
145-
// FF: originally in python : r"'[^'\\]*(\\.[^'\\]*)*'"
146137
rules.append(HighlightingRule("'[^'\\\\]*(\\\\.[^'\\\\]*)*'", 0, basicStyles.value("string")));
147138

148139
// 'def' followed by an identifier
149-
// FF: originally: r'\bdef\b\s*(\w+)'
150140
rules.append(HighlightingRule("\\bdef\\b\\s*(\\w+)", 1, basicStyles.value("defclass")));
151141
// 'class' followed by an identifier
152-
// FF: originally: r'\bclass\b\s*(\w+)'
153142
rules.append(HighlightingRule("\\bclass\\b\\s*(\\w+)", 1, basicStyles.value("defclass")));
154143

155144
// From '#' until a newline
156-
// FF: originally: r'#[^\\n]*'
157145
rules.append(HighlightingRule("#[^\\n]*", 0, basicStyles.value("comment")));
158146

159147
// Numeric literals
160-
rules.append(HighlightingRule("\\b[+-]?[0-9]+[lL]?\\b", 0, basicStyles.value("numbers"))); // r'\b[+-]?[0-9]+[lL]?\b'
161-
rules.append(HighlightingRule("\\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\\b", 0, basicStyles.value("numbers"))); // r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b'
162-
rules.append(HighlightingRule("\\b[+-]?[0-9]+(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b", 0, basicStyles.value("numbers"))); // r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b'
148+
rules.append(HighlightingRule("\\b[+-]?[0-9]+[lL]?\\b", 0, basicStyles.value("numbers")));
149+
rules.append(HighlightingRule("\\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\\b", 0, basicStyles.value("numbers")));
150+
rules.append(HighlightingRule("\\b[+-]?[0-9]+(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b", 0, basicStyles.value("numbers")));
151+
152+
// tab and space mixed
153+
rules.append(HighlightingRule("[^\\n]*(?:\\t | \\t)[^\\n]*", 0, basicStyles.value("bugs")));
163154
}
164155

165156
void PythonSyntaxHighlighter::highlightBlock(const QString& text)
@@ -227,11 +218,17 @@ bool PythonSyntaxHighlighter::matchMultiline(const QString& text, const QRegExp&
227218
return false;
228219
}
229220

230-
const QTextCharFormat PythonSyntaxHighlighter::getTextCharFormat(const QString& colorName, const QString& style)
221+
const QTextCharFormat PythonSyntaxHighlighter::getTextCharFormat(
222+
const QString& colorName, const QString& style, const QString& backColorName)
231223
{
232224
QTextCharFormat charFormat;
233225
QColor color(colorName);
234226
charFormat.setForeground(color);
227+
228+
if (!backColorName.isEmpty()) {
229+
QColor backColor(backColorName);
230+
charFormat.setBackground(backColor);
231+
}
235232
if (style.contains("bold", Qt::CaseInsensitive))
236233
charFormat.setFontWeight(QFont::Bold);
237234
if (style.contains("italic", Qt::CaseInsensitive))

CodeEditor/pythonsyntaxhighlighter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class PythonSyntaxHighlighter : public QSyntaxHighlighter {
6363
void initializeRules();
6464
//! Highlighst multi-line strings, returns true if after processing we are still within the multi-line section.
6565
bool matchMultiline(const QString& text, const QRegExp& delimiter, const int inState, const QTextCharFormat& style);
66-
const QTextCharFormat getTextCharFormat(const QString& colorName, const QString& style = QString());
66+
const QTextCharFormat getTextCharFormat(const QString& colorName, const QString& style = QString(),
67+
const QString& backColorName = QString());
6768
QList<HighlightingRule> rules;
6869
QRegExp triSingleQuote;
6970
QRegExp triDoubleQuote;

main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ static MainView* mainView;
99
int main(int argc, char* argv[])
1010
{
1111
QApplication app(argc, argv);
12-
wchar_t c_s[] = L"expressPython";
13-
Py_SetProgramName(c_s);
12+
13+
wchar_t name[] = L"expressPython";
14+
Py_SetProgramName(name);
15+
1416
snip = new Snippets();
1517
mainView = new MainView();
1618
mainView->SetSnippets(snip);

0 commit comments

Comments
 (0)