mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
Add "Highlight all" to Article search (Ctrl + F)
This commit is contained in:
parent
0726b90f30
commit
c55061c302
10
article-style-search-selection.css
Normal file
10
article-style-search-selection.css
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
/* This stylesheet is used only to highligh current selection when doing a search.
|
||||||
|
It's programatically set/unset to restore default selection color (e.g. blue under Windows, orange under Ubuntu) */
|
||||||
|
|
||||||
|
/* highlight/select color in Windows when a widget is inactive is nearly impossible to read (light gray).
|
||||||
|
* then change it to green to use with the find option. */
|
||||||
|
::selection {
|
||||||
|
background: #23DC23;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
|
@ -214,6 +214,9 @@ void ArticleView::showDefinition( QString const & word, unsigned group,
|
||||||
// Any search opened is probably irrelevant now
|
// Any search opened is probably irrelevant now
|
||||||
closeSearch();
|
closeSearch();
|
||||||
|
|
||||||
|
// Clear highlight all button selection
|
||||||
|
ui.highlightAllButton->setChecked(false);
|
||||||
|
|
||||||
ui.definition->load( req );
|
ui.definition->load( req );
|
||||||
|
|
||||||
//QApplication::setOverrideCursor( Qt::WaitCursor );
|
//QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||||
|
@ -1291,6 +1294,16 @@ void ArticleView::on_searchCloseButton_clicked()
|
||||||
closeSearch();
|
closeSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ArticleView::on_searchCaseSensitive_clicked()
|
||||||
|
{
|
||||||
|
performFindOperation( false, false, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArticleView::on_highlightAllButton_clicked()
|
||||||
|
{
|
||||||
|
performFindOperation( false, false, true );
|
||||||
|
}
|
||||||
|
|
||||||
void ArticleView::doubleClicked()
|
void ArticleView::doubleClicked()
|
||||||
{
|
{
|
||||||
// We might want to initiate translation of the selected word
|
// We might want to initiate translation of the selected word
|
||||||
|
@ -1317,12 +1330,17 @@ void ArticleView::doubleClicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ArticleView::performFindOperation( bool restart, bool backwards )
|
void ArticleView::performFindOperation( bool restart, bool backwards, bool checkHighlight )
|
||||||
{
|
{
|
||||||
QString text = ui.searchText->text();
|
QString text = ui.searchText->text();
|
||||||
|
|
||||||
if ( restart )
|
//highlight in a non-default color current selection
|
||||||
|
if( ui.definition->settings()->userStyleSheetUrl().isEmpty() )
|
||||||
|
ui.definition->settings()->setUserStyleSheetUrl(QUrl::fromLocalFile( ":/article-style-search-selection.css" ));
|
||||||
|
|
||||||
|
if ( restart || checkHighlight )
|
||||||
{
|
{
|
||||||
|
if( restart ) {
|
||||||
// Anyone knows how we reset the search position?
|
// Anyone knows how we reset the search position?
|
||||||
// For now we resort to this hack:
|
// For now we resort to this hack:
|
||||||
if ( ui.definition->selectedText().size() )
|
if ( ui.definition->selectedText().size() )
|
||||||
|
@ -1334,6 +1352,22 @@ void ArticleView::performFindOperation( bool restart, bool backwards )
|
||||||
|
|
||||||
QWebPage::FindFlags f( 0 );
|
QWebPage::FindFlags f( 0 );
|
||||||
|
|
||||||
|
if ( ui.searchCaseSensitive->isChecked() )
|
||||||
|
f |= QWebPage::FindCaseSensitively;
|
||||||
|
|
||||||
|
f |= QWebPage::HighlightAllOccurrences;
|
||||||
|
|
||||||
|
ui.definition->findText( "", f );
|
||||||
|
|
||||||
|
if( ui.highlightAllButton->isChecked() )
|
||||||
|
ui.definition->findText( text, f );
|
||||||
|
|
||||||
|
if( checkHighlight )
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWebPage::FindFlags f( 0 );
|
||||||
|
|
||||||
if ( ui.searchCaseSensitive->isChecked() )
|
if ( ui.searchCaseSensitive->isChecked() )
|
||||||
f |= QWebPage::FindCaseSensitively;
|
f |= QWebPage::FindCaseSensitively;
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,8 @@ private slots:
|
||||||
void on_searchText_textEdited();
|
void on_searchText_textEdited();
|
||||||
void on_searchText_returnPressed();
|
void on_searchText_returnPressed();
|
||||||
void on_searchCloseButton_clicked();
|
void on_searchCloseButton_clicked();
|
||||||
|
void on_searchCaseSensitive_clicked();
|
||||||
|
void on_highlightAllButton_clicked();
|
||||||
|
|
||||||
/// Handles the double-click from the definition.
|
/// Handles the double-click from the definition.
|
||||||
void doubleClicked();
|
void doubleClicked();
|
||||||
|
@ -244,7 +246,7 @@ private:
|
||||||
|
|
||||||
bool eventFilter( QObject * obj, QEvent * ev );
|
bool eventFilter( QObject * obj, QEvent * ev );
|
||||||
|
|
||||||
void performFindOperation( bool restart, bool backwards );
|
void performFindOperation( bool restart, bool backwards, bool checkHighlight = false );
|
||||||
|
|
||||||
void reloadStyleSheet();
|
void reloadStyleSheet();
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,29 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="highlightAllButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Highlight &all</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/icons/highlighter.png</normaloff>:/icons/highlighter.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="toolButtonStyle">
|
||||||
|
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
void ArticleWebView::mousePressEvent( QMouseEvent * event )
|
void ArticleWebView::mousePressEvent( QMouseEvent * event )
|
||||||
{
|
{
|
||||||
|
//restore default color for selection
|
||||||
|
if( !this->settings()->userStyleSheetUrl().isEmpty() )
|
||||||
|
this->settings()->setUserStyleSheetUrl(QUrl());
|
||||||
|
|
||||||
if ( event->buttons() & Qt::MidButton )
|
if ( event->buttons() & Qt::MidButton )
|
||||||
midButtonPressed = true;
|
midButtonPressed = true;
|
||||||
|
|
||||||
|
|
BIN
icons/highlighter.png
Normal file
BIN
icons/highlighter.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 489 B |
|
@ -18,6 +18,7 @@
|
||||||
<file>icons/warning.png</file>
|
<file>icons/warning.png</file>
|
||||||
<file>article-style.css</file>
|
<file>article-style.css</file>
|
||||||
<file>article-style-print.css</file>
|
<file>article-style-print.css</file>
|
||||||
|
<file>article-style-search-selection.css</file>
|
||||||
<file>qt-style.css</file>
|
<file>qt-style.css</file>
|
||||||
<file>icons/icon32_dsl.png</file>
|
<file>icons/icon32_dsl.png</file>
|
||||||
<file>icons/icon32_stardict.png</file>
|
<file>icons/icon32_stardict.png</file>
|
||||||
|
@ -44,5 +45,6 @@
|
||||||
<file>icons/forvo.png</file>
|
<file>icons/forvo.png</file>
|
||||||
<file>icons/windows-list.png</file>
|
<file>icons/windows-list.png</file>
|
||||||
<file>CREDITS.txt</file>
|
<file>CREDITS.txt</file>
|
||||||
|
<file>icons/highlighter.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Loading…
Reference in a new issue