Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
libkleo
Commits
509b1236
Commit
509b1236
authored
Jul 28, 2022
by
Ingo Klöcker
Browse files
Add QTreeView-derived variant of NavigatableTreeWidget
GnuPG-bug-id: 6102
parent
b5353e50
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/CMakeLists.txt
View file @
509b1236
...
...
@@ -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
...
...
src/ui/navigatabletreeview.cpp
0 → 100644
View file @
509b1236
/*
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
;
}
src/ui/navigatabletreeview.h
0 → 100644
View file @
509b1236
/*
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
;
};
}
src/ui/navigatabletreewidget.h
View file @
509b1236
...
...
@@ -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.
*
* Th
e 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 t
ree
v
iew
accessible.
* Th
is is the QTreeWidget-derived variant of NavigatableTreeView.
*
*
\sa NavigatableT
ree
V
iew
*/
class
KLEO_EXPORT
NavigatableTreeWidget
:
public
QTreeWidget
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment