3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
5
* Copyright 1999-2006 by the BibleTime developers.
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
13
#include "cdisplaywindow.h"
14
#include "creadwindow.h"
15
#include "cbiblereadwindow.h"
16
#include "ccommentaryreadwindow.h"
17
#include "clexiconreadwindow.h"
18
#include "cbookreadwindow.h"
20
#include "cwritewindow.h"
21
#include "cplainwritewindow.h"
22
#include "chtmlwritewindow.h"
24
#include "cmodulechooserbar.h"
27
#include "backend/cswordkey.h"
29
#include "frontend/keychooser/ckeychooser.h"
31
#include "frontend/display/cdisplay.h"
33
#include "frontend/cmdiarea.h"
34
#include "frontend/cprofilewindow.h"
35
#include "frontend/cbtconfig.h"
37
#include "frontend/searchdialog/csearchdialog.h"
39
#include "util/cresmgr.h"
45
#include <kdeversion.h>
49
using namespace Profile;
51
CReadWindow* CDisplayWindow::createReadInstance(ListCSwordModuleInfo modules, CMDIArea* parent, const char* name) {
52
switch (modules.first()->type()) {
53
case CSwordModuleInfo::Bible:
54
return new CBibleReadWindow(modules, parent, name);
55
case CSwordModuleInfo::Commentary:
56
return new CCommentaryReadWindow(modules, parent, name);
57
case CSwordModuleInfo::Lexicon:
58
return new CLexiconReadWindow(modules, parent, name);
59
case CSwordModuleInfo::GenericBook:
60
return new CBookReadWindow(modules, parent, name);
62
qWarning("unknown module type");
69
CWriteWindow* CDisplayWindow::createWriteInstance(ListCSwordModuleInfo modules, CMDIArea* parent, const CDisplayWindow::WriteWindowType type, const char* name) {
70
if (type == HTMLWindow) {
71
return new CHTMLWriteWindow(modules, parent, name);
74
return new CPlainWriteWindow(modules, parent, name);
79
CDisplayWindow::CDisplayWindow(ListCSwordModuleInfo modules, CMDIArea *parent, const char *name )
80
#if KDE_VERSION >= 0x030200
81
: KMainWindow(KMainWindow::NoDCOPObject, parent, name, WDestructiveClose),
83
: KMainWindow(parent, name, WDestructiveClose),
88
m_displaySettingsButton(0),
92
m_moduleChooserBar(0),
99
CDisplayWindow::~CDisplayWindow() {
104
CMDIArea* const CDisplayWindow::mdi() const {
108
/** Returns the right window caption. */
109
const QString CDisplayWindow::windowCaption() {
110
if (!m_modules.count()) {
111
return QString::null;
114
return QString(key()->key()).append(" (").append(m_modules.join(" | ")).append(")");
117
/** Returns the used modules as a QPtrList */
118
ListCSwordModuleInfo CDisplayWindow::modules() {
119
ListCSwordModuleInfo mods;
121
for (QStringList::iterator it = m_modules.begin(); it != m_modules.end(); ++it) {
122
Q_ASSERT(backend()->findModuleByName(*it));
123
if (CSwordModuleInfo* m = backend()->findModuleByName(*it)) {
131
/** Set the window caption. */
132
void CDisplayWindow::setCaption( const QString& ) {
133
QWidget::setCaption( windowCaption() );
134
m_mdi->emitWindowCaptionChanged();
137
void CDisplayWindow::insertKeyboardActions( KActionCollection* const a ) {
138
KStdAction::zoomIn(0, 0, a, "zoomIn"); //no slot
139
KStdAction::zoomOut(0, 0, a, "zoomOut"); //no slot
140
KStdAction::close(0, 0, a, "closeWindow"); //no slot
141
KStdAction::selectAll(0, 0, a, "selectAll");
142
KStdAction::copy(0, 0, a, "copySelectedText");
143
KStdAction::find(0, 0, a, "findText");
145
new KToolBarPopupAction(
146
i18n("Back in history"),
147
CResMgr::displaywindows::general::backInHistory::icon,
148
CResMgr::displaywindows::general::backInHistory::accel,
150
CResMgr::displaywindows::general::backInHistory::actionName
152
new KToolBarPopupAction(
153
i18n("Forward in history"),
154
CResMgr::displaywindows::general::forwardInHistory::icon,
155
CResMgr::displaywindows::general::forwardInHistory::accel,
156
a, CResMgr::displaywindows::general::forwardInHistory::actionName
160
void CDisplayWindow::initActions() {
161
new KAction(i18n("Search"),
162
CResMgr::displaywindows::general::search::icon,
163
CResMgr::displaywindows::general::search::accel,
164
this, SLOT(slotSearchInModules()),
165
actionCollection(), CResMgr::displaywindows::general::search::actionName
169
displayWidget()->connectionsProxy(), SLOT(zoomIn()),
170
actionCollection(), "zoomIn"
173
displayWidget()->connectionsProxy(), SLOT(zoomOut()),
174
actionCollection(), "zoomOut"
178
actionCollection(), "closeWindow"
181
KStdAction::selectAll(
182
displayWidget()->connectionsProxy(), SLOT(selectAll()),
183
actionCollection(), "selectAll"
187
displayWidget()->connectionsProxy(), SLOT(copySelection()),
188
actionCollection(), "copySelectedText"
192
displayWidget()->connectionsProxy(), SLOT(openFindTextDialog()),
193
actionCollection(), "findText"
196
new KToolBarPopupAction(
197
i18n("Back in history"), CResMgr::displaywindows::general::backInHistory::icon, CResMgr::displaywindows::general::backInHistory::accel,
198
keyChooser(), SLOT( backInHistory() ),
199
actionCollection(), CResMgr::displaywindows::general::backInHistory::actionName
202
new KToolBarPopupAction(
203
i18n("Forward in history"), CResMgr::displaywindows::general::forwardInHistory::icon, CResMgr::displaywindows::general::forwardInHistory::accel,
204
keyChooser(), SLOT( forwardInHistory() ),
205
actionCollection(), CResMgr::displaywindows::general::forwardInHistory::actionName
208
CBTConfig::setupAccelSettings(CBTConfig::allWindows, actionCollection());
211
/** Is called when this window gets the focus or looses the focus. */
212
void CDisplayWindow::windowActivated( const bool hasFocus ) {
214
accel()->setEnabled(hasFocus);
218
/** Refresh the settings of this window. */
219
void CDisplayWindow::reload() {
220
//first make sure all used Sword modules are still present
221
for (QStringList::iterator it = m_modules.begin(); it != m_modules.end(); ++it) {
222
if (!backend()->findModuleByName(*it)) {
223
it = m_modules.remove(it);
224
if (it == m_modules.end()) {
229
if (m_modules.count() == 0){
234
if (keyChooser()) keyChooser()->setModules( modules(), false );
236
if (m_moduleChooserBar) { //necessary for edit windows which have now chooser bar
237
m_moduleChooserBar->setModules(modules());
243
/** Returns the filter options used by this window. */
244
CSwordBackend::FilterOptions& CDisplayWindow::filterOptions() {
245
return m_filterOptions;
248
/** Returns the display options used by this display window. */
249
CSwordBackend::DisplayOptions& CDisplayWindow::displayOptions() {
250
return m_displayOptions;
253
/** Sets the new display options for this window. */
254
void CDisplayWindow::setDisplayOptions( const CSwordBackend::DisplayOptions& displayOptions ) {
255
m_displayOptions = displayOptions;
258
/** Sets the new filter options of this window. */
259
void CDisplayWindow::setFilterOptions( CSwordBackend::FilterOptions& filterOptions ) {
260
m_filterOptions = filterOptions;
263
/** Returns true if the widget is ready for use. */
264
const bool CDisplayWindow::isReady() const {
268
/** Set the ready status */
269
void CDisplayWindow::setReady( const bool& ready ) {
273
/** Returns true if the window may be closed. */
274
bool CDisplayWindow::queryClose() {
278
/** Returns the keychooser widget of this display window. */
279
CKeyChooser* const CDisplayWindow::keyChooser() const {
283
/** Sets the keychooser widget for this display window. */
284
void CDisplayWindow::setKeyChooser( CKeyChooser* ck ) {
288
/** Returns the key of this display window. */
289
CSwordKey* CDisplayWindow::key() const {
290
Q_ASSERT( m_swordKey );
294
/** Sets the new sword key. */
295
void CDisplayWindow::setKey( CSwordKey* key ) {
300
void CDisplayWindow::modulesChanged() {
301
if (moduleChooserBar()) { //necessary for write windows
302
setModules( m_moduleChooserBar->getModuleList() );
305
if (!modules().count()) {
309
if (displaySettingsButton()) {
310
displaySettingsButton()->reset(modules());
313
key()->module(modules().first());
314
keyChooser()->setModules(modules());
318
/** Returns the module chooser bar. */
319
CModuleChooserBar* const CDisplayWindow::moduleChooserBar() const {
320
return m_moduleChooserBar;
323
/** Sets the module chooser bar. */
324
void CDisplayWindow::setModuleChooserBar( CModuleChooserBar* bar ) {
325
if (m_moduleChooserBar) {
326
disconnect(m_moduleChooserBar, SIGNAL(sigChanged()), this, SLOT(modulesChanged()));
329
//if a new bar should be set!
331
m_moduleChooserBar = bar;
332
connect(bar, SIGNAL(sigChanged()), SLOT(modulesChanged()));
336
/** Sets the modules. */
337
void CDisplayWindow::setModules( const ListCSwordModuleInfo& newModules ) {
340
ListCSwordModuleInfo::const_iterator end_it = newModules.end();
341
for (ListCSwordModuleInfo::const_iterator it(newModules.begin()); it != end_it; ++it) {
342
m_modules.append((*it)->name());
346
/** Initialize the window. Call this method from the outside, because calling this in the constructor is not possible! */
347
const bool CDisplayWindow::init() {
348
//BibleTime::createReadDisplayWindow calls the show() method
350
setMinimumSize( 250,200 );
352
setCaption(windowCaption());
354
setFocusPolicy(QWidget::ClickFocus);
355
parentWidget()->setFocusPolicy(QWidget::ClickFocus);
362
m_filterOptions = CBTConfig::getFilterOptionDefaults();
363
m_displayOptions = CBTConfig::getDisplayOptionDefaults();
364
if (displaySettingsButton()) {
365
displaySettingsButton()->reset(modules());
372
/** Returns the main toolbar. */
373
KToolBar* const CDisplayWindow::mainToolBar() const {
374
return m_mainToolBar;
377
/** Returns the main toolbar. */
378
KToolBar* const CDisplayWindow::buttonsToolBar() const {
379
return m_buttonsToolBar;
382
/** Sets the main toolbar. */
383
void CDisplayWindow::setMainToolBar( KToolBar* bar ) {
387
/** Sets the main toolbar. */
388
void CDisplayWindow::setButtonsToolBar( KToolBar* bar ) {
389
m_buttonsToolBar = bar;
392
/** Returns the display settings button */
393
CDisplaySettingsButton* const CDisplayWindow::displaySettingsButton() const {
394
return m_displaySettingsButton;
397
/** Sets the display settings button. */
398
void CDisplayWindow::setDisplaySettingsButton( CDisplaySettingsButton* button ) {
399
if (m_displaySettingsButton)
400
disconnect(m_displaySettingsButton, SIGNAL( sigChanged() ),this, SLOT(lookup() ));
402
m_displaySettingsButton = button;
403
connect(m_displaySettingsButton, SIGNAL(sigChanged()),this, SLOT(lookup()));
406
/** Lookup the current key. Used to refresh the display. */
407
void CDisplayWindow::lookup() {
411
void CDisplayWindow::lookup( const QString& moduleName, const QString& keyName ) {
417
CSwordModuleInfo* m = backend()->findModuleByName(moduleName);
423
//ToDo: check for containsRef compat
424
if (m && modules().contains(m)) {
426
keyChooser()->setKey(key()); //the key chooser does send an update signal
428
else { //given module not displayed in this window
429
//if the module is displayed in another display window we assume a wrong drop
431
//create a new window for the given module
432
ListCSwordModuleInfo mList;
434
mdi()->emitCreateDisplayWindow(mList, keyName);
438
void CDisplayWindow::lookup( const QString& keyName ) {
439
/* This function is called for example after a bookmark was dropped on this window
441
Q_ASSERT(modules().first());
443
//qDebug("CDisplayWindow::lookup: %s", keyName.latin1());
444
lookup(modules().first()->name(), keyName);
447
/** Update the status of the popup menu entries. */
448
void CDisplayWindow::updatePopupMenu() {}
451
///** Returns the installed popup menu. */
452
KPopupMenu* const CDisplayWindow::popup() {
453
// qWarning("CReadWindow::popup()");
455
m_popupMenu = new KPopupMenu(this);
456
connect(m_popupMenu, SIGNAL(aboutToShow()), this, SLOT(updatePopupMenu()));
457
if (displayWidget()) {
458
displayWidget()->installPopup(m_popupMenu);
461
qWarning("CDisplayWindow:: can't instal popup menu");
467
/** Returns the display widget used by this implementation of CDisplayWindow. */
468
CDisplay* const CDisplayWindow::displayWidget() const {
469
Q_ASSERT(m_displayWidget);
470
return m_displayWidget;
473
/** Sets the display widget used by this display window. */
474
void CDisplayWindow::setDisplayWidget( CDisplay* newDisplay ) {
475
m_displayWidget = newDisplay;
478
void CDisplayWindow::closeEvent(QCloseEvent* e) {
487
void CDisplayWindow::slotSearchInModules() {
488
Search::CSearchDialog::openDialog(modules());
491
void CDisplayWindow::printAll() {
492
m_displayWidget->connectionsProxy()->printAll( m_displayOptions, m_filterOptions);
495
void CDisplayWindow::printAnchorWithText() {
496
m_displayWidget->connectionsProxy()->printAnchorWithText( m_displayOptions, m_filterOptions);