2010-12-09 12:31:50 +00:00
|
|
|
/* This file is (c) 2008-2011 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"
|
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();
|
|
|
|
|
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 );
|
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
public slots:
|
|
|
|
|
|
|
|
/// 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;
|
2009-05-16 11:14:43 +00:00
|
|
|
QAction escapeAction;
|
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;
|
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;
|
|
|
|
|
2009-02-02 20:28:53 +00:00
|
|
|
void handleInputWord( QString const & );
|
2010-01-02 23:26:09 +00:00
|
|
|
void engagePopup( bool giveFocus = false );
|
2009-02-01 00:08:08 +00:00
|
|
|
void initiateTranslation();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
private slots:
|
|
|
|
|
|
|
|
void clipboardChanged( QClipboard::Mode );
|
2009-02-02 20:28:53 +00:00
|
|
|
void mouseHovered( QString const & );
|
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 15:52:08 +00:00
|
|
|
void on_wordListButton_clicked();
|
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 );
|
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
|
|
|
|
2011-07-09 19:26:30 +00:00
|
|
|
#ifdef Q_OS_WIN32
|
2011-06-17 12:15:41 +00:00
|
|
|
void needHandleWord(bool *pNeed);
|
2011-07-09 19:26:30 +00:00
|
|
|
void useUIAutomation(bool *pUse);
|
|
|
|
void useIAccessibleEx(bool *pUse);
|
|
|
|
void useGDMessage(bool *pUse);
|
|
|
|
#endif
|
2011-06-17 12:15:41 +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();
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|