Use constexpr QColor where applicable
MODIFY
external/VSRTL
external/VSRTL
-Subproject commit 9d808febca3805e277cf380cf5d0326ac785f7e2
+Subproject commit 1b8be3b8549c21e95eecace1290dba3cc4e3a40d

MODIFY
src/cachesim/cacheplotwidget.cpp
src/cachesim/cacheplotwidget.cpp
@@ -120,13 +120,13 @@ void CachePlotWidget::setCache(std::shared_ptr<CacheSim> cache) {
m_plot = new QChart();
m_series = new QLineSeries(m_plot);
auto defaultPen = m_series->pen(); // Inherit default pen state
- defaultPen.setColor(QColor(FoundersRock));
+ defaultPen.setColor(Colors::FoundersRock);
m_series->setName("Total");
m_series->setPen(defaultPen);
m_plot->addSeries(m_series);
m_mavgSeries = new QLineSeries(m_plot);
m_mavgSeries->setName("Moving avg.");
- defaultPen.setColor(QColor(Medalist));
+ defaultPen.setColor(Colors::Medalist);
m_mavgSeries->setPen(defaultPen);
m_plot->addSeries(m_mavgSeries);
m_plot->createDefaultAxes();

MODIFY
src/cachesim/callout.cpp
src/cachesim/callout.cpp
@@ -95,7 +95,7 @@ void Callout::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, Q
path.lineTo(point2);
path = path.simplified();
}
- painter->setBrush(QColor(255, 255, 255));
+ painter->setBrush(QColorConstants::White);
painter->drawPath(path);
painter->drawText(m_textRect, m_text);
painter->restore();

MODIFY
src/defines.h
src/defines.h
#pragma once
+#include <QColor>
#include <QList>
#include <QMetaType>
#include <QPair>
#include <QString>
+
#include <cstdint>
#include <map>
#include <vector>
@@ -46,14 +48,13 @@ public:
PC WB;
};
-enum Colors {
- // Berkeley primary color palette
- BerkeleyBlue = 0x003262,
- FoundersRock = 0x3B7EA1,
- CaliforniaGold = 0xFDB515,
- Medalist = 0xC4820E,
- FlatGreen = 0x4cde75
-};
+namespace Colors {
+constexpr QColor BerkeleyBlue = {0x00, 0x32, 0x62};
+constexpr QColor FoundersRock = {0x3B, 0x7E, 0xA1};
+constexpr QColor CaliforniaGold = {0xFD, 0xB5, 0x15};
+constexpr QColor Medalist = {0xC4, 0x82, 0x0E};
+constexpr QColor FlatGreen = {0x4c, 0xde, 0x75};
+}; // namespace Colors
namespace {
static QMap<QString, displayTypeN> initDisplayTypes() {

MODIFY
src/editor/codeeditor.cpp
src/editor/codeeditor.cpp
@@ -233,7 +233,7 @@ void CodeEditor::highlightCurrentLine() {
if (!isReadOnly()) {
QTextEdit::ExtraSelection selection;
- QColor lineColor = QColor(Colors::Medalist).lighter(160);
+ QColor lineColor = Colors::Medalist.lighter(160);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
@@ -247,7 +247,7 @@ void CodeEditor::highlightCurrentLine() {
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event) {
QPainter painter(m_lineNumberArea);
- painter.fillRect(event->rect(), QColor(Qt::lightGray).lighter(120));
+ painter.fillRect(event->rect(), QColorConstants::LightGray.lighter(120));
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
@@ -257,7 +257,7 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event) {
while (block.isValid() && top <= event->rect().bottom()) {
if (block.isVisible() && bottom >= event->rect().top()) {
QString number = QString::number(blockNumber + 1);
- painter.setPen(QColor(Qt::gray).darker(130));
+ painter.setPen(QColorConstants::Gray.darker(130));
painter.drawText(0, top, m_lineNumberArea->width() - 3, fontMetrics().height(), Qt::AlignRight, number);
}

MODIFY
src/editor/csyntaxhighlighter.cpp
src/editor/csyntaxhighlighter.cpp
@@ -43,24 +43,24 @@ CSyntaxHighlighter::CSyntaxHighlighter(QTextDocument* parent, std::shared_ptr<As
highlightingRules.append(rule);
}
- singleLineCommentFormat.setForeground(QColor(Colors::Medalist));
+ singleLineCommentFormat.setForeground(Colors::Medalist);
rule.pattern = QRegularExpression(QStringLiteral("//[^\n]*"));
rule.format = singleLineCommentFormat;
highlightingRules.append(rule);
- multiLineCommentFormat.setForeground(QColor(Colors::Medalist));
+ multiLineCommentFormat.setForeground(Colors::Medalist);
- preprocessorFormat.setForeground(QColor(Qt::magenta).darker());
+ preprocessorFormat.setForeground(QColorConstants::DarkMagenta);
rule.pattern = QRegularExpression(QStringLiteral("^\\ *#[^ ]*"));
rule.format = preprocessorFormat;
highlightingRules.append(rule);
- quotationFormat.setForeground(QColor(0x800000));
+ quotationFormat.setForeground(QColor{0x80, 0x00, 0x00});
rule.pattern = QRegularExpression(QStringLiteral("\".*\""));
rule.format = quotationFormat;
highlightingRules.append(rule);
- functionFormat.setForeground(QColor(Colors::BerkeleyBlue));
+ functionFormat.setForeground(Colors::BerkeleyBlue);
rule.pattern = QRegularExpression(QStringLiteral("\\b[A-Za-z0-9_]+(?=\\()"));
rule.format = functionFormat;
highlightingRules.append(rule);

MODIFY
src/editor/rvsyntaxhighlighter.cpp
src/editor/rvsyntaxhighlighter.cpp
@@ -10,7 +10,7 @@ RVSyntaxHighlighter::RVSyntaxHighlighter(QTextDocument* parent, std::shared_ptr<
HighlightingRule rule;
// General registers
- registerFormat.setForeground(QColor(0x800000));
+ registerFormat.setForeground(QColor{0x80, 0x00, 0x00});
rule.pattern = QRegularExpression("\\b[(a|s|t|x)][0-9]{1,2}");
rule.format = registerFormat;
m_highlightingRules.append(rule);
@@ -30,7 +30,7 @@ RVSyntaxHighlighter::RVSyntaxHighlighter(QTextDocument* parent, std::shared_ptr<
}
// Instructions
- instructionFormat.setForeground(QColor(Colors::BerkeleyBlue));
+ instructionFormat.setForeground(Colors::BerkeleyBlue);
for (const auto& pattern : supportedOpcodes) {
const QString regexPattern = "\\b" + pattern + "\\b";
rule.pattern = QRegularExpression(regexPattern);
@@ -39,19 +39,19 @@ RVSyntaxHighlighter::RVSyntaxHighlighter(QTextDocument* parent, std::shared_ptr<
}
// Labels
- labelFormat.setForeground(QColor(Colors::Medalist));
+ labelFormat.setForeground(Colors::Medalist);
rule.pattern = QRegularExpression(R"([\S]+:)");
rule.format = labelFormat;
m_highlightingRules.append(rule);
// Strings
- stringFormat.setForeground(QColor(0x800000));
+ stringFormat.setForeground(QColor{0x80, 0x00, 0x00});
rule.pattern = QRegularExpression(R"("(?:[^"]|\.)*")");
rule.format = stringFormat;
m_highlightingRules.append(rule);
// Immediates
- immediateFormat.setForeground(QColor(Qt::darkGreen));
+ immediateFormat.setForeground(QColorConstants::DarkGreen);
rule.pattern = QRegularExpression("\\b(?<![A-Za-z])[-+]?\\d+");
rule.format = immediateFormat;
m_highlightingRules.append(rule);
@@ -61,7 +61,7 @@ RVSyntaxHighlighter::RVSyntaxHighlighter(QTextDocument* parent, std::shared_ptr<
m_highlightingRules.append(rule);
// Comments
- commentFormat.setForeground(QColor(Colors::Medalist));
+ commentFormat.setForeground(Colors::Medalist);
rule.pattern = QRegularExpression("[#]+.*");
rule.format = commentFormat;
m_highlightingRules.append(rule);

MODIFY
src/loaddialog.cpp
src/loaddialog.cpp
@@ -109,7 +109,7 @@ void LoadDialog::openFileButtonTriggered() {
void LoadDialog::paletteValidate(QWidget* w, bool valid) {
QPalette palette = this->palette();
if (!valid) {
- palette.setColor(QPalette::Base, QColor(0xEB8383));
+ palette.setColor(QPalette::Base, QColor{0xEB, 0x83, 0x83});
}
w->setPalette(palette);
}

MODIFY
src/programviewer.cpp
src/programviewer.cpp
@@ -94,7 +94,7 @@ void ProgramViewer::setFollowEnabled(bool enabled) {
void ProgramViewer::updateHighlightedAddresses() {
const unsigned stages = ProcessorHandler::getProcessor()->stageCount();
- QColor bg = QColor(Qt::red).lighter(120);
+ QColor bg = QColorConstants::Red.lighter(120);
const int decRatio = 100 + 80 / stages;
QList<QTextEdit::ExtraSelection> highlights;
std::set<unsigned long> highlightedPCs;
@@ -162,8 +162,8 @@ void ProgramViewer::breakpointAreaPaintEvent(QPaintEvent* event) {
// redrawing the visible breakpoint area
auto area = m_breakpointArea->rect();
QLinearGradient gradient = QLinearGradient(area.topLeft(), area.bottomRight());
- gradient.setColorAt(0, QColor(Colors::FoundersRock).lighter(120));
- gradient.setColorAt(1, QColor(Colors::FoundersRock));
+ gradient.setColorAt(0, Colors::FoundersRock.lighter(120));
+ gradient.setColorAt(1, Colors::FoundersRock);
painter.fillRect(area, gradient);

MODIFY
src/registermodel.cpp
src/registermodel.cpp
@@ -82,7 +82,7 @@ QVariant RegisterModel::data(const QModelIndex& index, int role) const {
if (role == Qt::ToolTipRole) {
return tooltipData(idx);
} else if (role == Qt::BackgroundRole && index.row() == m_mostRecentlyModifiedReg) {
- return QBrush(QColor(0xFDB515));
+ return QBrush(QColor{0xFD, 0xB5, 0x15});
}
switch (index.column()) {

MODIFY
src/ripessettings.cpp
src/ripessettings.cpp
@@ -15,10 +15,10 @@ const std::map<QString, QVariant> s_defaultSettings = {
{RIPES_SETTING_CCARGS, "-O0"},
{RIPES_SETTING_LDARGS, "-static-libgcc -lm"}, // Ensure statically linked executable + link with math library
{RIPES_SETTING_CONSOLEECHO, "true"},
- {RIPES_SETTING_CONSOLEBG, QColor(Qt::white)},
- {RIPES_SETTING_CONSOLEFONTCOLOR, QColor(Qt::black)},
+ {RIPES_SETTING_CONSOLEBG, QColorConstants::White},
+ {RIPES_SETTING_CONSOLEFONTCOLOR, QColorConstants::Black},
{RIPES_SETTING_CONSOLEFONT, QVariant() /* Let Console define its own default font */},
- {RIPES_SETTING_CONSOLEFONT, QColor(Qt::black)},
+ {RIPES_SETTING_CONSOLEFONT, QColorConstants::Black},
{RIPES_SETTING_INDENTAMT, 4},
{RIPES_SETTING_ASSEMBLER_TEXTSTART, 0x0},

MODIFY
src/settingsdialog.cpp
src/settingsdialog.cpp
@@ -241,10 +241,10 @@ QWidget* SettingsDialog::createCompilerPage() {
void SettingsDialog::CCPathChanged(CCManager::CCRes res) {
QPalette palette = this->palette();
if (res.success) {
- palette.setColor(QPalette::Base, QColor(Qt::green).lighter());
+ palette.setColor(QPalette::Base, QColorConstants::Green.lighter());
m_compileInfoHeader->setText("Compile command:");
} else {
- palette.setColor(QPalette::Base, QColor(Qt::red).lighter());
+ palette.setColor(QPalette::Base, QColorConstants::Red.lighter());
m_compileInfoHeader->setText("Error:");
}
m_ccpath->setPalette(palette);

Use constexpr QColor where applicable