summaryrefslogtreecommitdiffstats
path: root/bibletime/frontend/display/chtmlreaddisplay.h
blob: 5b875cf890354018e60799542f1e188d05eee965 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2006 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/



#ifndef CHTMLREADDISPLAY_H
#define CHTMLREADDISPLAY_H

//BibleTime includes
#include "creaddisplay.h"
//#include "frontend/ctooltip.h"

//Qt includes
#include <qstring.h>
#include <qwidget.h>

//KDE includes
#include <khtml_part.h>
#include <khtmlview.h>
#include <kparts/browserextension.h>

class CHTMLReadDisplayView;

/** The implementation for the HTML read display.
  * @author The BibleTime team
  */
class CHTMLReadDisplay : public KHTMLPart, 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 const bool hasSelection();
	/**
	* Reimplementation.
	*/
	virtual QScrollView* view();
	virtual void selectAll();
	virtual void moveToAnchor( const QString& anchor );

	virtual void zoomIn();
	virtual void zoomOut();
	virtual void openFindTextDialog();
	
	virtual QMap<CDisplay::NodeInfoType, QString> getCurrentNodeInfo() {
		return m_nodeInfo;
	}

protected:
	friend class CDisplay;
	CHTMLReadDisplay( CReadWindow* readWindow, QWidget* parent = 0 );
	virtual ~CHTMLReadDisplay();

	virtual void urlSelected( const QString& url, int button, int state, const QString& _target, KParts::URLArgs args);
	/**
	* Reimplementation.
	*/
	virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent* event );
	virtual void khtmlMousePressEvent( khtml::MousePressEvent* event );
	virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent* event );
	virtual void timerEvent(QTimerEvent *event);


	struct DNDData {
		bool mousePressed;
		bool isDragging;
		DOM::Node node;
		DOM::DOMString anchor;
		QString selection;
		QPoint startPos;
		enum DragType {
			Link,
			Text
		} dragType;
	}
	m_dndData;

	QMap<NodeInfoType, QString> m_nodeInfo;
		
private:
	CHTMLReadDisplayView* m_view;
	struct URLWorkaroundData {
		bool doWorkaround;
		QString url;
		int button;
		int state;
		QString target;
		KParts::URLArgs args;

		QString module;
		QString key;
	}
	m_urlWorkaroundData;

	DOM::Node m_previousEventNode;
	QString m_currentAnchorCache;

protected slots:
	void slotGoToAnchor();
};

class CHTMLReadDisplayView : public KHTMLView, public CPointers {
	Q_OBJECT
protected: // Protected methods
	friend class CHTMLReadDisplay;


	CHTMLReadDisplayView(CHTMLReadDisplay* display, QWidget* parent);
	/**
	* Reimplementation from QScrollView. Sets the right slots
	*/
	virtual void polish();
	/**
	* Reimplementatiob from QScrollView.
	*/
	virtual void contentsDropEvent( QDropEvent* );
	/**
	* Reimplementatiob from QScrollView.
	*/
	virtual void contentsDragEnterEvent( QDragEnterEvent* );

protected slots: // Protected slots
	/**
	* Opens the popupmenu at the given position.
	*/
	void popupMenu( const QString&, const QPoint& );

private:
	CHTMLReadDisplay* m_display;
};

#endif