Commit a81947bf authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Ensure that current group is selected when list gets focus

By default, QListView (resp. QAbstractItemView) make the first visible
item the current item when the view gets focus, but it doesn't select
this item. OTOH, if one navigates the items with the keyboard, then
the current item is also selected. This change makes the behavior more
consistent and allows the user to interact immediately with the current
item after moving the focus to the list without having to select the
current item first.

GnuPG-bug-id: 6095
parent 12055d69
......@@ -22,6 +22,7 @@
#include <KLocalizedString>
#include <KRandom>
#include <QItemSelectionModel>
#include <QLabel>
#include <QLineEdit>
#include <QListView>
......@@ -39,6 +40,23 @@ Q_DECLARE_METATYPE(KeyGroup)
namespace
{
class ListView : public QListView
{
Q_OBJECT
public:
using QListView::QListView;
protected:
void focusInEvent(QFocusEvent *event) override
{
QListView::focusInEvent(event);
// select current item if it isn't selected
if (currentIndex().isValid() && !selectionModel()->isSelected(currentIndex())) {
selectionModel()->select(currentIndex(), QItemSelectionModel::ClearAndSelect);
}
}
};
class ProxyModel : public AbstractKeyListSortFilterProxyModel
{
Q_OBJECT
......@@ -135,7 +153,7 @@ public:
groupsFilterModel->setSortCaseSensitivity(Qt::CaseInsensitive);
groupsFilterModel->setSourceModel(groupsModel);
groupsFilterModel->sort(KeyList::Summary, Qt::AscendingOrder);
ui.groupsList = new QListView(q);
ui.groupsList = new ListView(q);
ui.groupsList->setModel(groupsFilterModel);
ui.groupsList->setSelectionBehavior(QAbstractItemView::SelectRows);
ui.groupsList->setSelectionMode(QAbstractItemView::ExtendedSelection);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment