mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
refactor & simplify ScanFlag:
All slots of ScanFlag are used just as functions calls.
This commit is contained in:
parent
79f8b05d40
commit
6e0a6cfa42
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
23
scanflag.cc
23
scanflag.cc
|
@ -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()
|
||||
|
|
12
scanflag.hh
12
scanflag.hh
|
@ -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
|
||||
|
|
17
scanpopup.cc
17
scanpopup.cc
|
@ -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();
|
||||
}
|
||||
|
|
13
scanpopup.hh
13
scanpopup.hh
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue