2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
2009-01-28 20:55:45 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#ifndef __SCANPOPUP_HH_INCLUDED__
|
|
|
|
#define __SCANPOPUP_HH_INCLUDED__
|
|
|
|
|
|
|
|
#include "article_netmgr.hh"
|
2023-03-17 22:42:11 +00:00
|
|
|
#include "ui/articleview.h"
|
2009-02-01 00:08:08 +00:00
|
|
|
#include "wordfinder.hh"
|
|
|
|
#include "keyboardstate.hh"
|
2009-02-05 20:55:00 +00:00
|
|
|
#include "config.hh"
|
2009-01-28 20:55:45 +00:00
|
|
|
#include "ui_scanpopup.h"
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QClipboard>
|
2009-10-21 19:37:07 +00:00
|
|
|
#include "history.hh"
|
2010-03-30 20:15:55 +00:00
|
|
|
#include "dictionarybar.hh"
|
2011-07-14 08:17:59 +00:00
|
|
|
#include "mainstatusbar.hh"
|
2017-06-05 13:15:38 +00:00
|
|
|
#ifdef HAVE_X11
|
|
|
|
#include "scanflag.hh"
|
|
|
|
#endif
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-01 00:08:08 +00:00
|
|
|
/// This is a popup dialog to show translations when clipboard scanning mode
|
|
|
|
/// is enabled.
|
2010-03-30 20:15:55 +00:00
|
|
|
class ScanPopup: public QMainWindow, KeyboardState
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2009-02-01 00:08:08 +00:00
|
|
|
ScanPopup( QWidget * parent,
|
2009-02-06 17:04:11 +00:00
|
|
|
Config::Class & cfg,
|
2009-02-01 00:08:08 +00:00
|
|
|
ArticleNetworkAccessManager &,
|
2018-03-21 17:49:34 +00:00
|
|
|
AudioPlayerPtr const &,
|
2009-02-01 00:08:08 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > const & allDictionaries,
|
2009-10-21 19:37:07 +00:00
|
|
|
Instances::Groups const &,
|
|
|
|
History & );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-08 20:20:02 +00:00
|
|
|
~ScanPopup();
|
2009-04-21 18:27:26 +00:00
|
|
|
|
2023-02-23 00:44:29 +00:00
|
|
|
// update dictionary bar, group data and possibly other data
|
|
|
|
void refresh();
|
|
|
|
|
2009-04-30 20:20:05 +00:00
|
|
|
/// Applies current zoom factor to the popup's view. Should be called when
|
|
|
|
/// it's changed.
|
|
|
|
void applyZoomFactor();
|
2017-07-14 13:02:21 +00:00
|
|
|
void applyWordsZoomLevel();
|
2011-11-16 13:02:56 +00:00
|
|
|
/// Translate the word
|
|
|
|
void translateWord( QString const & word );
|
|
|
|
|
2013-02-27 13:12:46 +00:00
|
|
|
void setDictionaryIconSize();
|
|
|
|
|
2018-03-27 18:01:33 +00:00
|
|
|
void saveConfigData();
|
2022-11-20 06:19:27 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_X11
|
|
|
|
/// Interaction with scan flag window
|
|
|
|
void showScanFlag();
|
|
|
|
void hideScanFlag();
|
2022-12-29 02:36:02 +00:00
|
|
|
|
|
|
|
QTimer selectionDelayTimer;
|
2022-11-20 06:19:27 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-08 14:01:59 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
/// Forwarded from the dictionary bar, so that main window could act on this.
|
|
|
|
void editGroupRequested( unsigned id );
|
2011-11-16 12:52:25 +00:00
|
|
|
/// Send word to main window
|
2021-06-10 16:13:11 +00:00
|
|
|
void sendPhraseToMainWindow( Config::InputPhrase const & phrase );
|
2012-09-12 14:18:16 +00:00
|
|
|
/// Close opened menus when window hide
|
|
|
|
void closeMenu();
|
2023-03-21 06:00:23 +00:00
|
|
|
|
2022-09-08 13:11:25 +00:00
|
|
|
void inspectSignal(QWebEnginePage * page);
|
2012-09-16 10:19:47 +00:00
|
|
|
/// Signal to switch expand optional parts mode
|
|
|
|
void switchExpandMode();
|
2012-09-16 10:30:14 +00:00
|
|
|
/// Signal to add word to history even if history is disabled
|
|
|
|
void forceAddWordToHistory( const QString & word);
|
2012-09-25 13:13:35 +00:00
|
|
|
/// Retranslate signal from dictionary bar
|
|
|
|
void showDictionaryInfo( QString const & id );
|
2013-06-09 13:31:57 +00:00
|
|
|
void openDictionaryFolder( QString const & id );
|
2012-11-12 13:52:54 +00:00
|
|
|
/// Put translated word into history
|
|
|
|
void sendWordToHistory( QString const & word );
|
2017-05-15 15:08:06 +00:00
|
|
|
/// Put translated word into Favorites
|
|
|
|
void sendWordToFavorites( QString const & word, unsigned groupId );
|
2017-10-23 14:21:43 +00:00
|
|
|
/// Check is word already presented in Favorites
|
|
|
|
bool isWordPresentedInFavorites( QString const & word, unsigned groupId );
|
2010-05-08 14:01:59 +00:00
|
|
|
|
2012-09-24 13:20:58 +00:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
/// Ask for source window is current translate tab
|
|
|
|
bool isGoldenDictWindow( HWND hwnd );
|
|
|
|
#endif
|
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
public slots:
|
2013-01-29 21:30:24 +00:00
|
|
|
void requestWindowFocus();
|
2009-04-21 18:27:26 +00:00
|
|
|
|
2022-09-08 13:11:25 +00:00
|
|
|
void inspectElementWhenPinned( QWebEnginePage * page );
|
2009-04-21 18:27:26 +00:00
|
|
|
/// Translates the word from the clipboard, showing the window etc.
|
|
|
|
void translateWordFromClipboard();
|
2009-07-31 11:40:54 +00:00
|
|
|
/// Translates the word from the clipboard selection
|
|
|
|
void translateWordFromSelection();
|
2010-05-08 14:01:59 +00:00
|
|
|
/// From the dictionary bar.
|
|
|
|
void editGroupRequested();
|
2009-04-21 18:27:26 +00:00
|
|
|
|
2017-03-10 13:29:23 +00:00
|
|
|
void setGroupByName( QString const & name );
|
|
|
|
|
2017-06-05 13:15:38 +00:00
|
|
|
#ifdef HAVE_X11
|
|
|
|
void showEngagePopup();
|
|
|
|
#endif
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
private:
|
|
|
|
|
Allow customizing unpinned scan popup window flags on X11 with Qt5
My tests in many desktop environments and window managers indicate that
no single configuration works perfectly in all environments. There are
also behavior differences between Qt::Popup and Qt::Tool flags, which
are not exactly bugs, so I suppose users might subjectively prefer
different options.
Customizing the flags allows the user to prevent unpinned scan popup
window flickering with Qt5 on Linux. In a way adding these options fixes
issue #645, which is: the scan popup window blinks rapidly, barely
noticeably in some applications, such as Calibre ebook-viewer
and Chromium. In this case the scan popup window usually ends up hidden
when selection ends, unless it was finished with a jerk.
I have tested the new options in 9 desktop environments and window
managers: at least one configuration for each eliminates #645 and makes
the scan popup window work the same as with Qt4 in this regard:
the popup window remains visible, text in the popup's translation line
keeps up with the text selection in the external application,
and the selected text is being translated on the fly.
Moreover, for each tested DE/WM, at least one configuration makes
the scan popup window work perfectly as far as I am concerned.
This issue was partially worked around with a 200ms scan popup delay
timer in the recent commit 58e41fe3ceb769cab37608e36637044e597ba1f8
for the duplicate issue #854. However the timer solution is incomplete
because it requires the user to select text quickly and without delays.
If global mouse selection does not change for 200ms while the left mouse
button is held down, the user will likely not see the scan popup when
(s)he finishes selection, and will have to try selecting again -
hopefully faster this time.
The 200ms delay is no longer critically important after this commit,
but it is still beneficial: the lookup query changes less often,
which in turn reduces article definition update frequency.
So the delay improves the UI (perhaps subjectively) and performance.
2018-04-09 17:50:23 +00:00
|
|
|
Qt::WindowFlags unpinnedWindowFlags() const;
|
|
|
|
|
2009-07-31 11:40:54 +00:00
|
|
|
// Translates the word from the clipboard or the clipboard selection
|
|
|
|
void translateWordFromClipboard(QClipboard::Mode m);
|
|
|
|
|
2010-01-02 23:26:09 +00:00
|
|
|
// Hides the popup window, effectively closing it.
|
|
|
|
void hideWindow();
|
|
|
|
|
|
|
|
// Grabs mouse and installs global event filter to track it thoroughly.
|
|
|
|
void interceptMouse();
|
|
|
|
// Ungrabs mouse and uninstalls global event filter.
|
|
|
|
void uninterceptMouse();
|
|
|
|
|
2010-03-30 20:15:55 +00:00
|
|
|
void updateDictionaryBar();
|
|
|
|
|
2009-02-06 17:04:11 +00:00
|
|
|
Config::Class & cfg;
|
2009-02-01 00:08:08 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > const & allDictionaries;
|
2010-04-30 09:56:40 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > dictionariesUnmuted;
|
2009-02-01 00:08:08 +00:00
|
|
|
Instances::Groups const & groups;
|
2009-10-21 19:37:07 +00:00
|
|
|
History & history;
|
2009-01-28 20:55:45 +00:00
|
|
|
Ui::ScanPopup ui;
|
2009-02-01 00:08:08 +00:00
|
|
|
ArticleView * definition;
|
2013-01-25 15:42:44 +00:00
|
|
|
QAction escapeAction, switchExpandModeAction, focusTranslateLineAction;
|
2014-04-16 16:18:28 +00:00
|
|
|
QAction openSearchAction;
|
2021-06-10 16:13:11 +00:00
|
|
|
Config::InputPhrase pendingInputPhrase, inputPhrase;
|
|
|
|
QString translateBoxSuffix; ///< A punctuation suffix that corresponds to translateBox's text.
|
2009-02-01 00:08:08 +00:00
|
|
|
WordFinder wordFinder;
|
2010-03-30 20:15:55 +00:00
|
|
|
Config::Events configEvents;
|
|
|
|
DictionaryBar dictionaryBar;
|
2011-07-14 08:17:59 +00:00
|
|
|
MainStatusBar * mainStatusBar;
|
2017-07-14 13:02:21 +00:00
|
|
|
/// Fonts saved before words zooming is in effect, so it could be reset back.
|
2019-01-26 19:11:27 +00:00
|
|
|
QFont wordListDefaultFont, translateLineDefaultFont, groupListDefaultFont;
|
2009-02-01 00:08:08 +00:00
|
|
|
|
2017-06-05 13:15:38 +00:00
|
|
|
#ifdef HAVE_X11
|
|
|
|
ScanFlag * scanFlag;
|
|
|
|
#endif
|
|
|
|
|
2010-01-02 23:26:09 +00:00
|
|
|
bool mouseEnteredOnce;
|
|
|
|
bool mouseIntercepted;
|
|
|
|
|
2009-02-06 18:43:07 +00:00
|
|
|
QPoint startPos; // For window moving
|
2023-02-14 14:51:03 +00:00
|
|
|
QByteArray pinnedGeometry;
|
2009-02-06 18:43:07 +00:00
|
|
|
|
2009-04-10 13:56:38 +00:00
|
|
|
QTimer hideTimer; // When mouse leaves the window, a grace period is
|
|
|
|
// given for it to return back. If it doesn't before
|
|
|
|
// this timer expires, the window gets hidden.
|
|
|
|
|
2010-07-03 16:24:30 +00:00
|
|
|
QTimer mouseGrabPollTimer;
|
|
|
|
|
2017-10-23 14:21:43 +00:00
|
|
|
QIcon starIcon, blueStarIcon;
|
|
|
|
|
2012-09-24 13:20:58 +00:00
|
|
|
void handleInputWord( QString const & , bool forcePopup = false );
|
|
|
|
void engagePopup( bool forcePopup, bool giveFocus = false );
|
2009-02-01 00:08:08 +00:00
|
|
|
|
|
|
|
vector< sptr< Dictionary::Class > > const & getActiveDicts();
|
|
|
|
|
2010-01-02 23:26:09 +00:00
|
|
|
virtual bool eventFilter( QObject * watched, QEvent * event );
|
2010-07-03 16:24:30 +00:00
|
|
|
|
|
|
|
/// Called from event filter or from mouseGrabPoll to handle mouse event
|
|
|
|
/// while it is being intercepted.
|
|
|
|
void reactOnMouseMove( QPoint const & p );
|
|
|
|
|
2009-02-06 18:43:07 +00:00
|
|
|
virtual void mousePressEvent( QMouseEvent * );
|
|
|
|
virtual void mouseMoveEvent( QMouseEvent * );
|
|
|
|
virtual void mouseReleaseEvent( QMouseEvent * );
|
2009-02-01 00:08:08 +00:00
|
|
|
virtual void leaveEvent( QEvent * event );
|
2022-02-27 05:17:37 +00:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
|
|
|
virtual void enterEvent( QEnterEvent * event );
|
|
|
|
#else
|
2009-04-10 13:56:38 +00:00
|
|
|
virtual void enterEvent( QEvent * event );
|
2022-02-27 05:17:37 +00:00
|
|
|
#endif
|
2009-02-08 21:26:35 +00:00
|
|
|
virtual void showEvent( QShowEvent * );
|
2023-02-14 14:51:03 +00:00
|
|
|
virtual void closeEvent( QCloseEvent * );
|
2023-02-14 19:40:08 +00:00
|
|
|
virtual void moveEvent( QMoveEvent * );
|
2009-02-01 00:08:08 +00:00
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
/// Returns inputWord, chopped with appended ... if it's too long/
|
|
|
|
QString elideInputWord();
|
|
|
|
|
2012-12-24 12:59:46 +00:00
|
|
|
void updateBackForwardButtons();
|
|
|
|
|
2021-06-10 16:13:11 +00:00
|
|
|
void showTranslationFor( Config::InputPhrase const & inputPhrase );
|
|
|
|
|
|
|
|
void updateSuggestionList();
|
|
|
|
void updateSuggestionList( QString const & text );
|
2009-01-28 20:55:45 +00:00
|
|
|
private slots:
|
2012-09-24 13:20:58 +00:00
|
|
|
void mouseHovered( QString const & , bool forcePopup);
|
2022-02-27 06:26:49 +00:00
|
|
|
void currentGroupChanged( int );
|
2009-03-26 19:00:08 +00:00
|
|
|
void prefixMatchFinished();
|
2009-04-10 21:07:03 +00:00
|
|
|
void on_pronounceButton_clicked();
|
2009-02-01 00:08:08 +00:00
|
|
|
void pinButtonClicked( bool checked );
|
2010-03-30 20:15:55 +00:00
|
|
|
void on_showDictionaryBar_clicked( bool checked );
|
2011-07-14 20:11:57 +00:00
|
|
|
void showStatusBarMessage ( QString const &, int, QPixmap const & );
|
2011-11-16 12:52:25 +00:00
|
|
|
void on_sendWordButton_clicked();
|
2017-05-15 15:08:06 +00:00
|
|
|
void on_sendWordToFavoritesButton_clicked();
|
2012-12-24 12:59:46 +00:00
|
|
|
void on_goBackButton_clicked();
|
|
|
|
void on_goForwardButton_clicked();
|
2009-04-10 13:56:38 +00:00
|
|
|
|
|
|
|
void hideTimerExpired();
|
2009-04-10 21:07:03 +00:00
|
|
|
|
2010-07-03 16:24:30 +00:00
|
|
|
/// Called repeatedly once the popup is initially engaged and we monitor the
|
|
|
|
/// mouse as it may move away from the window. This simulates mouse grab, in
|
2017-09-16 13:14:26 +00:00
|
|
|
/// essence, but seems more reliable. Once the mouse enters the window, the
|
2010-07-03 16:24:30 +00:00
|
|
|
/// polling stops.
|
|
|
|
void mouseGrabPoll();
|
|
|
|
|
2009-05-14 19:42:04 +00:00
|
|
|
void pageLoaded( ArticleView * );
|
2009-05-16 11:14:43 +00:00
|
|
|
|
|
|
|
void escapePressed();
|
2010-03-30 20:15:55 +00:00
|
|
|
|
|
|
|
void mutedDictionariesChanged();
|
2012-09-16 10:19:47 +00:00
|
|
|
|
|
|
|
void switchExpandOptionalPartsMode();
|
2013-01-25 15:42:44 +00:00
|
|
|
|
|
|
|
void translateInputChanged(QString const & text);
|
|
|
|
void translateInputFinished();
|
|
|
|
void wordListItemActivated( QListWidgetItem * );
|
|
|
|
|
|
|
|
void focusTranslateLine();
|
|
|
|
|
|
|
|
void typingEvent( QString const & );
|
2017-06-13 15:00:16 +00:00
|
|
|
|
2017-07-13 15:00:19 +00:00
|
|
|
void alwaysOnTopClicked( bool checked );
|
|
|
|
|
2017-11-07 14:46:59 +00:00
|
|
|
void titleChanged( ArticleView *, QString const & title );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|