diff options
author | Roberto C. Sanchez <roberto@connexer.com> | 2014-10-21 22:48:25 -0400 |
---|---|---|
committer | Roberto C. Sanchez <roberto@connexer.com> | 2014-10-21 22:48:25 -0400 |
commit | b954e6dbcceaba3b50aca624e1bddc6db4830829 (patch) | |
tree | 31fa8e2579585c9626d56bc9beb55326cbd40ff2 /src/frontend/displaywindow/cdisplaywindow.cpp | |
parent | 04e7ba8bf082e2b170595eef488834accd9d946e (diff) |
Imported Upstream version 2.2
Diffstat (limited to 'src/frontend/displaywindow/cdisplaywindow.cpp')
-rw-r--r-- | src/frontend/displaywindow/cdisplaywindow.cpp | 255 |
1 files changed, 148 insertions, 107 deletions
diff --git a/src/frontend/displaywindow/cdisplaywindow.cpp b/src/frontend/displaywindow/cdisplaywindow.cpp index 59fccab..6cf160d 100644 --- a/src/frontend/displaywindow/cdisplaywindow.cpp +++ b/src/frontend/displaywindow/cdisplaywindow.cpp @@ -10,7 +10,6 @@ #include "cdisplaywindow.h" #include "bttoolbarpopupaction.h" #include "btactioncollection.h" - #include "cmodulechooserbar.h" #include "cbuttons.h" #include "backend/keys/cswordkey.h" @@ -54,21 +53,24 @@ CDisplayWindow::CDisplayWindow(QList<CSwordModuleInfo*> modules, CMDIArea *paren // Connect this to the backend module list changes connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(reload(CSwordBackend::SetupChangedReason))); - //KMainWindow::setAttribute(Qt::WA_DeleteOnClose); //what about QMdiSubWindow? } -CDisplayWindow::~CDisplayWindow() { +CDisplayWindow::~CDisplayWindow() +{ delete m_swordKey; m_swordKey = 0; } -CMDIArea* CDisplayWindow::mdi() const { +CMDIArea* CDisplayWindow::mdi() const +{ return m_mdi; } /** Returns the right window caption. */ -const QString CDisplayWindow::windowCaption() { - if (!m_modules.count()) { +const QString CDisplayWindow::windowCaption() +{ + if (!m_modules.count()) + { return QString::null; } @@ -76,12 +78,15 @@ const QString CDisplayWindow::windowCaption() { } /** Returns the used modules as a QPtrList */ -QList<CSwordModuleInfo*> CDisplayWindow::modules() { +QList<CSwordModuleInfo*> CDisplayWindow::modules() +{ QList<CSwordModuleInfo*> mods; - for (QStringList::iterator it = m_modules.begin(); it != m_modules.end(); ++it) { + for (QStringList::iterator it = m_modules.begin(); it != m_modules.end(); ++it) + { Q_ASSERT(backend()->findModuleByName(*it)); - if (CSwordModuleInfo* m = backend()->findModuleByName(*it)) { + if (CSwordModuleInfo* m = backend()->findModuleByName(*it)) + { mods.append(m); } } @@ -90,38 +95,39 @@ QList<CSwordModuleInfo*> CDisplayWindow::modules() { } /** Set the window caption. */ -void CDisplayWindow::setCaption( const QString& ) { +void CDisplayWindow::setCaption( const QString& ) +{ QWidget::setWindowTitle( windowCaption() ); m_mdi->emitWindowCaptionChanged(); } -void CDisplayWindow::insertKeyboardActions( BtActionCollection* 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); - //a->addAction(KStandardAction::ZoomIn, "zoomIn", 0, 0); + actn = new QAction(QIcon(), tr("Zoom out"), 0); actn->setShortcut(QKeySequence::ZoomOut); - a->addAction("zoomIn", actn); - //a->addAction(KStandardAction::ZoomOut, "zoomOut", 0, 0); + a->addAction("zoomOut", actn); + actn = new QAction(QIcon(), tr("Close"), 0); actn->setShortcut(QKeySequence::Close); a->addAction("closeWindow", actn); - //a->addAction(KStandardAction::Close, "closeWindow", 0, 0); + actn = new QAction(QIcon(), tr("Select all"), 0); actn->setShortcut(QKeySequence::SelectAll); a->addAction("selectAll", actn); - //a->addAction(KStandardAction::SelectAll, "selectAll", 0, 0); + actn = new QAction(QIcon(), tr("Copy"), 0); actn->setShortcut(QKeySequence::Copy); a->addAction("copySelectedText", actn); - //a->addAction(KStandardAction::Copy, "copySelectedText", 0, 0); + actn = new QAction(QIcon(), tr("Find..."), 0); actn->setShortcut(QKeySequence::Find); a->addAction("findText", actn); - //a->addAction(KStandardAction::Find, "findText", 0, 0); BtToolBarPopupAction* action = new BtToolBarPopupAction( QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::backInHistory::icon)), @@ -146,85 +152,70 @@ void CDisplayWindow::initActions() BtActionCollection* ac = actionCollection(); - QAction* kaction = new QAction( + CDisplayWindow::insertKeyboardActions(ac); + + QAction* qaction = new QAction( QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::search::icon)), tr("Open the search dialog with the works of this window"), ac ); - kaction->setShortcut(CResMgr::displaywindows::general::search::accel); - QObject::connect(kaction, SIGNAL(triggered()), this, SLOT(slotSearchInModules())); - ac->addAction(CResMgr::displaywindows::general::search::actionName, kaction); + qaction->setShortcut(CResMgr::displaywindows::general::search::accel); + QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(slotSearchInModules())); + ac->addAction(CResMgr::displaywindows::general::search::actionName, qaction); CDisplayConnections* conn = displayWidget()->connectionsProxy(); - QAction* actn = new QAction(QIcon(), tr("Zoom in"), ac); - actn->setShortcut(QKeySequence::ZoomIn); + QAction* actn = ac->action("zoomIn"); QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(zoomIn())); - ac->addAction("zoomIn", actn); addAction(actn); - //a->addAction(KStandardAction::ZoomIn, "zoomIn", 0, 0); - actn = new QAction(QIcon(), tr("Zoom out"), ac); - actn->setShortcut(QKeySequence::ZoomOut); + + actn = ac->action("zoomOut"); QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(zoomOut())); - ac->addAction("zoomOut", actn); addAction(actn); - //a->addAction(KStandardAction::ZoomOut, "zoomOut", 0, 0); - actn = new QAction(QIcon(), tr("Close"), ac); - actn->setShortcut(QKeySequence::Close); + + actn = ac->action("closeWindow"); QObject::connect(actn, SIGNAL(triggered()), this, SLOT(close())); - ac->addAction("closeWindow", actn); addAction(actn); - //a->addAction(KStandardAction::Close, "closeWindow", 0, 0); - actn = new QAction(QIcon(), tr("Select all"), ac); - actn->setShortcut(QKeySequence::SelectAll); + + actn = ac->action("selectAll"); QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(selectAll())); - ac->addAction("selectAll", actn); addAction(actn); - //a->addAction(KStandardAction::SelectAll, "selectAll", 0, 0); - actn = new QAction(QIcon(), tr("Copy"), ac); - actn->setShortcut(QKeySequence::Copy); + + actn = ac->action("copySelectedText"); QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(copySelection())); - ac->addAction("copySelectedText", actn); addAction(actn); - //a->addAction(KStandardAction::Copy, "copySelectedText", 0, 0); - actn = new QAction(QIcon(), tr("Find..."), ac); - actn->setShortcut(QKeySequence::Find); + + actn = ac->action("findText"); QObject::connect(actn, SIGNAL(triggered()), conn, SLOT(openFindTextDialog())); - ac->addAction("findText", actn); addAction(actn); - //a->addAction(KStandardAction::Find, "findText", 0, 0); - BtToolBarPopupAction* popupaction = new BtToolBarPopupAction( - QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::backInHistory::icon)), - tr("Back in history"), - ac - ); + QAction* popupaction = ac->action(CResMgr::displaywindows::general::backInHistory::actionName); bool ok = QObject::connect(popupaction, SIGNAL(triggered()), keyChooser()->history(), SLOT(back())); Q_ASSERT(ok); - ac->addAction(CResMgr::displaywindows::general::backInHistory::actionName, popupaction); + addAction(popupaction); - popupaction = new BtToolBarPopupAction( - QIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::displaywindows::general::forwardInHistory::icon)), - tr("Forward in history"), - ac - ); + popupaction = ac->action(CResMgr::displaywindows::general::forwardInHistory::actionName); ok = QObject::connect(popupaction, SIGNAL(triggered()), keyChooser()->history(), SLOT(fw()) ); Q_ASSERT(ok); - ac->addAction(CResMgr::displaywindows::general::forwardInHistory::actionName, popupaction); + addAction(popupaction); + CBTConfig::setupAccelSettings(CBTConfig::allWindows,ac); } /** Refresh the settings of this window. */ -void CDisplayWindow::reload(CSwordBackend::SetupChangedReason) { +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())) { + if (!backend()->findModuleByName(it.next())) + { it.remove(); } } - if (m_modules.count() == 0){ + if (m_modules.count() == 0) + { close(); return; } @@ -236,75 +227,93 @@ void CDisplayWindow::reload(CSwordBackend::SetupChangedReason) { } modulesChanged(); lookup(); + + CBTConfig::setupAccelSettings(CBTConfig::allWindows,actionCollection()); + CBTConfig::setupAccelSettings(CBTConfig::readWindow, actionCollection()); } /** Returns the filter options used by this window. */ -CSwordBackend::FilterOptions& CDisplayWindow::filterOptions() { +CSwordBackend::FilterOptions& CDisplayWindow::filterOptions() +{ return m_filterOptions; } /** Returns the display options used by this display window. */ -CSwordBackend::DisplayOptions& CDisplayWindow::displayOptions() { +CSwordBackend::DisplayOptions& CDisplayWindow::displayOptions() +{ return m_displayOptions; } /** Sets the new display options for this window. */ -void CDisplayWindow::setDisplayOptions( const CSwordBackend::DisplayOptions& displayOptions ) { +void CDisplayWindow::setDisplayOptions( const CSwordBackend::DisplayOptions& displayOptions ) +{ m_displayOptions = displayOptions; } /** Sets the new filter options of this window. */ -void CDisplayWindow::setFilterOptions( CSwordBackend::FilterOptions& filterOptions ) { +void CDisplayWindow::setFilterOptions( CSwordBackend::FilterOptions& filterOptions ) +{ m_filterOptions = filterOptions; } /** Returns true if the widget is ready for use. */ -bool CDisplayWindow::isReady() const { +bool CDisplayWindow::isReady() const +{ return m_isReady; } /** Set the ready status */ -void CDisplayWindow::setReady( const bool& ready ) { +void CDisplayWindow::setReady( const bool& ready ) +{ m_isReady = ready; } /** Returns true if the window may be closed. */ -bool CDisplayWindow::queryClose() { +bool CDisplayWindow::queryClose() +{ return true; } /** Returns the keychooser widget of this display window. */ -CKeyChooser* CDisplayWindow::keyChooser() const { +CKeyChooser* CDisplayWindow::keyChooser() const +{ return m_keyChooser; } /** Sets the keychooser widget for this display window. */ -void CDisplayWindow::setKeyChooser( CKeyChooser* ck ) { +void CDisplayWindow::setKeyChooser( CKeyChooser* ck ) +{ m_keyChooser = ck; } /** Returns the key of this display window. */ -CSwordKey* CDisplayWindow::key() const { +CSwordKey* CDisplayWindow::key() const +{ Q_ASSERT( m_swordKey ); return m_swordKey; } /** Sets the new sword key. */ -void CDisplayWindow::setKey( CSwordKey* key ) { +void CDisplayWindow::setKey( CSwordKey* key ) +{ Q_ASSERT( key ); m_swordKey = key; } -void CDisplayWindow::modulesChanged() { +void CDisplayWindow::modulesChanged() +{ if (moduleChooserBar()) { //necessary for write windows setModules( m_moduleChooserBar->getModuleList() ); } - if (!modules().count()) { + if (!modules().count()) + { close(); } - else { - if (displaySettingsButton()) { + else + { + if (displaySettingsButton()) + { displaySettingsButton()->reset(modules()); } @@ -314,35 +323,42 @@ void CDisplayWindow::modulesChanged() { } /** Returns the module chooser bar. */ -CModuleChooserBar* CDisplayWindow::moduleChooserBar() const { +CModuleChooserBar* CDisplayWindow::moduleChooserBar() const +{ return m_moduleChooserBar; } /** Sets the module chooser bar. */ -void CDisplayWindow::setModuleChooserBar( CModuleChooserBar* bar ) { - if (m_moduleChooserBar) { +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) { + if (bar) + { m_moduleChooserBar = bar; connect(bar, SIGNAL(sigChanged()), SLOT(modulesChanged())); } } /** Sets the modules. */ -void CDisplayWindow::setModules( const QList<CSwordModuleInfo*>& newModules ) { +void CDisplayWindow::setModules( const QList<CSwordModuleInfo*>& newModules ) +{ qDebug("CDisplayWindow::setModules"); m_modules.clear(); - foreach (CSwordModuleInfo* mod, newModules) { + 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() { +bool CDisplayWindow::init() +{ qDebug("CDisplayWindow::init"); initView(); setMinimumSize( 100,100 ); @@ -367,32 +383,38 @@ bool CDisplayWindow::init() { } /** Returns the main toolbar. */ -QToolBar* CDisplayWindow::mainToolBar() const { +QToolBar* CDisplayWindow::mainToolBar() const +{ return m_mainToolBar; } /** Returns the main toolbar. */ -QToolBar* CDisplayWindow::buttonsToolBar() const { +QToolBar* CDisplayWindow::buttonsToolBar() const +{ return m_buttonsToolBar; } /** Sets the main toolbar. */ -void CDisplayWindow::setMainToolBar( QToolBar* bar ) { +void CDisplayWindow::setMainToolBar( QToolBar* bar ) +{ m_mainToolBar = bar; } /** Sets the main toolbar. */ -void CDisplayWindow::setButtonsToolBar( QToolBar* bar ) { +void CDisplayWindow::setButtonsToolBar( QToolBar* bar ) +{ m_buttonsToolBar = bar; } /** Returns the display settings button */ -CDisplaySettingsButton* CDisplayWindow::displaySettingsButton() const { +CDisplaySettingsButton* CDisplayWindow::displaySettingsButton() const +{ return m_displaySettingsButton; } /** Sets the display settings button. */ -void CDisplayWindow::setDisplaySettingsButton( CDisplaySettingsButton* button ) { +void CDisplayWindow::setDisplaySettingsButton( CDisplaySettingsButton* button ) +{ if (m_displaySettingsButton) disconnect(m_displaySettingsButton, SIGNAL( sigChanged() ),this, SLOT(lookup() )); @@ -401,27 +423,33 @@ void CDisplayWindow::setDisplaySettingsButton( CDisplaySettingsButton* button ) } /** Lookup the current key. Used to refresh the display. */ -void CDisplayWindow::lookup() { +void CDisplayWindow::lookup() +{ lookupSwordKey( key() ); } -void CDisplayWindow::lookupModKey( const QString& moduleName, const QString& keyName ) { - if (!isReady()) { +void CDisplayWindow::lookupModKey( const QString& moduleName, const QString& keyName ) +{ + if (!isReady()) + { return; } CSwordModuleInfo* m = backend()->findModuleByName(moduleName); Q_ASSERT(m); - if (!m) { + if (!m) + { return; } //ToDo: check for containsRef compat - if (m && modules().contains(m)) { + 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 + 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; @@ -430,7 +458,8 @@ void CDisplayWindow::lookupModKey( const QString& moduleName, const QString& key } } -void CDisplayWindow::lookupKey( const QString& 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()); @@ -440,16 +469,21 @@ void CDisplayWindow::lookupKey( const QString& keyName ) { } /** Update the status of the popup menu entries. */ -void CDisplayWindow::updatePopupMenu() {} +void CDisplayWindow::updatePopupMenu() +{ +} ///** Returns the installed popup menu. */ -QMenu* CDisplayWindow::popup() { +QMenu* CDisplayWindow::popup() +{ // qWarning("CReadWindow::popup()"); - if (!m_popupMenu) { + if (!m_popupMenu) + { m_popupMenu = new QMenu(this); connect(m_popupMenu, SIGNAL(aboutToShow()), this, SLOT(updatePopupMenu())); - if (displayWidget()) { + if (displayWidget()) + { displayWidget()->installPopup(m_popupMenu); } /* else { @@ -460,18 +494,22 @@ QMenu* CDisplayWindow::popup() { } /** Returns the display widget used by this implementation of CDisplayWindow. */ -CDisplay* CDisplayWindow::displayWidget() const { +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 ) { +void CDisplayWindow::setDisplayWidget( CDisplay* newDisplay ) +{ m_displayWidget = newDisplay; } -void CDisplayWindow::closeEvent(QCloseEvent* e) { - if (!queryClose()) { +void CDisplayWindow::closeEvent(QCloseEvent* e) +{ + if (!queryClose()) + { e->ignore(); } else { @@ -479,15 +517,18 @@ void CDisplayWindow::closeEvent(QCloseEvent* e) { } } -void CDisplayWindow::slotSearchInModules() { +void CDisplayWindow::slotSearchInModules() +{ Search::CSearchDialog::openDialog(modules()); } -void CDisplayWindow::printAll() { +void CDisplayWindow::printAll() +{ m_displayWidget->connectionsProxy()->printAll( m_displayOptions, m_filterOptions); } -void CDisplayWindow::printAnchorWithText() { +void CDisplayWindow::printAnchorWithText() +{ m_displayWidget->connectionsProxy()->printAnchorWithText( m_displayOptions, m_filterOptions); } |