3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
5
* Copyright 1999-2008 by the BibleTime developers.
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
10
#include "frontend/displaywindow/btmodulechooserbar.h"
11
#include "frontend/displaywindow/btmodulechooserbutton.h"
12
#include "creadwindow.h"
20
BtModuleChooserBar::BtModuleChooserBar(QStringList useModules, CSwordModuleInfo::ModuleType type, CReadWindow *parent)
22
BtWindowModuleChooser(parent, type),
25
qDebug() << "BtModuleChooserBar::BtModuleChooserBar";
26
setAllowedAreas(Qt::TopToolBarArea);
28
setModules(useModules);
29
connect(parent, SIGNAL(sigModuleListSet(QStringList)), SLOT(slotBackendModulesChanged()));
30
connect(parent, SIGNAL(sigModuleListChanged()), SLOT(slotWindowModulesChanged()));
33
void BtModuleChooserBar::slotBackendModulesChanged() {
34
backendModulesChanged();
37
void BtModuleChooserBar::backendModulesChanged() {
38
m_modules = m_window->getModuleList();
42
//recreate all menus from scratch
43
for (int i = 0; i < m_buttonList.count(); i++) {
44
BtModuleChooserButton* button = m_buttonList.at(i);
45
QString moduleName = (i >= m_modules.count()) ? QString::null : m_modules.at(i);
46
qDebug() << "refresh button's menu:" << moduleName << i;
47
button->recreateMenu(m_modules, moduleName, i);
51
void BtModuleChooserBar::slotWindowModulesChanged() {
52
windowModulesChanged();
55
void BtModuleChooserBar::adjustButtonCount(bool adjustToZero) {
56
//qDebug() << "BtModuleChooserBar::ajustButtonCount";
57
int buttonCountDifference = 0;
59
buttonCountDifference = m_buttonList.count();
62
buttonCountDifference = m_buttonList.count() - (m_modules.count() + 1);
64
if (m_moduleType == CSwordModuleInfo::GenericBook && !adjustToZero) {
65
buttonCountDifference = (1 - m_buttonList.count()) * -1;
67
//if there are more buttons than modules, delete buttons
68
if (buttonCountDifference > 0) {
69
for (int j = 0; j < buttonCountDifference; j++) {
70
//qDebug() << "delete first button, " << j;
71
// it should be safe to delete the button later
72
BtModuleChooserButton* b = m_buttonList.takeFirst();
77
// if there are more modules than buttons, add buttons
78
if (buttonCountDifference < 0) {
79
for (int i = (buttonCountDifference * (-1)); i > 0; i--) {
85
void BtModuleChooserBar::windowModulesChanged() {
86
//qDebug() << "BtModuleChooserBar::windowModulesChanged";
87
m_modules = m_window->getModuleList();
92
BtModuleChooserButton* BtModuleChooserBar::addButton() {
93
//qDebug() << "BtModuleChooserBar::addButton";
94
BtModuleChooserButton* b = new BtModuleChooserButton(this, m_moduleType);
95
QAction* a = addWidget(b);
96
m_buttonList.append(b);
98
// the button sends signals directly to the window which then signals back when the module
100
connect(b, SIGNAL(sigModuleAdd(int, QString)), m_window, SLOT(slotAddModule(int, QString)));
101
connect(b, SIGNAL(sigModuleReplace(int, QString)), m_window, SLOT(slotReplaceModule(int, QString)));
102
connect(b, SIGNAL(sigModuleRemove(int)), m_window, SLOT(slotRemoveModule(int)));
108
/** Sets the modules which are chosen in this module chooser bar. */
109
void BtModuleChooserBar::setModules( QStringList useModules ) {
110
qDebug() << "BtModuleChooserBar::setModules";
111
m_modules = useModules;
112
adjustButtonCount(true);
114
//if (!useModules.count()) return;
115
for (int i = 0; i < useModules.count(); i++) {
118
if (!(m_moduleType == CSwordModuleInfo::GenericBook)) {
119
addButton(); // for ADD button
122
qDebug() << "BtModuleChooserBar::setModules end";
125
void BtModuleChooserBar::updateButtonMenus() {
126
//qDebug() << "BtModuleChooserBar::updateMenuItems";
128
for (int i = 0; i < m_buttonList.count(); i++) {
129
BtModuleChooserButton* button = m_buttonList.at(i);
130
QString moduleName = (i >= m_modules.count()) ? QString::null : m_modules.at(i);
131
//qDebug() << "refresh button's menu:" << moduleName << i;
132
button->updateMenu(m_modules, moduleName, i);