26 #include <QtCore/QEvent> 27 #include <QtGui/QLineEdit> 29 class KFileFilterCombo::Private
34 hasAllSupportedFiles(false),
40 void _k_slotFilterChanged();
47 bool hasAllSupportedFiles;
53 QStringList m_filters;
58 :
KComboBox(true, parent), d( new Private(this) )
61 setInsertPolicy(QComboBox::NoInsert);
62 connect(
this, SIGNAL(activated(
int)),
this, SIGNAL(
filterChanged()));
64 connect(
this, SIGNAL(
filterChanged()), SLOT(_k_slotFilterChanged()));
65 d->m_allTypes =
false;
77 d->hasAllSupportedFiles =
false;
79 if (!filter.isEmpty()) {
81 int index = tmp.indexOf(
'\n');
83 d->m_filters.append(tmp.left(index));
84 tmp = tmp.mid(index + 1);
85 index = tmp.indexOf(
'\n');
87 d->m_filters.append(tmp);
90 d->m_filters.append( d->defaultFilter );
92 QStringList::ConstIterator it;
93 QStringList::ConstIterator
end(d->m_filters.constEnd());
94 for (it = d->m_filters.constBegin(); it !=
end; ++it) {
95 int tab = (*it).indexOf(
'|');
96 addItem((tab < 0) ? *it :
100 d->lastFilter = currentText();
101 d->isMimeFilter =
false;
106 QString f = currentText();
107 if (f == itemText(currentIndex())) {
108 f = d->m_filters.value(currentIndex());
109 if ( d->isMimeFilter || (currentIndex() == 0 && d->hasAllSupportedFiles) ) {
114 int tab = f.indexOf(
'|');
123 return d->m_allTypes;
133 setCurrentIndex(d->m_filters.indexOf(filter));
138 const QString& defaultType )
141 d->m_filters.clear();
142 QString delim = QLatin1String(
", ");
143 d->hasAllSupportedFiles =
false;
144 bool hasAllFilesFilter =
false;
146 d->m_allTypes = defaultType.isEmpty() && (types.count() > 1);
148 QString allComments, allTypes;
149 for(QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
159 if ( type->
name().startsWith( QLatin1String(
"all/" ) ) ) {
160 hasAllFilesFilter =
true;
164 if ( d->m_allTypes && it != types.begin() ) {
165 allComments += delim;
169 d->m_filters.append( type->
name() );
172 allTypes += type->
name();
173 allComments += type->
comment();
176 if ( type->
name() == defaultType )
177 setCurrentIndex( count() - 1 );
183 insertItem(0, allComments);
185 insertItem(0,
i18n(
"All Supported Files"));
186 d->hasAllSupportedFiles =
true;
188 setCurrentIndex( 0 );
190 d->m_filters.prepend( allTypes );
193 if ( hasAllFilesFilter ) {
194 addItem(
i18n(
"All Files"));
195 d->m_filters.append( QLatin1String(
"all/allfiles") );
198 d->lastFilter = currentText();
199 d->isMimeFilter =
true;
202 void KFileFilterCombo::Private::_k_slotFilterChanged()
204 lastFilter = parent->currentText();
209 if ( o == lineEdit() && e->type() == QEvent::FocusOut ) {
210 if ( currentText() != d->lastFilter )
219 d->defaultFilter = filter;
224 return d->defaultFilter;
229 return d->isMimeFilter;
232 #include "kfilefiltercombo.moc" bool showsAllTypes() const
QString i18n(const char *text)
QStringList filters() const
void setFilter(const QString &filter)
Sets the filter string.
void setCurrentFilter(const QString &filter)
Sets the current filter.
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QString comment(const KUrl &url=KUrl()) const
KFileFilterCombo(QWidget *parent=0)
Creates a new filter combo box.
QString defaultFilter() const
~KFileFilterCombo()
Destroys the filter combo box.
void filterChanged()
This signal is emitted whenever the filter has been changed.
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
bool isMimeFilter() const
Returns true if the filter has been set using setMimeFilter().
void setTrapReturnKey(bool trap)
virtual bool eventFilter(QObject *, QEvent *)
void setMimeFilter(const QStringList &types, const QString &defaultType)
Sets a list of mimetypes.
static Ptr mimeType(const QString &name, FindByNameOption options=ResolveAliases)
void setDefaultFilter(const QString &filter)
This method allows you to set a default-filter, that is used when an empty filter is set...
virtual bool eventFilter(QObject *, QEvent *)
QString currentFilter() const