mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:18:12 +00:00
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:
parent
b89f64cb55
commit
31b5047894
4 changed files with 21 additions and 2 deletions
|
@ -108,3 +108,18 @@ void GAbstractView::notify_selection_changed(Badge<GModelSelection>)
|
||||||
on_selection_change();
|
on_selection_change();
|
||||||
update();
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -45,6 +45,8 @@ public:
|
||||||
|
|
||||||
void notify_selection_changed(Badge<GModelSelection>);
|
void notify_selection_changed(Badge<GModelSelection>);
|
||||||
|
|
||||||
|
NonnullRefPtr<Font> font_for_index(const GModelIndex&) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void did_scroll() override;
|
virtual void did_scroll() override;
|
||||||
void activate(const GModelIndex&);
|
void activate(const GModelIndex&);
|
||||||
|
|
|
@ -113,11 +113,12 @@ void GListView::paint_event(GPaintEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
auto column_metadata = model()->column_metadata(m_model_column);
|
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());
|
Rect row_rect(0, y, content_width(), item_height());
|
||||||
painter.fill_rect(row_rect, background_color);
|
painter.fill_rect(row_rect, background_color);
|
||||||
auto index = model()->index(row_index, m_model_column);
|
auto index = model()->index(row_index, m_model_column);
|
||||||
auto data = model()->data(index);
|
auto data = model()->data(index);
|
||||||
|
auto font = font_for_index(index);
|
||||||
if (data.is_bitmap()) {
|
if (data.is_bitmap()) {
|
||||||
painter.blit(row_rect.location(), data.as_bitmap(), data.as_bitmap().rect());
|
painter.blit(row_rect.location(), data.as_bitmap(), data.as_bitmap().rect());
|
||||||
} else if (data.is_icon()) {
|
} else if (data.is_icon()) {
|
||||||
|
|
|
@ -34,7 +34,8 @@ public:
|
||||||
Custom,
|
Custom,
|
||||||
ForegroundColor,
|
ForegroundColor,
|
||||||
BackgroundColor,
|
BackgroundColor,
|
||||||
Icon
|
Icon,
|
||||||
|
Font,
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~GModel();
|
virtual ~GModel();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue