summaryrefslogtreecommitdiff
path: root/src/frontend/display/cdisplay.h
blob: 59a6a37ba5af6e6a7e9dcd1a1678284b725e2c12 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2008 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/



#ifndef CDISPLAY_H
#define CDISPLAY_H

//BibleTime includes
#include "util/cpointers.h"
#include "backend/managers/cswordbackend.h"

//Qt includes
#include <QMap>


class CDisplayConnections;
class CReadWindow;
class CWriteWindow;

class CDisplayWindow;
class CReadDisplay;
class CWriteDisplay;

class QMenu;

/** The base class for all display widgets.
  * @author The BibleTime team
  */
class CDisplay : public CPointers {
public:
	enum WriteDisplayType {
		HTMLDisplay = 0,
		PlainTextDisplay
	};

	static CReadDisplay* createReadInstance(CReadWindow* readWindow, QWidget* parent = 0);
	static CWriteDisplay* createWriteInstance( CWriteWindow* writeWindow, const WriteDisplayType& type = PlainTextDisplay, QWidget* parent = 0 );

	enum TextType {
		HTMLText, /* Used for HTML markup */
		PlainText /* Plain text without links etc. */
	};
	enum TextPart {
		Document, /* All text */
		SelectedText, /* Only the selected text */
		AnchorOnly,
		AnchorTextOnly,
		AnchorWithText
	};

	/**
	* Copies the given text with the specified format into the applications clipboard.
	*/
	virtual bool copy( const CDisplay::TextType format, const CDisplay::TextPart part );
	/**
	* Saves the given text with the specified format into the applications clipboard.
	*/
	virtual bool save( const CDisplay::TextType format, const CDisplay::TextPart part );

	//the pure virtual methods of this base class

	/** Returns the text in the given format.
	*
	*/
	virtual const QString text( const CDisplay::TextType format = CDisplay::HTMLText, const CDisplay::TextPart part = CDisplay::Document ) = 0;
	/**
	* Sets the new text for this display widget.
	*/
	virtual void setText( const QString& newText ) = 0;
	/**
	* Returns true if the display widget has a selection. Otherwise false.
	*/
	virtual bool hasSelection() = 0;
	/**
	* Returns the view of this display widget.
	*/
	virtual QWidget* view() = 0;
	/**
	*  Selects the document text.
	*/
	virtual void selectAll() = 0;
	/**
	* Returns the connections obect used for signas and slots.
	*/
	virtual CDisplayConnections* connectionsProxy() const;
	/**
	* Returns the parent window used for this display widget.
	*/
	CDisplayWindow* parentWindow() const;
	virtual void print( const CDisplay::TextPart, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) = 0;
	/**
	* Installs the popup which should be opened when the right mouse button was pressed.
	*/
	void installPopup( QMenu* popup );
	/**
	* Returns the popup menu which was set by installPopupMenu()
	*/
	QMenu* installedPopup();

	virtual void zoomIn() {}
	virtual void zoomOut() {}
	virtual void openFindTextDialog() {}

	enum NodeInfoType {
		Lemma
	};


	virtual QMap<NodeInfoType, QString> getCurrentNodeInfo() {
		return QMap<NodeInfoType, QString>();
	}

protected:
	/**
	* Used when a reference was dropped onto the widget.
	*/
	void emitReferenceDropped( const QString& reference );
	/**
	* Emits the signal which used when a reference was clicked.
	*/
	void emitReferenceClicked( const QString& reference );

protected:
	CDisplay(CDisplayWindow* parent);
	virtual ~CDisplay();

private:
	CDisplayWindow* m_parentWindow;
	CDisplayConnections* m_connections;
	QMenu* m_popup;
};

class CDisplayConnections : public QObject {
	Q_OBJECT
public:
	CDisplayConnections( CDisplay* parent );

public slots:
	virtual void selectAll();
	void emitReferenceClicked( const QString& module, const QString& key);
	void emitReferenceDropped( const QString& key );
	void emitTextChanged();

	//stuff which works in every CDisplay
	void saveAsPlain();
	void saveAsHTML();
	void saveAnchorWithText();

	void printAll(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions);
	void printAnchorWithText(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions);

	void copySelection();
	void copyAll();
	void copyAnchorWithText();
	void copyAnchorTextOnly();
	void copyAnchorOnly();

	void clear();

	void zoomIn();
	void zoomOut();

	void openFindTextDialog();

signals:
	void referenceClicked(const QString& module, const QString& key);
	void referenceDropped(const QString& key);
	void textChanged();

private:
	CDisplay* m_display;

	struct {
		QString module;
		QString key;
	} m_referenceClickedCache;
};

#endif