m_model(0),
m_view(0),
m_selectionManager(new KItemListSelectionManager(this)),
- m_pressedIndex(-1)
+ m_pressedIndex(-1),
+ m_oldSelection()
{
}
} else {
startPos.rx() += m_view->offset();
}
+
+ m_oldSelection = m_selectionManager->selectedItems();
rubberBand->setStartPosition(startPos);
rubberBand->setEndPosition(startPos);
rubberBand->setActive(true);
if (rubberBand->isActive()) {
disconnect(rubberBand, SIGNAL(endPositionChanged(QPointF,QPointF)), this, SLOT(slotRubberBandChanged()));
rubberBand->setActive(false);
+ m_oldSelection.clear();
m_pressedIndex = -1;
return false;
}
rubberBandRect.translate(-m_view->offset(), 0);
}
- QSet<int> previousSelectedItems;
- if (m_selectionManager->hasSelection()) {
- // Don't clear the current selection in case if the user pressed the
- // Shift- or Control-key during the rubberband selection
+ if (!m_oldSelection.isEmpty()) {
+ // Clear the old selection that was available before the rubberband has
+ // been activated in case if no Shift- or Control-key are pressed
const bool shiftOrControlPressed = QApplication::keyboardModifiers() & Qt::ShiftModifier ||
QApplication::keyboardModifiers() & Qt::ControlModifier;
- if (shiftOrControlPressed) {
- previousSelectedItems = m_selectionManager->selectedItems();
+ if (!shiftOrControlPressed) {
+ m_oldSelection.clear();
}
}
}
} while (!selectionFinished);
- m_selectionManager->setSelectedItems(selectedItems + previousSelectedItems);
+ m_selectionManager->setSelectedItems(selectedItems + m_oldSelection);
}
#include "kitemlistcontroller.moc"
#include <libdolphin_export.h>
#include <QObject>
+#include <QSet>
class KItemModelBase;
class KItemListSelectionManager;
KItemListView* m_view;
KItemListSelectionManager* m_selectionManager;
int m_pressedIndex;
+
+ /**
+ * When starting a rubberband selection during a Shift- or Control-key has been
+ * pressed the current selection should never be deleted. To be able to restore
+ * the current selection it is remembered in m_oldSelection before
+ * rubberband gets activated.
+ */
+ QSet<int> m_oldSelection;
};
#endif