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"
|
2009-02-01 00:08:08 +00:00
|
|
|
#include "articleview.hh"
|
|
|
|
#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"
|
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 &,
|
|
|
|
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();
|
|
|
|
|
|
|
|
/// Enables scanning. When the object is created, the scanning is disabled
|
|
|
|
/// initially.
|
|
|
|
void enableScanning();
|
|
|
|
/// Disables scanning.
|
|
|
|
void disableScanning();
|
2009-04-21 18:27:26 +00:00
|
|
|
|
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();
|
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();
|
|
|
|
|
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
|
|
|
|
void sendWordToMainWindow( QString const & word );
|
2012-09-12 14:18:16 +00:00
|
|
|
/// Close opened menus when window hide
|
|
|
|
void closeMenu();
|
2012-09-25 13:13:35 +00:00
|
|
|
/// Signals to set expand optional parts mode (retranslation from/to MainWindow and dictionary bar)
|
2012-09-16 10:19:47 +00:00
|
|
|
void setExpandMode( bool expand );
|
|
|
|
void setViewExpandMode( bool expand );
|
|
|
|
/// 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 );
|
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
|
|
|
|
|
|
|
/// 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
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
private:
|
|
|
|
|
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-08 20:20:02 +00:00
|
|
|
bool isScanningEnabled;
|
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;
|
2009-04-11 16:44:14 +00:00
|
|
|
QString pendingInputWord, inputWord;
|
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;
|
2009-02-01 00:08:08 +00:00
|
|
|
|
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
|
|
|
|
|
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.
|
2009-04-11 16:44:14 +00:00
|
|
|
QTimer altModeExpirationTimer, altModePollingTimer; // Timers for alt mode
|
2009-04-10 13:56:38 +00:00
|
|
|
|
2010-07-03 16:24:30 +00:00
|
|
|
QTimer mouseGrabPollTimer;
|
|
|
|
|
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 );
|
2009-04-10 13:56:38 +00:00
|
|
|
virtual void enterEvent( QEvent * event );
|
2009-02-08 21:26:35 +00:00
|
|
|
virtual void showEvent( QShowEvent * );
|
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();
|
|
|
|
|
2013-01-25 15:42:44 +00:00
|
|
|
void showTranslationFor( QString const & inputWord );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
private slots:
|
|
|
|
|
|
|
|
void clipboardChanged( QClipboard::Mode );
|
2012-09-24 13:20:58 +00:00
|
|
|
void mouseHovered( QString const & , bool forcePopup);
|
2009-02-01 00:08:08 +00:00
|
|
|
void currentGroupChanged( QString const & );
|
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();
|
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-11 16:44:14 +00:00
|
|
|
void altModeExpired();
|
|
|
|
void altModePoll();
|
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
|
|
|
|
/// essense, but seems more reliable. Once the mouse enters the window, the
|
|
|
|
/// 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 & );
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|