From 76b7982f57255ce39cf39ee9168057861b1e5016 Mon Sep 17 00:00:00 2001 From: Fabio D'Urso Date: Thu, 12 Jul 2012 20:46:24 +0200 Subject: [PATCH] Keep the find bar working after ESC is pressed in PageView Instead of directly killing the search in the core, emit a signal caught by FindBar to tell its SearchLineEdit to reset the search operation. In this way, SearchLineEdit can set m_changed, and next time a new search operation will be started, instead of attempting to use the old one. --- part.cpp | 1 + ui/findbar.cpp | 5 +++++ ui/findbar.h | 1 + ui/pageview.cpp | 2 +- ui/pageview.h | 1 + ui/searchlineedit.cpp | 13 +++++++++++++ ui/searchlineedit.h | 1 + 7 files changed, 23 insertions(+), 1 deletion(-) diff --git a/part.cpp b/part.cpp index 83558c35e..30070f4b9 100644 --- a/part.cpp +++ b/part.cpp @@ -440,6 +440,7 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args connect( m_findBar, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(QKeyEvent*))); connect( m_miniBar, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(QKeyEvent*))); + connect( m_pageView, SIGNAL(escPressed()), m_findBar, SLOT(resetSearch()) ); connect( m_pageNumberTool, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(QKeyEvent*))); connect( m_reviewsWidget, SIGNAL(openAnnotationWindow(Okular::Annotation*,int)), diff --git a/ui/findbar.cpp b/ui/findbar.cpp index 745376ea1..f00f8833b 100644 --- a/ui/findbar.cpp +++ b/ui/findbar.cpp @@ -149,6 +149,11 @@ void FindBar::findPrev() m_search->lineEdit()->findPrev(); } +void FindBar::resetSearch() +{ + m_search->lineEdit()->resetSearch(); +} + void FindBar::caseSensitivityChanged() { m_search->lineEdit()->setSearchCaseSensitivity( m_caseSensitiveAct->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive ); diff --git a/ui/findbar.h b/ui/findbar.h index 2ee712f25..4db285572 100644 --- a/ui/findbar.h +++ b/ui/findbar.h @@ -40,6 +40,7 @@ class FindBar public slots: void findNext(); void findPrev(); + void resetSearch(); private slots: void caseSensitivityChanged(); diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 787311d5a..bf759a412 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -1642,7 +1642,7 @@ void PageView::keyPressEvent( QKeyEvent * e ) horizontalScrollBar()->triggerAction( QScrollBar::SliderSingleStepAdd ); break; case Qt::Key_Escape: - d->document->resetSearch( PART_SEARCH_ID ); + emit escPressed(); selectionClear( d->tableDividersGuessed ? ClearOnlyDividers : ClearAllSelection ); d->mousePressPos = QPoint(); if ( d->aPrevAction ) diff --git a/ui/pageview.h b/ui/pageview.h index bd9bdd967..438445f7a 100644 --- a/ui/pageview.h +++ b/ui/pageview.h @@ -131,6 +131,7 @@ Q_OBJECT signals: void urlDropped( const KUrl& ); void rightClick( const Okular::Page *, const QPoint & ); + void escPressed(); protected: void resizeEvent( QResizeEvent* ); diff --git a/ui/searchlineedit.cpp b/ui/searchlineedit.cpp index 4a3cc5636..787582158 100644 --- a/ui/searchlineedit.cpp +++ b/ui/searchlineedit.cpp @@ -90,6 +90,19 @@ void SearchLineEdit::setSearchFromStart( bool fromStart ) m_fromStart = fromStart; } +void SearchLineEdit::resetSearch() +{ + // Stop the currently running search, if any + stopSearch(); + + // Clear highlights + if ( m_id != -1 ) + m_document->resetSearch( m_id ); + + // Make sure that the search will be reset at the next one + m_changed = true; +} + bool SearchLineEdit::isSearchRunning() const { return m_searchRunning; diff --git a/ui/searchlineedit.h b/ui/searchlineedit.h index 5108f5a65..63ff4965b 100644 --- a/ui/searchlineedit.h +++ b/ui/searchlineedit.h @@ -36,6 +36,7 @@ class SearchLineEdit : public KLineEdit void setSearchColor( const QColor &color ); void setSearchMoveViewport( bool move ); void setSearchFromStart( bool fromStart ); + void resetSearch(); bool isSearchRunning() const;