aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui/widgets/ProjectItem.cpp
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-07-29 13:50:08 -0300
committerflow <flowlnlnln@gmail.com>2022-09-23 16:59:40 -0300
commit1862f3c124e090c1f27fa26babf65f14b8af8a37 (patch)
tree5688a19b5385dfb07fc540032fd81cd4e195a1d6 /launcher/ui/widgets/ProjectItem.cpp
parentc6bcb6228b421983006d16c93f7cda091dc9679b (diff)
downloadPrismLauncher-1862f3c124e090c1f27fa26babf65f14b8af8a37.tar.gz
PrismLauncher-1862f3c124e090c1f27fa26babf65f14b8af8a37.tar.bz2
PrismLauncher-1862f3c124e090c1f27fa26babf65f14b8af8a37.zip
fix: set icon sizes correctly in ProjectItemDelegate
no more dumb hacks with icons!! Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/ui/widgets/ProjectItem.cpp')
-rw-r--r--launcher/ui/widgets/ProjectItem.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/launcher/ui/widgets/ProjectItem.cpp b/launcher/ui/widgets/ProjectItem.cpp
index 56ae35fb..01be88d9 100644
--- a/launcher/ui/widgets/ProjectItem.cpp
+++ b/launcher/ui/widgets/ProjectItem.cpp
@@ -14,9 +14,7 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
QStyleOptionViewItem opt(option);
initStyleOption(&opt, index);
- auto& rect = opt.rect;
- auto icon_width = rect.height(), icon_height = rect.height();
- auto remaining_width = rect.width() - icon_width;
+ auto rect = opt.rect;
if (opt.state & QStyle::State_Selected) {
painter->fillRect(rect, opt.palette.highlight());
@@ -25,11 +23,34 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
painter->fillRect(rect, opt.palette.window());
}
- { // Icon painting
- // Square-sized, occupying the left portion
- opt.icon.paint(painter, rect.x(), rect.y(), icon_width, icon_height);
+ // The default icon size will be a square (and height is usually the lower value).
+ auto icon_width = rect.height(), icon_height = rect.height();
+ int icon_x_margin = (rect.height() - icon_width) / 2;
+ int icon_y_margin = (rect.height() - icon_height) / 2;
+
+ if (!opt.icon.isNull()) { // Icon painting
+ {
+ auto icon_size = opt.decorationSize;
+ icon_width = icon_size.width();
+ icon_height = icon_size.height();
+
+ icon_x_margin = (rect.height() - icon_width) / 2;
+ icon_y_margin = (rect.height() - icon_height) / 2;
+ }
+
+ // Centralize icon with a margin to separate from the other elements
+ int x = rect.x() + icon_x_margin;
+ int y = rect.y() + icon_y_margin;
+
+ // Prevent 'scaling null pixmap' warnings
+ if (icon_width > 0 && icon_height > 0)
+ opt.icon.paint(painter, x, y, icon_width, icon_height);
}
+ // Change the rect so that funther painting is easier
+ auto remaining_width = rect.width() - icon_width - 2 * icon_x_margin;
+ rect.setRect(rect.x() + icon_width + 2 * icon_x_margin, rect.y(), remaining_width, rect.height());
+
{ // Title painting
auto title = index.data(UserDataTypes::TITLE).toString();
@@ -46,7 +67,7 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
painter->setFont(font);
// On the top, aligned to the left after the icon
- painter->drawText(rect.x() + icon_width, rect.y() + QFontMetrics(font).height(), title);
+ painter->drawText(rect.x(), rect.y() + QFontMetrics(font).height(), title);
painter->restore();
}
@@ -70,7 +91,7 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
}
// On the bottom, aligned to the left after the icon, and featuring at most two lines of text (with some margin space to spare)
- painter->drawText(rect.x() + icon_width, rect.y() + rect.height() - 2.2 * opt.fontMetrics.height(), remaining_width,
+ painter->drawText(rect.x(), rect.y() + rect.height() - 2.2 * opt.fontMetrics.height(), remaining_width,
2 * opt.fontMetrics.height(), Qt::TextWordWrap, description);
}