summaryrefslogtreecommitdiffstats
path: root/bibletime/frontend/display/cdisplay.cpp
blob: f4f5f04a4f867f8c6c0b810bb027065f591c5caf (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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*********
*
* 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.
*
**********/



#include "cdisplay.h"
#include "chtmlreaddisplay.h"
#include "cplainwritedisplay.h"
#include "chtmlwritedisplay.h"

#include "backend/creferencemanager.h"

#include "util/ctoolclass.h"


//Qt includes
#include <tqclipboard.h>
#include <tqpopupmenu.h>
#include <tqtimer.h>

//KDE includes
#include <kapplication.h>
#include <kfiledialog.h>
#include <klocale.h>


CDisplayConnections::CDisplayConnections( CDisplay* display ) : m_display(display) {}

void CDisplayConnections::selectAll() {
	m_display->selectAll();
}

void CDisplayConnections::saveAsHTML() {
	m_display->save(CDisplay::HTMLText, CDisplay::Document);
}

void CDisplayConnections::saveAsPlain() {
	m_display->save(CDisplay::PlainText, CDisplay::Document);
}

/** Emits the signal. */
void CDisplayConnections::emitReferenceClicked( const TQString& module, const TQString& key) {
	emit referenceClicked( module, key );
}

/** Emits the signal. */
void CDisplayConnections::emitReferenceDropped( const TQString& key) {
	emit referenceDropped(key);
}

/** Emits the signal. */
void CDisplayConnections::emitTextChanged() {
	emit textChanged();
}

void CDisplayConnections::copyAll() {
	m_display->copy(CDisplay::PlainText, CDisplay::Document);
}

/** No descriptions */
void CDisplayConnections::copySelection() {
	qWarning("copyign the selected text");
	m_display->copy(CDisplay::PlainText, CDisplay::SelectedText);
}

void CDisplayConnections::printAll(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
	m_display->print(CDisplay::Document, displayOptions, filterOptions);
}

void CDisplayConnections::printAnchorWithText(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
	m_display->print(CDisplay::AnchorWithText, displayOptions, filterOptions);
}

void CDisplayConnections::copyAnchorOnly() {
	m_display->copy(CDisplay::PlainText, CDisplay::AnchorOnly);
}

void CDisplayConnections::copyAnchorTextOnly() {
	m_display->copy(CDisplay::PlainText, CDisplay::AnchorTextOnly);
}

void CDisplayConnections::copyAnchorWithText() {
	m_display->copy(CDisplay::PlainText, CDisplay::AnchorWithText);
}

void CDisplayConnections::saveAnchorWithText() {
	m_display->save(CDisplay::PlainText, CDisplay::AnchorWithText);
}

void CDisplayConnections::clear() {
	m_display->setText(TQString::null);
}

void CDisplayConnections::zoomIn() {
	m_display->zoomIn();
}

void CDisplayConnections::zoomOut() {
	m_display->zoomOut();
}

void CDisplayConnections::openFindTextDialog() {
	m_display->openFindTextDialog();
}


/*----------------------*/

CReadDisplay* CDisplay::createReadInstance( CReadWindow* readWindow, TQWidget* parent ) {
	return new CHTMLReadDisplay(readWindow, parent);
}

CWriteDisplay* CDisplay::createWriteInstance( CWriteWindow* writeWindow, const CWriteDisplay::WriteDisplayType& type, TQWidget* parent ) {
	//  qWarning("CDisplay::createWriteInstance");
	if (type == PlainTextDisplay) {
		return new CPlainWriteDisplay(writeWindow, parent);
	}
	else {
		return new CHTMLWriteDisplay(writeWindow, parent);
	};
}


CDisplay::CDisplay(CDisplayWindow* parent) :
m_parentWindow(parent),
m_connections( new CDisplayConnections( this ) ),
m_popup(0) {}

CDisplay::~CDisplay() {
	delete m_connections;
}

const bool CDisplay::copy( const CDisplay::TextType format, const CDisplay::TextPart part  ) {
	const TQString content = text(format, part);

	QClipboard* cb = KApplication::clipboard();
	cb->setText(content);
	return true;
}

const bool CDisplay::save( const CDisplay::TextType format, const CDisplay::TextPart part ) {
	//  qWarning("CDisplay::save( const CDisplay::TextType format, const CDisplay::TextPart part  )");
	const TQString content = text(format, part);
	TQString filter = TQString::null;

	switch (format) {
		case HTMLText:
		filter = TQString("*.html *.htm | ") + i18n("HTML files") + TQString("\n *.* | All files (*.*)");
		break;
		case PlainText:
		filter = TQString("*.txt | ") + i18n("Text files") + TQString("\n *.* | All files (*.*)");
		break;
	};

	const TQString filename = KFileDialog::getSaveFileName(TQString::null, filter, 0, i18n("Save document ..."));

	if (!filename.isEmpty()) {
		CToolClass::savePlainFile(filename, content);
	}
	return true;
}

/** Emits the signal which used when a reference was clicked. */
void CDisplay::emitReferenceClicked( const TQString& reference ) {
	qWarning("reference clicked %s", reference.latin1());
	TQString module;
	TQString key;
	CReferenceManager::Type type;
	/*const bool ok = */
	CReferenceManager::decodeHyperlink(reference, module, key, type);
	if (module.isEmpty()) {
		module = CReferenceManager::preferredModule( type );
	}
	m_connections->emitReferenceClicked(module, key);
}

/** Used when a reference was dropped onto the widget. */
void CDisplay::emitReferenceDropped( const TQString& reference ) {
	TQString module;
	TQString key;
	CReferenceManager::Type type;
	/*const bool ok = */
	CReferenceManager::decodeHyperlink(reference, module, key, type);
	//  if (module.isEmpty()) {
	//    module = CReferenceManager::preferredModule( type );
	//  }

	m_connections->emitReferenceDropped(key);
}

/** Returns the connections obect used for signas and slots. */
CDisplayConnections* const CDisplay::connectionsProxy() const {
	return m_connections;
}

CDisplayWindow* const CDisplay::parentWindow() const {
	return m_parentWindow;
}

/** Installs the popup which should be opened when the right mouse button was pressed. */
void CDisplay::installPopup( TQPopupMenu* popup ) {
	m_popup = popup;
}

/** Returns the popup menu which was set by installPopupMenu() */
TQPopupMenu* const CDisplay::installedPopup() {
	Q_ASSERT(m_popup);
	return m_popup;
}