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

Add QTreeView-derived variant of NavigatableTreeWidget

GnuPG-bug-id: 6102
parent b5353e50
......@@ -133,6 +133,8 @@ target_sources(KF5Libkleo PRIVATE
ui/filenamerequester.h
ui/messagebox.cpp
ui/messagebox.h
ui/navigatabletreeview.cpp
ui/navigatabletreeview.h
ui/navigatabletreewidget.cpp
ui/navigatabletreewidget.h
ui/progressbar.cpp
......@@ -292,6 +294,7 @@ ecm_generate_headers(libkleo_CamelCase_ui_HEADERS
KeySelectionCombo
KeySelectionDialog
MessageBox
NavigatableTreeView
NavigatableTreeWidget
NewKeyApprovalDialog
ProgressDialog
......
/*
ui/navigatabletreeview.cpp
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 "navigatabletreeview.h"
using namespace Kleo;
QModelIndex NavigatableTreeView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
{
// make column by column keyboard navigation with Left/Right possible by switching
// the selection behavior to SelectItems before calling the parent class's moveCursor,
// because it ignores MoveLeft/MoveRight if the selection behavior is SelectRows;
// moreover, temporarily disable exanding of items to prevent expanding/collapsing
// on MoveLeft/MoveRight
if ((cursorAction != MoveLeft) && (cursorAction != MoveRight)) {
return QTreeView::moveCursor(cursorAction, modifiers);
}
const auto savedSelectionBehavior = selectionBehavior();
setSelectionBehavior(SelectItems);
const auto savedItemsExpandable = itemsExpandable();
setItemsExpandable(false);
const auto result = QTreeView::moveCursor(cursorAction, modifiers);
setItemsExpandable(savedItemsExpandable);
setSelectionBehavior(savedSelectionBehavior);
return result;
}
/*
ui/navigatabletreeview.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 <QTreeView>
namespace Kleo
{
/**
* A tree view that allows accessible column by column keyboard navigation.
*
* Column by column navigation is required to make a tree view accessible.
*
* The NavigatableTreeView allows column by column keyboard navigation even if
* the selection behavior is set to SelectRows and users can expand/collapse
* list items. To achieve this it deactivates the standard behavior of QTreeView
* to expand/collapse items if the left/right arrow keys are used.
*
* Additionally, you may want to disable parent-child navigation in tree views
* with left/right arrow keys because this also interferes with column by column
* navigation. You can do this by setting
* "QTreeView { arrow-keys-navigate-into-children: 0; }"
* as application style sheet.
*
* \sa NavigatableTreeWidget
*/
class KLEO_EXPORT NavigatableTreeView : public QTreeView
{
Q_OBJECT
public:
using QTreeView::QTreeView;
protected:
QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
};
}
......@@ -18,11 +18,11 @@ namespace Kleo
{
/**
* A tree view that allows extended keyboard navigation.
* A tree widget that allows accessible column by column 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.
* This is the QTreeWidget-derived variant of NavigatableTreeView.
*
* \sa NavigatableTreeView
*/
class KLEO_EXPORT NavigatableTreeWidget : public QTreeWidget
{
......
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