mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 06:02:07 +03:00
LibGUI: Allow dropping drags on AbstractView
You can now drop things on an AbstractView, which will ask its model if the drag is acceptable to drop at the index where it's dropped. If it's accepted by the model, the view will fire the on_drop hook.
This commit is contained in:
parent
8b3864c70a
commit
f0ae353c9e
Notes:
sideshowbarker
2024-07-19 09:21:33 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f0ae353c9ef
@ -326,4 +326,19 @@ void AbstractView::context_menu_event(ContextMenuEvent& event)
|
||||
on_context_menu_request(index, event);
|
||||
}
|
||||
|
||||
void AbstractView::drop_event(DropEvent& event)
|
||||
{
|
||||
event.accept();
|
||||
|
||||
if (!model())
|
||||
return;
|
||||
|
||||
auto index = index_at_event_position(event.position());
|
||||
if (!index.is_valid())
|
||||
return;
|
||||
|
||||
if (on_drop)
|
||||
on_drop(index, event);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ public:
|
||||
Function<void(const ModelIndex&)> on_activation;
|
||||
Function<void(const ModelIndex&)> on_selection;
|
||||
Function<void(const ModelIndex&, const ContextMenuEvent&)> on_context_menu_request;
|
||||
Function<void(const ModelIndex&, const DropEvent&)> on_drop;
|
||||
|
||||
Function<OwnPtr<ModelEditingDelegate>(const ModelIndex&)> aid_create_editing_delegate;
|
||||
|
||||
@ -83,6 +84,7 @@ protected:
|
||||
virtual void mouseup_event(MouseEvent&) override;
|
||||
virtual void doubleclick_event(MouseEvent&) override;
|
||||
virtual void context_menu_event(ContextMenuEvent&) override;
|
||||
virtual void drop_event(DropEvent&) override;
|
||||
|
||||
virtual void did_scroll() override;
|
||||
void activate(const ModelIndex&);
|
||||
|
Loading…
Reference in New Issue
Block a user