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.

ckeychooser.cpp 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 "ckeychooser.h"
  10. #include "backend/cswordmoduleinfo.h"
  11. #include "backend/cswordbiblemoduleinfo.h"
  12. #include "backend/cswordcommentarymoduleinfo.h"
  13. #include "backend/cswordlexiconmoduleinfo.h"
  14. #include "clexiconkeychooser.h"
  15. #include "cbiblekeychooser.h"
  16. #include "cbookkeychooser.h"
  17. CKeyChooser::CKeyChooser(ListCSwordModuleInfo, CSwordKey *, TQWidget *parent, const char *name )
  18. : TQWidget(parent, name),
  19. m_inHistoryFunction(false) {}
  20. CKeyChooser::~CKeyChooser() {}
  21. CKeyChooser* CKeyChooser::createInstance(ListCSwordModuleInfo modules, CSwordKey *key, TQWidget *parent) {
  22. if (!modules.count()) {
  23. return 0;
  24. }
  25. CKeyChooser* ck = 0;
  26. switch ( modules.first()->type() ) {
  27. case CSwordModuleInfo::Commentary: //Bibles and commentaries uise the same key chooser
  28. case CSwordModuleInfo::Bible:
  29. ck = new CBibleKeyChooser(modules,key,parent);
  30. break;
  31. case CSwordModuleInfo::Lexicon:
  32. ck = new CLexiconKeyChooser(modules,key,parent);
  33. break;
  34. case CSwordModuleInfo::GenericBook:
  35. ck = new CBookKeyChooser(modules,key,parent);
  36. break;
  37. default:
  38. return 0;
  39. }
  40. return ck;
  41. }
  42. void CKeyChooser::backInHistory() {
  43. backInHistory(1);
  44. }
  45. void CKeyChooser::backInHistory(int count) {
  46. m_inHistoryFunction = true;
  47. // tqWarning("go back %d items in history", count);
  48. Q_ASSERT(m_prevKeyHistoryList.size());
  49. TQStringList::iterator it = m_prevKeyHistoryList.begin();
  50. //pop_front count items, the top item is then the new current key
  51. int index = count;
  52. while ((index > 0) && (it != m_prevKeyHistoryList.end())) {
  53. // tqWarning("pop_front");
  54. m_nextKeyHistoryList.prepend(*it);
  55. it = m_prevKeyHistoryList.remove(it);
  56. --index;
  57. }
  58. //the first item is now the item which should be set as key
  59. if (it != m_nextKeyHistoryList.end() && key()) {
  60. CSwordKey* k = key();
  61. k->key(*it);
  62. setKey(k);
  63. }
  64. m_inHistoryFunction = false;
  65. }
  66. void CKeyChooser::forwardInHistory() {
  67. forwardInHistory(1);
  68. }
  69. void CKeyChooser::forwardInHistory(int count) {
  70. m_inHistoryFunction = true;
  71. // tqWarning("go forward %d items in history", count);
  72. Q_ASSERT(m_nextKeyHistoryList.size());
  73. TQStringList::iterator it = m_nextKeyHistoryList.begin();
  74. //pop_front count-1 items, the top item is then the new current key
  75. int index = count;
  76. while (index > 0 && it != m_nextKeyHistoryList.end()) {
  77. // tqWarning("pop_front");
  78. m_prevKeyHistoryList.prepend(*it);
  79. it = m_nextKeyHistoryList.remove(it);
  80. --index;
  81. }
  82. //the first item of the back list is now the new key
  83. it = m_prevKeyHistoryList.begin();
  84. if (it != m_prevKeyHistoryList.end() && key()) {
  85. CSwordKey* k = key();
  86. k->key(*it);
  87. setKey(k);
  88. }
  89. m_inHistoryFunction = false;
  90. }
  91. void CKeyChooser::addToHistory(CSwordKey* k) {
  92. // tqWarning("addToHistory");
  93. Q_ASSERT(!m_inHistoryFunction);
  94. if (k && !m_inHistoryFunction) {
  95. Q_ASSERT(k->key() == key()->key());
  96. m_prevKeyHistoryList.prepend(k->key());
  97. }
  98. emit historyChanged();
  99. }
  100. const TQStringList CKeyChooser::getPreviousKeys() const {
  101. TQStringList ret = m_prevKeyHistoryList;
  102. if (ret.size() >= 1) {
  103. ret.pop_front(); //the first item always is equal to the current key
  104. }
  105. return ret;
  106. }
  107. const TQStringList CKeyChooser::getNextKeys() const {
  108. return m_nextKeyHistoryList;
  109. }
  110. /*!
  111. \fn CKeyChooser::polish()
  112. */
  113. void CKeyChooser::polish() {
  114. TQWidget::polish();
  115. //connect the history calls just before we show, we want an empty history
  116. connect(this, TQT_SIGNAL(keyChanged(CSwordKey*)), TQT_SLOT(addToHistory(CSwordKey*)));
  117. }
  118. #include "ckeychooser.moc"