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

List:       kde-commits
Subject:    KDE/kdepim/kleopatra
From:       Marc Mutz <mutz () kde ! org>
Date:       2010-11-03 22:51:42
Message-ID: 20101103225142.30395AC8A0 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1192770 by mutz:

MainWindow: add a dynamically shown (as-you-type) SearchBar

The key filter selection doesn't really work (combobox)
but the string filter does.

Kudos go to Tobias for the twisted-brain approach to
SearchBar hiding :)

 M  +54 -1     mainwindow_mobile.cpp  
 M  +5 -0      mainwindow_mobile.h  
 M  +23 -1     qml/kleopatra-mobile.qml  


--- trunk/KDE/kdepim/kleopatra/mainwindow_mobile.cpp #1192769:1192770
@@ -39,8 +39,8 @@
 #include "models/keylistmodel.h"
 #include "models/keylistsortfilterproxymodel.h"
 
+#include "view/searchbar.h"
 #if 0
-#include "view/searchbar.h"
 #include "view/tabwidget.h"
 #endif
 #include "view/keytreeview.h"
@@ -76,6 +76,7 @@
 #include <KMessageBox>
 #include <KStandardGuiItem>
 #include <KStandardDirs>
+#include <KLineEdit>
 #if 0
 #include <KShortcutsDialog>
 #include <KEditToolBar>
@@ -135,6 +136,14 @@
     ~KeyTreeViewItem() {}
 };
 
+class MainWindow::SearchBarItem : public \
DeclarativeWidgetBase<SearchBar,MainWindow,&MainWindow::registerSearchBar> { +    \
Q_OBJECT +public:
+    explicit SearchBarItem( QGraphicsItem * parent=0 )
+        : DeclarativeWidgetBase<SearchBar,MainWindow,&MainWindow::registerSearchBar>( \
parent ) {} +    ~SearchBarItem() {}
+};
+
 static KGuiItem KStandardGuiItem_quit() {
     static const QString app = KGlobal::mainComponent().aboutData()->programName();
     KGuiItem item = KStandardGuiItem::quit();
@@ -219,6 +228,7 @@
     }
 
     void slotConfigCommitted();
+    void slotSearchBarTextChanged( const QString & );
 
     void aboutGpg4Win() {
         ( new KAboutApplicationDialog( aboutGpg4WinData(), \
KAboutApplicationDialog::HideKdeVersion|KAboutApplicationDialog::HideTranslators, q ) \
)->show(); @@ -226,18 +236,26 @@
 
 private:
     void setupActions();
+    void tryToConnectSearchBarToKeyTreeView() {
+        if ( searchBar && keyTreeView )
+            keyTreeView->connectSearchBar( searchBar );
+    }
 
     QAbstractItemView * currentView() const {
         return controller.currentView();
     }
 
 private:
+    QPointer<SearchBar> searchBar;
+    QPointer<KeyTreeView> keyTreeView;
     Kleo::KeyListController controller;
     bool firstShow : 1;
 };
 
 MainWindow::Private::Private( MainWindow * qq )
     : q( qq ),
+      searchBar(),
+      keyTreeView(),
       controller( q ),
       firstShow( true )
 {
@@ -287,6 +305,7 @@
 
 void MainWindow::delayedInit() {
     qmlRegisterType<KeyTreeViewItem>( "org.kde.kleopatra", 2, 1, "KeyTreeView" );
+    qmlRegisterType<SearchBarItem>  ( "org.kde.kleopatra", 2, 1, "SearchBar"   );
     KDeclarativeFullScreenView::delayedInit();
     d->setupActions();
     engine()->rootContext()->setContextProperty( "application", QVariant::fromValue( \
static_cast<QObject*>( this ) ) ); @@ -300,8 +319,20 @@
     QAbstractItemView * const v = view->view();
     d->controller.addView( v );
     d->controller.setCurrentView( v );
+    d->keyTreeView = view;
+    d->tryToConnectSearchBarToKeyTreeView();
 }
 
+void MainWindow::registerSearchBar( SearchBar * bar ) {
+    if ( !bar )
+        return;
+    d->searchBar = bar;
+    bar->setFixedHeight( 0 );
+    connect( bar,  SIGNAL(stringFilterChanged(QString)),
+             this, SLOT(slotSearchBarTextChanged(QString)) );
+    d->tryToConnectSearchBarToKeyTreeView();
+}
+
 void MainWindow::Private::slotConfigCommitted() {
     controller.updateConfig();
 }
@@ -337,10 +368,32 @@
     e->accept();
 }
 
+void MainWindow::keyPressEvent( QKeyEvent * e ) {
+    static bool isSendingEvent = false;
+
+    if ( !isSendingEvent && d->searchBar && !e->text().isEmpty() ) {
+        const struct guard { guard() { isSendingEvent = true; } ~guard() { \
isSendingEvent = false; } } guard; +        QCoreApplication::sendEvent( \
d->searchBar->lineEdit(), e ); +    } else {
+        KDeclarativeFullScreenView::keyPressEvent( e );
+    }
+}
+
 void MainWindow::importCertificatesFromFile( const QStringList & files ) {
     if ( !files.empty() )
         d->createAndStart<ImportCertificateFromFileCommand>( files );
 }
 
+void MainWindow::Private::slotSearchBarTextChanged( const QString & text ) {
+    if ( text.isEmpty() && searchBar && searchBar->isVisible() ) {
+        searchBar->setFixedHeight( 0 );
+        searchBar->hide();
+    } else if ( !text.isEmpty() && searchBar && !searchBar->isVisible() ) {
+        searchBar->setFixedHeight( searchBar->minimumSizeHint().height() );
+        searchBar->show();
+        searchBar->setFocus();
+    }
+}
+
 #include "moc_mainwindow_mobile.cpp"
 #include "mainwindow_mobile.moc"
--- trunk/KDE/kdepim/kleopatra/mainwindow_mobile.h #1192769:1192770
@@ -39,6 +39,7 @@
 
 namespace Kleo {
     class KeyTreeView;
+    class SearchBar;
 }
 
 class QStringList;
@@ -57,15 +58,19 @@
 
 protected:
     /* reimp */ void closeEvent( QCloseEvent * );
+    /* reimp */ void keyPressEvent( QKeyEvent * );
 
 private:
     void registerKeyTreeView( Kleo::KeyTreeView * view );
+    void registerSearchBar( Kleo::SearchBar * bar );
 
 private:
     Q_PRIVATE_SLOT( d, void configDialogRequested() )
     Q_PRIVATE_SLOT( d, void closeAndQuit() )
     Q_PRIVATE_SLOT( d, void selfTest() )
+    Q_PRIVATE_SLOT( d, void slotSearchBarTextChanged(QString) )
     class KeyTreeViewItem;
+    class SearchBarItem;
     class Private;
     kdtools::pimpl_ptr<Private> d;
 };
--- trunk/KDE/kdepim/kleopatra/qml/kleopatra-mobile.qml #1192769:1192770
@@ -38,11 +38,33 @@
 KPIM.MainView {
   id: kleopatraMobile;
 
+  QML.Rectangle {
+
+    anchors.fill : parent
+
   Kleo.KeyTreeView {
     id: keyTreeView
-    anchors.fill: parent
+
+      anchors.top    : parent.top
+      anchors.bottom : searchBar.top
+      anchors.left   : parent.left
+      anchors.right  : parent.right
   }
 
+    Kleo.SearchBar {
+      id : searchBar
+
+      anchors.bottom : parent.bottom
+      anchors.left   : parent.left
+      anchors.right  : parent.right
+
+      visible : false
+      height  : 0
+      y       : height == 0 ? parent.height : parent.height - height
+    }
+
+  }
+
   SlideoutPanelContainer {
     anchors.fill: parent
 


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

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