An Search Bar for Incremental Search. More...
#include <klfsearchbar.h>
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 () |
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 |
Properties | |
QString | currentSearchText |
bool | autoHide |
bool | showOverlayMode |
QRect | showOverlayRelativeGeometry |
QString | focusOutText |
QColor | colorFound |
QColor | colorNotFound |
bool | showHideButton |
bool | showSearchLabel |
bool | emacsStyleBackspace |
int | resetTimeout |
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.
Definition at line 482 of file klfsearchbar.h.
KLFSearchBar::KLFSearchBar | ( | QWidget * | parent = NULL | ) |
Definition at line 299 of file klfsearchbar.cpp.
References _isInQtDesigner, clear(), Default, displayState(), find(), findNext(), findPrev(), FocusOut, KLF_DEBUG_TIME_BLOCK, KLF_FUNC_NAME, klfDbg, QPalette::setColor(), setColorFound(), setColorNotFound(), setShowHideButton(), slotSearchReset(), and u.
KLFSearchBar::~KLFSearchBar | ( | ) | [virtual] |
Definition at line 370 of file klfsearchbar.cpp.
void KLFSearchBar::abortSearch | ( | ) | [slot] |
Definition at line 898 of file klfsearchbar.cpp.
References Aborted, FocusOut, hasMatch(), KLF_DEBUG_BLOCK, KLF_FUNC_NAME, klfDbg, KLFPosSearchable::searchAborted(), searchAborted(), searchBarHasFocus(), setCurrentState(), KLFPosSearchable::setSearchInterruptRequested(), KLFPosSearchable::setSearchQueryString(), showSearchBarText(), and u.
Referenced by eventFilter(), setEmacsStyleBackspace(), setTarget(), and slotSearchReset().
bool KLFSearchBar::autoHide | ( | ) | const |
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().
QColor KLFSearchBar::colorFound | ( | ) | const |
This value is read from the palette. It does not take into account style sheets.
QColor KLFSearchBar::colorNotFound | ( | ) | const |
This value is read from the palette. It does not take into account style sheets.
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.
QString KLFSearchBar::currentSearchText | ( | ) | const |
Definition at line 418 of file klfsearchbar.cpp.
void KLFSearchBar::didNotFind | ( | ) | [signal] |
Referenced by emitFoundSignals().
void KLFSearchBar::didNotFind | ( | const QString & | queryString, |
bool | forward | ||
) | [signal] |
void KLFSearchBar::displayState | ( | SearchState | state | ) | [protected, virtual, slot] |
Does not change d->pState. Only sets up UI for the given state.
Definition at line 1064 of file klfsearchbar.cpp.
References FocusOut, klfDbg, showSearchBarText(), and u.
Referenced by KLFSearchBar(), setCurrentState(), and setFocusOutText().
QLineEdit * KLFSearchBar::editor | ( | ) |
Definition at line 656 of file klfsearchbar.cpp.
References u.
bool KLFSearchBar::emacsStyleBackspace | ( | ) | const |
void KLFSearchBar::emitFoundSignals | ( | const KLFPosSearchable::Pos & | pos, |
const QString & | searchstring, | ||
bool | forward | ||
) | [protected, slot] |
Definition at line 1079 of file klfsearchbar.cpp.
References didNotFind(), found(), searchPerformed(), and KLFPosSearchable::Pos::valid().
Referenced by eventFilter().
void KLFSearchBar::escapePressed | ( | ) | [signal] |
Referenced by eventFilter().
bool KLFSearchBar::event | ( | QEvent * | event | ) | [protected, virtual] |
Definition at line 1108 of file klfsearchbar.cpp.
References QEvent::type(), and visibilityChanged().
bool KLFSearchBar::eventFilter | ( | QObject * | obj, |
QEvent * | ev | ||
) | [virtual] |
Definition at line 543 of file klfsearchbar.cpp.
References abortSearch(), emitFoundSignals(), escapePressed(), findNext(), FocusOut, hasMatch(), QList::isEmpty(), QKeyEvent::key(), KLF_ASSERT_CONDITION_ELSE, KLF_DEBUG_TIME_BLOCK, KLF_FUNC_NAME, klfDbg, promptEmptySearch(), KLFPosSearchable::searchMoveToPos(), KLFPosSearchable::searchPerformed(), KLFPosSearchable::setSearchInterruptRequested(), KLFPosSearchable::setSearchQueryString(), QString::size(), slotSearchFocusIn(), slotSearchFocusOut(), QKeyEvent::text(), QEvent::type(), u, and updateSearchFound().
void KLFSearchBar::find | ( | const QString & | string | ) | [slot] |
Definition at line 732 of file klfsearchbar.cpp.
Referenced by findNext(), focusOrNext(), and KLFSearchBar().
void KLFSearchBar::find | ( | const QString & | string, |
bool | forward | ||
) | [slot] |
Definition at line 737 of file klfsearchbar.cpp.
References QString::isEmpty(), KLF_ASSERT_NOT_NULL, KLF_DEBUG_BLOCK, KLF_FUNC_NAME, klfDbg, klfDbgT, QString::mid(), promptEmptySearch(), KLFPosSearchable::searchStartFrom(), and KLFPosSearchable::setSearchInterruptRequested().
void KLFSearchBar::findNext | ( | bool | forward = true | ) | [slot] |
Definition at line 846 of file klfsearchbar.cpp.
References find(), focus(), KLF_ASSERT_NOT_NULL, klfDbg, klfDbgT, KLFTargeter::pTarget, searchBarHasFocus(), showSearchBarText(), and u.
Referenced by eventFilter(), focusOrNext(), KLFSearchBar(), and registerShortcuts().
void KLFSearchBar::findPrev | ( | ) | [inline, slot] |
Definition at line 577 of file klfsearchbar.h.
Referenced by KLFSearchBar(), and registerShortcuts().
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().
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().
void KLFSearchBar::focusOrPrev | ( | ) | [inline, slot] |
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().
QString KLFSearchBar::focusOutText | ( | ) | const |
Referenced by setFocusOutText().
void KLFSearchBar::found | ( | ) | [signal] |
Referenced by emitFoundSignals().
void KLFSearchBar::found | ( | const QString & | queryString, |
bool | forward | ||
) | [signal] |
void KLFSearchBar::found | ( | const QString & | queryString, |
bool | forward, | ||
const KLFPosSearchable::Pos & | pos | ||
) | [signal] |
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().
bool KLFSearchBar::hideButtonShown | ( | ) | const |
Definition at line 393 of file klfsearchbar.cpp.
References u.
void KLFSearchBar::promptEmptySearch | ( | ) | [protected, slot] |
Definition at line 877 of file klfsearchbar.cpp.
References Default, hasMatch(), klfDbg, KLFPosSearchable::searchMoveToPos(), KLFPosSearchable::searchReinitialized(), searchReinitialized(), setCurrentState(), KLFPosSearchable::setSearchInterruptRequested(), KLFPosSearchable::setSearchQueryString(), and u.
Referenced by eventFilter(), and find().
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().
int KLFSearchBar::resetTimeout | ( | ) | const |
void KLFSearchBar::searchAborted | ( | ) | [signal] |
Referenced by abortSearch().
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().
void KLFSearchBar::searchPerformed | ( | bool | found | ) | [signal] |
Referenced by emitFoundSignals().
void KLFSearchBar::searchPerformed | ( | const QString & | queryString, |
bool | found | ||
) | [signal] |
void KLFSearchBar::searchReinitialized | ( | ) | [signal] |
Referenced by promptEmptySearch().
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().
void KLFSearchBar::setColorFound | ( | const QColor & | color | ) |
Definition at line 424 of file klfsearchbar.cpp.
References Default, Found, QPalette::setColor(), and u.
Referenced by KLFSearchBar().
void KLFSearchBar::setColorNotFound | ( | const QColor & | color | ) |
Definition at line 433 of file klfsearchbar.cpp.
References Default, NotFound, QPalette::setColor(), and u.
Referenced by KLFSearchBar().
void KLFSearchBar::setCurrentState | ( | SearchState | state | ) | [protected, slot] |
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().
void KLFSearchBar::setEmacsStyleBackspace | ( | bool | on | ) |
Definition at line 452 of file klfsearchbar.cpp.
References abortSearch().
void KLFSearchBar::setFocusOutText | ( | const QString & | focusOutText | ) | [slot] |
Definition at line 518 of file klfsearchbar.cpp.
References displayState(), FocusOut, and focusOutText().
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.
virtual void KLFSearchBar::setSearchTarget | ( | KLFPosSearchable * | target | ) | [inline, virtual] |
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 KLFTargeter::setTarget().
void KLFSearchBar::setSearchText | ( | const QString & | text | ) | [virtual, slot] |
Definition at line 494 of file klfsearchbar.cpp.
References u.
Referenced by clear(), and focusOrNext().
void KLFSearchBar::setShowHideButton | ( | bool | showHideButton | ) |
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.
Definition at line 669 of file klfsearchbar.cpp.
References klfDbg.
void KLFSearchBar::setShowOverlayRelativeGeometry | ( | const QRect & | relativeGeometryPercent | ) |
Definition at line 682 of file klfsearchbar.cpp.
Referenced by setShowOverlayRelativeGeometry().
void KLFSearchBar::setShowOverlayRelativeGeometry | ( | int | widthPercent, |
int | heightPercent, | ||
int | positionXPercent, | ||
int | positionYPercent | ||
) |
Definition at line 687 of file klfsearchbar.cpp.
References setShowOverlayRelativeGeometry().
void KLFSearchBar::setShowSearchLabel | ( | bool | show | ) |
Definition at line 447 of file klfsearchbar.cpp.
References u.
void KLFSearchBar::setTarget | ( | KLFTarget * | target | ) | [virtual] |
Reimplemented from KLFTargeter.
Definition at line 482 of file klfsearchbar.cpp.
References abortSearch(), and KLF_ASSERT_CONDITION.
bool KLFSearchBar::showOverlayMode | ( | ) | const |
void KLFSearchBar::showSearchBarText | ( | const QString & | text | ) | [protected, slot] |
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().
bool KLFSearchBar::showSearchLabel | ( | ) | const |
void KLFSearchBar::slotSearchFocusIn | ( | ) | [protected, virtual, slot] |
Definition at line 979 of file klfsearchbar.cpp.
References Default, FocusOut, klfDbgT, setCurrentState(), and showSearchBarText().
Referenced by eventFilter().
void KLFSearchBar::slotSearchFocusOut | ( | ) | [protected, virtual, slot] |
Definition at line 993 of file klfsearchbar.cpp.
References klfDbgT, and slotSearchReset().
Referenced by eventFilter().
void KLFSearchBar::slotSearchReset | ( | ) | [protected, virtual, slot] |
Definition at line 1010 of file klfsearchbar.cpp.
References _isInQtDesigner, abortSearch(), and klfDbgT.
Referenced by KLFSearchBar(), and slotSearchFocusOut().
void KLFSearchBar::stateChanged | ( | SearchState | state | ) | [signal] |
Referenced by setCurrentState().
void KLFSearchBar::updateSearchFound | ( | bool | found | ) | [protected, virtual, slot] |
Definition at line 1020 of file klfsearchbar.cpp.
References Found, NotFound, and setCurrentState().
Referenced by eventFilter().
void KLFSearchBar::visibilityChanged | ( | bool | isShown | ) | [signal] |
Referenced by event().
bool KLFSearchBar::_isInQtDesigner [protected] |
Definition at line 594 of file klfsearchbar.h.
Referenced by KLFSearchBar(), setAutoHide(), and slotSearchReset().
Ui::KLFSearchBar* KLFSearchBar::u [protected] |
Definition at line 586 of file klfsearchbar.h.
Referenced by abortSearch(), displayState(), editor(), eventFilter(), findNext(), focus(), focusOrNext(), hideButtonShown(), KLFSearchBar(), promptEmptySearch(), searchBarHasFocus(), setColorFound(), setColorNotFound(), setSearchText(), setShowHideButton(), setShowSearchLabel(), and showSearchBarText().
bool KLFSearchBar::autoHide [read, write] |
Definition at line 468 of file klfsearchbar.h.
QColor KLFSearchBar::colorFound [read, write] |
Definition at line 473 of file klfsearchbar.h.
QColor KLFSearchBar::colorNotFound [read, write] |
Definition at line 474 of file klfsearchbar.h.
Definition at line 468 of file klfsearchbar.h.
bool KLFSearchBar::emacsStyleBackspace [read, write] |
Definition at line 477 of file klfsearchbar.h.
QString KLFSearchBar::focusOutText [read, write] |
Definition at line 472 of file klfsearchbar.h.
int KLFSearchBar::resetTimeout [read, write] |
Definition at line 478 of file klfsearchbar.h.
bool KLFSearchBar::showHideButton [read, write] |
Definition at line 475 of file klfsearchbar.h.
bool KLFSearchBar::showOverlayMode [read, write] |
Definition at line 469 of file klfsearchbar.h.
QRect KLFSearchBar::showOverlayRelativeGeometry [read, write] |
Definition at line 470 of file klfsearchbar.h.
bool KLFSearchBar::showSearchLabel [read, write] |
Definition at line 476 of file klfsearchbar.h.