Fix misbehavior when you double click after a single click on a tree item

This issue appeared as a side effect since the commit
bcaa9e4a37, which adds dropdown
animation to the library/internet view.

Reproduce:
Single/double click on a song item in library/internet view
then all double clicks on this item will be ignored, until you
single click on it once again.

The reason of this behavior in that the "setExpanded" method call from the
"ItemClicked" slot makes the invocation of the "mouseDoubleClickEvent"
method in the context where the view is in the "QAbstractTreeView::AnimatingState"
which makes impossible to emit "doubleClicked" signal, because it just
returns immediatelly (see http://code.qt.io/cgit/qt/qt.git/tree/src/gui/itemviews/qtreeview.cpp#n1849).

To get rid of this behavior we emit "doubleClicked" signal ourselves.
This commit is contained in:
Ivan Leontiev 2016-01-15 02:17:40 +03:00
parent 93aa5031c7
commit b85d09cd9c
2 changed files with 15 additions and 0 deletions

View File

@ -113,6 +113,20 @@ void AutoExpandingTreeView::mousePressEvent(QMouseEvent* event) {
}
}
void AutoExpandingTreeView::mouseDoubleClickEvent(QMouseEvent* event) {
State p_state = state();
QModelIndex index = indexAt(event->pos());
QTreeView::mouseDoubleClickEvent(event);
// If the p_state was the "AnimatingState", then the base class's
// "mouseDoubleClickEvent" method just did nothing, hence the
// "doubleClicked" signal is not emitted. So let's do it ourselves.
if (index.isValid() && p_state == AnimatingState) {
emit doubleClicked(index);
}
}
void AutoExpandingTreeView::keyPressEvent(QKeyEvent* e) {
switch (e->key()) {
case Qt::Key_Enter:

View File

@ -47,6 +47,7 @@ signals:
// QWidget
void mousePressEvent(QMouseEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
void keyPressEvent(QKeyEvent* event);
virtual bool CanRecursivelyExpand(const QModelIndex& index) const {