~ubuntu-branches/ubuntu/jaunty/bibletime/jaunty

« back to all changes in this revision

Viewing changes to bibletime/frontend/displaywindow/clexiconreadwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralph Janke
  • Date: 2008-05-10 15:18:16 UTC
  • mfrom: (1.1.6 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080510151816-bqp8y1to705zd0fm
Tags: 1.6.5.1-1
* New upstream version (Closes: #441161, #271502)
* fixes for new autotools and gcc 4.3 (Closes: #407291)
* added poxml to Build-Depends
* No DFSG necessary anymore since biblestudy howto has 
  now Commons Licence 
* Added libclucene-dev to dev-depends (Closes: #436677)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********
 
2
*
 
3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
 
4
*
 
5
* Copyright 1999-2006 by the BibleTime developers.
 
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
 
7
*
 
8
**********/
 
9
 
 
10
 
 
11
 
 
12
//BibleTime includes
 
13
#include "clexiconreadwindow.h"
 
14
#include "cmodulechooserbar.h"
 
15
#include "cbuttons.h"
 
16
 
 
17
#include "backend/cswordkey.h"
 
18
#include "backend/cswordldkey.h"
 
19
 
 
20
#include "frontend/cbtconfig.h"
 
21
#include "frontend/cexportmanager.h"
 
22
#include "frontend/display/cdisplay.h"
 
23
#include "frontend/display/creaddisplay.h"
 
24
#include "frontend/keychooser/ckeychooser.h"
 
25
 
 
26
#include "util/ctoolclass.h"
 
27
#include "util/cresmgr.h"
 
28
 
 
29
//Qt includes
 
30
 
 
31
//KDE includes
 
32
#include <kaccel.h>
 
33
#include <ktoolbar.h>
 
34
#include <klocale.h>
 
35
#include <kpopupmenu.h>
 
36
#include <kdeversion.h>
 
37
// #include <kactionclasses.h>
 
38
 
 
39
CLexiconReadWindow::CLexiconReadWindow(ListCSwordModuleInfo moduleList, CMDIArea* parent, const char *name) : CReadWindow(moduleList, parent,name) {
 
40
        setKey( CSwordKey::createInstance(moduleList.first()) );
 
41
}
 
42
 
 
43
CLexiconReadWindow::~CLexiconReadWindow() {}
 
44
 
 
45
void CLexiconReadWindow::insertKeyboardActions( KActionCollection* const a ) {
 
46
        new KAction(
 
47
                i18n("Next entry"), CResMgr::displaywindows::lexiconWindow::nextEntry::accel,
 
48
                a, "nextEntry"
 
49
        );
 
50
        new KAction(
 
51
                i18n("Previous entry"), CResMgr::displaywindows::lexiconWindow::previousEntry::accel,
 
52
                a, "previousEntry"
 
53
        );
 
54
 
 
55
        //  new KAction(i18n("Copy reference only"), KShortcut(0), a, "copyReferenceOnly");
 
56
        new KAction(i18n("Copy entry with text"), KShortcut(0), a, "copyEntryWithText");
 
57
        //  new KAction(i18n("Copy selected text"), KShortcut(0), a, "copySelectedText");
 
58
        new KAction(i18n("Save entry as plain text"), KShortcut(0), a, "saveEntryAsPlainText");
 
59
        new KAction(i18n("Save entry as HTML"), KShortcut(0), a, "saveEntryAsHTML");
 
60
        //   new KAction(i18n("Print reference only"), KShortcut(0), a, "printReferenceOnly");
 
61
        new KAction(i18n("Print entry with text"), KShortcut(0), a, "printEntryWithText");
 
62
}
 
63
 
 
64
void CLexiconReadWindow::initActions() {
 
65
        CReadWindow::initActions();
 
66
 
 
67
        m_actions.backInHistory = dynamic_cast<KToolBarPopupAction*>(
 
68
                                                                  actionCollection()->action(
 
69
                                                                          CResMgr::displaywindows::general::backInHistory::actionName
 
70
                                                                  )
 
71
                                                          );
 
72
        Q_ASSERT(m_actions.backInHistory);
 
73
 
 
74
        m_actions.forwardInHistory = dynamic_cast<KToolBarPopupAction*>(
 
75
                                                                         actionCollection()->action(
 
76
                                                                                 CResMgr::displaywindows::general::forwardInHistory::actionName
 
77
                                                                         )
 
78
                                                                 );
 
79
 
 
80
        Q_ASSERT(m_actions.forwardInHistory);
 
81
 
 
82
        new KAction(
 
83
                i18n("Next entry"), CResMgr::displaywindows::lexiconWindow::nextEntry::accel,
 
84
                this, SLOT( nextEntry() ),
 
85
                actionCollection(), "nextEntry"
 
86
        );
 
87
        new KAction(
 
88
                i18n("Previous entry"), CResMgr::displaywindows::lexiconWindow::previousEntry::accel,
 
89
                this, SLOT( previousEntry() ),
 
90
                actionCollection(), "previousEntry"
 
91
        );
 
92
 
 
93
        m_actions.selectAll = actionCollection()->action("selectAll");
 
94
        Q_ASSERT(m_actions.selectAll);
 
95
 
 
96
        m_actions.findText = actionCollection()->action("findText");
 
97
        Q_ASSERT(m_actions.findText);
 
98
        
 
99
        //m_actions.findStrongs = new KAction(i18n("Strong's Search"), KShortcut(0),this, SLOT(openSearchStrongsDialog()), actionCollection(), "findStrongs");
 
100
        m_actions.findStrongs = new KAction(
 
101
                i18n("Strong's Search"),
 
102
                CResMgr::displaywindows::general::findStrongs::icon,
 
103
                CResMgr::displaywindows::general::findStrongs::accel,
 
104
                this, SLOT(openSearchStrongsDialog()),
 
105
                actionCollection(),
 
106
                CResMgr::displaywindows::general::findStrongs::actionName);
 
107
 
 
108
        m_actions.copy.reference = new KAction(i18n("Reference only"), KShortcut(0), displayWidget()->connectionsProxy(), SLOT(copyAnchorOnly()), actionCollection(), "copyReferenceOnly");
 
109
 
 
110
        m_actions.copy.entry = new KAction(i18n("Entry with text"), KShortcut(0), displayWidget()->connectionsProxy(), SLOT(copyAll()), actionCollection(), "copyEntryWithText");
 
111
 
 
112
        m_actions.copy.selectedText = actionCollection()->action("copySelectedText");
 
113
        Q_ASSERT(m_actions.copy.selectedText);
 
114
 
 
115
        m_actions.save.entryAsPlain = new KAction(i18n("Entry as plain text"), KShortcut(0), this, SLOT(saveAsPlain()),actionCollection(), "saveEntryAsPlain");
 
116
 
 
117
        m_actions.save.entryAsHTML = new KAction(i18n("Entry as HTML"), KShortcut(0), this, SLOT(saveAsHTML()), actionCollection(), "saveEntryAsHTML");
 
118
 
 
119
        m_actions.print.reference = new KAction(i18n("Reference only"), KShortcut(0), this, SLOT(printAnchorWithText()), actionCollection(), "printReferenceOnly");
 
120
 
 
121
        m_actions.print.entry = new KAction(i18n("Entry with text"), KShortcut(0), this, SLOT(printAll()), actionCollection(), "printEntryWithText");
 
122
 
 
123
        // init with the user defined settings
 
124
        CBTConfig::setupAccelSettings(CBTConfig::lexiconWindow, actionCollection());
 
125
};
 
126
 
 
127
/** No descriptions */
 
128
void CLexiconReadWindow::initConnections() {
 
129
        Q_ASSERT(keyChooser());
 
130
 
 
131
        connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)),
 
132
                        this, SLOT(lookup(CSwordKey*)));
 
133
        connect(keyChooser(), SIGNAL(historyChanged()),
 
134
                        this, SLOT(slotUpdateHistoryButtons()));
 
135
 
 
136
        //connect the history actions to the right slots
 
137
        connect(
 
138
                m_actions.backInHistory->popupMenu(), SIGNAL(aboutToShow()),
 
139
                this, SLOT(slotFillBackHistory())
 
140
        );
 
141
        connect(
 
142
                m_actions.backInHistory->popupMenu(), SIGNAL(activated(int)),
 
143
                keyChooser(), SLOT(backInHistory(int))
 
144
        );
 
145
        connect(
 
146
                m_actions.forwardInHistory->popupMenu(), SIGNAL(aboutToShow()),
 
147
                this, SLOT(slotFillForwardHistory())
 
148
        );
 
149
        connect(
 
150
                m_actions.forwardInHistory->popupMenu(), SIGNAL(activated(int)),
 
151
                keyChooser(), SLOT(forwardInHistory(int))
 
152
        );
 
153
 
 
154
 
 
155
}
 
156
 
 
157
void CLexiconReadWindow::initView() {
 
158
        setDisplayWidget( CDisplay::createReadInstance(this) );
 
159
 
 
160
        setMainToolBar( new KToolBar(this) );
 
161
        addDockWindow(mainToolBar());
 
162
 
 
163
        setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) );
 
164
 
 
165
        mainToolBar()->insertWidget(0, keyChooser()->sizeHint().width(), keyChooser());
 
166
        mainToolBar()->setFullSize(false);
 
167
 
 
168
        setModuleChooserBar( new CModuleChooserBar(modules(), modules().first()->type(), this) );
 
169
        addDockWindow(moduleChooserBar());
 
170
 
 
171
        setButtonsToolBar( new KToolBar(this) );
 
172
        addDockWindow(buttonsToolBar());
 
173
        
 
174
        setIcon(CToolClass::getIconForModule(modules().first()));
 
175
        setCentralWidget( displayWidget()->view() );
 
176
}
 
177
 
 
178
void CLexiconReadWindow::initToolbars() {
 
179
        //main toolbar
 
180
        Q_ASSERT(m_actions.backInHistory);
 
181
        m_actions.backInHistory->plug( mainToolBar(),0 ); //1st button
 
182
        m_actions.forwardInHistory->plug( mainToolBar(),1 ); //2nd button
 
183
 
 
184
        //buttons toolbar
 
185
        KAction* action = actionCollection()->action(
 
186
                CResMgr::displaywindows::general::search::actionName);
 
187
        Q_ASSERT( action );
 
188
        if (action) {
 
189
                action->plug(buttonsToolBar());
 
190
        }
 
191
        #if KDE_VERSION_MINOR < 1
 
192
        action->plugAccel( accel() );
 
193
        #endif
 
194
 
 
195
        setDisplaySettingsButton( new CDisplaySettingsButton( &displayOptions(), &filterOptions(), modules(), buttonsToolBar()) );
 
196
        buttonsToolBar()->insertWidget(2,displaySettingsButton()->size().width(), displaySettingsButton());
 
197
}
 
198
 
 
199
void CLexiconReadWindow::setupPopupMenu() {
 
200
        popup()->insertTitle(CToolClass::getIconForModule(modules().first()), i18n("Lexicon window"));
 
201
 
 
202
        //   m_actions.selectAll = new KAction(i18n("Select all"), KShortcut(0), displayWidget()->connectionsProxy(), SLOT(selectAll()), actionCollection());
 
203
        m_actions.findText->plug(popup());
 
204
        m_actions.findStrongs->plug(popup());
 
205
        
 
206
        m_actions.selectAll->plug(popup());
 
207
 
 
208
        
 
209
        (new KActionSeparator(this))->plug( popup() );
 
210
 
 
211
        m_actions.copyMenu = new KActionMenu(i18n("Copy..."), CResMgr::displaywindows::lexiconWindow::copyMenu::icon, actionCollection());
 
212
        m_actions.copyMenu->setDelayed(false);
 
213
 
 
214
        m_actions.copyMenu->insert(m_actions.copy.reference);
 
215
        m_actions.copyMenu->insert(m_actions.copy.entry);
 
216
        m_actions.copyMenu->insert(new KActionSeparator(this));
 
217
        m_actions.copyMenu->insert(m_actions.copy.selectedText);
 
218
        m_actions.copyMenu->plug(popup());
 
219
 
 
220
        m_actions.saveMenu = new KActionMenu(i18n("Save..."), CResMgr::displaywindows::lexiconWindow::saveMenu::icon, actionCollection());
 
221
        m_actions.saveMenu->setDelayed(false);
 
222
        m_actions.saveMenu->insert(m_actions.save.entryAsPlain);
 
223
        m_actions.saveMenu->insert(m_actions.save.entryAsHTML);
 
224
        m_actions.saveMenu->plug(popup());
 
225
 
 
226
        m_actions.printMenu = new KActionMenu(i18n("Print..."), CResMgr::displaywindows::lexiconWindow::printMenu::icon, actionCollection());
 
227
        m_actions.printMenu->setDelayed(false);
 
228
        m_actions.printMenu->insert(m_actions.print.reference);
 
229
        m_actions.printMenu->insert(m_actions.print.entry);
 
230
        m_actions.printMenu->plug(popup());
 
231
}
 
232
 
 
233
/** Reimplemented. */
 
234
void CLexiconReadWindow::updatePopupMenu() {
 
235
        //enable the action depending on the supported module features
 
236
/*      bool hasStrongs = false;
 
237
        ListCSwordModuleInfo mods = modules();
 
238
        for (ListCSwordModuleInfo::iterator it = mods.begin(); it != mods.end(); ++it) {
 
239
                if ( (*it)->has( CSwordModuleInfo::strongNumbers ) ) {
 
240
                        hasStrongs = true;
 
241
                        break;
 
242
                }
 
243
        }
 
244
        m_actions.findStrongs->setEnabled( hasStrongs );*/
 
245
        m_actions.findStrongs->setEnabled( displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != QString::null );
 
246
        
 
247
        m_actions.copy.reference->setEnabled( displayWidget()->hasActiveAnchor() );
 
248
        //m_actions.copy.entry->setEnabled( displayWidget()->hasActiveAnchor() );
 
249
        m_actions.copy.selectedText->setEnabled( displayWidget()->hasSelection() );
 
250
 
 
251
        m_actions.print.reference->setEnabled( displayWidget()->hasActiveAnchor() );
 
252
}
 
253
 
 
254
/** No descriptions */
 
255
void CLexiconReadWindow::nextEntry() {
 
256
        keyChooser()->setKey(ldKey()->NextEntry());
 
257
}
 
258
 
 
259
/** No descriptions */
 
260
void CLexiconReadWindow::previousEntry() {
 
261
        keyChooser()->setKey(ldKey()->PreviousEntry());
 
262
}
 
263
 
 
264
/** Reimplementation to return the right key. */
 
265
CSwordLDKey* CLexiconReadWindow::ldKey() {
 
266
        return dynamic_cast<CSwordLDKey*>(CDisplayWindow::key());
 
267
}
 
268
 
 
269
/** This function saves the entry as html using the CExportMgr class. */
 
270
void CLexiconReadWindow::saveAsHTML() {
 
271
        CExportManager mgr(i18n("Saving entry ..."), true, i18n("Saving"), filterOptions(), displayOptions());
 
272
        mgr.saveKey(key(), CExportManager::HTML, true);
 
273
}
 
274
 
 
275
/** This function saves the entry as html using the CExportMgr class. */
 
276
void CLexiconReadWindow::saveAsPlain() {
 
277
        CExportManager mgr(i18n("Saving entry ..."), true, i18n("Saving"), filterOptions(), displayOptions());
 
278
        mgr.saveKey(key(), CExportManager::Text, true);
 
279
}
 
280
 
 
281
void CLexiconReadWindow::slotFillBackHistory() {
 
282
        //  qWarning("fill back history");
 
283
        QStringList keyList = keyChooser()->getPreviousKeys();
 
284
        QPopupMenu* menu = m_actions.backInHistory->popupMenu();
 
285
        menu->clear();
 
286
 
 
287
        QStringList::iterator it;
 
288
        int index = 1;
 
289
        for (it = keyList.begin(); it != keyList.end(); ++it) {
 
290
                menu->insertItem(*it,index, index);
 
291
                ++index;
 
292
        }
 
293
}
 
294
 
 
295
void CLexiconReadWindow::slotFillForwardHistory() {
 
296
        //  qWarning("fill forward history");
 
297
        QStringList keyList = keyChooser()->getNextKeys();
 
298
        QPopupMenu* menu = m_actions.forwardInHistory->popupMenu();
 
299
        menu->clear();
 
300
 
 
301
        QStringList::iterator it;
 
302
        int index = 1;
 
303
        for (it = keyList.begin(); it != keyList.end(); ++it) {
 
304
                menu->insertItem(*it,index, index);
 
305
                ++index;
 
306
        }
 
307
}
 
308
 
 
309
 
 
310
void CLexiconReadWindow::slotUpdateHistoryButtons() {
 
311
        //  qWarning("updating history buttons");
 
312
        Q_ASSERT(m_actions.backInHistory);
 
313
        Q_ASSERT(keyChooser());
 
314
 
 
315
        m_actions.backInHistory->setEnabled( keyChooser()->getPreviousKeys().size() > 0 );
 
316
        m_actions.forwardInHistory->setEnabled( keyChooser()->getNextKeys().size() > 0 );
 
317
}