Commit fa315eb5 authored by Marco Scarpetta's avatar Marco Scarpetta Committed by Albert Astals Cid

Allow to disable automatic search while typing

BUGS: 326522
REVIEW: 129956
parent 54436672
......@@ -298,6 +298,9 @@
<entry key="SearchFromCurrentPage" type="Bool">
<default>true</default>
</entry>
<entry key="FindAsYouType" type="Bool">
<default>true</default>
</entry>
</group>
<group name="Dlg Accessibility" >
<entry key="HighlightImages" type="Bool" >
......
......@@ -47,6 +47,7 @@ FindBar::FindBar( Okular::Document * document, QWidget * parent )
m_search->lineEdit()->setSearchId( PART_SEARCH_ID );
m_search->lineEdit()->setSearchColor( qRgb( 255, 255, 64 ) );
m_search->lineEdit()->setSearchMoveViewport( true );
m_search->lineEdit()->setFindAsYouType( false );
m_search->lineEdit()->setToolTip( i18n( "Text to search for" ) );
m_search->installEventFilter( this );
label->setBuddy( m_search->lineEdit() );
......@@ -68,6 +69,8 @@ FindBar::FindBar( Okular::Document * document, QWidget * parent )
m_caseSensitiveAct->setCheckable( true );
m_fromCurrentPageAct = optionsMenu->addAction( i18n( "From current page" ) );
m_fromCurrentPageAct->setCheckable( true );
m_findAsYouTypeAct = optionsMenu->addAction( i18n( "Find as you type" ) );
m_findAsYouTypeAct->setCheckable( true );
optionsBtn->setMenu( optionsMenu );
lay->addWidget( optionsBtn );
......@@ -76,9 +79,11 @@ FindBar::FindBar( Okular::Document * document, QWidget * parent )
connect( findPrevBtn, &QAbstractButton::clicked, this, &FindBar::findPrev );
connect( m_caseSensitiveAct, &QAction::toggled, this, &FindBar::caseSensitivityChanged );
connect( m_fromCurrentPageAct, &QAction::toggled, this, &FindBar::fromCurrentPageChanged );
connect( m_findAsYouTypeAct, &QAction::toggled, this, &FindBar::findAsYouTypeChanged );
m_caseSensitiveAct->setChecked( Okular::Settings::searchCaseSensitive() );
m_fromCurrentPageAct->setChecked( Okular::Settings::searchFromCurrentPage() );
m_findAsYouTypeAct->setChecked( Okular::Settings::findAsYouType() );
hide();
......@@ -173,6 +178,15 @@ void FindBar::fromCurrentPageChanged()
Okular::Settings::self()->save();
}
void FindBar::findAsYouTypeChanged()
{
m_search->lineEdit()->setFindAsYouType( m_findAsYouTypeAct->isChecked() );
if ( !m_active )
return;
Okular::Settings::setFindAsYouType( m_findAsYouTypeAct->isChecked() );
Okular::Settings::self()->save();
}
void FindBar::closeAndStopSearch()
{
if ( m_search->lineEdit()->isSearchRunning() )
......
......@@ -46,12 +46,14 @@ class FindBar
private Q_SLOTS:
void caseSensitivityChanged();
void fromCurrentPageChanged();
void findAsYouTypeChanged();
void closeAndStopSearch();
private:
SearchLineWidget * m_search;
QAction * m_caseSensitiveAct;
QAction * m_fromCurrentPageAct;
QAction * m_findAsYouTypeAct;
bool eventFilter( QObject *target, QEvent *event ) override;
bool m_active;
};
......
......@@ -28,7 +28,7 @@ SearchLineEdit::SearchLineEdit( QWidget * parent, Okular::Document * document )
m_caseSensitivity( Qt::CaseInsensitive ),
m_searchType( Okular::Document::AllDocument ), m_id( -1 ),
m_moveViewport( false ), m_changed( false ), m_fromStart( true ),
m_searchRunning( false )
m_findAsYouType( true ), m_searchRunning( false )
{
setObjectName( QStringLiteral( "SearchLineEdit" ) );
setClearButtonShown( true );
......@@ -100,6 +100,11 @@ void SearchLineEdit::setSearchFromStart( bool fromStart )
m_fromStart = fromStart;
}
void SearchLineEdit::setFindAsYouType( bool findAsYouType )
{
m_findAsYouType = findAsYouType;
}
void SearchLineEdit::resetSearch()
{
// Stop the currently running search, if any
......@@ -175,7 +180,11 @@ void SearchLineEdit::slotTextChanged( const QString & text )
Q_UNUSED(text);
prepareLineEditForSearch();
restartSearch();
if ( m_findAsYouType )
restartSearch();
else
m_changed = true;
}
void SearchLineEdit::prepareLineEditForSearch()
......
......@@ -36,6 +36,7 @@ class SearchLineEdit : public KLineEdit
void setSearchColor( const QColor &color );
void setSearchMoveViewport( bool move );
void setSearchFromStart( bool fromStart );
void setFindAsYouType( bool findAsYouType );
void resetSearch();
bool isSearchRunning() const;
......@@ -63,6 +64,7 @@ class SearchLineEdit : public KLineEdit
bool m_moveViewport;
bool m_changed;
bool m_fromStart;
bool m_findAsYouType;
bool m_searchRunning;
private Q_SLOTS:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment