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

Add a tree view with improved keyboard navigation

This simple derivative of QTreeWidget allows column by column navigation
with the keyboard which is crucial for accessibility.

GnuPG-bug-id: 6103
parent f9b902d5
......@@ -133,6 +133,8 @@ target_sources(KF5Libkleo PRIVATE
ui/filenamerequester.h
ui/messagebox.cpp
ui/messagebox.h
ui/navigatabletreewidget.cpp
ui/navigatabletreewidget.h
ui/progressbar.cpp
ui/progressbar.h
ui/progressdialog.cpp
......
/*
ui/navigatabletreewidget.h
This file is part of libkleopatra
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config-libkleo.h>
#include "navigatabletreewidget.h"
using namespace Kleo;
QModelIndex NavigatableTreeWidget::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
{
// make keyboard navigation with Left/Right possible by switching the selection behavior to SelectItems
// before calling QTreeWidget::moveCursor, because QTreeWidget::moveCursor ignores MoveLeft/MoveRight
// if the selection behavior is SelectRows
if ((cursorAction == MoveLeft) || (cursorAction == MoveRight)) {
setSelectionBehavior(SelectItems);
}
const auto result = QTreeWidget::moveCursor(cursorAction, modifiers);
if ((cursorAction == MoveLeft) || (cursorAction == MoveRight)) {
setSelectionBehavior(SelectRows);
}
return result;
}
/*
ui/navigatabletreewidget.h
This file is part of libkleopatra
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include "kleo_export.h"
#include <QTreeWidget>
namespace Kleo
{
/**
* A tree view that allows extended keyboard navigation.
*
* The NavigatableTreeWidget allows column by column keyboard navigation even if
* the selection behavior is set to SelectRows. Column by column navigation is
* required to make a tree view accessible.
*/
class KLEO_EXPORT NavigatableTreeWidget : public QTreeWidget
{
Q_OBJECT
public:
using QTreeWidget::QTreeWidget;
protected:
QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
};
}
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