Skip to content

Commit ea89681

Browse files
committed
Some view improvements and settings
1 parent 5c4bbb4 commit ea89681

12 files changed

Lines changed: 2257 additions & 491 deletions

‎codeeditor.cpp‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
105105
{
106106
//paint on line number area
107107
QPainter painter(lineNumberArea);
108-
painter.fillRect(event->rect(), QColor(240, 240, 240));
108+
QSettings settings("SASM Project", "SASM");
109+
painter.fillRect(event->rect(), settings.value("linenumberpanelcolor", this->palette().color(QPalette::Window)).value<QColor>());
109110

110111
QTextBlock block = firstVisibleBlock();
111112
int blockNumber = block.blockNumber();
@@ -119,7 +120,7 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
119120
while (block.isValid() && top <= event->rect().bottom()) {
120121
if (block.isVisible() && bottom >= event->rect().top()) {
121122
QString number = QString::number(blockNumber + 1);
122-
painter.setPen(Qt::black);
123+
painter.setPen(settings.value("fontcolor", this->palette().color(QPalette::Text)).value<QColor>());
123124
painter.drawText(0, top, lineNumberArea->width() - debugAreaWidth, fontMetrics().height(),
124125
Qt::AlignRight, number);
125126

@@ -190,13 +191,14 @@ QList<int> *CodeEditor::getBreakpoints()
190191

191192
void CodeEditor::highlightCurrentLine()
192193
{
193-
if (!debugMode) {
194+
QSettings settings("SASM Project", "SASM");
195+
if (!debugMode && settings.value("currentlinemode", true).toBool()) {
194196
QList<QTextEdit::ExtraSelection> extraSelections;
195197

196198
if (!isReadOnly()) {
197199
QTextEdit::ExtraSelection selection;
198200

199-
QColor lineColor = QColor(232, 232, 255);
201+
QColor lineColor = settings.value("currentlinecolor", QColor(232, 232, 255)).value<QColor>();
200202

201203
selection.format.setBackground(lineColor);
202204
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
@@ -217,7 +219,8 @@ void CodeEditor::highlightDebugLine(int lineNumber)
217219
if (!isReadOnly()) {
218220
QTextEdit::ExtraSelection selection;
219221

220-
QColor lineColor = QColor(235, 200, 40);
222+
QSettings settings("SASM Project", "SASM");
223+
QColor lineColor = settings.value("debuglinecolor", QColor(235, 200, 40)).value<QColor>();
221224

222225
selection.format.setBackground(lineColor);
223226
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
@@ -296,9 +299,7 @@ void CodeEditor::keyPressEvent(QKeyEvent *e)
296299
int indentWidth = -1;
297300
switch (e->key()) {
298301
case (Qt::Key_Tab) :
299-
if (e->modifiers() & Qt::ControlModifier)
300-
deleteTab();
301-
else
302+
if (! (e->modifiers() & Qt::ShiftModifier))
302303
putTab();
303304
break;
304305
case (Qt::Key_Enter) :

‎highlighter.cpp‎

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,28 @@
4444
: QSyntaxHighlighter(parent)
4545
{
4646
//setting up text formats
47-
keywordFormat.setForeground(Qt::blue);
48-
keywordFormat.setFontWeight(QFont::Bold);
47+
names << "keywords" << "registers" << "numbers" << "memory" <<
48+
"labels" << "comments" << "system" << "iomacro" <<
49+
"quotation";
50+
defaultColors << QColor(Qt::blue) << QColor(153, 0, 204) << //according to colorNames
51+
QColor(255, 122, 0) << QColor(0, 128, 255) <<
52+
QColor(128, 0, 0) << QColor(Qt::darkGreen) <<
53+
QColor(Qt::darkCyan) << QColor(Qt::blue) <<
54+
QColor(128, 128, 128);
4955

50-
registerFormat.setForeground(QColor(153, 0, 204));
51-
52-
labelWithDotFormat.setForeground(Qt::black);
53-
54-
labelFormat.setForeground(QColor(128, 0, 0));
55-
56-
commentFormat.setForeground(Qt::darkGreen);
57-
58-
quotationFormat.setForeground(QColor(128, 128, 128));
59-
60-
memoryFormat.setForeground(QColor(0, 128, 255));
61-
62-
systemFormat.setForeground(Qt::darkCyan);
63-
64-
numberFormat.setForeground(QColor(255, 122, 0));
65-
66-
iomacrosFormat.setForeground(Qt::blue);
56+
formats << &keywordFormat << &registerFormat << &numberFormat << &memoryFormat <<
57+
&labelFormat << &commentFormat << &systemFormat << &iomacrosFormat <<
58+
&quotationFormat;
6759

60+
QSettings settings("SASM Project", "SASM");
61+
for (int i = 0; i < formats.size(); i++) {
62+
formats[i]->setForeground(settings.value(names[i] + "color", defaultColors[i]).value<QColor>());
63+
formats[i]->setBackground(settings.value(names[i] + "colorbg", QPalette().color(QPalette::Base)).value<QColor>());
64+
if (settings.value(names[i] + "bold", (i == 0) ? true : false).toBool())
65+
formats[i]->setFontWeight(QFont::Bold);
66+
formats[i]->setFontItalic(settings.value(names[i] + "italic", false).toBool());
67+
}
68+
labelWithDotFormat = this->format(0);
6869

6970
//setting up regular expressions
7071
HighlightingRule rule;
@@ -207,22 +208,10 @@
207208
highlightingRules.append(rule);
208209

209210
//labels
210-
rule.pattern = QRegExp("\\..+");
211-
rule.format = labelWithDotFormat;
212-
highlightingRules.append(rule);
213-
214211
rule.pattern = QRegExp("\\S+:");
215212
rule.format = labelFormat;
216213
highlightingRules.append(rule);
217214

218-
//quotations
219-
rule.pattern = QRegExp("\".*\"");
220-
rule.format = quotationFormat;
221-
highlightingRules.append(rule);
222-
223-
rule.pattern = QRegExp("'.*'");
224-
highlightingRules.append(rule);
225-
226215
//numbers
227216
rule.format = numberFormat;
228217
rule.pattern = QRegExp("\\b\\d+[bod]?\\b");
@@ -251,6 +240,14 @@
251240
highlightingRules.append(rule);
252241
}
253242

243+
//.labels and numbers with point
244+
rule.pattern = QRegExp("\\..+");
245+
rule.format = labelWithDotFormat;
246+
highlightingRules.append(rule);
247+
rule.pattern = QRegExp("\\b\\d+\\.\\d+\\b");
248+
rule.format = numberFormat;
249+
highlightingRules.append(rule);
250+
254251
//system instructions and preprocessor commands
255252
rule.format = systemFormat;
256253
QStringList systemPatterns;
@@ -268,6 +265,14 @@
268265
highlightingRules.append(rule);
269266
}
270267

268+
//quotations
269+
rule.pattern = QRegExp("\".*\"");
270+
rule.format = quotationFormat;
271+
highlightingRules.append(rule);
272+
273+
rule.pattern = QRegExp("'.*'");
274+
highlightingRules.append(rule);
275+
271276
//comments
272277
rule.pattern = QRegExp(";[^\n]*");
273278
rule.format = commentFormat;

‎highlighter.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
#define HIGHLIGHTER_H
4343

4444
#include <QSyntaxHighlighter>
45+
#include <QSettings>
46+
#include <QPalette>
47+
#include <QTextDocument>
4548

4649
class Highlighter : public QSyntaxHighlighter
4750
{
@@ -70,6 +73,9 @@ class Highlighter : public QSyntaxHighlighter
7073
QTextCharFormat systemFormat;
7174
QTextCharFormat numberFormat;
7275
QTextCharFormat iomacrosFormat;
76+
QList<QColor> defaultColors;
77+
QList<QString> names;
78+
QList<QTextCharFormat *> formats;
7379
};
7480

7581
#endif // HIGHLIGHTER_H

‎language_ru.qm‎

1.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)