From abd82f88db694557a9eac0706f6831f150123c7b Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Thu, 7 Jan 2021 22:25:07 +0100 Subject: Fix Alt+Click for selecting children of separators. --- src/modlistview.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/modlistview.cpp') diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 91d522a6..53070d08 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -1333,10 +1333,19 @@ void ModListView::timerEvent(QTimerEvent* event) void ModListView::mousePressEvent(QMouseEvent* event) { + // disable edit if Alt is pressed + auto triggers = editTriggers(); + if (event->modifiers() & Qt::AltModifier) { + setEditTriggers(NoEditTriggers); + } + // we call the parent class first so that we can use the actual // selection state of the item after QTreeView::mousePressEvent(event); + // restore triggers + setEditTriggers(triggers); + const auto index = indexAt(event->pos()); if (event->isAccepted() @@ -1353,6 +1362,42 @@ void ModListView::mousePressEvent(QMouseEvent* event) } } +void ModListView::mouseReleaseEvent(QMouseEvent* event) +{ + // this is a duplicate of mousePressEvent because for some reason + // the selection is not always triggered in mousePressEvent and only + // doing it here create a small lag between the selection of the + // separator and the children + + // disable edit if Alt is pressed + auto triggers = editTriggers(); + if (event->modifiers() & Qt::AltModifier) { + setEditTriggers(NoEditTriggers); + } + + // we call the parent class first so that we can use the actual + // selection state of the item after + QTreeView::mouseReleaseEvent(event); + + const auto index = indexAt(event->pos()); + + // restore triggers + setEditTriggers(triggers); + + if (event->isAccepted() + && hasCollapsibleSeparators() + && index.isValid() && model()->hasChildren(indexAt(event->pos())) + && (event->modifiers() & Qt::AltModifier)) { + + const auto flag = selectionModel()->isSelected(index) ? + QItemSelectionModel::Select : QItemSelectionModel::Deselect; + const QItemSelection selection( + model()->index(0, index.column(), index), + model()->index(model()->rowCount(index) - 1, index.column(), index)); + selectionModel()->select(selection, flag | QItemSelectionModel::Rows); + } +} + bool ModListView::event(QEvent* event) { if (event->type() == QEvent::KeyPress -- cgit v1.3.1