1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:38:10 +00:00

LibGUI: Have widgets signal willingness to accept drops

If a widget accept()'s a "drag enter" event, that widget now becomes
the application-wide "pending drop" widget. That state is cleared if
the drag moves over another widget (or leaves the window entirely.)
This commit is contained in:
Andreas Kling 2021-01-09 00:11:17 +01:00
parent dbd090fd95
commit 3b94af2c07
5 changed files with 60 additions and 19 deletions

View file

@ -314,17 +314,22 @@ void Widget::handle_paint_event(PaintEvent& event)
});
second_paint_event(event);
auto* app = Application::the();
if (app && app->dnd_debugging_enabled() && has_pending_drop()) {
Painter painter(*this);
painter.draw_rect(rect(), Color::Blue);
}
if (app && app->focus_debugging_enabled() && is_focused()) {
Painter painter(*this);
painter.draw_rect(rect(), Color::Cyan);
}
if (is_being_inspected()) {
Painter painter(*this);
painter.draw_rect(rect(), Color::Magenta);
}
if (Application::the()->focus_debugging_enabled()) {
if (is_focused()) {
Painter painter(*this);
painter.draw_rect(rect(), Color::Cyan);
}
}
}
void Widget::set_layout(NonnullRefPtr<Layout> layout)
@ -499,27 +504,23 @@ void Widget::change_event(Event&)
{
}
void Widget::drag_move_event(DragEvent& event)
void Widget::drag_move_event(DragEvent&)
{
event.ignore();
}
void Widget::drag_enter_event(DragEvent& event)
{
dbgln("{} {:p} DRAG ENTER @ {}, {}", class_name(), this, event.position(), event.data_type());
event.ignore();
}
void Widget::drag_leave_event(Event& event)
void Widget::drag_leave_event(Event&)
{
dbgln("{} {:p} DRAG LEAVE", class_name(), this);
event.ignore();
}
void Widget::drop_event(DropEvent& event)
{
dbgln("{} {:p} DROP @ {}, '{}'", class_name(), this, event.position(), event.text());
event.ignore();
}
void Widget::theme_change_event(ThemeChangeEvent&)
@ -1035,4 +1036,9 @@ void Widget::set_shrink_to_fit(bool b)
invalidate_layout();
}
bool Widget::has_pending_drop() const
{
return Application::the()->pending_drop_widget() == this;
}
}