From d89901852c49593c448c895683730c711957dd39 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 15 Feb 2009 00:32:10 +0000 Subject: [PATCH] introduce a SearchLineWidget, which is a SearchLineEdit + AnimatedWidget this small widget is useful for providing a search line edit with an animated widget next to it, with the latter shown while the search is in progress currently, the animation is slightly delayed, so we avoid very quick results (ie the next occurrence is on the same page) to show the animation for a very short time svn path=/trunk/KDE/kdegraphics/okular/; revision=926299 --- ui/searchlineedit.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ ui/searchlineedit.h | 19 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/ui/searchlineedit.cpp b/ui/searchlineedit.cpp index 732126eb4..e058b487a 100644 --- a/ui/searchlineedit.cpp +++ b/ui/searchlineedit.cpp @@ -11,10 +11,12 @@ #include "searchlineedit.h" // local includes +#include "animatedwidget.h" #include "core/document.h" // qt/kde includes #include +#include #include #include @@ -189,4 +191,42 @@ void SearchLineEdit::searchFinished( int id, Okular::Document::SearchStatus endS emit searchStopped(); } + +SearchLineWidget::SearchLineWidget( QWidget * parent, Okular::Document * document ) + : QWidget( parent ) +{ + QHBoxLayout *layout = new QHBoxLayout( this ); + layout->setMargin( 0 ); + + m_edit = new SearchLineEdit( this, document ); + layout->addWidget( m_edit ); + + m_anim = new AnimatedWidget( "process-working", this ); + m_anim->setFixedSize( 22, 22 ); + layout->addWidget( m_anim ); + + m_timer = new QTimer( this ); + m_timer->setSingleShot( true ); + connect( m_timer, SIGNAL( timeout() ), m_anim, SLOT( start() ) ); + + connect( m_edit, SIGNAL( searchStarted() ), this, SLOT( slotSearchStarted() ) ); + connect( m_edit, SIGNAL( searchStopped() ), this, SLOT( slotSearchStopped() ) ); +} + +SearchLineEdit* SearchLineWidget::lineEdit() const +{ + return m_edit; +} + +void SearchLineWidget::slotSearchStarted() +{ + m_timer->start( 100 ); +} + +void SearchLineWidget::slotSearchStopped() +{ + m_timer->stop(); + m_anim->stop(); +} + #include "searchlineedit.moc" diff --git a/ui/searchlineedit.h b/ui/searchlineedit.h index 81035f974..1710da63b 100644 --- a/ui/searchlineedit.h +++ b/ui/searchlineedit.h @@ -16,6 +16,7 @@ #include class QTimer; +class AnimatedWidget; /** * @short A line edit for find-as-you-type search. Outputs to the Document. @@ -63,4 +64,22 @@ class SearchLineEdit : public KLineEdit void searchFinished( int id, Okular::Document::SearchStatus endStatus ); }; +class SearchLineWidget : public QWidget +{ + Q_OBJECT + public: + SearchLineWidget( QWidget *parent, Okular::Document *document ); + + SearchLineEdit* lineEdit() const; + + private slots: + void slotSearchStarted(); + void slotSearchStopped(); + + private: + SearchLineEdit *m_edit; + AnimatedWidget* m_anim; + QTimer *m_timer; +}; + #endif