1 /* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
2  * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
3 
4 #ifndef __ARTICLEWEBVIEW_HH_INCLUDED__
5 #define __ARTICLEWEBVIEW_HH_INCLUDED__
6 
7 #include <QWebView>
8 #include "config.hh"
9 
10 class ArticleInspector;
11 
12 /// A thin wrapper around QWebView to accommodate to some ArticleView's needs.
13 /// Currently the only added features:
14 /// 1. Ability to know if the middle mouse button is pressed or not according
15 ///    to the view's current state. This is used to open links in new tabs when
16 ///    they are clicked with middle button. There's also an added possibility to
17 ///    get double-click events after the fact with the doubleClicked() signal.
18 /// 2. Manage our own QWebInspector instance. In order to show inspector correctly,
19 ///    use triggerPageAction( QWebPage::InspectElement ) instead.
20 class ArticleWebView: public QWebView
21 {
22   Q_OBJECT
23 
24 public:
25 
26   ArticleWebView( QWidget * parent );
27   ~ArticleWebView();
28 
29   void setUp( Config::Class * cfg );
30 
isMidButtonPressed() const31   bool isMidButtonPressed() const
32   { return midButtonPressed; }
setSelectionBySingleClick(bool set)33   void setSelectionBySingleClick( bool set )
34   { selectionBySingleClick = set; }
35 
36   void triggerPageAction( QWebPage::WebAction action, bool checked = false );
37 
38 signals:
39 
40   /// Signals that the user has just double-clicked. The signal is delivered
41   /// after the event was processed by the view -- that's the difference from
42   /// installing an event filter. This is used for translating the double-clicked
43   /// word, which gets selected by the view in response to double-click.
44   void doubleClicked( QPoint pos );
45 
46 protected:
47 
48   bool event( QEvent * event );
49   void mousePressEvent( QMouseEvent * event );
50   void mouseReleaseEvent( QMouseEvent * event );
51   void mouseDoubleClickEvent( QMouseEvent * event );
52   void focusInEvent( QFocusEvent * event );
53   void wheelEvent( QWheelEvent * event );
54 
55 private:
56 
57   Config::Class * cfg;
58   ArticleInspector * inspector;
59 
60   bool midButtonPressed;
61   bool selectionBySingleClick;
62   bool showInspectorDirectly;
63 };
64 
65 #endif
66