Bibletime – a bible study tool
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.

cwritewindow.cpp 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 "cwritewindow.h"
  10. #include "backend/cswordmoduleinfo.h"
  11. #include "frontend/keychooser/ckeychooser.h"
  12. #include "frontend/cprofilewindow.h"
  13. //KDE includes
  14. #include <tdemessagebox.h>
  15. #include <tdelocale.h>
  16. using namespace Profile;
  17. CWriteWindow::CWriteWindow(ListCSwordModuleInfo modules, CMDIArea* parent, const char *name )
  18. : CDisplayWindow(modules, parent,name), m_writeDisplay(0) {}
  19. CWriteWindow::~CWriteWindow() {}
  20. // void CWriteWindow::insertKeyboardActions( TDEAccel* const /*a*/ ) {
  21. //
  22. // };
  23. void CWriteWindow::insertKeyboardActions( TDEActionCollection* const ) {
  24. /* new TDEAction(
  25. i18n("Next book"), CResMgr::displaywindows::bibleWindow::nextBook::accel,
  26. a, "nextBook"
  27. );*/
  28. }
  29. void CWriteWindow::initConnections() {
  30. // tqWarning("CWriteWindow::initConnections()");
  31. Q_ASSERT(keyChooser());
  32. connect(keyChooser(), TQT_SIGNAL(beforeKeyChange(const TQString&)),
  33. this, TQT_SLOT(beforeKeyChange(const TQString&))
  34. );
  35. };
  36. void CWriteWindow::initActions() {}
  37. ;
  38. void CWriteWindow::storeProfileSettings(CProfileWindow * const settings) {
  39. settings->setWriteWindowType( writeWindowType() );
  40. TQRect rect;
  41. rect.setX(parentWidget()->x());
  42. rect.setY(parentWidget()->y());
  43. rect.setWidth(width());
  44. rect.setHeight(height());
  45. settings->setGeometry(rect);
  46. // settings->setScrollbarPositions( m_htmlWidget->view()->horizontalScrollBar()->value(), m_htmlWidget->view()->verticalScrollBar()->value() );
  47. settings->setType(modules().first()->type());
  48. settings->setMaximized(isMaximized() || parentWidget()->isMaximized());
  49. if (key()) {
  50. sword::VerseKey* vk = dynamic_cast<sword::VerseKey*>(key());
  51. TQString oldLang;
  52. if (vk) {
  53. oldLang = TQString::fromLatin1(vk->getLocale());
  54. vk->setLocale("en"); //save english locale names as default!
  55. }
  56. settings->setKey( key()->key() );
  57. if (vk) {
  58. vk->setLocale(oldLang.latin1());
  59. }
  60. }
  61. TQStringList mods;
  62. ListCSwordModuleInfo allMods = modules();
  63. // for (CSwordModuleInfo* m = modules().first(); m; m = modules().next()) {
  64. ListCSwordModuleInfo::iterator end_it = allMods.end();
  65. for (ListCSwordModuleInfo::iterator it(allMods.begin()); it != end_it; ++it) {
  66. mods.append((*it)->name());
  67. }
  68. settings->setModules(mods);
  69. };
  70. void CWriteWindow::applyProfileSettings(CProfileWindow * const settings) {
  71. setUpdatesEnabled(false);
  72. if (settings->maximized()) {
  73. parentWidget()->showMaximized();
  74. }
  75. else {
  76. const TQRect rect = settings->geometry();
  77. resize(rect.width(), rect.height());
  78. parentWidget()->move(rect.x(), rect.y());
  79. //setGeometry( settings->geometry() );
  80. }
  81. // displayWidget()->view()->horizontalScrollBar()->setValue( settings->scrollbarPositions().horizontal );
  82. // m_htmlWidget->view()->verticalScrollBar()->setValue( settings->scrollbarPositions().vertical );
  83. setUpdatesEnabled(true);
  84. };
  85. /** Sets the write display-widget for this write display window. */
  86. void CWriteWindow::setDisplayWidget( CWriteDisplay* display ) {
  87. CDisplayWindow::setDisplayWidget(display);
  88. m_writeDisplay = display;
  89. }
  90. /** Look up the given key and display the text. In our case we offer to edit the text. */
  91. void CWriteWindow::lookup( CSwordKey* newKey ) {
  92. //set the raw text to the display widget
  93. if (!newKey)
  94. return;
  95. if (key() != newKey) { //set passage of newKey to key() if they're different, otherwise we'd get mixed up if we look up newkey which may have a different module set
  96. key()->key(newKey->key());
  97. }
  98. if ( modules().count() ) {
  99. displayWidget()->setText( key()->rawText() );
  100. }
  101. setCaption( windowCaption() );
  102. }
  103. /** Returns the write display widget used by this window. */
  104. CWriteDisplay* const CWriteWindow::displayWidget() {
  105. return m_writeDisplay;
  106. }
  107. /** Saves settings */
  108. bool CWriteWindow::queryClose() {
  109. // tqWarning("queryClose called!");
  110. //save the text if it has changed
  111. if (m_writeDisplay->isModified()) {
  112. switch (KMessageBox::warningYesNoCancel( this, i18n("Save text before closing?")) ) {
  113. case KMessageBox::Yes: { //save and close
  114. saveCurrentText();
  115. m_writeDisplay->setModified( false );
  116. return true;
  117. }
  118. case KMessageBox::No: //don't save and close
  119. return true;
  120. default: // cancel, don't close
  121. return false;
  122. }
  123. }
  124. return true;
  125. }
  126. void CWriteWindow::beforeKeyChange(const TQString& key) {
  127. Q_ASSERT(displayWidget());
  128. Q_ASSERT(keyChooser());
  129. if (!isReady()) {
  130. return;
  131. }
  132. //If the text changed and we'd do a lookup ask the user if the text should be saved
  133. if (modules().first() && displayWidget()->isModified()) {
  134. switch (KMessageBox::warningYesNo( this, i18n("Save changed text?")) ) {
  135. case KMessageBox::Yes: { //save the changes
  136. saveCurrentText( key );
  137. break;
  138. }
  139. default: {// set modified to false so it won't ask again
  140. displayWidget()->setModified(false);
  141. break;
  142. }
  143. }
  144. }
  145. }
  146. #include "cwritewindow.moc"