mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 04:24:59 +00:00
LibGUI: Move most of mouse event handling to GAbstractView
This deduplicates existing code, and also gives all the model-backed widgets selection manipulation and drag support for free :^)
This commit is contained in:
parent
fd11c96e8e
commit
d3ce7ae0e3
9 changed files with 197 additions and 185 deletions
|
@ -216,6 +216,8 @@ GModelIndex GColumnsView::index_at_event_position(const Point& a_position) const
|
|||
|
||||
void GColumnsView::mousedown_event(GMouseEvent& event)
|
||||
{
|
||||
GAbstractView::mousedown_event(event);
|
||||
|
||||
if (!model())
|
||||
return;
|
||||
|
||||
|
@ -223,15 +225,7 @@ void GColumnsView::mousedown_event(GMouseEvent& event)
|
|||
return;
|
||||
|
||||
auto index = index_at_event_position(event.position());
|
||||
if (!index.is_valid()) {
|
||||
selection().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.modifiers() & Mod_Ctrl) {
|
||||
selection().toggle(index);
|
||||
} else {
|
||||
selection().set(index);
|
||||
if (index.is_valid() && !(event.modifiers() & Mod_Ctrl)) {
|
||||
if (model()->row_count(index))
|
||||
push_column(index);
|
||||
}
|
||||
|
@ -250,34 +244,6 @@ void GColumnsView::did_update_model()
|
|||
update();
|
||||
}
|
||||
|
||||
void GColumnsView::doubleclick_event(GMouseEvent& event)
|
||||
{
|
||||
if (!model())
|
||||
return;
|
||||
|
||||
if (event.button() != GMouseButton::Left)
|
||||
return;
|
||||
|
||||
mousedown_event(event);
|
||||
activate_selected();
|
||||
}
|
||||
|
||||
void GColumnsView::context_menu_event(GContextMenuEvent& event)
|
||||
{
|
||||
if (!model())
|
||||
return;
|
||||
|
||||
auto index = index_at_event_position(event.position());
|
||||
if (index.is_valid()) {
|
||||
if (!selection().contains(index))
|
||||
selection().set(index);
|
||||
} else {
|
||||
selection().clear();
|
||||
}
|
||||
if (on_context_menu_request)
|
||||
on_context_menu_request(index, event);
|
||||
}
|
||||
|
||||
void GColumnsView::keydown_event(GKeyEvent& event)
|
||||
{
|
||||
if (!model())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue