diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-11-30 17:02:45 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-30 17:54:54 +0100 |
commit | 602a830428986463e63b8cf2fdd4fbb621280d06 (patch) | |
tree | 6dde86698f0359ca87e589d1dbc98a1188f6c61b /Applications | |
parent | 50b7122798ee8783ac52dacf7f1f9cb41d3be160 (diff) | |
download | serenity-602a830428986463e63b8cf2fdd4fbb621280d06.zip |
Spreadsheet: Invert the drag-selection trigger
Make drag-selection the default behaviour, allowing (almost) any part of
the cell to initiate a select.
a small 5x5 rect at the corners of a cell can be used to initiate a
drag-copy instead.
Fixes #4268.
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/Spreadsheet/SpreadsheetView.cpp | 17 | ||||
-rw-r--r-- | Applications/Spreadsheet/SpreadsheetView.h | 1 |
2 files changed, 13 insertions, 5 deletions
diff --git a/Applications/Spreadsheet/SpreadsheetView.cpp b/Applications/Spreadsheet/SpreadsheetView.cpp index 7c703e5b4f..4eef78dbe3 100644 --- a/Applications/Spreadsheet/SpreadsheetView.cpp +++ b/Applications/Spreadsheet/SpreadsheetView.cpp @@ -84,24 +84,30 @@ void InfinitelyScrollableTableView::mousemove_event(GUI::MouseEvent& event) if (auto model = this->model()) { auto index = index_at_event_position(event.position()); if (!index.is_valid()) - return; + return TableView::mousemove_event(event); auto holding_left_button = !!(event.buttons() & GUI::MouseButton::Left); auto rect = content_rect(index); auto distance = rect.center().absolute_relative_distance_to(event.position()); - if (distance.x() > rect.width() / 2 || distance.y() > rect.height() / 2) { + if (distance.x() >= rect.width() / 2 - 5 && distance.y() >= rect.height() / 2 - 5) { set_override_cursor(Gfx::StandardCursor::Crosshair); + m_should_intercept_drag = false; + if (holding_left_button) { + m_has_committed_to_dragging = true; + // Force a drag to happen by moving the mousedown position to the center of the cell. + m_left_mousedown_position = rect.center(); + } + } else if (!m_should_intercept_drag) { + set_override_cursor(Gfx::StandardCursor::Arrow); if (!holding_left_button) { m_starting_selection_index = index; } else { m_should_intercept_drag = true; m_might_drag = false; } - } else if (!m_should_intercept_drag) { - set_override_cursor(Gfx::StandardCursor::Arrow); } - if (holding_left_button && m_should_intercept_drag) { + if (holding_left_button && m_should_intercept_drag && !m_has_committed_to_dragging) { if (!m_starting_selection_index.is_valid()) m_starting_selection_index = index; @@ -126,6 +132,7 @@ void InfinitelyScrollableTableView::mousemove_event(GUI::MouseEvent& event) void InfinitelyScrollableTableView::mouseup_event(GUI::MouseEvent& event) { m_should_intercept_drag = false; + m_has_committed_to_dragging = false; TableView::mouseup_event(event); } diff --git a/Applications/Spreadsheet/SpreadsheetView.h b/Applications/Spreadsheet/SpreadsheetView.h index c48528938a..ae1fe2e26c 100644 --- a/Applications/Spreadsheet/SpreadsheetView.h +++ b/Applications/Spreadsheet/SpreadsheetView.h @@ -91,6 +91,7 @@ private: virtual void mouseup_event(GUI::MouseEvent&) override; bool m_should_intercept_drag { false }; + bool m_has_committed_to_dragging { false }; GUI::ModelIndex m_starting_selection_index; }; |