opt: Ctrl+F page search remove highlight checkbox

This commit is contained in:
Xiao Yi Fang 2024-06-14 16:33:39 +08:00
parent a767f3f030
commit 4bb4ff38c9
4 changed files with 5 additions and 39 deletions

View file

@ -141,7 +141,6 @@ ArticleView::ArticleView( QWidget * parent,
connect( searchPanel->next, &QPushButton::clicked, this, &ArticleView::on_searchNext_clicked );
connect( searchPanel->close, &QPushButton::clicked, this, &ArticleView::on_searchCloseButton_clicked );
connect( searchPanel->caseSensitive, &QPushButton::clicked, this, &ArticleView::on_searchCaseSensitive_clicked );
connect( searchPanel->highlightAll, &QPushButton::clicked, this, &ArticleView::on_highlightAllButton_clicked );
connect( searchPanel->lineEdit, &QLineEdit::textEdited, this, &ArticleView::on_searchText_textEdited );
connect( searchPanel->lineEdit, &QLineEdit::returnPressed, this, &ArticleView::on_searchText_returnPressed );
connect( ftsSearchPanel->next, &QPushButton::clicked, this, &ArticleView::on_ftsSearchNext_clicked );
@ -398,8 +397,6 @@ void ArticleView::showDefinition( QString const & word,
// Any search opened is probably irrelevant now
closeSearch();
// Clear highlight all button selection
searchPanel->highlightAll->setChecked( false );
webview->setCursor( Qt::WaitCursor );
load( req );
@ -1995,11 +1992,6 @@ void ArticleView::on_searchCaseSensitive_clicked()
performFindOperation( true, false );
}
void ArticleView::on_highlightAllButton_clicked()
{
performFindOperation( false, false, true );
}
//the id start with "gdform-"
void ArticleView::onJsActiveArticleChanged( QString const & id )
{
@ -2045,31 +2037,13 @@ void ArticleView::doubleClicked( QPoint pos )
}
void ArticleView::performFindOperation( bool restart, bool backwards, bool checkHighlight )
void ArticleView::performFindOperation( bool restart, bool backwards )
{
QString text = searchPanel->lineEdit->text();
if ( restart || checkHighlight ) {
if ( restart ) {
// Anyone knows how we reset the search position?
// For now we resort to this hack:
if ( webview->selectedText().size() ) {
webview->page()->runJavaScript( "window.getSelection().removeAllRanges();_=0;" );
}
}
QWebEnginePage::FindFlags f( 0 );
if ( searchPanel->caseSensitive->isChecked() )
f |= QWebEnginePage::FindCaseSensitively;
webview->findText( "", f );
if ( searchPanel->highlightAll->isChecked() )
webview->findText( text, f );
if ( checkHighlight )
return;
if ( restart ) {
// Clear any current selection
webview->findText( "" );
}
QWebEnginePage::FindFlags f( 0 );

View file

@ -363,7 +363,6 @@ private slots:
void on_searchText_returnPressed();
void on_searchCloseButton_clicked();
void on_searchCaseSensitive_clicked();
void on_highlightAllButton_clicked();
void on_ftsSearchPrevious_clicked();
void on_ftsSearchNext_clicked();
@ -412,7 +411,7 @@ private:
bool eventFilter( QObject * obj, QEvent * ev ) override;
void performFindOperation( bool restart, bool backwards, bool checkHighlight = false );
void performFindOperation( bool restart, bool backwards );
/// Returns the comma-separated list of dictionary ids which should be muted
/// for the given group. If there are none, returns empty string.

View file

@ -20,11 +20,6 @@ SearchPanel::SearchPanel( QWidget * parent ):
next->setText( tr( "&Next" ) );
next->setShortcut( QKeySequence( tr( "Ctrl+G" ) ) );
highlightAll = new QCheckBox( this );
highlightAll->setIcon( QIcon( ":/icons/highlighter.png" ) );
highlightAll->setText( tr( "Highlight &all" ) );
highlightAll->setChecked( true );
caseSensitive = new QCheckBox( this );
caseSensitive->setText( tr( "&Case Sensitive" ) );
@ -38,7 +33,6 @@ SearchPanel::SearchPanel( QWidget * parent ):
auto * buttonsRow = new QHBoxLayout();
buttonsRow->addWidget( previous );
buttonsRow->addWidget( next );
buttonsRow->addWidget( highlightAll );
buttonsRow->addWidget( caseSensitive );
buttonsRow->addStretch();

View file

@ -16,7 +16,6 @@ public:
QPushButton * close;
QPushButton * previous;
QPushButton * next;
QCheckBox * highlightAll;
QCheckBox * caseSensitive;
};