Add Avatar component and Style and Theme lib clases

This commit is contained in:
johanneshilden 2017-09-28 13:12:30 +03:00
parent e02b688216
commit a3c2a81142
9 changed files with 1011 additions and 0 deletions

View File

@ -0,0 +1,289 @@
#include "components/qtmaterialavatar.h"
#include "components/qtmaterialavatar_p.h"
#include <QPainter>
#include "lib/qtmaterialstyle.h"
/*!
* \class QtMaterialAvatarPrivate
* \internal
*/
/*!
* \internal
*/
QtMaterialAvatarPrivate::QtMaterialAvatarPrivate(QtMaterialAvatar *q)
: q_ptr(q)
{
}
/*!
* \internal
*/
QtMaterialAvatarPrivate::~QtMaterialAvatarPrivate()
{
}
/*!
* \internal
*/
void QtMaterialAvatarPrivate::init()
{
Q_Q(QtMaterialAvatar);
size = 40;
type = Material::LetterAvatar;
useThemeColors = true;
QFont font(q->font());
font.setPointSizeF(16);
q->setFont(font);
QSizePolicy policy(QSizePolicy::MinimumExpanding,
QSizePolicy::MinimumExpanding);
q->setSizePolicy(policy);
}
/*!
* \class QtMaterialAvatar
*/
QtMaterialAvatar::QtMaterialAvatar(QWidget *parent)
: QWidget(parent),
d_ptr(new QtMaterialAvatarPrivate(this))
{
d_func()->init();
}
QtMaterialAvatar::QtMaterialAvatar(const QIcon &icon, QWidget *parent)
: QWidget(parent),
d_ptr(new QtMaterialAvatarPrivate(this))
{
d_func()->init();
setIcon(icon);
}
QtMaterialAvatar::QtMaterialAvatar(const QChar &letter, QWidget *parent)
: QWidget(parent),
d_ptr(new QtMaterialAvatarPrivate(this))
{
d_func()->init();
setLetter(letter);
}
QtMaterialAvatar::QtMaterialAvatar(const QImage &image, QWidget *parent)
: QWidget(parent),
d_ptr(new QtMaterialAvatarPrivate(this))
{
d_func()->init();
setImage(image);
}
QtMaterialAvatar::~QtMaterialAvatar()
{
}
void QtMaterialAvatar::setUseThemeColors(bool value)
{
Q_D(QtMaterialAvatar);
if (d->useThemeColors == value) {
return;
}
d->useThemeColors = value;
update();
}
bool QtMaterialAvatar::useThemeColors() const
{
Q_D(const QtMaterialAvatar);
return d->useThemeColors;
}
void QtMaterialAvatar::setTextColor(const QColor &color)
{
Q_D(QtMaterialAvatar);
d->textColor = color;
setUseThemeColors(false);
}
QColor QtMaterialAvatar::textColor() const
{
Q_D(const QtMaterialAvatar);
if (d->useThemeColors || !d->textColor.isValid()) {
return QtMaterialStyle::instance().themeColor("canvas");
} else {
return d->textColor;
}
}
void QtMaterialAvatar::setBackgroundColor(const QColor &color)
{
Q_D(QtMaterialAvatar);
d->backgroundColor = color;
setUseThemeColors(false);
}
QColor QtMaterialAvatar::backgroundColor() const
{
Q_D(const QtMaterialAvatar);
if (d->useThemeColors || !d->backgroundColor.isValid()) {
return QtMaterialStyle::instance().themeColor("primary1");
} else {
return d->backgroundColor;
}
}
/*!
* \reimp
*/
QSize QtMaterialAvatar::sizeHint() const
{
Q_D(const QtMaterialAvatar);
return QSize(d->size+2, d->size+2);
}
void QtMaterialAvatar::setSize(int size)
{
Q_D(QtMaterialAvatar);
d->size = size;
if (!d->image.isNull()) {
d->pixmap = QPixmap::fromImage(d->image.scaled(d->size, d->size,
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation));
}
QFont f(font());
f.setPointSizeF(size*16/40);
setFont(f);
update();
}
int QtMaterialAvatar::size() const
{
Q_D(const QtMaterialAvatar);
return d->size;
}
void QtMaterialAvatar::setLetter(const QChar &letter)
{
Q_D(QtMaterialAvatar);
d->letter = letter;
d->type = Material::LetterAvatar;
update();
}
void QtMaterialAvatar::setImage(const QImage &image)
{
Q_D(QtMaterialAvatar);
d->image = image;
d->type = Material::ImageAvatar;
d->pixmap = QPixmap::fromImage(image.scaled(d->size, d->size,
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation));
update();
}
void QtMaterialAvatar::setIcon(const QIcon &icon)
{
Q_D(QtMaterialAvatar);
d->icon = icon;
d->type = Material::IconAvatar;
update();
}
Material::AvatarType QtMaterialAvatar::type() const
{
Q_D(const QtMaterialAvatar);
return d->type;
}
/*!
* \reimp
*/
void QtMaterialAvatar::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
Q_D(QtMaterialAvatar);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QRect r = rect();
const qreal hs = d->size/2;
if (!isEnabled())
{
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(QtMaterialStyle::instance().themeColor("disabled"));
painter.setPen(Qt::NoPen);
painter.setBrush(brush);
painter.drawEllipse(QRectF((width()-d->size)/2, (height()-d->size)/2,
d->size, d->size));
return;
}
if (Material::ImageAvatar != d->type)
{
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(backgroundColor());
painter.setPen(Qt::NoPen);
painter.setBrush(brush);
painter.drawEllipse(QRectF((width()-d->size)/2, (height()-d->size)/2,
d->size, d->size));
}
switch (d->type)
{
case Material::ImageAvatar:
{
QPainterPath path;
path.addEllipse(width()/2-hs, height()/2-hs, d->size, d->size);
painter.setClipPath(path);
painter.drawPixmap(QRect(width()/2-hs, height()/2-hs, d->size, d->size),
d->pixmap);
break;
}
case Material::IconAvatar:
{
QRect iconGeometry((width()-hs)/2, (height()-hs)/2, hs, hs);
QPixmap pixmap = d->icon.pixmap(hs, hs);
QPainter icon(&pixmap);
icon.setCompositionMode(QPainter::CompositionMode_SourceIn);
icon.fillRect(pixmap.rect(), textColor());
painter.drawPixmap(iconGeometry, pixmap);
break;
}
case Material::LetterAvatar:
{
painter.setPen(textColor());
painter.setBrush(Qt::NoBrush);
painter.drawText(r, Qt::AlignCenter, QString(d->letter));
break;
}
default:
break;
}
}

View File

@ -0,0 +1,50 @@
#ifndef QTMATERIALAVATAR_H
#define QTMATERIALAVATAR_H
#include <QWidget>
#include "lib/qtmaterialtheme.h"
class QtMaterialAvatarPrivate;
class QtMaterialAvatar : public QWidget
{
Q_OBJECT
public:
explicit QtMaterialAvatar(QWidget *parent = 0);
explicit QtMaterialAvatar(const QIcon &icon, QWidget *parent = 0);
explicit QtMaterialAvatar(const QChar &letter, QWidget *parent = 0);
explicit QtMaterialAvatar(const QImage &image, QWidget *parent = 0);
~QtMaterialAvatar();
void setUseThemeColors(bool value);
bool useThemeColors() const;
void setTextColor(const QColor &color);
QColor textColor() const;
void setBackgroundColor(const QColor &color);
QColor backgroundColor() const;
QSize sizeHint() const Q_DECL_OVERRIDE;
void setSize(int size);
int size() const;
void setLetter(const QChar &letter);
void setImage(const QImage &image);
void setIcon(const QIcon &icon);
Material::AvatarType type() const;
protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
const QScopedPointer<QtMaterialAvatarPrivate> d_ptr;
private:
Q_DISABLE_COPY(QtMaterialAvatar)
Q_DECLARE_PRIVATE(QtMaterialAvatar)
};
#endif // QTMATERIALAVATAR_H

View File

@ -0,0 +1,37 @@
#ifndef QTMATERIALAVATAR_P_H
#define QTMATERIALAVATAR_P_H
#include <QtGlobal>
#include <QChar>
#include <QImage>
#include <QIcon>
#include <QPixmap>
#include <QColor>
#include "lib/qtmaterialtheme.h"
class QtMaterialAvatar;
class QtMaterialAvatarPrivate
{
Q_DISABLE_COPY(QtMaterialAvatarPrivate)
Q_DECLARE_PUBLIC(QtMaterialAvatar)
public:
QtMaterialAvatarPrivate(QtMaterialAvatar *q);
~QtMaterialAvatarPrivate();
void init();
QtMaterialAvatar *const q_ptr;
int size;
Material::AvatarType type;
QChar letter;
QImage image;
QIcon icon;
QPixmap pixmap;
bool useThemeColors;
QColor textColor;
QColor backgroundColor;
};
#endif // QTMATERIALAVATAR_P_H

57
lib/qtmaterialstyle.cpp Normal file
View File

@ -0,0 +1,57 @@
#include "lib/qtmaterialstyle.h"
#include <QFontDatabase>
#include "lib/qtmaterialtheme.h"
/*!
* \class QtMaterialStylePrivate
* \internal
*/
QtMaterialStylePrivate::QtMaterialStylePrivate(QtMaterialStyle *q)
: q_ptr(q)
{
}
QtMaterialStylePrivate::~QtMaterialStylePrivate()
{
}
void QtMaterialStylePrivate::init()
{
Q_Q(QtMaterialStyle);
QFontDatabase::addApplicationFont(":/material/fonts/Roboto/Roboto-Regular.ttf");
QFontDatabase::addApplicationFont(":/material/fonts/Roboto/Roboto-Medium.ttf");
QFontDatabase::addApplicationFont(":/material/fonts/Roboto/Roboto-Bold.ttf");
q->setTheme(new QtMaterialTheme);
}
/*!
* \class QtMaterialStyle
* \internal
*/
void QtMaterialStyle::setTheme(QtMaterialTheme *theme)
{
Q_D(QtMaterialStyle);
d->theme = theme;
theme->setParent(this);
}
QColor QtMaterialStyle::themeColor(const QString &key) const
{
Q_D(const QtMaterialStyle);
Q_ASSERT(d->theme);
return d->theme->getColor(key);
}
QtMaterialStyle::QtMaterialStyle()
: QCommonStyle(),
d_ptr(new QtMaterialStylePrivate(this))
{
d_func()->init();
}

37
lib/qtmaterialstyle.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef QTMATERIALSTYLE_H
#define QTMATERIALSTYLE_H
#include <QCommonStyle>
#include "lib/qtmaterialstyle_p.h"
class QtMaterialTheme;
class QtMaterialStyle : public QCommonStyle
{
Q_OBJECT
public:
inline static QtMaterialStyle &instance();
void setTheme(QtMaterialTheme *theme);
QColor themeColor(const QString &key) const;
protected:
const QScopedPointer<QtMaterialStylePrivate> d_ptr;
private:
Q_DECLARE_PRIVATE(QtMaterialStyle)
QtMaterialStyle();
QtMaterialStyle(QtMaterialStyle const &);
void operator=(QtMaterialStyle const &);
};
inline QtMaterialStyle &QtMaterialStyle::instance()
{
static QtMaterialStyle instance;
return instance;
}
#endif // QTMATERIALSTYLE_H

24
lib/qtmaterialstyle_p.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef QTMATERIALSTYLE_P_H
#define QTMATERIALSTYLE_P_H
#include <QtGlobal>
class QtMaterialStyle;
class QtMaterialTheme;
class QtMaterialStylePrivate
{
Q_DISABLE_COPY(QtMaterialStylePrivate)
Q_DECLARE_PUBLIC(QtMaterialStyle)
public:
QtMaterialStylePrivate(QtMaterialStyle *q);
~QtMaterialStylePrivate();
void init();
QtMaterialStyle *const q_ptr;
QtMaterialTheme *theme;
};
#endif // QTMATERIALSTYLE_P_H

152
lib/qtmaterialtheme.cpp Normal file
View File

@ -0,0 +1,152 @@
#include "lib/qtmaterialtheme.h"
#include "lib/qtmaterialtheme_p.h"
#include <QDebug>
/*!
* \class QtMaterialThemePrivate
* \internal
*/
QtMaterialThemePrivate::QtMaterialThemePrivate(QtMaterialTheme *q)
: q_ptr(q)
{
}
QtMaterialThemePrivate::~QtMaterialThemePrivate()
{
}
QColor QtMaterialThemePrivate::rgba(int r, int g, int b, qreal a) const
{
QColor color(r, g, b);
color.setAlphaF(a);
return color;
}
/*!
* \class QtMaterialTheme
*/
QtMaterialTheme::QtMaterialTheme(QObject *parent)
: QObject(parent),
d_ptr(new QtMaterialThemePrivate(this))
{
setColor("primary1", Material::cyan500);
setColor("primary2", Material::cyan700);
setColor("primary3", Material::lightBlack);
setColor("accent1", Material::pinkA200);
setColor("accent2", Material::grey100);
setColor("accent3", Material::grey500);
setColor("text", Material::darkBlack);
setColor("alternateText", Material::white);
setColor("canvas", Material::white);
setColor("border", Material::grey300);
setColor("disabled", Material::minBlack);
setColor("disabled2", Material::faintBlack);
setColor("disabled3", Material::grey300);
}
QtMaterialTheme::~QtMaterialTheme()
{
}
QColor QtMaterialTheme::getColor(const QString &key) const
{
Q_D(const QtMaterialTheme);
if (!d->colors.contains(key)) {
qWarning() << "A theme color matching the key '" << key << "' could not be found.";
return QColor();
}
return d->colors.value(key);
}
void QtMaterialTheme::setColor(const QString &key, const QColor &color)
{
Q_D(QtMaterialTheme);
d->colors.insert(key, color);
}
void QtMaterialTheme::setColor(const QString &key, Material::Color color)
{
Q_D(QtMaterialTheme);
static const QColor palette[] = {
QColor("#ffebee"), QColor("#ffcdd2"), QColor("#ef9a9a"), QColor("#e57373"),
QColor("#ef5350"), QColor("#f44336"), QColor("#e53935"), QColor("#d32f2f"),
QColor("#c62828"), QColor("#b71c1c"), QColor("#ff8a80"), QColor("#ff5252"),
QColor("#ff1744"), QColor("#d50000"), QColor("#fce4ec"), QColor("#f8bbd0"),
QColor("#f48fb1"), QColor("#f06292"), QColor("#ec407a"), QColor("#e91e63"),
QColor("#d81b60"), QColor("#c2185b"), QColor("#ad1457"), QColor("#880e4f"),
QColor("#ff80ab"), QColor("#ff4081"), QColor("#f50057"), QColor("#c51162"),
QColor("#f3e5f5"), QColor("#e1bee7"), QColor("#ce93d8"), QColor("#ba68c8"),
QColor("#ab47bc"), QColor("#9c27b0"), QColor("#8e24aa"), QColor("#7b1fa2"),
QColor("#6a1b9a"), QColor("#4a148c"), QColor("#ea80fc"), QColor("#e040fb"),
QColor("#d500f9"), QColor("#aa00ff"), QColor("#ede7f6"), QColor("#d1c4e9"),
QColor("#b39ddb"), QColor("#9575cd"), QColor("#7e57c2"), QColor("#673ab7"),
QColor("#5e35b1"), QColor("#512da8"), QColor("#4527a0"), QColor("#311b92"),
QColor("#b388ff"), QColor("#7c4dff"), QColor("#651fff"), QColor("#6200ea"),
QColor("#e8eaf6"), QColor("#c5cae9"), QColor("#9fa8da"), QColor("#7986cb"),
QColor("#5c6bc0"), QColor("#3f51b5"), QColor("#3949ab"), QColor("#303f9f"),
QColor("#283593"), QColor("#1a237e"), QColor("#8c9eff"), QColor("#536dfe"),
QColor("#3d5afe"), QColor("#304ffe"), QColor("#e3f2fd"), QColor("#bbdefb"),
QColor("#90caf9"), QColor("#64b5f6"), QColor("#42a5f5"), QColor("#2196f3"),
QColor("#1e88e5"), QColor("#1976d2"), QColor("#1565c0"), QColor("#0d47a1"),
QColor("#82b1ff"), QColor("#448aff"), QColor("#2979ff"), QColor("#2962ff"),
QColor("#e1f5fe"), QColor("#b3e5fc"), QColor("#81d4fa"), QColor("#4fc3f7"),
QColor("#29b6f6"), QColor("#03a9f4"), QColor("#039be5"), QColor("#0288d1"),
QColor("#0277bd"), QColor("#01579b"), QColor("#80d8ff"), QColor("#40c4ff"),
QColor("#00b0ff"), QColor("#0091ea"), QColor("#e0f7fa"), QColor("#b2ebf2"),
QColor("#80deea"), QColor("#4dd0e1"), QColor("#26c6da"), QColor("#00bcd4"),
QColor("#00acc1"), QColor("#0097a7"), QColor("#00838f"), QColor("#006064"),
QColor("#84ffff"), QColor("#18ffff"), QColor("#00e5ff"), QColor("#00b8d4"),
QColor("#e0f2f1"), QColor("#b2dfdb"), QColor("#80cbc4"), QColor("#4db6ac"),
QColor("#26a69a"), QColor("#009688"), QColor("#00897b"), QColor("#00796b"),
QColor("#00695c"), QColor("#004d40"), QColor("#a7ffeb"), QColor("#64ffda"),
QColor("#1de9b6"), QColor("#00bfa5"), QColor("#e8f5e9"), QColor("#c8e6c9"),
QColor("#a5d6a7"), QColor("#81c784"), QColor("#66bb6a"), QColor("#4caf50"),
QColor("#43a047"), QColor("#388e3c"), QColor("#2e7d32"), QColor("#1b5e20"),
QColor("#b9f6ca"), QColor("#69f0ae"), QColor("#00e676"), QColor("#00c853"),
QColor("#f1f8e9"), QColor("#dcedc8"), QColor("#c5e1a5"), QColor("#aed581"),
QColor("#9ccc65"), QColor("#8bc34a"), QColor("#7cb342"), QColor("#689f38"),
QColor("#558b2f"), QColor("#33691e"), QColor("#ccff90"), QColor("#b2ff59"),
QColor("#76ff03"), QColor("#64dd17"), QColor("#f9fbe7"), QColor("#f0f4c3"),
QColor("#e6ee9c"), QColor("#dce775"), QColor("#d4e157"), QColor("#cddc39"),
QColor("#c0ca33"), QColor("#afb42b"), QColor("#9e9d24"), QColor("#827717"),
QColor("#f4ff81"), QColor("#eeff41"), QColor("#c6ff00"), QColor("#aeea00"),
QColor("#fffde7"), QColor("#fff9c4"), QColor("#fff59d"), QColor("#fff176"),
QColor("#ffee58"), QColor("#ffeb3b"), QColor("#fdd835"), QColor("#fbc02d"),
QColor("#f9a825"), QColor("#f57f17"), QColor("#ffff8d"), QColor("#ffff00"),
QColor("#ffea00"), QColor("#ffd600"), QColor("#fff8e1"), QColor("#ffecb3"),
QColor("#ffe082"), QColor("#ffd54f"), QColor("#ffca28"), QColor("#ffc107"),
QColor("#ffb300"), QColor("#ffa000"), QColor("#ff8f00"), QColor("#ff6f00"),
QColor("#ffe57f"), QColor("#ffd740"), QColor("#ffc400"), QColor("#ffab00"),
QColor("#fff3e0"), QColor("#ffe0b2"), QColor("#ffcc80"), QColor("#ffb74d"),
QColor("#ffa726"), QColor("#ff9800"), QColor("#fb8c00"), QColor("#f57c00"),
QColor("#ef6c00"), QColor("#e65100"), QColor("#ffd180"), QColor("#ffab40"),
QColor("#ff9100"), QColor("#ff6d00"), QColor("#fbe9e7"), QColor("#ffccbc"),
QColor("#ffab91"), QColor("#ff8a65"), QColor("#ff7043"), QColor("#ff5722"),
QColor("#f4511e"), QColor("#e64a19"), QColor("#d84315"), QColor("#bf360c"),
QColor("#ff9e80"), QColor("#ff6e40"), QColor("#ff3d00"), QColor("#dd2c00"),
QColor("#efebe9"), QColor("#d7ccc8"), QColor("#bcaaa4"), QColor("#a1887f"),
QColor("#8d6e63"), QColor("#795548"), QColor("#6d4c41"), QColor("#5d4037"),
QColor("#4e342e"), QColor("#3e2723"), QColor("#eceff1"), QColor("#cfd8dc"),
QColor("#b0bec5"), QColor("#90a4ae"), QColor("#78909c"), QColor("#607d8b"),
QColor("#546e7a"), QColor("#455a64"), QColor("#37474f"), QColor("#263238"),
QColor("#fafafa"), QColor("#f5f5f5"), QColor("#eeeeee"), QColor("#e0e0e0"),
QColor("#bdbdbd"), QColor("#9e9e9e"), QColor("#757575"), QColor("#616161"),
QColor("#424242"), QColor("#212121"), QColor("#000000"), QColor("#ffffff"),
d->rgba(0, 0, 0, 0),
d->rgba(0, 0, 0, 1),
d->rgba(0, 0, 0, 0.87),
d->rgba(0, 0, 0, 0.54),
d->rgba(0, 0, 0, 0.26),
d->rgba(0, 0, 0, 0.12),
d->rgba(255, 255, 255, 1),
d->rgba(255, 255, 255, 0.87),
d->rgba(255, 255, 255, 0.54)
};
d->colors.insert(key, palette[color]);
}

341
lib/qtmaterialtheme.h Normal file
View File

@ -0,0 +1,341 @@
#ifndef QTMATERIALTHEME_H
#define QTMATERIALTHEME_H
#include <QObject>
#include <QScopedPointer>
#include <QColor>
namespace Material
{
enum ButtonPreset {
FlatPreset,
CheckablePreset
};
enum RippleStyle {
CenteredRipple,
PositionedRipple,
NoRipple
};
enum OverlayStyle {
NoOverlay,
TintedOverlay,
GrayOverlay
};
enum Role {
Default,
Primary,
Secondary
};
enum ButtonIconPlacement {
LeftIcon,
RightIcon
};
enum ProgressType {
DeterminateProgress,
IndeterminateProgress
};
enum AvatarType {
ImageAvatar,
IconAvatar,
LetterAvatar
};
enum Color {
red50,
red100,
red200,
red300,
red400,
red500,
red600,
red700,
red800,
red900,
redA100,
redA200,
redA400,
redA700,
pink50,
pink100,
pink200,
pink300,
pink400,
pink500,
pink600,
pink700,
pink800,
pink900,
pinkA100,
pinkA200,
pinkA400,
pinkA700,
purple50,
purple100,
purple200,
purple300,
purple400,
purple500,
purple600,
purple700,
purple800,
purple900,
purpleA100,
purpleA200,
purpleA400,
purpleA700,
deepPurple50,
deepPurple100,
deepPurple200,
deepPurple300,
deepPurple400,
deepPurple500,
deepPurple600,
deepPurple700,
deepPurple800,
deepPurple900,
deepPurpleA100,
deepPurpleA200,
deepPurpleA400,
deepPurpleA700,
indigo50,
indigo100,
indigo200,
indigo300,
indigo400,
indigo500,
indigo600,
indigo700,
indigo800,
indigo900,
indigoA100,
indigoA200,
indigoA400,
indigoA700,
blue50,
blue100,
blue200,
blue300,
blue400,
blue500,
blue600,
blue700,
blue800,
blue900,
blueA100,
blueA200,
blueA400,
blueA700,
lightBlue50,
lightBlue100,
lightBlue200,
lightBlue300,
lightBlue400,
lightBlue500,
lightBlue600,
lightBlue700,
lightBlue800,
lightBlue900,
lightBlueA100,
lightBlueA200,
lightBlueA400,
lightBlueA700,
cyan50,
cyan100,
cyan200,
cyan300,
cyan400,
cyan500,
cyan600,
cyan700,
cyan800,
cyan900,
cyanA100,
cyanA200,
cyanA400,
cyanA700,
teal50,
teal100,
teal200,
teal300,
teal400,
teal500,
teal600,
teal700,
teal800,
teal900,
tealA100,
tealA200,
tealA400,
tealA700,
green50,
green100,
green200,
green300,
green400,
green500,
green600,
green700,
green800,
green900,
greenA100,
greenA200,
greenA400,
greenA700,
lightGreen50,
lightGreen100,
lightGreen200,
lightGreen300,
lightGreen400,
lightGreen500,
lightGreen600,
lightGreen700,
lightGreen800,
lightGreen900,
lightGreenA100,
lightGreenA200,
lightGreenA400,
lightGreenA700,
lime50,
lime100,
lime200,
lime300,
lime400,
lime500,
lime600,
lime700,
lime800,
lime900,
limeA100,
limeA200,
limeA400,
limeA700,
yellow50,
yellow100,
yellow200,
yellow300,
yellow400,
yellow500,
yellow600,
yellow700,
yellow800,
yellow900,
yellowA100,
yellowA200,
yellowA400,
yellowA700,
amber50,
amber100,
amber200,
amber300,
amber400,
amber500,
amber600,
amber700,
amber800,
amber900,
amberA100,
amberA200,
amberA400,
amberA700,
orange50,
orange100,
orange200,
orange300,
orange400,
orange500,
orange600,
orange700,
orange800,
orange900,
orangeA100,
orangeA200,
orangeA400,
orangeA700,
deepOrange50,
deepOrange100,
deepOrange200,
deepOrange300,
deepOrange400,
deepOrange500,
deepOrange600,
deepOrange700,
deepOrange800,
deepOrange900,
deepOrangeA100,
deepOrangeA200,
deepOrangeA400,
deepOrangeA700,
brown50,
brown100,
brown200,
brown300,
brown400,
brown500,
brown600,
brown700,
brown800,
brown900,
blueGrey50,
blueGrey100,
blueGrey200,
blueGrey300,
blueGrey400,
blueGrey500,
blueGrey600,
blueGrey700,
blueGrey800,
blueGrey900,
grey50,
grey100,
grey200,
grey300,
grey400,
grey500,
grey600,
grey700,
grey800,
grey900,
black,
white,
transparent,
fullBlack,
darkBlack,
lightBlack,
minBlack,
faintBlack,
fullWhite,
darkWhite,
lightWhite
};
}
class QtMaterialThemePrivate;
class QtMaterialTheme : public QObject
{
Q_OBJECT
public:
explicit QtMaterialTheme(QObject *parent = 0);
~QtMaterialTheme();
QColor getColor(const QString &key) const;
void setColor(const QString &key, const QColor &color);
void setColor(const QString &key, Material::Color color);
protected:
const QScopedPointer<QtMaterialThemePrivate> d_ptr;
private:
Q_DISABLE_COPY(QtMaterialTheme)
Q_DECLARE_PRIVATE(QtMaterialTheme)
};
#endif // QTMATERIALTHEME_H

24
lib/qtmaterialtheme_p.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef QTMATERIALTHEME_P_H
#define QTMATERIALTHEME_P_H
#include <QHash>
#include <QColor>
class QtMaterialTheme;
class QtMaterialThemePrivate
{
Q_DISABLE_COPY(QtMaterialThemePrivate)
Q_DECLARE_PUBLIC(QtMaterialTheme)
public:
QtMaterialThemePrivate(QtMaterialTheme *q);
~QtMaterialThemePrivate();
QColor rgba(int r, int g, int b, qreal a) const;
QtMaterialTheme *const q_ptr;
QHash<QString, QColor> colors;
};
#endif // QTMATERIALTHEME_P_H