Skip to content

Commit

Permalink
Added ability to paint icons in center of QRectF.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Sep 3, 2024
1 parent 6a0b261 commit d830ae1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ui/style/style_core_icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions ui/style/style_core_icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit d830ae1

Please sign in to comment.