refactor: centralize hardcoded color values into Colors namespace
Add src/util/colors.hpp with named constants for all QColor values (brand accents, badge colors, text shades, surface backgrounds) and replace scattered QColor constructor calls across 7 source files. Stylesheet string colors are intentionally left inline. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
37
src/main.cpp
37
src/main.cpp
@@ -1,5 +1,6 @@
|
||||
#include "mainwindow.hpp"
|
||||
#include "backend/qobuzbackend.hpp"
|
||||
#include "util/colors.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStyleFactory>
|
||||
@@ -15,24 +16,24 @@ int main(int argc, char *argv[])
|
||||
// Accent: #FFB232 (yellow-orange), Blue: #46B3EE, Backgrounds: #191919 / #141414
|
||||
app.setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
|
||||
QPalette darkPalette;
|
||||
darkPalette.setColor(QPalette::Window, QColor(0x19, 0x19, 0x19));
|
||||
darkPalette.setColor(QPalette::WindowText, QColor(0xe8, 0xe8, 0xe8));
|
||||
darkPalette.setColor(QPalette::Base, QColor(0x14, 0x14, 0x14));
|
||||
darkPalette.setColor(QPalette::AlternateBase, QColor(0x1e, 0x1e, 0x1e));
|
||||
darkPalette.setColor(QPalette::ToolTipBase, QColor(0x19, 0x19, 0x19));
|
||||
darkPalette.setColor(QPalette::ToolTipText, QColor(0xe8, 0xe8, 0xe8));
|
||||
darkPalette.setColor(QPalette::Text, QColor(0xe8, 0xe8, 0xe8));
|
||||
darkPalette.setColor(QPalette::Button, QColor(0x2a, 0x2a, 0x2a));
|
||||
darkPalette.setColor(QPalette::ButtonText, QColor(0xe8, 0xe8, 0xe8));
|
||||
darkPalette.setColor(QPalette::BrightText, QColor(0xFF, 0xB2, 0x32));
|
||||
darkPalette.setColor(QPalette::Link, QColor(0x46, 0xB3, 0xEE)); // Qobuz blue
|
||||
darkPalette.setColor(QPalette::Highlight, QColor(0xFF, 0xB2, 0x32)); // Qobuz orange
|
||||
darkPalette.setColor(QPalette::HighlightedText, QColor(0x10, 0x10, 0x10)); // dark on orange
|
||||
darkPalette.setColor(QPalette::PlaceholderText, QColor(0x66, 0x66, 0x66));
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(0x55, 0x55, 0x55));
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(0x55, 0x55, 0x55));
|
||||
darkPalette.setColor(QPalette::Mid, QColor(0x2f, 0x2f, 0x2f));
|
||||
darkPalette.setColor(QPalette::Dark, QColor(0x0e, 0x0e, 0x0e));
|
||||
darkPalette.setColor(QPalette::Window, Colors::WindowBg);
|
||||
darkPalette.setColor(QPalette::WindowText, Colors::LightText);
|
||||
darkPalette.setColor(QPalette::Base, Colors::BaseBg);
|
||||
darkPalette.setColor(QPalette::AlternateBase, Colors::AlternateBaseBg);
|
||||
darkPalette.setColor(QPalette::ToolTipBase, Colors::WindowBg);
|
||||
darkPalette.setColor(QPalette::ToolTipText, Colors::LightText);
|
||||
darkPalette.setColor(QPalette::Text, Colors::LightText);
|
||||
darkPalette.setColor(QPalette::Button, Colors::ButtonSurface);
|
||||
darkPalette.setColor(QPalette::ButtonText, Colors::LightText);
|
||||
darkPalette.setColor(QPalette::BrightText, Colors::QobuzOrange);
|
||||
darkPalette.setColor(QPalette::Link, Colors::QobuzBlue);
|
||||
darkPalette.setColor(QPalette::Highlight, Colors::QobuzOrange);
|
||||
darkPalette.setColor(QPalette::HighlightedText, Colors::HighlightedFg);
|
||||
darkPalette.setColor(QPalette::PlaceholderText, Colors::PlaceholderText);
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::Text, Colors::DisabledText);
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, Colors::DisabledText);
|
||||
darkPalette.setColor(QPalette::Mid, Colors::MidSurface);
|
||||
darkPalette.setColor(QPalette::Dark, Colors::DarkSurface);
|
||||
app.setPalette(darkPalette);
|
||||
|
||||
// Stylesheet tweaks: orange accent on scrollbars, focus rings, etc.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "tracklistmodel.hpp"
|
||||
#include "../util/colors.hpp"
|
||||
|
||||
#include <QJsonValue>
|
||||
#include <QColor>
|
||||
@@ -255,7 +256,7 @@ QVariant TrackListModel::data(const QModelIndex &index, int role) const
|
||||
QFont f; f.setBold(true); return f;
|
||||
}
|
||||
if (role == Qt::ForegroundRole)
|
||||
return QColor(0xFF, 0xB2, 0x32);
|
||||
return Colors::QobuzOrange;
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -278,8 +279,8 @@ QVariant TrackListModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
|
||||
if (role == Qt::ForegroundRole) {
|
||||
if (!t.streamable) return QColor(0x55, 0x55, 0x55);
|
||||
if (isPlaying) return QColor(0xFF, 0xB2, 0x32); // Qobuz orange
|
||||
if (!t.streamable) return Colors::DisabledText;
|
||||
if (isPlaying) return Colors::QobuzOrange;
|
||||
}
|
||||
|
||||
if (role == Qt::DecorationRole && index.column() == ColNumber && isPlaying) {
|
||||
|
||||
32
src/util/colors.hpp
Normal file
32
src/util/colors.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QColor>
|
||||
|
||||
namespace Colors {
|
||||
|
||||
// Brand accents
|
||||
inline const QColor QobuzOrange{0xFF, 0xB2, 0x32};
|
||||
inline const QColor QobuzBlue {0x46, 0xB3, 0xEE};
|
||||
|
||||
// Badge / indicator colors used in tree-view item foregrounds
|
||||
inline const QColor BadgeGreen {QStringLiteral("#2FA84F")};
|
||||
inline const QColor BadgeBlue {QStringLiteral("#2B7CD3")};
|
||||
inline const QColor BadgeGray {QStringLiteral("#8E8E93")};
|
||||
|
||||
// Text
|
||||
inline const QColor LightText {0xe8, 0xe8, 0xe8};
|
||||
inline const QColor SubduedText {0xaa, 0xaa, 0xaa};
|
||||
inline const QColor PlaceholderText{0x66, 0x66, 0x66};
|
||||
inline const QColor DisabledText {0x55, 0x55, 0x55};
|
||||
|
||||
// Surfaces / backgrounds
|
||||
inline const QColor WindowBg {0x19, 0x19, 0x19};
|
||||
inline const QColor BaseBg {0x14, 0x14, 0x14};
|
||||
inline const QColor AlternateBaseBg{0x1e, 0x1e, 0x1e};
|
||||
inline const QColor ButtonSurface {0x2a, 0x2a, 0x2a};
|
||||
inline const QColor ContextBg {0x1a, 0x1a, 0x1a};
|
||||
inline const QColor MidSurface {0x2f, 0x2f, 0x2f};
|
||||
inline const QColor DarkSurface {0x0e, 0x0e, 0x0e};
|
||||
inline const QColor HighlightedFg {0x10, 0x10, 0x10};
|
||||
|
||||
} // namespace Colors
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../util/colors.hpp"
|
||||
|
||||
#include <QTreeWidget>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QHeaderView>
|
||||
@@ -89,7 +91,7 @@ public:
|
||||
auto *item = new QTreeWidgetItem(this);
|
||||
if (hiRes) {
|
||||
item->setText(0, QStringLiteral("H"));
|
||||
item->setForeground(0, QColor(QStringLiteral("#FFB232")));
|
||||
item->setForeground(0, Colors::QobuzOrange);
|
||||
item->setFont(0, hiResFont);
|
||||
item->setTextAlignment(0, Qt::AlignCenter);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../backend/qobuzbackend.hpp"
|
||||
#include "../../util/colors.hpp"
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QWidget>
|
||||
@@ -32,11 +33,11 @@ namespace Context
|
||||
{
|
||||
QPainter p(this);
|
||||
if (m_pix.isNull()) {
|
||||
p.fillRect(rect(), QColor(0x1a, 0x1a, 0x1a));
|
||||
p.fillRect(rect(), Colors::ContextBg);
|
||||
return;
|
||||
}
|
||||
const QPixmap scaled = m_pix.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
p.fillRect(rect(), QColor(0x1a, 0x1a, 0x1a));
|
||||
p.fillRect(rect(), Colors::ContextBg);
|
||||
p.drawPixmap((width() - scaled.width()) / 2,
|
||||
(height() - scaled.height()) / 2,
|
||||
scaled);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "genrebrowser.hpp"
|
||||
#include "../util/colors.hpp"
|
||||
|
||||
#include <QAction>
|
||||
#include <QDialog>
|
||||
@@ -740,7 +741,7 @@ void GenreBrowserView::setPlaylistItems(const QJsonArray &items, bool append)
|
||||
auto *item = new QTreeWidgetItem(m_playlistList,
|
||||
QStringList{QStringLiteral("P"), name, owner, tracksCount > 0 ? QString::number(tracksCount) : QString()});
|
||||
item->setData(0, Qt::UserRole, playlistId);
|
||||
item->setForeground(0, QColor(QStringLiteral("#2B7CD3")));
|
||||
item->setForeground(0, Colors::BadgeBlue);
|
||||
item->setFont(0, tagFont);
|
||||
item->setTextAlignment(0, Qt::AlignCenter);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "view.hpp"
|
||||
#include "../../util/colors.hpp"
|
||||
#include "../../util/trackinfo.hpp"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
@@ -125,7 +126,7 @@ void SearchTab::onMostPopularResult(const QJsonObject &result)
|
||||
const QString artist = content["performer"].toObject()["name"].toString();
|
||||
const QString album = content["album"].toObject()["title"].toString();
|
||||
item->setText(0, QStringLiteral("T"));
|
||||
item->setForeground(0, QColor(QStringLiteral("#2FA84F")));
|
||||
item->setForeground(0, Colors::BadgeGreen);
|
||||
item->setFont(0, badgeFont);
|
||||
item->setTextAlignment(0, Qt::AlignCenter);
|
||||
item->setText(1, title);
|
||||
@@ -139,8 +140,8 @@ void SearchTab::onMostPopularResult(const QJsonObject &result)
|
||||
|| content["rights"].toObject()["hires_streamable"].toBool();
|
||||
item->setText(0, hiRes ? QStringLiteral("H") : QStringLiteral("A"));
|
||||
item->setForeground(0, hiRes
|
||||
? QColor(QStringLiteral("#FFB232"))
|
||||
: QColor(QStringLiteral("#8E8E93")));
|
||||
? Colors::QobuzOrange
|
||||
: Colors::BadgeGray);
|
||||
item->setFont(0, badgeFont);
|
||||
item->setTextAlignment(0, Qt::AlignCenter);
|
||||
item->setText(1, title);
|
||||
@@ -149,7 +150,7 @@ void SearchTab::onMostPopularResult(const QJsonObject &result)
|
||||
item->setData(1, IdRole, content["id"].toString());
|
||||
} else if (type == QStringLiteral("artists")) {
|
||||
item->setText(0, QStringLiteral("A"));
|
||||
item->setForeground(0, QColor(QStringLiteral("#2B7CD3")));
|
||||
item->setForeground(0, Colors::BadgeBlue);
|
||||
item->setFont(0, badgeFont);
|
||||
item->setTextAlignment(0, Qt::AlignCenter);
|
||||
item->setText(1, content["name"].toString());
|
||||
@@ -193,7 +194,7 @@ void SearchTab::onSearchResult(const QJsonObject &result)
|
||||
QStringList{QString(), a["title"].toString(), artist});
|
||||
if (hiRes) {
|
||||
item->setText(0, QStringLiteral("H"));
|
||||
item->setForeground(0, QColor(QStringLiteral("#FFB232")));
|
||||
item->setForeground(0, Colors::QobuzOrange);
|
||||
item->setFont(0, hiResFont);
|
||||
item->setTextAlignment(0, Qt::AlignCenter);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../util/colors.hpp"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
@@ -63,7 +65,7 @@ public:
|
||||
|
||||
m_meta = new QLabel(info);
|
||||
QPalette mp = m_meta->palette();
|
||||
mp.setColor(QPalette::WindowText, QColor(0xaa, 0xaa, 0xaa));
|
||||
mp.setColor(QPalette::WindowText, Colors::SubduedText);
|
||||
m_meta->setPalette(mp);
|
||||
vlay->addWidget(m_meta);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user