[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
KLFSearchBar Class Reference

An Search Bar for Incremental Search. More...

#include <klfsearchbar.h>

Inheritance diagram for KLFSearchBar:
Collaboration diagram for KLFSearchBar:

Public Types

enum  SearchState {
  Default , FocusOut , Found , NotFound ,
  Aborted
}

Public Slots

void clear ()
void focusOrNext (bool forward=true)
void focusOrPrev ()
void find (const QString &string)
void find (const QString &string, bool forward)
void findNext (bool forward=true)
void findPrev ()
void abortSearch ()
void focus ()
virtual void setSearchText (const QString &text)
void setFocusOutText (const QString &focusOutText)

Signals

void stateChanged (SearchState state)
void searchPerformed (bool found)
void searchPerformed (const QString &queryString, bool found)
void found ()
void found (const QString &queryString, bool forward)
void found (const QString &queryString, bool forward, const KLFPosSearchable::Pos &pos)
void didNotFind ()
void didNotFind (const QString &queryString, bool forward)
void searchAborted ()
void escapePressed ()
void searchReinitialized ()
void hasMatch (bool hasmatch)
 Reflects whether the search is currently pointing on a valid result.
void visibilityChanged (bool isShown)

Public Member Functions

 KLFSearchBar (QWidget *parent=NULL)
virtual ~KLFSearchBar ()
virtual void registerShortcuts (QWidget *parent)
virtual void setSearchTarget (KLFPosSearchable *target)
virtual void setTarget (KLFTarget *target)
QString currentSearchText () const
bool autoHide () const
bool showOverlayMode () const
QRect showOverlayRelativeGeometry () const
QString focusOutText () const
QColor colorFound () const
QColor colorNotFound () const
bool hideButtonShown () const
bool showSearchLabel () const
bool emacsStyleBackspace () const
int resetTimeout () const
KLFPosSearchable::Pos currentSearchPos () const
SearchState currentState () const
void setAutoHide (bool autohide)
void setShowOverlayMode (bool showOverlayMode)
void setShowOverlayRelativeGeometry (const QRect &relativeGeometryPercent)
void setShowOverlayRelativeGeometry (int widthPercent, int heightPercent, int positionXPercent, int positionYPercent)
void setColorFound (const QColor &color)
void setColorNotFound (const QColor &color)
void setShowHideButton (bool showHideButton)
void setShowSearchLabel (bool show)
void setEmacsStyleBackspace (bool on)
void setResetTimeout (int ms)
virtual bool eventFilter (QObject *obj, QEvent *ev)
QLineEdit * editor ()
Public Member Functions inherited from KLFTargeter
 KLFTargeter ()
virtual ~KLFTargeter ()

Protected Slots

virtual void slotSearchFocusIn ()
virtual void slotSearchFocusOut ()
virtual void slotSearchReset ()
virtual void updateSearchFound (bool found)
void promptEmptySearch ()
virtual void displayState (SearchState state)
void setCurrentState (SearchState state)
void emitFoundSignals (const KLFPosSearchable::Pos &pos, const QString &searchstring, bool forward)
void showSearchBarText (const QString &text)

Protected Member Functions

bool searchBarHasFocus ()
virtual bool event (QEvent *event)

Protected Attributes

Ui::KLFSearchBar * u
bool _isInQtDesigner
Protected Attributes inherited from KLFTargeter
KLFTargetpTarget

Properties

QString currentSearchText
bool autoHide
bool showOverlayMode
QRect showOverlayRelativeGeometry
QString focusOutText
QColor colorFound
QColor colorNotFound
bool showHideButton
bool showSearchLabel
bool emacsStyleBackspace
int resetTimeout

Detailed Description

An Search Bar for Incremental Search.

This widget provides a set of controls an incremental search. This includes a line edit to input the query string, a clear button, 'find next' and 'find previous' buttons.

This widget acts upon an abstract KLFSearchable object, which the object or display being searched will have to implement. You only need to implement three straightforward functions providing the actual search functionality. The search target can be set with setSearchTarget().

The user interface is inspired from (X)Emacs' I-search. More specifically:

  • results are searched for already while the user is typing
  • once arrived at the end of the list, the search will fail. However, re-attempting to find next (eg. F3 or Ctrl-S) (respectively previous) will wrap the search from the beginning (respectively from the end)

Shortcuts can be enabled so that Ctrl-F, Ctrl-S, F3, and such other keys work. See registerShortcuts(). The shortcuts are NOT enabled by default, you need to call registerShortcuts().

The search bar will turn red or green depending on whether the query string is found or not, you can customize these colors with setColorFound() and setColorNotFound(). To customize these colors using stylesheets, you may use the rules

QLineEdit[searchState="found"] {
    background-color: rgb(128,255,128,128);
}
QLineEdit[searchState="not-found"] {
    background-color: rgb(255,128,128,128);
}

since the property searchState is set to one of "default", "focus-out", "found", "not-found", or "aborted" depending on the current state.

Definition at line 464 of file klfsearchbar.h.

Member Enumeration Documentation

◆ SearchState

Enumerator
Default 
FocusOut 
Found 
NotFound 
Aborted 

Definition at line 482 of file klfsearchbar.h.

Constructor & Destructor Documentation

◆ KLFSearchBar()

◆ ~KLFSearchBar()

KLFSearchBar::~KLFSearchBar ( )
virtual

Definition at line 370 of file klfsearchbar.cpp.

Member Function Documentation

◆ abortSearch

void KLFSearchBar::abortSearch ( )
slot
Todo
shouldn't the code to possibly hide the search bar be here instead of in slotSearchFocusOut() ?

Definition at line 898 of file klfsearchbar.cpp.

References Aborted, FocusOut, hasMatch(), KLF_DEBUG_BLOCK, klfDbg, searchAborted(), searchBarHasFocus(), setCurrentState(), showSearchBarText(), and u.

Referenced by eventFilter(), setEmacsStyleBackspace(), setTarget(), and slotSearchReset().

◆ autoHide()

bool KLFSearchBar::autoHide ( ) const

Definition at line 499 of file klfsearchbar.cpp.

◆ clear

void KLFSearchBar::clear ( )
slot

Clears the search bar and takes focus.

Definition at line 697 of file klfsearchbar.cpp.

References focus(), klfDbgT, and setSearchText().

Referenced by KLFSearchBar(), registerShortcuts(), and visibilityChanged().

◆ colorFound()

QColor KLFSearchBar::colorFound ( ) const

This value is read from the palette. It does not take into account style sheets.

Definition at line 382 of file klfsearchbar.cpp.

References QPalette::color(), Found, and u.

◆ colorNotFound()

QColor KLFSearchBar::colorNotFound ( ) const

This value is read from the palette. It does not take into account style sheets.

Definition at line 387 of file klfsearchbar.cpp.

References QPalette::color(), NotFound, and u.

◆ currentSearchPos()

KLFPosSearchable::Pos KLFSearchBar::currentSearchPos ( ) const

Returns the current position in the searched object. This is useful only if you know how the searched object uses KLFPosSearchable::Pos structures.

Definition at line 413 of file klfsearchbar.cpp.

◆ currentSearchText()

QString KLFSearchBar::currentSearchText ( ) const

Definition at line 375 of file klfsearchbar.cpp.

References FocusOut, and u.

◆ currentState()

KLFSearchBar::SearchState KLFSearchBar::currentState ( ) const

Definition at line 418 of file klfsearchbar.cpp.

◆ didNotFind [1/2]

void KLFSearchBar::didNotFind ( )
signal

Referenced by emitFoundSignals().

◆ didNotFind [2/2]

void KLFSearchBar::didNotFind ( const QString & queryString,
bool forward )
signal

◆ displayState

void KLFSearchBar::displayState ( SearchState state)
protectedvirtualslot

Does not change d->pState. Only sets up UI for the given state.

Todo
should these next two lines be inverted? (ie. first set palette, then style sheet)

Definition at line 1064 of file klfsearchbar.cpp.

References FocusOut, klfDbg, showSearchBarText(), and u.

Referenced by KLFSearchBar(), KLFSearchBarDesPlugin, setCurrentState(), and setFocusOutText().

◆ editor()

QLineEdit * KLFSearchBar::editor ( )

Definition at line 656 of file klfsearchbar.cpp.

References u.

◆ emacsStyleBackspace()

bool KLFSearchBar::emacsStyleBackspace ( ) const

Definition at line 403 of file klfsearchbar.cpp.

◆ emitFoundSignals

void KLFSearchBar::emitFoundSignals ( const KLFPosSearchable::Pos & pos,
const QString & searchstring,
bool forward )
protectedslot

◆ escapePressed

void KLFSearchBar::escapePressed ( )
signal

Referenced by eventFilter().

◆ event()

bool KLFSearchBar::event ( QEvent * event)
protectedvirtual

Definition at line 1108 of file klfsearchbar.cpp.

References event(), and visibilityChanged().

Referenced by event().

◆ eventFilter()

◆ find [1/2]

void KLFSearchBar::find ( const QString & string)
slot

Definition at line 732 of file klfsearchbar.cpp.

References find().

Referenced by find(), findNext(), focusOrNext(), and KLFSearchBar().

◆ find [2/2]

void KLFSearchBar::find ( const QString & string,
bool forward )
slot

◆ findNext

void KLFSearchBar::findNext ( bool forward = true)
slot

◆ findPrev

void KLFSearchBar::findPrev ( )
inlineslot

Definition at line 577 of file klfsearchbar.h.

References findNext().

Referenced by KLFSearchBar(), and registerShortcuts().

◆ focus

void KLFSearchBar::focus ( )
slot

Definition at line 964 of file klfsearchbar.cpp.

References KLF_DEBUG_BLOCK, and u.

Referenced by clear(), findNext(), and focusOrNext().

◆ focusOrNext

void KLFSearchBar::focusOrNext ( bool forward = true)
slot

If the search bar does not have focus, takes focus and clears the bar, preparing to search in forward direction (unless forward is FALSE). If it has focus, finds the next occurence (resp. previous if forward is FALSE) of the current or last search string.

Definition at line 704 of file klfsearchbar.cpp.

References find(), findNext(), focus(), FocusOut, klfDbgT, searchBarHasFocus(), setSearchText(), and u.

Referenced by focusOrPrev(), registerShortcuts(), and visibilityChanged().

◆ focusOrPrev

void KLFSearchBar::focusOrPrev ( )
inlineslot

If the search bar does not have focus, takes focus and clears the bar, preparing for a backwards search. If it has focus, finds the previous occurence of the current or last search string.

Definition at line 573 of file klfsearchbar.h.

References focusOrNext().

Referenced by registerShortcuts().

◆ focusOutText()

QString KLFSearchBar::focusOutText ( ) const

Definition at line 512 of file klfsearchbar.cpp.

◆ found [1/3]

void KLFSearchBar::found ( )
signal

◆ found [2/3]

void KLFSearchBar::found ( const QString & queryString,
bool forward )
signal

◆ found [3/3]

void KLFSearchBar::found ( const QString & queryString,
bool forward,
const KLFPosSearchable::Pos & pos )
signal

◆ hasMatch

void KLFSearchBar::hasMatch ( bool hasmatch)
signal

Reflects whether the search is currently pointing on a valid result.

Emitted with argument TRUE each time that a successful search is performed; emitted with FALSE if the query string is not found, or if the search is aborted, or if the user resets the search.

Referenced by abortSearch(), eventFilter(), and promptEmptySearch().

◆ hideButtonShown()

bool KLFSearchBar::hideButtonShown ( ) const

Definition at line 393 of file klfsearchbar.cpp.

References u.

◆ promptEmptySearch

void KLFSearchBar::promptEmptySearch ( )
protectedslot

Definition at line 877 of file klfsearchbar.cpp.

References Default, hasMatch(), klfDbg, searchReinitialized(), setCurrentState(), and u.

Referenced by eventFilter(), find(), and KLFSearchBarDesPlugin.

◆ registerShortcuts()

void KLFSearchBar::registerShortcuts ( QWidget * parent)
virtual

Enables shortcuts such as C-F, C-S, /, F3 etc. The parent is given to the QShortcut constructor.

Definition at line 470 of file klfsearchbar.cpp.

References clear(), DECLARE_SEARCH_SHORTCUT, findNext(), findPrev(), focusOrNext(), and focusOrPrev().

◆ resetTimeout()

int KLFSearchBar::resetTimeout ( ) const

Definition at line 408 of file klfsearchbar.cpp.

◆ searchAborted

void KLFSearchBar::searchAborted ( )
signal

Referenced by abortSearch().

◆ searchBarHasFocus()

bool KLFSearchBar::searchBarHasFocus ( )
protected

Little helper: returns TRUE if the search bar has focus, FALSE otherwise.

Definition at line 1102 of file klfsearchbar.cpp.

References u.

Referenced by abortSearch(), findNext(), focusOrNext(), and setAutoHide().

◆ searchPerformed [1/2]

void KLFSearchBar::searchPerformed ( bool found)
signal

References found().

Referenced by emitFoundSignals().

◆ searchPerformed [2/2]

void KLFSearchBar::searchPerformed ( const QString & queryString,
bool found )
signal

References found().

◆ searchReinitialized

void KLFSearchBar::searchReinitialized ( )
signal

Referenced by promptEmptySearch().

◆ setAutoHide()

void KLFSearchBar::setAutoHide ( bool autohide)

Hides the search bar when it does not have focus.

Definition at line 661 of file klfsearchbar.cpp.

References _isInQtDesigner, klfDbg, and searchBarHasFocus().

◆ setColorFound()

void KLFSearchBar::setColorFound ( const QColor & color)

Definition at line 424 of file klfsearchbar.cpp.

References Default, Found, QVariant::fromValue(), QPalette::setColor(), and u.

Referenced by KLFSearchBar().

◆ setColorNotFound()

void KLFSearchBar::setColorNotFound ( const QColor & color)

Definition at line 433 of file klfsearchbar.cpp.

References Default, QVariant::fromValue(), NotFound, QPalette::setColor(), and u.

Referenced by KLFSearchBar().

◆ setCurrentState

void KLFSearchBar::setCurrentState ( SearchState state)
protectedslot

Updates d->pState, emits the stateChanged() signal, and calls displayState().

Definition at line 1052 of file klfsearchbar.cpp.

References displayState(), klfDbg, and stateChanged().

Referenced by abortSearch(), KLFSearchBarDesPlugin, promptEmptySearch(), slotSearchFocusIn(), and updateSearchFound().

◆ setEmacsStyleBackspace()

void KLFSearchBar::setEmacsStyleBackspace ( bool on)

Definition at line 452 of file klfsearchbar.cpp.

References abortSearch().

◆ setFocusOutText

void KLFSearchBar::setFocusOutText ( const QString & focusOutText)
slot

Definition at line 518 of file klfsearchbar.cpp.

References displayState(), FocusOut, and focusOutText.

◆ setResetTimeout()

void KLFSearchBar::setResetTimeout ( int ms)

Sets the timeout after which the search is reset when the search bar loses focus. Positive values specify a timeout in milliseconds; zero resets the search immediately when focus is lost, and a negative value never resets the search on focus lost.

Definition at line 459 of file klfsearchbar.cpp.

◆ setSearchTarget()

virtual void KLFSearchBar::setSearchTarget ( KLFPosSearchable * target)
inlinevirtual

Set the object upon which we will perform searches. As long as no object is set this bar is unusable.

Definition at line 492 of file klfsearchbar.h.

References setTarget().

◆ setSearchText

void KLFSearchBar::setSearchText ( const QString & text)
virtualslot

Definition at line 494 of file klfsearchbar.cpp.

References u.

Referenced by clear(), and focusOrNext().

◆ setShowHideButton()

void KLFSearchBar::setShowHideButton ( bool showHideButton)

Definition at line 442 of file klfsearchbar.cpp.

References showHideButton, and u.

Referenced by KLFSearchBar().

◆ setShowOverlayMode()

void KLFSearchBar::setShowOverlayMode ( bool showOverlayMode)

Sets the overlay mode. If overlay mode is on, then the search bar is displayed overlaying the parent widget, with no specific layout, possibly hiding other widgets. It is hidden as soon as the search is over.

You may use, eg. the keyboard shortcuts to activate the search and show the search bar.

Todo
..... the search bar should install an event filter on the parent to listen for resize events, and to resize appropriately.

Definition at line 669 of file klfsearchbar.cpp.

References QVariant::fromValue(), and klfDbg.

◆ setShowOverlayRelativeGeometry() [1/2]

void KLFSearchBar::setShowOverlayRelativeGeometry ( const QRect & relativeGeometryPercent)

Definition at line 682 of file klfsearchbar.cpp.

Referenced by setShowOverlayRelativeGeometry().

◆ setShowOverlayRelativeGeometry() [2/2]

void KLFSearchBar::setShowOverlayRelativeGeometry ( int widthPercent,
int heightPercent,
int positionXPercent,
int positionYPercent )

Definition at line 687 of file klfsearchbar.cpp.

References setShowOverlayRelativeGeometry().

◆ setShowSearchLabel()

void KLFSearchBar::setShowSearchLabel ( bool show)

Definition at line 447 of file klfsearchbar.cpp.

References u.

◆ setTarget()

void KLFSearchBar::setTarget ( KLFTarget * target)
virtual

Reimplemented from KLFTargeter.

Definition at line 482 of file klfsearchbar.cpp.

References abortSearch(), KLF_ASSERT_CONDITION, KLFTargeter::KLFTarget, and KLFTargeter::setTarget().

Referenced by setSearchTarget().

◆ showOverlayMode()

bool KLFSearchBar::showOverlayMode ( ) const

Definition at line 504 of file klfsearchbar.cpp.

◆ showOverlayRelativeGeometry()

QRect KLFSearchBar::showOverlayRelativeGeometry ( ) const

Definition at line 508 of file klfsearchbar.cpp.

◆ showSearchBarText

void KLFSearchBar::showSearchBarText ( const QString & text)
protectedslot

sets the given text in the search bar, ensuring that the search bar will NOT emit any textChanged() signals.

Definition at line 1094 of file klfsearchbar.cpp.

References u.

Referenced by abortSearch(), displayState(), findNext(), KLFSearchBarDesPlugin, and slotSearchFocusIn().

◆ showSearchLabel()

bool KLFSearchBar::showSearchLabel ( ) const

Definition at line 398 of file klfsearchbar.cpp.

References u.

◆ slotSearchFocusIn

void KLFSearchBar::slotSearchFocusIn ( )
protectedvirtualslot

Definition at line 979 of file klfsearchbar.cpp.

References Default, FocusOut, klfDbgT, setCurrentState(), and showSearchBarText().

Referenced by eventFilter(), and KLFSearchBarDesPlugin.

◆ slotSearchFocusOut

void KLFSearchBar::slotSearchFocusOut ( )
protectedvirtualslot

Definition at line 993 of file klfsearchbar.cpp.

References klfDbgT, and slotSearchReset().

Referenced by eventFilter(), and KLFSearchBarDesPlugin.

◆ slotSearchReset

void KLFSearchBar::slotSearchReset ( )
protectedvirtualslot

Definition at line 1010 of file klfsearchbar.cpp.

References _isInQtDesigner, abortSearch(), and klfDbgT.

Referenced by KLFSearchBar(), KLFSearchBarDesPlugin, and slotSearchFocusOut().

◆ stateChanged

void KLFSearchBar::stateChanged ( SearchState state)
signal

Referenced by setCurrentState().

◆ updateSearchFound

void KLFSearchBar::updateSearchFound ( bool found)
protectedvirtualslot

Definition at line 1020 of file klfsearchbar.cpp.

References Found, found(), NotFound, and setCurrentState().

Referenced by eventFilter(), and KLFSearchBarDesPlugin.

◆ visibilityChanged

void KLFSearchBar::visibilityChanged ( bool isShown)
signal

References clear(), and focusOrNext().

Referenced by event().

Member Data Documentation

◆ _isInQtDesigner

bool KLFSearchBar::_isInQtDesigner
protected

Definition at line 594 of file klfsearchbar.h.

Referenced by KLFSearchBar(), setAutoHide(), and slotSearchReset().

◆ u

Property Documentation

◆ autoHide

bool KLFSearchBar::autoHide
readwrite

Definition at line 469 of file klfsearchbar.h.

◆ colorFound

QColor KLFSearchBar::colorFound
readwrite

Definition at line 474 of file klfsearchbar.h.

◆ colorNotFound

QColor KLFSearchBar::colorNotFound
readwrite

Definition at line 475 of file klfsearchbar.h.

◆ currentSearchText

QString KLFSearchBar::currentSearchText
read

Definition at line 468 of file klfsearchbar.h.

◆ emacsStyleBackspace

bool KLFSearchBar::emacsStyleBackspace
readwrite

Definition at line 478 of file klfsearchbar.h.

◆ focusOutText

QString KLFSearchBar::focusOutText
readwrite

Definition at line 473 of file klfsearchbar.h.

Referenced by setFocusOutText().

◆ resetTimeout

int KLFSearchBar::resetTimeout
readwrite

Definition at line 479 of file klfsearchbar.h.

◆ showHideButton

bool KLFSearchBar::showHideButton
readwrite

Definition at line 476 of file klfsearchbar.h.

Referenced by setShowHideButton().

◆ showOverlayMode

bool KLFSearchBar::showOverlayMode
readwrite

Definition at line 470 of file klfsearchbar.h.

◆ showOverlayRelativeGeometry

QRect KLFSearchBar::showOverlayRelativeGeometry
readwrite

Definition at line 471 of file klfsearchbar.h.

◆ showSearchLabel

bool KLFSearchBar::showSearchLabel
readwrite

Definition at line 477 of file klfsearchbar.h.


The documentation for this class was generated from the following files:

Generated by doxygen 1.14.0