LibGUI: Allow override the font on a per-index basis in GListView

This should be ported to all of the GAbstractView subclasses.
This commit is contained in:
Andreas Kling 2019-10-22 21:38:04 +02:00
parent b89f64cb55
commit 31b5047894
Notes: sideshowbarker 2024-07-19 11:35:16 +09:00
4 changed files with 21 additions and 2 deletions

View file

@ -108,3 +108,18 @@ void GAbstractView::notify_selection_changed(Badge<GModelSelection>)
on_selection_change();
update();
}
NonnullRefPtr<Font> GAbstractView::font_for_index(const GModelIndex& index) const
{
if (!model())
return font();
auto font_data = model()->data(index, GModel::Role::Font);
if (font_data.is_font())
return font_data.as_font();
auto column_metadata = model()->column_metadata(index.column());
if (column_metadata.font)
return *column_metadata.font;
return font();
}

View file

@ -45,6 +45,8 @@ public:
void notify_selection_changed(Badge<GModelSelection>);
NonnullRefPtr<Font> font_for_index(const GModelIndex&) const;
protected:
virtual void did_scroll() override;
void activate(const GModelIndex&);

View file

@ -113,11 +113,12 @@ void GListView::paint_event(GPaintEvent& event)
}
auto column_metadata = model()->column_metadata(m_model_column);
const Font& font = column_metadata.font ? *column_metadata.font : this->font();
Rect row_rect(0, y, content_width(), item_height());
painter.fill_rect(row_rect, background_color);
auto index = model()->index(row_index, m_model_column);
auto data = model()->data(index);
auto font = font_for_index(index);
if (data.is_bitmap()) {
painter.blit(row_rect.location(), data.as_bitmap(), data.as_bitmap().rect());
} else if (data.is_icon()) {

View file

@ -34,7 +34,8 @@ public:
Custom,
ForegroundColor,
BackgroundColor,
Icon
Icon,
Font,
};
virtual ~GModel();