1 /* -*- mode: c++; c-basic-offset:4 -*-
2     view/tabwidget.h
3 
4     This file is part of Kleopatra, the KDE keymanager
5     SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
6 
7     SPDX-License-Identifier: GPL-2.0-or-later
8 */
9 
10 #pragma once
11 
12 #include <QWidget>
13 
14 #include <memory>
15 #include <vector>
16 
17 #include <utils/pimpl_ptr.h>
18 
19 
20 class QAbstractItemView;
21 
22 class KConfigGroup;
23 class KActionCollection;
24 class KConfig;
25 
26 namespace Kleo
27 {
28 
29 class AbstractKeyListModel;
30 class AbstractKeyListSortFilterProxyModel;
31 class KeyFilter;
32 class KeyListModelInterface;
33 
34 class TabWidget : public QWidget
35 {
36     Q_OBJECT
37 public:
38     explicit TabWidget(QWidget *parent = nullptr, Qt::WindowFlags f = {});
39     ~TabWidget() override;
40 
41     void setFlatModel(AbstractKeyListModel *model);
42     AbstractKeyListModel *flatModel() const;
43     void setHierarchicalModel(AbstractKeyListModel *model);
44     AbstractKeyListModel *hierarchicalModel() const;
45 
46     QAbstractItemView *addView(const QString &title = QString(), const QString &keyFilterID = QString(), const QString &searchString = QString());
47     QAbstractItemView *addView(const KConfigGroup &group);
48     QAbstractItemView *addTemporaryView(const QString &title = QString(), AbstractKeyListSortFilterProxyModel *proxy = nullptr, const QString &tabToolTip = QString());
49 
50     void loadViews(const KConfig *cfg);
51     void saveViews(KConfig *cfg) const;
52 
53     std::vector<QAbstractItemView *> views() const;
54     QAbstractItemView *currentView() const;
55     KeyListModelInterface *currentModel() const;
56 
57     unsigned int count() const;
58 
59     void createActions(KActionCollection *collection);
60     void connectSearchBar(QObject *sb);
61 
62     void setMultiSelection(bool on);
63 
64     QString stringFilter() const;
65 
66 public Q_SLOTS:
67     void setKeyFilter(const std::shared_ptr<Kleo::KeyFilter> &filter);
68     void setStringFilter(const QString &filter);
69 
70 Q_SIGNALS:
71     void viewAdded(QAbstractItemView *view);
72     void viewAboutToBeRemoved(QAbstractItemView *view);
73 
74     void currentViewChanged(QAbstractItemView *view);
75     void stringFilterChanged(const QString &filter);
76     void keyFilterChanged(const std::shared_ptr<Kleo::KeyFilter> &filter);
77 
78     void enableChangeStringFilter(bool enable);
79     void enableChangeKeyFilter(bool enable);
80 
81 private:
82     class Private;
83     kdtools::pimpl_ptr<Private> d;
84 
85     Q_PRIVATE_SLOT(d, void currentIndexChanged(int))
86     Q_PRIVATE_SLOT(d, void slotPageTitleChanged(const QString &))
87     Q_PRIVATE_SLOT(d, void slotPageKeyFilterChanged(const std::shared_ptr<Kleo::KeyFilter> &))
88     Q_PRIVATE_SLOT(d, void slotPageStringFilterChanged(const QString &))
89     Q_PRIVATE_SLOT(d, void slotPageHierarchyChanged(bool))
90     Q_PRIVATE_SLOT(d, void slotRenameCurrentTab())
91     Q_PRIVATE_SLOT(d, void slotNewTab())
92     Q_PRIVATE_SLOT(d, void slotDuplicateCurrentTab())
93     Q_PRIVATE_SLOT(d, void slotCloseCurrentTab())
94     Q_PRIVATE_SLOT(d, void slotMoveCurrentTabLeft())
95     Q_PRIVATE_SLOT(d, void slotMoveCurrentTabRight())
96     Q_PRIVATE_SLOT(d, void slotToggleHierarchicalView(bool))
97     Q_PRIVATE_SLOT(d, void slotExpandAll())
98     Q_PRIVATE_SLOT(d, void slotCollapseAll())
99 };
100 
101 }
102 
103