1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(Style): Move Style enums to enum class

This commit is contained in:
Anthony Bilinski 2022-03-12 03:52:53 -08:00
parent 0c967725df
commit b9c4b0075c
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
15 changed files with 104 additions and 103 deletions

View File

@ -97,7 +97,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
if (isMe)
authorFont.setBold(true);
QColor color = Style::getColor(Style::MainText);
QColor color = Style::getColor(Style::ColorPalette::MainText);
if (colorizeName) {
QByteArray hash = QCryptographicHash::hash((sender.toUtf8()), QCryptographicHash::Sha256);
auto lightness = color.lightnessF();

View File

@ -235,7 +235,7 @@ ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& doc
setDragMode(QGraphicsView::NoDrag);
setViewportUpdateMode(MinimalViewportUpdate);
setContextMenuPolicy(Qt::CustomContextMenu);
setBackgroundBrush(QBrush(Style::getColor(Style::GroundBase), Qt::SolidPattern));
setBackgroundBrush(QBrush(Style::getColor(Style::ColorPalette::GroundBase), Qt::SolidPattern));
// The selection rect for multi-line selection
selGraphItem = scene->addRect(0, 0, 0, 0, selectionRectColor.darker(120), selectionRectColor);
@ -798,8 +798,8 @@ void ChatWidget::fontChanged(const QFont& font)
void ChatWidget::reloadTheme()
{
setStyleSheet(Style::getStylesheet("chatArea/chatArea.css", settings));
setBackgroundBrush(QBrush(Style::getColor(Style::GroundBase), Qt::SolidPattern));
selectionRectColor = Style::getColor(Style::SelectText);
setBackgroundBrush(QBrush(Style::getColor(Style::ColorPalette::GroundBase), Qt::SolidPattern));
selectionRectColor = Style::getColor(Style::ColorPalette::SelectText);
selGraphItem->setBrush(QBrush(selectionRectColor));
selGraphItem->setPen(QPen(selectionRectColor.darker(120)));
setTypingNotification();

View File

@ -187,7 +187,7 @@ private:
int selClickedCol = -1;
ChatLine::Ptr selFirstRow;
ChatLine::Ptr selLastRow;
QColor selectionRectColor = Style::getColor(Style::SelectText);
QColor selectionRectColor = Style::getColor(Style::ColorPalette::SelectText);
SelectionMode selectionMode = SelectionMode::None;
QPointF clickPos;
QGraphicsRectItem* selGraphItem = nullptr;

View File

@ -54,9 +54,9 @@ FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile,
, coreFile{_coreFile}
, ui(new Ui::FileTransferWidget)
, fileInfo(file)
, backgroundColor(Style::getColor(Style::TransferMiddle))
, buttonColor(Style::getColor(Style::TransferWait))
, buttonBackgroundColor(Style::getColor(Style::GroundBase))
, backgroundColor(Style::getColor(Style::ColorPalette::TransferMiddle))
, buttonColor(Style::getColor(Style::ColorPalette::TransferWait))
, buttonBackgroundColor(Style::getColor(Style::ColorPalette::GroundBase))
, active(true)
, settings(settings_)
{
@ -387,7 +387,7 @@ void FileTransferWidget::setupButtons(ToxFile const& file)
ui->rightButton->setObjectName("cancel");
ui->rightButton->setToolTip(tr("Cancel transfer"));
setButtonColor(Style::getColor(Style::TransferGood));
setButtonColor(Style::getColor(Style::ColorPalette::TransferGood));
break;
case ToxFile::PAUSED:
@ -405,7 +405,7 @@ void FileTransferWidget::setupButtons(ToxFile const& file)
ui->rightButton->setObjectName("cancel");
ui->rightButton->setToolTip(tr("Cancel transfer"));
setButtonColor(Style::getColor(Style::TransferMiddle));
setButtonColor(Style::getColor(Style::ColorPalette::TransferMiddle));
break;
case ToxFile::INITIALIZING:
@ -534,14 +534,14 @@ void FileTransferWidget::updateBackgroundColor(const ToxFile::FileStatus status)
case ToxFile::INITIALIZING:
case ToxFile::PAUSED:
case ToxFile::TRANSMITTING:
setBackgroundColor(Style::getColor(Style::TransferMiddle), false);
setBackgroundColor(Style::getColor(Style::ColorPalette::TransferMiddle), false);
break;
case ToxFile::BROKEN:
case ToxFile::CANCELED:
setBackgroundColor(Style::getColor(Style::TransferBad), true);
setBackgroundColor(Style::getColor(Style::ColorPalette::TransferBad), true);
break;
case ToxFile::FINISHED:
setBackgroundColor(Style::getColor(Style::TransferGood), true);
setBackgroundColor(Style::getColor(Style::ColorPalette::TransferGood), true);
break;
default:
qCritical() << "Invalid file status";

View File

@ -231,7 +231,7 @@ void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWid
sel.cursor.setPosition(getSelectionEnd(), QTextCursor::KeepAnchor);
}
const QColor selectionColor = Style::getColor(Style::SelectText);
const QColor selectionColor = Style::getColor(Style::ColorPalette::SelectText);
sel.format.setBackground(selectionColor.lighter(selectionHasFocus ? 100 : 160));
sel.format.setForeground(selectionHasFocus ? Qt::white : Qt::black);
@ -463,7 +463,7 @@ void Text::selectText(QTextCursor& cursor, const std::pair<int, int>& point)
cursor.endEditBlock();
QTextCharFormat format;
format.setBackground(QBrush(Style::getColor(Style::SearchHighlighted)));
format.setBackground(QBrush(Style::getColor(Style::ColorPalette::SearchHighlighted)));
cursor.mergeCharFormat(format);
regenerate();
@ -473,9 +473,9 @@ void Text::selectText(QTextCursor& cursor, const std::pair<int, int>& point)
QColor Text::textColor() const
{
QColor c = Style::getColor(Style::MainText);
QColor c = Style::getColor(Style::ColorPalette::MainText);
if (textType == ACTION) {
c = Style::getColor(Style::Action);
c = Style::getColor(Style::ColorPalette::Action);
} else if (textType == CUSTOM) {
c = customColor;
}

View File

@ -43,7 +43,7 @@ public:
Text(DocumentCache&, Settings&, const QString& txt = "", const QFont& font = QFont(),
bool enableElide = false, const QString& rawText = QString(),
const TextType& type = NORMAL,
const QColor& custom = Style::getColor(Style::MainText));
const QColor& custom = Style::getColor(Style::ColorPalette::MainText));
virtual ~Text();
void setText(const QString& txt);

View File

@ -222,7 +222,7 @@ void Settings::loadGlobal()
s.beginGroup("Chat");
{
chatMessageFont = s.value("chatMessageFont", Style::getFont(Style::Big)).value<QFont>();
chatMessageFont = s.value("chatMessageFont", Style::getFont(Style::Font::Big)).value<QFont>();
}
s.endGroup();

View File

@ -128,7 +128,7 @@ ChatFormHeader::ChatFormHeader(Settings& settings_, QWidget* parent)
nameLabel = new CroppingLabel();
nameLabel->setObjectName("nameLabel");
nameLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize());
nameLabel->setMinimumHeight(Style::getFont(Style::Font::Medium).pixelSize());
nameLabel->setEditable(true);
nameLabel->setTextFormat(Qt::PlainText);
connect(nameLabel, &CroppingLabel::editFinished, this, &ChatFormHeader::nameChanged);

View File

@ -124,8 +124,8 @@ ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
statusMessageLabel = new CroppingLabel();
statusMessageLabel->setObjectName("statusLabel");
statusMessageLabel->setFont(Style::getFont(Style::Medium));
statusMessageLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize());
statusMessageLabel->setFont(Style::getFont(Style::Font::Medium));
statusMessageLabel->setMinimumHeight(Style::getFont(Style::Font::Medium).pixelSize());
statusMessageLabel->setTextFormat(Qt::PlainText);
statusMessageLabel->setContextMenuPolicy(Qt::CustomContextMenu);

View File

@ -106,7 +106,7 @@ GroupChatForm::GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_,
headWidget->setMode(mode);
setName(group->getName());
nusersLabel->setFont(Style::getFont(Style::Medium));
nusersLabel->setFont(Style::getFont(Style::Font::Medium));
nusersLabel->setObjectName("statusLabel");
retranslateUi();

View File

@ -116,7 +116,7 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo_, Settings& settings_,
// tox
toxId = new ClickableTE();
toxId->setFont(Style::getFont(Style::Small));
toxId->setFont(Style::getFont(Style::Font::Small));
toxId->setToolTip(bodyUI->toxId->toolTip());
QVBoxLayout* toxIdGroup = qobject_cast<QVBoxLayout*>(bodyUI->toxGroup->layout());

View File

@ -212,7 +212,7 @@ QString AboutForm::createLink(QString path, QString text) const
{
return QString::fromUtf8(
"<a href=\"%1\" style=\"text-decoration: underline; color:%2;\">%3</a>")
.arg(path, Style::getColor(Style::Link).name(), text);
.arg(path, Style::getColor(Style::ColorPalette::Link).name(), text);
}
AboutForm::~AboutForm()

View File

@ -94,8 +94,8 @@ void GenericChatroomWidget::compactChange(bool _compact)
mainLayout->addWidget(&statusPic);
mainLayout->addSpacing(5);
mainLayout->activate();
statusMessageLabel->setFont(Style::getFont(Style::Small));
nameLabel->setFont(Style::getFont(Style::Medium));
statusMessageLabel->setFont(Style::getFont(Style::Font::Small));
nameLabel->setFont(Style::getFont(Style::Font::Medium));
} else {
setFixedHeight(55);
avatar->setSize(QSize(40, 40));
@ -111,8 +111,8 @@ void GenericChatroomWidget::compactChange(bool _compact)
mainLayout->addWidget(&statusPic);
mainLayout->addSpacing(10);
mainLayout->activate();
statusMessageLabel->setFont(Style::getFont(Style::Medium));
nameLabel->setFont(Style::getFont(Style::Big));
statusMessageLabel->setFont(Style::getFont(Style::Font::Medium));
nameLabel->setFont(Style::getFont(Style::Font::Big));
}
}

View File

@ -82,45 +82,46 @@ QString qssifyFont(QFont font)
return QString("%1 %2px \"%3\"").arg(font.weight() * 8).arg(font.pixelSize()).arg(font.family());
}
QMap<Style::ColorPalette, QColor> palette;
using ColorPalette = Style::ColorPalette;
QMap<ColorPalette, QColor> palette;
QMap<QString, QString> dictColor;
QMap<QString, QString> dictFont;
QMap<QString, QString> dictTheme;
using MainTheme = Style::MainTheme;
const QList<Style::ThemeNameColor> themeNameColors = {
{Style::Light, QObject::tr("Default"), QColor()},
{Style::Light, QObject::tr("Blue"), QColor("#004aa4")},
{Style::Light, QObject::tr("Olive"), QColor("#97ba00")},
{Style::Light, QObject::tr("Red"), QColor("#c23716")},
{Style::Light, QObject::tr("Violet"), QColor("#4617b5")},
{Style::Dark, QObject::tr("Dark"), QColor()},
{Style::Dark, QObject::tr("Dark blue"), QColor("#00336d")},
{Style::Dark, QObject::tr("Dark olive"), QColor("#4d5f00")},
{Style::Dark, QObject::tr("Dark red"), QColor("#7a210d")},
{Style::Dark, QObject::tr("Dark violet"), QColor("#280d6c")}
{MainTheme::Light, QObject::tr("Default"), QColor()},
{MainTheme::Light, QObject::tr("Blue"), QColor("#004aa4")},
{MainTheme::Light, QObject::tr("Olive"), QColor("#97ba00")},
{MainTheme::Light, QObject::tr("Red"), QColor("#c23716")},
{MainTheme::Light, QObject::tr("Violet"), QColor("#4617b5")},
{MainTheme::Dark, QObject::tr("Dark"), QColor()},
{MainTheme::Dark, QObject::tr("Dark blue"), QColor("#00336d")},
{MainTheme::Dark, QObject::tr("Dark olive"), QColor("#4d5f00")},
{MainTheme::Dark, QObject::tr("Dark red"), QColor("#7a210d")},
{MainTheme::Dark, QObject::tr("Dark violet"), QColor("#280d6c")}
};
const QMap<Style::ColorPalette, QString> aliasColors = {
{Style::TransferGood, "transferGood"},
{Style::TransferWait, "transferWait"},
{Style::TransferBad, "transferBad"},
{Style::TransferMiddle, "transferMiddle"},
{Style::MainText,"mainText"},
{Style::NameActive, "nameActive"},
{Style::StatusActive,"statusActive"},
{Style::GroundExtra, "groundExtra"},
{Style::GroundBase, "groundBase"},
{Style::Orange, "orange"},
{Style::Yellow, "yellow"},
{Style::ThemeDark, "themeDark"},
{Style::ThemeMediumDark, "themeMediumDark"},
{Style::ThemeMedium, "themeMedium"},
{Style::ThemeLight, "themeLight"},
{Style::Action, "action"},
{Style::Link, "link"},
{Style::SearchHighlighted, "searchHighlighted"},
{Style::SelectText, "selectText"},
const QMap<ColorPalette, QString> aliasColors = {
{ColorPalette::TransferGood, "transferGood"},
{ColorPalette::TransferWait, "transferWait"},
{ColorPalette::TransferBad, "transferBad"},
{ColorPalette::TransferMiddle, "transferMiddle"},
{ColorPalette::MainText,"mainText"},
{ColorPalette::NameActive, "nameActive"},
{ColorPalette::StatusActive,"statusActive"},
{ColorPalette::GroundExtra, "groundExtra"},
{ColorPalette::GroundBase, "groundBase"},
{ColorPalette::Orange, "orange"},
{ColorPalette::Yellow, "yellow"},
{ColorPalette::ThemeDark, "themeDark"},
{ColorPalette::ThemeMediumDark, "themeMediumDark"},
{ColorPalette::ThemeMedium, "themeMedium"},
{ColorPalette::ThemeLight, "themeLight"},
{ColorPalette::Action, "action"},
{ColorPalette::Link, "link"},
{ColorPalette::SearchHighlighted, "searchHighlighted"},
{ColorPalette::SelectText, "selectText"},
};
// stylesheet filename, font -> stylesheet
@ -206,12 +207,12 @@ const QString Style::getImagePath(const QString& filename, Settings& settings)
}
}
QColor Style::getColor(Style::ColorPalette entry)
QColor Style::getColor(ColorPalette entry)
{
return palette[entry];
}
QFont Style::getFont(Style::Font font)
QFont Style::getFont(Font font)
{
// fonts as defined in
// https://github.com/ItsDuke/Tox-UI/blob/master/UI%20GUIDELINES.md
@ -228,7 +229,7 @@ QFont Style::getFont(Style::Font font)
appFont(defSize - 1, QFont::Light), // small light
};
return fonts[font];
return fonts[static_cast<int>(font)];
}
const QString Style::resolve(const QString& filename, Settings& settings, const QFont& baseFont)
@ -266,13 +267,13 @@ const QString Style::resolve(const QString& filename, Settings& settings, const
dictFont = {
{"@baseFont",
QString::fromUtf8("'%1' %2px").arg(baseFont.family()).arg(QFontInfo(baseFont).pixelSize())},
{"@extraBig", qssifyFont(Style::getFont(Style::ExtraBig))},
{"@big", qssifyFont(Style::getFont(Style::Big))},
{"@bigBold", qssifyFont(Style::getFont(Style::BigBold))},
{"@medium", qssifyFont(Style::getFont(Style::Medium))},
{"@mediumBold", qssifyFont(Style::getFont(Style::MediumBold))},
{"@small", qssifyFont(Style::getFont(Style::Small))},
{"@smallLight", qssifyFont(Style::getFont(Style::SmallLight))}};
{"@extraBig", qssifyFont(Style::getFont(Font::ExtraBig))},
{"@big", qssifyFont(Style::getFont(Font::Big))},
{"@bigBold", qssifyFont(Style::getFont(Font::BigBold))},
{"@medium", qssifyFont(Style::getFont(Font::Medium))},
{"@mediumBold", qssifyFont(Style::getFont(Font::MediumBold))},
{"@small", qssifyFont(Style::getFont(Font::Small))},
{"@smallLight", qssifyFont(Style::getFont(Font::SmallLight))}};
}
for (const QString& key : dictColor.keys()) {
@ -353,21 +354,21 @@ void Style::setThemeColor(const QColor& color)
{
if (!color.isValid()) {
// Reset to default
palette[ThemeDark] = getColor(ThemeDark);
palette[ThemeMediumDark] = getColor(ThemeMediumDark);
palette[ThemeMedium] = getColor(ThemeMedium);
palette[ThemeLight] = getColor(ThemeLight);
palette[ColorPalette::ThemeDark] = getColor(ColorPalette::ThemeDark);
palette[ColorPalette::ThemeMediumDark] = getColor(ColorPalette::ThemeMediumDark);
palette[ColorPalette::ThemeMedium] = getColor(ColorPalette::ThemeMedium);
palette[ColorPalette::ThemeLight] = getColor(ColorPalette::ThemeLight);
} else {
palette[ThemeDark] = color.darker(155);
palette[ThemeMediumDark] = color.darker(135);
palette[ThemeMedium] = color.darker(120);
palette[ThemeLight] = color.lighter(110);
palette[ColorPalette::ThemeDark] = color.darker(155);
palette[ColorPalette::ThemeMediumDark] = color.darker(135);
palette[ColorPalette::ThemeMedium] = color.darker(120);
palette[ColorPalette::ThemeLight] = color.lighter(110);
}
dictTheme["@themeDark"] = getColor(ThemeDark).name();
dictTheme["@themeMediumDark"] = getColor(ThemeMediumDark).name();
dictTheme["@themeMedium"] = getColor(ThemeMedium).name();
dictTheme["@themeLight"] = getColor(ThemeLight).name();
dictTheme["@themeDark"] = getColor(ColorPalette::ThemeDark).name();
dictTheme["@themeMediumDark"] = getColor(ColorPalette::ThemeMediumDark).name();
dictTheme["@themeMedium"] = getColor(ColorPalette::ThemeMedium).name();
dictTheme["@themeLight"] = getColor(ColorPalette::ThemeLight).name();
}
/**
@ -395,7 +396,7 @@ void Style::initPalette(Settings& settings)
auto keys = aliasColors.keys();
colourSettings.beginGroup("colors");
QMap<Style::ColorPalette, QString> c;
QMap<ColorPalette, QString> c;
for (auto k : keys) {
c[k] = colourSettings.value(aliasColors[k], "#000").toString();
palette[k] = QColor(colourSettings.value(aliasColors[k], "#000").toString());
@ -408,27 +409,27 @@ void Style::initPalette(Settings& settings)
void Style::initDictColor()
{
dictColor = {
{"@transferGood", Style::getColor(Style::TransferGood).name()},
{"@transferWait", Style::getColor(Style::TransferWait).name()},
{"@transferBad", Style::getColor(Style::TransferBad).name()},
{"@transferMiddle", Style::getColor(Style::TransferMiddle).name()},
{"@mainText", Style::getColor(Style::MainText).name()},
{"@nameActive", Style::getColor(Style::NameActive).name()},
{"@statusActive", Style::getColor(Style::StatusActive).name()},
{"@groundExtra", Style::getColor(Style::GroundExtra).name()},
{"@groundBase", Style::getColor(Style::GroundBase).name()},
{"@orange", Style::getColor(Style::Orange).name()},
{"@yellow", Style::getColor(Style::Yellow).name()},
{"@action", Style::getColor(Style::Action).name()},
{"@link", Style::getColor(Style::Link).name()},
{"@searchHighlighted", Style::getColor(Style::SearchHighlighted).name()},
{"@selectText", Style::getColor(Style::SelectText).name()}};
{"@transferGood", Style::getColor(ColorPalette::TransferGood).name()},
{"@transferWait", Style::getColor(ColorPalette::TransferWait).name()},
{"@transferBad", Style::getColor(ColorPalette::TransferBad).name()},
{"@transferMiddle", Style::getColor(ColorPalette::TransferMiddle).name()},
{"@mainText", Style::getColor(ColorPalette::MainText).name()},
{"@nameActive", Style::getColor(ColorPalette::NameActive).name()},
{"@statusActive", Style::getColor(ColorPalette::StatusActive).name()},
{"@groundExtra", Style::getColor(ColorPalette::GroundExtra).name()},
{"@groundBase", Style::getColor(ColorPalette::GroundBase).name()},
{"@orange", Style::getColor(ColorPalette::Orange).name()},
{"@yellow", Style::getColor(ColorPalette::Yellow).name()},
{"@action", Style::getColor(ColorPalette::Action).name()},
{"@link", Style::getColor(ColorPalette::Link).name()},
{"@searchHighlighted", Style::getColor(ColorPalette::SearchHighlighted).name()},
{"@selectText", Style::getColor(ColorPalette::SelectText).name()}};
}
QString Style::getThemePath(Settings& settings)
{
const int num = settings.getThemeColor();
if (themeNameColors[num].type == Dark) {
if (themeNameColors[num].type == MainTheme::Dark) {
return BuiltinThemeDarkPath;
}

View File

@ -29,7 +29,7 @@ class Settings;
class Style
{
public:
enum ColorPalette
enum class ColorPalette
{
TransferGood,
TransferWait,
@ -52,7 +52,7 @@ public:
SelectText
};
enum Font
enum class Font
{
ExtraBig,
Big,
@ -63,7 +63,7 @@ public:
SmallLight
};
enum MainTheme
enum class MainTheme
{
Light,
Dark