mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-17 06:37:24 +02:00
Added ability to override brush for color icons in settings.
This commit is contained in:
parent
f3ca4f45ea
commit
e7cc8ff44b
2 changed files with 15 additions and 0 deletions
|
@ -83,6 +83,11 @@ Icon::Icon(IconDescriptor descriptor) : _icon(descriptor.icon) {
|
|||
? st::settingsIconRadius
|
||||
: (std::min(_icon->width(), _icon->height()) / 2);
|
||||
_background.emplace(radius, *background);
|
||||
} else if (const auto brush = descriptor.backgroundBrush) {
|
||||
const auto radius = (descriptor.type == IconType::Rounded)
|
||||
? st::settingsIconRadius
|
||||
: (std::min(_icon->width(), _icon->height()) / 2);
|
||||
_backgroundBrush.emplace(radius, std::move(*brush));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,6 +98,14 @@ void Icon::paint(QPainter &p, QPoint position) const {
|
|||
void Icon::paint(QPainter &p, int x, int y) const {
|
||||
if (_background) {
|
||||
_background->paint(p, { { x, y }, _icon->size() });
|
||||
} else if (_backgroundBrush) {
|
||||
PainterHighQualityEnabler hq(p);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(_backgroundBrush->second);
|
||||
p.drawRoundedRect(
|
||||
QRect(QPoint(x, y), _icon->size()),
|
||||
_backgroundBrush->first,
|
||||
_backgroundBrush->first);
|
||||
}
|
||||
if (OptionMonoSettingsIcons.value()) {
|
||||
_icon->paint(p, { x, y }, 2 * x + _icon->width(), st::menuIconFg->c);
|
||||
|
|
|
@ -137,6 +137,7 @@ struct IconDescriptor {
|
|||
int color = 0; // settingsIconBg{color}, 9 for settingsIconBgArchive.
|
||||
IconType type = IconType::Rounded;
|
||||
const style::color *background = nullptr;
|
||||
std::optional<QBrush> backgroundBrush; // Can be useful for gragdients.
|
||||
|
||||
explicit operator bool() const {
|
||||
return (icon != nullptr);
|
||||
|
@ -157,6 +158,7 @@ public:
|
|||
private:
|
||||
not_null<const style::icon*> _icon;
|
||||
std::optional<Ui::RoundRect> _background;
|
||||
std::optional<std::pair<int, QBrush>> _backgroundBrush;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue