+ Pressing Enter in translateLine focuses on definition.

+ Typing any text key switches back to translateLine and puts it there.
This commit is contained in:
Konstantin Isakov 2009-05-12 13:25:18 +00:00
parent 806f8e4760
commit 25dce23d50
4 changed files with 45 additions and 0 deletions

View file

@ -10,6 +10,7 @@
#include <QDesktopServices>
#include <QWebHistory>
#include <QClipboard>
#include <QKeyEvent>
#include "folding.hh"
#include "wstring_qt.hh"
@ -63,6 +64,8 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm,
ui.definition->addAction( &pasteAction );
connect( &pasteAction, SIGNAL( triggered() ), this, SLOT( pasteTriggered() ) );
ui.definition->installEventFilter( this );
// Load the default blank page instantly, so there would be no flicker.
QString contentType;
@ -224,6 +227,29 @@ void ArticleView::cleanupTemp()
}
}
bool ArticleView::eventFilter( QObject * obj, QEvent * ev )
{
if ( obj == ui.definition )
{
if ( ev->type() == QEvent::KeyPress )
{
QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev );
QString text = keyEvent->text();
if ( text.size() )
{
emit typingEvent( text );
return true;
}
}
}
else
return QFrame::eventFilter( obj, ev );
return false;
}
void ArticleView::linkClicked( QUrl const & url )
{

View file

@ -120,6 +120,10 @@ signals:
void showDefinitionInNewTab( QString const & word, unsigned group,
QString const & fromArticle );
/// Emitted when user types a text key. This should typically be used to
/// switch focus to word input.
void typingEvent( QString const & text );
private slots:
void loadFinished( bool ok );
@ -152,6 +156,8 @@ private:
/// Attempts removing last temporary file created.
void cleanupTemp();
bool eventFilter( QObject * obj, QEvent * ev );
protected:
// We need this to hide the search bar when we're showed

View file

@ -499,6 +499,9 @@ ArticleView * MainWindow::createNewTab( bool switchToIt,
connect( view, SIGNAL( showDefinitionInNewTab( QString const &, unsigned, QString const & ) ),
this, SLOT( showDefinitionInNewTab( QString const &, unsigned, QString const & ) ) );
connect( view, SIGNAL( typingEvent( QString const & ) ),
this, SLOT( typingEvent( QString const & ) ) );
int index = cfg.preferences.newTabsOpenAfterCurrentOne ?
ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
@ -729,6 +732,8 @@ void MainWindow::translateInputFinished()
addNewTab();
showTranslationFor( word );
dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) ).focus();
}
}
@ -900,6 +905,13 @@ void MainWindow::showDefinitionInNewTab( QString const & word,
showDefinition( word, group, fromArticle );
}
void MainWindow::typingEvent( QString const & t )
{
ui.translateLine->setText( t );
ui.translateLine->setFocus();
ui.translateLine->setCursorPosition( t.size() );
}
void MainWindow::showTranslationFor( QString const & inWord )
{
ArticleView & view =

View file

@ -179,6 +179,7 @@ private slots:
void openLinkInNewTab( QUrl const &, QUrl const &, QString const & );
void showDefinitionInNewTab( QString const & word, unsigned group,
QString const & fromArticle );
void typingEvent( QString const & );
void showTranslationFor( QString const & );