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

Allow column-by-column navigation in certificate list

This overrides the default handling of left/right cursor movement of
QTreeView. The left/right keys always move the cursor to the previous/next
column (or move the horizontal scroll bar). QTreeView's expanding and
collapsing of items with children is not done. The user has to use Plus,
Minus, or Asterisk for expanding or collapsing items.

Navigation column by column is important for people using screen
readers because this way they can get the values of the individual
entries of the table. Visually it may not be possible to see which entry
is the current entry because we always select complete rows, but that
shouldn't be a problem because it doesn't matter which entry of a row is
the current entry since there is no interaction possible with individual
table entries. Any interaction always applies to the selected rows.

GnuPG-bug-id: 5841
parent de481c9e
Pipeline #140956 passed with stage
in 3 minutes and 28 seconds
......@@ -38,6 +38,7 @@
#include <QAction>
#include <QEvent>
#include <QContextMenuEvent>
#include <QScrollBar>
#include <KSharedConfig>
#include <KLocalizedString>
......@@ -114,12 +115,96 @@ protected:
return false;
}
void keyPressEvent(QKeyEvent *event) override;
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
private:
bool mMoveCursorUpdatedView = false;
QMenu *mHeaderPopup = nullptr;
QList<QAction *> mColumnActions;
};
void TreeView::keyPressEvent(QKeyEvent *event)
{
mMoveCursorUpdatedView = false;
QTreeView::keyPressEvent(event);
if (mMoveCursorUpdatedView) {
event->accept();
}
}
QModelIndex TreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
{
// this code is based heavily on QTreeView::moveCursor()
QModelIndex current = currentIndex();
if (!current.isValid()) {
// let QTreeView handle invalid current index
return QTreeView::moveCursor(cursorAction, modifiers);
}
if (isRightToLeft()) {
if (cursorAction == MoveRight) {
cursorAction = MoveLeft;
} else if (cursorAction == MoveLeft) {
cursorAction = MoveRight;
}
}
switch (cursorAction) {
case MoveLeft: {
int visualColumn = header()->visualIndex(current.column()) - 1;
while (visualColumn >= 0 && isColumnHidden(header()->logicalIndex(visualColumn))) {
visualColumn--;
}
int newColumn = header()->logicalIndex(visualColumn);
QModelIndex next = current.sibling(current.row(), newColumn);
if (next.isValid()) {
return next;
}
//last restort: we change the scrollbar value
QScrollBar *sb = horizontalScrollBar();
int oldValue = sb->value();
sb->setValue(sb->value() - sb->singleStep());
if (oldValue != sb->value()) {
mMoveCursorUpdatedView = true;
}
updateGeometries();
viewport()->update();
break;
}
case MoveRight: {
int visualColumn = header()->visualIndex(current.column()) + 1;
while (visualColumn < model()->columnCount(current.parent()) && isColumnHidden(header()->logicalIndex(visualColumn))) {
visualColumn++;
}
const int newColumn = header()->logicalIndex(visualColumn);
const QModelIndex next = current.sibling(current.row(), newColumn);
if (next.isValid()) {
return next;
}
//last restort: we change the scrollbar value
QScrollBar *sb = horizontalScrollBar();
int oldValue = sb->value();
sb->setValue(sb->value() + sb->singleStep());
if (oldValue != sb->value()) {
mMoveCursorUpdatedView = true;
}
updateGeometries();
viewport()->update();
break;
}
default:
return QTreeView::moveCursor(cursorAction, modifiers);
}
return current;
}
const KeyListModelInterface * keyListModel(const QTreeView &view)
{
const KeyListModelInterface *const klmi = dynamic_cast<KeyListModelInterface *>(view.model());
......@@ -250,8 +335,7 @@ void KeyTreeView::init()
m_view->setSelectionBehavior(QAbstractItemView::SelectRows);
m_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
//m_view->setAlternatingRowColors( true );
m_view->setAllColumnsShowFocus(true);
m_view->setAllColumnsShowFocus(false);
m_view->setSortingEnabled(true);
m_view->setAccessibleName(i18n("Certificates"));
m_view->setAccessibleDescription(m_isHierarchical ? i18n("Hierarchical list of certificates") : i18n("List of certificates"));
......
Markdown is supported
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