forked from goldendict/goldendict
-
Notifications
You must be signed in to change notification settings - Fork 1
/
articlewebview.cc
57 lines (44 loc) · 1.44 KB
/
articlewebview.cc
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
/* This file is (c) 2008-2012 Konstantin Isakov <[email protected]>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "articlewebview.hh"
#include <QMouseEvent>
#include <QWebFrame>
void ArticleWebView::mousePressEvent( QMouseEvent * event )
{
if ( event->buttons() & Qt::MidButton )
midButtonPressed = true;
QWebView::mousePressEvent( event );
}
void ArticleWebView::mouseReleaseEvent( QMouseEvent * event )
{
bool noMidButton = !( event->buttons() & Qt::MidButton );
QWebView::mouseReleaseEvent( event );
if ( midButtonPressed & noMidButton )
midButtonPressed = false;
}
void ArticleWebView::mouseDoubleClickEvent( QMouseEvent * event )
{
QWebView::mouseDoubleClickEvent( event );
int scrollBarWidth = page()->mainFrame()->scrollBarGeometry( Qt::Vertical ).width();
int scrollBarHeight = page()->mainFrame()->scrollBarGeometry( Qt::Horizontal ).height();
// emit the signal only if we are not double-clicking on scrollbars
if ( ( event->x() < width() - scrollBarWidth ) &&
( event->y() < height() - scrollBarHeight ) )
{
emit doubleClicked();
}
}
void ArticleWebView::focusInEvent( QFocusEvent * event )
{
QWebView::focusInEvent( event );
switch( event->reason() )
{
case Qt::MouseFocusReason:
case Qt::TabFocusReason:
case Qt::BacktabFocusReason:
page()->mainFrame()->evaluateJavaScript("top.focus();");
break;
default:
break;
}
}