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.

cbiblekeychooser.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 "cbiblekeychooser.h"
  11. #include "ckeyreferencewidget.h"
  12. #include "cscrollbutton.h"
  13. #include "backend/cswordversekey.h"
  14. #include "backend/cswordbiblemoduleinfo.h"
  15. #include "backend/cswordmoduleinfo.h"
  16. #include "util/cresmgr.h"
  17. //TQt includes
  18. #include <tqcombobox.h>
  19. #include <tqlistbox.h>
  20. #include <tqpushbutton.h>
  21. //KDE includes
  22. #include <tdelocale.h>
  23. CBibleKeyChooser::CBibleKeyChooser(ListCSwordModuleInfo modules, CSwordKey *key, TQWidget *parent, const char *name )
  24. : CKeyChooser(modules, key, parent, name),
  25. m_key(dynamic_cast<CSwordVerseKey*>(key)) {
  26. w_ref = 0;
  27. setModules(modules, false);
  28. if (!m_modules.count()) {
  29. tqWarning("CBibleKeyChooser: module is not a Bible or commentary!");
  30. m_key = 0;
  31. return;
  32. }
  33. TQHBoxLayout* layout = new TQHBoxLayout(this);
  34. layout->setDirection( TQBoxLayout::LeftToRight );
  35. w_ref = new CKeyReferenceWidget(dynamic_cast<CSwordBibleModuleInfo*>(m_modules.first()), m_key, this);
  36. layout->addWidget(w_ref);
  37. connect(w_ref,TQT_SIGNAL(changed(CSwordVerseKey *)),TQT_SLOT(refChanged(CSwordVerseKey *)));
  38. setKey(m_key); //set the key without changing it, setKey(key()) would change it
  39. }
  40. CSwordKey* const CBibleKeyChooser::key() {
  41. return m_key;
  42. }
  43. void CBibleKeyChooser::setKey(CSwordKey* key) {
  44. Q_ASSERT(dynamic_cast<CSwordVerseKey*>(key));
  45. if (dynamic_cast<CSwordVerseKey*>(key) == 0) {
  46. return;
  47. }
  48. m_key = dynamic_cast<CSwordVerseKey*>(key);
  49. emit (beforeKeyChange(m_key->key())); //required to make direct setKey calls work from the outside
  50. w_ref->setKey(m_key);
  51. emit keyChanged(m_key);
  52. }
  53. void CBibleKeyChooser::refChanged(CSwordVerseKey* key) {
  54. Q_ASSERT(m_key);
  55. Q_ASSERT(key);
  56. if (!isUpdatesEnabled())
  57. return;
  58. setUpdatesEnabled(false);
  59. if (m_key)
  60. emit beforeKeyChange(m_key->key());
  61. m_key = key;
  62. emit keyChanged(m_key);
  63. setUpdatesEnabled(true);
  64. }
  65. /** Sets te module and refreshes the combos */
  66. void CBibleKeyChooser::setModules(const ListCSwordModuleInfo& modules, const bool refresh) {
  67. m_modules.clear();
  68. // for (modules.first(); modules.current(); modules.next()) {
  69. ListCSwordModuleInfo::const_iterator end_it = modules.end();
  70. for (ListCSwordModuleInfo::const_iterator it(modules.begin()); it != end_it; ++it) {
  71. if ((*it)->type() == CSwordModuleInfo::Bible || (*it)->type() == CSwordModuleInfo::Commentary) {
  72. if (CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(*it)) {
  73. m_modules.append(bible);
  74. }
  75. }
  76. }
  77. // First time this is called we havnt set up w_ref.
  78. if (w_ref) w_ref->setModule(dynamic_cast<CSwordBibleModuleInfo*>(m_modules.first()));
  79. if (refresh) refreshContent();
  80. }
  81. void CBibleKeyChooser::refreshContent() {
  82. setKey (m_key);
  83. }
  84. /** No descriptions */
  85. void CBibleKeyChooser::updateKey(CSwordKey* /*key*/) {}
  86. void CBibleKeyChooser::adjustFont() {}
  87. #include "cbiblekeychooser.moc"