+ 'Text Find' implemented.

This commit is contained in:
Konstantin Isakov 2009-05-16 11:14:43 +00:00
parent b14a6271d9
commit 22fb1d2f5f
7 changed files with 202 additions and 3 deletions

View file

@ -36,6 +36,8 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm,
pasteAction( this ),
articleUpAction( this ),
articleDownAction( this ),
openSearchAction( this ),
searchIsOpened( false ),
groupComboBox( groupComboBox_ )
{
ui.setupUi( this );
@ -82,6 +84,10 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm,
ui.definition->addAction( &articleDownAction );
connect( &articleDownAction, SIGNAL( triggered() ), this, SLOT( moveOneArticleDown() ) );
openSearchAction.setShortcut( QKeySequence( "Ctrl+F" ) );
ui.definition->addAction( &openSearchAction );
connect( &openSearchAction, SIGNAL( triggered() ), this, SLOT( openSearch() ) );
ui.definition->installEventFilter( this );
// Load the default blank page instantly, so there would be no flicker.
@ -782,9 +788,107 @@ void ArticleView::moveOneArticleDown()
}
}
void ArticleView::openSearch()
{
if ( !searchIsOpened )
{
ui.searchFrame->show();
ui.searchText->setText( getTitle() );
searchIsOpened = true;
}
ui.searchText->setFocus();
ui.searchText->selectAll();
// Clear any current selection
if ( ui.definition->selectedText().size() )
{
ui.definition->triggerPageAction( QWebPage::SelectAll );
ui.definition->triggerPageAction( QWebPage::SelectStartOfDocument );
}
if ( ui.searchText->property( "noResults" ).toBool() )
{
ui.searchText->setProperty( "noResults", false );
qApp->setStyleSheet( qApp->styleSheet() );
}
}
void ArticleView::on_searchPrevious_clicked()
{
performFindOperation( false, true );
}
void ArticleView::on_searchNext_clicked()
{
performFindOperation( false, false );
}
void ArticleView::on_searchText_textEdited()
{
performFindOperation( true, false );
}
void ArticleView::on_searchText_returnPressed()
{
on_searchNext_clicked();
}
void ArticleView::on_searchCloseButton_clicked()
{
closeSearch();
}
void ArticleView::performFindOperation( bool restart, bool backwards )
{
QString text = ui.searchText->text();
if ( restart )
{
// Anyone knows how we reset the search position?
// For now we resort to this hack:
if ( ui.definition->selectedText().size() )
{
ui.definition->triggerPageAction( QWebPage::SelectAll );
ui.definition->triggerPageAction( QWebPage::SelectStartOfDocument );
}
}
QWebPage::FindFlags f( 0 );
if ( ui.searchCaseSensitive->isChecked() )
f |= QWebPage::FindCaseSensitively;
if ( backwards )
f |= QWebPage::FindBackward;
bool setMark = text.size() && !ui.definition->findText( text, f );
if ( ui.searchText->property( "noResults" ).toBool() != setMark )
{
ui.searchText->setProperty( "noResults", setMark );
qApp->setStyleSheet( qApp->styleSheet() );
}
}
bool ArticleView::closeSearch()
{
if ( searchIsOpened )
{
ui.searchFrame->hide();
ui.definition->setFocus();
searchIsOpened = false;
return true;
}
else
return false;
}
void ArticleView::showEvent( QShowEvent * ev )
{
QFrame::showEvent( ev );
ui.searchFrame->hide();
if ( !searchIsOpened )
ui.searchFrame->hide();
}

View file

@ -26,7 +26,8 @@ class ArticleView: public QFrame
Ui::ArticleView ui;
QAction pasteAction, articleUpAction, articleDownAction;
QAction pasteAction, articleUpAction, articleDownAction, openSearchAction;
bool searchIsOpened;
#ifdef Q_OS_WIN32
// Used in Windows only
@ -113,6 +114,10 @@ public:
/// Prints current article
void print( QPrinter * ) const;
/// Closes search if it's open and returns true. Returns false if it
/// wasn't open.
bool closeSearch();
signals:
@ -152,6 +157,15 @@ private slots:
/// Nagivates to the next article relative to the active one.
void moveOneArticleDown();
/// Opens the search area
void openSearch();
void on_searchPrevious_clicked();
void on_searchNext_clicked();
void on_searchText_textEdited();
void on_searchText_returnPressed();
void on_searchCloseButton_clicked();
private:
/// Deduces group from the url. If there doesn't seem to be any group,
@ -174,6 +188,8 @@ private:
bool eventFilter( QObject * obj, QEvent * ev );
void performFindOperation( bool restart, bool backwards );
protected:
// We need this to hide the search bar when we're showed

View file

@ -58,6 +58,13 @@
<property name="text">
<string>x</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/closetab.png</normaloff>:/icons/closetab.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
@ -70,6 +77,50 @@
<item>
<widget class="QLineEdit" name="searchText"/>
</item>
<item>
<widget class="QToolButton" name="searchPrevious">
<property name="text">
<string>&amp;Previous</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/previous.png</normaloff>:/icons/previous.png</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="searchNext">
<property name="text">
<string>&amp;Next</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/next.png</normaloff>:/icons/next.png</iconset>
</property>
<property name="shortcut">
<string>Ctrl+G</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="searchCaseSensitive">
<property name="text">
<string>&amp;Case Sensitive</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -95,6 +146,8 @@
<header>QtWebKit/QWebView</header>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -750,6 +750,9 @@ void MainWindow::translateInputFinished()
void MainWindow::focusTranslateLine()
{
if ( dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) ).closeSearch() )
return;
if ( ui.searchPane->isFloating() )
ui.searchPane->activateWindow();

View file

@ -8,6 +8,11 @@ MainWindow #centralWidget #translateLine[noResults="true"]
background: #febb7d;
}
ArticleView #searchText[noResults="true"]
{
background: #febb7d;
}
.ScanPopup #outerFrame
{
border: 1px solid grey;

View file

@ -25,6 +25,7 @@ ScanPopup::ScanPopup( QWidget * parent,
isScanningEnabled( false ),
allDictionaries( allDictionaries_ ),
groups( groups_ ),
escapeAction( this ),
wordFinder( this ),
mouseEnteredOnce( false ),
hideTimer( this )
@ -68,6 +69,11 @@ ScanPopup::ScanPopup( QWidget * parent,
setAttribute( Qt::WA_NoSystemBackground );
#endif
escapeAction.setShortcut( QKeySequence( "Esc" ) );
addAction( &escapeAction );
connect( &escapeAction, SIGNAL( triggered() ),
this, SLOT( escapePressed() ) );
connect( ui.groupList, SIGNAL( currentIndexChanged( QString const & ) ),
this, SLOT( currentGroupChanged( QString const & ) ) );
@ -499,3 +505,12 @@ void ScanPopup::pageLoaded( ArticleView * )
if ( cfg.preferences.pronounceOnLoadPopup )
definition->playSound();
}
void ScanPopup::escapePressed()
{
if ( !definition->closeSearch() )
{
unsetCursor();
hide();
}
}

View file

@ -52,6 +52,7 @@ private:
Instances::Groups const & groups;
Ui::ScanPopup ui;
ArticleView * definition;
QAction escapeAction;
QString pendingInputWord, inputWord;
WordFinder wordFinder;
@ -96,6 +97,8 @@ private slots:
void altModePoll();
void pageLoaded( ArticleView * );
void escapePressed();
};
#endif