From d830ae11ecf4194b88c1cba6d376b24d16d01501 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 3 Sep 2024 14:31:31 +0300 Subject: [PATCH] Added ability to paint icons in center of QRectF. --- ui/style/style_core_icon.cpp | 19 +++++++++++++++++++ ui/style/style_core_icon.h | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/ui/style/style_core_icon.cpp b/ui/style/style_core_icon.cpp index 3f00b902..d90d2f6e 100644 --- a/ui/style/style_core_icon.cpp +++ b/ui/style/style_core_icon.cpp @@ -393,6 +393,25 @@ Icon Icon::withPalette(const style::palette &palette) const { return result; } +void Icon::paintInCenter(QPainter &p, const QRectF &outer) const { + const auto dx = outer.x() + (outer.width() - width()) / 2.; + const auto dy = outer.y() + (outer.height() - height()) / 2.; + p.translate(dx, dy); + _data->paint(p, QPoint(), outer.x() * 2. + outer.width()); + p.translate(-dx, -dy); +} + +void Icon::paintInCenter( + QPainter &p, + const QRectF &outer, + QColor override) const { + const auto dx = outer.x() + (outer.width() - width()) / 2; + const auto dy = outer.y() + (outer.height() - height()) / 2; + p.translate(dx, dy); + _data->paint(p, QPoint(), outer.x() * 2 + outer.width(), override); + p.translate(-dx, -dy); +} + void ResetIcons() { iconPixmaps.clear(); for (const auto data : iconData) { diff --git a/ui/style/style_core_icon.h b/ui/style/style_core_icon.h index 6cfa3ff6..eac59679 100644 --- a/ui/style/style_core_icon.h +++ b/ui/style/style_core_icon.h @@ -234,6 +234,7 @@ class Icon { outer.y() + (outer.height() - height()) / 2), outer.x() * 2 + outer.width()); } + void paintInCenter(QPainter &p, const QRectF &outer) const; void fill(QPainter &p, const QRect &rect) const { return _data->fill(p, rect); } @@ -265,6 +266,10 @@ class Icon { outer.x() * 2 + outer.width(), colorOverride); } + void paintInCenter( + QPainter &p, + const QRectF &outer, + QColor override) const; void fill(QPainter &p, const QRect &rect, QColor colorOverride) const { return _data->fill(p, rect, colorOverride); }