summaryrefslogtreecommitdiff
path: root/src/frontend/display
diff options
context:
space:
mode:
authorTeus Benschop <teusjannette@gmail.com>2017-10-06 12:24:31 +0200
committerTeus Benschop <teusjannette@gmail.com>2017-10-06 12:24:31 +0200
commit90d2181239761f8950b95768d3b037843e9e8b50 (patch)
tree6cc667ab420cc04029de2de7e361d2305e214595 /src/frontend/display
parent1ea03c0fce8066c1e22188447b4a6ca4dcef1201 (diff)
New upstream version 2.11.0
Diffstat (limited to 'src/frontend/display')
-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
20 files changed, 584 insertions, 450 deletions
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;