Add scan popup flag

After select a word, show a flag window, click the flag to show
popup window.
This commit is contained in:
sunwxg 2017-06-05 21:15:38 +08:00
parent 971e7176ca
commit ad8008c37b
11 changed files with 260 additions and 7 deletions

View file

@ -109,6 +109,9 @@ Preferences::Preferences():
scanPopupUseIAccessibleEx( true ), scanPopupUseIAccessibleEx( true ),
scanPopupUseGDMessage( true ), scanPopupUseGDMessage( true ),
scanToMainWindow( false ), scanToMainWindow( false ),
#ifdef HAVE_X11
showScanFlag( false ),
#endif
pronounceOnLoadMain( false ), pronounceOnLoadMain( false ),
pronounceOnLoadPopup( false ), pronounceOnLoadPopup( false ),
#ifndef DISABLE_INTERNAL_PLAYER #ifndef DISABLE_INTERNAL_PLAYER
@ -758,6 +761,9 @@ Class load() throw( exError )
if ( !preferences.namedItem( "scanPopupAltModeSecs" ).isNull() ) if ( !preferences.namedItem( "scanPopupAltModeSecs" ).isNull() )
c.preferences.scanPopupAltModeSecs = preferences.namedItem( "scanPopupAltModeSecs" ).toElement().text().toUInt(); c.preferences.scanPopupAltModeSecs = preferences.namedItem( "scanPopupAltModeSecs" ).toElement().text().toUInt();
c.preferences.scanToMainWindow = ( preferences.namedItem( "scanToMainWindow" ).toElement().text() == "1" ); c.preferences.scanToMainWindow = ( preferences.namedItem( "scanToMainWindow" ).toElement().text() == "1" );
#ifdef HAVE_X11
c.preferences.showScanFlag= ( preferences.namedItem( "showScanFlag" ).toElement().text() == "1" );
#endif
c.preferences.scanPopupUseUIAutomation = ( preferences.namedItem( "scanPopupUseUIAutomation" ).toElement().text() == "1" ); c.preferences.scanPopupUseUIAutomation = ( preferences.namedItem( "scanPopupUseUIAutomation" ).toElement().text() == "1" );
c.preferences.scanPopupUseIAccessibleEx = ( preferences.namedItem( "scanPopupUseIAccessibleEx" ).toElement().text() == "1" ); c.preferences.scanPopupUseIAccessibleEx = ( preferences.namedItem( "scanPopupUseIAccessibleEx" ).toElement().text() == "1" );
c.preferences.scanPopupUseGDMessage = ( preferences.namedItem( "scanPopupUseGDMessage" ).toElement().text() == "1" ); c.preferences.scanPopupUseGDMessage = ( preferences.namedItem( "scanPopupUseGDMessage" ).toElement().text() == "1" );
@ -1622,6 +1628,12 @@ void save( Class const & c ) throw( exError )
opt.appendChild( dd.createTextNode( c.preferences.scanToMainWindow ? "1":"0" ) ); opt.appendChild( dd.createTextNode( c.preferences.scanToMainWindow ? "1":"0" ) );
preferences.appendChild( opt ); preferences.appendChild( opt );
#ifdef HAVE_X11
opt = dd.createElement( "showScanFlag" );
opt.appendChild( dd.createTextNode( c.preferences.showScanFlag? "1":"0" ) );
preferences.appendChild( opt );
#endif
opt = dd.createElement( "scanPopupUseUIAutomation" ); opt = dd.createElement( "scanPopupUseUIAutomation" );
opt.appendChild( dd.createTextNode( c.preferences.scanPopupUseUIAutomation ? "1":"0" ) ); opt.appendChild( dd.createTextNode( c.preferences.scanPopupUseUIAutomation ? "1":"0" ) );
preferences.appendChild( opt ); preferences.appendChild( opt );

View file

@ -214,6 +214,9 @@ struct Preferences
bool scanPopupUseIAccessibleEx; bool scanPopupUseIAccessibleEx;
bool scanPopupUseGDMessage; bool scanPopupUseGDMessage;
bool scanToMainWindow; bool scanToMainWindow;
#ifdef HAVE_X11
bool showScanFlag;
#endif
// Whether the word should be pronounced on page load, in main window/popup // Whether the word should be pronounced on page load, in main window/popup
bool pronounceOnLoadMain, pronounceOnLoadPopup; bool pronounceOnLoadMain, pronounceOnLoadPopup;

View file

@ -79,8 +79,8 @@ win32 {
LIBS += -L$${PWD}/winlibs/lib LIBS += -L$${PWD}/winlibs/lib
} }
!x64:QMAKE_LFLAGS += -Wl,--large-address-aware !x64:QMAKE_LFLAGS += -Wl,--large-address-aware
isEmpty(HUNSPELL_LIB) { isEmpty(HUNSPELL_LIB) {
CONFIG(gcc48) { CONFIG(gcc48) {
LIBS += -lhunspell-1.3.2 LIBS += -lhunspell-1.3.2
} else { } else {
@ -514,6 +514,12 @@ mac {
SOURCES += texttospeechsource.cc SOURCES += texttospeechsource.cc
} }
unix:!mac {
HEADERS += scanflag.hh
FORMS += scanflag.ui
SOURCES += scanflag.cc
}
CONFIG( zim_support ) { CONFIG( zim_support ) {
DEFINES += MAKE_ZIM_SUPPORT DEFINES += MAKE_ZIM_SUPPORT
LIBS += -llzma LIBS += -llzma

View file

@ -22,6 +22,9 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
connect( ui.enableScanPopupModifiers, SIGNAL( toggled( bool ) ), connect( ui.enableScanPopupModifiers, SIGNAL( toggled( bool ) ),
this, SLOT( enableScanPopupModifiersToggled( bool ) ) ); this, SLOT( enableScanPopupModifiersToggled( bool ) ) );
connect( ui.showScanFlag, SIGNAL( toggled( bool ) ),
this, SLOT( showScanFlagToggled( bool ) ) );
connect( ui.altKey, SIGNAL( clicked( bool ) ), connect( ui.altKey, SIGNAL( clicked( bool ) ),
this, SLOT( wholeAltClicked( bool ) ) ); this, SLOT( wholeAltClicked( bool ) ) );
connect( ui.ctrlKey, SIGNAL( clicked( bool ) ), connect( ui.ctrlKey, SIGNAL( clicked( bool ) ),
@ -229,6 +232,12 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
// ui.tabWidget->removeTab( 5 ); // ui.tabWidget->removeTab( 5 );
#endif #endif
#ifdef HAVE_X11
ui.showScanFlag->setChecked( p.showScanFlag);
#else
ui.showScanFlag->hide();
#endif
// Sound // Sound
ui.pronounceOnLoadMain->setChecked( p.pronounceOnLoadMain ); ui.pronounceOnLoadMain->setChecked( p.pronounceOnLoadMain );
@ -366,6 +375,9 @@ Config::Preferences Preferences::getPreferences()
p.scanPopupAltMode = ui.scanPopupAltMode->isChecked(); p.scanPopupAltMode = ui.scanPopupAltMode->isChecked();
p.scanPopupAltModeSecs = ui.scanPopupAltModeSecs->value(); p.scanPopupAltModeSecs = ui.scanPopupAltModeSecs->value();
p.scanToMainWindow = ui.scanToMainWindow->isChecked(); p.scanToMainWindow = ui.scanToMainWindow->isChecked();
#ifdef HAVE_X11
p.showScanFlag= ui.showScanFlag->isChecked();
#endif
p.scanPopupUseUIAutomation = ui.scanPopupUseUIAutomation->isChecked(); p.scanPopupUseUIAutomation = ui.scanPopupUseUIAutomation->isChecked();
p.scanPopupUseIAccessibleEx = ui.scanPopupUseIAccessibleEx->isChecked(); p.scanPopupUseIAccessibleEx = ui.scanPopupUseIAccessibleEx->isChecked();
p.scanPopupUseGDMessage = ui.scanPopupUseGDMessage->isChecked(); p.scanPopupUseGDMessage = ui.scanPopupUseGDMessage->isChecked();
@ -507,6 +519,14 @@ void Preferences::enableScanPopupToggled( bool b )
void Preferences::enableScanPopupModifiersToggled( bool b ) void Preferences::enableScanPopupModifiersToggled( bool b )
{ {
ui.scanPopupModifiers->setEnabled( b && ui.enableScanPopup->isChecked() ); ui.scanPopupModifiers->setEnabled( b && ui.enableScanPopup->isChecked() );
if( b )
ui.showScanFlag->setChecked( false );
}
void Preferences::showScanFlagToggled( bool b )
{
if( b )
ui.enableScanPopupModifiers->setChecked( false );
} }
void Preferences::wholeAltClicked( bool b ) void Preferences::wholeAltClicked( bool b )

View file

@ -33,6 +33,7 @@ private slots:
void enableScanPopupToggled( bool ); void enableScanPopupToggled( bool );
void enableScanPopupModifiersToggled( bool ); void enableScanPopupModifiersToggled( bool );
void showScanFlagToggled( bool b );
void wholeAltClicked( bool ); void wholeAltClicked( bool );
void wholeCtrlClicked( bool ); void wholeCtrlClicked( bool );

View file

@ -679,6 +679,16 @@ seconds, which is specified here.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="showScanFlag">
<property name="toolTip">
<string>Show a flag window before showing popup window, click the flag to show popup window. </string>
</property>
<property name="text">
<string>Show scan flag when word is selected</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

90
scanflag.cc Normal file
View file

@ -0,0 +1,90 @@
#include <QCursor>
#include <QDesktopWidget>
#include "scanflag.hh"
#include "ui_scanflag.h"
static Qt::WindowFlags popupWindowFlags =
Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint
#if QT_VERSION >= 0x050000
| Qt::WindowDoesNotAcceptFocus
#endif
;
ScanFlag::ScanFlag(QWidget *parent) :
QMainWindow(parent)
{
ui.setupUi( this );
setWindowFlags( popupWindowFlags );
setAttribute(Qt::WA_X11DoNotAcceptFocus);
hideTimer.setSingleShot( true );
hideTimer.setInterval( 1500 );
connect( &hideTimer, SIGNAL( timeout() ),
this, SLOT( hideWindow() ) );
connect( ui.pushButton, SIGNAL( clicked( bool ) ),
this, SLOT( pushButtonClicked() ) );
}
ScanFlag::~ScanFlag()
{
}
void ScanFlag::pushButtonClicked()
{
hideTimer.stop();
hide();
emit showScanPopup();
}
void ScanFlag::hideWindow()
{
if ( isVisible() )
hide();
}
void ScanFlag::showScanFlag()
{
if ( isVisible() )
hide();
QPoint currentPos = QCursor::pos();
QRect desktop = QApplication::desktop()->screenGeometry();
QSize windowSize = geometry().size();
int x, y;
/// Try the to-the-right placement
if ( currentPos.x() + 4 + windowSize.width() <= desktop.topRight().x() )
x = currentPos.x() + 4;
else
/// Try the to-the-left placement
if ( currentPos.x() - 4 - windowSize.width() >= desktop.x() )
x = currentPos.x() - 4 - windowSize.width();
else
// Center it
x = desktop.x() + ( desktop.width() - windowSize.width() ) / 2;
/// Try the to-the-top placement
if ( currentPos.y() - 15 - windowSize.height() >= desktop.y() )
y = currentPos.y() - 15 - windowSize.height();
else
/// Try the to-the-bottom placement
if ( currentPos.y() + 15 + windowSize.height() <= desktop.bottomLeft().y() )
y = currentPos.y() + 15;
else
// Center it
y = desktop.y() + ( desktop.height() - windowSize.height() ) / 2;
move( x, y );
show();
hideTimer.start();
}

33
scanflag.hh Normal file
View file

@ -0,0 +1,33 @@
#ifndef SCAN_FLAG_H
#define SCAN_FLAG_H
#include "config.hh"
#include <QMainWindow>
#include <QTimer>
#include "ui_scanflag.h"
class ScanFlag : public QMainWindow
{
Q_OBJECT
public:
ScanFlag( QWidget *parent );
~ScanFlag();
signals:
void showScanPopup ();
private:
Ui::ScanFlag ui;
QTimer hideTimer;
private slots:
void showScanFlag();
void pushButtonClicked();
void hideWindow();
};
#endif // SCAN_FLAG_H

38
scanflag.ui Normal file
View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScanFlag</class>
<widget class="QMainWindow" name="ScanFlag">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>30</width>
<height>30</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>30</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/icons/programicon.png</normaloff>:/icons/programicon.png</iconset>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -35,7 +35,7 @@ Qt::Popup
ScanPopup::ScanPopup( QWidget * parent, ScanPopup::ScanPopup( QWidget * parent,
Config::Class & cfg_, Config::Class & cfg_,
ArticleNetworkAccessManager & articleNetMgr, ArticleNetworkAccessManager & articleNetMgr,
std::vector< sptr< Dictionary::Class > > const & allDictionaries_, std::vector< sptr< Dictionary::Class > > const & allDictionaries_,
Instances::Groups const & groups_, Instances::Groups const & groups_,
History & history_ ): History & history_ ):
@ -92,7 +92,7 @@ ScanPopup::ScanPopup( QWidget * parent,
this, SLOT( typingEvent( QString const & ) ) ); this, SLOT( typingEvent( QString const & ) ) );
applyZoomFactor(); applyZoomFactor();
ui.mainLayout->addWidget( definition ); ui.mainLayout->addWidget( definition );
ui.translateBox->wordList()->attachFinder( &wordFinder ); ui.translateBox->wordList()->attachFinder( &wordFinder );
@ -270,6 +270,16 @@ ScanPopup::ScanPopup( QWidget * parent,
grabGesture( Gestures::GDPinchGestureType ); grabGesture( Gestures::GDPinchGestureType );
grabGesture( Gestures::GDSwipeGestureType ); grabGesture( Gestures::GDSwipeGestureType );
#endif #endif
#ifdef HAVE_X11
scanFlag = new ScanFlag( 0 );
connect( this, SIGNAL( showScanFlag( bool ) ),
scanFlag, SLOT( showScanFlag() ) );
connect( scanFlag, SIGNAL( showScanPopup() ),
this, SLOT( showEngagePopup() ) );
#endif
} }
ScanPopup::~ScanPopup() ScanPopup::~ScanPopup()
@ -362,7 +372,7 @@ void ScanPopup::clipboardChanged( QClipboard::Mode m )
{ {
if ( !isScanningEnabled ) if ( !isScanningEnabled )
return; return;
GD_DPRINTF( "clipboard changed\n" ); GD_DPRINTF( "clipboard changed\n" );
QString subtype = "plain"; QString subtype = "plain";
@ -400,6 +410,14 @@ void ScanPopup::handleInputWord( QString const & str, bool forcePopup )
return; return;
} }
#ifdef HAVE_X11
if ( cfg.preferences.showScanFlag ) {
inputWord = pendingInputWord;
emit showScanFlag( forcePopup );
return;
}
#endif
// Check key modifiers // Check key modifiers
if ( cfg.preferences.enableScanPopupModifiers && !checkModifiersPressed( cfg.preferences.scanPopupModifiers ) ) if ( cfg.preferences.enableScanPopupModifiers && !checkModifiersPressed( cfg.preferences.scanPopupModifiers ) )
@ -417,6 +435,13 @@ void ScanPopup::handleInputWord( QString const & str, bool forcePopup )
engagePopup( forcePopup ); engagePopup( forcePopup );
} }
#ifdef HAVE_X11
void ScanPopup::showEngagePopup()
{
engagePopup(false);
}
#endif
void ScanPopup::engagePopup( bool forcePopup, bool giveFocus ) void ScanPopup::engagePopup( bool forcePopup, bool giveFocus )
{ {
if( cfg.preferences.scanToMainWindow && !forcePopup ) if( cfg.preferences.scanToMainWindow && !forcePopup )
@ -745,7 +770,7 @@ void ScanPopup::mouseMoveEvent( QMouseEvent * event )
move( pos() + delta ); move( pos() + delta );
} }
QMainWindow::mouseMoveEvent( event ); QMainWindow::mouseMoveEvent( event );
} }
@ -808,7 +833,7 @@ void ScanPopup::showEvent( QShowEvent * ev )
QMainWindow::showEvent( ev ); QMainWindow::showEvent( ev );
QTimer::singleShot(100, this, SLOT( requestWindowFocus() ) ); QTimer::singleShot(100, this, SLOT( requestWindowFocus() ) );
if ( groups.size() <= 1 ) // Only the default group? Hide then. if ( groups.size() <= 1 ) // Only the default group? Hide then.
ui.groupList->hide(); ui.groupList->hide();

View file

@ -15,6 +15,9 @@
#include "history.hh" #include "history.hh"
#include "dictionarybar.hh" #include "dictionarybar.hh"
#include "mainstatusbar.hh" #include "mainstatusbar.hh"
#ifdef HAVE_X11
#include "scanflag.hh"
#endif
/// This is a popup dialog to show translations when clipboard scanning mode /// This is a popup dialog to show translations when clipboard scanning mode
/// is enabled. /// is enabled.
@ -70,6 +73,10 @@ signals:
/// Put translated word into Favorites /// Put translated word into Favorites
void sendWordToFavorites( QString const & word, unsigned groupId ); void sendWordToFavorites( QString const & word, unsigned groupId );
#ifdef HAVE_X11
void showScanFlag( bool forcePopup );
#endif
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
/// Ask for source window is current translate tab /// Ask for source window is current translate tab
bool isGoldenDictWindow( HWND hwnd ); bool isGoldenDictWindow( HWND hwnd );
@ -87,6 +94,10 @@ public slots:
void setGroupByName( QString const & name ); void setGroupByName( QString const & name );
#ifdef HAVE_X11
void showEngagePopup();
#endif
private: private:
// Translates the word from the clipboard or the clipboard selection // Translates the word from the clipboard or the clipboard selection
@ -118,6 +129,10 @@ private:
DictionaryBar dictionaryBar; DictionaryBar dictionaryBar;
MainStatusBar * mainStatusBar; MainStatusBar * mainStatusBar;
#ifdef HAVE_X11
ScanFlag * scanFlag;
#endif
bool mouseEnteredOnce; bool mouseEnteredOnce;
bool mouseIntercepted; bool mouseIntercepted;