summaryrefslogtreecommitdiffstats
path: root/bibletime/frontend/displaywindow/cbuttons.cpp
blob: 42085fd4e18d8ff967f71e08e2b01f7c02f85355 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2006 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/



//HibleTime includes
#include "cbuttons.h"

#include "util/cresmgr.h"

#include "util/cpointers.h"

//TQt includes
#include <tqstring.h>
#include <tqtooltip.h>

//KDE includes
#include <tdepopupmenu.h>
#include <tdelocale.h>


// CTransliterationButton::CTransliterationButton(CSwordBackend::FilterOptions* filterOptions, TQWidget *parent, const char *name )
//  : TDEToolBarButton(CResMgr::displaywindows::transliteration::icon, 0,parent,name) {
//   m_filterOptions = filterOptions;
//   m_filterOptions->transliteration = 0;
//
//   m_popup = new TDEPopupMenu(this);
//  setPopup(m_popup);
//  setPopupDelay(0001);
//
//  connect(m_popup, TQT_SIGNAL(activated(int)), this, TQT_SLOT(optionSelected(int)));
//  populateMenu();
// }
//
// CTransliterationButton::~CTransliterationButton(){
//
// }
//
// /** Resets the buttons with the list of used modules. */
// void CTransliterationButton::reset( ListCSwordModuleInfo& /*modules*/ ){
//   m_popup->clear();
// //  popuplateMenu();
// }
//
// /** Setup the menu entries. */
// void CTransliterationButton::populateMenu(){
//   m_popup->clear();
//   m_popup->insertTitle(i18n("Transliteration"));
//  m_popup->setCheckable(true);
//
//   if (!CPointers::backend()->useICU())
//     return;
//
//   Q_ASSERT(CPointers::backend()->transliterator());
//   if (!CPointers::backend()->transliterator())
//     return;
//
//   sword::StringList options = CPointers::backend()->transliterator()->getOptionValues();
//   sword::StringList::iterator it;
//
//   for (it = options.begin(); it != options.end(); ++it) {
//   int id = m_popup->insertItem(TQString::fromLatin1((*it).c_str()));
//   if (m_filterOptions->transliteration == m_popup->indexOf(id)-1 ) { //workaround
//    m_popup->setItemChecked(id, true);
//   }
//   }
// }
//
// /** No descriptions */
// void CTransliterationButton::optionSelected(int ID){
//   for (unsigned int i = 0; i < m_popup->count(); i++)
//    m_popup->setItemChecked(m_popup->idAt(i),false);
//   m_popup->setItemChecked(ID, true);
//
//   m_filterOptions->transliteration = m_popup->indexOf( ID )-1; //workaround
//   emit sigChanged();
// }

/************************************************
 *********** CDisplaySettingsButton *************
 ************************************************/

CDisplaySettingsButton::CDisplaySettingsButton(CSwordBackend::DisplayOptions *displaySettings, CSwordBackend::FilterOptions *moduleSettings, const ListCSwordModuleInfo& useModules,TQWidget *parent, const char *name )
: TDEToolBarButton(CResMgr::displaywindows::displaySettings::icon, 0, parent, name) {
	//  tqWarning("CDisplaySettingsButton::CDisplaySettingsButton");
	m_displaySettings = displaySettings;
	m_moduleSettings = moduleSettings;
	m_modules = useModules;

	m_popup = new TDEPopupMenu(this);
	setPopup(m_popup);
	setPopupDelay(0001); //Fix, O only opens menu on mouse release or move

	connect(m_popup, TQT_SIGNAL(activated(int)), this, TQT_SLOT(optionToggled(int)));
	populateMenu();
}

void CDisplaySettingsButton::reset(const ListCSwordModuleInfo& useModules) {
	m_modules = useModules;
	populateMenu();
	//disable the settings button if no options are available
	if (!populateMenu()) {
		setEnabled(false);
		TQToolTip::add
			(this, i18n("Display settings: No options available"));
	}
	else {
		setEnabled(true);
		TQToolTip::add
			(this, i18n("Display settings"));
	}
}


void CDisplaySettingsButton::optionToggled(int ID) {
	m_popup->setItemChecked( ID, !(m_popup->isItemChecked(ID)));
	if (!m_popup->text(ID).isEmpty())
		*(m_dict[m_popup->text(ID).remove('&')]) =  m_popup->isItemChecked(ID);
	emit sigChanged();
}

/** No descriptions */
int CDisplaySettingsButton::populateMenu() {
	int ret = 0;

	m_popup->clear();
	m_popup->insertTitle(i18n("Display options"));
	m_popup->setCheckable(true);

	ret += addMenuEntry(i18n("Use linebreaks after each verse"), &m_displaySettings->lineBreaks, (m_modules.first()->type() == CSwordModuleInfo::Bible));

	//only show the verse numbers option for bible modules
	ret += addMenuEntry(i18n("Show versenumbers"), &m_displaySettings->verseNumbers, (m_modules.first()->type() == CSwordModuleInfo::Bible));

	ret += addMenuEntry(i18n("Show headings"), &m_moduleSettings->headings,
						isOptionAvailable(CSwordModuleInfo::headings));
	/* ret += addMenuEntry(i18n("Show footnotes"), &m_moduleSettings->footnotes,
	  isOptionAvailable(CSwordBackend::footnotes ));*/
	ret += addMenuEntry(i18n("Highlight words of Jesus"), &m_moduleSettings->redLetterWords,
						isOptionAvailable(CSwordModuleInfo::redLetterWords ));
	//  ret += addMenuEntry(i18n("Show Strong's Numbers"), &m_moduleSettings->strongNumbers,
	//   isOptionAvailable(CSwordBackend::strongNumbers ));

	/* ret += addMenuEntry(i18n("Show morphologic tags"),&m_moduleSettings->morphTags,
	  isOptionAvailable(CSwordBackend::morphTags ));
	 ret += addMenuEntry(i18n("Show lemmas"),&m_moduleSettings->lemmas,
	  isOptionAvailable(CSwordBackend::lemmas ));*/
	ret += addMenuEntry(i18n("Show Hebrew vowel points"), &m_moduleSettings->hebrewPoints,
						isOptionAvailable(CSwordModuleInfo::hebrewPoints ));
	ret += addMenuEntry(i18n("Show Hebrew cantillation marks"), &m_moduleSettings->hebrewCantillation,
						isOptionAvailable(CSwordModuleInfo::hebrewCantillation ));
	ret += addMenuEntry(i18n("Show Greek accents"), &m_moduleSettings->greekAccents,
						isOptionAvailable(CSwordModuleInfo::greekAccents ));

	ret += addMenuEntry(i18n("Use alternative textual variant"), &m_moduleSettings->textualVariants,
						isOptionAvailable(CSwordModuleInfo::textualVariants ));
	ret += addMenuEntry(i18n("Show scripture cross-references"), &m_moduleSettings->scriptureReferences,
						isOptionAvailable(CSwordModuleInfo::scriptureReferences ));
	ret += addMenuEntry(i18n("Show morph segmentation"), &m_moduleSettings->morphSegmentation,
						isOptionAvailable(CSwordModuleInfo::morphSegmentation ));

	return ret;
}

/** No descriptions */
int CDisplaySettingsButton::addMenuEntry( const TQString name, const int* option, const bool available) {
	int ret = 0;

	if (available) {
		m_dict.insert( name, option );
		m_popup->setItemChecked(m_popup->insertItem( name ), *option );
		ret = 1;
	}

	return ret;
}

bool CDisplaySettingsButton::isOptionAvailable( const CSwordModuleInfo::FilterTypes option ) {
	bool ret = false;
	//  for (m_modules.first(); m_modules.current() && !ret; m_modules.next()) {
	ListCSwordModuleInfo::iterator end_it = m_modules.end();
	for (ListCSwordModuleInfo::iterator it(m_modules.begin()); it != end_it; ++it) {
		ret = ret || (*it)->has(option);
	}

	return ret;
}

/** Returns the number of usable menu items in the setttings menu. */
const int CDisplaySettingsButton::menuItemCount() {
	return m_popup->count();
}

/** Sets the item at position pos to the satet given as 2nd paramter. */
void CDisplaySettingsButton::setItemStatus( const int index, const bool checked ) {
	const int ID = m_popup->idAt(index);
	m_popup->setItemChecked(ID, checked);
	const TQString text = m_popup->text(ID).remove('&');
	if (m_dict[text]) {
		*(m_dict[text]) = checked;
	}
}

/** Returns the status of the item at position "index" */
const bool CDisplaySettingsButton::itemStatus( const int index ) {
	return m_popup->isItemChecked( m_popup->idAt(index) );
}

/** Sets the status to changed. The signal changed will be emitted. */
void CDisplaySettingsButton::setChanged() {
	emit sigChanged();
}