29 #include <QtGui/QMenu> 30 #include <QtGui/QLineEdit> 40 m_next->setIcon(
KIcon(
"go-down-search" ) );
41 m_previous->setIcon(
KIcon(
"go-up-search" ) );
42 m_next->setDisabled(
true );
43 m_previous->setDisabled(
true );
46 m_incMenu =
new QMenu();
47 m_options->setMenu(m_incMenu);
48 m_caseSensitive = m_incMenu->addAction(
i18n(
"C&ase sensitive"));
49 m_caseSensitive->setCheckable(
true);
50 m_wholeWordsOnly = m_incMenu->addAction(
i18n(
"&Whole words only"));
51 m_wholeWordsOnly->setCheckable(
true);
52 m_fromCursor = m_incMenu->addAction(
i18n(
"From c&ursor"));
53 m_fromCursor->setCheckable(
true);
54 m_selectedText = m_incMenu->addAction(
i18n(
"&Selected text"));
55 m_selectedText->setCheckable(
true);
56 m_regExp = m_incMenu->addAction(
i18n(
"Regular e&xpression"));
57 m_regExp->setCheckable(
true);
58 m_findLinksOnly = m_incMenu->addAction(
i18n(
"Find &links only"));
59 m_findLinksOnly->setCheckable(
true);
63 m_find->setDuplicatesEnabled(
false );
66 connect( m_selectedText, SIGNAL(toggled(
bool)),
this, SLOT(slotSelectedTextToggled(
bool)) );
67 connect( m_find, SIGNAL(editTextChanged(QString)),
this, SIGNAL(
searchChanged()) );
68 connect( m_find->lineEdit(), SIGNAL(clearButtonClicked()),
this, SLOT(slotAddPatternToHistory()) );
69 connect(
this, SIGNAL(
hideMe()),
this, SLOT(slotAddPatternToHistory()) );
70 connect(
this, SIGNAL(
searchChanged()),
this, SLOT(slotSearchChanged()) );
73 connect( m_caseSensitive, SIGNAL(changed()),
this, SIGNAL(
searchChanged()) );
74 connect( m_wholeWordsOnly, SIGNAL(changed()),
this, SIGNAL(
searchChanged()) );
75 connect( m_fromCursor, SIGNAL(changed()),
this, SIGNAL(
searchChanged()) );
76 connect( m_regExp, SIGNAL(changed()),
this, SIGNAL(
searchChanged()) );
77 connect( m_findLinksOnly, SIGNAL(changed()),
this, SIGNAL(
searchChanged()) );
84 return d->m_find->historyItems();
91 if (
d->m_caseSensitive->isChecked())
93 if (
d->m_wholeWordsOnly->isChecked())
95 if (
d->m_fromCursor->isChecked())
97 if (
d->m_selectedText->isChecked())
99 if (
d->m_regExp->isChecked())
101 if (
d->m_findLinksOnly->isChecked())
108 return m_find->currentText();
111 void KHTMLFindBar::slotSearchChanged()
115 d->m_find->setPalette(QPalette());
116 m_next->setDisabled(
true );
117 m_previous->setDisabled(
true );
118 m_statusLabel->clear();
121 m_next->setDisabled(
false );
122 m_previous->setDisabled(
false );
128 if (
d->m_find->historyItems().isEmpty())
130 d->m_find->lineEdit()->setText(
d->m_find->historyItems().first() );
136 if (strings.count() > 0)
138 d->m_find->setHistoryItems(strings,
true);
143 d->m_find->clearHistory();
149 else d->m_enabled &= ~
KFind::SelectedText;
150 d->m_selectedText->setEnabled( hasSelection );
153 d->m_selectedText->setChecked(
false );
154 slotSelectedTextToggled( hasSelection );
158 void KHTMLFindBar::slotAddPatternToHistory()
160 bool patternIsEmpty =
pattern().isEmpty();
161 if (!patternIsEmpty || !m_prevPattern.isEmpty()) {
162 d->m_find->addToHistory(
pattern().isEmpty() ? m_prevPattern :
pattern());
163 if (patternIsEmpty && !
pattern().isEmpty()) {
166 bool sb =
d->m_find->blockSignals(
true);
167 d->m_find->lineEdit()->setText(QString());
168 d->m_find->blockSignals(sb);
170 m_prevPattern.clear();
174 void KHTMLFindBar::slotSelectedTextToggled(
bool selec)
179 m_fromCursor->setChecked(
false );
185 else d->m_enabled &= ~
KFind::FromCursor;
186 d->m_fromCursor->setEnabled( hasCursor );
203 m_find->setPalette(QPalette());
204 m_next->setDisabled(
true );
205 m_previous->setDisabled(
true );
206 m_statusLabel->clear();
207 }
else if ( !match ) {
208 QPalette newPal( m_find->palette() );
210 m_find->setPalette(newPal);
211 m_statusLabel->setText(
i18n(
"Not found"));
213 QPalette newPal( m_find->palette() );
215 m_find->setPalette(newPal);
216 m_statusLabel->clear();
222 if (atEnd == m_atEnd)
225 m_statusLabel->setText(
i18n(
"No more matches for this search direction." ) );
227 m_statusLabel->clear();
234 KHTMLViewBarWidget::setVisible( visible );
237 m_find->setFocus( Qt::ActiveWindowFocusReason );
238 m_find->lineEdit()->selectAll();
248 if (e->type() == QEvent::ShortcutOverride) {
249 QKeyEvent* kev =
static_cast<QKeyEvent*
>(e);
250 if (kev->key() == Qt::Key_Escape) {
256 return KHTMLViewBarWidget::event(e);
void setFoundMatch(bool match)
QString i18n(const char *text)
bool restoreLastPatternFromHistory()
void setFindHistory(const QStringList &history)
Provide the list of strings to be displayed as the history of find strings.
void setHasCursor(bool hasCursor)
Hide/show the 'from cursor' option, depending on whether the application implements a cursor...
This class is khtml's main class.
KHTMLFindBar(QWidget *parent=0)
QString pattern() const
Returns the pattern to find.
QStringList findHistory() const
Returns the list of history items.
void setOptions(long options)
Set the options which are checked.
void setAtEnd(bool atEnd)
virtual void setVisible(bool visible)
void setHasSelection(bool hasSelection)
Enable/disable the 'search in selection' option, depending on whether there actually is a selection...
void findPreviousClicked()
static void adjustBackground(QPalette &, BackgroundRole newRole=NormalBackground, QPalette::ColorRole color=QPalette::Base, ColorSet set=View, KSharedConfigPtr=KSharedConfigPtr())
long options() const
Returns the state of the options.
virtual bool event(QEvent *e)