mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
Add scan popup flag
After select a word, show a flag window, click the flag to show popup window.
This commit is contained in:
parent
971e7176ca
commit
ad8008c37b
12
config.cc
12
config.cc
|
@ -109,6 +109,9 @@ Preferences::Preferences():
|
|||
scanPopupUseIAccessibleEx( true ),
|
||||
scanPopupUseGDMessage( true ),
|
||||
scanToMainWindow( false ),
|
||||
#ifdef HAVE_X11
|
||||
showScanFlag( false ),
|
||||
#endif
|
||||
pronounceOnLoadMain( false ),
|
||||
pronounceOnLoadPopup( false ),
|
||||
#ifndef DISABLE_INTERNAL_PLAYER
|
||||
|
@ -758,6 +761,9 @@ Class load() throw( exError )
|
|||
if ( !preferences.namedItem( "scanPopupAltModeSecs" ).isNull() )
|
||||
c.preferences.scanPopupAltModeSecs = preferences.namedItem( "scanPopupAltModeSecs" ).toElement().text().toUInt();
|
||||
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.scanPopupUseIAccessibleEx = ( preferences.namedItem( "scanPopupUseIAccessibleEx" ).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" ) );
|
||||
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.appendChild( dd.createTextNode( c.preferences.scanPopupUseUIAutomation ? "1":"0" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
|
|
@ -214,6 +214,9 @@ struct Preferences
|
|||
bool scanPopupUseIAccessibleEx;
|
||||
bool scanPopupUseGDMessage;
|
||||
bool scanToMainWindow;
|
||||
#ifdef HAVE_X11
|
||||
bool showScanFlag;
|
||||
#endif
|
||||
|
||||
// Whether the word should be pronounced on page load, in main window/popup
|
||||
bool pronounceOnLoadMain, pronounceOnLoadPopup;
|
||||
|
|
|
@ -80,7 +80,7 @@ win32 {
|
|||
}
|
||||
!x64:QMAKE_LFLAGS += -Wl,--large-address-aware
|
||||
|
||||
isEmpty(HUNSPELL_LIB) {
|
||||
isEmpty(HUNSPELL_LIB) {
|
||||
CONFIG(gcc48) {
|
||||
LIBS += -lhunspell-1.3.2
|
||||
} else {
|
||||
|
@ -514,6 +514,12 @@ mac {
|
|||
SOURCES += texttospeechsource.cc
|
||||
}
|
||||
|
||||
unix:!mac {
|
||||
HEADERS += scanflag.hh
|
||||
FORMS += scanflag.ui
|
||||
SOURCES += scanflag.cc
|
||||
}
|
||||
|
||||
CONFIG( zim_support ) {
|
||||
DEFINES += MAKE_ZIM_SUPPORT
|
||||
LIBS += -llzma
|
||||
|
|
|
@ -22,6 +22,9 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
|
|||
connect( ui.enableScanPopupModifiers, SIGNAL( toggled( bool ) ),
|
||||
this, SLOT( enableScanPopupModifiersToggled( bool ) ) );
|
||||
|
||||
connect( ui.showScanFlag, SIGNAL( toggled( bool ) ),
|
||||
this, SLOT( showScanFlagToggled( bool ) ) );
|
||||
|
||||
connect( ui.altKey, SIGNAL( clicked( bool ) ),
|
||||
this, SLOT( wholeAltClicked( bool ) ) );
|
||||
connect( ui.ctrlKey, SIGNAL( clicked( bool ) ),
|
||||
|
@ -229,6 +232,12 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
|
|||
// ui.tabWidget->removeTab( 5 );
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_X11
|
||||
ui.showScanFlag->setChecked( p.showScanFlag);
|
||||
#else
|
||||
ui.showScanFlag->hide();
|
||||
#endif
|
||||
|
||||
// Sound
|
||||
|
||||
ui.pronounceOnLoadMain->setChecked( p.pronounceOnLoadMain );
|
||||
|
@ -366,6 +375,9 @@ Config::Preferences Preferences::getPreferences()
|
|||
p.scanPopupAltMode = ui.scanPopupAltMode->isChecked();
|
||||
p.scanPopupAltModeSecs = ui.scanPopupAltModeSecs->value();
|
||||
p.scanToMainWindow = ui.scanToMainWindow->isChecked();
|
||||
#ifdef HAVE_X11
|
||||
p.showScanFlag= ui.showScanFlag->isChecked();
|
||||
#endif
|
||||
p.scanPopupUseUIAutomation = ui.scanPopupUseUIAutomation->isChecked();
|
||||
p.scanPopupUseIAccessibleEx = ui.scanPopupUseIAccessibleEx->isChecked();
|
||||
p.scanPopupUseGDMessage = ui.scanPopupUseGDMessage->isChecked();
|
||||
|
@ -507,6 +519,14 @@ void Preferences::enableScanPopupToggled( bool b )
|
|||
void Preferences::enableScanPopupModifiersToggled( bool b )
|
||||
{
|
||||
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 )
|
||||
|
|
|
@ -33,6 +33,7 @@ private slots:
|
|||
|
||||
void enableScanPopupToggled( bool );
|
||||
void enableScanPopupModifiersToggled( bool );
|
||||
void showScanFlagToggled( bool b );
|
||||
|
||||
void wholeAltClicked( bool );
|
||||
void wholeCtrlClicked( bool );
|
||||
|
|
|
@ -679,6 +679,16 @@ seconds, which is specified here.</string>
|
|||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
90
scanflag.cc
Normal file
90
scanflag.cc
Normal 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
33
scanflag.hh
Normal 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
38
scanflag.ui
Normal 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>
|
25
scanpopup.cc
25
scanpopup.cc
|
@ -270,6 +270,16 @@ ScanPopup::ScanPopup( QWidget * parent,
|
|||
grabGesture( Gestures::GDPinchGestureType );
|
||||
grabGesture( Gestures::GDSwipeGestureType );
|
||||
#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()
|
||||
|
@ -400,6 +410,14 @@ void ScanPopup::handleInputWord( QString const & str, bool forcePopup )
|
|||
return;
|
||||
}
|
||||
|
||||
#ifdef HAVE_X11
|
||||
if ( cfg.preferences.showScanFlag ) {
|
||||
inputWord = pendingInputWord;
|
||||
emit showScanFlag( forcePopup );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Check key modifiers
|
||||
|
||||
if ( cfg.preferences.enableScanPopupModifiers && !checkModifiersPressed( cfg.preferences.scanPopupModifiers ) )
|
||||
|
@ -417,6 +435,13 @@ void ScanPopup::handleInputWord( QString const & str, bool forcePopup )
|
|||
engagePopup( forcePopup );
|
||||
}
|
||||
|
||||
#ifdef HAVE_X11
|
||||
void ScanPopup::showEngagePopup()
|
||||
{
|
||||
engagePopup(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
void ScanPopup::engagePopup( bool forcePopup, bool giveFocus )
|
||||
{
|
||||
if( cfg.preferences.scanToMainWindow && !forcePopup )
|
||||
|
|
15
scanpopup.hh
15
scanpopup.hh
|
@ -15,6 +15,9 @@
|
|||
#include "history.hh"
|
||||
#include "dictionarybar.hh"
|
||||
#include "mainstatusbar.hh"
|
||||
#ifdef HAVE_X11
|
||||
#include "scanflag.hh"
|
||||
#endif
|
||||
|
||||
/// This is a popup dialog to show translations when clipboard scanning mode
|
||||
/// is enabled.
|
||||
|
@ -70,6 +73,10 @@ signals:
|
|||
/// Put translated word into Favorites
|
||||
void sendWordToFavorites( QString const & word, unsigned groupId );
|
||||
|
||||
#ifdef HAVE_X11
|
||||
void showScanFlag( bool forcePopup );
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
/// Ask for source window is current translate tab
|
||||
bool isGoldenDictWindow( HWND hwnd );
|
||||
|
@ -87,6 +94,10 @@ public slots:
|
|||
|
||||
void setGroupByName( QString const & name );
|
||||
|
||||
#ifdef HAVE_X11
|
||||
void showEngagePopup();
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
// Translates the word from the clipboard or the clipboard selection
|
||||
|
@ -118,6 +129,10 @@ private:
|
|||
DictionaryBar dictionaryBar;
|
||||
MainStatusBar * mainStatusBar;
|
||||
|
||||
#ifdef HAVE_X11
|
||||
ScanFlag * scanFlag;
|
||||
#endif
|
||||
|
||||
bool mouseEnteredOnce;
|
||||
bool mouseIntercepted;
|
||||
|
||||
|
|
Loading…
Reference in a new issue