matrixion/src/ui/Theme.cc

70 lines
1.6 KiB
C++
Raw Normal View History

2017-04-06 02:06:42 +03:00
#include <QDebug>
#include "Theme.h"
Theme::Theme(QObject *parent)
2017-08-20 13:47:22 +03:00
: QObject(parent)
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
setColor("Black", ui::Color::Black);
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
setColor("BrightWhite", ui::Color::BrightWhite);
setColor("FadedWhite", ui::Color::FadedWhite);
setColor("MediumWhite", ui::Color::MediumWhite);
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
setColor("BrightGreen", ui::Color::BrightGreen);
setColor("DarkGreen", ui::Color::DarkGreen);
setColor("LightGreen", ui::Color::LightGreen);
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
setColor("Gray", ui::Color::Gray);
setColor("Red", ui::Color::Red);
setColor("Blue", ui::Color::Blue);
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
setColor("Transparent", ui::Color::Transparent);
2017-04-06 02:06:42 +03:00
}
2017-10-01 12:11:33 +03:00
Theme::~Theme() {}
2017-04-06 02:06:42 +03:00
2017-08-20 13:47:22 +03:00
QColor
Theme::rgba(int r, int g, int b, qreal a) const
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
QColor color(r, g, b);
color.setAlphaF(a);
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
return color;
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
QColor
Theme::getColor(const QString &key) const
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
if (!colors_.contains(key)) {
qWarning() << "Color with key" << key << "could not be found";
return QColor();
}
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
return colors_.value(key);
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
void
Theme::setColor(const QString &key, const QColor &color)
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
colors_.insert(key, color);
2017-04-06 02:06:42 +03:00
}
2017-08-20 13:47:22 +03:00
void
Theme::setColor(const QString &key, ui::Color color)
2017-04-06 02:06:42 +03:00
{
2017-09-10 12:59:21 +03:00
static const QColor palette[] = {
QColor("#171919"),
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
QColor("#EBEBEB"), QColor("#C9C9C9"), QColor("#929292"),
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
QColor("#1C3133"), QColor("#577275"), QColor("#46A451"),
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
QColor("#5D6565"), QColor("#E22826"), QColor("#81B3A9"),
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
rgba(0, 0, 0, 0),
};
2017-04-06 02:06:42 +03:00
2017-09-10 12:59:21 +03:00
colors_.insert(key, palette[static_cast<int>(color)]);
2017-04-06 02:06:42 +03:00
}