Skip to content

Commit

Permalink
Use constexpr QColor where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbopet committed May 28, 2021
1 parent 47135ef commit 6b48c2c
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/cachesim/cacheplotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/cachesim/callout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 9 additions & 8 deletions src/defines.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#pragma once

#include <QColor>
#include <QList>
#include <QMetaType>
#include <QPair>
#include <QString>

#include <cstdint>
#include <map>
#include <vector>
Expand Down Expand Up @@ -46,14 +48,13 @@ class StagePCS {
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() {
Expand Down
6 changes: 3 additions & 3 deletions src/editor/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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);
}

Expand Down
10 changes: 5 additions & 5 deletions src/editor/csyntaxhighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/editor/rvsyntaxhighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/loaddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/programviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/registermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
6 changes: 3 additions & 3 deletions src/ripessettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6b48c2c

Please sign in to comment.