summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-20 13:35:11 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-20 13:36:07 +0100
commit951377e93e1d64fd97d0823aaf8e6ccb10fa28c2 (patch)
tree4057974cb8779e349fb0cd7653f433111676b589
parentd17a91f1851e8f0b3a3353d677ad8d1f51e921b7 (diff)
downloadserenity-951377e93e1d64fd97d0823aaf8e6ccb10fa28c2.zip
GTableView: Add ability to hide individual columns at view-level.
Use this in IRCClient to hide the "sender" column in the server message view since everything in that view comes from the "Server" anyway.
-rw-r--r--Applications/IRCClient/IRCClient.cpp4
-rw-r--r--Applications/IRCClient/IRCLogBufferModel.cpp2
-rw-r--r--Applications/IRCClient/IRCWindow.cpp4
-rw-r--r--LibGUI/GTableView.cpp30
-rw-r--r--LibGUI/GTableView.h4
5 files changed, 41 insertions, 3 deletions
diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp
index 1aeb56d69b..922716f862 100644
--- a/Applications/IRCClient/IRCClient.cpp
+++ b/Applications/IRCClient/IRCClient.cpp
@@ -246,7 +246,7 @@ void IRCClient::handle(const Message& msg, const String&)
void IRCClient::add_server_message(const String& text)
{
- m_log->add_message(0, "Server", text);
+ m_log->add_message(0, "", text);
m_server_subwindow->did_add_message();
}
@@ -354,7 +354,7 @@ void IRCClient::handle_ping(const Message& msg)
{
if (msg.arguments.size() < 0)
return;
- m_log->add_message(0, "Server", "Ping? Pong!");
+ m_log->add_message(0, "", "Ping? Pong!");
send_pong(msg.arguments[0]);
}
diff --git a/Applications/IRCClient/IRCLogBufferModel.cpp b/Applications/IRCClient/IRCLogBufferModel.cpp
index e5aea977b9..db396c61f0 100644
--- a/Applications/IRCClient/IRCLogBufferModel.cpp
+++ b/Applications/IRCClient/IRCLogBufferModel.cpp
@@ -60,6 +60,8 @@ GVariant IRCLogBufferModel::data(const GModelIndex& index, Role role) const
}
}
if (role == Role::ForegroundColor) {
+ if (index.column() == Column::Timestamp)
+ return Color(Color::MidGray);
if (index.column() == Column::Text)
return m_log_buffer->at(index.row()).color;
}
diff --git a/Applications/IRCClient/IRCWindow.cpp b/Applications/IRCClient/IRCWindow.cpp
index 627d03c578..3413b0d51b 100644
--- a/Applications/IRCClient/IRCWindow.cpp
+++ b/Applications/IRCClient/IRCWindow.cpp
@@ -26,6 +26,10 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na
m_table_view->set_font(Font::default_fixed_width_font());
m_table_view->set_alternating_row_colors(false);
+ if (m_type == Server) {
+ m_table_view->set_column_hidden(IRCLogBufferModel::Column::Name, true);
+ }
+
if (m_type == Channel) {
auto* member_view = new GTableView(container);
member_view->set_headers_visible(false);
diff --git a/LibGUI/GTableView.cpp b/LibGUI/GTableView.cpp
index 1f42a176c0..f5f384ba5e 100644
--- a/LibGUI/GTableView.cpp
+++ b/LibGUI/GTableView.cpp
@@ -63,9 +63,14 @@ int GTableView::column_width(int column_index) const
Rect GTableView::header_rect(int column_index) const
{
+ if (is_column_hidden(column_index))
+ return { };
int x_offset = 0;
- for (int i = 0; i < column_index; ++i)
+ for (int i = 0; i < column_index; ++i) {
+ if (is_column_hidden(i))
+ continue;
x_offset += column_width(i) + horizontal_padding() * 2;
+ }
auto column_metadata = m_model->column_metadata(column_index);
int column_width = column_metadata.preferred_width;
return { x_offset, 0, column_width + horizontal_padding() * 2, header_height() };
@@ -137,6 +142,8 @@ void GTableView::paint_event(GPaintEvent& event)
int x_offset = 0;
for (int column_index = 0; column_index < m_model->column_count(); ++column_index) {
+ if (is_column_hidden(column_index))
+ continue;
auto column_metadata = m_model->column_metadata(column_index);
int column_width = column_metadata.preferred_width;
const Font& font = column_metadata.font ? *column_metadata.font : this->font();
@@ -192,6 +199,8 @@ void GTableView::paint_headers(Painter& painter)
painter.draw_line({ 0, header_height() - 1 }, { exposed_width - 1, header_height() - 1 }, Color::DarkGray);
int x_offset = 0;
for (int column_index = 0; column_index < m_model->column_count(); ++column_index) {
+ if (is_column_hidden(column_index))
+ continue;
auto column_metadata = m_model->column_metadata(column_index);
int column_width = column_metadata.preferred_width;
bool is_key_column = m_model->key_column() == column_index;
@@ -277,3 +286,22 @@ void GTableView::scroll_into_view(const GModelIndex& index, Orientation orientat
auto rect = row_rect(index.row()).translated(0, -header_height());
GScrollableWidget::scroll_into_view(rect, orientation);
}
+
+bool GTableView::is_column_hidden(int column) const
+{
+ if (column >= 0 && column < m_column_visibility.size())
+ return !m_column_visibility[column];
+ return false;
+}
+
+void GTableView::set_column_hidden(int column, bool hidden)
+{
+ ASSERT(column >= 0);
+ if (m_column_visibility.size() <= column) {
+ int previous_column_count = m_column_visibility.size();
+ m_column_visibility.resize(column + 1);
+ for (int i = previous_column_count; i < m_column_visibility.size(); ++i)
+ m_column_visibility[i] = true;
+ }
+ m_column_visibility[column] = !hidden;
+}
diff --git a/LibGUI/GTableView.h b/LibGUI/GTableView.h
index 1cb5e4de3e..4a8e3f97b8 100644
--- a/LibGUI/GTableView.h
+++ b/LibGUI/GTableView.h
@@ -35,6 +35,9 @@ public:
void scroll_into_view(const GModelIndex&, Orientation);
+ bool is_column_hidden(int) const;
+ void set_column_hidden(int, bool);
+
private:
virtual void model_notification(const GModelNotification&);
@@ -49,6 +52,7 @@ private:
int column_width(int) const;
void update_content_size();
+ Vector<bool> m_column_visibility;
RetainPtr<GTableModel> m_model;
int m_horizontal_padding { 5 };
bool m_headers_visible { true };