1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: Stephan Kulow <coolo@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef KFILEFILTERCOMBO_H |
9 | #define KFILEFILTERCOMBO_H |
10 | |
11 | #include "kiofilewidgets_export.h" |
12 | |
13 | #include <QStringList> |
14 | |
15 | #include <KComboBox> |
16 | #include <KFileFilter> |
17 | |
18 | class KFileFilterComboPrivate; |
19 | |
20 | /*! |
21 | * \class KFileFilterCombo |
22 | * \inmodule KIOFileWidgets |
23 | * |
24 | * \brief File filter combo box. |
25 | */ |
26 | class KIOFILEWIDGETS_EXPORT KFileFilterCombo : public KComboBox |
27 | { |
28 | Q_OBJECT |
29 | |
30 | public: |
31 | /*! |
32 | * Creates a new filter combo box. |
33 | * |
34 | * \a parent The parent widget. |
35 | */ |
36 | explicit KFileFilterCombo(QWidget *parent = nullptr); |
37 | |
38 | ~KFileFilterCombo() override; |
39 | |
40 | /*! |
41 | * Sets the filters to be used. |
42 | * |
43 | * \a filters each item in the list corresponds to one item in the combobox. |
44 | * Entries for "All files" and "All supported files" are added automatically as needed. |
45 | * |
46 | * \a defaultFilter if not empty this will be the by default active filter |
47 | * |
48 | * \since 6.0 |
49 | * |
50 | */ |
51 | void setFilters(const QList<KFileFilter> &filters, const KFileFilter &defaultFilter = KFileFilter()); |
52 | |
53 | /*! |
54 | * The currently selected/active filter. |
55 | * |
56 | * \since 6.0 |
57 | */ |
58 | KFileFilter currentFilter() const; |
59 | |
60 | /*! |
61 | * The current filters. |
62 | * |
63 | * This is not necessarily the same as the list set by setFileFilters() since |
64 | * entries for "All files" and "All supported files" are added automatically as needed. |
65 | * |
66 | * \since 6.0 |
67 | */ |
68 | QList<KFileFilter> filters() const; |
69 | |
70 | /*! |
71 | * This method allows to set a default-filter, that is used when an |
72 | * empty filter is set. Make sure you call this before calling |
73 | * setFileFilter(). |
74 | * |
75 | * By default, this is set to match all files. |
76 | * \sa defaultFilter |
77 | * |
78 | * \since 6.0 |
79 | */ |
80 | void setDefaultFilter(const KFileFilter &filter); |
81 | |
82 | /*! |
83 | * Returns the default filter, used when an empty filter is set. |
84 | * \sa setDefaultFilter |
85 | * |
86 | * \since 6.0 |
87 | */ |
88 | KFileFilter defaultFilter() const; |
89 | |
90 | /*! |
91 | * Sets the current filter. Filter must match one of the filter items |
92 | * passed before to this widget. |
93 | * |
94 | * \since 6.0 |
95 | */ |
96 | void setCurrentFilter(const KFileFilter &filter); |
97 | |
98 | /*! |
99 | * Returns true if the filter's first item is the list of all MIME types |
100 | */ |
101 | bool showsAllTypes() const; |
102 | |
103 | protected: |
104 | bool eventFilter(QObject *, QEvent *) override; |
105 | |
106 | Q_SIGNALS: |
107 | /*! |
108 | * This signal is emitted whenever the filter has been changed. |
109 | */ |
110 | void filterChanged(); |
111 | |
112 | private: |
113 | std::unique_ptr<KFileFilterComboPrivate> const d; |
114 | }; |
115 | |
116 | #endif |
117 | |