Libkleo

keylistview.h
1/*
2 keylistview.h
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#pragma once
11
12#include "kleo_export.h"
13
14#include "treewidget.h"
15
16#include <QByteArray>
17#include <QHeaderView>
18#include <QIcon>
19
20#include <gpgme++/key.h>
21
22class QFont;
23class QColor;
24
25namespace Kleo
26{
27
28// work around moc parser bug...
29#define TEMPLATE_TYPENAME(T) template<typename T>
30TEMPLATE_TYPENAME(T)
31inline T *lvi_cast(QTreeWidgetItem *item)
32{
33 return item && (item->type() == T::RTTI) ? static_cast<T *>(item) : nullptr;
34}
35
36TEMPLATE_TYPENAME(T)
37inline const T *lvi_cast(const QTreeWidgetItem *item)
38{
39 return item && (item->type() == T::RTTI) ? static_cast<const T *>(item) : nullptr;
40}
41#undef TEMPLATE_TYPENAME
42
43class KeyListView;
44
45class KeyListViewItem : public QTreeWidgetItem
46{
47public:
48 KeyListViewItem(KeyListView *parent, const GpgME::Key &key);
49 KeyListViewItem(KeyListView *parent, KeyListViewItem *after, const GpgME::Key &key);
50 KeyListViewItem(KeyListViewItem *parent, const GpgME::Key &key);
51 KeyListViewItem(KeyListViewItem *parent, KeyListViewItem *after, const GpgME::Key &key);
52 ~KeyListViewItem() override;
53
54 void setKey(const GpgME::Key &key);
55 const GpgME::Key &key() const
56 {
57 return mKey;
58 }
59
60 enum { RTTI = QTreeWidgetItem::UserType + 1 };
61
62 //
63 // only boring stuff below:
64 //
65 virtual QString toolTip(int column) const;
66
67 /*! \reimp for covariant return */
68 KeyListView *listView() const;
69 /*! \reimp for covariant return */
70 KeyListViewItem *nextSibling() const;
71 /*! \reimp */
72 bool operator<(const QTreeWidgetItem &other) const override;
73 /*! \reimp */
74 void takeItem(QTreeWidgetItem *item);
75
76private:
77 GpgME::Key mKey;
78};
79
80class KLEO_EXPORT KeyListView : public TreeWidget
81{
82 Q_OBJECT
83 friend class KeyListViewItem;
84
85public:
86 class KLEO_EXPORT ColumnStrategy
87 {
88 public:
89 virtual ~ColumnStrategy();
90 virtual QString title(int column) const = 0;
91 virtual int width(int column, const QFontMetrics &fm) const;
92 virtual QHeaderView::ResizeMode resizeMode(int) const
93 {
95 }
96
97 virtual QString text(const GpgME::Key &key, int column) const = 0;
98 virtual QString accessibleText(const GpgME::Key &key, int column) const = 0;
99 virtual QString toolTip(const GpgME::Key &key, int column) const;
100 virtual QIcon icon(const GpgME::Key &, int) const
101 {
102 return QIcon();
103 }
104 virtual int compare(const GpgME::Key &key1, const GpgME::Key &key2, const int column) const;
105 };
106
107 class KLEO_EXPORT DisplayStrategy
108 {
109 public:
110 virtual ~DisplayStrategy();
111 // font
112 virtual QFont keyFont(const GpgME::Key &, const QFont &) const;
113 // foreground
114 virtual QColor keyForeground(const GpgME::Key &, const QColor &) const;
115 // background
116 virtual QColor keyBackground(const GpgME::Key &, const QColor &) const;
117 };
118
119 explicit KeyListView(const ColumnStrategy *strategy, const DisplayStrategy *display = nullptr, QWidget *parent = nullptr, Qt::WindowFlags f = {});
120
121 ~KeyListView() override;
122
123 const ColumnStrategy *columnStrategy() const
124 {
125 return mColumnStrategy;
126 }
127 const DisplayStrategy *displayStrategy() const
128 {
129 return mDisplayStrategy;
130 }
131
132 bool hierarchical() const
133 {
134 return mHierarchical;
135 }
136 virtual void setHierarchical(bool hier);
137
138 void flushKeys()
139 {
140 slotUpdateTimeout();
141 }
142
143 bool isMultiSelection() const;
144
145 KeyListViewItem *itemByFingerprint(const QByteArray &) const;
146
147public:
148 using QTreeWidget::selectionChanged; // for below, but moc doesn't like it to be in the Q_SIGNALS: section
149Q_SIGNALS:
150 void doubleClicked(Kleo::KeyListViewItem *, int);
151 void returnPressed(Kleo::KeyListViewItem *);
152 void selectionChanged(Kleo::KeyListViewItem *);
153 void contextMenu(Kleo::KeyListViewItem *, const QPoint &);
154
155protected:
156 void keyPressEvent(QKeyEvent *event) override;
157
158public Q_SLOTS:
159 virtual void slotAddKey(const GpgME::Key &key);
160 virtual void slotRefreshKey(const GpgME::Key &key);
161
162 //
163 // Only boring stuff below:
164 //
165private Q_SLOTS:
166 void slotEmitDoubleClicked(QTreeWidgetItem *, int);
167 void slotEmitReturnPressed(QTreeWidgetItem *);
168 void slotEmitSelectionChanged();
169 void slotEmitContextMenu(const QPoint &pos);
170 void slotUpdateTimeout();
171
172public:
173 /*! \reimp for covariant return */
174 KeyListViewItem *selectedItem() const;
175 /*! \reimp */
176 QList<KeyListViewItem *> selectedItems() const;
177 /*! \reimp for covariant return */
178 KeyListViewItem *firstChild() const;
179 /*! \reimp */
180 void clear();
181 /*! \reimp */
182 void takeItem(QTreeWidgetItem *);
183
184private:
185 void doHierarchicalInsert(const GpgME::Key &);
186 void gatherScattered();
187 void scatterGathered(KeyListViewItem *);
188 void registerItem(KeyListViewItem *);
189 void deregisterItem(const KeyListViewItem *);
190
191private:
192 const ColumnStrategy *mColumnStrategy = nullptr;
193 const DisplayStrategy *mDisplayStrategy = nullptr;
194 bool mHierarchical = false;
195
196 class KeyListViewPrivate;
197 std::unique_ptr<KeyListViewPrivate> const d;
198};
199}
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
typedef WindowFlags
QTreeWidgetItem * parent() const const
int type() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.