2009-02-05 14:21:47 +00:00
|
|
|
/* This file is (c) 2008-2009 Konstantin Isakov <ikm@users.berlios.de>
|
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"
|
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.
|
|
|
|
class ScanPopup: public QDialog, 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();
|
|
|
|
|
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();
|
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();
|
|
|
|
|
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;
|
|
|
|
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-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
|
|
|
|
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 );
|
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-06 17:16:33 +00:00
|
|
|
virtual void resizeEvent( QResizeEvent * 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 );
|
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
|
|
|
|
2009-05-14 19:42:04 +00:00
|
|
|
void pageLoaded( ArticleView * );
|
2009-05-16 11:14:43 +00:00
|
|
|
|
|
|
|
void escapePressed();
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|