Bibletime – a bible study tool
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

cdisplaywindow.cpp 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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 "cdisplaywindow.h"
  11. #include "creadwindow.h"
  12. #include "cbiblereadwindow.h"
  13. #include "ccommentaryreadwindow.h"
  14. #include "clexiconreadwindow.h"
  15. #include "cbookreadwindow.h"
  16. #include "cwritewindow.h"
  17. #include "cplainwritewindow.h"
  18. #include "chtmlwritewindow.h"
  19. #include "cmodulechooserbar.h"
  20. #include "cbuttons.h"
  21. #include "backend/cswordkey.h"
  22. #include "frontend/keychooser/ckeychooser.h"
  23. #include "frontend/display/cdisplay.h"
  24. #include "frontend/cmdiarea.h"
  25. #include "frontend/cprofilewindow.h"
  26. #include "frontend/cbtconfig.h"
  27. #include "frontend/searchdialog/csearchdialog.h"
  28. #include "util/cresmgr.h"
  29. //TQt includes
  30. //KDE includes
  31. #include <tdeversion.h>
  32. #include <tdeaccel.h>
  33. #include <tdelocale.h>
  34. using namespace Profile;
  35. CReadWindow* CDisplayWindow::createReadInstance(ListCSwordModuleInfo modules, CMDIArea* parent, const char* name) {
  36. switch (modules.first()->type()) {
  37. case CSwordModuleInfo::Bible:
  38. return new CBibleReadWindow(modules, parent, name);
  39. case CSwordModuleInfo::Commentary:
  40. return new CCommentaryReadWindow(modules, parent, name);
  41. case CSwordModuleInfo::Lexicon:
  42. return new CLexiconReadWindow(modules, parent, name);
  43. case CSwordModuleInfo::GenericBook:
  44. return new CBookReadWindow(modules, parent, name);
  45. default:
  46. tqWarning("unknown module type");
  47. break;
  48. }
  49. return 0;
  50. }
  51. CWriteWindow* CDisplayWindow::createWriteInstance(ListCSwordModuleInfo modules, CMDIArea* parent, const CDisplayWindow::WriteWindowType type, const char* name) {
  52. if (type == HTMLWindow) {
  53. return new CHTMLWriteWindow(modules, parent, name);
  54. }
  55. else {
  56. return new CPlainWriteWindow(modules, parent, name);
  57. }
  58. return 0;
  59. }
  60. CDisplayWindow::CDisplayWindow(ListCSwordModuleInfo modules, CMDIArea *parent, const char *name )
  61. #if TDE_VERSION >= 0x030200
  62. : TDEMainWindow(TDEMainWindow::NoDCOPObject, parent, name, WDestructiveClose),
  63. #else
  64. : TDEMainWindow(parent, name, WDestructiveClose),
  65. #endif
  66. m_mdi(parent),
  67. m_filterOptions(),
  68. m_displayOptions(),
  69. m_displaySettingsButton(0),
  70. m_keyChooser(0),
  71. m_swordKey(0),
  72. m_isReady(false),
  73. m_moduleChooserBar(0),
  74. m_mainToolBar(0),
  75. m_popupMenu(0),
  76. m_displayWidget(0) {
  77. setModules(modules);
  78. }
  79. CDisplayWindow::~CDisplayWindow() {
  80. delete m_swordKey;
  81. m_swordKey = 0;
  82. }
  83. CMDIArea* const CDisplayWindow::mdi() const {
  84. return m_mdi;
  85. }
  86. /** Returns the right window caption. */
  87. const TQString CDisplayWindow::windowCaption() {
  88. if (!m_modules.count()) {
  89. return TQString();
  90. }
  91. return TQString(key()->key()).append(" (").append(m_modules.join(" | ")).append(")");
  92. }
  93. /** Returns the used modules as a TQPtrList */
  94. ListCSwordModuleInfo CDisplayWindow::modules() {
  95. ListCSwordModuleInfo mods;
  96. for (TQStringList::iterator it = m_modules.begin(); it != m_modules.end(); ++it) {
  97. Q_ASSERT(backend()->findModuleByName(*it));
  98. if (CSwordModuleInfo* m = backend()->findModuleByName(*it)) {
  99. mods.append(m);
  100. }
  101. }
  102. return mods;
  103. }
  104. /** Set the window caption. */
  105. void CDisplayWindow::setCaption( const TQString& ) {
  106. TQWidget::setCaption( windowCaption() );
  107. m_mdi->emitWindowCaptionChanged();
  108. }
  109. void CDisplayWindow::insertKeyboardActions( TDEActionCollection* const a ) {
  110. KStdAction::zoomIn(0, 0, a, "zoomIn"); //no slot
  111. KStdAction::zoomOut(0, 0, a, "zoomOut"); //no slot
  112. KStdAction::close(0, 0, a, "closeWindow"); //no slot
  113. KStdAction::selectAll(0, 0, a, "selectAll");
  114. KStdAction::copy(0, 0, a, "copySelectedText");
  115. KStdAction::find(0, 0, a, "findText");
  116. new TDEToolBarPopupAction(
  117. i18n("Back in history"),
  118. CResMgr::displaywindows::general::backInHistory::icon,
  119. CResMgr::displaywindows::general::backInHistory::accel,
  120. a,
  121. CResMgr::displaywindows::general::backInHistory::actionName
  122. );
  123. new TDEToolBarPopupAction(
  124. i18n("Forward in history"),
  125. CResMgr::displaywindows::general::forwardInHistory::icon,
  126. CResMgr::displaywindows::general::forwardInHistory::accel,
  127. a, CResMgr::displaywindows::general::forwardInHistory::actionName
  128. );
  129. }
  130. void CDisplayWindow::initActions() {
  131. new TDEAction(i18n("Search"),
  132. CResMgr::displaywindows::general::search::icon,
  133. CResMgr::displaywindows::general::search::accel,
  134. TQT_TQOBJECT(this), TQT_SLOT(slotSearchInModules()),
  135. actionCollection(), CResMgr::displaywindows::general::search::actionName
  136. );
  137. KStdAction::zoomIn(
  138. displayWidget()->connectionsProxy(), TQT_SLOT(zoomIn()),
  139. actionCollection(), "zoomIn"
  140. );
  141. KStdAction::zoomOut(
  142. displayWidget()->connectionsProxy(), TQT_SLOT(zoomOut()),
  143. actionCollection(), "zoomOut"
  144. );
  145. KStdAction::close(
  146. TQT_TQOBJECT(this), TQT_SLOT(close()),
  147. actionCollection(), "closeWindow"
  148. );
  149. KStdAction::selectAll(
  150. displayWidget()->connectionsProxy(), TQT_SLOT(selectAll()),
  151. actionCollection(), "selectAll"
  152. );
  153. KStdAction::copy(
  154. displayWidget()->connectionsProxy(), TQT_SLOT(copySelection()),
  155. actionCollection(), "copySelectedText"
  156. );
  157. KStdAction::find(
  158. displayWidget()->connectionsProxy(), TQT_SLOT(openFindTextDialog()),
  159. actionCollection(), "findText"
  160. );
  161. new TDEToolBarPopupAction(
  162. i18n("Back in history"), CResMgr::displaywindows::general::backInHistory::icon, CResMgr::displaywindows::general::backInHistory::accel,
  163. TQT_TQOBJECT(keyChooser()), TQT_SLOT( backInHistory() ),
  164. actionCollection(), CResMgr::displaywindows::general::backInHistory::actionName
  165. );
  166. new TDEToolBarPopupAction(
  167. i18n("Forward in history"), CResMgr::displaywindows::general::forwardInHistory::icon, CResMgr::displaywindows::general::forwardInHistory::accel,
  168. TQT_TQOBJECT(keyChooser()), TQT_SLOT( forwardInHistory() ),
  169. actionCollection(), CResMgr::displaywindows::general::forwardInHistory::actionName
  170. );
  171. CBTConfig::setupAccelSettings(CBTConfig::allWindows, actionCollection());
  172. }
  173. /** Is called when this window gets the focus or looses the focus. */
  174. void CDisplayWindow::windowActivated( const bool hasFocus ) {
  175. if (accel()) {
  176. accel()->setEnabled(hasFocus);
  177. }
  178. }
  179. /** Refresh the settings of this window. */
  180. void CDisplayWindow::reload() {
  181. //first make sure all used Sword modules are still present
  182. for (TQStringList::iterator it = m_modules.begin(); it != m_modules.end(); ++it) {
  183. if (!backend()->findModuleByName(*it)) {
  184. it = m_modules.remove(it);
  185. if (it == m_modules.end()) {
  186. break;
  187. }
  188. }
  189. }
  190. if (m_modules.count() == 0){
  191. close();
  192. return;
  193. }
  194. if (keyChooser()) keyChooser()->setModules( modules(), false );
  195. if (m_moduleChooserBar) { //necessary for edit windows which have now chooser bar
  196. m_moduleChooserBar->setModules(modules());
  197. }
  198. modulesChanged();
  199. lookup();
  200. }
  201. /** Returns the filter options used by this window. */
  202. CSwordBackend::FilterOptions& CDisplayWindow::filterOptions() {
  203. return m_filterOptions;
  204. }
  205. /** Returns the display options used by this display window. */
  206. CSwordBackend::DisplayOptions& CDisplayWindow::displayOptions() {
  207. return m_displayOptions;
  208. }
  209. /** Sets the new display options for this window. */
  210. void CDisplayWindow::setDisplayOptions( const CSwordBackend::DisplayOptions& displayOptions ) {
  211. m_displayOptions = displayOptions;
  212. }
  213. /** Sets the new filter options of this window. */
  214. void CDisplayWindow::setFilterOptions( CSwordBackend::FilterOptions& filterOptions ) {
  215. m_filterOptions = filterOptions;
  216. }
  217. /** Returns true if the widget is ready for use. */
  218. const bool CDisplayWindow::isReady() const {
  219. return m_isReady;
  220. }
  221. /** Set the ready status */
  222. void CDisplayWindow::setReady( const bool& ready ) {
  223. m_isReady = ready;
  224. }
  225. /** Returns true if the window may be closed. */
  226. bool CDisplayWindow::queryClose() {
  227. return true;
  228. }
  229. /** Returns the keychooser widget of this display window. */
  230. CKeyChooser* const CDisplayWindow::keyChooser() const {
  231. return m_keyChooser;
  232. }
  233. /** Sets the keychooser widget for this display window. */
  234. void CDisplayWindow::setKeyChooser( CKeyChooser* ck ) {
  235. m_keyChooser = ck;
  236. }
  237. /** Returns the key of this display window. */
  238. CSwordKey* CDisplayWindow::key() const {
  239. Q_ASSERT( m_swordKey );
  240. return m_swordKey;
  241. }
  242. /** Sets the new sword key. */
  243. void CDisplayWindow::setKey( CSwordKey* key ) {
  244. Q_ASSERT( key );
  245. m_swordKey = key;
  246. }
  247. void CDisplayWindow::modulesChanged() {
  248. if (moduleChooserBar()) { //necessary for write windows
  249. setModules( m_moduleChooserBar->getModuleList() );
  250. }
  251. if (!modules().count()) {
  252. close();
  253. }
  254. else {
  255. if (displaySettingsButton()) {
  256. displaySettingsButton()->reset(modules());
  257. }
  258. key()->module(modules().first());
  259. keyChooser()->setModules(modules());
  260. }
  261. }
  262. /** Returns the module chooser bar. */
  263. CModuleChooserBar* const CDisplayWindow::moduleChooserBar() const {
  264. return m_moduleChooserBar;
  265. }
  266. /** Sets the module chooser bar. */
  267. void CDisplayWindow::setModuleChooserBar( CModuleChooserBar* bar ) {
  268. if (m_moduleChooserBar) {
  269. disconnect(m_moduleChooserBar, TQT_SIGNAL(sigChanged()), this, TQT_SLOT(modulesChanged()));
  270. }
  271. //if a new bar should be set!
  272. if (bar) {
  273. m_moduleChooserBar = bar;
  274. connect(bar, TQT_SIGNAL(sigChanged()), TQT_SLOT(modulesChanged()));
  275. }
  276. }
  277. /** Sets the modules. */
  278. void CDisplayWindow::setModules( const ListCSwordModuleInfo& newModules ) {
  279. m_modules.clear();
  280. ListCSwordModuleInfo::const_iterator end_it = newModules.end();
  281. for (ListCSwordModuleInfo::const_iterator it(newModules.begin()); it != end_it; ++it) {
  282. m_modules.append((*it)->name());
  283. }
  284. }
  285. /** Initialize the window. Call this method from the outside, because calling this in the constructor is not possible! */
  286. const bool CDisplayWindow::init() {
  287. //BibleTime::createReadDisplayWindow calls the show() method
  288. initView();
  289. setMinimumSize( 250,200 );
  290. setCaption(windowCaption());
  291. //setup focus stuff.
  292. setFocusPolicy(TQ_ClickFocus);
  293. parentWidget()->setFocusPolicy(TQ_ClickFocus);
  294. initActions();
  295. initToolbars();
  296. initConnections();
  297. setupPopupMenu();
  298. m_filterOptions = CBTConfig::getFilterOptionDefaults();
  299. m_displayOptions = CBTConfig::getDisplayOptionDefaults();
  300. if (displaySettingsButton()) {
  301. displaySettingsButton()->reset(modules());
  302. }
  303. setReady(true);
  304. return true;
  305. }
  306. /** Returns the main toolbar. */
  307. TDEToolBar* const CDisplayWindow::mainToolBar() const {
  308. return m_mainToolBar;
  309. }
  310. /** Returns the main toolbar. */
  311. TDEToolBar* const CDisplayWindow::buttonsToolBar() const {
  312. return m_buttonsToolBar;
  313. }
  314. /** Sets the main toolbar. */
  315. void CDisplayWindow::setMainToolBar( TDEToolBar* bar ) {
  316. m_mainToolBar = bar;
  317. }
  318. /** Sets the main toolbar. */
  319. void CDisplayWindow::setButtonsToolBar( TDEToolBar* bar ) {
  320. m_buttonsToolBar = bar;
  321. }
  322. /** Returns the display settings button */
  323. CDisplaySettingsButton* const CDisplayWindow::displaySettingsButton() const {
  324. return m_displaySettingsButton;
  325. }
  326. /** Sets the display settings button. */
  327. void CDisplayWindow::setDisplaySettingsButton( CDisplaySettingsButton* button ) {
  328. if (m_displaySettingsButton)
  329. disconnect(m_displaySettingsButton, TQT_SIGNAL( sigChanged() ),this, TQT_SLOT(lookup() ));
  330. m_displaySettingsButton = button;
  331. connect(m_displaySettingsButton, TQT_SIGNAL(sigChanged()),this, TQT_SLOT(lookup()));
  332. }
  333. /** Lookup the current key. Used to refresh the display. */
  334. void CDisplayWindow::lookup() {
  335. lookup( key() );
  336. }
  337. void CDisplayWindow::lookup( const TQString& moduleName, const TQString& keyName ) {
  338. Q_ASSERT(isReady());
  339. if (!isReady()) {
  340. return;
  341. }
  342. CSwordModuleInfo* m = backend()->findModuleByName(moduleName);
  343. Q_ASSERT(m);
  344. if (!m) {
  345. return;
  346. }
  347. //ToDo: check for containsRef compat
  348. if (m && modules().contains(m)) {
  349. key()->key(keyName);
  350. keyChooser()->setKey(key()); //the key chooser does send an update signal
  351. }
  352. else { //given module not displayed in this window
  353. //if the module is displayed in another display window we assume a wrong drop
  354. bool found = false;
  355. //create a new window for the given module
  356. ListCSwordModuleInfo mList;
  357. mList.append(m);
  358. mdi()->emitCreateDisplayWindow(mList, keyName);
  359. }
  360. }
  361. void CDisplayWindow::lookup( const TQString& keyName ) {
  362. /* This function is called for example after a bookmark was dropped on this window
  363. */
  364. Q_ASSERT(modules().first());
  365. //tqDebug("CDisplayWindow::lookup: %s", keyName.latin1());
  366. lookup(modules().first()->name(), keyName);
  367. }
  368. /** Update the status of the popup menu entries. */
  369. void CDisplayWindow::updatePopupMenu() {}
  370. ///** Returns the installed popup menu. */
  371. TDEPopupMenu* const CDisplayWindow::popup() {
  372. // tqWarning("CReadWindow::popup()");
  373. if (!m_popupMenu) {
  374. m_popupMenu = new TDEPopupMenu(this);
  375. connect(m_popupMenu, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(updatePopupMenu()));
  376. if (displayWidget()) {
  377. displayWidget()->installPopup(m_popupMenu);
  378. }
  379. /* else {
  380. tqWarning("CDisplayWindow:: can't instal popup menu");
  381. }*/
  382. }
  383. return m_popupMenu;
  384. }
  385. /** Returns the display widget used by this implementation of CDisplayWindow. */
  386. CDisplay* const CDisplayWindow::displayWidget() const {
  387. Q_ASSERT(m_displayWidget);
  388. return m_displayWidget;
  389. }
  390. /** Sets the display widget used by this display window. */
  391. void CDisplayWindow::setDisplayWidget( CDisplay* newDisplay ) {
  392. m_displayWidget = newDisplay;
  393. }
  394. void CDisplayWindow::closeEvent(TQCloseEvent* e) {
  395. if (!queryClose()) {
  396. e->ignore();
  397. }
  398. else {
  399. e->accept();
  400. }
  401. }
  402. void CDisplayWindow::slotSearchInModules() {
  403. Search::CSearchDialog::openDialog(modules());
  404. }
  405. void CDisplayWindow::printAll() {
  406. m_displayWidget->connectionsProxy()->printAll( m_displayOptions, m_filterOptions);
  407. }
  408. void CDisplayWindow::printAnchorWithText() {
  409. m_displayWidget->connectionsProxy()->printAnchorWithText( m_displayOptions, m_filterOptions);
  410. }
  411. #include "cdisplaywindow.moc"