summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-28 20:16:10 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-28 20:16:10 +0100
commitb1321507992009bcdc0ad72d604cb005c284ce32 (patch)
tree2920e72c038ce0dde12a6dcff5356839eff2ea21
parent3fe7ddadaf4aa698cc8156be818a3fc954e6d27e (diff)
downloadserenity-b1321507992009bcdc0ad72d604cb005c284ce32.zip
LibGUI: Support bitmaps in GTableView cells.
Use this to add an icon for each process in the ProcessManager. Right now they all use a generic gear icon, but I'd like to have per-process icons, obviously. :^)
-rw-r--r--Applications/ProcessManager/ProcessTableModel.cpp31
-rw-r--r--Applications/ProcessManager/ProcessTableModel.h1
-rw-r--r--LibGUI/GTableView.cpp6
-rw-r--r--LibGUI/GVariant.h5
4 files changed, 30 insertions, 13 deletions
diff --git a/Applications/ProcessManager/ProcessTableModel.cpp b/Applications/ProcessManager/ProcessTableModel.cpp
index 64fdb0f3b8..a5bd507abc 100644
--- a/Applications/ProcessManager/ProcessTableModel.cpp
+++ b/Applications/ProcessManager/ProcessTableModel.cpp
@@ -4,14 +4,15 @@
#include <pwd.h>
enum Column {
- PID = 0,
+ Icon = 0,
+ Name,
+ CPU,
State,
- User,
Priority,
+ User,
+ PID,
Linear,
Physical,
- CPU,
- Name,
__Count
};
@@ -21,6 +22,9 @@ ProcessTableModel::ProcessTableModel()
while (auto* passwd = getpwent())
m_usernames.set(passwd->pw_uid, passwd->pw_name);
endpwent();
+
+ m_generic_process_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/gear16.rgb", { 16, 16 });
+ ASSERT(m_generic_process_icon);
}
ProcessTableModel::~ProcessTableModel()
@@ -40,6 +44,7 @@ int ProcessTableModel::column_count() const
String ProcessTableModel::column_name(int column) const
{
switch (column) {
+ case Column::Icon: return "";
case Column::PID: return "PID";
case Column::State: return "State";
case Column::User: return "User";
@@ -55,14 +60,15 @@ String ProcessTableModel::column_name(int column) const
GTableModel::ColumnMetadata ProcessTableModel::column_metadata(int column) const
{
switch (column) {
- case Column::PID: return { 30, TextAlignment::CenterRight };
- case Column::State: return { 80, TextAlignment::CenterLeft };
- case Column::Priority: return { 75, TextAlignment::CenterLeft };
- case Column::User: return { 60, TextAlignment::CenterLeft };
- case Column::Linear: return { 70, TextAlignment::CenterRight };
- case Column::Physical: return { 70, TextAlignment::CenterRight };
- case Column::CPU: return { 30, TextAlignment::CenterRight };
- case Column::Name: return { 200, TextAlignment::CenterLeft };
+ case Column::Icon: return { 16, TextAlignment::CenterLeft };
+ case Column::PID: return { 25, TextAlignment::CenterRight };
+ case Column::State: return { 75, TextAlignment::CenterLeft };
+ case Column::Priority: return { 65, TextAlignment::CenterLeft };
+ case Column::User: return { 50, TextAlignment::CenterLeft };
+ case Column::Linear: return { 65, TextAlignment::CenterRight };
+ case Column::Physical: return { 65, TextAlignment::CenterRight };
+ case Column::CPU: return { 25, TextAlignment::CenterRight };
+ case Column::Name: return { 140, TextAlignment::CenterLeft };
default: ASSERT_NOT_REACHED();
}
}
@@ -93,6 +99,7 @@ GVariant ProcessTableModel::data(int row, int column) const
auto it = m_processes.find(m_pids[row]);
auto& process = *(*it).value;
switch (column) {
+ case Column::Icon: return *m_generic_process_icon;
case Column::PID: return process.current_state.pid;
case Column::State: return process.current_state.state;
case Column::User: return process.current_state.user;
diff --git a/Applications/ProcessManager/ProcessTableModel.h b/Applications/ProcessManager/ProcessTableModel.h
index 93ba789dfc..0246f521ed 100644
--- a/Applications/ProcessManager/ProcessTableModel.h
+++ b/Applications/ProcessManager/ProcessTableModel.h
@@ -44,4 +44,5 @@ private:
HashMap<pid_t, OwnPtr<Process>> m_processes;
Vector<pid_t> m_pids;
int m_selected_row { -1 };
+ RetainPtr<GraphicsBitmap> m_generic_process_icon;
};
diff --git a/LibGUI/GTableView.cpp b/LibGUI/GTableView.cpp
index df18c6bd83..d05b257745 100644
--- a/LibGUI/GTableView.cpp
+++ b/LibGUI/GTableView.cpp
@@ -121,7 +121,11 @@ void GTableView::paint_event(GPaintEvent& event)
auto column_metadata = m_model->column_metadata(column_index);
int column_width = column_metadata.preferred_width;
Rect cell_rect(horizontal_padding() + x_offset, y, column_width, item_height());
- painter.draw_text(cell_rect, m_model->data(row_index, column_index).to_string(), column_metadata.text_alignment, text_color);
+ auto data = m_model->data(row_index, column_index);
+ if (data.is_bitmap())
+ painter.blit(cell_rect.location(), data.as_bitmap(), data.as_bitmap().rect());
+ else
+ painter.draw_text(cell_rect, data.to_string(), column_metadata.text_alignment, text_color);
x_offset += column_width + horizontal_padding() * 2;
}
++painted_item_index;
diff --git a/LibGUI/GVariant.h b/LibGUI/GVariant.h
index c682d9d656..1dd6faef12 100644
--- a/LibGUI/GVariant.h
+++ b/LibGUI/GVariant.h
@@ -23,6 +23,11 @@ public:
};
bool is_valid() const { return m_type != Type::Invalid; }
+ bool is_bool() const { return m_type == Type::Bool; }
+ bool is_int() const { return m_type == Type::Int; }
+ bool is_float() const { return m_type == Type::Float; }
+ bool is_string() const { return m_type == Type::String; }
+ bool is_bitmap() const { return m_type == Type::Bitmap; }
Type type() const { return m_type; }
bool as_bool() const