refactor & simplify ScanFlag:

All slots of ScanFlag are used just as functions calls.
This commit is contained in:
shenleban tongying 2022-11-20 01:19:27 -05:00
parent 79f8b05d40
commit 6e0a6cfa42
5 changed files with 34 additions and 33 deletions

View file

@ -940,7 +940,7 @@ void MainWindow::clipboardChange( QClipboard::Mode m)
// Show a Flag instead of translate directly. // Show a Flag instead of translate directly.
// And hand over the control of showing the popup to scanFlag // And hand over the control of showing the popup to scanFlag
if ( cfg.preferences.showScanFlag ) { if ( cfg.preferences.showScanFlag ) {
emit scanPopup->showScanFlag(); scanPopup->showScanFlag();
return; return;
} }

View file

@ -4,29 +4,28 @@
#include "ui_scanflag.h" #include "ui_scanflag.h"
#include <QScreen> #include <QScreen>
static Qt::WindowFlags popupWindowFlags =
Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint
| Qt::WindowDoesNotAcceptFocus
;
ScanFlag::ScanFlag(QWidget *parent) : ScanFlag::ScanFlag(QWidget *parent) :
QMainWindow(parent) QMainWindow(parent)
{ {
ui.setupUi( this ); ui.setupUi( this );
setWindowFlags( popupWindowFlags ); setWindowFlags( Qt::ToolTip
| Qt::FramelessWindowHint
| Qt::WindowStaysOnTopHint
| Qt::WindowDoesNotAcceptFocus);
setAttribute(Qt::WA_X11DoNotAcceptFocus); setAttribute(Qt::WA_X11DoNotAcceptFocus);
hideTimer.setSingleShot( true ); hideTimer.setSingleShot( true );
hideTimer.setInterval( 1500 ); hideTimer.setInterval( 1000 );
connect( &hideTimer, SIGNAL( timeout() ), connect( &hideTimer, &QTimer::timeout,
this, SLOT( hideWindow() ) ); this, [=]{ hideWindow();
});
connect( ui.pushButton, SIGNAL( clicked( bool ) ), connect( ui.pushButton, &QPushButton::clicked,
this, SLOT( pushButtonClicked() ) ); this, &ScanFlag::pushButtonClicked );
} }
ScanFlag::~ScanFlag() ScanFlag::~ScanFlag()
@ -37,7 +36,7 @@ void ScanFlag::pushButtonClicked()
{ {
hideTimer.stop(); hideTimer.stop();
hide(); hide();
emit showScanPopup(); emit requestScanPopup();
} }
void ScanFlag::hideWindow() void ScanFlag::hideWindow()

View file

@ -2,7 +2,6 @@
#define SCAN_FLAG_H #define SCAN_FLAG_H
#include "config.hh"
#include <QMainWindow> #include <QMainWindow>
#include <QTimer> #include <QTimer>
#include "ui_scanflag.h" #include "ui_scanflag.h"
@ -16,18 +15,17 @@ public:
~ScanFlag(); ~ScanFlag();
void showScanFlag();
void pushButtonClicked();
void hideWindow();
signals: signals:
void showScanPopup (); void requestScanPopup ();
private: private:
Ui::ScanFlag ui; Ui::ScanFlag ui;
QTimer hideTimer; QTimer hideTimer;
private slots:
void showScanFlag();
void pushButtonClicked();
void hideWindow();
}; };
#endif // SCAN_FLAG_H #endif // SCAN_FLAG_H

View file

@ -317,13 +317,7 @@ ScanPopup::ScanPopup( QWidget * parent,
#ifdef HAVE_X11 #ifdef HAVE_X11
scanFlag = new ScanFlag( this ); scanFlag = new ScanFlag( this );
connect( this, SIGNAL( showScanFlag() ), connect( scanFlag, &ScanFlag::requestScanPopup,
scanFlag, SLOT( showScanFlag() ) );
connect( this, SIGNAL( hideScanFlag() ),
scanFlag, SLOT( hideWindow() ) );
connect( scanFlag, &ScanFlag::showScanPopup,
this, [=]{ this, [=]{
translateWordFromSelection(); translateWordFromSelection();
}); });
@ -1344,3 +1338,12 @@ void ScanPopup::titleChanged( ArticleView *, QString const & title )
ui.sendWordToFavoritesButton->setIcon( isWordPresentedInFavorites( title, groupId ) ? ui.sendWordToFavoritesButton->setIcon( isWordPresentedInFavorites( title, groupId ) ?
blueStarIcon : starIcon ); blueStarIcon : starIcon );
} }
void ScanPopup::showScanFlag(){
scanFlag->showScanFlag();
}
void ScanPopup::hideScanFlag(){
scanFlag->hideWindow();
}

View file

@ -53,6 +53,13 @@ public:
void setDictionaryIconSize(); void setDictionaryIconSize();
void saveConfigData(); void saveConfigData();
#ifdef HAVE_X11
/// Interaction with scan flag window
void showScanFlag();
void hideScanFlag();
#endif
signals: signals:
/// Forwarded from the dictionary bar, so that main window could act on this. /// Forwarded from the dictionary bar, so that main window could act on this.
@ -79,12 +86,6 @@ signals:
/// Check is word already presented in Favorites /// Check is word already presented in Favorites
bool isWordPresentedInFavorites( QString const & word, unsigned groupId ); bool isWordPresentedInFavorites( QString const & word, unsigned groupId );
#ifdef HAVE_X11
/// Interaction with scan flag window
void showScanFlag();
void hideScanFlag();
#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 );