forked from goldendict/goldendict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacmouseover.hh
65 lines (46 loc) · 1.46 KB
/
macmouseover.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef __MACMOUSEOVER_HH_INCLUDED__
#define __MACMOUSEOVER_HH_INCLUDED__
#include <QObject>
#include <QTimer>
#include <ApplicationServices/ApplicationServices.h>
#include "config.hh"
#include "keyboardstate.hh"
#include "mutex.hh"
/// This is a mouseover feature interface, where you can point your mouse at
/// any word in any window and wait a little, and it would provide that word
/// for the translation.
class MacMouseOver: public QObject, public KeyboardState
{
Q_OBJECT
public:
/// The class is a singleton.
static MacMouseOver & instance();
/// Enables mouseover. The mouseover is initially disabled.
void enableMouseOver();
/// Disables mouseover.
void disableMouseOver();
/// Set pointer to program configuration
void setPreferencesPtr( Config::Preferences const *ppref ) { pPref = ppref; };
/// Called from event loop callback
void mouseMoved();
static bool isAXAPIEnabled();
signals:
/// Emitted when there was some text under cursor which was hovered over.
void hovered( QString const &, bool forcePopup );
private slots:
void timerShot();
private:
MacMouseOver();
~MacMouseOver();
void handlePosition();
QString CFStringRefToQString( CFStringRef str );
void handleRetrievedString( QString & wordSeq, int wordSeqPos );
Config::Preferences const *pPref;
QTimer mouseTimer;
CFMachPortRef tapRef;
CFRunLoopSourceRef loop;
Mutex mouseMutex;
AXUIElementRef elementSystemWide;
bool mouseOverEnabled;
};
#endif