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.

clexiconreadwindow.cpp 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. //BibleTime includes
  10. #include "clexiconreadwindow.h"
  11. #include "cmodulechooserbar.h"
  12. #include "cbuttons.h"
  13. #include "backend/cswordkey.h"
  14. #include "backend/cswordldkey.h"
  15. #include "frontend/cbtconfig.h"
  16. #include "frontend/cexportmanager.h"
  17. #include "frontend/display/cdisplay.h"
  18. #include "frontend/display/creaddisplay.h"
  19. #include "frontend/keychooser/ckeychooser.h"
  20. #include "util/ctoolclass.h"
  21. #include "util/cresmgr.h"
  22. //TQt includes
  23. //KDE includes
  24. #include <kaccel.h>
  25. #include <ktoolbar.h>
  26. #include <klocale.h>
  27. #include <kpopupmenu.h>
  28. #include <tdeversion.h>
  29. // #include <kactionclasses.h>
  30. CLexiconReadWindow::CLexiconReadWindow(ListCSwordModuleInfo moduleList, CMDIArea* parent, const char *name) : CReadWindow(moduleList, parent,name) {
  31. setKey( CSwordKey::createInstance(moduleList.first()) );
  32. }
  33. CLexiconReadWindow::~CLexiconReadWindow() {}
  34. void CLexiconReadWindow::insertKeyboardActions( TDEActionCollection* const a ) {
  35. new TDEAction(
  36. i18n("Next entry"), CResMgr::displaywindows::lexiconWindow::nextEntry::accel,
  37. a, "nextEntry"
  38. );
  39. new TDEAction(
  40. i18n("Previous entry"), CResMgr::displaywindows::lexiconWindow::previousEntry::accel,
  41. a, "previousEntry"
  42. );
  43. // new TDEAction(i18n("Copy reference only"), TDEShortcut(0), a, "copyReferenceOnly");
  44. new TDEAction(i18n("Copy entry with text"), TDEShortcut(0), a, "copyEntryWithText");
  45. // new TDEAction(i18n("Copy selected text"), TDEShortcut(0), a, "copySelectedText");
  46. new TDEAction(i18n("Save entry as plain text"), TDEShortcut(0), a, "saveEntryAsPlainText");
  47. new TDEAction(i18n("Save entry as HTML"), TDEShortcut(0), a, "saveEntryAsHTML");
  48. // new TDEAction(i18n("Print reference only"), TDEShortcut(0), a, "printReferenceOnly");
  49. new TDEAction(i18n("Print entry with text"), TDEShortcut(0), a, "printEntryWithText");
  50. }
  51. void CLexiconReadWindow::initActions() {
  52. CReadWindow::initActions();
  53. m_actions.backInHistory = dynamic_cast<TDEToolBarPopupAction*>(
  54. actionCollection()->action(
  55. CResMgr::displaywindows::general::backInHistory::actionName
  56. )
  57. );
  58. Q_ASSERT(m_actions.backInHistory);
  59. m_actions.forwardInHistory = dynamic_cast<TDEToolBarPopupAction*>(
  60. actionCollection()->action(
  61. CResMgr::displaywindows::general::forwardInHistory::actionName
  62. )
  63. );
  64. Q_ASSERT(m_actions.forwardInHistory);
  65. new TDEAction(
  66. i18n("Next entry"), CResMgr::displaywindows::lexiconWindow::nextEntry::accel,
  67. TQT_TQOBJECT(this), TQT_SLOT( nextEntry() ),
  68. actionCollection(), "nextEntry"
  69. );
  70. new TDEAction(
  71. i18n("Previous entry"), CResMgr::displaywindows::lexiconWindow::previousEntry::accel,
  72. TQT_TQOBJECT(this), TQT_SLOT( previousEntry() ),
  73. actionCollection(), "previousEntry"
  74. );
  75. m_actions.selectAll = actionCollection()->action("selectAll");
  76. Q_ASSERT(m_actions.selectAll);
  77. m_actions.findText = actionCollection()->action("findText");
  78. Q_ASSERT(m_actions.findText);
  79. //m_actions.findStrongs = new TDEAction(i18n("Strong's Search"), TDEShortcut(0),this, TQT_SLOT(openSearchStrongsDialog()), actionCollection(), "findStrongs");
  80. m_actions.findStrongs = new TDEAction(
  81. i18n("Strong's Search"),
  82. CResMgr::displaywindows::general::findStrongs::icon,
  83. CResMgr::displaywindows::general::findStrongs::accel,
  84. TQT_TQOBJECT(this), TQT_SLOT(openSearchStrongsDialog()),
  85. actionCollection(),
  86. CResMgr::displaywindows::general::findStrongs::actionName);
  87. m_actions.copy.reference = new TDEAction(i18n("Reference only"), TDEShortcut(0), displayWidget()->connectionsProxy(), TQT_SLOT(copyAnchorOnly()), actionCollection(), "copyReferenceOnly");
  88. m_actions.copy.entry = new TDEAction(i18n("Entry with text"), TDEShortcut(0), displayWidget()->connectionsProxy(), TQT_SLOT(copyAll()), actionCollection(), "copyEntryWithText");
  89. m_actions.copy.selectedText = actionCollection()->action("copySelectedText");
  90. Q_ASSERT(m_actions.copy.selectedText);
  91. m_actions.save.entryAsPlain = new TDEAction(i18n("Entry as plain text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(saveAsPlain()),actionCollection(), "saveEntryAsPlain");
  92. m_actions.save.entryAsHTML = new TDEAction(i18n("Entry as HTML"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(saveAsHTML()), actionCollection(), "saveEntryAsHTML");
  93. m_actions.print.reference = new TDEAction(i18n("Reference only"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(printAnchorWithText()), actionCollection(), "printReferenceOnly");
  94. m_actions.print.entry = new TDEAction(i18n("Entry with text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(printAll()), actionCollection(), "printEntryWithText");
  95. // init with the user defined settings
  96. CBTConfig::setupAccelSettings(CBTConfig::lexiconWindow, actionCollection());
  97. };
  98. /** No descriptions */
  99. void CLexiconReadWindow::initConnections() {
  100. Q_ASSERT(keyChooser());
  101. connect(keyChooser(), TQT_SIGNAL(keyChanged(CSwordKey*)),
  102. TQT_TQOBJECT(this), TQT_SLOT(lookup(CSwordKey*)));
  103. connect(keyChooser(), TQT_SIGNAL(historyChanged()),
  104. TQT_TQOBJECT(this), TQT_SLOT(slotUpdateHistoryButtons()));
  105. //connect the history actions to the right slots
  106. connect(
  107. m_actions.backInHistory->popupMenu(), TQT_SIGNAL(aboutToShow()),
  108. TQT_TQOBJECT(this), TQT_SLOT(slotFillBackHistory())
  109. );
  110. connect(
  111. m_actions.backInHistory->popupMenu(), TQT_SIGNAL(activated(int)),
  112. keyChooser(), TQT_SLOT(backInHistory(int))
  113. );
  114. connect(
  115. m_actions.forwardInHistory->popupMenu(), TQT_SIGNAL(aboutToShow()),
  116. TQT_TQOBJECT(this), TQT_SLOT(slotFillForwardHistory())
  117. );
  118. connect(
  119. m_actions.forwardInHistory->popupMenu(), TQT_SIGNAL(activated(int)),
  120. keyChooser(), TQT_SLOT(forwardInHistory(int))
  121. );
  122. }
  123. void CLexiconReadWindow::initView() {
  124. setDisplayWidget( CDisplay::createReadInstance(this) );
  125. setMainToolBar( new TDEToolBar(this) );
  126. addDockWindow(mainToolBar());
  127. setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) );
  128. mainToolBar()->insertWidget(0, keyChooser()->sizeHint().width(), keyChooser());
  129. mainToolBar()->setFullSize(false);
  130. setModuleChooserBar( new CModuleChooserBar(modules(), modules().first()->type(), this) );
  131. addDockWindow(moduleChooserBar());
  132. setButtonsToolBar( new TDEToolBar(this) );
  133. addDockWindow(buttonsToolBar());
  134. setIcon(CToolClass::getIconForModule(modules().first()));
  135. setCentralWidget( displayWidget()->view() );
  136. }
  137. void CLexiconReadWindow::initToolbars() {
  138. //main toolbar
  139. Q_ASSERT(m_actions.backInHistory);
  140. m_actions.backInHistory->plug( mainToolBar(),0 ); //1st button
  141. m_actions.forwardInHistory->plug( mainToolBar(),1 ); //2nd button
  142. //buttons toolbar
  143. TDEAction* action = actionCollection()->action(
  144. CResMgr::displaywindows::general::search::actionName);
  145. Q_ASSERT( action );
  146. if (action) {
  147. action->plug(buttonsToolBar());
  148. }
  149. #if TDE_VERSION_MINOR < 1
  150. action->plugAccel( accel() );
  151. #endif
  152. setDisplaySettingsButton( new CDisplaySettingsButton( &displayOptions(), &filterOptions(), modules(), buttonsToolBar()) );
  153. buttonsToolBar()->insertWidget(2,displaySettingsButton()->size().width(), displaySettingsButton());
  154. }
  155. void CLexiconReadWindow::setupPopupMenu() {
  156. popup()->insertTitle(CToolClass::getIconForModule(modules().first()), i18n("Lexicon window"));
  157. // m_actions.selectAll = new TDEAction(i18n("Select all"), TDEShortcut(0), displayWidget()->connectionsProxy(), TQT_SLOT(selectAll()), actionCollection());
  158. m_actions.findText->plug(popup());
  159. m_actions.findStrongs->plug(popup());
  160. m_actions.selectAll->plug(popup());
  161. (new TDEActionSeparator(TQT_TQOBJECT(this)))->plug( popup() );
  162. m_actions.copyMenu = new TDEActionMenu(i18n("Copy..."), CResMgr::displaywindows::lexiconWindow::copyMenu::icon, actionCollection());
  163. m_actions.copyMenu->setDelayed(false);
  164. m_actions.copyMenu->insert(m_actions.copy.reference);
  165. m_actions.copyMenu->insert(m_actions.copy.entry);
  166. m_actions.copyMenu->insert(new TDEActionSeparator(TQT_TQOBJECT(this)));
  167. m_actions.copyMenu->insert(m_actions.copy.selectedText);
  168. m_actions.copyMenu->plug(popup());
  169. m_actions.saveMenu = new TDEActionMenu(i18n("Save..."), CResMgr::displaywindows::lexiconWindow::saveMenu::icon, actionCollection());
  170. m_actions.saveMenu->setDelayed(false);
  171. m_actions.saveMenu->insert(m_actions.save.entryAsPlain);
  172. m_actions.saveMenu->insert(m_actions.save.entryAsHTML);
  173. m_actions.saveMenu->plug(popup());
  174. m_actions.printMenu = new TDEActionMenu(i18n("Print..."), CResMgr::displaywindows::lexiconWindow::printMenu::icon, actionCollection());
  175. m_actions.printMenu->setDelayed(false);
  176. m_actions.printMenu->insert(m_actions.print.reference);
  177. m_actions.printMenu->insert(m_actions.print.entry);
  178. m_actions.printMenu->plug(popup());
  179. }
  180. /** Reimplemented. */
  181. void CLexiconReadWindow::updatePopupMenu() {
  182. //enable the action depending on the supported module features
  183. /* bool hasStrongs = false;
  184. ListCSwordModuleInfo mods = modules();
  185. for (ListCSwordModuleInfo::iterator it = mods.begin(); it != mods.end(); ++it) {
  186. if ( (*it)->has( CSwordModuleInfo::strongNumbers ) ) {
  187. hasStrongs = true;
  188. break;
  189. }
  190. }
  191. m_actions.findStrongs->setEnabled( hasStrongs );*/
  192. m_actions.findStrongs->setEnabled( displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != TQString() );
  193. m_actions.copy.reference->setEnabled( displayWidget()->hasActiveAnchor() );
  194. //m_actions.copy.entry->setEnabled( displayWidget()->hasActiveAnchor() );
  195. m_actions.copy.selectedText->setEnabled( displayWidget()->hasSelection() );
  196. m_actions.print.reference->setEnabled( displayWidget()->hasActiveAnchor() );
  197. }
  198. /** No descriptions */
  199. void CLexiconReadWindow::nextEntry() {
  200. keyChooser()->setKey(ldKey()->NextEntry());
  201. }
  202. /** No descriptions */
  203. void CLexiconReadWindow::previousEntry() {
  204. keyChooser()->setKey(ldKey()->PreviousEntry());
  205. }
  206. /** Reimplementation to return the right key. */
  207. CSwordLDKey* CLexiconReadWindow::ldKey() {
  208. return dynamic_cast<CSwordLDKey*>(CDisplayWindow::key());
  209. }
  210. /** This function saves the entry as html using the CExportMgr class. */
  211. void CLexiconReadWindow::saveAsHTML() {
  212. CExportManager mgr(i18n("Saving entry ..."), true, i18n("Saving"), filterOptions(), displayOptions());
  213. mgr.saveKey(key(), CExportManager::HTML, true);
  214. }
  215. /** This function saves the entry as html using the CExportMgr class. */
  216. void CLexiconReadWindow::saveAsPlain() {
  217. CExportManager mgr(i18n("Saving entry ..."), true, i18n("Saving"), filterOptions(), displayOptions());
  218. mgr.saveKey(key(), CExportManager::Text, true);
  219. }
  220. void CLexiconReadWindow::slotFillBackHistory() {
  221. // tqWarning("fill back history");
  222. TQStringList keyList = keyChooser()->getPreviousKeys();
  223. TQPopupMenu* menu = m_actions.backInHistory->popupMenu();
  224. menu->clear();
  225. TQStringList::iterator it;
  226. int index = 1;
  227. for (it = keyList.begin(); it != keyList.end(); ++it) {
  228. menu->insertItem(*it,index, index);
  229. ++index;
  230. }
  231. }
  232. void CLexiconReadWindow::slotFillForwardHistory() {
  233. // tqWarning("fill forward history");
  234. TQStringList keyList = keyChooser()->getNextKeys();
  235. TQPopupMenu* menu = m_actions.forwardInHistory->popupMenu();
  236. menu->clear();
  237. TQStringList::iterator it;
  238. int index = 1;
  239. for (it = keyList.begin(); it != keyList.end(); ++it) {
  240. menu->insertItem(*it,index, index);
  241. ++index;
  242. }
  243. }
  244. void CLexiconReadWindow::slotUpdateHistoryButtons() {
  245. // tqWarning("updating history buttons");
  246. Q_ASSERT(m_actions.backInHistory);
  247. Q_ASSERT(keyChooser());
  248. m_actions.backInHistory->setEnabled( keyChooser()->getPreviousKeys().size() > 0 );
  249. m_actions.forwardInHistory->setEnabled( keyChooser()->getNextKeys().size() > 0 );
  250. }