class KFind


Module kdeui
Namespace
Class KFind
Inherits QObject
A generic implementation of the "find" function.

Author S.R.Haque , David Faure , Arend van Beelen jr.

Detail:

This class includes prompt handling etc. Also provides some static functions which can be used to create custom behavior instead of using the class directly.

Example:

To use the class to implement a complete find feature:

In the slot connected to the find action, after using KFindDialog:

// This creates a find-next-prompt dialog if needed. m_find = new KFind(pattern, options, this);

// Connect highlight signal to code which handles highlighting // of found text. connect( m_find, SIGNAL( highlight( const QString &, int, int ) ), this, SLOT( slotHighlight( const QString &, int, int ) ) ); // Connect findNext signal - called when pressing the button in the dialog connect( m_find, SIGNAL( findNext() ), this, SLOT( slotFindNext() ) );

If you are using a non-modal find dialog (the recommended new way in KDE-3.2), you should call right away m_find->closeFindNextDialog().

Then initialize the variables determining the "current position" (to the cursor, if the option FromCursor is set, to the beginning of the selection if the option SelectedText is set, and to the beginning of the document otherwise). Initialize the "end of search" variables as well (end of doc or end of selection). Swap begin and end if FindBackwards. Finally, call slotFindNext();

void slotFindNext()
{
KFind.Result res = KFind.NoMatch;
while ( res == KFind.NoMatch &&  ) {
if ( m_find->needData() )
m_find->setData(  );

// Let KFind inspect the text fragment, and display a dialog if a match is found res = m_find->find();

if ( res == KFind.NoMatch ) { } }

if ( res == KFind.NoMatch ) // i.e. at end displayFinalDialog(); delete m_find; m_find = 0; or if ( m_find->shouldRestart() ) { reinit (w/o FromCursor) and call slotFindNext(); } else { m_find->closeFindNextDialog(); }> }

Don't forget to delete m_find in the destructor of your class, unless you gave it a parent widget on construction.

This implementation allows to have a "Find Next" action, which resumes the search, even if the user closed the "Find Next" dialog.

A "Find Previous" action can simply switch temporarily the value of FindBackwards and call slotFindNext() - and reset the value afterwards.



enums

enum details

methods