mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 12:05:08 +00:00
LibGUI: Take scroll offset into account on ItemView rubberband selection
Same kind of issue as #1271.
This commit is contained in:
parent
ee5a49e2fe
commit
b58893cfe1
2 changed files with 16 additions and 5 deletions
|
@ -129,7 +129,7 @@ ModelIndex ItemView::index_at_event_position(const Gfx::Point& position) const
|
||||||
ASSERT(model());
|
ASSERT(model());
|
||||||
// FIXME: Since all items are the same size, just compute the clicked item index
|
// FIXME: Since all items are the same size, just compute the clicked item index
|
||||||
// instead of iterating over everything.
|
// instead of iterating over everything.
|
||||||
auto adjusted_position = position.translated(0, vertical_scrollbar().value());
|
auto adjusted_position = this->adjusted_position(position);
|
||||||
const auto& column_metadata = model()->column_metadata(model_column());
|
const auto& column_metadata = model()->column_metadata(model_column());
|
||||||
const auto& font = column_metadata.font ? *column_metadata.font : this->font();
|
const auto& font = column_metadata.font ? *column_metadata.font : this->font();
|
||||||
for (int item_index = 0; item_index < item_count(); ++item_index) {
|
for (int item_index = 0; item_index < item_count(); ++item_index) {
|
||||||
|
@ -145,6 +145,11 @@ ModelIndex ItemView::index_at_event_position(const Gfx::Point& position) const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gfx::Point ItemView::adjusted_position(const Gfx::Point& position) const
|
||||||
|
{
|
||||||
|
return position.translated(0, vertical_scrollbar().value());
|
||||||
|
}
|
||||||
|
|
||||||
void ItemView::mousedown_event(MouseEvent& event)
|
void ItemView::mousedown_event(MouseEvent& event)
|
||||||
{
|
{
|
||||||
if (!model())
|
if (!model())
|
||||||
|
@ -169,10 +174,12 @@ void ItemView::mousedown_event(MouseEvent& event)
|
||||||
selection().clear();
|
selection().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto adjusted_position = this->adjusted_position(event.position());
|
||||||
|
|
||||||
m_might_drag = false;
|
m_might_drag = false;
|
||||||
m_rubber_banding = true;
|
m_rubber_banding = true;
|
||||||
m_rubber_band_origin = event.position();
|
m_rubber_band_origin = adjusted_position;
|
||||||
m_rubber_band_current = event.position();
|
m_rubber_band_current = adjusted_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemView::mouseup_event(MouseEvent& event)
|
void ItemView::mouseup_event(MouseEvent& event)
|
||||||
|
@ -210,8 +217,9 @@ void ItemView::mousemove_event(MouseEvent& event)
|
||||||
return AbstractView::mousemove_event(event);
|
return AbstractView::mousemove_event(event);
|
||||||
|
|
||||||
if (m_rubber_banding) {
|
if (m_rubber_banding) {
|
||||||
if (m_rubber_band_current != event.position()) {
|
auto adjusted_position = this->adjusted_position(event.position());
|
||||||
m_rubber_band_current = event.position();
|
if (m_rubber_band_current != adjusted_position) {
|
||||||
|
m_rubber_band_current = adjusted_position;
|
||||||
auto rubber_band_rect = Gfx::Rect::from_two_points(m_rubber_band_origin, m_rubber_band_current);
|
auto rubber_band_rect = Gfx::Rect::from_two_points(m_rubber_band_origin, m_rubber_band_current);
|
||||||
selection().clear();
|
selection().clear();
|
||||||
for (auto item_index : items_intersecting_rect(rubber_band_rect)) {
|
for (auto item_index : items_intersecting_rect(rubber_band_rect)) {
|
||||||
|
@ -249,6 +257,8 @@ void ItemView::second_paint_event(PaintEvent& event)
|
||||||
|
|
||||||
Painter painter(*this);
|
Painter painter(*this);
|
||||||
painter.add_clip_rect(event.rect());
|
painter.add_clip_rect(event.rect());
|
||||||
|
painter.translate(frame_thickness(), frame_thickness());
|
||||||
|
painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
|
||||||
|
|
||||||
auto rubber_band_rect = Gfx::Rect::from_two_points(m_rubber_band_origin, m_rubber_band_current);
|
auto rubber_band_rect = Gfx::Rect::from_two_points(m_rubber_band_origin, m_rubber_band_current);
|
||||||
painter.fill_rect(rubber_band_rect, parent_widget()->palette().rubber_band_fill());
|
painter.fill_rect(rubber_band_rect, parent_widget()->palette().rubber_band_fill());
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
void set_model_column(int column) { m_model_column = column; }
|
void set_model_column(int column) { m_model_column = column; }
|
||||||
|
|
||||||
virtual ModelIndex index_at_event_position(const Gfx::Point&) const override;
|
virtual ModelIndex index_at_event_position(const Gfx::Point&) const override;
|
||||||
|
Gfx::Point adjusted_position(const Gfx::Point&) const;
|
||||||
|
|
||||||
virtual void select_all() override;
|
virtual void select_all() override;
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue