2016-04-21 17:57:29 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-21 17:57:29 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-21 17:57:29 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace style {
|
2016-11-01 20:59:51 +00:00
|
|
|
|
|
|
|
class palette;
|
|
|
|
|
2016-04-21 17:57:29 +00:00
|
|
|
namespace internal {
|
|
|
|
|
2016-11-03 10:33:57 +00:00
|
|
|
class Color;
|
|
|
|
class ColorData {
|
|
|
|
public:
|
|
|
|
QColor c;
|
|
|
|
QPen p;
|
|
|
|
QBrush b;
|
|
|
|
|
|
|
|
QColor transparent() const {
|
|
|
|
return QColor(c.red(), c.green(), c.blue(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ColorData(uchar r, uchar g, uchar b, uchar a);
|
2016-12-23 13:21:01 +00:00
|
|
|
ColorData(const ColorData &other) = default;
|
|
|
|
ColorData &operator=(const ColorData &other) = default;
|
|
|
|
|
2016-11-03 10:33:57 +00:00
|
|
|
void set(uchar r, uchar g, uchar b, uchar a);
|
|
|
|
|
|
|
|
friend class Color;
|
|
|
|
friend class style::palette;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-21 17:57:29 +00:00
|
|
|
class Color {
|
|
|
|
public:
|
|
|
|
Color(Qt::Initialization = Qt::Uninitialized) {
|
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
Color(const Color &other) = default;
|
|
|
|
Color &operator=(const Color &other) = default;
|
2016-04-21 17:57:29 +00:00
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
void set(uchar r, uchar g, uchar b, uchar a) const {
|
|
|
|
_data->set(r, g, b, a);
|
|
|
|
}
|
2016-04-21 17:57:29 +00:00
|
|
|
|
2016-11-03 10:33:57 +00:00
|
|
|
operator const QBrush &() const {
|
2016-12-23 13:21:01 +00:00
|
|
|
return _data->b;
|
2016-11-03 10:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
operator const QPen &() const {
|
2016-12-23 13:21:01 +00:00
|
|
|
return _data->p;
|
2016-11-03 10:33:57 +00:00
|
|
|
}
|
2016-04-21 17:57:29 +00:00
|
|
|
|
|
|
|
ColorData *operator->() const {
|
2016-12-23 13:21:01 +00:00
|
|
|
return _data;
|
2016-04-21 17:57:29 +00:00
|
|
|
}
|
|
|
|
ColorData *v() const {
|
2016-12-23 13:21:01 +00:00
|
|
|
return _data;
|
2016-04-21 17:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
explicit operator bool() const {
|
2016-12-23 13:21:01 +00:00
|
|
|
return !!_data;
|
2016-04-21 17:57:29 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
class Proxy;
|
|
|
|
Proxy operator[](const style::palette &paletteOverride) const;
|
|
|
|
|
2016-04-21 17:57:29 +00:00
|
|
|
private:
|
2016-12-23 13:21:01 +00:00
|
|
|
friend class style::palette;
|
|
|
|
Color(ColorData *data) : _data(data) {
|
|
|
|
}
|
2016-04-21 17:57:29 +00:00
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
ColorData *_data = nullptr;
|
2016-04-21 17:57:29 +00:00
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Color::Proxy {
|
|
|
|
public:
|
|
|
|
Proxy(Color color) : _color(color) {
|
|
|
|
}
|
|
|
|
Proxy(const Proxy &other) = default;
|
|
|
|
|
|
|
|
operator const QBrush &() const { return _color; }
|
|
|
|
operator const QPen &() const { return _color; }
|
|
|
|
ColorData *operator->() const { return _color.v(); }
|
|
|
|
ColorData *v() const { return _color.v(); }
|
|
|
|
explicit operator bool() const { return _color ? true : false; }
|
|
|
|
Color clone() const { return _color; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Color _color;
|
2016-04-21 17:57:29 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
inline bool operator==(Color a, Color b) {
|
2016-04-21 17:57:29 +00:00
|
|
|
return a->c == b->c;
|
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
inline bool operator!=(Color a, Color b) {
|
2016-04-21 17:57:29 +00:00
|
|
|
return a->c != b->c;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace style
|