mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-18 03:14:06 +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.
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
23
scanflag.cc
23
scanflag.cc
|
@ -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()
|
||||||
|
|
12
scanflag.hh
12
scanflag.hh
|
@ -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
|
||||||
|
|
17
scanpopup.cc
17
scanpopup.cc
|
@ -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();
|
||||||
|
}
|
||||||
|
|
13
scanpopup.hh
13
scanpopup.hh
|
@ -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 );
|
||||||
|
|
Loading…
Reference in a new issue