From afca8efa2601d9566c8d34d7b67dfb5abc729956 Mon Sep 17 00:00:00 2001 From: Tirtha Chatterjee Date: Mon, 29 Aug 2011 04:12:05 +0530 Subject: Added support for highlighting items by typing their name on the keyboard. --- src/kitemviews/kfileitemmodel.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/kitemviews/kfileitemmodel.cpp') diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index f36ab8380..c2f49f705 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -124,6 +124,24 @@ bool KFileItemModel::setData(int index, const QHash& value return false; } +int KFileItemModel::indexForKeyboardSearch(const QString& text, int startFromIndex) const +{ + startFromIndex = qMax(0, startFromIndex); + for (int i = startFromIndex; i < count(); i++) { + if (data(i)["name"].toString().startsWith(text, Qt::CaseInsensitive)) { + kDebug() << data(i)["name"].toString(); + return i; + } + } + for (int i = 0; i < startFromIndex; i++) { + if (data(i)["name"].toString().startsWith(text, Qt::CaseInsensitive)) { + kDebug() << data(i)["name"].toString(); + return i; + } + } + return -1; +} + bool KFileItemModel::supportsGrouping() const { return true; -- cgit v1.3