From ea40295e233db219dc2431960e18fb4398ddb75c Mon Sep 17 00:00:00 2001 From: zautrix Date: Sun, 10 Oct 2004 23:26:49 +0000 Subject: added better searching in kapi --- (limited to 'kaddressbook') diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp index 3533427..78eaf65 100644 --- a/kaddressbook/incsearchwidget.cpp +++ b/kaddressbook/incsearchwidget.cpp @@ -81,6 +81,12 @@ IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name ) connect( mFieldCombo, SIGNAL( activated( const QString& ) ), SLOT( announceFieldChanged() ) ); + + + connect( mSearchText, SIGNAL( scrollUP() ), this, SIGNAL( scrollUP() )); + connect( mSearchText, SIGNAL( scrollDOWN() ), this, SIGNAL( scrollDOWN() )); + + setFocusProxy( mSearchText ); } @@ -96,7 +102,7 @@ void IncSearchWidget::announceDoSearch2() //qDebug("emit dosreach "); } -void IncSearchWidget::announceDoSearch() +void IncSearchWidget::announceDoSearch() { emit doSearch( mSearchText->text() ); diff --git a/kaddressbook/incsearchwidget.h b/kaddressbook/incsearchwidget.h index 5c95438..1546a51 100644 --- a/kaddressbook/incsearchwidget.h +++ b/kaddressbook/incsearchwidget.h @@ -48,6 +48,8 @@ class IncSearchWidget : public QWidget int currentItem() const; signals: + void scrollUP(); + void scrollDOWN(); /** This signal is emmited whenever the text in the input widget is changed. You can get the sorting field by diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index cd261f6..f2d4cd6 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -1673,7 +1673,8 @@ void KABCore::initGUI() // mIncSearchWidget->hide(); connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); - + connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); + connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); mJumpButtonBar = new JumpButtonBar( this, this ); diff --git a/kaddressbook/kaddressbookview.h b/kaddressbook/kaddressbookview.h index 17106e8..c134e96 100644 --- a/kaddressbook/kaddressbookview.h +++ b/kaddressbook/kaddressbookview.h @@ -65,6 +65,8 @@ class KAddressBookView : public QWidget */ virtual QStringList selectedUids() = 0; virtual void doSearch( const QString& s ,KABC::Field *field ) = 0; + virtual void scrollUP() = 0; + virtual void scrollDOWN() = 0; /** Called whenever this view should read the config. This can be used diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp index c6baeac..f4fb08b 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp @@ -85,7 +85,16 @@ ViewManager::~ViewManager() unloadViews(); mViewFactoryDict.clear(); } - +void ViewManager::scrollUP() +{ + if ( mActiveView ) + mActiveView->scrollUP(); +} +void ViewManager::scrollDOWN() +{ + if ( mActiveView ) + mActiveView->scrollDOWN(); +} void ViewManager::restoreSettings() { mViewNameList = KABPrefs::instance()->mViewNames; diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h index 6def6b6..585f4e9 100644 --- a/kaddressbook/viewmanager.h +++ b/kaddressbook/viewmanager.h @@ -66,6 +66,8 @@ class ViewManager : public QWidget void setListSelected(QStringList); public slots: + void scrollUP(); + void scrollDOWN(); //US void setSelected( const QString &uid = QString::null, bool selected = true ); void setSelected( const QString &uid, bool); diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp index 4babf67..a7bf6c9 100644 --- a/kaddressbook/views/kaddressbookcardview.cpp +++ b/kaddressbook/views/kaddressbookcardview.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -169,6 +170,17 @@ KAddressBookCardView::~KAddressBookCardView() { } +void KAddressBookCardView::scrollUP() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); + QApplication::postEvent( mCardView, ev ); + +} +void KAddressBookCardView::scrollDOWN() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); + QApplication::postEvent( mCardView, ev ); +} void KAddressBookCardView::readConfig(KConfig *config) { KAddressBookView::readConfig(config); @@ -290,8 +302,12 @@ void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) } mCardView->viewport()->setUpdatesEnabled( true ); mCardView->viewport()->update(); - // by default nothing is selected - emit selected(QString::null); + if ( mCardView->firstItem() ) { + mCardView->setCurrentItem ( mCardView->firstItem() ); + mCardView->setSelected ( mCardView->firstItem() , true ); + } + else + emit selected(QString::null); } QStringList KAddressBookCardView::selectedUids() { diff --git a/kaddressbook/views/kaddressbookcardview.h b/kaddressbook/views/kaddressbookcardview.h index b8efb01..45a9781 100644 --- a/kaddressbook/views/kaddressbookcardview.h +++ b/kaddressbook/views/kaddressbookcardview.h @@ -60,6 +60,8 @@ class KAddressBookCardView : public KAddressBookView virtual void readConfig(KConfig *config); virtual void writeConfig(KConfig *); + virtual void scrollUP(); + virtual void scrollDOWN(); public slots: void refresh(QString uid = QString::null); diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp index fdc0db9..f4c68b8 100644 --- a/kaddressbook/views/kaddressbookiconview.cpp +++ b/kaddressbook/views/kaddressbookiconview.cpp @@ -41,6 +41,7 @@ #include "kaddressbookiconview.h" #include #include +#include #include /*US transfered to the headerfile class IconViewFactory : public ViewFactory @@ -211,6 +212,16 @@ KAddressBookIconView::~KAddressBookIconView() { } +void KAddressBookIconView::scrollUP() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); + QApplication::postEvent( mIconView, ev ); +} +void KAddressBookIconView::scrollDOWN() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); + QApplication::postEvent( mIconView, ev ); +} void KAddressBookIconView::readConfig(KConfig *config) { KAddressBookView::readConfig(config); @@ -280,6 +291,12 @@ void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field ) } } mIconView->arrangeItemsInGrid( true ); + if ( mIconView->firstItem() ) { + mIconView->setCurrentItem ( mIconView->firstItem() ); + mIconView->setSelected ( mIconView->firstItem() , true ); + } + else + emit selected(QString::null); } QStringList KAddressBookIconView::selectedUids() { diff --git a/kaddressbook/views/kaddressbookiconview.h b/kaddressbook/views/kaddressbookiconview.h index 963ee7c..acfcd71 100644 --- a/kaddressbook/views/kaddressbookiconview.h +++ b/kaddressbook/views/kaddressbookiconview.h @@ -61,6 +61,8 @@ class KAddressBookIconView : public KAddressBookView void doSearch( const QString& s ,KABC::Field *field ); virtual void readConfig(KConfig *config); + virtual void scrollUP(); + virtual void scrollDOWN(); public slots: void refresh(QString uid = QString::null); diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index fbfddba..2412170 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp @@ -51,7 +51,16 @@ KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, KAddressBookTableView::~KAddressBookTableView() { } - +void KAddressBookTableView::scrollUP() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); + QApplication::postEvent( mListView, ev ); +} +void KAddressBookTableView::scrollDOWN() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); + QApplication::postEvent( mListView, ev ); +} void KAddressBookTableView::reconstructListView() { if (mListView) @@ -159,7 +168,12 @@ void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field ) // Sometimes the background pixmap gets messed up when we add lots // of items. mListView->repaint(); - emit selected(QString::null); + if ( mListView->firstChild() ) { + mListView->setCurrentItem ( mListView->firstChild() ); + mListView->setSelected ( mListView->firstChild(), true ); + } + else + emit selected(QString::null); } void KAddressBookTableView::writeConfig(KConfig *config) diff --git a/kaddressbook/views/kaddressbooktableview.h b/kaddressbook/views/kaddressbooktableview.h index ecfe7a1..865f8d5 100644 --- a/kaddressbook/views/kaddressbooktableview.h +++ b/kaddressbook/views/kaddressbooktableview.h @@ -63,6 +63,8 @@ friend class ContactListView; virtual void writeConfig(KConfig *config); virtual QString type() const { return "Table"; } void doSearch( const QString& s ,KABC::Field *field ); + virtual void scrollUP(); + virtual void scrollDOWN(); public slots: virtual void reconstructListView(); -- cgit v0.9.0.2