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.
// And hand over the control of showing the popup to scanFlag
if ( cfg.preferences.showScanFlag ) {
emit scanPopup->showScanFlag();
scanPopup->showScanFlag();
return;
}

View file

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

View file

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

View file

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

View file

@ -53,6 +53,13 @@ public:
void setDictionaryIconSize();
void saveConfigData();
#ifdef HAVE_X11
/// Interaction with scan flag window
void showScanFlag();
void hideScanFlag();
#endif
signals:
/// 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
bool isWordPresentedInFavorites( QString const & word, unsigned groupId );
#ifdef HAVE_X11
/// Interaction with scan flag window
void showScanFlag();
void hideScanFlag();
#endif
#ifdef Q_OS_WIN32
/// Ask for source window is current translate tab
bool isGoldenDictWindow( HWND hwnd );