mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 16:35:08 +00:00
LibGUI: Indicate ItemView drag acceptance with a little rectangle
If an index accepts a drag, we now draw a little rectangle around it when the drag moves over it.
This commit is contained in:
parent
f0ae353c9e
commit
2c14e46b96
2 changed files with 29 additions and 0 deletions
|
@ -33,6 +33,8 @@
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGUI/ScrollBar.h>
|
#include <LibGUI/ScrollBar.h>
|
||||||
|
|
||||||
|
//#define DRAGDROP_DEBUG
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
ItemView::ItemView(Widget* parent)
|
ItemView::ItemView(Widget* parent)
|
||||||
|
@ -178,6 +180,25 @@ void ItemView::mouseup_event(MouseEvent& event)
|
||||||
AbstractView::mouseup_event(event);
|
AbstractView::mouseup_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemView::drag_move_event(DragEvent& event)
|
||||||
|
{
|
||||||
|
auto index = index_at_event_position(event.position());
|
||||||
|
ModelIndex new_drop_candidate_index;
|
||||||
|
if (index.is_valid()) {
|
||||||
|
bool acceptable = model()->accepts_drag(index, event.data_type());
|
||||||
|
#ifdef DRAGDROP_DEBUG
|
||||||
|
dbg() << "Drag of type '" << event.data_type() << "' moving over " << index << ", acceptable: " << acceptable;
|
||||||
|
#endif
|
||||||
|
if (acceptable)
|
||||||
|
new_drop_candidate_index = index;
|
||||||
|
}
|
||||||
|
if (m_drop_candidate_index != new_drop_candidate_index) {
|
||||||
|
m_drop_candidate_index = new_drop_candidate_index;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
event.accept();
|
||||||
|
}
|
||||||
|
|
||||||
void ItemView::mousemove_event(MouseEvent& event)
|
void ItemView::mousemove_event(MouseEvent& event)
|
||||||
{
|
{
|
||||||
if (!model())
|
if (!model())
|
||||||
|
@ -273,6 +294,11 @@ void ItemView::paint_event(PaintEvent& event)
|
||||||
text_color = model()->data(model_index, Model::Role::ForegroundColor).to_color(palette().color(foreground_role()));
|
text_color = model()->data(model_index, Model::Role::ForegroundColor).to_color(palette().color(foreground_role()));
|
||||||
painter.fill_rect(text_rect, background_color);
|
painter.fill_rect(text_rect, background_color);
|
||||||
painter.draw_text(text_rect, item_text.to_string(), font, Gfx::TextAlignment::Center, text_color, Gfx::TextElision::Right);
|
painter.draw_text(text_rect, item_text.to_string(), font, Gfx::TextAlignment::Center, text_color, Gfx::TextElision::Right);
|
||||||
|
|
||||||
|
if (model_index == m_drop_candidate_index) {
|
||||||
|
// FIXME: This visualization is not great, as it's also possible to drop things on the text label..
|
||||||
|
painter.draw_rect(icon_rect.inflated(8, 8), palette().selection(), true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ private:
|
||||||
virtual void mousemove_event(MouseEvent&) override;
|
virtual void mousemove_event(MouseEvent&) override;
|
||||||
virtual void mouseup_event(MouseEvent&) override;
|
virtual void mouseup_event(MouseEvent&) override;
|
||||||
virtual void keydown_event(KeyEvent&) override;
|
virtual void keydown_event(KeyEvent&) override;
|
||||||
|
virtual void drag_move_event(DragEvent&) override;
|
||||||
|
|
||||||
int item_count() const;
|
int item_count() const;
|
||||||
Gfx::Rect item_rect(int item_index) const;
|
Gfx::Rect item_rect(int item_index) const;
|
||||||
|
@ -81,6 +82,8 @@ private:
|
||||||
Gfx::Point m_rubber_band_origin;
|
Gfx::Point m_rubber_band_origin;
|
||||||
Gfx::Point m_rubber_band_current;
|
Gfx::Point m_rubber_band_current;
|
||||||
Vector<ModelIndex> m_rubber_band_remembered_selection;
|
Vector<ModelIndex> m_rubber_band_remembered_selection;
|
||||||
|
|
||||||
|
ModelIndex m_drop_candidate_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue