1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +00:00

LibGUI: Add GTableModel::Role::ForegroundColor.

This makes it possible to specify the text color for each table cell.
Use this to make the IRCClient show unread window list items in red.
This commit is contained in:
Andreas Kling 2019-03-18 04:54:07 +01:00
parent f4b8e4966f
commit d466f2634d
10 changed files with 120 additions and 63 deletions

View file

@ -40,17 +40,29 @@ GTableModel::ColumnMetadata IRCWindowListModel::column_metadata(int column) cons
ASSERT_NOT_REACHED();
}
GVariant IRCWindowListModel::data(const GModelIndex& index, Role) const
GVariant IRCWindowListModel::data(const GModelIndex& index, Role role) const
{
switch (index.column()) {
case Column::Name: {
auto& window = m_client.window_at(index.row());
if (!window.unread_count())
if (role == Role::Display) {
switch (index.column()) {
case Column::Name: {
auto& window = m_client.window_at(index.row());
if (window.unread_count())
return String::format("%s (%d)", window.name().characters(), window.unread_count());
return window.name();
return String::format("%s (%d)\n", window.name().characters(), window.unread_count());
}
}
}
if (role == Role::ForegroundColor) {
switch (index.column()) {
case Column::Name: {
auto& window = m_client.window_at(index.row());
if (window.unread_count())
return Color(Color::Red);
return Color(Color::Black);
}
}
}
ASSERT_NOT_REACHED();
return { };
}
void IRCWindowListModel::update()