An Search Bar for Incremental Search. More...
#include <klfsearchbar.h>
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 | searchPerformed (bool found) |
void | found () |
void | found (const QString &queryString, bool forward) |
void | didNotFind () |
void | didNotFind (const QString &queryString, bool forward) |
void | searchAborted () |
void | escapePressed () |
Public Member Functions | |
KLFSearchBar (QWidget *parent=NULL) | |
virtual | ~KLFSearchBar () |
virtual void | registerShortcuts (QWidget *parent) |
virtual void | setSearchTarget (KLFSearchable *object) |
QString | currentSearchText () const |
bool | showOverlayMode () const |
QRect | showOverlayRelativeGeometry () const |
QString | focusOutText () const |
QColor | colorFound () const |
QColor | colorNotFound () const |
bool | hideButtonShown () const |
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) |
virtual bool | eventFilter (QObject *obj, QEvent *ev) |
QLineEdit * | editor () |
![]() | |
QFrame (QWidget *parent=0, Qt::WindowFlags f=0) | |
frameStyle () | |
setFrameStyle (int style) | |
QFrame (QWidget *parent, const char *name, Qt::WindowFlags f=0) | |
Protected Types | |
enum | SearchState { Default, FocusOut, Found, NotFound, Aborted } |
Protected Member Functions | |
virtual void | slotSearchFocusIn () |
virtual void | slotSearchFocusOut () |
virtual void | updateSearchFound (bool found) |
virtual void | displayState (SearchState state) |
void | emitFoundSignals (bool found, const QString &searchstring, bool forward) |
void | showSearchBarText (const QString &text) |
bool | searchBarHasFocus () |
virtual bool | event (QEvent *event) |
Protected Attributes | |
Ui::KLFSearchBar * | u |
Properties | |
QString | currentSearchText |
bool | showOverlayMode |
QRect | showOverlayRelativeGeometry |
QString | focusOutText |
QColor | colorFound |
QColor | colorNotFound |
bool | showHideButton |
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 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 172 of file klfsearchbar.h.
|
protected |
Enumerator | |
---|---|
Default | |
FocusOut | |
Found | |
NotFound | |
Aborted |
Definition at line 252 of file klfsearchbar.h.
KLFSearchBar::KLFSearchBar | ( | QWidget * | parent = NULL | ) |
Definition at line 93 of file klfsearchbar.cpp.
References clear(), Default, find(), findNext(), findPrev(), FocusOut, KLF_DEBUG_TIME_BLOCK, KLF_FUNC_NAME, klfDbg, QPalette::setColor(), setColorFound(), setColorNotFound(), setSearchTarget(), setShowHideButton(), KLFWaitAnimationOverlay::setWaitMovie(), slotSearchFocusOut(), and u.
|
virtual |
Definition at line 143 of file klfsearchbar.cpp.
References QList::removeAll().
|
slot |
Definition at line 371 of file klfsearchbar.cpp.
References Aborted, displayState(), FocusOut, KLF_DEBUG_BLOCK, KLF_FUNC_NAME, klfDbg, KLFSearchable::searchAbort(), searchAborted(), searchBarHasFocus(), showSearchBarText(), and u.
Referenced by eventFilter(), find(), and setSearchTarget().
|
slot |
Clears the search bar and takes focus.
Definition at line 293 of file klfsearchbar.cpp.
References focus(), klfDbgT, and u.
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.
QString KLFSearchBar::currentSearchText | ( | ) | const |
|
signal |
Referenced by emitFoundSignals().
|
signal |
|
protectedvirtual |
Definition at line 478 of file klfsearchbar.cpp.
References FocusOut, klfDbg, showSearchBarText(), and u.
Referenced by abortSearch(), slotSearchFocusIn(), slotSearchFocusOut(), and updateSearchFound().
QLineEdit * KLFSearchBar::editor | ( | ) |
Definition at line 261 of file klfsearchbar.cpp.
References u.
|
protected |
Definition at line 492 of file klfsearchbar.cpp.
References didNotFind(), found(), and searchPerformed().
Referenced by find(), and findNext().
|
signal |
Referenced by eventFilter().
|
protectedvirtual |
Definition at line 516 of file klfsearchbar.cpp.
References QEvent::type().
Definition at line 237 of file klfsearchbar.cpp.
References abortSearch(), escapePressed(), QKeyEvent::key(), klfDbg, slotSearchFocusIn(), slotSearchFocusOut(), QEvent::type(), and u.
|
inlineslot |
Definition at line 234 of file klfsearchbar.h.
References find().
Referenced by find(), findNext(), focusOrNext(), and KLFSearchBar().
|
slot |
Definition at line 324 of file klfsearchbar.cpp.
References abortSearch(), emitFoundSignals(), found(), QString::isEmpty(), KLF_ASSERT_NOT_NULL, klfDbgT, KLFSearchable::searchFind(), KLFWaitAnimationOverlay::startWait(), KLFWaitAnimationOverlay::stopWait(), and updateSearchFound().
|
slot |
Definition at line 342 of file klfsearchbar.cpp.
References emitFoundSignals(), find(), focus(), found(), QString::isEmpty(), KLF_ASSERT_NOT_NULL, klfDbg, klfDbgT, searchBarHasFocus(), KLFSearchable::searchFindNext(), showSearchBarText(), KLFWaitAnimationOverlay::startWait(), KLFWaitAnimationOverlay::stopWait(), u, and updateSearchFound().
Referenced by focusOrNext(), KLFSearchBar(), and registerShortcuts().
|
inlineslot |
Definition at line 237 of file klfsearchbar.h.
Referenced by KLFSearchBar(), and registerShortcuts().
|
slot |
Definition at line 394 of file klfsearchbar.cpp.
References QSize::expandedTo(), QSize::height(), KLF_DEBUG_BLOCK, KLF_FUNC_NAME, klfDbg, QRect::size(), QRect::topLeft(), u, QSize::width(), QPoint::x(), and QPoint::y().
Referenced by clear(), findNext(), and focusOrNext().
|
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 300 of file klfsearchbar.cpp.
References find(), findNext(), focus(), QApplication::focusWidget(), QString::isEmpty(), klfDbgT, and u.
Referenced by registerShortcuts().
|
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 233 of file klfsearchbar.h.
Referenced by registerShortcuts().
|
inline |
Definition at line 196 of file klfsearchbar.h.
Referenced by setFocusOutText().
|
signal |
Referenced by emitFoundSignals(), find(), and findNext().
|
signal |
bool KLFSearchBar::hideButtonShown | ( | ) | const |
Definition at line 165 of file klfsearchbar.cpp.
References u.
|
virtual |
Definition at line 197 of file klfsearchbar.cpp.
References clear(), DECLARE_SEARCH_SHORTCUT, findNext(), findPrev(), focusOrNext(), and focusOrPrev().
|
signal |
Referenced by abortSearch().
|
protected |
Little helper: returns TRUE if the search bar has focus, FALSE otherwise.
Definition at line 510 of file klfsearchbar.cpp.
References QApplication::focusWidget(), and u.
Referenced by abortSearch(), findNext(), and setShowOverlayMode().
|
signal |
Referenced by emitFoundSignals().
void KLFSearchBar::setColorFound | ( | const QColor & | color | ) |
Definition at line 170 of file klfsearchbar.cpp.
References Default, Found, QPalette::setColor(), and u.
Referenced by KLFSearchBar().
void KLFSearchBar::setColorNotFound | ( | const QColor & | color | ) |
Definition at line 178 of file klfsearchbar.cpp.
References Default, NotFound, QPalette::setColor(), and u.
Referenced by KLFSearchBar().
|
slot |
Definition at line 231 of file klfsearchbar.cpp.
References focusOutText().
|
virtual |
Set the object upon which we will perform searches. As long as no object is set this bar is unusable.
Definition at line 208 of file klfsearchbar.cpp.
References abortSearch(), QList::append(), KLF_DEBUG_BLOCK, KLF_FUNC_NAME, klfDbg, and QList::removeAll().
Referenced by KLFSearchBar().
|
virtualslot |
Definition at line 226 of file klfsearchbar.cpp.
References u.
void KLFSearchBar::setShowHideButton | ( | bool | showHideButton | ) |
void KLFSearchBar::setShowOverlayMode | ( | bool | showOverlayMode | ) |
Definition at line 266 of file klfsearchbar.cpp.
References klfDbg, and searchBarHasFocus().
void KLFSearchBar::setShowOverlayRelativeGeometry | ( | const QRect & | relativeGeometryPercent | ) |
Definition at line 280 of file klfsearchbar.cpp.
Referenced by setShowOverlayRelativeGeometry().
void KLFSearchBar::setShowOverlayRelativeGeometry | ( | int | widthPercent, |
int | heightPercent, | ||
int | positionXPercent, | ||
int | positionYPercent | ||
) |
Definition at line 284 of file klfsearchbar.cpp.
References setShowOverlayRelativeGeometry().
|
inline |
Definition at line 194 of file klfsearchbar.h.
|
inline |
Definition at line 195 of file klfsearchbar.h.
|
protected |
sets the given text
in the search bar, ensuring that the search bar will NOT emit any textChanged() signals.
Definition at line 504 of file klfsearchbar.cpp.
References u.
Referenced by abortSearch(), displayState(), findNext(), and slotSearchFocusIn().
|
protectedvirtual |
Definition at line 431 of file klfsearchbar.cpp.
References Default, displayState(), klfDbgT, and showSearchBarText().
Referenced by eventFilter().
|
protectedvirtual |
Definition at line 438 of file klfsearchbar.cpp.
References displayState(), FocusOut, and klfDbgT.
Referenced by eventFilter(), and KLFSearchBar().
|
protectedvirtual |
Definition at line 446 of file klfsearchbar.cpp.
References displayState(), Found, and NotFound.
Referenced by find(), and findNext().
|
protected |
Definition at line 246 of file klfsearchbar.h.
Referenced by abortSearch(), clear(), displayState(), editor(), eventFilter(), findNext(), focus(), focusOrNext(), hideButtonShown(), KLFSearchBar(), searchBarHasFocus(), setColorFound(), setColorNotFound(), setSearchText(), setShowHideButton(), and showSearchBarText().
|
readwrite |
Definition at line 180 of file klfsearchbar.h.
|
readwrite |
Definition at line 181 of file klfsearchbar.h.
|
readwrite |
Definition at line 176 of file klfsearchbar.h.
|
readwrite |
Definition at line 179 of file klfsearchbar.h.
|
readwrite |
Definition at line 182 of file klfsearchbar.h.
|
readwrite |
Definition at line 176 of file klfsearchbar.h.
|
readwrite |
Definition at line 177 of file klfsearchbar.h.