summaryrefslogtreecommitdiffstats
path: root/bibletime/frontend/displaywindow/clexiconreadwindow.cpp
blob: b43f8a038da4633695b7aef5729c87d29dc0be82 (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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*********
*
* 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.
*
**********/



//BibleTime includes
#include "clexiconreadwindow.h"
#include "cmodulechooserbar.h"
#include "cbuttons.h"

#include "backend/cswordkey.h"
#include "backend/cswordldkey.h"

#include "frontend/cbtconfig.h"
#include "frontend/cexportmanager.h"
#include "frontend/display/cdisplay.h"
#include "frontend/display/creaddisplay.h"
#include "frontend/keychooser/ckeychooser.h"

#include "util/ctoolclass.h"
#include "util/cresmgr.h"

//TQt includes

//KDE includes
#include <tdeaccel.h>
#include <tdetoolbar.h>
#include <tdelocale.h>
#include <tdepopupmenu.h>
#include <tdeversion.h>
// #include <tdeactionclasses.h>

CLexiconReadWindow::CLexiconReadWindow(ListCSwordModuleInfo moduleList, CMDIArea* parent, const char *name) : CReadWindow(moduleList, parent,name) {
	setKey( CSwordKey::createInstance(moduleList.first()) );
}

CLexiconReadWindow::~CLexiconReadWindow() {}

void CLexiconReadWindow::insertKeyboardActions( TDEActionCollection* const a ) {
	new TDEAction(
		i18n("Next entry"), CResMgr::displaywindows::lexiconWindow::nextEntry::accel,
		a, "nextEntry"
	);
	new TDEAction(
		i18n("Previous entry"), CResMgr::displaywindows::lexiconWindow::previousEntry::accel,
		a, "previousEntry"
	);

	//  new TDEAction(i18n("Copy reference only"), TDEShortcut(0), a, "copyReferenceOnly");
	new TDEAction(i18n("Copy entry with text"), TDEShortcut(0), a, "copyEntryWithText");
	//  new TDEAction(i18n("Copy selected text"), TDEShortcut(0), a, "copySelectedText");
	new TDEAction(i18n("Save entry as plain text"), TDEShortcut(0), a, "saveEntryAsPlainText");
	new TDEAction(i18n("Save entry as HTML"), TDEShortcut(0), a, "saveEntryAsHTML");
	//   new TDEAction(i18n("Print reference only"), TDEShortcut(0), a, "printReferenceOnly");
	new TDEAction(i18n("Print entry with text"), TDEShortcut(0), a, "printEntryWithText");
}

void CLexiconReadWindow::initActions() {
	CReadWindow::initActions();

	m_actions.backInHistory = dynamic_cast<TDEToolBarPopupAction*>(
								  actionCollection()->action(
									  CResMgr::displaywindows::general::backInHistory::actionName
								  )
							  );
	Q_ASSERT(m_actions.backInHistory);

	m_actions.forwardInHistory = dynamic_cast<TDEToolBarPopupAction*>(
									 actionCollection()->action(
										 CResMgr::displaywindows::general::forwardInHistory::actionName
									 )
								 );

	Q_ASSERT(m_actions.forwardInHistory);

	new TDEAction(
		i18n("Next entry"), CResMgr::displaywindows::lexiconWindow::nextEntry::accel,
		TQT_TQOBJECT(this), TQT_SLOT( nextEntry() ),
		actionCollection(), "nextEntry"
	);
	new TDEAction(
		i18n("Previous entry"), CResMgr::displaywindows::lexiconWindow::previousEntry::accel,
		TQT_TQOBJECT(this), TQT_SLOT( previousEntry() ),
		actionCollection(), "previousEntry"
	);

	m_actions.selectAll = actionCollection()->action("selectAll");
	Q_ASSERT(m_actions.selectAll);

	m_actions.findText = actionCollection()->action("findText");
	Q_ASSERT(m_actions.findText);
	
	//m_actions.findStrongs = new TDEAction(i18n("Strong's Search"), TDEShortcut(0),this, TQT_SLOT(openSearchStrongsDialog()), actionCollection(), "findStrongs");
	m_actions.findStrongs = new TDEAction(
		i18n("Strong's Search"),
		CResMgr::displaywindows::general::findStrongs::icon,
		CResMgr::displaywindows::general::findStrongs::accel,
		TQT_TQOBJECT(this), TQT_SLOT(openSearchStrongsDialog()),
		actionCollection(),
		CResMgr::displaywindows::general::findStrongs::actionName);

	m_actions.copy.reference = new TDEAction(i18n("Reference only"), TDEShortcut(0), displayWidget()->connectionsProxy(), TQT_SLOT(copyAnchorOnly()), actionCollection(), "copyReferenceOnly");

	m_actions.copy.entry = new TDEAction(i18n("Entry with text"), TDEShortcut(0), displayWidget()->connectionsProxy(), TQT_SLOT(copyAll()), actionCollection(), "copyEntryWithText");

	m_actions.copy.selectedText = actionCollection()->action("copySelectedText");
	Q_ASSERT(m_actions.copy.selectedText);

	m_actions.save.entryAsPlain = new TDEAction(i18n("Entry as plain text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(saveAsPlain()),actionCollection(), "saveEntryAsPlain");

	m_actions.save.entryAsHTML = new TDEAction(i18n("Entry as HTML"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(saveAsHTML()), actionCollection(), "saveEntryAsHTML");

	m_actions.print.reference = new TDEAction(i18n("Reference only"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(printAnchorWithText()), actionCollection(), "printReferenceOnly");

	m_actions.print.entry = new TDEAction(i18n("Entry with text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(printAll()), actionCollection(), "printEntryWithText");

	// init with the user defined settings
	CBTConfig::setupAccelSettings(CBTConfig::lexiconWindow, actionCollection());
};

/** No descriptions */
void CLexiconReadWindow::initConnections() {
	Q_ASSERT(keyChooser());

	connect(keyChooser(), TQT_SIGNAL(keyChanged(CSwordKey*)),
			TQT_TQOBJECT(this), TQT_SLOT(lookup(CSwordKey*)));
	connect(keyChooser(), TQT_SIGNAL(historyChanged()),
			TQT_TQOBJECT(this), TQT_SLOT(slotUpdateHistoryButtons()));

	//connect the history actions to the right slots
	connect(
		m_actions.backInHistory->popupMenu(), TQT_SIGNAL(aboutToShow()),
		TQT_TQOBJECT(this), TQT_SLOT(slotFillBackHistory())
	);
	connect(
		m_actions.backInHistory->popupMenu(), TQT_SIGNAL(activated(int)),
		keyChooser(), TQT_SLOT(backInHistory(int))
	);
	connect(
		m_actions.forwardInHistory->popupMenu(), TQT_SIGNAL(aboutToShow()),
		TQT_TQOBJECT(this), TQT_SLOT(slotFillForwardHistory())
	);
	connect(
		m_actions.forwardInHistory->popupMenu(), TQT_SIGNAL(activated(int)),
		keyChooser(), TQT_SLOT(forwardInHistory(int))
	);


}

void CLexiconReadWindow::initView() {
	setDisplayWidget( CDisplay::createReadInstance(this) );

	setMainToolBar( new TDEToolBar(this) );
	addDockWindow(mainToolBar());

	setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) );

	mainToolBar()->insertWidget(0, keyChooser()->sizeHint().width(), keyChooser());
	mainToolBar()->setFullSize(false);

	setModuleChooserBar( new CModuleChooserBar(modules(), modules().first()->type(), this) );
	addDockWindow(moduleChooserBar());

	setButtonsToolBar( new TDEToolBar(this) );
	addDockWindow(buttonsToolBar());
	
	setIcon(CToolClass::getIconForModule(modules().first()));
	setCentralWidget( displayWidget()->view() );
}

void CLexiconReadWindow::initToolbars() {
	//main toolbar
	Q_ASSERT(m_actions.backInHistory);
	m_actions.backInHistory->plug( mainToolBar(),0 ); //1st button
	m_actions.forwardInHistory->plug( mainToolBar(),1 ); //2nd button

	//buttons toolbar
	TDEAction* action = actionCollection()->action(
		CResMgr::displaywindows::general::search::actionName);
	Q_ASSERT( action );
	if (action) {
		action->plug(buttonsToolBar());
	}
	#if TDE_VERSION_MINOR < 1
	action->plugAccel( accel() );
	#endif

	setDisplaySettingsButton( new CDisplaySettingsButton( &displayOptions(), &filterOptions(), modules(), buttonsToolBar()) );
	buttonsToolBar()->insertWidget(2,displaySettingsButton()->size().width(), displaySettingsButton());
}

void CLexiconReadWindow::setupPopupMenu() {
	popup()->insertTitle(CToolClass::getIconForModule(modules().first()), i18n("Lexicon window"));

	//   m_actions.selectAll = new TDEAction(i18n("Select all"), TDEShortcut(0), displayWidget()->connectionsProxy(), TQT_SLOT(selectAll()), actionCollection());
	m_actions.findText->plug(popup());
	m_actions.findStrongs->plug(popup());
	
	m_actions.selectAll->plug(popup());

	
	(new TDEActionSeparator(TQT_TQOBJECT(this)))->plug( popup() );

	m_actions.copyMenu = new TDEActionMenu(i18n("Copy..."), CResMgr::displaywindows::lexiconWindow::copyMenu::icon, actionCollection());
	m_actions.copyMenu->setDelayed(false);

	m_actions.copyMenu->insert(m_actions.copy.reference);
	m_actions.copyMenu->insert(m_actions.copy.entry);
	m_actions.copyMenu->insert(new TDEActionSeparator(TQT_TQOBJECT(this)));
	m_actions.copyMenu->insert(m_actions.copy.selectedText);
	m_actions.copyMenu->plug(popup());

	m_actions.saveMenu = new TDEActionMenu(i18n("Save..."), CResMgr::displaywindows::lexiconWindow::saveMenu::icon, actionCollection());
	m_actions.saveMenu->setDelayed(false);
	m_actions.saveMenu->insert(m_actions.save.entryAsPlain);
	m_actions.saveMenu->insert(m_actions.save.entryAsHTML);
	m_actions.saveMenu->plug(popup());

	m_actions.printMenu = new TDEActionMenu(i18n("Print..."), CResMgr::displaywindows::lexiconWindow::printMenu::icon, actionCollection());
	m_actions.printMenu->setDelayed(false);
	m_actions.printMenu->insert(m_actions.print.reference);
	m_actions.printMenu->insert(m_actions.print.entry);
	m_actions.printMenu->plug(popup());
}

/** Reimplemented. */
void CLexiconReadWindow::updatePopupMenu() {
	//enable the action depending on the supported module features
/*	bool hasStrongs = false;
	ListCSwordModuleInfo mods = modules();
	for (ListCSwordModuleInfo::iterator it = mods.begin(); it != mods.end(); ++it) {
		if ( (*it)->has( CSwordModuleInfo::strongNumbers ) ) {
			hasStrongs = true;
			break;
		}
	}
	m_actions.findStrongs->setEnabled( hasStrongs );*/
	m_actions.findStrongs->setEnabled( displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != TQString() );
	
	m_actions.copy.reference->setEnabled( displayWidget()->hasActiveAnchor() );
	//m_actions.copy.entry->setEnabled( displayWidget()->hasActiveAnchor() );
	m_actions.copy.selectedText->setEnabled( displayWidget()->hasSelection() );

	m_actions.print.reference->setEnabled( displayWidget()->hasActiveAnchor() );
}

/** No descriptions */
void CLexiconReadWindow::nextEntry() {
	keyChooser()->setKey(ldKey()->NextEntry());
}

/** No descriptions */
void CLexiconReadWindow::previousEntry() {
	keyChooser()->setKey(ldKey()->PreviousEntry());
}

/** Reimplementation to return the right key. */
CSwordLDKey* CLexiconReadWindow::ldKey() {
	return dynamic_cast<CSwordLDKey*>(CDisplayWindow::key());
}

/** This function saves the entry as html using the CExportMgr class. */
void CLexiconReadWindow::saveAsHTML() {
	CExportManager mgr(i18n("Saving entry ..."), true, i18n("Saving"), filterOptions(), displayOptions());
	mgr.saveKey(key(), CExportManager::HTML, true);
}

/** This function saves the entry as html using the CExportMgr class. */
void CLexiconReadWindow::saveAsPlain() {
	CExportManager mgr(i18n("Saving entry ..."), true, i18n("Saving"), filterOptions(), displayOptions());
	mgr.saveKey(key(), CExportManager::Text, true);
}

void CLexiconReadWindow::slotFillBackHistory() {
	//  tqWarning("fill back history");
	TQStringList keyList = keyChooser()->getPreviousKeys();
	TQPopupMenu* menu = m_actions.backInHistory->popupMenu();
	menu->clear();

	TQStringList::iterator it;
	int index = 1;
	for (it = keyList.begin(); it != keyList.end(); ++it) {
		menu->insertItem(*it,index, index);
		++index;
	}
}

void CLexiconReadWindow::slotFillForwardHistory() {
	//  tqWarning("fill forward history");
	TQStringList keyList = keyChooser()->getNextKeys();
	TQPopupMenu* menu = m_actions.forwardInHistory->popupMenu();
	menu->clear();

	TQStringList::iterator it;
	int index = 1;
	for (it = keyList.begin(); it != keyList.end(); ++it) {
		menu->insertItem(*it,index, index);
		++index;
	}
}


void CLexiconReadWindow::slotUpdateHistoryButtons() {
	//  tqWarning("updating history buttons");
	Q_ASSERT(m_actions.backInHistory);
	Q_ASSERT(keyChooser());

	m_actions.backInHistory->setEnabled( keyChooser()->getPreviousKeys().size() > 0 );
	m_actions.forwardInHistory->setEnabled( keyChooser()->getNextKeys().size() > 0 );
}