diff options
author | Roberto C. Sanchez <roberto@connexer.com> | 2014-10-21 22:48:29 -0400 |
---|---|---|
committer | Roberto C. Sanchez <roberto@connexer.com> | 2014-10-21 22:48:29 -0400 |
commit | e8a196082586bb68e0bf254a8f6f4b8f39071f32 (patch) | |
tree | b03dbbd1b5be6092ed5e9bcb3806aa2d4938bba3 /src/frontend/displaywindow | |
parent | dd2f7ce46df53f2c377c02d1bf4df8adcf092072 (diff) |
Imported Upstream version 2.3.3
Diffstat (limited to 'src/frontend/displaywindow')
30 files changed, 2738 insertions, 2932 deletions
diff --git a/src/frontend/displaywindow/btactioncollection.cpp b/src/frontend/displaywindow/btactioncollection.cpp index fc1a412..c9d5dd8 100644 --- a/src/frontend/displaywindow/btactioncollection.cpp +++ b/src/frontend/displaywindow/btactioncollection.cpp @@ -17,139 +17,117 @@ #include <QStringList> #include <QDebug> -class BtActionItem : public QObject -{ -public: - BtActionItem(QObject* parent) - : QObject(parent) - { - } - QKeySequence defaultKeys; - QAction* action; +class BtActionItem : public QObject { + public: + BtActionItem(QObject* parent) + : QObject(parent) { + } + QKeySequence defaultKeys; + QAction* action; }; BtActionCollection::BtActionCollection(QObject* parent) - : QObject(parent) -{ + : QObject(parent) { } -BtActionCollection::~BtActionCollection() -{ +BtActionCollection::~BtActionCollection() { } -QList<QAction*> BtActionCollection::actions() -{ - QList<QAction*> actionList; +QList<QAction*> BtActionCollection::actions() { + QList<QAction*> actionList; - QMap<QString, BtActionItem*>::const_iterator iter = m_actions.constBegin(); - while (iter != m_actions.constEnd()) - { - QAction* action = iter.value()->action; - actionList.append(action); - ++iter; - } - return actionList; + QMap<QString, BtActionItem*>::const_iterator iter = m_actions.constBegin(); + while (iter != m_actions.constEnd()) { + QAction* action = iter.value()->action; + actionList.append(action); + ++iter; + } + return actionList; } -QAction* BtActionCollection::action(const QString& name) -{ - if (m_actions.contains(name)) - return m_actions[name]->action; - qWarning() << "A QAction for a shortcut named" << name << "was requested but it is not defined."; - return (new QAction(this)); // dummy QAction* +QAction* BtActionCollection::action(const QString& name) { + if (m_actions.contains(name)) + return m_actions[name]->action; + qWarning() << "A QAction for a shortcut named" << name << "was requested but it is not defined."; + return (new QAction(this)); // dummy QAction* } -QAction* BtActionCollection::addAction(const QString& name, QAction* action) -{ - Q_ASSERT(action != 0); - Q_ASSERT(m_actions[name] == 0); // TODO - replacing actions is ok??? - int count; - count = m_actions.count(); - BtActionItem* item = new BtActionItem(this); - item->action = action; - item->defaultKeys = action->shortcut(); - m_actions[name] = item; - return action; +QAction* BtActionCollection::addAction(const QString& name, QAction* action) { + Q_ASSERT(action != 0); + Q_ASSERT(m_actions[name] == 0); // TODO - replacing actions is ok??? + int count; + count = m_actions.count(); + BtActionItem* item = new BtActionItem(this); + item->action = action; + item->defaultKeys = action->shortcut(); + m_actions[name] = item; + return action; } -QAction* BtActionCollection::addAction(const QString &name, const QObject *receiver, const char* member) -{ - QAction* action = new QAction(name, this); - if (receiver && member) - { - bool ok = connect(action, SIGNAL(triggered()), receiver, SLOT(triggered())); - Q_ASSERT(ok); - } - return addAction(name, action); +QAction* BtActionCollection::addAction(const QString &name, const QObject *receiver, const char* member) { + QAction* action = new QAction(name, this); + if (receiver && member) { + bool ok = connect(action, SIGNAL(triggered()), receiver, SLOT(triggered())); + Q_ASSERT(ok); + } + return addAction(name, action); } -QKeySequence BtActionCollection::getDefaultShortcut(QAction* action) -{ - QMap<QString, BtActionItem*>::const_iterator iter = m_actions.constBegin(); - while (iter != m_actions.constEnd()) - { - if ( iter.value()->action == action) - { - return iter.value()->defaultKeys; - } - iter++; - } - return QKeySequence(); +QKeySequence BtActionCollection::getDefaultShortcut(QAction* action) { + QMap<QString, BtActionItem*>::const_iterator iter = m_actions.constBegin(); + while (iter != m_actions.constEnd()) { + if ( iter.value()->action == action) { + return iter.value()->defaultKeys; + } + iter++; + } + return QKeySequence(); } -void BtActionCollection::setConfigGroup(const QString &group) -{ - m_groupName = group; +void BtActionCollection::setConfigGroup(const QString &group) { + m_groupName = group; } -void BtActionCollection::readSettings() -{ - QSettings* settings = CBTConfig::getConfig(); - settings->beginGroup(m_groupName); - QStringList keyList = settings->childKeys(); - for (int i=0; i<keyList.size(); i++) - { - QString key = keyList.at(i); - QVariant variant = settings->value(key); - QList<QKeySequence> shortcuts; - if ( variant != QVariant()) - { - QList<QVariant> varShortcuts = variant.toList(); - for (int i=0; i<varShortcuts.count(); i++) - { - QString keys = varShortcuts.at(i).toString(); - QKeySequence shortcut(keys); - shortcuts.append(shortcut); - } - } - action(key)->setShortcuts(shortcuts); - } - settings->endGroup(); +void BtActionCollection::readSettings() { + QSettings* settings = CBTConfig::getConfig(); + settings->beginGroup(m_groupName); + QStringList keyList = settings->childKeys(); + for (int i = 0; i < keyList.size(); i++) { + QString key = keyList.at(i); + QVariant variant = settings->value(key); + QList<QKeySequence> shortcuts; + if ( variant != QVariant()) { + QList<QVariant> varShortcuts = variant.toList(); + for (int i = 0; i < varShortcuts.count(); i++) { + QString keys = varShortcuts.at(i).toString(); + QKeySequence shortcut(keys); + shortcuts.append(shortcut); + } + } + action(key)->setShortcuts(shortcuts); + } + settings->endGroup(); } -static QList<QVariant> keyListToVariantList(const QList<QKeySequence>& keyList) -{ - QList<QVariant> varList; - for (int i=0; i<keyList.count(); i++) - { - QKeySequence keySeq = keyList.at(i); - varList.append(keySeq.toString()); - } - return varList; +static QList<QVariant> keyListToVariantList(const QList<QKeySequence>& keyList) { + QList<QVariant> varList; + for (int i = 0; i < keyList.count(); i++) { + QKeySequence keySeq = keyList.at(i); + varList.append(keySeq.toString()); + } + return varList; } -void BtActionCollection::writeSettings() -{ - QSettings* settings = CBTConfig::getConfig(); - settings->beginGroup(m_groupName); - QMap<QString, BtActionItem*>::const_iterator iter = m_actions.constBegin(); - while (iter != m_actions.constEnd()) - { - QString actionName = iter.key(); - QList<QKeySequence> keyList = iter.value()->action->shortcuts(); - QList<QVariant> varList = keyListToVariantList(keyList); - settings->setValue(actionName, varList); - iter++; - } - settings->endGroup(); +void BtActionCollection::writeSettings() { + QSettings* settings = CBTConfig::getConfig(); + settings->beginGroup(m_groupName); + QMap<QString, BtActionItem*>::const_iterator iter = m_actions.constBegin(); + while (iter != m_actions.constEnd()) { + QString actionName = iter.key(); + QList<QKeySequence> keyList = iter.value()->action->shortcuts(); + QList<QVariant> varList = keyListToVariantList(keyList); + settings->setValue(actionName, varList); + iter++; + } + settings->endGroup(); } diff --git a/src/frontend/displaywindow/btactioncollection.h b/src/frontend/displaywindow/btactioncollection.h index 48e6b10..4dde538 100644 --- a/src/frontend/displaywindow/btactioncollection.h +++ b/src/frontend/displaywindow/btactioncollection.h @@ -19,24 +19,23 @@ class QAction; class QKeySequence; class BtActionItem; -class BtActionCollection : public QObject -{ - Q_OBJECT -public: - BtActionCollection(QObject* parent); - ~BtActionCollection(); - QAction* addAction(const QString& name, QAction* action); - QAction* addAction(const QString &name, const QObject *receiver, const char* member=0); - QList<QAction*> actions(); - QAction* action(const QString& name); - void setConfigGroup(const QString &group); - void readSettings(); - void writeSettings(); - QKeySequence getDefaultShortcut(QAction* action); +class BtActionCollection : public QObject { + Q_OBJECT + public: + BtActionCollection(QObject* parent); + ~BtActionCollection(); + QAction* addAction(const QString& name, QAction* action); + QAction* addAction(const QString &name, const QObject *receiver, const char* member = 0); + QList<QAction*> actions(); + QAction* action(const QString& name); + void setConfigGroup(const QString &group); + void readSettings(); + void writeSettings(); + QKeySequence getDefaultShortcut(QAction* action); -private: - QMap<QString, BtActionItem*> m_actions; - QString m_groupName; + private: + QMap<QString, BtActionItem*> m_actions; + QString m_groupName; }; #endif diff --git a/src/frontend/displaywindow/bttoolbarpopupaction.cpp b/src/frontend/displaywindow/bttoolbarpopupaction.cpp index ffa672a..5a7fd8c 100644 --- a/src/frontend/displaywindow/bttoolbarpopupaction.cpp +++ b/src/frontend/displaywindow/bttoolbarpopupaction.cpp @@ -13,66 +13,56 @@ #include <QAction> #include <QEvent> -class BtToolButton : public QToolButton -{ -public: - BtToolButton(QWidget* parent=0) : QToolButton(parent) - { - } -private: - void nextCheckState() - { - } +class BtToolButton : public QToolButton { + public: + BtToolButton(QWidget* parent = 0) : QToolButton(parent) { + } + private: + void nextCheckState() { + } }; // This class provides a toolbar widget that has a icon plus a right side down arrow -// The icon is typically set to a back or forward arrow and the down arrow has a popup -// menu when clicked. The menu is typicallly populated with history actions. +// The icon is typically set to a back or forward arrow and the down arrow has a popup +// menu when clicked. The menu is typicallly populated with history actions. BtToolBarPopupAction::BtToolBarPopupAction(const QIcon& icon, const QString& text, QObject* parent) - : QWidgetAction(parent), m_icon(icon), m_text(text) -{ - setText(text); - m_menu = new QMenu(); + : QWidgetAction(parent), m_icon(icon), m_text(text) { + setText(text); + m_menu = new QMenu(); } -BtToolBarPopupAction::~BtToolBarPopupAction() -{ - delete m_menu; +BtToolBarPopupAction::~BtToolBarPopupAction() { + delete m_menu; } // return the QMenu object so a popup menu can be constructed -QMenu* BtToolBarPopupAction::popupMenu() const -{ - return m_menu; +QMenu* BtToolBarPopupAction::popupMenu() const { + return m_menu; } -QWidget* BtToolBarPopupAction::createWidget(QWidget* parent) -{ - m_button = new BtToolButton(parent); - setIcon(m_icon); - setToolTip(m_text); - m_button->setDefaultAction(this); - m_button->setPopupMode(QToolButton::MenuButtonPopup); - m_button->setMenu(m_menu); - bool ok = connect(m_button, SIGNAL(pressed()), this, SLOT(buttonPressed())); - Q_ASSERT(ok);; - return m_button; +QWidget* BtToolBarPopupAction::createWidget(QWidget* parent) { + m_button = new BtToolButton(parent); + setIcon(m_icon); + setToolTip(m_text); + m_button->setDefaultAction(this); + m_button->setPopupMode(QToolButton::MenuButtonPopup); + m_button->setMenu(m_menu); + bool ok = connect(m_button, SIGNAL(pressed()), this, SLOT(buttonPressed())); + Q_ASSERT(ok);; + return m_button; } // Slot to emit a triggered signal when the toolbar button is pressed -void BtToolBarPopupAction::buttonPressed() -{ - emit triggered(); +void BtToolBarPopupAction::buttonPressed() { + emit triggered(); } // Function to catch the Shortcut event and emit the triggered signal -bool BtToolBarPopupAction::event(QEvent *event) -{ - if (event->type() == QEvent::Shortcut) - { - emit triggered(); - return true; - } - return QWidgetAction::event(event); +bool BtToolBarPopupAction::event(QEvent *event) { + if (event->type() == QEvent::Shortcut) { + emit triggered(); + return true; + } + return QWidgetAction::event(event); } diff --git a/src/frontend/displaywindow/bttoolbarpopupaction.h b/src/frontend/displaywindow/bttoolbarpopupaction.h index 7615c02..06eb660 100644 --- a/src/frontend/displaywindow/bttoolbarpopupaction.h +++ b/src/frontend/displaywindow/bttoolbarpopupaction.h @@ -17,36 +17,35 @@ class QIcon; class QToolButton; // This class manages the toolbar display for going forward and backward in history. -class BtToolBarPopupAction : public QWidgetAction -{ - Q_OBJECT -public: +class BtToolBarPopupAction : public QWidgetAction { + Q_OBJECT + public: - BtToolBarPopupAction(const QIcon& icon, const QString& text, QObject* parent); - ~BtToolBarPopupAction(); + BtToolBarPopupAction(const QIcon& icon, const QString& text, QObject* parent); + ~BtToolBarPopupAction(); // return the QMenu object so a popup menu can be constructed - QMenu* popupMenu() const; + QMenu* popupMenu() const; // Function to catch the Shortcut event and emit the triggered signal - virtual bool event(QEvent* e); - -signals: - void triggered(); + virtual bool event(QEvent* e); -protected: - QWidget* createWidget(QWidget* parent); + signals: + void triggered(); -private slots: + protected: + QWidget* createWidget(QWidget* parent); + + private slots: // Slot to emit a triggered signal when the toolbar button is pressed - void buttonPressed(); + void buttonPressed(); -private: - QMenu* m_menu; - QToolButton* m_button; - QIcon m_icon; - QString m_text; + private: + QMenu* m_menu; + QToolButton* m_button; + QIcon m_icon; + QString m_text; }; #endif diff --git a/src/frontend/displaywindow/cbiblereadwindow.cpp b/src/frontend/displaywindow/cbiblereadwindow.cpp index 9b59544..2da6360 100644 --- a/src/frontend/displaywindow/cbiblereadwindow.cpp +++ b/src/frontend/displaywindow/cbiblereadwindow.cpp @@ -40,94 +40,85 @@ using namespace Profile; CBibleReadWindow::CBibleReadWindow(QList<CSwordModuleInfo*> moduleList, CMDIArea* parent) - : CLexiconReadWindow(moduleList, parent) -{ - qDebug("CBibleReadWindow::CBibleReadWindow"); + : CLexiconReadWindow(moduleList, parent) { + qDebug("CBibleReadWindow::CBibleReadWindow"); } -CBibleReadWindow::~CBibleReadWindow() -{ +CBibleReadWindow::~CBibleReadWindow() { } -void CBibleReadWindow::applyProfileSettings( CProfileWindow* const settings ) -{ - 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(); +void CBibleReadWindow::applyProfileSettings( CProfileWindow* const settings ) { + 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(); } -void CBibleReadWindow::storeProfileSettings( CProfileWindow* const settings ) -{ - CLexiconReadWindow::storeProfileSettings(settings); - - 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); +void CBibleReadWindow::storeProfileSettings( CProfileWindow* const settings ) { + CLexiconReadWindow::storeProfileSettings(settings); + + 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); } /** Reimplementation. */ -void CBibleReadWindow::insertKeyboardActions( BtActionCollection* const a ) -{ - QAction* qaction; - - qaction = new QAction(tr("Next book"), a); - qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextBook::accel); - a->addAction("nextBook", qaction); - - qaction = new QAction(tr("Previous book"), a); - qaction->setShortcut( CResMgr::displaywindows::bibleWindow::previousBook::accel); - a->addAction("previousBook", qaction); - - qaction = new QAction(tr("Next chapter"), a); - qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextChapter::accel); - a->addAction("nextChapter", qaction); - - qaction = new QAction(tr("Previous chapter"), a); - qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousChapter::accel); - a->addAction("previousChapter", qaction); - - qaction = new QAction(tr("Next verse"), a); - qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextVerse::accel); - a->addAction("nextVerse", qaction); - - qaction = new QAction(tr("Previous verse"), a); - qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousVerse::accel); - a->addAction("previousVerse", qaction); - - //popup menu items - qaction = new QAction(tr("Copy chapter"), a); - a->addAction("copyChapter", qaction); - - qaction = new QAction(tr("Save chapter as plain text"), a); - a->addAction("saveChapterAsPlainText", qaction); - - qaction = new QAction(tr("Save chapter as HTML"), a); - a->addAction("saveChapterAsHTML", qaction); - - qaction = new QAction(tr("Print chapter"), a); - qaction->setShortcut(QKeySequence::Print); - a->addAction("printChapter", qaction); +void CBibleReadWindow::insertKeyboardActions( BtActionCollection* const a ) { + QAction* qaction; + + qaction = new QAction(tr("Next book"), a); + qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextBook::accel); + a->addAction("nextBook", qaction); + + qaction = new QAction(tr("Previous book"), a); + qaction->setShortcut( CResMgr::displaywindows::bibleWindow::previousBook::accel); + a->addAction("previousBook", qaction); + + qaction = new QAction(tr("Next chapter"), a); + qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextChapter::accel); + a->addAction("nextChapter", qaction); + + qaction = new QAction(tr("Previous chapter"), a); + qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousChapter::accel); + a->addAction("previousChapter", qaction); + + qaction = new QAction(tr("Next verse"), a); + qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextVerse::accel); + a->addAction("nextVerse", qaction); + + qaction = new QAction(tr("Previous verse"), a); + qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousVerse::accel); + a->addAction("previousVerse", qaction); + + //popup menu items + qaction = new QAction(tr("Copy chapter"), a); + a->addAction("copyChapter", qaction); + + qaction = new QAction(tr("Save chapter as plain text"), a); + a->addAction("saveChapterAsPlainText", qaction); + + qaction = new QAction(tr("Save chapter as HTML"), a); + a->addAction("saveChapterAsHTML", qaction); + + qaction = new QAction(tr("Print chapter"), a); + qaction->setShortcut(QKeySequence::Print); + a->addAction("printChapter", qaction); // qaction = new QAction( /* QIcon(CResMgr::displaywindows::general::findStrongs::icon), */ tr("Strong's search"), a); // qaction->setShortcut(CResMgr::displaywindows::general::findStrongs::accel); @@ -137,356 +128,327 @@ void CBibleReadWindow::insertKeyboardActions( BtActionCollection* const a ) // qaction = new QAction(tr("Reference only"), a ); // a->addAction("copyReferenceOnly", qaction); - qaction = new QAction(tr("Text of reference"), a); - a->addAction("copyTextOfReference", qaction); + qaction = new QAction(tr("Text of reference"), a); + a->addAction("copyTextOfReference", qaction); - qaction = new QAction(tr("Reference with text"), a); - a->addAction( "copyReferenceWithText", qaction); + qaction = new QAction(tr("Reference with text"), a); + a->addAction( "copyReferenceWithText", qaction); - qaction = new QAction(tr("Reference with text"), a); - a->addAction("saveReferenceWithText", qaction); + qaction = new QAction(tr("Reference with text"), a); + a->addAction("saveReferenceWithText", qaction); } -void CBibleReadWindow::initActions() -{ - qDebug("CBibleReadWindow::initActions"); +void CBibleReadWindow::initActions() { + qDebug("CBibleReadWindow::initActions"); - BtActionCollection* ac = actionCollection(); + BtActionCollection* ac = actionCollection(); - CLexiconReadWindow::initActions(); //make sure the predefined actions are available + CLexiconReadWindow::initActions(); //make sure the predefined actions are available - CBibleReadWindow::insertKeyboardActions(ac); + CBibleReadWindow::insertKeyboardActions(ac); - //cleanup, not a clean oo-solution - ac->action("nextEntry")->setEnabled(false); - ac->action("previousEntry")->setEnabled(false); + //cleanup, not a clean oo-solution + ac->action("nextEntry")->setEnabled(false); + ac->action("previousEntry")->setEnabled(false); - QAction* qaction; + QAction* qaction; - qaction = m_actionCollection->action("nextBook"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextBook()) ); - addAction(qaction); + qaction = m_actionCollection->action("nextBook"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextBook()) ); + addAction(qaction); - qaction = m_actionCollection->action("previousBook"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousBook()) ); - addAction(qaction); + qaction = m_actionCollection->action("previousBook"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousBook()) ); + addAction(qaction); - qaction = m_actionCollection->action("nextChapter"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextChapter()) ); - addAction(qaction); + qaction = m_actionCollection->action("nextChapter"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextChapter()) ); + addAction(qaction); - qaction = m_actionCollection->action("previousChapter"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousChapter()) ); - addAction(qaction); + qaction = m_actionCollection->action("previousChapter"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousChapter()) ); + addAction(qaction); - qaction = m_actionCollection->action("nextVerse"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextVerse()) ); - addAction(qaction); + qaction = m_actionCollection->action("nextVerse"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextVerse()) ); + addAction(qaction); - qaction = m_actionCollection->action("previousVerse"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousVerse()) ); - addAction(qaction); + qaction = m_actionCollection->action("previousVerse"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousVerse()) ); + addAction(qaction); - m_actions.selectAll = ac->action("selectAll"); - Q_ASSERT(m_actions.selectAll); + m_actions.selectAll = ac->action("selectAll"); + Q_ASSERT(m_actions.selectAll); - m_actions.findText = ac->action("findText"); - Q_ASSERT(m_actions.findText); + m_actions.findText = ac->action("findText"); + Q_ASSERT(m_actions.findText); - m_actions.findStrongs = m_actionCollection->action(CResMgr::displaywindows::general::findStrongs::actionName); + m_actions.findStrongs = m_actionCollection->action(CResMgr::displaywindows::general::findStrongs::actionName); - m_actions.copy.referenceOnly = m_actionCollection->action("copyReferenceOnly"); + m_actions.copy.referenceOnly = m_actionCollection->action("copyReferenceOnly"); - m_actions.copy.referenceTextOnly = m_actionCollection->action("copyTextOfReference"); - QObject::connect(m_actions.copy.referenceTextOnly, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAnchorTextOnly()) ); - addAction(m_actions.copy.referenceTextOnly); + m_actions.copy.referenceTextOnly = m_actionCollection->action("copyTextOfReference"); + QObject::connect(m_actions.copy.referenceTextOnly, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAnchorTextOnly()) ); + addAction(m_actions.copy.referenceTextOnly); - m_actions.copy.referenceAndText = m_actionCollection->action("copyReferenceWithText"); - QObject::connect(m_actions.copy.referenceAndText, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAnchorWithText()) ); - addAction(m_actions.copy.referenceAndText); + m_actions.copy.referenceAndText = m_actionCollection->action("copyReferenceWithText"); + QObject::connect(m_actions.copy.referenceAndText, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAnchorWithText()) ); + addAction(m_actions.copy.referenceAndText); - m_actions.copy.chapter = m_actionCollection->action("copyChapter"); - QObject::connect(m_actions.copy.chapter, SIGNAL(triggered()), this, SLOT(copyDisplayedText()) ); - addAction(m_actions.copy.chapter); + m_actions.copy.chapter = m_actionCollection->action("copyChapter"); + QObject::connect(m_actions.copy.chapter, SIGNAL(triggered()), this, SLOT(copyDisplayedText()) ); + addAction(m_actions.copy.chapter); - m_actions.copy.selectedText = ac->action("copySelectedText"); - Q_ASSERT(m_actions.copy.selectedText); + m_actions.copy.selectedText = ac->action("copySelectedText"); + Q_ASSERT(m_actions.copy.selectedText); - m_actions.save.referenceAndText = m_actionCollection->action("saveReferenceWithText"); - QObject::connect(m_actions.save.referenceAndText, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(saveAnchorWithText()) ); - addAction(m_actions.copy.chapter); + m_actions.save.referenceAndText = m_actionCollection->action("saveReferenceWithText"); + QObject::connect(m_actions.save.referenceAndText, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(saveAnchorWithText()) ); + addAction(m_actions.copy.chapter); - m_actions.save.chapterAsPlain = m_actionCollection->action("saveChapterAsPlainText"); - QObject::connect(m_actions.save.chapterAsPlain, SIGNAL(triggered()), this, SLOT(saveChapterPlain()) ); - addAction(m_actions.save.referenceAndText); + m_actions.save.chapterAsPlain = m_actionCollection->action("saveChapterAsPlainText"); + QObject::connect(m_actions.save.chapterAsPlain, SIGNAL(triggered()), this, SLOT(saveChapterPlain()) ); + addAction(m_actions.save.referenceAndText); - m_actions.save.chapterAsHTML = m_actionCollection->action("saveChapterAsHTML"); - QObject::connect(m_actions.save.chapterAsHTML, SIGNAL(triggered()), this, SLOT(saveChapterHTML()) ); - addAction(m_actions.save.chapterAsHTML); + m_actions.save.chapterAsHTML = m_actionCollection->action("saveChapterAsHTML"); + QObject::connect(m_actions.save.chapterAsHTML, SIGNAL(triggered()), this, SLOT(saveChapterHTML()) ); + addAction(m_actions.save.chapterAsHTML); - m_actions.print.reference = m_actionCollection->action("saveReferenceWithText"); - QObject::connect(m_actions.print.reference, SIGNAL(triggered()), this, SLOT(printAnchorWithText()) ); - addAction(m_actions.print.reference); + m_actions.print.reference = m_actionCollection->action("saveReferenceWithText"); + QObject::connect(m_actions.print.reference, SIGNAL(triggered()), this, SLOT(printAnchorWithText()) ); + addAction(m_actions.print.reference); - m_actions.print.chapter = m_actionCollection->action("printChapter"); - QObject::connect(m_actions.print.chapter, SIGNAL(triggered()), this, SLOT(printAll()) ); - addAction(m_actions.print.chapter); + m_actions.print.chapter = m_actionCollection->action("printChapter"); + QObject::connect(m_actions.print.chapter, SIGNAL(triggered()), this, SLOT(printAll()) ); + addAction(m_actions.print.chapter); - CBTConfig::setupAccelSettings(CBTConfig::bibleWindow, ac); + CBTConfig::setupAccelSettings(CBTConfig::bibleWindow, ac); } -void CBibleReadWindow::initConnections() -{ - CLexiconReadWindow::initConnections(); +void CBibleReadWindow::initConnections() { + CLexiconReadWindow::initConnections(); } -void CBibleReadWindow::initToolbars() -{ - CLexiconReadWindow::initToolbars(); +void CBibleReadWindow::initToolbars() { + CLexiconReadWindow::initToolbars(); } -void CBibleReadWindow::initView() -{ - CLexiconReadWindow::initView(); +void CBibleReadWindow::initView() { + CLexiconReadWindow::initView(); - parentWidget()->installEventFilter(this); + parentWidget()->installEventFilter(this); } /** Reimplementation. */ -void CBibleReadWindow::setupPopupMenu() -{ - popup()->setTitle(tr("Bible window")); - popup()->setIcon(CToolClass::getIconForModule(modules().first()) ); - popup()->addAction(m_actions.findText); - QKeySequence ks = m_actions.findText->shortcut(); - QString keys = ks.toString(); - popup()->addAction(m_actions.findStrongs); - popup()->addAction(m_actions.selectAll); - - popup()->addSeparator(); - - m_actions.copyMenu = new QMenu(tr("Copy..."), popup()); - m_actions.copyMenu->addAction(m_actions.copy.referenceOnly); - m_actions.copyMenu->addAction(m_actions.copy.referenceTextOnly); - m_actions.copyMenu->addAction(m_actions.copy.referenceAndText); - m_actions.copyMenu->addAction(m_actions.copy.chapter); - - m_actions.copyMenu->addSeparator(); - - m_actions.copyMenu->addAction(m_actions.copy.selectedText); - popup()->addMenu(m_actions.copyMenu); - - m_actions.saveMenu = new QMenu(tr("Save..."), popup()); - m_actions.saveMenu->addAction(m_actions.save.referenceAndText); - m_actions.saveMenu->addAction(m_actions.save.chapterAsPlain); - m_actions.saveMenu->addAction(m_actions.save.chapterAsHTML); - - // Save raw HTML action for debugging purposes - if (qApp->property("--debug").toBool()) - { - QAction* debugAction = new QAction("Raw HTML", this); - QObject::connect(debugAction, SIGNAL(triggered()), this, SLOT(saveRawHTML())); - m_actions.saveMenu->addAction(debugAction); - } // end of Save Raw HTML - popup()->addMenu(m_actions.saveMenu); - - m_actions.printMenu = new QMenu(tr("Print..."), popup()); - m_actions.printMenu->addAction(m_actions.print.reference); - m_actions.printMenu->addAction(m_actions.print.chapter); - popup()->addMenu(m_actions.printMenu); +void CBibleReadWindow::setupPopupMenu() { + popup()->setTitle(tr("Bible window")); + popup()->setIcon(CToolClass::getIconForModule(modules().first()) ); + popup()->addAction(m_actions.findText); + QKeySequence ks = m_actions.findText->shortcut(); + QString keys = ks.toString(); + popup()->addAction(m_actions.findStrongs); + popup()->addAction(m_actions.selectAll); + + popup()->addSeparator(); + + m_actions.copyMenu = new QMenu(tr("Copy..."), popup()); + m_actions.copyMenu->addAction(m_actions.copy.referenceOnly); + m_actions.copyMenu->addAction(m_actions.copy.referenceTextOnly); + m_actions.copyMenu->addAction(m_actions.copy.referenceAndText); + m_actions.copyMenu->addAction(m_actions.copy.chapter); + + m_actions.copyMenu->addSeparator(); + + m_actions.copyMenu->addAction(m_actions.copy.selectedText); + popup()->addMenu(m_actions.copyMenu); + + m_actions.saveMenu = new QMenu(tr("Save..."), popup()); + m_actions.saveMenu->addAction(m_actions.save.referenceAndText); + m_actions.saveMenu->addAction(m_actions.save.chapterAsPlain); + m_actions.saveMenu->addAction(m_actions.save.chapterAsHTML); + + // Save raw HTML action for debugging purposes + if (qApp->property("--debug").toBool()) { + QAction* debugAction = new QAction("Raw HTML", this); + QObject::connect(debugAction, SIGNAL(triggered()), this, SLOT(saveRawHTML())); + m_actions.saveMenu->addAction(debugAction); + } // end of Save Raw HTML + popup()->addMenu(m_actions.saveMenu); + + m_actions.printMenu = new QMenu(tr("Print..."), popup()); + m_actions.printMenu->addAction(m_actions.print.reference); + m_actions.printMenu->addAction(m_actions.print.chapter); + popup()->addMenu(m_actions.printMenu); } /** Reimplemented. */ -void CBibleReadWindow::updatePopupMenu() -{ - qWarning("CBibleReadWindow::updatePopupMenu()"); +void CBibleReadWindow::updatePopupMenu() { + qWarning("CBibleReadWindow::updatePopupMenu()"); + + m_actions.findStrongs->setEnabled( displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != QString::null ); - m_actions.findStrongs->setEnabled( displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != QString::null ); - - m_actions.copy.referenceOnly->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); - m_actions.copy.referenceTextOnly->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); - m_actions.copy.referenceAndText->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); - m_actions.copy.selectedText->setEnabled( ((CReadDisplay*)displayWidget())->hasSelection() ); + m_actions.copy.referenceOnly->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); + m_actions.copy.referenceTextOnly->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); + m_actions.copy.referenceAndText->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); + m_actions.copy.selectedText->setEnabled( ((CReadDisplay*)displayWidget())->hasSelection() ); - m_actions.save.referenceAndText->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); + m_actions.save.referenceAndText->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); - m_actions.print.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); + m_actions.print.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); } /** Moves to the next book. */ -void CBibleReadWindow::nextBook() -{ - if (verseKey()->next(CSwordVerseKey::UseBook)) - { - keyChooser()->setKey(key()); - } +void CBibleReadWindow::nextBook() { + if (verseKey()->next(CSwordVerseKey::UseBook)) { + keyChooser()->setKey(key()); + } } /** Moves one book behind. */ void CBibleReadWindow::previousBook() { - if (verseKey()->previous(CSwordVerseKey::UseBook)) - { - keyChooser()->setKey(key()); - } + if (verseKey()->previous(CSwordVerseKey::UseBook)) { + keyChooser()->setKey(key()); + } } /** Moves to the next book. */ -void CBibleReadWindow::nextChapter() -{ - if (verseKey()->next(CSwordVerseKey::UseChapter)) - { - keyChooser()->setKey(key()); - } +void CBibleReadWindow::nextChapter() { + if (verseKey()->next(CSwordVerseKey::UseChapter)) { + keyChooser()->setKey(key()); + } } /** Moves one book behind. */ -void CBibleReadWindow::previousChapter() -{ - if (verseKey()->previous(CSwordVerseKey::UseChapter)) - { - keyChooser()->setKey(key()); - } +void CBibleReadWindow::previousChapter() { + if (verseKey()->previous(CSwordVerseKey::UseChapter)) { + keyChooser()->setKey(key()); + } } /** Moves to the next book. */ -void CBibleReadWindow::nextVerse() -{ - if (verseKey()->next(CSwordVerseKey::UseVerse)) - { - keyChooser()->setKey(key()); - } +void CBibleReadWindow::nextVerse() { + if (verseKey()->next(CSwordVerseKey::UseVerse)) { + keyChooser()->setKey(key()); + } } /** Moves one book behind. */ -void CBibleReadWindow::previousVerse() -{ - if (verseKey()->previous(CSwordVerseKey::UseVerse)) - { - keyChooser()->setKey(key()); - } +void CBibleReadWindow::previousVerse() { + if (verseKey()->previous(CSwordVerseKey::UseVerse)) { + keyChooser()->setKey(key()); + } } /** rapper around key() to return the right type of key. */ -CSwordVerseKey* CBibleReadWindow::verseKey() -{ - CSwordVerseKey* k = dynamic_cast<CSwordVerseKey*>(CDisplayWindow::key()); - Q_ASSERT(k); - - return k; +CSwordVerseKey* CBibleReadWindow::verseKey() { + CSwordVerseKey* k = dynamic_cast<CSwordVerseKey*>(CDisplayWindow::key()); + Q_ASSERT(k); + + return k; } /** Copies the current chapter into the clipboard. */ -void CBibleReadWindow::copyDisplayedText() -{ - CSwordVerseKey dummy(*verseKey()); - dummy.Verse(1); +void CBibleReadWindow::copyDisplayedText() { + CSwordVerseKey dummy(*verseKey()); + dummy.Verse(1); - CSwordVerseKey vk(*verseKey()); - vk.LowerBound(dummy); + CSwordVerseKey vk(*verseKey()); + vk.LowerBound(dummy); - CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first()); - dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter())); - vk.UpperBound(dummy); + CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first()); + dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter())); + vk.UpperBound(dummy); - CExportManager mgr(tr("Copy chapter to clipboard ..."), false, tr("Copying"), filterOptions(), displayOptions()); - mgr.copyKey(&vk, CExportManager::Text, true); + CExportManager mgr(tr("Copy chapter to clipboard ..."), false, tr("Copying"), filterOptions(), displayOptions()); + mgr.copyKey(&vk, CExportManager::Text, true); } /** Saves the chapter as valid HTML page. */ -void CBibleReadWindow::saveChapterHTML() -{ - //saves the complete chapter to disk - CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first()); - Q_ASSERT(bible); - if (!bible) //shouldn't happen - return; +void CBibleReadWindow::saveChapterHTML() { + //saves the complete chapter to disk + CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first()); + Q_ASSERT(bible); + if (!bible) //shouldn't happen + return; - CSwordVerseKey dummy(*verseKey()); - dummy.Verse(1); + CSwordVerseKey dummy(*verseKey()); + dummy.Verse(1); - CSwordVerseKey vk(*verseKey()); - vk.LowerBound(dummy); + CSwordVerseKey vk(*verseKey()); + vk.LowerBound(dummy); - dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter())); - vk.UpperBound(dummy); + dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter())); + vk.UpperBound(dummy); - CExportManager mgr(tr("Saving chapter ..."), true, tr("Saving"), filterOptions(), displayOptions()); - mgr.saveKey(&vk, CExportManager::HTML, true); + CExportManager mgr(tr("Saving chapter ..."), true, tr("Saving"), filterOptions(), displayOptions()); + mgr.saveKey(&vk, CExportManager::HTML, true); } /** Saves the chapter as valid HTML page. */ -void CBibleReadWindow::saveChapterPlain() -{ - //saves the complete chapter to disk +void CBibleReadWindow::saveChapterPlain() { + //saves the complete chapter to disk - CSwordVerseKey vk(*verseKey()); - CSwordVerseKey dummy(*verseKey()); + CSwordVerseKey vk(*verseKey()); + CSwordVerseKey dummy(*verseKey()); - dummy.Verse(1); - vk.LowerBound(dummy); + dummy.Verse(1); + vk.LowerBound(dummy); - CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first()); - dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter())); - vk.UpperBound(dummy); + CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(modules().first()); + dummy.Verse(bible->verseCount(dummy.book(), dummy.Chapter())); + vk.UpperBound(dummy); - CExportManager mgr(tr("Saving chapter ..."), true, tr("Saving"), filterOptions(),displayOptions()); - mgr.saveKey(&vk, CExportManager::Text, true); + CExportManager mgr(tr("Saving chapter ..."), true, tr("Saving"), filterOptions(), displayOptions()); + mgr.saveKey(&vk, CExportManager::Text, true); } -void CBibleReadWindow::reload(CSwordBackend::SetupChangedReason reason) -{ - CLexiconReadWindow::reload(reason); +void CBibleReadWindow::reload(CSwordBackend::SetupChangedReason reason) { + CLexiconReadWindow::reload(reason); - if (m_modules.count() == 0) - { - close(); - return; - } + if (m_modules.count() == 0) { + close(); + return; + } - //refresh the book lists - verseKey()->setLocale( backend()->booknameLanguage().toLatin1() ); - keyChooser()->refreshContent(); + //refresh the book lists + verseKey()->setLocale( backend()->booknameLanguage().toLatin1() ); + keyChooser()->refreshContent(); - CBTConfig::setupAccelSettings(CBTConfig::bibleWindow, actionCollection()); + CBTConfig::setupAccelSettings(CBTConfig::bibleWindow, actionCollection()); } /** No descriptions */ -bool CBibleReadWindow::eventFilter( QObject* o, QEvent* e) -{ - const bool ret = CLexiconReadWindow::eventFilter(o,e); - - // Q_ASSERT(o->inherits("CDisplayWindow")); - // qWarning("class: %s", o->className()); - if (e && (e->type() == QEvent::FocusIn)) - { //sync other windows to this active - - /* This is a hack to work around a KHTML problem (similair to the Drag&Drop problem we had): - * If new HTML content is loaded from inside a kHTML event handler - * the widget's state will be confused, i.e. it's scrolling without having - * the mousebutton clicked. - * - * This is not really in a KHTML event handler but works anyway. - * Sometime KDE/Qt is hard to use ... - */ - QTimer::singleShot(0, this, SLOT(syncWindows())); - } - - return ret; +bool CBibleReadWindow::eventFilter( QObject* o, QEvent* e) { + const bool ret = CLexiconReadWindow::eventFilter(o, e); + + // Q_ASSERT(o->inherits("CDisplayWindow")); + // qWarning("class: %s", o->className()); + if (e && (e->type() == QEvent::FocusIn)) { //sync other windows to this active + + /* This is a hack to work around a KHTML problem (similair to the Drag&Drop problem we had): + * If new HTML content is loaded from inside a kHTML event handler + * the widget's state will be confused, i.e. it's scrolling without having + * the mousebutton clicked. + * + * This is not really in a KHTML event handler but works anyway. + * Sometime KDE/Qt is hard to use ... + */ + QTimer::singleShot(0, this, SLOT(syncWindows())); + } + + return ret; } -void CBibleReadWindow::lookupSwordKey( CSwordKey* newKey ) -{ - CLexiconReadWindow::lookupSwordKey(newKey); - syncWindows(); +void CBibleReadWindow::lookupSwordKey( CSwordKey* newKey ) { + CLexiconReadWindow::lookupSwordKey(newKey); + syncWindows(); } -void CBibleReadWindow::syncWindows() -{ - foreach (QMdiSubWindow* subWindow, mdi()->subWindowList()) - { - CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(subWindow->widget()); - if (w && w->syncAllowed()) { - w->lookupKey( key()->key() ); - } - } +void CBibleReadWindow::syncWindows() { + foreach (QMdiSubWindow* subWindow, mdi()->subWindowList()) { + CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(subWindow->widget()); + if (w && w->syncAllowed()) { + w->lookupKey( key()->key() ); + } + } } diff --git a/src/frontend/displaywindow/cbiblereadwindow.h b/src/frontend/displaywindow/cbiblereadwindow.h index 3a5f64f..3b779e2 100644 --- a/src/frontend/displaywindow/cbiblereadwindow.h +++ b/src/frontend/displaywindow/cbiblereadwindow.h @@ -35,110 +35,110 @@ class QEvent; */ class CBibleReadWindow : public CLexiconReadWindow { - Q_OBJECT -public: - CBibleReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); - virtual ~CBibleReadWindow(); - /** - * Store the settings of this window in the given CProfileWindow object. - */ - virtual void storeProfileSettings( Profile::CProfileWindow* const settings ); - /** - * Store the settings of this window in the given profile window. - */ - virtual void applyProfileSettings( Profile::CProfileWindow* const settings ); - /** - * Reimplementation. - */ - static void insertKeyboardActions( BtActionCollection* const a ); - -protected: - virtual void initActions(); - virtual void initToolbars(); - virtual void initConnections(); - virtual void initView(); - /** - * Reimplementation. - */ - virtual void setupPopupMenu(); - /** - * Reimplemented. - */ - virtual void updatePopupMenu(); - /** Event filter. - * Reimplementation of the event filter to filter out events like focus in. - */ - virtual bool eventFilter( QObject* o, QEvent* e); - - struct { - QAction* selectAll; - QAction* findText; - QAction* findStrongs; - - QMenu* copyMenu; - struct { - QAction* referenceOnly; - QAction* referenceTextOnly; - QAction* referenceAndText; - QAction* chapter; - QAction* selectedText; - } - copy; - - QMenu* saveMenu; - struct { - QAction* referenceAndText; - QAction* chapterAsPlain; - QAction* chapterAsHTML; - } - save; - - QMenu* printMenu; - struct { - QAction* reference; - QAction* chapter; - } - print; - } - m_actions; - - -public slots: - void nextBook(); - void previousBook(); - void nextChapter(); - void previousChapter(); - void nextVerse(); - void previousVerse(); - /** - * Refreshes the content of this display window and the content of the keychooser. - */ - virtual void reload(CSwordBackend::SetupChangedReason reason); - -protected slots: // Protected slots - /** - * Copies the current chapter into the clipboard. - */ - void copyDisplayedText(); - /** - * Saves the chapter as valid HTML page. - */ - void saveChapterHTML(); - /** - * Saves the chapter as valid HTML page. - */ - void saveChapterPlain(); - virtual void lookupSwordKey( CSwordKey* newKey ); - void syncWindows(); - -private: - friend class CCommentaryReadWindow; - /** - * Wrapper around key() to return the right type of key. - */ - CSwordVerseKey* verseKey(); - - // CTransliterationButton* m_transliterationButton; + Q_OBJECT + public: + CBibleReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); + virtual ~CBibleReadWindow(); + /** + * Store the settings of this window in the given CProfileWindow object. + */ + virtual void storeProfileSettings( Profile::CProfileWindow* const settings ); + /** + * Store the settings of this window in the given profile window. + */ + virtual void applyProfileSettings( Profile::CProfileWindow* const settings ); + /** + * Reimplementation. + */ + static void insertKeyboardActions( BtActionCollection* const a ); + + protected: + virtual void initActions(); + virtual void initToolbars(); + virtual void initConnections(); + virtual void initView(); + /** + * Reimplementation. + */ + virtual void setupPopupMenu(); + /** + * Reimplemented. + */ + virtual void updatePopupMenu(); + /** Event filter. + * Reimplementation of the event filter to filter out events like focus in. + */ + virtual bool eventFilter( QObject* o, QEvent* e); + + struct { + QAction* selectAll; + QAction* findText; + QAction* findStrongs; + + QMenu* copyMenu; + struct { + QAction* referenceOnly; + QAction* referenceTextOnly; + QAction* referenceAndText; + QAction* chapter; + QAction* selectedText; + } + copy; + + QMenu* saveMenu; + struct { + QAction* referenceAndText; + QAction* chapterAsPlain; + QAction* chapterAsHTML; + } + save; + + QMenu* printMenu; + struct { + QAction* reference; + QAction* chapter; + } + print; + } + m_actions; + + + public slots: + void nextBook(); + void previousBook(); + void nextChapter(); + void previousChapter(); + void nextVerse(); + void previousVerse(); + /** + * Refreshes the content of this display window and the content of the keychooser. + */ + virtual void reload(CSwordBackend::SetupChangedReason reason); + + protected slots: // Protected slots + /** + * Copies the current chapter into the clipboard. + */ + void copyDisplayedText(); + /** + * Saves the chapter as valid HTML page. + */ + void saveChapterHTML(); + /** + * Saves the chapter as valid HTML page. + */ + void saveChapterPlain(); + virtual void lookupSwordKey( CSwordKey* newKey ); + void syncWindows(); + + private: + friend class CCommentaryReadWindow; + /** + * Wrapper around key() to return the right type of key. + */ + CSwordVerseKey* verseKey(); + + // CTransliterationButton* m_transliterationButton; }; #endif diff --git a/src/frontend/displaywindow/cbookreadwindow.cpp b/src/frontend/displaywindow/cbookreadwindow.cpp index 465eec9..1865a98 100644 --- a/src/frontend/displaywindow/cbookreadwindow.cpp +++ b/src/frontend/displaywindow/cbookreadwindow.cpp @@ -27,151 +27,137 @@ using namespace Profile; -CBookReadWindow::CBookReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent) - : CLexiconReadWindow(modules, parent), m_treeAction(0), m_treeChooser(0) -{ +CBookReadWindow::CBookReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent) + : CLexiconReadWindow(modules, parent), m_treeAction(0), m_treeChooser(0) { } -CBookReadWindow::~CBookReadWindow() -{ +CBookReadWindow::~CBookReadWindow() { } -void CBookReadWindow::applyProfileSettings( CProfileWindow* profileWindow ) -{ - CLexiconReadWindow::applyProfileSettings(profileWindow); +void CBookReadWindow::applyProfileSettings( CProfileWindow* profileWindow ) { + CLexiconReadWindow::applyProfileSettings(profileWindow); - const bool enable = static_cast<bool>( profileWindow->windowSettings() ); - if (enable) { - m_treeAction->activate(QAction::Trigger); - } + const bool enable = static_cast<bool>( profileWindow->windowSettings() ); + if (enable) { + m_treeAction->activate(QAction::Trigger); + } } -void CBookReadWindow::storeProfileSettings( CProfileWindow* profileWindow ) -{ - CLexiconReadWindow::storeProfileSettings(profileWindow); +void CBookReadWindow::storeProfileSettings( CProfileWindow* profileWindow ) { + CLexiconReadWindow::storeProfileSettings(profileWindow); - //store information about our show tree structure button - profileWindow->setWindowSettings( static_cast<int>( m_treeAction->isChecked() ) ); + //store information about our show tree structure button + profileWindow->setWindowSettings( static_cast<int>( m_treeAction->isChecked() ) ); } -void CBookReadWindow::initActions() -{ - CLexiconReadWindow::initActions(); - BtActionCollection* ac = actionCollection(); - insertKeyboardActions(ac); +void CBookReadWindow::initActions() { + CLexiconReadWindow::initActions(); + BtActionCollection* ac = actionCollection(); + insertKeyboardActions(ac); - //cleanup, not a clean oo-solution - Q_ASSERT(ac->action("nextEntry")); - Q_ASSERT(ac->action("previousEntry")); - ac->action("nextEntry")->setEnabled(false); - ac->action("previousEntry")->setEnabled(false); + //cleanup, not a clean oo-solution + Q_ASSERT(ac->action("nextEntry")); + Q_ASSERT(ac->action("previousEntry")); + ac->action("nextEntry")->setEnabled(false); + ac->action("previousEntry")->setEnabled(false); - m_treeAction = ac->action("toggleTree"); - QObject::connect(m_treeAction, SIGNAL(triggered()), this, SLOT(treeToggled()) ); - addAction(m_treeAction); + m_treeAction = ac->action("toggleTree"); + QObject::connect(m_treeAction, SIGNAL(triggered()), this, SLOT(treeToggled()) ); + addAction(m_treeAction); - CBTConfig::setupAccelSettings(CBTConfig::bookWindow, ac); + CBTConfig::setupAccelSettings(CBTConfig::bookWindow, ac); } -void CBookReadWindow::insertKeyboardActions( BtActionCollection* const a ) -{ - QAction* qaction; +void CBookReadWindow::insertKeyboardActions( BtActionCollection* const a ) { + QAction* qaction; - qaction = new QAction( /* QIcon(CResMgr::displaywindows::bookWindow::toggleTree::icon), */ - tr("Toggle tree view"), a); - qaction->setCheckable(true); - qaction->setShortcut(CResMgr::displaywindows::bookWindow::toggleTree::accel); - a->addAction("toggleTree", qaction); + qaction = new QAction( /* QIcon(CResMgr::displaywindows::bookWindow::toggleTree::icon), */ + tr("Toggle tree view"), a); + qaction->setCheckable(true); + qaction->setShortcut(CResMgr::displaywindows::bookWindow::toggleTree::accel); + a->addAction("toggleTree", qaction); } /** No descriptions */ -void CBookReadWindow::initConnections() -{ - CLexiconReadWindow::initConnections(); +void CBookReadWindow::initConnections() { + CLexiconReadWindow::initConnections(); - connect(m_treeChooser, SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*))); - connect(m_treeChooser, SIGNAL(keyChanged(CSwordKey*)), keyChooser(), SLOT(updateKey(CSwordKey*))); - connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), m_treeChooser, SLOT(updateKey(CSwordKey*))); + connect(m_treeChooser, SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*))); + connect(m_treeChooser, SIGNAL(keyChanged(CSwordKey*)), keyChooser(), SLOT(updateKey(CSwordKey*))); + connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), m_treeChooser, SLOT(updateKey(CSwordKey*))); } /** Init the view */ -void CBookReadWindow::initView() -{ - QSplitter* splitter = new QSplitter(this); +void CBookReadWindow::initView() { + QSplitter* splitter = new QSplitter(this); - setMainToolBar( new QToolBar(this) ); - mainToolBar()->setAllowedAreas(Qt::TopToolBarArea); - mainToolBar()->setFloatable(false); + setMainToolBar( new QToolBar(this) ); + mainToolBar()->setAllowedAreas(Qt::TopToolBarArea); + mainToolBar()->setFloatable(false); - addToolBar(mainToolBar()); + addToolBar(mainToolBar()); - m_treeChooser = new CBookTreeChooser(modules(), key(), splitter); - setDisplayWidget( CDisplay::createReadInstance(this, splitter) ); + m_treeChooser = new CBookTreeChooser(modules(), key(), splitter); + setDisplayWidget( CDisplay::createReadInstance(this, splitter) ); - setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) ); + setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) ); - setModuleChooserBar( new CModuleChooserBar(modules(), modules().first()->type(), this) ); - moduleChooserBar()->setButtonLimit(1); - addToolBar(moduleChooserBar()); + setModuleChooserBar( new CModuleChooserBar(modules(), modules().first()->type(), this) ); + moduleChooserBar()->setButtonLimit(1); + addToolBar(moduleChooserBar()); - setButtonsToolBar( new QToolBar(this) ); - buttonsToolBar()->setAllowedAreas(Qt::TopToolBarArea); - buttonsToolBar()->setFloatable(false); - setDisplaySettingsButton( new CDisplaySettingsButton( &displayOptions(), &filterOptions(), modules(), buttonsToolBar()) ); - addToolBar(buttonsToolBar()); - m_treeChooser->hide(); + setButtonsToolBar( new QToolBar(this) ); + buttonsToolBar()->setAllowedAreas(Qt::TopToolBarArea); + buttonsToolBar()->setFloatable(false); + setDisplaySettingsButton( new CDisplaySettingsButton( &displayOptions(), &filterOptions(), modules(), buttonsToolBar()) ); + addToolBar(buttonsToolBar()); + m_treeChooser->hide(); - setCentralWidget( splitter ); - setWindowIcon(CToolClass::getIconForModule(modules().first())); + setCentralWidget( splitter ); + setWindowIcon(CToolClass::getIconForModule(modules().first())); } -void CBookReadWindow::initToolbars() -{ - Q_ASSERT(m_treeAction); - Q_ASSERT(m_actions.backInHistory); +void CBookReadWindow::initToolbars() { + Q_ASSERT(m_treeAction); + Q_ASSERT(m_actions.backInHistory); - mainToolBar()->addAction(m_actions.backInHistory); - mainToolBar()->addAction(m_actions.forwardInHistory); + mainToolBar()->addAction(m_actions.backInHistory); + mainToolBar()->addAction(m_actions.forwardInHistory); - mainToolBar()->addWidget(keyChooser()); + mainToolBar()->addWidget(keyChooser()); - buttonsToolBar()->addAction(m_treeAction); - m_treeAction->setChecked(false); + buttonsToolBar()->addAction(m_treeAction); + m_treeAction->setChecked(false); - buttonsToolBar()->addWidget(displaySettingsButton()); + buttonsToolBar()->addWidget(displaySettingsButton()); - QAction* action = qobject_cast<QAction*>(actionCollection()->action( - CResMgr::displaywindows::general::search::actionName )); - if (action) { - buttonsToolBar()->addAction(action); - } + QAction* action = qobject_cast<QAction*>(actionCollection()->action( + CResMgr::displaywindows::general::search::actionName )); + if (action) { + buttonsToolBar()->addAction(action); + } } /** Is called when the action was executed to toggle the tree view. */ -void CBookReadWindow::treeToggled() -{ - if (m_treeAction->isChecked()) - { - m_treeChooser->show(); - } - else { - m_treeChooser->hide(); - } +void CBookReadWindow::treeToggled() { + if (m_treeAction->isChecked()) { + m_treeChooser->show(); + } + else { + m_treeChooser->hide(); + } } /** Reimplementation to take care of the tree chooser. */ -void CBookReadWindow::modulesChanged() -{ - CLexiconReadWindow::modulesChanged(); - m_treeChooser->setModules(modules()); +void CBookReadWindow::modulesChanged() { + CLexiconReadWindow::modulesChanged(); + m_treeChooser->setModules(modules()); } -void CBookReadWindow::setupPopupMenu() -{ - CLexiconReadWindow::setupPopupMenu(); +void CBookReadWindow::setupPopupMenu() { + CLexiconReadWindow::setupPopupMenu(); } -void CBookReadWindow::reload(CSwordBackend::SetupChangedReason reason) -{ - CLexiconReadWindow::reload(reason); +void CBookReadWindow::reload(CSwordBackend::SetupChangedReason reason) { + CLexiconReadWindow::reload(reason); } diff --git a/src/frontend/displaywindow/cbookreadwindow.h b/src/frontend/displaywindow/cbookreadwindow.h index a2a2219..62d788d 100644 --- a/src/frontend/displaywindow/cbookreadwindow.h +++ b/src/frontend/displaywindow/cbookreadwindow.h @@ -25,51 +25,51 @@ class BtActionCollection; * @author The BibleTime team */ class CBookReadWindow : public CLexiconReadWindow { - Q_OBJECT -public: - static void insertKeyboardActions( BtActionCollection* const a ); - - CBookReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); - - virtual ~CBookReadWindow(); - /** - * Store the settings of this window in the given CProfileWindow object. - */ - virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow ); - /** - * Store the settings of this window in the given profile window. - */ - virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow ); - -public slots: - /** - * Refreshes the content of this display window and the content of the keychooser. - */ - virtual void reload(CSwordBackend::SetupChangedReason reason); - -protected: - virtual void initActions(); - virtual void initToolbars(); - virtual void initConnections(); - virtual void initView(); - - virtual void setupPopupMenu(); - - protected slots: // Protected slots - /** - * Reimplementation to take care of the tree chooser. - */ - virtual void modulesChanged(); - -private: - QAction* m_treeAction; - CBookTreeChooser* m_treeChooser; - -private slots: // Private slots - /** - * Is called when the action was executed to toggle the tree view. - */ - void treeToggled(); + Q_OBJECT + public: + static void insertKeyboardActions( BtActionCollection* const a ); + + CBookReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); + + virtual ~CBookReadWindow(); + /** + * Store the settings of this window in the given CProfileWindow object. + */ + virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow ); + /** + * Store the settings of this window in the given profile window. + */ + virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow ); + + public slots: + /** + * Refreshes the content of this display window and the content of the keychooser. + */ + virtual void reload(CSwordBackend::SetupChangedReason reason); + + protected: + virtual void initActions(); + virtual void initToolbars(); + virtual void initConnections(); + virtual void initView(); + + virtual void setupPopupMenu(); + + protected slots: // Protected slots + /** + * Reimplementation to take care of the tree chooser. + */ + virtual void modulesChanged(); + + private: + QAction* m_treeAction; + CBookTreeChooser* m_treeChooser; + + private slots: // Private slots + /** + * Is called when the action was executed to toggle the tree view. + */ + void treeToggled(); }; #endif diff --git a/src/frontend/displaywindow/cbuttons.cpp b/src/frontend/displaywindow/cbuttons.cpp index 582e5de..fbe2443 100644 --- a/src/frontend/displaywindow/cbuttons.cpp +++ b/src/frontend/displaywindow/cbuttons.cpp @@ -26,166 +26,166 @@ -CDisplaySettingsButton::CDisplaySettingsButton(CSwordBackend::DisplayOptions *displaySettings, CSwordBackend::FilterOptions *moduleSettings, const QList<CSwordModuleInfo*>& useModules,QWidget *parent ) -: QToolButton(parent) { - // qWarning("CDisplaySettingsButton::CDisplaySettingsButton"); - QToolButton::setIcon(util::filesystem::DirectoryUtil::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(); +CDisplaySettingsButton::CDisplaySettingsButton(CSwordBackend::DisplayOptions *displaySettings, CSwordBackend::FilterOptions *moduleSettings, const QList<CSwordModuleInfo*>& useModules, QWidget *parent ) + : QToolButton(parent) { + // qWarning("CDisplaySettingsButton::CDisplaySettingsButton"); + QToolButton::setIcon(util::filesystem::DirectoryUtil::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")); - } + 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*/) { - qDebug("display settings option toggled"); - //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(); + qDebug("display settings option toggled"); + //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; + int ret = 0; - m_popup->clear(); + m_popup->clear(); - // See also optionToggled() + // See also optionToggled() - ret += addMenuEntry(tr("Use linebreaks after each verse"), Linebreak, &m_displaySettings->lineBreaks, (m_modules.first()->type() == CSwordModuleInfo::Bible)); + 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)); + //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("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("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 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 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("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("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 scripture cross-references"), Xref, &m_moduleSettings->scriptureReferences, + isOptionAvailable(CSwordModuleInfo::scriptureReferences )); - ret += addMenuEntry(tr("Show morph segmentation"), Morphseg, &m_moduleSettings->morphSegmentation, - isOptionAvailable(CSwordModuleInfo::morphSegmentation )); + ret += addMenuEntry(tr("Show morph segmentation"), Morphseg, &m_moduleSettings->morphSegmentation, + isOptionAvailable(CSwordModuleInfo::morphSegmentation )); - return ret; + 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; + 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; + 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(); + 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); + 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(); + return m_popup->actions().at(index)->isChecked(); } /** Sets the status to changed. The signal changed will be emitted. */ void CDisplaySettingsButton::setChanged() { - emit sigChanged(); + emit sigChanged(); } diff --git a/src/frontend/displaywindow/cbuttons.h b/src/frontend/displaywindow/cbuttons.h index 6d94c53..5f1d599 100644 --- a/src/frontend/displaywindow/cbuttons.h +++ b/src/frontend/displaywindow/cbuttons.h @@ -26,52 +26,53 @@ class QMenu; * @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); + 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/ccommentaryreadwindow.cpp b/src/frontend/displaywindow/ccommentaryreadwindow.cpp index 7ead206..fdd345e 100644 --- a/src/frontend/displaywindow/ccommentaryreadwindow.cpp +++ b/src/frontend/displaywindow/ccommentaryreadwindow.cpp @@ -27,180 +27,164 @@ using namespace Profile; -CCommentaryReadWindow::CCommentaryReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent) : CLexiconReadWindow(modules, parent) -{ +CCommentaryReadWindow::CCommentaryReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent) : CLexiconReadWindow(modules, parent) { } -void CCommentaryReadWindow::insertKeyboardActions(BtActionCollection* const a) -{ - QAction* qaction; +void CCommentaryReadWindow::insertKeyboardActions(BtActionCollection* const a) { + QAction* qaction; - qaction = new QAction(tr("Next book"), a); - qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextBook::accel); - a->addAction("nextBook", qaction); + qaction = new QAction(tr("Next book"), a); + qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextBook::accel); + a->addAction("nextBook", qaction); - qaction = new QAction(tr("Previous book"), a); - qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousBook::accel); - a->addAction( "previousBook", qaction); + qaction = new QAction(tr("Previous book"), a); + qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousBook::accel); + a->addAction( "previousBook", qaction); - qaction = new QAction(tr("Next chapter"), a); - qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextChapter::accel); - a->addAction("nextChapter", qaction); + qaction = new QAction(tr("Next chapter"), a); + qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextChapter::accel); + a->addAction("nextChapter", qaction); - qaction = new QAction(tr("Previous chapter"), a); - qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousChapter::accel); - a->addAction("previousChapter", qaction); + qaction = new QAction(tr("Previous chapter"), a); + qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousChapter::accel); + a->addAction("previousChapter", qaction); - qaction = new QAction(tr("Next verse"), a); - qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextVerse::accel); - a->addAction("nextVerse", qaction); + qaction = new QAction(tr("Next verse"), a); + qaction->setShortcut(CResMgr::displaywindows::bibleWindow::nextVerse::accel); + a->addAction("nextVerse", qaction); - qaction = new QAction(tr("Previous verse"), a); - qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousVerse::accel); - a->addAction("previousVerse", qaction); + qaction = new QAction(tr("Previous verse"), a); + qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousVerse::accel); + a->addAction("previousVerse", qaction); } -void CCommentaryReadWindow::initActions() -{ - CLexiconReadWindow::initActions(); //make sure the predefined actions are available - BtActionCollection* ac = actionCollection(); - insertKeyboardActions(ac); +void CCommentaryReadWindow::initActions() { + CLexiconReadWindow::initActions(); //make sure the predefined actions are available + BtActionCollection* ac = actionCollection(); + insertKeyboardActions(ac); - //cleanup, not a clean oo-solution - ac->action("nextEntry")->setEnabled(false); - ac->action("previousEntry")->setEnabled(false); + //cleanup, not a clean oo-solution + ac->action("nextEntry")->setEnabled(false); + ac->action("previousEntry")->setEnabled(false); - QAction* qaction; + QAction* qaction; - qaction = ac->action("nextBook"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextBook()) ); - addAction(qaction); + qaction = ac->action("nextBook"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextBook()) ); + addAction(qaction); - qaction = ac->action("previousBook"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousBook()) ); - addAction(qaction); + qaction = ac->action("previousBook"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousBook()) ); + addAction(qaction); - qaction = ac->action("nextChapter"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextChapter()) ); - addAction(qaction); + qaction = ac->action("nextChapter"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextChapter()) ); + addAction(qaction); - qaction = ac->action("previousChapter"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousChapter()) ); - addAction(qaction); + qaction = ac->action("previousChapter"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousChapter()) ); + addAction(qaction); - qaction = ac->action("nextVerse"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextVerse()) ); - addAction(qaction); + qaction = ac->action("nextVerse"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextVerse()) ); + addAction(qaction); - qaction = ac->action("previousVerse"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousVerse()) ); - addAction(qaction); + qaction = ac->action("previousVerse"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousVerse()) ); + addAction(qaction); - CBTConfig::setupAccelSettings(CBTConfig::commentaryWindow, actionCollection()); + CBTConfig::setupAccelSettings(CBTConfig::commentaryWindow, actionCollection()); } -void CCommentaryReadWindow::applyProfileSettings( CProfileWindow* profileWindow ) -{ - CLexiconReadWindow::applyProfileSettings(profileWindow); - if (profileWindow->windowSettings()) { - m_syncButton->setChecked(true); - } +void CCommentaryReadWindow::applyProfileSettings( CProfileWindow* profileWindow ) { + CLexiconReadWindow::applyProfileSettings(profileWindow); + if (profileWindow->windowSettings()) { + m_syncButton->setChecked(true); + } } -void CCommentaryReadWindow::storeProfileSettings( CProfileWindow* profileWindow ) -{ - CLexiconReadWindow::storeProfileSettings(profileWindow); - profileWindow->setWindowSettings( m_syncButton->isChecked() ); +void CCommentaryReadWindow::storeProfileSettings( CProfileWindow* profileWindow ) { + CLexiconReadWindow::storeProfileSettings(profileWindow); + profileWindow->setWindowSettings( m_syncButton->isChecked() ); } -void CCommentaryReadWindow::initToolbars() -{ - CLexiconReadWindow::initToolbars(); +void CCommentaryReadWindow::initToolbars() { + CLexiconReadWindow::initToolbars(); - m_syncButton = new QAction( - QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon)), - tr("Synchronize"), - actionCollection() - ); - m_syncButton->setCheckable(true); - m_syncButton->setShortcut(CResMgr::displaywindows::commentaryWindow::syncWindow::accel); - m_syncButton->setToolTip(tr("Synchronize the displayed entry of this work with the active Bible window")); - actionCollection()->addAction(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName, m_syncButton); - buttonsToolBar()->addAction(m_syncButton); + m_syncButton = new QAction( + QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon)), + tr("Synchronize"), + actionCollection() + ); + m_syncButton->setCheckable(true); + m_syncButton->setShortcut(CResMgr::displaywindows::commentaryWindow::syncWindow::accel); + m_syncButton->setToolTip(tr("Synchronize the displayed entry of this work with the active Bible window")); + actionCollection()->addAction(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName, m_syncButton); + buttonsToolBar()->addAction(m_syncButton); } /** Reimplementation to handle the keychooser refresh. */ -void CCommentaryReadWindow::reload(CSwordBackend::SetupChangedReason reason) -{ - CLexiconReadWindow::reload(reason); +void CCommentaryReadWindow::reload(CSwordBackend::SetupChangedReason reason) { + CLexiconReadWindow::reload(reason); - //refresh the book lists - verseKey()->setLocale( backend()->booknameLanguage().toLatin1() ); - keyChooser()->refreshContent(); + //refresh the book lists + verseKey()->setLocale( backend()->booknameLanguage().toLatin1() ); + keyChooser()->refreshContent(); - CBTConfig::setupAccelSettings(CBTConfig::commentaryWindow, actionCollection()); + CBTConfig::setupAccelSettings(CBTConfig::commentaryWindow, actionCollection()); } /** rapper around key() to return the right type of key. */ -CSwordVerseKey* CCommentaryReadWindow::verseKey() -{ - CSwordVerseKey* k = dynamic_cast<CSwordVerseKey*>(CDisplayWindow::key()); - Q_ASSERT(k); - return k; +CSwordVerseKey* CCommentaryReadWindow::verseKey() { + CSwordVerseKey* k = dynamic_cast<CSwordVerseKey*>(CDisplayWindow::key()); + Q_ASSERT(k); + return k; } /** Moves to the next book. */ -void CCommentaryReadWindow::nextBook() -{ - if (verseKey()->next(CSwordVerseKey::UseBook)) - keyChooser()->setKey(key()); +void CCommentaryReadWindow::nextBook() { + if (verseKey()->next(CSwordVerseKey::UseBook)) + keyChooser()->setKey(key()); } /** Moves one book behind. */ -void CCommentaryReadWindow::previousBook() -{ - if (verseKey()->previous(CSwordVerseKey::UseBook)) - keyChooser()->setKey(key()); +void CCommentaryReadWindow::previousBook() { + if (verseKey()->previous(CSwordVerseKey::UseBook)) + keyChooser()->setKey(key()); } /** Moves to the next book. */ -void CCommentaryReadWindow::nextChapter() -{ - if (verseKey()->next(CSwordVerseKey::UseChapter)) - keyChooser()->setKey(key()); +void CCommentaryReadWindow::nextChapter() { + if (verseKey()->next(CSwordVerseKey::UseChapter)) + keyChooser()->setKey(key()); } /** Moves one book behind. */ -void CCommentaryReadWindow::previousChapter() -{ - if (verseKey()->previous(CSwordVerseKey::UseChapter)) - keyChooser()->setKey(key()); +void CCommentaryReadWindow::previousChapter() { + if (verseKey()->previous(CSwordVerseKey::UseChapter)) + keyChooser()->setKey(key()); } /** Moves to the next book. */ -void CCommentaryReadWindow::nextVerse() -{ - if (verseKey()->next(CSwordVerseKey::UseVerse)) - keyChooser()->setKey(key()); +void CCommentaryReadWindow::nextVerse() { + if (verseKey()->next(CSwordVerseKey::UseVerse)) + keyChooser()->setKey(key()); } /** Moves one book behind. */ -void CCommentaryReadWindow::previousVerse() -{ - if (verseKey()->previous(CSwordVerseKey::UseVerse)) - keyChooser()->setKey(key()); +void CCommentaryReadWindow::previousVerse() { + if (verseKey()->previous(CSwordVerseKey::UseVerse)) + keyChooser()->setKey(key()); } -bool CCommentaryReadWindow::syncAllowed() const -{ - return m_syncButton->isChecked(); +bool CCommentaryReadWindow::syncAllowed() const { + return m_syncButton->isChecked(); } /*! \fn CCommentaryReadWindow::setupPopupMenu() */ -void CCommentaryReadWindow::setupPopupMenu() -{ - CLexiconReadWindow::setupPopupMenu(); +void CCommentaryReadWindow::setupPopupMenu() { + CLexiconReadWindow::setupPopupMenu(); } diff --git a/src/frontend/displaywindow/ccommentaryreadwindow.h b/src/frontend/displaywindow/ccommentaryreadwindow.h index 333b48f..21f4630 100644 --- a/src/frontend/displaywindow/ccommentaryreadwindow.h +++ b/src/frontend/displaywindow/ccommentaryreadwindow.h @@ -23,45 +23,45 @@ class BtActionCollection; */ class CCommentaryReadWindow : public CLexiconReadWindow { - Q_OBJECT -public: - /** - * Reimplementation. - */ - static void insertKeyboardActions( BtActionCollection* const a ); + Q_OBJECT + public: + /** + * Reimplementation. + */ + static void insertKeyboardActions( BtActionCollection* const a ); - CCommentaryReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); - /** - * Store the settings of this window in the given CProfileWindow object. - */ - virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow ); - /** - * Store the settings of this window in the given profile window. - */ - virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow ); - virtual bool syncAllowed() const; + CCommentaryReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); + /** + * Store the settings of this window in the given CProfileWindow object. + */ + virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow ); + /** + * Store the settings of this window in the given profile window. + */ + virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow ); + virtual bool syncAllowed() const; -public slots: // Public slots - void nextBook(); - void previousBook(); - void nextChapter(); - void previousChapter(); - void nextVerse(); - void previousVerse(); - /** - * Reimplementation to handle the keychooser refresh. - */ - virtual void reload(CSwordBackend::SetupChangedReason); + public slots: // Public slots + void nextBook(); + void previousBook(); + void nextChapter(); + void previousChapter(); + void nextVerse(); + void previousVerse(); + /** + * Reimplementation to handle the keychooser refresh. + */ + virtual void reload(CSwordBackend::SetupChangedReason); -protected: - virtual void initActions(); - virtual void initToolbars(); + protected: + virtual void initActions(); + virtual void initToolbars(); -private: - QAction* m_syncButton; - CSwordVerseKey* verseKey(); -protected: - virtual void setupPopupMenu(); + private: + QAction* m_syncButton; + CSwordVerseKey* verseKey(); + protected: + virtual void setupPopupMenu(); }; #endif diff --git a/src/frontend/displaywindow/cdisplaywindow.cpp b/src/frontend/displaywindow/cdisplaywindow.cpp index 8b4a9cd..394e96b 100644 --- a/src/frontend/displaywindow/cdisplaywindow.cpp +++ b/src/frontend/displaywindow/cdisplaywindow.cpp @@ -32,520 +32,458 @@ 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), - m_isReady(false), - m_moduleChooserBar(0), - m_mainToolBar(0), - m_popupMenu(0), - m_displayWidget(0) -{ - qDebug("CDisplayWindow::CDisplayWindow"); - setAttribute(Qt::WA_DeleteOnClose); //we want to destroy this window when it is closed - parent->addSubWindow(this); - m_actionCollection = new BtActionCollection(this); - setModules(modules); - - // Connect this to the backend module list changes - connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(reload(CSwordBackend::SetupChangedReason))); -} - -CDisplayWindow::~CDisplayWindow() -{ - delete m_swordKey; - m_swordKey = 0; -} - -CMDIArea* CDisplayWindow::mdi() const -{ - return m_mdi; + : QMainWindow(parent), + m_mdi(parent), + m_filterOptions(), + m_displayOptions(), + m_displaySettingsButton(0), + m_keyChooser(0), + m_swordKey(0), + m_isReady(false), + m_moduleChooserBar(0), + m_mainToolBar(0), + m_popupMenu(0), + m_displayWidget(0) { + qDebug("CDisplayWindow::CDisplayWindow"); + setAttribute(Qt::WA_DeleteOnClose); //we want to destroy this window when it is closed + parent->addSubWindow(this); + m_actionCollection = new BtActionCollection(this); + setModules(modules); + + // Connect this to the backend module list changes + connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(reload(CSwordBackend::SetupChangedReason))); +} + +CDisplayWindow::~CDisplayWindow() { + delete m_swordKey; + m_swordKey = 0; +} + +CMDIArea* CDisplayWindow::mdi() const { + return m_mdi; } /** Returns the right window caption. */ -const QString CDisplayWindow::windowCaption() -{ - if (!m_modules.count()) - { - return QString::null; - } +const QString CDisplayWindow::windowCaption() { + if (!m_modules.count()) { + return QString::null; + } - return QString(key()->key()).append(" (").append(m_modules.join(" | ")).append(")"); + return QString(key()->key()).append(" (").append(m_modules.join(" | ")).append(")"); } /** Returns the used modules as a QPtrList */ -QList<CSwordModuleInfo*> CDisplayWindow::modules() -{ - QList<CSwordModuleInfo*> mods; +QList<CSwordModuleInfo*> CDisplayWindow::modules() { + QList<CSwordModuleInfo*> mods; - 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); - } - } + 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 mods; } /** Set the window caption. */ -void CDisplayWindow::setCaption( const QString& ) -{ - QWidget::setWindowTitle( windowCaption() ); - m_mdi->emitWindowCaptionChanged(); +void CDisplayWindow::setCaption( const QString& ) { + QWidget::setWindowTitle( windowCaption() ); + m_mdi->emitWindowCaptionChanged(); } -void CDisplayWindow::insertKeyboardActions( BtActionCollection* a ) -{ - qDebug() << "CDisplayWindow::insertKeyboardActions: ac: " << a; +void CDisplayWindow::insertKeyboardActions( BtActionCollection* a ) { + qDebug() << "CDisplayWindow::insertKeyboardActions: ac: " << a; - QAction* actn = new QAction(QIcon(), tr("Zoom in"), 0); - actn->setShortcut(QKeySequence::ZoomIn); - a->addAction("zoomIn", actn); + QAction* actn = new QAction(QIcon(), tr("Zoom in"), a); + actn->setShortcut(QKeySequence::ZoomIn); + a->addAction("zoomIn", actn); - actn = new QAction(QIcon(), tr("Zoom out"), 0); - actn->setShortcut(QKeySequence::ZoomOut); - a->addAction("zoomOut", actn); + actn = new QAction(QIcon(), tr("Zoom out"), a); + actn->setShortcut(QKeySequence::ZoomOut); + a->addAction("zoomOut", actn); - actn = new QAction(QIcon(), tr("Close"), 0); - actn->setShortcut(QKeySequence::Close); - a->addAction("closeWindow", actn); + actn = new QAction(QIcon(), tr("Close"), a); + actn->setShortcut(QKeySequence::Close); + a->addAction("closeWindow", actn); - actn = new QAction(QIcon(), tr("Select all"), 0); - actn->setShortcut(QKeySequence::SelectAll); - a->addAction("selectAll", actn); + actn = new QAction(QIcon(), tr("Select all"), a); + actn->setShortcut(QKeySequence::SelectAll); + a->addAction("selectAll", actn); - actn = new QAction(QIcon(), tr("Copy"), 0); - actn->setShortcut(QKeySequence::Copy); - a->addAction("copySelectedText", actn); + actn = new QAction(QIcon(), tr("Copy"), a); + actn->setShortcut(QKeySequence::Copy); + a->addAction("copySelectedText", actn); - actn = new QAction(QIcon(), tr("Find..."), 0); - actn->setShortcut(QKeySequence::Find); - a->addAction("findText", actn); + actn = new QAction(QIcon(), tr("Find..."), a); + actn->setShortcut(QKeySequence::Find); + a->addAction("findText", actn); - actn = new QAction(QIcon(), tr("Change location"), 0); - actn->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L)); - a->addAction("openLocation", actn); + actn = new QAction(QIcon(), tr("Change location"), a); + actn->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L)); + a->addAction("openLocation", actn); - actn = new QAction(QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::search::icon)), - tr("Search with works of this window"), 0); - actn->setShortcut(CResMgr::displaywindows::general::search::accel); - a->addAction(CResMgr::displaywindows::general::search::actionName, actn); + actn = new QAction(QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::search::icon)), + tr("Search with works of this window"), a); + actn->setShortcut(CResMgr::displaywindows::general::search::accel); + a->addAction(CResMgr::displaywindows::general::search::actionName, actn); - BtToolBarPopupAction* action = new BtToolBarPopupAction( - QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::backInHistory::icon)), - tr("Back in history"), - a - ); - action->setShortcut(CResMgr::displaywindows::general::backInHistory::accel); - a->addAction(CResMgr::displaywindows::general::backInHistory::actionName, action); + BtToolBarPopupAction* action = new BtToolBarPopupAction( + QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::backInHistory::icon)), + tr("Back in history"), + a + ); + action->setShortcut(CResMgr::displaywindows::general::backInHistory::accel); + a->addAction(CResMgr::displaywindows::general::backInHistory::actionName, action); - action = new BtToolBarPopupAction( - QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::forwardInHistory::icon)), - tr("Forward in history"), - a - ); - action->setShortcut(CResMgr::displaywindows::general::forwardInHistory::accel); - a->addAction(CResMgr::displaywindows::general::forwardInHistory::actionName, action); + action = new BtToolBarPopupAction( + QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::forwardInHistory::icon)), + tr("Forward in history"), + a + ); + action->setShortcut(CResMgr::displaywindows::general::forwardInHistory::accel); + a->addAction(CResMgr::displaywindows::general::forwardInHistory::actionName, action); } -void CDisplayWindow::initActions() -{ - qDebug("CDisplayWindow::initActions"); +void CDisplayWindow::initActions() { + qDebug("CDisplayWindow::initActions"); - BtActionCollection* ac = actionCollection(); + BtActionCollection* ac = actionCollection(); - CDisplayWindow::insertKeyboardActions(ac); + CDisplayWindow::insertKeyboardActions(ac); - QAction* actn = ac->action(CResMgr::displaywindows::general::search::actionName); - QObject::connect(actn, SIGNAL(triggered()), this, SLOT(slotSearchInModules())); + QAction* actn = ac->action(CResMgr::displaywindows::general::search::actionName); + QObject::connect(actn, SIGNAL(triggered()), this, SLOT(slotSearchInModules())); - CDisplayConnections* conn = displayWidget()->connectionsProxy(); + CDisplayConnections* conn = displayWidget()->connectionsProxy(); - actn = ac->action("openLocation"); - QObject::connect(actn, SIGNAL(triggered()), this, SLOT(setFocusKeyChooser())); - addAction(actn); + actn = ac->action("openLocation"); + QObject::connect(actn, SIGNAL(triggered()), this, SLOT(setFocusKeyChooser())); + addAction(actn); - actn = ac->action("zoomIn"); - QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(zoomIn())); - addAction(actn); + actn = ac->action("zoomIn"); + QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(zoomIn())); + addAction(actn); - actn = ac->action("zoomOut"); - QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(zoomOut())); - addAction(actn); + actn = ac->action("zoomOut"); + 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("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); + actn = ac->action("selectAll"); + QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(selectAll())); + addAction(actn); - actn = ac->action("copySelectedText"); - QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(copySelection())); - addAction(actn); + actn = ac->action("copySelectedText"); + QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(copySelection())); + addAction(actn); - actn = ac->action("findText"); - QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(openFindTextDialog())); - addAction(actn); + actn = ac->action("findText"); + QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(openFindTextDialog())); + addAction(actn); - QAction* popupaction = ac->action(CResMgr::displaywindows::general::backInHistory::actionName); - bool ok = QObject::connect(popupaction, SIGNAL(triggered()), keyChooser()->history(), SLOT(back())); - Q_ASSERT(ok); - addAction(popupaction); + QAction* popupaction = ac->action(CResMgr::displaywindows::general::backInHistory::actionName); + bool ok = QObject::connect(popupaction, SIGNAL(triggered()), keyChooser()->history(), SLOT(back())); + Q_ASSERT(ok); + addAction(popupaction); - popupaction = ac->action(CResMgr::displaywindows::general::forwardInHistory::actionName); - ok = QObject::connect(popupaction, SIGNAL(triggered()), keyChooser()->history(), SLOT(fw()) ); - Q_ASSERT(ok); - addAction(popupaction); + popupaction = ac->action(CResMgr::displaywindows::general::forwardInHistory::actionName); + ok = QObject::connect(popupaction, SIGNAL(triggered()), keyChooser()->history(), SLOT(fw()) ); + Q_ASSERT(ok); + addAction(popupaction); - CBTConfig::setupAccelSettings(CBTConfig::allWindows,ac); + CBTConfig::setupAccelSettings(CBTConfig::allWindows, ac); } /** Refresh the settings of this window. */ -void CDisplayWindow::reload(CSwordBackend::SetupChangedReason) -{ - //first make sure all used Sword modules are still present - QMutableStringListIterator it(m_modules); - while (it.hasNext()) { - if (!backend()->findModuleByName(it.next())) - { - it.remove(); - } - } - - if (m_modules.count() == 0) - { - close(); - return; - } - - 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()); +void CDisplayWindow::reload(CSwordBackend::SetupChangedReason) { + //first make sure all used Sword modules are still present + QMutableStringListIterator it(m_modules); + while (it.hasNext()) { + if (!backend()->findModuleByName(it.next())) { + it.remove(); + } + } + + if (m_modules.count() == 0) { + close(); + return; + } + + 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()); } /** Returns the filter options used by this window. */ -CSwordBackend::FilterOptions& CDisplayWindow::filterOptions() -{ - return m_filterOptions; +CSwordBackend::FilterOptions& CDisplayWindow::filterOptions() { + return m_filterOptions; } /** Returns the display options used by this display window. */ -CSwordBackend::DisplayOptions& CDisplayWindow::displayOptions() -{ - return m_displayOptions; +CSwordBackend::DisplayOptions& CDisplayWindow::displayOptions() { + return m_displayOptions; } /** Sets the new display options for this window. */ -void CDisplayWindow::setDisplayOptions( const CSwordBackend::DisplayOptions& displayOptions ) -{ - m_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 ) -{ - m_filterOptions = filterOptions; +void CDisplayWindow::setFilterOptions( CSwordBackend::FilterOptions& filterOptions ) { + m_filterOptions = filterOptions; } /** Returns true if the widget is ready for use. */ -bool CDisplayWindow::isReady() const -{ - return m_isReady; +bool CDisplayWindow::isReady() const { + return m_isReady; } /** Set the ready status */ -void CDisplayWindow::setReady( const bool& ready ) -{ - m_isReady = ready; +void CDisplayWindow::setReady( const bool& ready ) { + m_isReady = ready; } /** Returns true if the window may be closed. */ -bool CDisplayWindow::queryClose() -{ - return true; +bool CDisplayWindow::queryClose() { + return true; } /** Returns the keychooser widget of this display window. */ -CKeyChooser* CDisplayWindow::keyChooser() const -{ - return m_keyChooser; +CKeyChooser* CDisplayWindow::keyChooser() const { + return m_keyChooser; } /** Sets the keychooser widget for this display window. */ -void CDisplayWindow::setKeyChooser( CKeyChooser* ck ) -{ - m_keyChooser = ck; +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; +CSwordKey* CDisplayWindow::key() const { + Q_ASSERT( m_swordKey ); + return m_swordKey; } /** Sets the new sword key. */ -void CDisplayWindow::setKey( CSwordKey* key ) -{ - Q_ASSERT( key ); - m_swordKey = key; -} - -void CDisplayWindow::modulesChanged() -{ - if (moduleChooserBar()) { //necessary for write windows - setModules( m_moduleChooserBar->getModuleList() ); - } - - if (!modules().count()) - { - close(); - } - else - { - if (displaySettingsButton()) - { - displaySettingsButton()->reset(modules()); - } - - key()->module(modules().first()); - keyChooser()->setModules(modules()); - } +void CDisplayWindow::setKey( CSwordKey* key ) { + Q_ASSERT( key ); + m_swordKey = key; +} + +void CDisplayWindow::modulesChanged() { + if (moduleChooserBar()) { //necessary for write windows + setModules( m_moduleChooserBar->getModuleList() ); + } + + if (!modules().count()) { + close(); + } + else { + if (displaySettingsButton()) { + displaySettingsButton()->reset(modules()); + } + + key()->module(modules().first()); + keyChooser()->setModules(modules()); + } } /** Returns the module chooser bar. */ -CModuleChooserBar* CDisplayWindow::moduleChooserBar() const -{ - return m_moduleChooserBar; +CModuleChooserBar* CDisplayWindow::moduleChooserBar() const { + return m_moduleChooserBar; } /** Sets the module chooser bar. */ -void CDisplayWindow::setModuleChooserBar( CModuleChooserBar* bar ) -{ - if (m_moduleChooserBar) - { - disconnect(m_moduleChooserBar, SIGNAL(sigChanged()), this, SLOT(modulesChanged())); - } +void CDisplayWindow::setModuleChooserBar( CModuleChooserBar* bar ) { + if (m_moduleChooserBar) { + disconnect(m_moduleChooserBar, SIGNAL(sigChanged()), this, SLOT(modulesChanged())); + } - //if a new bar should be set! - if (bar) - { - m_moduleChooserBar = bar; - connect(bar, SIGNAL(sigChanged()), SLOT(modulesChanged())); - } + //if a new bar should be set! + if (bar) { + m_moduleChooserBar = bar; + connect(bar, SIGNAL(sigChanged()), SLOT(modulesChanged())); + } } /** Sets the modules. */ -void CDisplayWindow::setModules( const QList<CSwordModuleInfo*>& newModules ) -{ - qDebug("CDisplayWindow::setModules"); - m_modules.clear(); +void CDisplayWindow::setModules( const QList<CSwordModuleInfo*>& newModules ) { + qDebug("CDisplayWindow::setModules"); + m_modules.clear(); - foreach (CSwordModuleInfo* mod, newModules) - { - m_modules.append(mod->name()); - } + foreach (CSwordModuleInfo* mod, newModules) { + m_modules.append(mod->name()); + } } /** Initialize the window. Call this method from the outside, because calling this in the constructor is not possible! */ -bool CDisplayWindow::init() -{ - qDebug("CDisplayWindow::init"); - initView(); - setMinimumSize( 100,100 ); - - setCaption(windowCaption()); - //setup focus stuff. - setFocusPolicy(Qt::ClickFocus); - parentWidget()->setFocusPolicy(Qt::ClickFocus); - initActions(); - initToolbars(); - initConnections(); - setupPopupMenu(); - - m_filterOptions = CBTConfig::getFilterOptionDefaults(); - m_displayOptions = CBTConfig::getDisplayOptionDefaults(); - if (displaySettingsButton()) { - displaySettingsButton()->reset(modules()); - } - - setReady(true); - return true; +bool CDisplayWindow::init() { + qDebug("CDisplayWindow::init"); + initView(); + setMinimumSize( 100, 100 ); + + setCaption(windowCaption()); + //setup focus stuff. + setFocusPolicy(Qt::ClickFocus); + parentWidget()->setFocusPolicy(Qt::ClickFocus); + initActions(); + initToolbars(); + initConnections(); + setupPopupMenu(); + + m_filterOptions = CBTConfig::getFilterOptionDefaults(); + m_displayOptions = CBTConfig::getDisplayOptionDefaults(); + if (displaySettingsButton()) { + displaySettingsButton()->reset(modules()); + } + + setReady(true); + return true; } /** Returns the main toolbar. */ -QToolBar* CDisplayWindow::mainToolBar() const -{ - return m_mainToolBar; +QToolBar* CDisplayWindow::mainToolBar() const { + return m_mainToolBar; } /** Returns the main toolbar. */ -QToolBar* CDisplayWindow::buttonsToolBar() const -{ - return m_buttonsToolBar; +QToolBar* CDisplayWindow::buttonsToolBar() const { + return m_buttonsToolBar; } /** Sets the main toolbar. */ -void CDisplayWindow::setMainToolBar( QToolBar* bar ) -{ - m_mainToolBar = bar; +void CDisplayWindow::setMainToolBar( QToolBar* bar ) { + m_mainToolBar = bar; } /** Sets the main toolbar. */ -void CDisplayWindow::setButtonsToolBar( QToolBar* bar ) -{ - m_buttonsToolBar = bar; +void CDisplayWindow::setButtonsToolBar( QToolBar* bar ) { + m_buttonsToolBar = bar; } /** Returns the display settings button */ -CDisplaySettingsButton* CDisplayWindow::displaySettingsButton() const -{ - return m_displaySettingsButton; +CDisplaySettingsButton* CDisplayWindow::displaySettingsButton() const { + return m_displaySettingsButton; } /** Sets the display settings button. */ -void CDisplayWindow::setDisplaySettingsButton( CDisplaySettingsButton* button ) -{ - if (m_displaySettingsButton) - disconnect(m_displaySettingsButton, SIGNAL( sigChanged() ),this, SLOT(lookup() )); +void CDisplayWindow::setDisplaySettingsButton( CDisplaySettingsButton* button ) { + if (m_displaySettingsButton) + disconnect(m_displaySettingsButton, SIGNAL( sigChanged() ), this, SLOT(lookup() )); - m_displaySettingsButton = button; - connect(m_displaySettingsButton, SIGNAL(sigChanged()),this, SLOT(lookup())); + m_displaySettingsButton = button; + connect(m_displaySettingsButton, SIGNAL(sigChanged()), this, SLOT(lookup())); } /** Lookup the current key. Used to refresh the display. */ -void CDisplayWindow::lookup() -{ - lookupSwordKey( key() ); -} - -void CDisplayWindow::lookupModKey( const QString& moduleName, const QString& keyName ) -{ - if (!isReady()) - { - return; - } - - CSwordModuleInfo* m = backend()->findModuleByName(moduleName); - Q_ASSERT(m); - if (!m) - { - return; - } - - //ToDo: check for containsRef compat - if (m && modules().contains(m)) - { - key()->key(keyName); - keyChooser()->setKey(key()); //the key chooser does send an update signal - } - else - { //given module not displayed in this window - //if the module is displayed in another display window we assume a wrong drop - //create a new window for the given module - QList<CSwordModuleInfo*> mList; - mList.append(m); - mdi()->emitCreateDisplayWindow(mList, keyName); - } -} - -void CDisplayWindow::lookupKey( const QString& keyName ) -{ - /* This function is called for example after a bookmark was dropped on this window - */ - Q_ASSERT(modules().first()); - - //qDebug("CDisplayWindow::lookup: %s", keyName.latin1()); - lookupModKey(modules().first()->name(), keyName); +void CDisplayWindow::lookup() { + lookupSwordKey( key() ); +} + +void CDisplayWindow::lookupModKey( const QString& moduleName, const QString& keyName ) { + if (!isReady()) { + return; + } + + CSwordModuleInfo* m = backend()->findModuleByName(moduleName); + Q_ASSERT(m); + if (!m) { + return; + } + + //ToDo: check for containsRef compat + if (m && modules().contains(m)) { + key()->key(keyName); + keyChooser()->setKey(key()); //the key chooser does send an update signal + } + else { //given module not displayed in this window + //if the module is displayed in another display window we assume a wrong drop + //create a new window for the given module + QList<CSwordModuleInfo*> mList; + mList.append(m); + mdi()->emitCreateDisplayWindow(mList, keyName); + } +} + +void CDisplayWindow::lookupKey( const QString& keyName ) { + /* This function is called for example after a bookmark was dropped on this window + */ + Q_ASSERT(modules().first()); + + //qDebug("CDisplayWindow::lookup: %s", keyName.latin1()); + lookupModKey(modules().first()->name(), keyName); } /** Update the status of the popup menu entries. */ -void CDisplayWindow::updatePopupMenu() -{ +void CDisplayWindow::updatePopupMenu() { } ///** Returns the installed popup menu. */ -QMenu* CDisplayWindow::popup() -{ - // qWarning("CReadWindow::popup()"); - if (!m_popupMenu) - { - m_popupMenu = new QMenu(this); - connect(m_popupMenu, SIGNAL(aboutToShow()), this, SLOT(updatePopupMenu())); - if (displayWidget()) - { - displayWidget()->installPopup(m_popupMenu); - } - /* else { - qWarning("CDisplayWindow:: can't instal popup menu"); - }*/ - } - return m_popupMenu; +QMenu* CDisplayWindow::popup() { + // qWarning("CReadWindow::popup()"); + if (!m_popupMenu) { + m_popupMenu = new QMenu(this); + connect(m_popupMenu, SIGNAL(aboutToShow()), this, SLOT(updatePopupMenu())); + if (displayWidget()) { + displayWidget()->installPopup(m_popupMenu); + } + /* else { + qWarning("CDisplayWindow:: can't instal popup menu"); + }*/ + } + return m_popupMenu; } /** Returns the display widget used by this implementation of CDisplayWindow. */ -CDisplay* CDisplayWindow::displayWidget() const -{ - Q_ASSERT(m_displayWidget); - return m_displayWidget; +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; +void CDisplayWindow::setDisplayWidget( CDisplay* newDisplay ) { + m_displayWidget = newDisplay; } -void CDisplayWindow::closeEvent(QCloseEvent* e) -{ - if (!queryClose()) - { - e->ignore(); - } - else { - e->accept(); - } +void CDisplayWindow::closeEvent(QCloseEvent* e) { + if (!queryClose()) { + e->ignore(); + } + else { + e->accept(); + } } -void CDisplayWindow::slotSearchInModules() -{ - Search::CSearchDialog::openDialog(modules()); +void CDisplayWindow::slotSearchInModules() { + Search::CSearchDialog::openDialog(modules()); } -void CDisplayWindow::printAll() -{ - m_displayWidget->connectionsProxy()->printAll( m_displayOptions, m_filterOptions); +void CDisplayWindow::printAll() { + m_displayWidget->connectionsProxy()->printAll( m_displayOptions, m_filterOptions); } -void CDisplayWindow::printAnchorWithText() -{ - m_displayWidget->connectionsProxy()->printAnchorWithText( m_displayOptions, m_filterOptions); +void CDisplayWindow::printAnchorWithText() { + m_displayWidget->connectionsProxy()->printAnchorWithText( m_displayOptions, m_filterOptions); } -BtActionCollection* CDisplayWindow::actionCollection() -{ - return m_actionCollection; +BtActionCollection* CDisplayWindow::actionCollection() { + return m_actionCollection; } -void CDisplayWindow::setFocusKeyChooser() -{ - keyChooser()->setFocus(); +void CDisplayWindow::setFocusKeyChooser() { + keyChooser()->setFocus(); } diff --git a/src/frontend/displaywindow/cdisplaywindow.h b/src/frontend/displaywindow/cdisplaywindow.h index 733f06e..5a32f9f 100644 --- a/src/frontend/displaywindow/cdisplaywindow.h +++ b/src/frontend/displaywindow/cdisplaywindow.h @@ -39,190 +39,187 @@ class BtActionCollection; * @author The BibleTime team */ -class CDisplayWindow : public QMainWindow, public CPointers -{ - Q_OBJECT -public: - enum WriteWindowType - { - HTMLWindow = 1, - PlainTextWindow = 2 - }; +class CDisplayWindow : public QMainWindow, public CPointers { + Q_OBJECT + public: + enum WriteWindowType { + HTMLWindow = 1, + PlainTextWindow = 2 + }; - // Insert the keyboard accelerators of this window into the given KAccel object. - static void insertKeyboardActions( BtActionCollection* const a ); + // Insert the keyboard accelerators of this window into the given KAccel object. + static void insertKeyboardActions( BtActionCollection* const a ); - CMDIArea* mdi() const; + CMDIArea* mdi() const; - // Returns the right window caption. - const QString windowCaption(); + // Returns the right window caption. + const QString windowCaption(); - // Returns the used modules as a QPtrList - QList<CSwordModuleInfo*> modules(); + // Returns the used modules as a QPtrList + QList<CSwordModuleInfo*> 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 CProfileWindow object. + virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow ) = 0; - // Store the settings of this window in the given profile window. - virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow ) = 0; + // Store the settings of this window in the given profile window. + virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow ) = 0; - // Set the window caption. - virtual void setCaption( const QString& ); + // Set the window caption. + virtual void setCaption( const QString& ); - // Sets the new filter options of this window. - void setFilterOptions( CSwordBackend::FilterOptions& filterOptions ); + // 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 ); + // 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. + CSwordBackend::DisplayOptions& displayOptions(); - // Returns the filter options used by this window. - CSwordBackend::FilterOptions& filterOptions(); + // Returns the filter options used by this window. + CSwordBackend::FilterOptions& filterOptions(); - // Set the ready status - void setReady( const bool& ready ); + // Set the ready status + void setReady( const bool& ready ); - // Returns true if the widget is ready for use. - bool isReady() const; + // Returns true if the widget is ready for use. + bool isReady() const; - // Returns true if the window may be closed. - virtual bool queryClose(); + // 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. + CKeyChooser* keyChooser() const; - // Sets the new sword key. - void setKey( CSwordKey* 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. + CSwordKey* key() const; - // Initialize the window. Call this method from the outside, because calling this in the constructor is not possible! - virtual bool init(); + // 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. - void setMainToolBar( QToolBar* bar ); + // Sets the main toolbar. + void setMainToolBar( QToolBar* bar ); - // Sets the buttons toolbar. - void setButtonsToolBar( QToolBar* bar ); + // Sets the buttons toolbar. + void setButtonsToolBar( QToolBar* bar ); - // Returns the main toolbar. - QToolBar* mainToolBar() const; + // Returns the main toolbar. + QToolBar* mainToolBar() const; - // Returns the buttons toolbar. - QToolBar* buttonsToolBar() const; + // Returns the buttons toolbar. + QToolBar* buttonsToolBar() const; - // Initialize the toolbars - virtual void initToolbars() = 0; + // Initialize the toolbars + virtual void initToolbars() = 0; - // Returns the display settings button - CDisplaySettingsButton* displaySettingsButton() const; + // Returns the display settings button + CDisplaySettingsButton* displaySettingsButton() const; - // Sets the display settings button. - void setDisplaySettingsButton( CDisplaySettingsButton* button ); + // Sets the display settings button. + void setDisplaySettingsButton( CDisplaySettingsButton* button ); - virtual void setupPopupMenu() = 0; + 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 CDisplay* displayWidget() const; - // Sets the display widget used by this display window. - virtual void setDisplayWidget( CDisplay* newDisplay ); + // 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 - virtual bool syncAllowed() const - { - return false; - }; + // 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(); + BtActionCollection* actionCollection(); -public slots: + 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. - virtual void lookupModKey( const QString& module, const QString& key ); + // 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. - virtual void lookupKey( const QString& key ); + // Lookup the key in the chosen modules. + virtual void lookupKey( const QString& key ); - // Refresh the settings of this window. - virtual void reload(CSwordBackend::SetupChangedReason reason); + // Refresh the settings of this window. + virtual void reload(CSwordBackend::SetupChangedReason reason); -protected: - friend class CMDIArea; - friend class CBibleReadWindow; + protected: + friend class CMDIArea; + friend class CBibleReadWindow; - CDisplayWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); - virtual ~CDisplayWindow(); + CDisplayWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); + virtual ~CDisplayWindow(); - // Initializes the intern keyboard actions. - virtual void initActions(); + // Initializes the intern keyboard actions. + virtual void initActions(); - // Sets the keychooser widget for this display window. - void setKeyChooser( CKeyChooser* ck ); + // 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. + CModuleChooserBar* moduleChooserBar() const; - // Lookup the given key. - virtual void lookupSwordKey( CSwordKey* ) = 0; + // 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( CModuleChooserBar* bar ); - // Sets the modules. - void setModules( const QList<CSwordModuleInfo*>& modules ); + // Sets the modules. + void setModules( const QList<CSwordModuleInfo*>& modules ); - // Initializes the signal / slot connections of this display window. - virtual void initConnections() = 0; + // Initializes the signal / slot connections of this display window. + virtual void initConnections() = 0; - // Initialize the view of this display window. - virtual void initView() = 0; + // Initialize the view of this display window. + virtual void initView() = 0; - // Returns the installed popup menu. - QMenu* popup(); + // Returns the installed popup menu. + QMenu* popup(); - virtual void closeEvent(QCloseEvent* e); + virtual void closeEvent(QCloseEvent* e); -protected slots: - virtual void modulesChanged(); + protected slots: + virtual void modulesChanged(); - // Lookup the current key. Used to refresh the display. - void lookup(); + // Lookup the current key. Used to refresh the display. + void lookup(); - virtual void updatePopupMenu(); + virtual void updatePopupMenu(); - void slotSearchInModules(); + void slotSearchInModules(); - void printAll(); + void printAll(); - void printAnchorWithText(); + void printAnchorWithText(); - void setFocusKeyChooser(); + void setFocusKeyChooser(); -private: - BtActionCollection* m_actionCollection; - CMDIArea* m_mdi; + private: + BtActionCollection* m_actionCollection; + CMDIArea* m_mdi; - //we may only cache the module names bacause after a backend relaod the pointers are invalid! - QStringList m_modules; + //we may only cache the module names bacause after a backend relaod the pointers are invalid! + QStringList m_modules; - CSwordBackend::FilterOptions m_filterOptions; - CSwordBackend::DisplayOptions m_displayOptions; + CSwordBackend::FilterOptions m_filterOptions; + CSwordBackend::DisplayOptions m_displayOptions; - CDisplaySettingsButton* m_displaySettingsButton; - CKeyChooser* m_keyChooser; - CSwordKey* m_swordKey; - bool m_isReady; - CModuleChooserBar* m_moduleChooserBar; - QToolBar* m_mainToolBar; - QToolBar* m_buttonsToolBar; - QMenu* m_popupMenu; - CDisplay* m_displayWidget; + CDisplaySettingsButton* m_displaySettingsButton; + CKeyChooser* m_keyChooser; + CSwordKey* m_swordKey; + bool m_isReady; + CModuleChooserBar* m_moduleChooserBar; + QToolBar* m_mainToolBar; + QToolBar* m_buttonsToolBar; + QMenu* m_popupMenu; + CDisplay* m_displayWidget; }; #endif diff --git a/src/frontend/displaywindow/cdisplaywindowfactory.cpp b/src/frontend/displaywindow/cdisplaywindowfactory.cpp index d386ecf..6581ffd 100644 --- a/src/frontend/displaywindow/cdisplaywindowfactory.cpp +++ b/src/frontend/displaywindow/cdisplaywindowfactory.cpp @@ -1,7 +1,7 @@ // // C++ Implementation: cdisplaywindowfactory // -// Description: +// Description: // // // Author: The BibleTime team <info@bibletime.info>, (C) 2007 @@ -25,33 +25,31 @@ #include "frontend/cmdiarea.h" -CReadWindow* CDisplayWindowFactory::createReadInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent) -{ - qDebug("CDisplayWindowFactory::createReadInstance"); - switch (modules.first()->type()) { - case CSwordModuleInfo::Bible: - return new CBibleReadWindow(modules, parent); - case CSwordModuleInfo::Commentary: - return new CCommentaryReadWindow(modules, parent); - case CSwordModuleInfo::Lexicon: - return new CLexiconReadWindow(modules, parent); - case CSwordModuleInfo::GenericBook: - return new CBookReadWindow(modules, parent); - default: - qWarning("unknown module type"); - break; - } - return 0; +CReadWindow* CDisplayWindowFactory::createReadInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent) { + qDebug("CDisplayWindowFactory::createReadInstance"); + switch (modules.first()->type()) { + case CSwordModuleInfo::Bible: + return new CBibleReadWindow(modules, parent); + case CSwordModuleInfo::Commentary: + return new CCommentaryReadWindow(modules, parent); + case CSwordModuleInfo::Lexicon: + return new CLexiconReadWindow(modules, parent); + case CSwordModuleInfo::GenericBook: + return new CBookReadWindow(modules, parent); + default: + qWarning("unknown module type"); + break; + } + return 0; } -CWriteWindow* CDisplayWindowFactory::createWriteInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent, const CDisplayWindow::WriteWindowType type) -{ - if (type == CDisplayWindow::HTMLWindow) { - return new CHTMLWriteWindow(modules, parent); - } - else { - return new CPlainWriteWindow(modules, parent); - } - return 0; +CWriteWindow* CDisplayWindowFactory::createWriteInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent, const CDisplayWindow::WriteWindowType type) { + if (type == CDisplayWindow::HTMLWindow) { + return new CHTMLWriteWindow(modules, parent); + } + else { + return new CPlainWriteWindow(modules, parent); + } + return 0; } diff --git a/src/frontend/displaywindow/cdisplaywindowfactory.h b/src/frontend/displaywindow/cdisplaywindowfactory.h index 4bc4372..d8bf2a9 100644 --- a/src/frontend/displaywindow/cdisplaywindowfactory.h +++ b/src/frontend/displaywindow/cdisplaywindowfactory.h @@ -1,7 +1,7 @@ // // C++ Interface: cdisplaywindowfactory // -// Description: +// Description: // // // Author: The BibleTime team <info@bibletime.info>, (C) 2007 @@ -21,14 +21,13 @@ class CReadWindow; class CWriteWindow; class CMDIArea; -class CDisplayWindowFactory -{ -public: - static CReadWindow* createReadInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent); - static CWriteWindow* createWriteInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent, const CDisplayWindow::WriteWindowType type = CDisplayWindow::HTMLWindow); +class CDisplayWindowFactory { + public: + static CReadWindow* createReadInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent); + static CWriteWindow* createWriteInstance(QList<CSwordModuleInfo*> modules, CMDIArea* parent, const CDisplayWindow::WriteWindowType type = CDisplayWindow::HTMLWindow); -private: - CDisplayWindowFactory(); + private: + CDisplayWindowFactory(); }; #endif diff --git a/src/frontend/displaywindow/chtmlwritewindow.cpp b/src/frontend/displaywindow/chtmlwritewindow.cpp index cee16e0..df4018e 100644 --- a/src/frontend/displaywindow/chtmlwritewindow.cpp +++ b/src/frontend/displaywindow/chtmlwritewindow.cpp @@ -31,137 +31,137 @@ using namespace Profile; CHTMLWriteWindow::CHTMLWriteWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent) -: CPlainWriteWindow(modules, parent) {} + : CPlainWriteWindow(modules, parent) {} CHTMLWriteWindow::~CHTMLWriteWindow() {} void CHTMLWriteWindow::initView() { - CWriteDisplay* writeDisplay = CDisplay::createWriteInstance(this, CDisplay::HTMLDisplay); - Q_ASSERT(writeDisplay); - setDisplayWidget( writeDisplay ); - setCentralWidget( displayWidget()->view() ); - - setMainToolBar( new QToolBar(this) ); - mainToolBar()->setAllowedAreas(Qt::TopToolBarArea); - mainToolBar()->setFloatable(false); - addToolBar(mainToolBar()); - - setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) ); - mainToolBar()->addWidget(keyChooser()); + CWriteDisplay* writeDisplay = CDisplay::createWriteInstance(this, CDisplay::HTMLDisplay); + Q_ASSERT(writeDisplay); + setDisplayWidget( writeDisplay ); + setCentralWidget( displayWidget()->view() ); + + setMainToolBar( new QToolBar(this) ); + mainToolBar()->setAllowedAreas(Qt::TopToolBarArea); + mainToolBar()->setFloatable(false); + addToolBar(mainToolBar()); + + setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) ); + mainToolBar()->addWidget(keyChooser()); } void CHTMLWriteWindow::initConnections() { - CWriteWindow::initConnections(); + CWriteWindow::initConnections(); - connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*))); - connect(displayWidget()->connectionsProxy(), SIGNAL(textChanged()), this, SLOT(textChanged()) ); + connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*))); + connect(displayWidget()->connectionsProxy(), SIGNAL(textChanged()), this, SLOT(textChanged()) ); } void CHTMLWriteWindow::initToolbars() { - //setup the main toolbar - m_actions.syncWindow = new QAction( - util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon), - tr("Sync with active Bible"), - actionCollection() - ); - m_actions.syncWindow->setCheckable(true); - m_actions.syncWindow->setShortcut(CResMgr::displaywindows::commentaryWindow::syncWindow::accel); - m_actions.syncWindow->setToolTip(tr("Synchronize (show the same verse) with the active Bible window")); - actionCollection()->addAction(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName, m_actions.syncWindow); - mainToolBar()->addAction(m_actions.syncWindow); - - m_actions.saveText = new QAction( - util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::saveText::icon), - tr("Save text"), - actionCollection() - ); - m_actions.saveText->setShortcut(CResMgr::displaywindows::writeWindow::saveText::accel); - m_actions.saveText->setToolTip( tr("Save text") ); - QObject::connect(m_actions.saveText, SIGNAL(triggered()), this, SLOT( saveCurrentText() ) ); - actionCollection()->addAction(CResMgr::displaywindows::writeWindow::saveText::actionName, m_actions.saveText); - mainToolBar()->addAction(m_actions.saveText); - - - m_actions.deleteEntry = new QAction( - util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::deleteEntry::icon), - tr("Delete current entry"), - actionCollection() - ); - m_actions.deleteEntry->setShortcut(CResMgr::displaywindows::writeWindow::deleteEntry::accel); - m_actions.deleteEntry->setToolTip( tr("Delete current entry (no undo)") ); - QObject::connect(m_actions.deleteEntry, SIGNAL(triggered()), this, SLOT( deleteEntry() ) ); - actionCollection()->addAction(CResMgr::displaywindows::writeWindow::deleteEntry::actionName, m_actions.deleteEntry); - mainToolBar()->addAction(m_actions.deleteEntry); - - m_actions.restoreText = new QAction( - util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::restoreText::icon), - tr("Restore original text"), - actionCollection() - ); - m_actions.restoreText->setShortcut(CResMgr::displaywindows::writeWindow::restoreText::accel); - m_actions.restoreText->setToolTip( tr("Restore original text, new text will be lost") ); - QObject::connect(m_actions.restoreText, SIGNAL(triggered()), this, SLOT( restoreText() ) ); - actionCollection()->addAction(CResMgr::displaywindows::writeWindow::restoreText::actionName, m_actions.restoreText); - mainToolBar()->addAction(m_actions.restoreText); - - //html formatting toolbar - QToolBar* bar = new QToolBar(this); - bar->setAllowedAreas(Qt::TopToolBarArea); - bar->setFloatable(false); - ((CWriteDisplay*)displayWidget())->setupToolbar( bar, actionCollection() ); - addToolBar(bar); + //setup the main toolbar + m_actions.syncWindow = new QAction( + util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon), + tr("Sync with active Bible"), + actionCollection() + ); + m_actions.syncWindow->setCheckable(true); + m_actions.syncWindow->setShortcut(CResMgr::displaywindows::commentaryWindow::syncWindow::accel); + m_actions.syncWindow->setToolTip(tr("Synchronize (show the same verse) with the active Bible window")); + actionCollection()->addAction(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName, m_actions.syncWindow); + mainToolBar()->addAction(m_actions.syncWindow); + + m_actions.saveText = new QAction( + util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::saveText::icon), + tr("Save text"), + actionCollection() + ); + m_actions.saveText->setShortcut(CResMgr::displaywindows::writeWindow::saveText::accel); + m_actions.saveText->setToolTip( tr("Save text") ); + QObject::connect(m_actions.saveText, SIGNAL(triggered()), this, SLOT( saveCurrentText() ) ); + actionCollection()->addAction(CResMgr::displaywindows::writeWindow::saveText::actionName, m_actions.saveText); + mainToolBar()->addAction(m_actions.saveText); + + + m_actions.deleteEntry = new QAction( + util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::deleteEntry::icon), + tr("Delete current entry"), + actionCollection() + ); + m_actions.deleteEntry->setShortcut(CResMgr::displaywindows::writeWindow::deleteEntry::accel); + m_actions.deleteEntry->setToolTip( tr("Delete current entry (no undo)") ); + QObject::connect(m_actions.deleteEntry, SIGNAL(triggered()), this, SLOT( deleteEntry() ) ); + actionCollection()->addAction(CResMgr::displaywindows::writeWindow::deleteEntry::actionName, m_actions.deleteEntry); + mainToolBar()->addAction(m_actions.deleteEntry); + + m_actions.restoreText = new QAction( + util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::restoreText::icon), + tr("Restore original text"), + actionCollection() + ); + m_actions.restoreText->setShortcut(CResMgr::displaywindows::writeWindow::restoreText::accel); + m_actions.restoreText->setToolTip( tr("Restore original text, new text will be lost") ); + QObject::connect(m_actions.restoreText, SIGNAL(triggered()), this, SLOT( restoreText() ) ); + actionCollection()->addAction(CResMgr::displaywindows::writeWindow::restoreText::actionName, m_actions.restoreText); + mainToolBar()->addAction(m_actions.restoreText); + + //html formatting toolbar + QToolBar* bar = new QToolBar(this); + bar->setAllowedAreas(Qt::TopToolBarArea); + bar->setFloatable(false); + ((CWriteDisplay*)displayWidget())->setupToolbar( bar, actionCollection() ); + addToolBar(bar); } void CHTMLWriteWindow::storeProfileSettings( CProfileWindow* profileWindow ) { - CWriteWindow::storeProfileSettings(profileWindow); - profileWindow->setWindowSettings( m_actions.syncWindow->isChecked() ); + CWriteWindow::storeProfileSettings(profileWindow); + profileWindow->setWindowSettings( m_actions.syncWindow->isChecked() ); } void CHTMLWriteWindow::applyProfileSettings( CProfileWindow* profileWindow ) { - CWriteWindow::applyProfileSettings(profileWindow); - if (profileWindow->windowSettings()) { - m_actions.syncWindow->setChecked(true); - } + CWriteWindow::applyProfileSettings(profileWindow); + if (profileWindow->windowSettings()) { + m_actions.syncWindow->setChecked(true); + } } /** Is called when the current text was changed. */ void CHTMLWriteWindow::textChanged() { - m_actions.saveText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() ); - m_actions.restoreText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() ); + m_actions.saveText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() ); + m_actions.restoreText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() ); } /** Loads the original text from the module. */ void CHTMLWriteWindow::restoreText() { - lookupSwordKey(key()); - ((CWriteDisplay*)displayWidget())->setModified(false); - textChanged(); + lookupSwordKey(key()); + ((CWriteDisplay*)displayWidget())->setModified(false); + textChanged(); } bool CHTMLWriteWindow::syncAllowed() const { - return m_actions.syncWindow->isChecked(); + return m_actions.syncWindow->isChecked(); } /** Saves the text for the current key. Directly writes the changed text into the module. */ void CHTMLWriteWindow::saveCurrentText( const QString& /*key*/ ) { - QString t = ((CHTMLWriteDisplay*)displayWidget())->toHtml(); - //since t is a complete HTML page at the moment, strip away headers and footers of a HTML page - QRegExp re("(?:<html.*>.+<body.*>)", Qt::CaseInsensitive); //remove headers, case insensitive - re.setMinimal(true); - t.replace(re, ""); - t.replace(QRegExp("</body></html>", Qt::CaseInsensitive), "");//remove footer - - const QString& oldKey = this->key()->key(); - if( modules().first()->isWritable() ) { - modules().first()->write(this->key(), t ); - this->key()->key( oldKey ); - - ((CWriteDisplay*)displayWidget())->setModified(false); - textChanged(); - } - else { - QMessageBox::critical( this, tr("Module not writable"), - QString::fromLatin1("<qt><b>%1</b><br />%2</qt>") - .arg( tr("Module is not writable.") ) - .arg( tr("Either the module may not be edited, or you do not have write permission.") ) ); - } + QString t = ((CHTMLWriteDisplay*)displayWidget())->toHtml(); + //since t is a complete HTML page at the moment, strip away headers and footers of a HTML page + QRegExp re("(?:<html.*>.+<body.*>)", Qt::CaseInsensitive); //remove headers, case insensitive + re.setMinimal(true); + t.replace(re, ""); + t.replace(QRegExp("</body></html>", Qt::CaseInsensitive), "");//remove footer + + const QString& oldKey = this->key()->key(); + if ( modules().first()->isWritable() ) { + modules().first()->write(this->key(), t ); + this->key()->key( oldKey ); + + ((CWriteDisplay*)displayWidget())->setModified(false); + textChanged(); + } + else { + QMessageBox::critical( this, tr("Module not writable"), + QString::fromLatin1("<qt><b>%1</b><br />%2</qt>") + .arg( tr("Module is not writable.") ) + .arg( tr("Either the module may not be edited, or you do not have write permission.") ) ); + } } diff --git a/src/frontend/displaywindow/chtmlwritewindow.h b/src/frontend/displaywindow/chtmlwritewindow.h index 9c50957..452a362 100644 --- a/src/frontend/displaywindow/chtmlwritewindow.h +++ b/src/frontend/displaywindow/chtmlwritewindow.h @@ -22,54 +22,54 @@ class QAction; * @author The BibleTime team */ class CHTMLWriteWindow : public CPlainWriteWindow { - Q_OBJECT -public: - CHTMLWriteWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); - virtual ~CHTMLWriteWindow(); + Q_OBJECT + public: + CHTMLWriteWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); + virtual ~CHTMLWriteWindow(); - /** - * Store the settings of this window in the given CProfileWindow object. - */ - virtual void storeProfileSettings( Profile::CProfileWindow* ); - /** - * Store the settings of this window in the given profile window. - */ - virtual void applyProfileSettings( Profile::CProfileWindow* ); + /** + * Store the settings of this window in the given CProfileWindow object. + */ + virtual void storeProfileSettings( Profile::CProfileWindow* ); + /** + * Store the settings of this window in the given profile window. + */ + virtual void applyProfileSettings( Profile::CProfileWindow* ); - virtual bool syncAllowed() const; + virtual bool syncAllowed() const; -protected: // Protected methods - /** - * Initialize the state of this widget. - */ - virtual void initView(); - virtual void initConnections(); - virtual void initToolbars(); - virtual CDisplayWindow::WriteWindowType writeWindowType() { - return CDisplayWindow::HTMLWindow; - }; + protected: // Protected methods + /** + * Initialize the state of this widget. + */ + virtual void initView(); + virtual void initConnections(); + virtual void initToolbars(); + virtual CDisplayWindow::WriteWindowType writeWindowType() { + return CDisplayWindow::HTMLWindow; + }; -protected slots: - /** - * Is called when the current text was changed. - */ - virtual void textChanged(); - /** - * Loads the original text from the module. - */ - virtual void restoreText(); - /** - * Saves the text for the current key. Directly writes the changed text into the module. - */ - virtual void saveCurrentText( const QString& ); -private: - struct { - QAction* saveText; - QAction* restoreText; - QAction* deleteEntry; - QAction* syncWindow; - } - m_actions; + protected slots: + /** + * Is called when the current text was changed. + */ + virtual void textChanged(); + /** + * Loads the original text from the module. + */ + virtual void restoreText(); + /** + * Saves the text for the current key. Directly writes the changed text into the module. + */ + virtual void saveCurrentText( const QString& ); + private: + struct { + QAction* saveText; + QAction* restoreText; + QAction* deleteEntry; + QAction* syncWindow; + } + m_actions; }; #endif diff --git a/src/frontend/displaywindow/clexiconreadwindow.cpp b/src/frontend/displaywindow/clexiconreadwindow.cpp index df22de9..d06578e 100644 --- a/src/frontend/displaywindow/clexiconreadwindow.cpp +++ b/src/frontend/displaywindow/clexiconreadwindow.cpp @@ -33,350 +33,330 @@ #include <QAction> CLexiconReadWindow::CLexiconReadWindow(QList<CSwordModuleInfo*> moduleList, CMDIArea* parent) - : CReadWindow(moduleList, parent) -{ - qDebug("CLexiconReadWindow::CLexiconReadWindow"); - moduleList.first(); - setKey( CSwordKey::createInstance(moduleList.first()) ); + : CReadWindow(moduleList, parent) { + qDebug("CLexiconReadWindow::CLexiconReadWindow"); + moduleList.first(); + setKey( CSwordKey::createInstance(moduleList.first()) ); } -CLexiconReadWindow::~CLexiconReadWindow() -{ +CLexiconReadWindow::~CLexiconReadWindow() { } -void CLexiconReadWindow::insertKeyboardActions( BtActionCollection* const a ) -{ - qDebug("CLexiconReadWindow::insertKeyboardActions"); - QAction* qaction; - qaction = new QAction( tr("Next entry"), a); - qaction->setShortcut(CResMgr::displaywindows::lexiconWindow::nextEntry::accel); - a->addAction("nextEntry", qaction); +void CLexiconReadWindow::insertKeyboardActions( BtActionCollection* const a ) { + qDebug("CLexiconReadWindow::insertKeyboardActions"); + QAction* qaction; + qaction = new QAction( tr("Next entry"), a); + qaction->setShortcut(CResMgr::displaywindows::lexiconWindow::nextEntry::accel); + a->addAction("nextEntry", qaction); - qaction = new QAction( tr("Previous entry"), a); - qaction->setShortcut( CResMgr::displaywindows::lexiconWindow::previousEntry::accel); - a->addAction("previousEntry", qaction); - - qaction = new QAction(tr("Copy reference only"), a); - a->addAction("copyReferenceOnly", qaction); + qaction = new QAction( tr("Previous entry"), a); + qaction->setShortcut( CResMgr::displaywindows::lexiconWindow::previousEntry::accel); + a->addAction("previousEntry", qaction); - qaction = new QAction(tr("Save entry as HTML"), a); - a->addAction("saveHtml", qaction); + qaction = new QAction(tr("Copy reference only"), a); + a->addAction("copyReferenceOnly", qaction); - qaction = new QAction(tr("Print reference only"), a); - a->addAction("printReferenceOnly", qaction); + qaction = new QAction(tr("Save entry as HTML"), a); + a->addAction("saveHtml", qaction); - qaction = new QAction(tr("Entry with text"), a); - a->addAction("copyEntryWithText", qaction); + qaction = new QAction(tr("Print reference only"), a); + a->addAction("printReferenceOnly", qaction); - qaction = new QAction(tr("Entry as plain text"), a); - a->addAction("saveEntryAsPlain", qaction); + qaction = new QAction(tr("Entry with text"), a); + a->addAction("copyEntryWithText", qaction); - qaction = new QAction(tr("Entry with text"), a); - a->addAction("printEntryWithText", qaction); + qaction = new QAction(tr("Entry as plain text"), a); + a->addAction("saveEntryAsPlain", qaction); - qaction = new QAction( /* QIcon(CResMgr::displaywindows::general::findStrongs::icon), */ tr("Strong's Search"), a); - qaction->setShortcut(CResMgr::displaywindows::general::findStrongs::accel); - a->addAction(CResMgr::displaywindows::general::findStrongs::actionName, qaction); + qaction = new QAction(tr("Entry with text"), a); + a->addAction("printEntryWithText", qaction); + + qaction = new QAction( /* QIcon(CResMgr::displaywindows::general::findStrongs::icon), */ tr("Strong's Search"), a); + qaction->setShortcut(CResMgr::displaywindows::general::findStrongs::accel); + a->addAction(CResMgr::displaywindows::general::findStrongs::actionName, qaction); } -void CLexiconReadWindow::initActions() -{ - qDebug("CLexiconReadWindow::initActions"); +void CLexiconReadWindow::initActions() { + qDebug("CLexiconReadWindow::initActions"); + + BtActionCollection* ac = actionCollection(); + CReadWindow::initActions(); + CLexiconReadWindow::insertKeyboardActions(ac); - BtActionCollection* ac = actionCollection(); - CReadWindow::initActions(); - CLexiconReadWindow::insertKeyboardActions(ac); + m_actions.backInHistory = dynamic_cast<BtToolBarPopupAction*>( + ac->action(CResMgr::displaywindows::general::backInHistory::actionName) ); + Q_ASSERT(m_actions.backInHistory); + addAction(m_actions.backInHistory); - m_actions.backInHistory = dynamic_cast<BtToolBarPopupAction*>( - ac->action(CResMgr::displaywindows::general::backInHistory::actionName) ); - Q_ASSERT(m_actions.backInHistory); - addAction(m_actions.backInHistory); + m_actions.forwardInHistory = dynamic_cast<BtToolBarPopupAction*>( + ac->action(CResMgr::displaywindows::general::forwardInHistory::actionName) ); + Q_ASSERT(m_actions.forwardInHistory); + addAction(m_actions.forwardInHistory); - m_actions.forwardInHistory = dynamic_cast<BtToolBarPopupAction*>( - ac->action(CResMgr::displaywindows::general::forwardInHistory::actionName) ); - Q_ASSERT(m_actions.forwardInHistory); - addAction(m_actions.forwardInHistory); + QAction* qaction; - QAction* qaction; + qaction = ac->action("nextEntry"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT( nextEntry() ) ); + addAction(qaction); - qaction = ac->action("nextEntry"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT( nextEntry() ) ); - addAction(qaction); + qaction = ac->action("previousEntry"); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT( previousEntry() ) ); + addAction(qaction); - qaction = ac->action("previousEntry"); - QObject::connect(qaction, SIGNAL(triggered()), this, SLOT( previousEntry() ) ); - addAction(qaction); + m_actions.selectAll = ac->action("selectAll"); + Q_ASSERT(m_actions.selectAll); - m_actions.selectAll = ac->action("selectAll"); - Q_ASSERT(m_actions.selectAll); + m_actions.findText = ac->action("findText"); + Q_ASSERT(m_actions.findText); - m_actions.findText = ac->action("findText"); - Q_ASSERT(m_actions.findText); + m_actions.findStrongs = ac->action(CResMgr::displaywindows::general::findStrongs::actionName); + QObject::connect(m_actions.findStrongs, SIGNAL(triggered()), this, SLOT(openSearchStrongsDialog()) ); + addAction(m_actions.findStrongs); - m_actions.findStrongs = ac->action(CResMgr::displaywindows::general::findStrongs::actionName); - QObject::connect(m_actions.findStrongs, SIGNAL(triggered()), this, SLOT(openSearchStrongsDialog()) ); - addAction(m_actions.findStrongs); + m_actions.copy.reference = ac->action("copyReferenceOnly"); + QObject::connect(m_actions.copy.reference, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAnchorOnly()) ); + addAction(m_actions.copy.reference); - m_actions.copy.reference = ac->action("copyReferenceOnly"); - QObject::connect(m_actions.copy.reference, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAnchorOnly()) ); - addAction(m_actions.copy.reference); + m_actions.copy.entry = ac->action("copyEntryWithText"); + QObject::connect(m_actions.copy.entry, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAll()) ); + addAction(m_actions.copy.entry); - m_actions.copy.entry = ac->action("copyEntryWithText"); - QObject::connect(m_actions.copy.entry, SIGNAL(triggered()), displayWidget()->connectionsProxy(), SLOT(copyAll()) ); - addAction(m_actions.copy.entry); + Q_ASSERT(ac->action("copySelectedText")); + m_actions.copy.selectedText = ac->action("copySelectedText"); - Q_ASSERT(ac->action("copySelectedText")); - m_actions.copy.selectedText = ac->action("copySelectedText"); - - m_actions.save.entryAsPlain = new QAction(tr("Entry as plain text"), ac ); - QObject::connect(m_actions.save.entryAsPlain, SIGNAL(triggered()), this, SLOT(saveAsPlain()) ); - addAction(m_actions.save.entryAsPlain); + m_actions.save.entryAsPlain = new QAction(tr("Entry as plain text"), ac ); + QObject::connect(m_actions.save.entryAsPlain, SIGNAL(triggered()), this, SLOT(saveAsPlain()) ); + addAction(m_actions.save.entryAsPlain); - m_actions.save.entryAsHTML = ac->action("saveHtml"); - QObject::connect(m_actions.save.entryAsHTML, SIGNAL(triggered()), this, SLOT(saveAsHTML())); - addAction(m_actions.save.entryAsHTML); + m_actions.save.entryAsHTML = ac->action("saveHtml"); + QObject::connect(m_actions.save.entryAsHTML, SIGNAL(triggered()), this, SLOT(saveAsHTML())); + addAction(m_actions.save.entryAsHTML); - m_actions.print.reference = ac->action("printReferenceOnly"); - QObject::connect(m_actions.print.reference, SIGNAL(triggered()), this, SLOT(printAnchorWithText())); - addAction(m_actions.print.reference); + m_actions.print.reference = ac->action("printReferenceOnly"); + QObject::connect(m_actions.print.reference, SIGNAL(triggered()), this, SLOT(printAnchorWithText())); + addAction(m_actions.print.reference); - m_actions.print.entry = ac->action("printEntryWithText"); - QObject::connect(m_actions.print.entry, SIGNAL(triggered()), this, SLOT(printAll())); - addAction(m_actions.print.entry); + m_actions.print.entry = ac->action("printEntryWithText"); + QObject::connect(m_actions.print.entry, SIGNAL(triggered()), this, SLOT(printAll())); + addAction(m_actions.print.entry); - // init with the user defined settings - qDebug("call CBTConfig::setupAccelSettings(CBTConfig::lexiconWindow, ac); and end CLexiconReadWindow::initActions"); - CBTConfig::setupAccelSettings(CBTConfig::lexiconWindow, ac); + // init with the user defined settings + qDebug("call CBTConfig::setupAccelSettings(CBTConfig::lexiconWindow, ac); and end CLexiconReadWindow::initActions"); + CBTConfig::setupAccelSettings(CBTConfig::lexiconWindow, ac); } /** No descriptions */ -void CLexiconReadWindow::initConnections() -{ - qDebug("CLexiconReadWindow::initConnections"); - Q_ASSERT(keyChooser()); - - connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*))); - connect(keyChooser()->history(), SIGNAL(historyChanged(bool, bool)), this, SLOT(slotUpdateHistoryButtons(bool, bool))); - - //connect the history actions to the right slots - bool ok = connect( - m_actions.backInHistory->popupMenu(), SIGNAL(aboutToShow()), - this, SLOT(slotFillBackHistory()) - ); - Q_ASSERT(ok); - ok = connect( - m_actions.backInHistory->popupMenu(), SIGNAL(triggered(QAction*)), - keyChooser()->history(), SLOT(move(QAction*)) - ); - Q_ASSERT(ok); - ok = connect( - m_actions.forwardInHistory->popupMenu(), SIGNAL(aboutToShow()), - this, SLOT(slotFillForwardHistory()) - ); - Q_ASSERT(ok); - ok = connect( - m_actions.forwardInHistory->popupMenu(), SIGNAL(triggered(QAction*)), - keyChooser()->history(), SLOT(move(QAction*)) - ); - Q_ASSERT(ok); +void CLexiconReadWindow::initConnections() { + qDebug("CLexiconReadWindow::initConnections"); + Q_ASSERT(keyChooser()); + + connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*))); + connect(keyChooser()->history(), SIGNAL(historyChanged(bool, bool)), this, SLOT(slotUpdateHistoryButtons(bool, bool))); + + //connect the history actions to the right slots + bool ok = connect( + m_actions.backInHistory->popupMenu(), SIGNAL(aboutToShow()), + this, SLOT(slotFillBackHistory()) + ); + Q_ASSERT(ok); + ok = connect( + m_actions.backInHistory->popupMenu(), SIGNAL(triggered(QAction*)), + keyChooser()->history(), SLOT(move(QAction*)) + ); + Q_ASSERT(ok); + ok = connect( + m_actions.forwardInHistory->popupMenu(), SIGNAL(aboutToShow()), + this, SLOT(slotFillForwardHistory()) + ); + Q_ASSERT(ok); + ok = connect( + m_actions.forwardInHistory->popupMenu(), SIGNAL(triggered(QAction*)), + keyChooser()->history(), SLOT(move(QAction*)) + ); + Q_ASSERT(ok); } -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(); - addToolBar(moduleChooserBar()); - setButtonsToolBar( new QToolBar(this) ); - buttonsToolBar()->setAllowedAreas(Qt::TopToolBarArea); - buttonsToolBar()->setFloatable(false); - addToolBar(buttonsToolBar()); - setWindowIcon(CToolClass::getIconForModule(modules().first())); - setCentralWidget( displayWidget()->view() ); +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(); + addToolBar(moduleChooserBar()); + setButtonsToolBar( new QToolBar(this) ); + buttonsToolBar()->setAllowedAreas(Qt::TopToolBarArea); + buttonsToolBar()->setFloatable(false); + addToolBar(buttonsToolBar()); + setWindowIcon(CToolClass::getIconForModule(modules().first())); + setCentralWidget( displayWidget()->view() ); } -void CLexiconReadWindow::initToolbars() -{ - //main toolbar - Q_ASSERT(m_actions.backInHistory); - mainToolBar()->addAction(m_actions.backInHistory); //1st button - mainToolBar()->addAction(m_actions.forwardInHistory); //2nd button - - //buttons toolbar - QAction* action = qobject_cast<QAction*>(actionCollection()->action( - CResMgr::displaywindows::general::search::actionName)); - Q_ASSERT( action ); - if (action) { - buttonsToolBar()->addAction(action); - } - setDisplaySettingsButton( new CDisplaySettingsButton( &displayOptions(), &filterOptions(), modules(), buttonsToolBar()) ); - - //TODO: find the right place for the button - buttonsToolBar()->addWidget(displaySettingsButton()); +void CLexiconReadWindow::initToolbars() { + //main toolbar + Q_ASSERT(m_actions.backInHistory); + mainToolBar()->addAction(m_actions.backInHistory); //1st button + mainToolBar()->addAction(m_actions.forwardInHistory); //2nd button + + //buttons toolbar + QAction* action = qobject_cast<QAction*>(actionCollection()->action( + CResMgr::displaywindows::general::search::actionName)); + Q_ASSERT( action ); + if (action) { + buttonsToolBar()->addAction(action); + } + setDisplaySettingsButton( new CDisplaySettingsButton( &displayOptions(), &filterOptions(), modules(), buttonsToolBar()) ); + + //TODO: find the right place for the button + buttonsToolBar()->addWidget(displaySettingsButton()); } -void CLexiconReadWindow::setupPopupMenu() -{ - popup()->setTitle(tr("Lexicon window")); - popup()->setIcon(CToolClass::getIconForModule(modules().first())); - popup()->addAction(m_actions.findText); - popup()->addAction(m_actions.findStrongs); - popup()->addAction(m_actions.selectAll); - popup()->addSeparator(); - - m_actions.copyMenu = new QMenu(tr("Copy..."), popup()); - - m_actions.copyMenu->addAction(m_actions.copy.reference); - m_actions.copyMenu->addAction(m_actions.copy.entry); - m_actions.copyMenu->addSeparator(); - m_actions.copyMenu->addAction(m_actions.copy.selectedText); - popup()->addMenu(m_actions.copyMenu); - - m_actions.saveMenu = new QMenu( - tr("Save..."), - popup() - ); - m_actions.saveMenu->addAction(m_actions.save.entryAsPlain); - m_actions.saveMenu->addAction(m_actions.save.entryAsHTML); - - // Save raw HTML action for debugging purposes - if (qApp->property("--debug").toBool()) { - QAction* debugAction = new QAction("Raw HTML", this); - QObject::connect(debugAction, SIGNAL(triggered()), this, SLOT(saveRawHTML())); - m_actions.saveMenu->addAction(debugAction); - } // end of Save Raw HTML - - popup()->addMenu(m_actions.saveMenu); - - m_actions.printMenu = new QMenu( - tr("Print..."), - popup() - ); - m_actions.printMenu->addAction(m_actions.print.reference); - m_actions.printMenu->addAction(m_actions.print.entry); - popup()->addMenu(m_actions.printMenu); +void CLexiconReadWindow::setupPopupMenu() { + popup()->setTitle(tr("Lexicon window")); + popup()->setIcon(CToolClass::getIconForModule(modules().first())); + popup()->addAction(m_actions.findText); + popup()->addAction(m_actions.findStrongs); + popup()->addAction(m_actions.selectAll); + popup()->addSeparator(); + + m_actions.copyMenu = new QMenu(tr("Copy..."), popup()); + + m_actions.copyMenu->addAction(m_actions.copy.reference); + m_actions.copyMenu->addAction(m_actions.copy.entry); + m_actions.copyMenu->addSeparator(); + m_actions.copyMenu->addAction(m_actions.copy.selectedText); + popup()->addMenu(m_actions.copyMenu); + + m_actions.saveMenu = new QMenu( + tr("Save..."), + popup() + ); + m_actions.saveMenu->addAction(m_actions.save.entryAsPlain); + m_actions.saveMenu->addAction(m_actions.save.entryAsHTML); + + // Save raw HTML action for debugging purposes + if (qApp->property("--debug").toBool()) { + QAction* debugAction = new QAction("Raw HTML", this); + QObject::connect(debugAction, SIGNAL(triggered()), this, SLOT(saveRawHTML())); + m_actions.saveMenu->addAction(debugAction); + } // end of Save Raw HTML + + popup()->addMenu(m_actions.saveMenu); + + m_actions.printMenu = new QMenu( + tr("Print..."), + popup() + ); + m_actions.printMenu->addAction(m_actions.print.reference); + m_actions.printMenu->addAction(m_actions.print.entry); + popup()->addMenu(m_actions.printMenu); } /** Reimplemented. */ -void CLexiconReadWindow::updatePopupMenu() -{ - //enable the action depending on the supported module features +void CLexiconReadWindow::updatePopupMenu() { + //enable the action depending on the supported module features + + m_actions.findStrongs->setEnabled( displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != QString::null ); - m_actions.findStrongs->setEnabled( displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != QString::null ); - - m_actions.copy.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); - m_actions.copy.selectedText->setEnabled( displayWidget()->hasSelection() ); + m_actions.copy.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); + m_actions.copy.selectedText->setEnabled( displayWidget()->hasSelection() ); - m_actions.print.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); + m_actions.print.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() ); } -void CLexiconReadWindow::reload(CSwordBackend::SetupChangedReason reason) -{ - CReadWindow::reload(reason); +void CLexiconReadWindow::reload(CSwordBackend::SetupChangedReason reason) { + CReadWindow::reload(reason); - CBTConfig::setupAccelSettings(CBTConfig::lexiconWindow, actionCollection()); + CBTConfig::setupAccelSettings(CBTConfig::lexiconWindow, actionCollection()); } /** No descriptions */ -void CLexiconReadWindow::nextEntry() -{ - keyChooser()->setKey(ldKey()->NextEntry()); +void CLexiconReadWindow::nextEntry() { + keyChooser()->setKey(ldKey()->NextEntry()); } /** No descriptions */ -void CLexiconReadWindow::previousEntry() -{ - keyChooser()->setKey(ldKey()->PreviousEntry()); +void CLexiconReadWindow::previousEntry() { + keyChooser()->setKey(ldKey()->PreviousEntry()); } /** Reimplementation to return the right key. */ -CSwordLDKey* CLexiconReadWindow::ldKey() -{ - return dynamic_cast<CSwordLDKey*>(CDisplayWindow::key()); +CSwordLDKey* CLexiconReadWindow::ldKey() { + return dynamic_cast<CSwordLDKey*>(CDisplayWindow::key()); } /** This function saves the entry as html using the CExportMgr class. */ void CLexiconReadWindow::saveAsHTML() { - CExportManager mgr(tr("Saving entry ..."), true, tr("Saving"), filterOptions(), displayOptions()); - mgr.saveKey(key(), CExportManager::HTML, true); + CExportManager mgr(tr("Saving entry ..."), true, tr("Saving"), filterOptions(), displayOptions()); + mgr.saveKey(key(), CExportManager::HTML, true); } /** Saving the raw HTML for debugging purposes */ -void CLexiconReadWindow::saveRawHTML() -{ - //qDebug("CLexiconReadWindow::saveRawHTML"); - QString savefilename = QFileDialog::getSaveFileName(); - if (savefilename.isEmpty()) return; - QFile file(savefilename); - BtHtmlReadDisplay* disp = dynamic_cast<BtHtmlReadDisplay*>(displayWidget()); - if (disp) { - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) - { - qDebug("could not open file"); - return; - } - QString source = disp->text(); - file.write(source.toUtf8()); - //qDebug() << "wrote" << bytes << "bytes"; - file.close(); - file.flush(); - } else { - qDebug("No htmlreaddisplay widget!"); - } - +void CLexiconReadWindow::saveRawHTML() { + //qDebug("CLexiconReadWindow::saveRawHTML"); + QString savefilename = QFileDialog::getSaveFileName(); + if (savefilename.isEmpty()) return; + QFile file(savefilename); + BtHtmlReadDisplay* disp = dynamic_cast<BtHtmlReadDisplay*>(displayWidget()); + if (disp) { + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + qDebug("could not open file"); + return; + } + QString source = disp->text(); + file.write(source.toUtf8()); + //qDebug() << "wrote" << bytes << "bytes"; + file.close(); + file.flush(); + } + else { + qDebug("No htmlreaddisplay widget!"); + } + } /** This function saves the entry as html using the CExportMgr class. */ -void CLexiconReadWindow::saveAsPlain() -{ - CExportManager mgr(tr("Saving entry ..."), true, tr("Saving"), filterOptions(), displayOptions()); - mgr.saveKey(key(), CExportManager::Text, true); +void CLexiconReadWindow::saveAsPlain() { + CExportManager mgr(tr("Saving entry ..."), true, tr("Saving"), filterOptions(), displayOptions()); + mgr.saveKey(key(), CExportManager::Text, true); } -void CLexiconReadWindow::slotFillBackHistory() -{ - qDebug("CLexiconReadWindow::slotFillBackHistory"); +void CLexiconReadWindow::slotFillBackHistory() { + qDebug("CLexiconReadWindow::slotFillBackHistory"); - QMenu* menu = m_actions.backInHistory->popupMenu(); - menu->clear(); + QMenu* menu = m_actions.backInHistory->popupMenu(); + menu->clear(); - //TODO: take the history list and fill the menu - QListIterator<QAction*> it(keyChooser()->history()->getBackList()); - while (it.hasNext()) - { - menu->addAction(it.next()); - } + //TODO: take the history list and fill the menu + QListIterator<QAction*> it(keyChooser()->history()->getBackList()); + while (it.hasNext()) { + menu->addAction(it.next()); + } } -void CLexiconReadWindow::slotFillForwardHistory() -{ - qDebug("CLexiconReadWindow::slotFillForwardHistory"); - - QMenu* menu = m_actions.forwardInHistory->popupMenu(); - menu->clear(); - //TODO: take the history list and fill the menu using addAction - QListIterator<QAction*> it(keyChooser()->history()->getFwList()); - while (it.hasNext()) - { - menu->addAction(it.next()); - } +void CLexiconReadWindow::slotFillForwardHistory() { + qDebug("CLexiconReadWindow::slotFillForwardHistory"); + + QMenu* menu = m_actions.forwardInHistory->popupMenu(); + menu->clear(); + //TODO: take the history list and fill the menu using addAction + QListIterator<QAction*> it(keyChooser()->history()->getFwList()); + while (it.hasNext()) { + menu->addAction(it.next()); + } } -void CLexiconReadWindow::slotUpdateHistoryButtons(bool backEnabled, bool fwEnabled) -{ - qDebug("CLexiconReadWindow::slotUpdateHistoryButtons"); - Q_ASSERT(m_actions.backInHistory); - Q_ASSERT(keyChooser()); +void CLexiconReadWindow::slotUpdateHistoryButtons(bool backEnabled, bool fwEnabled) { + qDebug("CLexiconReadWindow::slotUpdateHistoryButtons"); + Q_ASSERT(m_actions.backInHistory); + Q_ASSERT(keyChooser()); - m_actions.backInHistory->setEnabled( backEnabled ); - m_actions.forwardInHistory->setEnabled( fwEnabled ); + m_actions.backInHistory->setEnabled( backEnabled ); + m_actions.forwardInHistory->setEnabled( fwEnabled ); } diff --git a/src/frontend/displaywindow/clexiconreadwindow.h b/src/frontend/displaywindow/clexiconreadwindow.h index 45e9ceb..ee28c25 100644 --- a/src/frontend/displaywindow/clexiconreadwindow.h +++ b/src/frontend/displaywindow/clexiconreadwindow.h @@ -26,95 +26,95 @@ class QMenu; */ class CLexiconReadWindow : public CReadWindow { - Q_OBJECT -public: - CLexiconReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); - virtual ~CLexiconReadWindow(); - /** - * Store the settings of this window in the given CProfileWindow object. - */ - // virtual void storeProfileSettings( CProfileWindow* profileWindow ); - /** - * Store the settings of this window in the given profile window. - */ - // virtual void applyProfileSettings( CProfileWindow* profileWindow ); - /** - * Reimplementation. - */ - // static void insertKeyboardActions( KAccel* a ); - static void insertKeyboardActions( BtActionCollection* const a ); - -public slots: - /** - * Refreshes the content of this display window and the content of the keychooser. - */ - virtual void reload(CSwordBackend::SetupChangedReason reason); - -protected: - virtual void initActions(); - virtual void initToolbars(); - virtual void initConnections(); - virtual void initView(); - virtual void updatePopupMenu(); - virtual void setupPopupMenu(); - - - struct ActionsStruct { - BtToolBarPopupAction* backInHistory; - BtToolBarPopupAction* forwardInHistory; - - QAction* selectAll; - QAction* findText; - QAction* findStrongs; - - QMenu* copyMenu; - struct { - QAction* reference; - QAction* entry; - QAction* selectedText; - } - copy; - - QMenu* saveMenu; - struct { - QAction* reference; - QAction* entryAsPlain; - QAction* entryAsHTML; - } - save; - - QMenu* printMenu; - struct { - QAction* reference; - QAction* entry; - } - print; - } - m_actions; - -private: - /** - * Reimplementation to return the right key. - */ - CSwordLDKey* ldKey(); - -protected slots: // Protected slots - void previousEntry(); - void nextEntry(); - /** - * This function saves the entry as html using the CExportMgr class. - */ - void saveAsHTML(); - /** - * This function saves the entry as plain text using the CExportMgr class. - */ - void saveAsPlain(); - void saveRawHTML(); - - void slotFillBackHistory(); - void slotFillForwardHistory(); - - void slotUpdateHistoryButtons(bool backEnabled, bool fwEnabled); + Q_OBJECT + public: + CLexiconReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); + virtual ~CLexiconReadWindow(); + /** + * Store the settings of this window in the given CProfileWindow object. + */ + // virtual void storeProfileSettings( CProfileWindow* profileWindow ); + /** + * Store the settings of this window in the given profile window. + */ + // virtual void applyProfileSettings( CProfileWindow* profileWindow ); + /** + * Reimplementation. + */ + // static void insertKeyboardActions( KAccel* a ); + static void insertKeyboardActions( BtActionCollection* const a ); + + public slots: + /** + * Refreshes the content of this display window and the content of the keychooser. + */ + virtual void reload(CSwordBackend::SetupChangedReason reason); + + protected: + virtual void initActions(); + virtual void initToolbars(); + virtual void initConnections(); + virtual void initView(); + virtual void updatePopupMenu(); + virtual void setupPopupMenu(); + + + struct ActionsStruct { + BtToolBarPopupAction* backInHistory; + BtToolBarPopupAction* forwardInHistory; + + QAction* selectAll; + QAction* findText; + QAction* findStrongs; + + QMenu* copyMenu; + struct { + QAction* reference; + QAction* entry; + QAction* selectedText; + } + copy; + + QMenu* saveMenu; + struct { + QAction* reference; + QAction* entryAsPlain; + QAction* entryAsHTML; + } + save; + + QMenu* printMenu; + struct { + QAction* reference; + QAction* entry; + } + print; + } + m_actions; + + private: + /** + * Reimplementation to return the right key. + */ + CSwordLDKey* ldKey(); + + protected slots: // Protected slots + void previousEntry(); + void nextEntry(); + /** + * This function saves the entry as html using the CExportMgr class. + */ + void saveAsHTML(); + /** + * This function saves the entry as plain text using the CExportMgr class. + */ + void saveAsPlain(); + void saveRawHTML(); + + void slotFillBackHistory(); + void slotFillForwardHistory(); + + void slotUpdateHistoryButtons(bool backEnabled, bool fwEnabled); }; #endif diff --git a/src/frontend/displaywindow/cmodulechooserbar.cpp b/src/frontend/displaywindow/cmodulechooserbar.cpp index a282c4b..2e47851 100644 --- a/src/frontend/displaywindow/cmodulechooserbar.cpp +++ b/src/frontend/displaywindow/cmodulechooserbar.cpp @@ -17,113 +17,110 @@ #include <QToolBar> 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 - } + : 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; +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); + 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 + 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; + 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; + 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(); - } + const int tooMuch = m_buttonList.size() - limit; + for (int i = 0; i < tooMuch; ++i) { + CModuleChooserButton* b = m_buttonList.takeLast(); + b->deleteLater(); + } - updateMenuItems(); + 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 + setButtonLimit(0); + setButtonLimit(-1); //these two lines clear the bar - if (!useModules.count()) return; + 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 ); - } + 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 - } + if ( (m_buttonLimit == -1) || (m_buttonLimit > (int)m_buttonList.count()) ) { + addButton(0);//add button without module set + } - updateMenuItems(); + 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(); + 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 index d21fcb9..1a9ce95 100644 --- a/src/frontend/displaywindow/cmodulechooserbar.h +++ b/src/frontend/displaywindow/cmodulechooserbar.h @@ -26,51 +26,51 @@ 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 ); + 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(); + signals: + void sigChanged(); -protected: - /** - * Adds a button to the toolbar - */ - CModuleChooserButton* addButton( CSwordModuleInfo* const module ); + 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(); + 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; + private: + CSwordModuleInfo::ModuleType m_moduleType; + int m_idCounter; + int m_buttonLimit; + QList<CModuleChooserButton*> m_buttonList; }; diff --git a/src/frontend/displaywindow/cmodulechooserbutton.cpp b/src/frontend/displaywindow/cmodulechooserbutton.cpp index dd5a9ee..14760e0 100644 --- a/src/frontend/displaywindow/cmodulechooserbutton.cpp +++ b/src/frontend/displaywindow/cmodulechooserbutton.cpp @@ -26,186 +26,184 @@ #include <QMenu> #include <QtDebug> -CModuleChooserButton::CModuleChooserButton(CSwordModuleInfo* useModule,CSwordModuleInfo::ModuleType type, const int id, CModuleChooserBar *parent) - : QToolButton(parent), - m_id(id), m_popup(0), m_moduleChooserBar(parent) -{ - m_moduleType = type; - m_module = useModule; - m_hasModule = (m_module) ? true : false; - - setIcon( util::filesystem::DirectoryUtil::getIcon(iconName()) ); - setPopupMode(QToolButton::InstantPopup); - - populateMenu(); +CModuleChooserButton::CModuleChooserButton(CSwordModuleInfo* useModule, CSwordModuleInfo::ModuleType type, const int id, CModuleChooserBar *parent) + : QToolButton(parent), + m_id(id), m_popup(0), m_moduleChooserBar(parent) { + m_moduleType = type; + m_module = useModule; + m_hasModule = (m_module) ? true : false; + + setIcon( util::filesystem::DirectoryUtil::getIcon(iconName()) ); + setPopupMode(QToolButton::InstantPopup); + + populateMenu(); } CModuleChooserButton::~CModuleChooserButton() { - qDeleteAll(m_submenus); - m_submenus.clear(); - delete m_popup; //not necessary, because has "this" as parent? + 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; - } + 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 + 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; + return m_id; } /** Is called after a module was selected in the popup */ void CModuleChooserButton::moduleChosen( QAction* action ) { - - 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( util::filesystem::DirectoryUtil::getIcon(iconName()) ); - emit sigChanged(); - - if (m_module) { - setToolTip( tr("Select a work") + " [" + m_module->name() + "]" ); - } - else { - setToolTip( tr("Select an additional work") ); - } - } + + 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( util::filesystem::DirectoryUtil::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); + 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::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); - } - } + 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 index 7715bf3..23646c9 100644 --- a/src/frontend/displaywindow/cmodulechooserbutton.h +++ b/src/frontend/displaywindow/cmodulechooserbutton.h @@ -27,56 +27,60 @@ class CModuleChooserBar; * @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(); + 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/cplainwritewindow.cpp b/src/frontend/displaywindow/cplainwritewindow.cpp index 71dc603..dc97aec 100644 --- a/src/frontend/displaywindow/cplainwritewindow.cpp +++ b/src/frontend/displaywindow/cplainwritewindow.cpp @@ -30,9 +30,8 @@ using namespace Profile; CPlainWriteWindow::CPlainWriteWindow(QList<CSwordModuleInfo*> moduleList, CMDIArea* parent) : - CWriteWindow(moduleList, parent) -{ - setKey( CSwordKey::createInstance(moduleList.first()) ); + CWriteWindow(moduleList, parent) { + setKey( CSwordKey::createInstance(moduleList.first()) ); } @@ -40,142 +39,142 @@ CPlainWriteWindow::~CPlainWriteWindow() {} /** Initialize the state of this widget. */ void CPlainWriteWindow::initView() { - // qWarning("CPlainWriteWindow::initView()"); - setDisplayWidget( CDisplay::createWriteInstance(this) ); - setCentralWidget( displayWidget()->view() ); - - setMainToolBar( new QToolBar(this) ); - mainToolBar()->setAllowedAreas(Qt::TopToolBarArea); - mainToolBar()->setFloatable(false); - addToolBar(mainToolBar()); - addToolBarBreak(); - - setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) ); - mainToolBar()->addWidget(keyChooser()); + // qWarning("CPlainWriteWindow::initView()"); + setDisplayWidget( CDisplay::createWriteInstance(this) ); + setCentralWidget( displayWidget()->view() ); + + setMainToolBar( new QToolBar(this) ); + mainToolBar()->setAllowedAreas(Qt::TopToolBarArea); + mainToolBar()->setFloatable(false); + addToolBar(mainToolBar()); + addToolBarBreak(); + + setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) ); + mainToolBar()->addWidget(keyChooser()); } void CPlainWriteWindow::initToolbars() { - m_actions.syncWindow = new QAction( - //KIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon), - util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon), - tr("Sync with active Bible"), - actionCollection() - ); - m_actions.syncWindow->setCheckable(true); - m_actions.syncWindow->setShortcut(CResMgr::displaywindows::commentaryWindow::syncWindow::accel); - m_actions.syncWindow->setToolTip(tr("Synchronize (show the same verse) with the active Bible window")); - mainToolBar()->addAction(m_actions.syncWindow); - actionCollection()->addAction(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName, m_actions.syncWindow); - - - m_actions.saveText = new QAction( - //KIcon(CResMgr::displaywindows::writeWindow::saveText::icon), - util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::saveText::icon), - tr("Save text"), - actionCollection() - ); - m_actions.saveText->setShortcut(CResMgr::displaywindows::writeWindow::saveText::accel); - QObject::connect(m_actions.saveText, SIGNAL(triggered()), this, SLOT(saveCurrentText())); - m_actions.saveText->setToolTip( tr("Save text") ); - actionCollection()->addAction(CResMgr::displaywindows::writeWindow::saveText::actionName, m_actions.saveText); - mainToolBar()->addAction(m_actions.saveText); - - - m_actions.deleteEntry = new QAction( - //KIcon(CResMgr::displaywindows::writeWindow::deleteEntry::icon), - util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::deleteEntry::icon), - tr("Delete current entry"), - actionCollection() - ); - m_actions.deleteEntry->setShortcut(CResMgr::displaywindows::writeWindow::deleteEntry::accel); - QObject::connect(m_actions.deleteEntry, SIGNAL(triggered()), this, SLOT(deleteEntry()) ); - m_actions.deleteEntry->setToolTip( tr("Delete current entry (no undo)") ); - actionCollection()->addAction(CResMgr::displaywindows::writeWindow::deleteEntry::actionName, m_actions.deleteEntry); - mainToolBar()->addAction(m_actions.deleteEntry); - - - m_actions.restoreText = new QAction( - //KIcon(CResMgr::displaywindows::writeWindow::restoreText::icon), - util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::restoreText::icon), - tr("Restore original text"), - actionCollection() - ); - m_actions.restoreText->setShortcut(CResMgr::displaywindows::writeWindow::restoreText::accel); - QObject::connect(m_actions.restoreText, SIGNAL(triggered()), this, SLOT(restoreText()) ); - m_actions.restoreText->setToolTip( tr("Restore original text, new text will be lost") ); - actionCollection()->addAction(CResMgr::displaywindows::writeWindow::restoreText::actionName, m_actions.restoreText); - mainToolBar()->addAction(m_actions.restoreText); + m_actions.syncWindow = new QAction( + //KIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon), + util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon), + tr("Sync with active Bible"), + actionCollection() + ); + m_actions.syncWindow->setCheckable(true); + m_actions.syncWindow->setShortcut(CResMgr::displaywindows::commentaryWindow::syncWindow::accel); + m_actions.syncWindow->setToolTip(tr("Synchronize (show the same verse) with the active Bible window")); + mainToolBar()->addAction(m_actions.syncWindow); + actionCollection()->addAction(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName, m_actions.syncWindow); + + + m_actions.saveText = new QAction( + //KIcon(CResMgr::displaywindows::writeWindow::saveText::icon), + util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::saveText::icon), + tr("Save text"), + actionCollection() + ); + m_actions.saveText->setShortcut(CResMgr::displaywindows::writeWindow::saveText::accel); + QObject::connect(m_actions.saveText, SIGNAL(triggered()), this, SLOT(saveCurrentText())); + m_actions.saveText->setToolTip( tr("Save text") ); + actionCollection()->addAction(CResMgr::displaywindows::writeWindow::saveText::actionName, m_actions.saveText); + mainToolBar()->addAction(m_actions.saveText); + + + m_actions.deleteEntry = new QAction( + //KIcon(CResMgr::displaywindows::writeWindow::deleteEntry::icon), + util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::deleteEntry::icon), + tr("Delete current entry"), + actionCollection() + ); + m_actions.deleteEntry->setShortcut(CResMgr::displaywindows::writeWindow::deleteEntry::accel); + QObject::connect(m_actions.deleteEntry, SIGNAL(triggered()), this, SLOT(deleteEntry()) ); + m_actions.deleteEntry->setToolTip( tr("Delete current entry (no undo)") ); + actionCollection()->addAction(CResMgr::displaywindows::writeWindow::deleteEntry::actionName, m_actions.deleteEntry); + mainToolBar()->addAction(m_actions.deleteEntry); + + + m_actions.restoreText = new QAction( + //KIcon(CResMgr::displaywindows::writeWindow::restoreText::icon), + util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::writeWindow::restoreText::icon), + tr("Restore original text"), + actionCollection() + ); + m_actions.restoreText->setShortcut(CResMgr::displaywindows::writeWindow::restoreText::accel); + QObject::connect(m_actions.restoreText, SIGNAL(triggered()), this, SLOT(restoreText()) ); + m_actions.restoreText->setToolTip( tr("Restore original text, new text will be lost") ); + actionCollection()->addAction(CResMgr::displaywindows::writeWindow::restoreText::actionName, m_actions.restoreText); + mainToolBar()->addAction(m_actions.restoreText); } void CPlainWriteWindow::initConnections() { - CWriteWindow::initConnections(); - QObject::connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*))); - QObject::connect(displayWidget()->connectionsProxy(), SIGNAL(textChanged()), this, SLOT(textChanged()) ); + CWriteWindow::initConnections(); + QObject::connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*))); + QObject::connect(displayWidget()->connectionsProxy(), SIGNAL(textChanged()), this, SLOT(textChanged()) ); } void CPlainWriteWindow::storeProfileSettings( CProfileWindow* profileWindow ) { - CWriteWindow::storeProfileSettings(profileWindow); - profileWindow->setWindowSettings( m_actions.syncWindow->isChecked() ); + CWriteWindow::storeProfileSettings(profileWindow); + profileWindow->setWindowSettings( m_actions.syncWindow->isChecked() ); } void CPlainWriteWindow::applyProfileSettings( CProfileWindow* profileWindow ) { - CWriteWindow::applyProfileSettings(profileWindow); - if (profileWindow->windowSettings()) { - m_actions.syncWindow->setChecked(true); - } + CWriteWindow::applyProfileSettings(profileWindow); + if (profileWindow->windowSettings()) { + m_actions.syncWindow->setChecked(true); + } } /** Saves the text for the current key. Directly writes the changed text into the module. */ void CPlainWriteWindow::saveCurrentText( const QString& /*key*/ ) { - QString t = ((CWriteDisplay*)displayWidget())->plainText(); - //since t is a complete HTML page at the moment, strip away headers and footers of a HTML page - QRegExp re("(?:<html.*>.+<body.*>)", Qt::CaseInsensitive); //remove headers, case insensitive - re.setMinimal(true); - t.replace(re, ""); - t.replace(QRegExp("</body></html>", Qt::CaseInsensitive), "");//remove footer - - const QString& oldKey = this->key()->key(); - if( modules().first()->isWritable() ) { - modules().first()->write(this->key(), t ); - this->key()->key( oldKey ); - - ((CWriteDisplay*)displayWidget())->setModified(false); - textChanged(); - } - else { - QMessageBox::critical( this, tr("Module not writable"), - QString::fromLatin1("<qt><B>%1</B><BR>%2</qt>") - .arg( tr("Module is not writable.") ) - .arg( tr("Either the module may not be edited, or " - "you do not have write permission.") ) ); - } + QString t = ((CWriteDisplay*)displayWidget())->plainText(); + //since t is a complete HTML page at the moment, strip away headers and footers of a HTML page + QRegExp re("(?:<html.*>.+<body.*>)", Qt::CaseInsensitive); //remove headers, case insensitive + re.setMinimal(true); + t.replace(re, ""); + t.replace(QRegExp("</body></html>", Qt::CaseInsensitive), "");//remove footer + + const QString& oldKey = this->key()->key(); + if ( modules().first()->isWritable() ) { + modules().first()->write(this->key(), t ); + this->key()->key( oldKey ); + + ((CWriteDisplay*)displayWidget())->setModified(false); + textChanged(); + } + else { + QMessageBox::critical( this, tr("Module not writable"), + QString::fromLatin1("<qt><B>%1</B><BR>%2</qt>") + .arg( tr("Module is not writable.") ) + .arg( tr("Either the module may not be edited, or " + "you do not have write permission.") ) ); + } } /** Loads the original text from the module. */ void CPlainWriteWindow::restoreText() { - lookupSwordKey(key()); - ((CWriteDisplay*)displayWidget())->setModified(false); - textChanged(); + lookupSwordKey(key()); + ((CWriteDisplay*)displayWidget())->setModified(false); + textChanged(); } /** Is called when the current text was changed. */ void CPlainWriteWindow::textChanged() { - m_actions.saveText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() ); - m_actions.restoreText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() ); + m_actions.saveText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() ); + m_actions.restoreText->setEnabled( ((CWriteDisplay*)displayWidget())->isModified() ); } /** Deletes the module entry and clears the edit widget, */ void CPlainWriteWindow::deleteEntry() { - modules().first()->deleteEntry( key() ); - lookupSwordKey( key() ); - ((CWriteDisplay*)displayWidget())->setModified(false); + modules().first()->deleteEntry( key() ); + lookupSwordKey( key() ); + ((CWriteDisplay*)displayWidget())->setModified(false); } /** Setups the popup menu of this display widget. */ void CPlainWriteWindow::setupPopupMenu() {} bool CPlainWriteWindow::syncAllowed() const { - return m_actions.syncWindow->isChecked(); + return m_actions.syncWindow->isChecked(); } void CPlainWriteWindow::initActions() { diff --git a/src/frontend/displaywindow/cplainwritewindow.h b/src/frontend/displaywindow/cplainwritewindow.h index 1ed4215..a190f47 100644 --- a/src/frontend/displaywindow/cplainwritewindow.h +++ b/src/frontend/displaywindow/cplainwritewindow.h @@ -25,72 +25,72 @@ class QString; * @author The BibleTime team */ class CPlainWriteWindow : public CWriteWindow { - Q_OBJECT -public: - CPlainWriteWindow( QList<CSwordModuleInfo*> modules, CMDIArea* parent); - virtual ~CPlainWriteWindow(); + Q_OBJECT + public: + CPlainWriteWindow( QList<CSwordModuleInfo*> modules, CMDIArea* parent); + virtual ~CPlainWriteWindow(); - /** - * Store the settings of this window in the given CProfileWindow object. - */ - virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow ); - /** - * Store the settings of this window in the given profile window. - */ - virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow ); + /** + * Store the settings of this window in the given CProfileWindow object. + */ + virtual void storeProfileSettings( Profile::CProfileWindow* profileWindow ); + /** + * Store the settings of this window in the given profile window. + */ + virtual void applyProfileSettings( Profile::CProfileWindow* profileWindow ); - /** - * Setups the popup menu of this display widget. - */ - virtual void setupPopupMenu(); - virtual bool syncAllowed() const; + /** + * Setups the popup menu of this display widget. + */ + virtual void setupPopupMenu(); + virtual bool syncAllowed() const; -protected: // Protected methods - /** - * Initialize the state of this widget. - */ - virtual void initView(); - virtual void initConnections(); - virtual void initToolbars(); - virtual CDisplayWindow::WriteWindowType writeWindowType() { - return CDisplayWindow::PlainTextWindow; - }; + protected: // Protected methods + /** + * Initialize the state of this widget. + */ + virtual void initView(); + virtual void initConnections(); + virtual void initToolbars(); + virtual CDisplayWindow::WriteWindowType writeWindowType() { + return CDisplayWindow::PlainTextWindow; + }; - /** - * Initializes the intern keyboard actions. - */ - virtual void initActions(); - /** - * Insert the keyboard accelerators of this window into the given KAccel object. - */ - static void insertKeyboardActions( BtActionCollection* const a ); + /** + * Initializes the intern keyboard actions. + */ + virtual void initActions(); + /** + * Insert the keyboard accelerators of this window into the given KAccel object. + */ + static void insertKeyboardActions( BtActionCollection* const a ); -private: - struct { - QAction* saveText; - QAction* deleteEntry; - QAction* restoreText; - QAction* syncWindow; - } - m_actions; + private: + struct { + QAction* saveText; + QAction* deleteEntry; + QAction* restoreText; + QAction* syncWindow; + } + m_actions; -protected slots: // Protected slots - /** - * Saves the text for the current key. Directly writes the changed text into the module. - */ - virtual void saveCurrentText( const QString& ); - /** - * Is called when the current text was changed. - */ - virtual void textChanged(); - /** - * Loads the original text from the module. - */ - virtual void restoreText(); - /** - * Deletes the module entry and clears the edit widget. - */ - virtual void deleteEntry(); + protected slots: // Protected slots + /** + * Saves the text for the current key. Directly writes the changed text into the module. + */ + virtual void saveCurrentText( const QString& ); + /** + * Is called when the current text was changed. + */ + virtual void textChanged(); + /** + * Loads the original text from the module. + */ + virtual void restoreText(); + /** + * Deletes the module entry and clears the edit widget. + */ + virtual void deleteEntry(); }; #endif diff --git a/src/frontend/displaywindow/creadwindow.cpp b/src/frontend/displaywindow/creadwindow.cpp index a7d53ac..860fa72 100644 --- a/src/frontend/displaywindow/creadwindow.cpp +++ b/src/frontend/displaywindow/creadwindow.cpp @@ -31,156 +31,153 @@ typedef BtHtmlReadDisplay HTMLREADDISPLAY; using namespace Profile; CReadWindow::CReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent) - : CDisplayWindow(modules,parent), - m_displayWidget(0) -{ - qDebug("CReadWindow::CReadWindow"); - // installEventFilter(this); + : CDisplayWindow(modules, parent), + m_displayWidget(0) { + qDebug("CReadWindow::CReadWindow"); + // installEventFilter(this); } CReadWindow::~CReadWindow() { - // qWarning("destructor of CReadWindow"); + // qWarning("destructor of CReadWindow"); } /** Sets the display widget of this display window. */ void CReadWindow::setDisplayWidget( CDisplay* newDisplay ) { - Q_ASSERT(dynamic_cast<CReadDisplay*>(newDisplay)); - 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&))); - - HTMLREADDISPLAY* v = dynamic_cast<HTMLREADDISPLAY*>(m_displayWidget); - if (v) { - QObject::disconnect(v, SIGNAL(completed()), this, SLOT(slotMoveToAnchor()) ); - } - - } - - m_displayWidget = (CReadDisplay*)newDisplay; - connect( - m_displayWidget->connectionsProxy(), - SIGNAL(referenceClicked(const QString&, const QString&)), - this, - SLOT(lookupModKey(const QString&, const QString&)) - ); - - connect( - m_displayWidget->connectionsProxy(), - SIGNAL(referenceDropped(const QString&)), - this, - SLOT(lookupKey(const QString&)) - ); - HTMLREADDISPLAY* v = dynamic_cast<HTMLREADDISPLAY*>(m_displayWidget); - if (v) - { - QObject::connect(v, SIGNAL(completed()), this, SLOT(slotMoveToAnchor()) ); - } + Q_ASSERT(dynamic_cast<CReadDisplay*>(newDisplay)); + 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&))); + + HTMLREADDISPLAY* v = dynamic_cast<HTMLREADDISPLAY*>(m_displayWidget); + if (v) { + QObject::disconnect(v, SIGNAL(completed()), this, SLOT(slotMoveToAnchor()) ); + } + + } + + m_displayWidget = (CReadDisplay*)newDisplay; + connect( + m_displayWidget->connectionsProxy(), + SIGNAL(referenceClicked(const QString&, const QString&)), + this, + SLOT(lookupModKey(const QString&, const QString&)) + ); + + connect( + m_displayWidget->connectionsProxy(), + SIGNAL(referenceDropped(const QString&)), + this, + SLOT(lookupKey(const QString&)) + ); + HTMLREADDISPLAY* v = dynamic_cast<HTMLREADDISPLAY*>(m_displayWidget); + if (v) { + QObject::connect(v, SIGNAL(completed()), this, SLOT(slotMoveToAnchor()) ); + } } /** Lookup the given entry. */ void CReadWindow::lookupSwordKey( CSwordKey* newKey ) { - qDebug() << "CReadWindow::lookup newKey" << newKey->key(); - Q_ASSERT(newKey); + qDebug() << "CReadWindow::lookup newKey" << newKey->key(); + Q_ASSERT(newKey); - using namespace Rendering; + using namespace Rendering; // Q_ASSERT(isReady() && newKey && modules().first()); - if (!isReady() || !newKey || modules().empty() || !modules().first()) { - return; - } - - if (key() != newKey) { - key()->key(newKey->key()); - } - - //next-TODO: how about options? - Q_ASSERT(modules().first()->getDisplay()); - CEntryDisplay* display = modules().first()->getDisplay(); - if (display) { //do we have a display object? - displayWidget()->setText( - display->text( - modules(), - newKey->key(), - displayOptions(), - filterOptions() - ) - ); - } - - setCaption( windowCaption() ); - - // moving to anchor happens in slotMoveToAnchor which catches the completed() signal from KHTMLPart - - qDebug() << "CReadWindow::lookup end, key is :" << newKey->key(); + if (!isReady() || !newKey || modules().empty() || !modules().first()) { + return; + } + + if (key() != newKey) { + key()->key(newKey->key()); + } + + //next-TODO: how about options? + Q_ASSERT(modules().first()->getDisplay()); + CEntryDisplay* display = modules().first()->getDisplay(); + if (display) { //do we have a display object? + displayWidget()->setText( + display->text( + modules(), + newKey->key(), + displayOptions(), + filterOptions() + ) + ); + } + + setCaption( windowCaption() ); + + // moving to anchor happens in slotMoveToAnchor which catches the completed() signal from KHTMLPart + + qDebug() << "CReadWindow::lookup end, key is :" << newKey->key(); } -void CReadWindow::slotMoveToAnchor() -{ - qDebug("CReadWindow::slotMoveToAnchor"); - ((CReadDisplay*)displayWidget())->moveToAnchor( Rendering::CDisplayRendering::keyToHTMLAnchor(key()->key()) ); +void CReadWindow::slotMoveToAnchor() { + qDebug("CReadWindow::slotMoveToAnchor"); + ((CReadDisplay*)displayWidget())->moveToAnchor( Rendering::CDisplayRendering::keyToHTMLAnchor(key()->key()) ); } /** Store the settings of this window in the given CProfileWindow object. */ void CReadWindow::storeProfileSettings(CProfileWindow * const settings) { - QRect rect; - rect.setX(parentWidget()->x()); - rect.setY(parentWidget()->y()); - rect.setWidth(parentWidget()->width()); - rect.setHeight(parentWidget()->height()); - settings->setGeometry(rect); - - // settings->setScrollbarPositions( m_htmlWidget->view()->horizontalScrollBar()->value(), m_htmlWidget->view()->verticalScrollBar()->value() ); - settings->setType(modules().first()->type()); - settings->setMaximized(isMaximized() || parentWidget()->isMaximized()); - settings->setFocus( (this == dynamic_cast<CReadWindow*>(mdi()->activeSubWindow()) ) ); //set property to true if this window is the active one. - - if (key()) { - sword::VerseKey* vk = dynamic_cast<sword::VerseKey*>(key()); - QString oldLang; - if (vk) { - oldLang = QString(vk->getLocale()); - vk->setLocale("en"); //save english locale names as default! - } - settings->setKey( key()->key() ); - if (vk) { - vk->setLocale(oldLang.toLatin1()); - } - } - - QStringList mods; - - QList<CSwordModuleInfo*> allMods = modules(); - QList<CSwordModuleInfo*>::iterator end_it = allMods.end(); - for (QList<CSwordModuleInfo*>::iterator it(allMods.begin()); it != end_it; ++it) { - mods.append((*it)->name()); - } - settings->setModules(mods); + QRect rect; + rect.setX(parentWidget()->x()); + rect.setY(parentWidget()->y()); + rect.setWidth(parentWidget()->width()); + rect.setHeight(parentWidget()->height()); + settings->setGeometry(rect); + + // settings->setScrollbarPositions( m_htmlWidget->view()->horizontalScrollBar()->value(), m_htmlWidget->view()->verticalScrollBar()->value() ); + settings->setType(modules().first()->type()); + settings->setMaximized(isMaximized() || parentWidget()->isMaximized()); + settings->setFocus( (this == dynamic_cast<CReadWindow*>(mdi()->activeSubWindow()) ) ); //set property to true if this window is the active one. + + if (key()) { + sword::VerseKey* vk = dynamic_cast<sword::VerseKey*>(key()); + QString oldLang; + if (vk) { + oldLang = QString(vk->getLocale()); + vk->setLocale("en"); //save english locale names as default! + } + settings->setKey( key()->key() ); + if (vk) { + vk->setLocale(oldLang.toLatin1()); + } + } + + QStringList mods; + + QList<CSwordModuleInfo*> allMods = modules(); + QList<CSwordModuleInfo*>::iterator end_it = allMods.end(); + for (QList<CSwordModuleInfo*>::iterator it(allMods.begin()); it != end_it; ++it) { + mods.append((*it)->name()); + } + settings->setModules(mods); } void CReadWindow::applyProfileSettings(CProfileWindow * const settings) { - // parentWidget()->setUpdatesEnabled(false); - setUpdatesEnabled(false); - - if (settings->maximized()) { //maximize this window - // Use parentWidget() to call showMaximized. Otherwise we'd get lot's of X11 errors - parentWidget()->showMaximized(); - } - else { - const QRect rect = settings->geometry(); - parentWidget()->resize(rect.width(), rect.height()); - parentWidget()->move(rect.x(), rect.y()); - } - - setUpdatesEnabled(true); + // parentWidget()->setUpdatesEnabled(false); + setUpdatesEnabled(false); + + if (settings->maximized()) { //maximize this window + // Use parentWidget() to call showMaximized. Otherwise we'd get lot's of X11 errors + parentWidget()->showMaximized(); + } + else { + const QRect rect = settings->geometry(); + parentWidget()->resize(rect.width(), rect.height()); + parentWidget()->move(rect.x(), rect.y()); + } + + setUpdatesEnabled(true); } void CReadWindow::insertKeyboardActions( BtActionCollection* const ) {} /** No descriptions */ void CReadWindow::copyDisplayedText() { - CExportManager mgr(QString::null); - mgr.copyKey(key(), CExportManager::Text, true); + CExportManager mgr(QString::null); + mgr.copyKey(key(), CExportManager::Text, true); } @@ -188,18 +185,18 @@ void CReadWindow::copyDisplayedText() { \fn CReadWindow::resizeEvent(QResizeEvent* e) */ void CReadWindow::resizeEvent(QResizeEvent* /*e*/) { - if (displayWidget()) { - ((CReadDisplay*)displayWidget())->moveToAnchor(Rendering::CDisplayRendering::keyToHTMLAnchor(key()->key())); - } + if (displayWidget()) { + ((CReadDisplay*)displayWidget())->moveToAnchor(Rendering::CDisplayRendering::keyToHTMLAnchor(key()->key())); + } } void CReadWindow::openSearchStrongsDialog() { // qWarning("looking for lemma %s", displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma].latin1() ); - QString searchText = QString::null; - - if (displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != QString::null) { - searchText.append("strong:").append(displayWidget()->getCurrentNodeInfo() [CDisplay::Lemma]); - } - - Search::CSearchDialog::openDialog( modules(), searchText, 0 ); + QString searchText = QString::null; + + if (displayWidget()->getCurrentNodeInfo()[CDisplay::Lemma] != QString::null) { + searchText.append("strong:").append(displayWidget()->getCurrentNodeInfo() [CDisplay::Lemma]); + } + + Search::CSearchDialog::openDialog( modules(), searchText, 0 ); } diff --git a/src/frontend/displaywindow/creadwindow.h b/src/frontend/displaywindow/creadwindow.h index 3630b58..6144b2d 100644 --- a/src/frontend/displaywindow/creadwindow.h +++ b/src/frontend/displaywindow/creadwindow.h @@ -28,52 +28,52 @@ 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); - virtual ~CReadWindow(); - /** - * Store the settings of this window in the given CProfileWindow object. - */ - virtual void storeProfileSettings(Profile::CProfileWindow * const settings); - /** - * Store the settings of this window in the given CProfileWindow object. - */ - virtual void applyProfileSettings(Profile::CProfileWindow * const settings); - -protected: // Protected methods - /** - * Sets the display widget of this display window. - */ - virtual void setDisplayWidget( CDisplay* newDisplay ); - /** - */ - virtual void resizeEvent(QResizeEvent* e); - -protected slots: - /** - * Load the text using the key - */ - virtual void lookupSwordKey( CSwordKey* ); - /** - * Catch the signal when the KHTMLPart has finished the layout (anchors are not ready before that). - */ - virtual void slotMoveToAnchor(); - - /** - * Update the status of the popup menu entries. - */ - virtual void copyDisplayedText(); - /** Open the search dialog with the strong info of the last clicked word. - * - */ - void openSearchStrongsDialog(); - -private: - CReadDisplay* m_displayWidget; + Q_OBJECT + public: + // static void insertKeyboardActions( KAccel* const a ); + static void insertKeyboardActions( BtActionCollection* const a ); + + CReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); + virtual ~CReadWindow(); + /** + * Store the settings of this window in the given CProfileWindow object. + */ + virtual void storeProfileSettings(Profile::CProfileWindow * const settings); + /** + * Store the settings of this window in the given CProfileWindow object. + */ + virtual void applyProfileSettings(Profile::CProfileWindow * const settings); + + protected: // Protected methods + /** + * Sets the display widget of this display window. + */ + virtual void setDisplayWidget( CDisplay* newDisplay ); + /** + */ + virtual void resizeEvent(QResizeEvent* e); + + protected slots: + /** + * Load the text using the key + */ + virtual void lookupSwordKey( CSwordKey* ); + /** + * Catch the signal when the KHTMLPart has finished the layout (anchors are not ready before that). + */ + virtual void slotMoveToAnchor(); + + /** + * Update the status of the popup menu entries. + */ + virtual void copyDisplayedText(); + /** Open the search dialog with the strong info of the last clicked word. + * + */ + void openSearchStrongsDialog(); + + private: + CReadDisplay* m_displayWidget; }; #endif diff --git a/src/frontend/displaywindow/cwritewindow.cpp b/src/frontend/displaywindow/cwritewindow.cpp index 62009c0..c60d9cd 100644 --- a/src/frontend/displaywindow/cwritewindow.cpp +++ b/src/frontend/displaywindow/cwritewindow.cpp @@ -24,7 +24,7 @@ using namespace Profile; CWriteWindow::CWriteWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent) -: CDisplayWindow(modules, parent), m_writeDisplay(0) {} + : CDisplayWindow(modules, parent), m_writeDisplay(0) {} CWriteWindow::~CWriteWindow() {} @@ -32,8 +32,8 @@ CWriteWindow::~CWriteWindow() {} void CWriteWindow::insertKeyboardActions( BtActionCollection* const ) {} void CWriteWindow::initConnections() { - Q_ASSERT(keyChooser()); - QObject::connect(keyChooser(), SIGNAL(beforeKeyChange(const QString&)), this, SLOT(beforeKeyChange(const QString&))); + Q_ASSERT(keyChooser()); + QObject::connect(keyChooser(), SIGNAL(beforeKeyChange(const QString&)), this, SLOT(beforeKeyChange(const QString&))); } void CWriteWindow::initActions() {} @@ -41,121 +41,121 @@ void CWriteWindow::initActions() {} void CWriteWindow::storeProfileSettings(CProfileWindow * const settings) { - settings->setWriteWindowType( writeWindowType() ); - - QRect rect; - rect.setX(parentWidget()->x()); - rect.setY(parentWidget()->y()); - rect.setWidth(parentWidget()->width()); - rect.setHeight(parentWidget()->height()); - settings->setGeometry(rect); - - // settings->setScrollbarPositions( m_htmlWidget->view()->horizontalScrollBar()->value(), m_htmlWidget->view()->verticalScrollBar()->value() ); - settings->setType(modules().first()->type()); - settings->setMaximized(isMaximized() || parentWidget()->isMaximized()); - - if (key()) { - sword::VerseKey* vk = dynamic_cast<sword::VerseKey*>(key()); - QString oldLang; - if (vk) { - oldLang = QString::fromLatin1(vk->getLocale()); - vk->setLocale("en"); //save english locale names as default! - } - settings->setKey( key()->key() ); - if (vk) { - vk->setLocale(oldLang.toLatin1()); - } - } - - QStringList mods; - QList<CSwordModuleInfo*> allMods = modules(); - QList<CSwordModuleInfo*>::iterator end_it = allMods.end(); - for (QList<CSwordModuleInfo*>::iterator it(allMods.begin()); it != end_it; ++it) { - mods.append((*it)->name()); - } - settings->setModules(mods); + settings->setWriteWindowType( writeWindowType() ); + + QRect rect; + rect.setX(parentWidget()->x()); + rect.setY(parentWidget()->y()); + rect.setWidth(parentWidget()->width()); + rect.setHeight(parentWidget()->height()); + settings->setGeometry(rect); + + // settings->setScrollbarPositions( m_htmlWidget->view()->horizontalScrollBar()->value(), m_htmlWidget->view()->verticalScrollBar()->value() ); + settings->setType(modules().first()->type()); + settings->setMaximized(isMaximized() || parentWidget()->isMaximized()); + + if (key()) { + sword::VerseKey* vk = dynamic_cast<sword::VerseKey*>(key()); + QString oldLang; + if (vk) { + oldLang = QString::fromLatin1(vk->getLocale()); + vk->setLocale("en"); //save english locale names as default! + } + settings->setKey( key()->key() ); + if (vk) { + vk->setLocale(oldLang.toLatin1()); + } + } + + QStringList mods; + QList<CSwordModuleInfo*> allMods = modules(); + QList<CSwordModuleInfo*>::iterator end_it = allMods.end(); + for (QList<CSwordModuleInfo*>::iterator it(allMods.begin()); it != end_it; ++it) { + mods.append((*it)->name()); + } + settings->setModules(mods); } void CWriteWindow::applyProfileSettings(CProfileWindow * const settings) { - setUpdatesEnabled(false); - - if (settings->maximized()) { - parentWidget()->showMaximized(); - } - else { - const QRect rect = settings->geometry(); - parentWidget()->resize(rect.width(), rect.height()); - parentWidget()->move(rect.x(), rect.y()); - //setGeometry( settings->geometry() ); - } - // displayWidget()->view()->horizontalScrollBar()->setValue( settings->scrollbarPositions().horizontal ); - // m_htmlWidget->view()->verticalScrollBar()->setValue( settings->scrollbarPositions().vertical ); - - setUpdatesEnabled(true); + setUpdatesEnabled(false); + + if (settings->maximized()) { + parentWidget()->showMaximized(); + } + else { + const QRect rect = settings->geometry(); + parentWidget()->resize(rect.width(), rect.height()); + parentWidget()->move(rect.x(), rect.y()); + //setGeometry( settings->geometry() ); + } + // displayWidget()->view()->horizontalScrollBar()->setValue( settings->scrollbarPositions().horizontal ); + // m_htmlWidget->view()->verticalScrollBar()->setValue( settings->scrollbarPositions().vertical ); + + setUpdatesEnabled(true); } void CWriteWindow::setDisplayWidget( CDisplay* display ) { - Q_ASSERT(dynamic_cast<CWriteDisplay*>(display)); - CDisplayWindow::setDisplayWidget((CWriteDisplay*)display); - m_writeDisplay = (CWriteDisplay*)display; + Q_ASSERT(dynamic_cast<CWriteDisplay*>(display)); + CDisplayWindow::setDisplayWidget((CWriteDisplay*)display); + m_writeDisplay = (CWriteDisplay*)display; } void CWriteWindow::lookupSwordKey( CSwordKey* newKey ) { - //set the raw text to the display widget - if (!newKey) - return; - - if (key() != newKey) { //set passage of newKey to key() if they're different, otherwise we'd get mixed up if we look up newkey which may have a different module set - key()->key(newKey->key()); - } - - if ( modules().count() ) { - displayWidget()->setText( key()->rawText() ); - } - setCaption( windowCaption() ); + //set the raw text to the display widget + if (!newKey) + return; + + if (key() != newKey) { //set passage of newKey to key() if they're different, otherwise we'd get mixed up if we look up newkey which may have a different module set + key()->key(newKey->key()); + } + + if ( modules().count() ) { + displayWidget()->setText( key()->rawText() ); + } + setCaption( windowCaption() ); } bool CWriteWindow::queryClose() { - //save the text if it has changed - if (m_writeDisplay->isModified()) { - switch (QMessageBox::question( this, tr("Save Text?"), tr("Save text before closing?"), QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, QMessageBox::Yes) ) { - case QMessageBox::Yes: //save and close - saveCurrentText(); - m_writeDisplay->setModified( false ); - return true; - case QMessageBox::No: //don't save and close - return true; - default: // cancel, don't close - return false; - } - } - return true; + //save the text if it has changed + if (m_writeDisplay->isModified()) { + switch (QMessageBox::question( this, tr("Save Text?"), tr("Save text before closing?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes) ) { + case QMessageBox::Yes: //save and close + saveCurrentText(); + m_writeDisplay->setModified( false ); + return true; + case QMessageBox::No: //don't save and close + return true; + default: // cancel, don't close + return false; + } + } + return true; } void CWriteWindow::beforeKeyChange(const QString& key) { - Q_ASSERT(displayWidget()); - Q_ASSERT(keyChooser()); - if (!isReady()) return; - - //If the text changed and we'd do a lookup ask the user if the text should be saved - if (modules().first() && ((CWriteDisplay*)displayWidget())->isModified()) { - - switch (QMessageBox::question( this, tr("Save Text?"), tr("Save changed text?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) ) { - case QMessageBox::Yes: { //save the changes - saveCurrentText( key ); - break; - } - default: {// set modified to false so it won't ask again - ((CWriteDisplay*)displayWidget())->setModified(false); - break; - } - } - } + Q_ASSERT(displayWidget()); + Q_ASSERT(keyChooser()); + if (!isReady()) return; + + //If the text changed and we'd do a lookup ask the user if the text should be saved + if (modules().first() && ((CWriteDisplay*)displayWidget())->isModified()) { + + switch (QMessageBox::question( this, tr("Save Text?"), tr("Save changed text?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) ) { + case QMessageBox::Yes: { //save the changes + saveCurrentText( key ); + break; + } + default: {// set modified to false so it won't ask again + ((CWriteDisplay*)displayWidget())->setModified(false); + break; + } + } + } } void CWriteWindow::saveCurrentText() { - if(key()) { - saveCurrentText(key()->key()); - } + if (key()) { + saveCurrentText(key()->key()); + } } diff --git a/src/frontend/displaywindow/cwritewindow.h b/src/frontend/displaywindow/cwritewindow.h index c3b47c2..e2ffc54 100644 --- a/src/frontend/displaywindow/cwritewindow.h +++ b/src/frontend/displaywindow/cwritewindow.h @@ -23,50 +23,50 @@ class BtActionCollection; */ class CWriteWindow : public CDisplayWindow { - Q_OBJECT -public: - static void insertKeyboardActions( BtActionCollection* const a ); + Q_OBJECT + public: + static void insertKeyboardActions( BtActionCollection* const a ); - CWriteWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); - virtual ~CWriteWindow(); - /** - * Store the settings of this window in the given CProfileWindow object. - */ - virtual void storeProfileSettings(Profile::CProfileWindow * const settings); - /** - * Store the settings of this window in the given CProfileWindow object. - */ - virtual void applyProfileSettings(Profile::CProfileWindow * const settings); - virtual void initConnections(); - virtual void initActions(); + CWriteWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent); + virtual ~CWriteWindow(); + /** + * Store the settings of this window in the given CProfileWindow object. + */ + virtual void storeProfileSettings(Profile::CProfileWindow * const settings); + /** + * Store the settings of this window in the given CProfileWindow object. + */ + virtual void applyProfileSettings(Profile::CProfileWindow * const settings); + virtual void initConnections(); + virtual void initActions(); -public slots: - /** - * Look up the given key and display the text. In our case we offer to edit the text. - */ - virtual void lookupSwordKey( CSwordKey* key ); + public slots: + /** + * Look up the given key and display the text. In our case we offer to edit the text. + */ + virtual void lookupSwordKey( CSwordKey* key ); -protected: // Protected methods - /** - * Saves the given text as text of the given key. Use this function - * as backend in each write window implementation. - */ - void setDisplayWidget( CDisplay* display ); - virtual CDisplayWindow::WriteWindowType writeWindowType() = 0; - virtual bool queryClose(); - virtual void saveCurrentText( const QString& key ) = 0; + protected: // Protected methods + /** + * Saves the given text as text of the given key. Use this function + * as backend in each write window implementation. + */ + void setDisplayWidget( CDisplay* display ); + virtual CDisplayWindow::WriteWindowType writeWindowType() = 0; + virtual bool queryClose(); + virtual void saveCurrentText( const QString& key ) = 0; -protected slots: - /** Save text to the module - */ - void saveCurrentText(); - /** - */ - virtual void beforeKeyChange(const QString&); + protected slots: + /** Save text to the module + */ + void saveCurrentText(); + /** + */ + virtual void beforeKeyChange(const QString&); -private: - CWriteDisplay* m_writeDisplay; + private: + CWriteDisplay* m_writeDisplay; }; #endif |