[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/apps/plasma/applets/folderview
From:       Shantanu Tushar Jha <jhahoneyk () gmail ! com>
Date:       2010-04-25 15:03:13
Message-ID: 20100425150313.3838BAC8A3 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1118646 by shantanu:

Add simple Type-and-Select feature.

BUG: 187241



 M  +32 -2     iconview.cpp  
 M  +2 -0      iconview.h  


--- trunk/KDE/kdebase/apps/plasma/applets/folderview/iconview.cpp \
#1118645:1118646 @@ -1669,6 +1669,30 @@
 
     QModelIndex currentIndex = m_selectionModel->currentIndex();
 
+    bool sameKeyWasPressed = m_searchQuery.endsWith(event->text());
+    m_searchQuery.append(event->text());
+    m_searchQueryTimer.start(2000, this);   //clears search query when the \
user doesn't press any key +
+    // First try to match the exact icon string
+    QModelIndexList matches = m_model->match(currentIndex, \
Qt::DisplayRole, m_searchQuery, +                                           \
1, Qt::MatchFixedString | Qt::MatchWrap); +
+    if (matches.count()<=0) {
+        // Exact match failed, try matching the beginning of the icon \
string +        matches = m_model->match(currentIndex, Qt::DisplayRole, \
m_searchQuery, +                                             1, \
Qt::MatchStartsWith | Qt::MatchWrap); +
+        if (matches.count()<=0 && sameKeyWasPressed) {
+            // Didn't even match beginning, try next icon string starting \
with the same letter +            matches = \
m_model->match(currentIndex.sibling(currentIndex.row()+1, \
currentIndex.column()), +                                 Qt::DisplayRole, \
event->text(), 1, Qt::MatchStartsWith | Qt::MatchWrap); +        }
+    }
+
+    if (matches.count()>0) {
+            selectIcon(matches.at(0));
+    }
+
     switch (event->key()) {
     case Qt::Key_Home:
         selectFirstIcon();
@@ -2456,6 +2480,9 @@
 
 void IconView::selectIcon(QModelIndex index)
 {
+    if (!index.isValid()) {
+        return;
+    }
     repaintSelectedIcons();
     m_selectionModel->select(index, QItemSelectionModel::ClearAndSelect);
     m_selectionModel->setCurrentIndex(index, \
QItemSelectionModel::NoUpdate); @@ -2466,8 +2493,8 @@
 
 void IconView::selectFirstOrLastIcon(bool firstIcon)
 {
-    int minVertical;
-    int minHorizontal;
+    int minVertical=0;
+    int minHorizontal=0;
     int dirn=1;    //Useful in calculations as it stores whether view is \
                LeftToRight or RightToLeft
     int isFirst = firstIcon ? 1 : -1;    //Useful in calculations to \
decide whether to select First or Last icon  QModelIndex toSelect;
@@ -2651,6 +2678,9 @@
             connect(m_popupView, SIGNAL(requestClose()), \
SLOT(popupCloseRequested()));  m_popupIndex = m_hoveredIndex;
         }
+    } else if (event->timerId() == m_searchQueryTimer.timerId()) {
+        m_searchQuery.clear();
+        m_searchQueryTimer.stop();
     }
 }
 
--- trunk/KDE/kdebase/apps/plasma/applets/folderview/iconview.h \
#1118645:1118646 @@ -252,6 +252,7 @@
     QBasicTimer m_delayedRelayoutTimer;
     QBasicTimer m_delayedCacheClearTimer;
     QBasicTimer m_toolTipShowTimer;
+    QBasicTimer m_searchQueryTimer;
     ToolTipWidget *m_toolTipWidget;
     QPointer<PopupView> m_popupView;
     QPointer<QWidget> m_popupCausedWidget;
@@ -263,6 +264,7 @@
     Animator *m_animator;
     ActionOverlay *m_actionOverlay;
     QStringList m_popupPreviewPlugins;
+    QString m_searchQuery;
 };
 
 #endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic