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.

ckeyreferencewidget.cpp 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 "ckeyreferencewidget.h"
  11. #include "cscrollerwidgetset.h"
  12. //BibleTime frontend includes
  13. #include "frontend/cbtconfig.h"
  14. #include "backend/cswordversekey.h"
  15. #include "util/cresmgr.h"
  16. //TQt includes
  17. #include <klineedit.h>
  18. #include <tqstring.h>
  19. #include <tqstringlist.h>
  20. #include <tqevent.h>
  21. #include <tqpixmap.h>
  22. #include <tqapplication.h>
  23. #include <kcompletion.h>
  24. #include <tdeglobalsettings.h>
  25. #include <tdecompletionbox.h>
  26. #include <tdelocale.h>
  27. #include <kpushbutton.h>
  28. #include <kguiitem.h>
  29. /* Override the completion box for our references */
  30. CKeyReferenceCompletion::CKeyReferenceCompletion(CSwordBibleModuleInfo *mod) : TDECompletion()
  31. {
  32. m_key = new CSwordVerseKey(mod);
  33. m_module = mod;
  34. }
  35. TQString CKeyReferenceCompletion::makeCompletion(const TQString &text) {
  36. if(!text.isEmpty() && m_key->key(text)) {
  37. // XXX: key() does not check bounds properly if we only have eg the NT.
  38. return m_key->key();
  39. }
  40. return TQString();
  41. }
  42. //**********************************************************************************/
  43. /* To get popup working we have to rework KLineEdit too */
  44. CKeyReferenceLineEdit::CKeyReferenceLineEdit(TQWidget *parent, const char *name) : KLineEdit(parent,name) {
  45. }
  46. void CKeyReferenceLineEdit::makeCompletion(const TQString &text) {
  47. TDECompletion *comp = compObj();
  48. TDEGlobalSettings::Completion mode = completionMode();
  49. if ( !comp || mode == TDEGlobalSettings::CompletionNone )
  50. return; // No completion object...
  51. TQString match = comp->makeCompletion( text );
  52. if ( mode == TDEGlobalSettings::CompletionPopup ||
  53. mode == TDEGlobalSettings::CompletionPopupAuto )
  54. {
  55. if ( match.isNull() )
  56. {
  57. TDECompletionBox *compbox = completionBox();
  58. compbox->hide();
  59. compbox->clear();
  60. } else {
  61. TQStringList t;
  62. t.append(match);
  63. setCompletedItems(t);
  64. }
  65. } else {
  66. KLineEdit::makeCompletion(text);
  67. }
  68. }
  69. //**********************************************************************************/
  70. CKeyReferenceWidget::CKeyReferenceWidget( CSwordBibleModuleInfo *mod, CSwordVerseKey *key, TQWidget *parent, const char *name) : TQWidget(parent,name) {
  71. updatelock = false;
  72. m_module = mod;
  73. setFocusPolicy(TQ_WheelFocus);
  74. // Erase button
  75. KGuiItem erase_picture;
  76. erase_picture.setIconName("locationbar_erase");
  77. KPushButton *clearRef = new KPushButton(this);
  78. clearRef->setGuiItem(erase_picture);
  79. connect(clearRef, TQT_SIGNAL(clicked( ) ), TQT_SLOT(slotClearRef( )));
  80. m_bookScroller = new CScrollerWidgetSet(this);
  81. m_textbox = new CKeyReferenceLineEdit( this );
  82. setKey(key); // The order of these two functions is important.
  83. setModule();
  84. m_chapterScroller = new CScrollerWidgetSet(this);
  85. m_verseScroller = new CScrollerWidgetSet(this);
  86. m_mainLayout = new TQHBoxLayout( this );
  87. m_mainLayout->addWidget(clearRef);
  88. m_mainLayout->addWidget(m_bookScroller);
  89. m_mainLayout->addWidget(m_textbox);
  90. m_mainLayout->addWidget(m_chapterScroller);
  91. m_mainLayout->addWidget(m_verseScroller);
  92. setTabOrder(m_textbox, 0);
  93. m_bookScroller->setToolTips(
  94. CResMgr::displaywindows::bibleWindow::nextBook::tooltip,
  95. CResMgr::displaywindows::general::scrollButton::tooltip,
  96. CResMgr::displaywindows::bibleWindow::previousBook::tooltip
  97. );
  98. m_chapterScroller->setToolTips(
  99. CResMgr::displaywindows::bibleWindow::nextChapter::tooltip,
  100. CResMgr::displaywindows::general::scrollButton::tooltip,
  101. CResMgr::displaywindows::bibleWindow::previousChapter::tooltip
  102. );
  103. m_verseScroller->setToolTips(
  104. CResMgr::displaywindows::bibleWindow::nextVerse::tooltip,
  105. CResMgr::displaywindows::general::scrollButton::tooltip,
  106. CResMgr::displaywindows::bibleWindow::previousVerse::tooltip
  107. );
  108. // signals and slots connections
  109. connect(m_bookScroller, TQT_SIGNAL(change(int)), TQT_SLOT(slotBookChange(int)));
  110. connect(m_bookScroller, TQT_SIGNAL(scroller_pressed()), TQT_SLOT(slotUpdateLock()));
  111. connect(m_bookScroller, TQT_SIGNAL(scroller_released()), TQT_SLOT(slotUpdateUnlock()));
  112. connect(m_textbox, TQT_SIGNAL(returnPressed()), TQT_SLOT(slotReturnPressed()));
  113. connect(m_chapterScroller, TQT_SIGNAL(change(int)), TQT_SLOT(slotChapterChange(int)));
  114. connect(m_chapterScroller, TQT_SIGNAL(scroller_pressed()), TQT_SLOT(slotUpdateLock()));
  115. connect(m_chapterScroller, TQT_SIGNAL(scroller_released()), TQT_SLOT(slotUpdateUnlock()));
  116. connect(m_verseScroller, TQT_SIGNAL(change(int)), TQT_SLOT(slotVerseChange(int)));
  117. connect(m_verseScroller, TQT_SIGNAL(scroller_pressed()), TQT_SLOT(slotUpdateLock()));
  118. connect(m_verseScroller, TQT_SIGNAL(scroller_released()), TQT_SLOT(slotUpdateUnlock()));
  119. }
  120. void CKeyReferenceWidget::setModule(CSwordBibleModuleInfo *m) {
  121. if (m)
  122. m_module = m;
  123. delete m_textbox->completionObject();
  124. CKeyReferenceCompletion *comp = new CKeyReferenceCompletion(m_module);
  125. m_textbox->setCompletionObject(comp);
  126. m_textbox->setCompletionMode(TDEGlobalSettings::CompletionPopup);
  127. }
  128. void CKeyReferenceWidget::slotClearRef( ) {
  129. m_textbox->setText("");
  130. m_textbox->setFocus();
  131. }
  132. void CKeyReferenceWidget::updateText() {
  133. m_textbox->setText(m_key->key());
  134. }
  135. bool CKeyReferenceWidget::setKey(CSwordVerseKey *key) {
  136. m_key = key;
  137. updateText();
  138. return true;
  139. }
  140. KLineEdit* CKeyReferenceWidget::textbox() {
  141. return m_textbox;
  142. }
  143. void CKeyReferenceWidget::slotReturnPressed() {
  144. m_key->key(m_textbox->text());
  145. updateText();
  146. emit changed(m_key);
  147. }
  148. /* Handlers for the various scroller widgetsets. Do we really want a verse scroller? */
  149. void CKeyReferenceWidget::slotUpdateLock() {
  150. updatelock = true;
  151. oldKey = m_key->key();
  152. }
  153. void CKeyReferenceWidget::slotUpdateUnlock() {
  154. updatelock = false;
  155. if (oldKey != m_key->key()) emit changed(m_key);
  156. }
  157. void CKeyReferenceWidget::slotBookChange(int n) {
  158. n > 0 ? m_key->next( CSwordVerseKey::UseBook ) : m_key->previous( CSwordVerseKey::UseBook );
  159. updateText();
  160. if (!updatelock) emit changed(m_key);
  161. }
  162. void CKeyReferenceWidget::slotChapterChange(int n) {
  163. n > 0 ? m_key->next( CSwordVerseKey::UseChapter ) : m_key->previous( CSwordVerseKey::UseChapter );
  164. updateText();
  165. if (!updatelock) emit changed(m_key);
  166. }
  167. void CKeyReferenceWidget::slotVerseChange(int n) {
  168. n > 0 ? m_key->next( CSwordVerseKey::UseVerse ) : m_key->previous( CSwordVerseKey::UseVerse );
  169. updateText();
  170. if (!updatelock) emit changed(m_key);
  171. }
  172. #include "ckeyreferencewidget.moc"