summaryrefslogtreecommitdiff
path: root/src/frontend/display/bthtmlreaddisplay.h
blob: 99a91cf5a22908096e202c5ee03aab7ea77f8fe0 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2009 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/



#ifndef BTHTMLREADDISPLAY_H
#define BTHTMLREADDISPLAY_H

//BibleTime includes
#include "bthtmljsobject.h"
#include "creaddisplay.h"

//Qt includes
//Added by qt3to4:
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QTimerEvent>
#include <QWebView>
#include <QWebPage>
#include <QWebFrame>
#include <QPoint>

class BtHtmlReadDisplayView;
class QScrollArea;
class QWidget;
class QString;
class BtHtmlReadDisplay;


/** The implementation for the HTML read display.
  * @author The BibleTime team
  */
class BtHtmlReadDisplay : public QWebPage, public CReadDisplay {
	Q_OBJECT
public:
	//reimplemented functions from CDisplay
	// Returns the right text part in the specified format.
	virtual const QString text( const CDisplay::TextType format = CDisplay::HTMLText, const CDisplay::TextPart part = CDisplay::Document );

	// Sets the new text for this display widget.
	virtual void setText( const QString& newText );
	virtual bool hasSelection();

	// Reimplementation.
	virtual void selectAll();
	virtual void moveToAnchor( const QString& anchor );
	virtual void openFindTextDialog();
	virtual QMap<CDisplay::NodeInfoType, QString> getCurrentNodeInfo() 
	{
		return m_nodeInfo;
	}
	QWidget* view();
	void setLemma(const QString& lemma);

public slots:
	void loadJSObject();
	void slotLoadFinished(bool);

signals:
	void completed();

protected:
	friend class CDisplay;
	BtHtmlReadDisplay( CReadWindow* readWindow, QWidget* parent = 0 );
	virtual ~BtHtmlReadDisplay();
	void slotGoToAnchor(const QString& anchor);
	struct DNDData 
	{
		bool mousePressed;
		bool isDragging;
		QString selection;
		QPoint startPos;
		enum DragType 
		{
			Link,
			Text
		} dragType;
	}
	m_dndData;

	QMap<NodeInfoType, QString> m_nodeInfo;
	int m_magTimerId;

// For debugging javascript
//	void javaScriptConsoleMessage (const QString & message, int lineNumber, const QString & sourceID );

private:
	void initJavascript();
	BtHtmlReadDisplayView* m_view;
	BtHtmlJsObject* m_jsObject;
	QString m_currentAnchorCache;

};


class BtHtmlReadDisplayView : public QWebView, public CPointers 
{
	Q_OBJECT
protected:
	friend class BtHtmlReadDisplay;
	void contextMenuEvent(QContextMenuEvent* event);
	BtHtmlReadDisplayView(BtHtmlReadDisplay* display, QWidget* parent);
	~BtHtmlReadDisplayView();

private:
	BtHtmlReadDisplay* m_display;
	void dropEvent( QDropEvent* e );
	void dragEnterEvent( QDragEnterEvent* e );
	void dragMoveEvent( QDragMoveEvent* e );
};

#endif