Commit 6511b292 authored by Aaron J. Seigo's avatar Aaron J. Seigo
Browse files

don't search after every single key press as that tends to freeze the gui

up nice and solid when viewing large PDFs, even on fast machines. instead
search after the user has paused typing

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=372580
parent 05924776
......@@ -10,6 +10,7 @@
// qt/kde includes
#include <qtooltip.h>
#include <qapplication.h>
#include <qtimer.h>
#include <kaction.h>
#include <kactioncollection.h>
#include <klocale.h>
......@@ -38,8 +39,13 @@ SearchWidget::SearchWidget( QWidget * parent, KPDFDocument * document )
setIconSize( 16 );
setMovingEnabled( false );
// a timer to ensure that we don't flood the document with requests to search
m_inputDelayTimer = new QTimer(this);
connect( m_inputDelayTimer, SIGNAL( timeout() ),
this, SLOT( startSearch() ) );
// line edit
insertLined( QString::null, LEDIT_ID, SIGNAL( textChanged(const QString &) ),
m_linedId = insertLined( QString::null, LEDIT_ID, SIGNAL( textChanged(const QString &) ),
this, SLOT( slotTextChanged(const QString &) ), true,
i18n( "Enter at least 3 letters to filter pages" ), 0/*size*/, 1 );
......@@ -70,6 +76,13 @@ void SearchWidget::slotTextChanged( const QString & text )
// if length<3 set 'red' text and send a blank string to document
QColor color = text.length() < 3 ? Qt::red : palette().active().text();
getLined( LEDIT_ID )->setPaletteForegroundColor( color );
m_inputDelayTimer->stop();
m_inputDelayTimer->start(333, true);
}
void SearchWidget::startSearch()
{
QString text = getLinedText(m_linedId);
m_document->findTextAll( text.length() < 3 ? QString::null : text, m_caseSensitive );
}
......
......@@ -14,6 +14,7 @@
class KPopupMenu;
class KPDFDocument;
class m_inputDelayTimer;
/**
* @short A widget for find-as-you-type search. Outputs to the Document.
......@@ -32,11 +33,14 @@ class SearchWidget : public KToolBar
private:
KPDFDocument * m_document;
KPopupMenu * m_caseMenu;
QTimer* m_inputDelayTimer;
int m_linedId;
bool m_caseSensitive;
private slots:
void slotTextChanged( const QString & text );
void slotCaseChanged( int index );
void startSearch();
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment