File indexing completed on 2024-05-05 07:56:49
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: Stephan Kulow <coolo@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KFILEFILTERCOMBO_H 0009 #define KFILEFILTERCOMBO_H 0010 0011 #include "kiofilewidgets_export.h" 0012 0013 #include <QStringList> 0014 0015 #include <KComboBox> 0016 #include <KFileFilter> 0017 0018 class KFileFilterComboPrivate; 0019 0020 /** 0021 * @class KFileFilterCombo kfilefiltercombo.h <KFileFilterCombo> 0022 * 0023 * File filter combo box. 0024 */ 0025 class KIOFILEWIDGETS_EXPORT KFileFilterCombo : public KComboBox 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 /** 0031 * Creates a new filter combo box. 0032 * 0033 * @param parent The parent widget. 0034 */ 0035 explicit KFileFilterCombo(QWidget *parent = nullptr); 0036 0037 /** 0038 * Destroys the filter combo box. 0039 */ 0040 ~KFileFilterCombo() override; 0041 0042 /** 0043 * Sets the filters to be used. 0044 * 0045 * @param filters each item in the list corresponds to one item in the combobox. 0046 * Entries for "All files" and "All supported files" are added automatically as needed. 0047 * 0048 * @param defaultFilter if not empty this will be the by default active filter 0049 * 0050 * @since 6.0 0051 * 0052 */ 0053 void setFilters(const QList<KFileFilter> &filters, const KFileFilter &defaultFilter = KFileFilter()); 0054 0055 /** 0056 * The currently selected/active filter. 0057 * 0058 * @since 6.0 0059 */ 0060 KFileFilter currentFilter() const; 0061 0062 /** 0063 * The current filters. 0064 * 0065 * This is not necessarily the same as the list set by setFileFilters() since 0066 * entries for "All files" and "All supported files" are added automatically as needed. 0067 * 0068 * @since 6.0 0069 */ 0070 QList<KFileFilter> filters() const; 0071 0072 /** 0073 * This method allows to set a default-filter, that is used when an 0074 * empty filter is set. Make sure you call this before calling 0075 * setFileFilter(). 0076 * 0077 * By default, this is set to match all files. 0078 * @see defaultFileFilter 0079 * 0080 * @since 6.0 0081 */ 0082 void setDefaultFilter(const KFileFilter &filter); 0083 0084 /** 0085 * @return the default filter, used when an empty filter is set. 0086 * @see setDefaultFileFilter 0087 * 0088 * @since 6.0 0089 */ 0090 KFileFilter defaultFilter() const; 0091 0092 /** 0093 * Sets the current filter. Filter must match one of the filter items 0094 * passed before to this widget. 0095 * 0096 * @since 6.0 0097 */ 0098 void setCurrentFilter(const KFileFilter &filter); 0099 0100 /** 0101 * @return true if the filter's first item is the list of all MIME types 0102 */ 0103 bool showsAllTypes() const; 0104 0105 protected: 0106 bool eventFilter(QObject *, QEvent *) override; 0107 0108 Q_SIGNALS: 0109 /** 0110 * This signal is emitted whenever the filter has been changed. 0111 */ 0112 void filterChanged(); 0113 0114 private: 0115 std::unique_ptr<KFileFilterComboPrivate> const d; 0116 }; 0117 0118 #endif