Add shortcuts for Previous/Next actions on Article search (Ctrl + F)

This commit is contained in:
Julian Depetris Chauvin 2011-06-29 16:12:46 -03:00
parent 0726b90f30
commit 5f97db0449
5 changed files with 52 additions and 19 deletions

View file

@ -1378,6 +1378,11 @@ bool ArticleView::closeSearch()
return false;
}
bool ArticleView::isSearchOpened()
{
return searchIsOpened;
}
void ArticleView::showEvent( QShowEvent * ev )
{
QFrame::showEvent( ev );

View file

@ -144,6 +144,8 @@ public:
/// wasn't open.
bool closeSearch();
bool isSearchOpened();
/// Jumps to the article specified by the dictionary id,
/// by executing a javascript code.
void jumpToDictionary( QString const & );
@ -173,6 +175,11 @@ signals:
/// switch focus to word input.
void typingEvent( QString const & text );
public slots:
void on_searchPrevious_clicked();
void on_searchNext_clicked();
private slots:
void loadFinished( bool ok );
@ -195,8 +202,6 @@ private slots:
/// 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();

View file

@ -30,6 +30,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
groupList( &searchPaneTitleBar ),
foundInDictsLabel( &dictsPaneTitleBar ),
escAction( this ),
f3Action( this ),
shiftF3Action( this ),
focusTranslateLineAction( this ),
addTabAction( this ),
closeCurrentTabAction( this ),
@ -165,6 +167,20 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
connect( &escAction, SIGNAL( triggered() ),
this, SLOT( handleEsc() ) );
f3Action.setShortcutContext( Qt::ApplicationShortcut );
f3Action.setShortcut( QKeySequence( "F3" ) );
connect( &f3Action, SIGNAL( triggered() ),
this, SLOT( handleF3() ) );
addAction( &f3Action );
shiftF3Action.setShortcutContext( Qt::WidgetWithChildrenShortcut );
shiftF3Action.setShortcut( QKeySequence( "Shift+F3" ) );
connect( &shiftF3Action, SIGNAL( triggered() ),
this, SLOT( handleShiftF3() ) );
addAction( &shiftF3Action );
focusTranslateLineAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
focusTranslateLineAction.setShortcuts( QList< QKeySequence >() <<
QKeySequence( "Alt+D" ) <<
@ -1322,6 +1338,24 @@ void MainWindow::handleEsc()
focusTranslateLine();
}
void MainWindow::handleF3()
{
ArticleView & view = dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) );
if( view.isSearchOpened() )
view.on_searchNext_clicked();
else
editDictionaries();
}
void MainWindow::handleShiftF3()
{
ArticleView & view = dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) );
if( view.isSearchOpened() )
view.on_searchPrevious_clicked();
}
void MainWindow::focusTranslateLine()
{
if ( ui.searchPane->isFloating() )

View file

@ -69,7 +69,7 @@ private:
/// Fonts saved before words zooming is in effect, so it could be reset back.
QFont wordListDefaultFont, translateLineDefaultFont;
QAction escAction, focusTranslateLineAction, addTabAction, closeCurrentTabAction,
QAction escAction, f3Action, shiftF3Action, focusTranslateLineAction, addTabAction, closeCurrentTabAction,
closeAllTabAction, closeRestTabAction,
switchToNextTabAction, switchToPrevTabAction,
showDictBarNamesAction, useSmallIconsInToolbarsAction, toggleMenuBarAction;
@ -241,6 +241,10 @@ private slots:
/// Closes any opened search in the article view, and focuses the translateLine/close main window to tray.
void handleEsc();
/// Either triggers Edit Dictionaries menu option or perform a Find Next action.
void handleF3();
void handleShiftF3();
/// Gives the keyboard focus to the translateLine and selects all the text
/// it has.
void focusTranslateLine();

View file

@ -281,22 +281,7 @@
<normaloff>:/icons/book.png</normaloff>:/icons/book.png</iconset>
</property>
<property name="text">
<string>&amp;Dictionaries...</string>
</property>
<property name="shortcut">
<string>F3</string>
</property>
</action>
<action name="groups">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/playsound.png</normaloff>:/icons/playsound.png</iconset>
</property>
<property name="text">
<string>&amp;Groups...</string>
</property>
<property name="shortcut">
<string>F3</string>
<string>&amp;Dictionaries... F3</string>
</property>
</action>
<action name="preferences">