mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 01:34:58 +00:00
LibGUI+WindowServer: Allow specifying an optional drag bitmap
This bitmap is displayed alongside the dragged text underneath the mouse cursor while dragging. This will be a perfect fit for dragging e.g files around. :^)
This commit is contained in:
parent
183ee5847c
commit
f5dfb29607
5 changed files with 36 additions and 6 deletions
|
@ -113,14 +113,23 @@ void GItemView::mousemove_event(GMouseEvent& event)
|
|||
dbg() << "Initiate drag!";
|
||||
auto drag_operation = GDragOperation::construct();
|
||||
|
||||
RefPtr<GraphicsBitmap> bitmap;
|
||||
|
||||
StringBuilder builder;
|
||||
selection().for_each_index([&](auto& index) {
|
||||
auto data = model()->data(index);
|
||||
builder.append(data.to_string());
|
||||
builder.append(" ");
|
||||
|
||||
if (!bitmap) {
|
||||
GVariant icon_data = model()->data(index, GModel::Role::Icon);
|
||||
if (icon_data.is_icon())
|
||||
bitmap = icon_data.as_icon().bitmap_for_size(32);
|
||||
}
|
||||
});
|
||||
|
||||
drag_operation->set_text(builder.to_string());
|
||||
drag_operation->set_bitmap(bitmap);
|
||||
auto outcome = drag_operation->exec();
|
||||
switch (outcome) {
|
||||
case GDragOperation::Outcome::Accepted:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue