mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-18 03:14:06 +00:00
+ Pressing Enter in translateLine focuses on definition.
+ Typing any text key switches back to translateLine and puts it there.
This commit is contained in:
parent
806f8e4760
commit
25dce23d50
|
@ -10,6 +10,7 @@
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QWebHistory>
|
#include <QWebHistory>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QKeyEvent>
|
||||||
#include "folding.hh"
|
#include "folding.hh"
|
||||||
#include "wstring_qt.hh"
|
#include "wstring_qt.hh"
|
||||||
|
|
||||||
|
@ -63,6 +64,8 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm,
|
||||||
ui.definition->addAction( &pasteAction );
|
ui.definition->addAction( &pasteAction );
|
||||||
connect( &pasteAction, SIGNAL( triggered() ), this, SLOT( pasteTriggered() ) );
|
connect( &pasteAction, SIGNAL( triggered() ), this, SLOT( pasteTriggered() ) );
|
||||||
|
|
||||||
|
ui.definition->installEventFilter( this );
|
||||||
|
|
||||||
// Load the default blank page instantly, so there would be no flicker.
|
// Load the default blank page instantly, so there would be no flicker.
|
||||||
|
|
||||||
QString contentType;
|
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 )
|
void ArticleView::linkClicked( QUrl const & url )
|
||||||
{
|
{
|
||||||
|
|
|
@ -120,6 +120,10 @@ signals:
|
||||||
void showDefinitionInNewTab( QString const & word, unsigned group,
|
void showDefinitionInNewTab( QString const & word, unsigned group,
|
||||||
QString const & fromArticle );
|
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:
|
private slots:
|
||||||
|
|
||||||
void loadFinished( bool ok );
|
void loadFinished( bool ok );
|
||||||
|
@ -152,6 +156,8 @@ private:
|
||||||
/// Attempts removing last temporary file created.
|
/// Attempts removing last temporary file created.
|
||||||
void cleanupTemp();
|
void cleanupTemp();
|
||||||
|
|
||||||
|
bool eventFilter( QObject * obj, QEvent * ev );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// We need this to hide the search bar when we're showed
|
// We need this to hide the search bar when we're showed
|
||||||
|
|
|
@ -499,6 +499,9 @@ ArticleView * MainWindow::createNewTab( bool switchToIt,
|
||||||
connect( view, SIGNAL( showDefinitionInNewTab( QString const &, unsigned, QString const & ) ),
|
connect( view, SIGNAL( showDefinitionInNewTab( QString const &, unsigned, QString const & ) ),
|
||||||
this, SLOT( 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 ?
|
int index = cfg.preferences.newTabsOpenAfterCurrentOne ?
|
||||||
ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
|
ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
|
||||||
|
|
||||||
|
@ -729,6 +732,8 @@ void MainWindow::translateInputFinished()
|
||||||
addNewTab();
|
addNewTab();
|
||||||
|
|
||||||
showTranslationFor( word );
|
showTranslationFor( word );
|
||||||
|
|
||||||
|
dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) ).focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -900,6 +905,13 @@ void MainWindow::showDefinitionInNewTab( QString const & word,
|
||||||
showDefinition( word, group, fromArticle );
|
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 )
|
void MainWindow::showTranslationFor( QString const & inWord )
|
||||||
{
|
{
|
||||||
ArticleView & view =
|
ArticleView & view =
|
||||||
|
|
|
@ -179,6 +179,7 @@ private slots:
|
||||||
void openLinkInNewTab( QUrl const &, QUrl const &, QString const & );
|
void openLinkInNewTab( QUrl const &, QUrl const &, QString const & );
|
||||||
void showDefinitionInNewTab( QString const & word, unsigned group,
|
void showDefinitionInNewTab( QString const & word, unsigned group,
|
||||||
QString const & fromArticle );
|
QString const & fromArticle );
|
||||||
|
void typingEvent( QString const & );
|
||||||
|
|
||||||
void showTranslationFor( QString const & );
|
void showTranslationFor( QString const & );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue