~ubuntu-branches/ubuntu/jaunty/bibletime/jaunty

« back to all changes in this revision

Viewing changes to bibletime/frontend/displaywindow/cbuttons.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralph Janke
  • Date: 2008-05-10 15:18:16 UTC
  • mfrom: (1.1.6 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080510151816-bqp8y1to705zd0fm
Tags: 1.6.5.1-1
* New upstream version (Closes: #441161, #271502)
* fixes for new autotools and gcc 4.3 (Closes: #407291)
* added poxml to Build-Depends
* No DFSG necessary anymore since biblestudy howto has 
  now Commons Licence 
* Added libclucene-dev to dev-depends (Closes: #436677)

Show diffs side-by-side

added added

removed removed

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