GTreeView: Make double-clicking toggle openable items

This commit is contained in:
Andreas Kling 2019-09-07 21:45:06 +02:00
parent 2f5b2685af
commit 64b1e9deec
Notes: sideshowbarker 2024-07-19 12:13:17 +09:00
2 changed files with 19 additions and 0 deletions

View file

@ -77,6 +77,24 @@ void GTreeView::mousedown_event(GMouseEvent& event)
toggle_index(index);
}
void GTreeView::doubleclick_event(GMouseEvent& event)
{
if (!model())
return;
auto& model = *this->model();
auto adjusted_position = event.position().translated(horizontal_scrollbar().value() - frame_thickness(), vertical_scrollbar().value() - frame_thickness());
bool is_toggle;
auto index = index_at_content_position(adjusted_position, is_toggle);
if (!index.is_valid())
return;
if (selection().first() != index)
selection().set(index);
if (model.row_count(index))
toggle_index(index);
}
void GTreeView::toggle_index(const GModelIndex& index)
{
ASSERT(model()->row_count(index));

View file

@ -13,6 +13,7 @@ public:
protected:
virtual void paint_event(GPaintEvent&) override;
virtual void mousedown_event(GMouseEvent&) override;
virtual void doubleclick_event(GMouseEvent&) override;
virtual void keydown_event(GKeyEvent&) override;
virtual void did_update_selection() override;
virtual void did_update_model() override;