Changeset View
Changeset View
Standalone View
Standalone View
krusader/Panel/krsearchbar.cpp
Show First 20 Lines • Show All 165 Lines • ▼ Show 20 Line(s) | 165 | case MODE_FILTER: { | |||
---|---|---|---|---|---|
166 | const bool anyMatch =_view->op()->filterSearch(text, caseSensitive()); | 166 | const bool anyMatch =_view->op()->filterSearch(text, caseSensitive()); | ||
167 | indicateMatch(anyMatch); | 167 | indicateMatch(anyMatch); | ||
168 | break; | 168 | break; | ||
169 | } | 169 | } | ||
170 | default: | 170 | default: | ||
171 | krOut << "unexpected search mode: " << _currentMode; | 171 | krOut << "unexpected search mode: " << _currentMode; | ||
172 | } | 172 | } | ||
173 | 173 | | |||
174 | if (!text.isEmpty()) | | |||
175 | // needed to show where the cursor is now | | |||
176 | _view->widget()->setFocus(); | | |||
177 | else | | |||
178 | _textBox->setFocus(); | 174 | _textBox->setFocus(); | ||
179 | } | 175 | } | ||
180 | 176 | | |||
181 | void KrSearchBar::saveSearchString() | 177 | void KrSearchBar::saveSearchString() | ||
182 | { | 178 | { | ||
183 | KConfigGroup group(krConfig, "Private"); | 179 | KConfigGroup group(krConfig, "Private"); | ||
184 | QStringList lst = group.readEntry("Predefined Selections", QStringList()); | 180 | QStringList lst = group.readEntry("Predefined Selections", QStringList()); | ||
185 | QString searchString = _textBox->currentText(); | 181 | QString searchString = _textBox->currentText(); | ||
186 | if (lst.indexOf(searchString) != -1) { | 182 | if (lst.indexOf(searchString) != -1) { | ||
187 | // already saved | 183 | // already saved | ||
188 | return; | 184 | return; | ||
189 | } | 185 | } | ||
190 | 186 | | |||
191 | lst.append(searchString); | 187 | lst.append(searchString); | ||
192 | group.writeEntry("Predefined Selections", lst); | 188 | group.writeEntry("Predefined Selections", lst); | ||
193 | 189 | | |||
194 | _textBox->addItem(searchString); | 190 | _textBox->addItem(searchString); | ||
195 | QToolTip::showText(QCursor::pos(), i18n("Saved search text to history")); | 191 | QToolTip::showText(QCursor::pos(), i18n("Saved search text to history")); | ||
196 | } | 192 | } | ||
197 | 193 | | |||
198 | // #### protected | 194 | // #### protected | ||
199 | 195 | | |||
200 | void KrSearchBar::keyPressEvent(QKeyEvent *event) | 196 | void KrSearchBar::keyPressEvent(QKeyEvent *event) | ||
201 | { | 197 | { | ||
202 | bool handled = handleKeyPressEvent(static_cast<QKeyEvent*>(event)); | 198 | const bool handled = handleKeyPressEvent(static_cast<QKeyEvent*>(event)); | ||
203 | if(handled) { | 199 | if (handled) { | ||
204 | return; | 200 | return; | ||
205 | } | 201 | } | ||
206 | 202 | | |||
207 | QWidget::keyPressEvent(event); | 203 | QWidget::keyPressEvent(event); | ||
208 | } | 204 | } | ||
209 | 205 | | |||
210 | bool KrSearchBar::eventFilter(QObject *watched, QEvent *event) | 206 | bool KrSearchBar::eventFilter(QObject *watched, QEvent *event) | ||
211 | { | 207 | { | ||
212 | if(event->type() != QEvent::ShortcutOverride && watched == _view->widget()) { | 208 | if (event->type() != QEvent::ShortcutOverride && watched == _view->widget()) { | ||
213 | QKeyEvent *ke = static_cast<QKeyEvent*>(event); | 209 | QKeyEvent *ke = static_cast<QKeyEvent *>(event); | ||
214 | // overwrite "escape" shortcut if bar is shown | 210 | // overwrite "escape" shortcut if bar is shown | ||
215 | if ((ke->key() == Qt::Key_Escape) && (ke->modifiers() == Qt::NoModifier) && !isHidden()) { | 211 | if ((ke->key() == Qt::Key_Escape) && (ke->modifiers() == Qt::NoModifier) && !isHidden()) { | ||
216 | ke->accept(); | 212 | ke->accept(); | ||
217 | handleKeyPressEvent(ke); | 213 | handleKeyPressEvent(ke); | ||
218 | return true; | 214 | return true; | ||
219 | } | 215 | } | ||
220 | } | 216 | } | ||
221 | 217 | | |||
222 | if(event->type() != QEvent::KeyPress) { | 218 | if (event->type() != QEvent::KeyPress) { | ||
223 | return false; | 219 | return false; | ||
224 | } | 220 | } | ||
225 | 221 | | |||
226 | QKeyEvent *ke = static_cast<QKeyEvent*>(event); | 222 | QKeyEvent *ke = static_cast<QKeyEvent *>(event); | ||
227 | if (watched == _view->widget()) { | 223 | if (watched == _view->widget()) { | ||
228 | KConfigGroup grpSv(krConfig, "Look&Feel"); | 224 | KConfigGroup grpSv(krConfig, "Look&Feel"); | ||
229 | bool autoShow = grpSv.readEntry("New Style Quicksearch", _NewStyleQuicksearch); | 225 | const bool autoShow = grpSv.readEntry("New Style Quicksearch", _NewStyleQuicksearch); | ||
230 | 226 | | |||
231 | if (isHidden() && !autoShow) { | 227 | if (isHidden() && !autoShow) { | ||
232 | return false; | 228 | return false; | ||
233 | } | 229 | } | ||
234 | 230 | | |||
235 | if(!isHidden()) { | 231 | if (!isHidden()) { | ||
236 | bool handled = handleKeyPressEvent(ke); | 232 | const bool handled = handleKeyPressEvent(ke); | ||
237 | if (handled) { | 233 | if (handled) { | ||
238 | return true; | 234 | return true; | ||
239 | } | 235 | } | ||
240 | } | 236 | } | ||
241 | 237 | | |||
242 | if (isHidden() || | 238 | if (isHidden() || | ||
243 | // handle by search bar if user wants to remove text or... | 239 | // view can handle its own event if user does not want to remove text or... | ||
244 | !((ke->key() == Qt::Key_Backspace && !_textBox->currentText().isEmpty()) || | 240 | !((ke->key() == Qt::Key_Backspace && !_textBox->currentText().isEmpty()) || | ||
245 | // ... insert space in it (even if not focused) | 241 | // ...insert space in search bar (even if not focused) | ||
246 | (ke->key() == Qt::Key_Space && _currentMode == KrSearchBar::MODE_SEARCH))){ | 242 | (ke->key() == Qt::Key_Space && _currentMode == KrSearchBar::MODE_SEARCH))) { | ||
247 | // give the view a chance to handle its own event | 243 | const bool handled = _view->handleKeyEvent(ke); | ||
248 | bool handled = _view->handleKeyEvent(ke); | | |||
249 | if(handled) { | 244 | if (handled) { | ||
250 | return true; | 245 | return true; | ||
251 | } | 246 | } | ||
252 | } | 247 | } | ||
253 | 248 | | |||
254 | if (ke->text().isEmpty() || (ke->modifiers() != Qt::NoModifier && | 249 | if (ke->text().isEmpty() || (ke->modifiers() != Qt::NoModifier && | ||
255 | ke->modifiers() != Qt::ShiftModifier)) { | 250 | ke->modifiers() != Qt::ShiftModifier)) { | ||
256 | return false; | 251 | return false; | ||
257 | } | 252 | } | ||
258 | 253 | | |||
259 | // start searching if bar is hidden? | 254 | // start searching if bar is hidden? | ||
260 | if (isHidden()){ | 255 | if (isHidden()) { | ||
261 | if (autoShow) { | 256 | if (autoShow) { | ||
262 | showBar(); | 257 | showBar(); | ||
263 | } else { | 258 | } else { | ||
264 | return false; | 259 | return false; | ||
265 | } | 260 | } | ||
266 | } | 261 | } | ||
267 | 262 | | |||
268 | // bar is visible and gets the key input | 263 | // bar is visible and gets the key input | ||
269 | _textBox->setFocus(); | 264 | _textBox->setFocus(); | ||
270 | if (ke->key() == Qt::Key_Backspace) { | 265 | if (ke->key() == Qt::Key_Backspace) { | ||
271 | _textBox->lineEdit()->backspace(); | 266 | _textBox->lineEdit()->backspace(); | ||
272 | } else { | 267 | } else { | ||
273 | _textBox->setEditText(_textBox->currentText().append(ke->text())); | 268 | _textBox->setEditText(_textBox->currentText().append(ke->text())); | ||
274 | } | 269 | } | ||
275 | return true; | 270 | return true; | ||
276 | } else if (watched == _textBox) { | 271 | } else if (watched == _textBox) { | ||
277 | // allow the view to handle (some) key events from the text box | 272 | // allow the view to handle (most) key events from the text box | ||
278 | if (ke->modifiers() == Qt::NoModifier && | 273 | if (ke->modifiers() == Qt::NoModifier && | ||
279 | ke->key() != Qt::Key_Space && | 274 | ke->key() != Qt::Key_Space && | ||
280 | ke->key() != Qt::Key_Backspace && | 275 | ke->key() != Qt::Key_Backspace && | ||
281 | ke->key() != Qt::Key_Left && | 276 | ke->key() != Qt::Key_Left && | ||
282 | ke->key() != Qt::Key_Right) { | 277 | ke->key() != Qt::Key_Right) { | ||
283 | bool handled = _view->handleKeyEvent(ke); | 278 | bool handled = _view->handleKeyEvent(ke); | ||
284 | if(handled) { | 279 | if (handled) { | ||
285 | _view->widget()->setFocus(); | 280 | _view->widget()->setFocus(); | ||
286 | return true; | 281 | return true; | ||
287 | } | 282 | } | ||
288 | } | 283 | } | ||
289 | } | 284 | } | ||
290 | return false; | 285 | return false; | ||
291 | } | 286 | } | ||
292 | 287 | | |||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
339 | } | 334 | } | ||
340 | 335 | | |||
341 | bool KrSearchBar::handleUpDownKeyPress(bool up) | 336 | bool KrSearchBar::handleUpDownKeyPress(bool up) | ||
342 | { | 337 | { | ||
343 | if (_currentMode != MODE_SEARCH) { | 338 | if (_currentMode != MODE_SEARCH) { | ||
344 | return false; | 339 | return false; | ||
345 | } | 340 | } | ||
346 | 341 | | |||
347 | bool updownCancel = KConfigGroup(krConfig, "Look&Feel") | 342 | const bool updownCancel = KConfigGroup(krConfig, "Look&Feel") | ||
348 | .readEntry("Up/Down Cancels Quicksearch", false); | 343 | .readEntry("Up/Down Cancels Quicksearch", false); | ||
349 | if(updownCancel) { | 344 | if (updownCancel) { | ||
350 | hideBar(); | 345 | hideBar(); | ||
351 | return false; | 346 | return false; | ||
352 | } | 347 | } | ||
353 | 348 | | |||
354 | bool anyMatch = _view->op()->searchItem(_textBox->currentText(), caseSensitive(), up ? -1 : 1); | 349 | const bool anyMatch = _view->op()->searchItem(_textBox->currentText(), caseSensitive(), up ? -1 : 1); | ||
355 | indicateMatch(anyMatch); | 350 | indicateMatch(anyMatch); | ||
356 | return true; | 351 | return true; | ||
357 | } | 352 | } | ||
358 | 353 | | |||
359 | void KrSearchBar::indicateMatch(bool anyMatch) | 354 | void KrSearchBar::indicateMatch(bool anyMatch) | ||
360 | { | 355 | { | ||
361 | KConfigGroup gc(krConfig, "Colors"); | 356 | KConfigGroup gc(krConfig, "Colors"); | ||
362 | QPalette p = QGuiApplication::palette(); | 357 | QPalette p = QGuiApplication::palette(); | ||
Show All 36 Lines |