diff options
Diffstat (limited to 'src/frontend/displaywindow')
24 files changed, 1662 insertions, 978 deletions
diff --git a/src/frontend/displaywindow/btdisplaysettingsbutton.cpp b/src/frontend/displaywindow/btdisplaysettingsbutton.cpp new file mode 100644 index 0000000..e809efc --- /dev/null +++ b/src/frontend/displaywindow/btdisplaysettingsbutton.cpp @@ -0,0 +1,232 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2008 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#include "frontend/displaywindow/btdisplaysettingsbutton.h" + +#include <QHash> +#include <QMenu> +#include <QString> +#include <QToolTip> +#include <QToolButton> +#include "util/directory.h" +#include "util/cpointers.h" +#include "util/cresmgr.h" + + +BtDisplaySettingsButton::BtDisplaySettingsButton(QWidget *parent) + : QToolButton(parent) { + namespace DU = util::directory; + + initMenu(); + + setIcon(DU::getIcon(CResMgr::displaywindows::displaySettings::icon)); + setPopupMode(QToolButton::InstantPopup); + setEnabled(false); + + initMenu(); + retranslateUi(); + + connect(m_popup, SIGNAL(triggered(QAction*)), + this, SLOT(slotOptionToggled(QAction*))); +} + +void BtDisplaySettingsButton::setDisplayOptions( + const CSwordBackend::DisplayOptions &displaySettings, bool repopulate) +{ + m_displayOptions = displaySettings; + if (repopulate) { + repopulateMenu(); + } +} + +void BtDisplaySettingsButton::setFilterOptions( + const CSwordBackend::FilterOptions &moduleSettings, + bool repopulate) +{ + m_filterOptions = moduleSettings; + if (repopulate) { + repopulateMenu(); + } +} + +void BtDisplaySettingsButton::setModules(const QList<CSwordModuleInfo*> &modules) { + m_modules = modules; + repopulateMenu(); +} + +void BtDisplaySettingsButton::initMenu() { + m_popup = new QMenu(this); + setMenu(m_popup); + + m_lineBreakAction = new QAction(this); + m_lineBreakAction->setCheckable(true); + + m_verseNumbersAction = new QAction(this); + m_verseNumbersAction->setCheckable(true); + + m_headingsAction = new QAction(this); + m_headingsAction->setCheckable(true); + + m_redWordsAction = new QAction(this); + m_redWordsAction->setCheckable(true); + + m_hebrewPointsAction = new QAction(this); + m_hebrewPointsAction->setCheckable(true); + + m_hebrewCantillationAction = new QAction(this); + m_hebrewCantillationAction->setCheckable(true); + + m_greekAccentsAction = new QAction(this); + m_greekAccentsAction->setCheckable(true); + + m_variantAction = new QAction(this); + m_variantAction->setCheckable(true); + + m_scriptureReferencesAction = new QAction(this); + m_scriptureReferencesAction->setCheckable(true); + + m_morphSegmentationAction = new QAction(this); + m_morphSegmentationAction->setCheckable(true); +} + +void BtDisplaySettingsButton::retranslateUi() { + m_lineBreakAction->setText(tr("Use linebreaks after each verse")); + m_verseNumbersAction->setText(tr("Show verse numbers")); + m_headingsAction->setText(tr("Show headings")); + m_redWordsAction->setText(tr("Highlight words of Jesus")); + m_hebrewPointsAction->setText(tr("Show Hebrew vowel points")); + m_hebrewCantillationAction->setText(tr("Show Hebrew cantillation marks")); + m_greekAccentsAction->setText(tr("Show Greek accents")); + m_variantAction->setText(tr("Use alternative textual variant")); + m_scriptureReferencesAction->setText(tr("Show scripture cross-references")); + m_morphSegmentationAction->setText(tr("Show morph segmentation")); + + retranslateToolTip(); +} + +void BtDisplaySettingsButton::retranslateToolTip() { + if (isEnabled()) { + setToolTip(tr("Display settings")); + } + else { + setToolTip(tr("Display settings: No options available")); + } +} + +void BtDisplaySettingsButton::slotOptionToggled(QAction *action) { + bool checked = action->isChecked(); + + if (action == m_lineBreakAction) { + m_displayOptions.lineBreaks = checked; + emit sigDisplayOptionsChanged(m_displayOptions); + } else if (action == m_verseNumbersAction) { + m_displayOptions.verseNumbers = checked; + emit sigDisplayOptionsChanged(m_displayOptions); + } else if (action == m_variantAction) { + m_filterOptions.textualVariants = checked; + emit sigFilterOptionsChanged(m_filterOptions); + } else if (action == m_hebrewPointsAction) { + m_filterOptions.hebrewPoints = checked; + emit sigFilterOptionsChanged(m_filterOptions); + } else if (action == m_greekAccentsAction) { + m_filterOptions.greekAccents = checked; + emit sigFilterOptionsChanged(m_filterOptions); + } else if (action == m_hebrewCantillationAction) { + m_filterOptions.hebrewCantillation = checked; + emit sigFilterOptionsChanged(m_filterOptions); + } else if (action == m_headingsAction) { + m_filterOptions.headings = checked; + emit sigFilterOptionsChanged(m_filterOptions); + } else if (action == m_morphSegmentationAction) { + m_filterOptions.morphSegmentation = checked; + emit sigFilterOptionsChanged(m_filterOptions); + } else if (action == m_scriptureReferencesAction) { + m_filterOptions.scriptureReferences = checked; + emit sigFilterOptionsChanged(m_filterOptions); + } else if (action == m_redWordsAction) { + m_filterOptions.redLetterWords = checked; + emit sigFilterOptionsChanged(m_filterOptions); + } else { + Q_ASSERT(false); + return; + } + + emit sigChanged(); +} + +/** No descriptions */ +void BtDisplaySettingsButton::repopulateMenu() { + bool enable = false; + + m_popup->clear(); + if (!m_modules.isEmpty()) { + if (m_modules.first()->type() == CSwordModuleInfo::Bible) { + addMenuEntry(m_lineBreakAction, m_displayOptions.lineBreaks); + addMenuEntry(m_verseNumbersAction, m_displayOptions.verseNumbers); + enable = true; + } + + if (isOptionAvailable(CSwordModuleInfo::headings)) { + addMenuEntry(m_headingsAction, m_filterOptions.headings); + enable = true; + } + + if (isOptionAvailable(CSwordModuleInfo::redLetterWords)) { + addMenuEntry(m_redWordsAction, m_filterOptions.redLetterWords); + enable = true; + } + + if (isOptionAvailable(CSwordModuleInfo::hebrewPoints)) { + addMenuEntry(m_hebrewPointsAction, m_filterOptions.hebrewPoints); + enable = true; + } + + if (isOptionAvailable(CSwordModuleInfo::hebrewCantillation)) { + addMenuEntry(m_hebrewCantillationAction, m_filterOptions.hebrewCantillation); + enable = true; + } + + if (isOptionAvailable(CSwordModuleInfo::greekAccents)) { + addMenuEntry(m_greekAccentsAction, m_filterOptions.greekAccents); + enable = true; + } + + if (isOptionAvailable(CSwordModuleInfo::textualVariants)) { + addMenuEntry(m_variantAction, m_filterOptions.textualVariants); + enable = true; + } + + if (isOptionAvailable(CSwordModuleInfo::scriptureReferences)) { + addMenuEntry(m_scriptureReferencesAction, m_filterOptions.scriptureReferences); + enable = true; + } + + if (isOptionAvailable(CSwordModuleInfo::morphSegmentation)) { + addMenuEntry(m_morphSegmentationAction, m_filterOptions.morphSegmentation); + enable = true; + } + } + + // Disable the settings button if no options are available: + setEnabled(enable); + retranslateToolTip(); +} + +/** Adds an entry to m_popup. */ +void BtDisplaySettingsButton::addMenuEntry(QAction *action, bool checked) { + action->setChecked(checked); + m_popup->addAction(action); +} + +bool BtDisplaySettingsButton::isOptionAvailable(const CSwordModuleInfo::FilterTypes option) { + foreach (CSwordModuleInfo *module, m_modules) { + if (module->has(option)) return true; + } + return false; +} diff --git a/src/frontend/displaywindow/btdisplaysettingsbutton.h b/src/frontend/displaywindow/btdisplaysettingsbutton.h new file mode 100644 index 0000000..e947e83 --- /dev/null +++ b/src/frontend/displaywindow/btdisplaysettingsbutton.h @@ -0,0 +1,71 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2008 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#ifndef BTDISPLAYSETTINGSBUTTON_H +#define BTDISPLAYSETTINGSBUTTON_H + +#include <QToolButton> + +#include "backend/managers/cswordbackend.h" + + +class CSwordModuleInfo; +class QMenu; + +/** This class manages the display options of the selected modules. + * @author The BibleTime team + */ +class BtDisplaySettingsButton: public QToolButton { + Q_OBJECT + + public: + BtDisplaySettingsButton(QWidget *parent = 0); + + void setDisplayOptions(const CSwordBackend::DisplayOptions &displaySettings, + bool repopulate = true); + void setFilterOptions(const CSwordBackend::FilterOptions &moduleSettings, + bool repopulate = true); + void setModules(const QList<CSwordModuleInfo*> &modules); + + signals: + void sigFilterOptionsChanged(CSwordBackend::FilterOptions filterOptions); + void sigDisplayOptionsChanged(CSwordBackend::DisplayOptions displayOptions); + void sigChanged(void); + + protected slots: + void slotOptionToggled(QAction *action); + + protected: + void initMenu(); + void retranslateUi(); + void retranslateToolTip(); + void repopulateMenu(); + + bool isOptionAvailable(const CSwordModuleInfo::FilterTypes option); + void addMenuEntry(QAction *action, bool checked); + + private: + CSwordBackend::FilterOptions m_filterOptions; + CSwordBackend::DisplayOptions m_displayOptions; + QList<CSwordModuleInfo*> m_modules; + + QMenu *m_popup; + QAction *m_lineBreakAction; + QAction *m_verseNumbersAction; + QAction *m_headingsAction; + QAction *m_redWordsAction; + QAction *m_hebrewPointsAction; + QAction *m_hebrewCantillationAction; + QAction *m_greekAccentsAction; + QAction *m_variantAction; + QAction *m_scriptureReferencesAction; + QAction *m_morphSegmentationAction; +}; + +#endif diff --git a/src/frontend/displaywindow/btmodulechooserbar.cpp b/src/frontend/displaywindow/btmodulechooserbar.cpp new file mode 100644 index 0000000..e07e739 --- /dev/null +++ b/src/frontend/displaywindow/btmodulechooserbar.cpp @@ -0,0 +1,134 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2008 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#include "frontend/displaywindow/btmodulechooserbar.h" +#include "frontend/displaywindow/btmodulechooserbutton.h" +#include "creadwindow.h" + +#include <QAction> +#include <QDebug> +#include <QList> +#include <QToolBar> + + +BtModuleChooserBar::BtModuleChooserBar(QStringList useModules, CSwordModuleInfo::ModuleType type, CReadWindow *parent) + : QToolBar(parent), + BtWindowModuleChooser(parent, type), + m_idCounter(0) { + + qDebug() << "BtModuleChooserBar::BtModuleChooserBar"; + setAllowedAreas(Qt::TopToolBarArea); + setFloatable(false); + setModules(useModules); + connect(parent, SIGNAL(sigModuleListSet(QStringList)), SLOT(slotBackendModulesChanged())); + connect(parent, SIGNAL(sigModuleListChanged()), SLOT(slotWindowModulesChanged())); +} + +void BtModuleChooserBar::slotBackendModulesChanged() { + backendModulesChanged(); +} + +void BtModuleChooserBar::backendModulesChanged() { + m_modules = m_window->getModuleList(); + + adjustButtonCount(); + + //recreate all menus from scratch + for (int i = 0; i < m_buttonList.count(); i++) { + BtModuleChooserButton* button = m_buttonList.at(i); + QString moduleName = (i >= m_modules.count()) ? QString::null : m_modules.at(i); + qDebug() << "refresh button's menu:" << moduleName << i; + button->recreateMenu(m_modules, moduleName, i); + } +} + +void BtModuleChooserBar::slotWindowModulesChanged() { + windowModulesChanged(); +} + +void BtModuleChooserBar::adjustButtonCount(bool adjustToZero) { + //qDebug() << "BtModuleChooserBar::ajustButtonCount"; + int buttonCountDifference = 0; + if (adjustToZero) { + buttonCountDifference = m_buttonList.count(); + } + else { + buttonCountDifference = m_buttonList.count() - (m_modules.count() + 1); + } + if (m_moduleType == CSwordModuleInfo::GenericBook && !adjustToZero) { + buttonCountDifference = (1 - m_buttonList.count()) * -1; + } + //if there are more buttons than modules, delete buttons + if (buttonCountDifference > 0) { + for (int j = 0; j < buttonCountDifference; j++) { + //qDebug() << "delete first button, " << j; + // it should be safe to delete the button later + BtModuleChooserButton* b = m_buttonList.takeFirst(); + b->setParent(0); + b->deleteLater(); + } + } + // if there are more modules than buttons, add buttons + if (buttonCountDifference < 0) { + for (int i = (buttonCountDifference * (-1)); i > 0; i--) { + addButton(); + } + } +} + +void BtModuleChooserBar::windowModulesChanged() { + //qDebug() << "BtModuleChooserBar::windowModulesChanged"; + m_modules = m_window->getModuleList(); + adjustButtonCount(); + updateButtonMenus(); +} + +BtModuleChooserButton* BtModuleChooserBar::addButton() { + //qDebug() << "BtModuleChooserBar::addButton"; + BtModuleChooserButton* b = new BtModuleChooserButton(this, m_moduleType); + QAction* a = addWidget(b); + m_buttonList.append(b); + + // the button sends signals directly to the window which then signals back when the module + // list has changed + connect(b, SIGNAL(sigModuleAdd(int, QString)), m_window, SLOT(slotAddModule(int, QString))); + connect(b, SIGNAL(sigModuleReplace(int, QString)), m_window, SLOT(slotReplaceModule(int, QString))); + connect(b, SIGNAL(sigModuleRemove(int)), m_window, SLOT(slotRemoveModule(int))); + + a->setVisible(true); + return b; +} + +/** Sets the modules which are chosen in this module chooser bar. */ +void BtModuleChooserBar::setModules( QStringList useModules ) { + qDebug() << "BtModuleChooserBar::setModules"; + m_modules = useModules; + adjustButtonCount(true); + + //if (!useModules.count()) return; + for (int i = 0; i < useModules.count(); i++) { + addButton(); + } + if (!(m_moduleType == CSwordModuleInfo::GenericBook)) { + addButton(); // for ADD button + } + updateButtonMenus(); + qDebug() << "BtModuleChooserBar::setModules end"; +} + +void BtModuleChooserBar::updateButtonMenus() { + //qDebug() << "BtModuleChooserBar::updateMenuItems"; + + for (int i = 0; i < m_buttonList.count(); i++) { + BtModuleChooserButton* button = m_buttonList.at(i); + QString moduleName = (i >= m_modules.count()) ? QString::null : m_modules.at(i); + //qDebug() << "refresh button's menu:" << moduleName << i; + button->updateMenu(m_modules, moduleName, i); + } +} diff --git a/src/frontend/displaywindow/btmodulechooserbar.h b/src/frontend/displaywindow/btmodulechooserbar.h new file mode 100644 index 0000000..7ae903c --- /dev/null +++ b/src/frontend/displaywindow/btmodulechooserbar.h @@ -0,0 +1,62 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2008 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#ifndef BT_MODULECHOOSERBAR +#define BT_MODULECHOOSERBAR + +#include "btwindowmodulechooser.h" +#include "backend/drivers/cswordmoduleinfo.h" +#include <QToolBar> +#include <QStringList> + +class CReadWindow; +class BtModuleChooserButton; + +class BtModuleChooserBar: public QToolBar, public BtWindowModuleChooser { + Q_OBJECT + public: + BtModuleChooserBar(QStringList useModules, CSwordModuleInfo::ModuleType type, CReadWindow* parent); + + public slots: + /** The backend module list was updated, module list and widgets must be updated*/ + void slotBackendModulesChanged(); + void slotWindowModulesChanged(); + + protected: + /** + * The backend module list was updated, module list and widgets must be updated. + * The signal comes from the window, not from the backend. The new list can + * be shorter but not longer than the old list. + */ + virtual void backendModulesChanged(); + /** + * The window module list was changed, i.e. 1 module added, removed or replaced. + */ + virtual void windowModulesChanged(); + + private: + /** Adds an empty button to the toolbar.*/ + BtModuleChooserButton* addButton(); + /** Initialize with module list.*/ + void setModules( QStringList useModules ); + + /** Updates every button's menu without recreating it.*/ + void updateButtonMenus(); + /** + * Removes or adds buttons so that the count matches the limit. + * If given limit is -1 the module count is the limit. + */ + void adjustButtonCount(bool adjustToZero = false); + + private: + int m_idCounter; + QList<BtModuleChooserButton*> m_buttonList; +}; + +#endif diff --git a/src/frontend/displaywindow/btmodulechooserbutton.cpp b/src/frontend/displaywindow/btmodulechooserbutton.cpp new file mode 100644 index 0000000..549123f --- /dev/null +++ b/src/frontend/displaywindow/btmodulechooserbutton.cpp @@ -0,0 +1,166 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2008 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#include "frontend/displaywindow/btmodulechooserbutton.h" + +#include <QDebug> +#include <QHash> +#include <QMenu> +#include <QString> +#include <QToolButton> +#include <QToolTip> +#include "backend/config/cbtconfig.h" +#include "backend/managers/cswordbackend.h" +#include "frontend/displaywindow/btmodulechooserbar.h" +#include "util/cresmgr.h" +#include "util/directory.h" +#include "util/cpointers.h" + + +BtModuleChooserButton::BtModuleChooserButton(BtModuleChooserBar *parent, CSwordModuleInfo::ModuleType mtype) + : QToolButton(parent), + m_moduleType(mtype), + m_popup(0) { + //qDebug()<<"BtModuleChooserButton::BtModuleChooserButton"; + setPopupMode(QToolButton::InstantPopup); +} + +BtModuleChooserButton::~BtModuleChooserButton() {} + +void BtModuleChooserButton::recreateMenu(QStringList newModulesToUse, QString thisModule, int newIndex) { + populateMenu(); + updateMenu(newModulesToUse, thisModule, newIndex); +} + +const QString BtModuleChooserButton::iconName() { + qDebug() << "BtModuleChooserButton::iconName, has module:" << m_hasModule; + switch (m_moduleType) { + case CSwordModuleInfo::Bible: + return (m_hasModule) ? CResMgr::modules::bible::icon_unlocked : CResMgr::modules::bible::icon_add; + case CSwordModuleInfo::Commentary: + return (m_hasModule) ? CResMgr::modules::commentary::icon_unlocked : CResMgr::modules::commentary::icon_add; + case CSwordModuleInfo::Lexicon: + return m_hasModule ? CResMgr::modules::lexicon::icon_unlocked : CResMgr::modules::lexicon::icon_add; + case CSwordModuleInfo::GenericBook: + return m_hasModule ? CResMgr::modules::book::icon_unlocked : CResMgr::modules::book::icon_add; + default: //return as default the bible icon + return CResMgr::modules::bible::icon_unlocked; + } +} + +void BtModuleChooserButton::updateMenu(QStringList newModulesToUse, QString thisModule, int newIndex) { + //qDebug() << "BtModuleChooserButton::updateMenu" << newModulesToUse << thisModule << newIndex << this; + // create the menu if it doesn't exist + if (!m_popup) populateMenu(); + + m_id = newIndex; + m_module = thisModule; + m_hasModule = thisModule.isEmpty() ? false : true; + namespace DU = util::directory; + + //All items are iterated and the state is changed properly + QListIterator<QMenu*> it(m_submenus); + while (it.hasNext()) { + QMenu* popup = it.next(); + foreach (QAction* a, popup->actions()) { + a->setChecked( (a->text() == thisModule) ? true : false ); + a->setDisabled( newModulesToUse.contains(a->text()) ? true : false ); + } + } + m_noneAction->setChecked(m_hasModule ? false : true); + setIcon(DU::getIcon(iconName())); + + if (m_hasModule) { + setToolTip( QString(tr("Select a work [%1]")).arg(m_module) ); + } + else { + setToolTip( tr("Select an additional work") ); + } + m_noneAction->setDisabled((newModulesToUse.count() == 1) ? true : false); + //qDebug()<<"BtModuleChooserButton::modulesChanged end"; +} + +/** Is called after a module was selected in the popup */ +void BtModuleChooserButton::moduleChosen( QAction* action ) { + //qDebug() << "BtModuleChooserButton::moduleChosen"; + + if (action->text() == tr("NONE")) { // note: this is for m_popup, the toplevel! + if (m_hasModule) { + qDebug() << "remove module" << m_id; + emit sigModuleRemove(m_id); + return; + } + else { + // nothing else is done but the item must be set to checked + // lest it change to unchecked + action->setChecked(true); + } + } + else { + if (!m_hasModule) { + emit sigModuleAdd(m_id + 1, action->text()); + return; + } + emit sigModuleReplace(m_id, action->text()); + } +} + + +void BtModuleChooserButton::populateMenu() { + //qDebug()<<"BtModuleChooserButton::populateMenu"; + qDeleteAll(m_submenus); + m_submenus.clear(); + delete m_popup; + m_popup = new QMenu(this); + + m_noneAction = m_popup->addAction(tr("NONE")); + m_noneAction->setCheckable(true); + if (m_module.isEmpty()) m_noneAction->setChecked(true); + + m_popup->addSeparator(); + connect(m_popup, SIGNAL(triggered(QAction*)), this, SLOT(moduleChosen(QAction*))); + setMenu(m_popup); + + + // ******* Add languages and modules ******** + + // Filters: add only non-hidden and right type + BTModuleTreeItem::HiddenOff hiddenFilter; + TypeFilter typeFilter(m_moduleType); + QList<BTModuleTreeItem::Filter*> filters; + if (!CBTConfig::get(CBTConfig::bookshelfShowHidden)) { + filters.append(&hiddenFilter); + } + filters.append(&typeFilter); + BTModuleTreeItem root(filters, BTModuleTreeItem::LangMod); + // add all items recursively + addItemToMenu(&root, m_popup); +} + +void BtModuleChooserButton::addItemToMenu(BTModuleTreeItem* item, QMenu* menu) { + qDebug() << "BtModuleChooserButton::addItemToMenu"; + foreach (BTModuleTreeItem* i, item->children()) { + + if (i->type() == BTModuleTreeItem::Language) { + // argument menu was m_popup, create and add a new lang menu to it + QMenu* langMenu = new QMenu(i->text(), this); + menu->addMenu(langMenu); + m_submenus.append(langMenu); + // add the module items to the lang menu + addItemToMenu(i, langMenu); + } + else { + // item must be module, create and add it to the lang menu + QString name(i->text()); + QAction* modItem = new QAction(name, menu); + modItem->setCheckable(true); + menu->addAction(modItem); + } + } +} diff --git a/src/frontend/displaywindow/btmodulechooserbutton.h b/src/frontend/displaywindow/btmodulechooserbutton.h new file mode 100644 index 0000000..9835eb0 --- /dev/null +++ b/src/frontend/displaywindow/btmodulechooserbutton.h @@ -0,0 +1,104 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2008 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#ifndef BT_MODULECHOOSERBUTTON +#define BT_MODULECHOOSERBUTTON + +#include <QToolButton> +#include "backend/btmoduletreeitem.h" +#include "backend/drivers/cswordmoduleinfo.h" + +class BtModuleChooserBar; +class QMenu; +class QAction; + +/** +* A toolbar button for choosing a module in a window. When user selects a module, +* button sends a signal. This button needs to get a signal back after a window +* module list has been changed. Only then the button will be updated. +* See BtModuleChooserBar. +*/ +class BtModuleChooserButton : public QToolButton { + Q_OBJECT + public: + + /** Filter out modules of wrong type from buttons module list. + * See populateMenu() and BTModuleTreeItem. */ + struct TypeFilter : public BTModuleTreeItem::Filter { + TypeFilter(CSwordModuleInfo::ModuleType t) { + m_mType = t; + } + bool filter(CSwordModuleInfo* mi) { + return ((mi->type() == m_mType) && !mi->isLocked()); + } + CSwordModuleInfo::ModuleType m_mType; + }; + + /** + * A new empty button. updateMenu() is needed to update the icon, menu items etc. + */ + BtModuleChooserButton(BtModuleChooserBar *parent, CSwordModuleInfo::ModuleType mtype); + /** Does nothing. All resources are freed and children deleted automatically.*/ + ~BtModuleChooserButton(); + + // /** Returns the module name this button represents. Not needed?*/ + //QString module(); + // /** Returns the index used for this button.*/ + //int getIndex() const; + // /** Updates existing menu items, setting their states.*/ + //void updateMenuItems(); + + public: + /** + * Called after the window module list has changed. Updates the existing menu items + * but doesn't add or remove them if the menu exists. + * If the menu doesn't exist, creates it first and then updates it. + * Updates also the icon. + */ + void updateMenu(QStringList newModulesToUse, QString thisModule, int newIndex); + + /** Creates the menu from scratch and updates the items using updateMenu().*/ + void recreateMenu(QStringList newModulesToUse, QString thisModule, int newIndex); + + signals: + /** User selected a module from menu to replace another module*/ + void sigModuleReplace ( int index, QString newModule ); + /** User selected a module from menu to add */ + void sigModuleAdd ( int index, QString module ); + /** User selected a module from menu to be removed */ + void sigModuleRemove ( int index ); + + private slots: + /** Handle the action signal from the menu.*/ + void moduleChosen(QAction* action ); + + private: + /** Returns the icon used for the current status.*/ + const QString iconName(); + + /** + * Populates the menu with language submenus and module items without setting + * their states. + */ + void populateMenu(); + /** Adds items to the menu recursively. */ + void addItemToMenu(BTModuleTreeItem* item, QMenu* menu); + + private: + bool m_hasModule; + int m_id; + QAction* m_noneAction; + CSwordModuleInfo::ModuleType m_moduleType; + QString m_module; + + QMenu* m_popup; + QList<QMenu*> m_submenus; +}; + +#endif diff --git a/src/frontend/displaywindow/bttextwindowheader.cpp b/src/frontend/displaywindow/bttextwindowheader.cpp new file mode 100644 index 0000000..cd5392f --- /dev/null +++ b/src/frontend/displaywindow/bttextwindowheader.cpp @@ -0,0 +1,132 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2008 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#include "bttextwindowheader.h" + +#include "bttextwindowheaderwidget.h" +#include "clexiconreadwindow.h" + +#include <QStringList> +#include <QWidget> +#include <QHBoxLayout> +#include <QLabel> +#include <QSizePolicy> +#include <QToolButton> +#include <QFrame> +#include <QAction> +#include <QDebug> + +BtTextWindowHeader::BtTextWindowHeader ( CDisplayWindow* window, CSwordModuleInfo::ModuleType modtype, QStringList modules ) + : QWidget ( window ), + BtWindowModuleChooser(window, modtype) { + QHBoxLayout* layout = new QHBoxLayout ( this ); + layout->setContentsMargins(0, 0, 0, 0); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + setLayoutDirection(Qt::LeftToRight); + setModules(modules); + connect(window, SIGNAL(sigModuleListSet(QStringList)), SLOT(slotBackendModulesChanged())); + connect(window, SIGNAL(sigModuleListChanged()), SLOT(slotWindowModulesChanged())); +} + +BtTextWindowHeader::~BtTextWindowHeader() {} + +void BtTextWindowHeader::slotBackendModulesChanged() { + backendModulesChanged(); +} + +void BtTextWindowHeader::backendModulesChanged() { + m_modules = m_window->getModuleList(); + + adjustWidgetCount(); + + //recreate all widgets from scratch + for (int i = 0; i < m_widgetList.count(); i++) { + BtTextWindowHeaderWidget* widgt = m_widgetList.at(i); + QString moduleName = m_modules.at(i); + qDebug() << "refresh button's menu:" << moduleName << i; + widgt->recreateWidget(m_modules, moduleName, i); + } +} + +void BtTextWindowHeader::slotWindowModulesChanged() { + windowModulesChanged(); +} + +void BtTextWindowHeader::windowModulesChanged() { + m_modules = m_window->getModuleList(); + adjustWidgetCount(); + updateWidgets(); +} + +void BtTextWindowHeader::adjustWidgetCount(bool adjustToZero) { + //qDebug() << "BtModuleChooserBar::ajustButtonCount"; + int widgetCountDifference = 0; + if (adjustToZero) { + widgetCountDifference = m_widgetList.count(); + } + else { + widgetCountDifference = m_widgetList.count() - (m_modules.count()); + } + if (m_moduleType == CSwordModuleInfo::GenericBook && !adjustToZero) { + widgetCountDifference = (1 - m_widgetList.count()) * -1; + } + //if there are more buttons than modules, delete buttons + if (widgetCountDifference > 0) { + while (widgetCountDifference) { + // it should be safe to delete the button later + BtTextWindowHeaderWidget* w = m_widgetList.takeFirst(); + w->setParent(0); + w->deleteLater(); + widgetCountDifference--; + } + } + // if there are more modules than buttons, add buttons + if (widgetCountDifference < 0) { + while (widgetCountDifference) { + addWidget(); + widgetCountDifference++; + } + } +} + +BtTextWindowHeaderWidget* BtTextWindowHeader::addWidget() { + BtTextWindowHeaderWidget* w = new BtTextWindowHeaderWidget(this, m_moduleType); + layout()->addWidget(w); + m_widgetList.append(w); + + // the button sends signals directly to the window which then signals back when the module + // list has changed + connect(w, SIGNAL(sigModuleAdd(int, QString)), m_window, SLOT(slotAddModule(int, QString))); + connect(w, SIGNAL(sigModuleReplace(int, QString)), m_window, SLOT(slotReplaceModule(int, QString))); + connect(w, SIGNAL(sigModuleRemove(int)), m_window, SLOT(slotRemoveModule(int))); + + return w; +} + +void BtTextWindowHeader::setModules( QStringList useModules ) { + qDebug() << "BtModuleChooserBar::setModules"; + m_modules = useModules; + adjustWidgetCount(true); + + //if (!useModules.count()) return; + for (int i = 0; i < useModules.count(); i++) { + addWidget(); + } + updateWidgets(); + //qDebug() << "BtModuleChooserBar::setModules end"; +} + +void BtTextWindowHeader::updateWidgets() { + for (int i = 0; i < m_widgetList.count(); i++) { + BtTextWindowHeaderWidget* w = m_widgetList.at(i); + //QString moduleName = m_modules.at(i); + //qDebug() << "refresh button's menu:" << moduleName << i; + w->updateWidget(m_modules, m_modules.at(i), i); + } +} diff --git a/src/frontend/displaywindow/bttextwindowheader.h b/src/frontend/displaywindow/bttextwindowheader.h new file mode 100644 index 0000000..a3e6b6b --- /dev/null +++ b/src/frontend/displaywindow/bttextwindowheader.h @@ -0,0 +1,67 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2008 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#ifndef BT_TEXTWINDOWHEADER +#define BT_TEXTWINDOWHEADER + +#include "btwindowmodulechooser.h" +#include <QStringList> +#include <QWidget> + +class QAction; +class QToolButton; +class CDisplayWindow; +class BtTextWindowHeaderWidget; + +class BtTextWindowHeader: public QWidget, public BtWindowModuleChooser { + Q_OBJECT + public: + BtTextWindowHeader(CDisplayWindow* window, CSwordModuleInfo::ModuleType modtype, QStringList modules); + virtual ~BtTextWindowHeader(); + + public slots: + void slotBackendModulesChanged(); + void slotWindowModulesChanged(); + + + protected: + /** The backend module list was updated, module list and widgets must be updated from scratch.*/ + void backendModulesChanged(); + /** The window module list was updated, module list and widgets must be updated.*/ + void windowModulesChanged(); + + signals: + /** User selected a module from menu to replace another module*/ + void sigModuleReplace ( int index, QString newModule ); + /** User selected a module from menu to add */ + void sigModuleAdd ( int index, QString module ); + /** User selected a module from menu to be removed */ + void sigModuleRemove ( int index ); + + private: + /** Called when backend has changed and menus must be created from scratch.*/ + void initMenus(); + /** Updates all widgets without recreating them. */ + void updateWidgets(); + /** + * Removes or adds widgets so that the count matches the limit. + * The module count is the limit unless adjustToZero is true + * when limit is 0 and list is emptied. + */ + void adjustWidgetCount(bool adjustToZero = false); + /** Adds an empty widget to the header.*/ + BtTextWindowHeaderWidget* addWidget(); + /** Sets the initial modules.*/ + void setModules( QStringList useModules ); + + private: + QList<BtTextWindowHeaderWidget*> m_widgetList; +}; + +#endif diff --git a/src/frontend/displaywindow/bttextwindowheaderwidget.cpp b/src/frontend/displaywindow/bttextwindowheaderwidget.cpp new file mode 100644 index 0000000..3858efb --- /dev/null +++ b/src/frontend/displaywindow/bttextwindowheaderwidget.cpp @@ -0,0 +1,197 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2008 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#include "frontend/displaywindow/bttextwindowheaderwidget.h" + +#include <QDebug> +//#include <QHash> +#include <QMenu> +#include <QString> +#include <QToolButton> +#include <QToolTip> +#include <QHBoxLayout> +#include <QSizePolicy> +#include <QLabel> + +#include "backend/config/cbtconfig.h" +#include "backend/managers/cswordbackend.h" +#include "frontend/displaywindow/bttextwindowheader.h" +#include "util/cresmgr.h" +#include "util/directory.h" +#include "util/cpointers.h" + +const char* ActionType = "ActionType"; + +BtTextWindowHeaderWidget::BtTextWindowHeaderWidget(BtTextWindowHeader *parent, CSwordModuleInfo::ModuleType mtype) + : QWidget(parent), + m_moduleType(mtype), + m_popup(0) { + QHBoxLayout* layout = new QHBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + + m_label = new QLabel("", this); + QSizePolicy sizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + m_label->setSizePolicy(sizePolicy); + m_label->setStyleSheet("QLabel{font-weight:bold}"); + layout->addWidget(m_label, 0, Qt::AlignRight); + + m_button = new QToolButton( this ); + m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_button->setPopupMode( QToolButton::InstantPopup ); + m_button->setArrowType(Qt::NoArrow); + m_button->setStyleSheet("QToolButton{margin:0px;}QToolButton::menu-indicator{subcontrol-position: center center;}"); + m_button->setToolTip( tr("Add/remove/replace") ); + + layout->addWidget(m_button, 0, Qt::AlignLeft); + + m_separator = new QFrame(this); + m_separator->setFrameShape(QFrame::VLine); + layout->addWidget(m_separator); +} + +BtTextWindowHeaderWidget::~BtTextWindowHeaderWidget() {} + +void BtTextWindowHeaderWidget::recreateWidget(QStringList newModulesToUse, QString thisModule, int newIndex) { + populateMenu(); + updateWidget(newModulesToUse, thisModule, newIndex); +} + +// don't remove yet, maybe we'll add icons to buttons... +// const QString BtTextWindowHeaderWidget::iconName() { +// qDebug() << "BtTextWindowHeaderWidget::iconName, has module:" << m_hasModule; +// switch (m_moduleType) { +// case CSwordModuleInfo::Bible: +// return (m_hasModule) ? CResMgr::modules::bible::icon_unlocked : CResMgr::modules::bible::icon_add; +// case CSwordModuleInfo::Commentary: +// return (m_hasModule) ? CResMgr::modules::commentary::icon_unlocked : CResMgr::modules::commentary::icon_add; +// case CSwordModuleInfo::Lexicon: +// return m_hasModule ? CResMgr::modules::lexicon::icon_unlocked : CResMgr::modules::lexicon::icon_add; +// case CSwordModuleInfo::GenericBook: +// return m_hasModule ? CResMgr::modules::book::icon_unlocked : CResMgr::modules::book::icon_add; +// default: //return as default the bible icon +// return CResMgr::modules::bible::icon_unlocked; +// } +// } + +void BtTextWindowHeaderWidget::updateWidget(QStringList newModulesToUse, QString thisModule, int newIndex) { + //qDebug() << "BtTextWindowHeaderWidget::updateMenu" << newModulesToUse << thisModule << newIndex << this; + m_label->setText(thisModule); + // create the menu if it doesn't exist + if (!m_popup) populateMenu(); + + m_id = newIndex; + m_module = thisModule; + namespace DU = util::directory; + + //All items are iterated and the state is changed properly + QListIterator<QMenu*> it(m_submenus); + while (it.hasNext()) { + QMenu* popup = it.next(); + foreach (QAction* a, popup->actions()) { + a->setChecked( (a->text() == thisModule) ? true : false ); + a->setDisabled( newModulesToUse.contains(a->text()) ? true : false ); + } + } + + if (m_id == newModulesToUse.count() - 1) { + // this is the rightmost module, hide the separator + m_separator->hide(); + } + else { + m_separator->show(); + } + m_removeAction->setDisabled((newModulesToUse.count() == 1) ? true : false); +} + +/** Is called after a module was selected in the popup */ +void BtTextWindowHeaderWidget::moduleChosen( QAction* action ) { + //qDebug() << "BtTextWindowHeaderWidget::moduleChosen"; + + if (action->property(ActionType).toInt() == RemoveAction) { // note: this is for m_popup, the toplevel! + emit sigModuleRemove(m_id); + return; + } + if (action->property(ActionType).toInt() == AddAction) { + emit sigModuleAdd(m_id + 1, action->text()); + return; + } + if (action->property(ActionType).toInt() == ReplaceAction) { + emit sigModuleReplace(m_id, action->text()); + } +} + + +void BtTextWindowHeaderWidget::populateMenu() { + //qDebug()<<"BtTextWindowHeaderWidget::populateMenu"; + delete m_popup; + m_popup = new QMenu(m_button); + + connect(m_popup, SIGNAL(triggered(QAction*)), this, SLOT(moduleChosen(QAction*))); + m_button->setMenu(m_popup); + + m_removeAction = new QAction(tr("Remove"), m_popup); + m_removeAction->setProperty(ActionType, RemoveAction); + m_removeAction->setIcon(util::directory::getIcon(CResMgr::displaywindows::general::removemoduleicon)); + m_popup->addAction(m_removeAction); + + // Add Replace and Add menus, both have all modules in them + QMenu* replaceItem = new QMenu(tr("Replace"), m_popup); + replaceItem->setIcon(util::directory::getIcon(CResMgr::displaywindows::general::replacemoduleicon)); + replaceItem->setProperty(ActionType, ReplaceAction); + m_popup->addMenu(replaceItem); + + QMenu* addItem = new QMenu(tr("Add"), m_popup); + addItem->setProperty(ActionType, AddAction); + addItem->setIcon(util::directory::getIcon(CResMgr::displaywindows::general::addmoduleicon)); + m_popup->addMenu(addItem); + + QList<QMenu*> toplevelMenus; + toplevelMenus.append(replaceItem); + toplevelMenus.append(addItem); + + foreach(QMenu* menu, toplevelMenus) { + // ******* Add languages and modules ******** + //m_popup->addSeparator(); + + // Filters: add only non-hidden, non-locked and correct type + BTModuleTreeItem::HiddenOff hiddenFilter; + TypeFilter typeFilter(m_moduleType); + QList<BTModuleTreeItem::Filter*> filters; + if (!CBTConfig::get(CBTConfig::bookshelfShowHidden)) { + filters.append(&hiddenFilter); + } + filters.append(&typeFilter); + BTModuleTreeItem root(filters, BTModuleTreeItem::LangMod); + // add all items recursively + addItemToMenu(&root, menu, (TypeOfAction)menu->property(ActionType).toInt()); + } +} + +void BtTextWindowHeaderWidget::addItemToMenu(BTModuleTreeItem* item, QMenu* menu, TypeOfAction actionType) { + qDebug() << "BtTextWindowHeaderWidget::addItemToMenu"; + foreach (BTModuleTreeItem* i, item->children()) { + + if (i->type() == BTModuleTreeItem::Language) { + // argument menu was m_popup, create and add a new lang menu to it + QMenu* langMenu = new QMenu(i->text(), this); + menu->addMenu(langMenu); + m_submenus.append(langMenu); + // add the module items to the lang menu + addItemToMenu(i, langMenu, actionType); + } + else { + // item must be module, create and add it to the lang menu + QString name(i->text()); + QAction* modItem = new QAction(name, menu); + modItem->setCheckable(true); + modItem->setProperty(ActionType, actionType); + menu->addAction(modItem); + } + } +} diff --git a/src/frontend/displaywindow/bttextwindowheaderwidget.h b/src/frontend/displaywindow/bttextwindowheaderwidget.h new file mode 100644 index 0000000..2b5379e --- /dev/null +++ b/src/frontend/displaywindow/bttextwindowheaderwidget.h @@ -0,0 +1,106 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2008 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#ifndef BT_MODULECHOOSERHEADERWIDGET +#define BT_MODULECHOOSERHEADERWIDGET + +#include <QString> +#include <QWidget> +#include <QList> + +#include "backend/btmoduletreeitem.h" +#include "backend/drivers/cswordmoduleinfo.h" + +class BtTextWindowHeader; +class QMenu; +class QAction; +class QLabel; +class QToolButton; +class QFrame; + +/** +* A widget for choosing a module in a window. Consists of a label and a button. +* When user selects a module, +* button sends a signal. This widget needs to get a message back after a window +* module list has been changed. Only then it will be updated. +* See BtTextWindowHeader. +*/ +class BtTextWindowHeaderWidget : public QWidget { + Q_OBJECT + + public: + /** For internal use to mark the menu items */ + enum TypeOfAction {RemoveAction, AddAction, ReplaceAction}; + + /** Filter out modules of wrong type from buttons module list. + * See populateMenu() and BTModuleTreeItem. */ + struct TypeFilter : public BTModuleTreeItem::Filter { + TypeFilter(CSwordModuleInfo::ModuleType t) { + m_mType = t; + } + bool filter(CSwordModuleInfo* mi) { + return ((mi->type() == m_mType) && !mi->isLocked()); + } + CSwordModuleInfo::ModuleType m_mType; + }; + + /** + * A new empty widget. updateMenu() is needed to update the label, menu items etc. + */ + BtTextWindowHeaderWidget(BtTextWindowHeader *parent, CSwordModuleInfo::ModuleType mtype); + /** Does nothing. All resources are freed and children deleted automatically.*/ + ~BtTextWindowHeaderWidget(); + + public: + /** + * Called after the window module list has changed. Updates the module name and + * the existing menu items but doesn't add or remove them if the menu exists. + * If the menu doesn't exist, creates it first and then updates it. + */ + void updateWidget(QStringList newModulesToUse, QString thisModule, int newIndex); + + /** Creates the menu from scratch and updates the items using updateMenu().*/ + void recreateWidget(QStringList newModulesToUse, QString thisModule, int newIndex); + + signals: + /** User selected a module from menu to replace an existing module.*/ + void sigModuleReplace ( int index, QString newModule ); + /** User selected a module from menu to add. */ + void sigModuleAdd ( int index, QString module ); + /** User selected a module from menu to be removed. */ + void sigModuleRemove ( int index ); + + private slots: + /** Handle the action signal from the menu.*/ + void moduleChosen(QAction* action ); + + private: + + /** + * Populates the menu with language submenus and module items without setting + * their states. + */ + void populateMenu(); + /** Adds items to the menu recursively. */ + void addItemToMenu(BTModuleTreeItem* item, QMenu* menu, TypeOfAction actionType); + + private: + + int m_id; + QAction* m_removeAction; + CSwordModuleInfo::ModuleType m_moduleType; + QString m_module; + QLabel* m_label; + QToolButton* m_button; + QFrame* m_separator; + QMenu* m_popup; + QList<QMenu*> m_submenus; +}; + +#endif diff --git a/src/frontend/displaywindow/btwindowmodulechooser.h b/src/frontend/displaywindow/btwindowmodulechooser.h new file mode 100644 index 0000000..c30c284 --- /dev/null +++ b/src/frontend/displaywindow/btwindowmodulechooser.h @@ -0,0 +1,61 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2008 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#ifndef BT_WINDOWMODULECHOOSER +#define BT_WINDOWMODULECHOOSER + +#include "backend/drivers/cswordmoduleinfo.h" +#include <QStringList> + +class CDisplayWindow; + +/** +* This is an abstract base class for buttonbar and text window header +* which work as module choosers in a text window. +* +* Signals or slots can't be inherited from this class for Qt's +* technical reasons. Add corresponding slots for the protected +* modulesChanged methods and delegate the message. +* +* Add these signals to the subclass or to some part of it: +* User selected a module from menu to replace another module: +* void sigModuleReplace ( int index, QString newModule ); +* User selected a module from menu to add: +* void sigModuleAdd ( int index, QString module ); +* User selected a module from menu to be removed: +* void sigModuleRemove ( int index ); +* +* Connect slots and signals to the window's corresponding signals and slots. +*/ +class BtWindowModuleChooser { + public: + BtWindowModuleChooser ( CDisplayWindow* parentWindow, CSwordModuleInfo::ModuleType moduleType ) + : m_window ( parentWindow ), m_moduleType ( moduleType ) {} + + virtual ~BtWindowModuleChooser() {} + + protected: + /** + * The backend module list was updated, module list and widgets must be updated. + * This expects that the window module list has already been updated, so + * the corresponding slot should be connected to the window, not to the backend. + */ + virtual void backendModulesChanged() = 0; + /** Modules have been added, replaced or removed in the window without backend changing.*/ + virtual void windowModulesChanged() = 0; + + + protected: + CDisplayWindow* m_window; + CSwordModuleInfo::ModuleType m_moduleType; + /** The cache of the window module list. Kept for convenience.*/ + QStringList m_modules; +}; + +#endif diff --git a/src/frontend/displaywindow/cbiblereadwindow.cpp b/src/frontend/displaywindow/cbiblereadwindow.cpp index 7b346f7..70dbd35 100644 --- a/src/frontend/displaywindow/cbiblereadwindow.cpp +++ b/src/frontend/displaywindow/cbiblereadwindow.cpp @@ -9,7 +9,6 @@ #include "frontend/displaywindow/cbiblereadwindow.h" -#include <cmath> #include <QAction> #include <QApplication> #include <QEvent> @@ -27,7 +26,7 @@ #include "frontend/display/creaddisplay.h" #include "frontend/displaywindow/btactioncollection.h" #include "frontend/displaywindow/ccommentaryreadwindow.h" -#include "frontend/displaywindow/cbuttons.h" +#include "frontend/displaywindow/btdisplaysettingsbutton.h" #include "frontend/keychooser/ckeychooser.h" #include "frontend/profile/cprofilewindow.h" #include "util/directory.h" @@ -45,34 +44,59 @@ CBibleReadWindow::CBibleReadWindow(QList<CSwordModuleInfo*> moduleList, CMDIArea CBibleReadWindow::~CBibleReadWindow() { } -void CBibleReadWindow::applyProfileSettings( CProfileWindow* const settings ) { +void CBibleReadWindow::applyProfileSettings(CProfileWindow* const settings) { + /** + \todo Make \ref CProfileWindow properly handle these things so we wouldn't have to mess + around with bits. + */ CLexiconReadWindow::applyProfileSettings(settings); - const int count = displaySettingsButton()->menuItemCount(); int result = settings->windowSettings(); - for (int i = count - 1; i >= 1; i--) { - if (result - (int)pow((double)2, i - 1) >= 0) { //2^i was added before, so item with index i is set - result -= (int)pow((double)2, i - 1); - displaySettingsButton()->setItemStatus(i, true); - } - else { - displaySettingsButton()->setItemStatus(i, false); - } - } - displaySettingsButton()->setChanged(); + + filterOptions().footnotes = (result & 0x0001) != 0; + filterOptions().strongNumbers = (result & 0x0002) != 0; + filterOptions().headings = (result & 0x0004) != 0; + filterOptions().morphTags = (result & 0x0008) != 0; + filterOptions().lemmas = (result & 0x0010) != 0; + filterOptions().hebrewPoints = (result & 0x0020) != 0; + filterOptions().hebrewCantillation = (result & 0x0040) != 0; + filterOptions().greekAccents = (result & 0x0080) != 0; + filterOptions().textualVariants = (result & 0x0100) != 0; + filterOptions().redLetterWords = (result & 0x0200) != 0; + filterOptions().scriptureReferences = (result & 0x0400) != 0; + filterOptions().morphSegmentation = (result & 0x0800) != 0; + displayOptions().lineBreaks = (result & 0x1000) != 0; + displayOptions().verseNumbers = (result & 0x2000) != 0; + + displaySettingsButton()->setFilterOptions(filterOptions(), false); + displaySettingsButton()->setDisplayOptions(displayOptions()); } -void CBibleReadWindow::storeProfileSettings( CProfileWindow* const settings ) { - CLexiconReadWindow::storeProfileSettings(settings); +void CBibleReadWindow::storeProfileSettings( CProfileWindow * const settings) { + /** + \todo Make \ref CProfileWindow properly handle these things so we wouldn't have to mess + around with bits. + */ + + int result = 0x0000; + if (filterOptions().footnotes) result |= 0x0001; + if (filterOptions().strongNumbers) result |= 0x0002; + if (filterOptions().headings) result |= 0x0004; + if (filterOptions().morphTags) result |= 0x0008; + if (filterOptions().lemmas) result |= 0x0010; + if (filterOptions().hebrewPoints) result |= 0x0020; + if (filterOptions().hebrewCantillation) result |= 0x0040; + if (filterOptions().greekAccents) result |= 0x0080; + if (filterOptions().textualVariants) result |= 0x0100; + if (filterOptions().redLetterWords) result |= 0x0200; + if (filterOptions().scriptureReferences) result |= 0x0400; + if (filterOptions().morphSegmentation) result |= 0x0800; + if (displayOptions().lineBreaks) result |= 0x1000; + if (displayOptions().verseNumbers) result |= 0x2000; - const int count = displaySettingsButton()->menuItemCount(); - int result = 0; - //now check every item - for (int i = 1; i < count; i++) { //first item is a title - if (displaySettingsButton()->itemStatus(i)) //item is checked - result += (int)pow((double)2, i - 1);//add 2^i (the i. digit in binary) - } settings->setWindowSettings(result); + + CLexiconReadWindow::storeProfileSettings(settings); } @@ -135,7 +159,7 @@ void CBibleReadWindow::insertKeyboardActions( BtActionCollection* const a ) { qaction = new QAction(tr("Reference with text"), a); a->addAction("printReferenceWithText", qaction); - qaction = new QAction(tr("Reference with text"), a); + qaction = new QAction(tr("Reference with text"), a); a->addAction("saveReferenceWithText", qaction); } diff --git a/src/frontend/displaywindow/cbookreadwindow.cpp b/src/frontend/displaywindow/cbookreadwindow.cpp index d852eb3..062d42d 100644 --- a/src/frontend/displaywindow/cbookreadwindow.cpp +++ b/src/frontend/displaywindow/cbookreadwindow.cpp @@ -18,8 +18,8 @@ #include "frontend/display/cdisplay.h" #include "frontend/displaywindow/bttoolbarpopupaction.h" #include "frontend/displaywindow/btactioncollection.h" -#include "frontend/displaywindow/cmodulechooserbar.h" -#include "frontend/displaywindow/cbuttons.h" +#include "frontend/displaywindow/btmodulechooserbar.h" +#include "frontend/displaywindow/btdisplaysettingsbutton.h" #include "frontend/keychooser/cbooktreechooser.h" #include "frontend/profile/cprofilewindow.h" #include "util/cresmgr.h" @@ -103,14 +103,15 @@ void CBookReadWindow::initView() { setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) ); - setModuleChooserBar( new CModuleChooserBar(modules(), modules().first()->type(), this) ); - moduleChooserBar()->setButtonLimit(1); + setModuleChooserBar( new BtModuleChooserBar(getModuleList(), modules().first()->type(), this) ); addToolBar(moduleChooserBar()); setButtonsToolBar( new QToolBar(this) ); buttonsToolBar()->setAllowedAreas(Qt::TopToolBarArea); buttonsToolBar()->setFloatable(false); - setDisplaySettingsButton( new CDisplaySettingsButton( &displayOptions(), &filterOptions(), modules(), buttonsToolBar()) ); + + setDisplaySettingsButton(new BtDisplaySettingsButton(buttonsToolBar())); + addToolBar(buttonsToolBar()); m_treeChooser->hide(); diff --git a/src/frontend/displaywindow/cbuttons.cpp b/src/frontend/displaywindow/cbuttons.cpp deleted file mode 100644 index 46c262a..0000000 --- a/src/frontend/displaywindow/cbuttons.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/********* -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2008 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#include "frontend/displaywindow/cbuttons.h" - -#include <QHash> -#include <QMenu> -#include <QString> -#include <QToolTip> -#include <QToolButton> -#include "util/directory.h" -#include "util/cpointers.h" -#include "util/cresmgr.h" - - -CDisplaySettingsButton::CDisplaySettingsButton(CSwordBackend::DisplayOptions *displaySettings, CSwordBackend::FilterOptions *moduleSettings, const QList<CSwordModuleInfo*>& useModules, QWidget *parent ) - : QToolButton(parent) { - namespace DU = util::directory; - - // qWarning("CDisplaySettingsButton::CDisplaySettingsButton"); - QToolButton::setIcon(DU::getIcon(CResMgr::displaywindows::displaySettings::icon)); - - m_displaySettings = displaySettings; - m_moduleSettings = moduleSettings; - m_modules = useModules; - - m_popup = new QMenu(this); - setMenu(m_popup); - setPopupMode(QToolButton::InstantPopup); - setToolTip(tr("Display options")); - - connect(m_popup, SIGNAL(triggered(QAction*)), this, SLOT(optionToggled(QAction*))); - populateMenu(); -} - -void CDisplaySettingsButton::reset(const QList<CSwordModuleInfo*>& useModules) { - m_modules = useModules; - populateMenu(); - //disable the settings button if no options are available - if (!populateMenu()) { - setEnabled(false); - setToolTip(tr("Display settings: No options available")); - } - else { - setEnabled(true); - setToolTip(tr("Display settings")); - } -} - - -void CDisplaySettingsButton::optionToggled(QAction* /*action*/) { - //Take each Action and set the corresponding setting. - //Using QAction (QObject) property and OptionType enum is a dirty way to do this. - //See populateMenu(). - foreach (QAction* act, m_popup->actions()) { - int optionType = act->property("OptionType").toInt(); - bool checked = act->isChecked(); - switch (optionType) { - case Linebreak: - m_displaySettings->lineBreaks = checked; - break; - case Versenum: - m_displaySettings->verseNumbers = checked; - break; - case Variant: - m_moduleSettings->textualVariants = checked; - break; - case Vowel: - m_moduleSettings->hebrewPoints = checked; - break; - case Accents: - m_moduleSettings->greekAccents = checked; - break; - case Cantillation: - m_moduleSettings->hebrewCantillation = checked; - break; - case Headings: - m_moduleSettings->headings = checked; - break; - case Morphseg: - m_moduleSettings->morphSegmentation = checked; - break; - case Xref: - m_moduleSettings->scriptureReferences = checked; - break; - case WordsofJ: - m_moduleSettings->redLetterWords = checked; - break; - } - } - - emit sigChanged(); -} - -/** No descriptions */ -int CDisplaySettingsButton::populateMenu() { - int ret = 0; - - m_popup->clear(); - - // See also optionToggled() - - ret += addMenuEntry(tr("Use linebreaks after each verse"), Linebreak, &m_displaySettings->lineBreaks, (m_modules.first()->type() == CSwordModuleInfo::Bible)); - - //show the verse numbers option only for bible modules - ret += addMenuEntry(tr("Show verse numbers"), Versenum, &m_displaySettings->verseNumbers, (m_modules.first()->type() == CSwordModuleInfo::Bible)); - - ret += addMenuEntry(tr("Show headings"), Headings, &m_moduleSettings->headings, - isOptionAvailable(CSwordModuleInfo::headings)); - - ret += addMenuEntry(tr("Highlight words of Jesus"), WordsofJ, &m_moduleSettings->redLetterWords, - isOptionAvailable(CSwordModuleInfo::redLetterWords )); - - ret += addMenuEntry(tr("Show Hebrew vowel points"), Vowel, &m_moduleSettings->hebrewPoints, - isOptionAvailable(CSwordModuleInfo::hebrewPoints )); - - ret += addMenuEntry(tr("Show Hebrew cantillation marks"), Cantillation, &m_moduleSettings->hebrewCantillation, - isOptionAvailable(CSwordModuleInfo::hebrewCantillation )); - - ret += addMenuEntry(tr("Show Greek accents"), Accents, &m_moduleSettings->greekAccents, - isOptionAvailable(CSwordModuleInfo::greekAccents )); - - ret += addMenuEntry(tr("Use alternative textual variant"), Variant, &m_moduleSettings->textualVariants, - isOptionAvailable(CSwordModuleInfo::textualVariants )); - - ret += addMenuEntry(tr("Show scripture cross-references"), Xref, &m_moduleSettings->scriptureReferences, - isOptionAvailable(CSwordModuleInfo::scriptureReferences )); - - ret += addMenuEntry(tr("Show morph segmentation"), Morphseg, &m_moduleSettings->morphSegmentation, - isOptionAvailable(CSwordModuleInfo::morphSegmentation )); - - return ret; -} - -/** Adds an entry to m_popup. */ -int CDisplaySettingsButton::addMenuEntry( const QString name, OptionType type, const int* option, const bool available) { - int ret = 0; - - if (available) { - QAction* a = m_popup->addAction(name); - //see optionToggled() - a->setProperty("OptionType", type); - a->setCheckable(true); - a->setChecked(*option); - ret = 1; - } - - return ret; -} - -bool CDisplaySettingsButton::isOptionAvailable( const CSwordModuleInfo::FilterTypes option ) { - bool ret = false; - QList<CSwordModuleInfo*>::iterator end_it = m_modules.end(); - for (QList<CSwordModuleInfo*>::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 settings menu. */ -int CDisplaySettingsButton::menuItemCount() { - return m_popup->actions().count(); -} - -/** Sets the item at position pos to the state given as 2nd paramter. */ -void CDisplaySettingsButton::setItemStatus( const int index, const bool checked ) { - QAction* action = m_popup->actions().at(index); - action->setChecked(checked); -} - -/** Returns the status of the item at position "index" */ -bool CDisplaySettingsButton::itemStatus( const int index ) { - return m_popup->actions().at(index)->isChecked(); -} - -/** Sets the status to changed. The signal changed will be emitted. */ -void CDisplaySettingsButton::setChanged() { - optionToggled(0); -} diff --git a/src/frontend/displaywindow/cbuttons.h b/src/frontend/displaywindow/cbuttons.h deleted file mode 100644 index 39dbbf9..0000000 --- a/src/frontend/displaywindow/cbuttons.h +++ /dev/null @@ -1,75 +0,0 @@ -/********* -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2008 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#ifndef CBUTTONS_H -#define CBUTTONS_H - -#include <QToolButton> - -#include <QHash> -#include "backend/managers/cswordbackend.h" - - -class CSwordModuleInfo; -class QMenu; - -/** This class manages the display options of the selected modules. - * @author The BibleTime team - */ -class CDisplaySettingsButton : public QToolButton { - Q_OBJECT - public: - - CDisplaySettingsButton(CSwordBackend::DisplayOptions *displaySettings, CSwordBackend::FilterOptions *settings, const QList<CSwordModuleInfo*>& useModules, QWidget *parent = 0); - void reset(const QList<CSwordModuleInfo*>& useModules); - /** - * Sets the item at position pos to the satet given as 2nd paramter. - */ - void setItemStatus( const int pos, const bool checked ); - /** - * Returns the number of usable menu items in the setttings menu. - */ - int menuItemCount(); - /** - * Returns the status of the item at position "index" - */ - bool itemStatus( const int index ); - /** - * Sets the status to changed. The signal changed will be emitted. - */ - void setChanged(); - - signals: - void sigChanged(void); - - protected slots: - void optionToggled(QAction* action); - - protected: - - /** This enum marks the option types for a display. Used internally.*/ - enum OptionType {Linebreak, Versenum, Headings, WordsofJ, Vowel, Cantillation, Accents, - Variant, Xref, Morphseg - }; - - CSwordBackend::FilterOptions* m_moduleSettings; - CSwordBackend::DisplayOptions* m_displaySettings; - CSwordBackend::FilterOptions m_available; - QList<CSwordModuleInfo*> m_modules; - - QHash<QString, int> m_dict; - - QMenu* m_popup; - - int populateMenu(); - bool isOptionAvailable( const CSwordModuleInfo::FilterTypes option); - int addMenuEntry( const QString name, OptionType type, const int* option, const bool available); -}; - -#endif diff --git a/src/frontend/displaywindow/cdisplaywindow.cpp b/src/frontend/displaywindow/cdisplaywindow.cpp index 4ba567a..3900a92 100644 --- a/src/frontend/displaywindow/cdisplaywindow.cpp +++ b/src/frontend/displaywindow/cdisplaywindow.cpp @@ -21,8 +21,8 @@ #include "frontend/display/cdisplay.h" #include "frontend/displaywindow/bttoolbarpopupaction.h" #include "frontend/displaywindow/btactioncollection.h" -#include "frontend/displaywindow/cmodulechooserbar.h" -#include "frontend/displaywindow/cbuttons.h" +#include "frontend/displaywindow/btmodulechooserbar.h" +#include "frontend/displaywindow/btdisplaysettingsbutton.h" #include "frontend/keychooser/ckeychooser.h" #include "frontend/keychooser/bthistory.h" #include "frontend/profile/cprofilewindow.h" @@ -36,8 +36,6 @@ using namespace Profile; CDisplayWindow::CDisplayWindow(QList<CSwordModuleInfo*> modules, CMDIArea *parent) : QMainWindow(parent), m_mdi(parent), - m_filterOptions(), - m_displayOptions(), m_displaySettingsButton(0), m_keyChooser(0), m_swordKey(0), @@ -53,7 +51,14 @@ CDisplayWindow::CDisplayWindow(QList<CSwordModuleInfo*> modules, CMDIArea *paren setModules(modules); // Connect this to the backend module list changes - connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(reload(CSwordBackend::SetupChangedReason))); + connect(CPointers::backend(), + SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), + SLOT(reload(CSwordBackend::SetupChangedReason))); + BibleTime* mainwindow = dynamic_cast<BibleTime*>(m_mdi->parent()); + connect(mainwindow, SIGNAL(toggledTextWindowHeader(bool)), SLOT(slotShowHeader(bool)) ); + connect(mainwindow, SIGNAL(toggledTextWindowNavigator(bool)), SLOT(slotShowNavigator(bool)) ); + connect(mainwindow, SIGNAL(toggledTextWindowToolButtons(bool)), SLOT(slotShowToolButtons(bool)) ); + connect(mainwindow, SIGNAL(toggledTextWindowModuleChooser(bool)), SLOT(slotShowModuleChooser(bool)) ); } CDisplayWindow::~CDisplayWindow() { @@ -61,10 +66,6 @@ CDisplayWindow::~CDisplayWindow() { m_swordKey = 0; } -CMDIArea* CDisplayWindow::mdi() const { - return m_mdi; -} - /** Returns the right window caption. */ const QString CDisplayWindow::windowCaption() { if (!m_modules.count()) { @@ -74,18 +75,11 @@ const QString CDisplayWindow::windowCaption() { return QString(key()->key()).append(" (").append(m_modules.join(" | ")).append(")"); } -/** Returns the used modules as a QPtrList */ +/** Returns the used modules as a pointer list */ QList<CSwordModuleInfo*> CDisplayWindow::modules() { - QList<CSwordModuleInfo*> mods; + //qDebug() << "CDisplayWindow::modules"; - for (QStringList::iterator it = m_modules.begin(); it != m_modules.end(); ++it) { - Q_ASSERT(backend()->findModuleByName(*it)); - if (CSwordModuleInfo* m = backend()->findModuleByName(*it)) { - mods.append(m); - } - } - - return mods; + return CPointers::backend()->getPointerList(m_modules); } void CDisplayWindow::insertKeyboardActions( BtActionCollection* a ) { @@ -101,10 +95,6 @@ void CDisplayWindow::insertKeyboardActions( BtActionCollection* a ) { actn->setShortcut(QKeySequence::ZoomOut); a->addAction("zoomOut", actn); - actn = new QAction(QIcon(), tr("Close"), a); - actn->setShortcut(QKeySequence::Close); - a->addAction("closeWindow", actn); - actn = new QAction(QIcon(), tr("Select all"), a); actn->setShortcut(QKeySequence::SelectAll); a->addAction("selectAll", actn); @@ -167,10 +157,6 @@ void CDisplayWindow::initActions() { QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(zoomOut())); addAction(actn); - actn = ac->action("closeWindow"); - QObject::connect(actn, SIGNAL(triggered()), this, SLOT(close())); - addAction(actn); - actn = ac->action("selectAll"); QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(selectAll())); addAction(actn); @@ -198,6 +184,7 @@ void CDisplayWindow::initActions() { /** Refresh the settings of this window. */ void CDisplayWindow::reload(CSwordBackend::SetupChangedReason) { + qDebug() << "CDisplayWindow::reload"; //first make sure all used Sword modules are still present QMutableStringListIterator it(m_modules); while (it.hasNext()) { @@ -213,43 +200,51 @@ void CDisplayWindow::reload(CSwordBackend::SetupChangedReason) { if (keyChooser()) keyChooser()->setModules( modules(), false ); - if (m_moduleChooserBar) { //necessary for edit windows which have now chooser bar - m_moduleChooserBar->setModules(modules()); - } - modulesChanged(); lookup(); CBTConfig::setupAccelSettings(CBTConfig::allWindows, actionCollection()); CBTConfig::setupAccelSettings(CBTConfig::readWindow, actionCollection()); + qDebug() << "CDisplayWindow::reload emits sigModuleListSet..."; + emit sigModuleListSet(m_modules); +} + +void CDisplayWindow::slotAddModule(int index, QString module) { + qDebug() << "CDisplayWindow::slotAddModule"; + m_modules.insert(index, module); + lookup(); + modulesChanged(); + emit sigModuleListChanged(); } -/** Returns the filter options used by this window. */ -CSwordBackend::FilterOptions& CDisplayWindow::filterOptions() { - return m_filterOptions; +void CDisplayWindow::slotReplaceModule(int index, QString newModule) { + qDebug() << "CDisplayWindow::slotReplaceModule" << m_modules.at(index) << "with" << newModule; + m_modules.replace(index, newModule); + qDebug() << "window's new module list:" << m_modules; + lookup(); + modulesChanged(); + emit sigModuleListChanged(); } -/** Returns the display options used by this display window. */ -CSwordBackend::DisplayOptions& CDisplayWindow::displayOptions() { - return m_displayOptions; +void CDisplayWindow::slotRemoveModule(int index) { + qDebug() << "CDisplayWindow::slotRemoveModule"; + m_modules.removeAt(index); + lookup(); + modulesChanged(); + emit sigModuleListChanged(); } /** Sets the new display options for this window. */ -void CDisplayWindow::setDisplayOptions( const CSwordBackend::DisplayOptions& displayOptions ) { +void CDisplayWindow::setDisplayOptions(const CSwordBackend::DisplayOptions &displayOptions) { m_displayOptions = displayOptions; } /** Sets the new filter options of this window. */ -void CDisplayWindow::setFilterOptions( CSwordBackend::FilterOptions& filterOptions ) { +void CDisplayWindow::setFilterOptions(const CSwordBackend::FilterOptions &filterOptions) { m_filterOptions = filterOptions; } -/** Returns true if the widget is ready for use. */ -bool CDisplayWindow::isReady() const { - return m_isReady; -} - /** Set the ready status */ -void CDisplayWindow::setReady( const bool& ready ) { +void CDisplayWindow::setReady(bool ready) { m_isReady = ready; } @@ -258,22 +253,11 @@ bool CDisplayWindow::queryClose() { return true; } -/** Returns the keychooser widget of this display window. */ -CKeyChooser* CDisplayWindow::keyChooser() const { - return m_keyChooser; -} - /** Sets the keychooser widget for this display window. */ void CDisplayWindow::setKeyChooser( CKeyChooser* ck ) { m_keyChooser = ck; } -/** Returns the key of this display window. */ -CSwordKey* CDisplayWindow::key() const { - Q_ASSERT( m_swordKey ); - return m_swordKey; -} - /** Sets the new sword key. */ void CDisplayWindow::setKey( CSwordKey* key ) { Q_ASSERT( key ); @@ -281,16 +265,16 @@ void CDisplayWindow::setKey( CSwordKey* key ) { } void CDisplayWindow::modulesChanged() { - if (moduleChooserBar()) { //necessary for write windows - setModules( m_moduleChooserBar->getModuleList() ); - } - - if (!modules().count()) { + // this would only set the stringlist again + //if (moduleChooserBar()) { //necessary for write windows + //setModules( m_moduleChooserBar->getModuleList() ); + //} + if (modules().isEmpty()) { close(); } else { if (displaySettingsButton()) { - displaySettingsButton()->reset(modules()); + displaySettingsButton()->setModules(modules()); } key()->module(modules().first()); @@ -298,24 +282,30 @@ void CDisplayWindow::modulesChanged() { } } -/** Returns the module chooser bar. */ -CModuleChooserBar* CDisplayWindow::moduleChooserBar() const { - return m_moduleChooserBar; -} - /** Sets the module chooser bar. */ -void CDisplayWindow::setModuleChooserBar( CModuleChooserBar* bar ) { +void CDisplayWindow::setModuleChooserBar( BtModuleChooserBar* bar ) { + qDebug() << "CDisplayWindow::setModuleChooserBar"; if (m_moduleChooserBar) { - disconnect(m_moduleChooserBar, SIGNAL(sigChanged()), this, SLOT(modulesChanged())); + m_moduleChooserBar->deleteLater(); } //if a new bar should be set! if (bar) { m_moduleChooserBar = bar; - connect(bar, SIGNAL(sigChanged()), SLOT(modulesChanged())); + bar->setWindowTitle(tr("Work chooser buttons")); + bar->setLayoutDirection(Qt::LeftToRight); + bar->setVisible(CBTConfig::get(CBTConfig::showTextWindowModuleSelectorButtons)); } } +/** Sets the module header of text area. */ +void CDisplayWindow::setHeaderBar( QToolBar* header ) { + m_headerBar = header; + header->setMovable(false); + header->setWindowTitle(tr("Text area header")); + header->setVisible(CBTConfig::get(CBTConfig::showTextWindowHeaders)); +} + /** Sets the modules. */ void CDisplayWindow::setModules( const QList<CSwordModuleInfo*>& newModules ) { qDebug() << "CDisplayWindow::setModules"; @@ -344,45 +334,67 @@ bool CDisplayWindow::init() { m_filterOptions = CBTConfig::getFilterOptionDefaults(); m_displayOptions = CBTConfig::getDisplayOptionDefaults(); if (displaySettingsButton()) { - displaySettingsButton()->reset(modules()); + displaySettingsButton()->setFilterOptions(m_filterOptions, false); + displaySettingsButton()->setDisplayOptions(m_displayOptions, false); + displaySettingsButton()->setModules(modules()); } setReady(true); return true; } -/** Returns the main toolbar. */ -QToolBar* CDisplayWindow::mainToolBar() const { - return m_mainToolBar; -} - -/** Returns the main toolbar. */ -QToolBar* CDisplayWindow::buttonsToolBar() const { - return m_buttonsToolBar; -} - /** Sets the main toolbar. */ void CDisplayWindow::setMainToolBar( QToolBar* bar ) { m_mainToolBar = bar; + bar->setAllowedAreas(Qt::TopToolBarArea); + bar->setFloatable(false); + bar->setWindowTitle(tr("Navigation")); + bar->setVisible(CBTConfig::get(CBTConfig::showTextWindowNavigator)); } /** Sets the main toolbar. */ void CDisplayWindow::setButtonsToolBar( QToolBar* bar ) { m_buttonsToolBar = bar; -} - -/** Returns the display settings button */ -CDisplaySettingsButton* CDisplayWindow::displaySettingsButton() const { - return m_displaySettingsButton; + bar->setAllowedAreas(Qt::TopToolBarArea); + bar->setFloatable(false); + bar->setWindowTitle(tr("Tools")); + bar->setVisible( CBTConfig::get(CBTConfig::showTextWindowToolButtons) ); } /** Sets the display settings button. */ -void CDisplayWindow::setDisplaySettingsButton( CDisplaySettingsButton* button ) { - if (m_displaySettingsButton) - disconnect(m_displaySettingsButton, SIGNAL( sigChanged() ), this, SLOT(lookup() )); +void CDisplayWindow::setDisplaySettingsButton( BtDisplaySettingsButton* button ) { + if (m_displaySettingsButton) { + m_displaySettingsButton->disconnect(this); + } m_displaySettingsButton = button; - connect(m_displaySettingsButton, SIGNAL(sigChanged()), this, SLOT(lookup())); + + button->setDisplayOptions(displayOptions(), false); + button->setFilterOptions(filterOptions(), false); + button->setModules(modules()); + + connect(button, SIGNAL(sigFilterOptionsChanged(CSwordBackend::FilterOptions)), + this, SLOT(setFilterOptions(CSwordBackend::FilterOptions))); + connect(button, SIGNAL(sigDisplayOptionsChanged(CSwordBackend::DisplayOptions)), + this, SLOT(setDisplayOptions(CSwordBackend::DisplayOptions))); + connect(button, SIGNAL(sigChanged()), + this, SLOT(lookup())); +} + +void CDisplayWindow::slotShowHeader(bool show) { + headerBar()->setVisible(show); +} + +void CDisplayWindow::slotShowNavigator(bool show) { + mainToolBar()->setVisible(show); +} + +void CDisplayWindow::slotShowToolButtons(bool show) { + buttonsToolBar()->setVisible(show); +} + +void CDisplayWindow::slotShowModuleChooser(bool show) { + moduleChooserBar()->setVisible(show); } /** Lookup the current key. Used to refresh the display. */ @@ -423,12 +435,13 @@ void CDisplayWindow::lookupKey( const QString& keyName ) { */ Q_ASSERT(modules().first()); - //qDebug("CDisplayWindow::lookup: %s", keyName.latin1()); + qDebug() << "CDisplayWindow::lookupKey: " << keyName; lookupModKey(modules().first()->name(), keyName); } /** Update the status of the popup menu entries. */ void CDisplayWindow::updatePopupMenu() { + /// \todo Verify this should be empty and comment. } @@ -448,12 +461,6 @@ QMenu* CDisplayWindow::popup() { return m_popupMenu; } -/** Returns the display widget used by this implementation of CDisplayWindow. */ -CDisplay* CDisplayWindow::displayWidget() const { - Q_ASSERT(m_displayWidget); - return m_displayWidget; -} - /** Sets the display widget used by this display window. */ void CDisplayWindow::setDisplayWidget( CDisplay* newDisplay ) { m_displayWidget = newDisplay; @@ -480,10 +487,6 @@ void CDisplayWindow::printAnchorWithText() { m_displayWidget->connectionsProxy()->printAnchorWithText( m_displayOptions, m_filterOptions); } -BtActionCollection* CDisplayWindow::actionCollection() { - return m_actionCollection; -} - void CDisplayWindow::setFocusKeyChooser() { keyChooser()->setFocus(); } diff --git a/src/frontend/displaywindow/cdisplaywindow.h b/src/frontend/displaywindow/cdisplaywindow.h index 6164e94..b23d856 100644 --- a/src/frontend/displaywindow/cdisplaywindow.h +++ b/src/frontend/displaywindow/cdisplaywindow.h @@ -20,10 +20,11 @@ class BtActionCollection; class CDisplay; -class CDisplaySettingsButton; +class BtDisplaySettingsButton; class CKeyChooser; class CMDIArea; -class CModuleChooserBar; +//class CModuleChooserBar; +class BtModuleChooserBar; class CReadWindow; class CSwordModuleInfo; class CWriteWindow; @@ -42,105 +43,153 @@ class CDisplayWindow : public QMainWindow, public CPointers { PlainTextWindow = 2 }; - // Insert the keyboard accelerators of this window into the given KAccel object. + /** Insert the keyboard accelerators of this window into the given actioncollection.*/ static void insertKeyboardActions( BtActionCollection* const a ); - CMDIArea* mdi() const; + inline CMDIArea *mdi() const { + return m_mdi; + } - // Returns the right window caption. + /** Returns the correct window caption.*/ const QString windowCaption(); - // Returns the used modules as a QPtrList + /** Returns the used modules as a pointer list.*/ QList<CSwordModuleInfo*> modules(); - // Store the settings of this window in the given CProfileWindow object. + /** Returns the used modules as a string list. */ + inline const QStringList &getModuleList() const { + return m_modules; + } + + /** Store the settings of this window in the given CProfileWindow object.*/ virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow ) = 0; - // Store the settings of this window in the given profile window. + /** Store the settings of this window in the given profile window.*/ virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow ) = 0; - // Sets the new filter options of this window. - void setFilterOptions( CSwordBackend::FilterOptions& filterOptions ); - - // Sets the new display options for this window. - void setDisplayOptions( const CSwordBackend::DisplayOptions& displayOptions ); - - // Returns the display options used by this display window. - CSwordBackend::DisplayOptions& displayOptions(); + /** Returns the display options used by this display window. */ + inline const CSwordBackend::DisplayOptions &displayOptions() const { + return m_displayOptions; + } - // Returns the filter options used by this window. - CSwordBackend::FilterOptions& filterOptions(); + /** Returns the filter options used by this window. */ + inline const CSwordBackend::FilterOptions &filterOptions() const { + return m_filterOptions; + } - // Set the ready status - void setReady( const bool& ready ); + /** Set the ready status. */ + void setReady(bool ready); - // Returns true if the widget is ready for use. - bool isReady() const; + /** Returns true if the widget is ready for use. */ + inline bool isReady() const { + return m_isReady; + } - // Returns true if the window may be closed. + /** Returns true if the window may be closed.*/ virtual bool queryClose(); - // Returns the keychooser widget of this display window. - CKeyChooser* keyChooser() const; + /** Returns the keychooser widget of this display window. */ + inline CKeyChooser *keyChooser() const { + return m_keyChooser; + } - // Sets the new sword key. + /** Sets the new sword key.*/ void setKey( CSwordKey* key ); - // Returns the key of this display window. - CSwordKey* key() const; + /** Returns the key of this display window. */ + inline CSwordKey *key() const { + Q_ASSERT(m_swordKey != 0); + return m_swordKey; + } - // Initialize the window. Call this method from the outside, because calling this in the constructor is not possible! + /** + * Initialize the window. Call this method from the outside, + * because calling this in the constructor is not possible! + */ virtual bool init(); - // Sets the main toolbar. + /** Sets and inits the properties of the main navigation toolbar.*/ void setMainToolBar( QToolBar* bar ); - // Sets the buttons toolbar. + /** Sets and inits the properties of the tool buttons toolbar.*/ void setButtonsToolBar( QToolBar* bar ); - // Returns the main toolbar. - QToolBar* mainToolBar() const; + /** Returns the main navigation toolbar. */ + inline QToolBar *mainToolBar() const { + return m_mainToolBar; + } - // Returns the buttons toolbar. - QToolBar* buttonsToolBar() const; + /** Returns the tool buttons toolbar. */ + inline QToolBar *buttonsToolBar() const { + return m_buttonsToolBar; + } - // Initialize the toolbars + /** Initialize the toolbars.*/ virtual void initToolbars() = 0; - // Returns the display settings button - CDisplaySettingsButton* displaySettingsButton() const; + /** Returns the display settings button. */ + inline BtDisplaySettingsButton *displaySettingsButton() const { + return m_displaySettingsButton; + } - // Sets the display settings button. - void setDisplaySettingsButton( CDisplaySettingsButton* button ); + /** Sets the display settings button.*/ + void setDisplaySettingsButton( BtDisplaySettingsButton* button ); virtual void setupPopupMenu() = 0; - // Returns the display widget used by this implementation of CDisplayWindow. - virtual CDisplay* displayWidget() const; + /** Returns the display widget used by this implementation of CDisplayWindow. */ + virtual inline CDisplay *displayWidget() const { + Q_ASSERT(m_displayWidget != 0); + return m_displayWidget; + } - // Sets the display widget used by this display window. + /** Sets the display widget used by this display window.*/ virtual void setDisplayWidget( CDisplay* newDisplay ); - // Returns whether syncs to the active window are allowed at this time for this display window - // @return boolean value whether sync is allowed + /** + * Returns whether syncs to the active window are allowed at this time for this display window + * @return boolean value whether sync is allowed + */ virtual bool syncAllowed() const { return false; }; - BtActionCollection* actionCollection(); - + inline BtActionCollection *actionCollection() const { + return m_actionCollection; + } + + signals: + /** The module list was set because backend was reloaded.*/ + void sigModuleListSet(QStringList modules); + /** A module was added to this window.*/ + void sigModuleAdded(int index, QString module); + void sigModuleReplaced(int index, QString newModule); + void sigModuleRemoved(int index); + /** The module list of window changed but backend list didn't.*/ + void sigModuleListChanged(); public slots: - - // Lookup the specified key in the given module. If the module is not chosen withing - // this display window create a new displaywindow with the right module in it. + /** Receives a signal telling that a module should be added.*/ + void slotAddModule(int index, QString module); + void slotReplaceModule(int index, QString newModule); + void slotRemoveModule(int index); + + /** + * Lookup the specified key in the given module. If the module is not chosen withing + * this display window create a new displaywindow with the right module in it. + */ virtual void lookupModKey( const QString& module, const QString& key ); - // Lookup the key in the chosen modules. + /** Lookup the key in the chosen modules.*/ virtual void lookupKey( const QString& key ); - // Refresh the settings of this window. + /** Refresh the settings of this window.*/ virtual void reload(CSwordBackend::SetupChangedReason reason); + void slotShowNavigator(bool show); + void slotShowToolButtons(bool show); + void slotShowModuleChooser(bool show); + void slotShowHeader(bool show); + protected: friend class CMDIArea; friend class CBibleReadWindow; @@ -148,39 +197,63 @@ class CDisplayWindow : public QMainWindow, public CPointers { CDisplayWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); virtual ~CDisplayWindow(); - // Initializes the intern keyboard actions. + /** Returns the display options used by this display window. */ + inline CSwordBackend::DisplayOptions &displayOptions() { + return m_displayOptions; + } + + /** Returns the filter options used by this window. */ + inline CSwordBackend::FilterOptions &filterOptions() { + return m_filterOptions; + } + + /** Initializes the internel keyboard actions.*/ virtual void initActions(); - // Sets the keychooser widget for this display window. + /** Sets the keychooser widget for this display window.*/ void setKeyChooser( CKeyChooser* ck ); - // Returns the module chooser bar. - CModuleChooserBar* moduleChooserBar() const; + /** Returns the module chooser bar. */ + inline BtModuleChooserBar *moduleChooserBar() const { + return m_moduleChooserBar; + } - // Lookup the given key. + /** Lookup the given key.*/ virtual void lookupSwordKey( CSwordKey* ) = 0; - // Sets the module chooser bar. - void setModuleChooserBar( CModuleChooserBar* bar ); + /** Sets the module chooser bar.*/ + void setModuleChooserBar( BtModuleChooserBar* bar ); + + void setHeaderBar(QToolBar* header); - // Sets the modules. + inline QToolBar *headerBar() const { + return m_headerBar; + } + + /** Sets the modules. */ void setModules( const QList<CSwordModuleInfo*>& modules ); - // Initializes the signal / slot connections of this display window. + /** Initializes the signal / slot connections of this display window.*/ virtual void initConnections() = 0; - // Initialize the view of this display window. + /** Initialize the view of this display window.*/ virtual void initView() = 0; - // Returns the installed popup menu. + /** Returns the installed RMB popup menu.*/ QMenu* popup(); virtual void closeEvent(QCloseEvent* e); protected slots: + /** Sets the new filter options of this window.*/ + void setFilterOptions(const CSwordBackend::FilterOptions &filterOptions); + + /** Sets the new display options for this window.*/ + void setDisplayOptions(const CSwordBackend::DisplayOptions &displayOptions); + virtual void modulesChanged(); - // Lookup the current key. Used to refresh the display. + /** Lookup the current key. Used to refresh the display.*/ void lookup(); virtual void updatePopupMenu(); @@ -203,13 +276,14 @@ class CDisplayWindow : public QMainWindow, public CPointers { CSwordBackend::FilterOptions m_filterOptions; CSwordBackend::DisplayOptions m_displayOptions; - CDisplaySettingsButton* m_displaySettingsButton; + BtDisplaySettingsButton* m_displaySettingsButton; CKeyChooser* m_keyChooser; CSwordKey* m_swordKey; bool m_isReady; - CModuleChooserBar* m_moduleChooserBar; + BtModuleChooserBar* m_moduleChooserBar; QToolBar* m_mainToolBar; QToolBar* m_buttonsToolBar; + QToolBar* m_headerBar; QMenu* m_popupMenu; CDisplay* m_displayWidget; }; diff --git a/src/frontend/displaywindow/clexiconreadwindow.cpp b/src/frontend/displaywindow/clexiconreadwindow.cpp index 2a5fb40..894c787 100644 --- a/src/frontend/displaywindow/clexiconreadwindow.cpp +++ b/src/frontend/displaywindow/clexiconreadwindow.cpp @@ -25,8 +25,9 @@ #include "frontend/display/creaddisplay.h" #include "frontend/displaywindow/btactioncollection.h" #include "frontend/displaywindow/bttoolbarpopupaction.h" -#include "frontend/displaywindow/cbuttons.h" -#include "frontend/displaywindow/cmodulechooserbar.h" +#include "frontend/displaywindow/btdisplaysettingsbutton.h" +#include "frontend/displaywindow/bttextwindowheader.h" +#include "frontend/displaywindow/btmodulechooserbar.h" #include "frontend/keychooser/bthistory.h" #include "frontend/keychooser/ckeychooser.h" #include "util/directory.h" @@ -183,18 +184,18 @@ void CLexiconReadWindow::initView() { qDebug() << "CLexiconReadWindow::initView"; setDisplayWidget( CDisplay::createReadInstance(this) ); setMainToolBar( new QToolBar(this) ); - mainToolBar()->setAllowedAreas(Qt::TopToolBarArea); - mainToolBar()->setFloatable(false); addToolBar(mainToolBar()); setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) ); mainToolBar()->addWidget(keyChooser()); - setModuleChooserBar( new CModuleChooserBar(modules(), modules().first()->type(), this) ); - moduleChooserBar()->adjustSize(); + setModuleChooserBar( new BtModuleChooserBar(getModuleList(), modules().first()->type(), this) ); addToolBar(moduleChooserBar()); setButtonsToolBar( new QToolBar(this) ); - buttonsToolBar()->setAllowedAreas(Qt::TopToolBarArea); - buttonsToolBar()->setFloatable(false); addToolBar(buttonsToolBar()); + addToolBarBreak(); + setHeaderBar(new QToolBar(this)); + addToolBar(headerBar()); + BtTextWindowHeader* h = new BtTextWindowHeader(this, modules().first()->type(), getModuleList()); + headerBar()->addWidget(h); setWindowIcon(util::tool::getIconForModule(modules().first())); setCentralWidget( displayWidget()->view() ); } @@ -212,7 +213,8 @@ void CLexiconReadWindow::initToolbars() { if (action) { buttonsToolBar()->addAction(action); } - setDisplaySettingsButton( new CDisplaySettingsButton( &displayOptions(), &filterOptions(), modules(), buttonsToolBar()) ); + + setDisplaySettingsButton(new BtDisplaySettingsButton(buttonsToolBar())); /// \todo find the right place for the button buttonsToolBar()->addWidget(displaySettingsButton()); @@ -310,7 +312,7 @@ void CLexiconReadWindow::saveRawHTML() { qDebug() << "could not open file"; return; } - QString source = disp->text(); + QString source = disp->getCurrentSource(); file.write(source.toUtf8()); //qDebug() << "wrote" << bytes << "bytes"; file.close(); diff --git a/src/frontend/displaywindow/cmodulechooserbar.cpp b/src/frontend/displaywindow/cmodulechooserbar.cpp deleted file mode 100644 index 0e6131a..0000000 --- a/src/frontend/displaywindow/cmodulechooserbar.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/********* -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2008 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#include "frontend/displaywindow/cmodulechooserbar.h" - -#include <QAction> -#include <QDebug> -#include <QList> -#include <QToolBar> -#include "frontend/displaywindow/cmodulechooserbutton.h" - - -CModuleChooserBar::CModuleChooserBar(QList<CSwordModuleInfo*> useModules, CSwordModuleInfo::ModuleType type, QWidget *parent) - : QToolBar(parent), - m_moduleType(type), - m_idCounter(0), - m_buttonLimit(-1) { //-1 means no limit - setAllowedAreas(Qt::TopToolBarArea); - setFloatable(false); - //insert buttons if useModules != 0 - QList<CSwordModuleInfo*>::iterator end_it = useModules.end(); - for (QList<CSwordModuleInfo*>::iterator it(useModules.begin()); it != end_it; ++it) { - if ((m_buttonLimit != -1) && ( m_buttonLimit <= (int)m_buttonList.count()) ) { //we reached the button limit - break; - } - addButton( *it ); - } - - // We can add a button to choose an additional module - if ( (m_buttonLimit == -1) || (m_buttonLimit > (int)m_buttonList.count()) ) { - addButton(0); //add a button without module set - } -} - -CModuleChooserButton* CModuleChooserBar::addButton( CSwordModuleInfo* const module ) { - CModuleChooserButton* b = new CModuleChooserButton(module, m_moduleType, ++m_idCounter, this); - QAction* a = addWidget(b); - m_buttonList.append(b); - connect( b, SIGNAL(sigAddButton()), this, SLOT(addButton()) ); - connect( b, SIGNAL(sigRemoveButton(const int)), this, SLOT(removeButton(const int)) ); - connect( b, SIGNAL(sigChanged()), SIGNAL(sigChanged()) ); - connect( b, SIGNAL(sigChanged()), SLOT(updateMenuItems()) ); - a->setVisible(true); - updateMenuItems(); //make sure the items are up to date with the newest module list - return b; -} - -void CModuleChooserBar::addButton( ) { - addButton(0); -} - -//change current with next and remove -/** Removes a button from the toolbar */ -void CModuleChooserBar::removeButton( const int ID ) { - QMutableListIterator<CModuleChooserButton*> it(m_buttonList); - while (it.hasNext()) { - CModuleChooserButton* b = it.next(); - if (b->getId() == ID) { //found the right button to remove - it.remove(); - b->deleteLater(); - break; - } - } - emit sigChanged(); - updateMenuItems(); //make sure the items are up to date with the newest module list -} - -/** Returns a list of selected modules. */ -QList<CSwordModuleInfo*> CModuleChooserBar::getModuleList() { - QList<CSwordModuleInfo*> list; - foreach (CModuleChooserButton* b, m_buttonList) { - if (b->module()) list.append( b->module() ); - } - return list; -} - -//change current with remove -/** Sets the number of the maximum count of buttons. */ -void CModuleChooserBar::setButtonLimit(const int limit) { - m_buttonLimit = limit; - if (limit == -1) //no need to delete buttons - return; - - const int tooMuch = m_buttonList.size() - limit; - for (int i = 0; i < tooMuch; ++i) { - CModuleChooserButton* b = m_buttonList.takeLast(); - b->deleteLater(); - } - - updateMenuItems(); -} - -/** Sets the modules which are chosen in this module chooser bar. */ -void CModuleChooserBar::setModules( QList<CSwordModuleInfo*> useModules ) { - setButtonLimit(0); - setButtonLimit(-1); //these two lines clear the bar - - if (!useModules.count()) return; - - QList<CSwordModuleInfo*>::iterator end_it = useModules.end(); - for (QList<CSwordModuleInfo*>::iterator it(useModules.begin()); it != end_it; ++it) { - if ( (m_buttonLimit != -1) && (m_buttonLimit <= (int)m_buttonList.count()) ) { - break; - } - addButton( *it ); - } - - if ( (m_buttonLimit == -1) || (m_buttonLimit > (int)m_buttonList.count()) ) { - addButton(0);//add button without module set - } - - updateMenuItems(); -} - -void CModuleChooserBar::updateMenuItems() { - resize(sizeHint()); - update(); //seems to be neccessary to enforce display of the layout changes when a button was removed or added - foreach (CModuleChooserButton* b, m_buttonList) - b->updateMenuItems(); -} diff --git a/src/frontend/displaywindow/cmodulechooserbar.h b/src/frontend/displaywindow/cmodulechooserbar.h deleted file mode 100644 index fbdd737..0000000 --- a/src/frontend/displaywindow/cmodulechooserbar.h +++ /dev/null @@ -1,75 +0,0 @@ -/********* -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2008 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#ifndef CMODULECHOOSERBAR_H -#define CMODULECHOOSERBAR_H - -#include <QToolBar> - -#include <QList> -#include "backend/drivers/cswordmoduleinfo.h" -#include "util/cpointers.h" - - -class CModuleChooserButton; -class QWidget; - -/** - * @author The BibleTime team - */ -class CModuleChooserBar : public QToolBar { - Q_OBJECT - public: - /** - * Default constructor - */ - CModuleChooserBar(QList<CSwordModuleInfo*> useModules, CSwordModuleInfo::ModuleType type, QWidget *parent = 0); - /** - * Returns a list of selected modules. - */ - QList<CSwordModuleInfo*> getModuleList(); - /** - * Sets the number of the maximum count of buttons. - */ - void setButtonLimit( const int limit); - /** - * Sets the modules which are chosen in this module chooser bar. - */ - void setModules( QList<CSwordModuleInfo*> modules ); - - signals: - void sigChanged(); - - protected: - /** - * Adds a button to the toolbar - */ - CModuleChooserButton* addButton( CSwordModuleInfo* const module ); - - protected slots: // Protected slots - /* - * This slot calls the addButton function above to add a button. - */ - void addButton(); - /** - * Removes a button from the toolbar - */ - void removeButton( const int ID ); - /** */ - void updateMenuItems(); - - private: - CSwordModuleInfo::ModuleType m_moduleType; - int m_idCounter; - int m_buttonLimit; - QList<CModuleChooserButton*> m_buttonList; - -}; - -#endif diff --git a/src/frontend/displaywindow/cmodulechooserbutton.cpp b/src/frontend/displaywindow/cmodulechooserbutton.cpp deleted file mode 100644 index 0444cf6..0000000 --- a/src/frontend/displaywindow/cmodulechooserbutton.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/********* -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2008 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#include "frontend/displaywindow/cmodulechooserbutton.h" - -#include <QDebug> -#include <QHash> -#include <QMenu> -#include <QString> -#include <QToolButton> -#include <QToolTip> -#include "backend/config/cbtconfig.h" -#include "backend/managers/cswordbackend.h" -#include "frontend/displaywindow/cmodulechooserbar.h" -#include "util/cresmgr.h" -#include "util/directory.h" - - -CModuleChooserButton::CModuleChooserButton(CSwordModuleInfo* useModule, CSwordModuleInfo::ModuleType type, const int id, CModuleChooserBar *parent) - : QToolButton(parent), - m_id(id), m_popup(0), m_moduleChooserBar(parent) { - namespace DU = util::directory; - - m_moduleType = type; - m_module = useModule; - m_hasModule = (m_module) ? true : false; - - setIcon(DU::getIcon(iconName())); - setPopupMode(QToolButton::InstantPopup); - - populateMenu(); -} - -CModuleChooserButton::~CModuleChooserButton() { - qDeleteAll(m_submenus); - m_submenus.clear(); - delete m_popup; //not necessary, because has "this" as parent? -} - -/** Returns the icon used for the current status. */ -const QString CModuleChooserButton::iconName() { - switch (m_moduleType) { - case CSwordModuleInfo::Bible: - return (m_hasModule) ? CResMgr::modules::bible::icon_unlocked : CResMgr::modules::bible::icon_add; - case CSwordModuleInfo::Commentary: - return (m_hasModule) ? CResMgr::modules::commentary::icon_unlocked : CResMgr::modules::commentary::icon_add; - case CSwordModuleInfo::Lexicon: - return m_hasModule ? CResMgr::modules::lexicon::icon_unlocked : CResMgr::modules::lexicon::icon_add; - case CSwordModuleInfo::GenericBook: - return m_hasModule ? CResMgr::modules::book::icon_unlocked : CResMgr::modules::book::icon_add; - default: //return as default the bible icon - return CResMgr::modules::bible::icon_unlocked; - } -} - -CSwordModuleInfo* CModuleChooserButton::module() { - foreach (QMenu* popup, m_submenus) { - foreach (QAction* action, popup->actions()) { - if ( action->isChecked() ) { //idAt -> , isItemChecked -> QAction::isChecked - QString mod = action->text(); //popup->text(popup->idAt(i)); //text -> - mod.remove(QChar('&')); //remove hotkey indicators - return backend()->findModuleByName( mod.left(mod.indexOf(" ")) ); - } - } - } - return 0; //"none" selected -} - -/** Returns the id used for this button. */ -int CModuleChooserButton::getId() const { - return m_id; -} - -/** Is called after a module was selected in the popup */ -void CModuleChooserButton::moduleChosen( QAction* action ) { - namespace DU = util::directory; - - QListIterator<QMenu*> it(m_submenus); - while (it.hasNext()) { - QMenu* popup = it.next(); - foreach (QAction* a, popup->actions()) { - a->setChecked(false); - } - action->setChecked(true); - } - - m_noneAction->setChecked(false); //uncheck the "none" item - if (action->text().remove(QChar('&')) == tr("NONE")) { // note: this is for m_popup, the toplevel! - if (m_hasModule) { - emit sigRemoveButton(m_id); - return; - } - } - else { - if (!m_hasModule) { - emit sigAddButton(); - } - - m_hasModule = true; - m_module = module(); - - setIcon(DU::getIcon(iconName())); - emit sigChanged(); - - if (m_module) { - setToolTip( tr("Select a work") + " [" + m_module->name() + "]" ); - } - else { - setToolTip( tr("Select an additional work") ); - } - } -} - -/** No descriptions */ -void CModuleChooserButton::populateMenu() { - qDeleteAll(m_submenus); - m_submenus.clear(); - delete m_popup; - m_popup = new QMenu(this); - - if (m_module) { - this->setToolTip( tr("Select a work") + " [" + m_module->name() + "]" ); - } - else { - this->setToolTip( tr("Select an additional work") ); - } - - m_noneAction = m_popup->addAction(tr("NONE")); - m_noneAction->setCheckable(true); - if (!m_module) m_noneAction->setChecked(true); - - m_popup->addSeparator(); - connect(m_popup, SIGNAL(triggered(QAction*)), this, SLOT(moduleChosen(QAction*))); - setMenu(m_popup); - - - // ******* Add languages and modules ******** - - // Filters: add only non-hidden and right type - BTModuleTreeItem::HiddenOff hiddenFilter; - TypeFilter typeFilter(m_moduleType); - QList<BTModuleTreeItem::Filter*> filters; - if (!CBTConfig::get(CBTConfig::bookshelfShowHidden)) { - filters.append(&hiddenFilter); - } - filters.append(&typeFilter); - BTModuleTreeItem root(filters, BTModuleTreeItem::LangMod); - // add all items recursively - addItemToMenu(&root, m_popup); - -} - -void CModuleChooserButton::addItemToMenu(BTModuleTreeItem* item, QMenu* menu) { - foreach (BTModuleTreeItem* i, item->children()) { - - if (i->type() == BTModuleTreeItem::Language) { - // argument menu was m_popup, create and add a new lang menu to it - QMenu* langMenu = new QMenu(i->text(), this); - menu->addMenu(langMenu); - m_submenus.append(langMenu); - connect(langMenu, SIGNAL(triggered(QAction*)), this, SLOT(moduleChosen(QAction*))); - // add the module items to the lang menu - addItemToMenu(i, langMenu); - } - else { - // item must be module, create and add it to the lang menu - QString name(i->text()); - name.append(" ").append(i->moduleInfo()->isLocked() ? tr("[locked]") : QString::null); - QAction* modItem = new QAction(name, menu); - modItem->setCheckable(true); - if ( m_module && i->text() == m_module->name()) modItem->setChecked(true); - menu->addAction(modItem); - } - } -} - -void CModuleChooserButton::updateMenuItems() { - QString moduleName; - CSwordModuleInfo* module = 0; - QList<CSwordModuleInfo*> chosenModules = m_moduleChooserBar->getModuleList(); - - //for ( QMenu* popup = m_submenus.first(); popup; popup = m_submenus.next() ) { - QListIterator<QMenu*> it(m_submenus); - while (it.hasNext()) { - QMenu* popup = it.next(); - foreach (QAction* action, popup->actions()) { - moduleName = action->text(); - moduleName.remove(QChar('&')); //remove Hotkey indicator - module = backend()->findModuleByName( moduleName.left(moduleName.lastIndexOf(" ")) ); - - //Q_ASSERT(module); - if (!module) qWarning("Can't find module with name %s", moduleName.toLatin1().data()); - - bool alreadyChosen = chosenModules.contains( module ); - if (m_module) { - alreadyChosen = alreadyChosen && (m_module->name() != moduleName); - } - //grey it out, it was chosen already - action->setEnabled(!alreadyChosen); - } - } -} diff --git a/src/frontend/displaywindow/cmodulechooserbutton.h b/src/frontend/displaywindow/cmodulechooserbutton.h deleted file mode 100644 index 4d62b67..0000000 --- a/src/frontend/displaywindow/cmodulechooserbutton.h +++ /dev/null @@ -1,85 +0,0 @@ -/********* -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2008 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#ifndef CMODULECHOOSERBUTTON_H -#define CMODULECHOOSERBUTTON_H - -#include <QToolButton> -#include "util/cpointers.h" - -#include <QList> -#include "backend/btmoduletreeitem.h" - - -class QMenu; -class CModuleChooserBar; -class CSwordModuleInfo; - -/** The CModuleChooserButton displays a list of submenus sorted by language which contain the possible modules - * which can be displayed together with the first one. - * @author The BibleTime team - */ -class CModuleChooserButton : public QToolButton, public CPointers { - Q_OBJECT - public: - - /** Filter out modules of wrong type. See populateMenu() and BTModuleTreeItem. */ - struct TypeFilter : public BTModuleTreeItem::Filter { - TypeFilter(CSwordModuleInfo::ModuleType t) { - m_mType = t; - } - bool filter(CSwordModuleInfo* mi) { - return (mi->type() == m_mType); - } - CSwordModuleInfo::ModuleType m_mType; - }; - - CModuleChooserButton(CSwordModuleInfo* useModule, CSwordModuleInfo::ModuleType type, const int id, CModuleChooserBar *parent); - ~CModuleChooserButton(); - - CSwordModuleInfo* module(); - /** - * Returns the id used for this button. - */ - int getId() const; - void updateMenuItems(); - - protected: - /** Populates the menu with language submenus and module items. */ - void populateMenu(); - /** Adds items to the menu recursively. */ - void addItemToMenu(BTModuleTreeItem* item, QMenu* menu); - - private: - /** - * Returns the icon used for the current status. - */ - const QString iconName(); - - bool m_hasModule; - int m_id; - QAction* m_noneAction; - CSwordModuleInfo::ModuleType m_moduleType; - CSwordModuleInfo* m_module; - - QMenu* m_popup; - QList<QMenu*> m_submenus; - - CModuleChooserBar* m_moduleChooserBar; - - - private slots: - void moduleChosen(QAction* action ); - - signals: - void sigRemoveButton(const int ID); - void sigAddButton(); - void sigChanged(); -}; -#endif diff --git a/src/frontend/displaywindow/creadwindow.cpp b/src/frontend/displaywindow/creadwindow.cpp index b65cf8c..07c0abb 100644 --- a/src/frontend/displaywindow/creadwindow.cpp +++ b/src/frontend/displaywindow/creadwindow.cpp @@ -26,11 +26,9 @@ using namespace Profile; -typedef BtHtmlReadDisplay HTMLREADDISPLAY; - CReadWindow::CReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent) : CDisplayWindow(modules, parent), - m_displayWidget(0) { + m_readDisplayWidget(0) { qDebug() << "CReadWindow::CReadWindow"; // installEventFilter(this); } @@ -41,34 +39,38 @@ CReadWindow::~CReadWindow() { /** Sets the display widget of this display window. */ void CReadWindow::setDisplayWidget( CDisplay* newDisplay ) { - Q_ASSERT(dynamic_cast<CReadDisplay*>(newDisplay)); + // Lets be orwellianly paranoid here: + Q_ASSERT(dynamic_cast<CReadDisplay*>(newDisplay) != 0); + CDisplayWindow::setDisplayWidget(newDisplay); - if (m_displayWidget) { - disconnect(m_displayWidget->connectionsProxy(), SIGNAL(referenceClicked(const QString&, const QString&)), this, SLOT(lookupModKey(const QString&, const QString&))); - disconnect(m_displayWidget->connectionsProxy(), SIGNAL(referenceDropped(const QString&)), this, SLOT(lookupKey(const QString&))); + if (m_readDisplayWidget) { + disconnect(m_readDisplayWidget->connectionsProxy(), SIGNAL(referenceClicked(const QString&, const QString&)), + this, SLOT(lookupModKey(const QString&, const QString&))); + disconnect(m_readDisplayWidget->connectionsProxy(), SIGNAL(referenceDropped(const QString&)), + this, SLOT(lookupKey(const QString&))); - HTMLREADDISPLAY* v = dynamic_cast<HTMLREADDISPLAY*>(m_displayWidget); + BtHtmlReadDisplay* v = dynamic_cast<BtHtmlReadDisplay*>(m_readDisplayWidget); if (v) { QObject::disconnect(v, SIGNAL(completed()), this, SLOT(slotMoveToAnchor()) ); } } - m_displayWidget = (CReadDisplay*)newDisplay; + m_readDisplayWidget = static_cast<CReadDisplay*>(newDisplay); connect( - m_displayWidget->connectionsProxy(), + m_readDisplayWidget->connectionsProxy(), SIGNAL(referenceClicked(const QString&, const QString&)), this, SLOT(lookupModKey(const QString&, const QString&)) ); connect( - m_displayWidget->connectionsProxy(), + m_readDisplayWidget->connectionsProxy(), SIGNAL(referenceDropped(const QString&)), this, SLOT(lookupKey(const QString&)) ); - HTMLREADDISPLAY* v = dynamic_cast<HTMLREADDISPLAY*>(m_displayWidget); + BtHtmlReadDisplay* v = dynamic_cast<BtHtmlReadDisplay*>(m_readDisplayWidget); if (v) { QObject::connect(v, SIGNAL(completed()), this, SLOT(slotMoveToAnchor()) ); } @@ -193,9 +195,9 @@ void CReadWindow::openSearchStrongsDialog() { QString searchText = QString::null; if (displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != QString::null) { - Q_FOREACH(QString strongNumber, displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma].split("|")) { - searchText.append("strong:").append( strongNumber ).append(" "); - } + Q_FOREACH(QString strongNumber, displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma].split("|")) { + searchText.append("strong:").append( strongNumber ).append(" "); + } } Search::CSearchDialog::openDialog( modules(), searchText, 0 ); diff --git a/src/frontend/displaywindow/creadwindow.h b/src/frontend/displaywindow/creadwindow.h index 1debe9f..7a529b8 100644 --- a/src/frontend/displaywindow/creadwindow.h +++ b/src/frontend/displaywindow/creadwindow.h @@ -25,7 +25,7 @@ class QResizeEvent; class CReadWindow : public CDisplayWindow { Q_OBJECT public: - // static void insertKeyboardActions( KAccel* const a ); + static void insertKeyboardActions( BtActionCollection* const a ); CReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); @@ -39,7 +39,7 @@ class CReadWindow : public CDisplayWindow { */ virtual void applyProfileSettings(Profile::CProfileWindow * const settings); - protected: // Protected methods + protected: /** * Sets the display widget of this display window. */ @@ -68,7 +68,7 @@ class CReadWindow : public CDisplayWindow { void openSearchStrongsDialog(); private: - CReadDisplay* m_displayWidget; + CReadDisplay* m_readDisplayWidget; }; #endif |