Skip to content

Commit 6b48c2c

Browse files
committed
Use constexpr QColor where applicable
1 parent 47135ef commit 6b48c2c

File tree

12 files changed

+37
-36
lines changed

12 files changed

+37
-36
lines changed

src/cachesim/cacheplotwidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ void CachePlotWidget::setCache(std::shared_ptr<CacheSim> cache) {
120120
m_plot = new QChart();
121121
m_series = new QLineSeries(m_plot);
122122
auto defaultPen = m_series->pen(); // Inherit default pen state
123-
defaultPen.setColor(QColor(FoundersRock));
123+
defaultPen.setColor(Colors::FoundersRock);
124124
m_series->setName("Total");
125125
m_series->setPen(defaultPen);
126126
m_plot->addSeries(m_series);
127127
m_mavgSeries = new QLineSeries(m_plot);
128128
m_mavgSeries->setName("Moving avg.");
129-
defaultPen.setColor(QColor(Medalist));
129+
defaultPen.setColor(Colors::Medalist);
130130
m_mavgSeries->setPen(defaultPen);
131131
m_plot->addSeries(m_mavgSeries);
132132
m_plot->createDefaultAxes();

src/cachesim/callout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void Callout::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, Q
9595
path.lineTo(point2);
9696
path = path.simplified();
9797
}
98-
painter->setBrush(QColor(255, 255, 255));
98+
painter->setBrush(QColorConstants::White);
9999
painter->drawPath(path);
100100
painter->drawText(m_textRect, m_text);
101101
painter->restore();

src/defines.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#pragma once
22

3+
#include <QColor>
34
#include <QList>
45
#include <QMetaType>
56
#include <QPair>
67
#include <QString>
8+
79
#include <cstdint>
810
#include <map>
911
#include <vector>
@@ -46,14 +48,13 @@ class StagePCS {
4648
PC WB;
4749
};
4850

49-
enum Colors {
50-
// Berkeley primary color palette
51-
BerkeleyBlue = 0x003262,
52-
FoundersRock = 0x3B7EA1,
53-
CaliforniaGold = 0xFDB515,
54-
Medalist = 0xC4820E,
55-
FlatGreen = 0x4cde75
56-
};
51+
namespace Colors {
52+
constexpr QColor BerkeleyBlue = {0x00, 0x32, 0x62};
53+
constexpr QColor FoundersRock = {0x3B, 0x7E, 0xA1};
54+
constexpr QColor CaliforniaGold = {0xFD, 0xB5, 0x15};
55+
constexpr QColor Medalist = {0xC4, 0x82, 0x0E};
56+
constexpr QColor FlatGreen = {0x4c, 0xde, 0x75};
57+
}; // namespace Colors
5758

5859
namespace {
5960
static QMap<QString, displayTypeN> initDisplayTypes() {

src/editor/codeeditor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void CodeEditor::highlightCurrentLine() {
233233
if (!isReadOnly()) {
234234
QTextEdit::ExtraSelection selection;
235235

236-
QColor lineColor = QColor(Colors::Medalist).lighter(160);
236+
QColor lineColor = Colors::Medalist.lighter(160);
237237

238238
selection.format.setBackground(lineColor);
239239
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
@@ -247,7 +247,7 @@ void CodeEditor::highlightCurrentLine() {
247247

248248
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event) {
249249
QPainter painter(m_lineNumberArea);
250-
painter.fillRect(event->rect(), QColor(Qt::lightGray).lighter(120));
250+
painter.fillRect(event->rect(), QColorConstants::LightGray.lighter(120));
251251

252252
QTextBlock block = firstVisibleBlock();
253253
int blockNumber = block.blockNumber();
@@ -257,7 +257,7 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event) {
257257
while (block.isValid() && top <= event->rect().bottom()) {
258258
if (block.isVisible() && bottom >= event->rect().top()) {
259259
QString number = QString::number(blockNumber + 1);
260-
painter.setPen(QColor(Qt::gray).darker(130));
260+
painter.setPen(QColorConstants::Gray.darker(130));
261261
painter.drawText(0, top, m_lineNumberArea->width() - 3, fontMetrics().height(), Qt::AlignRight, number);
262262
}
263263

src/editor/csyntaxhighlighter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,24 @@ CSyntaxHighlighter::CSyntaxHighlighter(QTextDocument* parent, std::shared_ptr<As
4343
highlightingRules.append(rule);
4444
}
4545

46-
singleLineCommentFormat.setForeground(QColor(Colors::Medalist));
46+
singleLineCommentFormat.setForeground(Colors::Medalist);
4747
rule.pattern = QRegularExpression(QStringLiteral("//[^\n]*"));
4848
rule.format = singleLineCommentFormat;
4949
highlightingRules.append(rule);
5050

51-
multiLineCommentFormat.setForeground(QColor(Colors::Medalist));
51+
multiLineCommentFormat.setForeground(Colors::Medalist);
5252

53-
preprocessorFormat.setForeground(QColor(Qt::magenta).darker());
53+
preprocessorFormat.setForeground(QColorConstants::DarkMagenta);
5454
rule.pattern = QRegularExpression(QStringLiteral("^\\ *#[^ ]*"));
5555
rule.format = preprocessorFormat;
5656
highlightingRules.append(rule);
5757

58-
quotationFormat.setForeground(QColor(0x800000));
58+
quotationFormat.setForeground(QColor{0x80, 0x00, 0x00});
5959
rule.pattern = QRegularExpression(QStringLiteral("\".*\""));
6060
rule.format = quotationFormat;
6161
highlightingRules.append(rule);
6262

63-
functionFormat.setForeground(QColor(Colors::BerkeleyBlue));
63+
functionFormat.setForeground(Colors::BerkeleyBlue);
6464
rule.pattern = QRegularExpression(QStringLiteral("\\b[A-Za-z0-9_]+(?=\\()"));
6565
rule.format = functionFormat;
6666
highlightingRules.append(rule);

src/editor/rvsyntaxhighlighter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RVSyntaxHighlighter::RVSyntaxHighlighter(QTextDocument* parent, std::shared_ptr<
1010
HighlightingRule rule;
1111

1212
// General registers
13-
registerFormat.setForeground(QColor(0x800000));
13+
registerFormat.setForeground(QColor{0x80, 0x00, 0x00});
1414
rule.pattern = QRegularExpression("\\b[(a|s|t|x)][0-9]{1,2}");
1515
rule.format = registerFormat;
1616
m_highlightingRules.append(rule);
@@ -30,7 +30,7 @@ RVSyntaxHighlighter::RVSyntaxHighlighter(QTextDocument* parent, std::shared_ptr<
3030
}
3131

3232
// Instructions
33-
instructionFormat.setForeground(QColor(Colors::BerkeleyBlue));
33+
instructionFormat.setForeground(Colors::BerkeleyBlue);
3434
for (const auto& pattern : supportedOpcodes) {
3535
const QString regexPattern = "\\b" + pattern + "\\b";
3636
rule.pattern = QRegularExpression(regexPattern);
@@ -39,19 +39,19 @@ RVSyntaxHighlighter::RVSyntaxHighlighter(QTextDocument* parent, std::shared_ptr<
3939
}
4040

4141
// Labels
42-
labelFormat.setForeground(QColor(Colors::Medalist));
42+
labelFormat.setForeground(Colors::Medalist);
4343
rule.pattern = QRegularExpression(R"([\S]+:)");
4444
rule.format = labelFormat;
4545
m_highlightingRules.append(rule);
4646

4747
// Strings
48-
stringFormat.setForeground(QColor(0x800000));
48+
stringFormat.setForeground(QColor{0x80, 0x00, 0x00});
4949
rule.pattern = QRegularExpression(R"("(?:[^"]|\.)*")");
5050
rule.format = stringFormat;
5151
m_highlightingRules.append(rule);
5252

5353
// Immediates
54-
immediateFormat.setForeground(QColor(Qt::darkGreen));
54+
immediateFormat.setForeground(QColorConstants::DarkGreen);
5555
rule.pattern = QRegularExpression("\\b(?<![A-Za-z])[-+]?\\d+");
5656
rule.format = immediateFormat;
5757
m_highlightingRules.append(rule);
@@ -61,7 +61,7 @@ RVSyntaxHighlighter::RVSyntaxHighlighter(QTextDocument* parent, std::shared_ptr<
6161
m_highlightingRules.append(rule);
6262

6363
// Comments
64-
commentFormat.setForeground(QColor(Colors::Medalist));
64+
commentFormat.setForeground(Colors::Medalist);
6565
rule.pattern = QRegularExpression("[#]+.*");
6666
rule.format = commentFormat;
6767
m_highlightingRules.append(rule);

src/loaddialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void LoadDialog::openFileButtonTriggered() {
109109
void LoadDialog::paletteValidate(QWidget* w, bool valid) {
110110
QPalette palette = this->palette();
111111
if (!valid) {
112-
palette.setColor(QPalette::Base, QColor(0xEB8383));
112+
palette.setColor(QPalette::Base, QColor{0xEB, 0x83, 0x83});
113113
}
114114
w->setPalette(palette);
115115
}

src/programviewer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void ProgramViewer::setFollowEnabled(bool enabled) {
9494

9595
void ProgramViewer::updateHighlightedAddresses() {
9696
const unsigned stages = ProcessorHandler::getProcessor()->stageCount();
97-
QColor bg = QColor(Qt::red).lighter(120);
97+
QColor bg = QColorConstants::Red.lighter(120);
9898
const int decRatio = 100 + 80 / stages;
9999
QList<QTextEdit::ExtraSelection> highlights;
100100
std::set<unsigned long> highlightedPCs;
@@ -162,8 +162,8 @@ void ProgramViewer::breakpointAreaPaintEvent(QPaintEvent* event) {
162162
// redrawing the visible breakpoint area
163163
auto area = m_breakpointArea->rect();
164164
QLinearGradient gradient = QLinearGradient(area.topLeft(), area.bottomRight());
165-
gradient.setColorAt(0, QColor(Colors::FoundersRock).lighter(120));
166-
gradient.setColorAt(1, QColor(Colors::FoundersRock));
165+
gradient.setColorAt(0, Colors::FoundersRock.lighter(120));
166+
gradient.setColorAt(1, Colors::FoundersRock);
167167

168168
painter.fillRect(area, gradient);
169169

src/registermodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ QVariant RegisterModel::data(const QModelIndex& index, int role) const {
8282
if (role == Qt::ToolTipRole) {
8383
return tooltipData(idx);
8484
} else if (role == Qt::BackgroundRole && index.row() == m_mostRecentlyModifiedReg) {
85-
return QBrush(QColor(0xFDB515));
85+
return QBrush(QColor{0xFD, 0xB5, 0x15});
8686
}
8787

8888
switch (index.column()) {

0 commit comments

Comments
 (0)