LibGUI: Mouse events didn't hit table headers when vertically scrolled

Only take the horizontal scroll into account when hit testing the
table view headers.
This commit is contained in:
Andreas Kling 2020-02-25 23:05:16 +01:00
parent 4f99c3726c
commit ac53af6b7b
Notes: sideshowbarker 2024-07-19 09:03:36 +09:00

View file

@ -263,6 +263,7 @@ void AbstractTableView::mousemove_event(MouseEvent& event)
return AbstractView::mousemove_event(event);
auto adjusted_position = this->adjusted_position(event.position());
Gfx::Point horizontally_adjusted_position(adjusted_position.x(), event.position().y());
if (m_in_column_resize) {
auto delta = adjusted_position - m_column_resize_origin;
@ -281,7 +282,7 @@ void AbstractTableView::mousemove_event(MouseEvent& event)
if (m_pressed_column_header_index != -1) {
auto header_rect = this->header_rect(m_pressed_column_header_index);
if (header_rect.contains(adjusted_position)) {
if (header_rect.contains(horizontally_adjusted_position)) {
set_hovered_header_index(m_pressed_column_header_index);
if (!m_pressed_column_header_is_pressed)
update_headers();
@ -299,12 +300,12 @@ void AbstractTableView::mousemove_event(MouseEvent& event)
int column_count = model()->column_count();
bool found_hovered_header = false;
for (int i = 0; i < column_count; ++i) {
if (column_resize_grabbable_rect(i).contains(adjusted_position)) {
if (column_resize_grabbable_rect(i).contains(horizontally_adjusted_position)) {
window()->set_override_cursor(StandardCursor::ResizeHorizontal);
set_hovered_header_index(-1);
return;
}
if (header_rect(i).contains(adjusted_position)) {
if (header_rect(i).contains(horizontally_adjusted_position)) {
set_hovered_header_index(i);
found_hovered_header = true;
}
@ -320,16 +321,17 @@ void AbstractTableView::mousemove_event(MouseEvent& event)
void AbstractTableView::mouseup_event(MouseEvent& event)
{
auto adjusted_position = this->adjusted_position(event.position());
Gfx::Point horizontally_adjusted_position(adjusted_position.x(), event.position().y());
if (event.button() == MouseButton::Left) {
if (m_in_column_resize) {
if (!column_resize_grabbable_rect(m_resizing_column).contains(adjusted_position))
if (!column_resize_grabbable_rect(m_resizing_column).contains(horizontally_adjusted_position))
window()->set_override_cursor(StandardCursor::None);
m_in_column_resize = false;
return;
}
if (m_pressed_column_header_index != -1) {
auto header_rect = this->header_rect(m_pressed_column_header_index);
if (header_rect.contains(adjusted_position)) {
if (header_rect.contains(horizontally_adjusted_position)) {
auto new_sort_order = SortOrder::Ascending;
if (model()->key_column() == m_pressed_column_header_index)
new_sort_order = model()->sort_order() == SortOrder::Ascending
@ -356,11 +358,12 @@ void AbstractTableView::mousedown_event(MouseEvent& event)
return AbstractView::mousedown_event(event);
auto adjusted_position = this->adjusted_position(event.position());
Gfx::Point horizontally_adjusted_position(adjusted_position.x(), event.position().y());
if (event.y() < header_height()) {
int column_count = model()->column_count();
for (int i = 0; i < column_count; ++i) {
if (column_resize_grabbable_rect(i).contains(adjusted_position)) {
if (column_resize_grabbable_rect(i).contains(horizontally_adjusted_position)) {
m_resizing_column = i;
m_in_column_resize = true;
m_column_resize_original_width = column_width(i);
@ -369,7 +372,7 @@ void AbstractTableView::mousedown_event(MouseEvent& event)
}
auto header_rect = this->header_rect(i);
auto column_metadata = model()->column_metadata(i);
if (header_rect.contains(adjusted_position) && column_metadata.sortable == Model::ColumnMetadata::Sortable::True) {
if (header_rect.contains(horizontally_adjusted_position) && column_metadata.sortable == Model::ColumnMetadata::Sortable::True) {
m_pressed_column_header_index = i;
m_pressed_column_header_is_pressed = true;
update_headers();