File indexing completed on 2024-11-03 12:39:23

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 
0017 class KFileFilterComboPrivate;
0018 
0019 /**
0020  * @class KFileFilterCombo kfilefiltercombo.h <KFileFilterCombo>
0021  *
0022  * File filter combo box.
0023  */
0024 class KIOFILEWIDGETS_EXPORT KFileFilterCombo : public KComboBox
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     /**
0030      * Creates a new filter combo box.
0031      *
0032      * @param parent The parent widget.
0033      */
0034     explicit KFileFilterCombo(QWidget *parent = nullptr);
0035 
0036     /**
0037      * Destroys the filter combo box.
0038      */
0039     ~KFileFilterCombo() override;
0040 
0041     /**
0042      * Sets the @p filter string.
0043      */
0044     void setFilter(const QString &filter);
0045 
0046     /**
0047      * @returns the current filter, either something like "*.cpp *.h"
0048      * or the current MIME type, like "text/html", or a list of those, like
0049      " "text/html text/plain image/png", all separated with one space.
0050      */
0051     QString currentFilter() const;
0052 
0053     /**
0054      * Sets the current filter. Filter must match one of the filter items
0055      * passed before to this widget.
0056      */
0057     void setCurrentFilter(const QString &filter);
0058 
0059     /**
0060      * Sets a list of MIME types.
0061      * If @p defaultType is set, it will be set as the current item.
0062      * Otherwise, a first item showing all the MIME types will be created.
0063      */
0064     void setMimeFilter(const QStringList &types, const QString &defaultType);
0065 
0066     /**
0067      * @return true if the filter's first item is the list of all MIME types
0068      */
0069     bool showsAllTypes() const;
0070 
0071     /**
0072      * This method allows you to set a default-filter, that is used when an
0073      * empty filter is set. Make sure you call this before calling
0074      * setFilter().
0075      *
0076      * By default, this is set to i18n("*|All Files")
0077      * @see defaultFilter
0078      */
0079     void setDefaultFilter(const QString &filter);
0080 
0081     /**
0082      * @return the default filter, used when an empty filter is set.
0083      * @see setDefaultFilter
0084      */
0085     QString defaultFilter() const;
0086 
0087     /**
0088      * @return all filters (this can be a list of patterns or a list of MIME types)
0089      */
0090     QStringList filters() const;
0091 
0092     /**
0093      * Returns true if the filter has been set using setMimeFilter().
0094      * @since 4.6.1
0095      */
0096     bool isMimeFilter() const;
0097 
0098 protected:
0099     bool eventFilter(QObject *, QEvent *) override;
0100 
0101 Q_SIGNALS:
0102     /**
0103      * This signal is emitted whenever the filter has been changed.
0104      */
0105     void filterChanged();
0106 
0107 private:
0108     std::unique_ptr<KFileFilterComboPrivate> const d;
0109 };
0110 
0111 #endif