DolphinTreeView::DolphinTreeView(QWidget* parent) :
QTreeView(parent),
- m_keyPressed(false),
+ m_updateCurrentIndex(false),
m_expandingTogglePressed(false),
m_useDefaultIndexAt(true),
m_ignoreScrollTo(false),
// If a key-press triggers an action that e. g. opens a dialog, the
// widget gets no key-release event. Assure that the pressed state
// is reset to prevent accidently setting the current index during a selection.
- m_keyPressed = false;
+ m_updateCurrentIndex = false;
break;
default:
break;
void DolphinTreeView::keyPressEvent(QKeyEvent* event)
{
- // If the Control modifier is pressed, a multiple selection
- // is done and DolphinDetailsView::currentChanged() may not
- // not change the selection in a custom way.
- m_keyPressed = !(event->modifiers() & Qt::ControlModifier);
-
+ // See DolphinTreeView::currentChanged() for more information about m_updateCurrentIndex
+ m_updateCurrentIndex = (event->modifiers() == Qt::NoModifier);
QTreeView::keyPressEvent(event);
}
void DolphinTreeView::keyReleaseEvent(QKeyEvent* event)
{
QTreeView::keyReleaseEvent(event);
- m_keyPressed = false;
+ m_updateCurrentIndex = false;
}
void DolphinTreeView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
{
QTreeView::currentChanged(current, previous);
- // Stay consistent with QListView: When changing the current index by key presses,
- // also change the selection.
- if (m_keyPressed) {
+ // Stay consistent with QListView: When changing the current index by key presses
+ // without modifiers, also change the selection.
+ if (m_updateCurrentIndex) {
setCurrentIndex(current);
}
}
virtual QModelIndex indexAt (const QPoint& point) const;
virtual QRegion visualRegionForSelection(const QItemSelection& selection) const;
-protected:
+protected:
/**
* @return True, if the item with the index \p index accepts a drop. In this
* case a visual feedback for the user is given during dragging. Per
bool isAboveExpandingToggle(const QPoint& pos) const;
private:
- bool m_keyPressed; // true if a key is pressed currently; info used by currentChanged()
+ bool m_updateCurrentIndex;
bool m_expandingTogglePressed;
bool m_useDefaultIndexAt; // true, if QTreeView::indexAt() should be used
bool m_ignoreScrollTo; // true if calls to scrollTo(...) should do nothing.