summaryrefslogtreecommitdiff
path: root/src/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend')
-rw-r--r--src/frontend/bookmarks/btbookmarkfolder.cpp122
-rw-r--r--src/frontend/bookmarks/btbookmarkfolder.h50
-rw-r--r--src/frontend/bookmarks/btbookmarkitem.cpp147
-rw-r--r--src/frontend/bookmarks/btbookmarkitem.h77
-rw-r--r--src/frontend/bookmarks/btbookmarkitembase.h56
-rw-r--r--src/frontend/bookmarks/btbookmarkloader.cpp173
-rw-r--r--src/frontend/bookmarks/btbookmarkloader.h48
-rw-r--r--src/frontend/bookmarks/bteditbookmarkdialog.cpp14
-rw-r--r--src/frontend/bookmarks/bteditbookmarkdialog.h4
-rw-r--r--src/frontend/bookmarks/cbookmarkindex.cpp1126
-rw-r--r--src/frontend/bookmarks/cbookmarkindex.h230
-rw-r--r--src/frontend/bookshelfmanager/btconfigdialog.cpp109
-rw-r--r--src/frontend/bookshelfmanager/btconfigdialog.h110
-rw-r--r--src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp71
-rw-r--r--src/frontend/bookshelfmanager/btmodulemanagerdialog.h46
-rw-r--r--src/frontend/bookshelfmanager/indexpage/btindexpage.cpp181
-rw-r--r--src/frontend/bookshelfmanager/indexpage/btindexpage.h74
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp83
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h55
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.cpp129
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.h43
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpage.cpp447
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpage.h101
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpagemodel.cpp83
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpagemodel.h32
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.cpp118
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.h57
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp236
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h51
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp163
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h69
-rw-r--r--src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.cpp53
-rw-r--r--src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.h40
-rw-r--r--src/frontend/bookshelfmanager/removepage/btremovepage.cpp194
-rw-r--r--src/frontend/bookshelfmanager/removepage/btremovepage.h61
-rw-r--r--src/frontend/bookshelfmanager/removepage/btremovepagetreemodel.cpp60
-rw-r--r--src/frontend/bookshelfmanager/removepage/btremovepagetreemodel.h30
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfinstallfinalpage.cpp189
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfinstallfinalpage.h77
-rw-r--r--src/frontend/bookshelfwizard/btbookshelflanguagespage.cpp122
-rw-r--r--src/frontend/bookshelfwizard/btbookshelflanguagespage.h57
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfremovefinalpage.cpp61
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfremovefinalpage.h48
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfsourcespage.cpp208
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfsourcespage.h61
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.cpp134
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.h60
-rw-r--r--src/frontend/bookshelfwizard/btbookshelftaskpage.cpp137
-rw-r--r--src/frontend/bookshelfwizard/btbookshelftaskpage.h51
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfwizard.cpp169
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfwizard.h84
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfwizardenums.h33
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfwizardpage.h42
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfworkspage.cpp320
-rw-r--r--src/frontend/bookshelfwizard/btbookshelfworkspage.h78
-rw-r--r--src/frontend/bookshelfwizard/btinstallpagemodel.cpp83
-rw-r--r--src/frontend/bookshelfwizard/btinstallpagemodel.h38
-rw-r--r--src/frontend/bookshelfwizard/cswordsetupinstallsourcesdialog.cpp (renamed from src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp)29
-rw-r--r--src/frontend/bookshelfwizard/cswordsetupinstallsourcesdialog.h (renamed from src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h)4
-rw-r--r--src/frontend/btaboutdialog.cpp35
-rw-r--r--src/frontend/btaboutdialog.h22
-rw-r--r--src/frontend/btaboutmoduledialog.cpp8
-rw-r--r--src/frontend/btaboutmoduledialog.h6
-rw-r--r--src/frontend/btbookshelfdockwidget.cpp76
-rw-r--r--src/frontend/btbookshelfdockwidget.h4
-rw-r--r--src/frontend/btbookshelfgroupingmenu.cpp32
-rw-r--r--src/frontend/btbookshelfgroupingmenu.h6
-rw-r--r--src/frontend/btbookshelfview.cpp19
-rw-r--r--src/frontend/btbookshelfview.h8
-rw-r--r--src/frontend/btbookshelfwidget.cpp65
-rw-r--r--src/frontend/btbookshelfwidget.h6
-rw-r--r--src/frontend/btcentralwidget.cpp2
-rw-r--r--src/frontend/btcentralwidget.h2
-rw-r--r--src/frontend/btmenuview.cpp34
-rw-r--r--src/frontend/btmenuview.h4
-rw-r--r--src/frontend/btmodulechooserdialog.cpp14
-rw-r--r--src/frontend/btmodulechooserdialog.h4
-rw-r--r--src/frontend/btmoduleindexdialog.cpp58
-rw-r--r--src/frontend/btmoduleindexdialog.h10
-rw-r--r--src/frontend/btopenworkaction.cpp50
-rw-r--r--src/frontend/btopenworkaction.h9
-rw-r--r--src/frontend/btprinter.cpp116
-rw-r--r--src/frontend/btprinter.h45
-rw-r--r--src/frontend/btwebenginepage.cpp95
-rw-r--r--src/frontend/btwebenginepage.h69
-rw-r--r--src/frontend/btwebengineview.cpp62
-rw-r--r--src/frontend/btwebengineview.h45
-rw-r--r--src/frontend/cdragdrop.h4
-rw-r--r--src/frontend/cexportmanager.cpp547
-rw-r--r--src/frontend/cexportmanager.h211
-rw-r--r--src/frontend/cinfodisplay.cpp391
-rw-r--r--src/frontend/cinfodisplay.h37
-rw-r--r--src/frontend/cmdiarea.cpp113
-rw-r--r--src/frontend/cmdiarea.h16
-rw-r--r--src/frontend/cprinter.cpp124
-rw-r--r--src/frontend/cprinter.h50
-rw-r--r--src/frontend/crossrefrendering.cpp6
-rw-r--r--src/frontend/crossrefrendering.h8
-rw-r--r--src/frontend/display/btcolorwidget.cpp44
-rw-r--r--src/frontend/display/btcolorwidget.h33
-rw-r--r--src/frontend/display/btfindwidget.cpp140
-rw-r--r--src/frontend/display/btfindwidget.h87
-rw-r--r--src/frontend/display/btfontsizewidget.cpp38
-rw-r--r--src/frontend/display/btfontsizewidget.h40
-rw-r--r--src/frontend/display/bthtml.js2
-rw-r--r--src/frontend/display/bthtmljsobject.cpp29
-rw-r--r--src/frontend/display/bthtmljsobject.h2
-rw-r--r--src/frontend/display/bthtmlreaddisplay.cpp197
-rw-r--r--src/frontend/display/bthtmlreaddisplay.h56
-rw-r--r--src/frontend/display/btwebengine.js140
-rw-r--r--src/frontend/display/cdisplay.cpp6
-rw-r--r--src/frontend/display/cdisplay.h8
-rw-r--r--src/frontend/display/chtmlwritedisplay.cpp98
-rw-r--r--src/frontend/display/chtmlwritedisplay.h22
-rw-r--r--src/frontend/display/cplainwritedisplay.cpp14
-rw-r--r--src/frontend/display/cplainwritedisplay.h58
-rw-r--r--src/frontend/display/creaddisplay.cpp8
-rw-r--r--src/frontend/display/creaddisplay.h12
-rw-r--r--src/frontend/displaywindow/btactioncollection.cpp141
-rw-r--r--src/frontend/displaywindow/btactioncollection.h110
-rw-r--r--src/frontend/displaywindow/btdisplaysettingsbutton.cpp21
-rw-r--r--src/frontend/displaywindow/btdisplaysettingsbutton.h14
-rw-r--r--src/frontend/displaywindow/btmodulechooserbar.cpp60
-rw-r--r--src/frontend/displaywindow/btmodulechooserbar.h6
-rw-r--r--src/frontend/displaywindow/btmodulechooserbutton.cpp53
-rw-r--r--src/frontend/displaywindow/btmodulechooserbutton.h10
-rw-r--r--src/frontend/displaywindow/bttextwindowheader.cpp63
-rw-r--r--src/frontend/displaywindow/bttextwindowheader.h6
-rw-r--r--src/frontend/displaywindow/bttextwindowheaderwidget.cpp49
-rw-r--r--src/frontend/displaywindow/bttextwindowheaderwidget.h7
-rw-r--r--src/frontend/displaywindow/bttoolbarpopupaction.cpp10
-rw-r--r--src/frontend/displaywindow/bttoolbarpopupaction.h7
-rw-r--r--src/frontend/displaywindow/btwindowmodulechooser.h2
-rw-r--r--src/frontend/displaywindow/cbiblereadwindow.cpp194
-rw-r--r--src/frontend/displaywindow/cbiblereadwindow.h60
-rw-r--r--src/frontend/displaywindow/cbookreadwindow.cpp70
-rw-r--r--src/frontend/displaywindow/cbookreadwindow.h36
-rw-r--r--src/frontend/displaywindow/ccommentaryreadwindow.cpp89
-rw-r--r--src/frontend/displaywindow/ccommentaryreadwindow.h27
-rw-r--r--src/frontend/displaywindow/cdisplaywindow.cpp261
-rw-r--r--src/frontend/displaywindow/cdisplaywindow.h48
-rw-r--r--src/frontend/displaywindow/cdisplaywindowfactory.cpp65
-rw-r--r--src/frontend/displaywindow/cdisplaywindowfactory.h33
-rw-r--r--src/frontend/displaywindow/chtmlwritewindow.cpp49
-rw-r--r--src/frontend/displaywindow/chtmlwritewindow.h44
-rw-r--r--src/frontend/displaywindow/clexiconreadwindow.cpp199
-rw-r--r--src/frontend/displaywindow/clexiconreadwindow.h41
-rw-r--r--src/frontend/displaywindow/cplainwritewindow.cpp160
-rw-r--r--src/frontend/displaywindow/cplainwritewindow.h45
-rw-r--r--src/frontend/displaywindow/creadwindow.cpp143
-rw-r--r--src/frontend/displaywindow/creadwindow.h91
-rw-r--r--src/frontend/keychooser/bthistory.cpp39
-rw-r--r--src/frontend/keychooser/bthistory.h2
-rw-r--r--src/frontend/keychooser/cbookkeychooser.cpp39
-rw-r--r--src/frontend/keychooser/cbookkeychooser.h37
-rw-r--r--src/frontend/keychooser/cbooktreechooser.cpp27
-rw-r--r--src/frontend/keychooser/cbooktreechooser.h41
-rw-r--r--src/frontend/keychooser/ckeychooser.cpp17
-rw-r--r--src/frontend/keychooser/ckeychooser.h13
-rw-r--r--src/frontend/keychooser/ckeychooserwidget.cpp40
-rw-r--r--src/frontend/keychooser/ckeychooserwidget.h19
-rw-r--r--src/frontend/keychooser/clexiconkeychooser.cpp25
-rw-r--r--src/frontend/keychooser/clexiconkeychooser.h39
-rw-r--r--src/frontend/keychooser/cscrollbutton.cpp8
-rw-r--r--src/frontend/keychooser/cscrollbutton.h14
-rw-r--r--src/frontend/keychooser/cscrollerwidgetset.cpp28
-rw-r--r--src/frontend/keychooser/cscrollerwidgetset.h6
-rw-r--r--src/frontend/keychooser/versekeychooser/btbiblekeywidget.cpp51
-rw-r--r--src/frontend/keychooser/versekeychooser/btbiblekeywidget.h16
-rw-r--r--src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.cpp48
-rw-r--r--src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.h18
-rw-r--r--src/frontend/keychooser/versekeychooser/btversekeymenu.cpp15
-rw-r--r--src/frontend/keychooser/versekeychooser/btversekeymenu.h6
-rw-r--r--src/frontend/keychooser/versekeychooser/cbiblekeychooser.cpp48
-rw-r--r--src/frontend/keychooser/versekeychooser/cbiblekeychooser.h34
-rw-r--r--src/frontend/messagedialog.cpp11
-rw-r--r--src/frontend/messagedialog.h2
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp20
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisdialog.h9
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisitem.cpp40
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisitem.h6
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp27
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysislegenditem.h12
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisscene.cpp45
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisscene.h5
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisview.cpp18
-rw-r--r--src/frontend/searchdialog/analysis/csearchanalysisview.h20
-rw-r--r--src/frontend/searchdialog/btsearchmodulechooserdialog.cpp10
-rw-r--r--src/frontend/searchdialog/btsearchmodulechooserdialog.h20
-rw-r--r--src/frontend/searchdialog/btsearchoptionsarea.cpp101
-rw-r--r--src/frontend/searchdialog/btsearchoptionsarea.h26
-rw-r--r--src/frontend/searchdialog/btsearchresultarea.cpp50
-rw-r--r--src/frontend/searchdialog/btsearchresultarea.h14
-rw-r--r--src/frontend/searchdialog/btsearchsyntaxhelpdialog.cpp19
-rw-r--r--src/frontend/searchdialog/btsearchsyntaxhelpdialog.h8
-rw-r--r--src/frontend/searchdialog/chistorycombobox.cpp2
-rw-r--r--src/frontend/searchdialog/chistorycombobox.h4
-rw-r--r--src/frontend/searchdialog/cmoduleresultview.cpp72
-rw-r--r--src/frontend/searchdialog/cmoduleresultview.h6
-rw-r--r--src/frontend/searchdialog/crangechooserdialog.cpp79
-rw-r--r--src/frontend/searchdialog/crangechooserdialog.h8
-rw-r--r--src/frontend/searchdialog/csearchdialog.cpp97
-rw-r--r--src/frontend/searchdialog/csearchdialog.h15
-rw-r--r--src/frontend/searchdialog/csearchresultview.cpp71
-rw-r--r--src/frontend/searchdialog/csearchresultview.h12
-rw-r--r--src/frontend/settingsdialogs/btconfigdialog.cpp87
-rw-r--r--src/frontend/settingsdialogs/btconfigdialog.h94
-rw-r--r--src/frontend/settingsdialogs/btfontchooserwidget.cpp51
-rw-r--r--src/frontend/settingsdialogs/btfontchooserwidget.h11
-rw-r--r--src/frontend/settingsdialogs/btfontsettings.cpp31
-rw-r--r--src/frontend/settingsdialogs/btfontsettings.h8
-rw-r--r--src/frontend/settingsdialogs/btlanguagesettings.cpp139
-rw-r--r--src/frontend/settingsdialogs/btlanguagesettings.h50
-rw-r--r--src/frontend/settingsdialogs/btshortcutsdialog.cpp9
-rw-r--r--src/frontend/settingsdialogs/btshortcutsdialog.h4
-rw-r--r--src/frontend/settingsdialogs/btshortcutseditor.cpp277
-rw-r--r--src/frontend/settingsdialogs/btshortcutseditor.h20
-rw-r--r--src/frontend/settingsdialogs/btstandardworkstab.cpp25
-rw-r--r--src/frontend/settingsdialogs/btstandardworkstab.h2
-rw-r--r--src/frontend/settingsdialogs/bttextfilterstab.cpp7
-rw-r--r--src/frontend/settingsdialogs/bttextfilterstab.h2
-rw-r--r--src/frontend/settingsdialogs/cacceleratorsettings.cpp59
-rw-r--r--src/frontend/settingsdialogs/cacceleratorsettings.h15
-rw-r--r--src/frontend/settingsdialogs/cconfigurationdialog.cpp24
-rw-r--r--src/frontend/settingsdialogs/cconfigurationdialog.h6
-rw-r--r--src/frontend/settingsdialogs/cdisplaysettings.cpp160
-rw-r--r--src/frontend/settingsdialogs/cdisplaysettings.h22
-rw-r--r--src/frontend/settingsdialogs/clistwidget.cpp2
-rw-r--r--src/frontend/settingsdialogs/clistwidget.h6
-rw-r--r--src/frontend/settingsdialogs/cswordsettings.cpp5
-rw-r--r--src/frontend/settingsdialogs/cswordsettings.h7
-rw-r--r--src/frontend/tips/bttipdialog.cpp59
-rw-r--r--src/frontend/tips/bttipdialog.h9
-rw-r--r--src/frontend/welcome/btwelcomedialog.cpp95
-rw-r--r--src/frontend/welcome/btwelcomedialog.h45
235 files changed, 6798 insertions, 8481 deletions
diff --git a/src/frontend/bookmarks/btbookmarkfolder.cpp b/src/frontend/bookmarks/btbookmarkfolder.cpp
deleted file mode 100644
index 3088e99..0000000
--- a/src/frontend/bookmarks/btbookmarkfolder.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/bookmarks/btbookmarkfolder.h"
-
-#include <QFileDialog>
-#include "bibletimeapp.h"
-#include "frontend/bookmarks/btbookmarkitembase.h"
-#include "frontend/bookmarks/btbookmarkitem.h"
-#include "frontend/bookmarks/btbookmarkloader.h"
-#include "util/cresmgr.h"
-#include "util/geticon.h"
-
-
-BtBookmarkFolder::BtBookmarkFolder(const QString &name, QTreeWidgetItem *parent)
- : BtBookmarkItemBase(parent) {
- setText(0, name);
- setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled);
-}
-
-bool BtBookmarkFolder::enableAction(MenuAction action) {
- if (action == ChangeFolder || action == NewFolder || action == DeleteEntries || action == ImportBookmarks )
- return true;
- if (action == SortFolderBookmarks || action == ExportBookmarks || action == ImportBookmarks )
- return true;
- if ((action == PrintBookmarks) && childCount())
- return true;
- return false;
-}
-
-void BtBookmarkFolder::exportBookmarks() {
- QString filter = QObject::tr("BibleTime bookmark files") + QString(" (*.btb);;") + QObject::tr("All files") + QString(" (*.*)");
- QString fileName = QFileDialog::getSaveFileName(0, QObject::tr("Export Bookmarks"), "", filter);
-
- if (!fileName.isEmpty()) {
- BtBookmarkLoader loader;
- loader.saveTreeFromRootItem(this, fileName, false ); //false: don't overwrite without asking
- };
-
-}
-
-void BtBookmarkFolder::importBookmarks() {
- QString filter = QObject::tr("BibleTime bookmark files") + QString(" (*.btb);;") + QObject::tr("All files") + QString(" (*.*)");
- QString fileName = QFileDialog::getOpenFileName(0, QObject::tr("Import bookmarks"), "", filter);
- if (!fileName.isEmpty()) {
- BtBookmarkLoader loader;
- QList<QTreeWidgetItem*> itemList = loader.loadTree(fileName);
- this->insertChildren(0, itemList);
- };
-}
-
-void BtBookmarkFolder::newSubFolder() {
- if (dynamic_cast<BtBookmarkFolder*>(this)) {
- BtBookmarkFolder* f = new BtBookmarkFolder(QObject::tr("New folder"), this);
-
- treeWidget()->setCurrentItem(f);
- f->update();
- f->rename();
- }
-}
-
-QList<QTreeWidgetItem*> BtBookmarkFolder::getChildList() const {
- QList<QTreeWidgetItem*> list;
- for (int i = 0; i < childCount(); i++) {
- list.append(child(i));
- }
- return list;
-}
-
-void BtBookmarkFolder::rename() {
- treeWidget()->editItem(this);
-}
-
-void BtBookmarkFolder::update() {
- setIcon(0, util::getIcon(isExpanded() && childCount()
- ? CResMgr::mainIndex::openedFolder::icon
- : CResMgr::mainIndex::closedFolder::icon));
-}
-
-bool BtBookmarkFolder::hasDescendant(QTreeWidgetItem* item) const {
- if (this == item) {
- return true;
- }
- if (getChildList().indexOf(item) > -1) {
- return true;
- }
- foreach(QTreeWidgetItem* childItem, getChildList()) {
- bool subresult = false;
- BtBookmarkFolder* folder = 0;
- if ( (folder = dynamic_cast<BtBookmarkFolder*>(childItem)) ) {
- subresult = folder->hasDescendant(childItem);
- }
-
- if (subresult == true) {
- return true;
- }
- }
- return false;
-}
-
-BtBookmarkFolder* BtBookmarkFolder::deepCopy() {
- BtBookmarkFolder* newFolder = new BtBookmarkFolder(this->text(0));
- foreach(QTreeWidgetItem* subitem, getChildList()) {
- if (BtBookmarkItem* bmItem = dynamic_cast<BtBookmarkItem*>(subitem)) {
- newFolder->addChild(new BtBookmarkItem(*bmItem));
- }
- else {
- if (BtBookmarkFolder* bmFolder = dynamic_cast<BtBookmarkFolder*>(subitem)) {
- newFolder->addChild(bmFolder->deepCopy());
- }
- }
- }
- newFolder->update();
- return newFolder;
-}
-
diff --git a/src/frontend/bookmarks/btbookmarkfolder.h b/src/frontend/bookmarks/btbookmarkfolder.h
deleted file mode 100644
index 4f7c80c..0000000
--- a/src/frontend/bookmarks/btbookmarkfolder.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTBOOKMARKFOLDER_H
-#define BTBOOKMARKFOLDER_H
-
-#include "frontend/bookmarks/btbookmarkitembase.h"
-
-
-#define CURRENT_SYNTAX_VERSION 1
-
-class BtBookmarkFolder : public BtBookmarkItemBase {
- public:
-
- BtBookmarkFolder(const QString &name, QTreeWidgetItem *parent = 0);
-
- /** See the base class. */
- virtual bool enableAction(const MenuAction action);
-
- /** User gives a file from which to load items into this folder. */
- virtual void exportBookmarks();
- /** User gives a file to which items from this folder are saved. */
- virtual void importBookmarks();
-
- /** Creates a new folder under this. */
- void newSubFolder();
-
- /** Returns a list of direct childs of this item. */
- QList<QTreeWidgetItem*> getChildList() const;
-
- /** Returns true if the given item is this or a direct or indirect subitem of this. */
- bool hasDescendant(QTreeWidgetItem* item) const;
-
- /** Creates a deep copy of this item. */
- BtBookmarkFolder* deepCopy();
-
- void rename();
- void update();
-
-};
-
-#endif
diff --git a/src/frontend/bookmarks/btbookmarkitem.cpp b/src/frontend/bookmarks/btbookmarkitem.cpp
deleted file mode 100644
index 952be22..0000000
--- a/src/frontend/bookmarks/btbookmarkitem.cpp
+++ /dev/null
@@ -1,147 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/bookmarks/btbookmarkitem.h"
-
-#include <QSharedPointer>
-#include "backend/config/btconfig.h"
-#include "backend/managers/cswordbackend.h"
-#include "backend/drivers/cswordmoduleinfo.h"
-#include "backend/keys/cswordversekey.h"
-#include "bibletimeapp.h"
-#include "btglobal.h"
-#include "frontend/bookmarks/btbookmarkfolder.h"
-#include "frontend/bookmarks/bteditbookmarkdialog.h"
-#include "util/cresmgr.h"
-#include "util/geticon.h"
-
-
-BtBookmarkItem::BtBookmarkItem(const CSwordModuleInfo *module,
- const QString &key,
- const QString &description,
- const QString &title)
- : m_description(description),
- m_moduleName(module ? module->name() : QString::null),
- m_title(title)
-{
- if (((module && (module->type() == CSwordModuleInfo::Bible)) || (module->type() == CSwordModuleInfo::Commentary)) ) {
- CSwordVerseKey vk(0);
- vk.setKey(key);
- vk.setLocale("en");
- m_key = vk.key(); //the m_key member is always the english key!
- }
- else {
- m_key = key;
- };
-
- update();
-}
-
-BtBookmarkItem::BtBookmarkItem(QTreeWidgetItem* parent)
- : BtBookmarkItemBase(parent) {}
-
-BtBookmarkItem::BtBookmarkItem(const BtBookmarkItem& other)
- : BtBookmarkItemBase(0),
- m_key(other.m_key),
- m_description(other.m_description),
- m_moduleName(other.m_moduleName),
- m_title(other.m_title)
-{
- update();
-}
-
-CSwordModuleInfo *BtBookmarkItem::module() const {
- return CSwordBackend::instance()->findModuleByName(m_moduleName);
-}
-
-QString BtBookmarkItem::key() const {
- const QString englishKeyName = englishKey();
- if (!module()) {
- return englishKeyName;
- }
-
- QString returnKeyName = englishKeyName;
- if ((module()->type() == CSwordModuleInfo::Bible) || (module()->type() == CSwordModuleInfo::Commentary)) {
- CSwordVerseKey vk(0);
- vk.setKey(englishKeyName);
- vk.setLocale(CSwordBackend::instance()->booknameLanguage().toLatin1() );
-
- returnKeyName = vk.key(); //the returned key is always in the currently set bookname language
- }
-
- return returnKeyName;
-}
-
-QString BtBookmarkItem::toolTip() const {
- if (!module()) {
- return QString::null;
- }
-
- FilterOptions filterOptions = btConfig().getFilterOptions();
- filterOptions.footnotes = false;
- filterOptions.scriptureReferences = false;
- CSwordBackend::instance()->setFilterOptions(filterOptions);
-
- QString ret;
- QSharedPointer<CSwordKey> k( CSwordKey::createInstance(module()) );
- k->setKey(key());
-
- // const CLanguageMgr::Language* lang = module()->language();
- // BtConfig::FontSettingsPair fontPair = getBtConfig().getFontForLanguage(lang);
-
- Q_ASSERT(k.data());
- QString header = QString::fromLatin1("%1 (%2)")
- .arg(key())
- .arg(module()->name());
- if (title() != header) {
- ret = QString::fromLatin1("<b>%1</b><br>%2<hr>%3")
- .arg(header)
- .arg(title())
- .arg(description())
- ;
- }
- else {
- ret = QString::fromLatin1("<b>%1</b><hr>%2")
- .arg(header)
- .arg(description())
- ;
- }
-
- return ret;
-}
-
-bool BtBookmarkItem::enableAction(MenuAction action) {
- if (action == EditBookmark || (module() && (action == PrintBookmarks)) || action == DeleteEntries)
- return true;
-
- return false;
-}
-
-void BtBookmarkItem::rename() {
- BtEditBookmarkDialog d(QString::fromLatin1("%1 (%2)").arg(key()).arg(module() ? module()->name() : QObject::tr("unknown")),
- m_title,
- m_description, treeWidget());
-
- if (d.exec() == QDialog::Accepted) {
- m_title = d.titleText();
- m_description = d.descriptionText();
- update();
- }
-}
-
-void BtBookmarkItem::update() {
- setIcon(0, util::getIcon(CResMgr::mainIndex::bookmark::icon));
-
- if (m_title.isEmpty()) {
- m_title = QString::fromLatin1("%1 (%2)").arg(key()).arg(module() ? module()->name() : QObject::tr("unknown"));
- }
- setText(0,m_title);
- setToolTip(0, toolTip());
-}
-
diff --git a/src/frontend/bookmarks/btbookmarkitem.h b/src/frontend/bookmarks/btbookmarkitem.h
deleted file mode 100644
index 932d4e0..0000000
--- a/src/frontend/bookmarks/btbookmarkitem.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTBOOKMARKITEM_H
-#define BTBOOKMARKITEM_H
-
-#include "frontend/bookmarks/btbookmarkitembase.h"
-
-#include <QString>
-
-
-class BtBookmarkFolder;
-class CSwordModuleInfo;
-
-class BtBookmarkItem : public BtBookmarkItemBase {
- public:
- friend class BtBookmarkLoader;
-
- BtBookmarkItem(QTreeWidgetItem* parent);
-
- /** Creates a bookmark with module, key and description. */
- BtBookmarkItem(const CSwordModuleInfo *module, const QString &key,
- const QString &description, const QString &title);
-
- /** Creates a copy. */
- BtBookmarkItem(const BtBookmarkItem& other);
-
- /** Returns the used module, 0 if there is no such module. */
- CSwordModuleInfo *module() const;
-
- /** Returns the used key. */
- QString key() const;
-
- /** Returns the used description. */
- inline const QString &description() const {
- return m_description;
- }
-
- /** Returns the title. */
- inline const QString &title() const {
- return m_title;
- }
-
- /** Returns whether the action is supported by this item. */
- virtual bool enableAction(MenuAction action);
-
- /** Changes this bookmark. */
- virtual void rename();
-
- virtual void update();
-
- private:
-
- /** Returns a tooltip for this bookmark. */
- QString toolTip() const;
-
- /** Returns the english key.*/
- inline const QString &englishKey() const {
- return m_key;
- }
-
- private:
- QString m_key;
- QString m_description;
- QString m_moduleName;
- QString m_title;
-};
-
-#endif
diff --git a/src/frontend/bookmarks/btbookmarkitembase.h b/src/frontend/bookmarks/btbookmarkitembase.h
deleted file mode 100644
index 630d018..0000000
--- a/src/frontend/bookmarks/btbookmarkitembase.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTBOOKMARKITEMBASE_H
-#define BTBOOKMARKITEMBASE_H
-
-#include <QTreeWidgetItem>
-
-
-class BtBookmarkItemBase: public QTreeWidgetItem {
-
- public: /* Types: */
-
- enum MenuAction {
- NewFolder = 0,
- ChangeFolder,
-
- EditBookmark,
- SortFolderBookmarks,
- SortAllBookmarks,
- ImportBookmarks,
- ExportBookmarks,
- PrintBookmarks,
-
- DeleteEntries,
-
- ActionBegin = NewFolder,
- ActionEnd = DeleteEntries
- };
-
- public: /* Methods: */
-
- inline BtBookmarkItemBase(QTreeWidgetItem *parent = 0)
- : QTreeWidgetItem(parent) {}
-
- /** Returns true if the given action should be enabled in the popup menu. */
- virtual bool enableAction(MenuAction action) = 0;
-
- /** Rename the item. */
- virtual void rename() = 0;
-
- /** Update the item (icon etc.) after creating or changing it. */
- virtual void update() = 0;
-
-};
-
-#endif
-
diff --git a/src/frontend/bookmarks/btbookmarkloader.cpp b/src/frontend/bookmarks/btbookmarkloader.cpp
deleted file mode 100644
index 63e0797..0000000
--- a/src/frontend/bookmarks/btbookmarkloader.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/bookmarks/btbookmarkloader.h"
-
-#include <QDomElement>
-#include <QDomNode>
-#include <QDomDocument>
-#include <QFile>
-#include <QIODevice>
-#include <QTextCodec>
-#include <QTextStream>
-#include <QTreeWidgetItem>
-#include "backend/drivers/cswordmoduleinfo.h"
-#include "frontend/bookmarks/btbookmarkitem.h"
-#include "frontend/bookmarks/btbookmarkfolder.h"
-#include "util/tool.h"
-
-
-#define CURRENT_SYNTAX_VERSION 1
-
-QList<QTreeWidgetItem*> BtBookmarkLoader::loadTree(QString fileName) {
- QList<QTreeWidgetItem*> itemList;
-
- QDomDocument doc;
- doc.setContent(loadXmlFromFile(fileName));
-
- //bookmarkfolder::loadBookmarksFromXML()
-
- QDomElement document = doc.documentElement();
- if ( document.tagName() != "SwordBookmarks" ) {
- qWarning("Not a BibleTime Bookmark XML file");
- return QList<QTreeWidgetItem*>();
- }
-
- QDomElement child = document.firstChild().toElement();
-
- while ( !child.isNull() && child.parentNode() == document) {
- QTreeWidgetItem* i = handleXmlElement(child, 0);
- itemList.append(i);
- if (!child.nextSibling().isNull()) {
- child = child.nextSibling().toElement();
- }
- else {
- child = QDomElement(); //null
- }
-
- }
-
- return itemList;
-}
-
-QTreeWidgetItem* BtBookmarkLoader::handleXmlElement(QDomElement& element, QTreeWidgetItem* parent) {
- QTreeWidgetItem* newItem = 0;
- if (element.tagName() == "Folder") {
- BtBookmarkFolder* newFolder = new BtBookmarkFolder(QString::null, parent);
- if (element.hasAttribute("caption")) {
- newFolder->setText(0, element.attribute("caption"));
- }
- QDomNodeList childList = element.childNodes();
-#if QT_VERSION < 0x050000
- for (unsigned int i = 0; i < childList.length(); i++) {
-#else
- for (int i = 0; i < childList.length(); i++) {
-#endif
- QDomElement newElement = childList.at(i).toElement();
- QTreeWidgetItem* newChildItem = handleXmlElement(newElement, newFolder);
- newFolder->addChild(newChildItem);
- }
- newFolder->update();
- newItem = newFolder;
- }
- else if (element.tagName() == "Bookmark") {
- BtBookmarkItem* newBookmarkItem = new BtBookmarkItem(parent);
- if (element.hasAttribute("modulename")) {
- //we use the name in all cases, even if the module isn't installed anymore
- newBookmarkItem->m_moduleName = element.attribute("modulename");
- }
- if (element.hasAttribute("key")) {
- newBookmarkItem->m_key = element.attribute("key");
- }
- if (element.hasAttribute("description")) {
- newBookmarkItem->m_description = element.attribute("description");
- }
- if (element.hasAttribute("title")) {
- newBookmarkItem->m_title = element.attribute("title");
- }
- newBookmarkItem->update();
- newItem = newBookmarkItem;
- }
- return newItem;
-}
-
-
-QString BtBookmarkLoader::loadXmlFromFile(QString fileName) {
- namespace DU = util::directory;
-
- if (fileName.isNull()) {
- fileName = DU::getUserBaseDir().absolutePath() + "/bookmarks.xml";
- }
- QFile file(fileName);
- if (!file.exists())
- return QString::null;
-
- QString xml;
- if (file.open(QIODevice::ReadOnly)) {
- QTextStream t;
- t.setAutoDetectUnicode(false);
- t.setCodec(QTextCodec::codecForName("UTF-8"));
- t.setDevice(&file);
- xml = t.readAll();
- file.close();
- }
- return xml;
-}
-
-void BtBookmarkLoader::saveTreeFromRootItem(QTreeWidgetItem* rootItem, QString fileName, bool forceOverwrite) {
- namespace DU = util::directory;
-
- Q_ASSERT(rootItem);
- if (fileName.isNull()) {
- fileName = DU::getUserBaseDir().absolutePath() + "/bookmarks.xml";
- }
-
- QDomDocument doc("DOC");
- doc.appendChild( doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
-
- QDomElement content = doc.createElement("SwordBookmarks");
- content.setAttribute("syntaxVersion", CURRENT_SYNTAX_VERSION);
- doc.appendChild(content);
-
- //append the XML nodes of all child items
-
- for (int i = 0; i < rootItem->childCount(); i++) {
- saveItem(rootItem->child(i), content);
- }
- util::tool::savePlainFile(fileName, doc.toString(), forceOverwrite, QTextCodec::codecForName("UTF-8"));
-
-}
-
-void BtBookmarkLoader::saveItem(QTreeWidgetItem* item, QDomElement& parentElement) {
- BtBookmarkFolder* folderItem = 0;
- BtBookmarkItem* bookmarkItem = 0;
-
- if ((folderItem = dynamic_cast<BtBookmarkFolder*>(item))) {
- QDomElement elem = parentElement.ownerDocument().createElement("Folder");
- elem.setAttribute("caption", folderItem->text(0));
-
- parentElement.appendChild(elem);
-
- for (int i = 0; i < folderItem->childCount(); i++) {
- saveItem(folderItem->child(i), elem);
- }
- }
- else if ((bookmarkItem = dynamic_cast<BtBookmarkItem*>(item))) {
- QDomElement elem = parentElement.ownerDocument().createElement("Bookmark");
-
- elem.setAttribute("key", bookmarkItem->englishKey());
- elem.setAttribute("description", bookmarkItem->description());
- elem.setAttribute("modulename", bookmarkItem->m_moduleName);
- elem.setAttribute("moduledescription", bookmarkItem->module() ? bookmarkItem->module()->config(CSwordModuleInfo::Description) : QString::null);
- if ( ! bookmarkItem->title().isEmpty()) {
- elem.setAttribute("title", bookmarkItem->m_title);
- }
- parentElement.appendChild(elem);
- }
-}
diff --git a/src/frontend/bookmarks/btbookmarkloader.h b/src/frontend/bookmarks/btbookmarkloader.h
deleted file mode 100644
index 25b56b8..0000000
--- a/src/frontend/bookmarks/btbookmarkloader.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTBOOKMARKLOADER_H
-#define BTBOOKMARKLOADER_H
-
-#include "util/directory.h"
-
-#include <QDomElement>
-#include <QList>
-#include <QString>
-
-
-class QTreeWidgetItem;
-
-/**
-* Class for loading and saving bookmarks.
-*/
-class BtBookmarkLoader {
- public:
- /** Loads a list of items (with subitem trees) from a named file
- * or from the default bookmarks file. */
- QList<QTreeWidgetItem*> loadTree(QString fileName = QString::null);
-
- /** Takes one item and saves the tree which is under it to a named file
- * or to the default bookmarks file, asking the user about overwriting if necessary. */
- void saveTreeFromRootItem(QTreeWidgetItem* rootItem, QString fileName = QString::null, bool forceOverwrite = true);
-
- private:
- /** Create a new item from a document element. */
- QTreeWidgetItem* handleXmlElement(QDomElement& element, QTreeWidgetItem* parent);
-
- /** Writes one item to a document element. */
- void saveItem(QTreeWidgetItem* item, QDomElement& parentElement);
-
- /** Loads a bookmark XML document from a named file or from the default bookmarks file. */
- QString loadXmlFromFile(QString fileName = QString::null);
-};
-
-#endif
diff --git a/src/frontend/bookmarks/bteditbookmarkdialog.cpp b/src/frontend/bookmarks/bteditbookmarkdialog.cpp
index 1291f56..f27b501 100644
--- a/src/frontend/bookmarks/bteditbookmarkdialog.cpp
+++ b/src/frontend/bookmarks/bteditbookmarkdialog.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -10,16 +10,16 @@
#include "bteditbookmarkdialog.h"
#include <QDialogButtonBox>
-#include <QVBoxLayout>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
+#include <QVBoxLayout>
#include <QWidget>
#include "bibletimeapp.h"
-#include "util/cresmgr.h"
#include "frontend/messagedialog.h"
-#include "util/geticon.h"
+#include "util/btconnect.h"
+#include "util/cresmgr.h"
BtEditBookmarkDialog::BtEditBookmarkDialog(const QString &key,
@@ -32,7 +32,7 @@ BtEditBookmarkDialog::BtEditBookmarkDialog(const QString &key,
QVBoxLayout *mainLayout = new QVBoxLayout(this);
resize(400, 300);
- setWindowIcon(util::getIcon(CResMgr::mainIndex::bookmark::icon));
+ setWindowIcon(CResMgr::mainIndex::bookmark::icon());
m_layout = new QFormLayout;
@@ -59,8 +59,8 @@ BtEditBookmarkDialog::BtEditBookmarkDialog(const QString &key,
message::prepareDialogBox(m_buttonBox);
mainLayout->addWidget(m_buttonBox);
- QObject::connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
- QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ BT_CONNECT(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ BT_CONNECT(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
retranslateUi();
diff --git a/src/frontend/bookmarks/bteditbookmarkdialog.h b/src/frontend/bookmarks/bteditbookmarkdialog.h
index 674ccdf..1093842 100644
--- a/src/frontend/bookmarks/bteditbookmarkdialog.h
+++ b/src/frontend/bookmarks/bteditbookmarkdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -31,7 +31,7 @@ class BtEditBookmarkDialog : public QDialog {
BtEditBookmarkDialog(const QString &key,
const QString &title,
const QString &description,
- QWidget *parent = 0,
+ QWidget *parent = nullptr,
Qt::WindowFlags wflags = Qt::Dialog);
/**
diff --git a/src/frontend/bookmarks/cbookmarkindex.cpp b/src/frontend/bookmarks/cbookmarkindex.cpp
index 1b697d0..30b6855 100644
--- a/src/frontend/bookmarks/cbookmarkindex.cpp
+++ b/src/frontend/bookmarks/cbookmarkindex.cpp
@@ -2,79 +2,69 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
-#include "frontend/bookmarks/cbookmarkindex.h"
-
-#include <QSharedPointer>
+#include <memory>
#include <QAction>
#include <QApplication>
#include <QCursor>
-#include <QDebug>
#include <QDrag>
#include <QDragLeaveEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
-#include <QInputDialog>
-#include <QList>
+#include <QFileDialog>
#include <QMenu>
#include <QMouseEvent>
#include <QPainter>
#include <QPaintEvent>
#include <QTimer>
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
#include <QToolTip>
#include "backend/config/btconfig.h"
#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/btbookmarksmodel.h"
#include "backend/managers/referencemanager.h"
+#include "bibletime.h"
#include "bibletimeapp.h"
+#include "frontend/btprinter.h"
#include "frontend/cdragdrop.h"
#include "frontend/cinfodisplay.h"
-#include "frontend/cprinter.h"
-#include "frontend/bookmarks/btbookmarkitembase.h"
-#include "frontend/bookmarks/btbookmarkitem.h"
-#include "frontend/bookmarks/btbookmarkfolder.h"
-#include "frontend/bookmarks/btbookmarkloader.h"
#include "frontend/messagedialog.h"
#include "frontend/searchdialog/csearchdialog.h"
+#include "frontend/bookmarks/bteditbookmarkdialog.h"
+#include "frontend/bookmarks/cbookmarkindex.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
+#include "util/bticons.h"
+#include "util/btscopeexit.h"
#include "util/cresmgr.h"
#include "util/tool.h"
#include "util/directory.h"
-#include "util/geticon.h"
-#include "bibletime.h"
-CBookmarkIndex::CBookmarkIndex(QWidget *parent)
- : QTreeWidget(parent),
- m_magTimer(this),
- m_previousEventItem(0) {
+CBookmarkIndex::CBookmarkIndex(QWidget * const parent)
+ : QTreeView{parent}
+ , m_magTimer{this}
+ , m_bookmarksModel{nullptr}
+{
setMouseTracking(true);
m_magTimer.setSingleShot(true);
m_magTimer.setInterval(btConfig().value<int>("GUI/magDelay", 400));
setContextMenuPolicy(Qt::CustomContextMenu);
- initView();
- initConnections();
- initTree();
-}
-
-CBookmarkIndex::~CBookmarkIndex() {
- saveBookmarks();
-}
+ setHeaderHidden(true);
+ //--------------------------------------------------------------------------
+ // Initialize view:
-/** Initializes the view. */
-void CBookmarkIndex::initView() {
setHeaderHidden(true);
setFocusPolicy(Qt::WheelFocus);
//d'n'd related settings
- setDragEnabled( true );
- setAcceptDrops( true );
+ setDragEnabled(true);
+ setAcceptDrops(true);
setDragDropMode(QAbstractItemView::DragDrop);
viewport()->setAcceptDrops(true);
setAutoScroll(true);
@@ -85,168 +75,169 @@ void CBookmarkIndex::initView() {
setAllColumnsShowFocus(true);
setSelectionMode(QAbstractItemView::ExtendedSelection);
+ //setExpandsOnDoubleClick(true);
+ setEditTriggers(editTriggers() ^ QAbstractItemView::DoubleClicked);
+
//setup the popup menu
- m_popup = new QMenu(viewport());
+ m_popup = new QMenu{viewport()};
m_popup->setTitle(tr("Bookmarks"));
- m_actions.newFolder = newQAction(tr("New folder"), CResMgr::mainIndex::newFolder::icon, 0, this, SLOT(createNewFolder()), this);
- m_actions.changeFolder = newQAction(tr("Rename folder"), CResMgr::mainIndex::changeFolder::icon, 0, this, SLOT(changeFolder()), this);
-
- m_actions.editBookmark = newQAction(tr("Edit bookmark..."), CResMgr::mainIndex::editBookmark::icon, 0, this, SLOT(editBookmark()), this);
+ auto const newQAction = [this](QString const & text,
+ QIcon const & pix,
+ char const * const slot)
+ {
+ QAction * const action = new QAction{pix, text, this};
+ BT_CONNECT(action, SIGNAL(triggered()), this, slot);
+ return action;
+ };
+
+ namespace MI = CResMgr::mainIndex;
+ m_actions[NewFolder] = newQAction(tr("New folder"),
+ MI::newFolder::icon(),
+ SLOT(createNewFolder()));
+ m_actions[ChangeFolder] = newQAction(tr("Rename folder"),
+ MI::changeFolder::icon(),
+ SLOT(changeFolder()));
+ m_actions[EditBookmark] = newQAction(tr("Edit bookmark..."),
+ MI::editBookmark::icon(),
+ SLOT(editBookmark()));
/// \todo Add icons for sorting bookmarks
- m_actions.sortFolderBookmarks = newQAction(tr("Sort folder bookmarks..."), QString::null, 0, this, SLOT(sortFolderBookmarks()), this);
- m_actions.sortAllBookmarks = newQAction(tr("Sort all bookmarks..."), QString::null, 0, this, SLOT(sortAllBookmarks()), this);
- m_actions.importBookmarks = newQAction(tr("Import to folder..."), CResMgr::mainIndex::importBookmarks::icon, 0, this, SLOT(importBookmarks()), this);
- m_actions.exportBookmarks = newQAction(tr("Export from folder..."), CResMgr::mainIndex::exportBookmarks::icon, 0, this, SLOT(exportBookmarks()), this);
- m_actions.printBookmarks = newQAction(tr("Print bookmarks..."), CResMgr::mainIndex::printBookmarks::icon, 0, this, SLOT(printBookmarks()), this);
-
- m_actions.deleteEntries = newQAction(tr("Remove selected items..."), CResMgr::mainIndex::deleteItems::icon, 0, this, SLOT(deleteEntries()), this);
-
-
- //fill the popup menu itself
- m_popup->addAction(m_actions.newFolder);
- m_popup->addAction(m_actions.changeFolder);
- QAction* separator = new QAction(this);
- separator->setSeparator(true);
- m_popup->addAction(separator);
- m_popup->addAction(m_actions.editBookmark);
- m_popup->addAction(m_actions.sortFolderBookmarks);
- m_popup->addAction(m_actions.sortAllBookmarks);
- m_popup->addAction(m_actions.importBookmarks);
- m_popup->addAction(m_actions.exportBookmarks);
- m_popup->addAction(m_actions.printBookmarks);
- separator = new QAction(this);
- separator->setSeparator(true);
- m_popup->addAction(separator);
- m_popup->addAction(m_actions.deleteEntries);
-
- m_bookmarksModified = false;
-}
+ m_actions[SortFolderBookmarks] = newQAction(tr("Sort folder bookmarks..."),
+ MI::sortFolderBookmarks::icon(),
+ SLOT(sortFolderBookmarks()));
+ m_actions[SortAllBookmarks] = newQAction(tr("Sort all bookmarks..."),
+ MI::sortAllBookmarks::icon(),
+ SLOT(sortAllBookmarks()));
+ m_actions[ImportBookmarks] = newQAction(tr("Import to folder..."),
+ MI::importBookmarks::icon(),
+ SLOT(importBookmarks()));
+ m_actions[ExportBookmarks] = newQAction(tr("Export from folder..."),
+ MI::exportBookmarks::icon(),
+ SLOT(exportBookmarks()));
+ m_actions[PrintBookmarks] = newQAction(tr("Print bookmarks..."),
+ MI::printBookmarks::icon(),
+ SLOT(printBookmarks()));
+
+ m_actions[DeleteEntries] = newQAction(tr("Remove selected items..."),
+ MI::deleteItems::icon(),
+ SLOT(confirmDeleteEntries()));
+
+ // Fill the popup menu:
+ auto const createSeparator = [this]{
+ QAction * const separator = new QAction{this};
+ separator->setSeparator(true);
+ return separator;
+ };
+ m_popup->addAction(m_actions[NewFolder]);
+ m_popup->addAction(m_actions[ChangeFolder]);
+ m_popup->addAction(createSeparator());
+ m_popup->addAction(m_actions[EditBookmark]);
+ m_popup->addAction(m_actions[SortFolderBookmarks]);
+ m_popup->addAction(m_actions[SortAllBookmarks]);
+ m_popup->addAction(m_actions[ImportBookmarks]);
+ m_popup->addAction(m_actions[ExportBookmarks]);
+ m_popup->addAction(m_actions[PrintBookmarks]);
+ m_popup->addAction(createSeparator());
+ m_popup->addAction(m_actions[DeleteEntries]);
+
+
+ //--------------------------------------------------------------------------
+ // Initialize connections:
+
+ BT_CONNECT(this, SIGNAL(activated(QModelIndex const &)),
+ this, SLOT(slotExecuted(QModelIndex const &)));
+ BT_CONNECT(this, SIGNAL(customContextMenuRequested(QPoint const &)),
+ this, SLOT(contextMenu(QPoint const &)));
+ BT_CONNECT(&m_magTimer, SIGNAL(timeout()), this, SLOT(magTimeout()));
+
+ //--------------------------------------------------------------------------
+ // Initialize tree:
+
+ m_bookmarksModel = new BtBookmarksModel{this};
+ setModel(m_bookmarksModel);
-/** Convenience function for creating a new QAction.
-* Should be replaced with something better; it was easier to make a new function
-* than to modify all QAction constructors.
-*/
-QAction* CBookmarkIndex::newQAction(const QString& text, const QString& pix, const int /*shortcut*/, const QObject* receiver, const char* slot, QObject* parent) {
- QAction *action;
- if (pix.isEmpty()) {
- action = new QAction(text, parent);
- } else {
- action = new QAction(util::getIcon(pix), text, parent);
- }
- QObject::connect(action, SIGNAL(triggered()), receiver, slot);
- return action;
-}
-
-/** Initialize the SIGNAL<->SLOT connections */
-void CBookmarkIndex::initConnections() {
- bool ok;
- ok = connect(this, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(slotExecuted(QTreeWidgetItem*)));
- Q_ASSERT(ok);
- ok = connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
- SLOT(contextMenu(const QPoint&)));
- Q_ASSERT(ok);
- ok = connect(&m_magTimer, SIGNAL(timeout()), this, SLOT(magTimeout()));
- Q_ASSERT(ok);
- ok = connect(this, SIGNAL(itemEntered(QTreeWidgetItem*, int)), this, SLOT(slotItemEntered(QTreeWidgetItem*, int)) );
- Q_ASSERT(ok);
-
- // Connection to detect changes in the items themselves (e.g. renames,
- // description changes) so that we can consider saving the bookmarks.
- connect(this, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(needToSaveBookmarks(QTreeWidgetItem*)) );
-
- // Connect the bookmark saving timer.
- bookmarkSaveTimer.setSingleShot(true);
- connect(&bookmarkSaveTimer, SIGNAL(timeout()), this, SLOT(considerSavingBookmarks()) );
+ // add the invisible extra item at the end
+ if(m_bookmarksModel->insertRows(m_bookmarksModel->rowCount(), 1))
+ m_extraItem = m_bookmarksModel->index(m_bookmarksModel->rowCount() - 1, 0);
+ showExtraItem();
}
-
-/**
-* Hack to get single click and selection working. See slotExecuted.
-*/
+/** \note Hack to get single click and selection working. See slotExecuted. */
void CBookmarkIndex::mouseReleaseEvent(QMouseEvent* event) {
m_mouseReleaseEventModifiers = event->modifiers();
- QTreeWidget::mouseReleaseEvent(event);
+ QTreeView::mouseReleaseEvent(event);
}
/** Called when an item is clicked with mouse or activated with keyboard. */
-void CBookmarkIndex::slotExecuted( QTreeWidgetItem* i ) {
- //HACK: checking the modifier keys from the last mouseReleaseEvent
- //depends on executing order: mouseReleaseEvent first, then itemClicked signal
- int modifiers = m_mouseReleaseEventModifiers;
+void CBookmarkIndex::slotExecuted( const QModelIndex &index ) {
+ /** \note HACK: checking the modifier keys from the last mouseReleaseEvent
+ depends on executing order: mouseReleaseEvent first, then
+ itemClicked signal. */
+ auto const modifiers = m_mouseReleaseEventModifiers;
m_mouseReleaseEventModifiers = Qt::NoModifier;
- if (modifiers != Qt::NoModifier) {
- return;
- }
-
- BtBookmarkItemBase* btItem = dynamic_cast<BtBookmarkItemBase*>(i);
- if (!btItem) {
+ if (modifiers != Qt::NoModifier || !index.isValid())
return;
- }
- BtBookmarkFolder* folderItem = 0;
- BtBookmarkItem* bookmarkItem = 0;
- if ((folderItem = dynamic_cast<BtBookmarkFolder*>(btItem))) {
- i->setExpanded( !i->isExpanded() );
- }
- else if (( bookmarkItem = dynamic_cast<BtBookmarkItem*>(btItem) )) { //clicked on a bookmark
- if (CSwordModuleInfo* mod = bookmarkItem->module()) {
- QList<CSwordModuleInfo*> modules;
- modules.append(mod);
- emit createReadDisplayWindow(modules, bookmarkItem->key());
- }
- }
+ // Clicked on a bookmark:
+ if (m_bookmarksModel->isBookmark(index))
+ if (CSwordModuleInfo * const mod = m_bookmarksModel->module(index))
+ emit createReadDisplayWindow(QList<CSwordModuleInfo *>() << mod,
+ m_bookmarksModel->key(index));
}
/** Creates a drag mime data object for the current selection. */
-QMimeData* CBookmarkIndex::dragObject() {
- BTMimeData::ItemList dndItems;
- BTMimeData* mimeData = new BTMimeData;
+QMimeData * CBookmarkIndex::dragObject() {
+ BTMimeData * const mimeData = new BTMimeData{};
- foreach( QTreeWidgetItem* widgetItem, selectedItems() ) {
- if (!widgetItem)
+ Q_FOREACH(QModelIndex const & widgetItem, selectedIndexes()) {
+ if (!widgetItem.isValid())
break;
- if (dynamic_cast<BtBookmarkItemBase*>(widgetItem)) {
- if (BtBookmarkItem* bookmark = dynamic_cast<BtBookmarkItem*>( widgetItem )) {
- //take care of bookmarks which have no valid module any more, e.g. if it was uninstalled
- const QString moduleName = bookmark->module() ? bookmark->module()->name() : QString::null;
- mimeData->appendBookmark(moduleName, bookmark->key(), bookmark->description());
- }
+ if (m_bookmarksModel->isBookmark(widgetItem)) {
+ /* Take care of bookmarks which have no valid module any more, e.g.
+ if these were uninstalled: */
+ CSwordModuleInfo * const module =
+ m_bookmarksModel->module(widgetItem);
+ const QString moduleName = module ? module->name() : QString::null;
+ mimeData->appendBookmark(moduleName, m_bookmarksModel->key(widgetItem),
+ m_bookmarksModel->description(widgetItem));
}
}
return mimeData;
}
-void CBookmarkIndex::dragEnterEvent( QDragEnterEvent* event ) {
- setState(QAbstractItemView::DraggingState);
- QTreeWidget::dragEnterEvent(event);
- if (event->source() == this || event->mimeData()->hasFormat("BibleTime/Bookmark")) {
+void CBookmarkIndex::dragEnterEvent(QDragEnterEvent * event) {
+ if (event->mimeData()->hasFormat("BibleTime/Bookmark")) {
event->acceptProposedAction();
+ setState(DraggingState);
+ } else {
+ QAbstractItemView::dragEnterEvent(event);
}
}
-
-void CBookmarkIndex::dragMoveEvent( QDragMoveEvent* event ) {
- // do this first, otherwise the event may be ignored
- QTreeWidget::dragMoveEvent(event);
+void CBookmarkIndex::dragMoveEvent(QDragMoveEvent * event) {
+ // Do this first, otherwise the event may be ignored:
+ QTreeView::dragMoveEvent(event);
event->acceptProposedAction();
event->accept();
- // do this to paint the arrow
+ // Do this to paint the arrow:
m_dragMovementPosition = event->pos();
viewport()->update();
-
}
-void CBookmarkIndex::dragLeaveEvent( QDragLeaveEvent* ) {
- setState(QAbstractItemView::NoState); // not dragging anymore
- viewport()->update(); // clear the arrow
+void CBookmarkIndex::dragLeaveEvent(QDragLeaveEvent *) {
+ setState(QAbstractItemView::NoState); // Not dragging anymore
+ viewport()->update(); // Clear the arrow
}
+void CBookmarkIndex::paintEvent(QPaintEvent * event) {
+ // Do the normal painting first
+ QTreeView::paintEvent(event);
-void CBookmarkIndex::paintEvent(QPaintEvent* event) {
- namespace DU = util::directory;
+ // Don't paint the arrow if not dragging:
+ if (state() != QAbstractItemView::DraggingState)
+ return;
static QPixmap pix;
static int halfPixHeight;
@@ -255,467 +246,383 @@ void CBookmarkIndex::paintEvent(QPaintEvent* event) {
// Initialize the static variables, including the arrow pixmap
if (!arrowInitialized) {
arrowInitialized = true;
- int arrowSize = util::tool::mWidth(this, 1);
- QString fileName;
- if (DU::getIconDir().exists("pointing_arrow.svg")) {
- fileName = DU::getIconDir().filePath("pointing_arrow.svg");
- }
- else {
- if (DU::getIconDir().exists("pointing_arrow.png")) {
- fileName = DU::getIconDir().filePath("pointing_arrow.png");
- }
- else {
- qWarning() << "Picture file pointing_arrow.svg or .png not found!";
- }
- }
-
- pix = QPixmap(fileName);
- pix = pix.scaled(arrowSize, arrowSize, Qt::KeepAspectRatioByExpanding);
+ pix = BtIcons::instance().icon_pointing_arrow.pixmap(util::tool::mWidth(this, 1));
halfPixHeight = pix.height() / 2;
}
- // Do the normal painting first
- QTreeWidget::paintEvent(event);
-
- // Paint the arrow if the drag is going on
- if (QAbstractItemView::DraggingState == state()) {
- bool rtol = QApplication::isRightToLeft();
-
- QPainter painter(this->viewport());
- QTreeWidgetItem* item = itemAt(m_dragMovementPosition);
- bool isFolder = dynamic_cast<BtBookmarkFolder*>(item);
- bool isBookmark = dynamic_cast<BtBookmarkItem*>(item);
-
- // Find the place for the arrow
- QRect rect = visualItemRect(item);
- int xCoord = rtol ? rect.right() : rect.left();
- int yCoord;
- if (isFolder) {
- if (m_dragMovementPosition.y() > rect.bottom() - (2* rect.height() / 3) ) {
+ // Find the place for the arrow:
+ QModelIndex const index = indexAt(m_dragMovementPosition);
+ int xCoord, yCoord;
+ if (m_bookmarksModel->isBookmark(index)) {
+ QRect const rect = visualRect(index);
+ xCoord = QApplication::isRightToLeft() ? rect.right() : rect.left();
+ if (m_dragMovementPosition.y() > rect.bottom() - rect.height() / 2) {
+ yCoord = rect.bottom() - halfPixHeight; // bottom
+ } else {
+ yCoord = rect.top() - halfPixHeight - 1; // top
+ }
+ } else {
+ if (m_bookmarksModel->isFolder(index)) {
+ QRect const rect = visualRect(index);
+ if (m_dragMovementPosition.y()
+ > rect.bottom() - (2 * rect.height() / 3))
+ {
yCoord = rect.bottom() - halfPixHeight; // bottom
- xCoord = rtol ? (xCoord - indentation()) : (xCoord + indentation());
- }
- else {
+ xCoord = QApplication::isRightToLeft()
+ ? (rect.right() - indentation())
+ : (rect.left() + indentation());
+ } else {
yCoord = rect.top() - halfPixHeight - 1; // top
+ xCoord = QApplication::isRightToLeft()
+ ? rect.right()
+ : rect.left();
}
-
+ } else if (index.isValid()) { // the extra item
+ QRect const rect = visualRect(index);
+ xCoord = QApplication::isRightToLeft() ? rect.right() : rect.left();
+ yCoord = rect.top() - halfPixHeight - 1;
+ } else { // empty area
+ QRect const rect = visualRect(m_extraItem);
+ yCoord = rect.top() - halfPixHeight - 1;
+ xCoord = QApplication::isRightToLeft() ? rect.right() : rect.left();
}
- else {
- if (isBookmark) {
- if (m_dragMovementPosition.y() > rect.bottom() - rect.height() / 2) {
- yCoord = rect.bottom() - halfPixHeight; // bottom
- }
- else {
- yCoord = rect.top() - halfPixHeight - 1; // top
- }
- }
- else {
- if (item) { // the extra item
- yCoord = rect.top() - halfPixHeight - 1;
- }
- else { // empty area
- rect = visualItemRect(m_extraItem);
- yCoord = rect.top() - halfPixHeight - 1;
- xCoord = rtol ? rect.right() : rect.left();
- }
- }
- }
-
- painter.drawPixmap(xCoord, yCoord, pix);
}
+ QPainter{this->viewport()}.drawPixmap(xCoord, yCoord, pix);
}
-void CBookmarkIndex::dropEvent( QDropEvent* event ) {
-
- //setState(QAbstractItemView::NoState);
- // Try to prevent annoying timed autocollapsing. Remember to disconnect before return.
- QObject::connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*)));
- QTreeWidgetItem* item = itemAt(event->pos());
- QTreeWidgetItem* parentItem = 0;
+void CBookmarkIndex::dropEvent(QDropEvent * event) {
+ // Try to prevent annoying timed autocollapsing:
+ BT_CONNECT(this, SIGNAL(collapsed(QModelIndex const &)),
+ this, SLOT(expandAutoCollapsedItem(QModelIndex const &)));
+ BT_SCOPE_EXIT(
+ QObject::disconnect(
+ this, SIGNAL(collapsed(QModelIndex const &)),
+ this, SLOT(expandAutoCollapsedItem(QModelIndex const &)));
+ );
+ QModelIndex const index = indexAt(event->pos());
+ QModelIndex parentIndex;
int indexUnderParent = 0;
// Find the place where the drag is dropped
- if (item) {
- QRect rect = visualItemRect(item);
- bool isFolder = dynamic_cast<BtBookmarkFolder*>(item);
- bool isBookmark = dynamic_cast<BtBookmarkItem*>(item);
-
- if (isFolder) { // item is a folder
+ if (index.isValid()) {
+ if (m_bookmarksModel->isFolder(index)) {
+ QRect const rect = visualRect(index);
if (event->pos().y() > rect.bottom() - (2* rect.height() / 3) ) {
- parentItem = item;
+ parentIndex = index;
+ } else {
+ parentIndex = index.parent();
+ indexUnderParent = index.row(); // before the current folder
}
- else {
- parentItem = item->parent();
- if (!parentItem) {
- parentItem = invisibleRootItem();
- }
- indexUnderParent = parentItem->indexOfChild(item); // before the current folder
- }
- }
- else {
- if (isBookmark) { // item is a bookmark
- parentItem = item->parent();
- if (!parentItem) {
- parentItem = invisibleRootItem();
- }
- indexUnderParent = parentItem->indexOfChild(item); // before the current bookmark
- if (event->pos().y() > rect.bottom() - rect.height() / 2) {
+ } else {
+ if (m_bookmarksModel->isBookmark(index)) {
+ parentIndex = index.parent();
+ indexUnderParent = index.row(); // before the current bookmark
+ QRect const rect = visualRect(index);
+ if (event->pos().y() > rect.bottom() - rect.height() / 2)
indexUnderParent++; // after the current bookmark
- }
- }
- else { // item is the extra item
- parentItem = item->parent();
- if (!parentItem) {
- parentItem = invisibleRootItem();
- }
- indexUnderParent = parentItem->indexOfChild(item); // before the current bookmark
+ } else { // item is the extra item
+ parentIndex = index.parent();
+ indexUnderParent = index.row(); // before the current bookmark
}
}
-
- }
- else { // no item under event point: drop to the end
- parentItem = invisibleRootItem();
- indexUnderParent = parentItem->childCount() - 1;
- }
-
-
- if ( event->source() == this ) {
+ } else { // no item under event point: drop to the end
+ indexUnderParent = m_bookmarksModel->rowCount() - 1;
+ }
+
+ if (event->source() != this) {
+ // Take the bookmark data from the mime source
+ if (BTMimeData const * const mdata =
+ dynamic_cast<BTMimeData const *>(event->mimeData()))
+ {
+ //create the new bookmark
+ QString const moduleName(mdata->bookmark().module());
+ QString const keyText(mdata->bookmark().key());
+ QString const description(mdata->bookmark().description());
+ CSwordModuleInfo * minfo =
+ CSwordBackend::instance()->findModuleByName(moduleName);
+ BT_ASSERT(minfo);
+
+ /// \todo add title
+ m_bookmarksModel->addBookmark(indexUnderParent,
+ parentIndex,
+ *minfo,
+ keyText,
+ description);
+ }
+ } else {
event->accept();
bool bookmarksOnly = true;
bool targetIncluded = false;
bool moreThanOneFolder = false;
- QList<QTreeWidgetItem*> newItems = addItemsToDropTree(parentItem, bookmarksOnly, targetIncluded, moreThanOneFolder);
+ QModelIndexList const list = selectedIndexes();
+ QModelIndexList newList;
+
+ Q_FOREACH(QModelIndex const & index, list) {
+ if (m_bookmarksModel->isFolder(index)) {
+ bookmarksOnly = false;
+ // Only one item allowed if a folder is selected:
+ if (list.count() > 1) {
+ moreThanOneFolder = true;
+ break;
+ }
+ // Dropping to self or descendand not allowed:
+ if (m_bookmarksModel->hasDescendant(index, parentIndex)) {
+ targetIncluded = true;
+ break;
+ }
+ } else {
+ newList.append(index);
+ }
+ }
+
+ if (!bookmarksOnly && list.count() == 1) {
+ newList.append(list[0]); // list contain only one folder item
+ } else if (!bookmarksOnly && list.count() > 1) {
+ moreThanOneFolder = true; // wrong amount of items
+ }
if (moreThanOneFolder) {
QToolTip::showText(QCursor::pos(), tr("Can drop only bookmarks or one folder"));
- QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*)));
return;
}
if (targetIncluded) {
QToolTip::showText(QCursor::pos(), tr("Can't drop folder into the folder itself or into its subfolder"));
- QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*)));
return;
}
+
// Ask whether to copy or move with a popup menu
+ std::unique_ptr<QMenu> dropPopupMenu{new QMenu{this}};
+ dropPopupMenu->setEnabled(!newList.empty());
+ QAction * const copy = dropPopupMenu->addAction(tr("Copy"));
+ QAction * const move = dropPopupMenu->addAction(tr("Move"));
+ QAction * const dropAction = dropPopupMenu->exec(QCursor::pos());
+ dropPopupMenu.reset();
- QMenu* dropPopupMenu = new QMenu(this);
- QAction* copy = dropPopupMenu->addAction(tr("Copy"));
- QAction* move = dropPopupMenu->addAction(tr("Move"));
- QAction* dropAction = dropPopupMenu->exec(QCursor::pos());
if (dropAction == copy) {
- parentItem->insertChildren(indexUnderParent, newItems);
- // Need this here because the "move" case goes through
- // "deleteEntries" which has a save call.
- needToSaveBookmarks();
- }
- else {
- if (dropAction == move) {
- parentItem->insertChildren(indexUnderParent, newItems);
- deleteEntries(false);
- }
- else {
- QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)),
- this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*)));
- return; // user canceled
- }
+ m_bookmarksModel->copyItems(indexUnderParent, parentIndex, newList);
+ } else if (dropAction == move) {
+ m_bookmarksModel->copyItems(indexUnderParent, parentIndex, newList);
+ deleteEntries();
+ } else { // user canceled
+ return;
}
}
- else {
- createBookmarkFromDrop(event, parentItem, indexUnderParent);
- }
- QObject::disconnect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(expandAutoCollapsedItem(QTreeWidgetItem*)));
setState(QAbstractItemView::NoState);
}
-
-void CBookmarkIndex::createBookmarkFromDrop(QDropEvent* event, QTreeWidgetItem* parentItem, int indexInParent) {
- //take the bookmark data from the mime source
- const BTMimeData* mdata = dynamic_cast<const BTMimeData*>(event->mimeData());
- if (mdata) {
- //create the new bookmark
- QString moduleName = mdata->bookmark().module();
- QString keyText = mdata->bookmark().key();
- QString description = mdata->bookmark().description();
- CSwordModuleInfo *minfo = CSwordBackend::instance()->findModuleByName(moduleName);
- QString title; /// \todo
-
- QTreeWidgetItem* newItem = new BtBookmarkItem(minfo, keyText, description, title);
- // connect(newItem, SIGNAL(bookmarkModified()), this, SLOT(needToSaveBookmarks()) );
- parentItem->insertChild(indexInParent, newItem);
-
- needToSaveBookmarks();
+bool CBookmarkIndex::enableAction(QModelIndex const & index,
+ CBookmarkIndex::MenuAction const type) const
+{
+ switch (type) {
+ case NewFolder:
+ case ChangeFolder:
+ case SortFolderBookmarks:
+ case ImportBookmarks:
+ case ExportBookmarks:
+ return m_bookmarksModel->isFolder(index);
+ case DeleteEntries:
+ return true;
+ case PrintBookmarks:
+ return hasBookmarksRecursively(QModelIndexList{} << index);
+ case EditBookmark:
+ return m_bookmarksModel->isBookmark(index);
+ default:
+ return false;
}
}
-
-/** Load the tree from file */
-void CBookmarkIndex::initTree() {
- BtBookmarkLoader loader;
- addTopLevelItems(loader.loadTree());
-
- // add the invisible extra item at the end
- m_extraItem = new QTreeWidgetItem();
- m_extraItem->setFlags(Qt::ItemIsDropEnabled);
- addTopLevelItem(m_extraItem);
-}
-
-void CBookmarkIndex::slotItemEntered(QTreeWidgetItem* item, int) {
- if (item == m_extraItem) {
- m_extraItem->setText(0, tr("Drag references from text views to this view"));
- }
- else {
- m_extraItem->setText(0, QString::null);
+bool CBookmarkIndex::hasBookmarksRecursively(QModelIndexList items) const {
+ while (!items.empty()) {
+ QModelIndex const index = items.takeFirst();
+ if (m_bookmarksModel->isBookmark(index))
+ return true;
+ if (m_bookmarksModel->isFolder(index)) {
+ int const numChildren = m_bookmarksModel->rowCount(index);
+ for (int i = 0; i < numChildren; i++)
+ items.append(index.child(i, 0));
+ }
}
+ return false;
}
+void CBookmarkIndex::showExtraItem() {
+ model()->setData(m_extraItem,
+ tr("Drag references from text views to this view"));
+}
-/** Returns the correct QAction object for the given type of action. */
-QAction* CBookmarkIndex::action( BtBookmarkItemBase::MenuAction type ) const {
- switch (type) {
- case BtBookmarkItemBase::NewFolder:
- return m_actions.newFolder;
- case BtBookmarkItemBase::ChangeFolder:
- return m_actions.changeFolder;
-
- case BtBookmarkItemBase::EditBookmark:
- return m_actions.editBookmark;
- case BtBookmarkItemBase::SortFolderBookmarks:
- return m_actions.sortFolderBookmarks;
- case BtBookmarkItemBase::SortAllBookmarks:
- return m_actions.sortAllBookmarks;
- case BtBookmarkItemBase::ImportBookmarks:
- return m_actions.importBookmarks;
- case BtBookmarkItemBase::ExportBookmarks:
- return m_actions.exportBookmarks;
- case BtBookmarkItemBase::PrintBookmarks:
- return m_actions.printBookmarks;
-
- case BtBookmarkItemBase::DeleteEntries:
- return m_actions.deleteEntries;
+void CBookmarkIndex::hideExtraItem()
+{ model()->setData(m_extraItem, QVariant()); }
- default:
- return 0;
- }
+void CBookmarkIndex::leaveEvent(QEvent * event) {
+ showExtraItem();
+ update();
+ QTreeView::leaveEvent(event);
}
/** Shows the context menu at the given position. */
-void CBookmarkIndex::contextMenu(const QPoint& p) {
- //setup menu entries depending on current selection
- QTreeWidgetItem* i = itemAt(p);
- QList<QTreeWidgetItem *> items = selectedItems();
- //The item which was clicked may not be selected
- if (i && !items.contains(i) && i != m_extraItem)
- items.append(i);
-
- if (items.isEmpty()) {
- //special handling for no selection
- BtBookmarkItemBase::MenuAction actionType;
- for (int index = BtBookmarkItemBase::ActionBegin; index <= BtBookmarkItemBase::ActionEnd; ++index) {
- actionType = static_cast<BtBookmarkItemBase::MenuAction>(index);
- if (QAction* a = action(actionType)) {
- switch (index) {
- //case BtBookmarkItemBase::ExportBookmarks:
- //case BtBookmarkItemBase::ImportBookmarks:
- case BtBookmarkItemBase::NewFolder:
- case BtBookmarkItemBase::SortAllBookmarks:
- //case BtBookmarkItemBase::PrintBookmarks:
- a->setEnabled(true);
- break;
- default:
- a->setEnabled(false);
- }
- }
- }
- }
- else if (items.count() == 1) {
- //special handling for one selected item
-
- BtBookmarkItemBase* item = dynamic_cast<BtBookmarkItemBase*>(items.at(0));
- BtBookmarkItemBase::MenuAction actionType;
- for (int index = BtBookmarkItemBase::ActionBegin; index <= BtBookmarkItemBase::ActionEnd; ++index) {
- actionType = static_cast<BtBookmarkItemBase::MenuAction>(index);
- if (QAction* a = action(actionType))
- a->setEnabled( item->enableAction(actionType) );
- }
- }
- else {
- //first disable all actions
- BtBookmarkItemBase::MenuAction actionType;
- for (int index = BtBookmarkItemBase::ActionBegin; index <= BtBookmarkItemBase::ActionEnd; ++index) {
- actionType = static_cast<BtBookmarkItemBase::MenuAction>(index);
- if (QAction* a = action(actionType))
- a->setEnabled(false);
- }
- //enable the menu items depending on the types of the selected items.
- for (int index = BtBookmarkItemBase::ActionBegin; index <= BtBookmarkItemBase::ActionEnd; ++index) {
- actionType = static_cast<BtBookmarkItemBase::MenuAction>(index);
- bool enableAction = isMultiAction(actionType);
- QListIterator<QTreeWidgetItem *> it(items);
- while (it.hasNext()) {
- BtBookmarkItemBase* i = dynamic_cast<BtBookmarkItemBase*>(it.next());
- enableAction = enableAction && i->enableAction(actionType);
- }
- if (enableAction) {
- QAction* a = action(actionType) ;
- if (i && a)
- a->setEnabled(enableAction);
- }
- }
+void CBookmarkIndex::contextMenu(QPoint const & p) {
+ // Enable actions based on the selected items (if any):
+ QModelIndex const i = indexAt(p);
+ QModelIndexList const items = selectedIndexes();
+ if (items.isEmpty()) { // Special handling for no selection:
+ for (int index = ActionBegin; index < ActionEnd; ++index)
+ m_actions[index]->setEnabled((index == NewFolder)
+ || (index == SortAllBookmarks));
+ } else if (items.count() == 1) { // Special handling for one selected item:
+ for (int index = ActionBegin; index < ActionEnd; ++index)
+ m_actions[index]->setEnabled(
+ enableAction(items.at(0), static_cast<MenuAction>(index)));
+ } else if (!i.isValid()) { // Disable all actions for invalid index:
+ for (int index = ActionBegin; index < ActionEnd; ++index)
+ m_actions[index]->setEnabled(false);
+ } else { // Enable actions depending on the the selected items:
+ for (int index = ActionBegin; index < ActionEnd; ++index)
+ m_actions[index]->setEnabled(
+ (index == DeleteEntries)
+ || ((index == PrintBookmarks)
+ && hasBookmarksRecursively(items)));
}
- //finally, open the popup
m_popup->exec(mapToGlobal(p));
}
/** Adds a new subfolder to the current item. */
void CBookmarkIndex::createNewFolder() {
- QList<QTreeWidgetItem*> selected = selectedItems();
- if (selected.count() > 0) {
- BtBookmarkFolder* i = dynamic_cast<BtBookmarkFolder*>(currentItem());
- if (i) {
- i->newSubFolder();
- }
- }
- else {
- // create a top level folder
- BtBookmarkFolder* newFolder = new BtBookmarkFolder(tr("New folder"));
- //parentFolder->addChild(newFolder);
- insertTopLevelItem(topLevelItemCount() - 1, newFolder);
- newFolder->update();
- newFolder->rename();
+ if (!selectedIndexes().empty()) {
+ if (m_bookmarksModel->isFolder(currentIndex()))
+ setCurrentIndex(m_bookmarksModel->addFolder(
+ m_bookmarksModel->rowCount(currentIndex()),
+ currentIndex()));
+ } else { // create a top level folder
+ setCurrentIndex(
+ m_bookmarksModel->addFolder(m_bookmarksModel->rowCount() - 1,
+ QModelIndex{}));
}
- needToSaveBookmarks();
}
/** Opens a dialog to change the current folder. */
void CBookmarkIndex::changeFolder() {
- BtBookmarkFolder* i = dynamic_cast<BtBookmarkFolder*>(currentItem());
- Q_ASSERT(i);
- if (i) {
- i->rename();
- }
+ BT_ASSERT(m_bookmarksModel->isFolder(currentIndex()));
+ edit(currentIndex());
}
/** Edits the current bookmark. */
void CBookmarkIndex::editBookmark() {
- BtBookmarkItem* i = dynamic_cast<BtBookmarkItem*>(currentItem());
- Q_ASSERT(i);
-
- if (i) {
- i->rename();
+ QModelIndex const index = currentIndex();
+ BT_ASSERT(m_bookmarksModel->isBookmark(index));
+ CSwordModuleInfo * const module = m_bookmarksModel->module(index);
+ BtEditBookmarkDialog d{
+ QString::fromLatin1("%1 (%2)").arg(m_bookmarksModel->key(index))
+ .arg(module
+ ? module->name()
+ : QObject::tr("unknown")),
+ index.data().toString(),
+ m_bookmarksModel->description(index),
+ this};
+ if (d.exec() == QDialog::Accepted) {
+ m_bookmarksModel->setData(index, d.titleText());
+ m_bookmarksModel->setDescription(index, d.descriptionText());
}
}
/** Sorts the current folder bookmarks. */
void CBookmarkIndex::sortFolderBookmarks() {
- BtBookmarkFolder* i = dynamic_cast<BtBookmarkFolder*>(currentItem());
- Q_ASSERT(i);
-
- if (i) {
- i->sortChildren(0, Qt::AscendingOrder);
- }
+ BT_ASSERT(m_bookmarksModel->isFolder(currentIndex()));
+ m_bookmarksModel->sortItems(currentIndex());
}
/** Sorts all bookmarks. */
void CBookmarkIndex::sortAllBookmarks() {
- sortItems(0, Qt::AscendingOrder);
- int index = indexOfTopLevelItem(m_extraItem);
- if (index >= 0) {
- QTreeWidgetItem* item = takeTopLevelItem(index);
- if (item != 0) {
- addTopLevelItem(m_extraItem);
- }
+ m_bookmarksModel->sortItems();
+ if (m_extraItem.row() != m_bookmarksModel->rowCount() - 1) {
+ m_bookmarksModel->removeRow(m_extraItem.row(), m_extraItem.parent());
+ if (m_bookmarksModel->insertRows(m_bookmarksModel->rowCount(), 1))
+ m_extraItem = m_bookmarksModel->index(m_bookmarksModel->rowCount() - 1, 0);
}
}
/** Exports the bookmarks being in the selected folder. */
void CBookmarkIndex::exportBookmarks() {
- BtBookmarkFolder* i = dynamic_cast<BtBookmarkFolder*>(currentItem());
- Q_ASSERT(i);
-
- if (i) {
- i->exportBookmarks();
- }
+ BT_ASSERT(m_bookmarksModel->isFolder(currentIndex()));
+ QString const fileName =
+ QFileDialog::getSaveFileName(
+ nullptr,
+ QObject::tr("Export Bookmarks"),
+ "",
+ QObject::tr("BibleTime bookmark files") + QString(" (*.btb);;")
+ + QObject::tr("All files") + QString(" (*.*)"));
+ if (!fileName.isEmpty())
+ m_bookmarksModel->save(fileName, currentIndex());
}
/** Import bookmarks from a file and add them to the selected folder. */
void CBookmarkIndex::importBookmarks() {
- BtBookmarkFolder* i = dynamic_cast<BtBookmarkFolder*>(currentItem());
- Q_ASSERT(i);
-
- if (i) {
- i->importBookmarks();
- }
- needToSaveBookmarks();
+ BT_ASSERT(m_bookmarksModel->isFolder(currentIndex()));
+ QString const fileName =
+ QFileDialog::getOpenFileName(
+ nullptr,
+ QObject::tr("Import bookmarks"),
+ "",
+ QObject::tr("BibleTime bookmark files")
+ + QString(" (*.btb);;")
+ + QObject::tr("All files") + QString(" (*.*)"));
+ if (!fileName.isEmpty())
+ m_bookmarksModel->load(fileName, currentIndex());
}
/** Prints the selected bookmarks. */
void CBookmarkIndex::printBookmarks() {
- Printing::CPrinter::KeyTree tree;
- Printing::CPrinter::KeyTreeItem::Settings settings;
- settings.keyRenderingFace = Printing::CPrinter::KeyTreeItem::Settings::CompleteShort;
-
- QList<QTreeWidgetItem*> items;
- BtBookmarkFolder* bf = dynamic_cast<BtBookmarkFolder*>(currentItem());
-
- if (bf) {
- items = bf->getChildList();
- }
- else {
- items = selectedItems();
- }
-
- //create a tree of keytreeitems using the bookmark hierarchy.
- QListIterator<QTreeWidgetItem*> it(items);
- while (it.hasNext()) {
- BtBookmarkItem* i = dynamic_cast<BtBookmarkItem*>(it.next());
- if (i) {
- qDebug() << "printBookmarks: add to list" << i->key();
- tree.append( new Printing::CPrinter::KeyTreeItem( i->key(), i->module(), settings ) );
+ BT_ASSERT(hasBookmarksRecursively(selectedIndexes()));
+ BtPrinter::KeyTree tree;
+ {
+ BtPrinter::KeyTreeItem::Settings const settings{
+ false,
+ BtPrinter::KeyTreeItem::Settings::CompleteShort};
+ QModelIndexList items(selectedIndexes());
+ while (!items.empty()) {
+ QModelIndex const index(items.takeFirst());
+ if (m_bookmarksModel->isBookmark(index)) {
+ tree.append(
+ new BtPrinter::KeyTreeItem{
+ m_bookmarksModel->key(index),
+ m_bookmarksModel->module(index),
+ settings});
+ } else if (m_bookmarksModel->isFolder(index)) {
+ int const numChildren = m_bookmarksModel->rowCount(index);
+ for (int i = 0; i < numChildren; i++)
+ items.append(index.child(i, 0));
+ }
}
}
+ BT_ASSERT(!tree.isEmpty());
- if (items.isEmpty()) {
- qWarning("Tried to print empty bookmark list.");
- return;
- }
- QSharedPointer<Printing::CPrinter> printer(
- new Printing::CPrinter( this, btConfig().getDisplayOptions(), btConfig().getFilterOptions() )
- );
- printer->printKeyTree(tree);
+ BtPrinter{btConfig().getDisplayOptions(),
+ btConfig().getFilterOptions(),
+ this}.printKeyTree(tree);
}
-/** Deletes the selected entries. */
-void CBookmarkIndex::deleteEntries(bool confirm) {
- if (confirm) {
- if (!selectedItems().count()) {
- BtBookmarkItemBase* f = dynamic_cast<BtBookmarkItemBase*>(currentItem());
- if (f) {
- currentItem()->setSelected(true);
- }
- else {
- return;
- }
- }
+void CBookmarkIndex::confirmDeleteEntries() {
+ if (message::showQuestion(
+ this,
+ tr("Delete Items"),
+ tr("Do you really want to delete the selected items and folders?"),
+ QMessageBox::Yes | QMessageBox::No,
+ QMessageBox::No) == QMessageBox::Yes)
+ deleteEntries();
+}
- if (message::showQuestion(this, tr("Delete Items"),
- tr("Do you really want to delete the selected items and child-items?"),
- QMessageBox::Yes | QMessageBox::No, QMessageBox::No )
- != QMessageBox::Yes) {
- return;
- }
- }
+void CBookmarkIndex::deleteEntries() {
+ /* We need to use QPersistentModelIndex because after removeRows QModelIndex
+ will be invalidated. Need to delete per index because selected indexes
+ might be under different parents. */
+ QList<QPersistentModelIndex> list;
+ Q_FOREACH(QModelIndex const & i, selectedIndexes())
+ list.append(i);
- while (selectedItems().size() > 0) {
- delete selectedItems().at(0); // deleting all does not work because it may cause double deletion
- }
- // Save the bookmarks. One way would be to signal that the bookmarks have
- // changed emit a signal so that a number of changes may be saved at once.
- // Another way is to simply save the bookmarks after each change, which can
- // be inefficient.
- needToSaveBookmarks();
+ Q_FOREACH(QModelIndex const & i, list)
+ model()->removeRows(i.row(), 1, i.parent());
}
@@ -727,164 +634,59 @@ a BibleTime mimedata object. It can be dragged and dropped to a text view or som
The internal drag is handled differently, it doesn't use the mimedata (see dropEvent()).
*/
void CBookmarkIndex::startDrag(Qt::DropActions) {
-
- QMimeData* mData = dragObject(); // create the data which can be used in other widgets
- QDrag* drag = new QDrag(this);
+ // Create the data which can be used in other widgets:
+ QMimeData * const mData = dragObject();
+ QDrag * const drag = new QDrag{this};
drag->setMimeData(mData);
drag->exec();
viewport()->update(); // because of the arrow
}
-
-
-
-
-
-/* Returns true if more than one entry is supported by this action type. Returns false for actions which support only one entry, e.g. about module etc. */
-bool CBookmarkIndex::isMultiAction( const BtBookmarkItemBase::MenuAction type ) const {
- switch (type) {
- case BtBookmarkItemBase::NewFolder:
- return false;
- case BtBookmarkItemBase::ChangeFolder:
- return false;
-
- case BtBookmarkItemBase::EditBookmark:
- return false;
- case BtBookmarkItemBase::SortFolderBookmarks:
- return false;
- case BtBookmarkItemBase::SortAllBookmarks:
- return false;
- case BtBookmarkItemBase::ImportBookmarks:
- return false;
- case BtBookmarkItemBase::ExportBookmarks:
- return false;
- case BtBookmarkItemBase::PrintBookmarks:
- return true;
-
- case BtBookmarkItemBase::DeleteEntries:
- return true;
- }
-
- return false;
-}
-
-/* Saves the bookmarks to the default bookmarks file. */
-void CBookmarkIndex::saveBookmarks() {
- BtBookmarkLoader loader;
- loader.saveTreeFromRootItem(invisibleRootItem());
-}
-
-void CBookmarkIndex::mouseMoveEvent(QMouseEvent* event) {
-
- // Restart the mag timer if we have moved to another item and shift was not pressed.
- QTreeWidgetItem* itemUnderPointer = itemAt(event->pos());
- if (itemUnderPointer && (itemUnderPointer != m_previousEventItem) ) {
- if ( !(event->modifiers() & Qt::ShiftModifier)) {
- m_magTimer.start(); // see the ctor for the timer properties
- }
- }
+void CBookmarkIndex::mouseMoveEvent(QMouseEvent * event) {
+ /* Restart the mag timer if we have moved to another item and shift was not
+ pressed: */
+ QModelIndex const itemUnderPointer = indexAt(event->pos());
+ if (itemUnderPointer.isValid()
+ && (itemUnderPointer != m_previousEventItem)
+ && !(event->modifiers() & Qt::ShiftModifier))
+ m_magTimer.start();
m_previousEventItem = itemUnderPointer;
- // Clear the extra item text unless we are on top of it
- if ( (itemUnderPointer != m_extraItem) && !m_extraItem->text(0).isNull()) {
- m_extraItem->setText(0, QString::null);
+ if (!itemUnderPointer.isValid() || itemUnderPointer == m_extraItem) {
+ showExtraItem();
+ } else {
+ hideExtraItem();
}
+ update();
- QTreeWidget::mouseMoveEvent(event);
+ QTreeView::mouseMoveEvent(event);
}
void CBookmarkIndex::magTimeout() {
- QTreeWidgetItem* itemUnderPointer = 0;
- if (underMouse()) {
- itemUnderPointer = itemAt(mapFromGlobal(QCursor::pos()));
- }
- // if the mouse pointer have been over the same item since the timer was started
- if (itemUnderPointer && (m_previousEventItem == itemUnderPointer)) {
- BtBookmarkItem* bitem = dynamic_cast<BtBookmarkItem*>(itemUnderPointer);
- if (bitem) {
- // Update the mag
- if (bitem->module()) {
- (BibleTime::instance()->infoDisplay())->setInfo(
- InfoDisplay::CInfoDisplay::CrossReference,
- bitem->module()->name() + ":" + bitem->key()
- );
- }
- else {
- (BibleTime::instance()->infoDisplay())->setInfo(InfoDisplay::CInfoDisplay::Text, tr("The work to which the bookmark points to is not installed."));
- }
+ if (!underMouse())
+ return;
+ /* Update the Mag only if the mouse pointer have been over the same item
+ since the timer was started. */
+ QModelIndex const itemUnderPointer{indexAt(mapFromGlobal(QCursor::pos()))};
+ if (itemUnderPointer.isValid()
+ && m_previousEventItem == itemUnderPointer
+ && m_bookmarksModel->isBookmark(itemUnderPointer))
+ {
+ BT_ASSERT(BibleTime::instance()->infoDisplay());
+ InfoDisplay::CInfoDisplay & infoDisplay =
+ *(BibleTime::instance()->infoDisplay());
+ if (CSwordModuleInfo const * const module =
+ m_bookmarksModel->module(itemUnderPointer))
+ {
+ infoDisplay.setInfo(
+ Rendering::CrossReference,
+ module->name() + ":" + m_bookmarksModel->key(itemUnderPointer));
+ } else {
+ infoDisplay.setInfo(Rendering::Text,
+ tr("The work to which the bookmark points to "
+ "is not installed."));
}
}
}
-
-/*
-Creates a list of new items based on the current selection.
-If there are only bookmarks in the selection they are all included.
-If there is one folder it's included as a deep copy.
-Sets bookmarksOnly=false if it finds a folder.
-Sets targetIncluded=true if the target is in the list.
-Sets moreThanOneFolder=true if selection includes one folder and something more.
-If moreThanOneFolder or targetIncluded is detected the creation of list is stopped
-and the list is incomplete.
-*/
-QList<QTreeWidgetItem*> CBookmarkIndex::addItemsToDropTree(
- QTreeWidgetItem* target, bool& bookmarksOnly, bool& targetIncluded, bool& moreThanOneFolder) {
- QList<QTreeWidgetItem*> selectedList = selectedItems();
- QList<QTreeWidgetItem*> newList;
-
- foreach(QTreeWidgetItem* item, selectedList) {
- if ( BtBookmarkFolder* folder = dynamic_cast<BtBookmarkFolder*>(item)) {
- bookmarksOnly = false;
- if (selectedList.count() > 1) { // only one item allowed if a folder is selected
- moreThanOneFolder = true;
- break;
- }
- if (folder->hasDescendant(target)) { // dropping to self or descendand not allowed
- targetIncluded = true;
- break;
- }
- }
- else {
- newList.append(new BtBookmarkItem( *(dynamic_cast<BtBookmarkItem*>(item)) ));
- }
- }
- if (!bookmarksOnly && selectedList.count() == 1) {
- BtBookmarkFolder* folder = dynamic_cast<BtBookmarkFolder*>(selectedList.value(0));
- BtBookmarkFolder* copy = folder->deepCopy();
- newList.append(copy);
- }
- if (!bookmarksOnly && selectedList.count() > 1) {
- // wrong amount of items
- moreThanOneFolder = true;
- }
- return newList;
-}
-
-/// Bookmark saving code. To avoid many saves during a short period of time,
-/// bookmark modification is first noted. Then, after a wait (1.5s), if no more
-/// modifications are made, the bookmarks are saved. The timer is reset when a
-/// new modification is made. The timer bookmarkSaveTimer is set to be oneshot.
-void CBookmarkIndex::needToSaveBookmarks() {
- m_bookmarksModified = true;
- bookmarkSaveTimer.start(1500); // Only save after 1.5s.
-}
-void CBookmarkIndex::needToSaveBookmarks(QTreeWidgetItem* treeItem) {
- // Need to test whether the item that changed is not just a display item,
- // but actually a folder or bookmark.
- BtBookmarkItemBase* bookmark = dynamic_cast<BtBookmarkItemBase*>(treeItem);
- if (bookmark) {
- m_bookmarksModified = true;
- bookmarkSaveTimer.start(1500); // Only save after 1.5s.
- }
-}
-
-/// Considers saving bookmarks only if they have been modified. This procedure
-/// should be called by the qtimer bookmarkTimer.
-void CBookmarkIndex::considerSavingBookmarks() {
- if (m_bookmarksModified) {
- saveBookmarks();
- m_bookmarksModified = false;
- }
-}
-
diff --git a/src/frontend/bookmarks/cbookmarkindex.h b/src/frontend/bookmarks/cbookmarkindex.h
index df4a1c6..4ae3c0e 100644
--- a/src/frontend/bookmarks/cbookmarkindex.h
+++ b/src/frontend/bookmarks/cbookmarkindex.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,18 +12,13 @@
#ifndef CBOOKMARKINDEX_H
#define CBOOKMARKINDEX_H
-#include "frontend/bookmarks/btbookmarkitembase.h"
-
-#include <QList>
#include <QTimer>
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
#include <QToolTip>
-#include "frontend/displaywindow/cdisplaywindow.h"
+#include <QTreeView>
class BTMimeData;
-class CSearchDialog;
+class BtBookmarksModel;
class CSwordModuleInfo;
class QAction;
class QDragLeaveEvent;
@@ -32,185 +27,128 @@ class QDropEvent;
class QMenu;
class QMouseEvent;
class QPaintEvent;
-class QWidget;
/**
* The widget which manages all bookmarks.
-* @author The BibleTime team
+*
+* \author The BibleTime team
*/
-class CBookmarkIndex : public QTreeWidget {
- Q_OBJECT
- public:
- CBookmarkIndex(QWidget *parent);
- virtual ~CBookmarkIndex();
-
- void initTree();
-
- /**
- * Saves the bookmarks to disk
- */
- void saveBookmarks();
-
- signals:
- /**
- * Is emitted when a module should be opened,
- */
- void createReadDisplayWindow( QList<CSwordModuleInfo*>, const QString& );
-
- public slots:
-
- /**
- * Indicates a need to save the bookmarks.
- * This is needed to provide a way for a bookmarkitem stored in the
- * treeWidget to inform us that it has been modified, namely its
- * description text. It only sets a dirty-bit so we don't execute many
- * consecutive saves.
- */
- void needToSaveBookmarks();
- void needToSaveBookmarks(QTreeWidgetItem* treeItem);
-
-
- protected: // Protected methods
-
- /** A hack to get the modifiers. */
- virtual void mouseReleaseEvent(QMouseEvent* event);
+class CBookmarkIndex: public QTreeView {
- /** Needed to paint an drag pointer arrow. */
- virtual void paintEvent(QPaintEvent* event);
+ Q_OBJECT
- /** Initialize the SIGNAL<->SLOT connections. */
- void initConnections();
+public: /* Types: */
- /** Returns the drag object for the current selection. */
- virtual QMimeData* dragObject();
+ enum MenuAction {
+ NewFolder = 0,
+ ChangeFolder,
- /**
- * D'n'd methods are reimplementations from QTreeWidget or its ancestors.
- * In these we handle creating, moving and copying bookmarks with d'n'd.
- */
- virtual void dragEnterEvent( QDragEnterEvent* event );
- virtual void dragMoveEvent( QDragMoveEvent* event );
- virtual void dropEvent( QDropEvent* event );
- virtual void dragLeaveEvent( QDragLeaveEvent* event );
+ EditBookmark,
+ SortFolderBookmarks,
+ SortAllBookmarks,
+ ImportBookmarks,
+ ExportBookmarks,
+ PrintBookmarks,
- /** Returns the correct action object for the given type of action. */
- QAction* action( BtBookmarkItemBase::MenuAction type ) const;
+ DeleteEntries,
- /** Reimplementation from QAbstractItemView. Takes care of movable items. */
- virtual void startDrag(Qt::DropActions supportedActions);
+ ActionCount,
+ ActionBegin = NewFolder,
+ ActionEnd = ActionCount
+ };
+public: /* Methods: */
- /** Handle mouse moving (mag updates) */
- virtual void mouseMoveEvent(QMouseEvent* event);
+ CBookmarkIndex(QWidget * const parent = nullptr);
+signals:
- protected slots:
+ /** \brief Emitted when a module should be opened. */
+ void createReadDisplayWindow(QList<CSwordModuleInfo *>, QString const &);
- /** Prevents annoying folder collapsing while dropping. */
- void expandAutoCollapsedItem(QTreeWidgetItem* i) {
- expandItem(i);
- }
+protected: /* Methods: */
- /** Is called when an item was clicked or activated. */
- void slotExecuted( QTreeWidgetItem* );
+ QMimeData * dragObject();
- /** Shows the context menu at the given position. */
- void contextMenu(const QPoint&);
+ void mouseReleaseEvent(QMouseEvent * event) override;
+ void paintEvent(QPaintEvent * event) override;
+ void dragEnterEvent(QDragEnterEvent * event) override;
+ void dragMoveEvent(QDragMoveEvent * event) override;
+ void dropEvent(QDropEvent * event) override;
+ void dragLeaveEvent(QDragLeaveEvent * event) override;
+ void startDrag(Qt::DropActions supportedActions) override;
+ void mouseMoveEvent(QMouseEvent * event) override;
+ void leaveEvent(QEvent * event) override;
- /** Adds a new subfolder to the current item. */
- void createNewFolder();
+protected slots:
- /** Opens a dialog to change the current folder. */
- void changeFolder();
+ /** Prevents annoying folder collapsing while dropping. */
+ void expandAutoCollapsedItem(QModelIndex const & index) { expand(index); }
- /** Exports the bookmarks from the selected folder. */
- void exportBookmarks();
+ /** Is called when an item was clicked or activated. */
+ void slotExecuted(QModelIndex const & index);
- /** Changes the current bookmark. */
- void editBookmark();
+ /** Shows the context menu at the given position. */
+ void contextMenu(QPoint const & p);
- /** Sorts the current folder bookmarks. */
- void sortFolderBookmarks();
+ /** Adds a new subfolder to the current item. */
+ void createNewFolder();
- /** Sorts all bookmarks. */
- void sortAllBookmarks();
+ /** Opens a dialog to change the current folder. */
+ void changeFolder();
- /** Helps with the extra item. */
- void slotItemEntered(QTreeWidgetItem*, int);
+ /** Exports the bookmarks from the selected folder. */
+ void exportBookmarks();
- /** Import bookmarks from a file and add them to the selected folder. */
- void importBookmarks();
+ /** Changes the current bookmark. */
+ void editBookmark();
- /** Deletes the selected entries. */
- void deleteEntries(bool confirm = true);
+ /** Sorts the current folder bookmarks. */
+ void sortFolderBookmarks();
- /** Prints the selected bookmarks. */
- void printBookmarks();
+ /** Sorts all bookmarks. */
+ void sortAllBookmarks();
- /** Slot for the mag update timer. */
- void magTimeout();
+ /** Import bookmarks from a file and add them to the selected folder. */
+ void importBookmarks();
- private:
+ /** Deletes the selected entries after user confirmation. */
+ void confirmDeleteEntries();
- /** Initializes the view. */
- void initView();
+ /** Deletes the selected entries. */
+ void deleteEntries();
- /** Convenience function for creating a new action. */
- QAction* newQAction(const QString& text, const QString& pix, int shortcut, const QObject* receiver, const char* slot, QObject* parent);
+ /** Prints the selected bookmarks. */
+ void printBookmarks();
- /**
- * Returns true if more than one entry is supported by this action type.
- * Returns false for actions which support only one entry.
- */
- bool isMultiAction( const BtBookmarkItemBase::MenuAction type ) const;
+ /** Slot for the mag update timer. */
+ void magTimeout();
- /** A helper function for d'n'd which creates a new bookmark item when drop happens. */
- void createBookmarkFromDrop(QDropEvent* event, QTreeWidgetItem* parentItem, int indexInParent);
+private: /* Methods: */
- /**
- * Returns a list of new items created from the selection.
- * Sets flags which indicate whether the selection was legal for dropping.
- */
- QList<QTreeWidgetItem*> addItemsToDropTree(QTreeWidgetItem* target, bool& bookmarksOnly, bool& targetIncluded, bool& moreThanOneFolder);
+ bool enableAction(QModelIndex const & index,
+ MenuAction const type) const;
- struct Actions {
- QAction* newFolder;
- QAction* changeFolder;
+ bool hasBookmarksRecursively(QModelIndexList selected) const;
- QAction* editBookmark;
- QAction* sortFolderBookmarks;
- QAction* sortAllBookmarks;
- QAction* importBookmarks;
- QAction* exportBookmarks;
- QAction* printBookmarks;
+ void showExtraItem();
+ void hideExtraItem();
- QAction* deleteEntries;
- }
- m_actions;
+private: /* Fields: */
- QMenu* m_popup;
- QTimer m_magTimer;
- int m_mouseReleaseEventModifiers;
- QTreeWidgetItem* m_previousEventItem;
- QPoint m_dragMovementPosition;
- QPoint m_dragStartPosition;
- QTreeWidgetItem* m_extraItem;
+ QAction * m_actions[ActionCount];
- // The following is for managing saving bookmarks. It uses a QTimer to
- // determine whether the bookmarks should be saved. This may seem like
- // a hassle, but it is to prevent many saves from being executed at a
- // time.
+ QMenu * m_popup;
+ QTimer m_magTimer;
+ int m_mouseReleaseEventModifiers;
+ QModelIndex m_previousEventItem;
+ QPoint m_dragMovementPosition;
+ QPoint m_dragStartPosition;
+ QPersistentModelIndex m_extraItem;
- /** Flag indicating that bookmarks have been modified. */
- bool m_bookmarksModified;
- QTimer bookmarkSaveTimer;
+ /** Pointer to bookmarks model, added for convenience. */
+ BtBookmarksModel * m_bookmarksModel;
- private slots:
- /**
- * Saves the bookmarks.
- * It checks m_bookmarksModified and resets it at the end. It should be
- * connected to a timer that periodically calls this. */
- void considerSavingBookmarks();
};
#endif
diff --git a/src/frontend/bookshelfmanager/btconfigdialog.cpp b/src/frontend/bookshelfmanager/btconfigdialog.cpp
deleted file mode 100644
index e5d0fd1..0000000
--- a/src/frontend/bookshelfmanager/btconfigdialog.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/btconfigdialog.h"
-
-#include <QDialog>
-#include <QDialogButtonBox>
-#include <QEvent>
-#include <QFrame>
-#include <QHBoxLayout>
-#include <QLabel>
-#include <QListWidget>
-#include <QListView>
-#include <QStackedWidget>
-#include <QVBoxLayout>
-
-
-BtConfigDialog::BtConfigDialog(QWidget* parent, Qt::WindowFlags flags)
- : QDialog(parent, flags)
- , m_buttonBoxRuler(0)
- , m_buttonBox(0)
- , m_maxItemWidth(0)
- , m_previousPageIndex(-2)
-{
- m_contentsList = new QListWidget(this);
- m_contentsList->setViewMode(QListView::IconMode);
- m_contentsList->setMovement(QListView::Static);
-
- m_pageWidget = new QStackedWidget(this);
- m_pageWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
-
- m_pageLayout = new QVBoxLayout;
- m_pageLayout->addWidget(m_pageWidget);
-
- QHBoxLayout *mainLayout = new QHBoxLayout(this);
- mainLayout->addWidget(m_contentsList);
- mainLayout->addLayout(m_pageLayout);
-
- connect(m_contentsList, SIGNAL(currentRowChanged(int)),
- this, SLOT(slotChangePage(int)));
-}
-
-void BtConfigDialog::addPage(Page* pageWidget) {
-
- m_pageWidget->addWidget(pageWidget);
-
- QListWidgetItem* item = new QListWidgetItem(m_contentsList);
- item->setIcon(pageWidget->icon());
- item->setText(pageWidget->headerText());
- item->setTextAlignment(Qt::AlignHCenter);
- item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- pageWidget->setListWidgetItem(item);
-
- //set the list width - it may bee too wide (if there were no pages) or too narrow
- if (m_maxItemWidth < m_contentsList->visualItemRect(item).width()) {
- m_maxItemWidth = m_contentsList->visualItemRect(item).width();
- m_contentsList->setFixedWidth( m_maxItemWidth + (m_contentsList->frameWidth()*2) );
- }
- // all items should has the same width
- for (int i = 0; i < m_contentsList->count(); ++i) {
- m_contentsList->item(i)->setSizeHint(QSize(m_maxItemWidth, m_contentsList->visualItemRect(m_contentsList->item(i)).height()) );
- }
-
- setCurrentPage(m_contentsList->row(item));
-}
-
-void BtConfigDialog::setButtonBox(QDialogButtonBox *box) {
- Q_ASSERT(box != 0);
- Q_ASSERT(m_buttonBox == 0);
- Q_ASSERT(m_buttonBoxRuler == 0);
-
- m_buttonBox = box;
-
- // First add a horizontal ruler:
- m_buttonBoxRuler = new QFrame(this);
- m_buttonBoxRuler->setGeometry(QRect(1, 1, 1, 3));
- m_buttonBoxRuler->setFrameShape(QFrame::HLine);
- m_buttonBoxRuler->setFrameShadow(QFrame::Sunken);
- m_buttonBoxRuler->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- m_pageLayout->addWidget(m_buttonBoxRuler);
-
- // Add button box:
- m_pageLayout->addWidget(box);
-}
-
-void BtConfigDialog::setCurrentPage(int newIndex) {
- if (m_previousPageIndex != newIndex) {
- m_previousPageIndex = newIndex;
- m_contentsList->setCurrentRow(newIndex);
- m_pageWidget->setCurrentIndex(newIndex);
- }
-}
-
-void BtConfigDialog::slotChangePage(int newIndex) {
- /*
- This check is in place here because this slot is indirectly called by the
- setCurrentPage method.
- */
- if (m_previousPageIndex != newIndex) {
- m_previousPageIndex = newIndex;
- m_pageWidget->setCurrentIndex(newIndex);
- }
-}
diff --git a/src/frontend/bookshelfmanager/btconfigdialog.h b/src/frontend/bookshelfmanager/btconfigdialog.h
deleted file mode 100644
index 2525bd8..0000000
--- a/src/frontend/bookshelfmanager/btconfigdialog.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTCONFIGDIALOG_H
-#define BTCONFIGDIALOG_H
-
-#include <QDialog>
-
-#include <QIcon>
-#include <QListWidgetItem>
-
-
-class BtConfigPage;
-class QDialogButtonBox;
-class QFrame;
-class QStackedWidget;
-class QVBoxLayout;
-
-/**
-* Base class for configuration dialogs. A dialog which has a page chooser (icons
-* + text) at the left, widget pages and a buttonbox.
-*
-* Usage: add BtConfigPage pages with addPage(), add a button box with addButtonBox().
-* Connect the button box signals. Use setAttribute(Qt::WA_DeleteOnClose) if you want
-* an auto-destroying window.
-*/
-class BtConfigDialog : public QDialog {
-
- Q_OBJECT
-
- public: /* Types: */
-
- /** Base class for configuration dialog pages. */
- class Page : public QWidget {
-
- friend class BtConfigDialog;
-
- public: /* Methods: */
-
- inline Page(BtConfigDialog *parent)
- : QWidget(parent), m_listWidgetItem(0) {}
- inline Page(const QIcon &icon, BtConfigDialog *parent)
- : QWidget(parent), m_icon(icon), m_listWidgetItem(0) {}
-
- inline const QIcon &icon() const { return m_icon; }
- inline void setIcon(const QIcon &icon) {
- m_icon = icon;
- if (m_listWidgetItem != 0)
- m_listWidgetItem->setIcon(icon);
- }
-
- inline const QString &headerText() const { return m_headerText; }
- inline void setHeaderText(const QString &headerText) {
- m_headerText = headerText;
- if (m_listWidgetItem != 0)
- m_listWidgetItem->setText(headerText);
- }
-
- private: /* Methods: */
-
- void setListWidgetItem(QListWidgetItem *item) {
- m_listWidgetItem = item;
- }
-
- private: /* Fields: */
-
- QIcon m_icon;
- QString m_headerText;
- QListWidgetItem *m_listWidgetItem;
-
- };
-
- public: /* Methods: */
-
- BtConfigDialog(QWidget *parent = 0, Qt::WindowFlags flags = 0);
-
- /** Adds a BtConfigPage to the paged widget stack. The new page will be the current page.*/
- void addPage(Page *pageWidget);
-
- /** Adds a button box to the lower edge of the dialog. */
- void setButtonBox(QDialogButtonBox* buttonBox);
-
- /** Changes the current page using the given index number. */
- void setCurrentPage(int newIndex);
-
- private slots:
-
- void slotChangePage(int newIndex);
-
- private: /* Fields: */
-
- QListWidget* m_contentsList;
- QStackedWidget* m_pageWidget;
- QVBoxLayout* m_pageLayout;
- QFrame *m_buttonBoxRuler;
- QDialogButtonBox *m_buttonBox;
- int m_maxItemWidth;
- int m_previousPageIndex;
-
-};
-
-#endif
diff --git a/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp b/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp
deleted file mode 100644
index 8eebde6..0000000
--- a/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
-
-#include "backend/config/btconfig.h"
-#include "backend/managers/cswordbackend.h"
-#include "frontend/bookshelfmanager/indexpage/btindexpage.h"
-#include "frontend/bookshelfmanager/installpage/btinstallpage.h"
-#include "frontend/bookshelfmanager/removepage/btremovepage.h"
-
-
-namespace {
-const QString GeometryKey = "GUI/BookshelfManager/ModuleManagerDialog/geometry";
-} // anonymous namespace
-
-static BtModuleManagerDialog *m_staticModuleManagerDialog = 0;
-
-BtModuleManagerDialog* BtModuleManagerDialog::getInstance(QWidget *parent,
- Qt::WindowFlags flags)
-{
- if (m_staticModuleManagerDialog) {
- m_staticModuleManagerDialog->setParent(parent, flags);
- } else {
- m_staticModuleManagerDialog = new BtModuleManagerDialog(parent, flags);
- }
- Q_ASSERT(m_staticModuleManagerDialog);
- return m_staticModuleManagerDialog;
-}
-
-BtModuleManagerDialog::BtModuleManagerDialog(QWidget *parent,
- Qt::WindowFlags flags)
- : BtConfigDialog(parent,
- flags | Qt::CustomizeWindowHint | Qt::WindowTitleHint
- | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint)
-{
- setAttribute(Qt::WA_DeleteOnClose);
-
- addPage(new BtInstallPage());
- addPage(new BtRemovePage());
- addPage(new BtIndexPage());
-
- retranslateUi();
-
- loadDialogSettings();
- setCurrentPage(0);
-
-}
-
-void BtModuleManagerDialog::retranslateUi() {
- setWindowTitle(tr("Bookshelf Manager"));
-}
-
-BtModuleManagerDialog::~BtModuleManagerDialog() {
- saveDialogSettings();
- m_staticModuleManagerDialog = 0;
-}
-
-void BtModuleManagerDialog::loadDialogSettings() {
- restoreGeometry(btConfig().value<QByteArray>(GeometryKey, QByteArray()));
-}
-
-void BtModuleManagerDialog::saveDialogSettings() const {
- btConfig().setValue(GeometryKey, saveGeometry());
-}
diff --git a/src/frontend/bookshelfmanager/btmodulemanagerdialog.h b/src/frontend/bookshelfmanager/btmodulemanagerdialog.h
deleted file mode 100644
index 4d94026..0000000
--- a/src/frontend/bookshelfmanager/btmodulemanagerdialog.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTMODULEMANAGERDIALOG_H
-#define BTMODULEMANAGERDIALOG_H
-
-#include "frontend/bookshelfmanager/btconfigdialog.h"
-
-
-/**
-* The Bookshelf Manager dialog. Includes pages for Install, Remove, Indexes.
-*/
-class BtModuleManagerDialog: public BtConfigDialog {
-
- Q_OBJECT
-
- public:
-
- static BtModuleManagerDialog *getInstance(QWidget *parent = 0,
- Qt::WindowFlags flags = 0);
- ~BtModuleManagerDialog();
-
- private:
-
- BtModuleManagerDialog(QWidget *parent = 0, Qt::WindowFlags flags = 0);
-
- void retranslateUi();
-
- /** Loads the settings from the resource file. */
- void loadDialogSettings();
-
- /** Saves the settings to the resource file. */
- void saveDialogSettings() const;
-
-};
-
-
-#endif
diff --git a/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp b/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp
deleted file mode 100644
index b117f80..0000000
--- a/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp
+++ /dev/null
@@ -1,181 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/indexpage/btindexpage.h"
-
-#include <QCheckBox>
-#include <QDir>
-#include <QHBoxLayout>
-#include <QPushButton>
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
-#include <QVBoxLayout>
-#include "backend/config/btconfig.h"
-#include "backend/drivers/cswordmoduleinfo.h"
-#include "backend/managers/cswordbackend.h"
-#include "bibletimeapp.h"
-#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
-#include "frontend/btmoduleindexdialog.h"
-#include "util/cresmgr.h"
-#include "util/geticon.h"
-#include "util/tool.h"
-
-
-BtIndexPage::BtIndexPage(BtModuleManagerDialog *parent)
- : BtConfigDialog::Page(util::getIcon(CResMgr::bookshelfmgr::indexpage::icon), parent)
-{
- QVBoxLayout *vboxLayout = new QVBoxLayout(this);
- QHBoxLayout *hboxLayout;
-
- m_autoDeleteOrphanedIndicesBox = new QCheckBox(this);
- vboxLayout->addWidget(m_autoDeleteOrphanedIndicesBox);
-
- m_moduleList = new QTreeWidget(this);
- vboxLayout->addWidget(m_moduleList);
-
- hboxLayout = new QHBoxLayout();
-
- QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
- hboxLayout->addItem(spacerItem);
-
- m_deleteButton = new QPushButton(this);
- hboxLayout->addWidget(m_deleteButton);
-
- m_createButton = new QPushButton(this);
- hboxLayout->addWidget(m_createButton);
-
- vboxLayout->addLayout(hboxLayout);
-
- // configure the list view
- m_moduleList->setHeaderLabels( (QStringList(tr("Work")) << tr("Index size")) ); /// \todo Move to retranslateUi()
- m_moduleList->setRootIsDecorated(true);
- m_moduleList->setColumnWidth(0, util::tool::mWidth(m_moduleList, 20) );
- //m_moduleList->setTextAlignment(1, Qt::AlignRight); see doc...
- m_moduleList->setSortingEnabled(false);
-
- m_autoDeleteOrphanedIndicesBox->setChecked( btConfig().value<bool>("settings/behaviour/autoDeleteOrphanedIndices", true) );
-
- // icons for our buttons
- m_createButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::indexpage::create_icon));
- m_deleteButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::indexpage::delete_icon));
-
- // connect our signals/slots
- connect(m_createButton, SIGNAL(clicked()),
- this, SLOT(createIndices()));
- connect(m_deleteButton, SIGNAL(clicked()),
- this, SLOT(deleteIndices()));
- connect(CSwordBackend::instance(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)),
- this, SLOT(slotSwordSetupChanged()));
-
- retranslateUi(); // also calls populateModuleList();
-}
-
-BtIndexPage::~BtIndexPage() {
- btConfig().setValue("settings/behaviour/autoDeleteOrphanedIndices", m_autoDeleteOrphanedIndicesBox->isChecked() );
-}
-
-/** Populates the module list with installed modules and orphaned indices */
-void BtIndexPage::populateModuleList() {
- typedef QList<CSwordModuleInfo*>::const_iterator MLCI;
-
- m_moduleList->clear();
-
- // populate installed modules
- m_modsWithIndices = new QTreeWidgetItem(m_moduleList);
- m_modsWithIndices->setText(0, tr("Indexed Works"));
- m_modsWithIndices->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
- m_modsWithIndices->setExpanded(true);
-
- m_modsWithoutIndices = new QTreeWidgetItem(m_moduleList);
- m_modsWithoutIndices->setText(0, tr("Unindexed Works"));
- m_modsWithoutIndices->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
- m_modsWithoutIndices->setExpanded(true);
-
- const QList<CSwordModuleInfo*> &modules(CSwordBackend::instance()->moduleList());
- for (MLCI it(modules.begin()); it != modules.end(); ++it) {
- QTreeWidgetItem* item = 0;
-
- if ((*it)->hasIndex()) {
- item = new QTreeWidgetItem(m_modsWithIndices);
- item->setText(0, (*it)->name());
- item->setText(1, tr("%1 KiB").arg((*it)->indexSize() / 1024));
- item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
- item->setCheckState(0, Qt::Unchecked);
- }
- else {
- item = new QTreeWidgetItem(m_modsWithoutIndices);
- item->setText(0, (*it)->name());
- item->setText(1, tr("0 KiB"));
- item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
- item->setCheckState(0, Qt::Checked);
- }
- }
-}
-
-void BtIndexPage::retranslateUi() {
- setHeaderText(tr("Search Indexes"));
-
- m_autoDeleteOrphanedIndicesBox->setToolTip(tr("If selected, those indexes which have no corresponding work will be deleted when BibleTime starts"));
- m_autoDeleteOrphanedIndicesBox->setText(tr("Automatically delete orphaned indexes when BibleTime starts"));
-
- m_deleteButton->setToolTip(tr("Delete the selected indexes"));
- m_deleteButton->setText(tr("Delete"));
-
- m_createButton->setToolTip(tr("Create new indexes for the selected works"));
- m_createButton->setText(tr("Create..."));
-
- populateModuleList();
-}
-
-/** Creates indices for selected modules if no index currently exists */
-void BtIndexPage::createIndices() {
- bool indicesCreated = false;
- QList<const CSwordModuleInfo*> moduleList;
-
- for (int i = 0; i < m_modsWithoutIndices->childCount(); i++) {
- if (m_modsWithoutIndices->child(i)->checkState(0) == Qt::Checked) {
- CSwordModuleInfo* module = CSwordBackend::instance()->findModuleByName(m_modsWithoutIndices->child(i)->text(0).toUtf8());
- if (module) {
- moduleList.append( module );
- indicesCreated = true;
- }
- }
- }
-
- //Shows the progress dialog
- if (indicesCreated) {
- BtModuleIndexDialog::indexAllModules(moduleList);
- populateModuleList();
- }
-}
-
-/** Deletes indices for selected modules */
-void BtIndexPage::deleteIndices() {
- bool indicesDeleted = false;
-
- for (int i = 0; i < m_modsWithIndices->childCount(); i++) {
- if (m_modsWithIndices->child(i)->checkState(0) == Qt::Checked) {
- CSwordModuleInfo* module = CSwordBackend::instance()->findModuleByName(m_modsWithIndices->child(i)->text(0).toUtf8());
- if (module) {
- module->deleteIndex();
- indicesDeleted = true;
- }
- }
- }
-
- // repopulate the list if an action was taken
- if (indicesDeleted) {
- populateModuleList();
- }
-}
-
-void BtIndexPage::slotSwordSetupChanged() {
- populateModuleList();
-}
-
diff --git a/src/frontend/bookshelfmanager/indexpage/btindexpage.h b/src/frontend/bookshelfmanager/indexpage/btindexpage.h
deleted file mode 100644
index 100de17..0000000
--- a/src/frontend/bookshelfmanager/indexpage/btindexpage.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTINDEXPAGE_H
-#define BTINDEXPAGE_H
-
-#include "frontend/bookshelfmanager/btconfigdialog.h"
-
-
-class BtModuleManagerDialog;
-class QCheckBox;
-class QTreeWidget;
-class QTreeWidgetItem;
-
-/** \todo add void retranslateUi(); */
-
-/**
-* This class encapsulates the "Manage search indices" page of the Bookshelf
-* Manager. It allows for creation and deletion of search indicies for each
-* installed module. It also allows for deletion of orphaned indices.
-*/
-class BtIndexPage: public BtConfigDialog::Page {
-
- Q_OBJECT
-
- public:
-
- BtIndexPage(BtModuleManagerDialog *parent = 0);
- ~BtIndexPage();
-
- public slots:
- void slotSwordSetupChanged();
-
- protected:
-
- /**
- * Populates the module list with installed modules and orphaned indices
- */
- void populateModuleList();
-
- void retranslateUi();
-
- public slots:
- /**
- * Creates indices for selected modules if no index currently exists
- */
- void createIndices();
- /**
- * Deletes indices for selected modules
- */
- void deleteIndices();
-
- private:
-
- QCheckBox *m_autoDeleteOrphanedIndicesBox;
- QTreeWidget *m_moduleList;
- QPushButton *m_deleteButton;
- QPushButton *m_createButton;
-
- QTreeWidgetItem* m_modsWithIndices;
- QTreeWidgetItem* m_modsWithoutIndices;
-
-};
-
-
-#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp
deleted file mode 100644
index a689c05..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License
-* version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h"
-
-#include <QAction>
-#include <QHeaderView>
-#include <QToolButton>
-#include "backend/bookshelfmodel/btbookshelffiltermodel.h"
-#include "frontend/btbookshelfview.h"
-#include "util/tool.h"
-
-
-namespace {
-const QString groupingOrderKey("GUI/BookshelfManager/InstallConfirmDialog/grouping");
-}
-
-BtInstallModuleChooserDialog::BtInstallModuleChooserDialog(const BtBookshelfTreeModel::Grouping &g,
- QWidget *parent,
- Qt::WindowFlags flags)
- : BtModuleChooserDialog(parent, flags), m_shown(false)
-{
- resize(550, 340);
-
- // Read grouping order from settings or the default from argument:
- BtBookshelfTreeModel::Grouping groupingOrder(false);
- if (!groupingOrder.loadFrom(groupingOrderKey)) {
- groupingOrder = g;
- }
-
- BtInstallModuleChooserDialogModel *treeModel;
- treeModel = new BtInstallModuleChooserDialogModel(groupingOrder, this);
- connect(treeModel, SIGNAL(groupingOrderChanged(BtBookshelfTreeModel::Grouping)),
- this, SLOT(slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping&)));
-
- m_bookshelfModel = new BtBookshelfModel(this);
- bookshelfWidget()->postFilterModel()->setShowShown(true);
- bookshelfWidget()->setTreeModel(treeModel);
- bookshelfWidget()->setSourceModel(m_bookshelfModel);
- bookshelfWidget()->showHideAction()->setVisible(false);
- bookshelfWidget()->showHideButton()->hide();
- bookshelfWidget()->treeView()->header()->show();
-
- retranslateUi();
-}
-
-void BtInstallModuleChooserDialog::addModuleItem(CSwordModuleInfo *module,
- const QString &sourceName)
-{
- module->setProperty("installSourceName", sourceName);
- m_bookshelfModel->addModule(module);
-}
-
-void BtInstallModuleChooserDialog::retranslateUi() {
- setWindowTitle(tr("Install/Update works?"));
- util::tool::initExplanationLabel(
- label(), QString::null,
- tr("Do you really want to install these works?") + "<br/><br/><small>" +
- tr("Only one version of a work can be installed at the same time. Select only "
- "one if there are items marked with red.") + "</small>");
-}
-
-void BtInstallModuleChooserDialog::showEvent(QShowEvent *event) {
- Q_UNUSED(event);
-
- if (m_shown) return;
- bookshelfWidget()->treeView()->expandAll();
- bookshelfWidget()->treeView()->header()->resizeSections(QHeaderView::ResizeToContents);
- m_shown = true;
-}
-
-void BtInstallModuleChooserDialog::slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping &g) {
- g.saveTo(groupingOrderKey);
-}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h
deleted file mode 100644
index 49f1978..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License
-* version 2.0.
-*
-**********/
-
-#ifndef BTINSTALLMODULECHOOSERDIALOG_H
-#define BTINSTALLMODULECHOOSERDIALOG_H
-
-#include "frontend/btmodulechooserdialog.h"
-
-#include "frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.h"
-
-
-class BtBookshelfModel;
-class BtInstallModuleChooserDialogModel;
-class CSwordModuleInfo;
-
-/**
-* Confirmation dialog for installation. Lets the user
-* uncheck modules from the list.
-*/
-class BtInstallModuleChooserDialog: public BtModuleChooserDialog {
- Q_OBJECT
- public:
- BtInstallModuleChooserDialog(const BtBookshelfTreeModel::Grouping &g,
- QWidget *parent = 0,
- Qt::WindowFlags flags = 0);
-
- inline const QSet<CSwordModuleInfo*> &checkedModules() const {
- return bookshelfWidget()->treeModel()->checkedModules();
- }
-
- void addModuleItem(CSwordModuleInfo *module, const QString &sourceName);
-
- protected:
- void retranslateUi();
- void showEvent(QShowEvent *event);
-
- protected slots:
- void slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping &g);
-
- private:
- BtBookshelfModel *m_bookshelfModel;
-
- bool m_shown;
-};
-
-#endif // BTINSTALLMODULECHOOSERDIALOG_H
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.cpp b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.cpp
deleted file mode 100644
index 6f0fc9b..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License
-* version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.h"
-
-#include <QBrush>
-#include "backend/drivers/cswordmoduleinfo.h"
-#include "backend/managers/cswordbackend.h"
-
-
-#define MODULEPOINTERFORINDEX(i) static_cast<CSwordModuleInfo *>(\
- BtBookshelfTreeModel::data((i), BtBookshelfModel::ModulePointerRole).value<void*>())
-
-BtInstallModuleChooserDialogModel::BtInstallModuleChooserDialogModel(
- const Grouping &grouping,
- QObject *parent)
- : BtBookshelfTreeModel(grouping, parent), m_dataChangedFired(false)
-{
- setDefaultChecked(BtBookshelfTreeModel::CHECKED);
- setCheckable(true);
- connect(this, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(parentDataChanged(QModelIndex,QModelIndex)),
- Qt::DirectConnection);
-}
-
-QVariant BtInstallModuleChooserDialogModel::data(const QModelIndex &i, int role) const {
- switch (role) {
- case Qt::BackgroundRole:
- if (isMulti(i)) return QBrush(Qt::red);
- return BtBookshelfTreeModel::data(i, role);
- case Qt::ForegroundRole:
- if (isMulti(i)) return QBrush(Qt::white);
- return BtBookshelfTreeModel::data(i, role);
- case Qt::DisplayRole:
- switch (i.column()) {
- case 0:
- return BtBookshelfTreeModel::data(i, role);
- case 1:
- {
- CSwordModuleInfo *module = MODULEPOINTERFORINDEX(index(i.row(), 0, i.parent()));
- if (module != 0) return module->property("installSourceName");
- break;
- }
- case 2:
- {
- CSwordModuleInfo *module = MODULEPOINTERFORINDEX(index(i.row(), 0, i.parent()));
- if (module == 0) break;
- CSwordBackend *b = CSwordBackend::instance();
- CSwordModuleInfo *imodule = b->findModuleByName(module->name());
- if (imodule == 0) {
- return module->config(CSwordModuleInfo::ModuleVersion);
- } else {
- return imodule->config(CSwordModuleInfo::ModuleVersion)
- + " => "
- + module->config(CSwordModuleInfo::ModuleVersion);
- }
- }
- default: break;
- }
- default:
- if (i.column() == 0) return BtBookshelfTreeModel::data(i, role);
- }
-
- return QVariant();
-}
-
-int BtInstallModuleChooserDialogModel::columnCount(const QModelIndex &parent) const {
- Q_UNUSED(parent);
-
- return 3;
-}
-
-QVariant BtInstallModuleChooserDialogModel::headerData(int section,
- Qt::Orientation orientation,
- int role) const
-{
- if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
- switch (section) {
- case 0: return tr("Work");
- case 1: return tr("Installation source");
- case 2: return tr("Version");
- default: break;
- }
- }
-
- return QVariant();
-}
-
-void BtInstallModuleChooserDialogModel::parentDataChanged(const QModelIndex &topLeft,
- const QModelIndex &bottomRight)
-{
- Q_UNUSED(topLeft);
- Q_UNUSED(bottomRight);
-
- if (m_dataChangedFired) return;
- m_dataChangedFired = true;
- resetData();
- m_dataChangedFired = false;
-}
-
-bool BtInstallModuleChooserDialogModel::isMulti(CSwordModuleInfo * m1) const {
- if (m1 != 0 && checkedModules().contains(m1))
- Q_FOREACH (CSwordModuleInfo * m2, modules())
- if (m1 != m2 && checkedModules().contains(m2) && m1->name() == m2->name())
- return true;
- return false;
-}
-
-bool BtInstallModuleChooserDialogModel::isMulti(const QModelIndex &i) const {
- if (!i.isValid()) return false;
-
- if (!hasChildren(i)) {
- return isMulti(MODULEPOINTERFORINDEX(index(i.row(), 0, i.parent())));
- } else {
- for (int row = 0; row < rowCount(i); row++) {
- if (isMulti(i.child(row, 0))) return true;
- }
- }
- return false;
-}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.h b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.h
deleted file mode 100644
index 406b89c..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License
-* version 2.0.
-*
-**********/
-
-#ifndef BTINSTALLMODULECHOOSERDIALOGMODEL_H
-#define BTINSTALLMODULECHOOSERDIALOGMODEL_H
-
-#include "backend/bookshelfmodel/btbookshelftreemodel.h"
-
-#include <QMap>
-
-
-class BtInstallModuleChooserDialogModel: public BtBookshelfTreeModel {
- Q_OBJECT
- public:
- BtInstallModuleChooserDialogModel(const Grouping &grouping, QObject *parent = 0);
-
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
-
- private slots:
- void parentDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
-
- private:
- bool isMulti(CSwordModuleInfo *module) const;
- bool isMulti(const QModelIndex &index) const;
-
- private:
- QMap<QString, int> m_nameCounts;
- bool m_dataChangedFired;
-};
-
-#endif // BTINSTALLMODULECHOOSERDIALOGMODEL_H
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp
deleted file mode 100644
index 5f8bfb8..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp
+++ /dev/null
@@ -1,447 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/installpage/btinstallpage.h"
-
-#include <QApplication>
-#include <QComboBox>
-#include <QGroupBox>
-#include <QHBoxLayout>
-#include <QHeaderView>
-#include <QLabel>
-#include <QPushButton>
-#include <QSharedPointer>
-#include <QStackedLayout>
-#include <QToolButton>
-#include "backend/config/btconfig.h"
-#include "backend/btinstallbackend.h"
-#include "bibletimeapp.h"
-#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
-#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h"
-#include "frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h"
-#include "frontend/bookshelfmanager/installpage/btinstallpageworkswidget.h"
-#include "frontend/bookshelfmanager/installpage/btinstallpathdialog.h"
-#include "frontend/bookshelfmanager/installpage/btinstallprogressdialog.h"
-#include "frontend/btbookshelfview.h"
-#include "frontend/messagedialog.h"
-#include "util/cresmgr.h"
-#include "util/directory.h"
-#include "util/geticon.h"
-#include "util/tool.h"
-
-
-namespace {
-const QString groupingOrderKey ("GUI/BookshelfManager/InstallPage/grouping");
-const QString headerStateKey ("GUI/BookshelfManager/InstallPage/headerState");
-const QString selectedModuleKey("GUI/BookshelfManager/InstallPage/selectedModule");
-const QString installPathKey ("GUI/BookshelfManager/InstallPage/installPathIndex");
-} // anonymous namespace
-
-
-// *********************************************************
-// *********** Config dialog page: Install/Update **********
-// *********************************************************
-
-BtInstallPage::BtInstallPage(BtModuleManagerDialog *parent)
- : BtConfigDialog::Page(util::getIcon(CResMgr::bookshelfmgr::installpage::icon), parent)
- , m_groupingOrder(groupingOrderKey)
- , m_modulesSelected(0)
- , m_modulesSelectedSources(0)
-{
- // Read settings:
- m_headerState = btConfig().value<QByteArray>(headerStateKey, QByteArray());
-
- // Initialize widgets:
- initView();
- initConnections();
-
- retranslateUi();
-}
-
-void BtInstallPage::setInstallEnabled(bool b) {
- m_installButton->setEnabled(b);
-}
-
-QString BtInstallPage::selectedInstallPath() {
- return m_pathCombo->currentText();
-}
-
-void BtInstallPage::initView() {
- // Warning label:
- m_warningLabel = new QLabel(this);
-
- // Source chooser:
- m_sourceGroupBox = new QGroupBox(this);
- m_sourceGroupBox->setFlat(true);
-
- m_sourceComboBox = new QComboBox(this);
- m_sourceComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
- initSourcesCombo();
-
- m_sourceAddButton = new QPushButton(this);
- m_sourceAddButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::installpage::add_icon));
-
- m_sourceDeleteButton = new QPushButton(this);
- m_sourceDeleteButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::installpage::delete_icon));
-
- QHBoxLayout *sourceChooserLayout = new QHBoxLayout();
- sourceChooserLayout->setContentsMargins(0, 8, 0, 0);
- sourceChooserLayout->addWidget(m_sourceComboBox, 1);
- sourceChooserLayout->addWidget(m_sourceAddButton);
- sourceChooserLayout->addWidget(m_sourceDeleteButton);
- m_sourceGroupBox->setLayout(sourceChooserLayout);
-
- // Works chooser:
- m_worksGroupBox = new QGroupBox(this);
- m_worksGroupBox->setFlat(true);
- m_worksLayout = new QStackedLayout();
- m_worksGroupBox->setLayout(m_worksLayout);
- slotSourceIndexChanged(m_sourceComboBox->currentIndex());
-
- // Installation path chooser:
- m_installGroupBox = new QGroupBox(this);
- m_installGroupBox->setFlat(true);
- retranslateInstallGroupBox();
-
- m_pathLabel = new QLabel(this);
- m_pathCombo = new QComboBox(this);
- m_pathCombo->setMinimumContentsLength(20);
- m_pathCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
- m_pathCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
- m_pathCombo->view()->setTextElideMode(Qt::ElideMiddle);
- m_pathLabel->setBuddy(m_pathCombo);
- initPathCombo();
-
- m_configurePathButton = new QToolButton(this);
- m_configurePathButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::installpage::path_icon));
-
- m_installButton = new QPushButton(this);
- m_installButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::installpage::install_icon));
- m_installButton->setEnabled(false);
-
- QHBoxLayout *pathLayout = new QHBoxLayout();
- pathLayout->setContentsMargins(0, 8, 0, 0);
- pathLayout->addWidget(m_pathLabel);
- pathLayout->addWidget(m_pathCombo);
- pathLayout->addWidget(m_configurePathButton);
- pathLayout->addWidget(m_installButton);
- m_installGroupBox->setLayout(pathLayout);
-
- QVBoxLayout *mainLayout = new QVBoxLayout(this);
- mainLayout->addWidget(m_warningLabel);
- mainLayout->addWidget(m_sourceGroupBox);
- mainLayout->addWidget(m_worksGroupBox, 1);
- mainLayout->addWidget(m_installGroupBox);
-}
-
-void BtInstallPage::initConnections() {
- connect(m_sourceComboBox, SIGNAL(currentIndexChanged(int)),
- this, SLOT(slotSourceIndexChanged(int)));
- connect(m_sourceAddButton, SIGNAL(clicked()),
- this, SLOT(slotSourceAdd()));
- connect(m_sourceDeleteButton, SIGNAL(clicked()),
- this, SLOT(slotSourceDelete()));
- connect(m_installButton, SIGNAL(clicked()),
- this, SLOT(slotInstall()));
- connect(m_pathCombo, SIGNAL(activated(const QString&)),
- this , SLOT(slotPathChanged(const QString&)));
- connect(m_configurePathButton, SIGNAL(clicked()),
- this, SLOT(slotEditPaths()));
- connect(CSwordBackend::instance(),
- SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)),
- this, SLOT(slotSwordSetupChanged()));
-}
-
-void BtInstallPage::initPathCombo() {
- //populate the combo list
- m_pathCombo->clear();
-
- QStringList targets = BtInstallBackend::targetList();
- for (QStringList::iterator it = targets.begin(); it != targets.end(); ++it) {
- // Add the path only if it's writable
- if ((*it).isEmpty()) continue;
- QDir dir(*it);
- if (!dir.exists()) continue;
- if (!dir.isReadable()) continue;
- QFileInfo fi( dir.canonicalPath());
- if (!fi.isWritable()) continue;
- m_pathCombo->addItem(util::directory::convertDirSeparators(*it));
- }
-
- // choose the current value from config but check whether we have so many items
- int configValue = btConfig().value<int>(installPathKey, 0);
- int index = configValue > (m_pathCombo->count() - 1) ? m_pathCombo->count() - 1 : configValue;
- m_pathCombo->setCurrentIndex(index);
-}
-
-void BtInstallPage::initSourcesCombo() {
- /// \todo Implement a proper model for this
-
- m_sourceComboBox->clear();
- QStringList sourceList = BtInstallBackend::sourceNameList();
-
- // Add a default entry, the Crosswire main repository
- if (sourceList.empty()) {
- /// \todo Open a dialog which asks whether to get list from server and add sources
- sword::InstallSource is("FTP"); //default return value
- is.caption = "CrossWire Bible Society";
- is.source = "ftp.crosswire.org";
- is.directory = "/pub/sword/raw";
- // passive ftp is not needed here, it's the default
-
- BtInstallBackend::addSource(is);
-
- sourceList = BtInstallBackend::sourceNameList();
- Q_ASSERT(!sourceList.empty());
- }
-
- // Read selected module from config:
- const QString selected = btConfig().value<QString>(selectedModuleKey, QString());
-
- // Populate combo box
- bool selectionOk = false;
- for (int i = 0; i < sourceList.size(); i++) {
- m_sourceComboBox->addItem(sourceList.at(i));
-
- // Select configured item:
- if (!selectionOk && sourceList.at(i) == selected) {
- m_sourceComboBox->setCurrentIndex(i);
- selectionOk = true;
- }
- }
-
- // Set selection, if it wasn't properly configured:
- if (!selectionOk) {
- m_sourceComboBox->setCurrentIndex(0);
- btConfig().setValue(selectedModuleKey, sourceList.at(0));
- }
-}
-
-void BtInstallPage::activateSource(const sword::InstallSource &src) {
- qApp->setOverrideCursor(Qt::WaitCursor);
- BtInstallPageWorksWidget *w = m_sourceMap.value(QString(src.caption), 0);
- if (w == 0) {
- window()->setEnabled(false);
- qApp->processEvents();
- w = new BtInstallPageWorksWidget(src, m_groupingOrder, this);
- m_sourceMap.insert(QString(src.caption), w);
- m_worksLayout->addWidget(w);
- connect(w->treeModel(), SIGNAL(groupingOrderChanged(BtBookshelfTreeModel::Grouping)),
- this, SLOT(slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping&)));
- connect(w->treeModel(), SIGNAL(moduleChecked(CSwordModuleInfo*,bool)),
- this, SLOT(slotSelectedModulesChanged()));
- window()->setEnabled(true);
- } else {
- disconnect(w->treeView()->header(), SIGNAL(geometriesChanged()),
- this, SLOT(slotHeaderChanged()));
- }
- m_worksLayout->setCurrentWidget(w);
- w->treeModel()->setGroupingOrder(m_groupingOrder);
- w->treeView()->header()->restoreState(m_headerState);
- connect(w->treeView()->header(), SIGNAL(geometriesChanged()),
- this, SLOT(slotHeaderChanged()));
- qApp->restoreOverrideCursor();
-}
-
-void BtInstallPage::retranslateInstallGroupBox() {
- if (m_modulesSelected > 0) {
- m_installGroupBox->setTitle(tr("Start installation of %1 works from %2 sources:")
- .arg(m_modulesSelected)
- .arg(m_modulesSelectedSources));
- } else {
- m_installGroupBox->setTitle(tr("Start installation:"));
- }
-}
-
-void BtInstallPage::retranslateUi() {
- setHeaderText(tr("Install/Update"));
-
- util::tool::initExplanationLabel(m_warningLabel, tr("WARNING!!!"),
- tr("If you live in a persecuted country and don't want to risk "
- "detection don't use remote sources."));
-
- m_sourceGroupBox->setTitle(tr("Select installation &source:"));
- m_sourceAddButton->setText(tr("&Add..."));
- m_sourceAddButton->setToolTip(tr("Add new source"));
- m_sourceDeleteButton->setText(tr("&Delete..."));
- m_sourceDeleteButton->setToolTip(tr("Delete this source"));
-
- m_worksGroupBox->setTitle(tr("Select &works to install:"));
-
- m_pathLabel->setText(tr("Install &folder:"));
- m_pathCombo->setToolTip(tr("The folder where the new works will be installed"));
- m_configurePathButton->setToolTip(tr("Configure folders where works are installed and found"));
- m_installButton->setText(tr("&Install..."));
- m_installButton->setToolTip(tr("Install or update selected works"));
-
- retranslateInstallGroupBox();
-}
-
-void BtInstallPage::slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping &g) {
- m_groupingOrder = g;
- m_groupingOrder.saveTo(groupingOrderKey);
-}
-
-void BtInstallPage::slotHeaderChanged() {
- typedef BtInstallPageWorksWidget IPWW;
- Q_ASSERT(qobject_cast<IPWW*>(m_worksLayout->currentWidget()) != 0);
- IPWW *w = static_cast<IPWW*>(m_worksLayout->currentWidget());
- m_headerState = w->treeView()->header()->saveState();
- btConfig().setValue(headerStateKey, m_headerState);
-}
-
-void BtInstallPage::slotInstall() {
- // check that the destination path is writable, do nothing if not and user doesn't want to continue
- QDir dir = selectedInstallPath();
- bool canWrite = true;
- if (dir.isReadable()) {
- const QFileInfo fi( dir.canonicalPath() );
- if (!fi.exists() || !fi.isWritable()) {
- canWrite = false;
- }
- }
- else {
- canWrite = false;
- }
- if (!canWrite) {
- const int result = message::showWarning(this, tr("Warning"), tr("The destination directory is not writable or does not exist. Installation will fail unless this has first been fixed."), QMessageBox::Ignore | QMessageBox::Cancel, QMessageBox::Cancel);
- if (result != QMessageBox::Ignore) {
- return;
- }
- }
-
- // create the confirmation dialog
- BtInstallModuleChooserDialog *dlg = new BtInstallModuleChooserDialog(m_groupingOrder, this);
-
- // Add all checked modules from all tabs:
- Q_FOREACH (BtInstallPageWorksWidget *w, m_sourceMap.values()) {
- Q_FOREACH (CSwordModuleInfo *module, w->treeModel()->checkedModules()) {
- dlg->addModuleItem(module, QString(w->installSource().caption));
- }
- }
-
- if (dlg->exec() == QDialog::Accepted) {
- QList<CSwordModuleInfo *> modules(dlg->checkedModules().toList());
- if (modules.empty())
- return;
-
- /// \todo first remove all modules which will be updated from the module list
- // but what modules? all with the same real name? (there may be _n modules...)
-
- // progressDialog is WA_DeleteOnClose
- typedef BtInstallProgressDialog BIPD;
- BIPD * const progressDialog = new BIPD(modules, selectedInstallPath(), this);
- m_installButton->setEnabled(false);
- // the progress dialog is now modal, it can be made modeless later.
- progressDialog->exec();
-
- }
- delete dlg;
-}
-
-void BtInstallPage::slotPathChanged(const QString& /*pathText*/) {
- btConfig().setValue(installPathKey, m_pathCombo->currentIndex());
-}
-
-void BtInstallPage::slotEditPaths() {
- BtInstallPathDialog* dlg = new BtInstallPathDialog();
- int result = dlg->exec();
- if (result == QDialog::Accepted) {
- //dynamic_cast<BtModuleManagerDialog*>(parentDialog())->slotSwordSetupChanged();
- CSwordBackend::instance()->reloadModules(CSwordBackend::PathChanged);
- }
-}
-
-void BtInstallPage::slotSourceAdd() {
- typedef CSwordSetupInstallSourcesDialog SSISD;
-
- QSharedPointer<SSISD> dlg(new SSISD());
- if (dlg->exec() == QDialog::Accepted) {
- if (dlg->wasRemoteListAdded()) {
- initSourcesCombo();
- }
- else {
- sword::InstallSource newSource = dlg->getSource();
- if ( !((QString)newSource.type.c_str()).isEmpty() ) { // we have a valid source to add
- BtInstallBackend::addSource(newSource);
- }
- initSourcesCombo();
- for (int i = 0; i < m_sourceComboBox->count(); i++) {
- if (m_sourceComboBox->itemText(i) == newSource.caption) {
- m_sourceComboBox->setCurrentIndex(i);
- break;
- }
- }
- }
- }
-}
-
-void BtInstallPage::slotSourceDelete() {
- typedef BtInstallPageWorksWidget IPWW;
-
- int ret = message::showWarning(this, tr("Delete Source?"),
- tr("Do you really want to delete this source?"),
- QMessageBox::Yes | QMessageBox::No);
-
- if (ret == QMessageBox::Yes) {
- qApp->setOverrideCursor(Qt::WaitCursor);
- window()->setEnabled(false);
- Q_ASSERT(qobject_cast<IPWW*>(m_worksLayout->currentWidget()));
- IPWW *w = static_cast<IPWW*>(m_worksLayout->currentWidget());
- m_sourceMap.remove(QString(w->installSource().caption));
- w->deleteSource();
- initSourcesCombo();
- slotSourceIndexChanged(m_sourceComboBox->currentIndex());
- delete w;
- window()->setEnabled(true);
- qApp->restoreOverrideCursor();
- }
-}
-
-void BtInstallPage::slotSourceIndexChanged(int index) {
- if (index < 0) {
- if(!m_sourceComboBox->count())
- return;
- index = 0;
- }
-
- /// \todo use pointers instead of text
- QString moduleName = m_sourceComboBox->itemText(index);
- btConfig().setValue(selectedModuleKey, moduleName);
- activateSource(BtInstallBackend::source(moduleName));
-}
-
-void BtInstallPage::slotSelectedModulesChanged() {
- m_modulesSelected = 0;
- m_modulesSelectedSources = 0;
- Q_FOREACH (BtInstallPageWorksWidget *w, m_sourceMap.values()) {
- int selected = w->treeModel()->checkedModules().size();
- if (selected > 0) {
- m_modulesSelectedSources++;
- m_modulesSelected += selected;
- }
- }
-
- m_installButton->setEnabled(m_modulesSelected > 0);
- retranslateInstallGroupBox();
-}
-
-void BtInstallPage::slotSwordSetupChanged() {
- QString moduleName = m_sourceComboBox->currentText();
-
- // clean m_sourceMap before initSourcesCombo() make too much work
- qDeleteAll(m_sourceMap.values());
- m_sourceMap.clear();
- initSourcesCombo();
- m_sourceComboBox->setCurrentIndex(m_sourceComboBox->findText(moduleName));
- initPathCombo();
- m_modulesSelected = 0;
- m_modulesSelectedSources = 0;
- retranslateInstallGroupBox();
-}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpage.h b/src/frontend/bookshelfmanager/installpage/btinstallpage.h
deleted file mode 100644
index fe791cf..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallpage.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTINSTALLPAGE_H
-#define BTINSTALLPAGE_H
-
-#include "frontend/bookshelfmanager/btconfigdialog.h"
-
-#include "backend/bookshelfmodel/btbookshelftreemodel.h"
-
-
-namespace sword {
-class InstallSource;
-}
-
-class BtInstallPageWorksWidget;
-class BtModuleManagerDialog;
-class QComboBox;
-class QGroupBox;
-class QLabel;
-class QPushButton;
-class QStackedLayout;
-class QToolButton;
-
-/**
-* The Install page includes module path chooser, source/module handler and install button.
-*/
-class BtInstallPage: public BtConfigDialog::Page {
-
- Q_OBJECT
-
- public:
-
- BtInstallPage(BtModuleManagerDialog *parent = 0);
-
- void setInstallEnabled(bool b);
-
- QString selectedInstallPath();
-
- public slots:
- void slotSwordSetupChanged();
-
- protected:
-
- void retranslateUi();
-
- private:
- void initView();
- void initConnections();
- void initPathCombo();
- void initSourcesCombo();
-
- void activateSource(const sword::InstallSource &src);
- void retranslateInstallGroupBox();
-
- private slots:
- void slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping &g);
- void slotHeaderChanged();
- void slotInstall();
- void slotPathChanged(const QString& pathText);
- void slotEditPaths();
- void slotSourceAdd();
- void slotSourceDelete();
- void slotSourceIndexChanged(int index);
- void slotSelectedModulesChanged();
-
- private:
- BtBookshelfTreeModel::Grouping m_groupingOrder;
- QByteArray m_headerState;
-
- QMap<QString, BtInstallPageWorksWidget*> m_sourceMap;
-
- QLabel *m_warningLabel;
-
- QGroupBox *m_sourceGroupBox;
- QComboBox *m_sourceComboBox;
- QPushButton *m_sourceAddButton;
- QPushButton *m_sourceDeleteButton;
-
- QGroupBox *m_worksGroupBox;
- QStackedLayout *m_worksLayout;
-
- QGroupBox *m_installGroupBox;
- QLabel *m_pathLabel;
- QComboBox *m_pathCombo;
- QToolButton *m_configurePathButton;
- QPushButton *m_installButton;
-
- unsigned m_modulesSelected;
- unsigned m_modulesSelectedSources;
-};
-
-#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.cpp
deleted file mode 100644
index 06e97f8..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License
-* version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/installpage/btinstallpagemodel.h"
-
-
-#include "backend/drivers/cswordmoduleinfo.h"
-#include "backend/managers/cswordbackend.h"
-
-
-#define MODULEPOINTERFORINDEX(i) static_cast<CSwordModuleInfo *>(\
- BtBookshelfTreeModel::data((i), BtBookshelfModel::ModulePointerRole).value<void*>())
-
-BtInstallPageModel::BtInstallPageModel(const Grouping &grouping, QObject *parent)
- : BtBookshelfTreeModel(grouping, parent)
-{
- setDefaultChecked(BtBookshelfTreeModel::UNCHECKED);
- setCheckable(true);
-}
-
-QVariant BtInstallPageModel::data(const QModelIndex &i, int role) const {
- switch (role) {
- case Qt::DisplayRole:
- switch (i.column()) {
- case 0:
- return BtBookshelfTreeModel::data(i, role);
- case 1:
- {
- CSwordModuleInfo *module = MODULEPOINTERFORINDEX(index(i.row(), 0, i.parent()));
- if (module == 0) break;
- CSwordBackend *b = CSwordBackend::instance();
- CSwordModuleInfo *imodule = b->findModuleByName(module->name());
- if (imodule == 0) {
- return module->config(CSwordModuleInfo::ModuleVersion);
- } else {
- return imodule->config(CSwordModuleInfo::ModuleVersion)
- + " => "
- + module->config(CSwordModuleInfo::ModuleVersion);
- }
- }
- case 2:
- {
- CSwordModuleInfo *module = MODULEPOINTERFORINDEX(index(i.row(), 0, i.parent()));
- if (module != 0) return module->config(CSwordModuleInfo::Description);
- }
- default: break;
- }
- default:
- if (i.column() == 0) return BtBookshelfTreeModel::data(i, role);
- }
-
- return QVariant();
-}
-
-int BtInstallPageModel::columnCount(const QModelIndex &parent) const {
- Q_UNUSED(parent);
-
- return 3;
-}
-
-QVariant BtInstallPageModel::headerData(int section, Qt::Orientation orientation,
- int role) const
-{
- if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
- switch (section) {
- case 0: return tr("Work");
- case 1: return tr("Version");
- case 2: return tr("Description");
- default: break;
- }
- }
-
- return QVariant();
-}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.h b/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.h
deleted file mode 100644
index 009aa15..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License
-* version 2.0.
-*
-**********/
-
-#ifndef BTINSTALLPAGEMODEL_H
-#define BTINSTALLPAGEMODEL_H
-
-#include "backend/bookshelfmodel/btbookshelftreemodel.h"
-
-#include <QMap>
-
-
-class BtInstallPageModel: public BtBookshelfTreeModel {
- Q_OBJECT
- public:
- BtInstallPageModel(const Grouping &grouping, QObject *parent = 0);
-
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
-};
-
-#endif // BTINSTALLPAGEMODEL_H
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.cpp
deleted file mode 100644
index 629a69c..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/installpage/btinstallpageworkswidget.h"
-
-#include <QApplication>
-#include <QAction>
-#include <QDebug>
-#include <QTimer>
-#include <QToolButton>
-#include "backend/btinstallbackend.h"
-#include "backend/managers/cswordbackend.h"
-#include "bibletimeapp.h"
-#include "frontend/bookshelfmanager/installpage/btinstallpage.h"
-#include "frontend/bookshelfmanager/installpage/btinstallpagemodel.h"
-#include "frontend/bookshelfmanager/installpage/btrefreshprogressdialog.h"
-#include "frontend/btbookshelfview.h"
-#include "util/cresmgr.h"
-#include "util/geticon.h"
-
-
-namespace {
-
-/** Filters out already installed modules which can't be updated right now. */
-bool filter(CSwordModuleInfo *mInfo) {
- typedef CSwordModuleInfo CSMI;
- typedef sword::SWVersion SV;
-
- const CSMI *installedModule = CSwordBackend::instance()->findModuleByName(mInfo->name());
- if (installedModule) {
- // Already installed, check if it's an update:
- const SV curVersion(installedModule->config(CSMI::ModuleVersion).toLatin1());
- const SV newVersion(mInfo->config(CSMI::ModuleVersion).toLatin1());
- if (curVersion >= newVersion) {
- return false;
- }
- }
- return true;
-}
-
-}
-
-BtInstallPageWorksWidget::BtInstallPageWorksWidget(
- const sword::InstallSource &source,
- const BtBookshelfTreeModel::Grouping &g,
- BtInstallPage *parent, Qt::WindowFlags flags)
- : BtBookshelfWidget(parent, flags)
- , m_source(source)
- , m_parent(parent)
- , m_backend(0)
- , m_myModel(0)
-{
-
- setTreeModel(new BtInstallPageModel(g, this));
-
- treeView()->setHeaderHidden(false);
- showHideButton()->hide();
- showHideAction()->setVisible(false);
-
- m_sourceRefreshButton = new QToolButton(this);
- m_sourceRefreshButton->setAutoRaise(true);
- m_sourceRefreshButton->setToolTip(tr("Refresh the list of works from this source"));
- m_sourceRefreshButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::installpage::refresh_icon));
- setRightCornerWidget(m_sourceRefreshButton);
-
- connect(m_sourceRefreshButton, SIGNAL(clicked()),
- this, SLOT(slotSourceRefresh()));
-
- m_backend = BtInstallBackend::backend(m_source);
- Q_ASSERT(m_backend != 0);
- m_myModel = new BtBookshelfModel(this);
- Q_FOREACH(CSwordModuleInfo *module, m_backend->moduleList()) {
- if (filter(module)) m_myModel->addModule(module);
- }
- setSourceModel(m_myModel);
-}
-
-BtInstallPageWorksWidget::~BtInstallPageWorksWidget() {
- delete m_backend;
-}
-
-void BtInstallPageWorksWidget::deleteSource() {
- qDebug() << "Deleting source" << m_source.caption;
-
- m_myModel->clear();
- BtInstallBackend::deleteSource(QString(m_source.caption));
-}
-
-void BtInstallPageWorksWidget::updateTree() {
- qDebug() << "Updating BtInstallPageWorksWidget tree for source" << m_source.caption;
-
- m_myModel->clear();
-
- // Is this necessary?
- m_source = BtInstallBackend::source(QString(m_source.caption));
- m_backend = BtInstallBackend::backend(m_source);
-
- // Repopulate model:
- Q_FOREACH(CSwordModuleInfo *module, m_backend->moduleList()) {
- if (filter(module)) m_myModel->addModule(module);
- }
-}
-
-void BtInstallPageWorksWidget::slotSourceRefresh() {
- qDebug() << "Refreshing source" << m_source.caption;
-
- if (BtInstallBackend::isRemote(m_source)) {
- BtRefreshProgressDialog d(m_source, this);
- if (!d.runAndDelete()) return;
- }
- updateTree();
-}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.h b/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.h
deleted file mode 100644
index d02e99e..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTINSTALLPAGEWORKSWIDGET_H
-#define BTINSTALLPAGEWORKSWIDGET_H
-
-
-#include "frontend/btbookshelfwidget.h"
-
-// Sword includes
-#include <installmgr.h>
-
-
-class BtInstallPage;
-
-class BtInstallPageWorksWidget: public BtBookshelfWidget {
- Q_OBJECT
-
- public: /* Methods: */
-
- BtInstallPageWorksWidget(const sword::InstallSource &source,
- const BtBookshelfTreeModel::Grouping &g,
- BtInstallPage *parent, Qt::WindowFlags f = 0);
-
- ~BtInstallPageWorksWidget();
-
- inline const sword::InstallSource &installSource() const {
- return m_source;
- }
- void deleteSource();
-
- private: /* Methods: */
-
- void updateTree();
-
- private slots:
-
- void slotSourceRefresh();
-
- private: /* Fields: */
-
- sword::InstallSource m_source;
- BtInstallPage *m_parent;
- QToolButton *m_sourceRefreshButton;
- CSwordBackend *m_backend;
- BtBookshelfModel *m_myModel;
-};
-
-#endif // BTINSTALLPAGEWORKSWIDGET_H
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp
deleted file mode 100644
index 109bbd9..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp
+++ /dev/null
@@ -1,236 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/installpage/btinstallpathdialog.h"
-
-#include <QDebug>
-#include <QDialog>
-#include <QDialogButtonBox>
-#include <QDir>
-#include <QFileDialog>
-#include <QGridLayout>
-#include <QLabel>
-#include <QPushButton>
-#include <QString>
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
-#include "backend/btinstallbackend.h"
-#include "bibletimeapp.h"
-#include "frontend/messagedialog.h"
-#include "util/directory.h"
-#include "util/cresmgr.h"
-#include "util/geticon.h"
-#include "util/tool.h"
-
-
-BtInstallPathDialog::BtInstallPathDialog() {
- namespace DU = util::directory;
-
- setWindowTitle(tr("Bookshelf Folders"));
-
- QVBoxLayout *mainLayout;
- QHBoxLayout *viewLayout;
-
- mainLayout = new QVBoxLayout(this);
- viewLayout = new QHBoxLayout();
-
- QString l1 = tr("Works can be installed in one or more folders. After setting up folders here you can choose one of them in Install page.");
- /// \bug The following string has an extra space character:
- QString l2 = tr("BibleTime and the SWORD library find the works from all of these folders. If a folder is removed here it still exists in the system with all the works in it.");
-
- QLabel* mainLabel = util::tool::explanationLabel(this,
- tr("Configure bookshelf folders"), l1 + QString("<small><br/><br/>") + l2 + QString("</small>"));
- mainLayout->addWidget(mainLabel);
-
- QString swordConfPath = BtInstallBackend::swordConfigFilename();
- /// \todo After releasing 2.4, change the following line to: QLabel *confPathLabel = new QLabel(tr("Configuration file for the folders is: <b>%1</b>").arg(swordConfPath), this);
- QLabel* confPathLabel = new QLabel(tr("Configuration file for the folders is: ").append("<b>%1</b>").arg(swordConfPath), this);
- confPathLabel->setWordWrap(true);
- mainLayout->addWidget(confPathLabel);
-
-
- m_swordPathListBox = new QTreeWidget(this);
- m_swordPathListBox->setHeaderHidden(true);
-
- QString rwfolderitem(tr("Folders where new works can be installed"));
- m_writableItem = new QTreeWidgetItem(m_swordPathListBox, QStringList(rwfolderitem));;
- m_writableItem->setFlags(Qt::ItemIsEnabled);
- m_readableItem = new QTreeWidgetItem(m_swordPathListBox, QStringList(tr("Read-only folders")));;
- m_readableItem->setFlags(Qt::ItemIsEnabled);
- m_nonexistingItem = new QTreeWidgetItem(m_swordPathListBox, QStringList(tr("Nonexistent folders")));;
- m_nonexistingItem->setFlags(Qt::ItemIsEnabled);
-
- QStringList targets = BtInstallBackend::targetList();
-
- foreach (QString pathname, targets) {
- addPathToList(pathname);
- }
- updateTopLevelItems();
-
- viewLayout->addWidget(m_swordPathListBox);
-
- QVBoxLayout* buttonLayout = new QVBoxLayout();
-
- m_addButton = new QPushButton(tr("&Add..."), this);
- m_addButton->setToolTip(tr("Add new folder"));
- m_addButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::paths::add_icon));
- connect(m_addButton, SIGNAL(clicked()), this, SLOT(slotAddClicked()));
- buttonLayout->addWidget(m_addButton);
-
- m_editButton = new QPushButton(tr("&Edit..."), this);
- m_editButton->setToolTip(tr("Edit the selected folder"));
- m_editButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::paths::edit_icon));
- connect(m_editButton, SIGNAL(clicked()), this, SLOT(slotEditClicked()));
- buttonLayout->addWidget(m_editButton);
-
- m_removeButton = new QPushButton(tr("&Remove"), this);
- m_removeButton->setToolTip(tr("Remove the selected folder"));
- m_removeButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::paths::remove_icon));
- connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveClicked()));
- buttonLayout->addWidget(m_removeButton);
-
- QSpacerItem* spacerItem = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
- buttonLayout->addItem(spacerItem);
-
- viewLayout->addLayout(buttonLayout);
- mainLayout->addLayout(viewLayout);
-
- QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
- buttonBox->setOrientation(Qt::Horizontal);
- buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::NoButton | QDialogButtonBox::Ok);
- message::prepareDialogBox(buttonBox);
- mainLayout->addWidget(buttonBox);
- connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
- connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
- //clumsy way to set width. Could someone please fix Qt to have an easy way to set widget sizes?
- int textWidth = fontMetrics().width(rwfolderitem.append("MMMMMMMMMM"));
- int buttonWidth = m_addButton->width();
- resize(textWidth + buttonWidth, size().height());
-}
-
-BtInstallPathDialog::~BtInstallPathDialog() {
- m_swordPathListBox->invisibleRootItem()->takeChildren();
- delete m_readableItem;
- delete m_writableItem;
- delete m_nonexistingItem;
-}
-
-void BtInstallPathDialog::updateTopLevelItems() {
- if (m_writableItem->childCount()) {
- m_writableItem->setHidden(false);
- m_swordPathListBox->expandItem(m_writableItem);
- }
- else {
- m_writableItem->setHidden(true);
- }
- if (m_readableItem->childCount()) {
- m_readableItem->setHidden(false);
- m_swordPathListBox->expandItem(m_readableItem);
- }
- else {
- m_readableItem->setHidden(true);
- }
- if (m_nonexistingItem->childCount()) {
- m_nonexistingItem->setHidden(false);
- m_swordPathListBox->expandItem(m_nonexistingItem);
- }
- else {
- m_nonexistingItem->setHidden(true);
- }
-}
-
-
-void BtInstallPathDialog::addPathToList(QString pathname) {
- if (pathname.isEmpty()) return;
- QTreeWidgetItem* i = 0;
- QDir dir(pathname);
- if (!dir.exists()) {
- i = new QTreeWidgetItem(m_nonexistingItem, QStringList(pathname) );
- }
- else if (dir.isReadable()) {
- const QFileInfo fi( dir.canonicalPath() );
- if (fi.isWritable()) {
- i = new QTreeWidgetItem(m_writableItem, QStringList(pathname) );
- }
- else {
- i = new QTreeWidgetItem(m_readableItem, QStringList(pathname) );
- }
- }
- if (i && QDir(pathname) == BtInstallBackend::swordDir()) {
- i->setFlags(Qt::NoItemFlags);
- i->setToolTip(0, tr("This default folder in your home directory can't be removed"));
- }
-}
-
-void BtInstallPathDialog::slotEditClicked() {
- if (QTreeWidgetItem* i = m_swordPathListBox->currentItem()) {
- QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), i->text(0), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
-
- if (dirname.isEmpty()) { // if user cancelled the dialog
- return;
- }
- QDir dir = QDir(dirname);
- if (dir.isReadable()) {
- const QFileInfo fi( dir.canonicalPath() );
- if (!fi.exists() || !fi.isWritable()) {
- const int result = message::showWarning(this, tr("Use Folder?"), tr("This folder is not writable, so works can not be installed here using BibleTime. Do you want to use this folder instead of the previous value?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
- if (result != QMessageBox::Yes) return;
- }
- //i->setText(0, dir.absolutePath()); // absolute, not canonical
- addPathToList(dir.absolutePath());
- delete i;
- updateTopLevelItems();
- }
- }
-}
-
-void BtInstallPathDialog::slotAddClicked() {
- QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
- if (dirname.isEmpty()) { // if user cancelled the dialog
- return;
- }
- QDir dir = QDir(dirname);
- if (dir.isReadable()) {
- const QFileInfo fi( dir.canonicalPath() );
- if (!fi.exists() || !fi.isWritable()) {
- const int result = message::showWarning(this, tr("Use Folder?"), tr("This folder is not writable, so works can not be installed here using BibleTime. Do you still want to add it to the list of bookshelf folders?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
- if (result != QMessageBox::Yes) {
- return;
- }
- }
- addPathToList(util::directory::convertDirSeparators(dir.canonicalPath()));
- updateTopLevelItems();
- }
-}
-
-void BtInstallPathDialog::slotRemoveClicked() {
- QTreeWidgetItem* i = m_swordPathListBox->selectedItems().value(0);
- if (i && i->parent() != m_swordPathListBox->invisibleRootItem()) {
- delete i;
- }
- updateTopLevelItems();
-}
-
-void BtInstallPathDialog::writeSwordConfig() {
- QStringList targets;
- QTreeWidgetItemIterator it(m_swordPathListBox, QTreeWidgetItemIterator::NoChildren | QTreeWidgetItemIterator::Enabled | QTreeWidgetItemIterator::NotHidden);
- while (*it) {
- if (!(*it)->text(0).isEmpty()) {
- targets << (*it)->text(0);
- }
- ++it;
- }
- qDebug() << "save the target list" << targets;
- BtInstallBackend::setTargetList(targets); //creates new Sword config
-}
-
-void BtInstallPathDialog::accept() {
- writeSwordConfig();
- QDialog::accept();
-}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h
deleted file mode 100644
index de4c69a..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTINSTALLPATHDIALOG_H
-#define BTINSTALLPATHDIALOG_H
-
-#include <QDialog>
-
-
-class QPushButton;
-class QTreeWidget;
-class QTreeWidgetItem;
-
-class BtInstallPathDialog : public QDialog {
- Q_OBJECT
- public:
- BtInstallPathDialog();
- ~BtInstallPathDialog();
-
- public slots:
- virtual void accept();
-
- private slots:
- void slotAddClicked();
- void slotRemoveClicked();
- void slotEditClicked();
-
- private:
- void writeSwordConfig();
- void updateTopLevelItems();
- void addPathToList(QString path);
-
- private:
- QPushButton* m_editButton;
- QPushButton* m_addButton;
- QPushButton* m_removeButton;
- QTreeWidget* m_swordPathListBox;
- QTreeWidgetItem* m_writableItem;
- QTreeWidgetItem* m_readableItem;
- QTreeWidgetItem* m_nonexistingItem;
-};
-
-#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp
deleted file mode 100644
index 53fd274..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/installpage/btinstallprogressdialog.h"
-
-#include <QApplication>
-#include <QCloseEvent>
-#include <QDebug>
-#include <QDialog>
-#include <QHeaderView>
-#include <QMultiMap>
-#include <QProgressBar>
-#include <QPushButton>
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
-#include <QVBoxLayout>
-#include "backend/managers/cswordbackend.h"
-#include "backend/btinstallthread.h"
-
-
-BtInstallProgressDialog::BtInstallProgressDialog(const QList<CSwordModuleInfo *> & modules,
- const QString & destination,
- QWidget * parent,
- Qt::WindowFlags flags)
- : QDialog(parent, flags)
- , m_nextInstallIndex(0)
-{
- // we want this dialog to be deleted when user closes it or the downloads are completed
- setAttribute(Qt::WA_DeleteOnClose, true);
-
- setWindowTitle(tr("Install Progress"));
-
- m_statusWidget = new QTreeWidget();
- m_statusWidget->setRootIsDecorated(false);
- m_statusWidget->setHeaderLabels(QStringList(tr("Work")) << tr("Progress"));
- m_statusWidget->header()->setStretchLastSection(false);
-#if QT_VERSION < 0x050000
- m_statusWidget->header()->setResizeMode(1, QHeaderView::Stretch);
- m_statusWidget->header()->setMovable(false);
-#else
- m_statusWidget->header()->setSectionResizeMode(1, QHeaderView::Stretch);
- m_statusWidget->header()->setSectionsMovable(false);
-#endif
-
- Q_FOREACH(const CSwordModuleInfo * module, modules) {
- QTreeWidgetItem * progressItem = new QTreeWidgetItem(m_statusWidget);
- progressItem->setText(0, module->name());
- progressItem->setIcon(0, module->moduleIcon());
- progressItem->setText(1, tr("Waiting for turn..."));
- progressItem->setFlags(Qt::ItemIsEnabled);
- }
-
- m_statusWidget->setMinimumWidth(m_statusWidget->size().width());
- m_stopAllButton = new QPushButton(tr("Stop All"), this);
-
- QVBoxLayout * layout = new QVBoxLayout(this);
- layout->addWidget(m_statusWidget);
- layout->addWidget(m_stopAllButton);
-
- connect(m_stopAllButton, SIGNAL(clicked()),
- this, SLOT(slotStopInstall()));
-
- m_thread = new BtInstallThread(modules, destination, this);
- // Connect the signals between the dialog, items and threads
- connect(m_thread, SIGNAL(preparingInstall(int)),
- this, SLOT(slotInstallStarted(int)),
- Qt::QueuedConnection);
- connect(m_thread, SIGNAL(downloadStarted(int)),
- this, SLOT(slotDownloadStarted(int)),
- Qt::QueuedConnection);
- connect(m_thread, SIGNAL(statusUpdated(int, int)),
- this, SLOT(slotStatusUpdated(int, int)),
- Qt::QueuedConnection);
- connect(m_thread, SIGNAL(installCompleted(int, bool)),
- this, SLOT(slotOneItemCompleted(int, bool)),
- Qt::QueuedConnection);
- connect(m_thread, SIGNAL(finished()),
- this, SLOT(slotThreadFinished()),
- Qt::QueuedConnection);
- #if QT_VERSION < 0x050000
- connect(m_thread, SIGNAL(terminated()),
- this, SLOT(slotThreadFinished()),
- Qt::QueuedConnection);
- #endif
- m_thread->start();
-}
-
-BtInstallProgressDialog::~BtInstallProgressDialog() {
- m_thread->wait();
- delete m_thread;
-}
-
-void BtInstallProgressDialog::slotStopInstall() {
- m_stopAllButton->setDisabled(true);
- m_thread->stopInstall();
- for (int i = m_nextInstallIndex; i < m_statusWidget->topLevelItemCount(); i++) {
- QTreeWidgetItem * const item = m_statusWidget->topLevelItem(i);
- item->setText(1, QString::null);
- item->setDisabled(true);
- }
-}
-
-void BtInstallProgressDialog::slotInstallStarted(int moduleIndex) {
- Q_ASSERT(moduleIndex == m_nextInstallIndex);
- m_nextInstallIndex++;
- QTreeWidgetItem * const item = m_statusWidget->topLevelItem(moduleIndex);
- item->setText(1, tr("Preparing install..."));
- m_statusWidget->scrollToItem(item);
-}
-
-void BtInstallProgressDialog::slotDownloadStarted(int moduleIndex) {
- QTreeWidgetItem * const item = m_statusWidget->topLevelItem(moduleIndex);
- item->setText(1, QString::null);
- getOrCreateProgressBar(item)->setValue(0);
-}
-
-void BtInstallProgressDialog::slotStatusUpdated(int moduleIndex, int status) {
- // find the progress bar for this module and update the value
- getOrCreateProgressBar(moduleIndex)->setValue(status);
-}
-
-void BtInstallProgressDialog::slotOneItemCompleted(int moduleIndex, bool successful) {
-QTreeWidgetItem * const item = m_statusWidget->topLevelItem(moduleIndex);
- // update the list item
- m_statusWidget->setItemWidget(item, 1, NULL);
- item->setText(1, successful ? tr("Completed") : tr("Failed"));
- item->setDisabled(true);
-}
-
-void BtInstallProgressDialog::slotThreadFinished() {
- close();
-}
-
-void BtInstallProgressDialog::closeEvent(QCloseEvent * event) {
- if (event->spontaneous()) {
- event->ignore();
- slotStopInstall();
- return;
- }
- // other parts of the UI/engine must be updated
- CSwordBackend::instance()->reloadModules(CSwordBackend::AddedModules);
-}
-
-QProgressBar * BtInstallProgressDialog::getOrCreateProgressBar(int moduleIndex) {
- return getOrCreateProgressBar(m_statusWidget->topLevelItem(moduleIndex));
-}
-
-QProgressBar * BtInstallProgressDialog::getOrCreateProgressBar(QTreeWidgetItem * item) {
- QWidget * const itemWidget = m_statusWidget->itemWidget(item, 1);
- QProgressBar * progressBar = dynamic_cast<QProgressBar *>(itemWidget);
- if (!progressBar) {
- progressBar = new QProgressBar(m_statusWidget);
- progressBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- m_statusWidget->setItemWidget(item, 1, progressBar);
- }
- return progressBar;
-}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h
deleted file mode 100644
index e6add1c..0000000
--- a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTINSTALLPROGRESSDIALOG_H
-#define BTINSTALLPROGRESSDIALOG_H
-
-#include <QDialog>
-
-#include <QString>
-
-
-class BtInstallThread;
-class CSwordModuleInfo;
-class QProgressBar;
-class QTreeWidget;
-class QTreeWidgetItem;
-
-class BtInstallProgressDialog: public QDialog {
-
- Q_OBJECT
-
-public: /* Methods: */
-
- BtInstallProgressDialog(const QList<CSwordModuleInfo *> & modules,
- const QString & destination,
- QWidget * parent = 0,
- Qt::WindowFlags flags = 0);
- ~BtInstallProgressDialog();
-
-public slots:
-
- void slotStopInstall();
- void slotInstallStarted(int moduleIndex);
- void slotDownloadStarted(int moduleIndex);
- void slotStatusUpdated(int moduleIndex, int status);
- void slotOneItemCompleted(int moduleIndex, bool status);
- void slotThreadFinished();
-
-protected: /* Methods: */
-
- /**
- Handles closing by the window close button, Cancel (Stop) All button, or
- completing the downloads.
- */
- virtual void closeEvent(QCloseEvent * event);
-
-private: /* Methods: */
-
- QProgressBar * getOrCreateProgressBar(int moduleIndex);
- QProgressBar * getOrCreateProgressBar(QTreeWidgetItem * item);
-
-private: /* Fields: */
-
- QTreeWidget * m_statusWidget;
- QPushButton * m_stopAllButton;
- BtInstallThread * m_thread;
- int m_nextInstallIndex;
-
-};
-
-#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.cpp b/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.cpp
deleted file mode 100644
index 856f58b..0000000
--- a/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "frontend/bookshelfmanager/installpage/btrefreshprogressdialog.h"
-
-#include <QApplication>
-#include "backend/btinstallbackend.h"
-#include "frontend/messagedialog.h"
-
-
-BtRefreshProgressDialog::BtRefreshProgressDialog(sword::InstallSource &source,
- QWidget *parent,
- Qt::WindowFlags flags)
- : QProgressDialog(parent, flags)
- , m_source(source)
-{
- Q_ASSERT(BtInstallBackend::isRemote(source));
- setWindowTitle(tr("Refreshing source %1").arg(QString(source.caption)));
- setCancelButtonText(tr("&Cancel"));
- setLabelText(tr("Connecting..."));
- Q_ASSERT(minimum() == 0);
- setMaximum(100);
- setValue(0);
- setWindowModality(Qt::ApplicationModal);
- setMinimumDuration(1000);
-
- connect(this, SIGNAL(canceled()),
- this, SLOT(slotCanceled()));
- connect(&m_installMgr, SIGNAL(percentCompleted(int,int)),
- this, SLOT(slotPercentCompleted(int,int)));
-}
-
-void BtRefreshProgressDialog::slotPercentCompleted(int, int current) {
- setValue(current);
- qApp->processEvents();
-}
-
-void BtRefreshProgressDialog::slotCanceled() {
- m_installMgr.terminate();
-}
-
-bool BtRefreshProgressDialog::runAndDelete() {
- show();
- qApp->processEvents();
- bool r = (m_installMgr.refreshRemoteSource(&m_source) == 0);
- if (r) {
- setValue(100);
- qApp->processEvents();
- } else {
- message::showWarning(this, tr("Warning"),
- tr("Failed to refresh source %1")
- .arg(QString(m_source.caption)));
- }
- deleteLater();
- return r;
-}
diff --git a/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.h b/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.h
deleted file mode 100644
index 03f82c9..0000000
--- a/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTREFRESHPROGRESSDIALOG_H
-#define BTREFRESHPROGRESSDIALOG_H
-
-#include <QProgressDialog>
-
-#include "backend/btinstallmgr.h"
-
-
-class BtRefreshProgressDialog: public QProgressDialog {
- Q_OBJECT
-
- public: /* Methods: */
- BtRefreshProgressDialog(sword::InstallSource &source,
- QWidget *parent = 0, Qt::WindowFlags f = 0);
-
- bool runAndDelete();
-
- private slots:
-
- void slotPercentCompleted(int, int);
- void slotCanceled();
-
- private: /* Fields: */
-
- sword::InstallSource m_source;
- BtInstallMgr m_installMgr;
-};
-
-#endif // BTREFRESHPROGRESSDIALOG_H
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepage.cpp b/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
deleted file mode 100644
index 57879ea..0000000
--- a/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
+++ /dev/null
@@ -1,194 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License
-* version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/removepage/btremovepage.h"
-
-#include <QAction>
-#include <QDebug>
-#include <QGroupBox>
-#include <QHBoxLayout>
-#include <QHeaderView>
-#include <QPushButton>
-#include <QToolButton>
-#include <QVBoxLayout>
-#include "backend/bookshelfmodel/btbookshelffiltermodel.h"
-#include "backend/managers/cswordbackend.h"
-#include "bibletimeapp.h"
-#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
-#include "frontend/btbookshelfview.h"
-#include "frontend/btbookshelfwidget.h"
-#include "frontend/messagedialog.h"
-#include "util/cresmgr.h"
-#include "util/directory.h"
-#include "util/geticon.h"
-
-// Sword includes:
-#include <swmgr.h>
-#include <installmgr.h>
-
-
-namespace {
-const QString groupingOrderKey("GUI/BookshelfManager/RemovePage/grouping");
-}
-
-BtRemovePage::BtRemovePage(BtModuleManagerDialog *parent)
- : BtConfigDialog::Page(util::getIcon(CResMgr::bookshelfmgr::removepage::icon), parent)
-{
- m_worksGroupBox = new QGroupBox(this);
- m_worksGroupBox->setFlat(true);
- QVBoxLayout *wLayout = new QVBoxLayout;
- wLayout->setContentsMargins(0, 0, 0, 0);
- m_worksGroupBox->setLayout(wLayout);
-
- BtRemovePageTreeModel *treeModel = new BtRemovePageTreeModel(groupingOrderKey,
- this);
- connect(treeModel, SIGNAL(groupingOrderChanged(BtBookshelfTreeModel::Grouping)),
- this, SLOT(slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping&)));
-
- m_bookshelfWidget = new BtBookshelfWidget(this);
- m_bookshelfWidget->postFilterModel()->setShowHidden(true);
- m_bookshelfWidget->setTreeModel(treeModel);
- m_bookshelfWidget->setSourceModel(CSwordBackend::instance()->model());
- m_bookshelfWidget->showHideAction()->setVisible(false);
- m_bookshelfWidget->showHideButton()->hide();
- m_bookshelfWidget->treeView()->header()->show();
-#if QT_VERSION < 0x050000
- m_bookshelfWidget->treeView()->header()->setResizeMode(QHeaderView::ResizeToContents);
-#else
- m_bookshelfWidget->treeView()->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
-#endif
- wLayout->addWidget(m_bookshelfWidget);
-
- m_uninstallGroupBox = new QGroupBox(this);
- m_uninstallGroupBox->setFlat(true);
- QHBoxLayout *uLayout = new QHBoxLayout;
- uLayout->setContentsMargins(0, 0, 0, 0);
- m_uninstallGroupBox->setLayout(uLayout);
- uLayout->addStretch(1);
-
- m_removeButton = new QPushButton(this);
- m_removeButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::removepage::remove_icon));
- m_removeButton->setEnabled(false);
- uLayout->addWidget(m_removeButton, 0, Qt::AlignRight);
-
- QVBoxLayout *mainLayout = new QVBoxLayout(this);
- mainLayout->addWidget(m_worksGroupBox, 1);
- mainLayout->addWidget(m_uninstallGroupBox);
-
- connect(m_removeButton, SIGNAL(clicked()),
- this, SLOT(slotRemoveModules()));
- connect(m_bookshelfWidget->treeModel(), SIGNAL(moduleChecked(CSwordModuleInfo*,bool)),
- this, SLOT(slotResetRemoveButton()));
- connect(m_bookshelfWidget->treeModel(), SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
- this, SLOT(slotResetRemoveButton()));
-
- retranslateUi();
-}
-
-void BtRemovePage::retranslateUi() {
- setHeaderText(tr("Remove"));
-
- m_worksGroupBox->setTitle(tr("Select &works to uninstall:"));
-
- m_removeButton->setText(tr("&Remove..."));
- m_removeButton->setToolTip(tr("Remove the selected works"));
-
- retranslateUninstallGroupBox();
-}
-
-void BtRemovePage::retranslateUninstallGroupBox() {
- int count = m_bookshelfWidget->treeModel()->checkedModules().count();
- if (count > 0) {
- m_uninstallGroupBox->setTitle(tr("Start removal of %1 works:")
- .arg(count));
- } else {
- m_uninstallGroupBox->setTitle(tr("Start removal:"));
- }
-}
-
-void BtRemovePage::slotResetRemoveButton() {
- retranslateUninstallGroupBox();
- m_removeButton->setEnabled(!m_bookshelfWidget->treeModel()->checkedModules().empty());
-}
-
-void BtRemovePage::slotRemoveModules() {
- // Do nothing when this signal fires without anything selected to remove:
- if (m_bookshelfWidget->treeModel()->checkedModules().empty()) return;
-
- QStringList moduleNames;
- QStringList prettyModuleNames;
- const int textHeight = fontMetrics().height();
- /// \bug <nobr> is not working, Qt bug
- const QString moduleString("<nobr><img src=\"%1\" width=\"%2\" height=\"%3\"/>&nbsp;%4</nobr>");
- const QString iconDir = util::directory::getIconDir().canonicalPath() + '/';
- Q_FOREACH(const CSwordModuleInfo * m,
- m_bookshelfWidget->treeModel()->checkedModules())
- {
- const QIcon icon = CSwordModuleInfo::moduleIcon(*m);
- const QSize iconSize = icon.actualSize(QSize(textHeight, textHeight));
- prettyModuleNames.append(moduleString
- .arg(iconDir + CSwordModuleInfo::moduleIconFilename(*m))
- .arg(iconSize.width())
- .arg(iconSize.height())
- .arg(m->name()));
- moduleNames.append(m->name());
- }
- const QString message = tr("You selected the following work(s): ")
- .append("<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;")
- .append(prettyModuleNames.join(",&nbsp; "))
- .append("<br/><br/>")
- .append(tr("Do you really want to remove them from your system?"));
-
- if ((message::showQuestion(this, tr("Remove Works?"), message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)) { //Yes was pressed.
-
- // Update the module list before really removing. Remember deleting the pointers later.
- QList<CSwordModuleInfo*> toBeDeleted = CSwordBackend::instance()->takeModulesFromList(moduleNames);
- Q_ASSERT(toBeDeleted.size() == moduleNames.size());
-
- sword::InstallMgr installMgr;
- QMap<QString, sword::SWMgr*> mgrDict; //maps config paths to SWMgr objects
- foreach ( CSwordModuleInfo* mInfo, toBeDeleted ) {
- Q_ASSERT(mInfo); // Only installed modules could have been selected and returned by takeModulesFromList
- // Find the install path for the sword manager
- QString prefixPath = mInfo->config(CSwordModuleInfo::AbsoluteDataPath) + "/";
- QString dataPath = mInfo->config(CSwordModuleInfo::DataPath);
- if (dataPath.left(2) == "./") {
- dataPath = dataPath.mid(2);
- }
- if (prefixPath.contains(dataPath)) { //remove module part to get the prefix path
- prefixPath = prefixPath.remove( prefixPath.indexOf(dataPath), dataPath.length() );
- }
- else { //This is an error, should not happen
- qWarning() << "Removing" << mInfo->name() << "didn't succeed because the absolute path" << prefixPath << "didn't contain the data path" << dataPath;
- continue; // don't remove this, go to next of the for loop
- }
-
- // Create the sword manager and remove the module
- sword::SWMgr* mgr = mgrDict[ prefixPath ];
- if (!mgr) { //create new mgr if it's not yet available
- mgrDict.insert(prefixPath, new sword::SWMgr(prefixPath.toLocal8Bit()));
- mgr = mgrDict[ prefixPath ];
- }
- qDebug() << "Removing the module" << mInfo->name() << "...";
- installMgr.removeModule(mgr, mInfo->module()->getName());
- }
- //delete the removed moduleinfo pointers
- qDeleteAll(toBeDeleted);
- //delete all mgrs which were created above
- qDeleteAll(mgrDict);
- mgrDict.clear();
- }
-}
-
-void BtRemovePage::slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping &g) {
- g.saveTo(groupingOrderKey);
-}
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepage.h b/src/frontend/bookshelfmanager/removepage/btremovepage.h
deleted file mode 100644
index a9600d8..0000000
--- a/src/frontend/bookshelfmanager/removepage/btremovepage.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License
-* version 2.0.
-*
-**********/
-
-#ifndef BTREMOVEPAGE_H
-#define BTREMOVEPAGE_H
-
-#include "frontend/bookshelfmanager/btconfigdialog.h"
-
-#include <QMultiMap>
-#include <QString>
-#include "backend/btmoduletreeitem.h"
-#include "frontend/bookshelfmanager/removepage/btremovepagetreemodel.h"
-
-
-class BtBookshelfWidget;
-class BtModuleManagerDialog;
-class QGroupBox;
-class QPushButton;
-
-class BtRemovePage: public BtConfigDialog::Page {
-
- Q_OBJECT
-
- public: /* Methods: */
-
- BtRemovePage(BtModuleManagerDialog *parent = 0);
-
- public: /* Methods: */
-
- void retranslateUi();
-
- private: /* Methods: */
-
- void retranslateUninstallGroupBox();
-
- private slots:
-
- void slotRemoveModules();
- void slotResetRemoveButton();
- void slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping &g);
-
- private: /* Fields: */
-
- QGroupBox *m_worksGroupBox;
- BtBookshelfWidget *m_bookshelfWidget;
-
- QGroupBox *m_uninstallGroupBox;
- QPushButton *m_removeButton;
-
-};
-
-#endif
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepagetreemodel.cpp b/src/frontend/bookshelfmanager/removepage/btremovepagetreemodel.cpp
deleted file mode 100644
index 9fce7ab..0000000
--- a/src/frontend/bookshelfmanager/removepage/btremovepagetreemodel.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License
-* version 2.0.
-*
-**********/
-
-#include "frontend/bookshelfmanager/removepage/btremovepagetreemodel.h"
-
-
-BtRemovePageTreeModel::BtRemovePageTreeModel(const QString &configKey, QObject *parent)
- : BtBookshelfTreeModel(configKey, parent)
-{
- setCheckable(true);
- setDefaultChecked(BtBookshelfTreeModel::UNCHECKED);
-}
-
-int BtRemovePageTreeModel::columnCount(const QModelIndex &parent) const {
- Q_UNUSED(parent);
-
- return 2;
-}
-
-QVariant BtRemovePageTreeModel::data(const QModelIndex &i, int role) const {
- if (i.column() == 1) {
- QModelIndex realIndex(index(i.row(), 0, i.parent()));
- switch (role) {
- case Qt::DisplayRole:
- case Qt::ToolTipRole:
- return BtBookshelfTreeModel::data(realIndex, BtBookshelfModel::ModuleInstallPathRole);
- default:
- break;
- }
- }
- else {
- return BtBookshelfTreeModel::data(i, role);
- }
-
- return QVariant();
-}
-
-QVariant BtRemovePageTreeModel::headerData(int section,
- Qt::Orientation orientation,
- int role) const {
- if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
- if (section == 0) {
- return tr("Work");
- }
- else if (section == 1) {
- return tr("Install path");
- }
- }
-
- return QVariant();
-}
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepagetreemodel.h b/src/frontend/bookshelfmanager/removepage/btremovepagetreemodel.h
deleted file mode 100644
index 50da32b..0000000
--- a/src/frontend/bookshelfmanager/removepage/btremovepagetreemodel.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License
-* version 2.0.
-*
-**********/
-
-#ifndef BTREMOVEPAGETREEMODEL_H
-#define BTREMOVEPAGETREEMODEL_H
-
-#include "backend/bookshelfmodel/btbookshelftreemodel.h"
-
-class BtRemovePageTreeModel: public BtBookshelfTreeModel {
- Q_OBJECT
-
- public:
- BtRemovePageTreeModel(const QString &configKey, QObject *parent = 0);
-
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
-};
-
-#endif // BTREMOVEPAGETREEMODEL_H
diff --git a/src/frontend/bookshelfwizard/btbookshelfinstallfinalpage.cpp b/src/frontend/bookshelfwizard/btbookshelfinstallfinalpage.cpp
new file mode 100644
index 0000000..b91a732
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfinstallfinalpage.cpp
@@ -0,0 +1,189 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "frontend/bookshelfwizard/btbookshelfinstallfinalpage.h"
+
+#include <QApplication>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QProgressBar>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include "backend/btinstallbackend.h"
+#include "backend/btinstallthread.h"
+#include "frontend/bookshelfwizard/btbookshelfwizard.h"
+#include "frontend/bookshelfwizard/btbookshelfwizardenums.h"
+#include "util/btconnect.h"
+
+
+namespace {
+QString const groupingOrderKey = "GUI/BookshelfWizard/InstallPage/grouping";
+QString const installPathKey =
+ "GUI/BookshelfWizard/InstallPage/installPathIndex";
+} // anonymous namespace
+
+BtBookshelfInstallFinalPage::BtBookshelfInstallFinalPage(QWidget * parent)
+ : BtBookshelfWizardPage(parent)
+{
+ // Setup UI:
+ m_verticalLayout = new QVBoxLayout(this);
+ m_verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
+
+ m_verticalLayout->addItem(new QSpacerItem(20,
+ 40,
+ QSizePolicy::Minimum,
+ QSizePolicy::Expanding));
+
+ m_msgLabel = new QLabel(this);
+ m_msgLabel->setAlignment(Qt::AlignCenter);
+ m_msgLabel->setWordWrap(true);
+ m_verticalLayout->addWidget(m_msgLabel);
+
+ m_msgLabel2 = new QLabel(this);
+ m_msgLabel2->setAlignment(Qt::AlignCenter);
+ m_msgLabel2->setWordWrap(true);
+ m_verticalLayout->addWidget(m_msgLabel2);
+
+ m_progressBar = new QProgressBar(this);
+ m_progressBar->setObjectName("progressBar");
+ m_progressBar->setMinimum(0);
+ m_progressBar->setMaximum(100);
+ m_verticalLayout->addWidget(m_progressBar,Qt::AlignCenter);
+
+ QHBoxLayout * const horizontalLayout = new QHBoxLayout();
+ m_stopButton = new QPushButton(this);
+ horizontalLayout->addSpacerItem(
+ new QSpacerItem(1, 1, QSizePolicy::Expanding));
+ horizontalLayout->addWidget(m_stopButton);
+ horizontalLayout->addSpacerItem(
+ new QSpacerItem(1, 1, QSizePolicy::Expanding));
+ m_verticalLayout->addLayout(horizontalLayout);
+
+ m_verticalLayout->addItem(new QSpacerItem(20,
+ 40,
+ QSizePolicy::Minimum,
+ QSizePolicy::Expanding));
+
+ // Initialize connections:
+ BT_CONNECT(m_stopButton, &QPushButton::clicked,
+ this, &BtBookshelfInstallFinalPage::slotStopInstall);
+}
+
+void BtBookshelfInstallFinalPage::destroyThread() noexcept {
+ if (m_thread) {
+ m_thread->stopInstall();
+ while (!m_thread->wait()) /* join */;
+ delete m_thread;
+ m_thread = nullptr;
+ }
+}
+
+void BtBookshelfInstallFinalPage::retranslateUi() {
+ m_stopButton->setText(tr("Stop"));
+
+ if (btWizard().taskType() == WizardTaskType::updateWorks) {
+ setTitle(QApplication::translate(
+ "BookshelfWizard", "Updating Works"));
+ setSubTitle(QApplication::translate(
+ "BookshelfWizard",
+ "The selected works are being updated."));
+ } else {
+ setTitle(QApplication::translate(
+ "BookshelfWizard", "Installing Works"));
+ setSubTitle(QApplication::translate(
+ "BookshelfWizard",
+ "The selected works are being installed."));
+ }
+}
+
+int BtBookshelfInstallFinalPage::nextId() const { return -1; }
+
+void BtBookshelfInstallFinalPage::initializePage() {
+ destroyThread();
+ retranslateUi();
+
+ // Install works:
+ auto & btWiz = btWizard();
+ m_modules = btWiz.selectedWorks().toList();
+ m_thread = new BtInstallThread(m_modules, btWiz.installPath(), this);
+ BT_CONNECT(m_thread, &BtInstallThread::preparingInstall,
+ this, &BtBookshelfInstallFinalPage::slotInstallStarted,
+ Qt::QueuedConnection);
+ BT_CONNECT(m_thread, &BtInstallThread::statusUpdated,
+ this, &BtBookshelfInstallFinalPage::slotStatusUpdated,
+ Qt::QueuedConnection);
+ BT_CONNECT(m_thread, &BtInstallThread::installCompleted,
+ this, &BtBookshelfInstallFinalPage::slotOneItemCompleted,
+ Qt::QueuedConnection);
+ BT_CONNECT(m_thread, &BtInstallThread::finished,
+ this, &BtBookshelfInstallFinalPage::slotThreadFinished,
+ Qt::QueuedConnection);
+ m_progressBar->setValue(0);
+ m_stopButton->setEnabled(true);
+ m_installFailed = false;
+ m_installCompleted = false;
+ m_thread->start();
+ btWiz.downloadStarted();
+}
+
+bool BtBookshelfInstallFinalPage::isComplete() const
+{ return m_installCompleted; }
+
+void BtBookshelfInstallFinalPage::slotStopInstall() {
+ m_stopButton->setDisabled(true);
+ m_thread->stopInstall();
+ m_installFailed = true;
+}
+
+void BtBookshelfInstallFinalPage::slotInstallStarted(int moduleIndex) {
+ m_msgLabel->setText(
+ tr("Installing \"%1\"").arg(m_modules.at(moduleIndex)->name()));
+ m_msgLabel2->setText(m_modules.at(moduleIndex)->config(CSwordModuleInfo::Description));
+ m_lastStatus = -1;
+}
+
+void BtBookshelfInstallFinalPage::slotStatusUpdated(int moduleIndex, int status)
+{
+ // Skip initial high value sent by sword
+ if ((m_lastStatus == -1 && status > 80) || (m_lastStatus == status))
+ return;
+
+ m_lastStatus = status;
+
+ int const perModuleIncrement = 100 / m_modules.count();
+ m_progressBar->setValue((moduleIndex * perModuleIncrement)
+ + (status * perModuleIncrement / 100));
+}
+
+void BtBookshelfInstallFinalPage::slotOneItemCompleted(int moduleIndex,
+ bool successful)
+{
+ m_progressBar->setValue((moduleIndex + 1) * (100 / m_modules.count()));
+ if (!successful)
+ m_installFailed = true;
+}
+
+void BtBookshelfInstallFinalPage::slotThreadFinished() {
+ m_progressBar->setValue(100);
+ m_stopButton->setEnabled(false);
+ if (m_installFailed) {
+ m_msgLabel->setText(tr("Some of the selected works were not "
+ "installed."));
+ m_msgLabel->setStyleSheet("QLabel{color:red}");
+ } else {
+ m_msgLabel->setText(tr("The selected works have been installed."));
+ }
+ m_msgLabel2->setText("");
+
+ CSwordBackend::instance()->reloadModules(CSwordBackend::AddedModules);
+
+ m_installCompleted = true;
+ emit QWizardPage::completeChanged();
+ btWizard().downloadFinished();
+}
diff --git a/src/frontend/bookshelfwizard/btbookshelfinstallfinalpage.h b/src/frontend/bookshelfwizard/btbookshelfinstallfinalpage.h
new file mode 100644
index 0000000..6938384
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfinstallfinalpage.h
@@ -0,0 +1,77 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKSHELFINSTALLFINALPAGE
+#define BTBOOKSHELFINSTALLFINALPAGE
+
+#include "btbookshelfwizardpage.h"
+
+#include <QList>
+#include "backend/drivers/btmoduleset.h"
+
+
+class BtBookshelfWizard;
+class BtInstallThread;
+class QLabel;
+class QProgressBar;
+class QPushButton;
+class QSwordModuleInfo;
+class QVBoxLayout;
+
+class BtBookshelfInstallFinalPage final: public BtBookshelfWizardPage {
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ BtBookshelfInstallFinalPage(QWidget * parent = 0);
+ inline ~BtBookshelfInstallFinalPage() noexcept final override
+ { destroyThread(); }
+
+ void destroyThread() noexcept;
+
+ void initializePage() final override;
+ bool isComplete() const final override;
+ int nextId() const final override;
+ BtModuleSet selectedWorks() const;
+
+public slots:
+ void slotStopInstall();
+
+private slots:
+
+ void slotInstallStarted(int moduleIndex);
+ void slotOneItemCompleted(int moduleIndex, bool status);
+ void slotStatusUpdated(int moduleIndex, int status);
+ void slotThreadFinished();
+
+private: /* Methods: */
+
+ void retranslateUi();
+
+private: /* Fields: */
+
+ QLabel * m_msgLabel;
+ QLabel * m_msgLabel2;
+ QProgressBar * m_progressBar;
+ QPushButton * m_stopButton;
+ BtInstallThread * m_thread = nullptr;
+ QVBoxLayout * m_verticalLayout;
+
+ bool m_installFailed;
+ bool m_installCompleted;
+
+ QList<CSwordModuleInfo *> m_modules;
+ int m_lastStatus;
+
+}; /* class BtBookshelfInstallFinalPage */
+
+#endif
diff --git a/src/frontend/bookshelfwizard/btbookshelflanguagespage.cpp b/src/frontend/bookshelfwizard/btbookshelflanguagespage.cpp
new file mode 100644
index 0000000..b422172
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelflanguagespage.cpp
@@ -0,0 +1,122 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "frontend/bookshelfwizard/btbookshelflanguagespage.h"
+
+#include <QApplication>
+#include <QHBoxLayout>
+#include <QListView>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <set>
+#include "backend/btinstallbackend.h"
+#include "backend/config/btconfig.h"
+#include "backend/managers/clanguagemgr.h"
+#include "backend/models/btlistmodel.h"
+#include "frontend/bookshelfwizard/btbookshelfwizard.h"
+#include "frontend/bookshelfwizard/btbookshelfwizardenums.h"
+#include "util/btconnect.h"
+
+
+namespace {
+QString const LanguagesKey = "GUI/BookshelfWizard/languages";
+} // anonymous namespace
+
+BtBookshelfLanguagesPage::BtBookshelfLanguagesPage(QWidget * parent)
+ : BtBookshelfWizardPage(parent)
+{
+ // Setup UI:
+ m_verticalLayout = new QVBoxLayout(this);
+ m_verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
+ m_languagesListView = new QListView(this);
+ m_languagesListView->setObjectName(QStringLiteral("languagesListView"));
+ m_verticalLayout->addWidget(m_languagesListView);
+
+ // Create languages Model:
+ m_model = new BtListModel(true, this);
+ m_languagesListView->setModel(m_model);
+ BT_CONNECT(m_model, &QStandardItemModel::dataChanged,
+ this, &BtBookshelfLanguagesPage::slotDataChanged);
+}
+
+void BtBookshelfLanguagesPage::retranslateUi() {
+ setTitle(QApplication::translate("BookshelfWizard", "Choose Languages"));
+ setSubTitle(QApplication::translate("BookshelfWizard",
+ "Choose one or more languages to "
+ "install works from."));
+}
+
+int BtBookshelfLanguagesPage::nextId() const
+{ return WizardPage::installWorksPage; }
+
+void BtBookshelfLanguagesPage::initializePage() {
+
+ { // Select languages:
+ QStringList languages;
+ if (m_firstTimeInit) {
+ languages << btConfig().value<QStringList>(LanguagesKey,
+ QStringList{});
+ if (languages.isEmpty())
+ languages << tr("English");
+ m_firstTimeInit = false;
+ } else {
+ languages << selectedLanguages();
+ }
+
+ bool scrolledToFirstSelected = false;
+ for (int row = 0; row < m_model->rowCount(); ++row) {
+ QStandardItem * const item = m_model->item(row, 0);
+ if (languages.contains(item->text())) {
+ item->setCheckState(Qt::Checked);
+ // Scroll to first selected item:
+ if (!scrolledToFirstSelected) {
+ m_languagesListView->scrollTo(m_model->indexFromItem(item));
+ scrolledToFirstSelected = true;
+ }
+ }
+ }
+ }
+
+ retranslateUi();
+}
+
+void BtBookshelfLanguagesPage::initializeLanguages() {
+ // Get languages from sources:
+ std::set<QString> languages;
+ for (auto const & sourceName : btWizard().selectedSources())
+ for (auto const * module :
+ BtInstallBackend::backend(
+ BtInstallBackend::source(sourceName))->moduleList())
+ languages.insert(module->language()->translatedName());
+
+ // Update languages model:
+ m_model->clear();
+ for (auto const & lang : languages)
+ m_model->appendItem(lang);
+ if (languages.size() == 1u)
+ m_model->item(0, 0)->setCheckState(Qt::Checked);
+}
+
+bool BtBookshelfLanguagesPage::skipPage() const noexcept
+{ return m_model->rowCount() == 1; }
+
+void BtBookshelfLanguagesPage::slotDataChanged() { emit completeChanged(); }
+
+bool BtBookshelfLanguagesPage::isComplete() const
+{ return selectedLanguages().count() > 0; }
+
+QStringList BtBookshelfLanguagesPage::selectedLanguages() const {
+ QStringList languages;
+ for (int row = 0; row < m_model->rowCount(); ++row) {
+ QStandardItem * const item = m_model->item(row,0);
+ if (item->checkState() == Qt::Checked)
+ languages << item->text();
+ }
+ return languages;
+}
diff --git a/src/frontend/bookshelfwizard/btbookshelflanguagespage.h b/src/frontend/bookshelfwizard/btbookshelflanguagespage.h
new file mode 100644
index 0000000..12b1a30
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelflanguagespage.h
@@ -0,0 +1,57 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKSHELFLANGUAGESPAGE
+#define BTBOOKSHELFLANGUAGESPAGE
+
+#include "frontend/bookshelfwizard/btbookshelfwizardpage.h"
+
+#include <QStringList>
+
+
+class BtBookshelfWizard;
+class BtListModel;
+class QListView;
+class QVBoxLayout;
+
+class BtBookshelfLanguagesPage final: public BtBookshelfWizardPage {
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ BtBookshelfLanguagesPage(QWidget * parent = 0);
+
+ void initializeLanguages();
+ void initializePage() final override;
+ bool isComplete() const final override;
+ int nextId() const final override;
+ QStringList selectedLanguages() const;
+ bool skipPage() const noexcept;
+
+private slots:
+
+ void slotDataChanged();
+
+private: /* Methods: */
+
+ void retranslateUi();
+
+private: /* Fields: */
+
+ bool m_firstTimeInit = true;
+ QListView * m_languagesListView;
+ QVBoxLayout * m_verticalLayout;
+ BtListModel * m_model;
+
+}; /* class BtBookshelfLanguagesPage */
+
+#endif
diff --git a/src/frontend/bookshelfwizard/btbookshelfremovefinalpage.cpp b/src/frontend/bookshelfwizard/btbookshelfremovefinalpage.cpp
new file mode 100644
index 0000000..1c4eb36
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfremovefinalpage.cpp
@@ -0,0 +1,61 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "frontend/bookshelfwizard/btbookshelfremovefinalpage.h"
+
+#include <QDebug>
+#include <QLabel>
+#include <QSpacerItem>
+#include <QVBoxLayout>
+#include "backend/managers/cswordbackend.h"
+#include "frontend/bookshelfwizard/btbookshelfwizard.h"
+#include "util/btconnect.h"
+
+
+namespace {
+const QString groupingOrderKey ("GUI/BookshelfWizard/InstallPage/grouping");
+const QString installPathKey ("GUI/BookshelfWizard/InstallPage/installPathIndex");
+} // anonymous namespace
+
+BtBookshelfRemoveFinalPage::BtBookshelfRemoveFinalPage(QWidget * parent)
+ : BtBookshelfWizardPage(parent)
+{
+ m_verticalLayout = new QVBoxLayout(this);
+ m_verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
+
+ m_verticalLayout->addItem(new QSpacerItem(20,
+ 40,
+ QSizePolicy::Minimum,
+ QSizePolicy::Expanding));
+
+ m_msgLabel = new QLabel(this);
+ m_msgLabel->setAlignment(Qt::AlignCenter);
+ m_msgLabel->setObjectName(QStringLiteral("msgLabel"));
+ m_msgLabel->setWordWrap(true);
+ m_verticalLayout->addWidget(m_msgLabel);
+
+ m_verticalLayout->addItem(new QSpacerItem(20,
+ 40,
+ QSizePolicy::Minimum,
+ QSizePolicy::Expanding));
+}
+
+void BtBookshelfRemoveFinalPage::retranslateUi()
+{ m_msgLabel->setText(tr("The selected works have been removed.")); }
+
+void BtBookshelfRemoveFinalPage::initializePage() {
+ retranslateUi();
+
+ // Remove works:
+ CSwordBackend::instance()->uninstallModules(btWizard().selectedWorks());
+}
+
+bool BtBookshelfRemoveFinalPage::isComplete() const { return true; }
+
+int BtBookshelfRemoveFinalPage::nextId() const { return -1; }
diff --git a/src/frontend/bookshelfwizard/btbookshelfremovefinalpage.h b/src/frontend/bookshelfwizard/btbookshelfremovefinalpage.h
new file mode 100644
index 0000000..a081fba
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfremovefinalpage.h
@@ -0,0 +1,48 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKSHELFREMOVEFINALPAGE
+#define BTBOOKSHELFREMOVEFINALPAGE
+
+#include "frontend/bookshelfwizard/btbookshelfwizardpage.h"
+
+#include "backend/bookshelfmodel/btbookshelftreemodel.h"
+#include "backend/drivers/btmoduleset.h"
+
+
+class BtBookshelfWizard;
+class QLabel;
+class QVBoxLayout;
+
+class BtBookshelfRemoveFinalPage final: public BtBookshelfWizardPage {
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ BtBookshelfRemoveFinalPage(QWidget * parent = 0);
+
+ bool isComplete() const final override;
+ void initializePage() final override;
+ int nextId() const final override;
+
+private: /* Methods: */
+
+ void retranslateUi();
+
+private: /* Fields: */
+
+ QLabel * m_msgLabel;
+ QVBoxLayout * m_verticalLayout;
+
+}; /* class BtBookshelfRemoveFinalPage */
+
+#endif
diff --git a/src/frontend/bookshelfwizard/btbookshelfsourcespage.cpp b/src/frontend/bookshelfwizard/btbookshelfsourcespage.cpp
new file mode 100644
index 0000000..c0af1a3
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfsourcespage.cpp
@@ -0,0 +1,208 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "frontend/bookshelfwizard/btbookshelfsourcespage.h"
+
+#include <QAbstractItemView>
+#include <QApplication>
+#include <QDate>
+#include <QHBoxLayout>
+#include <QHeaderView>
+#include <QMessageBox>
+#include <QModelIndex>
+#include <QProgressDialog>
+#include <QPushButton>
+#include <QSignalMapper>
+#include <QTableView>
+#include <QtGlobal>
+#include <QVBoxLayout>
+#include "backend/config/btconfig.h"
+#include "backend/btinstallbackend.h"
+#include "backend/btinstallmgr.h"
+#include "backend/models/btlistmodel.h"
+#include "frontend/bookshelfwizard/cswordsetupinstallsourcesdialog.h"
+#include "frontend/bookshelfwizard/btbookshelflanguagespage.h"
+#include "frontend/bookshelfwizard/btbookshelfwizard.h"
+#include "frontend/bookshelfwizard/btbookshelfwizardenums.h"
+#include "util/btconnect.h"
+
+
+namespace {
+char const buttonPropertyName[] = "BtBookshelfSourcesPageButtonProperty";
+constexpr bool const ButtonTagAdd = true;
+constexpr bool const ButtonTagRemove = false;
+QString const SourcesKey = "GUI/BookshelfWizard/sources";
+QString const lastUpdate = "GUI/BookshelfWizard/lastUpdate";
+QStringList const initialSelection{"CrossWire", "Bible.org", "Xiphos"};
+} // anonymous namespace
+
+
+BtBookshelfSourcesPage::BtBookshelfSourcesPage(QWidget * parent)
+ : BtBookshelfWizardPage(parent)
+{
+ // Setup UI:
+ m_verticalLayout = new QVBoxLayout(this);
+ m_verticalLayout->setObjectName(QStringLiteral("m_verticalLayout"));
+ m_sourcesTableView = new QTableView(this);
+ m_sourcesTableView->setObjectName(QStringLiteral("sourcesListView"));
+ m_sourcesTableView->horizontalHeader()->setVisible(false);
+ m_sourcesTableView->verticalHeader()->setVisible(false);
+ m_verticalLayout->addWidget(m_sourcesTableView);
+
+ // Create sources model:
+ m_model = new BtListModel(true, this, 2);
+ m_sourcesTableView->setModel(m_model);
+ BT_CONNECT(m_model, &QStandardItemModel::dataChanged,
+ this, &QWizardPage::completeChanged);
+}
+
+void BtBookshelfSourcesPage::retranslateUi() {
+ setTitle(QApplication::translate("BookshelfWizard",
+ "Choose Remote Libraries"));
+ setSubTitle(QApplication::translate(
+ "BookshelfWizard",
+ "Choose one or more remote libraries to install works from."));
+}
+
+int BtBookshelfSourcesPage::nextId() const {
+ auto & languagesPage = btWizard().languagesPage();
+ languagesPage.initializeLanguages();
+ return languagesPage.skipPage()
+ ? WizardPage::installWorksPage
+ : WizardPage::languagesPage;
+}
+
+void BtBookshelfSourcesPage::initializePage() {
+ QStringList saveSources;
+ if (m_firstTimeInit) {
+ saveSources << btConfig().value<QStringList>(SourcesKey, QStringList{});
+ if (saveSources.empty())
+ saveSources << initialSelection;
+ m_firstTimeInit = false;
+ } else {
+ saveSources << selectedSources();
+ }
+
+ // Do before updating models to get correct
+ // column width for buttons
+ retranslateUi();
+
+ updateSourcesModel();
+ selectSourcesInModel(saveSources);
+}
+
+void BtBookshelfSourcesPage::selectSourcesInModel(const QStringList& sources) {
+ for (int row = 0; row < m_model->rowCount(); ++row) {
+ QStandardItem * const item = m_model->item(row,0);
+ if (sources.contains(item->text()))
+ item->setCheckState(Qt::Checked);
+ }
+}
+
+void BtBookshelfSourcesPage::updateSourcesModel() {
+ QStringList sourceList = BtInstallBackend::sourceNameList();
+ m_model->clear();
+ m_model->setColumnCount(2);
+
+ m_signalMapper = new QSignalMapper(this);
+
+ auto const addButton = [this](int row, int column,
+ QString const & text, bool const tag) {
+ QPushButton * const button = new QPushButton(text, this);
+ button->setProperty(buttonPropertyName, tag);
+ m_sourcesTableView->setIndexWidget(m_model->index(row, column), button);
+ return button;
+ };
+
+ constexpr auto const smMap =
+ static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map);
+ QString const removeText = tr("Remove");
+ for (QString source : sourceList) {
+ m_model->appendItem(source);
+ int const row = m_model->rowCount() - 1;
+ QPushButton * button = addButton(row, 1, removeText, ButtonTagRemove);
+ BT_CONNECT(button, &QPushButton::clicked,
+ m_signalMapper, smMap);
+ m_signalMapper->setMapping(button, row);
+ }
+
+ m_model->appendRow(new QStandardItem(tr("< Add new remote library >")));
+ int const row = m_model->rowCount() - 1;
+ QString const addText = tr("Add");
+ QPushButton * const button = addButton(row, 1, addText, ButtonTagAdd);
+ BT_CONNECT(button, &QPushButton::clicked, m_signalMapper,smMap);
+ m_signalMapper->setMapping(button, row);
+
+ BT_CONNECT(m_signalMapper,
+ static_cast<void (QSignalMapper::*)(int)>(
+ &QSignalMapper::mapped),
+ this, &BtBookshelfSourcesPage::slotButtonClicked);
+
+ m_sourcesTableView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
+ m_sourcesTableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
+ m_sourcesTableView->setShowGrid(false);
+
+ // Calculate button column width:
+ QFontMetrics const fontMetrics = m_sourcesTableView->fontMetrics();
+ m_sourcesTableView->setColumnWidth(1,
+ qMax(fontMetrics.width(removeText),
+ fontMetrics.width(addText)) + 60);
+}
+
+bool BtBookshelfSourcesPage::isComplete() const {
+ for (int row = 0; row < m_model->rowCount(); ++row)
+ if (m_model->item(row, 0)->checkState() == Qt::Checked)
+ return true;
+ return false;
+}
+
+QStringList BtBookshelfSourcesPage::selectedSources() const {
+ QStringList sources;
+ for (int row = 0; row < m_model->rowCount(); ++row) {
+ QStandardItem * const item = m_model->item(row, 0);
+ if (item->checkState() == Qt::Checked)
+ sources << item->text();
+ }
+ return sources;
+}
+
+void BtBookshelfSourcesPage::slotButtonClicked(int row) {
+ QModelIndex const index = m_model->index(row, 1);
+ if (static_cast<QPushButton *>(
+ m_sourcesTableView->indexWidget(index))->property(
+ buttonPropertyName).toBool() == ButtonTagRemove)
+ {
+ if (QMessageBox::warning(
+ this,
+ tr("Delete Source"),
+ tr("Do you really want to delete this source?"),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
+ BtInstallBackend::deleteSource(
+ m_model->item(index.row(), 0)->text());
+ QStringList const saveSources = selectedSources();
+ updateSourcesModel();
+ selectSourcesInModel(saveSources);
+ return;
+ }
+
+ CSwordSetupInstallSourcesDialog dlg;
+ QStringList const saveSources = selectedSources();
+ if (dlg.exec() != QDialog::Accepted)
+ return;
+ if (dlg.wasRemoteListAdded()) {
+ updateSourcesModel();
+ selectSourcesInModel(saveSources);
+ return;
+ }
+ sword::InstallSource newSource = dlg.getSource();
+ if (*(newSource.type.c_str()) != '\0') // we have a valid source to add
+ BtInstallBackend::addSource(newSource);
+ updateSourcesModel();
+ selectSourcesInModel(saveSources);
+}
diff --git a/src/frontend/bookshelfwizard/btbookshelfsourcespage.h b/src/frontend/bookshelfwizard/btbookshelfsourcespage.h
new file mode 100644
index 0000000..8f5ef73
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfsourcespage.h
@@ -0,0 +1,61 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKSHELFSOURCESPAGE
+#define BTBOOKSHELFSOURCESPAGE
+
+#include "frontend/bookshelfwizard/btbookshelfwizardpage.h"
+
+#include <QStringList>
+
+
+class BtInstallMgr;
+class BtListModel;
+class QPushButton;
+class QSignalMapper;
+class QTableView;
+class QVBoxLayout;
+
+class BtBookshelfSourcesPage final: public BtBookshelfWizardPage {
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ BtBookshelfSourcesPage(QWidget * parent = 0);
+
+ bool isComplete() const final override;
+ void initializePage() final override;
+ int nextId() const final override;
+ QStringList selectedSources() const;
+
+private slots:
+
+ void slotButtonClicked(int row);
+
+private: /* Methods: */
+
+ void retranslateUi();
+ void selectSourcesInModel(QStringList const & sources);
+ void updateSourcesModel();
+
+private: /* Fields: */
+
+ bool m_firstTimeInit = true;
+ QTableView * m_sourcesTableView;
+ QVBoxLayout * m_verticalLayout;
+ BtListModel * m_model;
+ BtInstallMgr * m_currentInstallMgr;
+ QSignalMapper * m_signalMapper;
+
+}; /* class BtBookshelfSourcesPage */
+
+#endif
diff --git a/src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.cpp b/src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.cpp
new file mode 100644
index 0000000..b26e4cb
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.cpp
@@ -0,0 +1,134 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "frontend/bookshelfwizard/btbookshelfsourcesprogresspage.h"
+
+#include <QApplication>
+#include <QDate>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QProgressBar>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include "backend/btinstallbackend.h"
+#include "backend/btsourcesthread.h"
+#include "backend/config/btconfig.h"
+#include "frontend/bookshelfwizard/btbookshelfwizardenums.h"
+#include "frontend/bookshelfwizard/btbookshelfwizard.h"
+#include "util/btconnect.h"
+
+
+namespace {
+QString const lastUpdate = "GUI/BookshelfWizard/lastUpdate";
+}
+
+BtBookshelfSourcesProgressPage::BtBookshelfSourcesProgressPage(QWidget * parent)
+ : BtBookshelfWizardPage(parent)
+{
+ // Setup UI:
+ QVBoxLayout * const vLayout = new QVBoxLayout(this);
+ vLayout->setObjectName(QStringLiteral("verticalLayout"));
+
+ vLayout->addItem(new QSpacerItem(20,
+ 40,
+ QSizePolicy::Minimum,
+ QSizePolicy::Expanding));
+
+ m_msgLabel = new QLabel(this);
+ m_msgLabel->setAlignment(Qt::AlignCenter);
+ m_msgLabel->setObjectName(QStringLiteral("msgLabel"));
+ m_msgLabel->setWordWrap(true);
+ vLayout->addWidget(m_msgLabel);
+
+ m_progressBar = new QProgressBar(this);
+ m_progressBar->setObjectName("progressBar");
+ m_progressBar->setMinimum(0);
+ m_progressBar->setMaximum(100);
+ vLayout->addWidget(m_progressBar, Qt::AlignCenter);
+
+ QHBoxLayout * const horizontalLayout = new QHBoxLayout();
+ m_stopButton = new QPushButton(this);
+ horizontalLayout->addSpacerItem(
+ new QSpacerItem(1, 1, QSizePolicy::Expanding));
+ horizontalLayout->addWidget(m_stopButton);
+ horizontalLayout->addSpacerItem(
+ new QSpacerItem(1, 1, QSizePolicy::Expanding));
+ vLayout->addLayout(horizontalLayout);
+
+ vLayout->addItem(new QSpacerItem(20,
+ 40,
+ QSizePolicy::Minimum,
+ QSizePolicy::Expanding));
+
+ // Initialize connections:
+ BT_CONNECT(m_stopButton, &QPushButton::clicked,
+ this, &BtBookshelfSourcesProgressPage::slotStopInstall);
+}
+
+void BtBookshelfSourcesProgressPage::destroyThread() noexcept {
+ if (m_thread) {
+ m_thread->stop();
+ while (!m_thread->wait()) /* join */;
+ delete m_thread;
+ m_thread = nullptr;
+ }
+}
+
+void BtBookshelfSourcesProgressPage::retranslateUi() {
+ m_stopButton->setText(tr("Stop"));
+
+ setTitle(QApplication::translate(
+ "BookshelfWizard", "Updating Remote Libraries"));
+ setSubTitle(QApplication::translate(
+ "BookshelfWizard",
+ "Updating information from remote libraries."));
+}
+
+int BtBookshelfSourcesProgressPage::nextId() const {
+ if (btWizard().taskType() == WizardTaskType::updateWorks)
+ return WizardPage::updateWorksPage;
+ return WizardPage::sourcesPage;
+}
+
+void BtBookshelfSourcesProgressPage::initializePage() {
+ destroyThread();
+
+ m_installCompleted = false;
+ m_thread = new BtSourcesThread(this);
+ BT_CONNECT(m_thread, &BtSourcesThread::percentComplete,
+ m_progressBar, &QProgressBar::setValue,
+ Qt::QueuedConnection);
+ BT_CONNECT(m_thread, &BtSourcesThread::showMessage,
+ m_msgLabel, &QLabel::setText,
+ Qt::QueuedConnection);
+ BT_CONNECT(m_thread, &BtSourcesThread::finished,
+ this, &BtBookshelfSourcesProgressPage::slotThreadFinished,
+ Qt::QueuedConnection);
+ m_thread->start();
+ m_stopButton->setEnabled(true);
+ btWizard().downloadStarted();
+ retranslateUi();
+}
+
+bool BtBookshelfSourcesProgressPage::isComplete() const
+{ return m_installCompleted; }
+
+void BtBookshelfSourcesProgressPage::slotThreadFinished() {
+ m_stopButton->setDisabled(true);
+ if (m_thread->finishedSuccessfully())
+ btConfig().setValue<QDate>(lastUpdate, QDate::currentDate());
+ m_installCompleted = true;
+ emit QWizardPage::completeChanged();
+ btWizard().downloadFinished();
+}
+
+void BtBookshelfSourcesProgressPage::slotStopInstall() {
+ m_stopButton->setDisabled(true);
+ m_thread->stop();
+}
diff --git a/src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.h b/src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.h
new file mode 100644
index 0000000..459167e
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.h
@@ -0,0 +1,60 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKSHELFSOURCESPROGRESSPAGE
+#define BTBOOKSHELFSOURCESPROGRESSPAGE
+
+#include "frontend/bookshelfwizard/btbookshelfwizardpage.h"
+
+
+class BtSourcesThread;
+class QLabel;
+class QProgressBar;
+class QPushButton;
+
+class BtBookshelfSourcesProgressPage final: public BtBookshelfWizardPage {
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ BtBookshelfSourcesProgressPage(QWidget * parent = 0);
+ inline ~BtBookshelfSourcesProgressPage() noexcept override
+ { destroyThread(); }
+
+ void destroyThread() noexcept;
+
+ void initializePage() final override;
+ bool isComplete() const final override;
+ int nextId() const final override;
+
+public slots:
+ void slotStopInstall();
+
+private slots:
+
+ void slotThreadFinished();
+
+private: /* Methods: */
+
+ void retranslateUi();
+
+private: /* Methods: */
+
+ bool m_installCompleted = false;
+ QLabel * m_msgLabel;
+ QProgressBar * m_progressBar;
+ QPushButton * m_stopButton;
+ BtSourcesThread * m_thread = nullptr;
+
+};
+
+#endif
diff --git a/src/frontend/bookshelfwizard/btbookshelftaskpage.cpp b/src/frontend/bookshelfwizard/btbookshelftaskpage.cpp
new file mode 100644
index 0000000..ca9c936
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelftaskpage.cpp
@@ -0,0 +1,137 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "backend/config/btconfig.h"
+#include "frontend/bookshelfwizard/btbookshelftaskpage.h"
+
+#include <QApplication>
+#include <QDate>
+#include <QGroupBox>
+#include <QLabel>
+#include <QRadioButton>
+#include <QVBoxLayout>
+
+
+namespace {
+QString const lastUpdate = "GUI/BookshelfWizard/lastUpdate";
+} // anonymous namespace
+
+
+BtBookshelfTaskPage::BtBookshelfTaskPage(QWidget * parent)
+ : BtBookshelfWizardPage(parent)
+{
+ m_verticalLayout = new QVBoxLayout(this);
+ m_verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
+
+ m_warningLabel = new QLabel(this);
+ m_warningLabel->setObjectName(QStringLiteral("warningLabel"));
+ m_warningLabel->setWordWrap(true);
+
+ m_verticalLayout->addWidget(m_warningLabel);
+ m_verticalLayout->addItem(
+ new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
+
+ m_groupBox = new QGroupBox(this);
+ { // Setup radio buttons:
+ QVBoxLayout * const vLayout = new QVBoxLayout(m_groupBox);
+ vLayout->setObjectName(QStringLiteral("verticalLayout2"));
+
+ m_installRadioButton = new QRadioButton(m_groupBox);
+ m_installRadioButton->setObjectName(
+ QStringLiteral("installRadioButton"));
+ QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
+ sizePolicy.setHorizontalStretch(0);
+ sizePolicy.setVerticalStretch(0);
+ sizePolicy.setHeightForWidth(
+ m_installRadioButton->sizePolicy().hasHeightForWidth());
+ m_installRadioButton->setSizePolicy(sizePolicy);
+ m_installRadioButton->setChecked(true);
+ vLayout->addWidget(m_installRadioButton);
+
+ m_updateRadioButton = new QRadioButton(m_groupBox);
+ m_updateRadioButton->setObjectName(QStringLiteral("updateRadioButton"));
+ sizePolicy.setHeightForWidth(
+ m_updateRadioButton->sizePolicy().hasHeightForWidth());
+ m_updateRadioButton->setSizePolicy(sizePolicy);
+ vLayout->addWidget(m_updateRadioButton);
+
+ m_removeRadioButton = new QRadioButton(m_groupBox);
+ m_removeRadioButton->setObjectName(QStringLiteral("removeRadioButton"));
+ vLayout->addWidget(m_removeRadioButton);
+ }
+ m_verticalLayout->addWidget(m_groupBox);
+
+ m_verticalLayout->addItem(
+ new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
+ m_verticalLayout->setStretch(0, 1);
+ m_verticalLayout->setStretch(1, 1);
+ m_verticalLayout->setStretch(2, 1);
+ m_verticalLayout->setStretch(3, 3);
+
+ retranslateUi();
+}
+
+void BtBookshelfTaskPage::retranslateUi() {
+ setTitle(QApplication::translate("BookshelfWizard",
+ "Bookshelf Manager"));
+ setSubTitle(QApplication::translate("BookshelfWizard",
+ "Install, update, or remove works on your bookshelf."));
+ m_warningLabel->setText(
+ QApplication::translate(
+ "BookshelfWizard",
+ "<html><head/><body><p><span style=\" font-weight:600;\">"
+ "WARNING</span>: Installing or updating works uses the "
+ "internet. If you live in a persecuted country you may not "
+ "want to do this.</p></body></html>"));
+ m_groupBox->setTitle(QApplication::translate("BookshelfWizard",
+ "Bookshelf task"));
+ m_installRadioButton->setText(
+ QApplication::translate(
+ "BookshelfWizard",
+ "Install additional works (uses internet)"));
+ m_updateRadioButton->setText(
+ QApplication::translate("BookshelfWizard",
+ "Update installed works (uses internet)"));
+ m_removeRadioButton->setText(
+ QApplication::translate("BookshelfWizard",
+ "Remove installed works"));
+}
+
+static bool timeToUpdate() {
+ QDate const lastDate = btConfig().value<QDate>(lastUpdate);
+ if (!lastDate.isValid())
+ return true;
+ if (QDate::currentDate().toJulianDay() - lastDate.toJulianDay() > 7)
+ return true;
+ return false;
+}
+
+int BtBookshelfTaskPage::nextId() const {
+ if (m_installRadioButton->isChecked()) {
+ if (timeToUpdate())
+ return WizardPage::sourcesProgressPage;
+ return WizardPage::sourcesPage;
+ } else if (m_updateRadioButton->isChecked()) {
+ if (timeToUpdate())
+ return WizardPage::sourcesProgressPage;
+ return WizardPage::updateWorksPage;
+ } else if (m_removeRadioButton->isChecked()) {
+ return WizardPage::removeWorksPage;
+ } else {
+ return -1;
+ }
+}
+
+WizardTaskType BtBookshelfTaskPage::taskType() const {
+ if (m_installRadioButton->isChecked())
+ return WizardTaskType::installWorks;
+ if (m_updateRadioButton->isChecked())
+ return WizardTaskType::updateWorks;
+ return WizardTaskType::removeWorks;
+}
diff --git a/src/frontend/bookshelfwizard/btbookshelftaskpage.h b/src/frontend/bookshelfwizard/btbookshelftaskpage.h
new file mode 100644
index 0000000..8118f89
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelftaskpage.h
@@ -0,0 +1,51 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKSHELFTASKPAGE
+#define BTBOOKSHELFTASKPAGE
+
+#include "frontend/bookshelfwizard/btbookshelfwizardpage.h"
+
+#include "frontend/bookshelfwizard/btbookshelfwizardenums.h"
+
+
+class QGroupBox;
+class QLabel;
+class QRadioButton;
+class QVBoxLayout;
+
+class BtBookshelfTaskPage final: public BtBookshelfWizardPage {
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ BtBookshelfTaskPage(QWidget * parent = 0);
+
+ int nextId() const final override;
+ WizardTaskType taskType() const;
+
+private: /* Methods: */
+
+ void retranslateUi();
+
+private: /* Fields: */
+
+ QLabel * m_warningLabel;
+ QGroupBox * m_groupBox;
+ QVBoxLayout * m_verticalLayout;
+ QRadioButton * m_installRadioButton;
+ QRadioButton * m_updateRadioButton;
+ QRadioButton * m_removeRadioButton;
+
+};
+
+#endif
diff --git a/src/frontend/bookshelfwizard/btbookshelfwizard.cpp b/src/frontend/bookshelfwizard/btbookshelfwizard.cpp
new file mode 100644
index 0000000..a5db6d4
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfwizard.cpp
@@ -0,0 +1,169 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "frontend/bookshelfwizard/btbookshelfwizard.h"
+
+#include <QAbstractButton>
+#include <QApplication>
+#include <QByteArray>
+#include <QKeyEvent>
+#include <QMessageBox>
+#include <QPushButton>
+#include "backend/config/btconfig.h"
+#include "frontend/bookshelfwizard/btbookshelfinstallfinalpage.h"
+#include "frontend/bookshelfwizard/btbookshelflanguagespage.h"
+#include "frontend/bookshelfwizard/btbookshelfremovefinalpage.h"
+#include "frontend/bookshelfwizard/btbookshelfsourcespage.h"
+#include "frontend/bookshelfwizard/btbookshelfsourcesprogresspage.h"
+#include "frontend/bookshelfwizard/btbookshelftaskpage.h"
+#include "frontend/bookshelfwizard/btbookshelfwizardenums.h"
+#include "frontend/bookshelfwizard/btbookshelfworkspage.h"
+
+
+namespace {
+QString const GeometryKey = "GUI/BookshelfWizard/geometry";
+QString const SourcesKey = "GUI/BookshelfWizard/sources";
+QString const LanguagesKey = "GUI/BookshelfWizard/languages";
+} // anonymous namespace
+
+BtBookshelfWizard::BtBookshelfWizard(QWidget * parent, Qt::WindowFlags flags)
+ : QWizard(parent, flags)
+ , m_downloadInProgress(false)
+ , m_closeRequested(false)
+ , m_closeMessageBox(new QMessageBox(this))
+ , m_taskPage(new BtBookshelfTaskPage(this))
+ , m_sourcesPage(new BtBookshelfSourcesPage(this))
+ , m_sourcesProgressPage(new BtBookshelfSourcesProgressPage(this))
+ , m_languagesPage(new BtBookshelfLanguagesPage(this))
+ , m_installWorksPage(new BtBookshelfWorksPage(WizardTaskType::installWorks, this))
+ , m_updateWorksPage(new BtBookshelfWorksPage(WizardTaskType::updateWorks, this))
+ , m_removeWorksPage(new BtBookshelfWorksPage(WizardTaskType::removeWorks, this))
+ , m_installFinalPage(new BtBookshelfInstallFinalPage(this)) // For install and update
+{
+ setPage(WizardPage::taskPage, m_taskPage);
+ setPage(WizardPage::sourcesProgressPage,m_sourcesProgressPage);
+ setPage(WizardPage::sourcesPage, m_sourcesPage);
+ setPage(WizardPage::languagesPage, m_languagesPage);
+ setPage(WizardPage::installWorksPage, m_installWorksPage);
+ setPage(WizardPage::updateWorksPage, m_updateWorksPage);
+ setPage(WizardPage::removeWorksPage, m_removeWorksPage);
+ setPage(WizardPage::removeFinalPage, new BtBookshelfRemoveFinalPage(this));
+ setPage(WizardPage::installFinalPage, m_installFinalPage);
+ setStartId(WizardPage::taskPage);
+
+ QRect rect = geometry();
+ rect.setWidth(780);
+ rect.setHeight(600);
+ setGeometry(rect);
+ setOption(QWizard::NoBackButtonOnLastPage);
+
+ retranslateUi();
+
+ // Load wizard geometry:
+ restoreGeometry(btConfig().value<QByteArray>(GeometryKey, QByteArray()));
+}
+
+static void replaceButtonText(QWizard * wizard, QWizard::WizardButton which, const QString& text) {
+ QAbstractButton * button = wizard->button(which);
+ if (button != nullptr)
+ button->setText(text);
+}
+
+// This function can be used by other QWizard's in the future
+void translateQWizardStandardButtons(QWizard * wizard) {
+ replaceButtonText(wizard, QWizard::BackButton, QPushButton::tr("Back" ,"Dialog Button"));
+ replaceButtonText(wizard, QWizard::NextButton, QPushButton::tr("Next" ,"Dialog Button"));
+ replaceButtonText(wizard, QWizard::CommitButton, QPushButton::tr("Commit","Dialog Button"));
+ replaceButtonText(wizard, QWizard::FinishButton, QPushButton::tr("Finish","Dialog Button"));
+ replaceButtonText(wizard, QWizard::CancelButton, QPushButton::tr("Cancel","Dialog Button"));
+ replaceButtonText(wizard, QWizard::HelpButton, QPushButton::tr("Help" ,"Dialog Button"));
+}
+
+void BtBookshelfWizard::retranslateUi() {
+ translateQWizardStandardButtons(this);
+ setWindowTitle(QApplication::translate("BookshelfWizard",
+ "Bookshelf Manager"));
+ m_closeMessageBox->setWindowTitle(QApplication::translate(
+ "BookshelfWizard",
+ "Canceling Downloads"));
+ m_closeMessageBox->setText(QApplication::translate(
+ "BookshelfWizard",
+ "The Bookshelf Manager will close when the current download finishes."));
+}
+
+QStringList BtBookshelfWizard::selectedSources() const
+{ return m_sourcesPage->selectedSources(); }
+
+QStringList BtBookshelfWizard::selectedLanguages() const
+{ return m_languagesPage->selectedLanguages(); }
+
+void BtBookshelfWizard::accept() {
+ if (currentPage() == m_installFinalPage) {
+ // Save settings:
+ btConfig().setValue(SourcesKey, selectedSources());
+ btConfig().setValue(LanguagesKey, selectedLanguages());
+ }
+
+ btConfig().setValue(GeometryKey, saveGeometry()); // Save wizard geometry
+ QDialog::accept();
+}
+
+BtModuleSet BtBookshelfWizard::selectedWorks() const {
+ WizardTaskType const iType = m_taskPage->taskType();
+ if (iType == WizardTaskType::installWorks)
+ return m_installWorksPage->checkedModules();
+ if (iType == WizardTaskType::updateWorks)
+ return m_updateWorksPage->checkedModules();
+ BT_ASSERT(iType == WizardTaskType::removeWorks);
+ return m_removeWorksPage->checkedModules();
+}
+
+WizardTaskType BtBookshelfWizard::taskType() const
+{ return m_taskPage->taskType(); }
+
+QString BtBookshelfWizard::installPath() const {
+ WizardTaskType const iType = m_taskPage->taskType();
+ if (iType == WizardTaskType::installWorks)
+ return m_installWorksPage->installPath();
+ BT_ASSERT(iType == WizardTaskType::updateWorks);
+ return m_updateWorksPage->installPath();
+}
+
+void BtBookshelfWizard::stopDownload() {
+ if (currentPage() == m_installFinalPage) {
+ m_installFinalPage->slotStopInstall();
+ }
+ if (currentPage() == m_sourcesProgressPage) {
+ m_sourcesProgressPage->slotStopInstall();
+ }
+}
+
+void BtBookshelfWizard::keyPressEvent(QKeyEvent * event) {
+ if(event->key() == Qt::Key_Escape) {
+ if (m_downloadInProgress) {
+ m_closeRequested = true;
+ m_closeMessageBox->show();
+ stopDownload();
+ return;
+ }
+ }
+ QWizard::keyPressEvent(event);
+}
+
+void BtBookshelfWizard::downloadStarted() {
+ m_downloadInProgress = true;
+}
+
+void BtBookshelfWizard::downloadFinished() {
+ m_downloadInProgress = false;
+ if (m_closeRequested) {
+ m_closeMessageBox->hide();
+ accept();
+ }
+}
diff --git a/src/frontend/bookshelfwizard/btbookshelfwizard.h b/src/frontend/bookshelfwizard/btbookshelfwizard.h
new file mode 100644
index 0000000..44219c1
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfwizard.h
@@ -0,0 +1,84 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKSHELFWIZARD_H
+#define BTBOOKSHELFWIZARD_H
+
+#include <QWizard>
+
+#include <QStringList>
+#include "frontend/bookshelfwizard/btbookshelfwizardenums.h"
+#include "util/btassert.h"
+
+
+class BtBookshelfWorksPage;
+class BtBookshelfInstallFinalPage;
+class BtBookshelfLanguagesPage;
+class BtBookshelfSourcesPage;
+class BtBookshelfSourcesProgressPage;
+class BtBookshelfTaskPage;
+class BtBookshelfUpdatePage;
+class BtModuleSet;
+class QKeyEvent;
+class QMessageBox;
+
+/** \brief The Bookshelf Manager wizard. */
+class BtBookshelfWizard final: public QWizard {
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ BtBookshelfWizard(QWidget * parent = nullptr, Qt::WindowFlags flags = 0);
+
+ QStringList selectedSources() const;
+ QStringList selectedLanguages() const;
+ BtModuleSet selectedWorks() const;
+ WizardTaskType taskType() const;
+ QString installPath() const;
+
+ BtBookshelfLanguagesPage & languagesPage() const noexcept {
+ return *m_languagesPage;
+ }
+
+ void downloadStarted();
+ void downloadFinished();
+
+public slots:
+
+ void accept() final override;
+
+protected:
+ virtual void keyPressEvent(QKeyEvent * event) override;
+
+private: /* Methods: */
+
+ void retranslateUi();
+ void stopDownload();
+
+private: /* Fields: */
+
+ bool m_downloadInProgress;
+ bool m_closeRequested;
+ QMessageBox * m_closeMessageBox;
+
+ BtBookshelfTaskPage * const m_taskPage;
+ BtBookshelfSourcesPage * const m_sourcesPage;
+ BtBookshelfSourcesProgressPage * const m_sourcesProgressPage;
+ BtBookshelfLanguagesPage * const m_languagesPage;
+ BtBookshelfWorksPage * const m_installWorksPage;
+ BtBookshelfWorksPage * const m_updateWorksPage;
+ BtBookshelfWorksPage * const m_removeWorksPage;
+ BtBookshelfInstallFinalPage * const m_installFinalPage;
+
+}; /* class BtBookshelfWizard */
+
+#endif
diff --git a/src/frontend/bookshelfwizard/btbookshelfwizardenums.h b/src/frontend/bookshelfwizard/btbookshelfwizardenums.h
new file mode 100644
index 0000000..410961a
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfwizardenums.h
@@ -0,0 +1,33 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKSHELFWIZARDENUM_H
+#define BTBOOKSHELFWIZARDENUM_H
+
+enum WizardPage: int {
+ taskPage,
+ sourcesProgressPage,
+ sourcesPage,
+ languagesPage,
+ installWorksPage,
+ updateWorksPage,
+ removeWorksPage,
+ removeFinalPage,
+ installFinalPage
+};
+
+enum WizardTaskType {
+ installWorks,
+ updateWorks,
+ removeWorks
+};
+
+#endif
diff --git a/src/frontend/bookshelfwizard/btbookshelfwizardpage.h b/src/frontend/bookshelfwizard/btbookshelfwizardpage.h
new file mode 100644
index 0000000..0a00606
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfwizardpage.h
@@ -0,0 +1,42 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKSHELFWIZARDPAGE_H
+#define BTBOOKSHELFWIZARDPAGE_H
+
+#include <QWizardPage>
+
+#include <utility>
+#include "frontend/bookshelfwizard/btbookshelfwizard.h"
+#include "util/btassert.h"
+
+
+class BtBookshelfWizardPage: public QWizardPage {
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ template <typename ... Args>
+ BtBookshelfWizardPage(Args && ... args)
+ : QWizardPage(std::forward<Args>(args)...)
+ {}
+
+ inline BtBookshelfWizard & btWizard() const noexcept {
+ BtBookshelfWizard * const w =
+ qobject_cast<BtBookshelfWizard *>(wizard());
+ BT_ASSERT(w);
+ return *w;
+ }
+
+}; /* class BtBookshelfWizardPage */
+
+#endif
diff --git a/src/frontend/bookshelfwizard/btbookshelfworkspage.cpp b/src/frontend/bookshelfwizard/btbookshelfworkspage.cpp
new file mode 100644
index 0000000..2b7808a
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfworkspage.cpp
@@ -0,0 +1,320 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "frontend/bookshelfwizard/btbookshelfworkspage.h"
+
+#include <QApplication>
+#include <QComboBox>
+#include <QHBoxLayout>
+#include <QHeaderView>
+#include <QLabel>
+#include <QSet>
+#include <QToolButton>
+#include <QVBoxLayout>
+#include "backend/btinstallbackend.h"
+#include "backend/bookshelfmodel/btbookshelffiltermodel.h"
+#include "backend/config/btconfig.h"
+#include "backend/managers/cswordbackend.h"
+#include "frontend/bookshelfwizard/btinstallpagemodel.h"
+#include "frontend/btbookshelfgroupingmenu.h"
+#include "frontend/btbookshelfview.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
+#include "util/directory.h"
+
+
+namespace {
+QString const groupingOrderKey("GUI/BookshelfWizard/InstallPage/grouping");
+QString const installPathKey(
+ "GUI/BookshelfWizard/InstallPage/installPathIndex");
+
+inline bool filter(WizardTaskType const taskType,
+ QStringList const & languages,
+ CSwordModuleInfo const * const mInfo)
+{
+ if (taskType == WizardTaskType::installWorks) {
+ return !CSwordBackend::instance()->findModuleByName(mInfo->name())
+ && languages.contains(mInfo->language()->translatedName());
+ } else if (taskType == WizardTaskType::updateWorks) {
+ using CSMI = CSwordModuleInfo;
+ using CSV = sword::SWVersion const;
+ CSMI const * const installedModule =
+ CSwordBackend::instance()->findModuleByName(mInfo->name());
+ return installedModule
+ && (CSV(installedModule->config(CSMI::ModuleVersion).toLatin1())
+ < CSV(mInfo->config(CSMI::ModuleVersion).toLatin1()));
+ } else {
+ BT_ASSERT(taskType == WizardTaskType::removeWorks);
+ return CSwordBackend::instance()->findModuleByName(mInfo->name());
+ }
+}
+
+} // anonymous namespace
+
+BtBookshelfWorksPage::BtBookshelfWorksPage(WizardTaskType iType,
+ QWidget * parent)
+ : BtBookshelfWizardPage(parent)
+ , m_taskType(iType)
+ , m_groupingOrder(groupingOrderKey)
+{
+ // Initialize menus:
+ m_groupingMenu = new BtBookshelfGroupingMenu(this);
+ m_contextMenu = new QMenu(this);
+ m_contextMenu->addMenu(m_groupingMenu);
+ m_itemContextMenu = m_contextMenu;
+
+ // Setup UI:
+ QVBoxLayout * const verticalLayout = new QVBoxLayout(this);
+ verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
+
+ m_bookshelfView = new BtBookshelfView(this);
+ m_bookshelfView->setObjectName(QStringLiteral("worksTreeView"));
+ m_bookshelfView->setHeaderHidden(false);
+ m_bookshelfView->header()->setSectionResizeMode(
+ QHeaderView::ResizeToContents);
+ verticalLayout->addWidget(m_bookshelfView);
+
+ m_msgLabel = new QLabel(this);
+ m_msgLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ m_msgLabel->setWordWrap(true);
+ verticalLayout->addWidget(m_msgLabel);
+
+ QHBoxLayout * const pathLayout = new QHBoxLayout();
+ if (m_taskType != WizardTaskType::removeWorks) {
+ m_pathCombo = new QComboBox(this);
+ m_pathCombo->setMinimumContentsLength(20);
+ m_pathCombo->setSizeAdjustPolicy(
+ QComboBox::AdjustToMinimumContentsLengthWithIcon);
+ m_pathCombo->setSizePolicy(QSizePolicy::Expanding,
+ QSizePolicy::Minimum);
+ m_pathCombo->view()->setTextElideMode(Qt::ElideMiddle);
+
+ m_pathLabel = new QLabel(this);
+ m_pathLabel->setBuddy(m_pathCombo);
+ slotInitPathCombo();
+
+ pathLayout->setContentsMargins(0, 8, 0, 0);
+ pathLayout->addWidget(m_pathLabel);
+ pathLayout->addWidget(m_pathCombo);
+ }
+ pathLayout->addStretch();
+
+ m_groupingLabel = new QLabel(this);
+ pathLayout->addWidget(m_groupingLabel);
+
+ m_groupingButton = new QToolButton(this);
+ m_groupingButton->setPopupMode(QToolButton::InstantPopup);
+ m_groupingButton->setMenu(m_groupingMenu);
+ m_groupingButton->setIcon(m_groupingMenu->icon());
+ m_groupingButton->setAutoRaise(true);
+ pathLayout->addWidget(m_groupingButton);
+
+ verticalLayout->addLayout(pathLayout);
+
+ // Setup models:
+ BtBookshelfFilterModel * const filterModel =
+ new BtBookshelfFilterModel(this);
+ m_bookshelfView->setModel(filterModel);
+
+ m_installPageModel = new BtInstallPageModel(m_groupingOrder, this);
+ if (m_taskType == WizardTaskType::updateWorks)
+ m_installPageModel->setDefaultChecked(BtBookshelfTreeModel::CHECKED);
+ filterModel->setSourceModel(m_installPageModel);
+
+ m_bookshelfModel = new BtBookshelfModel(this);
+ if (m_taskType == WizardTaskType::removeWorks) {
+ m_installPageModel->setSourceModel(CSwordBackend::instance()->model());
+ } else {
+ m_installPageModel->setSourceModel(m_bookshelfModel);
+ }
+ if (m_taskType == WizardTaskType::removeWorks)
+ m_bookshelfView->setColumnHidden(1, true);
+
+ // Initialize connections:
+ BT_CONNECT(m_groupingMenu,
+ &BtBookshelfGroupingMenu::signalGroupingOrderChanged,
+ this,
+ &BtBookshelfWorksPage::slotGroupingActionTriggered);
+ if (m_taskType != WizardTaskType::removeWorks) {
+ BT_CONNECT(m_pathCombo,
+ static_cast<void (QComboBox::*)(int)>(
+ &QComboBox::currentIndexChanged),
+ this, &BtBookshelfWorksPage::slotPathChanged);
+ BT_CONNECT(
+ CSwordBackend::instance(), &CSwordBackend::sigSwordSetupChanged,
+ this, &BtBookshelfWorksPage::slotInitPathCombo);
+ }
+ BT_CONNECT(m_installPageModel, &BtBookshelfTreeModel::moduleChecked,
+ this, &BtBookshelfWorksPage::completeChanged);
+ BT_CONNECT(m_installPageModel, &BtInstallPageModel::groupingOrderChanged,
+ this, &BtBookshelfWorksPage::slotGroupingOrderChanged);
+
+ retranslateUi();
+}
+
+void BtBookshelfWorksPage::retranslateUi() {
+ if (m_taskType == installWorks) {
+ setTitle(QApplication::translate("BookshelfWizard", "Install Works"));
+ setSubTitle(QApplication::translate("BookshelfWizard",
+ "Choose one or more works to "
+ "install."));
+ setButtonText(QWizard::NextButton,tr("Install Works >"));
+ } else if (m_taskType == WizardTaskType::updateWorks) {
+ setTitle(QApplication::translate("BookshelfWizard", "Update Works"));
+ setSubTitle(QApplication::translate("BookshelfWizard",
+ "Choose one or more works to "
+ "update."));
+ setButtonText(QWizard::NextButton,tr("Update Works >"));
+ } else {
+ BT_ASSERT(m_taskType == WizardTaskType::removeWorks);
+ setTitle(QApplication::translate("BookshelfWizard", "Remove Works"));
+ setSubTitle(QApplication::translate("BookshelfWizard",
+ "Choose one or more works to "
+ "remove."));
+ setButtonText(QWizard::NextButton,tr("Remove Works >"));
+ }
+
+ if (m_taskType != WizardTaskType::removeWorks) {
+ m_pathLabel->setText(tr("Install &folder:"));
+ m_pathCombo->setToolTip(tr("The folder where the new works will be "
+ "installed"));
+ }
+
+ if (m_taskType == WizardTaskType::updateWorks) {
+ m_msgLabel->setText(tr("There are no works to update."));
+ } else if (m_taskType == WizardTaskType::removeWorks) {
+ m_msgLabel->setText(tr("No works are currently installed so they "
+ "cannot be removed."));
+ } else {
+ BT_ASSERT(m_taskType == WizardTaskType::installWorks);
+ m_msgLabel->setText(
+ tr("No works can be installed with the current selection of "
+ "remote libraries and languages. Please go back and make a "
+ "different selection."));
+ }
+
+ m_groupingLabel->setText(tr("Grouping:"));
+ m_groupingButton->setText(tr("Grouping"));
+ m_groupingButton->setToolTip(
+ tr("Change the grouping of items in the bookshelf."));
+}
+
+int BtBookshelfWorksPage::nextId() const {
+ if (btWizard().taskType() == WizardTaskType::removeWorks)
+ return WizardPage::removeFinalPage;
+ return WizardPage::installFinalPage;
+}
+
+void BtBookshelfWorksPage::initializePage() {
+ // Update models:
+ QStringList sources;
+ QStringList languages;
+ if (m_taskType == installWorks) {
+ sources = btWizard().selectedSources();
+ languages = btWizard().selectedLanguages();
+ } else {
+ sources = BtInstallBackend::sourceNameList();
+ }
+
+ {
+ QSet<QString> addedModuleNames;
+ m_bookshelfModel->clear();
+ for (auto const & sourceName : sources) {
+ sword::InstallSource const source =
+ BtInstallBackend::source(sourceName);
+ CSwordBackend * const backend = BtInstallBackend::backend(source);
+ for (auto * const module : backend->moduleList()) {
+ if (filter(m_taskType, languages, module)) {
+ QString const & moduleName = module->name();
+ if (addedModuleNames.contains(moduleName))
+ continue;
+ addedModuleNames.insert(moduleName);
+ m_bookshelfModel->addModule(module);
+ module->setProperty("installSourceName",
+ QString(source.caption.c_str()));
+ }
+ }
+ }
+ if (m_taskType != WizardTaskType::installWorks)
+ m_bookshelfView->expandAll();
+
+ bool const noWorks = (addedModuleNames.count() == 0);
+ m_msgLabel->setVisible(noWorks);
+ m_bookshelfView->setVisible(!noWorks);
+ m_groupingButton->setVisible(!noWorks);
+ m_groupingLabel->setVisible(!noWorks);
+ }
+
+ // Set grouping:
+ static BtBookshelfTreeModel::Grouping const cat(
+ BtBookshelfTreeModel::GROUP_CATEGORY);
+ static BtBookshelfTreeModel::Grouping const catLang; // No grouping
+ if (languages.count() == 1) {
+ slotGroupingActionTriggered(cat);
+ } else if (languages.count() > 1 && m_groupingOrder == cat) {
+ slotGroupingActionTriggered(catLang);
+ }
+}
+
+void BtBookshelfWorksPage::slotGroupingActionTriggered(
+ BtBookshelfTreeModel::Grouping const & grouping)
+{
+ m_installPageModel->setGroupingOrder(grouping);
+ m_bookshelfView->setRootIsDecorated(!grouping.isEmpty());
+}
+
+bool BtBookshelfWorksPage::isComplete() const
+{ return checkedModules().count() > 0; }
+
+void BtBookshelfWorksPage::slotGroupingOrderChanged(
+ BtBookshelfTreeModel::Grouping const & g)
+{
+ m_groupingOrder = g;
+ m_groupingOrder.saveTo(groupingOrderKey);
+}
+
+BtModuleSet const & BtBookshelfWorksPage::checkedModules() const
+{ return m_installPageModel->checkedModules(); }
+
+QString BtBookshelfWorksPage::installPath() const
+{ return m_pathCombo->currentText(); }
+
+void BtBookshelfWorksPage::slotPathChanged(int const index)
+{ btConfig().setValue(installPathKey, index); }
+
+static bool installPathIsUsable(QString const & path) {
+ if (path.isEmpty())
+ return false;
+ QDir const dir(path);
+ if (!dir.exists() || !dir.isReadable())
+ return false;
+ return QFileInfo(dir.canonicalPath()).isWritable();
+}
+
+void BtBookshelfWorksPage::slotInitPathCombo() {
+ m_pathCombo->clear();
+ QStringList const targets(BtInstallBackend::targetList());
+ bool haveUsableTargets = false;
+ for (auto const & target : targets) {
+ if (installPathIsUsable(target)) {
+ m_pathCombo->addItem(util::directory::convertDirSeparators(target));
+ haveUsableTargets = true;
+ }
+ }
+
+ m_pathCombo->setVisible(haveUsableTargets);
+ m_pathLabel->setVisible(haveUsableTargets);
+ if (haveUsableTargets) {
+ /* Choose the current value from config but check whether we have so
+ many items: */
+ int const cfgValue = btConfig().value<int>(installPathKey, 0);
+ int const lastIdx = m_pathCombo->count() - 1;
+ m_pathCombo->setCurrentIndex(cfgValue > lastIdx ? lastIdx : cfgValue);
+ }
+}
diff --git a/src/frontend/bookshelfwizard/btbookshelfworkspage.h b/src/frontend/bookshelfwizard/btbookshelfworkspage.h
new file mode 100644
index 0000000..5ed385d
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btbookshelfworkspage.h
@@ -0,0 +1,78 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTBOOKSHELFWORKSPAGE
+#define BTBOOKSHELFWORKSPAGE
+
+#include "frontend/bookshelfwizard/btbookshelfwizardpage.h"
+
+#include "backend/bookshelfmodel/btbookshelftreemodel.h"
+#include "backend/drivers/btmoduleset.h"
+#include "frontend/bookshelfwizard/btbookshelfwizardenums.h"
+
+
+class BtBookshelfGroupingMenu;
+class BtBookshelfModel;
+class BtBookshelfView;
+class BtInstallPageModel;
+class QComboBox;
+class QLabel;
+class QMenu;
+class QToolButton;
+
+class BtBookshelfWorksPage final: public BtBookshelfWizardPage {
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ BtBookshelfWorksPage(WizardTaskType iType, QWidget * parent = nullptr);
+
+ BtModuleSet const & checkedModules() const;
+ bool isComplete() const final override;
+ void initializePage() final override;
+ QString installPath() const;
+ int nextId() const final override;
+
+private slots:
+
+ void slotGroupingActionTriggered(
+ BtBookshelfTreeModel::Grouping const & grouping);
+ void slotGroupingOrderChanged(BtBookshelfTreeModel::Grouping const & g);
+ void slotPathChanged(int const index);
+ void slotInitPathCombo();
+
+private: /* Methods: */
+
+ void retranslateUi();
+
+private: /* Fields: */
+
+ WizardTaskType const m_taskType;
+ BtBookshelfTreeModel::Grouping m_groupingOrder;
+
+ QToolButton * m_groupingButton;
+ BtBookshelfView * m_bookshelfView;
+ QLabel * m_msgLabel;
+ QLabel * m_pathLabel;
+ QLabel * m_groupingLabel;
+ QComboBox * m_pathCombo;
+
+ BtInstallPageModel * m_installPageModel;
+ BtBookshelfModel * m_bookshelfModel;
+
+ QMenu * m_contextMenu;
+ BtBookshelfGroupingMenu * m_groupingMenu;
+ QMenu * m_itemContextMenu;
+
+}; /* class BtBookshelfWorksPage */
+
+#endif
diff --git a/src/frontend/bookshelfwizard/btinstallpagemodel.cpp b/src/frontend/bookshelfwizard/btinstallpagemodel.cpp
new file mode 100644
index 0000000..25b6e1d
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btinstallpagemodel.cpp
@@ -0,0 +1,83 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License
+* version 2.0.
+*
+**********/
+
+#include "btinstallpagemodel.h"
+
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+
+
+BtInstallPageModel::BtInstallPageModel(Grouping const & grouping,
+ QObject * const parent)
+ : BtBookshelfTreeModel(grouping, parent)
+{
+ setDefaultChecked(BtBookshelfTreeModel::UNCHECKED);
+ setCheckable(true);
+}
+
+QVariant BtInstallPageModel::data(QModelIndex const & i, int role) const {
+ switch (role) {
+ case Qt::DisplayRole:
+ switch (i.column()) {
+ case 0:
+ return BtBookshelfTreeModel::data(i, role);
+ case 1:
+ if (CSwordModuleInfo * const m =
+ module(index(i.row(), 0, i.parent())))
+ {
+ if (CSwordModuleInfo * imodule =
+ CSwordBackend::instance()->findModuleByName(
+ m->name()))
+ return imodule->config(
+ CSwordModuleInfo::ModuleVersion)
+ + " => "
+ + m->config(CSwordModuleInfo::ModuleVersion);
+ return m->config(CSwordModuleInfo::ModuleVersion);
+ }
+ break;
+ case 2:
+ if (CSwordModuleInfo * const m =
+ module(index(i.row(), 0, i.parent())))
+ return m->config(CSwordModuleInfo::Description);
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ if (i.column() == 0)
+ return BtBookshelfTreeModel::data(i, role);
+ break;
+ }
+
+ return QVariant();
+}
+
+int BtInstallPageModel::columnCount(QModelIndex const & parent) const {
+ Q_UNUSED(parent);
+ return 3;
+}
+
+QVariant BtInstallPageModel::headerData(int section,
+ Qt::Orientation orientation,
+ int role) const
+{
+ if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
+ switch (section) {
+ case 0: return tr("Work");
+ case 1: return tr("Version");
+ case 2: return tr("Description");
+ default: break;
+ }
+ }
+ return QVariant();
+}
diff --git a/src/frontend/bookshelfwizard/btinstallpagemodel.h b/src/frontend/bookshelfwizard/btinstallpagemodel.h
new file mode 100644
index 0000000..6003c9b
--- /dev/null
+++ b/src/frontend/bookshelfwizard/btinstallpagemodel.h
@@ -0,0 +1,38 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License
+* version 2.0.
+*
+**********/
+
+#ifndef BTINSTALLPAGEMODEL_H
+#define BTINSTALLPAGEMODEL_H
+
+#include "backend/bookshelfmodel/btbookshelftreemodel.h"
+
+
+class BtInstallPageModel: public BtBookshelfTreeModel {
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ BtInstallPageModel(Grouping const & grouping,
+ QObject * const parent = nullptr);
+
+ QVariant data(QModelIndex const & index,
+ int role = Qt::DisplayRole) const final override;
+ int columnCount(QModelIndex const & parent = QModelIndex())
+ const final override;
+ QVariant headerData(int section,
+ Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const final override;
+
+}; /* class BtInstallPageModel */
+
+#endif /* BTINSTALLPAGEMODEL_H */
diff --git a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp b/src/frontend/bookshelfwizard/cswordsetupinstallsourcesdialog.cpp
index 646efab..c183cfa 100644
--- a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
+++ b/src/frontend/bookshelfwizard/cswordsetupinstallsourcesdialog.cpp
@@ -2,14 +2,13 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
-#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h"
+#include "frontend/bookshelfwizard/cswordsetupinstallsourcesdialog.h"
-#include <QSharedPointer>
#include <QComboBox>
#include <QDir>
#include <QFileInfo>
@@ -26,6 +25,9 @@
#include <QApplication>
#include "backend/btinstallbackend.h"
#include "frontend/messagedialog.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
+
const QString PROTO_FILE( QObject::tr("Local") ); //Local path
const QString PROTO_FTP( QObject::tr("Remote FTP") ); //Remote path
@@ -91,11 +93,12 @@ CSwordSetupInstallSourcesDialog::CSwordSetupInstallSourcesDialog(/*QWidget *pare
QPushButton* getListButton = new QPushButton(tr("Get list..."), this);
getListButton->setToolTip(tr("Download a list of sources from CrossWire server and add sources"));
buttonBox->addButton(getListButton, QDialogButtonBox::ActionRole);
- connect(getListButton, SIGNAL(clicked()), SLOT(slotGetListClicked()));
+ BT_CONNECT(getListButton, SIGNAL(clicked()), SLOT(slotGetListClicked()));
mainLayout->addWidget(buttonBox);
- connect(buttonBox, SIGNAL(accepted()), SLOT(slotOk()));
- connect(buttonBox, SIGNAL(rejected()), SLOT(reject()));
- connect( m_protocolCombo, SIGNAL( activated(int) ), this, SLOT( slotProtocolChanged() ) );
+ BT_CONNECT(buttonBox, SIGNAL(accepted()), SLOT(slotOk()));
+ BT_CONNECT(buttonBox, SIGNAL(rejected()), SLOT(reject()));
+ BT_CONNECT(m_protocolCombo, SIGNAL(activated(int)),
+ this, SLOT(slotProtocolChanged()));
}
void CSwordSetupInstallSourcesDialog::slotOk() {
@@ -108,7 +111,7 @@ void CSwordSetupInstallSourcesDialog::slotOk() {
//BTInstallMgr iMgr;
//sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source( &iMgr, m_captionEdit->text() );
sword::InstallSource is = BtInstallBackend::source(m_captionEdit->text());
- if ( (QString)is.caption.c_str() == m_captionEdit->text() ) { //source already exists
+ if (is.caption.c_str() == m_captionEdit->text()) { // source already exists
message::showInformation( this, tr( "Error" ),
tr("A source with this caption already exists. Please provide a different caption."));
return;
@@ -167,10 +170,12 @@ void CSwordSetupInstallSourcesDialog::slotGetListClicked() {
m_progressDialog = new QProgressDialog("", tr("Cancel"), 0 , 100, this);
m_progressDialog->setWindowTitle(tr("Downloading List"));
m_progressDialog->setMinimumDuration(0);
- connect(m_progressDialog, SIGNAL(canceled()), SLOT(slotRefreshCanceled()));
+ BT_CONNECT(m_progressDialog, SIGNAL(canceled()),
+ SLOT(slotRefreshCanceled()));
m_currentInstallMgr = &iMgr; //for the progress dialog
// connect this directly to the dialog setValue(int) if possible
- connect(&iMgr, SIGNAL(percentCompleted(const int, const int)), SLOT(slotRefreshProgress(const int, const int)));
+ BT_CONNECT(&iMgr, SIGNAL(percentCompleted(const int, const int)),
+ SLOT(slotRefreshProgress(const int, const int)));
m_progressDialog->show();
qApp->processEvents();
@@ -189,7 +194,7 @@ void CSwordSetupInstallSourcesDialog::slotGetListClicked() {
qWarning("InstallMgr: getting remote list returned an error.");
}
delete m_progressDialog;
- m_progressDialog = 0;
+ m_progressDialog = nullptr;
}
void CSwordSetupInstallSourcesDialog::slotRefreshProgress(const int, const int current) {
@@ -203,7 +208,7 @@ void CSwordSetupInstallSourcesDialog::slotRefreshProgress(const int, const int c
}
void CSwordSetupInstallSourcesDialog::slotRefreshCanceled() {
- Q_ASSERT(m_currentInstallMgr);
+ BT_ASSERT(m_currentInstallMgr);
if (m_currentInstallMgr) {
m_currentInstallMgr->terminate();
}
diff --git a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h b/src/frontend/bookshelfwizard/cswordsetupinstallsourcesdialog.h
index 20bf461..ed763e7 100644
--- a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h
+++ b/src/frontend/bookshelfwizard/cswordsetupinstallsourcesdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -25,7 +25,7 @@ class QLabel;
class QLineEdit;
class QProgressDialog;
-class CSwordSetupInstallSourcesDialog : public QDialog {
+class CSwordSetupInstallSourcesDialog final: public QDialog {
Q_OBJECT
public:
diff --git a/src/frontend/btaboutdialog.cpp b/src/frontend/btaboutdialog.cpp
index fd0a3c9..65d9b34 100644
--- a/src/frontend/btaboutdialog.cpp
+++ b/src/frontend/btaboutdialog.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -18,7 +18,9 @@
#include <QTabWidget>
#include <QTextStream>
#include <QVBoxLayout>
-#include <QWebView>
+#include "frontend/btwebengineview.h"
+#include "util/btconnect.h"
+#include "util/bticons.h"
#include "util/directory.h"
// Sword includes:
@@ -58,7 +60,7 @@ BtAboutDialog::BtAboutDialog(QWidget *parent, Qt::WindowFlags wflags)
QWidget *top = new QWidget(this);
QHBoxLayout *topLayout = new QHBoxLayout;
m_iconLabel = new QLabel(this);
- m_iconLabel->setPixmap(QIcon(util::directory::getIconDir().path() + "/bibletime.svg").pixmap(48));
+ m_iconLabel->setPixmap(BtIcons::instance().icon_bibletime.pixmap(48));
topLayout->addWidget(m_iconLabel);
m_versionLabel = new QLabel(this);
QFont font = m_versionLabel->font();
@@ -82,8 +84,7 @@ BtAboutDialog::BtAboutDialog(QWidget *parent, Qt::WindowFlags wflags)
mainLayout->addWidget(m_buttonBox);
setLayout(mainLayout);
- connect(m_buttonBox, SIGNAL(rejected()),
- this, SLOT(reject()));
+ BT_CONNECT(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
retranslateUi();
}
@@ -98,11 +99,12 @@ void BtAboutDialog::resizeEvent(QResizeEvent* event) {
}
-void BtAboutDialog::initTab(QWebView *&tab) {
- tab = new QWebView(this);
+void BtAboutDialog::initTab(BtWebEngineView *&tab) {
+ tab = new BtWebEngineView(this);
+ BtWebEnginePage * page = new BtWebEnginePage(this);
+ tab->setPage(page);
m_tabWidget->addTab(tab, "");
- tab->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
- connect(tab, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClicked(QUrl)));
+ BT_CONNECT(tab->btPage(), SIGNAL(linkClicked(QUrl)), this, SLOT(linkClicked(QUrl)));
}
void BtAboutDialog::retranslateUi() {
@@ -123,11 +125,7 @@ void BtAboutDialog::retranslateBtTab() {
QString content("<p>");
content += tr("BibleTime is an easy to use but powerful Bible study tool.");
content += "</p><p>";
- content += tr("We are looking for developers and translators. If you would like to join "
- "our team, please send an email to %1.")
- .arg(MAKE_LINK_STATIC("mailto:info@bibletime.info", "info@bibletime.info"));
- content += "</p><p>";
- content += tr("(c)1999-2014, The BibleTime Team");
+ content += tr("(c)1999-2016, The BibleTime Team");
content += "</p><p>" MAKE_LINK_STATIC("http://www.bibletime.info", "www.bibletime.info")
"</p>";
m_bibletimeTab->setHtml(MAKE_HTML(m_bibletimeTab, content));
@@ -171,6 +169,7 @@ void BtAboutDialog::retranslateContributorsTab() {
MAKE_CONTR(content, "Andrus Raag", artist)
MAKE_CONTR2(content, "Jaak Ristioja", tr("project manager"), developer)
MAKE_CONTR(content, "Fred Saalbach", tr("documentation"))
+ MAKE_CONTR(content, "Erik Schanze", tr("documentation"))
MAKE_CONTR(content, "Gary Sims", developer)
MAKE_CONTR2(content, "Wolfgang Stradner", tr("tester"), tr("usability expert"))
MAKE_CONTR(content, "Kang Sun", developer)
@@ -217,10 +216,10 @@ void BtAboutDialog::retranslateContributorsTab() {
"<li>Dmitry Yurevich</li>"
"<li>Esteban Zeller</li>"
"</ul><p>";
- content += tr("Some names may be missing, please email %1 if you notice errors or "
- "omissions.").arg(MAKE_LINK_STATIC(
- "mailto:bibletime-translations@lists.sourceforge.net",
- "bibletime-translations@lists.sourceforge.net"));
+ content += tr("Some names may be missing, please file an issue at %1 if "
+ "you notice errors or omissions.").arg(MAKE_LINK_STATIC(
+ "https://github.com/bibletime/bibletime/issues",
+ "https://github.com/bibletime/bibletime/issues"));
content += "</p>";
m_contributorsTab->setHtml(MAKE_HTML(m_contributorsTab, content));
diff --git a/src/frontend/btaboutdialog.h b/src/frontend/btaboutdialog.h
index 132074a..b26409a 100644
--- a/src/frontend/btaboutdialog.h
+++ b/src/frontend/btaboutdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -15,21 +15,21 @@
#include <QDialog>
class QDialogButtonBox;
+class QLabel;
class QTabWidget;
class QUrl;
-class QWebView;
-class QLabel;
+class BtWebEngineView;
class BtAboutDialog: public QDialog {
Q_OBJECT
public:
- BtAboutDialog(QWidget *parent = 0, Qt::WindowFlags wflags = Qt::Dialog);
+ BtAboutDialog(QWidget *parent = nullptr, Qt::WindowFlags wflags = Qt::Dialog);
protected:
- virtual void resizeEvent(QResizeEvent* event);
+ void resizeEvent(QResizeEvent* event) override;
private:
- void initTab(QWebView *&tab);
+ void initTab(BtWebEngineView *&tab);
void retranslateUi();
void retranslateBtTab();
@@ -43,11 +43,11 @@ class BtAboutDialog: public QDialog {
private:
QTabWidget *m_tabWidget;
- QWebView *m_bibletimeTab;
- QWebView *m_contributorsTab;
- QWebView *m_swordTab;
- QWebView *m_qtTab;
- QWebView *m_licenceTab;
+ BtWebEngineView *m_bibletimeTab;
+ BtWebEngineView *m_contributorsTab;
+ BtWebEngineView *m_swordTab;
+ BtWebEngineView *m_qtTab;
+ BtWebEngineView *m_licenceTab;
QDialogButtonBox *m_buttonBox;
QLabel *m_iconLabel;
QLabel *m_versionLabel;
diff --git a/src/frontend/btaboutmoduledialog.cpp b/src/frontend/btaboutmoduledialog.cpp
index b8603b5..3d7cde3 100644
--- a/src/frontend/btaboutmoduledialog.cpp
+++ b/src/frontend/btaboutmoduledialog.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -15,6 +15,7 @@
#include "backend/drivers/cswordmoduleinfo.h"
#include "frontend/btaboutmoduledialog.h"
#include "frontend/messagedialog.h"
+#include "util/btconnect.h"
BTAboutModuleDialog::BTAboutModuleDialog(const CSwordModuleInfo *moduleInfo,
@@ -32,13 +33,12 @@ BTAboutModuleDialog::BTAboutModuleDialog(const CSwordModuleInfo *moduleInfo,
vboxLayout->addWidget(m_textEdit);
m_buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this);
- QObject::connect(m_buttons, SIGNAL(rejected()), this, SLOT(reject()));
+ BT_CONNECT(m_buttons, SIGNAL(rejected()), this, SLOT(reject()));
vboxLayout->addWidget(m_buttons);
retranslateUi();
- connect(moduleInfo, SIGNAL(destroyed()),
- this, SLOT(close()));
+ BT_CONNECT(moduleInfo, SIGNAL(destroyed()), this, SLOT(close()));
}
void BTAboutModuleDialog::retranslateUi() {
diff --git a/src/frontend/btaboutmoduledialog.h b/src/frontend/btaboutmoduledialog.h
index 05f78d1..e7a3f62 100644
--- a/src/frontend/btaboutmoduledialog.h
+++ b/src/frontend/btaboutmoduledialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -29,8 +29,8 @@ class BTAboutModuleDialog: public QDialog {
public: /* Methods: */
BTAboutModuleDialog(const CSwordModuleInfo *moduleInfo,
- QWidget *parent = 0,
- Qt::WindowFlags flags = 0);
+ QWidget *parent = nullptr,
+ Qt::WindowFlags flags = nullptr);
protected: /* Methods: */
diff --git a/src/frontend/btbookshelfdockwidget.cpp b/src/frontend/btbookshelfdockwidget.cpp
index 46ee023..78f3b42 100644
--- a/src/frontend/btbookshelfdockwidget.cpp
+++ b/src/frontend/btbookshelfdockwidget.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -25,20 +25,21 @@
#include "frontend/btbookshelfview.h"
#include "frontend/btbookshelfwidget.h"
#include "frontend/messagedialog.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
namespace {
const QString groupingOrderKey("GUI/MainWindow/Docks/Bookshelf/grouping");
}
-BtBookshelfDockWidget *BtBookshelfDockWidget::m_instance = 0;
+BtBookshelfDockWidget *BtBookshelfDockWidget::m_instance = nullptr;
BtBookshelfDockWidget::BtBookshelfDockWidget(QWidget *parent, Qt::WindowFlags f)
: QDockWidget(parent, f)
{
- Q_ASSERT(m_instance == 0);
+ BT_ASSERT(!m_instance);
m_instance = this;
setObjectName("BookshelfDock");
@@ -82,22 +83,29 @@ BtBookshelfDockWidget::BtBookshelfDockWidget(QWidget *parent, Qt::WindowFlags f)
setWidget(m_stackedWidget);
// Connect signals:
- connect(m_bookshelfWidget->treeView(), SIGNAL(moduleActivated(CSwordModuleInfo*)),
- this, SLOT(slotModuleActivated(CSwordModuleInfo*)));
- connect(m_bookshelfWidget->treeView(), SIGNAL(moduleHovered(CSwordModuleInfo*)),
- this, SIGNAL(moduleHovered(CSwordModuleInfo*)));
- connect(m_treeModel, SIGNAL(moduleChecked(CSwordModuleInfo*, bool)),
- this, SLOT(slotModuleChecked(CSwordModuleInfo*, bool)));
- connect(m_treeModel, SIGNAL(groupingOrderChanged(BtBookshelfTreeModel::Grouping)),
- this, SLOT(slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping&)));
- connect(m_bookshelfWidget->showHideAction(), SIGNAL(toggled(bool)),
- m_treeModel, SLOT(setCheckable(bool)));
- connect(bookshelfModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
- this, SLOT(slotModulesChanged()));
- connect(bookshelfModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
- this, SLOT(slotModulesChanged()));
- connect(m_installButton, SIGNAL(clicked()),
- BibleTime::instance(), SLOT(slotSwordSetupDialog()));
+ BT_CONNECT(m_bookshelfWidget->treeView(),
+ SIGNAL(moduleActivated(CSwordModuleInfo *)),
+ this, SLOT(slotModuleActivated(CSwordModuleInfo *)));
+ BT_CONNECT(m_bookshelfWidget->treeView(),
+ SIGNAL(moduleHovered(CSwordModuleInfo *)),
+ this, SIGNAL(moduleHovered(CSwordModuleInfo *)));
+ BT_CONNECT(m_treeModel, SIGNAL(moduleChecked(CSwordModuleInfo *, bool)),
+ this, SLOT(slotModuleChecked(CSwordModuleInfo *, bool)));
+ BT_CONNECT(m_treeModel,
+ SIGNAL(groupingOrderChanged(BtBookshelfTreeModel::Grouping)),
+ this,
+ SLOT(slotGroupingOrderChanged(
+ BtBookshelfTreeModel::Grouping const &)));
+ BT_CONNECT(m_bookshelfWidget->showHideAction(), SIGNAL(toggled(bool)),
+ m_treeModel, SLOT(setCheckable(bool)));
+ BT_CONNECT(bookshelfModel,
+ SIGNAL(rowsInserted(QModelIndex const &, int, int)),
+ this, SLOT(slotModulesChanged()));
+ BT_CONNECT(bookshelfModel,
+ SIGNAL(rowsRemoved(QModelIndex const &, int, int)),
+ this, SLOT(slotModulesChanged()));
+ BT_CONNECT(m_installButton, SIGNAL(clicked()),
+ BibleTime::instance(), SLOT(slotBookshelfWizard()));
retranslateUi();
}
@@ -107,43 +115,43 @@ void BtBookshelfDockWidget::initMenus() {
m_itemContextMenu = new QMenu(this);
m_itemActionGroup = new QActionGroup(this);
- connect(m_itemActionGroup, SIGNAL(triggered(QAction*)),
- this, SLOT(slotItemActionTriggered(QAction*)));
+ BT_CONNECT(m_itemActionGroup, SIGNAL(triggered(QAction *)),
+ this, SLOT(slotItemActionTriggered(QAction *)));
m_itemOpenAction = new QAction(this);
m_itemActionGroup->addAction(m_itemOpenAction);
m_itemContextMenu->addAction(m_itemOpenAction);
m_itemSearchAction = new QAction(this);
- m_itemSearchAction->setIcon(util::getIcon(RM::search::icon));
+ m_itemSearchAction->setIcon(RM::search::icon());
m_itemActionGroup->addAction(m_itemSearchAction);
m_itemContextMenu->addAction(m_itemSearchAction);
m_itemEditMenu = new QMenu(this);
- m_itemEditMenu->setIcon(util::getIcon(RM::editModuleMenu::icon));
+ m_itemEditMenu->setIcon(RM::editModuleMenu::icon());
m_itemContextMenu->addMenu(m_itemEditMenu);
m_itemEditPlainAction = new QAction(this);
- m_itemEditPlainAction->setIcon(util::getIcon(RM::editModulePlain::icon));
+ m_itemEditPlainAction->setIcon(RM::editModulePlain::icon());
m_itemActionGroup->addAction(m_itemEditPlainAction);
m_itemEditMenu->addAction(m_itemEditPlainAction);
m_itemEditHtmlAction = new QAction(this);
- m_itemEditHtmlAction->setIcon(util::getIcon(RM::editModuleHTML::icon));
+ m_itemEditHtmlAction->setIcon(RM::editModuleHTML::icon());
m_itemActionGroup->addAction(m_itemEditHtmlAction);
m_itemEditMenu->addAction(m_itemEditHtmlAction);
m_itemUnlockAction = new QAction(this);
- m_itemUnlockAction->setIcon(util::getIcon(RM::unlockModule::icon));
+ m_itemUnlockAction->setIcon(RM::unlockModule::icon());
m_itemActionGroup->addAction(m_itemUnlockAction);
m_itemContextMenu->addAction(m_itemUnlockAction);
m_itemAboutAction = new QAction(this);
- m_itemAboutAction->setIcon(util::getIcon(RM::aboutModule::icon));
+ m_itemAboutAction->setIcon(RM::aboutModule::icon());
m_itemActionGroup->addAction(m_itemAboutAction);
m_itemContextMenu->addAction(m_itemAboutAction);
- connect(m_itemContextMenu, SIGNAL(aboutToShow()),
- this, SLOT(slotPrepareItemContextMenu()));
+ BT_CONNECT(m_itemContextMenu, SIGNAL(aboutToShow()),
+ this, SLOT(slotPrepareItemContextMenu()));
}
void BtBookshelfDockWidget::retranslateUi() {
@@ -181,7 +189,7 @@ void BtBookshelfDockWidget::slotModuleActivated(CSwordModuleInfo *module) {
if (BibleTime::moduleUnlock(module)) {
// Re-initialize module pointer:
module = CSwordBackend::instance()->findModuleByName(moduleName);
- Q_ASSERT(module != 0);
+ BT_ASSERT(module);
emit moduleOpenTriggered(module);
}
@@ -193,8 +201,10 @@ void BtBookshelfDockWidget::slotModuleChecked(CSwordModuleInfo *module, bool c)
}
void BtBookshelfDockWidget::slotItemActionTriggered(QAction *action) {
- CSwordModuleInfo *module((CSwordModuleInfo*) m_itemContextMenu->property("BtModule").value<void*>());
- if (module == 0) return;
+ CSwordModuleInfo * const module =
+ static_cast<CSwordModuleInfo *>(
+ m_itemContextMenu->property("BtModule").value<void *>());
+ if (module == nullptr) return;
if (action == m_itemOpenAction) {
emit moduleOpenTriggered(module);
diff --git a/src/frontend/btbookshelfdockwidget.h b/src/frontend/btbookshelfdockwidget.h
index fe415d7..a18b0a3 100644
--- a/src/frontend/btbookshelfdockwidget.h
+++ b/src/frontend/btbookshelfdockwidget.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -29,7 +29,7 @@ class QStackedWidget;
class BtBookshelfDockWidget: public QDockWidget {
Q_OBJECT
public:
- BtBookshelfDockWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
+ BtBookshelfDockWidget(QWidget *parent = nullptr, Qt::WindowFlags f = nullptr);
static inline BtBookshelfDockWidget *getInstance() { return m_instance; }
diff --git a/src/frontend/btbookshelfgroupingmenu.cpp b/src/frontend/btbookshelfgroupingmenu.cpp
index c456f80..e182990 100644
--- a/src/frontend/btbookshelfgroupingmenu.cpp
+++ b/src/frontend/btbookshelfgroupingmenu.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -13,9 +13,10 @@
#include "frontend/btbookshelfgroupingmenu.h"
#include "bibletimeapp.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
#include "util/directory.h"
-#include "util/geticon.h"
namespace {
@@ -27,11 +28,11 @@ BtBookshelfTreeModel::Grouping groupingLang(true);
BtBookshelfTreeModel::Grouping groupingLangCat(true);
inline void initializeGroups() {
- Q_ASSERT(groupingNone.empty());
+ BT_ASSERT(groupingNone.empty());
groupingCat.append(BtBookshelfTreeModel::GROUP_CATEGORY);
- Q_ASSERT(groupingCatLang.size() == 2);
- Q_ASSERT(groupingCatLang.at(0) == BtBookshelfTreeModel::GROUP_CATEGORY);
- Q_ASSERT(groupingCatLang.at(1) == BtBookshelfTreeModel::GROUP_LANGUAGE);
+ BT_ASSERT(groupingCatLang.size() == 2);
+ BT_ASSERT(groupingCatLang.at(0) == BtBookshelfTreeModel::GROUP_CATEGORY);
+ BT_ASSERT(groupingCatLang.at(1) == BtBookshelfTreeModel::GROUP_LANGUAGE);
groupingLang.append(BtBookshelfTreeModel::GROUP_LANGUAGE);
groupingLangCat.append(BtBookshelfTreeModel::GROUP_LANGUAGE);
groupingLangCat.append(BtBookshelfTreeModel::GROUP_CATEGORY);
@@ -39,27 +40,28 @@ inline void initializeGroups() {
}
inline void setActionRef(QAction *a, const BtBookshelfTreeModel::Grouping &g) {
- a->setProperty("groupingPointer", QVariant::fromValue((void*) &g));
+ a->setProperty("groupingPointer",
+ QVariant::fromValue(
+ const_cast<void *>(static_cast<void const *>(&g))));
}
inline const BtBookshelfTreeModel::Grouping &getActionRef(const QAction *a) {
- return *((const BtBookshelfTreeModel::Grouping*) a->property("groupingPointer").value<void*>());
+ return *static_cast<BtBookshelfTreeModel::Grouping const *>(
+ a->property("groupingPointer").value<void *>());
}
} // anonymous namespace
void BtBookshelfGroupingMenu::initMenu(bool showNoGrouping) {
- namespace RM = CResMgr::mainIndex;
-
if (!groupsInitialized) initializeGroups();
- setIcon(util::getIcon(RM::grouping::icon));
+ setIcon(CResMgr::mainIndex::grouping::icon());
m_groupingActionGroup = new QActionGroup(this);
m_groupingActionGroup->setExclusive(true);
- connect(m_groupingActionGroup, SIGNAL(triggered(QAction*)),
- this, SLOT(slotGroupingActionTriggered(QAction*)));
+ BT_CONNECT(m_groupingActionGroup, SIGNAL(triggered(QAction *)),
+ this, SLOT(slotGroupingActionTriggered(QAction *)));
m_groupingCatLangAction = new QAction(this);
m_groupingCatLangAction->setCheckable(true);
@@ -92,7 +94,7 @@ void BtBookshelfGroupingMenu::initMenu(bool showNoGrouping) {
m_groupingActionGroup->addAction(m_groupingNoneAction);
addAction(m_groupingNoneAction);
} else {
- m_groupingNoneAction = 0;
+ m_groupingNoneAction = nullptr;
}
retranslateUi();
@@ -104,7 +106,7 @@ void BtBookshelfGroupingMenu::retranslateUi() {
m_groupingLangCatAction->setText(tr("Language/Category"));
m_groupingLangAction->setText(tr("Language"));
- if (m_groupingNoneAction != 0) {
+ if (m_groupingNoneAction != nullptr) {
m_groupingNoneAction->setText(tr("No grouping"));
}
}
diff --git a/src/frontend/btbookshelfgroupingmenu.h b/src/frontend/btbookshelfgroupingmenu.h
index f49c3c0..40e35f9 100644
--- a/src/frontend/btbookshelfgroupingmenu.h
+++ b/src/frontend/btbookshelfgroupingmenu.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -24,11 +24,11 @@ class QActionGroup;
class BtBookshelfGroupingMenu: public QMenu {
Q_OBJECT
public:
- explicit inline BtBookshelfGroupingMenu(QWidget *parent = 0)
+ explicit inline BtBookshelfGroupingMenu(QWidget *parent = nullptr)
: QMenu(parent) { initMenu(true); }
explicit inline BtBookshelfGroupingMenu(bool showNoGrouping,
- QWidget *parent = 0)
+ QWidget *parent = nullptr)
: QMenu(parent) { initMenu(showNoGrouping); }
signals:
diff --git a/src/frontend/btbookshelfview.cpp b/src/frontend/btbookshelfview.cpp
index 1a04eff..f6d3585 100644
--- a/src/frontend/btbookshelfview.cpp
+++ b/src/frontend/btbookshelfview.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -16,6 +16,7 @@
#include <QMouseEvent>
#include "backend/bookshelfmodel/btbookshelftreemodel.h"
#include "backend/drivers/cswordmoduleinfo.h"
+#include "util/btconnect.h"
BtBookshelfView::BtBookshelfView(QWidget *parent)
@@ -31,10 +32,10 @@ BtBookshelfView::BtBookshelfView(QWidget *parent)
*/
// setRootIsDecorated(false);
- connect(this, SIGNAL(activated(QModelIndex)),
- this, SLOT(slotItemActivated(QModelIndex)));
- connect(this, SIGNAL(entered(QModelIndex)),
- this, SLOT(slotItemHovered(QModelIndex)));
+ BT_CONNECT(this, SIGNAL(activated(QModelIndex)),
+ this, SLOT(slotItemActivated(QModelIndex)));
+ BT_CONNECT(this, SIGNAL(entered(QModelIndex)),
+ this, SLOT(slotItemHovered(QModelIndex)));
}
CSwordModuleInfo * BtBookshelfView::getModule(const QModelIndex & index) const {
@@ -51,7 +52,7 @@ void BtBookshelfView::keyPressEvent(QKeyEvent *event) {
CSwordModuleInfo *i(getModule(currentIndex()));
QRect itemRect(visualRect(currentIndex()));
QPoint p(viewport()->mapToGlobal(itemRect.bottomLeft()));
- if (i == 0) {
+ if (i == nullptr) {
emit contextMenuActivated(p);
}
else {
@@ -64,7 +65,7 @@ void BtBookshelfView::keyPressEvent(QKeyEvent *event) {
case Qt::Key_Enter: {
QModelIndex i(currentIndex());
CSwordModuleInfo *m(getModule(i));
- if (m != 0) {
+ if (m != nullptr) {
emit moduleActivated(m);
}
else {
@@ -86,7 +87,7 @@ void BtBookshelfView::mousePressEvent(QMouseEvent *event) {
setCurrentIndex(clickedItemIndex);
}
CSwordModuleInfo *i(getModule(clickedItemIndex));
- if (i == 0) {
+ if (i == nullptr) {
emit contextMenuActivated(mapToGlobal(event->pos()));
}
else {
@@ -101,7 +102,7 @@ void BtBookshelfView::mousePressEvent(QMouseEvent *event) {
void BtBookshelfView::slotItemActivated(const QModelIndex &index) {
CSwordModuleInfo *i(getModule(index));
- if (i != 0) {
+ if (i != nullptr) {
emit moduleActivated(i);
}
}
diff --git a/src/frontend/btbookshelfview.h b/src/frontend/btbookshelfview.h
index f957785..a9c5dd7 100644
--- a/src/frontend/btbookshelfview.h
+++ b/src/frontend/btbookshelfview.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -21,7 +21,7 @@ class CSwordModuleInfo;
class BtBookshelfView: public QTreeView {
Q_OBJECT
public:
- BtBookshelfView(QWidget *parent = 0);
+ BtBookshelfView(QWidget *parent = nullptr);
CSwordModuleInfo *getModule(const QModelIndex &index) const;
@@ -33,8 +33,8 @@ class BtBookshelfView: public QTreeView {
void moduleHovered(CSwordModuleInfo *item);
protected:
- void keyPressEvent(QKeyEvent *event);
- void mousePressEvent(QMouseEvent *event);
+ void keyPressEvent(QKeyEvent *event) override;
+ void mousePressEvent(QMouseEvent *event) override;
protected slots:
void slotItemActivated(const QModelIndex &index);
diff --git a/src/frontend/btbookshelfwidget.cpp b/src/frontend/btbookshelfwidget.cpp
index 2ce812e..819cabe 100644
--- a/src/frontend/btbookshelfwidget.cpp
+++ b/src/frontend/btbookshelfwidget.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -25,22 +25,21 @@
#include <QVBoxLayout>
#include "backend/bookshelfmodel/btbookshelffiltermodel.h"
#include "bibletimeapp.h"
-#include "frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.h"
-#include "frontend/bookshelfmanager/removepage/btremovepagetreemodel.h"
#include "frontend/btbookshelfdockwidget.h"
#include "frontend/btbookshelfgroupingmenu.h"
#include "frontend/btbookshelfview.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
#include "util/directory.h"
-#include "util/geticon.h"
BtBookshelfWidget::BtBookshelfWidget(QWidget *parent, Qt::WindowFlags flags)
: QWidget(parent, flags)
- , m_sourceModel(0)
- , m_treeModel(0)
- , m_leftCornerWidget(0)
- , m_rightCornerWidget(0)
+ , m_sourceModel(nullptr)
+ , m_treeModel(nullptr)
+ , m_leftCornerWidget(nullptr)
+ , m_rightCornerWidget(nullptr)
{
// Setup post-filter:
m_postFilterModel = new BtBookshelfFilterModel(this);
@@ -55,27 +54,28 @@ BtBookshelfWidget::BtBookshelfWidget(QWidget *parent, Qt::WindowFlags flags)
retranslateUi();
- connect(m_nameFilterEdit, SIGNAL(textEdited(QString)),
- m_postFilterModel, SLOT(setNameFilterFixedString(QString)));
- connect(m_treeView, SIGNAL(contextMenuActivated(QPoint)),
- this, SLOT(slotShowContextMenu(QPoint)));
- connect(m_treeView, SIGNAL(moduleContextMenuActivated(CSwordModuleInfo*, QPoint)),
- this, SLOT(slotShowItemContextMenu(CSwordModuleInfo*, QPoint)));
+ BT_CONNECT(m_nameFilterEdit, SIGNAL(textEdited(QString)),
+ m_postFilterModel, SLOT(setNameFilterFixedString(QString)));
+ BT_CONNECT(m_treeView, SIGNAL(contextMenuActivated(QPoint)),
+ this, SLOT(slotShowContextMenu(QPoint)));
+ BT_CONNECT(m_treeView,
+ SIGNAL(moduleContextMenuActivated(CSwordModuleInfo *, QPoint)),
+ this, SLOT(slotShowItemContextMenu(CSwordModuleInfo *, QPoint)));
}
void BtBookshelfWidget::setSourceModel(QAbstractItemModel *model) {
- Q_ASSERT(model != 0);
+ BT_ASSERT(model);
m_sourceModel = model;
- if (m_treeModel != 0) {
+ if (m_treeModel != nullptr) {
m_treeModel->setSourceModel(model);
}
}
void BtBookshelfWidget::setTreeModel(BtBookshelfTreeModel *model) {
- Q_ASSERT(model != 0);
- Q_ASSERT(m_treeModel == 0);
+ BT_ASSERT(model);
+ BT_ASSERT(!m_treeModel);
m_treeModel = model;
- if (m_sourceModel != 0) {
+ if (m_sourceModel != nullptr) {
model->setSourceModel(m_sourceModel);
}
m_postFilterModel->setSourceModel(model);
@@ -94,23 +94,22 @@ void BtBookshelfWidget::setRightCornerWidget(QWidget *w) {
}
void BtBookshelfWidget::initActions() {
- namespace RM = CResMgr::mainIndex;
-
m_showHideAction = new QAction(this);
- m_showHideAction->setIcon(util::getIcon("layer-visible-on.svg"));
+ m_showHideAction->setIcon(CResMgr::mainIndex::showHide::icon());
m_showHideAction->setCheckable(true);
- connect(m_showHideAction, SIGNAL(toggled(bool)),
- m_postFilterModel, SLOT(setShowHidden(bool)));
+ BT_CONNECT(m_showHideAction, SIGNAL(toggled(bool)),
+ m_postFilterModel, SLOT(setShowHidden(bool)));
}
void BtBookshelfWidget::initMenus() {
- namespace DU = util::directory;
- namespace RM = CResMgr::mainIndex;
-
// Grouping menu:
m_groupingMenu = new BtBookshelfGroupingMenu(this);
- connect(m_groupingMenu, SIGNAL(signalGroupingOrderChanged(BtBookshelfTreeModel::Grouping)),
- this, SLOT(slotGroupingActionTriggered(BtBookshelfTreeModel::Grouping)));
+ BT_CONNECT(m_groupingMenu,
+ SIGNAL(signalGroupingOrderChanged(
+ BtBookshelfTreeModel::Grouping)),
+ this,
+ SLOT(slotGroupingActionTriggered(
+ BtBookshelfTreeModel::Grouping)));
// Context menu
m_contextMenu = new QMenu(this);
@@ -162,7 +161,7 @@ void BtBookshelfWidget::retranslateUi() {
}
bool BtBookshelfWidget::eventFilter(QObject *object, QEvent *event) {
- Q_ASSERT(object == m_nameFilterEdit);
+ BT_ASSERT(object == m_nameFilterEdit);
if (event->type() == QEvent::KeyPress) {
QKeyEvent *e = static_cast<QKeyEvent*>(event);
switch (e->key()) {
@@ -190,8 +189,10 @@ void BtBookshelfWidget::slotShowContextMenu(const QPoint &pos) {
void BtBookshelfWidget::slotShowItemContextMenu(CSwordModuleInfo *module, const QPoint &pos)
{
- if (m_itemContextMenu != 0) {
- m_itemContextMenu->setProperty("BtModule", qVariantFromValue((void*) module));
+ if (m_itemContextMenu != nullptr) {
+ m_itemContextMenu->setProperty("BtModule",
+ qVariantFromValue(
+ static_cast<void *>(module)));
m_itemContextMenu->popup(pos);
} else {
m_itemContextMenu = m_contextMenu;
diff --git a/src/frontend/btbookshelfwidget.h b/src/frontend/btbookshelfwidget.h
index 7811b5c..09ab5aa 100644
--- a/src/frontend/btbookshelfwidget.h
+++ b/src/frontend/btbookshelfwidget.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -34,7 +34,7 @@ class QToolButton;
class BtBookshelfWidget: public QWidget {
Q_OBJECT
public:
- explicit BtBookshelfWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0);
+ explicit BtBookshelfWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr);
void setSourceModel(QAbstractItemModel *model);
@@ -68,7 +68,7 @@ class BtBookshelfWidget: public QWidget {
inline void setContextMenu(QMenu *newMenu) { m_contextMenu = newMenu; }
inline void setItemContextMenu(QMenu *newMenu) { m_itemContextMenu = newMenu; }
- bool eventFilter(QObject *object, QEvent *event);
+ bool eventFilter(QObject *object, QEvent *event) override;
protected:
void initActions();
diff --git a/src/frontend/btcentralwidget.cpp b/src/frontend/btcentralwidget.cpp
index 04615c3..e812ad5 100644
--- a/src/frontend/btcentralwidget.cpp
+++ b/src/frontend/btcentralwidget.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
diff --git a/src/frontend/btcentralwidget.h b/src/frontend/btcentralwidget.h
index 3ef9002..a136b4c 100644
--- a/src/frontend/btcentralwidget.h
+++ b/src/frontend/btcentralwidget.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
diff --git a/src/frontend/btmenuview.cpp b/src/frontend/btmenuview.cpp
index 919602b..d422de2 100644
--- a/src/frontend/btmenuview.cpp
+++ b/src/frontend/btmenuview.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -13,15 +13,17 @@
#include "frontend/btmenuview.h"
#include <QActionGroup>
+#include "util/btassert.h"
+#include "util/btconnect.h"
BtMenuView::BtMenuView(QWidget *parent)
- : QMenu(parent), m_model(0), m_parentIndex(QModelIndex()), m_actions(0)
+ : QMenu(parent), m_model(nullptr), m_parentIndex(QModelIndex()), m_actions(nullptr)
{
- connect(this, SIGNAL(aboutToShow()),
- this, SLOT(slotAboutToShow()));
- connect(this, SIGNAL(triggered(QAction*)),
- this, SLOT(slotActionTriggered(QAction*)));
+ BT_CONNECT(this, SIGNAL(aboutToShow()),
+ this, SLOT(slotAboutToShow()));
+ BT_CONNECT(this, SIGNAL(triggered(QAction*)),
+ this, SLOT(slotActionTriggered(QAction*)));
}
BtMenuView::~BtMenuView() {
@@ -31,7 +33,7 @@ BtMenuView::~BtMenuView() {
void BtMenuView::setModel(QAbstractItemModel *model) {
m_model = model;
delete m_actions;
- m_actions = 0;
+ m_actions = nullptr;
m_indexMap.clear();
m_parentIndex = QModelIndex();
}
@@ -91,10 +93,10 @@ QAction *BtMenuView::newAction(QMenu *parentMenu, const QModelIndex &itemIndex)
// Set checked:
QVariant checkData(m_model->data(itemIndex, Qt::CheckStateRole));
bool ok;
- Qt::CheckState state = (Qt::CheckState) checkData.toInt(&ok);
- if (ok) {
+ Qt::CheckState const state =
+ static_cast<Qt::CheckState>(checkData.toInt(&ok));
+ if (ok)
childAction->setChecked(state == Qt::Checked);
- }
return childAction;
}
@@ -137,8 +139,8 @@ QMenu *BtMenuView::newMenu(QMenu *parentMenu, const QModelIndex &itemIndex) {
}
void BtMenuView::buildMenu(QMenu *parentMenu, const QModelIndex &parentIndex) {
- Q_ASSERT(m_model != 0);
- Q_ASSERT(m_actions != 0);
+ BT_ASSERT(m_model);
+ BT_ASSERT(m_actions);
int children = m_model->rowCount(parentIndex);
for (int i = 0; i < children; i++) {
@@ -147,7 +149,7 @@ void BtMenuView::buildMenu(QMenu *parentMenu, const QModelIndex &parentIndex) {
if (m_model->rowCount(childIndex) > 0) {
QMenu *childMenu = newMenu(parentMenu, childIndex);
- if (childMenu != 0) {
+ if (childMenu != nullptr) {
// Add the child menu and populate it:
parentMenu->addMenu(childMenu);
buildMenu(childMenu, childIndex);
@@ -155,7 +157,7 @@ void BtMenuView::buildMenu(QMenu *parentMenu, const QModelIndex &parentIndex) {
} else {
QAction *childAction = newAction(parentMenu, childIndex);
- if (childAction != 0) {
+ if (childAction != nullptr) {
// Map index
m_indexMap.insert(childAction, childIndex);
@@ -175,12 +177,12 @@ void BtMenuView::slotAboutToShow() {
// to remove the menus here.
removeMenus();
delete m_actions;
- m_actions = 0;
+ m_actions = nullptr;
m_indexMap.clear();
preBuildMenu();
- if (m_model != 0) {
+ if (m_model != nullptr) {
m_actions = new QActionGroup(this);
buildMenu(this, m_parentIndex);
diff --git a/src/frontend/btmenuview.h b/src/frontend/btmenuview.h
index 39b56f6..d2e1100 100644
--- a/src/frontend/btmenuview.h
+++ b/src/frontend/btmenuview.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -44,7 +44,7 @@ class QActionGroup;
class BtMenuView: public QMenu {
Q_OBJECT
public:
- BtMenuView(QWidget *parent = 0);
+ BtMenuView(QWidget *parent = nullptr);
virtual ~BtMenuView();
/**
diff --git a/src/frontend/btmodulechooserdialog.cpp b/src/frontend/btmodulechooserdialog.cpp
index e6ed79f..bc7a63a 100644
--- a/src/frontend/btmodulechooserdialog.cpp
+++ b/src/frontend/btmodulechooserdialog.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -20,6 +20,7 @@
#include "frontend/btbookshelfview.h"
#include "frontend/btbookshelfwidget.h"
#include "frontend/messagedialog.h"
+#include "util/btconnect.h"
#include "util/tool.h"
@@ -32,16 +33,15 @@ BtModuleChooserDialog::BtModuleChooserDialog(QWidget *parent, Qt::WindowFlags fl
mainLayout->addWidget(m_captionLabel);
m_bookshelfWidget = new BtBookshelfWidget(this);
- connect(m_bookshelfWidget->treeView(), SIGNAL(moduleActivated(CSwordModuleInfo*)),
- this, SLOT(slotModuleAbout(CSwordModuleInfo*)));
+ BT_CONNECT(m_bookshelfWidget->treeView(),
+ SIGNAL(moduleActivated(CSwordModuleInfo *)),
+ this, SLOT(slotModuleAbout(CSwordModuleInfo *)));
mainLayout->addWidget(m_bookshelfWidget);
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok,
Qt::Horizontal, this);
- connect(m_buttonBox, SIGNAL(accepted()),
- this, SLOT(accept()));
- connect(m_buttonBox, SIGNAL(rejected()),
- this, SLOT(reject()));
+ BT_CONNECT(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ BT_CONNECT(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
mainLayout->addWidget(m_buttonBox);
setLayout(mainLayout);
diff --git a/src/frontend/btmodulechooserdialog.h b/src/frontend/btmodulechooserdialog.h
index 685ac48..f2ab06b 100644
--- a/src/frontend/btmodulechooserdialog.h
+++ b/src/frontend/btmodulechooserdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -26,7 +26,7 @@ class BtModuleChooserDialog : public QDialog {
Q_OBJECT
protected:
- explicit BtModuleChooserDialog(QWidget *parent = 0, Qt::WindowFlags flags = 0);
+ explicit BtModuleChooserDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr);
void retranslateUi();
diff --git a/src/frontend/btmoduleindexdialog.cpp b/src/frontend/btmoduleindexdialog.cpp
index 2714ea7..8b70541 100644
--- a/src/frontend/btmoduleindexdialog.cpp
+++ b/src/frontend/btmoduleindexdialog.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,43 +12,40 @@
#include <QApplication>
#include <QMutexLocker>
#include "backend/managers/cswordbackend.h"
+#include "frontend/messagedialog.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
-QMutex BtModuleIndexDialog::m_singleInstanceMutex;
-
-bool BtModuleIndexDialog::indexAllModules(
- const QList<const CSwordModuleInfo*> &modules)
+bool BtModuleIndexDialog::indexAllModules(const QList<CSwordModuleInfo *> &modules)
{
- QMutexLocker lock(&m_singleInstanceMutex);
+ static QMutex mutex;
+ QMutexLocker lock(&mutex);
if (modules.empty()) return true;
BtModuleIndexDialog d(modules.size());
d.show();
d.raise();
- return d.indexAllModules2(modules);
+ return d.indexAllModulesPrivate(modules);
}
BtModuleIndexDialog::BtModuleIndexDialog(int numModules)
: QProgressDialog(tr("Preparing to index modules..."), tr("Cancel"), 0,
- numModules * 100, 0),
+ numModules * 100, nullptr),
m_currentModuleIndex(0)
{
setWindowTitle(tr("Creating indices"));
setModal(true);
}
-bool BtModuleIndexDialog::indexAllModules2(
- const QList<const CSwordModuleInfo*> &modules)
+bool BtModuleIndexDialog::indexAllModulesPrivate(const QList<CSwordModuleInfo*> &modules)
{
bool success = true;
- QList<CSwordModuleInfo *> indexedModules;
- Q_FOREACH(const CSwordModuleInfo *cm, modules) {
- Q_ASSERT(!cm->hasIndex());
-
- /// \warning const_cast
- CSwordModuleInfo *m = const_cast<CSwordModuleInfo*>(cm);
+ QList <CSwordModuleInfo*> indexedModules;
+ Q_FOREACH(CSwordModuleInfo * const m, modules) {
+ BT_ASSERT(!m->hasIndex());
/*
Keep track of created indices to delete them on failure or
@@ -56,17 +53,23 @@ bool BtModuleIndexDialog::indexAllModules2(
*/
indexedModules.append(m);
- connect(this, SIGNAL(canceled()),
- m, SLOT(cancelIndexing()));
- connect(m, SIGNAL(indexingFinished()),
- this, SLOT(slotFinished()));
- connect(m, SIGNAL(indexingProgress(int)),
- this, SLOT(slotModuleProgress(int)));
+ BT_CONNECT(this, SIGNAL(canceled()), m, SLOT(cancelIndexing()));
+ BT_CONNECT(m, SIGNAL(indexingFinished()), this, SLOT(slotFinished()));
+ BT_CONNECT(m, SIGNAL(indexingProgress(int)),
+ this, SLOT(slotModuleProgress(int)));
// Single module indexing blocks until finished:
setLabelText(tr("Creating index for work: %1").arg(m->name()));
- if (!m->buildIndex()) success = false;
+ try {
+ m->buildIndex();
+ } catch (...) {
+ message::showWarning(this,
+ tr("Indexing aborted"),
+ tr("An internal error occurred while building "
+ "the index."));
+ success = false;
+ }
m_currentModuleIndex++;
@@ -82,14 +85,11 @@ bool BtModuleIndexDialog::indexAllModules2(
if (!success) break;
}
- if (!success) {
+ if (!success)
// Delete already created indices:
- Q_FOREACH(CSwordModuleInfo *m, indexedModules) {
- if (m->hasIndex()) {
+ Q_FOREACH(CSwordModuleInfo * const m, indexedModules)
+ if (m->hasIndex())
m->deleteIndex();
- }
- }
- }
return success;
}
diff --git a/src/frontend/btmoduleindexdialog.h b/src/frontend/btmoduleindexdialog.h
index 8b794f9..581a838 100644
--- a/src/frontend/btmoduleindexdialog.h
+++ b/src/frontend/btmoduleindexdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -14,8 +14,6 @@
#include <QProgressDialog>
-#include <QMutex>
-
class CSwordModuleInfo;
@@ -26,7 +24,6 @@ class CSwordModuleInfo;
*/
class BtModuleIndexDialog: public QProgressDialog {
Q_OBJECT
- Q_DISABLE_COPY(BtModuleIndexDialog)
public: /* Methods: */
/**
@@ -39,7 +36,7 @@ class BtModuleIndexDialog: public QProgressDialog {
\pre all given modules are unindexed
\returns whether the indexing was finished successfully.
*/
- static bool indexAllModules(const QList<const CSwordModuleInfo*> &modules);
+ static bool indexAllModules(const QList<CSwordModuleInfo*> &modules);
private: /* Methods: */
BtModuleIndexDialog(int numModules);
@@ -53,14 +50,13 @@ class BtModuleIndexDialog: public QProgressDialog {
\pre all given modules are unindexed
\returns whether the indexing was finished successfully.
*/
- bool indexAllModules2(const QList<const CSwordModuleInfo*> &modules);
+ bool indexAllModulesPrivate(const QList<CSwordModuleInfo*> &modules);
private slots:
void slotModuleProgress(int percentage);
void slotFinished();
private: /* Fields: */
- static QMutex m_singleInstanceMutex;
int m_currentModuleIndex;
};
diff --git a/src/frontend/btopenworkaction.cpp b/src/frontend/btopenworkaction.cpp
index a398412..2a5aae3 100644
--- a/src/frontend/btopenworkaction.cpp
+++ b/src/frontend/btopenworkaction.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -16,13 +16,17 @@
#include "backend/managers/cswordbackend.h"
#include "bibletimeapp.h"
#include "frontend/btbookshelfgroupingmenu.h"
-#include "util/geticon.h"
+#include "util/btconnect.h"
+#include "util/cresmgr.h"
BtOpenWorkActionMenu::BtOpenWorkActionMenu(const QString &groupingConfigKey,
QWidget *parent)
- : BtMenuView(parent), m_treeModel(0), m_postFilterModel(0),
- m_groupingConfigKey(groupingConfigKey)
+ : BtMenuView(parent)
+ , m_treeModel(nullptr)
+ , m_postFilterModel(nullptr)
+ , m_groupingMenu(nullptr)
+ , m_groupingConfigKey(groupingConfigKey)
{
// Setup models:
m_treeModel = new BtBookshelfTreeModel(groupingConfigKey, this);
@@ -30,8 +34,8 @@ BtOpenWorkActionMenu::BtOpenWorkActionMenu(const QString &groupingConfigKey,
m_postFilterModel->setSourceModel(m_treeModel);
setModel(m_postFilterModel);
- connect(this, SIGNAL(triggered(QModelIndex)),
- this, SLOT(slotIndexTriggered(QModelIndex)));
+ BT_CONNECT(this, SIGNAL(triggered(QModelIndex)),
+ this, SLOT(slotIndexTriggered(QModelIndex)));
}
void BtOpenWorkActionMenu::setSourceModel(QAbstractItemModel *model) {
@@ -39,6 +43,8 @@ void BtOpenWorkActionMenu::setSourceModel(QAbstractItemModel *model) {
}
void BtOpenWorkActionMenu::retranslateUi() {
+ if (!m_groupingMenu)
+ return;
m_groupingMenu->setTitle(tr("&Grouping order"));
m_groupingMenu->setStatusTip(tr("Sets the grouping order for the items in "
"this menu."));
@@ -48,8 +54,12 @@ void BtOpenWorkActionMenu::postBuildMenu() {
addSeparator();
m_groupingMenu = new BtBookshelfGroupingMenu(false, this);
- connect(m_groupingMenu, SIGNAL(signalGroupingOrderChanged(BtBookshelfTreeModel::Grouping)),
- this, SLOT(slotGroupingActionTriggered(BtBookshelfTreeModel::Grouping)));
+ BT_CONNECT(m_groupingMenu,
+ SIGNAL(signalGroupingOrderChanged(
+ BtBookshelfTreeModel::Grouping)),
+ this,
+ SLOT(slotGroupingActionTriggered(
+ BtBookshelfTreeModel::Grouping)));
retranslateUi();
addMenu(m_groupingMenu);
@@ -60,7 +70,7 @@ void BtOpenWorkActionMenu::slotIndexTriggered(const QModelIndex &index) {
CSwordModuleInfo *i;
i = static_cast<CSwordModuleInfo *>(model()->data(index, MPR).value<void*>());
- if (i != 0) {
+ if (i != nullptr) {
emit triggered(i);
}
}
@@ -78,21 +88,21 @@ BtOpenWorkAction::BtOpenWorkAction(const QString &groupingConfigKey,
m_menu->setSourceModel(CSwordBackend::instance()->model());
setMenu(m_menu);
- setIcon(util::getIcon("folder-open.svg"));
+ setIcon(CResMgr::mainWindow::icon_openAction());
retranslateUi();
slotModelChanged();
BtBookshelfFilterModel *filterModel = m_menu->postFilterModel();
- connect(m_menu, SIGNAL(triggered(CSwordModuleInfo*)),
- this, SIGNAL(triggered(CSwordModuleInfo*)));
- connect(filterModel, SIGNAL(layoutChanged()),
- this, SLOT(slotModelChanged()));
- connect(filterModel, SIGNAL(modelReset()),
- this, SLOT(slotModelChanged()));
- connect(filterModel, SIGNAL(rowsInserted(QModelIndex, int, int)),
- this, SLOT(slotModelChanged()));
- connect(filterModel, SIGNAL(rowsRemoved(QModelIndex, int, int)),
- this, SLOT(slotModelChanged()));
+ BT_CONNECT(m_menu, SIGNAL(triggered(CSwordModuleInfo *)),
+ this, SIGNAL(triggered(CSwordModuleInfo *)));
+ BT_CONNECT(filterModel, SIGNAL(layoutChanged()),
+ this, SLOT(slotModelChanged()));
+ BT_CONNECT(filterModel, SIGNAL(modelReset()),
+ this, SLOT(slotModelChanged()));
+ BT_CONNECT(filterModel, SIGNAL(rowsInserted(QModelIndex, int, int)),
+ this, SLOT(slotModelChanged()));
+ BT_CONNECT(filterModel, SIGNAL(rowsRemoved(QModelIndex, int, int)),
+ this, SLOT(slotModelChanged()));
}
BtOpenWorkAction::~BtOpenWorkAction() {
diff --git a/src/frontend/btopenworkaction.h b/src/frontend/btopenworkaction.h
index 1ca8379..0e6b38a 100644
--- a/src/frontend/btopenworkaction.h
+++ b/src/frontend/btopenworkaction.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -28,7 +28,7 @@ class BtOpenWorkActionMenu: public BtMenuView {
Q_OBJECT
public:
BtOpenWorkActionMenu(const QString &groupingConfigKey,
- QWidget *parent = 0);
+ QWidget *parent = nullptr);
void setSourceModel(QAbstractItemModel *model);
inline QAbstractItemModel *sourceModel() const { return m_treeModel->sourceModel(); }
@@ -41,8 +41,7 @@ class BtOpenWorkActionMenu: public BtMenuView {
private:
void retranslateUi();
- /* Reimplemented from BtMenuView. */
- virtual void postBuildMenu();
+ void postBuildMenu() override;
private slots:
void slotIndexTriggered(const QModelIndex &index);
@@ -62,7 +61,7 @@ class BtOpenWorkAction: public QAction {
Q_OBJECT
public:
explicit BtOpenWorkAction(const QString &groupingConfigKey,
- QObject *parent = 0);
+ QObject *parent = nullptr);
~BtOpenWorkAction();
signals:
diff --git a/src/frontend/btprinter.cpp b/src/frontend/btprinter.cpp
new file mode 100644
index 0000000..ae718e6
--- /dev/null
+++ b/src/frontend/btprinter.cpp
@@ -0,0 +1,116 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btprinter.h"
+#include "bibletime.h"
+#include <QPrintDialog>
+#include <QPrinter>
+#include <QTextEdit>
+#include "../util/btassert.h"
+#include "backend/config/btconfig.h"
+#include "backend/keys/cswordversekey.h"
+#include "backend/managers/cdisplaytemplatemgr.h"
+
+
+namespace {
+
+inline FilterOptions mangleFilterOptions(FilterOptions fo) {
+ fo.footnotes = false;
+ fo.scriptureReferences = false;
+ fo.strongNumbers = false;
+ fo.morphTags = false;
+ fo.headings = false;
+ return fo;
+}
+
+} // anonymous namespace
+
+BtPrinter::BtPrinter(DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions,
+ QObject * const parent)
+ : QObject{parent}
+ , CDisplayRendering{displayOptions, mangleFilterOptions(filterOptions)}
+{}
+
+void BtPrinter::printKeyTree(KeyTree const & tree) {
+ QTextEdit htmlPage;
+ htmlPage.setHtml(renderKeyTree(tree));
+
+ QPrinter printer;
+ QPrintDialog printDialog(&printer);
+ if (printDialog.exec() == QDialog::Accepted)
+ htmlPage.print(&printer);
+}
+
+QString BtPrinter::entryLink(KeyTreeItem const & item,
+ CSwordModuleInfo const * module)
+{
+ BT_ASSERT(module);
+ if (module->type() != CSwordModuleInfo::Bible)
+ return item.key();
+
+ CSwordVerseKey vk(module);
+ vk.setKey(item.key());
+ switch (item.settings().keyRenderingFace) {
+ case KeyTreeItem::Settings::CompleteShort:
+ return QString::fromUtf8(vk.getShortText());
+
+ case KeyTreeItem::Settings::CompleteLong:
+ return vk.key();
+
+ case KeyTreeItem::Settings::NoKey:
+ return QString::null;
+
+ case KeyTreeItem::Settings::SimpleKey: // fall through:
+ default:
+ return QString::number(vk.getVerse());
+ }
+}
+
+QString BtPrinter::renderEntry(KeyTreeItem const & i, CSwordKey * key) {
+ Q_UNUSED(key);
+ BT_ASSERT(dynamic_cast<BtPrinter::KeyTreeItem const *>(&i));
+ BtPrinter::KeyTreeItem const * const printItem =
+ static_cast<BtPrinter::KeyTreeItem const *>(&i);
+
+ if (printItem->hasAlternativeContent()) {
+ QString ret =
+ QString::fromLatin1("<div class=\"entry\"><div class=\""
+ "rangeheading\">%1</div>").arg(
+ printItem->getAlternativeContent());
+ if (!i.childList()->isEmpty())
+ Q_FOREACH (const KeyTreeItem * const c, *i.childList())
+ ret.append(CDisplayRendering::renderEntry(*c));
+ ret.append("</div>");
+ return ret;
+ }
+ return CDisplayRendering::renderEntry(i);
+}
+
+QString BtPrinter::finishText(QString const & text, KeyTree const & tree) {
+ BtConstModuleList const modules = collectModules(tree);
+ BT_ASSERT(!modules.empty());
+
+ CLanguageMgr::Language const * const lang = modules.first()->language();
+ BT_ASSERT(lang);
+
+ CDisplayTemplateMgr::Settings settings;
+ //settings.modules = modules;
+ settings.pageCSS_ID = "printer";
+ if (modules.count() == 1 && lang->isValid())
+ settings.langAbbrev = lang->abbrev();
+
+ if (modules.count() == 1)
+ settings.textDirection = modules.first()->textDirection();
+
+ return CDisplayTemplateMgr::instance()->fillTemplate(
+ CDisplayTemplateMgr::activeTemplateName(),
+ text,
+ settings);
+}
diff --git a/src/frontend/btprinter.h b/src/frontend/btprinter.h
new file mode 100644
index 0000000..8307881
--- /dev/null
+++ b/src/frontend/btprinter.h
@@ -0,0 +1,45 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTPRINTER_H
+#define BTPRINTER_H
+
+#include <QObject>
+#include "backend/rendering/cdisplayrendering.h"
+
+#include "backend/managers/cswordbackend.h"
+
+
+/** \brief Manages the print item queue and printing. */
+class BtPrinter final: public QObject, public Rendering::CDisplayRendering {
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ BtPrinter(DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions,
+ QObject * const parent = nullptr);
+
+ void printKeyTree(KeyTree const &);
+
+private: /* Methods: */
+
+ QString entryLink(KeyTreeItem const & item,
+ CSwordModuleInfo const * module) override;
+
+ QString renderEntry(KeyTreeItem const & item,
+ CSwordKey * const key = nullptr) override;
+ QString finishText(QString const & text, KeyTree const & tree) override;
+
+};
+
+#endif /* BTPRINTER_H */
diff --git a/src/frontend/btwebenginepage.cpp b/src/frontend/btwebenginepage.cpp
new file mode 100644
index 0000000..e2fd666
--- /dev/null
+++ b/src/frontend/btwebenginepage.cpp
@@ -0,0 +1,95 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+// This class encapsulates most differences between QWebPage and QWebEnginePage
+// Javascript issues are handled in BtHtmlReadDisplay
+
+#include "btwebenginepage.h"
+#include "btwebengineview.h"
+
+#include "frontend/display/bthtmljsobject.h"
+#include "util/directory.h"
+
+#include <QDebug>
+#include <QPainter>
+#include <QPrinter>
+#ifdef USEWEBENGINE
+#include <QWebChannel>
+#else
+#include <QWebPage>
+#endif
+
+#ifdef USEWEBENGINE
+
+BtWebEnginePage::BtWebEnginePage(QObject *parent)
+ :QWebEnginePage(parent),
+ m_webChannel(new QWebChannel(this)) {
+
+ setWebChannel(m_webChannel);
+}
+
+bool BtWebEnginePage::acceptNavigationRequest(
+ const QUrl& url, NavigationType /*type*/, bool /*isMainFrame*/) {
+ emit linkClicked(url);
+ return false;
+}
+
+void BtWebEnginePage::addJavaScriptObject(const QString &name, QObject *object) {
+ object->setObjectName(name);
+ m_webChannel->registerObject(name, object);
+}
+
+void BtWebEnginePage::selectAll() {
+ triggerAction(QWebEnginePage::SelectAll);
+}
+
+void BtWebEnginePage::print(QPrinter *printer) {
+ QPainter painter;
+ painter.begin(printer);
+ BtWebEngineView *btWebEngineView = btView();
+ btWebEngineView->render(&painter);
+ painter.end();
+}
+
+void BtWebEnginePage::javaScriptConsoleMessage(
+ JavaScriptConsoleMessageLevel /*level*/,
+ const QString & message, int /*lineNumber*/,
+ const QString & /*sourceID*/) {
+ qWarning() << "javascript console :" << message;
+}
+
+#else
+
+BtWebEnginePage::BtWebEnginePage(QObject *parent)
+ :QWebPage(parent) {
+ settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
+}
+
+void BtWebEnginePage::addJavaScriptObject(const QString &name, QObject *object) {
+ object->setObjectName(name);
+ mainFrame()->addToJavaScriptWindowObject(object->objectName(), object);
+}
+
+void BtWebEnginePage::selectAll() {
+ triggerAction(QWebPage::SelectAll);
+}
+
+void BtWebEnginePage::print(QPrinter *printer) {
+ mainFrame()->print(printer);
+}
+
+void BtWebEnginePage::setHtml(const QString& text) {
+ // TODO - test
+}
+
+#endif
+
+BtWebEngineView * BtWebEnginePage::btView() const {
+ return qobject_cast<BtWebEngineView*>(view());
+}
diff --git a/src/frontend/btwebenginepage.h b/src/frontend/btwebenginepage.h
new file mode 100644
index 0000000..ad2a9f8
--- /dev/null
+++ b/src/frontend/btwebenginepage.h
@@ -0,0 +1,69 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTWEBENGINEPAGE_H
+#define BTWEBENGINEPAGE_H
+
+#ifdef USEWEBENGINE
+#include <QWebEnginePage>
+#else
+#include <QWebPage>
+#include <QWebFrame>
+#endif
+#include <QUrl>
+#include <QObject>
+
+class QPrinter;
+class QWidget;
+class QWebChannel;
+class BtWebEngineView;
+
+
+#ifdef USEWEBENGINE
+class BtWebEnginePage : public QWebEnginePage {
+#else
+class BtWebEnginePage : public QWebPage {
+#endif
+
+ Q_OBJECT
+
+public:
+ BtWebEnginePage(QObject *parent = 0);
+
+ void addJavaScriptObject(const QString &name, QObject *object);
+ BtWebEngineView * btView() const;
+ void print(QPrinter* printer);
+ void selectAll();
+
+#ifdef USEWEBENGINE
+signals:
+ void linkClicked(const QUrl& url);
+
+protected:
+ virtual bool acceptNavigationRequest(
+ const QUrl& url, NavigationType type, bool isMainFrame);
+
+ void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level,
+ const QString & message, int lineNumber,
+ const QString & sourceID);
+
+private:
+
+ QWebChannel *m_webChannel;
+
+#else
+
+ void setHtml(const QString& text);
+
+#endif
+};
+
+#endif
diff --git a/src/frontend/btwebengineview.cpp b/src/frontend/btwebengineview.cpp
new file mode 100644
index 0000000..57d0f8f
--- /dev/null
+++ b/src/frontend/btwebengineview.cpp
@@ -0,0 +1,62 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btwebengineview.h"
+#include "btwebenginepage.h"
+
+// This class encapsulates differences between QWebView and QWebEngineView
+
+#ifdef USEWEBENGINE
+BtWebEngineView::BtWebEngineView(QWidget *parent)
+ : QWebEngineView(parent) {
+}
+#else
+BtWebEngineView::BtWebEngineView(QWidget *parent)
+ : QWebView(parent) {
+}
+#endif
+
+BtWebEnginePage * BtWebEngineView::btPage() const {
+ return qobject_cast<BtWebEnginePage*>(page());
+}
+
+void BtWebEngineView::findTextHighlight(const QString& text, bool caseSensitive) {
+#ifdef USEWEBENGINE
+ QWebEnginePage::FindFlags options;
+ if (caseSensitive)
+ options |= QWebEnginePage::FindCaseSensitively;
+ QWebEngineView::findText("", options); // clear old highlight
+ QWebEngineView::findText(text, options);
+#else
+ QWebPage::FindFlags options = QWebPage::HighlightAllOccurrences;
+ if (caseSensitive)
+ options |= QWebPage::FindCaseSensitively;
+ QWebView::findText("", options); // clear old highlight
+ QWebView::findText(text, options);
+
+#endif
+}
+
+void BtWebEngineView::findText(const QString& text, bool caseSensitive, bool backward) {
+#ifdef USEWEBENGINE
+ QWebEnginePage::FindFlags options;
+ if (backward)
+ options |= QWebEnginePage::FindBackward;
+ if (caseSensitive)
+ options |= QWebEnginePage::FindCaseSensitively;
+ QWebEngineView::findText(text, options);
+#else
+ QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
+ if (backward)
+ options |= QWebPage::FindBackward;
+ if (caseSensitive)
+ options |= QWebPage::FindCaseSensitively;
+ QWebView::findText(text, options);
+#endif
+}
diff --git a/src/frontend/btwebengineview.h b/src/frontend/btwebengineview.h
new file mode 100644
index 0000000..75f52b5
--- /dev/null
+++ b/src/frontend/btwebengineview.h
@@ -0,0 +1,45 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTWEBENGINEVIEW_H
+#define BTWEBENGINEVIEW_H
+
+#include "frontend/btwebenginepage.h"
+
+#ifdef USEWEBENGINE
+#include <QWebEngineView>
+#else
+#include <QWebView>
+#endif
+
+class BtWebEnginePage;
+
+#ifdef USEWEBENGINE
+class BtWebEngineView : public QWebEngineView {
+#else
+class BtWebEngineView : public QWebView {
+#endif
+
+ Q_OBJECT
+
+public:
+ BtWebEngineView(QWidget *parent = 0);
+
+ BtWebEnginePage * btPage() const;
+
+ void findTextHighlight(const QString& text, bool caseSensitive);
+ void findText(const QString& text, bool caseSensitive, bool backwards);
+};
+
+#endif
+
+
+
diff --git a/src/frontend/cdragdrop.h b/src/frontend/cdragdrop.h
index 869d2fb..296373c 100644
--- a/src/frontend/cdragdrop.h
+++ b/src/frontend/cdragdrop.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -72,7 +72,7 @@ class BTMimeData: public QMimeData {
public: /* Types: */
/** Type for bookmark item list. Usage: BTMimeData::ItemList. */
- typedef QList<BookmarkItem> ItemList;
+ using ItemList = QList<BookmarkItem>;
public: /* Methods: */
diff --git a/src/frontend/cexportmanager.cpp b/src/frontend/cexportmanager.cpp
index e7546ba..5d00ca7 100644
--- a/src/frontend/cexportmanager.cpp
+++ b/src/frontend/cexportmanager.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -23,7 +23,8 @@
#include "backend/rendering/centrydisplay.h"
#include "backend/rendering/chtmlexportrendering.h"
#include "backend/rendering/cplaintextexportrendering.h"
-#include "frontend/cprinter.h"
+#include "frontend/btprinter.h"
+#include "util/btassert.h"
#include "util/tool.h"
// Sword includes:
@@ -32,22 +33,34 @@
using namespace Rendering;
-using namespace Printing;
-CExportManager::CExportManager(const bool showProgress,
- const QString &progressLabel,
- const FilterOptions &filterOptions,
- const DisplayOptions &displayOptions)
+using KTI = CTextRendering::KeyTreeItem;
+
+
+namespace {
+
+QTextCodec * getCodec(CExportManager::Format const format) {
+ if (format == CExportManager::HTML)
+ return QTextCodec::codecForName("UTF-8");
+ return QTextCodec::codecForLocale();
+}
+
+} // anonymous namespace
+
+CExportManager::CExportManager(bool const showProgress,
+ QString const & progressLabel,
+ FilterOptions const & filterOptions,
+ DisplayOptions const & displayOptions)
{
m_filterOptions = filterOptions;
m_displayOptions = displayOptions;
if (showProgress) {
- m_progressDialog = new QProgressDialog(0, Qt::Dialog);
+ m_progressDialog = new QProgressDialog{nullptr, Qt::Dialog};
m_progressDialog->setWindowTitle("BibleTime");
m_progressDialog->setLabelText(progressLabel);
} else {
- m_progressDialog = 0;
+ m_progressDialog = nullptr;
}
}
@@ -55,396 +68,367 @@ CExportManager::~CExportManager() {
delete m_progressDialog;
}
-bool CExportManager::saveKey(CSwordKey* key, const Format format, const bool addText) {
- if (!key) {
- return false;
- }
- if (!key->module()) {
+bool CExportManager::saveKey(CSwordKey const * const key,
+ Format const format,
+ bool const addText)
+{
+ if (!key || !key->module())
return false;
- }
- const QString filename = getSaveFileName(format);
- if (filename.isEmpty()) {
+ QString const filename = getSaveFileName(format);
+ if (filename.isEmpty())
return false;
- }
-
- CTextRendering * render = newRenderer(format, addText);
QString text;
-
- QList<const CSwordModuleInfo*> modules;
- modules.append(key->module());
-
- CSwordVerseKey *vk = dynamic_cast<CSwordVerseKey*>(key);
- if (vk && vk->isBoundSet()) {
- text = render->renderKeyRange( QString::fromUtf8(vk->getLowerBound()), QString::fromUtf8(vk->getUpperBound()), modules );
- }
- else { //no range supported
- text = render->renderSingleKey(key->key(), modules);
+ {
+ BtConstModuleList modules;
+ modules.append(key->module());
+ CSwordVerseKey const * const vk =
+ dynamic_cast<CSwordVerseKey const *>(key);
+ auto const render = newRenderer(format, addText);
+ if (vk && vk->isBoundSet()) {
+ text = render->renderKeyRange(
+ QString::fromUtf8(vk->getLowerBound()),
+ QString::fromUtf8(vk->getUpperBound()),
+ modules);
+ } else { // no range supported
+ text = render->renderSingleKey(key->key(), modules);
+ }
}
- delete render;
-
- util::tool::savePlainFile(filename, text, false,
- (format == HTML)
- ? QTextCodec::codecForName("UTF-8")
- : QTextCodec::codecForLocale());
+ util::tool::savePlainFile(filename, text, false, getCodec(format));
return true;
}
-bool CExportManager::saveKeyList(const sword::ListKey & l,
- const CSwordModuleInfo *module,
- Format format,
- bool addText)
+bool CExportManager::saveKeyList(sword::ListKey const & l,
+ CSwordModuleInfo const * module,
+ Format const format,
+ bool const addText)
{
if (!l.getCount())
return false;
- const QString filename = getSaveFileName(format);
- if (filename.isEmpty()) {
+ QString const filename = getSaveFileName(format);
+ if (filename.isEmpty())
return false;
- }
CTextRendering::KeyTree tree; /// \todo Verify that items in tree are properly freed.
setProgressRange(l.getCount());
- CTextRendering::KeyTreeItem::Settings itemSettings;
+ KTI::Settings itemSettings;
itemSettings.highlight = false;
sword::ListKey list(l);
list.setPosition(sword::TOP);
- while (!list.popError() && !progressWasCancelled()) {
- tree.append( new CTextRendering::KeyTreeItem(QString::fromLocal8Bit((const char*)list) , module, itemSettings) );
+ while (!list.popError()) {
+ if (progressWasCancelled())
+ return false;
+ tree.append(new KTI(QString::fromLocal8Bit(list.getText()),
+ module,
+ itemSettings));
incProgress();
-
list.increment();
}
- CTextRendering * render = newRenderer(format, addText);
- const QString text = render->renderKeyTree(tree);
- delete render;
-
- if (!progressWasCancelled()) {
- util::tool::savePlainFile(filename, text, false, (format == HTML) ? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale() );
- closeProgressDialog();
- return true;
- }
- return false;
+ QString const text = newRenderer(format, addText)->renderKeyTree(tree);
+ util::tool::savePlainFile(filename, text, false, getCodec(format));
+ closeProgressDialog();
+ return true;
}
-bool CExportManager::saveKeyList(const QList<CSwordKey*> &list,
- Format format,
- bool addText)
+bool CExportManager::saveKeyList(QList<CSwordKey *> const & list,
+ Format const format,
+ bool const addText)
{
- if (!list.count())
+ if (list.empty())
return false;
const QString filename = getSaveFileName(format);
- if (filename.isEmpty()) {
+ if (filename.isEmpty())
return false;
- }
CTextRendering::KeyTree tree; /// \todo Verify that items in tree are properly freed.
- setProgressRange(list.count());
- CTextRendering::KeyTreeItem::Settings itemSettings;
+ KTI::Settings itemSettings;
itemSettings.highlight = false;
- QListIterator<CSwordKey*> it(list);
- while (it.hasNext() && !progressWasCancelled()) {
- CSwordKey* k = it.next();
- tree.append( new CTextRendering::KeyTreeItem(k->key(), k->module(), itemSettings) );
+ setProgressRange(list.count());
+ for (CSwordKey const * const k : list) {
+ if (progressWasCancelled())
+ return false;
+ tree.append(new KTI(k->key(), k->module(), itemSettings));
incProgress();
};
- CTextRendering * render = newRenderer(format, addText);
- const QString text = render->renderKeyTree(tree);
- delete render;
-
- if (!progressWasCancelled()) {
- util::tool::savePlainFile(filename, text, false, (format == HTML) ? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale() );
- closeProgressDialog();
- return true;
- }
- return false;
+ QString const text = newRenderer(format, addText)->renderKeyTree(tree);
+ util::tool::savePlainFile(filename, text, false, getCodec(format));
+ closeProgressDialog();
+ return true;
}
-bool CExportManager::copyKey(CSwordKey* key, const Format format, const bool addText) {
+namespace {
+
+template <typename Arg> inline void copyToClipboard(Arg && arg)
+{ QApplication::clipboard()->setText(std::forward<Arg>(arg)); }
+
+} // anonymous namespace
+
+bool CExportManager::copyKey(CSwordKey const * const key,
+ Format const format,
+ bool const addText)
+{
if (!key || !key->module())
return false;
QString text;
- QList<const CSwordModuleInfo*> modules;
+ BtConstModuleList modules;
modules.append(key->module());
- CTextRendering * render = newRenderer(format, addText);
- CSwordVerseKey * vk = dynamic_cast<CSwordVerseKey*>(key);
- if (vk && vk->isBoundSet()) {
- text = render->renderKeyRange(
- QString::fromUtf8(vk->getLowerBound()),
- QString::fromUtf8(vk->getUpperBound()),
- modules
- );
- }
- else { //no range supported
- text = render->renderSingleKey(key->key(), modules);
+ {
+ auto const render = newRenderer(format, addText);
+ CSwordVerseKey const * const vk =
+ dynamic_cast<CSwordVerseKey const *>(key);
+ if (vk && vk->isBoundSet()) {
+ text = render->renderKeyRange(
+ QString::fromUtf8(vk->getLowerBound()),
+ QString::fromUtf8(vk->getUpperBound()),
+ modules
+ );
+ } else { // no range supported
+ text = render->renderSingleKey(key->key(), modules);
+ }
}
- delete render;
-
- QApplication::clipboard()->setText(text);
+ copyToClipboard(text);
return true;
}
-bool CExportManager::copyKeyList(const sword::ListKey &l,
- const CSwordModuleInfo *module,
- Format format,
- bool addText)
+bool CExportManager::copyKeyList(sword::ListKey const & l,
+ CSwordModuleInfo const * const module,
+ Format const format,
+ bool const addText)
{
sword::ListKey list = l;
if (!list.getCount())
return false;
CTextRendering::KeyTree tree; /// \todo Verify that items in tree are properly freed.
- CTextRendering::KeyTreeItem::Settings itemSettings;
+ KTI::Settings itemSettings;
itemSettings.highlight = false;
list.setPosition(sword::TOP);
- while (!list.popError() && !progressWasCancelled()) {
- tree.append( new CTextRendering::KeyTreeItem(QString::fromLocal8Bit((const char*)list) , module, itemSettings) );
-
+ while (!list.popError()) {
+ if (progressWasCancelled())
+ return false;
+ tree.append(new KTI(QString::fromLocal8Bit(list.getText()),
+ module,
+ itemSettings));
list.increment();
}
- CTextRendering * render = newRenderer(format, addText);
- const QString text = render->renderKeyTree(tree);
- delete render;
- QApplication::clipboard()->setText(text);
+ copyToClipboard(newRenderer(format, addText)->renderKeyTree(tree));
+ closeProgressDialog();
return true;
}
-bool CExportManager::copyKeyList(const QList<CSwordKey*> &list,
- Format format,
- bool addText)
+bool CExportManager::copyKeyList(QList<CSwordKey *> const & list,
+ Format const format,
+ bool const addText)
{
- if (!list.count())
+ if (list.empty())
return false;
-
CTextRendering::KeyTree tree; /// \todo Verify that items in tree are properly freed.
-
- CTextRendering::KeyTreeItem::Settings itemSettings;
+ KTI::Settings itemSettings;
itemSettings.highlight = false;
- QListIterator<CSwordKey*> it(list);
- while (it.hasNext() && !progressWasCancelled()) {
- CSwordKey* k = it.next();
- tree.append( new CTextRendering::KeyTreeItem(k->key(), k->module(), itemSettings) );
+ setProgressRange(list.count());
+ for (CSwordKey const * const k : list) {
+ if (progressWasCancelled())
+ return false;
+ tree.append(new KTI(k->key(), k->module(), itemSettings));
incProgress();
};
- CTextRendering * render = newRenderer(format, addText);
- const QString text = render->renderKeyTree(tree);
- delete render;
-
- QApplication::clipboard()->setText(text);
- if (!progressWasCancelled()) {
- closeProgressDialog();
- }
+ copyToClipboard(newRenderer(format, addText)->renderKeyTree(tree));
+ closeProgressDialog();
return true;
}
-bool CExportManager::printKeyList(const sword::ListKey & list,
- const CSwordModuleInfo *module,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions)
-{
- CPrinter::KeyTreeItem::Settings settings;
- CPrinter::KeyTree tree; /// \todo Verify that items in tree are properly freed.
+namespace {
- setProgressRange(list.getCount());
- for (int i=0; i< list.getCount(); i++) {
- const sword::SWKey* swKey = list.getElement(i);
- const sword::VerseKey* vKey = dynamic_cast<const sword::VerseKey*>(swKey);
- if (vKey != 0) {
- QString startKey = vKey->getText();
- tree.append(new CTextRendering::KeyTreeItem(startKey,
- startKey,
- module,
- settings));
- }
- else {
- QString key = swKey->getText();
- tree.append(new CTextRendering::KeyTreeItem(key,
- key,
- module,
- settings));
- }
- incProgress();
- if (progressWasCancelled())
- break;
- }
+struct PrintSettings: BtPrinter::KeyTreeItem::Settings {
+ PrintSettings(DisplayOptions const & displayOptions)
+ : BtPrinter::KeyTreeItem::Settings{
+ false,
+ displayOptions.verseNumbers ? Settings::SimpleKey : Settings::NoKey}
+ {}
- if (!progressWasCancelled()) {
- CPrinter * printer = new CPrinter(0, displayOptions, filterOptions);
- printer->printKeyTree(tree);
- delete printer;
- closeProgressDialog();
- return true;
- }
+};
- return false;
-}
+} // anonymous namespace
-bool CExportManager::printKey(const CSwordModuleInfo *module,
- const QString &startKey,
- const QString &stopKey,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions)
+bool CExportManager::printKey(CSwordKey const * const key,
+ DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions)
{
- CPrinter::KeyTreeItem::Settings settings;
- settings.keyRenderingFace =
- displayOptions.verseNumbers
- ? CPrinter::KeyTreeItem::Settings::SimpleKey
- : CPrinter::KeyTreeItem::Settings::NoKey;
-
- CPrinter::KeyTree tree; /// \todo Verify that items in tree are properly freed.
- if (startKey != stopKey) {
- tree.append( new CPrinter::KeyTreeItem(startKey, stopKey, module, settings) );
- }
- else {
- tree.append( new CPrinter::KeyTreeItem(startKey, module, settings) );
- }
-
- CPrinter * printer = new CPrinter(0, displayOptions, filterOptions);
- printer->printKeyTree(tree);
- delete printer;
+ PrintSettings settings{displayOptions};
+ BtPrinter::KeyTree tree; /// \todo Verify that items in tree are properly freed.
+ tree.append(new BtPrinter::KeyTreeItem(key->key(), key->module(), settings));
+ BtPrinter{displayOptions, filterOptions}.printKeyTree(tree);
return true;
}
-bool CExportManager::printKey(const CSwordKey *key,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions)
+bool CExportManager::printKey(CSwordModuleInfo const * const module,
+ QString const & startKey,
+ QString const & stopKey,
+ DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions)
{
- CPrinter::KeyTreeItem::Settings settings;
- settings.keyRenderingFace =
- displayOptions.verseNumbers
- ? CPrinter::KeyTreeItem::Settings::SimpleKey
- : CPrinter::KeyTreeItem::Settings::NoKey;
-
- CPrinter::KeyTree tree; /// \todo Verify that items in tree are properly freed.
- tree.append( new CPrinter::KeyTreeItem(key->key(), key->module(), settings) );
-
- CPrinter * printer = new CPrinter(0, displayOptions, filterOptions);
- printer->printKeyTree(tree);
- delete printer;
+ PrintSettings settings{displayOptions};
+ BtPrinter::KeyTree tree; /// \todo Verify that items in tree are properly freed.
+ if (startKey != stopKey) {
+ tree.append(new BtPrinter::KeyTreeItem(startKey, stopKey, module, settings));
+ } else {
+ tree.append(new BtPrinter::KeyTreeItem(startKey, module, settings));
+ }
+ BtPrinter{displayOptions, filterOptions}.printKeyTree(tree);
return true;
}
-bool CExportManager::printByHyperlink(const QString &hyperlink,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions)
+bool CExportManager::printByHyperlink(QString const & hyperlink,
+ DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions)
{
QString moduleName;
QString keyName;
ReferenceManager::Type type;
-
ReferenceManager::decodeHyperlink(hyperlink, moduleName, keyName, type);
- if (moduleName.isEmpty()) {
+ if (moduleName.isEmpty())
moduleName = ReferenceManager::preferredModule(type);
- }
- CPrinter::KeyTree tree; /// \todo Verify that items in tree are properly freed.
- CPrinter::KeyTreeItem::Settings settings;
- settings.keyRenderingFace =
- displayOptions.verseNumbers
- ? CPrinter::KeyTreeItem::Settings::SimpleKey
- : CPrinter::KeyTreeItem::Settings::NoKey;
-
- CSwordModuleInfo* module = CSwordBackend::instance()->findModuleByName(moduleName);
- Q_ASSERT(module);
-
- if (module) {
- //check if we have a range of entries or a single one
- if ((module->type() == CSwordModuleInfo::Bible) || (module->type() == CSwordModuleInfo::Commentary)) {
- sword::ListKey verses = sword::VerseKey().parseVerseList((const char*)keyName.toUtf8(), "Genesis 1:1", true);
-
- for (int i = 0; i < verses.getCount(); i++) {
- sword::VerseKey* element = dynamic_cast<sword::VerseKey*>(verses.getElement(i));
- if (element) {
- const QString startKey = QString::fromUtf8(element->getLowerBound().getText());
- const QString stopKey = QString::fromUtf8(element->getUpperBound().getText());
-
- tree.append( new CPrinter::KeyTreeItem(startKey, stopKey, module, settings) );
- }
- else if (verses.getElement(i)) {
- const QString key = QString::fromUtf8(verses.getElement(i)->getText());
-
- tree.append( new CPrinter::KeyTreeItem(key, module, settings) );
- }
+ BtPrinter::KeyTree tree; /// \todo Verify that items in tree are properly freed.
+ PrintSettings settings{displayOptions};
+ CSwordModuleInfo const * module =
+ CSwordBackend::instance()->findModuleByName(moduleName);
+ BT_ASSERT(module);
+ //check if we have a range of entries or a single one
+ if ((module->type() == CSwordModuleInfo::Bible)
+ || (module->type() == CSwordModuleInfo::Commentary))
+ {
+ sword::ListKey const verses =
+ sword::VerseKey().parseVerseList(
+ keyName.toUtf8().constData(),
+ "Genesis 1:1",
+ true);
+
+ for (int i = 0; i < verses.getCount(); i++) {
+ if (sword::VerseKey const * const element =
+ dynamic_cast<sword::VerseKey const *>(verses.getElement(i)))
+ {
+ tree.append(
+ new BtPrinter::KeyTreeItem(
+ QString::fromUtf8(
+ element->getLowerBound().getText()),
+ QString::fromUtf8(
+ element->getUpperBound().getText()),
+ module,
+ settings) );
+ } else if (verses.getElement(i)) {
+ tree.append(
+ new BtPrinter::KeyTreeItem(
+ QString::fromUtf8(verses.getElement(i)->getText()),
+ module,
+ settings) );
}
}
- else {
- tree.append( new CPrinter::KeyTreeItem(keyName, module, settings) );
- }
+ } else {
+ tree.append(new BtPrinter::KeyTreeItem(keyName, module, settings));
}
-
- CPrinter * printer = new CPrinter(0, displayOptions, filterOptions);
- printer->printKeyTree(tree);
- delete printer;
+ BtPrinter{displayOptions, filterOptions}.printKeyTree(tree);
return true;
}
-bool CExportManager::printKeyList(const QStringList &list,
- const CSwordModuleInfo *module,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions)
+bool CExportManager::printKeyList(sword::ListKey const & list,
+ CSwordModuleInfo const * const module,
+ DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions)
{
- CPrinter::KeyTreeItem::Settings settings;
- settings.keyRenderingFace =
- displayOptions.verseNumbers
- ? CPrinter::KeyTreeItem::Settings::SimpleKey
- : CPrinter::KeyTreeItem::Settings::NoKey;
-
- CPrinter::KeyTree tree; /// \todo Verify that items in tree are properly freed.
- setProgressRange(list.count());
+ if (!list.getCount())
+ return false;
+ PrintSettings settings{displayOptions};
+ BtPrinter::KeyTree tree; /// \todo Verify that items in tree are properly freed.
- const QStringList::const_iterator end = list.constEnd();
- for (QStringList::const_iterator it = list.constBegin(); (it != end) && !progressWasCancelled(); ++it) {
- tree.append( new CPrinter::KeyTreeItem(*it, module, settings) );
+ setProgressRange(list.getCount());
+ for (int i = 0; i < list.getCount(); i++) {
+ if (progressWasCancelled())
+ return false;
+ sword::SWKey const * const swKey = list.getElement(i);
+ if (sword::VerseKey const * const vKey =
+ dynamic_cast<const sword::VerseKey*>(swKey))
+ {
+ QString const startKey = vKey->getText();
+ tree.append(new KTI(startKey, startKey, module, settings));
+ } else {
+ QString const key = swKey->getText();
+ tree.append(new KTI(key, key, module, settings));
+ }
incProgress();
}
+ BtPrinter{displayOptions, filterOptions}.printKeyTree(tree);
+ closeProgressDialog();
+ return true;
+}
+bool CExportManager::printKeyList(QStringList const & list,
+ CSwordModuleInfo const * const module,
+ DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions)
+{
+ if (list.empty())
+ return false;
- if (!progressWasCancelled()) {
- CPrinter * printer = new CPrinter(0, displayOptions, filterOptions);
- printer->printKeyTree(tree);
- delete printer;
- closeProgressDialog();
- return true;
- }
+ PrintSettings settings{displayOptions};
+ BtPrinter::KeyTree tree; /// \todo Verify that items in tree are properly freed.
- return false;
+ setProgressRange(list.count());
+ for (QString const & key: list) {
+ if (progressWasCancelled())
+ return false;
+ tree.append(new BtPrinter::KeyTreeItem(key, module, settings));
+ incProgress();
+ }
+ BtPrinter{displayOptions, filterOptions}.printKeyTree(tree);
+ closeProgressDialog();
+ return true;
}
/** Returns the string for the filedialogs to show the correct files. */
const QString CExportManager::filterString( const Format format ) {
+ QString const allFiles = QObject::tr("All files") + QString(" (*.*)");
switch (format) {
case HTML:
- return QObject::tr("HTML files") + QString(" (*.html *.htm);;") + QObject::tr("All files") + QString(" (*.*)");
+ return allFiles + QObject::tr("HTML files")
+ + QString(" (*.html *.htm);;");
case Text:
- return QObject::tr("Text files") + QString(" (*.txt);;") + QObject::tr("All files") + QString(" (*.*)");
+ return allFiles + QObject::tr("Text files") + QString(" (*.txt);;");
default:
- return QObject::tr("All files") + QString(" (*.*)");
+ return allFiles;
}
}
/** Returns a filename to save a file. */
const QString CExportManager::getSaveFileName(const Format format) {
- return QFileDialog::getSaveFileName(0, QObject::tr("Save file"), "", filterString(format), 0);
+ return QFileDialog::getSaveFileName(nullptr,
+ QObject::tr("Save file"),
+ "",
+ filterString(format),
+ nullptr);
}
-CTextRendering * CExportManager::newRenderer(const Format format, bool addText) {
+std::unique_ptr<CTextRendering> CExportManager::newRenderer(Format const format,
+ bool const addText)
+{
FilterOptions filterOptions = m_filterOptions;
filterOptions.footnotes = false;
filterOptions.strongNumbers = false;
@@ -453,15 +437,18 @@ CTextRendering * CExportManager::newRenderer(const Format format, bool addText)
filterOptions.scriptureReferences = false;
filterOptions.textualVariants = false;
- if (format == HTML) {
- return new CHTMLExportRendering(addText, m_displayOptions, filterOptions);
- } else {
- Q_ASSERT(format == Text);
- return new CPlainTextExportRendering(addText, m_displayOptions, filterOptions);
- }
+ using R = std::unique_ptr<CTextRendering>;
+ BT_ASSERT((format == Text) || (format == HTML));
+ if (format == HTML)
+ return R{new CHTMLExportRendering(addText,
+ m_displayOptions,
+ filterOptions)};
+ return R{new CPlainTextExportRendering(addText,
+ m_displayOptions,
+ filterOptions)};
}
-void CExportManager::setProgressRange( const int items ) {
+void CExportManager::setProgressRange(int const items) {
if (!m_progressDialog)
return;
@@ -480,10 +467,7 @@ void CExportManager::incProgress() {
}
bool CExportManager::progressWasCancelled() {
- if (m_progressDialog)
- return m_progressDialog->wasCanceled();
-
- return false;
+ return m_progressDialog ? m_progressDialog->wasCanceled() : false;
}
/** Closes the progress dialog immediatly. */
@@ -492,6 +476,5 @@ void CExportManager::closeProgressDialog() {
m_progressDialog->close();
m_progressDialog->reset();
}
-
qApp->processEvents(); //do not lock the GUI!
}
diff --git a/src/frontend/cexportmanager.h b/src/frontend/cexportmanager.h
index a222ac8..5286477 100644
--- a/src/frontend/cexportmanager.h
+++ b/src/frontend/cexportmanager.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,10 +12,12 @@
#ifndef CEXPORTMANAGER_H
#define CEXPORTMANAGER_H
+#include <memory>
#include <QList>
#include <QString>
+#include "backend/btglobal.h"
#include "backend/config/btconfig.h"
-#include "btglobal.h"
+
class CSwordKey;
class CSwordModuleInfo;
@@ -25,111 +27,108 @@ namespace Rendering {
class CTextRendering;
}
-/** Contains the functions to export text to disk, clipboard or printer.
- * @author The BibleTime team
- */
class CExportManager {
- public:
- /** The format the export actions should have
- */
- enum Format {
- HTML,
- Text
- };
-
- CExportManager(const bool showProgress = true,
- const QString &progressLabel = QString::null,
- const FilterOptions &filterOptions = btConfig().getFilterOptions(),
- const DisplayOptions &displayOptions = btConfig().getDisplayOptions());
- ~CExportManager();
-
- bool saveKey(CSwordKey* key, const Format format, const bool addText);
-
- bool saveKeyList(const sword::ListKey &list,
- const CSwordModuleInfo *module,
- Format format,
- bool addText);
-
- bool saveKeyList(const QList<CSwordKey*> &list,
- Format format,
- const bool addText );
-
- bool copyKey(CSwordKey* key, const Format format, const bool addText);
-
- bool copyKeyList(const sword::ListKey &list,
- const CSwordModuleInfo *module,
- Format format,
- bool addText);
-
- bool copyKeyList(const QList<CSwordKey*> &list,
- Format format,
- bool addText);
-
- bool printKey(const CSwordKey *key,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions);
-
- bool printKey(const CSwordModuleInfo *module,
- const QString &startKey,
- const QString &stopKey,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions);
-
- /**
- Prints a key using the hyperlink created by CReferenceManager.
- */
- bool printByHyperlink(const QString &hyperlink,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions);
-
- bool printKeyList(const sword::ListKey &list,
- const CSwordModuleInfo *module,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions);
-
- bool printKeyList(const QStringList &list,
- const CSwordModuleInfo *module,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions);
-
- protected: // Protected methods
- /**
- * Returns the string for the filedialogs to show the correct files.
- */
- const QString filterString( const Format format );
- /**
- * Returns a filename to save a file.
- */
- const QString getSaveFileName(const Format format);
-
- private: /* Methods: */
-
- Rendering::CTextRendering * newRenderer(const Format format,
- bool addText);
-
- /**
- * Returns the CSS string used in HTML pages.
- */
- void setProgressRange( const int item );
-
- /**
- * Increments the progress by one item.
- */
- inline void incProgress();
-
- bool progressWasCancelled();
-
- /**
- * Closes the progress dialog immediately.
- */
- void closeProgressDialog();
-
- private:
-
- FilterOptions m_filterOptions;
- DisplayOptions m_displayOptions;
-
- QProgressDialog* m_progressDialog;
+
+public: /* Types: */
+
+ /** The format the export actions should have. */
+ enum Format {
+ HTML,
+ Text
+ };
+
+public: /* Methods: */
+
+ CExportManager(const bool showProgress = true,
+ const QString &progressLabel = QString::null,
+ const FilterOptions &filterOptions = btConfig().getFilterOptions(),
+ const DisplayOptions &displayOptions = btConfig().getDisplayOptions());
+ ~CExportManager();
+
+ bool saveKey(CSwordKey const * const key,
+ Format const format,
+ bool const addText);
+
+ bool saveKeyList(sword::ListKey const & list,
+ CSwordModuleInfo const * const module,
+ Format const format,
+ bool const addText);
+
+ bool saveKeyList(QList<CSwordKey *> const & list,
+ Format const format,
+ bool const addText);
+
+ bool copyKey(CSwordKey const * const key,
+ Format const format,
+ bool const addText);
+
+ bool copyKeyList(sword::ListKey const & list,
+ CSwordModuleInfo const * const module,
+ Format const format,
+ bool const addText);
+
+ bool copyKeyList(QList<CSwordKey *> const & list,
+ Format const format,
+ bool const addText);
+
+ bool printKey(CSwordKey const * const key,
+ DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions);
+
+ bool printKey(CSwordModuleInfo const * const module,
+ QString const & startKey,
+ QString const & stopKey,
+ DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions);
+
+ /**
+ \brief Prints a key using the hyperlink created by CReferenceManager.
+ */
+ bool printByHyperlink(QString const & hyperlink,
+ DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions);
+
+ bool printKeyList(sword::ListKey const & list,
+ CSwordModuleInfo const * const module,
+ DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions);
+
+ bool printKeyList(QStringList const & list,
+ CSwordModuleInfo const * const module,
+ DisplayOptions const & displayOptions,
+ FilterOptions const & filterOptions);
+
+protected: /* Methods: */
+
+ /** \returns the string for the filedialogs to show the correct files.*/
+ const QString filterString(Format const format);
+
+ /** \returns a filename to save a file. */
+ const QString getSaveFileName(Format const format);
+
+private: /* Methods: */
+
+ std::unique_ptr<Rendering::CTextRendering> newRenderer(Format const format,
+ bool const addText);
+
+ /** \returns the CSS string used in HTML pages. */
+ void setProgressRange(int const items);
+
+ /** \brief Increments the progress by one item. */
+ void incProgress();
+
+ bool progressWasCancelled();
+
+ /** \brief Closes the progress dialog immediately. */
+ void closeProgressDialog();
+
+private: /* Fields: */
+
+ FilterOptions m_filterOptions;
+ DisplayOptions m_displayOptions;
+
+ QProgressDialog * m_progressDialog;
+
};
#endif
diff --git a/src/frontend/cinfodisplay.cpp b/src/frontend/cinfodisplay.cpp
index 202eb48..a9e6227 100644
--- a/src/frontend/cinfodisplay.cpp
+++ b/src/frontend/cinfodisplay.cpp
@@ -2,14 +2,14 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "frontend/cinfodisplay.h"
-#include <QSharedPointer>
+#include <memory>
#include <QAction>
#include <QDebug>
#include <QLabel>
@@ -19,7 +19,6 @@
#include <QVBoxLayout>
#include <QtAlgorithms>
#include <QMenu>
-
#include "backend/config/btconfig.h"
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/keys/cswordkey.h"
@@ -29,10 +28,8 @@
#include "bibletime.h"
#include "frontend/crossrefrendering.h"
#include "frontend/display/bthtmlreaddisplay.h"
-#include "util/htmlescape.h"
-
-// Sword includes:
-#include <listkey.h>
+#include "util/btassert.h"
+#include "util/btconnect.h"
using namespace Rendering;
@@ -48,28 +45,28 @@ CInfoDisplay::CInfoDisplay(BibleTime * parent)
layout->setContentsMargins(2, 2, 2, 2); // Leave small border
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
- m_htmlPart = new BtHtmlReadDisplay(0, this);
+ m_htmlPart = new BtHtmlReadDisplay(nullptr, this);
m_htmlPart->setMouseTracking(false); // We don't want strong/lemma/note mouse infos
m_htmlPart->view()->setAcceptDrops(false);
QAction * const selectAllAction = new QAction(QIcon(), tr("Select all"), this);
selectAllAction->setShortcut(QKeySequence::SelectAll);
- QObject::connect(selectAllAction, SIGNAL(triggered()),
- this, SLOT(selectAll()));
+ BT_CONNECT(selectAllAction, SIGNAL(triggered()),
+ this, SLOT(selectAll()));
QAction * const copyAction = new QAction(tr("Copy"), this);
copyAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
- QObject::connect(copyAction, SIGNAL(triggered()),
- m_htmlPart->connectionsProxy(), SLOT(copySelection()));
+ BT_CONNECT(copyAction, SIGNAL(triggered()),
+ m_htmlPart->connectionsProxy(), SLOT(copySelection()));
QMenu * const menu = new QMenu(this);
menu->addAction(selectAllAction);
menu->addAction(copyAction);
m_htmlPart->installPopup(menu);
- QObject::connect(m_htmlPart->connectionsProxy(),
- SIGNAL(referenceClicked(const QString &, const QString &)),
- SLOT(lookupInfo(const QString &, const QString &)));
+ BT_CONNECT(m_htmlPart->connectionsProxy(),
+ SIGNAL(referenceClicked(QString const &, QString const &)),
+ SLOT(lookupInfo(QString const &, QString const &)));
layout->addWidget(m_htmlPart->view());
@@ -85,22 +82,7 @@ void CInfoDisplay::unsetInfo() {
}
void CInfoDisplay::setInfo(const QString & renderedData, const QString & lang) {
- CDisplayTemplateMgr * const mgr = CDisplayTemplateMgr::instance();
- Q_ASSERT(mgr != 0);
-
- CDisplayTemplateMgr::Settings settings;
- settings.pageCSS_ID = "infodisplay";
-
- QString div = "<div class=\"infodisplay\"";
- if (!lang.isEmpty())
- div.append(" lang=\"").append(lang).append("\"");
-
- div.append(">");
-
- QString content(mgr->fillTemplate(CDisplayTemplateMgr::activeTemplateName(),
- div + renderedData + "</div>",
- settings));
- m_htmlPart->setText(content);
+ m_htmlPart->setText(Rendering::formatInfo(renderedData, lang));
}
void CInfoDisplay::lookupInfo(const QString & mod_name,
@@ -109,23 +91,19 @@ void CInfoDisplay::lookupInfo(const QString & mod_name,
qDebug() << "CInfoDisplay::lookup";
qDebug() << mod_name << key_text;
CSwordModuleInfo * const m = CSwordBackend::instance()->findModuleByName(mod_name);
- Q_ASSERT(m);
- if (!m)
- return;
- QSharedPointer<CSwordKey> key(CSwordKey::createInstance(m));
+ BT_ASSERT(m);
+ std::unique_ptr<CSwordKey> key(CSwordKey::createInstance(m));
key->setKey(key_text);
setInfo(key->renderedText(), m->language()->abbrev());
}
-void CInfoDisplay::setInfo(const InfoType type, const QString & data) {
- ListInfoData list;
- list.append(qMakePair(type, data));
- setInfo(list);
+void CInfoDisplay::setInfo(const Rendering::InfoType type, const QString & data) {
+ setInfo(Rendering::ListInfoData() << qMakePair(type, data));
}
-void CInfoDisplay::setInfo(const ListInfoData & list) {
+void CInfoDisplay::setInfo(const Rendering::ListInfoData & list) {
// If the widget is hidden it would be inefficient to render and display the data
if (!isVisible())
return;
@@ -135,50 +113,19 @@ void CInfoDisplay::setInfo(const ListInfoData & list) {
return;
}
- QString renderedText;
-
- ListInfoData::const_iterator end = list.end();
- for (ListInfoData::const_iterator it = list.begin(); it != end; ++it) {
- switch ((*it).first) {
- case Lemma:
- renderedText.append(decodeStrongs((*it).second));
- continue;
- case Morph:
- renderedText.append(decodeMorph((*it).second));
- continue;
- case CrossReference:
- renderedText.append(decodeCrossReference((*it).second));
- continue;
- case Footnote:
- renderedText.append(decodeFootnote((*it).second));
- continue;
- case WordTranslation:
- renderedText.append(getWordTranslation((*it).second));
- continue;
- case WordGloss:
- //text.append(getWordTranslation((*it).second));
- continue;
- case Abbreviation:
- renderedText.append(decodeAbbreviation((*it).second));
- continue;
- case Text:
- renderedText.append((*it).second);
- continue;
- default:
- continue;
- };
- }
- setInfo(renderedText);
+ BtConstModuleList l;
+ const CSwordModuleInfo * m(m_mainWindow->getCurrentModule());
+ if(m != nullptr)
+ l.append(m);
+ setInfo(Rendering::formatInfo(list, l));
}
void CInfoDisplay::setInfo(CSwordModuleInfo * const module) {
- using util::htmlEscape;
-
if (module) {
setInfo(tr("<div class=\"moduleinfo\"><h3>%1</h3><p>%2</p><p>Version: %3</p></div>")
- .arg(htmlEscape(module->name()))
- .arg(htmlEscape(module->config(CSwordModuleInfo::Description)))
- .arg(htmlEscape(module->config(CSwordModuleInfo::ModuleVersion))));
+ .arg(module->name().toHtmlEscaped())
+ .arg(module->config(CSwordModuleInfo::Description).toHtmlEscaped())
+ .arg(module->config(CSwordModuleInfo::ModuleVersion).toHtmlEscaped()));
} else {
unsetInfo();
}
@@ -188,292 +135,6 @@ void CInfoDisplay::selectAll() {
m_htmlPart->selectAll();
}
-const QString CInfoDisplay::decodeAbbreviation(const QString & data) {
- // QStringList strongs = QStringList::split("|", data);
- return QString("<div class=\"abbreviation\"><h3>%1: %2</h3><p>%3</p></div>")
- .arg(tr("Abbreviation"))
- .arg("text")
- .arg(data);
-}
-
-const QString CInfoDisplay::decodeCrossReference(const QString & data) {
- Q_ASSERT(!data.isEmpty());
- if (data.isEmpty())
- return QString("<div class=\"crossrefinfo\"><h3>%1</h3></div>")
- .arg(tr("Cross references"));
-
- // qWarning("setting crossref %s", data.latin1());
-
- DisplayOptions dispOpts;
- dispOpts.lineBreaks = false;
- dispOpts.verseNumbers = true;
-
- FilterOptions filterOpts;
- filterOpts.headings = false;
- filterOpts.strongNumbers = false;
- filterOpts.morphTags = false;
- filterOpts.lemmas = false;
- filterOpts.footnotes = false;
- filterOpts.scriptureReferences = false;
-
- CrossRefRendering renderer(dispOpts, filterOpts);
- CTextRendering::KeyTree tree;
-
- // const bool isBible = true;
- const CSwordModuleInfo * module = btConfig().getDefaultSwordModuleByType("standardBible");
- if (!module)
- module = m_mainWindow->getCurrentModule();
-
- // a prefixed module gives the module to look into
- QRegExp re("^[^ ]+:");
- // re.setMinimal(true);
- int pos = re.indexIn(data);
- if (pos != -1)
- pos += re.matchedLength() - 1;
-
- if (pos > 0) {
- const QString moduleName = data.left(pos);
- // qWarning("found module %s", moduleName.latin1());
- module = CSwordBackend::instance()->findModuleByName(moduleName);
- if (!module)
- module = btConfig().getDefaultSwordModuleByType("standardBible");
- // Q_ASSERT(module);
- }
-
- // Q_ASSERT(module); // why? the existense of the module is tested later
- CTextRendering::KeyTreeItem::Settings settings(
- false,
- CTextRendering::KeyTreeItem::Settings::CompleteShort
- );
-
- if (module && (module->type() == CSwordModuleInfo::Bible)) {
- VerseKey vk;
- sword::ListKey refs = vk.parseVerseList((const char*) data.mid((pos == -1) ? 0 : pos + 1).toUtf8(), "Gen 1:1", true);
-
- for (int i = 0; i < refs.getCount(); i++) {
- SWKey * const key = refs.getElement(i);
- Q_ASSERT(key);
- VerseKey * const vk = dynamic_cast<VerseKey*>(key);
-
- if (vk && vk->isBoundSet()) { // render a range of keys
- tree.append(new CTextRendering::KeyTreeItem(
- QString::fromUtf8(vk->getLowerBound().getText()),
- QString::fromUtf8(vk->getUpperBound().getText()),
- module,
- settings
- ));
- } else {
- tree.append(new CTextRendering::KeyTreeItem(
- QString::fromUtf8(key->getText()),
- QString::fromUtf8(key->getText()),
- module,
- settings
- ));
- }
- }
- } else if (module) {
- tree.append(new CTextRendering::KeyTreeItem(data.mid((pos == -1)
- ? 0
- : pos + 1),
- module,
- settings));
- }
-
- // qWarning("rendered the tree: %s", renderer.renderKeyTree(tree).latin1());
- // spanns containing rtl text need dir=rtl on their parent tag to be aligned properly
- QString lang = "en"; // default english
- if (module)
- lang = module->language()->abbrev();
-
- return QString("<div class=\"crossrefinfo\" lang=\"%1\"><h3>%2</h3><div class=\"para\" dir=\"%3\">%4</div></div>")
- .arg(lang)
- .arg(tr("Cross references"))
- .arg(module ? ((module->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl") : "")
- .arg(renderer.renderKeyTree(tree));
-}
-
-/*!
- \fn CInfoDisplay::decodeFootnote(const QString & data)
- */
-const QString CInfoDisplay::decodeFootnote(const QString & data) {
- QStringList list = data.split("/");
- Q_ASSERT(list.count() >= 3);
- if (!list.count())
- return QString::null;
-
- FilterOptions filterOpts;
- filterOpts.headings = false;
- filterOpts.strongNumbers = false;
- filterOpts.morphTags = false;
- filterOpts.lemmas = false;
- filterOpts.footnotes = true;
- // turn scripRefs off, so that they do not show up as footnotes in the OSIS filter's EntryAttributes
- filterOpts.scriptureReferences = false;
-
- CSwordBackend::instance()->setFilterOptions(filterOpts);
-
- const QString modulename = list.first();
- const QString swordFootnote = list.last();
-
- // remove the first and the last and then rejoin it to get a key
- list.pop_back();
- list.pop_front();
- const QString keyname = list.join("/");
-
- CSwordModuleInfo * const module = CSwordBackend::instance()->findModuleByName(modulename);
- if (!module)
- return QString::null;
-
- QSharedPointer<CSwordKey> key(CSwordKey::createInstance(module));
- key->setKey(keyname);
- key->renderedText(CSwordKey::ProcessEntryAttributesOnly); // force entryAttributes
-
- const char * const note =
- module->module()->getEntryAttributes()
- ["Footnote"][swordFootnote.toLatin1().data()]["body"].c_str();
-
- QString text = module->isUnicode() ? QString::fromUtf8(note) : QString(note);
- text = QString::fromUtf8(module->module()->renderText(
- module->isUnicode()
- ? static_cast<const char *>(text.toUtf8())
- : static_cast<const char *>(text.toLatin1())));
-
- return QString("<div class=\"footnoteinfo\" lang=\"%1\"><h3>%2</h3><p>%3</p></div>")
- .arg(module->language()->abbrev())
- .arg(tr("Footnote"))
- .arg(text);
-}
-
-const QString CInfoDisplay::decodeStrongs(const QString & data) {
- QStringList strongs = data.split("|");
- QString ret;
-
- QStringList::const_iterator end = strongs.end();
- for (QStringList::const_iterator it = strongs.begin(); it != end; ++it) {
- CSwordModuleInfo * const module = btConfig().getDefaultSwordModuleByType
- (
- ((*it).left(1) == QString("H")) ?
- "standardHebrewStrongsLexicon" :
- "standardGreekStrongsLexicon"
- );
-
- QString text;
- if (module) {
- QSharedPointer<CSwordKey> key(CSwordKey::createInstance(module));
- key->setKey((*it).mid(1)); // skip H or G (language sign), will have to change later if we have better modules
- text = key->renderedText();
- }
- //if the module could not be found just display an empty lemma info
-
- QString lang = "en"; // default english
- if (module)
- lang = module->language()->abbrev();
- ret.append(
- QString("<div class=\"strongsinfo\" lang=\"%1\"><h3>%2: %3</h3><p>%4</p></div>")
- .arg(lang)
- .arg(tr("Strongs"))
- .arg(*it)
- .arg(text)
- );
- }
-
- return ret;
-}
-
-const QString CInfoDisplay::decodeMorph(const QString & data) {
- QStringList morphs = data.split("|");
- QString ret;
-
- Q_FOREACH (QString morph, morphs) {
- //qDebug() << "CInfoDisplay::decodeMorph, morph: " << morph;
- CSwordModuleInfo * module = 0;
- bool skipFirstChar = false;
- QString value = "";
- QString valueClass = "";
-
- int valStart = morph.indexOf(':');
- if (valStart > -1) {
- valueClass = morph.mid(0, valStart);
- // qDebug() << "valueClass: " << valueClass;
- module = CSwordBackend::instance()->findModuleByName(valueClass);
- }
- value = morph.mid(valStart + 1); //works for prepended module and without (-1 +1 == 0).
-
- // if we don't have a class assigned or desired one isn't installed...
- if (!module) {
- // Morphs usually don't have [GH] prepended, but some old OLB
- // codes do. We should check if we're digit after first char
- // to better guess this.
- if (value.size() > 1 && value.at(1).isDigit()) {
- switch (value.at(0).toLatin1()) {
- case 'G':
- module = btConfig().getDefaultSwordModuleByType("standardGreekMorphLexicon");
- skipFirstChar = true;
- break;
- case 'H':
- module = btConfig().getDefaultSwordModuleByType("standardHebrewMorphLexicon");
- skipFirstChar = true;
- break;
- default:
- skipFirstChar = false;
- /// \todo we can't tell here if it's a greek or hebrew moprh code, that's a problem we have to solve
- // module = getBtConfig().getDefaultSwordModuleByType("standardGreekMorphLexicon");
- break;
- }
- }
- //if it is still not set use the default
- if (!module)
- module = btConfig().getDefaultSwordModuleByType("standardGreekMorphLexicon");
- }
-
- QString text;
- // Q_ASSERT(module);
- if (module) {
- QSharedPointer<CSwordKey> key(CSwordKey::createInstance(module));
-
- // skip H or G (language sign) if we have to skip it
- const bool isOk = key->setKey(skipFirstChar ? value.mid(1) : value);
- // Q_ASSERT(isOk);
- if (!isOk) { // try to use the other morph lexicon, because this one failed with the current morph code
- key->setModule(btConfig().getDefaultSwordModuleByType("standardHebrewMorphLexicon")); /// \todo: what if the module doesn't exist?
- key->setKey(skipFirstChar ? value.mid(1) : value);
- }
-
- text = key->renderedText();
- }
-
- // if the module wasn't found just display an empty morph info
- QString lang = "en"; // default to english
- if (module)
- lang = module->language()->abbrev();
- ret.append(QString("<div class=\"morphinfo\" lang=\"%1\"><h3>%2: %3</h3><p>%4</p></div>")
- .arg(lang)
- .arg(tr("Morphology"))
- .arg(value)
- .arg(text)
- );
- }
-
- return ret;
-}
-
-const QString CInfoDisplay::getWordTranslation(const QString & data) {
- CSwordModuleInfo * const module = btConfig().getDefaultSwordModuleByType("standardLexicon");
- if (!module)
- return QString::null;
-
- QSharedPointer<CSwordKey> key(CSwordKey::createInstance(module));
- key->setKey(data);
- if (key->key().toUpper() != data.toUpper()) //key not present in the lexicon
- return QString::null;
-
- return QString("<div class=\"translationinfo\" lang=\"%1\"><h3>%2: %3</h3><p>%4</p></div>")
- .arg(module->language()->abbrev())
- .arg(tr("Word lookup"))
- .arg(data)
- .arg(key->renderedText());
-}
-
QSize CInfoDisplay::sizeHint() const {
return QSize(100, 150);
}
diff --git a/src/frontend/cinfodisplay.h b/src/frontend/cinfodisplay.h
index 46623ba..a7e18b1 100644
--- a/src/frontend/cinfodisplay.h
+++ b/src/frontend/cinfodisplay.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -16,7 +16,7 @@
#include <QList>
#include <QPair>
-#include "backend/rendering/ctextrendering.h"
+#include "backend/rendering/btinforendering.h"
class CReadDisplay;
@@ -31,46 +31,21 @@ class CInfoDisplay: public QWidget {
Q_OBJECT
-public: /* Types: */
-
- enum InfoType {
- Abbreviation,
- CrossReference,
- Footnote,
- Lemma,
- Morph,
- WordTranslation,
- WordGloss,
- Text
- };
-
- typedef QPair<InfoType, QString> InfoData;
- typedef QList<InfoData> ListInfoData;
-
public: /* Methods: */
- CInfoDisplay(BibleTime * parent = NULL);
+ CInfoDisplay(BibleTime * parent = nullptr);
void unsetInfo();
void setInfo(const QString & renderedData,
const QString & lang = QString());
- void setInfo(const InfoType, const QString & data);
- void setInfo(const ListInfoData &);
- QSize sizeHint() const;
+ void setInfo(Rendering::InfoType const, QString const & data);
+ void setInfo(Rendering::ListInfoData const &);
+ QSize sizeHint() const override;
public slots:
void setInfo(CSwordModuleInfo * module);
-private: /* Methods: */
-
- const QString decodeAbbreviation(const QString & data);
- const QString decodeCrossReference(const QString & data);
- const QString decodeFootnote(const QString & data);
- const QString decodeStrongs(const QString & data);
- const QString decodeMorph(const QString & data);
- const QString getWordTranslation(const QString & data);
-
private slots:
void lookupInfo(const QString &, const QString &);
diff --git a/src/frontend/cmdiarea.cpp b/src/frontend/cmdiarea.cpp
index d879dfa..0e01cc8 100644
--- a/src/frontend/cmdiarea.cpp
+++ b/src/frontend/cmdiarea.cpp
@@ -2,15 +2,13 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
-#include "bibletime.h"
#include "frontend/cmdiarea.h"
-#include "frontend/displaywindow/btmodulechooserbar.h"
-#include "frontend/display/cdisplay.h"
+
#include <QEvent>
#include <QMdiSubWindow>
#include <QMenu>
@@ -18,8 +16,13 @@
#include <QTabBar>
#include <QTimer>
#include <QToolBar>
-#include <QWebView>
+#include "frontend/btwebenginepage.h"
+#include "frontend/btwebengineview.h"
#include <QWindowStateChangeEvent>
+#include "bibletime.h"
+#include "frontend/displaywindow/btmodulechooserbar.h"
+#include "frontend/display/cdisplay.h"
+#include "util/btconnect.h"
namespace {
@@ -28,30 +31,26 @@ inline CDisplayWindow * getDisplayWindow(const QMdiSubWindow * const mdiWindow)
return qobject_cast<CDisplayWindow *>(mdiWindow->widget());
}
-inline QWebView * getWebViewFromDisplayWindow(const CDisplayWindow * const displayWindow) {
+inline BtWebEngineView * getWebViewFromDisplayWindow(const CDisplayWindow * const displayWindow) {
if (!displayWindow)
- return NULL;
+ return nullptr;
CDisplay * const display = displayWindow->displayWidget();
if (!display)
- return NULL;
- return qobject_cast<QWebView *>(display->view());
+ return nullptr;
+ return qobject_cast<BtWebEngineView *>(display->view());
}
} // anonymous namespace
-CMDIArea::CMDIArea(BibleTime *parent)
- : QMdiArea(parent)
+CMDIArea::CMDIArea(BibleTime * parent)
+ : QMdiArea((BT_ASSERT(parent), parent))
, m_mdiArrangementMode(ArrangementModeManual)
- , m_activeWindow(0)
+ , m_activeWindow(nullptr)
, m_bibleTime(parent)
{
- Q_ASSERT(parent != 0);
-
- #if QT_VERSION >= 0x040500
// Set document-style tabs (for Mac):
setDocumentMode(true);
- #endif
/*
Activate windows based on the history of activation, e.g. when one has window A
@@ -63,8 +62,8 @@ CMDIArea::CMDIArea(BibleTime *parent)
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- connect(this, SIGNAL(subWindowActivated(QMdiSubWindow*)),
- this, SLOT(slotSubWindowActivated(QMdiSubWindow*)));
+ BT_CONNECT(this, SIGNAL(subWindowActivated(QMdiSubWindow *)),
+ this, SLOT(slotSubWindowActivated(QMdiSubWindow *)));
}
void CMDIArea::fixSystemMenu(QMdiSubWindow* subWindow) {
@@ -129,22 +128,18 @@ void CMDIArea::setMDIArrangementMode( const MDIArrangementMode newArrangementMod
break;
case ArrangementModeTabbed:
setViewMode(QMdiArea::TabbedView);
+ for (auto win : subWindowList())
+ win->showMaximized();
break;
default:
setViewMode(QMdiArea::SubWindowView);
triggerWindowUpdate();
break;
}
- Q_FOREACH (QTabBar* tab, findChildren<QTabBar *>()) {
+ Q_FOREACH(QTabBar * const tab, findChildren<QTabBar *>()) {
QObject* parent = tab->parent();
- if (parent == this) {
+ if (parent == this)
tab->setTabsClosable(true);
-// As of version 4.8, Qt does the close for us.
-#if QT_VERSION < 0x040800
- disconnect(tab, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
- connect(tab, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
-#endif
- }
}
}
@@ -182,7 +177,7 @@ void CMDIArea::myTileVertical() {
x += actWidth;
}
- if (active != 0) {
+ if (active != nullptr) {
active->setFocus();
}
@@ -215,7 +210,7 @@ void CMDIArea::myTileHorizontal() {
y += actHeight;
}
- if (active != 0) {
+ if (active != nullptr) {
active->setFocus();
}
@@ -292,19 +287,17 @@ QList<QMdiSubWindow*> CMDIArea::usableWindowList() const {
//Take care: when new windows are added, they will not appear
//in subWindowList() when their ChildAdded-Event is triggered
QList<QMdiSubWindow*> ret;
- Q_FOREACH (QMdiSubWindow * const w, subWindowList()) {
- if (!w->isHidden()) {
+ Q_FOREACH(QMdiSubWindow * const w, subWindowList())
+ if (!w->isHidden())
ret.append(w);
- }
- }
return ret;
}
-QWebView* CMDIArea::getActiveWebView()
+BtWebEngineView* CMDIArea::getActiveWebView()
{
QMdiSubWindow* activeMdiWindow = activeSubWindow();
CDisplayWindow* const activeWindow = getDisplayWindow(activeMdiWindow);
- QWebView* webView = getWebViewFromDisplayWindow(activeWindow);
+ BtWebEngineView* webView = getWebViewFromDisplayWindow(activeWindow);
return webView;
}
@@ -312,48 +305,39 @@ void CMDIArea::slotSubWindowActivated(QMdiSubWindow* client) {
if (subWindowList().isEmpty())
m_bibleTime->clearMdiToolBars();
- if (client == 0) {
+ if (client == nullptr) {
return;
}
emit sigSetToplevelCaption( client->windowTitle().trimmed() );
// Notify child window it is active
CDisplayWindow* const activeWindow = getDisplayWindow(client);
- if (activeWindow != 0 && activeWindow != m_activeWindow) {
+ if (activeWindow != nullptr && activeWindow != m_activeWindow) {
m_activeWindow = activeWindow;
activeWindow->windowActivated();
}
}
-void CMDIArea::findNextTextInActiveWindow(const QString& text, bool caseSensitive) {
- QWebView* activeWebView = getActiveWebView();
- if (activeWebView == 0)
- return;
- QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
- if (caseSensitive)
- options |= QWebPage::FindCaseSensitively;
- activeWebView->findText(text, options);
-}
+void CMDIArea::findNextTextInActiveWindow(QString const & text, bool cs)
+{ findTextInActiveWindow(text, cs, false); }
-void CMDIArea::findPreviousTextInActiveWindow(const QString& text, bool caseSensitive) {
- QWebView* activeWebView = getActiveWebView();
- if (activeWebView == 0)
- return;
- QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
- if (caseSensitive)
- options |= QWebPage::FindCaseSensitively;
- activeWebView->findText(text, options);
-}
+void CMDIArea::findPreviousTextInActiveWindow(QString const & text, bool cs)
+{ findTextInActiveWindow(text, cs, true); }
void CMDIArea::highlightTextInActiveWindow(const QString& text, bool caseSensitive) {
- QWebView* activeWebView = getActiveWebView();
- if (activeWebView == 0)
+ BtWebEngineView* activeWebView = getActiveWebView();
+ if (activeWebView == nullptr)
return;
- QWebPage::FindFlags options = QWebPage::HighlightAllOccurrences;
- if (caseSensitive)
- options |= QWebPage::FindCaseSensitively;
- activeWebView->findText("", options); // clear old highlight
- activeWebView->findText(text, options);
+ activeWebView->findTextHighlight(text, caseSensitive);
+}
+
+void CMDIArea::findTextInActiveWindow(QString const & text,
+ bool caseSensitive,
+ bool backward)
+{
+ if (BtWebEngineView * const activeWebView = getActiveWebView()) {
+ activeWebView->findText(text, caseSensitive, backward);
+ }
}
void CMDIArea::resizeEvent(QResizeEvent* e) {
@@ -377,13 +361,14 @@ bool CMDIArea::eventFilter(QObject *o, QEvent *e) {
const QMdiSubWindow * const w = qobject_cast<QMdiSubWindow*>(o);
// Let the event be handled by other filters:
- if (w == 0)
+ if (w == nullptr)
return QMdiArea::eventFilter(o, e);
switch (e->type()) {
case QEvent::WindowStateChange: {
- Qt::WindowStates newState(w->windowState());
- Qt::WindowStates oldState(((QWindowStateChangeEvent*)e)->oldState());
+ Qt::WindowStates const newState(w->windowState());
+ Qt::WindowStates const oldState(
+ static_cast<QWindowStateChangeEvent *>(e)->oldState());
/*
Do not handle window activation or deactivation here, it will
diff --git a/src/frontend/cmdiarea.h b/src/frontend/cmdiarea.h
index 6245d94..56afce4 100644
--- a/src/frontend/cmdiarea.h
+++ b/src/frontend/cmdiarea.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -20,7 +20,7 @@
class BibleTime;
class CSwordModuleInfo;
class CDisplayWindow;
-class QWebView;
+class BtWebEngineView;
/**
A custom MDI area widget.
@@ -55,7 +55,7 @@ class CMDIArea: public QMdiArea {
Reimplementation of QMdiArea::addSubWindow().
*/
QMdiSubWindow * addSubWindow(QWidget * widget,
- Qt::WindowFlags windowFlags = 0);
+ Qt::WindowFlags windowFlags = nullptr);
/**
Returns the BibleTime main window
@@ -144,23 +144,27 @@ class CMDIArea: public QMdiArea {
protected: /* Methods: */
+ void findTextInActiveWindow(QString const & text,
+ bool caseSensitive,
+ bool backward);
+
/**
Reimplementation of QWidget::resizeEvent() to handle our automatic
tiling properly.
*/
- void resizeEvent(QResizeEvent *e);
+ void resizeEvent(QResizeEvent *e) override;
/**
Reimplementation of QObject::eventFilter() used to handle some MDI
subwindow events.
*/
- bool eventFilter(QObject *o, QEvent *e);
+ bool eventFilter(QObject *o, QEvent *e) override;
void emitWindowCaptionChanged();
void fixSystemMenu(QMdiSubWindow* subWindow);
- QWebView* getActiveWebView();
+ BtWebEngineView *getActiveWebView();
protected slots:
diff --git a/src/frontend/cprinter.cpp b/src/frontend/cprinter.cpp
deleted file mode 100644
index b10d614..0000000
--- a/src/frontend/cprinter.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/cprinter.h"
-
-#include <QPrintDialog>
-#include <QPrinter>
-#include <QWebFrame>
-#include <QWebPage>
-#include "backend/keys/cswordversekey.h"
-#include "backend/managers/cdisplaytemplatemgr.h"
-#include "backend/config/btconfig.h"
-
-
-namespace Printing {
-
-/// \todo WHY IS parent NOT USED!?
-CPrinter::CPrinter(QObject *,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions)
- : QObject(0),
- CDisplayRendering(displayOptions, filterOptions),
- m_htmlPage(new QWebPage())
-{
- m_htmlPage->setParent(this);
-
- //override the filteroptions set in the c-tor of CDisplayRendering
- m_filterOptions.footnotes = false;
- m_filterOptions.scriptureReferences = false;
- m_filterOptions.strongNumbers = false;
- m_filterOptions.morphTags = false;
- m_filterOptions.headings = false;
-}
-
-CPrinter::~CPrinter() {
- delete m_htmlPage;
- m_htmlPage = 0;
-}
-
-void CPrinter::printKeyTree( KeyTree& tree ) {
- m_htmlPage->mainFrame()->setHtml(renderKeyTree(tree));
-
- QPrinter printer;
- QPrintDialog printDialog(&printer);
- if (printDialog.exec() == QDialog::Accepted) {
- m_htmlPage->mainFrame()->print(&printer);
- }
-}
-
-QString CPrinter::entryLink(const KeyTreeItem &item,
- const CSwordModuleInfo * module)
-{
- Q_ASSERT(module);
- if (module->type() == CSwordModuleInfo::Bible) {
- CSwordVerseKey vk(module);
- vk.setKey(item.key());
- switch (item.settings().keyRenderingFace) {
- case KeyTreeItem::Settings::CompleteShort:
- return QString::fromUtf8(vk.getShortText());
-
- case KeyTreeItem::Settings::CompleteLong:
- return vk.key();
-
- case KeyTreeItem::Settings::NoKey:
- return QString::null;
-
- case KeyTreeItem::Settings::SimpleKey: //fall through
- default:
- return QString::number(vk.getVerse());
- }
- }
- return item.key();
-}
-
-QString CPrinter::renderEntry(const KeyTreeItem &i, CSwordKey * key) {
- Q_UNUSED(key);
-
- const CPrinter::KeyTreeItem* printItem = dynamic_cast<const CPrinter::KeyTreeItem*>(&i);
- Q_ASSERT(printItem);
-
- if (printItem && printItem->hasAlternativeContent()) {
- QString ret = QString::fromLatin1("<div class=\"entry\"><div class=\"rangeheading\">%1</div>").arg(printItem->getAlternativeContent());
-
- if (!i.childList()->isEmpty()) {
- KeyTree const * tree = i.childList();
-
- Q_FOREACH (const KeyTreeItem * const c, *tree) {
- ret.append( CDisplayRendering::renderEntry( *c ) );
- }
- }
-
- ret.append("</div>");
- return ret;
- }
- return CDisplayRendering::renderEntry(i);
-}
-
-QString CPrinter::finishText(const QString &text, const KeyTree &tree) {
- QList<const CSwordModuleInfo*> modules = collectModules(tree);
- Q_ASSERT(modules.count() > 0);
-
- const CLanguageMgr::Language* const lang = modules.first()->language();
- Q_ASSERT(lang);
-
- CDisplayTemplateMgr::Settings settings;
- //settings.modules = modules;
- settings.pageCSS_ID = "printer";
- if (modules.count() == 1 && lang->isValid())
- settings.langAbbrev = lang->abbrev();
-
- if (modules.count() == 1)
- settings.textDirection = modules.first()->textDirection();
-
- CDisplayTemplateMgr *tMgr = CDisplayTemplateMgr::instance();
- return tMgr->fillTemplate(CDisplayTemplateMgr::activeTemplateName(), text, settings);
-}
-
-} //end of namespace
diff --git a/src/frontend/cprinter.h b/src/frontend/cprinter.h
deleted file mode 100644
index 48001a1..0000000
--- a/src/frontend/cprinter.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef CPRINTER_H
-#define CPRINTER_H
-
-#include <QObject>
-#include "backend/rendering/cdisplayrendering.h"
-
-#include "backend/managers/cswordbackend.h"
-
-
-class QWebPage;
-
-namespace Printing {
-
-// The CPrinter class manages the print item queue and the printing of them to the printer.
-
-class CPrinter : public QObject, public Rendering::CDisplayRendering {
- Q_OBJECT
- public:
- CPrinter(QObject *parent,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions);
-
- virtual ~CPrinter();
- void printKeyTree( KeyTree& );
-
- protected:
- virtual QString entryLink(const KeyTreeItem &item,
- const CSwordModuleInfo * module);
-
- virtual QString renderEntry(const KeyTreeItem &item, CSwordKey * key = 0);
- virtual QString finishText(const QString &text, const KeyTree &tree);
-
- private:
- QWebPage* m_htmlPage;
-};
-
-} //namespace Printing
-
-#endif
diff --git a/src/frontend/crossrefrendering.cpp b/src/frontend/crossrefrendering.cpp
index 868b6ce..d81c326 100644
--- a/src/frontend/crossrefrendering.cpp
+++ b/src/frontend/crossrefrendering.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,6 +12,7 @@
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/keys/cswordversekey.h"
#include "backend/managers/referencemanager.h"
+#include "util/btassert.h"
namespace InfoDisplay {
@@ -31,9 +32,10 @@ QString CrossRefRendering::finishText(const QString &text, const KeyTree &tree)
QString CrossRefRendering::entryLink(const KeyTreeItem &item,
const CSwordModuleInfo *module)
{
+ BT_ASSERT(module);
QString linkText;
- const bool isBible = module && (module->type() == CSwordModuleInfo::Bible);
+ const bool isBible = (module->type() == CSwordModuleInfo::Bible);
CSwordVerseKey vk(module); //only valid for bible modules, i.e. isBible == true
if (isBible) {
vk.setKey(item.key());
diff --git a/src/frontend/crossrefrendering.h b/src/frontend/crossrefrendering.h
index fb22aa2..0dbf233 100644
--- a/src/frontend/crossrefrendering.h
+++ b/src/frontend/crossrefrendering.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -27,10 +27,10 @@ class CrossRefRendering : public Rendering::CHTMLExportRendering {
const FilterOptions &filterOptions = btConfig().getFilterOptions()
);
- virtual QString entryLink(const KeyTreeItem &item,
- const CSwordModuleInfo *module);
+ QString entryLink(const KeyTreeItem &item,
+ const CSwordModuleInfo *module) override;
- virtual QString finishText(const QString &text, const KeyTree &tree);
+ QString finishText(const QString &text, const KeyTree &tree) override;
};
diff --git a/src/frontend/display/btcolorwidget.cpp b/src/frontend/display/btcolorwidget.cpp
index 579e461..908037b 100644
--- a/src/frontend/display/btcolorwidget.cpp
+++ b/src/frontend/display/btcolorwidget.cpp
@@ -2,58 +2,46 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "frontend/display/btcolorwidget.h"
-#include <QColor>
#include <QColorDialog>
#include <QMouseEvent>
#include <QPalette>
-BtColorWidget::BtColorWidget(QWidget* parent)
- : QFrame(parent) {
+BtColorWidget::BtColorWidget(QWidget * parent)
+ : QFrame(parent)
+{
setFrameShadow(QFrame::Sunken);
setFrameShape(QFrame::StyledPanel);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
setAutoFillBackground(true);
+ setBackgroundRole(QPalette::Window);
}
-BtColorWidget::~BtColorWidget() {
-}
-
-QSize BtColorWidget::sizeHint() const {
- return QSize(35, 18);
-}
+QSize BtColorWidget::sizeHint() const { return QSize(35, 18); }
-void BtColorWidget::setColor(const QColor& color) {
- QPalette p = palette();
+void BtColorWidget::setColor(QColor const & color) {
+ QPalette p(palette());
p.setColor(QPalette::Normal, QPalette::Window, color);
setPalette(p);
-
- if (color.isValid())
- m_color = color;
- else
- m_color = QColor(0, 0, 0);
update();
}
-void BtColorWidget::mouseReleaseEvent(QMouseEvent* event) {
+void BtColorWidget::mouseReleaseEvent(QMouseEvent * event) {
if (event->button() == Qt::LeftButton) {
event->accept();
- showColorDialog();
- return;
- }
-}
-
-void BtColorWidget::showColorDialog() {
- QColor color = QColorDialog::getColor(m_color, this);
- if (color.isValid()) {
- m_color = color;
- emit changed(m_color);
+ QColor const color(QColorDialog::getColor(
+ palette().color(QPalette::Normal, QPalette::Window),
+ this));
+ if (color.isValid()) {
+ setColor(color);
+ emit changed(color);
+ }
}
}
diff --git a/src/frontend/display/btcolorwidget.h b/src/frontend/display/btcolorwidget.h
index 9dd2e97..ab8d9c4 100644
--- a/src/frontend/display/btcolorwidget.h
+++ b/src/frontend/display/btcolorwidget.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -15,29 +15,28 @@
#include <QFrame>
-class QPaintEvent;
+class BtColorWidget: public QFrame {
-class BtColorWidget : public QFrame {
- Q_OBJECT
+ Q_OBJECT
- public:
- BtColorWidget(QWidget* parent = 0);
- ~BtColorWidget();
- QSize sizeHint() const;
+public:
- public slots:
- void setColor(const QColor& color);
+ BtColorWidget(QWidget * parent = nullptr);
- protected:
- void mouseReleaseEvent(QMouseEvent* event);
+ QSize sizeHint() const override;
- private:
- void showColorDialog();
+public slots:
- QColor m_color;
+ void setColor(QColor const & color);
+
+protected: /* Methods: */
+
+ void mouseReleaseEvent(QMouseEvent * event) override;
+
+signals:
+
+ void changed(QColor const & color);
- signals:
- void changed(const QColor& color);
};
#endif
diff --git a/src/frontend/display/btfindwidget.cpp b/src/frontend/display/btfindwidget.cpp
index 1ada629..d60c290 100644
--- a/src/frontend/display/btfindwidget.cpp
+++ b/src/frontend/display/btfindwidget.cpp
@@ -2,117 +2,99 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "frontend/display/btfindwidget.h"
-#include "QApplication"
#include "QCheckBox"
#include "QHBoxLayout"
#include "QLineEdit"
#include "QSpacerItem"
#include "QToolButton"
-#include "bibletimeapp.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
-
-
-BtFindWidget::BtFindWidget(QWidget* parent)
- : QWidget(parent) {
- createLayout();
- createToolButton(CResMgr::findWidget::close_icon, "", SLOT(hide()));
- createTextEditor();
- createToolButton(CResMgr::findWidget::previous_icon, tr("Previous"), SLOT(findPrevious()));
- createToolButton(CResMgr::findWidget::next_icon, tr("Next"), SLOT(findNext()));
- createCaseCheckBox();
- createSpacer();
- setFocusProxy(m_textEditor);
-}
-BtFindWidget::~BtFindWidget() {
+
+namespace {
+inline QToolButton * newToolButton(QIcon const & icon,
+ char const * const slot,
+ QWidget * const parent,
+ QHBoxLayout * const layout)
+{
+ QToolButton * const button = new QToolButton(parent);
+ button->setIcon(icon);
+ button->setIconSize(QSize(16, 16));
+ button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ button->setAutoRaise(true);
+ layout->addWidget(button);
+ BT_CONNECT_QOBJECT(button, SIGNAL(released()), parent, slot);
+ return button;
}
+} // anonymous namespace
-void BtFindWidget::createLayout() {
+BtFindWidget::BtFindWidget(QWidget * parent)
+ : QWidget(parent)
+{
+ // Overall layout:
m_layout = new QHBoxLayout(this);
m_layout->setMargin(0);
m_layout->setSpacing(8);
-}
-void BtFindWidget::createToolButton(const QString& iconName, const QString& text, const char* slot) {
- QToolButton* button = new QToolButton(this);
- button->setIcon(util::getIcon(iconName));
- button->setIconSize(QSize(16,16));
- button->setText(text);
- button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- button->setAutoRaise(true);
- m_layout->addWidget(button);
- bool ok = connect(button, SIGNAL(released()), this, slot);
- Q_ASSERT(ok);
-}
+ // Buttons and text editor:
+ #define newButton(...) newToolButton(__VA_ARGS__, this, m_layout)
+
+ // Close button:
+ newButton(CResMgr::findWidget::icon_close(), SLOT(hide()));
-void BtFindWidget::createTextEditor() {
+ // Text editor:
m_textEditor = new QLineEdit(this);
-#if QT_VERSION < 0x050000
- m_textEditor->setToolTip(QApplication::translate("findWidget",
- "The text you want to search for", 0, QApplication::UnicodeUTF8));
-#else
- m_textEditor->setToolTip(QApplication::translate("findWidget",
- "The text you want to search for", 0));
-#endif
m_layout->addWidget(m_textEditor);
- bool ok = connect(m_textEditor, SIGNAL(textChanged(const QString&)),
- this, SLOT(textChanged(const QString&)));
- Q_ASSERT(ok);
- ok = connect(m_textEditor,SIGNAL(returnPressed()), this, SLOT(returnPressed()));
- Q_ASSERT(ok);
-}
-
-void BtFindWidget::createCaseCheckBox() {
- m_caseCheckBox = new QCheckBox(tr("Match case"), this);
+ BT_CONNECT(m_textEditor, SIGNAL(textChanged(QString const &)),
+ this, SLOT(textChanged(QString const &)));
+ BT_CONNECT(m_textEditor, SIGNAL(returnPressed()),
+ this, SLOT(returnPressed()));
+
+ // Next and Previous buttons:
+ m_previousButton = newButton(CResMgr::findWidget::icon_previous(),
+ SLOT(findPrevious()));
+ m_nextButton = newButton(CResMgr::findWidget::icon_next(),
+ SLOT(findNext()));
+
+ // Case checkbox:
+ m_caseCheckBox = new QCheckBox(this);
+ BT_CONNECT(m_caseCheckBox, SIGNAL(stateChanged(int)),
+ this, SLOT(caseStateChanged(int)));
m_layout->addWidget(m_caseCheckBox);
-}
-
-void BtFindWidget::createSpacer() {
- QSpacerItem* spacer = new QSpacerItem(0,0,QSizePolicy::Expanding, QSizePolicy::Minimum);
- m_layout->addItem(spacer);
-}
-void BtFindWidget::highlightText(const QString& text) {
- bool caseSensitive = m_caseCheckBox->checkState() == Qt::Checked;
- emit highlightText(text, caseSensitive);
-}
+ // Spacer:
+ m_layout->addItem(new QSpacerItem(0,
+ 0,
+ QSizePolicy::Expanding,
+ QSizePolicy::Minimum));
+ setFocusProxy(m_textEditor);
-void BtFindWidget::returnPressed() {
- bool caseSensitive = m_caseCheckBox->checkState() == Qt::Checked;
- QString text = m_textEditor->text();
- emit highlightText(text, caseSensitive);
- emit findNext(text, caseSensitive);
+ retranslateUi();
}
-void BtFindWidget::textChanged(const QString& text) {
- bool caseSensitive = m_caseCheckBox->checkState() == Qt::Checked;
- emit highlightText(text, caseSensitive);
- emit findNext(text, caseSensitive);
+void BtFindWidget::retranslateUi() {
+ m_textEditor->setToolTip(tr("The text you want to search for",
+ "findWidget"));
+ m_previousButton->setText(tr("Previous"));
+ m_nextButton->setText(tr("Next"));
+ m_caseCheckBox->setText(tr("Match case"));
}
-void BtFindWidget::findNext() {
- bool caseSensitive = m_caseCheckBox->checkState() == Qt::Checked;
- QString text = m_textEditor->text();
- emit findNext(text, caseSensitive);
-}
+bool BtFindWidget::caseSensitive() const
+{ return m_caseCheckBox->checkState() == Qt::Checked; }
-void BtFindWidget::findPrevious() {
- bool caseSensitive = m_caseCheckBox->checkState() == Qt::Checked;
- QString text = m_textEditor->text();
- emit findPrevious(text, caseSensitive);
-}
+QString BtFindWidget::text() const { return m_textEditor->text(); }
-void BtFindWidget::showAndSelect(){
+void BtFindWidget::showAndSelect() {
setVisible(true);
- QWidget::show();
+ show();
m_textEditor->selectAll();
m_textEditor->setFocus(Qt::ShortcutFocusReason);
}
diff --git a/src/frontend/display/btfindwidget.h b/src/frontend/display/btfindwidget.h
index 52a879a..bd32cb7 100644
--- a/src/frontend/display/btfindwidget.h
+++ b/src/frontend/display/btfindwidget.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -13,44 +13,61 @@
#define BTFINDIDGET_H
#include <QWidget>
-#include <QWebPage>
+
+
class QCheckBox;
-class QLineEdit;
class QHBoxLayout;
+class QLineEdit;
class QString;
+class QToolButton;
-class BtFindWidget : public QWidget {
- Q_OBJECT
-
- public:
- BtFindWidget(QWidget* parent = 0);
- ~BtFindWidget();
- void showAndSelect();
-
- private slots:
- void findNext();
- void findPrevious();
- void returnPressed();
- void textChanged(const QString& text);
-
- private:
- void createCaseCheckBox();
- void createLayout();
- void createSpacer();
- void createTextEditor();
- void createToolButton(const QString& iconName, const QString& text, const char* slot);
- void highlightText(const QString& searchText);
-
- QHBoxLayout* m_layout;
- QLineEdit* m_textEditor;
- QCheckBox* m_caseCheckBox;
-
- signals:
- void findPrevious(const QString & text, bool caseSensitive);
- void findNext(const QString & text, bool caseSensitive);
- void highlightText(const QString & text, bool caseSensitive);
-};
+class BtFindWidget: public QWidget {
-#endif
+ Q_OBJECT
+
+public: /* Methods: */
+
+ BtFindWidget(QWidget * parent = nullptr);
+
+ void showAndSelect();
+
+private slots:
+
+ void findNext() { emit findNext(text(), caseSensitive()); }
+ void findPrevious() { emit findPrevious(text(), caseSensitive()); }
+ void returnPressed() { emitChange(text(), caseSensitive()); }
+ void textChanged(QString const & txt) { emitChange(txt, caseSensitive()); }
+ void caseStateChanged(int st) { emitChange(text(), st == Qt::Checked); }
+
+private: /* Methods: */
+ void retranslateUi();
+ void highlightText(QString const & text)
+ { emit highlightText(text, caseSensitive()); }
+
+ bool caseSensitive() const;
+
+ QString text() const;
+
+ void emitChange(QString const & text, bool const caseSensitive) {
+ emit highlightText(text, caseSensitive);
+ }
+
+signals:
+
+ void findPrevious(QString const & text, bool caseSensitive);
+ void findNext(QString const & text, bool caseSensitive);
+ void highlightText(QString const & text, bool caseSensitive);
+
+private: /* Fields: */
+
+ QHBoxLayout * m_layout;
+ QLineEdit * m_textEditor;
+ QToolButton * m_nextButton;
+ QToolButton * m_previousButton;
+ QCheckBox * m_caseCheckBox;
+
+};
+
+#endif
diff --git a/src/frontend/display/btfontsizewidget.cpp b/src/frontend/display/btfontsizewidget.cpp
index 82fdd08..eccacd3 100644
--- a/src/frontend/display/btfontsizewidget.cpp
+++ b/src/frontend/display/btfontsizewidget.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -11,36 +11,36 @@
#include <QCompleter>
#include <QFontDatabase>
+#include <QValidator>
+#include "util/btconnect.h"
-BtFontSizeWidget::BtFontSizeWidget(QWidget* parent)
- : QComboBox(parent) {
+BtFontSizeWidget::BtFontSizeWidget(QWidget * parent)
+ : QComboBox(parent)
+ , m_validator(new QIntValidator(1, 99, this))
+{
setEditable(true);
+ setValidator(m_validator);
completer()->setCompletionMode(QCompleter::PopupCompletion);
- QFontDatabase database;
- const QList<int> sizes = database.standardSizes();
- QStringList list;
- for ( QList<int>::ConstIterator it = sizes.begin(); it != sizes.end(); ++it )
- list.append( QString::number( *it ) );
- addItems(list);
+ Q_FOREACH (int const size, QFontDatabase().standardSizes()) {
+ if (size > m_validator->top())
+ m_validator->setTop(size);
+ addItem(QString::number(size), QVariant(size));
+ }
- bool ok = connect(this, SIGNAL(currentIndexChanged(const QString&)),
- this, SLOT(changed(const QString&)));
- Q_ASSERT(ok);
+ BT_CONNECT(this, SIGNAL(currentIndexChanged(QString const &)),
+ this, SLOT(changed(QString const &)));
}
-BtFontSizeWidget::~BtFontSizeWidget() {
-}
-
-void BtFontSizeWidget::changed(const QString& text) {
+void BtFontSizeWidget::changed(QString const & text) {
emit fontSizeChanged(text.toInt());
}
void BtFontSizeWidget::setFontSize(int size) {
- int index = findText(QString::number(size));
- if (index >= 0)
- setCurrentIndex(index);
+ if ((size < 1) || (size > m_validator->top()))
+ size = 12;
+ setCurrentText(QString::number(size));
}
int BtFontSizeWidget::fontSize() const {
diff --git a/src/frontend/display/btfontsizewidget.h b/src/frontend/display/btfontsizewidget.h
index 40b94a1..7cd7e43 100644
--- a/src/frontend/display/btfontsizewidget.h
+++ b/src/frontend/display/btfontsizewidget.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -15,22 +15,34 @@
#include <QComboBox>
-class BtFontSizeWidget : public QComboBox {
- Q_OBJECT
+class QIntValidator;
- public:
- BtFontSizeWidget(QWidget* parent = 0);
- ~BtFontSizeWidget();
- int fontSize() const;
+class BtFontSizeWidget: public QComboBox {
- public slots:
- void setFontSize(int size);
+ Q_OBJECT
- private slots:
- virtual void changed(const QString& text);
+public: /* Methods: */
- signals:
- void fontSizeChanged( int );
-};
+ BtFontSizeWidget(QWidget * parent = nullptr);
+
+ int fontSize() const;
+
+public slots:
+
+ void setFontSize(int size);
+
+private slots:
+
+ virtual void changed(QString const & text);
+
+signals:
+
+ void fontSizeChanged(int);
+
+private: /* Fields: */
+
+ QIntValidator * const m_validator;
+
+}; /* class BtFontSizeWidget { */
#endif
diff --git a/src/frontend/display/bthtml.js b/src/frontend/display/bthtml.js
index d56318f..79bffde 100644
--- a/src/frontend/display/bthtml.js
+++ b/src/frontend/display/bthtml.js
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
diff --git a/src/frontend/display/bthtmljsobject.cpp b/src/frontend/display/bthtmljsobject.cpp
index cb395cc..b2407e3 100644
--- a/src/frontend/display/bthtmljsobject.cpp
+++ b/src/frontend/display/bthtmljsobject.cpp
@@ -2,15 +2,15 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "frontend/display/bthtmljsobject.h"
+#include <memory>
#include <QDrag>
-#include <QSharedPointer>
#include "backend/config/btconfig.h"
#include "backend/keys/cswordkey.h"
#include "backend/managers/referencemanager.h"
@@ -76,7 +76,7 @@ void BtHtmlJsObject::mouseMoveEvent(const QString& attributes, const int& x, con
// If we have not started dragging, but the mouse button is down, create a the mime data
QPoint current(x, y);
if ((current - m_dndData.startPos).manhattanLength() > 4 /*qApp->startDragDistance()*/ ) {
- QDrag* drag = 0;
+ QDrag* drag = nullptr;
if (!m_dndData.url.isEmpty()) {
// create a new bookmark drag!
QString moduleName = QString::null;
@@ -89,7 +89,7 @@ void BtHtmlJsObject::mouseMoveEvent(const QString& attributes, const int& x, con
drag->setMimeData(mimedata);
//add real Bible text from module/key
if (CSwordModuleInfo *module = CSwordBackend::instance()->findModuleByName(moduleName)) {
- QSharedPointer<CSwordKey> key( CSwordKey::createInstance(module) );
+ std::unique_ptr<CSwordKey> key(CSwordKey::createInstance(module));
key->setKey(keyName);
mimedata->setText(key->strippedText()); // This works across applications!
}
@@ -118,24 +118,9 @@ void BtHtmlJsObject::timeOutEvent(const QString & attributes) {
return;
m_prev_attributes = "";
- CInfoDisplay::ListInfoData infoList;
- const QStringList attrList = attributes.split("||");
- for (int i = 0; i < attrList.count(); i++) {
- const QStringList attr(attrList[i].split('='));
- if (attr.count() == 2) {
- if (attr[0] == "note") {
- infoList.append(qMakePair(CInfoDisplay::Footnote, attr[1]));
- } else if (attr[0] == "lemma") {
- infoList.append(qMakePair(CInfoDisplay::Lemma, attr[1]));
- } else if (attr[0] == "morph") {
- infoList.append(qMakePair(CInfoDisplay::Morph, attr[1]));
- } else if (attr[0] == "expansion") {
- infoList.append(qMakePair(CInfoDisplay::Abbreviation, attr[1]));
- } else if (attr[0] == "crossrefs") {
- infoList.append(qMakePair(CInfoDisplay::CrossReference, attr[1]));
- }
- }
- }
+
+ Rendering::ListInfoData infoList(Rendering::detectInfo(attributes));
+
// Update the mag if valid attributes were found
if (!(infoList.isEmpty()))
BibleTime::instance()->infoDisplay()->setInfo(infoList);
diff --git a/src/frontend/display/bthtmljsobject.h b/src/frontend/display/bthtmljsobject.h
index 3bf37f5..3e34d1d 100644
--- a/src/frontend/display/bthtmljsobject.h
+++ b/src/frontend/display/bthtmljsobject.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
diff --git a/src/frontend/display/bthtmlreaddisplay.cpp b/src/frontend/display/bthtmlreaddisplay.cpp
index 7b303e7..eace51f 100644
--- a/src/frontend/display/bthtmlreaddisplay.cpp
+++ b/src/frontend/display/bthtmlreaddisplay.cpp
@@ -2,16 +2,18 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "frontend/display/bthtmlreaddisplay.h"
-#include <QSharedPointer>
+#include <memory>
#include <QMenu>
+#include <QDebug>
#include <QString>
+#include <QTimer>
#include "backend/keys/cswordkey.h"
#include "backend/managers/referencemanager.h"
#include "bibletime.h"
@@ -20,78 +22,115 @@
#include "frontend/cmdiarea.h"
#include "frontend/display/bthtmljsobject.h"
#include "frontend/displaywindow/cdisplaywindow.h"
-#include "frontend/displaywindow/cdisplaywindowfactory.h"
#include "frontend/displaywindow/creadwindow.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/directory.h"
+#ifdef USEWEBENGINE
+#include <QWebEngineScript>
+#include <QWebEngineScriptCollection>
+#endif
using namespace InfoDisplay;
-static QString javascript; // Initialized from file bthtml.js
+#ifdef USEWEBENGINE
+static QString javascriptFile = "btwebengine.js";
+#else
+static QString javascriptFile = "bthtml.js";
+#endif
+
+static QString s_javascript; // Initialized from javascript file
+
+// This is s work around for Qt bug 51565
+// It is also documented in BibleTime bug #53
+static void clearChildFocusWidget(QWidget * widget) {
+ QWidget * childFocusedWidget = widget->focusWidget();
+ if (childFocusedWidget)
+ childFocusedWidget->clearFocus();
+}
BtHtmlReadDisplay::BtHtmlReadDisplay(CReadWindow* readWindow, QWidget* parentWidget)
- : QWebPage(parentWidget), CReadDisplay(readWindow), m_magTimerId(0), m_view(0), m_jsObject(0)
+ : BtWebEnginePage(parentWidget), CReadDisplay(readWindow), m_magTimerId(0), m_view(nullptr), m_jsObject(nullptr)
{
- settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
m_view = new BtHtmlReadDisplayView(this, parentWidget ? parentWidget : readWindow, readWindow);
m_view->setAcceptDrops(true);
m_view->setPage(this);
setParent(m_view);
m_view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- m_view->setHtml("");
- initJavascript();
- bool ok = connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool)));
- Q_ASSERT(ok);
+ loadJSObject();
+ loadScripts();
+ m_view->setHtml(""); // This sets focus on a child widget
+ clearChildFocusWidget(m_view);
+
+ BT_CONNECT(this, SIGNAL(loadFinished(bool)),
+ this, SLOT(slotLoadFinished(bool)));
}
BtHtmlReadDisplay::~BtHtmlReadDisplay() {
- setView(0);
+ setView(nullptr);
}
-// Read javascript into memory once and create the c++ javascript object
-void BtHtmlReadDisplay::initJavascript() {
+void BtHtmlReadDisplay::loadScripts() {
namespace DU = util::directory;
- // read bthtml.js javascript file once
- if (javascript.isEmpty()) {
- QString jsFile = DU::getJavascriptDir().canonicalPath() + "/bthtml.js";
- QFile file(jsFile);
- if (file.open(QFile::ReadOnly)) {
- while (!file.atEnd()) {
- QByteArray line = file.readLine();
- javascript = javascript + line;
- }
- file.close();
+ QString jScript;
+#ifdef USEWEBENGINE
+ jScript = readJavascript(":/qtwebchannel/qwebchannel.js");
+#endif
+ QString jsFile = DU::getJavascriptDir().canonicalPath() + "/" + javascriptFile;
+ jScript += readJavascript(jsFile);
+
+#ifdef USEWEBENGINE
+ // Directly load javascript into QWebEngine
+ QWebEngineScript script;
+ script.setInjectionPoint(QWebEngineScript::DocumentReady);
+ script.setWorldId(QWebEngineScript::MainWorld);
+ script.setSourceCode(jScript);
+ script.setName("script1");
+ scripts().insert(script);
+#else
+ // Save javascript and load each time the document is loaded (setHtml)
+ s_javascript = jScript;
+#endif
+}
+
+QString BtHtmlReadDisplay::readJavascript(const QString& jsFileName) {
+ QString javascript;
+ QFile file(jsFileName);
+ if (file.open(QFile::ReadOnly)) {
+ while (!file.atEnd()) {
+ QString line = file.readLine();
+ javascript = javascript + line;
}
+ file.close();
+ } else {
+ qWarning() << objectName() << ": Missing " +jsFileName;
}
-
- // Setup BtHtmlJsObject which will be called from javascript
- m_jsObject = new BtHtmlJsObject(this);
- m_jsObject->setObjectName("btHtmlJsObject");
+ return javascript;
}
// When the QWebFrame is cleared, this function is called to install the
-// javascript object (BtHtmlJsObject class) into the Javascript model
+// javascript object (BtHtmlJsObject class) into the Javascript model.
+// It is called only once with QWebEngine.
void BtHtmlReadDisplay::loadJSObject() {
// Starting with Qt 4.7.4 with QtWebKit 2.2 stronger security checking occurs.
// The BtHtmlJsObject that is associated with a given load of a page is rejected
// as causing a cross site security problem when a new page is loaded. Deleting
// the object and creating it new for each page loaded allows the object to access
// javascript variables without this security issue.
- if (m_jsObject != 0)
+ if (m_jsObject != nullptr)
delete m_jsObject;
m_jsObject = new BtHtmlJsObject(this);
- m_jsObject->setObjectName("btHtmlJsObject");
-
- mainFrame()->addToJavaScriptWindowObject(m_jsObject->objectName(), m_jsObject);
+ addJavaScriptObject("btHtmlJsObject", m_jsObject);
}
const QString BtHtmlReadDisplay::text( const CDisplay::TextType format, const CDisplay::TextPart part) {
switch (part) {
case Document: {
if (format == HTMLText) {
- return mainFrame()->toHtml();
+ return getCurrentSource();
}
else {
CDisplayWindow* window = parentWindow();
@@ -100,21 +139,14 @@ const QString BtHtmlReadDisplay::text( const CDisplay::TextType format, const CD
//This is never used for Bibles, so it is not implemented for
//them. If it should be, see CReadDisplay::print() for example
//code.
- Q_ASSERT(module->type() == CSwordModuleInfo::Lexicon ||
+ BT_ASSERT(module->type() == CSwordModuleInfo::Lexicon ||
module->type() == CSwordModuleInfo::Commentary ||
module->type() == CSwordModuleInfo::GenericBook);
if (module->type() == CSwordModuleInfo::Lexicon ||
module->type() == CSwordModuleInfo::Commentary ||
module->type() == CSwordModuleInfo::GenericBook) {
- /// \todo This is a BAD HACK, we have to fnd a better solution to manage the settings now
- FilterOptions filterOptions;
- filterOptions.footnotes = false;
- filterOptions.strongNumbers = false;
- filterOptions.morphTags = false;
- filterOptions.lemmas = false;
- filterOptions.scriptureReferences = false;
- filterOptions.textualVariants = false;
+ FilterOptions filterOptions;
CSwordBackend::instance()->setFilterOptions(filterOptions);
return QString(key->strippedText()).append("\n(")
@@ -154,7 +186,7 @@ const QString BtHtmlReadDisplay::text( const CDisplay::TextType format, const CD
ReferenceManager::decodeHyperlink(activeAnchor(), moduleName, keyName, type);
if (CSwordModuleInfo *module = CSwordBackend::instance()->findModuleByName(moduleName)) {
- QSharedPointer<CSwordKey> key( CSwordKey::createInstance(module) );
+ std::unique_ptr<CSwordKey> key(CSwordKey::createInstance(module));
key->setKey(keyName);
return key->strippedText();
@@ -169,18 +201,10 @@ const QString BtHtmlReadDisplay::text( const CDisplay::TextType format, const CD
ReferenceManager::decodeHyperlink(activeAnchor(), moduleName, keyName, type);
if (CSwordModuleInfo *module = CSwordBackend::instance()->findModuleByName(moduleName)) {
- QSharedPointer<CSwordKey> key( CSwordKey::createInstance(module) );
+ std::unique_ptr<CSwordKey> key(CSwordKey::createInstance(module));
key->setKey(keyName);
- /// \todo This is a BAD HACK, we have to fnd a better solution to manage the settings now
FilterOptions filterOptions;
- filterOptions.footnotes = false;
- filterOptions.strongNumbers = false;
- filterOptions.morphTags = false;
- filterOptions.lemmas = false;
- filterOptions.scriptureReferences = false;
- filterOptions.textualVariants = false;
-
CSwordBackend::instance()->setFilterOptions(filterOptions);
return QString(key->strippedText()).append("\n(")
@@ -201,21 +225,23 @@ const QString BtHtmlReadDisplay::text( const CDisplay::TextType format, const CD
return QString::null;
}
-// Puts html text and javascript into QWebView
+// Puts html text and javascript into BtWebEngineView
void BtHtmlReadDisplay::setText( const QString& newText ) {
-
QString jsText = newText;
+#ifndef USEWEBENGINE
+ // Inject javascript into the document
jsText.replace(
QString("</body>"),
- QString("<script type=\"text/javascript\">").append(javascript).append("</script></body>")
+ QString("<script type=\"text/javascript\">").append(s_javascript).append("</script></body>")
);
// Disconnect any previous connections and connect to slot that loads the javascript object
QWebFrame* frame = mainFrame();
- disconnect(frame, SIGNAL(javaScriptWindowObjectCleared()), 0, 0);
- bool ok = connect(frame, SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(loadJSObject()));
- Q_ASSERT(ok);
+ disconnect(frame, SIGNAL(javaScriptWindowObjectCleared()), nullptr, nullptr);
+ BT_CONNECT(frame, SIGNAL(javaScriptWindowObjectCleared()),
+ this, SLOT(loadJSObject()));
+#endif
// Send text to the html viewer
m_view->setHtml(jsText);
@@ -228,10 +254,8 @@ QString BtHtmlReadDisplay::getCurrentSource( ) {
}
// See if any text is selected
-bool BtHtmlReadDisplay::hasSelection() {
- if (selectedText().isEmpty())
- return false;
- return true;
+bool BtHtmlReadDisplay::hasSelection() const {
+ return !selectedText().isEmpty();
}
// Reimplementation
@@ -242,19 +266,26 @@ QWidget* BtHtmlReadDisplay::view() {
// Select all text in the viewer
void BtHtmlReadDisplay::selectAll() {
- m_view->triggerPageAction( QWebPage::SelectAll, true );
+ BtWebEnginePage::selectAll();
}
-// Scroll QWebView to the correct location as specified by the anchor
+// Scroll BtWebEngineView to the correct location as specified by the anchor
void BtHtmlReadDisplay::moveToAnchor( const QString& anchor ) {
-#if QT_VERSION >= 0x040700
- mainFrame()->scrollToAnchor(anchor);
+#ifdef USEWEBENGINE
+ // Rendering in QWebEngine is asynchronous, must delay before scroll to anchor
+ // TODO - find a better solution
+ m_currentAnchorCache = anchor;
+ QTimer::singleShot(180, this, SLOT(slotDelayedMoveToAnchor()));
#else
- slotGoToAnchor(anchor);
+ mainFrame()->scrollToAnchor(anchor);
#endif
}
-// Scroll the QWebView to the correct location specified by anchor
+void BtHtmlReadDisplay::slotDelayedMoveToAnchor() {
+ m_jsObject->moveToAnchor(m_currentAnchorCache);
+}
+
+// Scroll the BtWebEngineView to the correct location specified by anchor
void BtHtmlReadDisplay::slotGoToAnchor(const QString& anchor) {
m_jsObject->moveToAnchor(anchor);
}
@@ -287,11 +318,11 @@ void BtHtmlReadDisplay::javaScriptConsoleMessage (const QString& message, int li
// ----------------- BtHtmlReadDisplayView -------------------------------------
BtHtmlReadDisplayView::BtHtmlReadDisplayView(BtHtmlReadDisplay* displayWidget, QWidget* parent, CReadWindow* readWindow)
- : QWebView(parent), m_display(displayWidget), m_readWindow(readWindow) {
+ : BtWebEngineView(parent), m_display(displayWidget), m_readWindow(readWindow) {
}
BtHtmlReadDisplayView::~BtHtmlReadDisplayView() {
- setPage(0);
+ setPage(nullptr);
}
// Create the right mouse context menus
@@ -306,9 +337,9 @@ void BtHtmlReadDisplayView::dropEvent( QDropEvent* e ) {
if (e->mimeData()->hasFormat("BibleTime/Bookmark")) {
//see docs for BTMimeData and QMimeData
const QMimeData* mimedata = e->mimeData();
- if (mimedata != 0) {
+ if (mimedata != nullptr) {
const BTMimeData* btmimedata = qobject_cast<const BTMimeData*>(mimedata);
- if (btmimedata != 0) {
+ if (btmimedata != nullptr) {
BookmarkItem item = (qobject_cast<const BTMimeData*>(e->mimeData()))->bookmark();
m_display->connectionsProxy()->emitReferenceDropped(item.key());
e->acceptProposedAction();
@@ -320,28 +351,28 @@ void BtHtmlReadDisplayView::dropEvent( QDropEvent* e ) {
// e->ignore();
}
-// Reimplementation from QWebView
+// Reimplementation from BtWebEngineView
void BtHtmlReadDisplayView::dragEnterEvent( QDragEnterEvent* e ) {
if ( ! e->mimeData()->hasFormat("BibleTime/Bookmark"))
return;
const QMimeData* mimedata = e->mimeData();
- if (mimedata == 0)
+ if (mimedata == nullptr)
return;
const BTMimeData* btmimedata = qobject_cast<const BTMimeData*>(mimedata);
- if (btmimedata == 0)
+ if (btmimedata == nullptr)
return;
BookmarkItem item = (qobject_cast<const BTMimeData*>(e->mimeData()))->bookmark();
QString moduleName = item.module();
CSwordModuleInfo *m = CSwordBackend::instance()->findModuleByName(moduleName);
- Q_ASSERT(m);
- if (m == 0)
- return;
+ BT_ASSERT(m);
CSwordModuleInfo::ModuleType bookmarkType = m->type();
- CSwordModuleInfo::ModuleType windowType = CDisplayWindowFactory::getModuleType(m_readWindow);
+ CSwordModuleInfo::ModuleType windowType = CSwordModuleInfo::Unknown;
+ if (m_readWindow)
+ windowType = m_readWindow->moduleType();
// Is bible reference bookmark compatible with the window type?
if ((bookmarkType == CSwordModuleInfo::Bible ||
@@ -349,19 +380,25 @@ void BtHtmlReadDisplayView::dragEnterEvent( QDragEnterEvent* e ) {
if (windowType == CSwordModuleInfo::Bible ||
windowType == CSwordModuleInfo::Commentary)
e->acceptProposedAction();
+#ifdef USEWEBENGINE
+ BtWebEngineView::dragEnterEvent(e); // Fix crash, QTBUG-54896, BT bug #70
+#endif
return;
}
// Is reference type compatible with window type
if (bookmarkType == windowType) {
e->acceptProposedAction();
+#ifdef USEWEBENGINE
+ BtWebEngineView::dragEnterEvent(e); // Fix crash, QTBUG-54896, BT bug #70
+#endif
return;
}
return;
}
-// Reimplementation from QWebView
+// Reimplementation from BtWebEngineView
void BtHtmlReadDisplayView::dragMoveEvent( QDragMoveEvent* e ) {
if (e->mimeData()->hasFormat("BibleTime/Bookmark")) {
e->acceptProposedAction();
diff --git a/src/frontend/display/bthtmlreaddisplay.h b/src/frontend/display/bthtmlreaddisplay.h
index 0a703d3..21fcd67 100644
--- a/src/frontend/display/bthtmlreaddisplay.h
+++ b/src/frontend/display/bthtmlreaddisplay.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,15 +12,14 @@
#ifndef BTHTMLREADDISPLAY_H
#define BTHTMLREADDISPLAY_H
+#include "frontend/btwebengineview.h"
+#include "frontend/btwebenginepage.h"
#include "frontend/display/creaddisplay.h"
-#include <QWebPage>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QPoint>
#include <QTimerEvent>
-#include <QWebView>
-#include <QWebFrame>
#include "frontend/display/bthtmljsobject.h"
@@ -29,36 +28,35 @@ class BtHtmlReadDisplayView;
/** The implementation for the HTML read display.
* @author The BibleTime team
*/
-class BtHtmlReadDisplay : public QWebPage, public CReadDisplay {
+class BtHtmlReadDisplay : public BtWebEnginePage, public CReadDisplay {
Q_OBJECT
friend class BtHtmlReadDisplayView;
public:
- BtHtmlReadDisplay( CReadWindow* readWindow, QWidget* parent = 0 );
- virtual ~BtHtmlReadDisplay();
+ BtHtmlReadDisplay( CReadWindow* readWindow, QWidget* parent = nullptr );
+ ~BtHtmlReadDisplay() override;
//reimplemented functions from CDisplay
// Returns the right text part in the specified format.
- virtual const QString text( const CDisplay::TextType format = CDisplay::HTMLText,
- const CDisplay::TextPart part = CDisplay::Document );
+ const QString text(const CDisplay::TextType format = CDisplay::HTMLText,
+ const CDisplay::TextPart part = CDisplay::Document)
+ override;
- // Sets the new text for this display widget.
- virtual void setText( const QString& newText );
- // Get the current source
- virtual QString getCurrentSource();
+ void setText( const QString& newText ) override;
- virtual bool hasSelection();
+ QString getCurrentSource();
- // Reimplementation.
- virtual void selectAll();
- virtual void moveToAnchor( const QString& anchor );
- virtual void openFindTextDialog();
- inline virtual QString getCurrentNodeInfo() const {
+ bool hasSelection() const override;
+
+ void selectAll() override;
+ void moveToAnchor( const QString& anchor ) override;
+ void openFindTextDialog() override;
+ inline QString getCurrentNodeInfo() const override {
return m_nodeInfo;
}
- QWidget* view();
+ QWidget* view() override;
void setLemma(const QString& lemma);
public slots:
@@ -94,8 +92,14 @@ class BtHtmlReadDisplay : public QWebPage, public CReadDisplay {
void javaScriptConsoleMessage (const QString & message, int lineNumber, const QString & sourceID );
#endif
+ private slots:
+ void slotDelayedMoveToAnchor();
+
private:
void initJavascript();
+ void loadScripts();
+ QString readJavascript(const QString& jsFileName);
+
BtHtmlReadDisplayView* m_view;
BtHtmlJsObject* m_jsObject;
QString m_currentAnchorCache;
@@ -103,21 +107,21 @@ class BtHtmlReadDisplay : public QWebPage, public CReadDisplay {
};
-class BtHtmlReadDisplayView : public QWebView {
+class BtHtmlReadDisplayView : public BtWebEngineView {
Q_OBJECT
protected:
friend class BtHtmlReadDisplay;
- void contextMenuEvent(QContextMenuEvent* event);
+ void contextMenuEvent(QContextMenuEvent* event) override;
BtHtmlReadDisplayView(BtHtmlReadDisplay* display, QWidget* parent, CReadWindow* readWindow);
~BtHtmlReadDisplayView();
- bool event(QEvent* e);
+ bool event(QEvent* e) override;
private:
BtHtmlReadDisplay* m_display;
CReadWindow* m_readWindow;
- void dropEvent( QDropEvent* e );
- void dragEnterEvent( QDragEnterEvent* e );
- void dragMoveEvent( QDragMoveEvent* e );
+ void dropEvent( QDropEvent* e ) override;
+ void dragEnterEvent( QDragEnterEvent* e ) override;
+ void dragMoveEvent( QDragMoveEvent* e ) override;
};
#endif
diff --git a/src/frontend/display/btwebengine.js b/src/frontend/display/btwebengine.js
new file mode 100644
index 0000000..f0bdfb3
--- /dev/null
+++ b/src/frontend/display/btwebengine.js
@@ -0,0 +1,140 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+var X = 0;
+var Y = 0;
+var attribs = [];
+var eventType = "";
+var prevNode = 0;
+var currentNode = 0;
+var timeOutId = -1;
+
+// Scroll window to html anchor
+function gotoAnchor(anchor)
+{
+ document.location=document.location + "#" + anchor;
+}
+
+// Mouse button clicked handler
+function mouseClickHandler (mEvent)
+{
+ var mTarget = mEvent.target;
+ if (mTarget)
+ {
+ var url = "";
+ var tmpUrl = mEvent.target.getAttribute("href");
+ if (tmpUrl)
+ url = tmpUrl;
+ btHtmlJsObject.mouseClick(url);
+ }
+}
+
+// Mouse button pressed down handler
+function mouseDownHandler (mEvent)
+{
+ var node;
+ var url = "";
+ var lemma = "";
+ var mTarget = mEvent.target;
+ if (mTarget)
+ {
+ var tmpUrl = mEvent.target.getAttribute("href");
+ if (tmpUrl)
+ url = tmpUrl;
+ var tmpLemma = mEvent.target.getAttribute("lemma");
+ if (tmpLemma)
+ lemma = tmpLemma;
+ }
+
+ if (mEvent.button === 2) // Right mouse button
+ {
+ btHtmlJsObject.mouseDownRight(url, lemma);
+ }
+ if (mEvent.button === 0) // Left mouse button
+ {
+ if (!(mEvent.target === undefined))
+ {
+ var X = mEvent.clientX;
+ var Y = mEvent.clientY;
+ btHtmlJsObject.mouseDownLeft(url, X, Y);
+ }
+ }
+}
+
+// Mouse moved event handler
+function mouseMoveHandler (mEvent)
+{
+ currentNode = mEvent.target;
+ var shiftKey = mEvent.shiftKey;
+ var x = mEvent.clientX;
+ var y = mEvent.clientY;
+ var node = mEvent.target;
+ if ( node != undefined && node != prevNode )
+ {
+ prevNode = node;
+ var attribList;
+ if (node.attributes.length > 0)
+ {
+ attribList = getNodeAttributes(node);
+ btHtmlJsObject.mouseMoveEvent(attribList, x, y, shiftKey);
+ }
+ }
+}
+
+// Get attributes of a DOM node and put into a single string
+function getNodeAttributes(node)
+{
+ var attribList = '';
+ if (node.attributes.length > 0)
+ {
+ var i;
+ for (i = 0; i < node.attributes.length; i++)
+ {
+ attribList = attribList + node.attributes[i].nodeName + '=' + node.attributes[i].value + '||';
+ }
+ }
+ return attribList;
+}
+
+// Start a timer event
+function startTimer(time)
+{
+ clearTimeout(timeOutId);
+ timeOutId = setTimeout("timerEvent()",time);
+}
+
+// Handles a timer event
+function timerEvent()
+{
+ timeOutId = -1;
+ if (currentNode != 0 && currentNode == prevNode)
+ {
+ var attributes = getNodeAttributes(currentNode);
+ btHtmlJsObject.timeOutEvent(attributes);
+ }
+}
+
+function selectAll () {
+ console.log("select all");
+}
+
+document.getElementsByTagName("body")[0].addEventListener ('mousedown', function (eve) { mouseDownHandler (eve); }, true);
+document.getElementsByTagName("body")[0].addEventListener ('mousemove', function (eve) { mouseMoveHandler (eve); }, true);
+document.getElementsByTagName("body")[0].addEventListener ('click', function (eve) { mouseClickHandler (eve); }, true);
+
+var btHtmlJsObject = 0;
+
+new QWebChannel(qt.webChannelTransport, function (channel) {
+ btHtmlJsObject = channel.objects.btHtmlJsObject;
+ btHtmlJsObject.startTimer.connect(startTimer);
+ btHtmlJsObject.gotoAnchor.connect(gotoAnchor);
+ btHtmlJsObject.selectAll.connect(selectAll);
+ });
+
+
diff --git a/src/frontend/display/cdisplay.cpp b/src/frontend/display/cdisplay.cpp
index a5c5bc8..b53d080 100644
--- a/src/frontend/display/cdisplay.cpp
+++ b/src/frontend/display/cdisplay.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -102,7 +102,7 @@ void CDisplayConnections::openFindTextDialog() {
CDisplay::CDisplay(CDisplayWindow* parent) :
m_parentWindow(parent),
m_connections( new CDisplayConnections( this ) ),
- m_popup(0) {}
+ m_popup(nullptr) {}
CDisplay::~CDisplay() {
delete m_connections;
@@ -127,7 +127,7 @@ bool CDisplay::save( const CDisplay::TextType format, const CDisplay::TextPart p
break;
}
- const QString filename = QFileDialog::getSaveFileName(0, QObject::tr("Save document ..."), "", filter);
+ const QString filename = QFileDialog::getSaveFileName(nullptr, QObject::tr("Save document ..."), "", filter);
if (!filename.isEmpty()) {
util::tool::savePlainFile(filename, content);
diff --git a/src/frontend/display/cdisplay.h b/src/frontend/display/cdisplay.h
index de971d5..6650322 100644
--- a/src/frontend/display/cdisplay.h
+++ b/src/frontend/display/cdisplay.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -61,7 +61,7 @@ class CDisplay {
/**
* Returns true if the display widget has a selection. Otherwise false.
*/
- virtual bool hasSelection() = 0;
+ virtual bool hasSelection() const = 0;
/**
* Returns the view of this display widget.
*/
@@ -157,10 +157,6 @@ class CDisplayConnections : public QObject {
private:
CDisplay* m_display;
- struct {
- QString module;
- QString key;
- } m_referenceClickedCache;
};
#endif
diff --git a/src/frontend/display/chtmlwritedisplay.cpp b/src/frontend/display/chtmlwritedisplay.cpp
index 829f607..709f10f 100644
--- a/src/frontend/display/chtmlwritedisplay.cpp
+++ b/src/frontend/display/chtmlwritedisplay.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -20,8 +20,9 @@
#include "frontend/display/btfontsizewidget.h"
#include "frontend/displaywindow/btactioncollection.h"
#include "frontend/displaywindow/chtmlwritewindow.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
class BtActionCollection;
@@ -44,76 +45,83 @@ CHTMLWriteDisplay::CHTMLWriteDisplay(CHTMLWriteWindow * parentWindow, QWidget* p
//--------------------bold toggle-------------------------
m_actions.bold = new QAction(
- util::getIcon(CResMgr::displaywindows::writeWindow::boldText::icon),
+ CResMgr::displaywindows::writeWindow::boldText::icon(),
tr("Bold"),
this);
m_actions.bold->setCheckable(true);
m_actions.bold->setChecked(f.bold());
m_actions.bold->setShortcut(CResMgr::displaywindows::writeWindow::boldText::accel);
m_actions.bold->setToolTip( tr("Bold") );
- connect(m_actions.bold, SIGNAL(toggled(bool)),
- this, SLOT(toggleBold(bool)), Qt::DirectConnection);
+ BT_CONNECT(m_actions.bold, SIGNAL(toggled(bool)),
+ this, SLOT(toggleBold(bool)),
+ Qt::DirectConnection);
//--------------------italic toggle-------------------------
m_actions.italic = new QAction(
- util::getIcon(CResMgr::displaywindows::writeWindow::italicText::icon),
+ CResMgr::displaywindows::writeWindow::italicText::icon(),
tr("Italic"),
this );
m_actions.italic->setCheckable(true);
m_actions.italic->setChecked(f.italic());
m_actions.bold->setShortcut(CResMgr::displaywindows::writeWindow::italicText::accel);
- connect(m_actions.italic, SIGNAL(toggled(bool)),
- this, SLOT(toggleItalic(bool)), Qt::DirectConnection);
+ BT_CONNECT(m_actions.italic, SIGNAL(toggled(bool)),
+ this, SLOT(toggleItalic(bool)),
+ Qt::DirectConnection);
m_actions.italic->setToolTip( tr("Italic") );
//--------------------underline toggle-------------------------
m_actions.underline = new QAction(
- util::getIcon(CResMgr::displaywindows::writeWindow::underlinedText::icon),
+ CResMgr::displaywindows::writeWindow::underlinedText::icon(),
tr("Underline"),
this );
m_actions.underline->setCheckable(true);
m_actions.underline->setChecked(f.underline());
m_actions.underline->setShortcut(CResMgr::displaywindows::writeWindow::underlinedText::accel);
- connect(m_actions.underline, SIGNAL(toggled(bool)),
- this, SLOT(toggleUnderline(bool)), Qt::DirectConnection);
+ BT_CONNECT(m_actions.underline, SIGNAL(toggled(bool)),
+ this, SLOT(toggleUnderline(bool)),
+ Qt::DirectConnection);
m_actions.underline->setToolTip( tr("Underline") );
//--------------------align left toggle-------------------------
m_actions.alignLeft = new QAction(
- util::getIcon(CResMgr::displaywindows::writeWindow::alignLeft::icon),
+ CResMgr::displaywindows::writeWindow::alignLeft::icon(),
tr("Left"), this);
m_actions.alignLeft->setCheckable(true);
m_actions.alignLeft->setShortcut(CResMgr::displaywindows::writeWindow::alignLeft::accel);
- connect(m_actions.alignLeft, SIGNAL(toggled(bool)),
- this, SLOT(alignLeft(bool)), Qt::DirectConnection);
+ BT_CONNECT(m_actions.alignLeft, SIGNAL(toggled(bool)),
+ this, SLOT(alignLeft(bool)),
+ Qt::DirectConnection);
m_actions.alignLeft->setToolTip( tr("Align left") );
//--------------------align center toggle-------------------------
m_actions.alignCenter = new QAction(
- util::getIcon(CResMgr::displaywindows::writeWindow::alignCenter::icon),
+ CResMgr::displaywindows::writeWindow::alignCenter::icon(),
tr("Center"), this);
m_actions.alignCenter->setCheckable(true);
m_actions.alignCenter->setShortcut(CResMgr::displaywindows::writeWindow::alignCenter::accel);
- connect(m_actions.alignCenter, SIGNAL(toggled(bool)),
- this, SLOT(alignCenter(bool)), Qt::DirectConnection);
+ BT_CONNECT(m_actions.alignCenter, SIGNAL(toggled(bool)),
+ this, SLOT(alignCenter(bool)),
+ Qt::DirectConnection);
m_actions.alignCenter->setToolTip( tr("Center") );
//--------------------align right toggle-------------------------
m_actions.alignRight = new QAction(
- util::getIcon(CResMgr::displaywindows::writeWindow::alignRight::icon),
+ CResMgr::displaywindows::writeWindow::alignRight::icon(),
tr("Right"), this);
m_actions.alignRight->setCheckable(true);
m_actions.alignRight->setShortcut(CResMgr::displaywindows::writeWindow::alignRight::accel);
- connect(m_actions.alignRight, SIGNAL(toggled(bool)),
- this, SLOT(alignRight(bool)), Qt::DirectConnection);
+ BT_CONNECT(m_actions.alignRight, SIGNAL(toggled(bool)),
+ this, SLOT(alignRight(bool)),
+ Qt::DirectConnection);
m_actions.alignRight->setToolTip( tr("Align right") );
setAcceptRichText(true);
setAcceptDrops(true);
viewport()->setAcceptDrops(true);
- connect(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
- this, SLOT(slotCurrentCharFormatChanged(QTextCharFormat)), Qt::DirectConnection);
+ BT_CONNECT(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
+ this, SLOT(slotCurrentCharFormatChanged(QTextCharFormat)),
+ Qt::DirectConnection);
}
void CHTMLWriteDisplay::setText(const QString & newText) {
@@ -162,7 +170,7 @@ void CHTMLWriteDisplay::alignRight(bool set) {
/** The text's alignment changed. Enable the right buttons. */
void CHTMLWriteDisplay::alignmentChanged( int a ) {
- Q_ASSERT(!m_handingFormatChangeFromEditor);
+ BT_ASSERT(!m_handingFormatChangeFromEditor);
bool alignLeft = false;
bool alignCenter = false;
bool alignRight = false;
@@ -187,7 +195,7 @@ void CHTMLWriteDisplay::alignmentChanged( int a ) {
}
void CHTMLWriteDisplay::slotCurrentCharFormatChanged(const QTextCharFormat &) {
- Q_ASSERT(!m_handingFormatChangeFromEditor);
+ BT_ASSERT(!m_handingFormatChangeFromEditor);
m_handingFormatChangeFromEditor = true;
QFont f = currentFont();
emit signalFontChanged(f);
@@ -206,13 +214,7 @@ void CHTMLWriteDisplay::slotCurrentCharFormatChanged(const QTextCharFormat &) {
void CHTMLWriteDisplay::slotFontSizeChosen(int newSize) {
if (!m_handingFormatChangeFromEditor)
- setFontPointSize((qreal)newSize);
-}
-
-/** Is called when a new color was selected. */
-void CHTMLWriteDisplay::slotFontColorChosen( const QColor& c) {
- if (!m_handingFormatChangeFromEditor)
- setTextColor( c );
+ setFontPointSize(static_cast<qreal>(newSize));
}
void CHTMLWriteDisplay::slotFontFamilyChosen(const QFont& font) {
@@ -230,36 +232,34 @@ void CHTMLWriteDisplay::setupToolbar(QToolBar * bar, BtActionCollection * action
fontFamilyCombo->setCurrentFont(f);
fontFamilyCombo->setToolTip( tr("Font") );
bar->addWidget(fontFamilyCombo);
- bool ok = connect(fontFamilyCombo, SIGNAL(currentFontChanged(const QFont&)),
- this, SLOT(slotFontFamilyChosen(const QFont&)), Qt::DirectConnection);
- Q_ASSERT(ok);
- ok = connect(this, SIGNAL(signalFontChanged(const QFont&)),
- fontFamilyCombo, SLOT(setCurrentFont(const QFont&)), Qt::DirectConnection);
- Q_ASSERT(ok);
+ BT_CONNECT(fontFamilyCombo, SIGNAL(currentFontChanged(QFont const &)),
+ this, SLOT(slotFontFamilyChosen(QFont const &)),
+ Qt::DirectConnection);
+ BT_CONNECT(this, SIGNAL(signalFontChanged(QFont const &)),
+ fontFamilyCombo, SLOT(setCurrentFont(QFont const &)),
+ Qt::DirectConnection);
//--------------------font size chooser-------------------------
BtFontSizeWidget* fontSizeChooser = new BtFontSizeWidget(this);
fontSizeChooser->setFontSize(f.pointSize());
fontSizeChooser->setToolTip( tr("Font size") );
bar->addWidget(fontSizeChooser);
- ok = connect(fontSizeChooser, SIGNAL(fontSizeChanged(int)),
- this, SLOT(slotFontSizeChosen(int)), Qt::DirectConnection);
- Q_ASSERT(ok);
- ok = connect(this, SIGNAL(signalFontSizeChanged(int)),
- fontSizeChooser, SLOT(setFontSize(int)), Qt::DirectConnection);
- Q_ASSERT(ok);
+ BT_CONNECT(fontSizeChooser, SIGNAL(fontSizeChanged(int)),
+ this, SLOT(slotFontSizeChosen(int)),
+ Qt::DirectConnection);
+ BT_CONNECT(this, SIGNAL(signalFontSizeChanged(int)),
+ fontSizeChooser, SLOT(setFontSize(int)), Qt::DirectConnection);
//--------------------color button-------------------------
BtColorWidget* fontColorChooser = new BtColorWidget();
fontColorChooser->setColor(textColor());
fontColorChooser->setToolTip(tr("Font color"));
bar->addWidget(fontColorChooser);
- ok = connect(fontColorChooser, SIGNAL(changed(const QColor&)),
- this, SLOT(slotFontColorChosen(const QColor&)), Qt::DirectConnection);
- Q_ASSERT(ok);
- ok = connect(this, SIGNAL(signalFontColorChanged(const QColor&)),
- fontColorChooser, SLOT(setColor(QColor)), Qt::DirectConnection);
- Q_ASSERT(ok);
+ BT_CONNECT(fontColorChooser, SIGNAL(changed(QColor const &)),
+ this, SLOT(setTextColor(QColor const &)),
+ Qt::DirectConnection);
+ BT_CONNECT(this, SIGNAL(signalFontColorChanged(QColor const &)),
+ fontColorChooser, SLOT(setColor(QColor)), Qt::DirectConnection);
bar->addSeparator();
diff --git a/src/frontend/display/chtmlwritedisplay.h b/src/frontend/display/chtmlwritedisplay.h
index 1bc9dd0..f94516d 100644
--- a/src/frontend/display/chtmlwritedisplay.h
+++ b/src/frontend/display/chtmlwritedisplay.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -32,22 +32,13 @@ class CHTMLWriteDisplay : public CPlainWriteDisplay {
Q_OBJECT
public:
- CHTMLWriteDisplay(CHTMLWriteWindow * parentWindow, QWidget * parent = 0);
+ CHTMLWriteDisplay(CHTMLWriteWindow * parentWindow, QWidget * parent = nullptr);
- /**
- * Sets the new text for this display widget. (CPlainWriteDisplay).
- */
- virtual void setText( const QString& newText );
- /**
- * Returns the text of this edit widget. (CPlainWriteDisplay).
- */
- virtual const QString plainText();
+ void setText( const QString& newText ) override;
- /**
- * Creates the necessary action objects and puts them on the toolbar.
- * (CPlainWriteDisplay)
- */
- virtual void setupToolbar(QToolBar * bar, BtActionCollection * actionCollection);
+ const QString plainText() override;
+
+ void setupToolbar(QToolBar * bar, BtActionCollection * actionCollection) override;
protected:
@@ -64,7 +55,6 @@ class CHTMLWriteDisplay : public CPlainWriteDisplay {
void slotFontFamilyChosen(const QFont&);
void slotFontSizeChosen(int);
- void slotFontColorChosen( const QColor& );
void slotCurrentCharFormatChanged(const QTextCharFormat &);
diff --git a/src/frontend/display/cplainwritedisplay.cpp b/src/frontend/display/cplainwritedisplay.cpp
index e4b22d5..5d04067 100644
--- a/src/frontend/display/cplainwritedisplay.cpp
+++ b/src/frontend/display/cplainwritedisplay.cpp
@@ -2,24 +2,24 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "frontend/display/cplainwritedisplay.h"
-#include <QSharedPointer>
+#include <memory>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QMenu>
-
#include "backend/keys/cswordkey.h"
#include "frontend/cdragdrop.h"
#include "frontend/displaywindow/btactioncollection.h"
#include "frontend/displaywindow/cdisplaywindow.h"
#include "frontend/displaywindow/cplainwritewindow.h"
+#include "util/btconnect.h"
CPlainWriteDisplay::CPlainWriteDisplay(CPlainWriteWindow * parentWindow, QWidget * parent)
@@ -30,8 +30,8 @@ CPlainWriteDisplay::CPlainWriteDisplay(CPlainWriteWindow * parentWindow, QWidget
setAcceptDrops(true);
viewport()->setAcceptDrops(true);
- connect(this, SIGNAL(textChanged()),
- connectionsProxy(), SLOT(emitTextChanged()));
+ BT_CONNECT(this, SIGNAL(textChanged()),
+ connectionsProxy(), SLOT(emitTextChanged()));
}
/** Reimplementation. */
@@ -48,7 +48,7 @@ void CPlainWriteDisplay::setText( const QString& newText ) {
QTextEdit::setText(text);
}
-bool CPlainWriteDisplay::hasSelection() {
+bool CPlainWriteDisplay::hasSelection() const {
/// \todo test this
return textCursor().hasSelection();
}
@@ -123,7 +123,7 @@ void CPlainWriteDisplay::dropEvent( QDropEvent* e ) {
for (it = items.begin(); it != items.end(); ++it) {
CSwordModuleInfo *module = CSwordBackend::instance()->findModuleByName((*it).module());
- QSharedPointer<CSwordKey> key( CSwordKey::createInstance(module) );
+ std::unique_ptr<CSwordKey> key(CSwordKey::createInstance(module));
key->setKey((*it).key());
QString moduleText = key->strippedText();
diff --git a/src/frontend/display/cplainwritedisplay.h b/src/frontend/display/cplainwritedisplay.h
index dad57a1..8ff095b 100644
--- a/src/frontend/display/cplainwritedisplay.h
+++ b/src/frontend/display/cplainwritedisplay.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -26,32 +26,23 @@ class QToolBar;
class CPlainWriteDisplay : public QTextEdit, public CDisplay {
public:
- CPlainWriteDisplay(CPlainWriteWindow * parentWindow, QWidget * parent = 0);
+ CPlainWriteDisplay(CPlainWriteWindow * parentWindow, QWidget * parent = nullptr);
- /**
- * Reimplementation.
- */
- virtual void selectAll();
- /**
- * Sets the new text for this display widget.
- */
- virtual void setText( const QString& newText );
- /**
- * Returns true if the display widget has a selection. Otherwise false.
- */
- virtual bool hasSelection();
- /**
- * Returns the view of this display widget.
- */
- virtual QWidget* view();
- virtual const QString text( const CDisplay::TextType format = CDisplay::HTMLText, const CDisplay::TextPart part = CDisplay::Document );
+ void selectAll() override;
- /**
- Reimplemented from CDisplay.
- */
- virtual inline void print(const CDisplay::TextPart,
- const DisplayOptions &,
- const FilterOptions &) {}
+ void setText(const QString & newText) override;
+
+ bool hasSelection() const override;
+
+ QWidget* view() override;
+
+ const QString text(const CDisplay::TextType format = CDisplay::HTMLText,
+ const CDisplay::TextPart part = CDisplay::Document )
+ override;
+
+ inline void print(const CDisplay::TextPart,
+ const DisplayOptions &,
+ const FilterOptions &) override {}
virtual bool isModified() const;
/**
@@ -69,18 +60,11 @@ class CPlainWriteDisplay : public QTextEdit, public CDisplay {
protected:
- /**
- * Reimplementation from QTextEdit to manage drops of our drag and drop objects.
- */
- virtual void dropEvent( QDropEvent* e );
- /**
- * Reimplementation from QTextEdit to insert the text of a dragged reference into the edit view.
- */
- virtual void dragEnterEvent( QDragEnterEvent* e );
- /**
- * Reimplementation from QTextEdit to insert the text of a dragged reference into the edit view.
- */
- virtual void dragMoveEvent( QDragMoveEvent* e );
+ void dropEvent(QDropEvent * e) override;
+
+ void dragEnterEvent(QDragEnterEvent * e) override;
+
+ void dragMoveEvent(QDragMoveEvent * e) override;
};
diff --git a/src/frontend/display/creaddisplay.cpp b/src/frontend/display/creaddisplay.cpp
index f5c3459..cf4374c 100644
--- a/src/frontend/display/creaddisplay.cpp
+++ b/src/frontend/display/creaddisplay.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -28,7 +28,7 @@ CReadDisplay::CReadDisplay(CReadWindow* readWindow) :
m_useMouseTracking(true) {}
/** Returns the current active anchor. */
-const QString& CReadDisplay::activeAnchor() {
+const QString& CReadDisplay::activeAnchor() const {
return m_activeAnchor;
}
@@ -39,7 +39,7 @@ void CReadDisplay::setActiveAnchor( const QString& anchor ) {
/** Returns true if the display has an active anchor. */
-bool CReadDisplay::hasActiveAnchor() {
+bool CReadDisplay::hasActiveAnchor() const {
return !activeAnchor().isEmpty();
}
@@ -48,7 +48,7 @@ void CReadDisplay::print(const CDisplay::TextPart type,
const DisplayOptions &displayOptions,
const FilterOptions &filterOptions)
{
- typedef CSwordBibleModuleInfo CSBiMI;
+ using CSBiMI = CSwordBibleModuleInfo;
CDisplayWindow* window = parentWindow();
CSwordKey* const key = window->key();
const CSwordModuleInfo *module = key->module();
diff --git a/src/frontend/display/creaddisplay.h b/src/frontend/display/creaddisplay.h
index dd25a76..4ae0ec6 100644
--- a/src/frontend/display/creaddisplay.h
+++ b/src/frontend/display/creaddisplay.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -28,19 +28,19 @@ class CReadDisplay : public CDisplay {
/**
* Returns true if the display has an active anchor.
*/
- bool hasActiveAnchor();
+ bool hasActiveAnchor() const;
/**
* Returns the current active anchor.
*/
- const QString& activeAnchor();
+ QString const & activeAnchor() const;
/**
* Moves the widget to the given anchor.
*/
virtual void moveToAnchor( const QString& ) = 0;
- virtual void print(const CDisplay::TextPart,
- const DisplayOptions &displayOptions,
- const FilterOptions &filterOptions);
+ void print(const CDisplay::TextPart,
+ const DisplayOptions &displayOptions,
+ const FilterOptions &filterOptions) override;
void setMouseTracking(const bool trackingEnabled) {
m_useMouseTracking = trackingEnabled;
diff --git a/src/frontend/displaywindow/btactioncollection.cpp b/src/frontend/displaywindow/btactioncollection.cpp
index f25b972..b150e8c 100644
--- a/src/frontend/displaywindow/btactioncollection.cpp
+++ b/src/frontend/displaywindow/btactioncollection.cpp
@@ -2,110 +2,85 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "frontend/displaywindow/btactioncollection.h"
-#include <QAction>
-#include <QDebug>
-#include <QKeySequence>
-#include <QString>
-#include <QStringList>
+#include "util/btconnect.h"
#include "util/directory.h"
-class BtActionItem: public QObject {
-
- public: /* Methods: */
-
- BtActionItem(QAction *action, QObject *parent = 0)
- : QObject(parent), defaultKeys(action->shortcut()), action(action)
- {
- // Intentionally empty
- }
-
- public: /* Fields: */
-
- QKeySequence defaultKeys;
- QAction* action;
-
-};
+QAction & BtActionCollection::action(QString const & name) const {
+ Item const * const foundItem = findActionItem(name);
+ BT_ASSERT(foundItem);
+ return *(foundItem->m_action);
+}
-QList<QAction*> BtActionCollection::actions() {
- QList<QAction*> actionList;
- for (ActionMap::const_iterator iter = m_actions.constBegin();
- iter != m_actions.constEnd();
- ++iter)
- {
- actionList.append(iter.value()->action);
+void BtActionCollection::addAction(QString const & name,
+ QAction * const action)
+{
+ BT_ASSERT(action);
+ BT_ASSERT(m_actions.find(name) == m_actions.end());
+ Item * const item = new Item{action, this};
+ try {
+ m_actions.insert(name, item);
+ } catch (...) {
+ delete item;
+ throw;
}
- return actionList;
}
-QAction *BtActionCollection::action(const QString &name) const {
- ActionMap::const_iterator it = m_actions.find(name);
- if (it != m_actions.constEnd())
- return (*it)->action;
-
- qWarning() << "A QAction for a shortcut named" << name << "was requested but it is not defined.";
- return 0;
+void BtActionCollection::addAction(QString const & name,
+ QObject const * const receiver,
+ char const * const member)
+{
+ QAction * const action = new QAction{name, this};
+ try {
+ if (receiver && member)
+ BT_CONNECT(action, SIGNAL(triggered()),
+ receiver, SLOT(triggered()));
+ return addAction(name, action);
+ } catch (...) {
+ delete action;
+ throw;
+ }
}
-QAction* BtActionCollection::addAction(const QString& name, QAction* action) {
- Q_ASSERT(action != 0);
- ActionMap::iterator it = m_actions.find(name);
- if (it != m_actions.constEnd())
- delete *it;
-
- m_actions.insert(name, new BtActionItem(action, this));
- return action;
+void BtActionCollection::removeAction(QString const & name) {
+ #ifndef NDEBUG
+ int const r =
+ #endif
+ m_actions.remove(name);
+ BT_ASSERT(r > 0);
}
-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) const {
+ for (Item * const item : m_actions)
+ if (item->m_action == action)
+ return item->m_defaultKeys;
+ return QKeySequence{};
}
-QKeySequence BtActionCollection::getDefaultShortcut(QAction* action) {
- for (ActionMap::const_iterator iter = m_actions.constBegin();
- iter != m_actions.constEnd();
- ++iter)
- {
- if (iter.value()->action == action) {
- return iter.value()->defaultKeys;
- }
- }
- return QKeySequence();
+void BtActionCollection::readShortcuts(QString const & group) {
+ BtConfig::ShortcutsMap shortcuts = btConfig().getShortcuts(group);
+ for (auto it = shortcuts.begin(); it != shortcuts.end(); ++it)
+ if (Item const * const foundItem = findActionItem(it.key()))
+ foundItem->m_action->setShortcuts(it.value());
}
-void BtActionCollection::readShortcuts(const QString &group) {
- QHash<QString, QList <QKeySequence > > shortcuts = btConfig().getShortcuts(group);
- for(QHash<QString, QList <QKeySequence> >::const_iterator iter = shortcuts.begin();
- iter != shortcuts.end();
- ++iter)
- {
- QAction *a = action(iter.key());
- if (a == 0)
- continue;
- action(iter.key())->setShortcuts(iter.value());
- }
+void BtActionCollection::writeShortcuts(QString const & group) const {
+ BtConfig::ShortcutsMap shortcuts;
+ for (auto it = m_actions.begin(); it != m_actions.end(); ++it)
+ shortcuts.insert(it.key(), it.value()->m_action->shortcuts());
+ btConfig().setShortcuts(group, shortcuts);
}
-void BtActionCollection::writeShortcuts(const QString &group) {
- QHash< QString, QList<QKeySequence> > shortcuts;
- for (ActionMap::const_iterator iter = m_actions.constBegin();
- iter != m_actions.constEnd();
- ++iter)
- {
- shortcuts.insert(iter.key(), iter.value()->action->shortcuts());
- }
- btConfig().setShortcuts(group, shortcuts);
+BtActionCollection::Item * BtActionCollection::findActionItem(
+ QString const & name) const
+{
+ ActionMap::const_iterator const it = m_actions.find(name);
+ return (it != m_actions.constEnd()) ? *it : nullptr;
}
diff --git a/src/frontend/displaywindow/btactioncollection.h b/src/frontend/displaywindow/btactioncollection.h
index a4d062f..a5f2fc8 100644
--- a/src/frontend/displaywindow/btactioncollection.h
+++ b/src/frontend/displaywindow/btactioncollection.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -14,61 +14,97 @@
#include <QObject>
-#include <QList>
+#include <QAction>
+#include <QKeySequence>
#include <QMap>
-
+#include <QString>
#include "backend/config/btconfig.h"
+#include "util/btassert.h"
-class BtActionItem;
-class QAction;
-class QKeySequence;
-class QString;
class BtActionCollection: public QObject {
- Q_OBJECT
+ Q_OBJECT
- private: /* Types: */
+private: /* Types: */
- typedef QMap<QString, BtActionItem*> ActionMap;
+ class Item: public QObject {
public: /* Methods: */
- inline BtActionCollection(QObject *parent = 0) : QObject(parent) {}
+ Item(QAction * const action, QObject * const parent)
+ : QObject{parent}
+ , m_defaultKeys{action->shortcut()}
+ , m_action{action}
+ {}
+
+ public: /* Fields: */
+
+ QKeySequence const m_defaultKeys;
+ QAction * const m_action;
+
+ };
+ using ActionMap = QMap<QString, Item *>;
+
+public: /* Methods: */
+
+ inline BtActionCollection(QObject * const parent = nullptr)
+ : QObject{parent}
+ {}
+
+ void addAction(QString const & name, QAction * const action);
+
+ void addAction(QString const & name,
+ QObject const * const receiver,
+ const char * const member = nullptr);
+
+ void removeAction(QString const & name);
+
+ QAction & action(QString const & name) const;
+
+ template <typename T>
+ inline T & actionAs(QString const & name) const {
+ QAction & a = action(name);
+ BT_ASSERT(dynamic_cast<T *>(&a));
+ return static_cast<T &>(a);
+ }
- QAction* addAction(const QString& name, QAction* action);
+ template <typename F>
+ inline void foreachQAction(F && f) const {
+ for (Item const * const item : m_actions)
+ f(*(item->m_action), item->m_defaultKeys);
+ }
- QAction* addAction(const QString &name, const QObject *receiver, const char* member = 0);
+ /*!
+ * \brief Read shortcuts from config.
+ *
+ * Read the shortcuts for the given group
+ * from the configuration and add them to
+ * this action collection.
+ *
+ * \param[in] group Shortcut group to read actions from.
+ */
+ void readShortcuts(QString const & group);
- QList<QAction*> actions();
+ /*!
+ * \brief Write shortcuts to config.
+ *
+ * Write the shortcuts of this action collection
+ * to the given group in the configuration.
+ *
+ * \param[in] group Shortcut group to write actions to.
+ */
+ void writeShortcuts(QString const & group) const;
- QAction *action(const QString &name) const;
+ QKeySequence getDefaultShortcut(QAction * const action) const;
- /*!
- * \brief Read shortcuts from config.
- *
- * Read the shortcuts for the given group
- * from the configuration and add them to
- * this action collection.
- *
- * \param[in] group Shortcut group to read actions from.
- */
- void readShortcuts(const QString &group);
+private: /* Methods: */
- /*!
- * \brief Write shortcuts to config.
- *
- * Write the shortcuts of this action collection
- * to the given group in the configuration.
- *
- * \param[in] group Shortcut group to write actions to.
- */
- void writeShortcuts(const QString& group);
- QKeySequence getDefaultShortcut(QAction* action);
+ Item * findActionItem(QString const & name) const;
- private: /* Fields: */
+private: /* Fields: */
- ActionMap m_actions;
+ ActionMap m_actions;
};
diff --git a/src/frontend/displaywindow/btdisplaysettingsbutton.cpp b/src/frontend/displaywindow/btdisplaysettingsbutton.cpp
index bca9334..2e99e48 100644
--- a/src/frontend/displaywindow/btdisplaysettingsbutton.cpp
+++ b/src/frontend/displaywindow/btdisplaysettingsbutton.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -15,23 +15,24 @@
#include <QToolTip>
#include <QToolButton>
#include "bibletimeapp.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
BtDisplaySettingsButton::BtDisplaySettingsButton(QWidget *parent)
: QToolButton(parent) {
initMenu();
- setIcon(util::getIcon(CResMgr::displaywindows::displaySettings::icon));
+ setIcon(CResMgr::displaywindows::displaySettings::icon());
setPopupMode(QToolButton::InstantPopup);
setEnabled(false);
initMenu();
retranslateUi();
- connect(m_popup, SIGNAL(triggered(QAction*)),
- this, SLOT(slotOptionToggled(QAction*)));
+ BT_CONNECT(m_popup, SIGNAL(triggered(QAction *)),
+ this, SLOT(slotOptionToggled(QAction *)));
}
void BtDisplaySettingsButton::setDisplayOptions(
@@ -55,7 +56,7 @@ void BtDisplaySettingsButton::setFilterOptions(
}
void BtDisplaySettingsButton::setModules(
- const QList<const CSwordModuleInfo*> &modules)
+ const BtConstModuleList &modules)
{
m_modules = modules;
repopulateMenu();
@@ -161,7 +162,7 @@ void BtDisplaySettingsButton::slotOptionToggled(QAction *action) {
m_filterOptions.redLetterWords = checked;
emit sigFilterOptionsChanged(m_filterOptions);
} else {
- Q_ASSERT(false);
+ BT_ASSERT(false && "Shouldn't happen!");
return;
}
@@ -238,8 +239,8 @@ void BtDisplaySettingsButton::addMenuEntry(QAction *action, bool checked) {
}
bool BtDisplaySettingsButton::isOptionAvailable(const CSwordModuleInfo::FilterTypes option) {
- Q_FOREACH (const CSwordModuleInfo *module, m_modules) {
- if (module->has(option)) return true;
- }
+ Q_FOREACH(CSwordModuleInfo const * const module, m_modules)
+ if (module->has(option))
+ return true;
return false;
}
diff --git a/src/frontend/displaywindow/btdisplaysettingsbutton.h b/src/frontend/displaywindow/btdisplaysettingsbutton.h
index f82f682..39cdcc3 100644
--- a/src/frontend/displaywindow/btdisplaysettingsbutton.h
+++ b/src/frontend/displaywindow/btdisplaysettingsbutton.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -14,8 +14,8 @@
#include <QToolButton>
+#include "backend/btglobal.h"
#include "backend/managers/cswordbackend.h"
-#include "btglobal.h"
class CSwordModuleInfo;
@@ -28,7 +28,7 @@ class BtDisplaySettingsButton: public QToolButton {
Q_OBJECT
public:
- BtDisplaySettingsButton(QWidget *parent = 0);
+ BtDisplaySettingsButton(QWidget *parent = nullptr);
public slots:
void setDisplayOptions(const DisplayOptions &displaySettings,
@@ -36,13 +36,13 @@ class BtDisplaySettingsButton: public QToolButton {
void setFilterOptions(const FilterOptions &moduleSettings,
bool repopulate = true);
- void setModules(const QList<const CSwordModuleInfo*> &modules);
+ void setModules(const BtConstModuleList &modules);
signals:
void sigFilterOptionsChanged(FilterOptions filterOptions);
void sigDisplayOptionsChanged(DisplayOptions displayOptions);
- void sigModulesChanged(const QList<CSwordModuleInfo*> &modules);
- void sigChanged(void);
+ void sigModulesChanged(const BtConstModuleList &modules);
+ void sigChanged();
protected slots:
void slotOptionToggled(QAction *action);
@@ -59,7 +59,7 @@ class BtDisplaySettingsButton: public QToolButton {
private:
FilterOptions m_filterOptions;
DisplayOptions m_displayOptions;
- QList<const CSwordModuleInfo*> m_modules;
+ BtConstModuleList m_modules;
QMenu *m_popup;
QAction *m_lineBreakAction;
diff --git a/src/frontend/displaywindow/btmodulechooserbar.cpp b/src/frontend/displaywindow/btmodulechooserbar.cpp
index e8d80cb..5e830d2 100644
--- a/src/frontend/displaywindow/btmodulechooserbar.cpp
+++ b/src/frontend/displaywindow/btmodulechooserbar.cpp
@@ -2,44 +2,45 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "frontend/displaywindow/btmodulechooserbar.h"
-#include "frontend/displaywindow/btmodulechooserbutton.h"
-#include "creadwindow.h"
-#include "util/btmodules.h"
#include <QAction>
#include <QDebug>
#include <QList>
#include <QToolBar>
+#include "frontend/displaywindow/btmodulechooserbutton.h"
+#include "creadwindow.h"
+#include "util/btconnect.h"
+#include "util/btmodules.h"
BtModuleChooserBar::BtModuleChooserBar(QWidget *parent)
: QToolBar(parent),
- BtWindowModuleChooser(CSwordModuleInfo::Unknown, 0),
+ BtWindowModuleChooser(CSwordModuleInfo::Unknown, nullptr),
m_idCounter(0),
- m_window(0) {
+ m_window(nullptr) {
setAllowedAreas(Qt::TopToolBarArea);
setFloatable(false);
}
void BtModuleChooserBar::slotBackendModulesChanged() {
m_modules = m_window->getModuleList();
-
adjustButtonCount();
- //recreate all menus from scratch
- for (int i = 0; i < m_buttonList.count(); i++) {
- BtModuleChooserButton* button = m_buttonList.at(i);
- QString moduleName = (i >= m_modules.count()) ? QString::null : m_modules.at(i);
- qDebug() << "refresh button's menu:" << moduleName << i;
- int leftLikeModules = leftLikeParallelModules(m_modules);
- button->recreateMenu(m_modules, moduleName, i, leftLikeModules);
- }
+ // Recreate all menus from scratch:
+ int const leftLikeModules = leftLikeParallelModules(m_modules);
+ for (int i = 0; i < m_buttonList.count(); i++)
+ m_buttonList.at(i)->recreateMenu(m_modules,
+ (i >= m_modules.count())
+ ? QString::null
+ : m_modules.at(i),
+ i,
+ leftLikeModules);
}
void BtModuleChooserBar::adjustButtonCount(bool adjustToZero) {
@@ -80,9 +81,12 @@ BtModuleChooserButton* BtModuleChooserBar::addButton() {
// the button sends signals directly to the window which then signals back when the module
// list has changed
- connect(b, SIGNAL(sigModuleAdd(int, QString)), m_window, SLOT(slotAddModule(int, QString)));
- connect(b, SIGNAL(sigModuleReplace(int, QString)), m_window, SLOT(slotReplaceModule(int, QString)));
- connect(b, SIGNAL(sigModuleRemove(int)), m_window, SLOT(slotRemoveModule(int)));
+ BT_CONNECT(b, &BtModuleChooserButton::sigModuleAdd,
+ m_window, &CReadWindow::slotAddModule);
+ BT_CONNECT(b, &BtModuleChooserButton::sigModuleReplace,
+ m_window, &CReadWindow::slotReplaceModule);
+ BT_CONNECT(b, &BtModuleChooserButton::sigModuleRemove,
+ m_window, &CReadWindow::slotRemoveModule);
a->setVisible(true);
return b;
@@ -108,15 +112,19 @@ void BtModuleChooserBar::setModules( QStringList useModules,CSwordModuleInfo::Mo
}
updateButtonMenus();
- connect(m_window, SIGNAL(sigModuleListSet(QStringList)), SLOT(slotBackendModulesChanged()));
- connect(m_window, SIGNAL(sigModuleListChanged()), SLOT(slotWindowModulesChanged()));
+ BT_CONNECT(m_window, &CReadWindow::sigModuleListSet,
+ this, &BtModuleChooserBar::slotBackendModulesChanged);
+ BT_CONNECT(m_window, &CReadWindow::sigModuleListChanged,
+ this, &BtModuleChooserBar::slotWindowModulesChanged);
}
void BtModuleChooserBar::updateButtonMenus() {
- int leftLikeModules = leftLikeParallelModules(m_modules);
- for (int i = 0; i < m_buttonList.count(); i++) {
- BtModuleChooserButton* button = m_buttonList.at(i);
- QString moduleName = (i >= m_modules.count()) ? QString::null : m_modules.at(i);
- button->updateMenu(m_modules, moduleName, i, leftLikeModules);
- }
+ int const leftLikeModules = leftLikeParallelModules(m_modules);
+ for (int i = 0; i < m_buttonList.count(); i++)
+ m_buttonList.at(i)->updateMenu(m_modules,
+ (i >= m_modules.count())
+ ? QString::null
+ : m_modules.at(i),
+ i,
+ leftLikeModules);
}
diff --git a/src/frontend/displaywindow/btmodulechooserbar.h b/src/frontend/displaywindow/btmodulechooserbar.h
index 024bc08..2e09627 100644
--- a/src/frontend/displaywindow/btmodulechooserbar.h
+++ b/src/frontend/displaywindow/btmodulechooserbar.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -33,12 +33,12 @@ class BtModuleChooserBar: public QToolBar, public BtWindowModuleChooser {
* The signal comes from the window, not from the backend. The new list can
* be shorter but not longer than the old list.
*/
- void slotBackendModulesChanged();
+ void slotBackendModulesChanged() override;
/**
* The window module list was changed, i.e. 1 module added, removed or replaced.
*/
- void slotWindowModulesChanged();
+ void slotWindowModulesChanged() override;
private:
/** Adds an empty button to the toolbar.*/
diff --git a/src/frontend/displaywindow/btmodulechooserbutton.cpp b/src/frontend/displaywindow/btmodulechooserbutton.cpp
index 4e0a5fc..5e6eea1 100644
--- a/src/frontend/displaywindow/btmodulechooserbutton.cpp
+++ b/src/frontend/displaywindow/btmodulechooserbutton.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -19,14 +19,14 @@
#include "backend/managers/cswordbackend.h"
#include "bibletimeapp.h"
#include "frontend/displaywindow/btmodulechooserbar.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
BtModuleChooserButton::BtModuleChooserButton(BtModuleChooserBar *parent, CSwordModuleInfo::ModuleType mtype)
: QToolButton(parent),
m_moduleType(mtype),
- m_popup(0) {
+ m_popup(nullptr) {
setPopupMode(QToolButton::InstantPopup);
}
@@ -35,18 +35,26 @@ void BtModuleChooserButton::recreateMenu(QStringList newModulesToUse, QString th
updateMenu(newModulesToUse, thisModule, newIndex, leftLikeModules);
}
-const QString BtModuleChooserButton::iconName() {
+QIcon const & BtModuleChooserButton::icon() {
switch (m_moduleType) {
case CSwordModuleInfo::Bible:
- return (m_hasModule) ? CResMgr::modules::bible::icon_unlocked : CResMgr::modules::bible::icon_add;
+ 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;
+ 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;
+ 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;
+ 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;
+ return CResMgr::modules::bible::icon_unlocked();
}
}
@@ -58,19 +66,20 @@ void BtModuleChooserButton::updateMenu(QStringList newModulesToUse, QString this
populateMenu();
m_module = thisModule;
- m_hasModule = thisModule.isEmpty() ? false : true;
+ m_hasModule = !thisModule.isEmpty();
//All items are iterated and the state is changed properly
QListIterator<QMenu*> it(m_submenus);
while (it.hasNext()) {
QMenu* popup = it.next();
- foreach (QAction* a, popup->actions()) {
- a->setChecked( (a->text() == thisModule) ? true : false );
- a->setDisabled( newModulesToUse.contains(a->text()) ? true : false );
+ Q_FOREACH(QAction * const a, popup->actions()) {
+ auto const moduleName(a->property("BibleTimeModule").toString());
+ a->setChecked(moduleName == thisModule);
+ a->setDisabled(newModulesToUse.contains(moduleName));
}
}
- m_noneAction->setChecked(m_hasModule ? false : true);
- setIcon(util::getIcon(iconName()));
+ m_noneAction->setChecked(!m_hasModule);
+ setIcon(icon());
if (m_hasModule) {
setToolTip( QString(tr("Select a work [%1]")).arg(m_module) );
@@ -99,7 +108,8 @@ void BtModuleChooserButton::updateMenu(QStringList newModulesToUse, QString this
/** Is called after a module was selected in the popup */
void BtModuleChooserButton::moduleChosen( QAction* action ) {
- if (action->text() == tr("NONE")) { // note: this is for m_popup, the toplevel!
+ auto modProperty(action->property("BibleTimeModule"));
+ if (!modProperty.isValid()) { // note: this is for m_popup, the toplevel!
if (m_hasModule) {
qDebug() << "remove module" << m_id;
emit sigModuleRemove(m_id);
@@ -113,10 +123,10 @@ void BtModuleChooserButton::moduleChosen( QAction* action ) {
}
else {
if (!m_hasModule) {
- emit sigModuleAdd(m_id + 1, action->text());
+ emit sigModuleAdd(m_id + 1, modProperty.toString());
return;
}
- emit sigModuleReplace(m_id, action->text());
+ emit sigModuleReplace(m_id, modProperty.toString());
}
}
@@ -132,7 +142,8 @@ void BtModuleChooserButton::populateMenu() {
if (m_module.isEmpty()) m_noneAction->setChecked(true);
m_popup->addSeparator();
- connect(m_popup, SIGNAL(triggered(QAction*)), this, SLOT(moduleChosen(QAction*)));
+ BT_CONNECT(m_popup, &QMenu::triggered,
+ this, &BtModuleChooserButton::moduleChosen);
setMenu(m_popup);
@@ -166,8 +177,7 @@ void BtModuleChooserButton::populateMenu() {
}
void BtModuleChooserButton::addItemToMenu(BTModuleTreeItem* item, QMenu* menu) {
- foreach (BTModuleTreeItem* i, item->children()) {
-
+ Q_FOREACH(BTModuleTreeItem * const i, item->children()) {
if (i->type() == BTModuleTreeItem::Language ||
i->type() == BTModuleTreeItem::Category ) {
// argument menu was m_popup, create and add a new lang menu to it
@@ -181,6 +191,7 @@ void BtModuleChooserButton::addItemToMenu(BTModuleTreeItem* item, QMenu* menu) {
// item must be module, create and add it to the lang menu
QString name(i->text());
QAction* modItem = new QAction(name, menu);
+ modItem->setProperty("BibleTimeModule", name);
modItem->setCheckable(true);
menu->addAction(modItem);
}
diff --git a/src/frontend/displaywindow/btmodulechooserbutton.h b/src/frontend/displaywindow/btmodulechooserbutton.h
index 03c2b9b..2d33b9a 100644
--- a/src/frontend/displaywindow/btmodulechooserbutton.h
+++ b/src/frontend/displaywindow/btmodulechooserbutton.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -36,9 +36,8 @@ class BtModuleChooserButton : public QToolButton {
TypeFilter(CSwordModuleInfo::ModuleType t) {
m_mType = t;
}
- bool filter(CSwordModuleInfo* mi) {
- return ((mi->type() == m_mType) && !mi->isLocked());
- }
+ bool filter(CSwordModuleInfo const & mi) const override
+ { return ((mi.type() == m_mType) && !mi.isLocked()); }
CSwordModuleInfo::ModuleType m_mType;
};
@@ -79,8 +78,9 @@ class BtModuleChooserButton : public QToolButton {
void moduleChosen(QAction* action );
private:
+
/** Returns the icon used for the current status.*/
- const QString iconName();
+ QIcon const & icon();
/**
* Populates the menu with language submenus and module items without setting
diff --git a/src/frontend/displaywindow/bttextwindowheader.cpp b/src/frontend/displaywindow/bttextwindowheader.cpp
index 6f108d7..3a1c546 100644
--- a/src/frontend/displaywindow/bttextwindowheader.cpp
+++ b/src/frontend/displaywindow/bttextwindowheader.cpp
@@ -2,26 +2,27 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "bttextwindowheader.h"
-#include "bttextwindowheaderwidget.h"
-#include "clexiconreadwindow.h"
-#include "util/btmodules.h"
-
-#include <QStringList>
-#include <QWidget>
+#include <QAction>
+#include <QDebug>
+#include <QFrame>
#include <QHBoxLayout>
#include <QLabel>
#include <QSizePolicy>
+#include <QStringList>
#include <QToolButton>
-#include <QFrame>
-#include <QAction>
-#include <QDebug>
+#include <QWidget>
+#include "bttextwindowheaderwidget.h"
+#include "clexiconreadwindow.h"
+#include "util/btconnect.h"
+#include "util/btmodules.h"
+
BtTextWindowHeader::BtTextWindowHeader(CSwordModuleInfo::ModuleType modtype,
QStringList modules,
@@ -34,8 +35,10 @@ BtTextWindowHeader::BtTextWindowHeader(CSwordModuleInfo::ModuleType modtype,
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setLayoutDirection(Qt::LeftToRight);
setModules(modules);
- connect(window, SIGNAL(sigModuleListSet(QStringList)), SLOT(slotBackendModulesChanged()));
- connect(window, SIGNAL(sigModuleListChanged()), SLOT(slotWindowModulesChanged()));
+ BT_CONNECT(window, SIGNAL(sigModuleListSet(QStringList)),
+ SLOT(slotBackendModulesChanged()));
+ BT_CONNECT(window, SIGNAL(sigModuleListChanged()),
+ SLOT(slotWindowModulesChanged()));
}
void BtTextWindowHeader::slotBackendModulesChanged() {
@@ -44,13 +47,12 @@ void BtTextWindowHeader::slotBackendModulesChanged() {
adjustWidgetCount();
//recreate all widgets from scratch
- for (int i = 0; i < m_widgetList.count(); i++) {
- BtTextWindowHeaderWidget* widgt = m_widgetList.at(i);
- QString moduleName = m_modules.at(i);
- qDebug() << "refresh button's menu:" << moduleName << i;
- int leftLikeModules = leftLikeParallelModules(m_modules);
- widgt->recreateWidget(m_modules, moduleName, i, leftLikeModules);
- }
+ int const leftLikeModules = leftLikeParallelModules(m_modules);
+ for (int i = 0; i < m_widgetList.count(); i++)
+ m_widgetList.at(i)->recreateWidget(m_modules,
+ m_modules.at(i),
+ i,
+ leftLikeModules);
}
void BtTextWindowHeader::slotWindowModulesChanged() {
@@ -75,7 +77,7 @@ void BtTextWindowHeader::adjustWidgetCount(bool adjustToZero) {
while (widgetCountDifference) {
// it should be safe to delete the button later
BtTextWindowHeaderWidget* w = m_widgetList.takeFirst();
- w->setParent(0);
+ w->setParent(nullptr);
w->deleteLater();
widgetCountDifference--;
}
@@ -96,9 +98,12 @@ BtTextWindowHeaderWidget* BtTextWindowHeader::addWidget() {
// the button sends signals directly to the window which then signals back when the module
// list has changed
- connect(w, SIGNAL(sigModuleAdd(int, QString)), m_window, SLOT(slotAddModule(int, QString)));
- connect(w, SIGNAL(sigModuleReplace(int, QString)), m_window, SLOT(slotReplaceModule(int, QString)));
- connect(w, SIGNAL(sigModuleRemove(int)), m_window, SLOT(slotRemoveModule(int)));
+ BT_CONNECT(w, SIGNAL(sigModuleAdd(int, QString)),
+ m_window, SLOT(slotAddModule(int, QString)));
+ BT_CONNECT(w, SIGNAL(sigModuleReplace(int, QString)),
+ m_window, SLOT(slotReplaceModule(int, QString)));
+ BT_CONNECT(w, SIGNAL(sigModuleRemove(int)),
+ m_window, SLOT(slotRemoveModule(int)));
return w;
}
@@ -115,10 +120,10 @@ void BtTextWindowHeader::setModules( QStringList useModules ) {
}
void BtTextWindowHeader::updateWidgets() {
- int leftLikeModules = leftLikeParallelModules(m_modules);
- for (int i = 0; i < m_widgetList.count(); i++) {
- BtTextWindowHeaderWidget* w = m_widgetList.at(i);
- //QString moduleName = m_modules.at(i);
- w->updateWidget(m_modules, m_modules.at(i), i, leftLikeModules);
- }
+ int const leftLikeModules = leftLikeParallelModules(m_modules);
+ for (int i = 0; i < m_widgetList.count(); i++)
+ m_widgetList.at(i)->updateWidget(m_modules,
+ m_modules.at(i),
+ i,
+ leftLikeModules);
}
diff --git a/src/frontend/displaywindow/bttextwindowheader.h b/src/frontend/displaywindow/bttextwindowheader.h
index 2673d78..fdd587d 100644
--- a/src/frontend/displaywindow/bttextwindowheader.h
+++ b/src/frontend/displaywindow/bttextwindowheader.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -31,12 +31,12 @@ class BtTextWindowHeader: public QWidget, public BtWindowModuleChooser {
The backend module list was updated, module list and widgets must be updated from
scratch.
*/
- void slotBackendModulesChanged();
+ void slotBackendModulesChanged() override;
/**
The window module list was updated, module list and widgets must be updated.
*/
- void slotWindowModulesChanged();
+ void slotWindowModulesChanged() override;
signals:
/** User selected a module from menu to replace another module*/
diff --git a/src/frontend/displaywindow/bttextwindowheaderwidget.cpp b/src/frontend/displaywindow/bttextwindowheaderwidget.cpp
index a974c2c..b8201ad 100644
--- a/src/frontend/displaywindow/bttextwindowheaderwidget.cpp
+++ b/src/frontend/displaywindow/bttextwindowheaderwidget.cpp
@@ -2,27 +2,26 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "frontend/displaywindow/bttextwindowheaderwidget.h"
+#include <QHBoxLayout>
+#include <QLabel>
#include <QMenu>
-#include <QString>
#include <QToolButton>
#include <QToolTip>
-#include <QHBoxLayout>
#include <QSizePolicy>
-#include <QLabel>
-
+#include <QString>
#include "backend/config/btconfig.h"
#include "backend/managers/cswordbackend.h"
#include "bibletimeapp.h"
#include "frontend/displaywindow/bttextwindowheader.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
namespace {
@@ -30,11 +29,12 @@ const QString BookshelfShowHiddenKey = "GUI/bookshelfShowHidden";
} // anonymous namespace
const char* ActionType = "ActionType";
+const char * ModuleName = "ModuleName";
BtTextWindowHeaderWidget::BtTextWindowHeaderWidget(BtTextWindowHeader *parent, CSwordModuleInfo::ModuleType mtype)
: QWidget(parent),
m_moduleType(mtype),
- m_popup(0) {
+ m_popup(nullptr) {
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
@@ -92,9 +92,11 @@ void BtTextWindowHeaderWidget::updateWidget(QStringList newModulesToUse, QString
QListIterator<QMenu*> it(m_submenus);
while (it.hasNext()) {
QMenu* popup = it.next();
- foreach (QAction* a, popup->actions()) {
- a->setChecked( (a->text() == thisModule) ? true : false );
- a->setDisabled( newModulesToUse.contains(a->text()) ? true : false );
+ Q_FOREACH(QAction * const a, popup->actions()) {
+ a->setChecked(a->property(ModuleName).toString() == thisModule);
+ a->setDisabled(
+ newModulesToUse.contains(
+ a->property(ModuleName).toString()));
}
}
@@ -113,7 +115,7 @@ void BtTextWindowHeaderWidget::updateWidget(QStringList newModulesToUse, QString
if (typeText != QObject::tr("Replace"))
continue;
QMenu* menuType = actionType->menu();
- if (menuType == 0)
+ if (menuType == nullptr)
continue;
QList<QAction*> actions = menuType->actions();
for (int i=0; i<actions.count(); i++) {
@@ -134,11 +136,11 @@ void BtTextWindowHeaderWidget::moduleChosen( QAction* action ) {
return;
}
if (action->property(ActionType).toInt() == AddAction) {
- emit sigModuleAdd(m_id + 1, action->text());
+ emit sigModuleAdd(m_id + 1, action->property(ModuleName).toString());
return;
}
if (action->property(ActionType).toInt() == ReplaceAction) {
- emit sigModuleReplace(m_id, action->text());
+ emit sigModuleReplace(m_id, action->property(ModuleName).toString());
}
}
@@ -147,30 +149,31 @@ void BtTextWindowHeaderWidget::populateMenu() {
delete m_popup;
m_popup = new QMenu(m_button);
- connect(m_popup, SIGNAL(triggered(QAction*)), this, SLOT(moduleChosen(QAction*)));
+ BT_CONNECT(m_popup, SIGNAL(triggered(QAction *)),
+ this, SLOT(moduleChosen(QAction *)));
m_button->setMenu(m_popup);
m_removeAction = new QAction(tr("Remove"), m_popup);
m_removeAction->setProperty(ActionType, RemoveAction);
- m_removeAction->setIcon(util::getIcon(CResMgr::displaywindows::general::removemoduleicon));
+ m_removeAction->setIcon(CResMgr::displaywindows::general::icon_removeModule());
m_popup->addAction(m_removeAction);
// Add Replace and Add menus, both have all modules in them
QMenu* replaceItem = new QMenu(tr("Replace"), m_popup);
- replaceItem->setIcon(util::getIcon(CResMgr::displaywindows::general::replacemoduleicon));
+ replaceItem->setIcon(CResMgr::displaywindows::general::icon_replaceModule());
replaceItem->setProperty(ActionType, ReplaceAction);
m_popup->addMenu(replaceItem);
QMenu* addItem = new QMenu(tr("Add"), m_popup);
addItem->setProperty(ActionType, AddAction);
- addItem->setIcon(util::getIcon(CResMgr::displaywindows::general::addmoduleicon));
+ addItem->setIcon(CResMgr::displaywindows::general::icon_addModule());
m_popup->addMenu(addItem);
QList<QMenu*> toplevelMenus;
toplevelMenus.append(replaceItem);
toplevelMenus.append(addItem);
- foreach(QMenu* menu, toplevelMenus) {
+ Q_FOREACH(QMenu * const menu, toplevelMenus) {
// ******* Add categories, languages and modules ********
// Filters: add only non-hidden, non-locked and correct type
BTModuleTreeItem::HiddenOff hiddenFilter;
@@ -181,6 +184,8 @@ void BtTextWindowHeaderWidget::populateMenu() {
TypeFilter typeFilter(m_moduleType);
filters.append(&typeFilter);
+ TypeOfAction const typeOfAction =
+ static_cast<TypeOfAction>(menu->property(ActionType).toInt());
if (m_moduleType == CSwordModuleInfo::Bible) {
BTModuleTreeItem root(filters, BTModuleTreeItem::CatLangMod);
QList<BTModuleTreeItem::Filter*> filters2;
@@ -192,18 +197,17 @@ void BtTextWindowHeaderWidget::populateMenu() {
filters2.append(&typeFilter2);
root.add_items(filters2);
}
- addItemToMenu(&root, menu, (TypeOfAction)menu->property(ActionType).toInt());
+ addItemToMenu(&root, menu, typeOfAction);
}
else {
BTModuleTreeItem root(filters, BTModuleTreeItem::LangMod);
- addItemToMenu(&root, menu, (TypeOfAction)menu->property(ActionType).toInt());
+ addItemToMenu(&root, menu, typeOfAction);
}
}
}
void BtTextWindowHeaderWidget::addItemToMenu(BTModuleTreeItem* item, QMenu* menu, TypeOfAction actionType) {
- foreach (BTModuleTreeItem* i, item->children()) {
-
+ Q_FOREACH(BTModuleTreeItem * const i, item->children()) {
if (i->type() == BTModuleTreeItem::Language ||
i->type() == BTModuleTreeItem::Category) {
// argument menu was m_popup, create and add a new lang menu to it
@@ -219,6 +223,7 @@ void BtTextWindowHeaderWidget::addItemToMenu(BTModuleTreeItem* item, QMenu* menu
QAction* modItem = new QAction(name, menu);
modItem->setCheckable(true);
modItem->setProperty(ActionType, actionType);
+ modItem->setProperty(ModuleName, name);
menu->addAction(modItem);
}
}
diff --git a/src/frontend/displaywindow/bttextwindowheaderwidget.h b/src/frontend/displaywindow/bttextwindowheaderwidget.h
index c69bf11..033cd64 100644
--- a/src/frontend/displaywindow/bttextwindowheaderwidget.h
+++ b/src/frontend/displaywindow/bttextwindowheaderwidget.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -46,9 +46,8 @@ class BtTextWindowHeaderWidget : public QWidget {
TypeFilter(CSwordModuleInfo::ModuleType t) {
m_mType = t;
}
- bool filter(CSwordModuleInfo* mi) {
- return ((mi->type() == m_mType) && !mi->isLocked());
- }
+ bool filter(CSwordModuleInfo const & mi) const override
+ { return ((mi.type() == m_mType) && !mi.isLocked()); }
CSwordModuleInfo::ModuleType m_mType;
};
diff --git a/src/frontend/displaywindow/bttoolbarpopupaction.cpp b/src/frontend/displaywindow/bttoolbarpopupaction.cpp
index e443f8a..da52c92 100644
--- a/src/frontend/displaywindow/bttoolbarpopupaction.cpp
+++ b/src/frontend/displaywindow/bttoolbarpopupaction.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -13,16 +13,17 @@
#include <QEvent>
#include <QMenu>
#include <QToolButton>
+#include "util/btconnect.h"
namespace {
class BtToolButton: public QToolButton {
public:
- inline BtToolButton(QWidget *parent = 0)
+ inline BtToolButton(QWidget *parent = nullptr)
: QToolButton(parent) {}
private:
- virtual inline void nextCheckState() {}
+ inline void nextCheckState() override {}
};
} // anonymous namespace
@@ -53,8 +54,7 @@ QWidget* BtToolBarPopupAction::createWidget(QWidget* parent) {
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);;
+ BT_CONNECT(m_button, SIGNAL(pressed()), this, SLOT(buttonPressed()));
return m_button;
}
diff --git a/src/frontend/displaywindow/bttoolbarpopupaction.h b/src/frontend/displaywindow/bttoolbarpopupaction.h
index 4999098..23bd688 100644
--- a/src/frontend/displaywindow/bttoolbarpopupaction.h
+++ b/src/frontend/displaywindow/bttoolbarpopupaction.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -31,11 +31,10 @@ class BtToolBarPopupAction : public QWidgetAction {
// return the QMenu object so a popup menu can be constructed
QMenu* popupMenu() const;
-// Function to catch the Shortcut event and emit the triggered signal
- virtual bool event(QEvent* e);
+ bool event(QEvent* e) override;
protected:
- QWidget* createWidget(QWidget* parent);
+ QWidget* createWidget(QWidget* parent) override;
private slots:
diff --git a/src/frontend/displaywindow/btwindowmodulechooser.h b/src/frontend/displaywindow/btwindowmodulechooser.h
index 40ffcf0..be34ee7 100644
--- a/src/frontend/displaywindow/btwindowmodulechooser.h
+++ b/src/frontend/displaywindow/btwindowmodulechooser.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
diff --git a/src/frontend/displaywindow/cbiblereadwindow.cpp b/src/frontend/displaywindow/cbiblereadwindow.cpp
index 4d88f13..7789953 100644
--- a/src/frontend/displaywindow/cbiblereadwindow.cpp
+++ b/src/frontend/displaywindow/cbiblereadwindow.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -10,7 +10,6 @@
#include "frontend/displaywindow/cbiblereadwindow.h"
#include <QAction>
-#include <QApplication>
#include <QEvent>
#include <QMdiSubWindow>
#include <QMenu>
@@ -18,6 +17,7 @@
#include <QWidget>
#include "backend/drivers/cswordbiblemoduleinfo.h"
#include "backend/keys/cswordversekey.h"
+#include "bibletimeapp.h"
#include "frontend/cexportmanager.h"
#include "frontend/cmdiarea.h"
#include "frontend/display/creaddisplay.h"
@@ -25,6 +25,8 @@
#include "frontend/displaywindow/ccommentaryreadwindow.h"
#include "frontend/displaywindow/btdisplaysettingsbutton.h"
#include "frontend/keychooser/ckeychooser.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/directory.h"
#include "util/cresmgr.h"
#include "util/tool.h"
@@ -46,7 +48,7 @@ void CBibleReadWindow::applyProfileSettings(const QString & windowGroup) {
lookup();
}
-void CBibleReadWindow::storeProfileSettings(const QString & windowGroup) {
+void CBibleReadWindow::storeProfileSettings(QString const & windowGroup) const {
BtConfig & conf = btConfig();
conf.beginGroup(windowGroup);
conf.setFilterOptions(filterOptions());
@@ -127,109 +129,60 @@ void CBibleReadWindow::initActions() {
CBibleReadWindow::insertKeyboardActions(ac);
- QAction * qaction;
-
- //cleanup, not a clean oo-solution
- qaction = ac->action("nextEntry");
- Q_ASSERT(qaction != 0);
- qaction->setEnabled(false);
- qaction = ac->action("previousEntry");
- Q_ASSERT(qaction != 0);
- qaction->setEnabled(false);
-
-
- qaction = m_actionCollection->action("nextBook");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextBook()) );
- addAction(qaction);
-
- qaction = m_actionCollection->action("previousBook");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousBook()) );
- addAction(qaction);
-
- qaction = m_actionCollection->action("nextChapter");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextChapter()) );
- addAction(qaction);
-
- qaction = m_actionCollection->action("previousChapter");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousChapter()) );
- addAction(qaction);
-
- qaction = m_actionCollection->action("nextVerse");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(nextVerse()) );
- addAction(qaction);
-
- qaction = m_actionCollection->action("previousVerse");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()), this, SLOT(previousVerse()) );
- addAction(qaction);
-
- m_actions.selectAll = ac->action("selectAll");
- Q_ASSERT(m_actions.selectAll != 0);
-
- m_actions.findText = ac->action("findText");
- Q_ASSERT(m_actions.findText != 0);
-
- m_actions.findStrongs = m_actionCollection->action(CResMgr::displaywindows::general::findStrongs::actionName);
- Q_ASSERT(m_actions.findStrongs != 0);
-
- m_actions.copy.referenceOnly = m_actionCollection->action("copyReferenceOnly");
- Q_ASSERT(m_actions.copy.referenceOnly != 0);
-
- m_actions.copy.referenceTextOnly = m_actionCollection->action("copyTextOfReference");
- Q_ASSERT(m_actions.copy.referenceTextOnly != 0);
- 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");
- Q_ASSERT(m_actions.copy.referenceAndText != 0);
- 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");
- Q_ASSERT(m_actions.copy.chapter != 0);
- 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 != 0);
-
- m_actions.save.referenceAndText = m_actionCollection->action("saveReferenceWithText");
- Q_ASSERT(m_actions.save.referenceAndText != 0);
- 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");
- Q_ASSERT(m_actions.save.chapterAsPlain != 0);
- QObject::connect(m_actions.save.chapterAsPlain, SIGNAL(triggered()),
- this, SLOT(saveChapterPlain()));
- addAction(m_actions.save.referenceAndText);
-
- m_actions.save.chapterAsHTML = m_actionCollection->action("saveChapterAsHTML");
- Q_ASSERT(m_actions.save.chapterAsHTML != 0);
- QObject::connect(m_actions.save.chapterAsHTML, SIGNAL(triggered()),
- this, SLOT(saveChapterHTML()));
- addAction(m_actions.save.chapterAsHTML);
-
- m_actions.print.reference = m_actionCollection->action("printReferenceWithText");
- Q_ASSERT(m_actions.print.reference != 0);
- QObject::connect(m_actions.print.reference, SIGNAL(triggered()),
- this, SLOT(printAnchorWithText()));
- addAction(m_actions.print.reference);
-
- m_actions.print.chapter = m_actionCollection->action("printChapter");
- Q_ASSERT(m_actions.print.chapter != 0);
- QObject::connect(m_actions.print.chapter, SIGNAL(triggered()),
- this, SLOT(printAll()));
- addAction(m_actions.print.chapter);
+ ac->action("nextEntry").setEnabled(false);
+ ac->action("previousEntry").setEnabled(false);
+
+ initAction("nextBook", this, &CBibleReadWindow::nextBook);
+ initAction("previousBook", this, &CBibleReadWindow::previousBook);
+ initAction("nextChapter", this, &CBibleReadWindow::nextChapter);
+ initAction("previousChapter", this, &CBibleReadWindow::previousChapter);
+ initAction("nextVerse", this, &CBibleReadWindow::nextVerse);
+ initAction("previousVerse", this, &CBibleReadWindow::previousVerse);
+
+ m_actions.selectAll = &ac->action("selectAll");
+ m_actions.findText = &ac->action("findText");
+ m_actions.findStrongs = &ac->action(CResMgr::displaywindows::general::findStrongs::actionName);
+ m_actions.copy.referenceOnly = &ac->action("copyReferenceOnly");
+
+ m_actions.copy.referenceTextOnly =
+ &initAction("copyTextOfReference",
+ displayWidget()->connectionsProxy(),
+ &CDisplayConnections::copyAnchorTextOnly);
+
+ m_actions.copy.referenceAndText =
+ &initAction("copyReferenceWithText",
+ displayWidget()->connectionsProxy(),
+ &CDisplayConnections::copyAnchorWithText);
+
+ m_actions.copy.chapter =
+ &initAction("copyChapter",
+ this,
+ &CBibleReadWindow::copyDisplayedText);
+
+ m_actions.copy.selectedText = &ac->action("copySelectedText");
+
+ m_actions.save.referenceAndText =
+ &initAction("saveReferenceWithText",
+ displayWidget()->connectionsProxy(),
+ &CDisplayConnections::saveAnchorWithText);
+
+ m_actions.save.chapterAsPlain =
+ &initAction("saveChapterAsPlainText",
+ this,
+ &CBibleReadWindow::saveChapterPlain);
+
+ m_actions.save.chapterAsHTML =
+ &initAction("saveChapterAsHTML",
+ this,
+ &CBibleReadWindow::saveChapterHTML);
+
+ m_actions.print.reference =
+ &initAction("printReferenceWithText",
+ this,
+ &CBibleReadWindow::printAnchorWithText);
+
+ m_actions.print.chapter =
+ &initAction("printChapter", this, &CBibleReadWindow::printAll);
ac->readShortcuts("Bible shortcuts");
}
@@ -277,9 +230,9 @@ void CBibleReadWindow::setupPopupMenu() {
m_actions.saveMenu->addAction(m_actions.save.chapterAsHTML);
// Save raw HTML action for debugging purposes
- if (qApp->property("--debug").toBool()) {
+ if (btApp->debugMode()) {
QAction* debugAction = new QAction("Raw HTML", this);
- QObject::connect(debugAction, SIGNAL(triggered()), this, SLOT(saveRawHTML()));
+ BT_CONNECT(debugAction, SIGNAL(triggered()), this, SLOT(saveRawHTML()));
m_actions.saveMenu->addAction(debugAction);
} // end of Save Raw HTML
popup()->addMenu(m_actions.saveMenu);
@@ -294,16 +247,19 @@ void CBibleReadWindow::setupPopupMenu() {
void CBibleReadWindow::updatePopupMenu() {
qWarning("CBibleReadWindow::updatePopupMenu()");
- m_actions.findStrongs->setEnabled(!displayWidget()->getCurrentNodeInfo().isNull());
+ CReadDisplay const & display =
+ *static_cast<CReadDisplay *>(displayWidget());
+ m_actions.findStrongs->setEnabled(!display.getCurrentNodeInfo().isNull());
- 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() );
+ bool const hasActiveAnchor = display.hasActiveAnchor();
+ m_actions.copy.referenceOnly->setEnabled(hasActiveAnchor);
+ m_actions.copy.referenceTextOnly->setEnabled(hasActiveAnchor);
+ m_actions.copy.referenceAndText->setEnabled(hasActiveAnchor);
+ m_actions.copy.selectedText->setEnabled(display.hasSelection());
- m_actions.save.referenceAndText->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() );
+ m_actions.save.referenceAndText->setEnabled(hasActiveAnchor);
- m_actions.print.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() );
+ m_actions.print.reference->setEnabled(hasActiveAnchor);
}
/** Moves to the next book. */
@@ -351,7 +307,7 @@ void CBibleReadWindow::previousVerse() {
/** wrapper around key() to return the right type of key. */
CSwordVerseKey* CBibleReadWindow::verseKey() {
CSwordVerseKey* k = dynamic_cast<CSwordVerseKey*>(CDisplayWindow::key());
- Q_ASSERT(k);
+ BT_ASSERT(k);
return k;
}
@@ -375,7 +331,7 @@ void CBibleReadWindow::copyDisplayedText() {
/** Saves the chapter as valid HTML page. */
void CBibleReadWindow::saveChapterHTML() {
//saves the complete chapter to disk
- Q_ASSERT(dynamic_cast<const CSwordBibleModuleInfo*>(modules().first()) != 0);
+ BT_ASSERT(dynamic_cast<CSwordBibleModuleInfo const *>(modules().first()));
const CSwordBibleModuleInfo *bible = static_cast<const CSwordBibleModuleInfo*>(modules().first());
CSwordVerseKey dummy(*verseKey());
@@ -428,7 +384,7 @@ void CBibleReadWindow::reload(CSwordBackend::SetupChangedReason reason) {
bool CBibleReadWindow::eventFilter( QObject* o, QEvent* e) {
const bool ret = CLexiconReadWindow::eventFilter(o, e);
- // Q_ASSERT(o->inherits("CDisplayWindow"));
+ // BT_ASSERT(o->inherits("CDisplayWindow"));
// qWarning("class: %s", o->className());
if (e && (e->type() == QEvent::FocusIn)) { //sync other windows to this active
@@ -452,7 +408,7 @@ void CBibleReadWindow::lookupSwordKey( CSwordKey* newKey ) {
}
void CBibleReadWindow::syncWindows() {
- foreach (QMdiSubWindow* subWindow, mdi()->subWindowList()) {
+ Q_FOREACH(QMdiSubWindow * const 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 99c98fb..0be8c6d 100644
--- a/src/frontend/displaywindow/cbiblereadwindow.h
+++ b/src/frontend/displaywindow/cbiblereadwindow.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -14,8 +14,11 @@
#include "frontend/displaywindow/clexiconreadwindow.h"
+#include <QAction>
+#include "frontend/displaywindow/btactioncollection.h"
+#include "util/btconnect.h"
+
-class BtActionCollection;
class CSwordKey;
class CSwordVerseKey;
class CTransliterationButton;
@@ -33,30 +36,33 @@ class CBibleReadWindow: public CLexiconReadWindow {
inline CBibleReadWindow(const QList<CSwordModuleInfo*> & modules, CMDIArea* parent)
: CLexiconReadWindow(modules, parent) {}
- virtual void storeProfileSettings(const QString & windowGroup);
- virtual void applyProfileSettings(const QString & windowGroup);
+ CSwordModuleInfo::ModuleType moduleType() const override
+ { return CSwordModuleInfo::Bible; }
+
+ void storeProfileSettings(QString const & windowGroup) const override;
+ void applyProfileSettings(const QString & windowGroup) override;
static void insertKeyboardActions( BtActionCollection* const a );
protected: /* Methods: */
- virtual void initActions();
- virtual void initToolbars();
- virtual void initConnections();
- virtual void initView();
- /** Called to add actions to mainWindow toolbars */
- virtual void setupMainWindowToolBars();
- /**
- * 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);
+ template <typename ... Args>
+ QAction & initAction(QString actionName, Args && ... args) {
+ QAction & action = m_actionCollection->action(std::move(actionName));
+ BT_CONNECT(&action,
+ &QAction::triggered,
+ std::forward<Args>(args)...);
+ addAction(&action);
+ return action;
+ }
+
+ void initActions() override;
+ void initToolbars() override;
+ void initConnections() override;
+ void initView() override;
+ void setupMainWindowToolBars() override;
+ void setupPopupMenu() override;
+ void updatePopupMenu() override;
+ bool eventFilter( QObject* o, QEvent* e) override;
struct {
QAction* selectAll;
@@ -99,17 +105,15 @@ class CBibleReadWindow: public CLexiconReadWindow {
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);
+
+ void reload(CSwordBackend::SetupChangedReason reason) override;
protected slots:
/**
* Copies the current chapter into the clipboard.
*/
- void copyDisplayedText();
+ void copyDisplayedText() override;
/**
* Saves the chapter as valid HTML page.
*/
@@ -118,7 +122,7 @@ class CBibleReadWindow: public CLexiconReadWindow {
* Saves the chapter as valid HTML page.
*/
void saveChapterPlain();
- virtual void lookupSwordKey( CSwordKey* newKey );
+ void lookupSwordKey(CSwordKey * newKey) override;
void syncWindows();
private: /* Methods: */
diff --git a/src/frontend/displaywindow/cbookreadwindow.cpp b/src/frontend/displaywindow/cbookreadwindow.cpp
index fade4d5..6c68264 100644
--- a/src/frontend/displaywindow/cbookreadwindow.cpp
+++ b/src/frontend/displaywindow/cbookreadwindow.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -21,6 +21,8 @@
#include "frontend/displaywindow/btmodulechooserbar.h"
#include "frontend/displaywindow/btdisplaysettingsbutton.h"
#include "frontend/keychooser/cbooktreechooser.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
#include "util/tool.h"
@@ -28,16 +30,16 @@
void CBookReadWindow::applyProfileSettings(const QString & windowGroup) {
CLexiconReadWindow::applyProfileSettings(windowGroup);
- Q_ASSERT(m_treeAction);
- Q_ASSERT(windowGroup.endsWith('/'));
+ BT_ASSERT(m_treeAction);
+ BT_ASSERT(windowGroup.endsWith('/'));
if (btConfig().sessionValue<bool>(windowGroup + "treeShown", true) != m_treeAction->isChecked())
m_treeAction->activate(QAction::Trigger);
}
-void CBookReadWindow::storeProfileSettings(const QString & windowGroup) {
+void CBookReadWindow::storeProfileSettings(QString const & windowGroup) const {
CLexiconReadWindow::storeProfileSettings(windowGroup);
- Q_ASSERT(windowGroup.endsWith('/'));
+ BT_ASSERT(windowGroup.endsWith('/'));
btConfig().setSessionValue(windowGroup + "treeShown", m_treeAction->isChecked());
}
@@ -47,17 +49,12 @@ void CBookReadWindow::initActions() {
insertKeyboardActions(ac);
//cleanup, not a clean oo-solution
- QAction *a = ac->action("nextEntry");
- Q_ASSERT(a != 0);
- a->setEnabled(false);
- a = ac->action("previousEntry");
- Q_ASSERT(a != 0);
- a->setEnabled(false);
-
- m_treeAction = ac->action("toggleTree");
- Q_ASSERT(m_treeAction != 0);
- QObject::connect(m_treeAction, SIGNAL(triggered()),
- this, SLOT(treeToggled()));
+ ac->action("nextEntry").setEnabled(false);
+ ac->action("previousEntry").setEnabled(false);
+
+ m_treeAction = &ac->action("toggleTree");
+ BT_ASSERT(m_treeAction);
+ BT_CONNECT(m_treeAction, SIGNAL(triggered()), this, SLOT(treeToggled()));
addAction(m_treeAction);
ac->readShortcuts("Book shortcuts");
@@ -69,7 +66,7 @@ void CBookReadWindow::insertKeyboardActions( BtActionCollection* const a ) {
qaction = new QAction( /* QIcon(CResMgr::displaywindows::bookWindow::toggleTree::icon), */
tr("Toggle tree view"), a);
qaction->setCheckable(true);
- qaction->setShortcut(CResMgr::displaywindows::bookWindow::toggleTree::accel);
+ // qaction->setShortcut(CResMgr::displaywindows::bookWindow::toggleTree::accel);
a->addAction("toggleTree", qaction);
}
@@ -77,9 +74,12 @@ void CBookReadWindow::insertKeyboardActions( BtActionCollection* const a ) {
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*)));
+ BT_CONNECT(m_treeChooser, SIGNAL(keyChanged(CSwordKey *)),
+ this, SLOT(lookupSwordKey(CSwordKey *)));
+ BT_CONNECT(m_treeChooser, SIGNAL(keyChanged(CSwordKey *)),
+ keyChooser(), SLOT(updateKey(CSwordKey *)));
+ BT_CONNECT(keyChooser(), SIGNAL(keyChanged(CSwordKey *)),
+ m_treeChooser, SLOT(updateKey(CSwordKey *)));
}
/** Init the view */
@@ -112,8 +112,8 @@ void CBookReadWindow::initView() {
}
void CBookReadWindow::initToolbars() {
- Q_ASSERT(m_treeAction);
- Q_ASSERT(m_actions.backInHistory);
+ BT_ASSERT(m_treeAction);
+ BT_ASSERT(m_actions.backInHistory);
mainToolBar()->addAction(m_actions.backInHistory);
mainToolBar()->addAction(m_actions.forwardInHistory);
@@ -125,10 +125,10 @@ void CBookReadWindow::initToolbars() {
BtDisplaySettingsButton* button = new BtDisplaySettingsButton(buttonsToolBar());
setDisplaySettingsButton(button);
buttonsToolBar()->addWidget(button); // Display settings
- QAction *action = actionCollection()->action(CResMgr::displaywindows::general::search::actionName);
- if (action != 0) {
- buttonsToolBar()->addAction(action); // Search
- }
+ // Search:
+ buttonsToolBar()->addAction(
+ &actionCollection()->action(
+ CResMgr::displaywindows::general::search::actionName));
}
void CBookReadWindow::setupMainWindowToolBars() {
@@ -137,10 +137,10 @@ void CBookReadWindow::setupMainWindowToolBars() {
btMainWindow()->navToolBar()->addAction(m_actions.forwardInHistory); //2nd button
CKeyChooser* keyChooser = CKeyChooser::createInstance(modules(), history(), key(), btMainWindow()->navToolBar() );
btMainWindow()->navToolBar()->addWidget(keyChooser);
- bool ok = connect(keyChooser, SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*)));
- Q_ASSERT(ok);
- ok = connect(this, SIGNAL(sigKeyChanged(CSwordKey*)), keyChooser, SLOT(updateKey(CSwordKey*)) );
- Q_ASSERT(ok);
+ BT_CONNECT(keyChooser, SIGNAL(keyChanged(CSwordKey *)),
+ this, SLOT(lookupSwordKey(CSwordKey *)));
+ BT_CONNECT(this, SIGNAL(sigKeyChanged(CSwordKey *)),
+ keyChooser, SLOT(updateKey(CSwordKey *)));
// Works toolbar
btMainWindow()->worksToolBar()->setModules(getModuleList(), modules().first()->type(), this);
@@ -150,16 +150,16 @@ void CBookReadWindow::setupMainWindowToolBars() {
BtDisplaySettingsButton* button = new BtDisplaySettingsButton(buttonsToolBar());
setDisplaySettingsButton(button);
btMainWindow()->toolsToolBar()->addWidget(button); // Display settings
- QAction *action = actionCollection()->action(CResMgr::displaywindows::general::search::actionName);
- if (action != 0) {
- btMainWindow()->toolsToolBar()->addAction(action); // Search
- }
+ // Search:
+ btMainWindow()->toolsToolBar()->addAction(
+ &actionCollection()->action(
+ CResMgr::displaywindows::general::search::actionName));
}
/** Is called when the action was executed to toggle the tree view. */
void CBookReadWindow::treeToggled() {
if (m_treeAction->isChecked()) {
- m_treeChooser->show();
+ m_treeChooser->doShow();
}
else {
m_treeChooser->hide();
diff --git a/src/frontend/displaywindow/cbookreadwindow.h b/src/frontend/displaywindow/cbookreadwindow.h
index 63f3922..e11ab12 100644
--- a/src/frontend/displaywindow/cbookreadwindow.h
+++ b/src/frontend/displaywindow/cbookreadwindow.h
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's BtActionCollection code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime BtActionCollection code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -25,37 +25,33 @@ class CBookReadWindow: public CLexiconReadWindow {
inline CBookReadWindow(const QList<CSwordModuleInfo *> & modules, CMDIArea * parent)
: CLexiconReadWindow(modules, parent)
- , m_treeAction(0)
- , m_treeChooser(0) {}
+ , m_treeAction(nullptr)
+ , m_treeChooser(nullptr) {}
- virtual void storeProfileSettings(const QString & windowGroup);
- virtual void applyProfileSettings(const QString & windowGroup);
+ CSwordModuleInfo::ModuleType moduleType() const override
+ { return CSwordModuleInfo::GenericBook; }
+
+ void storeProfileSettings(QString const & windowGroup) const override;
+ void applyProfileSettings(const QString & windowGroup) override;
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);
+ void reload(CSwordBackend::SetupChangedReason reason) override;
protected: /* Methods: */
- virtual void initActions();
- virtual void initToolbars();
- virtual void initConnections();
- virtual void initView();
- /** Called to add actions to mainWindow toolbars */
- virtual void setupMainWindowToolBars();
+ void initActions() override;
+ void initToolbars() override;
+ void initConnections() override;
+ void initView() override;
+ void setupMainWindowToolBars() override;
- virtual void setupPopupMenu();
+ void setupPopupMenu() override;
protected slots:
- /**
- * Reimplementation to take care of the tree chooser.
- */
- virtual void modulesChanged();
+ void modulesChanged() override;
private slots:
diff --git a/src/frontend/displaywindow/ccommentaryreadwindow.cpp b/src/frontend/displaywindow/ccommentaryreadwindow.cpp
index 1beb5c5..86313dc 100644
--- a/src/frontend/displaywindow/ccommentaryreadwindow.cpp
+++ b/src/frontend/displaywindow/ccommentaryreadwindow.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -21,8 +21,8 @@
#include "frontend/displaywindow/btactioncollection.h"
#include "frontend/displaywindow/btmodulechooserbar.h"
#include "frontend/keychooser/ckeychooser.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
void CCommentaryReadWindow::insertKeyboardActions(BtActionCollection* const a) {
@@ -52,7 +52,7 @@ void CCommentaryReadWindow::insertKeyboardActions(BtActionCollection* const a) {
qaction->setShortcut(CResMgr::displaywindows::bibleWindow::previousVerse::accel);
a->addAction("previousVerse", qaction);
- qaction = new QAction(QIcon(util::getIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon)),
+ qaction = new QAction(CResMgr::displaywindows::commentaryWindow::syncWindow::icon(),
tr("Synchronize"), a);
qaction->setCheckable(true);
qaction->setShortcut(CResMgr::displaywindows::commentaryWindow::syncWindow::accel);
@@ -65,54 +65,27 @@ void CCommentaryReadWindow::initActions() {
BtActionCollection* ac = actionCollection();
insertKeyboardActions(ac);
- //cleanup, not a clean oo-solution
- QAction *qaction = ac->action("nextEntry");
- Q_ASSERT(qaction != 0);
- qaction->setEnabled(false);
- qaction = ac->action("previousEntry");
- Q_ASSERT(qaction != 0);
- qaction->setEnabled(false);
-
- qaction = ac->action("nextBook");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()),
- this, SLOT(nextBook()));
- addAction(qaction);
-
- qaction = ac->action("previousBook");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()),
- this, SLOT(previousBook()));
- addAction(qaction);
-
- qaction = ac->action("nextChapter");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()),
- this, SLOT(nextChapter()));
- addAction(qaction);
-
- qaction = ac->action("previousChapter");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()),
- this, SLOT(previousChapter()));
- addAction(qaction);
-
- qaction = ac->action("nextVerse");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()),
- this, SLOT(nextVerse()));
- addAction(qaction);
-
- qaction = ac->action("previousVerse");
- Q_ASSERT(qaction != 0);
- QObject::connect(qaction, SIGNAL(triggered()),
- this, SLOT(previousVerse()));
- addAction(qaction);
-
- qaction = ac->action(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName);
- Q_ASSERT(qaction != 0);
- m_syncButton = qaction;
- addAction(qaction);
+ ac->action("nextEntry").setEnabled(false);
+ ac->action("previousEntry").setEnabled(false);
+
+ auto const initAction = [this, ac](QString actionName,
+ void (CCommentaryReadWindow::* slot)())
+ {
+ QAction & action = ac->action(std::move(actionName));
+ BT_CONNECT(&action, &QAction::triggered, this, slot);
+ addAction(&action);
+ };
+
+ initAction("nextBook", &CCommentaryReadWindow::nextBook);
+ initAction("previousBook", &CCommentaryReadWindow::previousBook);
+ initAction("nextChapter", &CCommentaryReadWindow::nextChapter);
+ initAction("previousChapter", &CCommentaryReadWindow::previousChapter);
+ initAction("nextVerse", &CCommentaryReadWindow::nextVerse);
+ initAction("previousVerse", &CCommentaryReadWindow::previousVerse);
+
+ QAction & qaction = ac->action(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName);
+ m_syncButton = &qaction;
+ addAction(&qaction);
actionCollection()->readShortcuts("Commentary shortcuts");
}
@@ -120,16 +93,18 @@ void CCommentaryReadWindow::initActions() {
void CCommentaryReadWindow::applyProfileSettings(const QString & windowGroup) {
CLexiconReadWindow::applyProfileSettings(windowGroup);
- Q_ASSERT(windowGroup.endsWith('/'));
- Q_ASSERT(m_syncButton);
+ BT_ASSERT(windowGroup.endsWith('/'));
+ BT_ASSERT(m_syncButton);
m_syncButton->setChecked(btConfig().sessionValue<bool>(windowGroup + "syncEnabled", false));
}
-void CCommentaryReadWindow::storeProfileSettings(const QString & windowGroup) {
+void CCommentaryReadWindow::storeProfileSettings(QString const & windowGroup)
+ const
+{
CLexiconReadWindow::storeProfileSettings(windowGroup);
- Q_ASSERT(windowGroup.endsWith('/'));
- Q_ASSERT(m_syncButton);
+ BT_ASSERT(windowGroup.endsWith('/'));
+ BT_ASSERT(m_syncButton);
btConfig().setSessionValue(windowGroup + "syncEnabled", m_syncButton->isChecked());
}
@@ -157,7 +132,7 @@ void CCommentaryReadWindow::reload(CSwordBackend::SetupChangedReason reason) {
/** rapper around key() to return the right type of key. */
CSwordVerseKey* CCommentaryReadWindow::verseKey() {
CSwordVerseKey* k = dynamic_cast<CSwordVerseKey*>(CDisplayWindow::key());
- Q_ASSERT(k);
+ BT_ASSERT(k);
return k;
}
diff --git a/src/frontend/displaywindow/ccommentaryreadwindow.h b/src/frontend/displaywindow/ccommentaryreadwindow.h
index 06cbd93..3dc7029 100644
--- a/src/frontend/displaywindow/ccommentaryreadwindow.h
+++ b/src/frontend/displaywindow/ccommentaryreadwindow.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -33,33 +33,32 @@ class CCommentaryReadWindow : public CLexiconReadWindow {
inline CCommentaryReadWindow(const QList<CSwordModuleInfo *> & modules, CMDIArea * parent)
: CLexiconReadWindow(modules, parent) {}
- virtual void storeProfileSettings(const QString & windowGroup);
- virtual void applyProfileSettings(const QString & windowGroup);
- virtual bool syncAllowed() const;
+ CSwordModuleInfo::ModuleType moduleType() const override
+ { return CSwordModuleInfo::Commentary; }
- public slots: // Public slots
+ void storeProfileSettings(QString const & windowGroup) const override;
+ void applyProfileSettings(const QString & windowGroup) override;
+ bool syncAllowed() const override;
+
+ 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);
+ void reload(CSwordBackend::SetupChangedReason) override;
protected:
- virtual void initActions();
- virtual void initToolbars();
- /** Called to add actions to mainWindow toolbars */
- virtual void setupMainWindowToolBars();
+ void initActions() override;
+ void initToolbars() override;
+ void setupMainWindowToolBars() override;
private:
QAction* m_syncButton;
CSwordVerseKey* verseKey();
protected:
- virtual void setupPopupMenu();
+ void setupPopupMenu() override;
};
#endif
diff --git a/src/frontend/displaywindow/cdisplaywindow.cpp b/src/frontend/displaywindow/cdisplaywindow.cpp
index a584d6e..1285205 100644
--- a/src/frontend/displaywindow/cdisplaywindow.cpp
+++ b/src/frontend/displaywindow/cdisplaywindow.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -22,59 +22,65 @@
#include "frontend/cmdiarea.h"
#include "frontend/display/cdisplay.h"
#include "frontend/displaywindow/bttoolbarpopupaction.h"
-#include "frontend/displaywindow/btactioncollection.h"
#include "frontend/displaywindow/btmodulechooserbar.h"
#include "frontend/displaywindow/btdisplaysettingsbutton.h"
#include "frontend/keychooser/ckeychooser.h"
#include "frontend/keychooser/bthistory.h"
#include "frontend/searchdialog/csearchdialog.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
+
+
+namespace {
+
+inline QWidget * getProfileWindow(QWidget * w) {
+ for (; w; w = w->parentWidget())
+ if (QMdiSubWindow * const sw = qobject_cast<QMdiSubWindow *>(w))
+ return sw;
+ return nullptr;
+}
+
+}
CDisplayWindow::CDisplayWindow(const QList<CSwordModuleInfo *> & modules, CMDIArea * parent)
: QMainWindow(parent),
- m_actionCollection(0),
+ m_actionCollection(nullptr),
m_mdi(parent),
- m_keyChooser(0),
- m_swordKey(0),
+ m_keyChooser(nullptr),
+ m_swordKey(nullptr),
m_isReady(false),
- m_moduleChooserBar(0),
- m_mainToolBar(0),
- m_buttonsToolBar(0),
- m_formatToolBar(0),
- m_headerBar(0),
- m_popupMenu(0),
- m_displayWidget(0),
- m_history(0) {
+ m_moduleChooserBar(nullptr),
+ m_mainToolBar(nullptr),
+ m_buttonsToolBar(nullptr),
+ m_formatToolBar(nullptr),
+ m_headerBar(nullptr),
+ m_popupMenu(nullptr),
+ m_displayWidget(nullptr),
+ m_history(nullptr) {
setAttribute(Qt::WA_DeleteOnClose); //we want to destroy this window when it is closed
m_actionCollection = new BtActionCollection(this);
setModules(modules);
// Connect this to the backend module list changes
- connect(CSwordBackend::instance(),
- SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)),
- SLOT(reload(CSwordBackend::SetupChangedReason)));
+ BT_CONNECT(CSwordBackend::instance(),
+ SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)),
+ SLOT(reload(CSwordBackend::SetupChangedReason)));
BibleTime* mainwindow = btMainWindow();
- connect(mainwindow, SIGNAL(toggledTextWindowHeader(bool)), SLOT(slotShowHeader(bool)) );
- connect(mainwindow, SIGNAL(toggledTextWindowNavigator(bool)), SLOT(slotShowNavigator(bool)) );
- connect(mainwindow, SIGNAL(toggledTextWindowToolButtons(bool)), SLOT(slotShowToolButtons(bool)) );
- connect(mainwindow, SIGNAL(toggledTextWindowModuleChooser(bool)), SLOT(slotShowModuleChooser(bool)) );
- connect(mainwindow, SIGNAL(toggledTextWindowFormatToolbar(bool)), SLOT(slotShowFormatToolBar(bool)) );
+ BT_CONNECT(mainwindow, SIGNAL(toggledTextWindowHeader(bool)),
+ SLOT(slotShowHeader(bool)));
+ BT_CONNECT(mainwindow, SIGNAL(toggledTextWindowNavigator(bool)),
+ SLOT(slotShowNavigator(bool)));
+ BT_CONNECT(mainwindow, SIGNAL(toggledTextWindowToolButtons(bool)),
+ SLOT(slotShowToolButtons(bool)));
+ BT_CONNECT(mainwindow, SIGNAL(toggledTextWindowModuleChooser(bool)),
+ SLOT(slotShowModuleChooser(bool)));
+ BT_CONNECT(mainwindow, SIGNAL(toggledTextWindowFormatToolbar(bool)),
+ SLOT(slotShowFormatToolBar(bool)));
}
CDisplayWindow::~CDisplayWindow() {
delete m_swordKey;
- m_swordKey = 0;
-}
-
-QWidget * CDisplayWindow::getProfileWindow() const {
- for (QWidget * w = parentWidget(); w; w = w->parentWidget()) {
- QMdiSubWindow * sw = qobject_cast<QMdiSubWindow *>(w);
- if (sw)
- return sw;
- }
- return const_cast<CDisplayWindow *>(this);
+ m_swordKey = nullptr;
}
BibleTime* CDisplayWindow::btMainWindow() {
@@ -83,14 +89,14 @@ BibleTime* CDisplayWindow::btMainWindow() {
void CDisplayWindow::setToolBarsHidden() {
// Hide current window toolbars
- if (mainToolBar())
- mainToolBar()->setHidden(true);
- if (buttonsToolBar())
- buttonsToolBar()->setHidden(true);
- if (moduleChooserBar())
- moduleChooserBar()->setHidden(true);
- if (formatToolBar())
- formatToolBar()->setHidden(true);
+ if (m_mainToolBar)
+ m_mainToolBar->setHidden(true);
+ if (m_buttonsToolBar)
+ m_buttonsToolBar->setHidden(true);
+ if (m_moduleChooserBar)
+ m_moduleChooserBar->setHidden(true);
+ if (m_formatToolBar)
+ m_formatToolBar->setHidden(true);
}
void CDisplayWindow::clearMainWindowToolBars() {
// Clear main window toolbars, except for works toolbar
@@ -114,17 +120,18 @@ const QString CDisplayWindow::windowCaption() {
}
/** Returns the used modules as a pointer list */
-const QList<const CSwordModuleInfo*> CDisplayWindow::modules() const {
+const BtConstModuleList CDisplayWindow::modules() const {
return CSwordBackend::instance()->getConstPointerList(m_modules);
}
/** Store the settings of this window in the given CProfileWindow object. */
-void CDisplayWindow::storeProfileSettings(const QString & windowGroup) {
+void CDisplayWindow::storeProfileSettings(QString const & windowGroup) const {
BtConfig & conf = btConfig();
conf.beginGroup(windowGroup);
- QWidget * w = getProfileWindow();
+ QWidget const * const w = getProfileWindow(parentWidget());
+ BT_ASSERT(w);
/**
\note We don't use saveGeometry/restoreGeometry for MDI subwindows,
@@ -133,7 +140,10 @@ void CDisplayWindow::storeProfileSettings(const QString & windowGroup) {
*/
const QRect rect(w->x(), w->y(), w->width(), w->height());
conf.setSessionValue<QRect>("windowRect", rect);
-
+ conf.setSessionValue<bool>("staysOnTop",
+ w->windowFlags() & Qt::WindowStaysOnTopHint);
+ conf.setSessionValue<bool>("staysOnBottom",
+ w->windowFlags() & Qt::WindowStaysOnBottomHint);
conf.setSessionValue("maximized", w->isMaximized());
bool hasFocus = (w == dynamic_cast<CDisplayWindow *>(mdi()->activeSubWindow()));
@@ -141,11 +151,8 @@ void CDisplayWindow::storeProfileSettings(const QString & windowGroup) {
// conf.setSessionValue("type", static_cast<int>(modules().first()->type()));
// Save current key:
- if (key()) {
- CSwordKey * k = key();
- sword::VerseKey * vk = dynamic_cast<sword::VerseKey*>(k);
- QString oldLang;
- if (vk) {
+ if (CSwordKey * const k = key()) {
+ if (sword::VerseKey * const vk = dynamic_cast<sword::VerseKey *>(k)) {
// Save keys in english only:
const QString oldLang = QString::fromLatin1(vk->getLocale());
vk->setLocale("en");
@@ -157,10 +164,10 @@ void CDisplayWindow::storeProfileSettings(const QString & windowGroup) {
}
// Save list of modules:
- QStringList mods;
- Q_FOREACH (const CSwordModuleInfo * module, modules())
- mods.append(module->name());
- conf.setSessionValue("modules", mods);
+ conf.setSessionValue("modules", m_modules);
+
+ // Default for "not a write window":
+ conf.setSessionValue("writeWindowType", int(0));
conf.endGroup();
}
@@ -170,7 +177,8 @@ void CDisplayWindow::applyProfileSettings(const QString & windowGroup) {
conf.beginGroup(windowGroup);
setUpdatesEnabled(false);
- QWidget * w = getProfileWindow();
+ QWidget * const w = getProfileWindow(parentWidget());
+ BT_ASSERT(w);
/**
\note We don't use restoreGeometry/saveGeometry for MDI subwindows,
@@ -180,7 +188,10 @@ void CDisplayWindow::applyProfileSettings(const QString & windowGroup) {
const QRect rect = conf.sessionValue<QRect>("windowRect");
w->resize(rect.width(), rect.height());
w->move(rect.x(), rect.y());
-
+ if (conf.sessionValue<bool>("staysOnTop", false))
+ w->setWindowFlags(w->windowFlags() | Qt::WindowStaysOnTopHint);
+ if (conf.sessionValue<bool>("staysOnBottom", false))
+ w->setWindowFlags(w->windowFlags() | Qt::WindowStaysOnBottomHint);
if (conf.sessionValue<bool>("maximized"))
w->showMaximized();
@@ -205,13 +216,13 @@ void CDisplayWindow::insertKeyboardActions( BtActionCollection* a ) {
actn->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L));
a->addAction("openLocation", actn);
- actn = new QAction(QIcon(util::getIcon(CResMgr::displaywindows::general::search::icon)),
+ actn = new QAction(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::getIcon(CResMgr::displaywindows::general::backInHistory::icon)),
+ CResMgr::displaywindows::general::backInHistory::icon(),
tr("Back in history"),
a
);
@@ -219,7 +230,7 @@ void CDisplayWindow::insertKeyboardActions( BtActionCollection* a ) {
a->addAction(CResMgr::displaywindows::general::backInHistory::actionName, action);
action = new BtToolBarPopupAction(
- QIcon(util::getIcon(CResMgr::displaywindows::general::forwardInHistory::icon)),
+ CResMgr::displaywindows::general::forwardInHistory::icon(),
tr("Forward in history"),
a
);
@@ -232,62 +243,39 @@ void CDisplayWindow::initActions() {
CDisplayWindow::insertKeyboardActions(ac);
- QAction* actn = ac->action(CResMgr::displaywindows::general::search::actionName);
- Q_ASSERT(actn != 0);
- QObject::connect(actn, SIGNAL(triggered()),
- this, SLOT(slotSearchInModules()));
-
- CDisplayConnections* conn = displayWidget()->connectionsProxy();
-
- actn = ac->action("openLocation");
- Q_ASSERT(actn != 0);
- QObject::connect(actn, SIGNAL(triggered()),
- this, SLOT(setFocusKeyChooser()));
- addAction(actn);
-
- actn = ac->action("selectAll");
- Q_ASSERT(actn != 0);
- QObject::connect(actn, SIGNAL(triggered()),
- conn, SLOT(selectAll()));
- addAction(actn);
-
- actn = ac->action("copySelectedText");
- Q_ASSERT(actn != 0);
- QObject::connect(actn, SIGNAL(triggered()),
- conn, SLOT(copySelection()));
- addAction(actn);
-
- actn = ac->action("findText");
- Q_ASSERT(actn != 0);
- QObject::connect(actn, SIGNAL(triggered()),
- conn, SLOT(openFindTextDialog()));
- addAction(actn);
-
- actn = ac->action(CResMgr::displaywindows::general::backInHistory::actionName);
- Q_ASSERT(actn != 0);
- bool ok = QObject::connect(actn, SIGNAL(triggered()),
- keyChooser()->history(), SLOT(back()));
- Q_ASSERT(ok);
- addAction(actn);
-
- actn = ac->action(CResMgr::displaywindows::general::forwardInHistory::actionName);
- Q_ASSERT(actn != 0);
- ok = QObject::connect(actn, SIGNAL(triggered()),
- keyChooser()->history(), SLOT(fw()));
- Q_ASSERT(ok);
- addAction(actn);
+ namespace DWG = CResMgr::displaywindows::general;
+ initAction(DWG::search::actionName,
+ this,
+ &CDisplayWindow::slotSearchInModules);
+ initAddAction("openLocation", this, &CDisplayWindow::setFocusKeyChooser);
+ CDisplayConnections * const conn = displayWidget()->connectionsProxy();
+ initAddAction("selectAll",
+ conn,
+ &CDisplayConnections::selectAll);
+ initAddAction("copySelectedText",
+ conn,
+ &CDisplayConnections::copySelection);
+ initAddAction("findText",
+ conn,
+ &CDisplayConnections::openFindTextDialog);
+ initAddAction(DWG::backInHistory::actionName,
+ keyChooser()->history(),
+ &BTHistory::back);
+ initAddAction(DWG::forwardInHistory::actionName,
+ keyChooser()->history(),
+ &BTHistory::fw);
ac->readShortcuts("Displaywindow shortcuts");
}
/** 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 (!CSwordBackend::instance()->findModuleByName(it.next())) {
- it.remove();
- }
+ { // First make sure all used Sword modules are still present:
+ CSwordBackend & backend = *(CSwordBackend::instance());
+ QMutableStringListIterator it(m_modules);
+ while (it.hasNext())
+ if (!backend.findModuleByName(it.next()))
+ it.remove();
}
if (m_modules.isEmpty()) {
@@ -295,12 +283,13 @@ void CDisplayWindow::reload(CSwordBackend::SetupChangedReason) {
return;
}
- if (keyChooser()) keyChooser()->setModules( modules(), false );
+ if (CKeyChooser * const kc = keyChooser())
+ kc->setModules(modules(), false);
lookup();
- actionCollection()->readShortcuts("DisplayWindow shortcuts");
- actionCollection()->readShortcuts("Readwindow shortcuts");
+ m_actionCollection->readShortcuts("DisplayWindow shortcuts");
+ m_actionCollection->readShortcuts("Readwindow shortcuts");
emit sigModuleListSet(m_modules);
}
@@ -339,11 +328,6 @@ void CDisplayWindow::setFilterOptions(const FilterOptions &filterOptions) {
emit sigFilterOptionsChanged(m_filterOptions);
}
-/** Set the ready status */
-void CDisplayWindow::setReady(bool ready) {
- m_isReady = ready;
-}
-
/** Returns true if the window may be closed. */
bool CDisplayWindow::queryClose() {
return true;
@@ -356,12 +340,12 @@ void CDisplayWindow::setKeyChooser( CKeyChooser* ck ) {
/** Sets the new sword key. */
void CDisplayWindow::setKey( CSwordKey* key ) {
- Q_ASSERT( key );
+ BT_ASSERT(key);
m_swordKey = key;
}
BTHistory* CDisplayWindow::history() {
- if (m_history == 0)
+ if (m_history == nullptr)
m_history = new BTHistory(this);
return m_history;
}
@@ -408,9 +392,8 @@ void CDisplayWindow::setHeaderBar( QToolBar* header ) {
void CDisplayWindow::setModules( const QList<CSwordModuleInfo*>& newModules ) {
m_modules.clear();
- foreach (CSwordModuleInfo* mod, newModules) {
+ Q_FOREACH(CSwordModuleInfo const * const 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! */
@@ -437,7 +420,7 @@ bool CDisplayWindow::init() {
emit sigFilterOptionsChanged(m_filterOptions);
emit sigModulesChanged(modules());
- setReady(true);
+ m_isReady = true;
return true;
}
@@ -468,23 +451,23 @@ void CDisplayWindow::setFormatToolBar( QToolBar* bar ) {
/** Sets the display settings button. */
void CDisplayWindow::setDisplaySettingsButton(BtDisplaySettingsButton *button) {
- connect(this, SIGNAL(sigDisplayOptionsChanged(const DisplayOptions&)),
- button, SLOT(setDisplayOptions(const DisplayOptions&)));
- connect(this, SIGNAL(sigFilterOptionsChanged(const FilterOptions&)),
- button, SLOT(setFilterOptions(const FilterOptions&)));
- connect(this, SIGNAL(sigModulesChanged(const QList<const CSwordModuleInfo*>&)),
- button, SLOT(setModules(const QList<const CSwordModuleInfo*>&)));
+ BT_CONNECT(this, SIGNAL(sigDisplayOptionsChanged(DisplayOptions const &)),
+ button, SLOT(setDisplayOptions(DisplayOptions const &)));
+ BT_CONNECT(this, SIGNAL(sigFilterOptionsChanged(FilterOptions const &)),
+ button, SLOT(setFilterOptions(FilterOptions const &)));
+ BT_CONNECT(this, SIGNAL(sigModulesChanged(BtConstModuleList const &)),
+ button, SLOT(setModules(BtConstModuleList const &)));
button->setDisplayOptions(displayOptions(), false);
button->setFilterOptions(filterOptions(), false);
button->setModules(modules());
- connect(button, SIGNAL(sigFilterOptionsChanged(const FilterOptions&)),
- this, SLOT(setFilterOptions(const FilterOptions&)));
- connect(button, SIGNAL(sigDisplayOptionsChanged(const DisplayOptions&)),
- this, SLOT(setDisplayOptions(const DisplayOptions&)));
- connect(button, SIGNAL(sigChanged()),
- this, SLOT(lookup()));
+ BT_CONNECT(button, SIGNAL(sigFilterOptionsChanged(FilterOptions const &)),
+ this, SLOT(setFilterOptions(FilterOptions const &)));
+ BT_CONNECT(button, SIGNAL(sigDisplayOptionsChanged(DisplayOptions const &)),
+ this, SLOT(setDisplayOptions(DisplayOptions const &)));
+ BT_CONNECT(button, SIGNAL(sigChanged()),
+ this, SLOT(lookup()));
}
void CDisplayWindow::slotShowHeader(bool show) {
@@ -536,19 +519,16 @@ void CDisplayWindow::lookupModKey( const QString& moduleName, const QString& key
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);
-
BibleTime *mainWindow = btMainWindow();
- Q_ASSERT(mainWindow != 0);
- mainWindow->createReadDisplayWindow(mList, keyName);
+ BT_ASSERT(mainWindow);
+ mainWindow->createReadDisplayWindow(m, 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());
+ BT_ASSERT(modules().first());
lookupModKey(modules().first()->name(), keyName);
}
@@ -564,7 +544,8 @@ QMenu* CDisplayWindow::popup() {
// qWarning("CReadWindow::popup()");
if (!m_popupMenu) {
m_popupMenu = new QMenu(this);
- connect(m_popupMenu, SIGNAL(aboutToShow()), this, SLOT(updatePopupMenu()));
+ BT_CONNECT(m_popupMenu, SIGNAL(aboutToShow()),
+ this, SLOT(updatePopupMenu()));
if (displayWidget()) {
displayWidget()->installPopup(m_popupMenu);
}
diff --git a/src/frontend/displaywindow/cdisplaywindow.h b/src/frontend/displaywindow/cdisplaywindow.h
index 72199d1..6728d95 100644
--- a/src/frontend/displaywindow/cdisplaywindow.h
+++ b/src/frontend/displaywindow/cdisplaywindow.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -14,12 +14,15 @@
#include <QMainWindow>
+#include <QAction>
#include <QStringList>
+#include "backend/btglobal.h"
#include "backend/managers/cswordbackend.h"
-#include "btglobal.h"
+#include "frontend/displaywindow/btactioncollection.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
-class BtActionCollection;
class CDisplay;
class BtDisplaySettingsButton;
class CKeyChooser;
@@ -46,9 +49,6 @@ class CDisplayWindow : public QMainWindow {
/** Insert the keyboard accelerators of this window into the given actioncollection.*/
static void insertKeyboardActions( BtActionCollection* const a );
- /** Returns a pointer to the parent widget of type QMdiSubWindow or pointer to self if none found. */
- QWidget * getProfileWindow() const;
-
/** Returns pointer to the mdi area object.*/
inline CMDIArea *mdi() const {
return m_mdi;
@@ -58,7 +58,7 @@ class CDisplayWindow : public QMainWindow {
const QString windowCaption();
/** Returns the used modules as a pointer list.*/
- const QList<const CSwordModuleInfo*> modules() const;
+ const BtConstModuleList modules() const;
/** Returns the used modules as a string list. */
inline const QStringList &getModuleList() const {
@@ -66,7 +66,7 @@ class CDisplayWindow : public QMainWindow {
}
/** Store the settings of this window in the given CProfileWindow object.*/
- virtual void storeProfileSettings(const QString & windowGroup);
+ virtual void storeProfileSettings(QString const & windowGroup) const;
/** Load the settings the given CProfileWindow object into this window.*/
virtual void applyProfileSettings(const QString & windowGroup);
@@ -81,9 +81,6 @@ class CDisplayWindow : public QMainWindow {
return m_filterOptions;
}
- /** Set the ready status. */
- void setReady(bool ready);
-
/** Returns true if the widget is ready for use. */
inline bool isReady() const {
return m_isReady;
@@ -105,7 +102,7 @@ class CDisplayWindow : public QMainWindow {
/** Returns the key of this display window. */
inline CSwordKey *key() const {
- Q_ASSERT(m_swordKey != 0);
+ BT_ASSERT(m_swordKey);
return m_swordKey;
}
@@ -113,7 +110,7 @@ class CDisplayWindow : public QMainWindow {
* Initialize the window. Call this method from the outside,
* because calling this in the constructor is not possible!
*/
- virtual bool init();
+ bool init();
/** Sets and inits the properties of the main navigation toolbar.*/
void setMainToolBar( QToolBar* bar );
@@ -149,7 +146,7 @@ class CDisplayWindow : public QMainWindow {
/** Returns the display widget used by this implementation of CDisplayWindow. */
virtual inline CDisplay *displayWidget() const {
- Q_ASSERT(m_displayWidget != 0);
+ BT_ASSERT(m_displayWidget);
return m_displayWidget;
}
@@ -160,9 +157,7 @@ class CDisplayWindow : public QMainWindow {
* 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;
- };
+ virtual bool syncAllowed() const { return false; }
/**
* Return pointer to the BibleTime main window
@@ -198,7 +193,7 @@ class CDisplayWindow : public QMainWindow {
void sigFilterOptionsChanged(const FilterOptions &filterOptions);
/** signal for change of modules */
- void sigModulesChanged(const QList<const CSwordModuleInfo*> &modules);
+ void sigModulesChanged(const BtConstModuleList &modules);
/** signal for sword key change */
void sigKeyChanged(CSwordKey* key);
@@ -232,7 +227,7 @@ class CDisplayWindow : public QMainWindow {
friend class CBibleReadWindow;
CDisplayWindow(const QList<CSwordModuleInfo *> & modules, CMDIArea * parent);
- virtual ~CDisplayWindow();
+ ~CDisplayWindow() override;
/**
\returns the display options used by this display window.
@@ -286,7 +281,7 @@ class CDisplayWindow : public QMainWindow {
/** Called to add actions to mainWindow toolbars */
virtual void setupMainWindowToolBars() = 0;
- virtual void closeEvent(QCloseEvent* e);
+ void closeEvent(QCloseEvent* e) override;
void setToolBarsHidden();
void clearMainWindowToolBars();
@@ -320,6 +315,19 @@ class CDisplayWindow : public QMainWindow {
void setFocusKeyChooser();
+ private: /* Methods: */
+
+ template <typename Name, typename ... Args>
+ inline QAction & initAction(Name && name, Args && ... args) {
+ QAction & a = m_actionCollection->action(std::forward<Name>(name));
+ BT_CONNECT(&a, &QAction::triggered, std::forward<Args>(args)...);
+ return a;
+ }
+
+ template <typename ... Args>
+ inline void initAddAction(Args && ... args)
+ { addAction(&initAction(std::forward<Args>(args)...)); }
+
private:
BtActionCollection* m_actionCollection;
CMDIArea* m_mdi;
diff --git a/src/frontend/displaywindow/cdisplaywindowfactory.cpp b/src/frontend/displaywindow/cdisplaywindowfactory.cpp
deleted file mode 100644
index 12059d1..0000000
--- a/src/frontend/displaywindow/cdisplaywindowfactory.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/displaywindow/cdisplaywindowfactory.h"
-
-#include "backend/drivers/cswordmoduleinfo.h"
-#include "frontend/displaywindow/cbiblereadwindow.h"
-#include "frontend/displaywindow/cbookreadwindow.h"
-#include "frontend/displaywindow/ccommentaryreadwindow.h"
-#include "frontend/displaywindow/chtmlwritewindow.h"
-#include "frontend/displaywindow/clexiconreadwindow.h"
-#include "frontend/displaywindow/cplainwritewindow.h"
-#include "frontend/displaywindow/creadwindow.h"
-#include "frontend/cmdiarea.h"
-
-
-CReadWindow* CDisplayWindowFactory::createReadInstance(const QList<CSwordModuleInfo *> & modules, CMDIArea * parent) {
- CReadWindow* win = 0;
- switch (modules.first()->type()) {
- case CSwordModuleInfo::Bible:
- win = new CBibleReadWindow(modules, parent);
- break;
- case CSwordModuleInfo::Commentary:
- win = new CCommentaryReadWindow(modules, parent);
- break;
- case CSwordModuleInfo::Lexicon:
- win = new CLexiconReadWindow(modules, parent);
- break;
- case CSwordModuleInfo::GenericBook:
- win = new CBookReadWindow(modules, parent);
- break;
- default:
- qWarning("unknown module type");
- break;
- }
- return win;
-}
-
-CPlainWriteWindow * CDisplayWindowFactory::createWriteInstance(const QList<CSwordModuleInfo *> & modules, CMDIArea * parent, CPlainWriteWindow::WriteWindowType type) {
- if (type == CPlainWriteWindow::HTMLWindow) {
- return new CHTMLWriteWindow(modules, parent);
- }
- else {
- return new CPlainWriteWindow(modules, parent);
- }
- return 0;
-}
-
-CSwordModuleInfo::ModuleType CDisplayWindowFactory::getModuleType(QObject* widget) {
- if (qobject_cast<CBibleReadWindow*>(widget) != 0 )
- return CSwordModuleInfo::Bible;
- if (qobject_cast<CCommentaryReadWindow*>(widget) != 0 )
- return CSwordModuleInfo::Commentary;
- if (qobject_cast<CBookReadWindow*>(widget) != 0 )
- return CSwordModuleInfo::GenericBook;
- if (qobject_cast<CLexiconReadWindow*>(widget) != 0 )
- return CSwordModuleInfo::Lexicon;
- return CSwordModuleInfo::Unknown;
-}
diff --git a/src/frontend/displaywindow/cdisplaywindowfactory.h b/src/frontend/displaywindow/cdisplaywindowfactory.h
deleted file mode 100644
index e065e50..0000000
--- a/src/frontend/displaywindow/cdisplaywindowfactory.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef CDISPLAYWINDOWFACTORY_H
-#define CDISPLAYWINDOWFACTORY_H
-
-#include "frontend/displaywindow/cdisplaywindow.h"
-#include "frontend/displaywindow/cplainwritewindow.h"
-
-
-class CReadWindow;
-class CSwordModuleInfo;
-
-/// \todo Make CDisplayWindowFactory a namespace instead?
-class CDisplayWindowFactory {
- public:
- static CReadWindow* createReadInstance(const QList<CSwordModuleInfo *> & modules, CMDIArea * parent);
- static CPlainWriteWindow* createWriteInstance(const QList<CSwordModuleInfo*> & modules, CMDIArea * parent, CPlainWriteWindow::WriteWindowType type = CPlainWriteWindow::HTMLWindow);
- static CSwordModuleInfo::ModuleType getModuleType(QObject* widget);
-
- private:
- CDisplayWindowFactory();
-};
-
-#endif
diff --git a/src/frontend/displaywindow/chtmlwritewindow.cpp b/src/frontend/displaywindow/chtmlwritewindow.cpp
index 20c8323..cff94f4 100644
--- a/src/frontend/displaywindow/chtmlwritewindow.cpp
+++ b/src/frontend/displaywindow/chtmlwritewindow.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -18,6 +18,8 @@
#include "frontend/displaywindow/btmodulechooserbar.h"
#include "frontend/keychooser/ckeychooser.h"
#include "frontend/messagedialog.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/directory.h"
#include "util/cresmgr.h"
@@ -27,7 +29,7 @@ CHTMLWriteWindow::CHTMLWriteWindow(const QList<CSwordModuleInfo *> & modules, CM
void CHTMLWriteWindow::initView() {
m_writeDisplay = new CHTMLWriteDisplay(this, this);
- Q_ASSERT(m_writeDisplay);
+ BT_ASSERT(m_writeDisplay);
setDisplayWidget(m_writeDisplay);
setCentralWidget(m_writeDisplay->view() );
@@ -47,8 +49,10 @@ void CHTMLWriteWindow::initView() {
void CHTMLWriteWindow::initConnections() {
CPlainWriteWindow::initConnections();
- connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*)));
- connect(m_writeDisplay->connectionsProxy(), SIGNAL(textChanged()), this, SLOT(textChanged()) );
+ BT_CONNECT(keyChooser(), SIGNAL(keyChanged(CSwordKey *)),
+ this, SLOT(lookupSwordKey(CSwordKey *)));
+ BT_CONNECT(m_writeDisplay->connectionsProxy(), SIGNAL(textChanged()),
+ this, SLOT(textChanged()));
}
void CHTMLWriteWindow::initToolbars() {
@@ -60,32 +64,33 @@ void CHTMLWriteWindow::initToolbars() {
m_writeDisplay->setupToolbar( formatToolBar(), actionCollection() );
}
-void CHTMLWriteWindow::storeProfileSettings(const QString & windowGroup) {
+void CHTMLWriteWindow::storeProfileSettings(QString const & windowGroup) const {
CPlainWriteWindow::storeProfileSettings(windowGroup);
- QAction * action = actionCollection()->action(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName);
- Q_ASSERT(action != 0);
- Q_ASSERT(windowGroup.endsWith('/'));
- btConfig().setSessionValue(windowGroup + "syncWindowEnabled", action->isChecked());
+ BT_ASSERT(windowGroup.endsWith('/'));
+ namespace SW = CResMgr::displaywindows::commentaryWindow::syncWindow;
+ btConfig().setSessionValue(
+ windowGroup + "syncWindowEnabled",
+ actionCollection()->action(SW::actionName).isChecked());
}
void CHTMLWriteWindow::applyProfileSettings(const QString & windowGroup) {
CPlainWriteWindow::applyProfileSettings(windowGroup);
- QAction* action = actionCollection()->action(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName);
- Q_ASSERT(action != 0);
- Q_ASSERT(windowGroup.endsWith('/'));
- action->setChecked(btConfig().sessionValue<bool>(windowGroup + "syncWindowEnabled", false));
+ namespace SW = CResMgr::displaywindows::commentaryWindow::syncWindow;
+ BT_ASSERT(windowGroup.endsWith('/'));
+ actionCollection()->action(SW::actionName).setChecked(
+ btConfig().sessionValue<bool>(windowGroup + "syncWindowEnabled",
+ false));
}
/** Is called when the current text was changed. */
void CHTMLWriteWindow::textChanged() {
- QAction* action = actionCollection()->action(CResMgr::displaywindows::writeWindow::saveText::actionName);
- Q_ASSERT(action != 0);
- action->setEnabled(m_writeDisplay->isModified());
- action = actionCollection()->action(CResMgr::displaywindows::writeWindow::restoreText::actionName);
- Q_ASSERT(action != 0);
- action->setEnabled(m_writeDisplay->isModified());
+ namespace WW = CResMgr::displaywindows::writeWindow;
+ actionCollection()->action(WW::saveText::actionName)
+ .setEnabled(m_writeDisplay->isModified());
+ actionCollection()->action(WW::restoreText::actionName)
+ .setEnabled(m_writeDisplay->isModified());
}
/** Loads the original text from the module. */
@@ -96,9 +101,9 @@ void CHTMLWriteWindow::restoreText() {
}
bool CHTMLWriteWindow::syncAllowed() const {
- QAction* action = actionCollection()->action(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName);
- Q_ASSERT(action != 0);
- return action->isChecked();
+ return actionCollection()->action(
+ CResMgr::displaywindows::commentaryWindow::syncWindow::actionName)
+ .isChecked();
}
/** Saves the text for the current key. Directly writes the changed text into the module. */
diff --git a/src/frontend/displaywindow/chtmlwritewindow.h b/src/frontend/displaywindow/chtmlwritewindow.h
index 2d2eee6..6942057 100644
--- a/src/frontend/displaywindow/chtmlwritewindow.h
+++ b/src/frontend/displaywindow/chtmlwritewindow.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -27,43 +27,27 @@ class CHTMLWriteWindow : public CPlainWriteWindow {
public:
CHTMLWriteWindow(const QList<CSwordModuleInfo *> & modules, CMDIArea * parent);
- virtual void storeProfileSettings(const QString & windowGroup);
- virtual void applyProfileSettings(const QString & windowGroup);
+ void storeProfileSettings(QString const & windowGroup) const override;
+ void applyProfileSettings(const QString & windowGroup) override;
- /**
- * Returns true if the sync toolbar is enabled.
- */
- virtual bool syncAllowed() const;
+ bool syncAllowed() const override;
protected:
- /**
- * Initialize the state of this widget.
- */
- virtual void initView();
- virtual void initConnections();
- virtual void initToolbars();
+ void initView() override;
+ void initConnections() override;
+ void initToolbars() override;
- virtual WriteWindowType writeWindowType() const {
+ WriteWindowType writeWindowType() const override {
return HTMLWindow;
}
- /**
- * Called to add actions to mainWindow toolbars
- */
- virtual void setupMainWindowToolBars();
+
+ void setupMainWindowToolBars() override;
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& );
+
+ void textChanged() override;
+ void restoreText() override;
+ void saveCurrentText(QString const &) override;
};
diff --git a/src/frontend/displaywindow/clexiconreadwindow.cpp b/src/frontend/displaywindow/clexiconreadwindow.cpp
index 3b76f38..495bddc 100644
--- a/src/frontend/displaywindow/clexiconreadwindow.cpp
+++ b/src/frontend/displaywindow/clexiconreadwindow.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -10,15 +10,15 @@
#include "frontend/displaywindow/clexiconreadwindow.h"
#include <QAction>
-#include <QApplication>
#include <QFile>
#include <QFileDialog>
#include <QMenu>
#include <QDebug>
-#include "bibletime.h"
#include "backend/keys/cswordldkey.h"
#include "backend/keys/cswordkey.h"
+#include "bibletime.h"
+#include "bibletimeapp.h"
#include "frontend/cexportmanager.h"
#include "frontend/display/bthtmlreaddisplay.h"
#include "frontend/displaywindow/btactioncollection.h"
@@ -28,6 +28,8 @@
#include "frontend/displaywindow/btmodulechooserbar.h"
#include "frontend/keychooser/bthistory.h"
#include "frontend/keychooser/ckeychooser.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/directory.h"
#include "util/cresmgr.h"
#include "util/tool.h"
@@ -80,79 +82,56 @@ void CLexiconReadWindow::initActions() {
CReadWindow::initActions();
CLexiconReadWindow::insertKeyboardActions(ac);
- QAction *qaction = ac->action(CResMgr::displaywindows::general::backInHistory::actionName);
- Q_ASSERT(qaction != 0);
- m_actions.backInHistory = dynamic_cast<BtToolBarPopupAction*>(qaction);
- Q_ASSERT(m_actions.backInHistory);
+ m_actions.backInHistory =
+ &ac->actionAs<BtToolBarPopupAction>(
+ CResMgr::displaywindows::general::backInHistory::actionName);
addAction(m_actions.backInHistory);
- qaction = ac->action(CResMgr::displaywindows::general::forwardInHistory::actionName);
- Q_ASSERT(qaction != 0);
- m_actions.forwardInHistory = dynamic_cast<BtToolBarPopupAction*>(qaction);
- Q_ASSERT(m_actions.forwardInHistory);
+ m_actions.forwardInHistory =
+ &ac->actionAs<BtToolBarPopupAction>(
+ CResMgr::displaywindows::general::forwardInHistory::actionName);
addAction(m_actions.forwardInHistory);
- qaction = ac->action("nextEntry");
- Q_ASSERT(qaction != 0);
- connect(qaction, SIGNAL(triggered()),
- this, SLOT(nextEntry()));
- addAction(qaction);
-
- qaction = ac->action("previousEntry");
- Q_ASSERT(qaction != 0);
- connect(qaction, SIGNAL(triggered()),
- this, SLOT(previousEntry()));
- addAction(qaction);
-
- m_actions.selectAll = ac->action("selectAll");
- Q_ASSERT(m_actions.selectAll != 0);
-
- m_actions.findText = ac->action("findText");
- Q_ASSERT(m_actions.findText != 0);
-
- m_actions.findStrongs = ac->action(CResMgr::displaywindows::general::findStrongs::actionName);
- Q_ASSERT(m_actions.findStrongs != 0);
- connect(m_actions.findStrongs, SIGNAL(triggered()),
- this, SLOT(openSearchStrongsDialog()) );
- addAction(m_actions.findStrongs);
-
- m_actions.copy.reference = ac->action("copyReferenceOnly");
- Q_ASSERT(m_actions.copy.reference != 0);
- connect(m_actions.copy.reference, SIGNAL(triggered()),
- displayWidget()->connectionsProxy(), SLOT(copyAnchorOnly()));
- addAction(m_actions.copy.reference);
-
- m_actions.copy.entry = ac->action("copyEntryWithText");
- Q_ASSERT(m_actions.copy.entry != 0);
- connect(m_actions.copy.entry, SIGNAL(triggered()),
- displayWidget()->connectionsProxy(), SLOT(copyAll()));
- addAction(m_actions.copy.entry);
-
- m_actions.copy.selectedText = ac->action("copySelectedText");
- Q_ASSERT(m_actions.copy.selectedText != 0);
-
- m_actions.save.entryAsPlain = new QAction(tr("Entry as plain text"), ac );
- connect(m_actions.save.entryAsPlain, SIGNAL(triggered()),
- this, SLOT(saveAsPlain()));
- addAction(m_actions.save.entryAsPlain);
-
- m_actions.save.entryAsHTML = ac->action("saveHtml");
- Q_ASSERT(m_actions.save.entryAsHTML != 0);
- connect(m_actions.save.entryAsHTML, SIGNAL(triggered()),
- this, SLOT(saveAsHTML()));
- addAction(m_actions.save.entryAsHTML);
-
- m_actions.print.reference = ac->action("printReferenceOnly");
- Q_ASSERT(m_actions.print.reference != 0);
- connect(m_actions.print.reference, SIGNAL(triggered()),
- this, SLOT(printAnchorWithText()));
+ initAction("nextEntry", this, &CLexiconReadWindow::nextEntry);
+ initAction("previousEntry", this, &CLexiconReadWindow::previousEntry);
+
+ m_actions.selectAll = &ac->action("selectAll");
+ m_actions.findText = &ac->action("findText");
+
+ m_actions.findStrongs =
+ &initAction(
+ CResMgr::displaywindows::general::findStrongs::actionName,
+ this,
+ &CLexiconReadWindow::openSearchStrongsDialog);
+
+ m_actions.copy.reference =
+ &initAction("copyReferenceOnly",
+ displayWidget()->connectionsProxy(),
+ &CDisplayConnections::copyAnchorOnly);
+
+ m_actions.copy.entry = &initAction("copyEntryWithText",
+ displayWidget()->connectionsProxy(),
+ &CDisplayConnections::copyAll);
+
+ m_actions.copy.selectedText = &ac->action("copySelectedText");
+
+ m_actions.save.entryAsPlain = &initAction("saveEntryAsPlain",
+ this,
+ &CLexiconReadWindow::saveAsPlain);
+
+ m_actions.save.entryAsHTML = &initAction("saveHtml",
+ this,
+ &CLexiconReadWindow::saveAsHTML);
+
+ m_actions.print.reference =
+ &initAction("printReferenceOnly",
+ this,
+ &CLexiconReadWindow::printAnchorWithText);
addAction(m_actions.print.reference);
- m_actions.print.entry = ac->action("printEntryWithText");
- Q_ASSERT(m_actions.print.entry != 0);
- connect(m_actions.print.entry, SIGNAL(triggered()),
- this, SLOT(printAll()));
- addAction(m_actions.print.entry);
+ m_actions.print.entry = &initAction("printEntryWithText",
+ this,
+ &CLexiconReadWindow::printAll);
// init with the user defined settings
ac->readShortcuts("Lexicon shortcuts");
@@ -160,32 +139,24 @@ void CLexiconReadWindow::initActions() {
/** No descriptions */
void CLexiconReadWindow::initConnections() {
- Q_ASSERT(keyChooser());
+ BT_ASSERT(keyChooser());
- connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*)));
- connect(history(), SIGNAL(historyChanged(bool, bool)), this, SLOT(slotUpdateHistoryButtons(bool, bool)));
+ BT_CONNECT(keyChooser(), SIGNAL(keyChanged(CSwordKey *)),
+ this, SLOT(lookupSwordKey(CSwordKey *)));
+ BT_CONNECT(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);
+ BT_CONNECT(m_actions.backInHistory->popupMenu(), SIGNAL(aboutToShow()),
+ this, SLOT(slotFillBackHistory()));
+ BT_CONNECT(m_actions.backInHistory->popupMenu(),
+ SIGNAL(triggered(QAction *)),
+ keyChooser()->history(), SLOT(move(QAction *)));
+ BT_CONNECT(m_actions.forwardInHistory->popupMenu(), SIGNAL(aboutToShow()),
+ this, SLOT(slotFillForwardHistory()));
+ BT_CONNECT(m_actions.forwardInHistory->popupMenu(),
+ SIGNAL(triggered(QAction *)),
+ keyChooser()->history(), SLOT(move(QAction *)));
}
@@ -219,15 +190,15 @@ void CLexiconReadWindow::initView() {
void CLexiconReadWindow::initToolbars() {
//Navigation toolbar
- Q_ASSERT(m_actions.backInHistory);
+ BT_ASSERT(m_actions.backInHistory);
mainToolBar()->addWidget(keyChooser());
mainToolBar()->addAction(m_actions.backInHistory); //1st button
mainToolBar()->addAction(m_actions.forwardInHistory); //2nd button
//Tools toolbar
- QAction *action = actionCollection()->action(CResMgr::displaywindows::general::search::actionName);
- Q_ASSERT(action != 0);
- buttonsToolBar()->addAction(action);
+ buttonsToolBar()->addAction(
+ &actionCollection()->action(
+ CResMgr::displaywindows::general::search::actionName));
BtDisplaySettingsButton* button = new BtDisplaySettingsButton(buttonsToolBar());
setDisplaySettingsButton(button);
@@ -242,10 +213,10 @@ void CLexiconReadWindow::setupMainWindowToolBars() {
// Navigation toolbar
CKeyChooser* keyChooser = CKeyChooser::createInstance(modules(), history(), key(), btMainWindow()->navToolBar() );
btMainWindow()->navToolBar()->addWidget(keyChooser);
- bool ok = connect(keyChooser, SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*)));
- Q_ASSERT(ok);
- ok = connect(this, SIGNAL(sigKeyChanged(CSwordKey*)), keyChooser, SLOT(updateKey(CSwordKey*)) );
- Q_ASSERT(ok);
+ BT_CONNECT(keyChooser, SIGNAL(keyChanged(CSwordKey *)),
+ this, SLOT(lookupSwordKey(CSwordKey *)));
+ BT_CONNECT(this, SIGNAL(sigKeyChanged(CSwordKey *)),
+ keyChooser, SLOT(updateKey(CSwordKey *)));
btMainWindow()->navToolBar()->addAction(m_actions.backInHistory); //1st button
btMainWindow()->navToolBar()->addAction(m_actions.forwardInHistory); //2nd button
@@ -253,9 +224,9 @@ void CLexiconReadWindow::setupMainWindowToolBars() {
btMainWindow()->worksToolBar()->setModules(getModuleList(), modules().first()->type(), this);
// Tools toolbar
- QAction *action = actionCollection()->action(CResMgr::displaywindows::general::search::actionName);
- Q_ASSERT(action != 0);
- btMainWindow()->toolsToolBar()->addAction(action);
+ btMainWindow()->toolsToolBar()->addAction(
+ &actionCollection()->action(
+ CResMgr::displaywindows::general::search::actionName));
BtDisplaySettingsButton* button = new BtDisplaySettingsButton(buttonsToolBar());
setDisplaySettingsButton(button);
btMainWindow()->toolsToolBar()->addWidget(button);
@@ -285,9 +256,9 @@ void CLexiconReadWindow::setupPopupMenu() {
m_actions.saveMenu->addAction(m_actions.save.entryAsHTML);
// Save raw HTML action for debugging purposes
- if (qApp->property("--debug").toBool()) {
+ if (btApp->debugMode()) {
QAction* debugAction = new QAction("Raw HTML", this);
- QObject::connect(debugAction, SIGNAL(triggered()), this, SLOT(saveRawHTML()));
+ BT_CONNECT(debugAction, SIGNAL(triggered()), this, SLOT(saveRawHTML()));
m_actions.saveMenu->addAction(debugAction);
} // end of Save Raw HTML
@@ -306,12 +277,16 @@ void CLexiconReadWindow::setupPopupMenu() {
void CLexiconReadWindow::updatePopupMenu() {
//enable the action depending on the supported module features
- m_actions.findStrongs->setEnabled(!displayWidget()->getCurrentNodeInfo().isNull());
+ CReadDisplay const & display =
+ *static_cast<CReadDisplay *>(displayWidget());
+
+ m_actions.findStrongs->setEnabled(!display.getCurrentNodeInfo().isNull());
- m_actions.copy.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() );
- m_actions.copy.selectedText->setEnabled( displayWidget()->hasSelection() );
+ bool const hasActiveAnchor = display.hasActiveAnchor();
+ m_actions.copy.reference->setEnabled(hasActiveAnchor);
+ m_actions.copy.selectedText->setEnabled(display.hasSelection());
- m_actions.print.reference->setEnabled( ((CReadDisplay*)displayWidget())->hasActiveAnchor() );
+ m_actions.print.reference->setEnabled(hasActiveAnchor);
}
void CLexiconReadWindow::reload(CSwordBackend::SetupChangedReason reason) {
@@ -388,8 +363,8 @@ void CLexiconReadWindow::slotFillForwardHistory() {
void CLexiconReadWindow::slotUpdateHistoryButtons(bool backEnabled, bool fwEnabled) {
- Q_ASSERT(m_actions.backInHistory);
- Q_ASSERT(keyChooser());
+ BT_ASSERT(m_actions.backInHistory);
+ BT_ASSERT(keyChooser());
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 6233545..6e939bb 100644
--- a/src/frontend/displaywindow/clexiconreadwindow.h
+++ b/src/frontend/displaywindow/clexiconreadwindow.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -36,27 +36,38 @@ class CLexiconReadWindow : public CReadWindow {
Q_OBJECT
public:
CLexiconReadWindow(const QList<CSwordModuleInfo *> & modules, CMDIArea * parent);
- virtual ~CLexiconReadWindow();
+ ~CLexiconReadWindow() override;
+
+ CSwordModuleInfo::ModuleType moduleType() const override
+ { return CSwordModuleInfo::Lexicon; }
/** Insert the keyboard accelerators of this window into the given actioncollection.*/
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);
+ void reload(CSwordBackend::SetupChangedReason reason) override;
protected:
- virtual void initActions();
- virtual void initToolbars();
- virtual void initConnections();
- virtual void initView();
- virtual void updatePopupMenu();
- virtual void setupPopupMenu();
-
- /** Called to add actions to mainWindow toolbars */
- virtual void setupMainWindowToolBars();
+
+ template <typename ... Args>
+ QAction & initAction(QString actionName, Args && ... args) {
+ QAction & action =
+ actionCollection()->action(std::move(actionName));
+ BT_CONNECT(&action,
+ &QAction::triggered,
+ std::forward<Args>(args)...);
+ addAction(&action);
+ return action;
+ }
+
+ void initActions() override;
+ void initToolbars() override;
+ void initConnections() override;
+ void initView() override;
+ void updatePopupMenu() override;
+ void setupPopupMenu() override;
+
+ void setupMainWindowToolBars() override;
struct ActionsStruct {
BtToolBarPopupAction* backInHistory;
diff --git a/src/frontend/displaywindow/cplainwritewindow.cpp b/src/frontend/displaywindow/cplainwritewindow.cpp
index f4b2d0b..b51339e 100644
--- a/src/frontend/displaywindow/cplainwritewindow.cpp
+++ b/src/frontend/displaywindow/cplainwritewindow.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -21,20 +21,20 @@
#include "frontend/displaywindow/btmodulechooserbar.h"
#include "frontend/keychooser/ckeychooser.h"
#include "frontend/messagedialog.h"
-#include "util/btsignal.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
CPlainWriteWindow::CPlainWriteWindow(const QList<CSwordModuleInfo*> & moduleList, CMDIArea * parent)
: CDisplayWindow(moduleList, parent)
- , m_writeDisplay(0)
+ , m_writeDisplay(nullptr)
{
setKey( CSwordKey::createInstance(moduleList.first()) );
}
void CPlainWriteWindow::setDisplayWidget(CDisplay * display) {
- Q_ASSERT(dynamic_cast<CPlainWriteDisplay *>(display));
+ BT_ASSERT(dynamic_cast<CPlainWriteDisplay *>(display));
CDisplayWindow::setDisplayWidget(static_cast<CPlainWriteDisplay *>(display));
m_writeDisplay = static_cast<CPlainWriteDisplay *>(display);
}
@@ -80,67 +80,68 @@ void CPlainWriteWindow::initToolbars() {
mainToolBar()->addWidget(keyChooser());
// Tools toolbar
- QAction* action = actionCollection()->action(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName);
- Q_ASSERT(action != 0);
- buttonsToolBar()->addAction(action);
- action = actionCollection()->action(CResMgr::displaywindows::writeWindow::saveText::actionName);
- Q_ASSERT(action != 0);
- buttonsToolBar()->addAction(action);
- action = actionCollection()->action(CResMgr::displaywindows::writeWindow::deleteEntry::actionName);
- Q_ASSERT(action != 0);
- buttonsToolBar()->addAction(action);
- action = actionCollection()->action(CResMgr::displaywindows::writeWindow::restoreText::actionName);
- Q_ASSERT(action != 0);
- buttonsToolBar()->addAction(action);
+ auto const initAction = [this](QString const & actionName) {
+ buttonsToolBar()->addAction(&actionCollection()->action(actionName));
+ };
+ using namespace CResMgr::displaywindows;
+ initAction(commentaryWindow::syncWindow::actionName);
+ initAction(writeWindow::saveText::actionName);
+ initAction(writeWindow::deleteEntry::actionName);
+ initAction(writeWindow::restoreText::actionName);
}
void CPlainWriteWindow::setupMainWindowToolBars() {
// Navigation toolbar
CKeyChooser* keyChooser = CKeyChooser::createInstance(modules(), history(), key(), btMainWindow()->navToolBar() );
btMainWindow()->navToolBar()->addWidget(keyChooser);
- bool ok = connect(keyChooser, SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*)));
- Q_ASSERT(ok);
+ BT_CONNECT(keyChooser, SIGNAL(keyChanged(CSwordKey *)),
+ this, SLOT(lookupSwordKey(CSwordKey *)));
// Tools toolbar
- QAction* action = actionCollection()->action(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName);
- Q_ASSERT(action != 0);
- btMainWindow()->toolsToolBar()->addAction(action);
- action = actionCollection()->action(CResMgr::displaywindows::writeWindow::saveText::actionName);
- Q_ASSERT(action != 0);
- btMainWindow()->toolsToolBar()->addAction(action);
- action = actionCollection()->action(CResMgr::displaywindows::writeWindow::deleteEntry::actionName);
- Q_ASSERT(action != 0);
- btMainWindow()->toolsToolBar()->addAction(action);
- action = actionCollection()->action(CResMgr::displaywindows::writeWindow::restoreText::actionName);
- Q_ASSERT(action != 0);
- btMainWindow()->toolsToolBar()->addAction(action);
+ QToolBar & toolsToolbar = *btMainWindow()->toolsToolBar();
+ auto const initAction = [this, &toolsToolbar](QString const & actionName) {
+ toolsToolbar.addAction(&actionCollection()->action(actionName));
+ };
+ using namespace CResMgr::displaywindows;
+ initAction(commentaryWindow::syncWindow::actionName);
+ initAction(writeWindow::saveText::actionName);
+ initAction(writeWindow::deleteEntry::actionName);
+ initAction(writeWindow::restoreText::actionName);
}
void CPlainWriteWindow::initConnections() {
- Q_ASSERT(keyChooser());
- QObject::connect(key()->beforeChangedSignaller(), SIGNAL(signal()), this, SLOT(beforeKeyChange()));
- QObject::connect(keyChooser(), SIGNAL(keyChanged(CSwordKey*)), this, SLOT(lookupSwordKey(CSwordKey*)));
- QObject::connect(displayWidget()->connectionsProxy(), SIGNAL(textChanged()), this, SLOT(textChanged()) );
+ BT_ASSERT(keyChooser());
+ BT_CONNECT(key()->beforeChangedSignaller(), SIGNAL(signal()),
+ this, SLOT(beforeKeyChange()));
+ BT_CONNECT(keyChooser(), SIGNAL(keyChanged(CSwordKey *)),
+ this, SLOT(lookupSwordKey(CSwordKey *)));
+ BT_CONNECT(displayWidget()->connectionsProxy(), SIGNAL(textChanged()),
+ this, SLOT(textChanged()));
}
-void CPlainWriteWindow::storeProfileSettings(const QString & windowGroup) {
+void CPlainWriteWindow::storeProfileSettings(QString const & windowGroup) const {
CDisplayWindow::storeProfileSettings(windowGroup);
- QAction * action = actionCollection()->action(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName);
- Q_ASSERT(action);
- Q_ASSERT(windowGroup.endsWith('/'));
+ BT_ASSERT(windowGroup.endsWith('/'));
btConfig().setSessionValue(windowGroup + "writeWindowType",
static_cast<int>(writeWindowType()));
- btConfig().setSessionValue(windowGroup + "syncWindowEnabled", action->isChecked());
+ using namespace CResMgr::displaywindows;
+ btConfig().setSessionValue(
+ windowGroup + "syncWindowEnabled",
+ actionCollection()->action(
+ commentaryWindow::syncWindow::actionName).isChecked());
}
void CPlainWriteWindow::applyProfileSettings(const QString & windowGroup) {
CDisplayWindow::applyProfileSettings(windowGroup);
- QAction * action = actionCollection()->action(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName);
- Q_ASSERT(action != 0);
- Q_ASSERT(windowGroup.endsWith('/'));
- action->setChecked(btConfig().sessionValue<bool>(windowGroup + "syncWindowEnabled", false));
+ BT_ASSERT(windowGroup.endsWith('/'));
+ using namespace CResMgr::displaywindows;
+ actionCollection()->action(commentaryWindow::syncWindow::actionName)
+ .setChecked(
+ btConfig().sessionValue<bool>(
+ windowGroup + "syncWindowEnabled",
+ false));
}
/** Saves the text for the current key. Directly writes the changed text into the module. */
@@ -177,12 +178,12 @@ void CPlainWriteWindow::restoreText() {
/** Is called when the current text was changed. */
void CPlainWriteWindow::textChanged() {
- QAction* action = actionCollection()->action(CResMgr::displaywindows::writeWindow::saveText::actionName);
- Q_ASSERT(action != 0);
- action->setEnabled(m_writeDisplay->isModified());
- action = actionCollection()->action(CResMgr::displaywindows::writeWindow::restoreText::actionName);
- Q_ASSERT(action != 0);
- action->setEnabled(m_writeDisplay->isModified());
+ namespace WW = CResMgr::displaywindows::writeWindow;
+ auto const & ac = *actionCollection();
+ ac.action(WW::saveText::actionName)
+ .setEnabled(m_writeDisplay->isModified());
+ ac.action(WW::restoreText::actionName)
+ .setEnabled(m_writeDisplay->isModified());
}
/** Deletes the module entry and clears the edit widget, */
@@ -196,42 +197,35 @@ void CPlainWriteWindow::deleteEntry() {
void CPlainWriteWindow::setupPopupMenu() {}
bool CPlainWriteWindow::syncAllowed() const {
- QAction* action = actionCollection()->action(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName);
- Q_ASSERT(action != 0);
- return action->isChecked();
+ return actionCollection()->action(
+ CResMgr::displaywindows::commentaryWindow::syncWindow::actionName)
+ .isChecked();
}
void CPlainWriteWindow::initActions() {
insertKeyboardActions(actionCollection());
- QAction* action = actionCollection()->action(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName);
- Q_ASSERT(action != 0);
- bool ok = QObject::connect(action, SIGNAL(triggered()),
- this, SLOT(saveCurrentText()));
- Q_ASSERT(ok);
-
- action = actionCollection()->action(CResMgr::displaywindows::writeWindow::saveText::actionName);
- Q_ASSERT(action != 0);
- ok = QObject::connect(action, SIGNAL(triggered()),
- this, SLOT(saveCurrentText()));
- Q_ASSERT(ok);
-
- action = actionCollection()->action(CResMgr::displaywindows::writeWindow::deleteEntry::actionName);
- Q_ASSERT(action != 0);
- ok = QObject::connect(action, SIGNAL(triggered()),
- this, SLOT(deleteEntry()));
- Q_ASSERT(ok);
-
- action = actionCollection()->action(CResMgr::displaywindows::writeWindow::restoreText::actionName);
- Q_ASSERT(action != 0);
- ok = QObject::connect(action, SIGNAL(triggered()),
- this, SLOT(restoreText()));
- Q_ASSERT(ok);
+ auto const initAction = [this](QString const & actionName,
+ void (CPlainWriteWindow:: *slot)())
+ {
+ BT_CONNECT(&actionCollection()->action(actionName),
+ &QAction::triggered,
+ this, slot);
+ };
+ namespace DW = CResMgr::displaywindows;
+ initAction(DW::commentaryWindow::syncWindow::actionName,
+ &CPlainWriteWindow::saveCurrentText);
+ initAction(DW::writeWindow::saveText::actionName,
+ &CPlainWriteWindow::saveCurrentText);
+ initAction(DW::writeWindow::deleteEntry::actionName,
+ &CPlainWriteWindow::deleteEntry);
+ initAction(DW::writeWindow::restoreText::actionName,
+ &CPlainWriteWindow::restoreText);
}
void CPlainWriteWindow::insertKeyboardActions( BtActionCollection* const a) {
QAction* action = new QAction(
- util::getIcon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon),
+ CResMgr::displaywindows::commentaryWindow::syncWindow::icon(),
tr("Sync with active Bible"),
a
);
@@ -241,7 +235,7 @@ void CPlainWriteWindow::insertKeyboardActions( BtActionCollection* const a) {
a->addAction(CResMgr::displaywindows::commentaryWindow::syncWindow::actionName, action);
action = new QAction(
- util::getIcon(CResMgr::displaywindows::writeWindow::saveText::icon),
+ CResMgr::displaywindows::writeWindow::saveText::icon(),
tr("Save text"),
a
);
@@ -250,7 +244,7 @@ void CPlainWriteWindow::insertKeyboardActions( BtActionCollection* const a) {
a->addAction(CResMgr::displaywindows::writeWindow::saveText::actionName, action);
action = new QAction(
- util::getIcon(CResMgr::displaywindows::writeWindow::deleteEntry::icon),
+ CResMgr::displaywindows::writeWindow::deleteEntry::icon(),
tr("Delete current entry"),
a
);
@@ -259,7 +253,7 @@ void CPlainWriteWindow::insertKeyboardActions( BtActionCollection* const a) {
a->addAction(CResMgr::displaywindows::writeWindow::deleteEntry::actionName, action);
action = new QAction(
- util::getIcon(CResMgr::displaywindows::writeWindow::restoreText::icon),
+ CResMgr::displaywindows::writeWindow::restoreText::icon(),
tr("Restore original text"),
a
);
@@ -292,15 +286,15 @@ bool CPlainWriteWindow::queryClose() {
}
void CPlainWriteWindow::beforeKeyChange() {
- Q_ASSERT(displayWidget());
- Q_ASSERT(keyChooser());
+ BT_ASSERT(displayWidget());
+ BT_ASSERT(keyChooser());
if (!isReady())
return;
// Get current key string for this window
QString thisWindowsKey;
CSwordKey* oldKey = key();
- if (oldKey == 0)
+ if (oldKey == nullptr)
return;
thisWindowsKey = oldKey->key();
diff --git a/src/frontend/displaywindow/cplainwritewindow.h b/src/frontend/displaywindow/cplainwritewindow.h
index cf11a46..31cd4c0 100644
--- a/src/frontend/displaywindow/cplainwritewindow.h
+++ b/src/frontend/displaywindow/cplainwritewindow.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -38,54 +38,37 @@ class CPlainWriteWindow : public CDisplayWindow {
CPlainWriteWindow(const QList<CSwordModuleInfo *> & modules, CMDIArea * parent);
/**
- * Set the displayWidget which is a subclass of QWebPage.
+ * Set the displayWidget which is a subclass of BtWebEnginePage.
*/
- void setDisplayWidget( CDisplay* display );
+ void setDisplayWidget( CDisplay* display ) override;
- virtual void storeProfileSettings(const QString & windowGroup);
- virtual void applyProfileSettings(const QString & windowGroup);
+ void storeProfileSettings(QString const & windowGroup) const override;
+ void applyProfileSettings(const QString & windowGroup) override;
- /**
- * Setups the popup menu of this display widget.
- */
- virtual void setupPopupMenu();
+ void setupPopupMenu() override;
- /**
- * Returns true if the sync toolbar is enabled.
- */
- virtual bool syncAllowed() const;
+ bool syncAllowed() const override;
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);
+ void lookupSwordKey(CSwordKey * key) override;
protected: // Protected methods
- /**
- * Initialize the state of this widget.
- */
- virtual void initView();
- virtual void initConnections();
- virtual void initToolbars();
+ void initView() override;
+ void initConnections() override;
+ void initToolbars() override;
virtual WriteWindowType writeWindowType() const {
return PlainTextWindow;
}
- /** Called to add actions to mainWindow toolbars */
- virtual void setupMainWindowToolBars();
- /**
- * Initializes the intern keyboard actions.
- */
- virtual void initActions();
+ void setupMainWindowToolBars() override;
+ void initActions() override;
/**
* Insert the keyboard accelerators of this window into the given KAccel object.
*/
static void insertKeyboardActions( BtActionCollection* const a );
- /** \returns whether the window may be closed.*/
- virtual bool queryClose();
+ bool queryClose() override;
protected slots: // Protected slots
diff --git a/src/frontend/displaywindow/creadwindow.cpp b/src/frontend/displaywindow/creadwindow.cpp
index 0d8f2d9..dd6f418 100644
--- a/src/frontend/displaywindow/creadwindow.cpp
+++ b/src/frontend/displaywindow/creadwindow.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -20,115 +20,98 @@
#include "frontend/display/bthtmlreaddisplay.h"
#include "frontend/displaywindow/btactioncollection.h"
#include "frontend/searchdialog/csearchdialog.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
-CReadWindow::CReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent)
- : CDisplayWindow(modules, parent),
- m_readDisplayWidget(0) {
- // installEventFilter(this);
-}
+CReadWindow::CReadWindow(QList<CSwordModuleInfo *> modules, CMDIArea * parent)
+ : CDisplayWindow(modules, parent)
+ , m_readDisplayWidget(nullptr)
+{}
-/** Sets the display widget of this display window. */
-void CReadWindow::setDisplayWidget( CDisplay* newDisplay ) {
+void CReadWindow::setDisplayWidget(CDisplay * newDisplay) {
// Lets be orwellianly paranoid here:
- Q_ASSERT(dynamic_cast<CReadDisplay*>(newDisplay) != 0);
+ BT_ASSERT(dynamic_cast<CReadDisplay *>(newDisplay));
CDisplayWindow::setDisplayWidget(newDisplay);
if (m_readDisplayWidget) {
- disconnect(m_readDisplayWidget->connectionsProxy(), SIGNAL(referenceClicked(const QString&, const QString&)),
- this, SLOT(lookupModKey(const QString&, const QString&)));
- disconnect(m_readDisplayWidget->connectionsProxy(), SIGNAL(referenceDropped(const QString&)),
- this, SLOT(lookupKey(const QString&)));
+ disconnect(m_readDisplayWidget->connectionsProxy(),
+ SIGNAL(referenceClicked(QString const &, QString const &)),
+ this,
+ SLOT(lookupModKey(QString const &, QString const &)));
+ disconnect(m_readDisplayWidget->connectionsProxy(),
+ SIGNAL(referenceDropped(QString const &)),
+ this,
+ SLOT(lookupKey(QString const &)));
+
+ if (BtHtmlReadDisplay * const v =
+ dynamic_cast<BtHtmlReadDisplay *>(m_readDisplayWidget))
+ QObject::disconnect(v, SIGNAL(completed()),
+ this, SLOT(slotMoveToAnchor()));
+ }
- BtHtmlReadDisplay* v = dynamic_cast<BtHtmlReadDisplay*>(m_readDisplayWidget);
- if (v) {
- QObject::disconnect(v, SIGNAL(completed()), this, SLOT(slotMoveToAnchor()) );
- }
+ m_readDisplayWidget = static_cast<CReadDisplay *>(newDisplay);
+ BT_CONNECT(m_readDisplayWidget->connectionsProxy(),
+ SIGNAL(referenceClicked(QString const &, QString const &)),
+ this,
+ SLOT(lookupModKey(QString const &, QString const &)));
- }
+ BT_CONNECT(m_readDisplayWidget->connectionsProxy(),
+ SIGNAL(referenceDropped(QString const &)),
+ this,
+ SLOT(lookupKey(QString const &)));
- m_readDisplayWidget = static_cast<CReadDisplay*>(newDisplay);
- connect(
- m_readDisplayWidget->connectionsProxy(),
- SIGNAL(referenceClicked(const QString&, const QString&)),
- this,
- SLOT(lookupModKey(const QString&, const QString&))
- );
-
- connect(
- m_readDisplayWidget->connectionsProxy(),
- SIGNAL(referenceDropped(const QString&)),
- this,
- SLOT(lookupKey(const QString&))
- );
- BtHtmlReadDisplay* v = dynamic_cast<BtHtmlReadDisplay*>(m_readDisplayWidget);
- if (v) {
- QObject::connect(v, SIGNAL(completed()), this, SLOT(slotMoveToAnchor()) );
- }
+ if (BtHtmlReadDisplay * const v =
+ dynamic_cast<BtHtmlReadDisplay *>(m_readDisplayWidget))
+ BT_CONNECT(v, SIGNAL(completed()), this, SLOT(slotMoveToAnchor()));
}
-/** Lookup the given entry. */
-void CReadWindow::lookupSwordKey( CSwordKey* newKey ) {
- Q_ASSERT(newKey);
+void CReadWindow::lookupSwordKey(CSwordKey * newKey) {
+ BT_ASSERT(newKey);
- using namespace Rendering;
-
-// Q_ASSERT(isReady() && newKey && modules().first());
- if (!isReady() || !newKey || modules().empty() || !modules().first()) {
+ if (!isReady() || !newKey || modules().empty() || !modules().first())
return;
- }
- if (key() != newKey) {
+ if (key() != newKey)
key()->setKey(newKey->key());
- }
/// \todo 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()
- )
- );
- }
+ Rendering::CEntryDisplay * const display = modules().first()->getDisplay();
+ BT_ASSERT(display);
+ displayWidget()->setText(display->text(modules(),
+ newKey->key(),
+ displayOptions(),
+ filterOptions()));
setWindowTitle(windowCaption());
-
- // moving to anchor happens in slotMoveToAnchor which catches the completed() signal from KHTMLPart
+ /* Moving to anchor happens in slotMoveToAnchor which catches the
+ completed() signal from KHTMLPart. */
}
void CReadWindow::slotMoveToAnchor() {
- ((CReadDisplay*)displayWidget())->moveToAnchor( Rendering::CDisplayRendering::keyToHTMLAnchor(key()->key()) );
+ static_cast<CReadDisplay *>(displayWidget())->moveToAnchor(
+ Rendering::CDisplayRendering::keyToHTMLAnchor(key()->key()));
}
-void CReadWindow::insertKeyboardActions( BtActionCollection* const ) {}
-
-/** No descriptions */
-void CReadWindow::copyDisplayedText() {
- CExportManager().copyKey(key(), CExportManager::Text, true);
-}
+void CReadWindow::insertKeyboardActions(BtActionCollection * const)
+{}
+void CReadWindow::copyDisplayedText()
+{ CExportManager().copyKey(key(), CExportManager::Text, true); }
-/*!
- \fn CReadWindow::resizeEvent(QResizeEvent* e)
- */
-void CReadWindow::resizeEvent(QResizeEvent* /*e*/) {
- if (displayWidget()) {
- ((CReadDisplay*)displayWidget())->moveToAnchor(Rendering::CDisplayRendering::keyToHTMLAnchor(key()->key()));
- }
+void CReadWindow::resizeEvent(QResizeEvent * e) {
+ Q_UNUSED(e)
+ if (displayWidget())
+ static_cast<CReadDisplay *>(displayWidget())->moveToAnchor(
+ Rendering::CDisplayRendering::keyToHTMLAnchor(key()->key()));
}
void CReadWindow::openSearchStrongsDialog() {
QString searchText;
- Q_FOREACH (const QString &strongNumber,
- displayWidget()->getCurrentNodeInfo().split('|', QString::SkipEmptyParts))
- {
+ Q_FOREACH(QString const & strongNumber,
+ displayWidget()->getCurrentNodeInfo().split(
+ '|',
+ QString::SkipEmptyParts))
searchText.append("strong:").append(strongNumber).append(' ');
- }
-
- Search::CSearchDialog::openDialog( modules(), searchText, 0 );
+ Search::CSearchDialog::openDialog(modules(), searchText, nullptr);
}
diff --git a/src/frontend/displaywindow/creadwindow.h b/src/frontend/displaywindow/creadwindow.h
index 2446e1e..48c0fe1 100644
--- a/src/frontend/displaywindow/creadwindow.h
+++ b/src/frontend/displaywindow/creadwindow.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -21,52 +21,49 @@
class BtActionCollection;
class QResizeEvent;
-/**
- \brief The base class for all read-only display windows.
-*/
+/** \brief The base class for all read-only display windows. */
class CReadWindow: public CDisplayWindow {
- Q_OBJECT
- public:
-
- /** Insert the keyboard accelerators of this window into the given actioncollection.*/
- static void insertKeyboardActions( BtActionCollection* const a );
-
- CReadWindow(QList<CSwordModuleInfo*> modules, CMDIArea* parent);
-
- protected:
- /**
- * Sets the display widget of this display window.
- */
- virtual void setDisplayWidget( CDisplay* newDisplay );
- /**
- * Reimplemented Qt function for resize of window.
- */
- virtual void resizeEvent(QResizeEvent* e);
-
- /** Called to add actions to mainWindow toolbars.*/
- virtual void setupMainWindowToolBars() = 0;
-
- 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_readDisplayWidget;
+
+ Q_OBJECT
+
+public: /* Methods: */
+
+ CReadWindow(QList<CSwordModuleInfo *> modules, CMDIArea * parent);
+
+ /**
+ Inserts the keyboard accelerators of this window into the given
+ collection.
+ */
+ static void insertKeyboardActions(BtActionCollection * const a);
+
+ virtual CSwordModuleInfo::ModuleType moduleType() const = 0;
+
+protected: /* Methods: */
+
+ void setDisplayWidget(CDisplay * newDisplay) override;
+
+ void resizeEvent(QResizeEvent * e) override;
+
+protected slots:
+
+ void lookupSwordKey(CSwordKey *) override;
+
+ /**
+ Catches the signal when the KHTMLPart has finished the layout (anchors are
+ not ready before that).
+ */
+ virtual void slotMoveToAnchor();
+
+ /** Updates the status of the popup menu entries. */
+ virtual void copyDisplayedText();
+
+ /** Opens the search dialog with the strong info of the last clicked word.*/
+ void openSearchStrongsDialog();
+
+private: /* Fields: */
+
+ CReadDisplay * m_readDisplayWidget;
+
};
-#endif
+#endif /* CREADWINDOW_H */
diff --git a/src/frontend/keychooser/bthistory.cpp b/src/frontend/keychooser/bthistory.cpp
index 22c9e69..a4ffd4a 100644
--- a/src/frontend/keychooser/bthistory.cpp
+++ b/src/frontend/keychooser/bthistory.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,57 +12,64 @@
#include <QAction>
#include <QList>
#include "backend/keys/cswordkey.h"
+#include "util/btassert.h"
+namespace {
+char const ActionText[] = "BtHistory key";
+}
+
BTHistory::BTHistory(QWidget* parent)
: m_historyList(),
m_index(-1),
m_inHistoryFunction(false) {
setParent(parent);
- Q_ASSERT(class_invariant());
+ BT_ASSERT(class_invariant());
}
void BTHistory::add(CSwordKey* newKey) {
- Q_ASSERT(newKey);
+ BT_ASSERT(newKey);
// Add new key Action after current index if we were not using the history functions,
// if it's not a duplicate and if it's not empty.
- if (!m_inHistoryFunction && ((m_index < 0) || (newKey->key() != m_historyList.at(m_index)->text()) )) {
+ if (!m_inHistoryFunction && ((m_index < 0) || (newKey->key() != m_historyList.at(m_index)->property(ActionText).toString()) )) {
if (!newKey->key().isEmpty()) {
- m_historyList.insert(++m_index, new QAction(newKey->key(), this));
+ auto * const a = new QAction(newKey->key(), this);
+ a->setProperty(ActionText, newKey->key());
+ m_historyList.insert(++m_index, a);
}
// \todo history limit?
sendChangedSignal();
}
- Q_ASSERT(class_invariant());
+ BT_ASSERT(class_invariant());
}
void BTHistory::move(QAction* historyItem) {
- //Q_ASSERT(historyItem);
- Q_ASSERT(m_historyList.count());
+ //BT_ASSERT(historyItem);
+ BT_ASSERT(m_historyList.count());
m_inHistoryFunction = true;
//find the action in the list
m_index = m_historyList.indexOf(historyItem);
//move to the selected item in the list, it will be the current item
- emit historyMoved(m_historyList.at(m_index)->text()); // signal to "outsiders"; key has been changed
+ emit historyMoved(m_historyList.at(m_index)->property(ActionText).toString()); // signal to "outsiders"; key has been changed
sendChangedSignal();
m_inHistoryFunction = false;
- Q_ASSERT(class_invariant());
+ BT_ASSERT(class_invariant());
}
void BTHistory::back() {
if ( m_index >= 1) {
move(m_historyList.at(m_index - 1));
}
- Q_ASSERT(class_invariant());
+ BT_ASSERT(class_invariant());
}
void BTHistory::fw() {
if (m_index < (m_historyList.size() - 1)) {
move(m_historyList.at(m_index + 1));
}
- Q_ASSERT(class_invariant());
+ BT_ASSERT(class_invariant());
}
QList<QAction*> BTHistory::getBackList() {
@@ -72,7 +79,7 @@ QList<QAction*> BTHistory::getBackList() {
list.append(m_historyList.at(i));
}
- Q_ASSERT(class_invariant());
+ BT_ASSERT(class_invariant());
return list;
}
@@ -82,7 +89,7 @@ QList<QAction*> BTHistory::getFwList() {
list.append(m_historyList.at(i));
}
- Q_ASSERT(class_invariant());
+ BT_ASSERT(class_invariant());
return list;
}
@@ -90,12 +97,12 @@ void BTHistory::sendChangedSignal() {
bool backEnabled = m_index > 0; //there are items in the back list
bool fwEnabled = m_historyList.size() > m_index + 1; //there are items in the fw list
emit historyChanged(backEnabled, fwEnabled);
- Q_ASSERT(class_invariant());
+ BT_ASSERT(class_invariant());
}
bool BTHistory::class_invariant() {
for (int i = 0; i < m_historyList.size(); ++i) {
- if (!m_historyList.at(i) || m_historyList.at(i)->text().isEmpty()) return false;
+ if (!m_historyList.at(i) || m_historyList.at(i)->property(ActionText).toString().isEmpty()) return false;
}
if (!(m_index >= -1 && m_index < m_historyList.size())) return false;
return true;
diff --git a/src/frontend/keychooser/bthistory.h b/src/frontend/keychooser/bthistory.h
index 6c65aca..4141e28 100644
--- a/src/frontend/keychooser/bthistory.h
+++ b/src/frontend/keychooser/bthistory.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
diff --git a/src/frontend/keychooser/cbookkeychooser.cpp b/src/frontend/keychooser/cbookkeychooser.cpp
index 9255980..f8a46d4 100644
--- a/src/frontend/keychooser/cbookkeychooser.cpp
+++ b/src/frontend/keychooser/cbookkeychooser.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -17,28 +17,30 @@
#include "backend/drivers/cswordbookmoduleinfo.h"
#include "backend/keys/cswordtreekey.h"
#include "frontend/keychooser/bthistory.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#define ID_PROPERTY_NAME "CBookKeyChooser_ID"
-CBookKeyChooser::CBookKeyChooser(const QList<const CSwordModuleInfo *> & modules,
+CBookKeyChooser::CBookKeyChooser(const BtConstModuleList & modules,
BTHistory * historyPtr,
CSwordKey * key,
QWidget * parent)
: CKeyChooser(modules, historyPtr, parent)
- , m_layout(0)
+ , m_layout(nullptr)
{
setModules(modules, false);
m_key = dynamic_cast<CSwordTreeKey * >(key);
if (!m_modules.count())
- m_key = 0;
+ m_key = nullptr;
setModules(modules, true);
setKey(key);
adjustFont();
- connect(this, SIGNAL(keyChanged(CSwordKey *)),
- history(), SLOT(add(CSwordKey *)));
+ BT_CONNECT(this, SIGNAL(keyChanged(CSwordKey *)),
+ history(), SLOT(add(CSwordKey *)));
}
void CBookKeyChooser::setKey(CSwordKey * newKey) {
@@ -119,17 +121,17 @@ CSwordKey * CBookKeyChooser::key() {
}
/** Sets another module to this keychooser */
-void CBookKeyChooser::setModules(const QList<const CSwordModuleInfo *> & modules,
+void CBookKeyChooser::setModules(const BtConstModuleList & modules,
bool refresh)
{
- typedef CSwordBookModuleInfo CSBMI;
+ using CSBMI = CSwordBookModuleInfo;
m_modules.clear();
// for (modules.first(); modules.current(); modules.next()) {
- Q_FOREACH(const CSwordModuleInfo * m, modules) {
+ Q_FOREACH(const CSwordModuleInfo * const m, modules) {
if (m->type() == CSwordModuleInfo::GenericBook ) {
const CSBMI * const book = dynamic_cast<const CSBMI *>(m);
- if (book != 0)
+ if (book != nullptr)
m_modules.append(book);
}
}
@@ -161,13 +163,14 @@ void CBookKeyChooser::setModules(const QList<const CSwordModuleInfo *> & modules
}
}
- int maxWidth = (int) ((float) totalWidth / (float) m_modules.first()->depth());
+ int maxWidth = static_cast<int>(static_cast<float>(totalWidth)
+ / m_modules.first()->depth());
w->comboBox().setMaximumWidth(maxWidth);
w->comboBox().setCurrentIndex(0);
- connect(w, SIGNAL(changed(int)), SLOT(keyChooserChanged(int)));
- connect(w, SIGNAL(focusOut(int)), SLOT(keyChooserChanged(int)));
+ BT_CONNECT(w, SIGNAL(changed(int)), SLOT(keyChooserChanged(int)));
+ BT_CONNECT(w, SIGNAL(focusOut(int)), SLOT(keyChooserChanged(int)));
m_layout->addWidget(w);
w->setProperty(ID_PROPERTY_NAME, i+1);
@@ -176,18 +179,18 @@ void CBookKeyChooser::setModules(const QList<const CSwordModuleInfo *> & modules
//set the tab order of the key chooser widgets
- CKeyChooserWidget * chooser = 0;
- CKeyChooserWidget * chooser_prev = 0;
+ CKeyChooserWidget * chooser = nullptr;
+ CKeyChooserWidget * chooser_prev = nullptr;
const int count = m_chooserWidgets.count();
for (int i = 0; i < count; i++) {
chooser = m_chooserWidgets.at(i);
- Q_ASSERT(chooser);
+ BT_ASSERT(chooser);
if (chooser_prev)
QWidget::setTabOrder(chooser_prev, chooser);
chooser_prev = chooser;
}
- QWidget::setTabOrder(chooser, 0);
+ QWidget::setTabOrder(chooser, nullptr);
updateKey(m_key);
adjustFont(); // only when refresh is set.
@@ -240,7 +243,7 @@ void CBookKeyChooser::keyChooserChanged(int newIndex) {
sender()->property(ID_PROPERTY_NAME).toInt());
for (int i = 0; i < max; i++) {
CKeyChooserWidget * const chooser = m_chooserWidgets.at(i);
- Q_ASSERT(chooser);
+ BT_ASSERT(chooser);
const QString currentText = chooser->comboBox().currentText();
if (currentText.isEmpty())
break;
diff --git a/src/frontend/keychooser/cbookkeychooser.h b/src/frontend/keychooser/cbookkeychooser.h
index c01e0e9..67703aa 100644
--- a/src/frontend/keychooser/cbookkeychooser.h
+++ b/src/frontend/keychooser/cbookkeychooser.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -31,30 +31,18 @@ class CBookKeyChooser: public CKeyChooser {
public:
- CBookKeyChooser(const QList<const CSwordModuleInfo *> & modules,
+ CBookKeyChooser(const BtConstModuleList & modules,
BTHistory * history,
- CSwordKey * key = 0,
- QWidget * parent = 0);
+ CSwordKey * key = nullptr,
+ QWidget * parent = nullptr);
- /**
- Reimplemented from CKeyChooser.
- */
- virtual void refreshContent();
+ void refreshContent() override;
- /**
- * Sets another module to this keychooser
- */
- virtual void setModules(const QList<const CSwordModuleInfo *> & modules,
- bool refresh = false);
- /**
- * Returns the key of this keychooser
- */
- virtual CSwordKey * key();
+ void setModules(const BtConstModuleList & modules,
+ bool refresh = false) override;
+ CSwordKey * key() override;
- /**
- * Sets a new key to this keychooser
- */
- virtual void setKey(CSwordKey * key);
+ void setKey(CSwordKey * key) override;
/**
* Sets a new key to this keychooser
@@ -66,7 +54,7 @@ public slots: // Public slots
/**
* Updates the keychoosers for the given key but emit no signal.
*/
- void updateKey(CSwordKey * key);
+ void updateKey(CSwordKey * key) override;
protected: /* Methods: */
@@ -76,8 +64,7 @@ protected: /* Methods: */
*/
void setupCombo(const QString & key, const int depth, const int currentItem);
- /** No descriptions */
- virtual void adjustFont();
+ void adjustFont() override;
protected slots:
@@ -86,7 +73,7 @@ protected slots:
*/
void keyChooserChanged(int);
- virtual void setKey(const QString & newKey);
+ void setKey(const QString & newKey) override;
private: /* Fields: */
diff --git a/src/frontend/keychooser/cbooktreechooser.cpp b/src/frontend/keychooser/cbooktreechooser.cpp
index 96917d8..e793a17 100644
--- a/src/frontend/keychooser/cbooktreechooser.cpp
+++ b/src/frontend/keychooser/cbooktreechooser.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -17,9 +17,10 @@
#include "backend/drivers/cswordbookmoduleinfo.h"
#include "backend/keys/cswordtreekey.h"
#include "frontend/keychooser/bthistory.h"
+#include "util/btconnect.h"
-CBookTreeChooser::CBookTreeChooser(const QList<const CSwordModuleInfo *> & modules,
+CBookTreeChooser::CBookTreeChooser(const BtConstModuleList & modules,
BTHistory * historyPtr,
CSwordKey * key,
QWidget * parent)
@@ -32,7 +33,7 @@ CBookTreeChooser::CBookTreeChooser(const QList<const CSwordModuleInfo *> & modul
//if there is no module there is no key either
if (!modules.count()) {
m_modules.clear();
- m_key = 0;
+ m_key = nullptr;
}
//now setup the keychooser widgets
@@ -45,11 +46,14 @@ CBookTreeChooser::CBookTreeChooser(const QList<const CSwordModuleInfo *> & modul
m_treeView->setHeaderHidden(true);
//when user selects the item whe must react
- connect(m_treeView, SIGNAL(currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(itemActivated(QTreeWidgetItem*)));
+ BT_CONNECT(m_treeView,
+ SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
+ SLOT(itemActivated(QTreeWidgetItem *)));
setKey(key);
adjustFont();
- connect(this, SIGNAL(keyChanged(CSwordKey*)), history(), SLOT(add(CSwordKey*)) );
+ BT_CONNECT(this, SIGNAL(keyChanged(CSwordKey *)),
+ history(), SLOT(add(CSwordKey *)));
}
/** Sets a new key to this keychooser. Inherited from ckeychooser. */
@@ -85,16 +89,16 @@ void CBookTreeChooser::setKey(CSwordKey* newKey, const bool emitSignal) {
}
}
-void CBookTreeChooser::setModules(const QList<const CSwordModuleInfo*> &modules,
+void CBookTreeChooser::setModules(const BtConstModuleList &modules,
bool refresh)
{
- typedef CSwordBookModuleInfo CSBMI;
+ using CSBMI = CSwordBookModuleInfo;
//Add given modules into private list
m_modules.clear();
- Q_FOREACH (const CSwordModuleInfo *m, modules) {
+ Q_FOREACH(CSwordModuleInfo const * const m, modules) {
const CSBMI *book = dynamic_cast<const CSBMI*>(m);
- if (book != 0) {
+ if (book != nullptr) {
m_modules.append(book);
}
}
@@ -144,9 +148,8 @@ void CBookTreeChooser::updateKey( CSwordKey* key ) {
}
/** Reimplementation to handle tree creation on show. */
-void CBookTreeChooser::show() {
- CKeyChooser::show();
-
+void CBookTreeChooser::doShow() {
+ show();
if (!m_treeView->topLevelItemCount()) {
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
setupTree(); //create the tree structure
diff --git a/src/frontend/keychooser/cbooktreechooser.h b/src/frontend/keychooser/cbooktreechooser.h
index 17b5825..bebf5e3 100644
--- a/src/frontend/keychooser/cbooktreechooser.h
+++ b/src/frontend/keychooser/cbooktreechooser.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -33,55 +33,40 @@ class BTHistory;
class CBookTreeChooser : public CKeyChooser {
Q_OBJECT
public:
- CBookTreeChooser(const QList<const CSwordModuleInfo*> &modules,
- BTHistory *history, CSwordKey *key = 0,
- QWidget *parent = 0);
+ CBookTreeChooser(const BtConstModuleList &modules,
+ BTHistory *history, CSwordKey *key = nullptr,
+ QWidget *parent = nullptr);
- /**
- Reimplemented from CKeyChooser::refreshContent().
- */
- virtual void refreshContent();
+ void refreshContent() override;
- /**
- Reimplemented from CKeyChooser::setModules().
- */
- virtual void setModules(const QList<const CSwordModuleInfo*> &modules,
- bool refresh = true);
+ void setModules(const BtConstModuleList &modules,
+ bool refresh = true) override;
- /**
- Reimplemented from CKeyChooser::key().
- */
- virtual inline CSwordKey *key() {
+ inline CSwordKey *key() override {
return m_key;
}
- /**
- Reimplemented from CKeyChooser::setKey().
- */
- virtual void setKey(CSwordKey *key);
+ void setKey(CSwordKey *key) override;
void setKey(CSwordKey*, const bool emitSinal);
public slots: // Public slots
- virtual void updateKey( CSwordKey* );
- /**
- * Reimplementation to handle tree creation on show.
- */
- virtual void show();
+ void updateKey( CSwordKey* ) override;
+ void doShow();
protected: // Protected methods
/**
* Creates the first level of the tree structure.
*/
void setupTree();
- virtual void adjustFont();
+ void adjustFont() override;
void addKeyChildren(CSwordTreeKey* key, QTreeWidgetItem* item);
protected slots: // Protected slots
void itemActivated( QTreeWidgetItem* item );
- void setKey(const QString & newKey);
+ void setKey(const QString & newKey) override;
private:
QList<const CSwordBookModuleInfo*> m_modules;
diff --git a/src/frontend/keychooser/ckeychooser.cpp b/src/frontend/keychooser/ckeychooser.cpp
index 96b5638..5cc229e 100644
--- a/src/frontend/keychooser/ckeychooser.cpp
+++ b/src/frontend/keychooser/ckeychooser.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -19,26 +19,27 @@
#include "frontend/keychooser/cbookkeychooser.h"
#include "frontend/keychooser/clexiconkeychooser.h"
#include "frontend/keychooser/versekeychooser/cbiblekeychooser.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
-CKeyChooser::CKeyChooser(const QList<const CSwordModuleInfo *> &,
+CKeyChooser::CKeyChooser(const BtConstModuleList &,
BTHistory * historyPtr,
QWidget * parent)
: QWidget(parent)
, m_history(historyPtr)
{
- bool ok = QObject::connect(history(), SIGNAL(historyMoved(QString)),
- this, SLOT(setKey(const QString &)));
- Q_ASSERT(ok);
+ BT_CONNECT(history(), SIGNAL(historyMoved(QString)),
+ this, SLOT(setKey(QString const &)));
}
-CKeyChooser * CKeyChooser::createInstance(const QList<const CSwordModuleInfo *> & modules,
+CKeyChooser * CKeyChooser::createInstance(const BtConstModuleList & modules,
BTHistory * historyPtr,
CSwordKey * key,
QWidget * parent)
{
- Q_ASSERT(!modules.empty());
- Q_ASSERT(modules.first()->type() == CSwordModuleInfo::Commentary
+ BT_ASSERT(!modules.empty());
+ BT_ASSERT(modules.first()->type() == CSwordModuleInfo::Commentary
|| modules.first()->type() == CSwordModuleInfo::Bible
|| modules.first()->type() == CSwordModuleInfo::Lexicon
|| modules.first()->type() == CSwordModuleInfo::GenericBook);
diff --git a/src/frontend/keychooser/ckeychooser.h b/src/frontend/keychooser/ckeychooser.h
index 79706cc..c18adbe 100644
--- a/src/frontend/keychooser/ckeychooser.h
+++ b/src/frontend/keychooser/ckeychooser.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -14,10 +14,11 @@
#include <QWidget>
+#include "backend/drivers/btmodulelist.h"
+
class BTHistory;
class CSwordKey;
-class CSwordModuleInfo;
class QAction;
/**
@@ -45,7 +46,7 @@ public: /* Methods: */
* @param key if not NULL, the @ref CKey the KeyChooser should be set to
* @param parent the parent of the widget to create
*/
- static CKeyChooser * createInstance(const QList<const CSwordModuleInfo *> & modules,
+ static CKeyChooser * createInstance(const BtConstModuleList & modules,
BTHistory * history,
CSwordKey * key,
QWidget * parent);
@@ -72,7 +73,7 @@ public slots:
/**
Sets the module of this keychooser and refreshes the comboboxes
*/
- virtual void setModules(const QList<const CSwordModuleInfo *> & modules,
+ virtual void setModules(const BtConstModuleList & modules,
bool refresh = true) = 0;
/**
@@ -89,9 +90,9 @@ signals:
protected: /* Methods: */
- CKeyChooser(const QList<const CSwordModuleInfo *> & info,
+ CKeyChooser(const BtConstModuleList & info,
BTHistory * history,
- QWidget * parent = 0);
+ QWidget * parent = nullptr);
/**
Resets the appropriate font to for the modules.
diff --git a/src/frontend/keychooser/ckeychooserwidget.cpp b/src/frontend/keychooser/ckeychooserwidget.cpp
index ea3421e..2f2d384 100644
--- a/src/frontend/keychooser/ckeychooserwidget.cpp
+++ b/src/frontend/keychooser/ckeychooserwidget.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -16,6 +16,7 @@
#include <QString>
#include <QWheelEvent>
#include "frontend/keychooser/cscrollerwidgetset.h"
+#include "util/btconnect.h"
class BtKeyLineEdit : public QLineEdit {
@@ -27,7 +28,7 @@ public: /* Methods: */
protected: /* Methods: */
- virtual void focusInEvent(QFocusEvent * event) {
+ void focusInEvent(QFocusEvent * event) override {
const Qt::FocusReason reason = event->reason();
if (reason == Qt::OtherFocusReason)
selectAll();
@@ -85,7 +86,7 @@ bool CKCComboBox::eventFilter(QObject * o, QEvent * e) {
void CKCComboBox::wheelEvent(QWheelEvent * e) {
return QComboBox::wheelEvent(e); /// \bug rest method won't get executed.
- const signed int change = (int)((float)e->delta() / (float)120);
+ int const change = static_cast<int>(static_cast<float>(e->delta()) / 120);
int current = currentIndex();
if ((current + change >= 0) && (current + change < count()) ) {
@@ -157,17 +158,13 @@ void CKeyChooserWidget::reset(const QStringList * list, int index, bool do_emit)
//DON'T REMOVE THE HIDE: Otherwise QComboBox's sizeHint() function won't work properly
m_comboBox->hide();
m_comboBox->clear();
- if (list)
- m_comboBox->insertItems(-1, *list);
-
- if (!list || (list && !list->count())) { // nothing in the combobox
- setEnabled(false);
- } else if (!isEnabled()) { // was disabled
+ if (list && !list->empty()) {
+ m_comboBox->insertItems(0, *list); // Prepend items
setEnabled(true);
- }
-
- if (list->count())
m_comboBox->setCurrentIndex(index);
+ } else {
+ setEnabled(false);
+ }
if (do_emit)
emit changed(m_comboBox->currentIndex());
@@ -206,17 +203,16 @@ void CKeyChooserWidget::init() {
m_mainLayout->addWidget(m_scroller);
m_mainLayout->addSpacing(0);
- setTabOrder(m_comboBox, 0);
+ setTabOrder(m_comboBox, nullptr);
setFocusProxy(m_comboBox);
- connect(m_scroller, SIGNAL(scroller_pressed()), SLOT(lock()));
- connect(m_scroller, SIGNAL(scroller_released()), SLOT(unlock()));
- connect(m_scroller, SIGNAL(change(int)), SLOT(changeCombo(int)));
- connect(m_comboBox, SIGNAL(activated(int)), SLOT(slotComboChanged(int)));
- // connect(m_comboBox, SIGNAL(activated(const QString&)), SLOT(slotReturnPressed(const QString&)));
- connect(m_comboBox->lineEdit(), SIGNAL(returnPressed()),
- SLOT(slotReturnPressed()));
- connect(m_comboBox, SIGNAL(focusOut(int)), SIGNAL(focusOut(int)));
+ BT_CONNECT(m_scroller, SIGNAL(scroller_pressed()), SLOT(lock()));
+ BT_CONNECT(m_scroller, SIGNAL(scroller_released()), SLOT(unlock()));
+ BT_CONNECT(m_scroller, SIGNAL(change(int)), SLOT(changeCombo(int)));
+ BT_CONNECT(m_comboBox, SIGNAL(activated(int)), SLOT(slotComboChanged(int)));
+ BT_CONNECT(m_comboBox->lineEdit(), SIGNAL(returnPressed()),
+ SLOT(slotReturnPressed()));
+ BT_CONNECT(m_comboBox, SIGNAL(focusOut(int)), SIGNAL(focusOut(int)));
updatelock = false;
m_isResetting = false;
@@ -224,7 +220,7 @@ void CKeyChooserWidget::init() {
/** Is called when the return key was presed in the combobox. */
void CKeyChooserWidget::slotReturnPressed() {
- Q_ASSERT(m_comboBox->lineEdit());
+ BT_ASSERT(m_comboBox->lineEdit());
const QString text(m_comboBox->lineEdit()->text());
for (int index = 0; index < m_comboBox->count(); ++index) {
diff --git a/src/frontend/keychooser/ckeychooserwidget.h b/src/frontend/keychooser/ckeychooserwidget.h
index a1fd31d..efc1fb5 100644
--- a/src/frontend/keychooser/ckeychooserwidget.h
+++ b/src/frontend/keychooser/ckeychooserwidget.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -15,6 +15,7 @@
#include <QComboBox>
#include <QStringList>
+#include "util/btassert.h"
class CLexiconKeyChooser;
@@ -35,13 +36,13 @@ class CKCComboBox: public QComboBox {
public: /* Methods: */
- CKCComboBox(QWidget * parent = 0);
+ CKCComboBox(QWidget * parent = nullptr);
protected: /* Methods: */
- virtual bool eventFilter(QObject * o, QEvent * e);
+ bool eventFilter(QObject * o, QEvent * e) override;
- virtual void wheelEvent(QWheelEvent * e);
+ void wheelEvent(QWheelEvent * e) override;
signals:
@@ -65,11 +66,11 @@ class CKeyChooserWidget: public QWidget {
public: /* Methods: */
- CKeyChooserWidget(QStringList * list = 0,
- QWidget * parent = 0);
+ CKeyChooserWidget(QStringList * list = nullptr,
+ QWidget * parent = nullptr);
CKeyChooserWidget(int count = 0,
- QWidget * parent = 0);
+ QWidget * parent = nullptr);
/**
* This function does clear the combobox, then fill in
@@ -90,7 +91,7 @@ public: /* Methods: */
* Initializes this widget. We need this function because
* we have more than one constructor.
*/
- virtual void init();
+ void init();
/**
* Sets the tooltips for the given entries using the parameters as text.
@@ -109,7 +110,7 @@ public: /* Methods: */
* Return the combobox of this key chooser widget.
*/
QComboBox & comboBox() const {
- Q_ASSERT(m_comboBox);
+ BT_ASSERT(m_comboBox);
return *m_comboBox;
}
diff --git a/src/frontend/keychooser/clexiconkeychooser.cpp b/src/frontend/keychooser/clexiconkeychooser.cpp
index 2c6545a..27a7dea 100644
--- a/src/frontend/keychooser/clexiconkeychooser.cpp
+++ b/src/frontend/keychooser/clexiconkeychooser.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -16,10 +16,11 @@
#include "frontend/keychooser/bthistory.h"
#include "frontend/keychooser/ckeychooserwidget.h"
#include "frontend/keychooser/cscrollbutton.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-CLexiconKeyChooser::CLexiconKeyChooser(const QList<const CSwordModuleInfo *> & modules,
+CLexiconKeyChooser::CLexiconKeyChooser(const BtConstModuleList & modules,
BTHistory * historyPtr,
CSwordKey * key,
QWidget * parent)
@@ -51,12 +52,13 @@ CLexiconKeyChooser::CLexiconKeyChooser(const QList<const CSwordModuleInfo *> & m
m_layout->addWidget(m_widget, 0, Qt::AlignLeft);
- connect(m_widget, SIGNAL(changed(int)), SLOT(activated(int)));
- connect(m_widget, SIGNAL(focusOut(int)), SLOT(activated(int)));
+ BT_CONNECT(m_widget, SIGNAL(changed(int)), SLOT(activated(int)));
+ BT_CONNECT(m_widget, SIGNAL(focusOut(int)), SLOT(activated(int)));
setModules(modules, true);
setKey(key);
- connect(this, SIGNAL(keyChanged(CSwordKey*)), history(), SLOT(add(CSwordKey*)) );
+ BT_CONNECT(this, SIGNAL(keyChanged(CSwordKey *)),
+ history(), SLOT(add(CSwordKey *)) );
}
CSwordKey* CLexiconKeyChooser::key() {
@@ -109,7 +111,7 @@ void CLexiconKeyChooser::refreshContent() {
// qWarning("resetted");
}
else {
- typedef std::multimap<unsigned int, const QStringList*> EntryMap;
+ using EntryMap = std::multimap<unsigned int, QStringList const *>;
EntryMap entryMap;
QListIterator<const CSwordLexiconModuleInfo*> mit(m_modules);
@@ -149,20 +151,17 @@ void CLexiconKeyChooser::refreshContent() {
}
-void CLexiconKeyChooser::setModules(const QList<const CSwordModuleInfo*> &modules,
+void CLexiconKeyChooser::setModules(const BtConstModuleList &modules,
bool refresh)
{
- typedef CSwordLexiconModuleInfo CSLMI;
+ using CSLMI = CSwordLexiconModuleInfo;
while (!m_modules.isEmpty())
m_modules.takeFirst(); // not deleting the pointer
- Q_FOREACH(const CSwordModuleInfo *m, modules) {
- const CSLMI *lexicon = dynamic_cast<const CSLMI*>(m);
- if (lexicon != 0) {
+ Q_FOREACH(CSwordModuleInfo const * const m, modules)
+ if (CSLMI const * const lexicon = dynamic_cast<CSLMI const *>(m))
m_modules.append(lexicon);
- }
- }
if (refresh) {
refreshContent();
diff --git a/src/frontend/keychooser/clexiconkeychooser.h b/src/frontend/keychooser/clexiconkeychooser.h
index 5f14747..cb59bca 100644
--- a/src/frontend/keychooser/clexiconkeychooser.h
+++ b/src/frontend/keychooser/clexiconkeychooser.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -34,38 +34,27 @@ class CLexiconKeyChooser : public CKeyChooser {
Q_OBJECT
public:
- CLexiconKeyChooser(const QList<const CSwordModuleInfo*> &modules,
- BTHistory *history, CSwordKey *key = 0,
- QWidget *parent = 0);
+ CLexiconKeyChooser(const BtConstModuleList &modules,
+ BTHistory *history, CSwordKey *key = nullptr,
+ QWidget *parent = nullptr);
public slots:
- /**
- Reimplemented from CKeyChooser::key().
- */
- virtual CSwordKey *key();
- /**
- Reimplemented from CKeyChooser::setKey().
- */
- virtual void setKey(CSwordKey* key);
+ CSwordKey *key() override;
+
+ void setKey(CSwordKey* key) override;
/**
* used to react to changes in the @ref CKeyChooserWidget
*
* @param index not used
**/
- virtual void activated(int index);
+ void activated(int index);
- /**
- Reimplemented from CKeyChooser::refreshContent().
- */
- virtual void refreshContent();
+ void refreshContent() override;
- /**
- Reimplemented from CKeyChooser::setModules().
- */
- virtual void setModules(const QList<const CSwordModuleInfo*> &modules,
- bool refresh = true);
+ void setModules(const BtConstModuleList &modules,
+ bool refresh = true) override;
protected:
CKeyChooserWidget *m_widget;
@@ -73,13 +62,13 @@ class CLexiconKeyChooser : public CKeyChooser {
QList<const CSwordLexiconModuleInfo*> m_modules;
QHBoxLayout *m_layout;
- virtual inline void adjustFont() {}
+ inline void adjustFont() override {}
public slots: // Public slots
- virtual void updateKey(CSwordKey* key);
+ void updateKey(CSwordKey* key) override;
protected slots:
- virtual void setKey(const QString & newKey);
+ void setKey(const QString & newKey) override;
};
diff --git a/src/frontend/keychooser/cscrollbutton.cpp b/src/frontend/keychooser/cscrollbutton.cpp
index 775d4db..1e46ecc 100644
--- a/src/frontend/keychooser/cscrollbutton.cpp
+++ b/src/frontend/keychooser/cscrollbutton.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -52,13 +52,13 @@ void CScrollButton::mouseMoveEvent(QMouseEvent *e) {
if (vchange != 0) {
// Adapt the change value, so we get a more natural feeling:
if(vchange > 0)
- m_movement += pow((float)vchange/10.0, 1.2);
+ m_movement += pow(vchange/10.0f, 1.2);
else // (vchange < 0)
- m_movement -= pow(-(float)vchange/10.0, 1.2);
+ m_movement -= pow(-vchange/10.0f, 1.2);
// Emit the change request signal only when the mouse was moved far enough
if (m_movement >= 1.0 || m_movement <= -1.0) {
- emit change_requested((int) m_movement);
+ emit change_requested(static_cast<int>(m_movement));
m_movement = 0.0;
}
}
diff --git a/src/frontend/keychooser/cscrollbutton.h b/src/frontend/keychooser/cscrollbutton.h
index 2b3f662..17b45e8 100644
--- a/src/frontend/keychooser/cscrollbutton.h
+++ b/src/frontend/keychooser/cscrollbutton.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -26,7 +26,7 @@ class QWidget;
class CScrollButton: public QToolButton {
Q_OBJECT
public:
- CScrollButton(QWidget *parent = 0);
+ CScrollButton(QWidget *parent = nullptr);
signals:
/**
@@ -53,19 +53,15 @@ class CScrollButton: public QToolButton {
/**
* \brief Grabs the mouse on left button click and emits lock().
*/
- virtual void mousePressEvent(QMouseEvent *e);
+ void mousePressEvent(QMouseEvent *e) override;
/**
* \brief If the mouse is grabbed and we release the left mouse button,
* releases the mouse and emits unlock().
*/
- virtual void mouseReleaseEvent(QMouseEvent *e);
+ void mouseReleaseEvent(QMouseEvent *e) override;
- /**
- * \brief Reimplementation of QWidget::mouseMoveEvent() to process mouse
- move events.
- */
- virtual void mouseMoveEvent(QMouseEvent *e);
+ void mouseMoveEvent(QMouseEvent *e) override;
protected:
/**
diff --git a/src/frontend/keychooser/cscrollerwidgetset.cpp b/src/frontend/keychooser/cscrollerwidgetset.cpp
index e169ae9..a599bf5 100644
--- a/src/frontend/keychooser/cscrollerwidgetset.cpp
+++ b/src/frontend/keychooser/cscrollerwidgetset.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -14,6 +14,7 @@
#include <QVBoxLayout>
#include <QWheelEvent>
#include "frontend/keychooser/cscrollbutton.h"
+#include "util/btconnect.h"
#define WIDTH (static_cast<unsigned int>(16))
@@ -51,11 +52,12 @@ CScrollerWidgetSet::CScrollerWidgetSet(QWidget * parent)
m_layout->addWidget(m_buttonDown, 0);
setMinimumWidth(WIDTH); // Kludge to add some spacing but seems to work.
- connect(m_scrollButton, SIGNAL(lock()), SLOT(slotLock()));
- connect(m_scrollButton, SIGNAL(unlock()), SLOT(slotUnlock()));
- connect(m_scrollButton, SIGNAL(change_requested(int)), SLOT(slotScroller(int)));
- connect(m_buttonUp, SIGNAL(clicked()), SLOT(slotUpClick()));
- connect(m_buttonDown, SIGNAL(clicked()), SLOT(slotDownClick()));
+ BT_CONNECT(m_scrollButton, SIGNAL(lock()), SLOT(slotLock()));
+ BT_CONNECT(m_scrollButton, SIGNAL(unlock()), SLOT(slotUnlock()));
+ BT_CONNECT(m_scrollButton, SIGNAL(change_requested(int)),
+ SLOT(slotScroller(int)));
+ BT_CONNECT(m_buttonUp, SIGNAL(clicked()), SLOT(slotUpClick()));
+ BT_CONNECT(m_buttonDown, SIGNAL(clicked()), SLOT(slotDownClick()));
}
/** Sets the tooltips for the given entries using the parameters as text. */
@@ -70,16 +72,12 @@ void CScrollerWidgetSet::setToolTips(const QString & nextEntryTip,
void CScrollerWidgetSet::wheelEvent(QWheelEvent * e) {
- /**
- * The problem is, that wheel events do everytime have the delta value 120
- */
- const int vchange = ((e->delta() > 0) ? -1 : 1);
-
- if (vchange != 0) { // Do not emit a change with value 0
- emit change(vchange);
- e->accept();
- } else {
+ int const delta = e->delta();
+ if (delta == 0) {
e->ignore();
+ } else {
+ emit change((delta > 0) ? -1 : 1);
+ e->accept();
}
}
diff --git a/src/frontend/keychooser/cscrollerwidgetset.h b/src/frontend/keychooser/cscrollerwidgetset.h
index 2894928..016a282 100644
--- a/src/frontend/keychooser/cscrollerwidgetset.h
+++ b/src/frontend/keychooser/cscrollerwidgetset.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -30,7 +30,7 @@ class CScrollerWidgetSet: public QWidget {
public: /* Methods: */
- CScrollerWidgetSet(QWidget * parent = 0);
+ CScrollerWidgetSet(QWidget * parent = nullptr);
/**
* Sets the tooltips for the given entries using the parameters as text.
@@ -54,7 +54,7 @@ signals:
protected: /* Methods: */
- virtual void wheelEvent(QWheelEvent * e);
+ void wheelEvent(QWheelEvent * e) override;
protected slots:
diff --git a/src/frontend/keychooser/versekeychooser/btbiblekeywidget.cpp b/src/frontend/keychooser/versekeychooser/btbiblekeywidget.cpp
index 2ac2574..98cd47f 100644
--- a/src/frontend/keychooser/versekeychooser/btbiblekeywidget.cpp
+++ b/src/frontend/keychooser/versekeychooser/btbiblekeywidget.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -24,9 +24,8 @@
#include "bibletimeapp.h"
#include "frontend/keychooser/cscrollerwidgetset.h"
#include "frontend/keychooser/versekeychooser/btdropdownchooserbutton.h"
-#include "util/btsignal.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
class BtLineEdit : public QLineEdit {
@@ -35,7 +34,7 @@ class BtLineEdit : public QLineEdit {
: QLineEdit(parent) {
}
protected:
- void focusInEvent(QFocusEvent* event) {
+ void focusInEvent(QFocusEvent* event) override {
Qt::FocusReason reason = event->reason();
if (reason == Qt::OtherFocusReason) {
selectAll();
@@ -59,10 +58,10 @@ BtBibleKeyWidget::BtBibleKeyWidget(const CSwordBibleModuleInfo *mod,
setFocusPolicy(Qt::WheelFocus);
QToolButton* clearRef = new QToolButton(this);
- clearRef->setIcon(util::getIcon("edit_clear_locationbar"));
+ clearRef->setIcon(CResMgr::icon_clearEdit());
clearRef->setAutoRaise(true);
clearRef->setStyleSheet("QToolButton{margin:0px;}");
- connect(clearRef, SIGNAL(clicked()), SLOT(slotClearRef()) );
+ BT_CONNECT(clearRef, SIGNAL(clicked()), SLOT(slotClearRef()) );
m_bookScroller = new CScrollerWidgetSet(this);
@@ -83,8 +82,8 @@ BtBibleKeyWidget::BtBibleKeyWidget(const CSwordBibleModuleInfo *mod,
m_mainLayout->addWidget(m_verseScroller);
- setTabOrder(m_textbox, 0);
- m_dropDownButtons = new QWidget(0);
+ setTabOrder(m_textbox, nullptr);
+ m_dropDownButtons = new QWidget(nullptr);
m_dropDownButtons->setWindowFlags(Qt::Popup);
m_dropDownButtons->setAttribute(Qt::WA_WindowPropagation);
m_dropDownButtons->setCursor(Qt::ArrowCursor);
@@ -104,8 +103,8 @@ BtBibleKeyWidget::BtBibleKeyWidget(const CSwordBibleModuleInfo *mod,
m_dropDownHoverTimer.setInterval(500);
m_dropDownHoverTimer.setSingleShot(true);
- connect(&m_dropDownHoverTimer, SIGNAL(timeout()),
- m_dropDownButtons, SLOT(hide()));
+ BT_CONNECT(&m_dropDownHoverTimer, SIGNAL(timeout()),
+ m_dropDownButtons, SLOT(hide()));
QString scrollButtonToolTip(tr("Scroll through the entries of the list. Press the button and move the mouse to increase or decrease the item."));
m_bookScroller->setToolTips(
@@ -126,18 +125,26 @@ BtBibleKeyWidget::BtBibleKeyWidget(const CSwordBibleModuleInfo *mod,
// signals and slots connections
- connect(m_bookScroller, SIGNAL(change(int)), SLOT(slotStepBook(int)));
- connect(m_bookScroller, SIGNAL(scroller_pressed()), SLOT(slotUpdateLock()));
- connect(m_bookScroller, SIGNAL(scroller_released()), SLOT(slotUpdateUnlock()));
- connect(m_textbox, SIGNAL(returnPressed()), SLOT(slotReturnPressed()));
- connect(m_chapterScroller, SIGNAL(change(int)), SLOT(slotStepChapter(int)));
- connect(m_chapterScroller, SIGNAL(scroller_pressed()), SLOT(slotUpdateLock()));
- connect(m_chapterScroller, SIGNAL(scroller_released()), SLOT(slotUpdateUnlock()));
- connect(m_verseScroller, SIGNAL(change(int)), SLOT(slotStepVerse(int)));
- connect(m_verseScroller, SIGNAL(scroller_pressed()), SLOT(slotUpdateLock()));
- connect(m_verseScroller, SIGNAL(scroller_released()), SLOT(slotUpdateUnlock()));
- bool ok = connect(m_key->afterChangedSignaller(), SIGNAL(signal()), this, SLOT(updateText()));
- Q_ASSERT(ok);
+ BT_CONNECT(m_bookScroller, SIGNAL(change(int)), SLOT(slotStepBook(int)));
+ BT_CONNECT(m_bookScroller, SIGNAL(scroller_pressed()),
+ SLOT(slotUpdateLock()));
+ BT_CONNECT(m_bookScroller, SIGNAL(scroller_released()),
+ SLOT(slotUpdateUnlock()));
+ BT_CONNECT(m_textbox, SIGNAL(returnPressed()),
+ SLOT(slotReturnPressed()));
+ BT_CONNECT(m_chapterScroller, SIGNAL(change(int)),
+ SLOT(slotStepChapter(int)));
+ BT_CONNECT(m_chapterScroller, SIGNAL(scroller_pressed()),
+ SLOT(slotUpdateLock()));
+ BT_CONNECT(m_chapterScroller, SIGNAL(scroller_released()),
+ SLOT(slotUpdateUnlock()));
+ BT_CONNECT(m_verseScroller, SIGNAL(change(int)), SLOT(slotStepVerse(int)));
+ BT_CONNECT(m_verseScroller, SIGNAL(scroller_pressed()),
+ SLOT(slotUpdateLock()));
+ BT_CONNECT(m_verseScroller, SIGNAL(scroller_released()),
+ SLOT(slotUpdateUnlock()));
+ BT_CONNECT(m_key->afterChangedSignaller(), SIGNAL(signal()),
+ this, SLOT(updateText()));
setKey(key); // The order of these two functions is important.
setModule();
diff --git a/src/frontend/keychooser/versekeychooser/btbiblekeywidget.h b/src/frontend/keychooser/versekeychooser/btbiblekeywidget.h
index 7d94c94..7a28ca0 100644
--- a/src/frontend/keychooser/versekeychooser/btbiblekeywidget.h
+++ b/src/frontend/keychooser/versekeychooser/btbiblekeywidget.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -29,22 +29,22 @@ class BtBibleKeyWidget : public QWidget {
public:
BtBibleKeyWidget(const CSwordBibleModuleInfo *module,
- CSwordVerseKey *key, QWidget *parent = 0,
- const char *name = 0);
+ CSwordVerseKey *key, QWidget *parent = nullptr,
+ const char *name = nullptr);
~BtBibleKeyWidget();
bool setKey(CSwordVerseKey* key);
- void setModule(const CSwordBibleModuleInfo *m = 0);
- bool eventFilter(QObject *o, QEvent *e);
+ void setModule(const CSwordBibleModuleInfo *m = nullptr);
+ bool eventFilter(QObject *o, QEvent *e) override;
signals:
void beforeChange(CSwordVerseKey* key);
void changed(CSwordVerseKey* key);
protected:
- void enterEvent(QEvent *event);
- void leaveEvent(QEvent *event);
- void resizeEvent(QResizeEvent *event);
+ void enterEvent(QEvent *event) override;
+ void leaveEvent(QEvent *event) override;
+ void resizeEvent(QResizeEvent *event) override;
void resetDropDownButtons();
protected slots: // Protected slots
diff --git a/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.cpp b/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.cpp
index 70f800a..5c59717 100644
--- a/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.cpp
+++ b/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,6 +12,7 @@
#include <QWheelEvent>
#include "frontend/keychooser/versekeychooser/btversekeymenu.h"
#include "frontend/keychooser/versekeychooser/btbiblekeywidget.h"
+#include "util/btconnect.h"
const unsigned int ARROW_HEIGHT = 15;
@@ -31,7 +32,8 @@ BtDropdownChooserButton::BtDropdownChooserButton(BtBibleKeyWidget* ref)
BtVerseKeyMenu* m = new BtVerseKeyMenu(this);
// KAcceleratorManager::setNoAccel(m);
setMenu(m);
- QObject::connect(m, SIGNAL(triggered(QAction*)), this, SLOT(slotMenuTriggered(QAction*)));
+ BT_CONNECT(m, SIGNAL(triggered(QAction *)),
+ this, SLOT(slotMenuTriggered(QAction *)));
}
@@ -43,16 +45,13 @@ void BtDropdownChooserButton::mousePressEvent(QMouseEvent* e) {
QToolButton::mousePressEvent(e);
}
-void BtDropdownChooserButton::wheelEvent(QWheelEvent* e) {
- // The problem is, that wheel events do everytime have the delta value 120
- const int vchange = ((e->delta() > 0) ? (-1) : (1));
-
- if (vchange != 0) {//do not emit a change with value 0
- emit stepItem(vchange);
- e->accept();
- }
- else {
+void BtDropdownChooserButton::wheelEvent(QWheelEvent * e) {
+ int const delta = e->delta();
+ if (delta == 0) {
e->ignore();
+ } else {
+ emit stepItem((delta > 0) ? -1 : 1);
+ e->accept();
}
}
@@ -62,19 +61,18 @@ void BtDropdownChooserButton::wheelEvent(QWheelEvent* e) {
BtBookDropdownChooserButton::BtBookDropdownChooserButton(BtBibleKeyWidget* ref)
: BtDropdownChooserButton(ref) {
setToolTip(tr("Select book"));
- QObject::connect(this, SIGNAL(stepItem(int)), m_ref, SLOT(slotStepBook(int)));
+ BT_CONNECT(this, SIGNAL(stepItem(int)), m_ref, SLOT(slotStepBook(int)));
}
void BtBookDropdownChooserButton::newList() {
QMenu* m = menu();
QStringList* booklist = ref()->m_module->books();
- foreach (QString bookname, *booklist) {
- m->addAction(bookname);
- }
+ Q_FOREACH(QString const & bookname, *booklist)
+ m->addAction(bookname)->setProperty("bookname", bookname);
}
void BtBookDropdownChooserButton::slotMenuTriggered(QAction* action) {
- m_ref->slotChangeBook(action->text());
+ m_ref->slotChangeBook(action->property("bookname").toString());
}
@@ -83,19 +81,18 @@ void BtBookDropdownChooserButton::slotMenuTriggered(QAction* action) {
BtChapterDropdownChooserButton::BtChapterDropdownChooserButton(BtBibleKeyWidget* ref)
: BtDropdownChooserButton(ref) {
setToolTip(tr("Select chapter"));
- QObject::connect(this, SIGNAL(stepItem(int)), m_ref, SLOT(slotStepChapter(int)));
+ BT_CONNECT(this, SIGNAL(stepItem(int)), m_ref, SLOT(slotStepChapter(int)));
}
void BtChapterDropdownChooserButton::newList() {
QMenu* m = menu();
int count = ref()->m_module->chapterCount(ref()->m_key->book());
- for (int i = 1; i <= count; i++) {
- m->addAction(QString::number(i));
- }
+ for (int i = 1; i <= count; i++)
+ m->addAction(QString::number(i))->setProperty("chapter", i);
}
void BtChapterDropdownChooserButton::slotMenuTriggered(QAction* action) {
- m_ref->slotChangeChapter(action->text().toInt());
+ m_ref->slotChangeChapter(action->property("chapter").toInt());
}
@@ -104,17 +101,16 @@ void BtChapterDropdownChooserButton::slotMenuTriggered(QAction* action) {
BtVerseDropdownChooserButton::BtVerseDropdownChooserButton(BtBibleKeyWidget* ref)
: BtDropdownChooserButton(ref) {
setToolTip(tr("Select verse"));
- QObject::connect(this, SIGNAL(stepItem(int)), m_ref, SLOT(slotStepVerse(int)));
+ BT_CONNECT(this, SIGNAL(stepItem(int)), m_ref, SLOT(slotStepVerse(int)));
}
void BtVerseDropdownChooserButton::newList() {
QMenu* m = menu();
int count = ref()->m_module->verseCount(ref()->m_key->book(), ref()->m_key->getChapter());
- for (int i = 1; i <= count; i++) {
- m->addAction(QString::number(i));
- }
+ for (int i = 1; i <= count; i++)
+ m->addAction(QString::number(i))->setProperty("verse", i);
}
void BtVerseDropdownChooserButton::slotMenuTriggered(QAction* action) {
- m_ref->slotChangeVerse(action->text().toInt());
+ m_ref->slotChangeVerse(action->property("verse").toInt());
}
diff --git a/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.h b/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.h
index 646b7ef..d276bf8 100644
--- a/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.h
+++ b/src/frontend/keychooser/versekeychooser/btdropdownchooserbutton.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -26,7 +26,7 @@ class BtDropdownChooserButton : public QToolButton {
BtDropdownChooserButton(BtBibleKeyWidget* ref);
/** The item list is constructed here just before the menu is shown.*/
- virtual void mousePressEvent(QMouseEvent* event);
+ void mousePressEvent(QMouseEvent* event) override;
/** Recreates the menu list.*/
virtual void newList() = 0;
/** Returns the verse reference widget which this button belongs to.*/
@@ -38,7 +38,7 @@ class BtDropdownChooserButton : public QToolButton {
virtual void slotMenuTriggered(QAction* action) = 0;
protected:
BtBibleKeyWidget* m_ref;
- void wheelEvent(QWheelEvent* event);
+ void wheelEvent(QWheelEvent* event) override;
signals:
void stepItem(int step);
};
@@ -48,9 +48,9 @@ class BtBookDropdownChooserButton : public BtDropdownChooserButton {
Q_OBJECT
public:
BtBookDropdownChooserButton(BtBibleKeyWidget* ref);
- virtual void newList();
+ void newList() override;
public slots:
- virtual void slotMenuTriggered(QAction* action);
+ void slotMenuTriggered(QAction* action) override;
};
/** See BtDropdownChooserButton.*/
@@ -58,9 +58,9 @@ class BtChapterDropdownChooserButton : public BtDropdownChooserButton {
Q_OBJECT
public:
BtChapterDropdownChooserButton(BtBibleKeyWidget* ref);
- virtual void newList();
+ void newList() override;
public slots:
- virtual void slotMenuTriggered(QAction* action);
+ void slotMenuTriggered(QAction* action) override;
};
/** See BtDropdownChooserButton.*/
@@ -68,8 +68,8 @@ class BtVerseDropdownChooserButton : public BtDropdownChooserButton {
Q_OBJECT
public:
BtVerseDropdownChooserButton(BtBibleKeyWidget* ref);
- virtual void newList();
+ void newList() override;
public slots:
- virtual void slotMenuTriggered(QAction* action);
+ void slotMenuTriggered(QAction* action) override;
};
#endif
diff --git a/src/frontend/keychooser/versekeychooser/btversekeymenu.cpp b/src/frontend/keychooser/versekeychooser/btversekeymenu.cpp
index 9a8d35e..61dbcc2 100644
--- a/src/frontend/keychooser/versekeychooser/btversekeymenu.cpp
+++ b/src/frontend/keychooser/versekeychooser/btversekeymenu.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,6 +12,7 @@
#include <QMenu>
#include <QMouseEvent>
#include <QTimerEvent>
+#include "util/btconnect.h"
BtVerseKeyMenu::BtVerseKeyMenu(QWidget* parent)
@@ -19,21 +20,25 @@ BtVerseKeyMenu::BtVerseKeyMenu(QWidget* parent)
, m_timerId(0)
, m_firstClickLock(true)
{
- connect(this, SIGNAL(aboutToShow()),
- this, SLOT(startFirstClickDelayTimer()));
+ BT_CONNECT(this, SIGNAL(aboutToShow()),
+ this, SLOT(startFirstClickDelayTimer()));
}
void BtVerseKeyMenu::startFirstClickDelayTimer() {
m_firstClickLock = true;
- if (m_timerId)
+ if (m_timerId) {
killTimer(m_timerId);
+ m_timerId = 0;
+ }
m_timerId = startTimer(300);
}
void BtVerseKeyMenu::timerEvent(QTimerEvent* e) {
if (e->timerId() == m_timerId) {
- if (m_timerId)
+ if (m_timerId) {
killTimer(m_timerId);
+ m_timerId = 0;
+ }
m_firstClickLock = false;
}
else {
diff --git a/src/frontend/keychooser/versekeychooser/btversekeymenu.h b/src/frontend/keychooser/versekeychooser/btversekeymenu.h
index 18caab5..56cbdf5 100644
--- a/src/frontend/keychooser/versekeychooser/btversekeymenu.h
+++ b/src/frontend/keychooser/versekeychooser/btversekeymenu.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -29,9 +29,9 @@ class BtVerseKeyMenu : public QMenu {
public:
BtVerseKeyMenu(QWidget* parent);
protected:
- virtual void mouseReleaseEvent(QMouseEvent* event);
+ void mouseReleaseEvent(QMouseEvent* event) override;
/** Frees the mouse button release after the delay has elapsed.*/
- virtual void timerEvent(QTimerEvent* event);
+ void timerEvent(QTimerEvent* event) override;
private slots:
/** Starts the delay timer for the first mouse button release.*/
void startFirstClickDelayTimer();
diff --git a/src/frontend/keychooser/versekeychooser/cbiblekeychooser.cpp b/src/frontend/keychooser/versekeychooser/cbiblekeychooser.cpp
index e481020..6d4ca36 100644
--- a/src/frontend/keychooser/versekeychooser/cbiblekeychooser.cpp
+++ b/src/frontend/keychooser/versekeychooser/cbiblekeychooser.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -17,23 +17,25 @@
#include "frontend/keychooser/bthistory.h"
#include "frontend/keychooser/cscrollbutton.h"
#include "frontend/keychooser/versekeychooser/btbiblekeywidget.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-CBibleKeyChooser::CBibleKeyChooser(const QList<const CSwordModuleInfo *> & modules,
+CBibleKeyChooser::CBibleKeyChooser(const BtConstModuleList & modules,
BTHistory * historyPtr,
CSwordKey * key,
QWidget * parent)
: CKeyChooser(modules, historyPtr, parent)
, m_key(dynamic_cast<CSwordVerseKey *>(key))
{
- typedef CSwordBibleModuleInfo CSBMI;
+ using CSBMI = CSwordBibleModuleInfo;
- w_ref = 0;
+ w_ref = nullptr;
setModules(modules, false);
if (!m_modules.count()) {
qWarning() << "CBibleKeyChooser: module is not a Bible or commentary!";
- m_key = 0;
+ m_key = nullptr;
return;
}
QHBoxLayout* layout = new QHBoxLayout(this);
@@ -46,16 +48,15 @@ CBibleKeyChooser::CBibleKeyChooser(const QList<const CSwordModuleInfo *> & modul
setFocusProxy(w_ref);
layout->addWidget(w_ref);
- bool ok = connect(w_ref, SIGNAL(beforeChange(CSwordVerseKey *)), SLOT(beforeRefChange(CSwordVerseKey *)));
- Q_ASSERT(ok);
-
- ok =connect(w_ref, SIGNAL(changed(CSwordVerseKey *)), SLOT(refChanged(CSwordVerseKey *)));
- Q_ASSERT(ok);
+ BT_CONNECT(w_ref, SIGNAL(beforeChange(CSwordVerseKey *)),
+ SLOT(beforeRefChange(CSwordVerseKey *)));
+ BT_CONNECT(w_ref, SIGNAL(changed(CSwordVerseKey *)),
+ SLOT(refChanged(CSwordVerseKey *)));
setKey(m_key); //set the key without changing it, setKey(key()) would change it
- ok = connect(this, SIGNAL(keyChanged(CSwordKey*)), history(), SLOT(add(CSwordKey*)) );
- Q_ASSERT(ok);
+ BT_CONNECT(this, SIGNAL(keyChanged(CSwordKey *)),
+ history(), SLOT(add(CSwordKey *)));
}
CSwordKey* CBibleKeyChooser::key() {
@@ -63,8 +64,8 @@ CSwordKey* CBibleKeyChooser::key() {
}
void CBibleKeyChooser::setKey(CSwordKey* key) {
- Q_ASSERT(dynamic_cast<CSwordVerseKey*>(key));
- if (dynamic_cast<CSwordVerseKey*>(key) == 0) return;
+ BT_ASSERT(dynamic_cast<CSwordVerseKey *>(key));
+ if (dynamic_cast<CSwordVerseKey*>(key) == nullptr) return;
m_key = dynamic_cast<CSwordVerseKey*>(key);
w_ref->setKey(m_key);
@@ -74,15 +75,15 @@ void CBibleKeyChooser::setKey(CSwordKey* key) {
void CBibleKeyChooser::beforeRefChange(CSwordVerseKey* key) {
Q_UNUSED(key);
- Q_ASSERT(m_key);
+ BT_ASSERT(m_key);
if (!updatesEnabled())
return;
}
void CBibleKeyChooser::refChanged(CSwordVerseKey* key) {
- Q_ASSERT(m_key);
- Q_ASSERT(key);
+ BT_ASSERT(m_key);
+ BT_ASSERT(key);
if (!updatesEnabled())
return;
@@ -94,23 +95,18 @@ void CBibleKeyChooser::refChanged(CSwordVerseKey* key) {
setUpdatesEnabled(true);
}
-void CBibleKeyChooser::setModules(const QList<const CSwordModuleInfo*> &modules,
+void CBibleKeyChooser::setModules(const BtConstModuleList &modules,
bool refresh)
{
- typedef CSwordBibleModuleInfo CSBMI;
+ using CSBMI = CSwordBibleModuleInfo;
m_modules.clear();
- Q_FOREACH (const CSwordModuleInfo *mod, modules) {
+ Q_FOREACH(CSwordModuleInfo const * const mod, modules)
if (mod->type() == CSwordModuleInfo::Bible
|| mod->type() == CSwordModuleInfo::Commentary)
- {
- const CSBMI* bible = dynamic_cast<const CSBMI*>(mod);
- if (bible != 0) {
+ if (CSBMI const * const bible = dynamic_cast<CSBMI const *>(mod))
m_modules.append(bible);
- }
- }
- }
// First time this is called we havnt set up w_ref.
if (w_ref) w_ref->setModule(dynamic_cast<const CSwordBibleModuleInfo*>(m_modules.first()));
diff --git a/src/frontend/keychooser/versekeychooser/cbiblekeychooser.h b/src/frontend/keychooser/versekeychooser/cbiblekeychooser.h
index 91ad265..4f49862 100644
--- a/src/frontend/keychooser/versekeychooser/cbiblekeychooser.h
+++ b/src/frontend/keychooser/versekeychooser/cbiblekeychooser.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -37,26 +37,18 @@ class CBibleKeyChooser : public CKeyChooser {
Q_OBJECT
public:
- CBibleKeyChooser(const QList<const CSwordModuleInfo*> &modules,
- BTHistory *history, CSwordKey *key = 0,
- QWidget *parent = 0);
+ CBibleKeyChooser(const BtConstModuleList &modules,
+ BTHistory *history, CSwordKey *key = nullptr,
+ QWidget *parent = nullptr);
public slots:
- /**
- Reimplemented from CKeyChooser::key().
- */
- CSwordKey* key();
- /**
- Reimplemented from CKeyChooser::setKey().
- */
- virtual void setKey(CSwordKey *key);
+ CSwordKey* key() override;
- /**
- Reimplemented from CKeyChooser::setModules().
- */
- virtual void setModules(const QList<const CSwordModuleInfo*> &modules,
- bool refresh = true);
+ void setKey(CSwordKey *key) override;
+
+ void setModules(const BtConstModuleList &modules,
+ bool refresh = true) override;
/**
* used to do actions before key changes
@@ -67,13 +59,13 @@ class CBibleKeyChooser : public CKeyChooser {
*/
void refChanged(CSwordVerseKey *key);
- void updateKey(CSwordKey* key);
- void adjustFont();
- void refreshContent();
+ void updateKey(CSwordKey* key) override;
+ void adjustFont() override;
+ void refreshContent() override;
protected slots:
- virtual void setKey(const QString & newKey);
+ void setKey(const QString & newKey) override;
private:
BtBibleKeyWidget* w_ref;
diff --git a/src/frontend/messagedialog.cpp b/src/frontend/messagedialog.cpp
index f064f06..7909b93 100644
--- a/src/frontend/messagedialog.cpp
+++ b/src/frontend/messagedialog.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -13,6 +13,7 @@
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QPushButton>
+#include "util/btassert.h"
namespace message {
@@ -22,7 +23,7 @@ namespace {
void replaceText(QDialogButtonBox *box, QDialogButtonBox::StandardButton flag,
const QString &text) {
QPushButton *button(box->button(flag));
- if (button != 0) {
+ if (button != nullptr) {
button->setText(text);
}
}
@@ -38,17 +39,17 @@ QMessageBox::StandardButton bt_messageBox(QMessageBox::Icon icon,
messageBox.setTextFormat(Qt::RichText);
//We need the button box to translate the strings (the idea of this whole function)
QDialogButtonBox* box = dynamic_cast<QDialogButtonBox*>(messageBox.button(QMessageBox::Ok)->parent());
- Q_ASSERT(box);
+ BT_ASSERT(box);
messageBox.setStandardButtons(buttons);
messageBox.setDefaultButton(defaultButton);
prepareDialogBox(box);
- return (QMessageBox::StandardButton)messageBox.exec();
+ return static_cast<QMessageBox::StandardButton>(messageBox.exec());
}
} // anonymous namespace
void setQActionCheckedNoTrigger(QAction * const action, const bool checked) {
- Q_ASSERT(action);
+ BT_ASSERT(action);
const bool signalsWereBlocked = action->blockSignals(true);
action->setChecked(checked);
action->blockSignals(signalsWereBlocked);
diff --git a/src/frontend/messagedialog.h b/src/frontend/messagedialog.h
index 3f1a34b..eda477a 100644
--- a/src/frontend/messagedialog.h
+++ b/src/frontend/messagedialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp b/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp
index 10e4566..8e7250d 100644
--- a/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp
+++ b/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -14,11 +14,13 @@
#include <QDesktopWidget>
#include <QDialog>
#include <QDialogButtonBox>
+#include <QtGlobal>
#include <QVBoxLayout>
#include "backend/drivers/cswordmoduleinfo.h"
#include "frontend/searchdialog/analysis/csearchanalysisscene.h"
#include "frontend/searchdialog/analysis/csearchanalysisview.h"
#include "frontend/messagedialog.h"
+#include "util/btconnect.h"
namespace Search {
@@ -37,11 +39,10 @@ CSearchAnalysisDialog::CSearchAnalysisDialog(
// Set initial width based on the search data, but limit to the
// width of the desktop
- int width = (int)( m_analysis->width() + DIALOG_BORDER );
- int desktopWidth = QApplication::desktop()->screenGeometry(this).width();
- if (width > desktopWidth)
- width = desktopWidth;
- resize(width, DIALOG_HEIGHT);
+ int const width = static_cast<int>(m_analysis->width() + DIALOG_BORDER);
+ int const desktopWidth =
+ QApplication::desktop()->screenGeometry(this).width();
+ resize(qMin(width, desktopWidth), DIALOG_HEIGHT);
}
/** Initializes this dialog. */
@@ -62,10 +63,9 @@ void CSearchAnalysisDialog::initView() {
message::prepareDialogBox(m_buttonBox);
vboxLayout->addWidget(m_buttonBox);
- bool ok = QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
- Q_ASSERT(ok);
- ok = QObject::connect(m_buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
- Q_ASSERT(ok);
+ BT_CONNECT(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ BT_CONNECT(m_buttonBox, SIGNAL(clicked(QAbstractButton *)),
+ this, SLOT(buttonClicked(QAbstractButton *)));
}
void CSearchAnalysisDialog::buttonClicked(QAbstractButton* button) {
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisdialog.h b/src/frontend/searchdialog/analysis/csearchanalysisdialog.h
index 454e105..c95875f 100644
--- a/src/frontend/searchdialog/analysis/csearchanalysisdialog.h
+++ b/src/frontend/searchdialog/analysis/csearchanalysisdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -16,9 +16,6 @@
#include "backend/cswordmodulesearch.h"
-// Sword includes
-#include <listkey.h>
-
class CSwordModuleInfo;
class QAbstractButton;
@@ -36,14 +33,14 @@ class CSearchAnalysisDialog : public QDialog {
Q_OBJECT
public:
CSearchAnalysisDialog(const CSwordModuleSearch::Results &results,
- QWidget *parentDialog = 0);
+ QWidget *parentDialog = nullptr);
protected: // Protected methods
/**
* Initializes this dialog.
*/
void initView();
- void resizeEvent(QResizeEvent* event);
+ void resizeEvent(QResizeEvent* event) override;
private slots:
void buttonClicked(QAbstractButton* button);
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp b/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp
index c516184..6d41839 100644
--- a/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp
+++ b/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -17,19 +17,11 @@
#include <QRect>
#include "backend/drivers/cswordmoduleinfo.h"
#include "frontend/searchdialog/analysis/csearchanalysisscene.h"
-#include "util/htmlescape.h"
namespace Search {
-const int SPACE_BETWEEN_PARTS = 5;
-const int RIGHT_BORDER = 15;
-const int LEFT_BORDER = 15;
-const int LOWER_BORDER = 10;
-const int UPPER_BORDER = 10;
-
const int ITEM_TEXT_SIZE = 8;
-const int LABEL_TEXT_SIZE = 6;
//used for the shift between the bars
const int BAR_DELTAX = 4;
@@ -38,10 +30,6 @@ const int BAR_WIDTH = 2 + (2*BAR_DELTAX); //should be equal or bigger than the
// Used for the text below the bars
const int BAR_LOWER_BORDER = 100;
-const int LEGEND_INNER_BORDER = 5;
-const int LEGEND_DELTAY = 4;
-const int LEGEND_WIDTH = 85;
-
CSearchAnalysisItem::CSearchAnalysisItem(
const int moduleCount,
const QString &bookname,
@@ -51,7 +39,7 @@ CSearchAnalysisItem::CSearchAnalysisItem(
m_scaleFactor(scaleFactor),
m_bookName(bookname),
m_moduleCount(moduleCount),
- m_bufferPixmap(0)
+ m_bufferPixmap(nullptr)
{
m_resultCountArray.resize(m_moduleCount);
int index = 0;
@@ -63,9 +51,9 @@ CSearchAnalysisItem::~CSearchAnalysisItem() {
}
bool CSearchAnalysisItem::hasHitsInAnyModule() {
- foreach (const int hits, m_resultCountArray) {
- if (hits) return true;
- }
+ Q_FOREACH(int const hits, m_resultCountArray)
+ if (hits)
+ return true;
return false;
}
@@ -93,10 +81,12 @@ void CSearchAnalysisItem::paint(QPainter* painter, const QStyleOptionGraphicsIte
while (drawn < m_moduleCount) {
for (index = 0; index < m_moduleCount; index++) {
if (m_resultCountArray[index] == Value) {
- QPoint p1((int)rect().x() + (m_moduleCount - drawn - 1)*BAR_DELTAX,
- (int)rect().height() + (int)y() - BAR_LOWER_BORDER - (m_moduleCount - drawn)*BAR_DELTAY);
+ #define S(...) static_cast<int>(__VA_ARGS__)
+ QPoint p1(S(rect().x()) + (m_moduleCount - drawn - 1)*BAR_DELTAX,
+ S(rect().height()) + S(y()) - BAR_LOWER_BORDER - (m_moduleCount - drawn)*BAR_DELTAY);
QPoint p2(p1.x() + BAR_WIDTH,
- p1.y() - (int)( !m_resultCountArray[index] ? 0 : ((m_resultCountArray[index])*(*m_scaleFactor))) );
+ p1.y() - S(!m_resultCountArray[index] ? 0 : ((m_resultCountArray[index])*(*m_scaleFactor))));
+ #undef S
QRect r(p1, p2);
painter->fillRect(r, QBrush(CSearchAnalysisScene::getColor(index)) );
painter->drawRect(r);
@@ -131,13 +121,13 @@ int CSearchAnalysisItem::width() {
/** Returns the tooltip for this item. */
const QString CSearchAnalysisItem::getToolTip() {
- typedef CSwordModuleSearch::Results::const_iterator RCI;
- using util::htmlEscape;
+ using RCI = CSwordModuleSearch::Results::const_iterator;
QString toolTipString("<center><b>");
- toolTipString.append(htmlEscape(m_bookName)).append("</b></center><hr/>")
- .append("<table cellspacing=\"0\" cellpadding=\"3\" width=\"10"
- "0%\" height=\"100%\" align=\"center\">");
+ toolTipString.append(m_bookName.toHtmlEscaped())
+ .append("</b></center><hr/><table cellspacing=\"0\" "
+ "cellpadding=\"3\" width=\"100%\" height=\"100%\" "
+ "align=\"center\">");
/// \todo Fix that loop
int i = 0;
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisitem.h b/src/frontend/searchdialog/analysis/csearchanalysisitem.h
index ec2cd03..cb83db9 100644
--- a/src/frontend/searchdialog/analysis/csearchanalysisitem.h
+++ b/src/frontend/searchdialog/analysis/csearchanalysisitem.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -51,14 +51,14 @@ class CSearchAnalysisItem : public QGraphicsRectItem {
/**
* Returns the width of this item.
*/
- virtual int width();
+ int width();
/**
* Returns the tooltip for this item.
*/
const QString getToolTip();
private:
- virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*);
+ void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) override;
private: /* Fields: */
CSwordModuleSearch::Results m_results;
diff --git a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp
index e630846..b091710 100644
--- a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp
+++ b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -18,33 +18,19 @@
namespace Search {
-const int SPACE_BETWEEN_PARTS = 5;
-const int RIGHT_BORDER = 15;
-const int LEFT_BORDER = 15;
-const int LOWER_BORDER = 10;
-const int UPPER_BORDER = 10;
-
const int ITEM_TEXT_SIZE = 8;
-const int LABEL_TEXT_SIZE = 6;
-
-//used for the shift between the bars
-const int BAR_DELTAX = 4;
-const int BAR_DELTAY = 2;
-const int BAR_WIDTH = 2 + (2*BAR_DELTAX); //should be equal or bigger than the label font size
-// Used for the text below the bars
-const int BAR_LOWER_BORDER = 100;
const int LEGEND_INNER_BORDER = 5;
const int LEGEND_DELTAY = 4;
-const int LEGEND_WIDTH = 85;
void CSearchAnalysisLegendItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) {
painter->save();
//the outer rectangle
- QPoint p1( (int)(rect().x()), (int)(rect().y()) );
- QPoint p2( (int)(rect().x() + rect().width() ), (int)(rect().y() + rect().height()));
+ #define S(...) static_cast<int>(__VA_ARGS__)
+ QPoint p1(S(rect().x()), S(rect().y()));
+ QPoint p2(S(rect().x() + rect().width()), S(rect().y() + rect().height()));
QRect r(p1, p2);
r = r.normalized();
painter->drawRect(r);
@@ -55,9 +41,10 @@ void CSearchAnalysisLegendItem::paint(QPainter* painter, const QStyleOptionGraph
// for (unsigned int index=0; index < m_moduleList->count(); index++){
int moduleIndex = 0;
- Q_FOREACH(const CSwordModuleInfo *m, m_moduleList) {
+ Q_FOREACH(CSwordModuleInfo const * const m, m_moduleList) {
// the module color indicators
- QPoint p1( (int)(rect().x()) + LEGEND_INNER_BORDER, (int)(rect().y()) + LEGEND_INNER_BORDER + moduleIndex*(LEGEND_DELTAY + ITEM_TEXT_SIZE) );
+ QPoint p1(S(rect().x()) + LEGEND_INNER_BORDER, S(rect().y()) + LEGEND_INNER_BORDER + moduleIndex*(LEGEND_DELTAY + ITEM_TEXT_SIZE));
+ #undef S
QPoint p2(p1.x() + ITEM_TEXT_SIZE, p1.y() + ITEM_TEXT_SIZE);
QRect r(p1, p2);
painter->fillRect(r, QBrush(CSearchAnalysisScene::getColor(moduleIndex)) );
diff --git a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h
index f199aaf..55378f4 100644
--- a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h
+++ b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -14,22 +14,20 @@
#include <QGraphicsRectItem>
-
-class CSwordModuleInfo;
+#include "backend/drivers/btmodulelist.h"
namespace Search {
class CSearchAnalysisLegendItem : public QGraphicsRectItem {
public: /* Methods: */
- inline CSearchAnalysisLegendItem(const QList<const CSwordModuleInfo*> &modules)
+ inline CSearchAnalysisLegendItem(const BtConstModuleList &modules)
: m_moduleList(modules) {}
private: /* Methods: */
- /** Reimplementation of QGraphicsItem::paint. */
- virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*);
+ void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) override;
private: /* Fields: */
- QList<const CSwordModuleInfo*> m_moduleList;
+ BtConstModuleList m_moduleList;
};
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp b/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp
index 9b375e8..5f63cf6 100644
--- a/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp
+++ b/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -18,9 +18,11 @@
#include "frontend/searchdialog/analysis/csearchanalysisitem.h"
#include "frontend/searchdialog/analysis/csearchanalysislegenditem.h"
#include "frontend/searchdialog/csearchdialog.h"
-#include "util/htmlescape.h"
#include "util/tool.h"
+// Sword includes
+#include <listkey.h>
+
namespace Search {
@@ -31,7 +33,6 @@ const int LOWER_BORDER = 10;
const int UPPER_BORDER = 10;
const int ITEM_TEXT_SIZE = 8;
-const int LABEL_TEXT_SIZE = 6;
//used for the shift between the bars
const int BAR_DELTAX = 4;
@@ -48,7 +49,7 @@ const int LEGEND_WIDTH = 85;
CSearchAnalysisScene::CSearchAnalysisScene(QObject *parent )
: QGraphicsScene(parent),
m_scaleFactor(0.0),
- m_legend(0) {
+ m_legend(nullptr) {
setBackgroundBrush(QBrush(Qt::white));
setSceneRect(0, 0, 1, 1);
}
@@ -57,7 +58,7 @@ CSearchAnalysisScene::CSearchAnalysisScene(QObject *parent )
void CSearchAnalysisScene::analyse(
const CSwordModuleSearch::Results &results)
{
- typedef CSwordModuleSearch::Results::const_iterator RCI;
+ using RCI = CSwordModuleSearch::Results::const_iterator;
/**
* Steps of analysing our search result;
@@ -79,11 +80,11 @@ void CSearchAnalysisScene::analyse(
LEGEND_WIDTH, LEGEND_INNER_BORDER*2 + ITEM_TEXT_SIZE*numberOfModules + LEGEND_DELTAY*(numberOfModules - 1) );
m_legend->show();
- int xPos = (int)(LEFT_BORDER + m_legend->rect().width() + SPACE_BETWEEN_PARTS);
+ int xPos = static_cast<int>(LEFT_BORDER + m_legend->rect().width() + SPACE_BETWEEN_PARTS);
int moduleIndex = 0;
m_maxCount = 0;
int count = 0;
- CSwordVerseKey key(0);
+ CSwordVerseKey key(nullptr);
key.setKey("Genesis 1:1");
CSearchAnalysisItem* analysisItem = m_itemList[key.book()];
@@ -106,7 +107,7 @@ void CSearchAnalysisScene::analyse(
QString tip = analysisItem->getToolTip();
analysisItem->setToolTip(tip);
analysisItem->show();
- xPos += (int)analysisItem->width() + SPACE_BETWEEN_PARTS;
+ xPos += static_cast<int>(analysisItem->width() + SPACE_BETWEEN_PARTS);
}
ok = key.next(CSwordVerseKey::UseBook);
analysisItem = m_itemList[key.book()];
@@ -119,7 +120,7 @@ void CSearchAnalysisScene::analyse(
void CSearchAnalysisScene::setResults(
const CSwordModuleSearch::Results &results)
{
- typedef CSwordModuleSearch::Results::const_iterator RCI;
+ using RCI = CSwordModuleSearch::Results::const_iterator;
m_results.clear();
for (RCI it = results.begin(); it != results.end(); ++it) {
@@ -130,8 +131,8 @@ void CSearchAnalysisScene::setResults(
}
m_itemList.clear();
- CSearchAnalysisItem* analysisItem = 0;
- CSwordVerseKey key(0);
+ CSearchAnalysisItem* analysisItem = nullptr;
+ CSwordVerseKey key(nullptr);
key.setKey("Genesis 1:1");
do {
analysisItem = new CSearchAnalysisItem(m_results.count(), key.book(), &m_scaleFactor, m_results);
@@ -157,15 +158,15 @@ void CSearchAnalysisScene::reset() {
if (m_legend) m_legend->hide();
delete m_legend;
- m_legend = 0;
+ m_legend = nullptr;
update();
}
/** No descriptions */
void CSearchAnalysisScene::slotResized() {
- m_scaleFactor = (double)( (double)(height() - UPPER_BORDER - LOWER_BORDER - BAR_LOWER_BORDER - 100 - (m_results.count() - 1) * BAR_DELTAY)
- / (double)m_maxCount);
+ m_scaleFactor = static_cast<double>(height() - UPPER_BORDER - LOWER_BORDER - BAR_LOWER_BORDER - 100 - (m_results.count() - 1) * BAR_DELTAY)
+ / static_cast<double>(m_maxCount);
QHashIterator<QString, CSearchAnalysisItem*> it( m_itemList );
while ( it.hasNext() ) {
it.next();
@@ -214,7 +215,7 @@ unsigned int CSearchAnalysisScene::getCount(const QString &book,
unsigned int count = 0;
const unsigned int resultCount = result.getCount();
while (i < resultCount) {
- if (strncmp(book.toUtf8(), (const char *) *result.getElement(i), length))
+ if (strncmp(book.toUtf8(), result.getElement(i)->getText(), length))
break;
i++;
++count;
@@ -224,11 +225,9 @@ unsigned int CSearchAnalysisScene::getCount(const QString &book,
}
void CSearchAnalysisScene::saveAsHTML() {
- using util::htmlEscape;
-
- typedef CSwordModuleSearch::Results::const_iterator RCI;
+ using RCI = CSwordModuleSearch::Results::const_iterator;
- const QString fileName = QFileDialog::getSaveFileName(0,
+ const QString fileName = QFileDialog::getSaveFileName(nullptr,
tr("Save Search Analysis"),
QString::null,
tr("XHTML files (*.html *.HTML *.HTM *.htm);;All files (*)"));
@@ -258,7 +257,7 @@ void CSearchAnalysisScene::saveAsHTML() {
text += "</h1><p><span style=\"font-weight:bold\">";
text += tr("Search text:");
text += "</span>&nbsp;";
- text += htmlEscape(CSearchDialog::getSearchDialog()->searchText());
+ text += CSearchDialog::getSearchDialog()->searchText().toHtmlEscaped();
text += "</p><table><caption>";
text += tr("Results by work and book");
text += "</caption><tr><th>";
@@ -267,18 +266,18 @@ void CSearchAnalysisScene::saveAsHTML() {
for (RCI it = m_results.begin(); it != m_results.end(); ++it) {
text += "<th>";
- text += htmlEscape(it.key()->name());
+ text += it.key()->name().toHtmlEscaped();
text += "</th>";
}
text += "</tr>";
- CSwordVerseKey key(0);
+ CSwordVerseKey key(nullptr);
key.setKey("Genesis 1:1");
do {
text += "<tr><td>";
const QString keyBook(key.book());
- text += htmlEscape(keyBook);
+ text += keyBook.toHtmlEscaped();
text += "</td>";
int mi = 0; // Module index
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisscene.h b/src/frontend/searchdialog/analysis/csearchanalysisscene.h
index d1927d5..fde2a0a 100644
--- a/src/frontend/searchdialog/analysis/csearchanalysisscene.h
+++ b/src/frontend/searchdialog/analysis/csearchanalysisscene.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -20,9 +20,6 @@
#include "backend/cswordmodulesearch.h"
#include "frontend/searchdialog/analysis/csearchanalysisitem.h"
-// Sword includes
-#include <listkey.h>
-
class CSwordModuleInfo;
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisview.cpp b/src/frontend/searchdialog/analysis/csearchanalysisview.cpp
index 277c1a3..479f2bf 100644
--- a/src/frontend/searchdialog/analysis/csearchanalysisview.cpp
+++ b/src/frontend/searchdialog/analysis/csearchanalysisview.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -24,26 +24,10 @@ CSearchAnalysisView::CSearchAnalysisView(CSearchAnalysisScene* scene, QWidget* p
resize(sizeHint());
}
-
-/** Returns the sizeHint for this view */
-QSize CSearchAnalysisView::sizeHint() const {
- return QGraphicsView::sizeHint();
-}
-
/** No descriptions */
void CSearchAnalysisView::resizeEvent( QResizeEvent* e) {
QGraphicsView::resizeEvent(e);
scene()->setSceneRect(0, 0, scene()->sceneRect().width(), viewport()->height() );
}
-
-/** Returns the item at position p. If there no item at that point return 0.
-Is needed?
-*/
-//CSearchAnalysisItem* CSearchAnalysisView::itemAt( const QPoint& p )
-//{
-//}
-
-
-
}
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisview.h b/src/frontend/searchdialog/analysis/csearchanalysisview.h
index 4b072f3..97780dc 100644
--- a/src/frontend/searchdialog/analysis/csearchanalysisview.h
+++ b/src/frontend/searchdialog/analysis/csearchanalysisview.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -30,23 +30,9 @@ class CSearchAnalysisView : public QGraphicsView {
public:
CSearchAnalysisView(CSearchAnalysisScene* scene, QWidget* parent);
- /**
- * Returns the sizeHint for this view
- * We give back the size of the parent widgetas default.
- * This is a reimplementation from QCanvasView::sizeHint().
- */
- virtual QSize sizeHint() const;
-
- /**
- * Returns the item at position p or 0 if there is no item.
- */
- //CSearchAnalysisItem* itemAt( const QPoint& p );
-
protected:
- /**
- * Reimplementation.
- */
- virtual void resizeEvent(QResizeEvent* e);
+
+ void resizeEvent(QResizeEvent* e) override;
};
diff --git a/src/frontend/searchdialog/btsearchmodulechooserdialog.cpp b/src/frontend/searchdialog/btsearchmodulechooserdialog.cpp
index a5bfd2c..661bd09 100644
--- a/src/frontend/searchdialog/btsearchmodulechooserdialog.cpp
+++ b/src/frontend/searchdialog/btsearchmodulechooserdialog.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -16,6 +16,7 @@
#include <QToolButton>
#include "backend/bookshelfmodel/btbookshelftreemodel.h"
#include "backend/managers/cswordbackend.h"
+#include "util/btconnect.h"
#include "util/tool.h"
@@ -31,8 +32,11 @@ BtSearchModuleChooserDialog::BtSearchModuleChooserDialog(QWidget *parent,
BtBookshelfTreeModel::Grouping grouping(groupingOrderKey);
BtBookshelfTreeModel *treeModel = new BtBookshelfTreeModel(grouping, this);
treeModel->setCheckable(true);
- connect(treeModel, SIGNAL(groupingOrderChanged(BtBookshelfTreeModel::Grouping)),
- this, SLOT(slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping&)));
+ BT_CONNECT(treeModel,
+ SIGNAL(groupingOrderChanged(BtBookshelfTreeModel::Grouping)),
+ this,
+ SLOT(slotGroupingOrderChanged(
+ BtBookshelfTreeModel::Grouping const &)));
// Initialize the bookshelf widget:
bookshelfWidget()->showHideAction()->setVisible(false);
diff --git a/src/frontend/searchdialog/btsearchmodulechooserdialog.h b/src/frontend/searchdialog/btsearchmodulechooserdialog.h
index 79802b5..5b46835 100644
--- a/src/frontend/searchdialog/btsearchmodulechooserdialog.h
+++ b/src/frontend/searchdialog/btsearchmodulechooserdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -15,6 +15,7 @@
#include "frontend/btmodulechooserdialog.h"
+#include "backend/drivers/btconstmoduleset.h"
#include "backend/bookshelfmodel/btbookshelftreemodel.h"
@@ -24,15 +25,14 @@ class CSwordModuleInfo;
class BtSearchModuleChooserDialog: public BtModuleChooserDialog {
Q_OBJECT
public:
- BtSearchModuleChooserDialog(QWidget *parent = 0,
- Qt::WindowFlags flags = 0);
-
- inline void setCheckedModules(const QSet<CSwordModuleInfo*> &modules) {
- bookshelfWidget()->treeModel()->setCheckedModules(modules);
- }
- inline const QSet<CSwordModuleInfo*> &checkedModules() const {
- return bookshelfWidget()->treeModel()->checkedModules();
- }
+ BtSearchModuleChooserDialog(QWidget *parent = nullptr,
+ Qt::WindowFlags flags = nullptr);
+
+ inline void setCheckedModules(BtConstModuleSet const & modules)
+ { bookshelfWidget()->treeModel()->setCheckedModules(modules); }
+
+ inline BtConstModuleSet checkedModules() const
+ { return bookshelfWidget()->treeModel()->checkedModules(); }
protected slots:
void slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping &g);
diff --git a/src/frontend/searchdialog/btsearchoptionsarea.cpp b/src/frontend/searchdialog/btsearchoptionsarea.cpp
index d850344..ca92d4b 100644
--- a/src/frontend/searchdialog/btsearchoptionsarea.cpp
+++ b/src/frontend/searchdialog/btsearchoptionsarea.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -21,13 +21,14 @@
#include "backend/bookshelfmodel/btbookshelftreemodel.h"
#include "backend/config/btconfig.h"
#include "backend/managers/cswordbackend.h"
+#include "backend/drivers/btconstmoduleset.h"
#include "backend/drivers/cswordmoduleinfo.h"
#include "bibletimeapp.h"
#include "frontend/searchdialog/btsearchmodulechooserdialog.h"
#include "frontend/searchdialog/btsearchsyntaxhelpdialog.h"
#include "frontend/searchdialog/crangechooserdialog.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
#include "util/tool.h"
@@ -52,14 +53,14 @@ QString BtSearchOptionsArea::searchText() const {
return m_searchTextCombo->currentText();
}
-BtSearchOptionsArea::SearchType BtSearchOptionsArea::searchType() {
+CSwordModuleSearch::SearchType BtSearchOptionsArea::searchType() {
if (m_typeAndButton->isChecked()) {
- return BtSearchOptionsArea::AndType;
+ return CSwordModuleSearch::AndType;
}
if (m_typeOrButton->isChecked()) {
- return BtSearchOptionsArea::OrType;
+ return CSwordModuleSearch::OrType;
}
- return BtSearchOptionsArea::FullType;
+ return CSwordModuleSearch::FullType;
}
void BtSearchOptionsArea::setSearchText(const QString& text) {
@@ -102,17 +103,17 @@ void BtSearchOptionsArea::initView() {
m_searchButton = new QPushButton(this);
m_searchButton->setText(tr("&Search"));
- m_searchButton->setIcon(util::getIcon(CResMgr::searchdialog::icon));
+ m_searchButton->setIcon(CResMgr::searchdialog::icon());
m_searchButton->setToolTip(tr("Start to search the text in the chosen works"));
gridLayout->addWidget(m_searchButton, 0, 2);
m_chooseModulesButton = new QPushButton(tr("Ch&oose..."), searchGroupBox);
- m_chooseModulesButton->setIcon(util::getIcon(CResMgr::searchdialog::chooseworks_icon));
+ m_chooseModulesButton->setIcon(CResMgr::searchdialog::icon_chooseWorks());
m_chooseModulesButton->setToolTip( tr("Choose works for the search"));
gridLayout->addWidget(m_chooseModulesButton, 2, 2);
m_chooseRangeButton = new QPushButton(tr("S&etup..."), searchGroupBox);
- m_chooseRangeButton->setIcon(util::getIcon(CResMgr::searchdialog::setupscope_icon));
+ m_chooseRangeButton->setIcon(CResMgr::searchdialog::icon_setupScope());
m_chooseRangeButton->setToolTip(tr("Configure predefined scopes for search"));
gridLayout->addWidget(m_chooseRangeButton, 3, 2);
@@ -192,26 +193,30 @@ void BtSearchOptionsArea::initView() {
}
void BtSearchOptionsArea::initConnections() {
- QObject::connect( m_searchTextCombo->lineEdit(), SIGNAL(returnPressed ()),
- this, SLOT( slotSearchTextEditReturnPressed() )
- );
- connect(m_chooseModulesButton, SIGNAL(clicked()), this, SLOT(chooseModules()));
- connect(m_chooseRangeButton, SIGNAL(clicked()), this, SLOT(setupRanges()));
- connect(m_modulesCombo, SIGNAL(activated(int)), this, SLOT(moduleListTextSelected(int) ) );
- connect(m_helpLabel, SIGNAL(linkActivated(QString)), this, SLOT(syntaxHelp()));
- connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&)));
+ BT_CONNECT(m_searchTextCombo->lineEdit(), SIGNAL(returnPressed()),
+ this, SLOT(slotSearchTextEditReturnPressed()));
+ BT_CONNECT(m_chooseModulesButton, SIGNAL(clicked()),
+ this, SLOT(chooseModules()));
+ BT_CONNECT(m_chooseRangeButton, SIGNAL(clicked()),
+ this, SLOT(setupRanges()));
+ BT_CONNECT(m_modulesCombo, SIGNAL(activated(int)),
+ this, SLOT(moduleListTextSelected(int)));
+ BT_CONNECT(m_helpLabel, SIGNAL(linkActivated(QString)),
+ this, SLOT(syntaxHelp()));
+ BT_CONNECT(m_searchTextCombo, SIGNAL(editTextChanged(QString const &)),
+ this, SLOT(slotValidateText(QString const &)));
}
/** Sets the modules used by the search. */
-void BtSearchOptionsArea::setModules(const QList<const CSwordModuleInfo*> &modules) {
+void BtSearchOptionsArea::setModules(const BtConstModuleList &modules) {
QString t;
m_modules.clear(); //remove old modules
- QList<const CSwordModuleInfo*>::const_iterator end_it = modules.end();
+ BtConstModuleList::const_iterator end_it = modules.end();
- for (QList<const CSwordModuleInfo*>::const_iterator it(modules.begin()); it != end_it; ++it) {
+ for (BtConstModuleList::const_iterator it(modules.begin()); it != end_it; ++it) {
/// \todo Check for containsRef compat
- if (*it == 0) { //don't operate on null modules.
+ if (*it == nullptr) { //don't operate on null modules.
continue;
}
qDebug() << "new module:" << (*it)->name();
@@ -251,27 +256,20 @@ void BtSearchOptionsArea::moduleListTextSelected(int index) {
//create the module list
QString text = m_modulesCombo->itemText(index);
QStringList moduleNamesList = text.split(", ");
- QList<const CSwordModuleInfo*> moduleList;
- foreach(QString name, moduleNamesList) {
+ BtConstModuleList moduleList;
+ Q_FOREACH(QString const & name, moduleNamesList)
moduleList.append(CSwordBackend::instance()->findModuleByName(name));
- }
//set the list and the combobox list and text
setModules(moduleList);
}
void BtSearchOptionsArea::chooseModules() {
BtSearchModuleChooserDialog* dlg = new BtSearchModuleChooserDialog(this);
- QSet<CSwordModuleInfo*> ms;
- Q_FOREACH (const CSwordModuleInfo *module, modules()) {
- ms.insert(const_cast<CSwordModuleInfo*>(module));
- }
-
- dlg->setCheckedModules(ms);
+ dlg->setCheckedModules(BtConstModuleSet::fromList(modules()));
if (dlg->exec() == QDialog::Accepted) {
- QList<const CSwordModuleInfo*> ms;
- Q_FOREACH(const CSwordModuleInfo *m, dlg->checkedModules()) {
+ BtConstModuleList ms;
+ Q_FOREACH(CSwordModuleInfo const * const m, dlg->checkedModules())
ms.append(m);
- }
setModules(ms);
}
delete dlg;
@@ -284,12 +282,12 @@ void BtSearchOptionsArea::reset() {
void BtSearchOptionsArea::saveSettings() {
btConfig().setValue("properties/searchTexts", m_searchTextCombo->historyItems());
- SearchType t = FullType;
+ CSwordModuleSearch::SearchType t = CSwordModuleSearch::FullType;
if (m_typeAndButton->isChecked()) {
- t = AndType;
+ t = CSwordModuleSearch::AndType;
}
if (m_typeOrButton->isChecked()) {
- t = OrType;
+ t = CSwordModuleSearch::OrType;
}
btConfig().setValue(SearchTypeKey, t);
}
@@ -302,19 +300,20 @@ void BtSearchOptionsArea::readSettings() {
if (text.size() > 0)
m_searchTextCombo->addItem(text);
}
- connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&)));
+ BT_CONNECT(m_searchTextCombo, SIGNAL(editTextChanged(QString const &)),
+ this, SLOT(slotValidateText(QString const &)));
m_modulesCombo->insertItems(0, btConfig().value<QStringList>("history/searchModuleHistory", QStringList()));
for (int i = 0; i < m_modulesCombo->count(); ++i) {
m_modulesCombo->setItemData(i, m_modulesCombo->itemText(i), Qt::ToolTipRole);
}
- int stype = btConfig().value<int>(SearchTypeKey, AndType);
+ int stype = btConfig().value<int>(SearchTypeKey, CSwordModuleSearch::AndType);
switch (stype) {
- case AndType:
+ case CSwordModuleSearch::AndType:
m_typeAndButton->setChecked(true);
break;
- case OrType:
+ case CSwordModuleSearch::OrType:
m_typeOrButton->setChecked(true);
break;
default:
@@ -353,11 +352,12 @@ void BtSearchOptionsArea::refreshRanges() {
sword::ListKey BtSearchOptionsArea::searchScope() {
if (m_rangeChooserCombo->currentIndex() > 0) { //is not "no scope"
- BtConfig::StringMap map = btConfig().getSearchScopesForCurrentLocale();
- QString scope = map[ m_rangeChooserCombo->currentText() ];
- if (!scope.isEmpty()) {
- return sword::VerseKey().parseVerseList( (const char*)scope.toUtf8(), "Genesis 1:1", true);
- }
+ QString const scope = btConfig().getSearchScopesForCurrentLocale()[
+ m_rangeChooserCombo->currentText()];
+ if (!scope.isEmpty())
+ return sword::VerseKey().parseVerseList(scope.toUtf8().constData(),
+ "Genesis 1:1",
+ true);
}
return sword::ListKey();
}
@@ -416,14 +416,3 @@ void BtSearchOptionsArea::slotValidateText(const QString& /*newText*/) {
} // namespace Search
-QDataStream &operator<<(QDataStream &out, const Search::BtSearchOptionsArea::SearchType &searchType) {
- out << static_cast<qint8>(searchType);
- return out;
-}
-
-QDataStream &operator>>(QDataStream &in, Search::BtSearchOptionsArea::SearchType &searchType) {
- qint8 i;
- in >> i;
- searchType = (Search::BtSearchOptionsArea::SearchType) i;
- return in;
-}
diff --git a/src/frontend/searchdialog/btsearchoptionsarea.h b/src/frontend/searchdialog/btsearchoptionsarea.h
index a6483ac..9b535be 100644
--- a/src/frontend/searchdialog/btsearchoptionsarea.h
+++ b/src/frontend/searchdialog/btsearchoptionsarea.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -14,11 +14,12 @@
#include <QWidget>
+#include "backend/cswordmodulesearch.h"
+#include "backend/drivers/btmodulelist.h"
#include "backend/keys/cswordversekey.h"
#include "frontend/searchdialog/chistorycombobox.h"
-class CSwordModuleInfo;
class QComboBox;
class QEvent;
class QGridLayout;
@@ -35,13 +36,7 @@ class BtSearchOptionsArea : public QWidget {
Q_OBJECT
public:
- enum SearchType { /* Values provided for serialization */
- AndType = 0,
- OrType = 1,
- FullType = 2
- };
-
- BtSearchOptionsArea(QWidget *parent = 0);
+ BtSearchOptionsArea(QWidget *parent = nullptr);
~BtSearchOptionsArea();
/*
* Add text to search combox box history
@@ -56,14 +51,14 @@ class BtSearchOptionsArea : public QWidget {
*/
QString searchText() const;
- SearchType searchType();
+ CSwordModuleSearch::SearchType searchType();
inline QPushButton * searchButton() const { return m_searchButton; }
/**
Returns the list of used modules.
*/
- inline QList<const CSwordModuleInfo*> modules() const {
+ inline const BtConstModuleList & modules() const {
return m_modules;
}
@@ -93,13 +88,13 @@ class BtSearchOptionsArea : public QWidget {
* Reads the settings for the searchdialog from disk.
*/
void saveSettings();
- bool eventFilter(QObject* obj, QEvent* event);
+ bool eventFilter(QObject* obj, QEvent* event) override;
public slots:
/**
Sets the modules used by the search.
*/
- void setModules(const QList<const CSwordModuleInfo*> &modules);
+ void setModules(const BtConstModuleList &modules);
/** Sets the modules when user selects them from the combobox.*/
void moduleListTextSelected(int index);
@@ -128,7 +123,7 @@ class BtSearchOptionsArea : public QWidget {
void sigStartSearch();
private:
- QList<const CSwordModuleInfo*> m_modules;
+ BtConstModuleList m_modules;
QHBoxLayout *hboxLayout;
QGroupBox *searchGroupBox;
@@ -151,8 +146,5 @@ class BtSearchOptionsArea : public QWidget {
}
-QDataStream &operator<<(QDataStream &out, const Search::BtSearchOptionsArea::SearchType &searchType);
-QDataStream &operator>>(QDataStream &in, Search::BtSearchOptionsArea::SearchType &searchType);
-Q_DECLARE_METATYPE(Search::BtSearchOptionsArea::SearchType)
#endif
diff --git a/src/frontend/searchdialog/btsearchresultarea.cpp b/src/frontend/searchdialog/btsearchresultarea.cpp
index 6a82a4f..18b8c2f 100644
--- a/src/frontend/searchdialog/btsearchresultarea.cpp
+++ b/src/frontend/searchdialog/btsearchresultarea.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -26,6 +26,8 @@
#include "frontend/searchdialog/cmoduleresultview.h"
#include "frontend/searchdialog/csearchdialog.h"
#include "frontend/searchdialog/csearchresultview.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/tool.h"
@@ -81,17 +83,17 @@ void BtSearchResultArea::initView() {
QVBoxLayout* frameLayout = new QVBoxLayout(m_displayFrame);
frameLayout->setContentsMargins(0, 0, 0, 0);
- m_previewDisplay = new BtHtmlReadDisplay(0, m_displayFrame);
+ m_previewDisplay = new BtHtmlReadDisplay(nullptr, m_displayFrame);
m_previewDisplay->view()->setToolTip(tr("Text of the selected search result item"));
frameLayout->addWidget(m_previewDisplay->view());
QAction* selectAllAction = new QAction(QIcon(), tr("Select all"), this);
selectAllAction->setShortcut(QKeySequence::SelectAll);
- QObject::connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()) );
+ BT_CONNECT(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));
QAction* copyAction = new QAction(tr("Copy"), this);
copyAction->setShortcut( QKeySequence(Qt::CTRL + Qt::Key_C) );
- QObject::connect(copyAction, SIGNAL(triggered()), this, SLOT(copySelection()) );
+ BT_CONNECT(copyAction, SIGNAL(triggered()), this, SLOT(copySelection()));
QMenu* menu = new QMenu();
menu->addAction(selectAllAction);
@@ -115,7 +117,7 @@ void BtSearchResultArea::setSearchResult(
// Pre-select the first module in the list:
m_moduleListBox->setCurrentItem(m_moduleListBox->topLevelItem(0), 0);
- Q_ASSERT(qobject_cast<CSearchDialog*>(parent()) != 0);
+ BT_ASSERT(qobject_cast<CSearchDialog *>(parent()));
static_cast<CSearchDialog*>(parent())->m_analyseButton->setEnabled(true);
}
@@ -140,7 +142,7 @@ void BtSearchResultArea::updatePreview(const QString& key) {
QString text;
CDisplayRendering render;
- QList<const CSwordModuleInfo*> modules;
+ BtConstModuleList modules;
modules.append(module);
CTextRendering::KeyTreeItem::Settings settings;
@@ -151,7 +153,9 @@ void BtSearchResultArea::updatePreview(const QString& key) {
vk.setIntros(true);
vk.setKey(key);
- ((sword::VerseKey*)(module->module()->getKey()))->setIntros(true); //HACK: enable headings for VerseKeys
+ // HACK: enable headings for VerseKeys:
+ static_cast<sword::VerseKey *>(module->module().getKey())
+ ->setIntros(true);
//first go back and then go forward the keys to be in context
vk.previous(CSwordVerseKey::UseVerse);
@@ -182,7 +186,9 @@ void BtSearchResultArea::updatePreview(const QString& key) {
vk.setIntros(true);
vk.setKey(key);
- ((sword::VerseKey*)(module->module()->getKey()))->setIntros(true); //HACK: enable headings for VerseKeys
+ // HACK: enable headings for VerseKeys:
+ static_cast<sword::VerseKey *>(module->module().getKey())
+ ->setIntros(true);
//include Headings in display, they are indexed and searched too
if (vk.getVerse() == 1) {
@@ -210,17 +216,23 @@ void BtSearchResultArea::updatePreview(const QString& key) {
/** Initializes the signal slot conections of the child widgets, */
void BtSearchResultArea::initConnections() {
- connect(m_resultListBox, SIGNAL(keySelected(const QString&)), this, SLOT(updatePreview(const QString&)));
- connect(m_resultListBox, SIGNAL(keyDeselected()), this, SLOT(clearPreview()));
- connect(m_moduleListBox,
- SIGNAL(moduleSelected(const CSwordModuleInfo*, const sword::ListKey&)),
- m_resultListBox,
- SLOT(setupTree(const CSwordModuleInfo*, const sword::ListKey&)));
- connect(m_moduleListBox, SIGNAL(moduleChanged()), m_previewDisplay->connectionsProxy(), SLOT(clear()));
+ BT_CONNECT(m_resultListBox, SIGNAL(keySelected(QString const &)),
+ this, SLOT(updatePreview(QString const &)));
+ BT_CONNECT(m_resultListBox, SIGNAL(keyDeselected()), this, SLOT(clearPreview()));
+ BT_CONNECT(m_moduleListBox,
+ SIGNAL(moduleSelected(CSwordModuleInfo const *,
+ sword::ListKey const &)),
+ m_resultListBox,
+ SLOT(setupTree(CSwordModuleInfo const *,
+ sword::ListKey const &)));
+ BT_CONNECT(m_moduleListBox, SIGNAL(moduleChanged()),
+ m_previewDisplay->connectionsProxy(), SLOT(clear()));
// connect the strongs list
- connect(m_moduleListBox, SIGNAL(strongsSelected(CSwordModuleInfo*, const QStringList&)),
- m_resultListBox, SLOT(setupStrongsTree(CSwordModuleInfo*, const QStringList&)));
+ BT_CONNECT(m_moduleListBox,
+ SIGNAL(strongsSelected(CSwordModuleInfo *, QStringList const &)),
+ m_resultListBox,
+ SLOT(setupStrongsTree(CSwordModuleInfo *, QStringList const &)));
}
/**
@@ -266,14 +278,14 @@ StrongsResultList::StrongsResultList(const CSwordModuleInfo *module,
return;
CTextRendering::KeyTreeItem::Settings settings;
- QList<const CSwordModuleInfo*> modules;
+ BtConstModuleList modules;
modules.append(module);
clear();
// for whatever reason the text "Parsing...translations." does not appear.
// this is not critical but the text is necessary to get the dialog box
// to be wide enough.
- QProgressDialog progress(QObject::tr("Parsing Strong's Numbers"), 0, 0, count);
+ QProgressDialog progress(QObject::tr("Parsing Strong's Numbers"), nullptr, 0, count);
//0, "progressDialog", tr("Parsing Strong's Numbers"), tr("Parsing Strong's numbers for translations."), true);
//progress->setAllowCancel(false);
//progress->setMinimumDuration(0);
diff --git a/src/frontend/searchdialog/btsearchresultarea.h b/src/frontend/searchdialog/btsearchresultarea.h
index e7a167d..4c0284d 100644
--- a/src/frontend/searchdialog/btsearchresultarea.h
+++ b/src/frontend/searchdialog/btsearchresultarea.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -95,7 +95,7 @@ class StrongsResultList: public QList<StrongsResult> {
class BtSearchResultArea : public QWidget {
Q_OBJECT
public: /* Methods: */
- BtSearchResultArea(QWidget *parent = 0);
+ BtSearchResultArea(QWidget *parent = nullptr);
inline ~BtSearchResultArea() { saveDialogSettings(); }
/**
@@ -104,17 +104,11 @@ class BtSearchResultArea : public QWidget {
void setSearchResult(
const CSwordModuleSearch::Results &results);
- /**
- Reimplemented from QWidget::sizeHint().
- */
- virtual QSize sizeHint() const {
+ QSize sizeHint() const override {
return baseSize();
}
- /**
- Reimplemented from QWidget::minimumSizeHint().
- */
- virtual QSize minimumSizeHint() const {
+ QSize minimumSizeHint() const override {
return minimumSize();
}
diff --git a/src/frontend/searchdialog/btsearchsyntaxhelpdialog.cpp b/src/frontend/searchdialog/btsearchsyntaxhelpdialog.cpp
index f1acddc..27a1fa3 100644
--- a/src/frontend/searchdialog/btsearchsyntaxhelpdialog.cpp
+++ b/src/frontend/searchdialog/btsearchsyntaxhelpdialog.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,9 +12,9 @@
#include <QDesktopServices>
#include <QDialogButtonBox>
#include <QVBoxLayout>
-#include <QWebView>
+#include <frontend/btwebengineview.h>
#include "frontend/messagedialog.h"
-#include "util/directory.h"
+#include "util/btconnect.h"
namespace Search {
@@ -26,14 +26,13 @@ BtSearchSyntaxHelpDialog::BtSearchSyntaxHelpDialog(QWidget *parent, Qt::WindowFl
QVBoxLayout *l = new QVBoxLayout;
- m_webView = new QWebView(this);
- m_webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
- connect(m_webView, SIGNAL(linkClicked(QUrl)),
- this, SLOT(linkClicked(QUrl)));
+ m_webView = new BtWebEngineView(this);
+ BT_CONNECT(m_webView->btPage(), SIGNAL(linkClicked(QUrl)),
+ this, SLOT(linkClicked(QUrl)));
l->addWidget(m_webView);
m_buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this);
- connect(m_buttons, SIGNAL(rejected()), this, SLOT(reject()));
+ BT_CONNECT(m_buttons, SIGNAL(rejected()), this, SLOT(reject()));
l->addWidget(m_buttons);
setLayout(l);
@@ -42,8 +41,6 @@ BtSearchSyntaxHelpDialog::BtSearchSyntaxHelpDialog(QWidget *parent, Qt::WindowFl
}
void BtSearchSyntaxHelpDialog::retranslateUi() {
- namespace DU = util::directory;
-
QString theTitle(tr("Search Syntax Help"));
setWindowTitle(theTitle);
@@ -212,7 +209,7 @@ void BtSearchSyntaxHelpDialog::retranslateUi() {
.arg("http://lucene.apache.org/java/1_4_3/queryparsersyntax.html");
html += "</p></body></html>";
- m_webView->setHtml(html, QUrl::fromLocalFile(DU::getIconDir().path()));
+ m_webView->setHtml(html);
message::prepareDialogBox(m_buttons);
}
diff --git a/src/frontend/searchdialog/btsearchsyntaxhelpdialog.h b/src/frontend/searchdialog/btsearchsyntaxhelpdialog.h
index 74b74b5..f7aab44 100644
--- a/src/frontend/searchdialog/btsearchsyntaxhelpdialog.h
+++ b/src/frontend/searchdialog/btsearchsyntaxhelpdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -16,14 +16,14 @@
class QDialogButtonBox;
class QUrl;
-class QWebView;
+class BtWebEngineView;
namespace Search {
class BtSearchSyntaxHelpDialog: public QDialog {
Q_OBJECT
public:
- BtSearchSyntaxHelpDialog(QWidget *parent = 0, Qt::WindowFlags wflags = Qt::Dialog);
+ BtSearchSyntaxHelpDialog(QWidget *parent = nullptr, Qt::WindowFlags wflags = Qt::Dialog);
protected:
void retranslateUi();
@@ -32,7 +32,7 @@ class BtSearchSyntaxHelpDialog: public QDialog {
void linkClicked(const QUrl &url);
private:
- QWebView *m_webView;
+ BtWebEngineView *m_webView;
QDialogButtonBox *m_buttons;
};
diff --git a/src/frontend/searchdialog/chistorycombobox.cpp b/src/frontend/searchdialog/chistorycombobox.cpp
index 231bd65..403e743 100644
--- a/src/frontend/searchdialog/chistorycombobox.cpp
+++ b/src/frontend/searchdialog/chistorycombobox.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
diff --git a/src/frontend/searchdialog/chistorycombobox.h b/src/frontend/searchdialog/chistorycombobox.h
index 922b042..136f9ac 100644
--- a/src/frontend/searchdialog/chistorycombobox.h
+++ b/src/frontend/searchdialog/chistorycombobox.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -20,7 +20,7 @@ namespace Search {
class CHistoryComboBox : public QComboBox {
Q_OBJECT
public:
- CHistoryComboBox(QWidget* parent = 0);
+ CHistoryComboBox(QWidget* parent = nullptr);
~CHistoryComboBox();
void addToHistory(const QString& item);
QStringList historyItems() const;
diff --git a/src/frontend/searchdialog/cmoduleresultview.cpp b/src/frontend/searchdialog/cmoduleresultview.cpp
index 5bbc32f..4924949 100644
--- a/src/frontend/searchdialog/cmoduleresultview.cpp
+++ b/src/frontend/searchdialog/cmoduleresultview.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -16,14 +16,14 @@
#include <QStringList>
#include <QTreeWidget>
#include <QtAlgorithms>
-
+#include "backend/config/btconfig.h"
#include "backend/drivers/cswordmoduleinfo.h"
#include "bibletimeapp.h"
#include "frontend/cexportmanager.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
#include "util/tool.h"
-#include "backend/config/btconfig.h"
namespace Search {
@@ -62,29 +62,34 @@ void CModuleResultView::initView() {
m_popup = new QMenu(this);
m_actions.copyMenu = new QMenu(tr("Copy..."), m_popup);
- m_actions.copyMenu->setIcon(util::getIcon( CResMgr::searchdialog::result::moduleList::copyMenu::icon) );
+ m_actions.copyMenu->setIcon(CResMgr::searchdialog::result::moduleList::copyMenu::icon());
m_actions.copy.result = new QAction(tr("Reference only"), this);
- QObject::connect(m_actions.copy.result, SIGNAL(triggered()), this, SLOT(copyResult()) );
+ BT_CONNECT(m_actions.copy.result, SIGNAL(triggered()),
+ this, SLOT(copyResult()));
m_actions.copyMenu->addAction(m_actions.copy.result);
m_actions.copy.resultWithText = new QAction(tr("Reference with text"), this);
- QObject::connect(m_actions.copy.resultWithText, SIGNAL(triggered()), this, SLOT(copyResultWithText()) );
+ BT_CONNECT(m_actions.copy.resultWithText, SIGNAL(triggered()),
+ this, SLOT(copyResultWithText()));
m_actions.copyMenu->addAction(m_actions.copy.resultWithText);
m_popup->addMenu(m_actions.copyMenu);
m_actions.saveMenu = new QMenu(tr("Save..."), m_popup);
- m_actions.saveMenu->setIcon(util::getIcon( CResMgr::searchdialog::result::moduleList::saveMenu::icon) );
+ m_actions.saveMenu->setIcon(CResMgr::searchdialog::result::moduleList::saveMenu::icon());
m_actions.save.result = new QAction(tr("Reference only"), this);
- QObject::connect(m_actions.save.result, SIGNAL(triggered()), this, SLOT(saveResult()) );
+ BT_CONNECT(m_actions.save.result, SIGNAL(triggered()),
+ this, SLOT(saveResult()));
m_actions.saveMenu->addAction(m_actions.save.result);
m_actions.save.resultWithText = new QAction(tr("Reference with text"), this);
- QObject::connect(m_actions.save.resultWithText, SIGNAL(triggered()), this, SLOT(saveResultWithText()) );
+ BT_CONNECT(m_actions.save.resultWithText, SIGNAL(triggered()),
+ this, SLOT(saveResultWithText()));
m_actions.saveMenu->addAction(m_actions.save.resultWithText);
m_popup->addMenu(m_actions.saveMenu);
m_actions.printMenu = new QMenu(tr("Print..."), m_popup);
- m_actions.printMenu->setIcon(util::getIcon(CResMgr::searchdialog::result::moduleList::printMenu::icon));
+ m_actions.printMenu->setIcon(CResMgr::searchdialog::result::moduleList::printMenu::icon());
m_actions.print.result = new QAction(tr("Reference with text"), this);
- QObject::connect(m_actions.print.result, SIGNAL(triggered()), this, SLOT(printResult()) );
+ BT_CONNECT(m_actions.print.result, SIGNAL(triggered()),
+ this, SLOT(printResult()));
m_actions.printMenu->addAction(m_actions.print.result);
m_popup->addMenu(m_actions.printMenu);
}
@@ -92,8 +97,10 @@ void CModuleResultView::initView() {
/** Initializes the connections of this widget, */
void CModuleResultView::initConnections() {
/// \todo
- connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
- this, SLOT(executed(QTreeWidgetItem*, QTreeWidgetItem*)));
+ BT_CONNECT(this,
+ SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
+ this,
+ SLOT(executed(QTreeWidgetItem *, QTreeWidgetItem *)));
}
void CModuleResultView::setupTree(const CSwordModuleSearch::Results & results,
@@ -111,11 +118,11 @@ void CModuleResultView::setupTree(const CSwordModuleSearch::Results & results,
bool strongsAvailable = false;
Q_FOREACH(const CSwordModuleInfo * m, results.keys()) {
- /// \todo Remove this constructor hack once sword gets it right:
- const int count = sword::ListKey(results.value(m)).getCount();
- QTreeWidgetItem * item = new QTreeWidgetItem(this,
- QStringList(m->name())
- << QString::number(count));
+ QTreeWidgetItem * const item =
+ new QTreeWidgetItem(this,
+ QStringList(m->name())
+ << QString::number(
+ results.value(m).getCount()));
item->setIcon(0, util::tool::getIconForModule(m));
/*
@@ -198,24 +205,15 @@ void CModuleResultView::executed( QTreeWidgetItem* i, QTreeWidgetItem*) {
/** Returns the currently active module. */
CSwordModuleInfo* CModuleResultView::activeModule() {
- Q_ASSERT(currentItem());
-
- QTreeWidgetItem* item = currentItem();
- if (!item) {
- return 0;
- }
+ QTreeWidgetItem * item = currentItem();
+ BT_ASSERT(item);
// we need to find the parent most node because that is the node
// that is the module name.
- while (item->parent()) {
+ while (item->parent())
item = item->parent();
- }
-
- if (item) {
- return CSwordBackend::instance()->findModuleByName(item->text(0));
- }
- return 0;
+ return CSwordBackend::instance()->findModuleByName(item->text(0));
}
/** Reimplementation from QWidget. */
@@ -227,7 +225,7 @@ void CModuleResultView::contextMenuEvent( QContextMenuEvent * event ) {
/** Copies the whole search result into the clipboard. */
void CModuleResultView::copyResult() {
CSwordModuleInfo *m = activeModule();
- if (m != 0) {
+ if (m != nullptr) {
CExportManager mgr(true, tr("Copying search result"));
mgr.copyKeyList(m_results[m], m, CExportManager::Text, false);
@@ -237,7 +235,7 @@ void CModuleResultView::copyResult() {
/** Copies the whole search result with the text into the clipboard. */
void CModuleResultView::copyResultWithText() {
CSwordModuleInfo *m = activeModule();
- if (m != 0) {
+ if (m != nullptr) {
CExportManager mgr(true, tr("Copying search result"));
mgr.copyKeyList(m_results[m], m, CExportManager::Text, true);
};
@@ -246,7 +244,7 @@ void CModuleResultView::copyResultWithText() {
/** Saves the search result keys. */
void CModuleResultView::saveResult() {
CSwordModuleInfo *m = activeModule();
- if (m != 0) {
+ if (m != nullptr) {
CExportManager mgr(true, tr("Saving search result"));
mgr.saveKeyList(m_results[m], m, CExportManager::Text, false);
};
@@ -255,7 +253,7 @@ void CModuleResultView::saveResult() {
/** Saves the search result with it's text. */
void CModuleResultView::saveResultWithText() {
CSwordModuleInfo *m = activeModule();
- if (m != 0) {
+ if (m != nullptr) {
CExportManager mgr(true, tr("Saving search result"));
mgr.saveKeyList(m_results[m], m, CExportManager::Text, true);
};
@@ -264,7 +262,7 @@ void CModuleResultView::saveResultWithText() {
/** Appends the whole search result to the printer queue. */
void CModuleResultView::printResult() {
CSwordModuleInfo *m = activeModule();
- if (m != 0) {
+ if (m != nullptr) {
CExportManager mgr(true, tr("Printing search result"));
mgr.printKeyList(m_results[m], m, btConfig().getDisplayOptions(),
btConfig().getFilterOptions());
diff --git a/src/frontend/searchdialog/cmoduleresultview.h b/src/frontend/searchdialog/cmoduleresultview.h
index 24571d9..6a69a65 100644
--- a/src/frontend/searchdialog/cmoduleresultview.h
+++ b/src/frontend/searchdialog/cmoduleresultview.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -45,7 +45,7 @@ class CModuleResultView : public QTreeWidget {
*/
CSwordModuleInfo* activeModule();
- virtual QSize sizeHint() const {
+ QSize sizeHint() const override {
return m_size;
}
@@ -81,7 +81,7 @@ class CModuleResultView : public QTreeWidget {
/**
* This event handler (reimplemented from QWidget) opens the popup menu at the given position.
*/
- void contextMenuEvent( QContextMenuEvent * event );
+ void contextMenuEvent( QContextMenuEvent * event ) override;
/**
* Appends the whole search result to the printer queue.
*/
diff --git a/src/frontend/searchdialog/crangechooserdialog.cpp b/src/frontend/searchdialog/crangechooserdialog.cpp
index efece49..99bbe42 100644
--- a/src/frontend/searchdialog/crangechooserdialog.cpp
+++ b/src/frontend/searchdialog/crangechooserdialog.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -21,6 +21,8 @@
#include <QVBoxLayout>
#include "backend/config/btconfig.h"
#include "frontend/messagedialog.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
// Sword includes:
#include "versekey.h"
@@ -107,27 +109,27 @@ void CRangeChooserDialog::initView() {
}
void CRangeChooserDialog::initConnections() {
- connect(m_rangeList, SIGNAL(currentItemChanged(QListWidgetItem*,
- QListWidgetItem*)),
- this, SLOT(selectedRangeChanged(QListWidgetItem*,
- QListWidgetItem*)));
- connect(m_nameEdit, SIGNAL(textEdited(QString)),
- this, SLOT(nameEditTextChanged(QString)));
- connect(m_rangeEdit, SIGNAL(textChanged()),
- this, SLOT(updateResultList()));
+ BT_CONNECT(m_rangeList, SIGNAL(currentItemChanged(QListWidgetItem *,
+ QListWidgetItem *)),
+ this, SLOT(selectedRangeChanged(QListWidgetItem *,
+ QListWidgetItem *)));
+ BT_CONNECT(m_nameEdit, SIGNAL(textEdited(QString)),
+ this, SLOT(nameEditTextChanged(QString)));
+ BT_CONNECT(m_rangeEdit, SIGNAL(textChanged()),
+ this, SLOT(updateResultList()));
// Connect buttons:
- connect(m_buttonBox, SIGNAL(accepted()),
- this, SLOT(accept()));
- connect(m_buttonBox, SIGNAL(rejected()),
- this, SLOT(reject()));
- connect(m_newRangeButton, SIGNAL(clicked()),
- this, SLOT(addNewRange()));
- connect(m_deleteRangeButton, SIGNAL(clicked()),
- this, SLOT(deleteCurrentRange()));
+ BT_CONNECT(m_buttonBox, SIGNAL(accepted()),
+ this, SLOT(accept()));
+ BT_CONNECT(m_buttonBox, SIGNAL(rejected()),
+ this, SLOT(reject()));
+ BT_CONNECT(m_newRangeButton, SIGNAL(clicked()),
+ this, SLOT(addNewRange()));
+ BT_CONNECT(m_deleteRangeButton, SIGNAL(clicked()),
+ this, SLOT(deleteCurrentRange()));
QPushButton * defaultsButton = m_buttonBox->button(QDialogButtonBox::RestoreDefaults);
- connect(defaultsButton, SIGNAL(clicked()),
- this, SLOT(restoreDefaults()));
+ BT_CONNECT(defaultsButton, SIGNAL(clicked()),
+ this, SLOT(restoreDefaults()));
}
void CRangeChooserDialog::retranslateUi() {
@@ -178,7 +180,7 @@ void CRangeChooserDialog::selectedRangeChanged(QListWidgetItem * current,
{
Q_UNUSED(current);
if (previous) {
- Q_ASSERT(dynamic_cast<RangeItem*>(previous) != 0);
+ BT_ASSERT(dynamic_cast<RangeItem *>(previous));
saveCurrentToRange(static_cast<RangeItem*>(previous));
}
@@ -187,30 +189,29 @@ void CRangeChooserDialog::selectedRangeChanged(QListWidgetItem * current,
void CRangeChooserDialog::resetEditControls() {
const QListWidgetItem * const item = m_rangeList->currentItem();
- Q_ASSERT(item == 0 || dynamic_cast<const RangeItem *>(item) != 0);
+ BT_ASSERT(!item || dynamic_cast<RangeItem const *>(item));
const RangeItem * rangeItem = static_cast<const RangeItem *>(item);
- m_nameEdit->setEnabled(item != 0);
- m_rangeEdit->setEnabled(item != 0);
- m_resultList->setEnabled(item != 0);
- m_deleteRangeButton->setEnabled(item != 0);
- m_nameEdit->setText(item != 0 ? rangeItem->caption() : "");
- m_rangeEdit->setText(item != 0 ? rangeItem->range() : "");
+ m_nameEdit->setEnabled(item != nullptr);
+ m_rangeEdit->setEnabled(item != nullptr);
+ m_resultList->setEnabled(item != nullptr);
+ m_deleteRangeButton->setEnabled(item != nullptr);
+ m_nameEdit->setText(item != nullptr ? rangeItem->caption() : "");
+ m_rangeEdit->setText(item != nullptr ? rangeItem->range() : "");
- if (item != 0)
+ if (item != nullptr)
m_nameEdit->setFocus();
- nameEditTextChanged(item != 0 ? rangeItem->caption() : "");
+ nameEditTextChanged(item != nullptr ? rangeItem->caption() : "");
}
void CRangeChooserDialog::updateResultList() {
- typedef sword::VerseKey VK;
+ using VK = sword::VerseKey;
m_resultList->clear();
- /// \todo remove this hack:
- //HACK: repair range to work with Sword 1.5.6
- const QString range = m_rangeEdit->toPlainText().replace(QRegExp("\\s{0,}-\\s{0,}"), "-");
+ QString const range =
+ m_rangeEdit->toPlainText().replace(QRegExp("\\s{0,}-\\s{0,}"), "-");
sword::ListKey verses = VK().parseVerseList(range.toUtf8().constData(),
"Genesis 1:1", true);
@@ -221,7 +222,7 @@ void CRangeChooserDialog::updateResultList() {
}
void CRangeChooserDialog::deleteCurrentRange() {
- Q_ASSERT(dynamic_cast<RangeItem*>(m_rangeList->currentItem()) != 0);
+ BT_ASSERT(dynamic_cast<RangeItem *>(m_rangeList->currentItem()));
QListWidgetItem *i = m_rangeList->currentItem();
m_rangeList->removeItemWidget(i);
delete i;
@@ -232,8 +233,8 @@ void CRangeChooserDialog::deleteCurrentRange() {
void CRangeChooserDialog::accept() {
// Update the active item:
QListWidgetItem *currentItem = m_rangeList->currentItem();
- if (currentItem != 0) {
- Q_ASSERT(dynamic_cast<RangeItem*>(currentItem) != 0);
+ if (currentItem != nullptr) {
+ BT_ASSERT(dynamic_cast<RangeItem *>(currentItem));
saveCurrentToRange(static_cast<RangeItem*>(currentItem));
}
@@ -241,7 +242,7 @@ void CRangeChooserDialog::accept() {
m_rangeList->sortItems();
BtConfig::StringMap map;
for (int i = 0; i < m_rangeList->count(); i++) {
- Q_ASSERT(dynamic_cast<RangeItem*>(m_rangeList->item(i)) != 0);
+ BT_ASSERT(dynamic_cast<RangeItem *>(m_rangeList->item(i)));
const RangeItem * item = static_cast<RangeItem*>(m_rangeList->item(i));
map[item->caption()] = item->range();
}
@@ -251,7 +252,7 @@ void CRangeChooserDialog::accept() {
}
void CRangeChooserDialog::restoreDefaults() {
- typedef BtConfig::StringMap::ConstIterator SMCI;
+ using SMCI = BtConfig::StringMap::ConstIterator;
m_rangeList->clear();
btConfig().deleteSearchScopesWithCurrentLocale();
@@ -259,7 +260,7 @@ void CRangeChooserDialog::restoreDefaults() {
for (SMCI it = map.begin(); it != map.end(); ++it) {
new RangeItem(it.key(), it.value(), m_rangeList);
};
- m_rangeList->setCurrentItem(0);
+ m_rangeList->setCurrentItem(nullptr);
resetEditControls();
}
diff --git a/src/frontend/searchdialog/crangechooserdialog.h b/src/frontend/searchdialog/crangechooserdialog.h
index a9cbaf4..c608c63 100644
--- a/src/frontend/searchdialog/crangechooserdialog.h
+++ b/src/frontend/searchdialog/crangechooserdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -39,7 +39,7 @@ private: /* Types: */
inline RangeItem(const QString &caption,
const QString &range = QString::null,
- QListWidget * parent = 0)
+ QListWidget * parent = nullptr)
: QListWidgetItem(caption, parent)
, m_range(range) {}
@@ -56,9 +56,9 @@ private: /* Types: */
public: /* Methods: */
- CRangeChooserDialog(QWidget *parentDialog = 0);
+ CRangeChooserDialog(QWidget *parentDialog = nullptr);
- virtual void accept();
+ void accept() override;
private: /* Methods: */
diff --git a/src/frontend/searchdialog/csearchdialog.cpp b/src/frontend/searchdialog/csearchdialog.cpp
index 54981e3..ccefe9f 100644
--- a/src/frontend/searchdialog/csearchdialog.cpp
+++ b/src/frontend/searchdialog/csearchdialog.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -19,7 +19,6 @@
#include <QRegExp>
#include <QVBoxLayout>
#include <QWidget>
-
#include "backend/config/btconfig.h"
#include "backend/cswordmodulesearch.h"
#include "backend/keys/cswordkey.h"
@@ -29,8 +28,9 @@
#include "frontend/searchdialog/btsearchoptionsarea.h"
#include "frontend/searchdialog/btsearchresultarea.h"
#include "frontend/messagedialog.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
namespace {
@@ -39,9 +39,9 @@ const QString GeometryKey = "GUI/SearchDialog/geometry";
namespace Search {
-static CSearchDialog* m_staticDialog = 0;
+static CSearchDialog* m_staticDialog = nullptr;
-void CSearchDialog::openDialog(const QList<const CSwordModuleInfo*> modules,
+void CSearchDialog::openDialog(const BtConstModuleList modules,
const QString &searchText, QWidget *parentDialog)
{
if (!m_staticDialog) {
@@ -71,19 +71,19 @@ void CSearchDialog::openDialog(const QList<const CSwordModuleInfo*> modules,
}
void CSearchDialog::closeDialog() {
- if (m_staticDialog != 0)
+ if (m_staticDialog != nullptr)
m_staticDialog->closeButtonClicked();
}
CSearchDialog* CSearchDialog::getSearchDialog() {
- Q_ASSERT(m_staticDialog);
+ BT_ASSERT(m_staticDialog);
return m_staticDialog;
}
CSearchDialog::CSearchDialog(QWidget *parent)
- : QDialog(parent), /*m_searchButton(0),*/ m_closeButton(0),
- m_searchResultArea(0), m_searchOptionsArea(0) {
- setWindowIcon(util::getIcon(CResMgr::searchdialog::icon));
+ : QDialog(parent), /*m_searchButton(0),*/ m_closeButton(nullptr),
+ m_searchResultArea(nullptr), m_searchOptionsArea(nullptr) {
+ setWindowIcon(CResMgr::searchdialog::icon());
setWindowTitle(tr("Search"));
setAttribute(Qt::WA_DeleteOnClose);
@@ -93,11 +93,10 @@ CSearchDialog::CSearchDialog(QWidget *parent)
CSearchDialog::~CSearchDialog() {
saveDialogSettings();
- m_staticDialog = 0;
+ m_staticDialog = nullptr;
}
void CSearchDialog::startSearch() {
- typedef QList<const CSwordModuleInfo*> ML;
QString originalSearchText(m_searchOptionsArea->searchText());
// first check the search string for errors
@@ -108,13 +107,19 @@ void CSearchDialog::startSearch() {
return;
}
}
- QString searchText = prepareSearchText(originalSearchText);
+ QString searchText = CSwordModuleSearch::prepareSearchText(originalSearchText, m_searchOptionsArea->searchType());
// Insert search text into history list of combobox
m_searchOptionsArea->addToHistory(originalSearchText);
// Check that we have the indices we need for searching
- ML unindexedModules = CSwordModuleSearch::unindexedModules(modules());
+ /// \warning indexing is some kind of internal optimization, so we leave
+ /// modules const, but unconst them here only
+ QList<CSwordModuleInfo*> unindexedModules;
+ Q_FOREACH(const CSwordModuleInfo * const m,
+ CSwordModuleSearch::unindexedModules(modules()))
+ unindexedModules.append(const_cast<CSwordModuleInfo*>(m));
+
if (unindexedModules.size() > 0) {
// Build the list of module names:
QStringList moduleNameList;
@@ -160,10 +165,21 @@ void CSearchDialog::startSearch() {
setCursor(Qt::WaitCursor);
// Execute search:
- m_searcher.startSearch();
+ try {
+ m_searcher.startSearch();
+ } catch (...) {
+ message::showWarning(this,
+ tr("Search aborted"),
+ tr("An internal error occurred while executing "
+ "your search."));
+ // Re-enable the dialog:
+ setEnabled(true);
+ setCursor(Qt::ArrowCursor);
+ return;
+ }
// Display the search results:
- if (m_searcher.foundItems() > 0) {
+ if (m_searcher.foundItems() > 0u) {
m_searchResultArea->setSearchResult(m_searcher.results());
} else {
m_searchResultArea->reset();
@@ -176,35 +192,7 @@ void CSearchDialog::startSearch() {
setCursor(Qt::ArrowCursor);
}
-QString CSearchDialog::prepareSearchText(const QString& orig) {
- qDebug() << "Original search text:" << orig;
- static const QRegExp syntaxCharacters("[+\\-()!\"~]");
- static const QRegExp andWords("\\band\\b", Qt::CaseInsensitive);
- static const QRegExp orWords("\\bor\\b", Qt::CaseInsensitive);
- QString text("");
- if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::AndType) {
- text = orig.simplified();
- text.remove(syntaxCharacters);
- qDebug() << "After syntax characters removed:" << text;
- text.replace(andWords, "\"and\"");
- text.replace(orWords, "\"or\"");
- qDebug() << "After \"and\" and \"or\" replaced:" << text;
- text.replace(" ", " AND ");
- }
- if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::OrType) {
- text = orig.simplified();
- text.remove(syntaxCharacters);
- text.replace(andWords, "\"and\"");
- text.replace(orWords, "\"or\"");
- }
- if (m_searchOptionsArea->searchType() == BtSearchOptionsArea::FullType) {
- text = orig;
- }
- qDebug() << "The final search string:" << text;
- return text;
-}
-
-void CSearchDialog::startSearch(const QList<const CSwordModuleInfo*> modules,
+void CSearchDialog::startSearch(const BtConstModuleList modules,
const QString &searchText)
{
m_searchResultArea->reset();
@@ -238,7 +226,7 @@ void CSearchDialog::initView() {
QHBoxLayout* horizontalLayout = new QHBoxLayout();
- m_analyseButton = new QPushButton(tr("&Analyze results..."), 0);
+ m_analyseButton = new QPushButton(tr("&Analyze results..."), nullptr);
m_analyseButton->setToolTip(tr("Show a graphical analysis of the search result"));
QSpacerItem* spacerItem = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout->addWidget(m_analyseButton);
@@ -246,7 +234,7 @@ void CSearchDialog::initView() {
m_closeButton = new QPushButton(this);
m_closeButton->setText(tr("&Close"));
- m_closeButton->setIcon(util::getIcon(CResMgr::searchdialog::close_icon));
+ m_closeButton->setIcon(CResMgr::searchdialog::icon_close());
horizontalLayout->addWidget(m_closeButton);
verticalLayout->addLayout(horizontalLayout);
@@ -261,15 +249,16 @@ void CSearchDialog::showModulesSelector() {
/** Initializes the signal slot connections */
void CSearchDialog::initConnections() {
// Search button is clicked
- bool ok = connect(m_searchOptionsArea->searchButton(), SIGNAL(clicked()), this, SLOT(startSearch()));
- Q_ASSERT(ok);
+ BT_CONNECT(m_searchOptionsArea->searchButton(), SIGNAL(clicked()),
+ this, SLOT(startSearch()));
// Return/Enter is pressed in the search text field
- ok = connect(m_searchOptionsArea, SIGNAL(sigStartSearch()), this, SLOT(startSearch()) );
- Q_ASSERT(ok);
- ok = connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
- Q_ASSERT(ok);
+ BT_CONNECT(m_searchOptionsArea, SIGNAL(sigStartSearch()),
+ this, SLOT(startSearch()) );
+ BT_CONNECT(m_closeButton, SIGNAL(clicked()),
+ this, SLOT(closeButtonClicked()));
- connect(m_analyseButton, SIGNAL(clicked()), m_searchResultArea, SLOT(showAnalysis()));
+ BT_CONNECT(m_analyseButton, SIGNAL(clicked()),
+ m_searchResultArea, SLOT(showAnalysis()));
}
diff --git a/src/frontend/searchdialog/csearchdialog.h b/src/frontend/searchdialog/csearchdialog.h
index dde8537..c0153fa 100644
--- a/src/frontend/searchdialog/csearchdialog.h
+++ b/src/frontend/searchdialog/csearchdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -33,9 +33,9 @@ namespace Search {
class CSearchDialog : public QDialog {
Q_OBJECT
public:
- static void openDialog(const QList<const CSwordModuleInfo*> modules,
+ static void openDialog(const BtConstModuleList modules,
const QString &searchText = QString::null,
- QWidget *parentDialog = 0);
+ QWidget *parentDialog = nullptr);
static void closeDialog();
@@ -60,23 +60,20 @@ class CSearchDialog : public QDialog {
/**
Starts the search with the given module list and given search text.
*/
- void startSearch(const QList<const CSwordModuleInfo*> modules,
+ void startSearch(const BtConstModuleList modules,
const QString &searchText);
- /**Prepares the search string given by user for a specific search type */
- QString prepareSearchText(const QString& orig);
-
/**
Sets the list of modules for the search.
*/
- void setModules(const QList<const CSwordModuleInfo*> modules) {
+ void setModules(const BtConstModuleList modules) {
m_searchOptionsArea->setModules(modules);
}
/**
Returns the list of used modules.
*/
- inline QList<const CSwordModuleInfo*> modules() const {
+ inline BtConstModuleList modules() const {
return m_searchOptionsArea->modules();
}
diff --git a/src/frontend/searchdialog/csearchresultview.cpp b/src/frontend/searchdialog/csearchresultview.cpp
index c08e5cc..f5d6ff0 100644
--- a/src/frontend/searchdialog/csearchresultview.cpp
+++ b/src/frontend/searchdialog/csearchresultview.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -15,20 +15,20 @@
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QWidget>
+#include "backend/config/btconfig.h"
#include "backend/keys/cswordversekey.h"
#include "bibletimeapp.h"
#include "frontend/cdragdrop.h"
#include "frontend/cexportmanager.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
-#include "backend/config/btconfig.h"
namespace Search {
CSearchResultView::CSearchResultView(QWidget* parent)
: QTreeWidget(parent),
- m_module(0) {
+ m_module(nullptr) {
initView();
initConnections();
}
@@ -45,48 +45,53 @@ void CSearchResultView::initView() {
m_popup = new QMenu(this);
m_actions.copyMenu = new QMenu(tr("Copy..."), m_popup);
- m_actions.copyMenu->setIcon(util::getIcon(CResMgr::searchdialog::result::foundItems::copyMenu::icon));
+ m_actions.copyMenu->setIcon(CResMgr::searchdialog::result::foundItems::copyMenu::icon());
m_actions.copy.result = new QAction(tr("Reference only"), this);
- QObject::connect(m_actions.copy.result, SIGNAL(triggered()), this, SLOT(copyItems()) );
+ BT_CONNECT(m_actions.copy.result, SIGNAL(triggered()),
+ this, SLOT(copyItems()));
m_actions.copyMenu->addAction(m_actions.copy.result);
m_actions.copy.resultWithText = new QAction(tr("Reference with text"), this);
- QObject::connect(m_actions.copy.resultWithText, SIGNAL(triggered()),
- this, SLOT(copyItemsWithText()));
+ BT_CONNECT(m_actions.copy.resultWithText, SIGNAL(triggered()),
+ this, SLOT(copyItemsWithText()));
m_actions.copyMenu->addAction(m_actions.copy.resultWithText);
m_popup->addMenu(m_actions.copyMenu);
m_actions.saveMenu = new QMenu(tr("Save..."), m_popup);
- m_actions.saveMenu->setIcon(util::getIcon(CResMgr::searchdialog::result::foundItems::saveMenu::icon));
+ m_actions.saveMenu->setIcon(CResMgr::searchdialog::result::foundItems::saveMenu::icon());
m_actions.save.result = new QAction(tr("Reference only"), this);
- QObject::connect(m_actions.save.result, SIGNAL(triggered()), this, SLOT(saveItems()) );
+ BT_CONNECT(m_actions.save.result, SIGNAL(triggered()),
+ this, SLOT(saveItems()) );
m_actions.saveMenu->addAction(m_actions.save.result);
m_actions.save.resultWithText = new QAction(tr("Reference with text"), this);
m_actions.saveMenu->addAction(m_actions.save.resultWithText);
- QObject::connect(m_actions.save.resultWithText, SIGNAL(triggered()), this, SLOT(saveItemsWithText()));
+ BT_CONNECT(m_actions.save.resultWithText, SIGNAL(triggered()),
+ this, SLOT(saveItemsWithText()));
m_popup->addMenu(m_actions.saveMenu);
m_actions.printMenu = new QMenu(tr("Print..."), m_popup);
- m_actions.printMenu->setIcon(util::getIcon(CResMgr::searchdialog::result::foundItems::printMenu::icon));
+ m_actions.printMenu->setIcon(CResMgr::searchdialog::result::foundItems::printMenu::icon());
m_actions.print.result = new QAction(tr("Reference with text"), this);
- QObject::connect(m_actions.print.result, SIGNAL(triggered()), this, SLOT(printItems()) );
+ BT_CONNECT(m_actions.print.result, SIGNAL(triggered()),
+ this, SLOT(printItems()));
m_actions.printMenu->addAction(m_actions.print.result);
m_popup->addMenu(m_actions.printMenu);
}
/** No descriptions */
void CSearchResultView::initConnections() {
- // connect(this, SIGNAL(executed(QListViewItem*)),
- // this, SLOT(executed(QListViewItem*)));
+ // BT_CONNECT(this, SIGNAL(executed(QListViewItem *)),
+ // this, SLOT(executed(QListViewItem *)));
/// \todo are these right after porting?
//items: current, previous
- connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
- this, SLOT(executed(QTreeWidgetItem*, QTreeWidgetItem*)));
+ BT_CONNECT(this,
+ SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
+ this, SLOT(executed(QTreeWidgetItem *, QTreeWidgetItem *)));
}
/** Setups the list with the given module. */
@@ -103,8 +108,8 @@ void CSearchResultView::setupTree(const CSwordModuleInfo *m,
setUpdatesEnabled(false);
- QTreeWidgetItem* oldItem = 0;
- QTreeWidgetItem* item = 0;
+ QTreeWidgetItem* oldItem = nullptr;
+ QTreeWidgetItem* item = nullptr;
for (int index = 0; index < count; index++) {
item = new QTreeWidgetItem(this, oldItem);
item->setText(0, QString::fromUtf8(result.getElement(index)->getText()));
@@ -126,10 +131,10 @@ void CSearchResultView::setupStrongsTree(CSwordModuleInfo* m, const QStringList
setUpdatesEnabled(false);
- QTreeWidgetItem* oldItem = 0;
- QTreeWidgetItem* item = 0;
+ QTreeWidgetItem* oldItem = nullptr;
+ QTreeWidgetItem* item = nullptr;
- foreach (QString s, vList) {
+ Q_FOREACH(QString const & s, vList) {
item = new QTreeWidgetItem(this, oldItem);
item->setText(0, (s));
oldItem = item;
@@ -164,9 +169,8 @@ void CSearchResultView::printItems() {
CExportManager mgr(true, tr("Printing search result"));
QStringList list;
- foreach (QTreeWidgetItem* k, items) {
+ Q_FOREACH(QTreeWidgetItem const * const k, items)
list.append( k->text(0) );
- }
mgr.printKeyList( list, module(), btConfig().getDisplayOptions(), btConfig().getFilterOptions() );
}
@@ -174,10 +178,10 @@ void CSearchResultView::saveItems() {
CExportManager mgr(true, tr("Saving search result"));
const CSwordModuleInfo *m = module();
- CSwordKey* k = 0;
+ CSwordKey* k = nullptr;
QList<QTreeWidgetItem*> items = selectedItems();
QList<CSwordKey*> keys;
- foreach (QTreeWidgetItem* i, items) {
+ Q_FOREACH(QTreeWidgetItem const * const i, items) {
k = CSwordKey::createInstance( m );
k->setKey(i->text(0));
keys.append( k );
@@ -192,10 +196,10 @@ void CSearchResultView::saveItemsWithText() {
CExportManager mgr(true, tr("Saving search result"));
const CSwordModuleInfo *m = module();
- CSwordKey* k = 0;
+ CSwordKey* k = nullptr;
QList<QTreeWidgetItem*> items = selectedItems();
QList<CSwordKey*> keys;
- foreach (QTreeWidgetItem* i, items) {
+ Q_FOREACH(QTreeWidgetItem const * const i, items) {
k = CSwordKey::createInstance( m );
k->setKey(i->text(0));
keys.append( k );
@@ -210,10 +214,10 @@ void CSearchResultView::copyItems() {
CExportManager mgr(true, tr("Copying search result"));
const CSwordModuleInfo *m = module();
- CSwordKey* k = 0;
+ CSwordKey* k = nullptr;
QList<QTreeWidgetItem*> items = selectedItems();
QList<CSwordKey*> keys;
- foreach (QTreeWidgetItem* i, items) {
+ Q_FOREACH(QTreeWidgetItem const * const i, items) {
k = CSwordKey::createInstance( m );
k->setKey(i->text(0));
keys.append( k );
@@ -228,10 +232,10 @@ void CSearchResultView::copyItemsWithText() {
CExportManager mgr(true, tr("Copying search result"));
const CSwordModuleInfo *m = module();
- CSwordKey* k = 0;
+ CSwordKey* k = nullptr;
QList<QTreeWidgetItem*> items = selectedItems();
QList<CSwordKey*> keys;
- foreach (QTreeWidgetItem* i, items) {
+ Q_FOREACH(QTreeWidgetItem const * const i, items) {
k = CSwordKey::createInstance( m );
k->setKey(i->text(0));
keys.append( k );
@@ -262,9 +266,8 @@ void CSearchResultView::copyItemsWithText() {
QMimeData * CSearchResultView::mimeData ( const QList<QTreeWidgetItem *> items ) const {
BTMimeData* mdata = new BTMimeData(m_module->name(), items.first()->text(0), QString::null);
- foreach (QTreeWidgetItem* i, items) {
+ Q_FOREACH(QTreeWidgetItem const * const i, items)
mdata->appendBookmark(m_module->name(), i->text(0), QString::null);
- }
return mdata;
}
diff --git a/src/frontend/searchdialog/csearchresultview.h b/src/frontend/searchdialog/csearchresultview.h
index 76b6d38..33e095b 100644
--- a/src/frontend/searchdialog/csearchresultview.h
+++ b/src/frontend/searchdialog/csearchresultview.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -45,8 +45,8 @@ class CSearchResultView : public QTreeWidget {
void initConnections();
//from QTreeWidget
- virtual QMimeData * mimeData ( const QList<QTreeWidgetItem *> items ) const;
- virtual QStringList mimeTypes () const;
+ QMimeData * mimeData ( const QList<QTreeWidgetItem *> items ) const override;
+ QStringList mimeTypes () const override;
public slots: // Public slots
void saveItems();
@@ -60,10 +60,8 @@ class CSearchResultView : public QTreeWidget {
void copyItemsWithText();
void copyItems();
void saveItemsWithText();
- /**
- * Reimplementation to show the popup menu.
- */
- virtual void contextMenuEvent(QContextMenuEvent* event);
+
+ void contextMenuEvent(QContextMenuEvent* event) override;
protected slots: // Protected slots
void printItems();
diff --git a/src/frontend/settingsdialogs/btconfigdialog.cpp b/src/frontend/settingsdialogs/btconfigdialog.cpp
new file mode 100644
index 0000000..7e971e9
--- /dev/null
+++ b/src/frontend/settingsdialogs/btconfigdialog.cpp
@@ -0,0 +1,87 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btconfigdialog.h"
+
+#include <QDialogButtonBox>
+#include <QFrame>
+#include <QHBoxLayout>
+#include <QListWidget>
+#include <QStackedWidget>
+#include <QVBoxLayout>
+#include "util/btassert.h"
+#include "util/btconnect.h"
+
+
+BtConfigDialog::BtConfigDialog(QWidget * const parent,
+ Qt::WindowFlags const flags)
+ : QDialog(parent, flags)
+ , m_contentsList(new QListWidget(this))
+ , m_pageWidget(new QStackedWidget(this))
+{
+ QHBoxLayout * const mainLayout = new QHBoxLayout(this);
+
+ m_contentsList->setViewMode(QListView::IconMode);
+ m_contentsList->setMovement(QListView::Static);
+ BT_CONNECT(m_contentsList, &QListWidget::currentRowChanged,
+ m_pageWidget, &QStackedWidget::setCurrentIndex);
+ mainLayout->addWidget(m_contentsList);
+
+ m_pageLayout = new QVBoxLayout;
+ mainLayout->addLayout(m_pageLayout);
+
+ m_pageWidget->setSizePolicy(QSizePolicy::MinimumExpanding,
+ QSizePolicy::MinimumExpanding);
+ m_pageLayout->addWidget(m_pageWidget);
+}
+
+void BtConfigDialog::addPage(Page * const pageWidget) {
+ m_pageWidget->addWidget(pageWidget);
+
+ QListWidgetItem * const item = new QListWidgetItem(m_contentsList);
+ item->setTextAlignment(Qt::AlignHCenter);
+ item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+ pageWidget->setListWidgetItem(item);
+
+ int const thisItemWidth = m_contentsList->visualItemRect(item).width();
+ if (m_maxItemWidth < thisItemWidth) {
+ // Reset the list width:
+ m_maxItemWidth = thisItemWidth;
+ m_contentsList->setFixedWidth(
+ m_maxItemWidth + (m_contentsList->frameWidth() * 2));
+ }
+
+ // All items should have the same width:
+ for (int i = 0; i < m_contentsList->count(); ++i)
+ m_contentsList->item(i)->setSizeHint(
+ QSize(m_maxItemWidth,
+ m_contentsList->visualItemRect(
+ m_contentsList->item(i)).height()));
+
+ setCurrentPage(m_contentsList->row(item));
+}
+
+void BtConfigDialog::setButtonBox(QDialogButtonBox * const box) {
+ BT_ASSERT(box);
+ BT_ASSERT(m_pageLayout->count() == 1); // Only m_pageWidget in layout
+
+ // First add a horizontal ruler:
+ QFrame * const buttonBoxRuler = new QFrame(this);
+ buttonBoxRuler->setGeometry(QRect(1, 1, 1, 3));
+ buttonBoxRuler->setFrameShape(QFrame::HLine);
+ buttonBoxRuler->setFrameShadow(QFrame::Sunken);
+ buttonBoxRuler->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ m_pageLayout->addWidget(buttonBoxRuler);
+
+ // Add button box:
+ m_pageLayout->addWidget(box);
+}
+
+void BtConfigDialog::setCurrentPage(int const newIndex)
+{ m_contentsList->setCurrentRow(newIndex); }
diff --git a/src/frontend/settingsdialogs/btconfigdialog.h b/src/frontend/settingsdialogs/btconfigdialog.h
new file mode 100644
index 0000000..ae096f3
--- /dev/null
+++ b/src/frontend/settingsdialogs/btconfigdialog.h
@@ -0,0 +1,94 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTCONFIGDIALOG_H
+#define BTCONFIGDIALOG_H
+
+#include <QDialog>
+
+#include <QIcon>
+#include <QListWidgetItem>
+
+
+class QDialogButtonBox;
+class QStackedWidget;
+class QVBoxLayout;
+
+/**
+* Base class for configuration dialogs. A dialog which has a page chooser (icons
+* + text) at the left, widget pages and a buttonbox.
+*
+* Usage: add BtConfigPage pages with addPage(), add a button box with addButtonBox().
+* Connect the button box signals. Use setAttribute(Qt::WA_DeleteOnClose) if you want
+* an auto-destroying window.
+*/
+class BtConfigDialog : public QDialog {
+
+public: /* Types: */
+
+ /** Base class for configuration dialog pages. */
+ class Page : public QWidget {
+
+ friend class BtConfigDialog;
+
+ public: /* Methods: */
+
+ inline Page(QIcon const & icon, QWidget * const parent)
+ : QWidget(parent)
+ , m_icon(icon)
+ {}
+
+ inline void setHeaderText(QString const & headerText) {
+ m_headerText = headerText;
+ if (m_listWidgetItem)
+ m_listWidgetItem->setText(headerText);
+ }
+
+ private: /* Methods: */
+
+ void setListWidgetItem(QListWidgetItem * const item) noexcept {
+ m_listWidgetItem = item;
+ item->setIcon(m_icon);
+ item->setText(m_headerText);
+ }
+
+ private: /* Fields: */
+
+ QIcon const m_icon;
+ QString m_headerText;
+ QListWidgetItem * m_listWidgetItem = nullptr;
+
+ };
+
+public: /* Methods: */
+
+ BtConfigDialog(QWidget * const parent = nullptr,
+ Qt::WindowFlags const flags = 0);
+
+ /** Adds a BtConfigPage to the paged widget stack. The new page will be the current page.*/
+ void addPage(Page * const pageWidget);
+
+ /** Adds a button box to the lower edge of the dialog. */
+ void setButtonBox(QDialogButtonBox * const buttonBox);
+
+ /** Changes the current page using the given index number. */
+ void setCurrentPage(int const newIndex);
+
+private: /* Fields: */
+
+ QListWidget * const m_contentsList;
+ QStackedWidget * const m_pageWidget;
+ QVBoxLayout * m_pageLayout;
+ int m_maxItemWidth = 0;
+
+};
+
+#endif
diff --git a/src/frontend/settingsdialogs/btfontchooserwidget.cpp b/src/frontend/settingsdialogs/btfontchooserwidget.cpp
index 7fcf6b5..9e3051c 100644
--- a/src/frontend/settingsdialogs/btfontchooserwidget.cpp
+++ b/src/frontend/settingsdialogs/btfontchooserwidget.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -15,24 +15,24 @@
#include <QLabel>
#include <QListWidget>
#include <QListWidgetItem>
-#include <QWebSettings>
-#include <QWebView>
+#include "frontend/btwebengineview.h"
#include "frontend/settingsdialogs/clistwidget.h"
+#include "util/btconnect.h"
namespace {
-class BtFontPreviewWebView: public QWebView {
+class BtFontPreviewWebView: public BtWebEngineView {
public: /* Methods: */
- inline BtFontPreviewWebView(QWidget *parent = 0)
- : QWebView(parent)
+ inline BtFontPreviewWebView(QWidget *parent = nullptr)
+ : BtWebEngineView(parent)
{
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
}
- virtual inline QSize sizeHint() const {
+ inline QSize sizeHint() const override {
return QSize(100, 100);
}
@@ -100,30 +100,24 @@ void BtFontChooserWidget::retranslateUi() {
}
void BtFontChooserWidget::connectListWidgets() {
- bool ok = connect(
- m_fontListWidget,
- SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
- this,
- SLOT(fontChanged(QListWidgetItem *, QListWidgetItem *)));
- Q_ASSERT(ok);
-
- ok = connect(
+ BT_CONNECT(m_fontListWidget,
+ SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
+ this,
+ SLOT(fontChanged(QListWidgetItem *, QListWidgetItem *)));
+ BT_CONNECT(
m_styleListWidget,
SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
this,
SLOT(styleChanged(QListWidgetItem *, QListWidgetItem *)));
- Q_ASSERT(ok);
-
- ok = connect(
+ BT_CONNECT(
m_sizeListWidget,
SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
this,
SLOT(sizeChanged(QListWidgetItem *, QListWidgetItem *)));
- Q_ASSERT(ok);
}
void BtFontChooserWidget::fontChanged(QListWidgetItem* current, QListWidgetItem* /*previous*/) {
- if (current == 0)
+ if (current == nullptr)
return;
const QString fontFamily = current->text();
@@ -136,9 +130,9 @@ void BtFontChooserWidget::fontChanged(QListWidgetItem* current, QListWidgetItem*
void BtFontChooserWidget::loadFonts() {
m_fontListWidget->clear();
QFontDatabase database;
- Q_FOREACH (const QString &font, database.families()) {
+ Q_FOREACH(QString const & font, database.families())
m_fontListWidget->addItem(font);
- }
+
// This triggers loading the styles for the first font
m_fontListWidget->setCurrentRow(0);
}
@@ -159,9 +153,8 @@ void BtFontChooserWidget::loadSizes(const QString& font, const QString& style) {
// Put new values into listWidget
m_sizeListWidget->clear();
QFontDatabase database;
- Q_FOREACH (int size, database.pointSizes(font, style)) {
+ Q_FOREACH(int const size, database.pointSizes(font, style))
m_sizeListWidget->addItem(QString::number(size));
- }
restoreListWidgetValue(m_sizeListWidget, saveText);
}
@@ -220,9 +213,9 @@ QString BtFontChooserWidget::saveListWidgetValue(QListWidget* listWidget) {
}
void BtFontChooserWidget::setFont(const QFont& font) {
- disconnect(m_fontListWidget, 0, 0, 0);
- disconnect(m_styleListWidget, 0, 0, 0);
- disconnect(m_sizeListWidget, 0, 0, 0);
+ disconnect(m_fontListWidget, nullptr, nullptr, nullptr);
+ disconnect(m_styleListWidget, nullptr, nullptr, nullptr);
+ disconnect(m_sizeListWidget, nullptr, nullptr, nullptr);
// set the font
m_font = font;
@@ -256,7 +249,7 @@ void BtFontChooserWidget::setSampleText(const QString& htmlText) {
}
void BtFontChooserWidget::sizeChanged(QListWidgetItem* current, QListWidgetItem* /*previous*/) {
- if (current == 0)
+ if (current == nullptr)
return;
m_font.setPointSize(m_sizeListWidget->currentItem()->text().toInt());
@@ -270,7 +263,7 @@ QSize BtFontChooserWidget::sizeHint() const {
}
void BtFontChooserWidget::styleChanged(QListWidgetItem* current, QListWidgetItem* /*previous*/) {
- if (current == 0)
+ if (current == nullptr)
return;
QString styleString = current->text();
diff --git a/src/frontend/settingsdialogs/btfontchooserwidget.h b/src/frontend/settingsdialogs/btfontchooserwidget.h
index eba5607..078fd89 100644
--- a/src/frontend/settingsdialogs/btfontchooserwidget.h
+++ b/src/frontend/settingsdialogs/btfontchooserwidget.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -22,7 +22,7 @@ class CListWidget;
class QListWidget;
class QListWidgetItem;
class QString;
-class QWebView;
+class BtWebEngineView;
class BtFontChooserWidget : public QFrame {
@@ -30,13 +30,12 @@ class BtFontChooserWidget : public QFrame {
public: /* Methods: */
- BtFontChooserWidget(QWidget *parent = 0);
+ BtFontChooserWidget(QWidget *parent = nullptr);
void setFont(const QFont &font);
void setSampleText(const QString &text);
- // Inherited from QWidget:
- virtual QSize sizeHint() const;
+ QSize sizeHint() const override;
signals:
@@ -72,7 +71,7 @@ class BtFontChooserWidget : public QFrame {
QLabel *m_fontSizeLabel;
CListWidget *m_sizeListWidget;
- QWebView *m_fontPreview;
+ BtWebEngineView *m_fontPreview;
QString m_htmlText;
QFont m_font;
diff --git a/src/frontend/settingsdialogs/btfontsettings.cpp b/src/frontend/settingsdialogs/btfontsettings.cpp
index 57a8aba..77aad3f 100644
--- a/src/frontend/settingsdialogs/btfontsettings.cpp
+++ b/src/frontend/settingsdialogs/btfontsettings.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -20,24 +20,20 @@
#include "bibletimeapp.h"
#include "frontend/settingsdialogs/btfontchooserwidget.h"
#include "frontend/settingsdialogs/cconfigurationdialog.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
#include "util/tool.h"
-// Sword includes:
-#include <localemgr.h>
-#include <swlocale.h>
-
BtFontSettingsPage::BtFontSettingsPage(CConfigurationDialog *parent)
- : BtConfigDialog::Page(util::getIcon(CResMgr::settings::fonts::icon), parent)
+ : BtConfigDialog::Page(CResMgr::settings::fonts::icon(), parent)
{
m_languageLabel = new QLabel(this);
m_languageComboBox = new QComboBox(this);
m_languageLabel->setBuddy(m_languageComboBox);
m_languageCheckBox = new QCheckBox(this);
- connect(m_languageCheckBox, SIGNAL(toggled(bool)),
- this, SLOT(useOwnFontClicked(bool)) );
+ BT_CONNECT(m_languageCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(useOwnFontClicked(bool)) );
QHBoxLayout *hLayout = new QHBoxLayout;
@@ -47,7 +43,7 @@ BtFontSettingsPage::BtFontSettingsPage(CConfigurationDialog *parent)
hLayout->addWidget(m_languageCheckBox);
CLanguageMgr::LangMap langMap = CLanguageMgr::instance()->availableLanguages();
- typedef CLanguageMgr::Language L;
+ using L = CLanguageMgr::Language;
for (CLanguageMgr::LangMapIterator it = langMap.constBegin();
it != langMap.constEnd();
it++)
@@ -64,7 +60,7 @@ BtFontSettingsPage::BtFontSettingsPage(CConfigurationDialog *parent)
for (FontMap::ConstIterator it = m_fontMap.constBegin(); it != m_fontMap.constEnd(); ++it) {
const QString &k = it.key();
if (m_fontMap[k].first) { // show font icon
- m_languageComboBox->addItem(util::getIcon("fonts.svg"), k);
+ m_languageComboBox->addItem(CResMgr::settings::fonts::icon(), k);
} else { // don't show icon for font
m_languageComboBox->addItem(k);
}
@@ -79,10 +75,10 @@ BtFontSettingsPage::BtFontSettingsPage(CConfigurationDialog *parent)
*/
// m_fontChooser->setSampleText("SOMETHING");
- connect(m_fontChooser, SIGNAL(fontSelected(const QFont&)),
- this, SLOT(newDisplayWindowFontSelected(const QFont&)));
- connect(m_languageComboBox, SIGNAL(activated(const QString&)),
- this, SLOT(newDisplayWindowFontAreaSelected(const QString&)));
+ BT_CONNECT(m_fontChooser, SIGNAL(fontSelected(QFont const &)),
+ this, SLOT(newDisplayWindowFontSelected(QFont const &)));
+ BT_CONNECT(m_languageComboBox, SIGNAL(activated(QString const &)),
+ this, SLOT(newDisplayWindowFontAreaSelected(QString const &)));
const BtConfig::FontSettingsPair &v = m_fontMap.value(m_languageComboBox->currentText());
m_fontChooser->setFont(v.second);
@@ -143,7 +139,9 @@ void BtFontSettingsPage::useOwnFontClicked(bool isOn) {
m_fontChooser->setEnabled(isOn);
m_fontMap[m_languageComboBox->currentText()].first = isOn;
m_languageComboBox->setItemIcon(m_languageComboBox->currentIndex(),
- isOn ? util::getIcon("fonts.svg") : QIcon());
+ isOn
+ ? CResMgr::settings::fonts::icon()
+ : QIcon());
}
void BtFontSettingsPage::retranslateUi() {
@@ -151,5 +149,4 @@ void BtFontSettingsPage::retranslateUi() {
m_languageLabel->setText(tr("&Language:"));
m_languageComboBox->setToolTip(tr("The font selection below will apply to all texts in this language"));
m_languageCheckBox->setText(tr("Use custom font"));
- m_fontsGroupBox->setTitle(tr("Optionally specify a custom font for each language:"));
}
diff --git a/src/frontend/settingsdialogs/btfontsettings.h b/src/frontend/settingsdialogs/btfontsettings.h
index 70d0d20..356a9a9 100644
--- a/src/frontend/settingsdialogs/btfontsettings.h
+++ b/src/frontend/settingsdialogs/btfontsettings.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,7 +12,7 @@
#ifndef BTFONTSETTINGS_H
#define BTFONTSETTINGS_H
-#include "frontend/bookshelfmanager/btconfigdialog.h"
+#include "btconfigdialog.h"
#include <QMap>
#include <QWidget>
@@ -32,11 +32,11 @@ class BtFontSettingsPage: public BtConfigDialog::Page {
private: /* Types: */
- typedef QMap<QString, BtConfig::FontSettingsPair> FontMap;
+ using FontMap = QMap<QString, BtConfig::FontSettingsPair>;
public: /* Methods: */
- BtFontSettingsPage(CConfigurationDialog *parent = 0);
+ BtFontSettingsPage(CConfigurationDialog *parent = nullptr);
void save() const;
diff --git a/src/frontend/settingsdialogs/btlanguagesettings.cpp b/src/frontend/settingsdialogs/btlanguagesettings.cpp
deleted file mode 100644
index 37e53c8..0000000
--- a/src/frontend/settingsdialogs/btlanguagesettings.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/*********
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#include "frontend/settingsdialogs/btlanguagesettings.h"
-
-#include <QComboBox>
-#include <QFormLayout>
-#include <QLabel>
-#include <QVBoxLayout>
-#include <QWidget>
-#include "backend/config/btconfig.h"
-#include "bibletimeapp.h"
-#include "frontend/settingsdialogs/cconfigurationdialog.h"
-#include "util/cresmgr.h"
-#include "util/geticon.h"
-#include "util/tool.h"
-
-// Sword includes:
-#include <localemgr.h>
-#include <swlocale.h>
-
-
-typedef std::list<sword::SWBuf>::const_iterator SBLCI;
-
-
-BtLanguageSettingsPage::BtLanguageSettingsPage(CConfigurationDialog *parent)
- : BtConfigDialog::Page(util::getIcon(CResMgr::settings::languages::icon), parent)
-{
- m_swordLocaleCombo = new QComboBox(this);
- m_languageNamesLabel = new QLabel(this);
- m_languageNamesLabel->setBuddy(m_swordLocaleCombo);
-
- QFormLayout * formLayout = new QFormLayout(this);
- formLayout->addRow(m_languageNamesLabel, m_swordLocaleCombo);
-
- retranslateUi();
-
- initSwordLocaleCombo();
-}
-
-void BtLanguageSettingsPage::save() {
- btConfig().setValue("language", m_swordLocaleCombo->itemData(m_swordLocaleCombo->currentIndex()));
-}
-
-void BtLanguageSettingsPage::resetLanguage() {
- QVector<QString> atv = bookNameAbbreviationsTryVector();
-
- QString best = "en_US";
- Q_ASSERT(atv.contains(best));
- int i = atv.indexOf(best);
- if (i > 0) {
- atv.resize(i);
- const std::list<sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
- for (SBLCI it = locales.begin(); it != locales.end(); ++it) {
- const char * abbr = sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getName();
- i = atv.indexOf(abbr);
- if (i >= 0) {
- best = abbr;
- if (i == 0)
- break;
- atv.resize(i);
- }
- }
- }
- btConfig().setValue("language", best);
-}
-
-QVector<QString> BtLanguageSettingsPage::bookNameAbbreviationsTryVector() {
- QVector<QString> atv;
- atv.reserve(4);
- {
- QString settingsLanguage = btConfig().value<QString>("language");
- if (!settingsLanguage.isEmpty())
- atv.append(settingsLanguage);
- }
- {
- const QString localeLanguageAndCountry = QLocale::system().name();
- if (!localeLanguageAndCountry.isEmpty()) {
- atv.append(localeLanguageAndCountry);
- int i = localeLanguageAndCountry.indexOf('_');
- if (i > 0)
- atv.append(localeLanguageAndCountry.left(i));
- }
- }
- Q_ASSERT(CLanguageMgr::instance()->languageForAbbrev("en_US"));
- atv.append("en_US");
- return atv;
-}
-
-void BtLanguageSettingsPage::initSwordLocaleCombo() {
- typedef QMap<QString, QString>::const_iterator SSMCI;
-
- QMap<QString, QString> languageNames;
- Q_ASSERT(CLanguageMgr::instance()->languageForAbbrev("en_US"));
- languageNames.insert(CLanguageMgr::instance()->languageForAbbrev("en_US")->translatedName(), "en_US");
-
- const std::list<sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
- for (SBLCI it = locales.begin(); it != locales.end(); ++it) {
- const char * const abbreviation = sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getName();
- const CLanguageMgr::Language * const l = CLanguageMgr::instance()->languageForAbbrev(abbreviation);
-
- if (l->isValid()) {
- languageNames.insert(l->translatedName(), abbreviation);
- } else {
- languageNames.insert(
- sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getDescription(),
- abbreviation);
- }
- }
-
- int index = 0;
- QVector<QString> atv = bookNameAbbreviationsTryVector();
- for (SSMCI it = languageNames.constBegin(); it != languageNames.constEnd(); ++it) {
- if (!atv.isEmpty()) {
- int i = atv.indexOf(it.value());
- if (i >= 0) {
- atv.resize(i);
- index = m_swordLocaleCombo->count();
- }
- }
- m_swordLocaleCombo->addItem(it.key(), it.value());
- }
- m_swordLocaleCombo->setCurrentIndex(index);
-}
-
-void BtLanguageSettingsPage::retranslateUi() {
- setHeaderText(tr("Languages"));
-
- m_languageNamesLabel->setText(tr("Language for names of Bible books:"));
- const QString toolTip(tr("The languages which can be used for the biblical book names. Translations are provided by the Sword library."));
- m_languageNamesLabel->setToolTip(toolTip);
- m_swordLocaleCombo->setToolTip(toolTip);
-}
diff --git a/src/frontend/settingsdialogs/btlanguagesettings.h b/src/frontend/settingsdialogs/btlanguagesettings.h
deleted file mode 100644
index 89caaf2..0000000
--- a/src/frontend/settingsdialogs/btlanguagesettings.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*********
-*
-* In the name of the Father, and of the Son, and of the Holy Spirit.
-*
-* This file is part of BibleTime's source code, http://www.bibletime.info/.
-*
-* Copyright 1999-2014 by the BibleTime developers.
-* The BibleTime source code is licensed under the GNU General Public License version 2.0.
-*
-**********/
-
-#ifndef BTLANGUAGESETTINGS_H
-#define BTLANGUAGESETTINGS_H
-
-#include "frontend/bookshelfmanager/btconfigdialog.h"
-
-#include <QMap>
-#include <QWidget>
-
-
-class CConfigurationDialog;
-class QComboBox;
-class QLabel;
-
-class BtLanguageSettingsPage: public BtConfigDialog::Page {
-
- Q_OBJECT
-
- public: /* Methods: */
-
- BtLanguageSettingsPage(CConfigurationDialog *parent = 0);
-
- void save();
-
- static void resetLanguage();
-
- private: /* Methods: */
-
- static QVector<QString> bookNameAbbreviationsTryVector();
- void initSwordLocaleCombo();
- void retranslateUi();
-
- private: /* Fields: */
-
- QLabel *m_languageNamesLabel;
- QComboBox* m_swordLocaleCombo;
-
-};
-
-#endif
diff --git a/src/frontend/settingsdialogs/btshortcutsdialog.cpp b/src/frontend/settingsdialogs/btshortcutsdialog.cpp
index 10601f6..5299560 100644
--- a/src/frontend/settingsdialogs/btshortcutsdialog.cpp
+++ b/src/frontend/settingsdialogs/btshortcutsdialog.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -16,13 +16,14 @@
#include <QLabel>
#include <QRadioButton>
#include <QVBoxLayout>
+#include "util/btconnect.h"
// *************** BtShortcutsDialog ***************************************************************************
// A dialog to allow the user to input a shortcut for a primary and alternate key
BtShortcutsDialog::BtShortcutsDialog(QWidget* parent)
- : QDialog(parent), m_primaryLabel(0), m_alternateLabel(0), m_primaryButton(0), m_alternateButton(0) {
+ : QDialog(parent), m_primaryLabel(nullptr), m_alternateLabel(nullptr), m_primaryButton(nullptr), m_alternateButton(nullptr) {
setWindowTitle(tr("Configure shortcuts"));
setMinimumWidth(350);
@@ -59,8 +60,8 @@ BtShortcutsDialog::BtShortcutsDialog(QWidget* parent)
message::prepareDialogBox(buttons);
vLayout->addWidget(buttons);
- connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
- connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
+ BT_CONNECT(buttons, SIGNAL(accepted()), this, SLOT(accept()));
+ BT_CONNECT(buttons, SIGNAL(rejected()), this, SLOT(reject()));
}
// get new primary key from dialog
diff --git a/src/frontend/settingsdialogs/btshortcutsdialog.h b/src/frontend/settingsdialogs/btshortcutsdialog.h
index 722cef9..e5294ac 100644
--- a/src/frontend/settingsdialogs/btshortcutsdialog.h
+++ b/src/frontend/settingsdialogs/btshortcutsdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -48,7 +48,7 @@ class BtShortcutsDialog : public QDialog {
protected:
// get key from users input, put into primary or alternate label for display to user
- void keyReleaseEvent(QKeyEvent* event);
+ void keyReleaseEvent(QKeyEvent* event) override;
private:
QLabel* m_primaryLabel;
diff --git a/src/frontend/settingsdialogs/btshortcutseditor.cpp b/src/frontend/settingsdialogs/btshortcutseditor.cpp
index 2e943eb..3811f7d 100644
--- a/src/frontend/settingsdialogs/btshortcutseditor.cpp
+++ b/src/frontend/settingsdialogs/btshortcutseditor.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -22,6 +22,7 @@
#include <QVBoxLayout>
#include "frontend/displaywindow/btactioncollection.h"
#include "frontend/settingsdialogs/btshortcutsdialog.h"
+#include "util/btconnect.h"
// *************** BtShortcutsEditorItem *******************************************************************
@@ -48,7 +49,7 @@ class BtShortcutsEditorItem : public QTableWidgetItem {
};
BtShortcutsEditorItem::BtShortcutsEditorItem(QAction* action)
- : m_action(action), m_newFirstHotkey(0), m_newSecondHotkey(0) {
+ : m_action(action), m_newFirstHotkey(nullptr), m_newSecondHotkey(nullptr) {
QList<QKeySequence> list = m_action->shortcuts();
if (list.count() > 0)
m_newFirstHotkey = new QKeySequence(list.at(0));
@@ -74,13 +75,13 @@ void BtShortcutsEditorItem::setDefaultKeys(QKeySequence keys) {
}
void BtShortcutsEditorItem::setFirstHotkey(QKeySequence keys) {
- if (m_newFirstHotkey == 0)
+ if (m_newFirstHotkey == nullptr)
m_newFirstHotkey = new QKeySequence();
*m_newFirstHotkey = keys;
}
void BtShortcutsEditorItem::setSecondHotkey(const QString& keys) {
- if (m_newSecondHotkey == 0)
+ if (m_newSecondHotkey == nullptr)
m_newSecondHotkey = new QKeySequence();
*m_newSecondHotkey = QKeySequence(keys);
}
@@ -88,22 +89,22 @@ void BtShortcutsEditorItem::setSecondHotkey(const QString& keys) {
// Deletes hotkey information
void BtShortcutsEditorItem::deleteHotkeys() {
delete m_newFirstHotkey;
- m_newFirstHotkey = 0;
+ m_newFirstHotkey = nullptr;
delete m_newSecondHotkey;
- m_newSecondHotkey = 0;
+ m_newSecondHotkey = nullptr;
}
// Moves the hotkey information into the QAction variable
void BtShortcutsEditorItem::commitChanges() {
QString actionName = text();
QList<QKeySequence> list;
- if ( (m_newFirstHotkey != 0) && (*m_newFirstHotkey != QKeySequence()) ) {
+ if ( (m_newFirstHotkey != nullptr) && (*m_newFirstHotkey != QKeySequence()) ) {
list << *m_newFirstHotkey;
}
- if ( (m_newSecondHotkey != 0) && (*m_newSecondHotkey != QKeySequence()) )
+ if ( (m_newSecondHotkey != nullptr) && (*m_newSecondHotkey != QKeySequence()) )
list << *m_newSecondHotkey;
- if (m_action != 0)
+ if (m_action != nullptr)
m_action->setShortcuts(list);
}
@@ -111,29 +112,139 @@ void BtShortcutsEditorItem::commitChanges() {
// ******************* BtShortcutsEditor *******************************************************
BtShortcutsEditor::BtShortcutsEditor(BtActionCollection* collection, QWidget* parent)
- : QWidget(parent), m_dlg(new BtShortcutsDialog(this)), m_table(0), m_shortcutChooser(0), m_noneButton(0), m_defaultButton(0),
- m_customButton(0), m_defaultLabelValue(0), m_currentRow(-1) {
- init();
- addCollection(collection);
- bool ok = connect(m_dlg, SIGNAL(keyChangeRequest(const QString&)), this, SLOT(makeKeyChangeRequest(const QString&)) );
- Q_ASSERT(ok);
-}
-
-BtShortcutsEditor::BtShortcutsEditor(QWidget* parent)
- : QWidget(parent), m_table(0) {
- init();
-}
+ : QWidget(parent), m_dlg(new BtShortcutsDialog(this)), m_table(nullptr), m_shortcutChooser(nullptr), m_noneButton(nullptr), m_defaultButton(nullptr),
+ m_customButton(nullptr), m_defaultLabelValue(nullptr), m_currentRow(-1) {
-// initialize this widget
-void BtShortcutsEditor::init() {
- QVBoxLayout* vBox = new QVBoxLayout(this);
+ QVBoxLayout * const vBox = new QVBoxLayout(this);
setLayout(vBox);
- m_table = createShortcutsTable();
+ // Create the action and shortcuts table:
+ m_table = new QTableWidget{this};
+ m_table->setColumnCount(3);
+ m_table->setAlternatingRowColors(true);
+ m_table->setSelectionBehavior(QAbstractItemView::SelectRows);
+ m_table->setHorizontalHeaderLabels({tr("Action\nname"),
+ tr("First\nshortcut"),
+ tr("Second\nshortcut")});
+ m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
+ m_table->horizontalHeader()->resizeSection(0, 180);
+ m_table->horizontalHeader()->resizeSection(1, 100);
+ m_table->horizontalHeader()->setStretchLastSection(true);
+ m_table->verticalHeader()->setVisible(false);
+ m_table->setShowGrid(false);
+ BT_CONNECT(m_table, &QTableWidget::cellClicked,
+ this, &BtShortcutsEditor::changeRow);
vBox->addWidget(m_table);
- m_shortcutChooser = createShortcutChooser();
+ // Create the area below the table where the shortcuts are edited:
+ m_shortcutChooser =
+ new QGroupBox(tr("Shortcut for selected action name"), this);
+ m_shortcutChooser->setFlat(false);
+ {
+ QVBoxLayout * const vLayout = new QVBoxLayout(m_shortcutChooser);
+ {
+ QHBoxLayout * const hLayout = new QHBoxLayout();
+ vLayout->addLayout(hLayout);
+
+ m_noneButton = new QRadioButton(tr("None"), m_shortcutChooser);
+ hLayout->addWidget(m_noneButton);
+ BT_CONNECT(m_noneButton, &QRadioButton::clicked,
+ this, &BtShortcutsEditor::noneButtonClicked);
+
+ m_defaultButton =
+ new QRadioButton(tr("Default"), m_shortcutChooser);
+ hLayout->addWidget(m_defaultButton);
+ BT_CONNECT(
+ m_defaultButton, &QRadioButton::clicked,
+ this, &BtShortcutsEditor::defaultButtonClicked);
+
+ m_customButton = new QRadioButton(tr("Custom"), m_shortcutChooser);
+ hLayout->addWidget(m_customButton);
+ BT_CONNECT(m_customButton, &QRadioButton::clicked,
+ this, &BtShortcutsEditor::customButtonClicked);
+
+ m_customPushButton = new QPushButton(m_shortcutChooser);
+ m_customPushButton->setMinimumWidth(140);
+ hLayout->addWidget(m_customPushButton);
+
+ hLayout->addItem(new QSpacerItem(1,
+ 1,
+ QSizePolicy::Expanding,
+ QSizePolicy::Minimum));
+ }
+
+ QHBoxLayout * const hLayout = new QHBoxLayout();
+ vLayout->addLayout(hLayout);
+
+ hLayout->addWidget(new QLabel(tr("Default key:"), m_shortcutChooser));
+
+ m_defaultLabelValue = new QLabel(m_shortcutChooser);
+ hLayout->addWidget(m_defaultLabelValue);
+
+ hLayout->addItem(new QSpacerItem(1,
+ 1,
+ QSizePolicy::Expanding,
+ QSizePolicy::Minimum));
+ }
vBox->addWidget(m_shortcutChooser);
+
+ collection->foreachQAction([this](QAction & action,
+ QKeySequence const & defaultKeys)
+ {
+ int const count = m_table->rowCount();
+ m_table->insertRow(count);
+
+ {
+ BtShortcutsEditorItem * const item =
+ new BtShortcutsEditorItem{&action};
+ try {
+ /// \todo Remove this & hack and use Qt properties instead:
+ item->setText(action.text().replace(QRegExp("&(.)"), "\\1"));
+ item->setIcon(action.icon());
+ item->setDefaultKeys(defaultKeys);
+ item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+ m_table->setItem(count, 0, item);
+ } catch (...) {
+ delete item;
+ throw;
+ }
+ }
+
+ QList<QKeySequence> keys = action.shortcuts();
+
+ {
+ QTableWidgetItem * const item = new QTableWidgetItem;
+ try {
+ item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+ item->setToolTip(tr("Select to change key"));
+ if (keys.count() > 0)
+ item->setText(keys[0].toString());
+ m_table->setItem(count, 1, item);
+ } catch (...) {
+ delete item;
+ throw;
+ }
+ }
+
+ {
+ QTableWidgetItem * const item = new QTableWidgetItem;
+ try {
+ item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+ item->setToolTip(tr("Select to change key"));
+ if (keys.count() > 1)
+ item->setText(keys[1].toString());
+ m_table->setItem(count, 2, item);
+ } catch (...) {
+ delete item;
+ throw;
+ }
+ }
+ });
+ m_table->sortItems(0);
+ m_table->selectRow(0);
+ changeRow(0, 0);
+ BT_CONNECT(m_dlg, &BtShortcutsDialog::keyChangeRequest,
+ this, &BtShortcutsEditor::makeKeyChangeRequest);
}
// get the shortcut editor item from the zeroth column of the table
@@ -148,77 +259,11 @@ void BtShortcutsEditor::commitChanges() {
int rows = m_table->rowCount();
for (int row = 0; row < rows; row++) {
BtShortcutsEditorItem* btItem = getShortcutsEditor(row);
- if (btItem != 0)
+ if (btItem != nullptr)
btItem->commitChanges();
}
}
-// puts actions and shortcut keys into QTableWidget
-void BtShortcutsEditor::addCollection(BtActionCollection* collection, const QString& title) {
- Q_UNUSED(title); /// \todo Is this correct?
-
- foreach (QAction *action, collection->actions()) {
- /// \todo Is the following check really necessary?
- if (action) {
- int count = m_table->rowCount();
- m_table->insertRow(count);
-
- QString name = action->text().remove('&');
- QList<QKeySequence> keys = action->shortcuts();
- QIcon icon = action->icon();
- QKeySequence defaultKeys = collection->getDefaultShortcut(action);
-
- BtShortcutsEditorItem* item = new BtShortcutsEditorItem(action);
- item->setText(name);
- item->setIcon(icon);
- item->setDefaultKeys(defaultKeys);
- item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- m_table->setItem(count, 0, item);
-
- QTableWidgetItem* item1 = new QTableWidgetItem();
- item1->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- item1->setToolTip(tr("Select to change key"));
- if (keys.count() > 0)
- item1->setText(keys[0].toString());
- m_table->setItem(count, 1, item1);
-
- QTableWidgetItem* item2 = new QTableWidgetItem();
- item2->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- item2->setToolTip(tr("Select to change key"));
- if (keys.count() > 1)
- item2->setText(keys[1].toString());
- m_table->setItem(count, 2, item2);
- }
- }
- m_table->sortItems(0);
- m_table->selectRow(0);
- changeRow(0, 0);
-}
-
-// create the action and shortcuts table
-QTableWidget* BtShortcutsEditor::createShortcutsTable() {
- QTableWidget* table = new QTableWidget(this);
- table->setColumnCount(3);
- table->setAlternatingRowColors(true);
- table->setSelectionBehavior(QAbstractItemView::SelectRows);
- QStringList headerList;
- headerList << tr("Action\nname") << tr("First\nshortcut") << tr("Second\nshortcut");
- table->setHorizontalHeaderLabels(headerList);
-#if QT_VERSION < 0x050000
- table->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
-#else
- table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
-#endif
- table->horizontalHeader()->resizeSection(0, 180);
- table->horizontalHeader()->resizeSection(1, 100);
- table->horizontalHeader()->setStretchLastSection(true);
- table->verticalHeader()->setVisible(false);
- table->setShowGrid(false);
- bool ok = connect(table, SIGNAL(cellClicked(int, int)), this, SLOT(changeRow(int, int)));
- Q_ASSERT(ok);
- return table;
-}
-
// called when a different action name row is selected
void BtShortcutsEditor::changeRow(int row, int column) {
Q_UNUSED(column); /// \todo Is this correct?
@@ -248,52 +293,6 @@ void BtShortcutsEditor::changeRow(int row, int column) {
m_customButton->setChecked(true);
}
-// create the area below the table where the shortcuts are edited
-QWidget* BtShortcutsEditor::createShortcutChooser() {
- QGroupBox* box = new QGroupBox(tr("Shortcut for selected action name"), this);
- box->setFlat(false);
- QVBoxLayout* vLayout = new QVBoxLayout(box);
- QHBoxLayout* hLayout = new QHBoxLayout();
- vLayout->addLayout(hLayout);
-
- m_noneButton = new QRadioButton(tr("None"), box);
- hLayout->addWidget(m_noneButton);
- bool ok = connect(m_noneButton, SIGNAL(clicked(bool)), this, SLOT(noneButtonClicked(bool)));
- Q_ASSERT(ok);
-
- m_defaultButton = new QRadioButton(tr("Default"), box);
- hLayout->addWidget(m_defaultButton);
- ok = connect(m_defaultButton, SIGNAL(clicked(bool)), this, SLOT(defaultButtonClicked(bool)));
- Q_ASSERT(ok);
-
- m_customButton = new QRadioButton(tr("Custom"), box);
- hLayout->addWidget(m_customButton);
- ok = connect(m_customButton, SIGNAL(clicked(bool)), this, SLOT(customButtonClicked(bool)));
- Q_ASSERT(ok);
-
- m_customPushButton = new QPushButton(box);
- m_customPushButton->setMinimumWidth(140);
- hLayout->addWidget(m_customPushButton);
-
- QSpacerItem* spacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
- hLayout->addItem(spacer);
-
- QHBoxLayout* hLayout2 = new QHBoxLayout();
- vLayout->addLayout(hLayout2);
-
- QLabel* defaultLabel = new QLabel(tr("Default key:"), box);
- hLayout2->addWidget(defaultLabel);
-
- m_defaultLabelValue = new QLabel(box);
- hLayout2->addWidget(m_defaultLabelValue);
-
- QSpacerItem* spacer2 = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
- hLayout2->addItem(spacer2);
-
- return box;
-}
-
-
// called when the none radio button is clicked
void BtShortcutsEditor::noneButtonClicked(bool checked) {
Q_UNUSED(checked); /// \todo Is this correct?
diff --git a/src/frontend/settingsdialogs/btshortcutseditor.h b/src/frontend/settingsdialogs/btshortcutseditor.h
index d58ac08..66cee81 100644
--- a/src/frontend/settingsdialogs/btshortcutseditor.h
+++ b/src/frontend/settingsdialogs/btshortcutseditor.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -19,6 +19,7 @@
class BtActionCollection;
class BtShortcutsEditorItem;
class BtShortcutsDialog;
+class QGroupBox;
class QLabel;
class QPushButton;
class QRadioButton;
@@ -28,15 +29,11 @@ class QTableWidget;
class BtShortcutsEditor : public QWidget {
Q_OBJECT
public:
- BtShortcutsEditor(BtActionCollection* collection, QWidget* parent);
- BtShortcutsEditor(QWidget* parent);
+ BtShortcutsEditor(BtActionCollection * collection, QWidget * parent);
// saves shortcut keys into the QAction
void commitChanges();
- // puts actions and shortcut keys into QTableWidget
- void addCollection(BtActionCollection *collection, const QString &title = QString::null);
-
// clears any shortcut keys in the table matching the specified keys
void clearConflictWithKeys(const QString& keys);
@@ -70,21 +67,12 @@ class BtShortcutsEditor : public QWidget {
private:
- // create the action and shortcuts table
- QTableWidget* createShortcutsTable();
-
- // create the area below the table where the shortcuts are edited
- QWidget* createShortcutChooser();
-
// get the shortcut editor item from the zeroth column of the table
BtShortcutsEditorItem* getShortcutsEditor(int row);
- // initialize this widget
- void init();
-
BtShortcutsDialog* m_dlg;
QTableWidget* m_table;
- QWidget* m_shortcutChooser;
+ QGroupBox * m_shortcutChooser;
QRadioButton* m_noneButton;
QRadioButton* m_defaultButton;
QRadioButton* m_customButton;
diff --git a/src/frontend/settingsdialogs/btstandardworkstab.cpp b/src/frontend/settingsdialogs/btstandardworkstab.cpp
index 9cef549..1190aa6 100644
--- a/src/frontend/settingsdialogs/btstandardworkstab.cpp
+++ b/src/frontend/settingsdialogs/btstandardworkstab.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -23,8 +23,6 @@
BtStandardWorksTab::BtStandardWorksTab(CSwordSettingsPage *parent)
: QWidget(parent)
{
- typedef QList<CSwordModuleInfo*>::const_iterator MLCI;
-
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(5);
mainLayout->setSpacing(2);
@@ -59,12 +57,13 @@ BtStandardWorksTab::BtStandardWorksTab(CSwordSettingsPage *parent)
//fill the comboboxes with the right modules
- const QList<CSwordModuleInfo*> &modules(CSwordBackend::instance()->moduleList());
QString modDescript;
- for (MLCI it(modules.begin()); it != modules.end(); it++) {
- modDescript = (*it)->config(CSwordModuleInfo::Description);
+ Q_FOREACH(CSwordModuleInfo const * const m,
+ CSwordBackend::instance()->moduleList())
+ {
+ modDescript = m->config(CSwordModuleInfo::Description);
- switch ((*it)->type()) {
+ switch (m->type()) {
case CSwordModuleInfo::Bible:
m_standardBibleCombo->addItem(modDescript);
break;
@@ -73,23 +72,23 @@ BtStandardWorksTab::BtStandardWorksTab(CSwordSettingsPage *parent)
break;
case CSwordModuleInfo::Lexicon: {
bool inserted = false;
- if ((*it)->has(CSwordModuleInfo::HebrewDef)) {
+ if (m->has(CSwordModuleInfo::HebrewDef)) {
m_standardHebrewStrongsLexiconCombo->addItem(modDescript);
inserted = true;
}
- if ((*it)->has(CSwordModuleInfo::GreekDef)) {
+ if (m->has(CSwordModuleInfo::GreekDef)) {
m_standardGreekStrongsLexiconCombo->addItem(modDescript);
inserted = true;
}
- if ((*it)->has(CSwordModuleInfo::HebrewParse)) {
+ if (m->has(CSwordModuleInfo::HebrewParse)) {
m_standardHebrewMorphLexiconCombo->addItem(modDescript);
inserted = true;
}
- if ((*it)->has(CSwordModuleInfo::GreekParse)) {
+ if (m->has(CSwordModuleInfo::GreekParse)) {
m_standardGreekMorphLexiconCombo->addItem(modDescript);
inserted = true;
}
- if ((*it)->category() == CSwordModuleInfo::DailyDevotional) {
+ if (m->category() == CSwordModuleInfo::DailyDevotional) {
m_standardDailyDevotionalCombo->addItem(modDescript);
inserted = true;
}
@@ -109,7 +108,7 @@ BtStandardWorksTab::BtStandardWorksTab(CSwordSettingsPage *parent)
QStringList moduleList;
// fill combobox and modulelist
- const CSwordModuleInfo* m;
+ const CSwordModuleInfo* m;
#define STANDARD_WORKS_COMBO_ADD(name) \
comboList.append(m_ ## name ## Combo); \
diff --git a/src/frontend/settingsdialogs/btstandardworkstab.h b/src/frontend/settingsdialogs/btstandardworkstab.h
index 0b91b4c..d03fe9e 100644
--- a/src/frontend/settingsdialogs/btstandardworkstab.h
+++ b/src/frontend/settingsdialogs/btstandardworkstab.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
diff --git a/src/frontend/settingsdialogs/bttextfilterstab.cpp b/src/frontend/settingsdialogs/bttextfilterstab.cpp
index e8da038..ee1c410 100644
--- a/src/frontend/settingsdialogs/bttextfilterstab.cpp
+++ b/src/frontend/settingsdialogs/bttextfilterstab.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -72,8 +72,9 @@ void BtTextFiltersTab::save() {
void BtTextFiltersTab::retranslateUi() {
util::tool::initExplanationLabel(m_explanationLabel, "",
tr("Filters control the appearance of text. Here you can specify "
- "default settings for all filters. You can override these "
- "settings in each display window."));
+ "default settings for all filters. These settings apply to newly "
+ "opened display windows only. You can override these settings in "
+ "each display window."));
m_lineBreaksCheck->setText(tr("Insert line break after each verse"));
m_verseNumbersCheck->setText(tr("Show verse numbers"));
diff --git a/src/frontend/settingsdialogs/bttextfilterstab.h b/src/frontend/settingsdialogs/bttextfilterstab.h
index 3f6e904..fbfedde 100644
--- a/src/frontend/settingsdialogs/bttextfilterstab.h
+++ b/src/frontend/settingsdialogs/bttextfilterstab.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
diff --git a/src/frontend/settingsdialogs/cacceleratorsettings.cpp b/src/frontend/settingsdialogs/cacceleratorsettings.cpp
index d85bf51..c95a715 100644
--- a/src/frontend/settingsdialogs/cacceleratorsettings.cpp
+++ b/src/frontend/settingsdialogs/cacceleratorsettings.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -26,12 +26,12 @@
#include "frontend/displaywindow/creadwindow.h"
#include "frontend/messagedialog.h"
#include "frontend/settingsdialogs/cconfigurationdialog.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
CAcceleratorSettingsPage::CAcceleratorSettingsPage(CConfigurationDialog *parent)
- : BtConfigDialog::Page(util::getIcon(CResMgr::settings::keys::icon), parent)
+ : BtConfigDialog::Page(CResMgr::settings::keys::icon(), parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
@@ -44,9 +44,8 @@ CAcceleratorSettingsPage::CAcceleratorSettingsPage(CConfigurationDialog *parent)
m_typeChooser = new QComboBox(this);
layoutForWindowTypeChooser->addWidget(m_typeChooser);
- bool ok = connect(m_typeChooser, SIGNAL(activated(const QString&)),
- SLOT(slotKeyChooserTypeChanged(const QString&)) );
- Q_ASSERT(ok);
+ BT_CONNECT(m_typeChooser, SIGNAL(activated(QString const &)),
+ SLOT(slotKeyChooserTypeChanged(QString const &)) );
// m_*.title strings are empty here, they are filled and added to the stacked widget in the retranslateUi() function
m_keyChooserStack = new QStackedWidget(this);
@@ -60,9 +59,11 @@ CAcceleratorSettingsPage::CAcceleratorSettingsPage(CConfigurationDialog *parent)
m_application.actionCollection->readShortcuts("Application shortcuts");
m_application.keyChooser = new BtShortcutsEditor(m_application.actionCollection, m_keyChooserStack);
m_keyChooserStack->addWidget(m_application.keyChooser);
- ok = connect(m_application.keyChooser, SIGNAL(keyChangeRequest(BtShortcutsEditor*, const QString&)),
- this, SLOT(completeKeyChangeRequest(BtShortcutsEditor*, const QString&)));
- Q_ASSERT(ok);
+ BT_CONNECT(m_application.keyChooser,
+ SIGNAL(keyChangeRequest(BtShortcutsEditor *, QString const &)),
+ this,
+ SLOT(completeKeyChangeRequest(BtShortcutsEditor *,
+ QString const &)));
// ----- All display windows ------ //
m_general.actionCollection = new BtActionCollection(this);
@@ -70,9 +71,11 @@ CAcceleratorSettingsPage::CAcceleratorSettingsPage(CConfigurationDialog *parent)
m_general.actionCollection->readShortcuts("Displaywindow shortcuts");
m_general.keyChooser = new BtShortcutsEditor(m_general.actionCollection, m_keyChooserStack);
m_keyChooserStack->addWidget(m_general.keyChooser);
- ok = connect(m_general.keyChooser, SIGNAL(keyChangeRequest(BtShortcutsEditor*, const QString&)),
- this, SLOT(completeKeyChangeRequest(BtShortcutsEditor*, const QString&)));
- Q_ASSERT(ok);
+ BT_CONNECT(m_general.keyChooser,
+ SIGNAL(keyChangeRequest(BtShortcutsEditor *, QString const &)),
+ this,
+ SLOT(completeKeyChangeRequest(BtShortcutsEditor *,
+ QString const &)));
// ----- Bible windows ------ //
m_bible.actionCollection = new BtActionCollection(this);
@@ -80,9 +83,11 @@ CAcceleratorSettingsPage::CAcceleratorSettingsPage(CConfigurationDialog *parent)
m_bible.actionCollection->readShortcuts("Bible shortcuts");
m_bible.keyChooser = new BtShortcutsEditor(m_bible.actionCollection, m_keyChooserStack);
m_keyChooserStack->addWidget(m_bible.keyChooser);
- ok = connect(m_bible.keyChooser, SIGNAL(keyChangeRequest(BtShortcutsEditor*, const QString&)),
- this, SLOT(completeKeyChangeRequest(BtShortcutsEditor*, const QString&)));
- Q_ASSERT(ok);
+ BT_CONNECT(m_bible.keyChooser,
+ SIGNAL(keyChangeRequest(BtShortcutsEditor *, QString const &)),
+ this,
+ SLOT(completeKeyChangeRequest(BtShortcutsEditor *,
+ QString const &)));
// ----- Commentary windows ------ //
m_commentary.actionCollection = new BtActionCollection(this);
@@ -90,9 +95,11 @@ CAcceleratorSettingsPage::CAcceleratorSettingsPage(CConfigurationDialog *parent)
m_commentary.actionCollection->readShortcuts("Commentary shortcuts");
m_commentary.keyChooser = new BtShortcutsEditor(m_commentary.actionCollection, m_keyChooserStack);
m_keyChooserStack->addWidget(m_commentary.keyChooser);
- ok = connect(m_commentary.keyChooser, SIGNAL(keyChangeRequest(BtShortcutsEditor*, const QString&)),
- this, SLOT(completeKeyChangeRequest(BtShortcutsEditor*, const QString&)));
- Q_ASSERT(ok);
+ BT_CONNECT(m_commentary.keyChooser,
+ SIGNAL(keyChangeRequest(BtShortcutsEditor *, QString const &)),
+ this,
+ SLOT(completeKeyChangeRequest(BtShortcutsEditor *,
+ QString const &)));
// ----- Lexicon windows ------ //
m_lexicon.actionCollection = new BtActionCollection(this);
@@ -100,9 +107,11 @@ CAcceleratorSettingsPage::CAcceleratorSettingsPage(CConfigurationDialog *parent)
m_lexicon.actionCollection->readShortcuts("Lexicon shortcuts");
m_lexicon.keyChooser = new BtShortcutsEditor(m_lexicon.actionCollection, m_keyChooserStack);
m_keyChooserStack->addWidget(m_lexicon.keyChooser);
- ok = connect(m_lexicon.keyChooser, SIGNAL(keyChangeRequest(BtShortcutsEditor*, const QString&)),
- this, SLOT(completeKeyChangeRequest(BtShortcutsEditor*, const QString&)));
- Q_ASSERT(ok);
+ BT_CONNECT(m_lexicon.keyChooser,
+ SIGNAL(keyChangeRequest(BtShortcutsEditor *, QString const &)),
+ this,
+ SLOT(completeKeyChangeRequest(BtShortcutsEditor *,
+ QString const &)));
// ----- Book windows ------ //
m_book.actionCollection = new BtActionCollection(this);
@@ -110,9 +119,11 @@ CAcceleratorSettingsPage::CAcceleratorSettingsPage(CConfigurationDialog *parent)
m_book.actionCollection->readShortcuts("Book shortcuts");
m_book.keyChooser = new BtShortcutsEditor(m_book.actionCollection, m_keyChooserStack);
m_keyChooserStack->addWidget(m_book.keyChooser);
- ok = connect(m_book.keyChooser, SIGNAL(keyChangeRequest(BtShortcutsEditor*, const QString&)),
- this, SLOT(completeKeyChangeRequest(BtShortcutsEditor*, const QString&)));
- Q_ASSERT(ok);
+ BT_CONNECT(m_book.keyChooser,
+ SIGNAL(keyChangeRequest(BtShortcutsEditor *, QString const &)),
+ this,
+ SLOT(completeKeyChangeRequest(BtShortcutsEditor *,
+ QString const &)));
mainLayout->addWidget(m_keyChooserStack);
slotKeyChooserTypeChanged(m_application.title);
diff --git a/src/frontend/settingsdialogs/cacceleratorsettings.h b/src/frontend/settingsdialogs/cacceleratorsettings.h
index 49408d5..4e79ca6 100644
--- a/src/frontend/settingsdialogs/cacceleratorsettings.h
+++ b/src/frontend/settingsdialogs/cacceleratorsettings.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,7 +12,7 @@
#ifndef CACCELERATORSETTINGS_H
#define CACCELERATORSETTINGS_H
-#include "frontend/bookshelfmanager/btconfigdialog.h"
+#include "btconfigdialog.h"
#include <QPointer>
#include <QWidget>
@@ -36,7 +36,7 @@ class CAcceleratorSettingsPage: public BtConfigDialog::Page {
public: /* Methods: */
- CAcceleratorSettingsPage(CConfigurationDialog *parent = 0);
+ CAcceleratorSettingsPage(CConfigurationDialog *parent = nullptr);
void save();
@@ -58,13 +58,8 @@ class CAcceleratorSettingsPage: public BtConfigDialog::Page {
QString title;
WindowType() {
- keyChooser = 0;
- actionCollection = 0;
- };
- WindowType(const QString& newTitle) {
- title = newTitle;
- keyChooser = 0;
- actionCollection = 0;
+ keyChooser = nullptr;
+ actionCollection = nullptr;
}
};
diff --git a/src/frontend/settingsdialogs/cconfigurationdialog.cpp b/src/frontend/settingsdialogs/cconfigurationdialog.cpp
index 951880b..93801f0 100644
--- a/src/frontend/settingsdialogs/cconfigurationdialog.cpp
+++ b/src/frontend/settingsdialogs/cconfigurationdialog.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -18,9 +18,9 @@
#include "frontend/settingsdialogs/cacceleratorsettings.h"
#include "frontend/settingsdialogs/cdisplaysettings.h"
#include "frontend/settingsdialogs/btfontsettings.h"
-#include "frontend/settingsdialogs/btlanguagesettings.h"
#include "frontend/settingsdialogs/cswordsettings.h"
#include "frontend/messagedialog.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
#include "util/directory.h"
@@ -32,12 +32,11 @@ const QString GeometryKey = "GUI/SettingsDialog/geometry";
CConfigurationDialog::CConfigurationDialog(QWidget * parent, BtActionCollection* actionCollection )
: BtConfigDialog(parent),
m_actionCollection(actionCollection),
- m_displayPage(0),
- m_swordPage(0),
- m_acceleratorsPage(0),
- m_fontsPage(0),
- m_languagesPage(0),
- m_bbox(0) {
+ m_displayPage(nullptr),
+ m_swordPage(nullptr),
+ m_acceleratorsPage(nullptr),
+ m_fontsPage(nullptr),
+ m_bbox(nullptr) {
setWindowTitle(tr("Configure BibleTime"));
setAttribute(Qt::WA_DeleteOnClose);
@@ -49,10 +48,6 @@ CConfigurationDialog::CConfigurationDialog(QWidget * parent, BtActionCollection*
m_swordPage = new CSwordSettingsPage(this);
addPage(m_swordPage);
- // Add "Languages" page
- m_languagesPage = new BtLanguageSettingsPage(this);
- addPage(m_languagesPage);
-
// Add "Fonts" page
m_fontsPage = new BtFontSettingsPage(this);
addPage(m_fontsPage);
@@ -68,8 +63,8 @@ CConfigurationDialog::CConfigurationDialog(QWidget * parent, BtActionCollection*
m_bbox->addButton(QDialogButtonBox::Cancel);
message::prepareDialogBox(m_bbox);
setButtonBox(m_bbox);
- bool ok = connect(m_bbox, SIGNAL(clicked(QAbstractButton *)), SLOT(slotButtonClicked(QAbstractButton *)));
- Q_ASSERT(ok);
+ BT_CONNECT(m_bbox, SIGNAL(clicked(QAbstractButton *)),
+ SLOT(slotButtonClicked(QAbstractButton *)));
loadDialogSettings();
@@ -83,7 +78,6 @@ CConfigurationDialog::~CConfigurationDialog() {
/** Save the dialog settings **/
void CConfigurationDialog::save() {
m_acceleratorsPage->save();
- m_languagesPage->save();
m_fontsPage->save();
m_swordPage->save();
m_displayPage->save();
diff --git a/src/frontend/settingsdialogs/cconfigurationdialog.h b/src/frontend/settingsdialogs/cconfigurationdialog.h
index fbd4944..ec00cf4 100644
--- a/src/frontend/settingsdialogs/cconfigurationdialog.h
+++ b/src/frontend/settingsdialogs/cconfigurationdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,14 +12,13 @@
#ifndef CCONFIGURATIONDIALOG_H
#define CCONFIGURATIONDIALOG_H
-#include "frontend/bookshelfmanager/btconfigdialog.h"
+#include "btconfigdialog.h"
class BtActionCollection;
class CAcceleratorSettingsPage;
class CDisplaySettingsPage;
class BtFontSettingsPage;
-class BtLanguageSettingsPage;
class CSwordSettingsPage;
class QAbstractButton;
class QDialogButtonBox;
@@ -41,7 +40,6 @@ class CConfigurationDialog : public BtConfigDialog {
CSwordSettingsPage* m_swordPage;
CAcceleratorSettingsPage* m_acceleratorsPage;
BtFontSettingsPage* m_fontsPage;
- BtLanguageSettingsPage* m_languagesPage;
QDialogButtonBox* m_bbox;
// Load the settings from the resource file
diff --git a/src/frontend/settingsdialogs/cdisplaysettings.cpp b/src/frontend/settingsdialogs/cdisplaysettings.cpp
index 5b690f6..92bf5a0 100644
--- a/src/frontend/settingsdialogs/cdisplaysettings.cpp
+++ b/src/frontend/settingsdialogs/cdisplaysettings.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -13,24 +13,31 @@
#include <QComboBox>
#include <QLabel>
#include <QVBoxLayout>
-#include <QWebView>
+#include <QFormLayout>
#include "backend/config/btconfig.h"
#include "backend/managers/cdisplaytemplatemgr.h"
#include "backend/rendering/cdisplayrendering.h"
#include "bibletimeapp.h"
+#include "frontend/btwebengineview.h"
#include "frontend/settingsdialogs/cconfigurationdialog.h"
+#include "util/btassert.h"
+#include "util/btconnect.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
#include "util/tool.h"
+// Sword includes:
+#include <localemgr.h>
+#include <swlocale.h>
+
+using SBLCI = std::list<sword::SWBuf>::const_iterator;
// ***********************
-// Container for QWebView to control its size
+// Container for BtWebEngineView to control its size
class CWebViewerWidget : public QWidget {
public:
- CWebViewerWidget(QWidget* parent = 0);
+ CWebViewerWidget(QWidget* parent = nullptr);
~CWebViewerWidget();
- virtual QSize sizeHint () const;
+ QSize sizeHint() const override;
};
CWebViewerWidget::CWebViewerWidget(QWidget* parent)
@@ -47,36 +54,37 @@ QSize CWebViewerWidget::sizeHint () const {
/** Initializes the startup section of the OD. */
CDisplaySettingsPage::CDisplaySettingsPage(CConfigurationDialog *parent)
- : BtConfigDialog::Page(util::getIcon(CResMgr::settings::startup::icon), parent)
+ : BtConfigDialog::Page(CResMgr::settings::startup::icon(), parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
- { //startup logo
- m_showLogoCheck = new QCheckBox(this);
- m_showLogoCheck->setChecked(btConfig().value<bool>("GUI/showSplashScreen", true));
- mainLayout->addWidget(m_showLogoCheck);
- }
- mainLayout->addSpacing(20);
+ QFormLayout *formLayout = new QFormLayout();
+
+ //startup logo
+ m_showLogoLabel = new QLabel(this);
+ m_showLogoCheck = new QCheckBox(this);
+ m_showLogoCheck->setChecked(btConfig().value<bool>("GUI/showSplashScreen", true));
+ formLayout->addRow(m_showLogoLabel, m_showLogoCheck);
- m_explanationLabel = new QLabel(this);
- mainLayout->addWidget(m_explanationLabel);
+ m_swordLocaleCombo = new QComboBox(this);
+ m_languageNamesLabel = new QLabel(this);
+ m_languageNamesLabel->setBuddy(m_swordLocaleCombo);
+ formLayout->addRow(m_languageNamesLabel, m_swordLocaleCombo);
- QHBoxLayout* hboxlayout = new QHBoxLayout();
+ initSwordLocaleCombo();
m_styleChooserCombo = new QComboBox( this ); //create first to enable buddy for label
- connect( m_styleChooserCombo, SIGNAL( activated( int ) ),
- this, SLOT( updateStylePreview() ) );
+ BT_CONNECT(m_styleChooserCombo, SIGNAL(activated(int)),
+ this, SLOT(updateStylePreview()));
m_availableLabel = new QLabel(this);
m_availableLabel->setBuddy(m_styleChooserCombo);
- hboxlayout->addWidget(m_availableLabel);
- hboxlayout->addWidget( m_styleChooserCombo );
- hboxlayout->addStretch();
- mainLayout->addLayout( hboxlayout );
+ formLayout->addRow(m_availableLabel, m_styleChooserCombo );
+ mainLayout->addLayout(formLayout);
QWidget* webViewWidget = new CWebViewerWidget(this);
QLayout* webViewLayout = new QVBoxLayout(webViewWidget);
- m_stylePreviewViewer = new QWebView(webViewWidget);
+ m_stylePreviewViewer = new BtWebEngineView(webViewWidget);
m_previewLabel = new QLabel(webViewWidget);
m_previewLabel->setBuddy(m_stylePreviewViewer);
webViewLayout->addWidget(m_previewLabel);
@@ -94,25 +102,116 @@ CDisplaySettingsPage::CDisplaySettingsPage(CConfigurationDialog *parent)
}
}
+ m_transifexLabel = new QLabel(this);
+ mainLayout->addWidget(m_transifexLabel);
+
retranslateUi(); // also calls updateStylePreview();
}
void CDisplaySettingsPage::retranslateUi() {
setHeaderText(tr("Display"));
- util::tool::initExplanationLabel(
- m_explanationLabel,
- tr("Display templates"),
- tr("Display templates define how text is displayed.")
- );
+ m_languageNamesLabel->setText(tr("Language for names of Bible books:"));
+ const QString toolTip(tr("The languages which can be used for the biblical book names. Translations are provided by the Sword library."));
+ m_languageNamesLabel->setToolTip(toolTip);
+ m_swordLocaleCombo->setToolTip(toolTip);
- m_showLogoCheck->setText(tr("Show startup logo"));
- m_showLogoCheck->setToolTip(tr("Show the BibleTime logo on startup"));
+ m_showLogoLabel->setText(tr("Show startup logo:"));
+ m_showLogoLabel->setToolTip(tr("Show the BibleTime logo on startup."));
m_availableLabel->setText(tr("Available display styles:"));
m_previewLabel->setText(tr("Style preview"));
updateStylePreview();
+
+ m_transifexLabel->setWordWrap(true);
+ m_transifexLabel->setOpenExternalLinks(true);
+ m_transifexLabel->setText(tr(
+ "Did you know? You can help translating the GUI of BibleTime to your language at %1."
+ ).arg(QString("<a href=\"https://www.transifex.com/bibletime/bibletime/\">")
+ .append(tr("Transifex"))
+ .append("</a>")));
+}
+
+void CDisplaySettingsPage::resetLanguage() {
+ QVector<QString> atv = bookNameAbbreviationsTryVector();
+
+ QString best = "en_US";
+ BT_ASSERT(atv.contains(best));
+ int i = atv.indexOf(best);
+ if (i > 0) {
+ atv.resize(i);
+ const std::list<sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
+ for (SBLCI it = locales.begin(); it != locales.end(); ++it) {
+ const char * abbr = sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getName();
+ i = atv.indexOf(abbr);
+ if (i >= 0) {
+ best = abbr;
+ if (i == 0)
+ break;
+ atv.resize(i);
+ }
+ }
+ }
+ btConfig().setValue("GUI/booknameLanguage", best);
+}
+
+QVector<QString> CDisplaySettingsPage::bookNameAbbreviationsTryVector() {
+ QVector<QString> atv;
+ atv.reserve(4);
+ {
+ QString settingsLanguage = btConfig().value<QString>("GUI/booknameLanguage");
+ if (!settingsLanguage.isEmpty())
+ atv.append(settingsLanguage);
+ }
+ {
+ const QString localeLanguageAndCountry = QLocale::system().name();
+ if (!localeLanguageAndCountry.isEmpty()) {
+ atv.append(localeLanguageAndCountry);
+ int i = localeLanguageAndCountry.indexOf('_');
+ if (i > 0)
+ atv.append(localeLanguageAndCountry.left(i));
+ }
+ }
+ BT_ASSERT(CLanguageMgr::instance()->languageForAbbrev("en_US"));
+ atv.append("en_US");
+ return atv;
+}
+
+void CDisplaySettingsPage::initSwordLocaleCombo() {
+ using SSMCI = QMap<QString, QString>::const_iterator;
+
+ QMap<QString, QString> languageNames;
+ BT_ASSERT(CLanguageMgr::instance()->languageForAbbrev("en_US"));
+ languageNames.insert(CLanguageMgr::instance()->languageForAbbrev("en_US")->translatedName(), "en_US");
+
+ const std::list<sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
+ for (SBLCI it = locales.begin(); it != locales.end(); ++it) {
+ const char * const abbreviation = sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getName();
+ const CLanguageMgr::Language * const l = CLanguageMgr::instance()->languageForAbbrev(abbreviation);
+
+ if (l->isValid()) {
+ languageNames.insert(l->translatedName(), abbreviation);
+ } else {
+ languageNames.insert(
+ sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getDescription(),
+ abbreviation);
+ }
+ }
+
+ int index = 0;
+ QVector<QString> atv = bookNameAbbreviationsTryVector();
+ for (SSMCI it = languageNames.constBegin(); it != languageNames.constEnd(); ++it) {
+ if (!atv.isEmpty()) {
+ int i = atv.indexOf(it.value());
+ if (i >= 0) {
+ atv.resize(i);
+ index = m_swordLocaleCombo->count();
+ }
+ }
+ m_swordLocaleCombo->addItem(it.key(), it.value());
+ }
+ m_swordLocaleCombo->setCurrentIndex(index);
}
@@ -172,4 +271,5 @@ void CDisplaySettingsPage::updateStylePreview() {
void CDisplaySettingsPage::save() {
btConfig().setValue("GUI/showSplashScreen", m_showLogoCheck->isChecked() );
btConfig().setValue("GUI/activeTemplateName", m_styleChooserCombo->currentText());
+ btConfig().setValue("GUI/booknameLanguage", m_swordLocaleCombo->itemData(m_swordLocaleCombo->currentIndex()));
}
diff --git a/src/frontend/settingsdialogs/cdisplaysettings.h b/src/frontend/settingsdialogs/cdisplaysettings.h
index 834c846..1f6ad6a 100644
--- a/src/frontend/settingsdialogs/cdisplaysettings.h
+++ b/src/frontend/settingsdialogs/cdisplaysettings.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,7 +12,7 @@
#ifndef CDISPLAYSETTINGS_H
#define CDISPLAYSETTINGS_H
-#include "frontend/bookshelfmanager/btconfigdialog.h"
+#include "btconfigdialog.h"
#include <QWidget>
@@ -21,7 +21,7 @@ class CConfigurationDialog;
class QCheckBox;
class QComboBox;
class QLabel;
-class QWebView;
+class BtWebEngineView;
class CDisplaySettingsPage: public BtConfigDialog::Page {
@@ -29,10 +29,12 @@ class CDisplaySettingsPage: public BtConfigDialog::Page {
public: /* Methods: */
- CDisplaySettingsPage(CConfigurationDialog *parent = 0);
+ CDisplaySettingsPage(CConfigurationDialog *parent = nullptr);
void save();
+ static void resetLanguage();
+
protected: /* Methods: */
void retranslateUi();
@@ -41,13 +43,21 @@ class CDisplaySettingsPage: public BtConfigDialog::Page {
/** Update the style preview widget. */
void updateStylePreview();
+ private: /* Methods: */
+
+ static QVector<QString> bookNameAbbreviationsTryVector();
+ void initSwordLocaleCombo();
+
private: /* Fields: */
+ QLabel* m_showLogoLabel;
QCheckBox* m_showLogoCheck;
- QLabel *m_explanationLabel;
+ QLabel *m_languageNamesLabel;
+ QComboBox* m_swordLocaleCombo;
+ QLabel *m_transifexLabel;
QComboBox* m_styleChooserCombo;
QLabel *m_availableLabel;
- QWebView* m_stylePreviewViewer;
+ BtWebEngineView* m_stylePreviewViewer;
QLabel *m_previewLabel;
};
diff --git a/src/frontend/settingsdialogs/clistwidget.cpp b/src/frontend/settingsdialogs/clistwidget.cpp
index 9504009..79a254e 100644
--- a/src/frontend/settingsdialogs/clistwidget.cpp
+++ b/src/frontend/settingsdialogs/clistwidget.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
diff --git a/src/frontend/settingsdialogs/clistwidget.h b/src/frontend/settingsdialogs/clistwidget.h
index 393754c..2693463 100644
--- a/src/frontend/settingsdialogs/clistwidget.h
+++ b/src/frontend/settingsdialogs/clistwidget.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -18,9 +18,9 @@
class CListWidget : public QListWidget {
Q_OBJECT
public:
- CListWidget(QWidget* parent = 0);
+ CListWidget(QWidget* parent = nullptr);
- virtual QSize sizeHint () const;
+ QSize sizeHint() const override;
void setCharWidth(int width);
};
diff --git a/src/frontend/settingsdialogs/cswordsettings.cpp b/src/frontend/settingsdialogs/cswordsettings.cpp
index f8f0ebf..5913d78 100644
--- a/src/frontend/settingsdialogs/cswordsettings.cpp
+++ b/src/frontend/settingsdialogs/cswordsettings.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -15,11 +15,10 @@
#include "frontend/settingsdialogs/bttextfilterstab.h"
#include "frontend/settingsdialogs/cconfigurationdialog.h"
#include "util/cresmgr.h"
-#include "util/geticon.h"
CSwordSettingsPage::CSwordSettingsPage(CConfigurationDialog * parent)
- : BtConfigDialog::Page(util::getIcon(CResMgr::settings::sword::icon), parent)
+ : BtConfigDialog::Page(CResMgr::settings::sword::icon(), parent)
{
static const QString nullString;
diff --git a/src/frontend/settingsdialogs/cswordsettings.h b/src/frontend/settingsdialogs/cswordsettings.h
index 18a4268..16f4b9a 100644
--- a/src/frontend/settingsdialogs/cswordsettings.h
+++ b/src/frontend/settingsdialogs/cswordsettings.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -12,7 +12,8 @@
#ifndef CSWORDSETTINGS_H
#define CSWORDSETTINGS_H
-#include "frontend/bookshelfmanager/btconfigdialog.h"
+#include "btconfigdialog.h"
+
#include <QWidget>
@@ -26,7 +27,7 @@ class CSwordSettingsPage: public BtConfigDialog::Page {
public: /* Methods: */
- CSwordSettingsPage(CConfigurationDialog * parent = 0);
+ CSwordSettingsPage(CConfigurationDialog * parent = nullptr);
void save();
diff --git a/src/frontend/tips/bttipdialog.cpp b/src/frontend/tips/bttipdialog.cpp
index 75b7a6d..994b655 100644
--- a/src/frontend/tips/bttipdialog.cpp
+++ b/src/frontend/tips/bttipdialog.cpp
@@ -2,27 +2,29 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "bttipdialog.h"
+#include "frontend/btwebengineview.h"
+#include "frontend/btwebenginepage.h"
+
#include <QCheckBox>
#include <QDesktopServices>
#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QPushButton>
#include <QVBoxLayout>
-#include <QWebView>
#include "backend/config/btconfig.h"
#include "bibletimeapp.h"
-#include "util/cresmgr.h"
#include "frontend/messagedialog.h"
+#include "util/btconnect.h"
+#include "util/bticons.h"
+#include "util/cresmgr.h"
#include "util/directory.h"
-#include "util/geticon.h"
-#include "util/htmlescape.h"
namespace {
@@ -50,13 +52,6 @@ inline QString make_html(QWidget *widget, const QString &text) {
+ vertical_align(text) + "</body></html>";
}
-inline QString make_icon(const QString &icon) {
- namespace DU = util::directory;
- QString fileName = DU::getIconDir().filePath(icon);
- QString iconUrl = QUrl::fromLocalFile(fileName).toString();
- return "<img src=\"" + util::htmlEscape(iconUrl) + "\" width=\"32\" />";
-}
-
const QString LastTipNumberKey = "GUI/lastTipNumber";
} // anonymous namespace
@@ -67,14 +62,15 @@ BtTipDialog::BtTipDialog(QWidget *parent, Qt::WindowFlags wflags)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowTitle(tr("Tip Of The Day"));
- setWindowIcon(util::getIcon(CResMgr::mainMenu::help::tipOfTheDay::icon));
+ setWindowIcon(CResMgr::mainMenu::help::tipOfTheDay::icon());
resize(450, 240);
QVBoxLayout *mainLayout = new QVBoxLayout;
- m_tipView = new QWebView;
+ m_tipView = new BtWebEngineView(this);
+ BtWebEnginePage *page = new BtWebEnginePage(this);
+ m_tipView->setPage(page);
m_tipView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- m_tipView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
mainLayout->addWidget(m_tipView);
QHBoxLayout* hLayout = new QHBoxLayout;
@@ -98,22 +94,14 @@ BtTipDialog::BtTipDialog(QWidget *parent, Qt::WindowFlags wflags)
mainLayout->addLayout(hLayout);
setLayout(mainLayout);
- bool ok;
- ok = connect(m_showTipsCheckBox, SIGNAL(toggled(bool)),
- this, SLOT(startupBoxChanged(bool)));
- Q_ASSERT(ok);
-
- ok = connect(m_buttonBox, SIGNAL(rejected()),
- this, SLOT(reject()));
- Q_ASSERT(ok);
-
- ok = connect(nextButton, SIGNAL(clicked()),
- this, SLOT(nextTip()));
- Q_ASSERT(ok);
-
- ok = connect(m_tipView->page(), SIGNAL(linkClicked(const QUrl&)),
- this, SLOT(linkClicked(const QUrl&)));
- Q_ASSERT(ok);
+ BT_CONNECT(m_showTipsCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(startupBoxChanged(bool)));
+ BT_CONNECT(m_buttonBox, SIGNAL(rejected()),
+ this, SLOT(reject()));
+ BT_CONNECT(nextButton, SIGNAL(clicked()),
+ this, SLOT(nextTip()));
+ BT_CONNECT(m_tipView->btPage(), SIGNAL(linkClicked(QUrl const &)),
+ this, SLOT(linkClicked(QUrl const &)));
m_tipNumber = btConfig().value<int>(LastTipNumberKey, 0);
initTips();
@@ -125,18 +113,18 @@ void BtTipDialog::initTips() {
m_tips << tr("To add multiple Bible works in parallel in your active Bible window"
" select this icon and choose another Bible work.")
- + "<br><center>" + make_icon(CResMgr::modules::bible::icon_add) + "</center>";
+ + "<br><center>" + iconToHtml(CResMgr::modules::bible::icon_add()) + "</center>";
m_tips << tr("To add multiple commentary works in parallel in your active commentary window"
" select this icon and choose another commentary work.")
- + "<br><center>" + make_icon(CResMgr::modules::commentary::icon_add) + "</center>";
+ + "<br><center>" + iconToHtml(CResMgr::modules::commentary::icon_add()) + "</center>";
m_tips << tr("To learn more about the BibleTime project please go to our web site.")
+ "<br><center><a href=\"http://www.bibletime.info\">www.bibletime.info</a></center>";
m_tips << tr("To synchronize a commentary window with the active Bible window, activate the"
" commentary window and select this icon.") + "<br><center>"
- + make_icon(CResMgr::displaywindows::commentaryWindow::syncWindow::icon)
+ + iconToHtml(CResMgr::displaywindows::commentaryWindow::syncWindow::icon())
+ "</center><br>" + tr("Select the icon again to stop the synchronization.");
m_tips << tr("To create a bookmark drag any verse reference from a Bible or commentary work"
@@ -148,9 +136,6 @@ void BtTipDialog::initTips() {
" and select the Edit Bookmark menu. After finishing the edit the description can be"
" seen by hovering over the bookmark.");
- m_tips << tr("To load multiple installation sources for works, go to the Bookshelf Manager"
- ", select the Add button, and then the Get List button.");
-
m_tips << tr("To find more information about a work, go the the Bookshelf window, right"
" click on the work, and select the About menu.");
diff --git a/src/frontend/tips/bttipdialog.h b/src/frontend/tips/bttipdialog.h
index e8058ee..1da539c 100644
--- a/src/frontend/tips/bttipdialog.h
+++ b/src/frontend/tips/bttipdialog.h
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -21,8 +21,7 @@ class QCheckBox;
class QDialogButtonBox;
class QPushButton;
class QUrl;
-class QWebView;
-
+class BtWebEngineView;
/**
The Tip Of The Day dialog.
*/
@@ -31,7 +30,7 @@ class BtTipDialog: public QDialog {
public: /* Methods: */
- BtTipDialog(QWidget *parent = 0, Qt::WindowFlags wflags = Qt::Dialog);
+ BtTipDialog(QWidget *parent = nullptr, Qt::WindowFlags wflags = Qt::Dialog);
private: /* Methods: */
@@ -55,7 +54,7 @@ class BtTipDialog: public QDialog {
private: /* Fields: */
QDialogButtonBox* m_buttonBox;
- QWebView* m_tipView;
+ BtWebEngineView* m_tipView;
QCheckBox* m_showTipsCheckBox;
int m_tipNumber;
QStringList m_tips;
diff --git a/src/frontend/welcome/btwelcomedialog.cpp b/src/frontend/welcome/btwelcomedialog.cpp
new file mode 100644
index 0000000..63346d0
--- /dev/null
+++ b/src/frontend/welcome/btwelcomedialog.cpp
@@ -0,0 +1,95 @@
+/*********
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#include "btwelcomedialog.h"
+
+#include "bibletime.h"
+#include "frontend/messagedialog.h"
+
+#include <QDialogButtonBox>
+#include <QLabel>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include "util/btconnect.h"
+#include "util/bticons.h"
+#include "util/cresmgr.h"
+
+void BtWelcomeDialog::openWelcome() {
+ BtWelcomeDialog dlg(BibleTime::instance());
+ dlg.exec();
+}
+
+BtWelcomeDialog::BtWelcomeDialog(QWidget *parent, Qt::WindowFlags wflags)
+ : QDialog(parent, wflags)
+{
+ setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+ setWindowIcon(CResMgr::mainMenu::help::tipOfTheDay::icon());
+ resize(560, 300);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+
+ m_iconLabel = new QLabel(this);
+ m_iconLabel->setPixmap(BtIcons::instance().icon_bibletime.pixmap(48));
+ mainLayout->addWidget(m_iconLabel, 0, Qt::AlignHCenter);
+
+ m_label = new QLabel(this);
+ m_label->setWordWrap(true);
+ mainLayout->addWidget(m_label);
+
+ mainLayout->addStretch();
+
+ m_buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
+
+ m_installButton = m_buttonBox->addButton(
+ "", QDialogButtonBox::AcceptRole);
+
+ m_laterButton = m_buttonBox->addButton(
+ "", QDialogButtonBox::RejectRole);
+
+ mainLayout->addWidget(m_buttonBox);
+
+ setLayout(mainLayout);
+
+ retranslateUi();
+
+ BT_CONNECT(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ BT_CONNECT(m_buttonBox, SIGNAL(accepted()), this, SLOT(slotAccept()));
+
+}
+
+void BtWelcomeDialog::slotAccept() {
+ hide();
+ accept();
+ BibleTime::instance()->slotBookshelfWizard();
+}
+
+void BtWelcomeDialog::retranslateUi() {
+ setWindowTitle(tr("Welcome to BibleTime"));
+
+ QString msg("<p>");
+ msg += tr("BibleTime is an easy to use but powerful Bible study tool.");
+ msg += "</p><p>";
+ msg += tr("Before you can use this application some works must be installed. ");
+ msg += tr("Various works such as Bibles, books, commentaries, and lexicons are available from remote libraries. ");
+ msg += "</p><p>";
+ msg += tr("Choose the \"Install works\" button to download works. ");
+ msg += tr("The menu \"Settings > Bookshelf Manager\" also installs works and can be used later.");
+ m_label->setText(msg);
+
+ m_laterButton->setText(tr("Install later"));
+
+ m_installButton->setText( QString(" ") + tr("Install works...") + QString(" "));
+ QFont font = m_installButton->font();
+ font.setBold(true);
+ m_installButton->setFont(font);
+}
+
+//void BtWelcomeDialog::linkClicked(const QUrl& url) {
+// QDesktopServices::openUrl(url);
+//}
diff --git a/src/frontend/welcome/btwelcomedialog.h b/src/frontend/welcome/btwelcomedialog.h
new file mode 100644
index 0000000..0b8320f
--- /dev/null
+++ b/src/frontend/welcome/btwelcomedialog.h
@@ -0,0 +1,45 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2016 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License version 2.0.
+*
+**********/
+
+#ifndef BTWELCOMEDIALOG_H
+#define BTWELCOMEDIALOG_H
+
+#include <QDialog>
+
+class QDialogButtonBox;
+class QLabel;
+
+class BtWelcomeDialog: public QDialog {
+
+ Q_OBJECT
+
+public:
+
+ BtWelcomeDialog(QWidget *parent = nullptr, Qt::WindowFlags wflags = Qt::Dialog);
+
+ static void openWelcome();
+
+protected:
+ void retranslateUi();
+
+private slots:
+ void slotAccept();
+
+private:
+
+ QLabel *m_iconLabel;
+ QLabel *m_label;
+ QPushButton *m_laterButton;
+ QPushButton *m_installButton;
+ QDialogButtonBox* m_buttonBox;
+};
+
+#endif