[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
Public Types | Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Properties | List of all members
KLFSearchBar Class Reference

An Search Bar for Incremental Search. More...

#include <klfsearchbar.h>

Inheritance diagram for KLFSearchBar:
Inheritance graph
[legend]
Collaboration diagram for KLFSearchBar:
Collaboration graph
[legend]

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. More...
 
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:

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 ( QWidget *  parent = NULL)

◆ ~KLFSearchBar()

KLFSearchBar::~KLFSearchBar ( )
virtual

Member Function Documentation

◆ abortSearch

void KLFSearchBar::abortSearch ( )
slot

◆ autoHide()

bool KLFSearchBar::autoHide ( ) const

Referenced by setSearchText().

◆ 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(), and registerShortcuts().

◆ colorFound()

QColor KLFSearchBar::colorFound ( ) const

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

Referenced by ~KLFSearchBar().

◆ colorNotFound()

QColor KLFSearchBar::colorNotFound ( ) const

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

Referenced by ~KLFSearchBar().

◆ 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

Referenced by ~KLFSearchBar().

◆ 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(), setCurrentState(), and setFocusOutText().

◆ editor()

QLineEdit * KLFSearchBar::editor ( )

Definition at line 656 of file klfsearchbar.cpp.

References u.

◆ emacsStyleBackspace()

bool KLFSearchBar::emacsStyleBackspace ( ) const

Referenced by hideButtonShown().

◆ emitFoundSignals

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

Definition at line 1079 of file klfsearchbar.cpp.

References didNotFind(), found(), searchPerformed(), and KLFPosSearchable::Pos::valid().

Referenced by find().

◆ escapePressed

void KLFSearchBar::escapePressed ( )
signal

Referenced by eventFilter().

◆ event()

bool KLFSearchBar::event ( QEvent event)
protectedvirtual

Definition at line 1108 of file klfsearchbar.cpp.

References QEvent::type(), and visibilityChanged().

◆ eventFilter()

bool KLFSearchBar::eventFilter ( QObject obj,
QEvent ev 
)
virtual

◆ find [1/2]

void KLFSearchBar::find ( const QString string)
slot

Definition at line 732 of file klfsearchbar.cpp.

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.

Referenced by KLFSearchBar(), and registerShortcuts().

◆ focus

void KLFSearchBar::focus ( )
slot

Definition at line 964 of file klfsearchbar.cpp.

References KLF_DEBUG_BLOCK, KLF_FUNC_NAME, 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 registerShortcuts().

◆ 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.

Referenced by registerShortcuts().

◆ focusOutText()

QString KLFSearchBar::focusOutText ( ) const

Referenced by setFocusOutText(), and setSearchText().

◆ found [1/3]

void KLFSearchBar::found ( )
signal

Referenced by emitFoundSignals().

◆ 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(), find(), and promptEmptySearch().

◆ hideButtonShown()

bool KLFSearchBar::hideButtonShown ( ) const

Definition at line 393 of file klfsearchbar.cpp.

References emacsStyleBackspace(), resetTimeout(), showSearchLabel(), and u.

◆ promptEmptySearch

void KLFSearchBar::promptEmptySearch ( )
protectedslot

◆ 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

Referenced by hideButtonShown().

◆ 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

Referenced by emitFoundSignals().

◆ searchPerformed [2/2]

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

◆ 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, QPalette::setColor(), and u.

Referenced by KLFSearchBar().

◆ setColorNotFound()

void KLFSearchBar::setColorNotFound ( const QColor color)

Definition at line 433 of file klfsearchbar.cpp.

References Default, 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(), 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.

◆ setSearchText

void KLFSearchBar::setSearchText ( const QString text)
virtualslot

Definition at line 494 of file klfsearchbar.cpp.

References autoHide(), focusOutText(), showOverlayMode(), showOverlayRelativeGeometry(), and u.

Referenced by clear(), and focusOrNext().

◆ setShowHideButton()

void KLFSearchBar::setShowHideButton ( bool  showHideButton)

Definition at line 442 of file klfsearchbar.cpp.

References 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 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, and KLFTargeter::setTarget().

◆ showOverlayMode()

bool KLFSearchBar::showOverlayMode ( ) const

Referenced by setSearchText().

◆ showOverlayRelativeGeometry()

QRect KLFSearchBar::showOverlayRelativeGeometry ( ) const

Referenced by setSearchText().

◆ 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(), and slotSearchFocusIn().

◆ showSearchLabel()

bool KLFSearchBar::showSearchLabel ( ) const

Referenced by hideButtonShown().

◆ slotSearchFocusIn

void KLFSearchBar::slotSearchFocusIn ( )
protectedvirtualslot

Definition at line 979 of file klfsearchbar.cpp.

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

Referenced by eventFilter().

◆ slotSearchFocusOut

void KLFSearchBar::slotSearchFocusOut ( )
protectedvirtualslot

Definition at line 993 of file klfsearchbar.cpp.

References klfDbgT, and slotSearchReset().

Referenced by eventFilter().

◆ slotSearchReset

void KLFSearchBar::slotSearchReset ( )
protectedvirtualslot

Definition at line 1010 of file klfsearchbar.cpp.

References _isInQtDesigner, abortSearch(), and klfDbgT.

Referenced by KLFSearchBar(), 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 Aborted, Default, FocusOut, Found, KLF_FUNC_NAME, NotFound, and setCurrentState().

Referenced by eventFilter(), and find().

◆ visibilityChanged

void KLFSearchBar::visibilityChanged ( bool  isShown)
signal

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

Ui::KLFSearchBar* KLFSearchBar::u
protected

Property Documentation

◆ autoHide

bool KLFSearchBar::autoHide
readwrite

Definition at line 468 of file klfsearchbar.h.

◆ colorFound

QColor KLFSearchBar::colorFound
readwrite

Definition at line 473 of file klfsearchbar.h.

◆ colorNotFound

QColor KLFSearchBar::colorNotFound
readwrite

Definition at line 474 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 477 of file klfsearchbar.h.

◆ focusOutText

QString KLFSearchBar::focusOutText
readwrite

Definition at line 472 of file klfsearchbar.h.

◆ resetTimeout

int KLFSearchBar::resetTimeout
readwrite

Definition at line 478 of file klfsearchbar.h.

◆ showHideButton

bool KLFSearchBar::showHideButton
readwrite

Definition at line 475 of file klfsearchbar.h.

◆ showOverlayMode

bool KLFSearchBar::showOverlayMode
readwrite

Definition at line 469 of file klfsearchbar.h.

◆ showOverlayRelativeGeometry

QRect KLFSearchBar::showOverlayRelativeGeometry
readwrite

Definition at line 470 of file klfsearchbar.h.

◆ showSearchLabel

bool KLFSearchBar::showSearchLabel
readwrite

Definition at line 476 of file klfsearchbar.h.


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

Generated by doxygen 1.8.13