mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
Win-specific: Show translation in popup window istead of sending word to GD main window while scanning GD main window
This commit is contained in:
parent
34419706c9
commit
09b9e9aa46
|
@ -874,6 +874,11 @@ void MainWindow::makeScanPopup()
|
|||
|
||||
connect( scanPopup.get(), SIGNAL( forceAddWordToHistory( const QString & ) ),
|
||||
this, SLOT( forceAddWordToHistory( const QString & ) ) );
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
connect( scanPopup.get(), SIGNAL( isGoldenDictWindow( HWND ) ),
|
||||
this, SLOT( isGoldenDictWindow( HWND ) ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
vector< sptr< Dictionary::Class > > const & MainWindow::getActiveDicts()
|
||||
|
@ -3027,4 +3032,9 @@ bool MainWindow::winEvent( MSG * message, long * result )
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MainWindow::isGoldenDictWindow( HWND hwnd )
|
||||
{
|
||||
return hwnd == (HWND)winId();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -356,6 +356,10 @@ signals:
|
|||
protected:
|
||||
unsigned gdAskMessage;
|
||||
bool winEvent( MSG * message, long * result );
|
||||
|
||||
private slots:
|
||||
/// Return true while scanning GoldenDict window
|
||||
bool isGoldenDictWindow( HWND hwnd );
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -201,6 +201,8 @@ LRESULT CALLBACK MouseOver::eventHandler( HWND hwnd, UINT msg,
|
|||
int wordSeqPos = 0;
|
||||
QString wordSeq;
|
||||
|
||||
HWND hwnd = GlobalData->LastWND;
|
||||
|
||||
if( GlobalData->CurMod.WordLen == 0)
|
||||
{
|
||||
if( ( res & GD_FLAG_METHOD_UI_AUTOMATION ) == 0 )
|
||||
|
@ -317,7 +319,9 @@ LRESULT CALLBACK MouseOver::eventHandler( HWND hwnd, UINT msg,
|
|||
}
|
||||
}
|
||||
|
||||
emit instance().hovered( word );
|
||||
bool forcePopup = false;
|
||||
forcePopup = emit instance().isGoldenDictWindow( hwnd );
|
||||
emit instance().hovered( word, forcePopup );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,12 @@ public:
|
|||
signals:
|
||||
|
||||
/// Emitted when there was some text under cursor which was hovered over.
|
||||
void hovered( QString const & );
|
||||
void hovered( QString const &, bool forcePopup );
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
/// Ask for source window is GoldenDict window
|
||||
bool isGoldenDictWindow( HWND hwnd );
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
|
|
27
scanpopup.cc
27
scanpopup.cc
|
@ -152,8 +152,13 @@ ScanPopup::ScanPopup( QWidget * parent,
|
|||
connect( QApplication::clipboard(), SIGNAL( changed( QClipboard::Mode ) ),
|
||||
this, SLOT( clipboardChanged( QClipboard::Mode ) ) );
|
||||
|
||||
connect( &MouseOver::instance(), SIGNAL( hovered( QString const & ) ),
|
||||
this, SLOT( mouseHovered( QString const & ) ) );
|
||||
connect( &MouseOver::instance(), SIGNAL( hovered( QString const &, bool ) ),
|
||||
this, SLOT( mouseHovered( QString const &, bool ) ) );
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
connect( &MouseOver::instance(), SIGNAL( isGoldenDictWindow( HWND ) ),
|
||||
this, SIGNAL( isGoldenDictWindow( HWND ) ) );
|
||||
#endif
|
||||
|
||||
hideTimer.setSingleShot( true );
|
||||
hideTimer.setInterval( 400 );
|
||||
|
@ -252,10 +257,12 @@ void ScanPopup::translateWord( QString const & word )
|
|||
altModeExpirationTimer.stop();
|
||||
|
||||
inputWord = str;
|
||||
engagePopup(
|
||||
engagePopup( false,
|
||||
#ifdef Q_WS_WIN
|
||||
true // We only focus popup under Windows when activated via Ctrl+C+C
|
||||
// -- on Linux it already has an implicit focus
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
@ -272,12 +279,12 @@ void ScanPopup::clipboardChanged( QClipboard::Mode m )
|
|||
handleInputWord( QApplication::clipboard()->text( subtype, m ) );
|
||||
}
|
||||
|
||||
void ScanPopup::mouseHovered( QString const & str )
|
||||
void ScanPopup::mouseHovered( QString const & str, bool forcePopup )
|
||||
{
|
||||
handleInputWord( str );
|
||||
handleInputWord( str, forcePopup );
|
||||
}
|
||||
|
||||
void ScanPopup::handleInputWord( QString const & str )
|
||||
void ScanPopup::handleInputWord( QString const & str, bool forcePopup )
|
||||
{
|
||||
QString sanitizedStr = gd::toQString( Folding::trimWhitespaceOrPunct( gd::toWString( str ) ) );
|
||||
|
||||
|
@ -316,12 +323,12 @@ void ScanPopup::handleInputWord( QString const & str )
|
|||
}
|
||||
|
||||
inputWord = pendingInputWord;
|
||||
engagePopup();
|
||||
engagePopup( forcePopup );
|
||||
}
|
||||
|
||||
void ScanPopup::engagePopup( bool giveFocus )
|
||||
void ScanPopup::engagePopup( bool forcePopup, bool giveFocus )
|
||||
{
|
||||
if( cfg.preferences.scanToMainWindow )
|
||||
if( cfg.preferences.scanToMainWindow && !forcePopup )
|
||||
{
|
||||
// Send translated word to main window istead of show popup
|
||||
emit sendWordToMainWindow( inputWord );
|
||||
|
@ -726,7 +733,7 @@ void ScanPopup::altModePoll()
|
|||
altModeExpirationTimer.stop();
|
||||
|
||||
inputWord = pendingInputWord;
|
||||
engagePopup();
|
||||
engagePopup( false );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
11
scanpopup.hh
11
scanpopup.hh
|
@ -61,6 +61,11 @@ signals:
|
|||
/// Signal to add word to history even if history is disabled
|
||||
void forceAddWordToHistory( const QString & word);
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
/// Ask for source window is current translate tab
|
||||
bool isGoldenDictWindow( HWND hwnd );
|
||||
#endif
|
||||
|
||||
public slots:
|
||||
|
||||
/// Translates the word from the clipboard, showing the window etc.
|
||||
|
@ -112,8 +117,8 @@ private:
|
|||
|
||||
QTimer mouseGrabPollTimer;
|
||||
|
||||
void handleInputWord( QString const & );
|
||||
void engagePopup( bool giveFocus = false );
|
||||
void handleInputWord( QString const & , bool forcePopup = false );
|
||||
void engagePopup( bool forcePopup, bool giveFocus = false );
|
||||
void initiateTranslation();
|
||||
|
||||
vector< sptr< Dictionary::Class > > const & getActiveDicts();
|
||||
|
@ -137,7 +142,7 @@ private:
|
|||
private slots:
|
||||
|
||||
void clipboardChanged( QClipboard::Mode );
|
||||
void mouseHovered( QString const & );
|
||||
void mouseHovered( QString const & , bool forcePopup);
|
||||
void currentGroupChanged( QString const & );
|
||||
void prefixMatchFinished();
|
||||
void on_wordListButton_clicked();
|
||||
|
|
Loading…
Reference in a new issue