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.

cbuttons.cpp 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. //HibleTime includes
  10. #include "cbuttons.h"
  11. #include "util/cresmgr.h"
  12. #include "util/cpointers.h"
  13. //TQt includes
  14. #include <tqstring.h>
  15. #include <tqtooltip.h>
  16. //KDE includes
  17. #include <kpopupmenu.h>
  18. #include <klocale.h>
  19. // CTransliterationButton::CTransliterationButton(CSwordBackend::FilterOptions* filterOptions, TQWidget *parent, const char *name )
  20. // : TDEToolBarButton(CResMgr::displaywindows::transliteration::icon, 0,parent,name) {
  21. // m_filterOptions = filterOptions;
  22. // m_filterOptions->transliteration = 0;
  23. //
  24. // m_popup = new TDEPopupMenu(this);
  25. // setPopup(m_popup);
  26. // setPopupDelay(0001);
  27. //
  28. // connect(m_popup, TQT_SIGNAL(activated(int)), this, TQT_SLOT(optionSelected(int)));
  29. // populateMenu();
  30. // }
  31. //
  32. // CTransliterationButton::~CTransliterationButton(){
  33. //
  34. // }
  35. //
  36. // /** Resets the buttons with the list of used modules. */
  37. // void CTransliterationButton::reset( ListCSwordModuleInfo& /*modules*/ ){
  38. // m_popup->clear();
  39. // // popuplateMenu();
  40. // }
  41. //
  42. // /** Setup the menu entries. */
  43. // void CTransliterationButton::populateMenu(){
  44. // m_popup->clear();
  45. // m_popup->insertTitle(i18n("Transliteration"));
  46. // m_popup->setCheckable(true);
  47. //
  48. // if (!CPointers::backend()->useICU())
  49. // return;
  50. //
  51. // Q_ASSERT(CPointers::backend()->transliterator());
  52. // if (!CPointers::backend()->transliterator())
  53. // return;
  54. //
  55. // sword::StringList options = CPointers::backend()->transliterator()->getOptionValues();
  56. // sword::StringList::iterator it;
  57. //
  58. // for (it = options.begin(); it != options.end(); ++it) {
  59. // int id = m_popup->insertItem(TQString::fromLatin1((*it).c_str()));
  60. // if (m_filterOptions->transliteration == m_popup->indexOf(id)-1 ) { //workaround
  61. // m_popup->setItemChecked(id, true);
  62. // }
  63. // }
  64. // }
  65. //
  66. // /** No descriptions */
  67. // void CTransliterationButton::optionSelected(int ID){
  68. // for (unsigned int i = 0; i < m_popup->count(); i++)
  69. // m_popup->setItemChecked(m_popup->idAt(i),false);
  70. // m_popup->setItemChecked(ID, true);
  71. //
  72. // m_filterOptions->transliteration = m_popup->indexOf( ID )-1; //workaround
  73. // emit sigChanged();
  74. // }
  75. /************************************************
  76. *********** CDisplaySettingsButton *************
  77. ************************************************/
  78. CDisplaySettingsButton::CDisplaySettingsButton(CSwordBackend::DisplayOptions *displaySettings, CSwordBackend::FilterOptions *moduleSettings, const ListCSwordModuleInfo& useModules,TQWidget *parent, const char *name )
  79. : TDEToolBarButton(CResMgr::displaywindows::displaySettings::icon, 0, parent, name) {
  80. // tqWarning("CDisplaySettingsButton::CDisplaySettingsButton");
  81. m_displaySettings = displaySettings;
  82. m_moduleSettings = moduleSettings;
  83. m_modules = useModules;
  84. m_popup = new TDEPopupMenu(this);
  85. setPopup(m_popup);
  86. setPopupDelay(0001); //Fix, O only opens menu on mouse release or move
  87. connect(m_popup, TQT_SIGNAL(activated(int)), this, TQT_SLOT(optionToggled(int)));
  88. populateMenu();
  89. }
  90. void CDisplaySettingsButton::reset(const ListCSwordModuleInfo& useModules) {
  91. m_modules = useModules;
  92. populateMenu();
  93. //disable the settings button if no options are available
  94. if (!populateMenu()) {
  95. setEnabled(false);
  96. TQToolTip::add
  97. (this, i18n("Display settings: No options available"));
  98. }
  99. else {
  100. setEnabled(true);
  101. TQToolTip::add
  102. (this, i18n("Display settings"));
  103. }
  104. }
  105. void CDisplaySettingsButton::optionToggled(int ID) {
  106. m_popup->setItemChecked( ID, !(m_popup->isItemChecked(ID)));
  107. if (!m_popup->text(ID).isEmpty())
  108. *(m_dict[m_popup->text(ID).remove('&')]) = m_popup->isItemChecked(ID);
  109. emit sigChanged();
  110. }
  111. /** No descriptions */
  112. int CDisplaySettingsButton::populateMenu() {
  113. int ret = 0;
  114. m_popup->clear();
  115. m_popup->insertTitle(i18n("Display options"));
  116. m_popup->setCheckable(true);
  117. ret += addMenuEntry(i18n("Use linebreaks after each verse"), &m_displaySettings->lineBreaks, (m_modules.first()->type() == CSwordModuleInfo::Bible));
  118. //only show the verse numbers option for bible modules
  119. ret += addMenuEntry(i18n("Show versenumbers"), &m_displaySettings->verseNumbers, (m_modules.first()->type() == CSwordModuleInfo::Bible));
  120. ret += addMenuEntry(i18n("Show headings"), &m_moduleSettings->headings,
  121. isOptionAvailable(CSwordModuleInfo::headings));
  122. /* ret += addMenuEntry(i18n("Show footnotes"), &m_moduleSettings->footnotes,
  123. isOptionAvailable(CSwordBackend::footnotes ));*/
  124. ret += addMenuEntry(i18n("Highlight words of Jesus"), &m_moduleSettings->redLetterWords,
  125. isOptionAvailable(CSwordModuleInfo::redLetterWords ));
  126. // ret += addMenuEntry(i18n("Show Strong's Numbers"), &m_moduleSettings->strongNumbers,
  127. // isOptionAvailable(CSwordBackend::strongNumbers ));
  128. /* ret += addMenuEntry(i18n("Show morphologic tags"),&m_moduleSettings->morphTags,
  129. isOptionAvailable(CSwordBackend::morphTags ));
  130. ret += addMenuEntry(i18n("Show lemmas"),&m_moduleSettings->lemmas,
  131. isOptionAvailable(CSwordBackend::lemmas ));*/
  132. ret += addMenuEntry(i18n("Show Hebrew vowel points"), &m_moduleSettings->hebrewPoints,
  133. isOptionAvailable(CSwordModuleInfo::hebrewPoints ));
  134. ret += addMenuEntry(i18n("Show Hebrew cantillation marks"), &m_moduleSettings->hebrewCantillation,
  135. isOptionAvailable(CSwordModuleInfo::hebrewCantillation ));
  136. ret += addMenuEntry(i18n("Show Greek accents"), &m_moduleSettings->greekAccents,
  137. isOptionAvailable(CSwordModuleInfo::greekAccents ));
  138. ret += addMenuEntry(i18n("Use alternative textual variant"), &m_moduleSettings->textualVariants,
  139. isOptionAvailable(CSwordModuleInfo::textualVariants ));
  140. ret += addMenuEntry(i18n("Show scripture cross-references"), &m_moduleSettings->scriptureReferences,
  141. isOptionAvailable(CSwordModuleInfo::scriptureReferences ));
  142. ret += addMenuEntry(i18n("Show morph segmentation"), &m_moduleSettings->morphSegmentation,
  143. isOptionAvailable(CSwordModuleInfo::morphSegmentation ));
  144. return ret;
  145. }
  146. /** No descriptions */
  147. int CDisplaySettingsButton::addMenuEntry( const TQString name, const int* option, const bool available) {
  148. int ret = 0;
  149. if (available) {
  150. m_dict.insert( name, option );
  151. m_popup->setItemChecked(m_popup->insertItem( name ), *option );
  152. ret = 1;
  153. }
  154. return ret;
  155. }
  156. bool CDisplaySettingsButton::isOptionAvailable( const CSwordModuleInfo::FilterTypes option ) {
  157. bool ret = false;
  158. // for (m_modules.first(); m_modules.current() && !ret; m_modules.next()) {
  159. ListCSwordModuleInfo::iterator end_it = m_modules.end();
  160. for (ListCSwordModuleInfo::iterator it(m_modules.begin()); it != end_it; ++it) {
  161. ret = ret || (*it)->has(option);
  162. }
  163. return ret;
  164. }
  165. /** Returns the number of usable menu items in the setttings menu. */
  166. const int CDisplaySettingsButton::menuItemCount() {
  167. return m_popup->count();
  168. }
  169. /** Sets the item at position pos to the satet given as 2nd paramter. */
  170. void CDisplaySettingsButton::setItemStatus( const int index, const bool checked ) {
  171. const int ID = m_popup->idAt(index);
  172. m_popup->setItemChecked(ID, checked);
  173. const TQString text = m_popup->text(ID).remove('&');
  174. if (m_dict[text]) {
  175. *(m_dict[text]) = checked;
  176. }
  177. }
  178. /** Returns the status of the item at position "index" */
  179. const bool CDisplaySettingsButton::itemStatus( const int index ) {
  180. return m_popup->isItemChecked( m_popup->idAt(index) );
  181. }
  182. /** Sets the status to changed. The signal changed will be emitted. */
  183. void CDisplaySettingsButton::setChanged() {
  184. emit sigChanged();
  185. }