31 #include <QKeySequence> 36 #include <ui_klfsearchbar.h> 46 for (k = 0; k < bars.
size(); ++k) {
47 bars[k]->pTarget = NULL;
50 for (k = 0; k < pl.
size(); ++k) {
51 pl[k]->pTarget = NULL;
60 pTarget->pTargetOfProxy.removeAll(
this);
66 pTarget->pTargetOfProxy.removeAll(
this);
71 pTarget->pTargetOfProxy.
append(
this);
77 return pTarget->searchFind(queryString, forward);
82 return pTarget->searchFindNext(forward);
87 return pTarget->searchAbort();
94 :
QFrame(parent), pTarget(NULL)
97 klfDbg(
"parent: "<<parent) ;
99 u =
new Ui::KLFSearchBar;
102 setSizePolicy(
QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
104 u->txtSearch->installEventFilter(
this);
105 connect(
u->btnSearchClear, SIGNAL(clicked()),
this, SLOT(
clear()));
106 connect(
u->txtSearch, SIGNAL(textChanged(
const QString&)),
108 connect(
u->btnFindNext, SIGNAL(clicked()),
this, SLOT(
findNext()));
109 connect(
u->btnFindPrev, SIGNAL(clicked()),
this, SLOT(
findPrev()));
111 QPalette defaultpal =
u->txtSearch->palette();
112 u->txtSearch->setProperty(palettePropName(
Default).toAscii(), QVariant::fromValue<QPalette>(defaultpal));
117 u->txtSearch->setProperty(palettePropName(
FocusOut).toAscii(), QVariant::fromValue<QPalette>(pal0));
122 connect(
u->btnHide, SIGNAL(clicked()),
this, SLOT(hide()));
131 pShowOverlayMode =
false;
136 pFocusOutText =
" "+tr(
"Hit Ctrl-F, Ctrl-S or / to start searching");
138 pSearchForward =
true;
151 return u->txtSearch->text();
157 return p.
color(QPalette::Base);
162 return p.
color(QPalette::Base);
167 return u->btnHide->isVisible();
173 pal1.
setColor(QPalette::Base, color);
174 pal1.
setColor(QPalette::Window, color);
175 pal1.
setColor(
u->txtSearch->backgroundRole(), color);
176 u->txtSearch->setProperty(palettePropName(
Found).toAscii(), QVariant::fromValue<QPalette>(pal1));
181 pal2.
setColor(QPalette::Base, color);
182 pal2.
setColor(QPalette::Window, color);
183 pal2.
setColor(
u->txtSearch->backgroundRole(), color);
184 u->txtSearch->setProperty(palettePropName(
NotFound).toAscii(), QVariant::fromValue<QPalette>(pal2));
189 u->btnHide->setShown(showHideButton);
193 #define DECLARE_SEARCH_SHORTCUT(shortcut, parent, slotmember) \ 194 { QShortcut *s = new QShortcut(parent); s->setKey(QKeySequence(shortcut)); \ 195 connect(s, SIGNAL(activated()), this, slotmember); } 211 klfDbg(
"target="<<
object) ;
221 pTarget->pTargetOf.
append(
this);
223 setEnabled(pTarget != NULL);
228 u->lblSearch->setText(text);
239 if (obj ==
u->txtSearch) {
240 if (ev->
type() == QEvent::FocusIn) {
241 klfDbg(
"focus-in event...") ;
244 }
else if (ev->
type() == QEvent::FocusOut) {
245 klfDbg(
"focus-out event...") ;
249 }
else if (ev->
type() == QEvent::KeyPress) {
251 if (ke->
key() == Qt::Key_Escape) {
258 return QFrame::eventFilter(obj, ev);
268 klfDbg(
"setting show overlay mode to "<<overlayMode) ;
269 pShowOverlayMode = overlayMode;
272 setProperty(
"klfShowOverlayMode", QVariant::fromValue<bool>(pShowOverlayMode));
274 setProperty(
"klfTopLevelWidget", QVariant::fromValue<bool>(pShowOverlayMode));
282 pShowOverlayRelativeGeometry = relativeGeometryPercent;
285 int positionXPercent,
int positionYPercent)
288 QSize(widthPercent, heightPercent)));
296 u->txtSearch->setText(
"");
302 pSearchForward = forward;
305 klfDbgT(
"already have focus") ;
309 if (
u->txtSearch->text().isEmpty()) {
310 u->txtSearch->setText(pLastSearchText);
313 find(
u->txtSearch->text(), forward);
319 u->txtSearch->setText(
"");
326 klfDbgT(
"text="<<text<<
", forward="<<forward) ;
351 klfDbg(
"called but not in search mode. recalling history="<<pLastSearchText) ;
357 find(
u->txtSearch->text(), forward);
367 pLastSearchText = pSearchText;
376 if ( !
u->txtSearch->text().isEmpty() ) {
385 if (pTarget != NULL) {
386 klfDbg(
"telling target to abort search...") ;
398 if (pShowOverlayMode) {
402 QSize pws = pw->size();
405 QSize relSz = pShowOverlayRelativeGeometry.
size();
411 klfDbg(
"Geometry is "<<gm) ;
414 setStyleSheet(styleSheet());
418 setWindowFlags(Qt::Tool);
420 setWindowOpacity(0.95);
428 u->txtSearch->setFocus();
442 if (pShowOverlayMode)
480 klfDbg(
"Setting state: "<<statePropValue(s));
481 u->txtSearch->setProperty(
"searchState", statePropValue(s));
482 QPalette pal =
u->txtSearch->property(palettePropName(s).toAscii()).value<
QPalette>();
483 u->txtSearch->setStyleSheet(
u->txtSearch->styleSheet());
484 u->txtSearch->setPalette(pal);
485 u->txtSearch->update();
497 emit
found(searchstring, forward);
506 u->txtSearch->blockSignals(
true);
507 u->txtSearch->setText(text);
508 u->txtSearch->blockSignals(
false);
518 if (event->
type() == QEvent::Polish)
519 setMinimumSize(minimumSizeHint());
521 return QFrame::event(event);
void setSearchTarget(KLFSearchable *target)
virtual bool searchFindNext(bool forward)
KLFSearchBar(QWidget *parent=NULL)
An interface for objects that can be I-searched with a KLFSearchBar.
setColor(ColorGroup group, ColorRole role, const QColor &color)
virtual bool searchFindNext(bool forward)=0
Find next or previous occurence of query string.
#define klfDbgT(streamableItems)
QString currentSearchText() const
void setFocusOutText(const QString &focusOutText)
virtual void slotSearchFocusIn()
color(ColorGroup group, ColorRole role)
virtual void searchAbort()=0
Abort I-Search.
#define klfDbg(streamableItems)
void showSearchBarText(const QString &text)
#define KLF_DEBUG_BLOCK(msg)
void setColorFound(const QColor &color)
void focusOrNext(bool forward=true)
void setColorNotFound(const QColor &color)
#define DECLARE_SEARCH_SHORTCUT(shortcut, parent, slotmember)
QColor colorNotFound() const
virtual void setSearchTarget(KLFSearchable *object)
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
virtual bool searchFind(const QString &queryString, bool forward)=0
Find the first occurence of a query string.
virtual void searchAbort()
virtual void displayState(SearchState state)
void findNext(bool forward=true)
removeAll(const T &value)
void setShowOverlayRelativeGeometry(const QRect &relativeGeometryPercent)
virtual void setSearchText(const QString &text)
#define KLF_DEBUG_TIME_BLOCK(msg)
void setShowHideButton(bool showHideButton)
void emitFoundSignals(bool found, const QString &searchstring, bool forward)
void searchPerformed(bool found)
virtual void updateSearchFound(bool found)
QColor colorFound() const
expandedTo(const QSize &otherSize)
void setShowOverlayMode(bool showOverlayMode)
virtual void setWaitMovie(QMovie *movie)
Set which animation to display while searching.
virtual void slotSearchFocusOut()
virtual void stopWait()
Hide the animation.
QString focusOutText() const
virtual ~KLFSearchableProxy()
bool hideButtonShown() const
virtual bool eventFilter(QObject *obj, QEvent *ev)
virtual void registerShortcuts(QWidget *parent)
virtual bool event(QEvent *event)
virtual void startWait()
Display the animation.
void find(const QString &string)
virtual bool searchFind(const QString &queryString, bool forward)