From 964dd0d5bd08acd790276163c1941c8e25c21718 Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Tue, 27 Apr 2010 11:49:37 +0400 Subject: [PATCH] Toggling main window gives focus to the translation line. Additionally, any opened search is now closed once a new definition is shown in the article view. --- src/articleview.cc | 3 +++ src/mainwindow.cc | 25 +++++++++++++++++++++++-- src/mainwindow.hh | 5 ++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/articleview.cc b/src/articleview.cc index 062c4c77..9c5313c1 100644 --- a/src/articleview.cc +++ b/src/articleview.cc @@ -195,6 +195,9 @@ void ArticleView::showDefinition( QString const & word, unsigned group, // Update history saveHistoryUserData(); + // Any search opened is probably irrelevant now + closeSearch(); + ui.definition->load( req ); //QApplication::setOverrideCursor( Qt::WaitCursor ); diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 277f789f..d09d85ec 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -25,6 +25,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ): trayIcon( 0 ), groupLabel( &searchPaneTitleBar ), groupList( &searchPaneTitleBar ), + escAction( this ), focusTranslateLineAction( this ), addTabAction( this ), closeCurrentTabAction( this ), @@ -110,15 +111,22 @@ MainWindow::MainWindow( Config::Class & cfg_ ): connect( trayIconMenu.addAction( tr( "&Quit" ) ), SIGNAL( activated() ), qApp, SLOT( quit() ) ); + escAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); + escAction.setShortcut( QKeySequence( "Esc" ) ); + connect( &escAction, SIGNAL( triggered() ), + this, SLOT( handleEsc() ) ); + focusTranslateLineAction.setShortcutContext( Qt::WidgetWithChildrenShortcut ); focusTranslateLineAction.setShortcuts( QList< QKeySequence >() << - QKeySequence( "Esc" ) << QKeySequence( "Alt+D" ) << QKeySequence( "Ctrl+L" ) ); connect( &focusTranslateLineAction, SIGNAL( triggered() ), this, SLOT( focusTranslateLine() ) ); + ui.centralWidget->addAction( &escAction ); + ui.searchPaneWidget->addAction( &escAction ); + groupList.addAction( &escAction ); ui.centralWidget->addAction( &focusTranslateLineAction ); ui.searchPaneWidget->addAction( &focusTranslateLineAction ); groupList.addAction( &focusTranslateLineAction ); @@ -936,11 +944,16 @@ void MainWindow::translateInputFinished() } } -void MainWindow::focusTranslateLine() +void MainWindow::handleEsc() { if ( dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) ).closeSearch() ) return; + focusTranslateLine(); +} + +void MainWindow::focusTranslateLine() +{ if ( ui.searchPane->isFloating() ) ui.searchPane->activateWindow(); @@ -1281,11 +1294,14 @@ void MainWindow::showTranslationFor( QString const & inWord, void MainWindow::toggleMainWindow( bool onlyShow ) { + bool shown = false; + if ( !isVisible() ) { show(); activateWindow(); raise(); + shown = true; } else if ( isMinimized() ) @@ -1293,16 +1309,21 @@ void MainWindow::toggleMainWindow( bool onlyShow ) showNormal(); activateWindow(); raise(); + shown = true; } else if ( !isActiveWindow() ) { activateWindow(); raise(); + shown = true; } else if ( !onlyShow ) hide(); + + if ( shown ) + focusTranslateLine(); } void MainWindow::installHotKeys() diff --git a/src/mainwindow.hh b/src/mainwindow.hh index c6a2f9f5..956f462c 100644 --- a/src/mainwindow.hh +++ b/src/mainwindow.hh @@ -48,7 +48,7 @@ private: QLabel groupLabel; GroupComboBox groupList; - QAction focusTranslateLineAction, addTabAction, closeCurrentTabAction, + QAction escAction, focusTranslateLineAction, addTabAction, closeCurrentTabAction, switchToNextTabAction, switchToPrevTabAction, showDictBarNamesAction; QToolBar * navToolbar; QAction * navBack, * navForward, * navPronounce, * enableScanPopup; @@ -181,6 +181,9 @@ private slots: void translateInputChanged( QString const & ); void translateInputFinished(); + /// Closes any opened search in the article view, and focuses the translateLine. + void handleEsc(); + /// Gives the keyboard focus to the translateLine and selects all the text /// it has. void focusTranslateLine();