bibletime
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cbiblereadwindow.cpp 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. #include "cbiblereadwindow.h"
  10. #include "ccommentaryreadwindow.h"
  11. #include "cbuttons.h"
  12. #include "backend/cswordversekey.h"
  13. #include "backend/cswordbiblemoduleinfo.h"
  14. #include "frontend/cprofilewindow.h"
  15. #include "frontend/cexportmanager.h"
  16. #include "frontend/cbtconfig.h"
  17. #include "frontend/cmdiarea.h"
  18. #include "util/cresmgr.h"
  19. #include "frontend/display/creaddisplay.h"
  20. #include "frontend/keychooser/ckeychooser.h"
  21. #include "util/ctoolclass.h"
  22. #include <math.h>
  23. //TQt includes
  24. #include <tqwidgetlist.h>
  25. #include <tqtimer.h>
  26. //KDE includes
  27. #include <kaccel.h>
  28. #include <klocale.h>
  29. #include <kpopupmenu.h>
  30. using namespace Profile;
  31. CBibleReadWindow::CBibleReadWindow(ListCSwordModuleInfo moduleList, CMDIArea* parent, const char *name ) : CLexiconReadWindow(moduleList, parent,name) {
  32. }
  33. CBibleReadWindow::~CBibleReadWindow() {}
  34. void CBibleReadWindow::applyProfileSettings( CProfileWindow* const settings ) {
  35. CLexiconReadWindow::applyProfileSettings(settings);
  36. const int count = displaySettingsButton()->menuItemCount();
  37. int result = settings->windowSettings();
  38. for (int i = count-1; i>=1; i--) {
  39. if (result-(int)pow((double)2,i-1)>= 0) { //2^i was added before, so item with index i is set
  40. result -= (int)pow((double)2,i-1);
  41. displaySettingsButton()->setItemStatus(i,true);
  42. }
  43. else {
  44. displaySettingsButton()->setItemStatus(i,false);
  45. }
  46. }
  47. displaySettingsButton()->setChanged();
  48. };
  49. void CBibleReadWindow::storeProfileSettings( CProfileWindow* const settings ) {
  50. CLexiconReadWindow::storeProfileSettings(settings);
  51. const int count = displaySettingsButton()->menuItemCount();
  52. int result = 0;
  53. //now check every item
  54. for (int i = 1; i < count; i++) { //first item is a title
  55. if (displaySettingsButton()->itemStatus(i)) //item is checked
  56. result += (int)pow((double)2,i-1);//add 2^i (the i. digit in binary)
  57. }
  58. settings->setWindowSettings(result);
  59. };
  60. /** Reimplementation. */
  61. void CBibleReadWindow::insertKeyboardActions( TDEActionCollection* const a ) {
  62. new TDEAction(
  63. i18n("Next book"), CResMgr::displaywindows::bibleWindow::nextBook::accel,
  64. a, "nextBook"
  65. );
  66. new TDEAction(
  67. i18n("Previous book"), CResMgr::displaywindows::bibleWindow::previousBook::accel,
  68. a, "previousBook"
  69. );
  70. new TDEAction(
  71. i18n("Next chapter"), CResMgr::displaywindows::bibleWindow::nextChapter::accel,
  72. a, "nextChapter"
  73. );
  74. new TDEAction(
  75. i18n("Previous chapter"), CResMgr::displaywindows::bibleWindow::previousChapter::accel,
  76. a, "previousChapter"
  77. );
  78. new TDEAction(
  79. i18n("Next verse"), CResMgr::displaywindows::bibleWindow::nextVerse::accel,
  80. a, "nextVerse"
  81. );
  82. new TDEAction(
  83. i18n("Previous verse"), CResMgr::displaywindows::bibleWindow::previousVerse::accel,
  84. a, "previousVerse"
  85. );
  86. //popup menu items
  87. // new TDEAction(i18n("Select all"), TDEStdAccel::selectAll(), a, "selectAll");
  88. //copy menu items
  89. // new TDEAction(i18n("Copy reference only"), TDEShortcut(0), a, "copyReferenceOnly");
  90. // new TDEAction(i18n("Text of reference"), TDEShortcut(0), a, "copyTextOfReference");
  91. // new TDEAction(i18n("Reference with text"), TDEShortcut(0), a, "copyReferenceWithText");
  92. new TDEAction(i18n("Copy chapter"), TDEShortcut(0), a, "copyChapter");
  93. // new TDEAction(i18n("Copy selected text"), TDEStdAccel::copy(), a, "copySelectedText");
  94. //save menu
  95. // new TDEAction(i18n("Reference with text"), TDEShortcut(0), a, "saveReferenceWithText");
  96. new TDEAction(i18n("Save chapter as plain text"), TDEShortcut(0), a, "saveChapterAsPlainText");
  97. new TDEAction(i18n("Save chapter as HTML"), TDEShortcut(0), a, "saveChapterAsHTML");
  98. // new TDEAction(i18n("Reference with text"), TDEShortcut(0), a, "saveReferenceWithText");
  99. //print
  100. new TDEAction(i18n("Print chapter"), TDEStdAccel::print(), a, "printChapter");
  101. }
  102. void CBibleReadWindow::initActions() {
  103. CLexiconReadWindow::initActions(); //make sure the predefined actions are available
  104. //cleanup, not a clean oo-solution
  105. actionCollection()->action("nextEntry")->setEnabled(false);
  106. actionCollection()->action("previousEntry")->setEnabled(false);
  107. new TDEAction(
  108. i18n("Next book"),
  109. CResMgr::displaywindows::bibleWindow::nextBook::accel,
  110. TQT_TQOBJECT(this), TQT_SLOT(nextBook()),
  111. actionCollection(), "nextBook"
  112. );
  113. new TDEAction(
  114. i18n("Previous book"),
  115. CResMgr::displaywindows::bibleWindow::previousBook::accel,
  116. TQT_TQOBJECT(this), TQT_SLOT(previousBook()),
  117. actionCollection(), "previousBook"
  118. );
  119. new TDEAction(
  120. i18n("Next chapter"),
  121. CResMgr::displaywindows::bibleWindow::nextChapter::accel,
  122. TQT_TQOBJECT(this), TQT_SLOT(nextChapter()),
  123. actionCollection(), "nextChapter"
  124. );
  125. new TDEAction(
  126. i18n("Previous chapter"),
  127. CResMgr::displaywindows::bibleWindow::previousChapter::accel,
  128. TQT_TQOBJECT(this), TQT_SLOT(previousChapter()),
  129. actionCollection(), "previousChapter"
  130. );
  131. new TDEAction(
  132. i18n("Next verse"),
  133. CResMgr::displaywindows::bibleWindow::nextVerse::accel,
  134. TQT_TQOBJECT(this), TQT_SLOT(nextVerse()),
  135. actionCollection(), "nextVerse"
  136. );
  137. new TDEAction(
  138. i18n("Previous verse"),
  139. CResMgr::displaywindows::bibleWindow::previousVerse::accel,
  140. TQT_TQOBJECT(this), TQT_SLOT(previousVerse()),
  141. actionCollection(), "previousVerse"
  142. );
  143. m_actions.selectAll = actionCollection()->action("selectAll");
  144. Q_ASSERT(m_actions.selectAll);
  145. m_actions.findText = actionCollection()->action("findText");
  146. Q_ASSERT(m_actions.findText);
  147. m_actions.findStrongs = new TDEAction(
  148. i18n("Strong's Search"),
  149. CResMgr::displaywindows::general::findStrongs::icon,
  150. CResMgr::displaywindows::general::findStrongs::accel,
  151. TQT_TQOBJECT(this), TQT_SLOT(openSearchStrongsDialog()),
  152. actionCollection(),
  153. CResMgr::displaywindows::general::findStrongs::actionName);
  154. m_actions.copy.referenceOnly = new TDEAction(i18n("Reference only"), TDEShortcut(0), displayWidget()->connectionsProxy(), TQT_SLOT(copyAnchorOnly()), actionCollection(), "copyReferenceOnly");
  155. m_actions.copy.referenceTextOnly = new TDEAction(i18n("Text of reference"), TDEShortcut(0),displayWidget()->connectionsProxy(), TQT_SLOT(copyAnchorTextOnly()), actionCollection(), "copyTextOfReference");
  156. m_actions.copy.referenceAndText = new TDEAction(i18n("Reference with text"), TDEShortcut(0), displayWidget()->connectionsProxy(), TQT_SLOT(copyAnchorWithText()), actionCollection(), "copyReferenceWithText");
  157. m_actions.copy.chapter = new TDEAction(i18n("Chapter"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(copyDisplayedText()), actionCollection(), "copyChapter");
  158. m_actions.copy.selectedText = actionCollection()->action("copySelectedText");
  159. Q_ASSERT(m_actions.copy.selectedText);
  160. m_actions.save.referenceAndText = new TDEAction(i18n("Reference with text"), TDEShortcut(0), displayWidget()->connectionsProxy(), TQT_SLOT(saveAnchorWithText()), actionCollection(), "saveReferenceWithText");
  161. m_actions.save.chapterAsPlain = new TDEAction(i18n("Chapter as plain text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(saveChapterPlain()), actionCollection(), "saveChapterAsPlainText");
  162. m_actions.save.chapterAsHTML = new TDEAction(i18n("Chapter as HTML"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(saveChapterHTML()), actionCollection(), "saveChapterAsHTML");
  163. m_actions.print.reference = new TDEAction(i18n("Reference with text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(printAnchorWithText()), actionCollection(), "saveReferenceWithText");
  164. m_actions.print.chapter = new TDEAction(i18n("Chapter"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(printAll()), actionCollection(), "printChapter");
  165. CBTConfig::setupAccelSettings(CBTConfig::bibleWindow, actionCollection());
  166. }
  167. void CBibleReadWindow::initConnections() {
  168. CLexiconReadWindow::initConnections();
  169. /* if (m_transliterationButton) { // Transliteration is not always available
  170. connect(m_transliterationButton, TQT_SIGNAL(sigChanged()), TQT_SLOT(lookup()));
  171. }*/
  172. }
  173. void CBibleReadWindow::initToolbars() {
  174. CLexiconReadWindow::initToolbars();
  175. }
  176. void CBibleReadWindow::initView() {
  177. CLexiconReadWindow::initView();
  178. parentWidget()->installEventFilter( this );
  179. }
  180. /** Reimplementation. */
  181. void CBibleReadWindow::setupPopupMenu() {
  182. popup()->insertTitle(CToolClass::getIconForModule(modules().first()), i18n("Bible window"));
  183. m_actions.findText->plug(popup());
  184. m_actions.findStrongs->plug(popup());
  185. m_actions.selectAll->plug(popup());
  186. (new TDEActionSeparator(TQT_TQOBJECT(this)))->plug( popup() );
  187. m_actions.copyMenu = new TDEActionMenu(i18n("Copy..."), CResMgr::displaywindows::bibleWindow::copyMenu::icon, TQT_TQOBJECT(popup()));
  188. m_actions.copyMenu->setDelayed( false );
  189. m_actions.copyMenu->insert(m_actions.copy.referenceOnly);
  190. m_actions.copyMenu->insert(m_actions.copy.referenceTextOnly);
  191. m_actions.copyMenu->insert(m_actions.copy.referenceAndText);
  192. m_actions.copyMenu->insert(m_actions.copy.chapter);
  193. m_actions.copyMenu->insert(new TDEActionSeparator(TQT_TQOBJECT(this)));
  194. m_actions.copyMenu->insert(m_actions.copy.selectedText);
  195. m_actions.copyMenu->plug(popup());
  196. m_actions.saveMenu = new TDEActionMenu(i18n("Save..."),CResMgr::displaywindows::bibleWindow::saveMenu::icon,TQT_TQOBJECT(popup()));
  197. m_actions.saveMenu->setDelayed( false );
  198. m_actions.saveMenu->insert(m_actions.save.referenceAndText);
  199. m_actions.saveMenu->insert(m_actions.save.chapterAsPlain);
  200. m_actions.saveMenu->insert(m_actions.save.chapterAsHTML);
  201. m_actions.saveMenu->plug(popup());
  202. m_actions.printMenu = new TDEActionMenu(i18n("Print..."),CResMgr::displaywindows::bibleWindow::printMenu::icon, TQT_TQOBJECT(popup()));
  203. m_actions.printMenu->setDelayed(false);
  204. m_actions.printMenu->insert(m_actions.print.reference);
  205. m_actions.printMenu->insert(m_actions.print.chapter);
  206. m_actions.printMenu->plug(popup());
  207. }
  208. /** Reimplemented. */
  209. void CBibleReadWindow::updatePopupMenu() {
  210. tqWarning("CBibleReadWindow::updatePopupMenu()");
  211. //enable the action depending on the supported module features
  212. // bool hasStrongs = false;
  213. // ListCSwordModuleInfo mods = modules();
  214. // for (ListCSwordModuleInfo::iterator it = mods.begin(); it != mods.end(); ++it) {
  215. // if ( (*it)->has( CSwordModuleInfo::strongNumbers ) ) {
  216. // hasStrongs = true;
  217. // break;
  218. // }
  219. // }
  220. //
  221. // m_actions.findStrongs->setEnabled( hasStrongs );
  222. m_actions.findStrongs->setEnabled( displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != TQString() );
  223. m_actions.copy.referenceOnly->setEnabled( displayWidget()->hasActiveAnchor() );
  224. m_actions.copy.referenceTextOnly->setEnabled( displayWidget()->hasActiveAnchor() );
  225. m_actions.copy.referenceAndText->setEnabled( displayWidget()->hasActiveAnchor() );
  226. m_actions.copy.selectedText->setEnabled( displayWidget()->hasSelection() );
  227. m_actions.save.referenceAndText->setEnabled( displayWidget()->hasActiveAnchor() );
  228. m_actions.print.reference->setEnabled( displayWidget()->hasActiveAnchor() );
  229. }
  230. /** Moves to the next book. */
  231. void CBibleReadWindow::nextBook() {
  232. if (verseKey()->next(CSwordVerseKey::UseBook)) {
  233. keyChooser()->setKey(key());
  234. }
  235. }
  236. /** Moves one book behind. */
  237. void CBibleReadWindow::previousBook() {
  238. if (verseKey()->previous(CSwordVerseKey::UseBook)) {
  239. keyChooser()->setKey(key());
  240. }
  241. }
  242. /** Moves to the next book. */
  243. void CBibleReadWindow::nextChapter() {
  244. if (verseKey()->next(CSwordVerseKey::UseChapter)) {
  245. keyChooser()->setKey(key());
  246. }
  247. }
  248. /** Moves one book behind. */
  249. void CBibleReadWindow::previousChapter() {
  250. if (verseKey()->previous(CSwordVerseKey::UseChapter)) {
  251. keyChooser()->setKey(key());
  252. }
  253. }
  254. /** Moves to the next book. */
  255. void CBibleReadWindow::nextVerse() {
  256. if (verseKey()->next(CSwordVerseKey::UseVerse)) {
  257. keyChooser()->setKey(key());
  258. }
  259. }
  260. /** Moves one book behind. */
  261. void CBibleReadWindow::previousVerse() {
  262. if (verseKey()->previous(CSwordVerseKey::UseVerse)) {
  263. keyChooser()->setKey(key());
  264. }
  265. }
  266. /** rapper around key() to return the right type of key. */
  267. CSwordVerseKey* CBibleReadWindow::verseKey() {
  268. CSwordVerseKey* k = dynamic_cast<CSwordVerseKey*>(CDisplayWindow::key());
  269. Q_ASSERT(k);
  270. return k;
  271. }
  272. /** Copies the current chapter into the clipboard. */
  273. void CBibleReadWindow::copyDisplayedText() {
  274. CSwordVerseKey dummy(*verseKey());
  275. dummy.Verse(1);
  276. CSwordVerseKey vk(*verseKey());
  277. vk.LowerBound(dummy);
  278. CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first());
  279. dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter()));
  280. vk.UpperBound(dummy);
  281. CExportManager mgr(i18n("Copy chapter to clipboard ..."), false, i18n("Copying"), filterOptions(), displayOptions());
  282. mgr.copyKey(&vk, CExportManager::Text, true);
  283. }
  284. /** Saves the chapter as valid HTML page. */
  285. void CBibleReadWindow::saveChapterHTML() {
  286. //saves the complete chapter to disk
  287. CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first());
  288. Q_ASSERT(bible);
  289. if (!bible) //shouldn't happen
  290. return;
  291. CSwordVerseKey dummy(*verseKey());
  292. dummy.Verse(1);
  293. CSwordVerseKey vk(*verseKey());
  294. vk.LowerBound(dummy);
  295. dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter()));
  296. vk.UpperBound(dummy);
  297. CExportManager mgr(i18n("Saving chapter ..."), true, i18n("Saving"), filterOptions(), displayOptions());
  298. mgr.saveKey(&vk, CExportManager::HTML, true);
  299. }
  300. /** Saves the chapter as valid HTML page. */
  301. void CBibleReadWindow::saveChapterPlain() {
  302. //saves the complete chapter to disk
  303. CSwordVerseKey vk(*verseKey());
  304. CSwordVerseKey dummy(*verseKey());
  305. dummy.Verse(1);
  306. vk.LowerBound(dummy);
  307. CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first());
  308. dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter()));
  309. vk.UpperBound(dummy);
  310. CExportManager mgr(i18n("Saving chapter ..."), true, i18n("Saving"), filterOptions(),displayOptions());
  311. mgr.saveKey(&vk, CExportManager::Text, true);
  312. }
  313. void CBibleReadWindow::reload() {
  314. CLexiconReadWindow::reload();
  315. if (m_modules.count() == 0) {
  316. close();
  317. return;
  318. }
  319. //refresh the book lists
  320. // tqDebug("lang is %s",backend()->booknameLanguage().latin1());
  321. verseKey()->setLocale( backend()->booknameLanguage().latin1() );
  322. keyChooser()->refreshContent();
  323. CBTConfig::setupAccelSettings(CBTConfig::readWindow, actionCollection()); //setup the predefined actions
  324. CBTConfig::setupAccelSettings(CBTConfig::bibleWindow, actionCollection());
  325. }
  326. /** No descriptions */
  327. bool CBibleReadWindow::eventFilter( TQObject* o, TQEvent* e) {
  328. const bool ret = CLexiconReadWindow::eventFilter(o,e);
  329. // Q_ASSERT(o->inherits("CDisplayWindow"));
  330. // tqWarning("class: %s", o->className());
  331. if (e && (e->type() == TQEvent::FocusIn)) { //sync other windows to this active
  332. /* This is a hack to work around a TDEHTML problem (similair to the Drag&Drop problem we had):
  333. * If new HTML content is loaded from inside a kHTML event handler
  334. * the widget's state will be confused, i.e. it's scrolling without having
  335. * the mousebutton clicked.
  336. *
  337. * This is not really in a TDEHTML event handler but works anyway.
  338. * Sometime KDE/TQt is hard to use ...
  339. */
  340. TQTimer::singleShot(0, TQT_TQOBJECT(this), TQT_SLOT(syncWindows()));
  341. }
  342. return ret;
  343. }
  344. void CBibleReadWindow::lookup( CSwordKey* newKey ) {
  345. CLexiconReadWindow::lookup(newKey);
  346. syncWindows();
  347. }
  348. void CBibleReadWindow::syncWindows() {
  349. // tqWarning("syncing windows");
  350. TQWidgetList windows = mdi()->windowList();
  351. // Q_ASSERT(windows.count());
  352. if (!windows.count()) {
  353. return;
  354. }
  355. for (windows.first(); windows.current(); windows.next()) {
  356. CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(windows.current());
  357. // Q_ASSERT(w && w->syncAllowed());
  358. if (w && w->syncAllowed()) {
  359. w->lookup( key()->key() );
  360. }
  361. /* else {
  362. tqWarning("class sync: %s", w->className());
  363. }*/
  364. }
  365. }