Merge pull request #482 from vedgy/shortcut_fixes_3

Third attempt to fix shortcuts and focus issues.
This commit is contained in:
Abs62 2014-05-11 05:06:46 -07:00
commit 3204e254fe
4 changed files with 73 additions and 45 deletions

View file

@ -823,7 +823,9 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev )
if ( keyEvent->key() == Qt::Key_Space || if ( keyEvent->key() == Qt::Key_Space ||
keyEvent->key() == Qt::Key_Backspace || keyEvent->key() == Qt::Key_Backspace ||
keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Tab ||
keyEvent->key() == Qt::Key_Backtab ) keyEvent->key() == Qt::Key_Backtab ||
keyEvent->key() == Qt::Key_Return ||
keyEvent->key() == Qt::Key_Enter )
return false; // Those key have other uses than to start typing return false; // Those key have other uses than to start typing
QString text = keyEvent->text(); QString text = keyEvent->text();

View file

@ -233,6 +233,18 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>searchLine</tabstop>
<tabstop>headwordsView</tabstop>
<tabstop>checkBoxDistanceBetweenWords</tabstop>
<tabstop>distanceBetweenWords</tabstop>
<tabstop>searchMode</tabstop>
<tabstop>checkBoxArticlesPerDictionary</tabstop>
<tabstop>articlesPerDictionary</tabstop>
<tabstop>matchCase</tabstop>
<tabstop>OKButton</tabstop>
<tabstop>cancelButton</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View file

@ -92,6 +92,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
toggleMenuBarAction( tr( "&Menubar" ), this ), toggleMenuBarAction( tr( "&Menubar" ), this ),
switchExpandModeAction( this ), switchExpandModeAction( this ),
focusHeadwordsDlgAction( this ), focusHeadwordsDlgAction( this ),
focusArticleViewAction( this ),
trayIconMenu( this ), trayIconMenu( this ),
addTab( this ), addTab( this ),
cfg( cfg_ ), cfg( cfg_ ),
@ -337,54 +338,21 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
connect( trayIconMenu.addAction( tr( "&Quit" ) ), SIGNAL( triggered() ), connect( trayIconMenu.addAction( tr( "&Quit" ) ), SIGNAL( triggered() ),
qApp, SLOT( quit() ) ); qApp, SLOT( quit() ) );
escAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); addGlobalAction( &escAction, SLOT( handleEsc() ) );
escAction.setShortcut( QKeySequence( "Esc" ) ); escAction.setShortcut( QKeySequence( "Esc" ) );
connect( &escAction, SIGNAL( triggered() ),
this, SLOT( handleEsc() ) );
focusTranslateLineAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); addGlobalAction( &focusTranslateLineAction, SLOT( focusTranslateLine() ) );
focusTranslateLineAction.setShortcuts( QList< QKeySequence >() << focusTranslateLineAction.setShortcuts( QList< QKeySequence >() <<
QKeySequence( "Alt+D" ) << QKeySequence( "Alt+D" ) <<
QKeySequence( "Ctrl+L" ) ); QKeySequence( "Ctrl+L" ) );
connect( &focusTranslateLineAction, SIGNAL( triggered() ), addGlobalAction( &focusHeadwordsDlgAction, SLOT( focusHeadwordsDialog() ) );
this, SLOT( focusTranslateLine() ) );
focusHeadwordsDlgAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
focusHeadwordsDlgAction.setShortcut( QKeySequence( "Ctrl+D" ) ); focusHeadwordsDlgAction.setShortcut( QKeySequence( "Ctrl+D" ) );
connect( &focusHeadwordsDlgAction, SIGNAL( triggered() ), addGlobalAction( &focusArticleViewAction, SLOT( focusArticleView() ) );
this, SLOT( focusHeadwordsDialog() ) ); focusArticleViewAction.setShortcut( QKeySequence( "Ctrl+N" ) );
ui.centralWidget->addAction( &escAction ); addGlobalAction( ui.fullTextSearchAction, SLOT( showFullTextSearchDialog() ) );
ui.dictsPane->addAction( &escAction );
ui.searchPaneWidget->addAction( &escAction );
ui.historyPane->addAction( &escAction );
groupList->addAction( &escAction );
translateBox->addAction( &escAction );
ui.centralWidget->addAction( &focusTranslateLineAction );
ui.dictsPane->addAction( &focusTranslateLineAction );
ui.searchPaneWidget->addAction( &focusTranslateLineAction );
ui.historyPane->addAction( &focusTranslateLineAction );
groupList->addAction( &focusTranslateLineAction );
ui.centralWidget->addAction( &focusHeadwordsDlgAction );
ui.dictsPane->addAction( &focusHeadwordsDlgAction );
ui.searchPaneWidget->addAction( &focusHeadwordsDlgAction );
ui.historyPane->addAction( &focusHeadwordsDlgAction );
groupList->addAction( &focusHeadwordsDlgAction );
translateBox->addAction( &focusHeadwordsDlgAction );
connect( ui.fullTextSearchAction, SIGNAL( triggered() ),
this, SLOT( showFullTextSearchDialog() ) );
ui.centralWidget->addAction( ui.fullTextSearchAction );
ui.dictsPane->addAction( ui.fullTextSearchAction );
ui.searchPaneWidget->addAction( ui.fullTextSearchAction );
ui.historyPane->addAction( ui.fullTextSearchAction );
groupList->addAction( ui.fullTextSearchAction );
translateBox->addAction( ui.fullTextSearchAction );
addTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); addTabAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
addTabAction.setShortcut( QKeySequence( "Ctrl+T" ) ); addTabAction.setShortcut( QKeySequence( "Ctrl+T" ) );
@ -969,6 +937,27 @@ MainWindow::~MainWindow()
commitData(); commitData();
} }
void MainWindow::addGlobalAction( QAction * action, const char * slot )
{
action->setShortcutContext( Qt::WidgetWithChildrenShortcut );
connect( action, SIGNAL( triggered() ), this, slot );
ui.centralWidget->addAction( action );
ui.dictsPane->addAction( action );
ui.searchPaneWidget->addAction( action );
ui.historyPane->addAction( action );
groupList->addAction( action );
translateBox->addAction( action );
}
void MainWindow::addGlobalActionsToDialog( QDialog * dialog )
{
dialog->addAction( &focusTranslateLineAction );
dialog->addAction( &focusHeadwordsDlgAction );
dialog->addAction( &focusArticleViewAction );
dialog->addAction( ui.fullTextSearchAction );
}
void MainWindow::commitData( QSessionManager & ) void MainWindow::commitData( QSessionManager & )
{ {
commitData(); commitData();
@ -3749,6 +3738,7 @@ void MainWindow::showDictionaryHeadwords( Dictionary::Class * dict )
if( headwordsDlg == 0 ) if( headwordsDlg == 0 )
{ {
headwordsDlg = new DictHeadwords( this, cfg, dict ); headwordsDlg = new DictHeadwords( this, cfg, dict );
addGlobalActionsToDialog( headwordsDlg );
connect( headwordsDlg, SIGNAL( headwordSelected( QString ) ), connect( headwordsDlg, SIGNAL( headwordSelected( QString ) ),
this, SLOT( wordReceived( QString ) ) ); this, SLOT( wordReceived( QString ) ) );
connect( headwordsDlg, SIGNAL( closeDialog() ), connect( headwordsDlg, SIGNAL( closeDialog() ),
@ -3772,7 +3762,22 @@ void MainWindow::closeHeadwordsDialog()
void MainWindow::focusHeadwordsDialog() void MainWindow::focusHeadwordsDialog()
{ {
if( headwordsDlg ) if( headwordsDlg )
{
headwordsDlg->activateWindow(); headwordsDlg->activateWindow();
if ( ftsDlg )
ftsDlg->lower();
}
}
void MainWindow::focusArticleView()
{
ArticleView * view = getCurrentArticleView();
if ( view )
{
if ( !isActiveWindow() )
activateWindow();
view->focus();
}
} }
void MainWindow::editDictionary( Dictionary::Class * dict ) void MainWindow::editDictionary( Dictionary::Class * dict )
@ -3988,6 +3993,7 @@ void MainWindow::showFullTextSearchDialog()
if( !ftsDlg ) if( !ftsDlg )
{ {
ftsDlg = new FTS::FullTextSearchDialog( this, cfg, dictionaries, groupInstances, ftsIndexing ); ftsDlg = new FTS::FullTextSearchDialog( this, cfg, dictionaries, groupInstances, ftsIndexing );
addGlobalActionsToDialog( ftsDlg );
connect( ftsDlg, SIGNAL( showTranslationFor( QString, QStringList, QRegExp ) ), connect( ftsDlg, SIGNAL( showTranslationFor( QString, QStringList, QRegExp ) ),
this, SLOT( showTranslationFor( QString, QStringList, QRegExp ) ) ); this, SLOT( showTranslationFor( QString, QStringList, QRegExp ) ) );
@ -3995,16 +4001,20 @@ void MainWindow::showFullTextSearchDialog()
this, SLOT( closeFullTextSearchDialog() ), Qt::QueuedConnection ); this, SLOT( closeFullTextSearchDialog() ), Qt::QueuedConnection );
connect( &configEvents, SIGNAL( mutedDictionariesChanged() ), connect( &configEvents, SIGNAL( mutedDictionariesChanged() ),
ftsDlg, SLOT( updateDictionaries() ) ); ftsDlg, SLOT( updateDictionaries() ) );
}
unsigned group = groupInstances.empty() ? 0 unsigned group = groupInstances.empty() ? 0
: groupInstances[ groupList->currentIndex() ].id; : groupInstances[ groupList->currentIndex() ].id;
ftsDlg->setCurrentGroup( group ); ftsDlg->setCurrentGroup( group );
}
if( !ftsDlg ->isVisible() ) if( !ftsDlg ->isVisible() )
ftsDlg->show(); ftsDlg->show();
else else
{
ftsDlg->activateWindow(); ftsDlg->activateWindow();
if ( headwordsDlg )
headwordsDlg->lower();
}
} }
void MainWindow::closeFullTextSearchDialog() void MainWindow::closeFullTextSearchDialog()

View file

@ -76,6 +76,8 @@ public slots:
void setExpandMode( bool expand ); void setExpandMode( bool expand );
private: private:
void addGlobalAction( QAction * action, const char * slot );
void addGlobalActionsToDialog( QDialog * dialog );
void commitData(); void commitData();
bool commitDataCompleted; bool commitDataCompleted;
@ -108,7 +110,7 @@ private:
closeAllTabAction, closeRestTabAction, closeAllTabAction, closeRestTabAction,
switchToNextTabAction, switchToPrevTabAction, switchToNextTabAction, switchToPrevTabAction,
showDictBarNamesAction, useSmallIconsInToolbarsAction, toggleMenuBarAction, showDictBarNamesAction, useSmallIconsInToolbarsAction, toggleMenuBarAction,
switchExpandModeAction, focusHeadwordsDlgAction; switchExpandModeAction, focusHeadwordsDlgAction, focusArticleViewAction;
QToolBar * navToolbar; QToolBar * navToolbar;
MainStatusBar * mainStatusBar; MainStatusBar * mainStatusBar;
QAction * navBack, * navForward, * navPronounce, * enableScanPopup; QAction * navBack, * navForward, * navPronounce, * enableScanPopup;
@ -418,6 +420,8 @@ private slots:
void focusHeadwordsDialog(); void focusHeadwordsDialog();
void focusArticleView();
void proxyAuthentication( const QNetworkProxy & proxy, QAuthenticator * authenticator ); void proxyAuthentication( const QNetworkProxy & proxy, QAuthenticator * authenticator );
void showFullTextSearchDialog(); void showFullTextSearchDialog();